UTF-8 config support (#8)
This commit is contained in:
parent
76d87da1a4
commit
5982028eda
|
@ -10,7 +10,7 @@ loader_version=0.8.8+build.202
|
||||||
fabric_version=0.14.0+build.371-1.16
|
fabric_version=0.14.0+build.371-1.16
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.4.5
|
mod_version = 1.4.6
|
||||||
maven_group = org.samo_lego
|
maven_group = org.samo_lego
|
||||||
archives_base_name = simpleauth
|
archives_base_name = simpleauth
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ package org.samo_lego.simpleauth;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||||
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.event.player.*;
|
import net.fabricmc.fabric.api.event.player.*;
|
||||||
import net.fabricmc.fabric.api.event.server.ServerStopCallback;
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
@ -112,10 +112,10 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
UseItemCallback.EVENT.register((player, world, hand) -> AuthEventHandler.onUseItem(player));
|
UseItemCallback.EVENT.register((player, world, hand) -> AuthEventHandler.onUseItem(player));
|
||||||
AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onAttackEntity(player));
|
AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onAttackEntity(player));
|
||||||
UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onUseEntity(player));
|
UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onUseEntity(player));
|
||||||
ServerStopCallback.EVENT.register(minecraftServer -> SimpleAuth.onStopServer());
|
ServerLifecycleEvents.SERVER_STOPPING.register(minecraftServer -> this.onStopServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onStopServer() {
|
private void onStopServer() {
|
||||||
LOGGER.info("[SimpleAuth] Shutting down SimpleAuth.");
|
LOGGER.info("[SimpleAuth] Shutting down SimpleAuth.");
|
||||||
|
|
||||||
WriteBatch batch = db.getLevelDBStore().createWriteBatch();
|
WriteBatch batch = db.getLevelDBStore().createWriteBatch();
|
||||||
|
|
|
@ -22,10 +22,8 @@ import com.google.gson.GsonBuilder;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileReader;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class AuthConfig {
|
public class AuthConfig {
|
||||||
// If player is not authenticated, following conditions apply
|
// If player is not authenticated, following conditions apply
|
||||||
|
@ -146,7 +144,7 @@ public class AuthConfig {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
public void save(File file) {
|
public void save(File file) {
|
||||||
try (FileWriter writer = new FileWriter(file)) {
|
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
|
||||||
gson.toJson(this, writer);
|
gson.toJson(this, writer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("[SimpleAuth] Problem occurred when saving config: ", e);
|
LOGGER.error("[SimpleAuth] Problem occurred when saving config: ", e);
|
||||||
|
|
Loading…
Reference in New Issue