Add console error logs

This commit is contained in:
itqop 2024-10-21 17:27:27 +03:00
parent dbdd6c9ac4
commit 39b750d590
4 changed files with 18 additions and 5 deletions

View File

@ -1,6 +1,5 @@
package org.itqop.chatit;
import com.mojang.logging.LogUtils;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.event.server.ServerStartingEvent;
@ -12,6 +11,7 @@ import org.itqop.chatit.handlers.ChatEventHandler;
import org.itqop.chatit.utils.Config;
import org.itqop.chatit.utils.PlayerConfigManager;
import org.slf4j.Logger;
import com.mojang.logging.LogUtils;
@Mod(ChatIT.MODID)
public class ChatIT {

View File

@ -11,15 +11,20 @@ import net.minecraft.ChatFormatting;
import org.itqop.chatit.utils.Config;
import org.itqop.chatit.utils.PlayerConfigManager;
import org.itqop.chatit.utils.ProfanityChecker;
import org.slf4j.Logger;
import com.mojang.logging.LogUtils;
import java.util.concurrent.CompletableFuture;
@Mod.EventBusSubscriber
public class ChatEventHandler {
private static final Logger LOGGER = LogUtils.getLogger();
@SubscribeEvent
public static void onServerChat(ServerChatEvent event) {
ServerPlayer sender = event.getPlayer();
MinecraftServer server = sender.getServer();
String originalMessage = event.getMessage().getString();
@ -57,7 +62,7 @@ public class ChatEventHandler {
});
}
}).exceptionally(ex -> {
ex.printStackTrace();
LOGGER.error(ex.toString());
if (server != null) {
server.execute(() -> {
MutableComponent errorComponent = createErrorMessage(sender, message);

View File

@ -12,11 +12,15 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.slf4j.Logger;
import com.mojang.logging.LogUtils;
public class PlayerConfigManager {
private static final Gson GSON = new Gson();
private static final File CONFIG_FILE = new File("config/chatit_player_settings.json");
private static final Type CONFIG_TYPE = new TypeToken<Map<UUID, Boolean>>() {}.getType();
private static final Logger LOGGER = LogUtils.getLogger();
private static Map<UUID, Boolean> playerSettings = new HashMap<>();
@ -25,7 +29,7 @@ public class PlayerConfigManager {
try (FileReader reader = new FileReader(CONFIG_FILE)) {
playerSettings = GSON.fromJson(reader, CONFIG_TYPE);
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e.toString());
}
}
}
@ -34,7 +38,7 @@ public class PlayerConfigManager {
try (FileWriter writer = new FileWriter(CONFIG_FILE)) {
GSON.toJson(playerSettings, writer);
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e.toString());
}
}

View File

@ -8,12 +8,16 @@ import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import com.mojang.logging.LogUtils;
import com.google.gson.Gson;
public class ProfanityChecker {
private static final Gson GSON = new Gson();
private static final HttpClient CLIENT = HttpClient.newHttpClient();
private static final Logger LOGGER = LogUtils.getLogger();
private static Pattern profanityPattern = null;
@ -49,7 +53,7 @@ public class ProfanityChecker {
return Double.parseDouble(responseBody);
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e.toString());
if (Config.useRegex) {
if (containsProfanity(message)) {
return 1.0;