Bring back customisable messages for reloading ServerUtils using wacky methods
This commit is contained in:
parent
6c8a93dc1b
commit
a0bdaeb2fc
5 changed files with 57 additions and 22 deletions
|
|
@ -29,6 +29,7 @@ import net.frankheijden.serverutils.common.entities.Result;
|
||||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||||
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
||||||
import net.frankheijden.serverutils.common.utils.ForwardFilter;
|
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.ListBuilder;
|
||||||
import net.frankheijden.serverutils.common.utils.ListFormat;
|
import net.frankheijden.serverutils.common.utils.ListFormat;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -196,18 +197,16 @@ public class CommandServerUtils extends BaseCommand {
|
||||||
@CommandPermission("serverutils.reloadplugin")
|
@CommandPermission("serverutils.reloadplugin")
|
||||||
@Description("Reloads a specified plugin.")
|
@Description("Reloads a specified plugin.")
|
||||||
public void onReloadPlugin(CommandSender sender, String pluginName) {
|
public void onReloadPlugin(CommandSender sender, String pluginName) {
|
||||||
if (pluginName.equalsIgnoreCase("ServerUtils")) {
|
// 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();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result result = BukkitPluginManager.get().reloadPlugin(pluginName);
|
String msg = (String) section.get(result.toLowerCase());
|
||||||
result.sendTo(BukkitUtils.wrap(sender), "reload", pluginName);
|
if (msg != null && !msg.isEmpty()) {
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', utils.convertHexString(
|
||||||
|
msg.replace("%action%", "reload").replace("%what%", pluginName))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.common.config.YamlConfig;
|
import net.frankheijden.serverutils.common.config.YamlConfig;
|
||||||
import org.bukkit.configuration.MemorySection;
|
import org.bukkit.configuration.MemorySection;
|
||||||
|
|
@ -37,6 +39,16 @@ public class BukkitYamlConfig implements YamlConfig {
|
||||||
return obj;
|
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
|
@Override
|
||||||
public void set(String path, Object value) {
|
public void set(String path, Object value) {
|
||||||
config.set(path, value);
|
config.set(path, value);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import net.frankheijden.serverutils.common.entities.CloseableResult;
|
||||||
import net.frankheijden.serverutils.common.entities.Result;
|
import net.frankheijden.serverutils.common.entities.Result;
|
||||||
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
import net.frankheijden.serverutils.common.entities.ServerCommandSender;
|
||||||
import net.frankheijden.serverutils.common.utils.FormatBuilder;
|
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.ListBuilder;
|
||||||
import net.frankheijden.serverutils.common.utils.ListFormat;
|
import net.frankheijden.serverutils.common.utils.ListFormat;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
@ -137,18 +138,16 @@ public class CommandServerUtils extends BaseCommand {
|
||||||
@CommandPermission("serverutils.reloadplugin")
|
@CommandPermission("serverutils.reloadplugin")
|
||||||
@Description("Reloads a specified plugin.")
|
@Description("Reloads a specified plugin.")
|
||||||
public void onReloadPlugin(CommandSender sender, String pluginName) {
|
public void onReloadPlugin(CommandSender sender, String pluginName) {
|
||||||
if (pluginName.equalsIgnoreCase("ServerUtils")) {
|
// 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();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result result = BungeePluginManager.get().reloadPlugin(pluginName);
|
String msg = (String) section.get(result.toLowerCase());
|
||||||
result.sendTo(BungeeUtils.wrap(sender), "reload", pluginName);
|
if (msg != null && !msg.isEmpty()) {
|
||||||
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', utils.convertHexString(
|
||||||
|
msg.replace("%action%", "reload").replace("%what%", pluginName))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.common.config.YamlConfig;
|
import net.frankheijden.serverutils.common.config.YamlConfig;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
|
@ -38,6 +40,21 @@ public class BungeeYamlConfig implements YamlConfig {
|
||||||
return obj;
|
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
|
@Override
|
||||||
public void set(String path, Object value) {
|
public void set(String path, Object value) {
|
||||||
config.set(path, value);
|
config.set(path, value);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package net.frankheijden.serverutils.common.config;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrap for a Yaml Configuration file.
|
* A wrap for a Yaml Configuration file.
|
||||||
|
|
@ -15,6 +16,13 @@ public interface YamlConfig {
|
||||||
*/
|
*/
|
||||||
Object get(String path);
|
Object get(String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a map with key/values for the path specified.
|
||||||
|
* @param path The path.
|
||||||
|
* @return The map object with key/values.
|
||||||
|
*/
|
||||||
|
Map<String, Object> getMap(String path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a value to a path.
|
* Sets a value to a path.
|
||||||
* @param path The path.
|
* @param path The path.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue