Bring back customisable messages for reloading ServerUtils using wacky methods

This commit is contained in:
Frank van der Heijden 2020-07-20 14:14:23 +02:00
parent 6c8a93dc1b
commit a0bdaeb2fc
No known key found for this signature in database
GPG key ID: 26DA56488D314D11
5 changed files with 57 additions and 22 deletions

View file

@ -24,6 +24,7 @@ import net.frankheijden.serverutils.common.entities.CloseableResult;
import net.frankheijden.serverutils.common.entities.Result;
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
import net.frankheijden.serverutils.common.utils.FormatBuilder;
import net.frankheijden.serverutils.common.utils.HexUtils;
import net.frankheijden.serverutils.common.utils.ListBuilder;
import net.frankheijden.serverutils.common.utils.ListFormat;
import net.md_5.bungee.api.ChatColor;
@ -137,18 +138,16 @@ public class CommandServerUtils extends BaseCommand {
@CommandPermission("serverutils.reloadplugin")
@Description("Reloads a specified plugin.")
public void onReloadPlugin(CommandSender sender, String pluginName) {
if (pluginName.equalsIgnoreCase("ServerUtils")) {
String result = BungeePluginManager.get().reloadPlugin(pluginName).toString();
if (result.equals("SUCCESS")) {
sender.sendMessage(ChatColor.GREEN + "Successfully reloaded ServerUtils.");
} else {
sender.sendMessage(ChatColor.RED + "Something went wrong reloading ServerUtils.");
}
return;
}
// Wacky method to have the resources needed for the reload in memory, in case of a self reload.
HexUtils utils = new HexUtils();
Map<String, Object> section = Messenger.getInstance().getConfig().getMap("serverutils");
String result = BungeePluginManager.get().reloadPlugin(pluginName).toString();
Result result = BungeePluginManager.get().reloadPlugin(pluginName);
result.sendTo(BungeeUtils.wrap(sender), "reload", pluginName);
String msg = (String) section.get(result.toLowerCase());
if (msg != null && !msg.isEmpty()) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', utils.convertHexString(
msg.replace("%action%", "reload").replace("%what%", pluginName))));
}
}
/**

View file

@ -4,6 +4,8 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import net.frankheijden.serverutils.common.config.YamlConfig;
import net.md_5.bungee.config.Configuration;
@ -38,6 +40,21 @@ public class BungeeYamlConfig implements YamlConfig {
return obj;
}
@Override
public Map<String, Object> getMap(String path) {
Object obj = config.get(path);
if (obj instanceof Configuration) {
Configuration section = (Configuration) obj;
Collection<String> keys = section.getKeys();
Map<String, Object> map = new HashMap<>(keys.size());
for (String key : keys) {
map.put(key, section.get(key));
}
return map;
}
return new HashMap<>();
}
@Override
public void set(String path, Object value) {
config.set(path, value);