From 609b7d8419e2218115a4106be73bb30508650bd5 Mon Sep 17 00:00:00 2001 From: ohAlee Date: Tue, 3 Jan 2023 17:45:42 +0100 Subject: [PATCH] Registered Tab and new cache --- .../java/it/ohalee/minecraftgpt/Main.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/it/ohalee/minecraftgpt/Main.java b/src/main/java/it/ohalee/minecraftgpt/Main.java index e67f976..82b099c 100644 --- a/src/main/java/it/ohalee/minecraftgpt/Main.java +++ b/src/main/java/it/ohalee/minecraftgpt/Main.java @@ -1,9 +1,9 @@ package it.ohalee.minecraftgpt; import com.google.common.cache.*; -import it.ohalee.minecraftgpt.command.GPTCommand; +import it.ohalee.minecraftgpt.command.ChatCommand; import it.ohalee.minecraftgpt.handler.PlayerHandlers; -import lombok.Getter; +import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -11,8 +11,8 @@ import java.util.concurrent.TimeUnit; public class Main extends JavaPlugin { - @Getter - private Cache cache; + public static Cache CACHE; + public static Cache USER_TYPE; @Override public void onEnable() { @@ -20,16 +20,24 @@ public class Main extends JavaPlugin { OpenAI.init(getConfig().getString("API_KEY")); - cache = CacheBuilder.newBuilder() + CACHE = CacheBuilder.newBuilder() .expireAfterWrite(30, TimeUnit.MINUTES) .removalListener((RemovalListener) notification -> { - if (notification.getCause() == RemovalCause.EXPIRED && notification.getKey() != null) { + if (notification.getKey() == null) { + return; + } + USER_TYPE.invalidate(notification.getKey()); + if (notification.getCause() == RemovalCause.EXPIRED) { notification.getKey().sendMessage(getConfig().getString("command.toggle.disabled").replace("&", "ยง")); } }).build(); + USER_TYPE = CacheBuilder.newBuilder().build(); getServer().getPluginManager().registerEvents(new PlayerHandlers(this), this); - getCommand("chatgpt").setExecutor(new GPTCommand(this)); + ChatCommand command = new ChatCommand(this); + PluginCommand chatgpt = getCommand("chatgpt"); + chatgpt.setExecutor(command); + chatgpt.setTabCompleter(command); getLogger().info("Plugin enabled!"); }