Skip to content

Commit

Permalink
chore(bukkit): Move purgeLog to LoggingUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Sep 29, 2024
1 parent 33d9417 commit 51c97b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Logger;

import static io.wdsj.asw.bukkit.util.LoggingUtils.purgeLog;
import static io.wdsj.asw.bukkit.util.TimingUtils.resetStatistics;
import static io.wdsj.asw.bukkit.util.Utils.*;

Expand All @@ -76,8 +77,8 @@ public final class AdvancedSensitiveWords extends JavaPlugin {
private static boolean isEventMode = false;
public static Logger LOGGER;
private static BukkitLibraryService libraryService;
private final OllamaProcessor OLLAMA_PROCESSOR = new OllamaProcessor();
private final OpenAIProcessor OPENAI_PROCESSOR = new OpenAIProcessor();
private OllamaProcessor ollamaProcessor;
private OpenAIProcessor openaiProcessor;
private VoiceChatHookService voiceChatHookService;
private CachingPermTool permCache;
public static TaskScheduler getScheduler() {
Expand Down Expand Up @@ -167,10 +168,12 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new AltsListener(), this);
getServer().getPluginManager().registerEvents(new FakeMessageExecutor(), this);
if (settingsManager.getProperty(PluginSettings.ENABLE_OLLAMA_AI_MODEL_CHECK)) {
OLLAMA_PROCESSOR.initService(settingsManager.getProperty(PluginSettings.OLLAMA_AI_API_ADDRESS), settingsManager.getProperty(PluginSettings.OLLAMA_AI_MODEL_NAME), settingsManager.getProperty(PluginSettings.AI_MODEL_TIMEOUT), settingsManager.getProperty(PluginSettings.OLLAMA_AI_DEBUG_LOG));
ollamaProcessor = new OllamaProcessor();
ollamaProcessor.initService(settingsManager.getProperty(PluginSettings.OLLAMA_AI_API_ADDRESS), settingsManager.getProperty(PluginSettings.OLLAMA_AI_MODEL_NAME), settingsManager.getProperty(PluginSettings.AI_MODEL_TIMEOUT), settingsManager.getProperty(PluginSettings.OLLAMA_AI_DEBUG_LOG));
}
if (settingsManager.getProperty(PluginSettings.ENABLE_OPENAI_AI_MODEL_CHECK)) {
OPENAI_PROCESSOR.initService(settingsManager.getProperty(PluginSettings.OPENAI_API_KEY), settingsManager.getProperty(PluginSettings.OPENAI_DEBUG_LOG));
openaiProcessor = new OpenAIProcessor();
openaiProcessor.initService(settingsManager.getProperty(PluginSettings.OPENAI_API_KEY), settingsManager.getProperty(PluginSettings.OPENAI_DEBUG_LOG));
}
if (settingsManager.getProperty(PluginSettings.ENABLE_SIGN_EDIT_CHECK)) {
getServer().getPluginManager().registerEvents(new SignListener(), this);
Expand Down Expand Up @@ -293,8 +296,12 @@ public void onDisable() {
SignContext.forceClearContext();
PlayerShadowController.clear();
PlayerAltController.clear();
OLLAMA_PROCESSOR.shutdown();
OPENAI_PROCESSOR.shutdown();
if (ollamaProcessor != null) {
ollamaProcessor.shutdown();
}
if (openaiProcessor != null) {
openaiProcessor.shutdown();
}
if (voiceChatHookService != null) {
voiceChatHookService.unregister();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.wdsj.asw.bukkit.util

import com.github.houbb.heaven.util.io.FileUtil
import com.google.common.util.concurrent.ThreadFactoryBuilder
import io.wdsj.asw.bukkit.AdvancedSensitiveWords
import io.wdsj.asw.bukkit.AdvancedSensitiveWords.LOGGER
Expand Down Expand Up @@ -39,6 +40,14 @@ object LoggingUtils {
}
}

@JvmStatic
fun purgeLog() {
val logFile = File(AdvancedSensitiveWords.getInstance().dataFolder, "violations.log")
if (!logFile.exists()) return
FileUtil.deleteFile(logFile)
LOGGER.info("Successfully purged violations")
}

@JvmStatic
fun start() {
loggingThreadPool = Executors.newSingleThreadExecutor(
Expand Down
11 changes: 0 additions & 11 deletions bukkit/src/main/kotlin/io/wdsj/asw/bukkit/util/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.wdsj.asw.bukkit.util

import com.github.houbb.heaven.util.io.FileUtil
import com.github.houbb.heaven.util.lang.StringUtil
import io.wdsj.asw.bukkit.AdvancedSensitiveWords
import io.wdsj.asw.bukkit.setting.PluginSettings
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import java.io.File
import java.util.*
import java.util.concurrent.atomic.AtomicLong

Expand Down Expand Up @@ -52,15 +50,6 @@ object Utils {
}
return true
}

@JvmStatic
fun purgeLog() {
val logFile = File(AdvancedSensitiveWords.getInstance().dataFolder, "violations.log")
if (!logFile.exists()) return
FileUtil.deleteFile(logFile)
AdvancedSensitiveWords.LOGGER.info("Successfully purged violations")
}

fun isCommand(command: String): Boolean {
return command.startsWith("/")
}
Expand Down

0 comments on commit 51c97b3

Please sign in to comment.