UTF-8 config support (#8)

This commit is contained in:
samo_lego 2020-06-29 15:32:16 +02:00
parent 76d87da1a4
commit 5982028eda
3 changed files with 7 additions and 9 deletions

View File

@ -10,7 +10,7 @@ loader_version=0.8.8+build.202
fabric_version=0.14.0+build.371-1.16
# Mod Properties
mod_version = 1.4.5
mod_version = 1.4.6
maven_group = org.samo_lego
archives_base_name = simpleauth

View File

@ -3,8 +3,8 @@ package org.samo_lego.simpleauth;
import com.google.gson.JsonObject;
import net.fabricmc.api.DedicatedServerModInitializer;
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.server.ServerStopCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
@ -112,10 +112,10 @@ public class SimpleAuth implements DedicatedServerModInitializer {
UseItemCallback.EVENT.register((player, world, hand) -> AuthEventHandler.onUseItem(player));
AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onAttackEntity(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.");
WriteBatch batch = db.getLevelDBStore().createWriteBatch();

View File

@ -22,10 +22,8 @@ import com.google.gson.GsonBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.nio.charset.StandardCharsets;
public class AuthConfig {
// If player is not authenticated, following conditions apply
@ -146,7 +144,7 @@ public class AuthConfig {
return config;
}
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);
} catch (IOException e) {
LOGGER.error("[SimpleAuth] Problem occurred when saving config: ", e);