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

@ -29,6 +29,7 @@ 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.ForwardFilter;
import net.frankheijden.serverutils.common.utils.HexUtils;
import net.frankheijden.serverutils.common.utils.ListBuilder;
import net.frankheijden.serverutils.common.utils.ListFormat;
import org.bukkit.Bukkit;
@ -196,18 +197,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 = BukkitPluginManager.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 = BukkitPluginManager.get().reloadPlugin(pluginName).toString();
Result result = BukkitPluginManager.get().reloadPlugin(pluginName);
result.sendTo(BukkitUtils.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

@ -5,6 +5,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import net.frankheijden.serverutils.common.config.YamlConfig;
import org.bukkit.configuration.MemorySection;
@ -37,6 +39,16 @@ public class BukkitYamlConfig implements YamlConfig {
return obj;
}
@Override
public Map<String, Object> getMap(String path) {
Object obj = config.get(path);
if (obj instanceof MemorySection) {
System.out.println("yes");
return ((MemorySection) obj).getValues(false);
}
return new HashMap<>();
}
@Override
public void set(String path, Object value) {
config.set(path, value);