From bc915af13ebf37222ad210bdb56f8b4c20f600e8 Mon Sep 17 00:00:00 2001 From: extendedclip Date: Fri, 29 Jun 2018 15:03:53 -0400 Subject: [PATCH] Added subcommand to register an expansion by specifying the name of the file, or unregistering by specifying the name of the expansion. --- .../commands/PlaceholderAPICommands.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/java/me/clip/placeholderapi/commands/PlaceholderAPICommands.java b/src/main/java/me/clip/placeholderapi/commands/PlaceholderAPICommands.java index 1ad6038..0fe6e85 100644 --- a/src/main/java/me/clip/placeholderapi/commands/PlaceholderAPICommands.java +++ b/src/main/java/me/clip/placeholderapi/commands/PlaceholderAPICommands.java @@ -67,6 +67,10 @@ public class PlaceholderAPICommands implements CommandExecutor { "&fParse a String with placeholders and broadcast the message", "&b/papi parserel <...args>", "&fParse a String with relational placeholders", + "&b/papi register ", + "&fRegister an expansion by the name of the file", + "&b/papi unregister ", + "&fUnregister an expansion by name", "&b/papi reload", "&fReload the config settings"); if (s.hasPermission("placeholderapi.ecloud")) { @@ -232,6 +236,46 @@ public class PlaceholderAPICommands implements CommandExecutor { } Msg.msg(s, registered.size() + " &7Placeholder hooks registered:"); Msg.msg(s, registered.toString()); + } else if (args.length > 1 && args[0].equalsIgnoreCase("register")) { + + if (s instanceof Player) { + if (!s.hasPermission("placeholderapi.register")) { + Msg.msg(s, "&cYou don't have permission to do that!"); + return true; + } + } + + String fileName = args[1].replace(".jar", ""); + PlaceholderExpansion ex = plugin.getExpansionManager().registerExpansion(fileName); + + if (ex == null) { + Msg.msg(s, "&cFailed to register expansion from " + fileName); + return true; + } + + Msg.msg(s, "&aSuccessfully registered expansion: &f" + ex.getName()); + } else if (args.length > 1 && args[0].equalsIgnoreCase("unregister")) { + + if (s instanceof Player) { + if (!s.hasPermission("placeholderapi.register")) { + Msg.msg(s, "&cYou don't have permission to do that!"); + return true; + } + } + + PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]); + + if (ex == null) { + Msg.msg(s, "&cFailed to find expansion: &f" + args[1]); + return true; + } + + if (PlaceholderAPI.unregisterExpansion(ex)) { + Msg.msg(s, "&aSuccessfully unregistered expansion: &f" + ex.getName()); + } else { + Msg.msg(s, "&cFailed to unregister expansion: &f" + ex.getName()); + } + } else { Msg.msg(s, "&cIncorrect usage! &7/papi help"); }