Add a reload command

This commit is contained in:
destro174 2021-08-14 19:55:32 +02:00
parent 0ace870550
commit 47fb205001
7 changed files with 82 additions and 2 deletions

View File

@ -13,4 +13,8 @@ public interface ChatAPI {
DatabaseConnection getDataBase();
void ReloadConfig();
void ReloadChatFilters();
}

View File

@ -18,7 +18,7 @@ public class ChatImplementation implements ChatAPI{
public ChatImplementation() {
instance = this;
Config.init();
ReloadConfig();
luckPerms = getLuckPerms();
databaseConnection = getDataBase();
@ -49,4 +49,14 @@ public class ChatImplementation implements ChatAPI{
return databaseConnection;
}
@Override
public void ReloadConfig() {
Config.init();
}
@Override
public void ReloadChatFilters() {
RegexManager.initialize();
}
}

View File

@ -68,7 +68,7 @@ public final class ServerConfig {
/** DO NOT EDIT ANYTHING ABOVE **/
public boolean GLOBALCHAT = true;
public boolean GLOBALCHAT = false;
public boolean JOINLEAVEMSSAGES = true;
public boolean MUTED = false;
private void ServerSettings() {

View File

@ -11,6 +11,8 @@ import com.alttd.chat.listeners.PluginMessage;
import com.alttd.chat.objects.channels.Channel;
import com.alttd.chat.objects.channels.CustomChannel;
import com.alttd.chat.util.ALogger;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
@ -104,4 +106,12 @@ public class ChatPlugin extends JavaPlugin {
public void toggleServerMuted() {
serverConfig.MUTED = !serverConfig.MUTED;
}
public void ReloadConfig() {
chatAPI.ReloadConfig();
chatAPI.ReloadChatFilters();
serverConfig = new ServerConfig(Bukkit.getServerName());
Bukkit.broadcast("Reloaded ChatPlugin Config.", "command.proxy.reloadchat");
ALogger.info("Reloaded ChatPlugin config.");
}
}

View File

@ -136,6 +136,9 @@ public class PluginMessage implements PluginMessageListener {
}.runTaskAsynchronously(ChatPlugin.getInstance());
break;
}
case "reloadconfig":
ChatPlugin.getInstance().ReloadConfig();
break;
default:
break;
}

View File

@ -9,7 +9,10 @@ import com.alttd.chat.listeners.ChatListener;
import com.alttd.chat.listeners.ProxyPlayerListener;
import com.alttd.chat.listeners.PluginMessageListener;
import com.alttd.chat.util.ALogger;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.google.inject.Inject;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Dependency;
@ -18,6 +21,7 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.slf4j.Logger;
import java.io.File;
@ -68,6 +72,16 @@ public class VelocityChat {
loadCommands();
}
public void ReloadConfig() {
chatAPI.ReloadConfig();
chatAPI.ReloadChatFilters();
serverHandler.cleanup();
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
buf.writeUTF("reloadconfig");
ALogger.info("Reloaded ChatPlugin proxy config.");
getProxy().getAllServers().stream().forEach(registeredServer -> registeredServer.sendPluginMessage(getChannelIdentifier(), buf.toByteArray()));
}
public File getDataDirectory() {
return dataDirectory.toFile();
}

View File

@ -0,0 +1,39 @@
package com.alttd.chat.commands;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.config.Config;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import java.util.ArrayList;
import java.util.Collection;
public class Reload {
public Reload(ProxyServer proxyServer) {
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("reloadchat")
.requires(ctx -> ctx.hasPermission("command.proxy.reloadchat"))
.executes(context -> {
VelocityChat.getPlugin().ReloadConfig();
return 1;
})
.build();
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
CommandMeta meta = metaBuilder.build();
proxyServer.getCommandManager().register(meta, brigadierCommand);
}
}