diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ChatonlyCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ChatonlyCommand.java index 69f4e43..5bd0c9e 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ChatonlyCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ChatonlyCommand.java @@ -30,7 +30,7 @@ public final class ChatonlyCommand extends TBMCCommandBase { } @Override - public String GetCommandName() { + public String GetCommandPath() { return "chatonly"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/CommandCaller.java b/src/io/github/norbipeti/thebuttonmcchat/commands/CommandCaller.java index 6dbc5d3..76f0e91 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/CommandCaller.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/CommandCaller.java @@ -2,6 +2,7 @@ package io.github.norbipeti.thebuttonmcchat.commands; import io.github.norbipeti.thebuttonmcchat.PluginMain; +import java.util.Arrays; import java.util.HashMap; import java.util.Set; @@ -12,13 +13,10 @@ import org.bukkit.command.CommandSender; import org.reflections.Reflections; public class CommandCaller implements CommandExecutor { - private CommandCaller() { - } private static HashMap commands = new HashMap(); - private static HashMap subcommands = new HashMap(); - public static void RegisterCommands(PluginMain plugin) { + public void RegisterCommands(PluginMain plugin) { System.out.println("Registering commands..."); Reflections rf = new Reflections( "io.github.norbipeti.thebuttonmcchat.commands"); @@ -27,28 +25,14 @@ public class CommandCaller implements CommandExecutor { for (Class cmd : cmds) { try { TBMCCommandBase c = cmd.newInstance(); - commands.put(c.GetCommandName(), c); - plugin.getCommand(c.GetCommandName()).setExecutor(c); + commands.put(c.GetCommandPath(), c); + plugin.getCommand(c.GetCommandPath()).setExecutor(this); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } - System.out.println("Registering subcommands..."); - Set> subcmds = rf - .getSubTypesOf(TBMCSubCommandBase.class); - for (Class subcmd : subcmds) { - try { - TBMCSubCommandBase sc = subcmd.newInstance(); - subcommands.put(sc.GetCommandPath(), sc); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - System.out.println("Done registering"); } @Override @@ -60,17 +44,23 @@ public class CommandCaller implements CommandExecutor { String path = command.getName(); for (String arg : args) path += "/" + arg; - TBMCSubCommandBase cmd = subcommands.get(path); - while (cmd == null && path.contains("/")) + TBMCCommandBase cmd = commands.get(path); + int argc = 0; + while (cmd == null && path.contains("/")) { path = path.substring(0, path.indexOf('/')); + argc++; + cmd = commands.get(path); + } if (cmd == null) { - sender.sendMessage("§cInternal error: Subcommand not registered to CommandCaller"); + sender.sendMessage("§cInternal error: Command not registered to CommandCaller"); if (sender != Bukkit.getConsoleSender()) Bukkit.getConsoleSender() .sendMessage( - "§cInternal error: Subcommand not registered to CommandCaller"); + "§cInternal error: Command not registered to CommandCaller"); return true; } + cmd.OnCommand(sender, alias, + Arrays.copyOfRange(args, argc, args.length - 1)); return true; } } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/MWikiCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/MWikiCommand.java index 2799b1d..1226fa8 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/MWikiCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/MWikiCommand.java @@ -30,7 +30,7 @@ public class MWikiCommand extends TBMCCommandBase { } @Override - public String GetCommandName() { + public String GetCommandPath() { return "mwiki"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/OOCCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/OOCCommand.java index 3b00481..446d7ee 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/OOCCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/OOCCommand.java @@ -32,7 +32,7 @@ public final class OOCCommand extends TBMCCommandBase { } @Override - public String GetCommandName() { + public String GetCommandPath() { return "ooc"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/UnlolCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/UnlolCommand.java index 2121400..d66da4e 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/UnlolCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/UnlolCommand.java @@ -42,7 +42,7 @@ public final class UnlolCommand extends TBMCCommandBase { } @Override - public String GetCommandName() { + public String GetCommandPath() { return "unlol"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/YeehawCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/YeehawCommand.java index fca74cb..35739e0 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/YeehawCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/YeehawCommand.java @@ -25,7 +25,7 @@ public class YeehawCommand extends TBMCCommandBase { } @Override - public String GetCommandName() { + public String GetCommandPath() { return "yeehaw"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/AppendTextCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/AppendTextCommandBase.java index 67061db..8d80daa 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/AppendTextCommandBase.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/AppendTextCommandBase.java @@ -20,8 +20,6 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase { return true; } - public abstract String GetCommandName(); - @Override public boolean GetPlayerOnly() { return false; diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/ShrugCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/ShrugCommand.java index 8460d38..8fc8475 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/ShrugCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/ShrugCommand.java @@ -16,7 +16,7 @@ public final class ShrugCommand extends AppendTextCommandBase { } @Override - public String GetCommandName() { + public String GetCommandPath() { return "shrug"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/TableflipCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/TableflipCommand.java index 6f81d21..5b73c23 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/TableflipCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/TableflipCommand.java @@ -16,7 +16,7 @@ public final class TableflipCommand extends AppendTextCommandBase { } @Override - public String GetCommandName() { + public String GetCommandPath() { return "tableflip"; } } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/UnflipCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/UnflipCommand.java index 259021b..df51f16 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/UnflipCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/appendtext/UnflipCommand.java @@ -16,7 +16,7 @@ public final class UnflipCommand extends AppendTextCommandBase { } @Override - public String GetCommandName() { + public String GetCommandPath() { return "unflip"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/AcceptCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/AcceptCommand.java index 7844921..16189da 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/AcceptCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/AcceptCommand.java @@ -20,7 +20,7 @@ public class AcceptCommand extends UCommandBase { } @Override - public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { final Player player = (Player) sender; MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromPlayer(player); if (args.length < 1 && p.UserNames.size() > 1) { @@ -88,7 +88,7 @@ public class AcceptCommand extends UCommandBase { } @Override - public String GetUCommandName() { + public String GetUCommandPath() { return "accept"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/CCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/CCommand.java index ea3b011..881d1a5 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/CCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/CCommand.java @@ -16,7 +16,7 @@ public class CCommand extends UCommandBase { } @Override - public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { Player player = (Player) sender; MaybeOfflinePlayer p = MaybeOfflinePlayer.AddPlayerIfNeeded(player .getUniqueId()); @@ -50,7 +50,7 @@ public class CCommand extends UCommandBase { } @Override - public String GetUCommandName() { + public String GetUCommandPath() { return "c"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java index 15367e4..65de68f 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java @@ -13,7 +13,7 @@ public final class HelpCommand extends UCommandBase { } @Override - public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { if (args.length == 0) { sender.sendMessage(new String[] { "§6---- TBMC Help ----", @@ -47,7 +47,7 @@ public final class HelpCommand extends UCommandBase { } @Override - public String GetUCommandName() { + public String GetUCommandPath() { return "help"; } } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/IgnoreCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/IgnoreCommand.java index 93fcf64..5764972 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/IgnoreCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/IgnoreCommand.java @@ -17,7 +17,7 @@ public final class IgnoreCommand extends UCommandBase { } @Override - public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { final Player player = (Player) sender; MaybeOfflinePlayer p = MaybeOfflinePlayer.GetFromPlayer(player); if (p.FlairState.equals(FlairStates.Accepted)) { @@ -39,7 +39,7 @@ public final class IgnoreCommand extends UCommandBase { } @Override - public String GetUCommandName() { + public String GetUCommandPath() { return "ignore"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/KittycannonCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/KittycannonCommand.java index 29c91e4..3ef4015 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/KittycannonCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/KittycannonCommand.java @@ -35,7 +35,7 @@ public class KittycannonCommand extends UCommandBase { } @Override - public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { Player player = (Player) sender; MinigamePlayer mp = Minigames.plugin.pdata.getMinigamePlayer(player); if (!(mp.isInMinigame() && mp.getMinigame().getName(false) @@ -84,7 +84,7 @@ public class KittycannonCommand extends UCommandBase { } @Override - public String GetUCommandName() { + public String GetUCommandPath() { return "kittycannon"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/NameCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/NameCommand.java index 13e676f..4b617f0 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/NameCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/NameCommand.java @@ -15,7 +15,7 @@ public class NameCommand extends UCommandBase { } @Override - public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { if (args.length == 1) { return false; } @@ -30,7 +30,7 @@ public class NameCommand extends UCommandBase { } @Override - public String GetUCommandName() { + public String GetUCommandPath() { return "name"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/OpmeCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/OpmeCommand.java index f5dd5af..11f22c9 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/OpmeCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/OpmeCommand.java @@ -10,13 +10,13 @@ public class OpmeCommand extends UCommandBase { } @Override - public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { sender.sendMessage("It would be nice, wouldn't it?"); return true; } @Override - public String GetUCommandName() { + public String GetUCommandPath() { return "opme"; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java index 8901839..234bd1e 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java @@ -9,16 +9,16 @@ public final class UCommand extends UCommandBase { @Override public String[] GetHelpText(String alias) { return new String[] { "§6---- U commands ----", - "Subcommands: help, accept, ignore, admin" }; + "Subcommands: help, accept, ignore, admin" }; //TODO } @Override - public boolean OnUCommand(CommandSender sender, String alias, String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { return false; } @Override - public String GetUCommandName() { + public String GetUCommandPath() { return "u"; // TODO: Same as at AdminCommand } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java index 5f0e631..25d22e4 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java @@ -5,7 +5,6 @@ import java.util.Arrays; import org.bukkit.command.CommandSender; import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; -import io.github.norbipeti.thebuttonmcchat.commands.TBMCSubCommandBase; public abstract class UCommandBase extends TBMCCommandBase { @@ -13,7 +12,9 @@ public abstract class UCommandBase extends TBMCCommandBase { @Override public String GetCommandPath() { - return "u/" + GetUCommandPath(); + if (GetUCommandPath().equals("u")) + return "u"; + return "u/" + GetUCommandPath(); //TODO: This for others } public abstract String GetUCommandPath(); // TODO: Help for /u commands diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java index eeaa2fd..2f6ca72 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java @@ -11,7 +11,7 @@ public final class AdminCommand extends AdminCommandBase { } @Override - public boolean OnAdminCommand(CommandSender sender, String alias, + public boolean OnCommand(CommandSender sender, String alias, String[] args) { return false; } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java index 5155f6a..4c9c357 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java @@ -11,27 +11,10 @@ public abstract class AdminCommandBase extends UCommandBase { public abstract String[] GetHelpText(String alias); @Override - public boolean OnUCommand(CommandSender sender, String alias, String[] args) { // TODO: - // Only - // mods/admins - // should - // be - // able - // to - // use - // these - if (args.length == 0) - return false; - return OnAdminCommand(sender, alias, - Arrays.copyOfRange(args, 1, args.length)); - } - - public abstract boolean OnAdminCommand(CommandSender sender, String alias, - String[] args); // TODO: Actually call subcommands - - @Override - public String GetUCommandName() { - return "admin"; + public String GetUCommandPath() { + if (GetAdminCommandName().equals("admin")) + return "admin"; + return "admin/" + GetAdminCommandName(); } @Override diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java index 63f2218..aed4aa5 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/ConfirmCommand.java @@ -13,8 +13,7 @@ public class ConfirmCommand extends AdminCommandBase { } @Override - public boolean OnAdminCommand(CommandSender sender, String alias, - String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { if (ReloadCommand.Reloader == sender) { try { if (sender != PluginMain.Console)