2021-05-13 12:11:29 +00:00
|
|
|
package com.alttd.chat;
|
|
|
|
|
|
2021-07-27 16:46:58 +00:00
|
|
|
import com.alttd.chat.commands.*;
|
2021-05-13 18:27:20 +00:00
|
|
|
import com.alttd.chat.config.Config;
|
2021-07-30 01:16:41 +00:00
|
|
|
import com.alttd.chat.config.ServerConfig;
|
2021-06-30 00:02:35 +00:00
|
|
|
import com.alttd.chat.database.DatabaseConnection;
|
2021-05-13 12:11:29 +00:00
|
|
|
import com.alttd.chat.handler.ChatHandler;
|
2021-06-13 11:53:49 +00:00
|
|
|
import com.alttd.chat.listeners.ChatListener;
|
2021-05-13 12:11:29 +00:00
|
|
|
import com.alttd.chat.listeners.PlayerListener;
|
2021-05-13 18:27:20 +00:00
|
|
|
import com.alttd.chat.listeners.PluginMessage;
|
2021-05-15 11:52:02 +00:00
|
|
|
import com.alttd.chat.util.ALogger;
|
2021-07-30 01:16:41 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2021-05-13 12:11:29 +00:00
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
|
|
public class ChatPlugin extends JavaPlugin {
|
|
|
|
|
|
|
|
|
|
private static ChatPlugin instance;
|
|
|
|
|
|
|
|
|
|
private ChatAPI chatAPI;
|
|
|
|
|
private ChatHandler chatHandler;
|
|
|
|
|
|
2021-05-13 18:27:20 +00:00
|
|
|
private String messageChannel;
|
2021-07-30 01:16:41 +00:00
|
|
|
private ServerConfig serverConfig;
|
2021-05-13 18:27:20 +00:00
|
|
|
|
2021-05-13 12:11:29 +00:00
|
|
|
@Override
|
|
|
|
|
public void onEnable() {
|
|
|
|
|
instance = this;
|
2021-06-13 11:53:49 +00:00
|
|
|
ALogger.init(getSLF4JLogger());
|
2021-05-13 12:11:29 +00:00
|
|
|
chatAPI = new ChatImplementation();
|
|
|
|
|
chatHandler = new ChatHandler();
|
2021-06-30 00:02:35 +00:00
|
|
|
DatabaseConnection.initialize();
|
2021-07-30 01:16:41 +00:00
|
|
|
serverConfig = new ServerConfig(Bukkit.getServerName());
|
2021-06-13 11:53:49 +00:00
|
|
|
registerListener(new PlayerListener(), new ChatListener());
|
2021-07-30 01:16:41 +00:00
|
|
|
if(serverConfig.GLOBALCHAT) {
|
|
|
|
|
registerCommand("globalchat", new GlobalChat());
|
|
|
|
|
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
|
|
|
|
}
|
2021-06-23 19:48:46 +00:00
|
|
|
registerCommand("message", new Message());
|
|
|
|
|
registerCommand("reply", new Reply());
|
2021-07-27 16:46:58 +00:00
|
|
|
registerCommand("ignore", new Ignore());
|
|
|
|
|
registerCommand("unignore", new Unignore());
|
2021-07-30 21:22:38 +00:00
|
|
|
registerCommand("muteserver", new MuteServer());
|
2021-08-01 19:00:57 +00:00
|
|
|
registerCommand("spy", new Spy());
|
2021-05-13 18:27:20 +00:00
|
|
|
|
|
|
|
|
messageChannel = Config.MESSAGECHANNEL;
|
|
|
|
|
getServer().getMessenger().registerOutgoingPluginChannel(this, messageChannel);
|
|
|
|
|
getServer().getMessenger().registerIncomingPluginChannel(this, messageChannel, new PluginMessage());
|
2021-05-13 12:11:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDisable() {
|
|
|
|
|
instance = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void registerListener(Listener... listeners) {
|
|
|
|
|
for (Listener listener : listeners) {
|
|
|
|
|
getServer().getPluginManager().registerEvents(listener, this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void registerCommand(String commandName, CommandExecutor CommandExecutor) {
|
|
|
|
|
getCommand(commandName).setExecutor(CommandExecutor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ChatPlugin getInstance() {
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ChatAPI getChatAPI() {
|
|
|
|
|
return chatAPI;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ChatHandler getChatHandler() {
|
|
|
|
|
return chatHandler;
|
|
|
|
|
}
|
2021-07-30 01:16:41 +00:00
|
|
|
|
|
|
|
|
public boolean serverGlobalChatEnabled() {
|
|
|
|
|
return serverConfig.GLOBALCHAT;
|
|
|
|
|
}
|
2021-07-30 21:22:38 +00:00
|
|
|
|
|
|
|
|
public boolean serverMuted() {
|
|
|
|
|
return serverConfig.MUTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void toggleServerMuted() {
|
|
|
|
|
serverConfig.MUTED = !serverConfig.MUTED;
|
|
|
|
|
}
|
2021-05-13 12:11:29 +00:00
|
|
|
}
|