117 lines
4.2 KiB
Java
Executable File
117 lines
4.2 KiB
Java
Executable File
package com.alttd.chat;
|
|
|
|
import com.alttd.chat.commands.*;
|
|
import com.alttd.chat.config.Config;
|
|
import com.alttd.chat.config.ServerConfig;
|
|
import com.alttd.chat.database.DatabaseConnection;
|
|
import com.alttd.chat.handler.ChatHandler;
|
|
import com.alttd.chat.listeners.*;
|
|
import com.alttd.chat.nicknames.Nicknames;
|
|
import com.alttd.chat.nicknames.NicknamesEvents;
|
|
import com.alttd.chat.objects.channels.Channel;
|
|
import com.alttd.chat.objects.channels.CustomChannel;
|
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
|
import com.alttd.chat.util.ALogger;
|
|
import com.alttd.chat.util.ServerName;
|
|
import com.alttd.chat.util.Utility;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import java.util.Objects;
|
|
|
|
public class ChatPlugin extends JavaPlugin {
|
|
|
|
private static ChatPlugin instance;
|
|
|
|
private ChatAPI chatAPI;
|
|
private ChatHandler chatHandler;
|
|
|
|
private ServerConfig serverConfig;
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
instance = this;
|
|
ALogger.init(getSLF4JLogger());
|
|
chatAPI = new ChatImplementation();
|
|
chatHandler = new ChatHandler();
|
|
DatabaseConnection.initialize();
|
|
serverConfig = new ServerConfig(ServerName.getServerName());
|
|
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
|
|
registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler, this));
|
|
if (serverConfig.GLOBALCHAT) {
|
|
registerCommand("globalchat", new GlobalChat());
|
|
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
|
}
|
|
registerCommand("message", new Message());
|
|
registerCommand("reply", new Reply());
|
|
registerCommand("continue", new Continue());
|
|
registerCommand("ignore", new Ignore());
|
|
registerCommand("unignore", new Unignore());
|
|
registerCommand("muteserver", new MuteServer());
|
|
registerCommand("spy", new Spy());
|
|
registerCommand("chatclear", new ChatClear());
|
|
registerCommand("p", new PartyChat());
|
|
registerCommand("emotes", new Emotes());
|
|
for (Channel channel : Channel.getChannels()) {
|
|
if (!(channel instanceof CustomChannel customChannel)) {
|
|
continue;
|
|
}
|
|
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
|
|
}
|
|
|
|
String messageChannel = Config.MESSAGECHANNEL;
|
|
getServer().getMessenger().registerOutgoingPluginChannel(this, messageChannel);
|
|
getServer().getMessenger().registerIncomingPluginChannel(this, messageChannel, new PluginMessage());
|
|
|
|
NicknamesEvents nicknamesEvents = new NicknamesEvents();
|
|
getServer().getMessenger().registerIncomingPluginChannel(this, messageChannel, nicknamesEvents);
|
|
getServer().getPluginManager().registerEvents(nicknamesEvents, this);
|
|
registerCommand("nick", new Nicknames());
|
|
}
|
|
|
|
@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) {
|
|
Objects.requireNonNull(getCommand(commandName)).setExecutor(commandExecutor);
|
|
}
|
|
|
|
public static ChatPlugin getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
public ChatHandler getChatHandler() {
|
|
return chatHandler;
|
|
}
|
|
|
|
public boolean serverGlobalChatEnabled() {
|
|
return serverConfig.GLOBALCHAT;
|
|
}
|
|
|
|
public boolean serverMuted() {
|
|
return serverConfig.MUTED;
|
|
}
|
|
|
|
public void toggleServerMuted() {
|
|
serverConfig.MUTED = !serverConfig.MUTED;
|
|
}
|
|
|
|
public void reloadConfig() {
|
|
chatAPI.reloadConfig();
|
|
chatAPI.reloadChatFilters();
|
|
serverConfig = new ServerConfig(ServerName.getServerName());
|
|
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config.").asComponent(), "command.chat.reloadchat");
|
|
ALogger.info("Reloaded ChatPlugin config.");
|
|
}
|
|
}
|