Add console error logs
This commit is contained in:
parent
dbdd6c9ac4
commit
39b750d590
|
@ -1,6 +1,5 @@
|
||||||
package org.itqop.chatit;
|
package org.itqop.chatit;
|
||||||
|
|
||||||
import com.mojang.logging.LogUtils;
|
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
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.Config;
|
||||||
import org.itqop.chatit.utils.PlayerConfigManager;
|
import org.itqop.chatit.utils.PlayerConfigManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
@Mod(ChatIT.MODID)
|
@Mod(ChatIT.MODID)
|
||||||
public class ChatIT {
|
public class ChatIT {
|
||||||
|
|
|
@ -11,15 +11,20 @@ import net.minecraft.ChatFormatting;
|
||||||
import org.itqop.chatit.utils.Config;
|
import org.itqop.chatit.utils.Config;
|
||||||
import org.itqop.chatit.utils.PlayerConfigManager;
|
import org.itqop.chatit.utils.PlayerConfigManager;
|
||||||
import org.itqop.chatit.utils.ProfanityChecker;
|
import org.itqop.chatit.utils.ProfanityChecker;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber
|
@Mod.EventBusSubscriber
|
||||||
public class ChatEventHandler {
|
public class ChatEventHandler {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onServerChat(ServerChatEvent event) {
|
public static void onServerChat(ServerChatEvent event) {
|
||||||
ServerPlayer sender = event.getPlayer();
|
ServerPlayer sender = event.getPlayer();
|
||||||
|
|
||||||
MinecraftServer server = sender.getServer();
|
MinecraftServer server = sender.getServer();
|
||||||
String originalMessage = event.getMessage().getString();
|
String originalMessage = event.getMessage().getString();
|
||||||
|
|
||||||
|
@ -57,7 +62,7 @@ public class ChatEventHandler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).exceptionally(ex -> {
|
}).exceptionally(ex -> {
|
||||||
ex.printStackTrace();
|
LOGGER.error(ex.toString());
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
server.execute(() -> {
|
server.execute(() -> {
|
||||||
MutableComponent errorComponent = createErrorMessage(sender, message);
|
MutableComponent errorComponent = createErrorMessage(sender, message);
|
||||||
|
|
|
@ -12,11 +12,15 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
public class PlayerConfigManager {
|
public class PlayerConfigManager {
|
||||||
|
|
||||||
private static final Gson GSON = new Gson();
|
private static final Gson GSON = new Gson();
|
||||||
private static final File CONFIG_FILE = new File("config/chatit_player_settings.json");
|
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 Type CONFIG_TYPE = new TypeToken<Map<UUID, Boolean>>() {}.getType();
|
||||||
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
|
||||||
private static Map<UUID, Boolean> playerSettings = new HashMap<>();
|
private static Map<UUID, Boolean> playerSettings = new HashMap<>();
|
||||||
|
|
||||||
|
@ -25,7 +29,7 @@ public class PlayerConfigManager {
|
||||||
try (FileReader reader = new FileReader(CONFIG_FILE)) {
|
try (FileReader reader = new FileReader(CONFIG_FILE)) {
|
||||||
playerSettings = GSON.fromJson(reader, CONFIG_TYPE);
|
playerSettings = GSON.fromJson(reader, CONFIG_TYPE);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
LOGGER.error(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +38,7 @@ public class PlayerConfigManager {
|
||||||
try (FileWriter writer = new FileWriter(CONFIG_FILE)) {
|
try (FileWriter writer = new FileWriter(CONFIG_FILE)) {
|
||||||
GSON.toJson(playerSettings, writer);
|
GSON.toJson(playerSettings, writer);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
LOGGER.error(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,16 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class ProfanityChecker {
|
public class ProfanityChecker {
|
||||||
|
|
||||||
private static final Gson GSON = new Gson();
|
private static final Gson GSON = new Gson();
|
||||||
private static final HttpClient CLIENT = HttpClient.newHttpClient();
|
private static final HttpClient CLIENT = HttpClient.newHttpClient();
|
||||||
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
|
||||||
private static Pattern profanityPattern = null;
|
private static Pattern profanityPattern = null;
|
||||||
|
|
||||||
|
@ -49,7 +53,7 @@ public class ProfanityChecker {
|
||||||
|
|
||||||
return Double.parseDouble(responseBody);
|
return Double.parseDouble(responseBody);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
LOGGER.error(e.toString());
|
||||||
if (Config.useRegex) {
|
if (Config.useRegex) {
|
||||||
if (containsProfanity(message)) {
|
if (containsProfanity(message)) {
|
||||||
return 1.0;
|
return 1.0;
|
||||||
|
|
Loading…
Reference in New Issue