Add PluginInfo command

- /su plugininfo will show info about the plugin
- Added dynamic messages.yml for better updating
This commit is contained in:
Frank van der Heijden 2020-06-07 16:54:50 +02:00
parent d60c34ddf1
commit 58a8e9304c
No known key found for this signature in database
GPG key ID: 26DA56488D314D11
7 changed files with 219 additions and 28 deletions

View file

@ -6,9 +6,43 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
public class Messenger {
private static final Defaults DEFAULT_MESSAGES;
static {
DEFAULT_MESSAGES = Defaults.of(
"serverutils", Defaults.of(
"success", "&3Successfully %action%ed &b%what%&3!",
"warning", "&3Successfully %action%ed &b%what%&3, but with warnings.",
"error", "&cAn error occurred while %action%ing &4%what%&c, please check the console!",
"not_exists", "&cAn error occurred while %action%ing &4%what%&c, plugin does not exist!",
"already_enabled", "&cAn error occurred while %action%ing &4%what%&c, plugin is already enabled!",
"help", Defaults.of(
"header", "&8&m-------------=&r&8[ &b&lServerUtils Help&r &8]&m=---------------",
"format", "&8/&3%command%&b%subcommand% &f(&7%help%&f)",
"footer", "&8&m-------------------------------------------------"
),
"plugins", Defaults.of(
"header", "&8&m------------=&r&8[ &b&lServerUtils Plugins&r &8]&m=-------------",
"format", "&3%plugin%",
"seperator", "&b, ",
"last_seperator", " &band ",
"version", " &8(&a%version%&8)",
"footer", "&8&m-------------------------------------------------"
),
"plugininfo", Defaults.of(
"header", "&8&m-----------=&r&8[ &b&lServerUtils PluginInfo&r &8]&m=-----------",
"format", " &3%key%&8: &b%value%",
"seperator", "&8, ",
"last_seperator", " &8and ",
"footer", "&8&m-------------------------------------------------"
)
)
);
}
private static final ServerUtils plugin = ServerUtils.getInstance();
private static Messenger instance;
private final YamlConfiguration messages;
@ -16,6 +50,18 @@ public class Messenger {
public Messenger(File file) {
instance = this;
messages = YamlConfiguration.loadConfiguration(file);
Defaults.addDefaults(DEFAULT_MESSAGES, messages);
try {
// Idk somehow the order messes up
// of the messages if we don't do this
file.delete();
file.createNewFile();
messages.save(file);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static String getMessage(String path, String... replacements) {
@ -36,6 +82,13 @@ public class Messenger {
return message;
}
public static void sendRawMessage(CommandSender sender, String msg, String... replacements) {
String message = apply(msg, replacements);
if (message != null) {
sender.sendMessage(color(message));
}
}
public static void sendMessage(CommandSender sender, String path, String... replacements) {
String message = getMessage(path, replacements);
if (message != null) {