Register event with custom priority
This commit is contained in:
parent
3231e15f36
commit
f1c06fd41d
@ -5,12 +5,17 @@ import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.RemovalCause;
|
||||
import com.google.common.cache.RemovalListener;
|
||||
import it.ohalee.minecraftgpt.command.ChatCommand;
|
||||
import it.ohalee.minecraftgpt.handler.PlayerHandlers;
|
||||
import it.ohalee.minecraftgpt.handler.ChatHandler;
|
||||
import it.ohalee.minecraftgpt.handler.PlayerHandler;
|
||||
import it.ohalee.minecraftgpt.util.Messages;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventException;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
@ -38,7 +43,18 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
}).build();
|
||||
|
||||
getServer().getPluginManager().registerEvents(new PlayerHandlers(this), this);
|
||||
String priority = getConfig().getString("chat-priority", "HIGH").toUpperCase();
|
||||
Class<AsyncPlayerChatEvent> eventClass = AsyncPlayerChatEvent.class;
|
||||
getServer().getPluginManager().registerEvent(eventClass, new ChatHandler(this), EventPriority.valueOf(priority), (listener, event) -> {
|
||||
try {
|
||||
listener.getClass().getMethod("onAsyncPlayerChat", eventClass).invoke(listener, event);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new EventException(ex.getCause());
|
||||
} catch (Throwable t) {
|
||||
throw new EventException(t);
|
||||
}
|
||||
}, this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerHandler(this), this);
|
||||
|
||||
ChatCommand command = new ChatCommand(this);
|
||||
PluginCommand chatgpt = getCommand("chatgpt");
|
||||
|
Loading…
Reference in New Issue
Block a user