diff --git a/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java b/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java index d4f3c58..9161b60 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java +++ b/src/io/github/norbipeti/thebuttonmcchat/PlayerListener.java @@ -246,7 +246,7 @@ public class PlayerListener implements Listener { @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - if (event.isCancelled()) // TODO: Change FactionChat to /tellraw + if (event.isCancelled()) return; event.setCancelled(ChatProcessing.ProcessChat(event.getPlayer(), event.getMessage())); diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/CommandCaller.java b/src/io/github/norbipeti/thebuttonmcchat/commands/CommandCaller.java index 4ad27fb..1cd6879 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/CommandCaller.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/CommandCaller.java @@ -3,6 +3,7 @@ package io.github.norbipeti.thebuttonmcchat.commands; import io.github.norbipeti.thebuttonmcchat.PluginMain; import java.lang.reflect.Modifier; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Set; @@ -87,7 +88,7 @@ public class CommandCaller implements CommandExecutor { TBMCCommandBase cmd = commands.get(path); int argc = 0; while (cmd == null && path.contains("/")) { - path = path.substring(0, path.indexOf('/')); + path = path.substring(0, path.lastIndexOf('/')); argc++; cmd = commands.get(path); System.out.println(path); @@ -100,12 +101,31 @@ public class CommandCaller implements CommandExecutor { "§cInternal error: Command not registered to CommandCaller"); return true; } + if (cmd.GetPlayerOnly() && sender == Bukkit.getConsoleSender()) { + sender.sendMessage("§cOnly ingame players can use this command."); + return true; + } if (!cmd.OnCommand( sender, alias, - (args.length > 0 ? Arrays.copyOfRange(args, argc, - args.length - 1) : args))) + (args.length > 0 ? Arrays.copyOfRange(args, args.length - argc, + args.length) : args))) sender.sendMessage(cmd.GetHelpText(alias)); return true; } + + public static String[] GetSubCommands(TBMCCommandBase command) { + ArrayList cmds = new ArrayList(); + cmds.add("§6---- Subcommands ----"); + for (TBMCCommandBase cmd : CommandCaller.GetCommands().values()) { + if (cmd.GetCommandPath().startsWith(command.GetCommandPath() + "/")) { + int ind = cmd.GetCommandPath().indexOf('/', + command.GetCommandPath().length() + 2); + if (ind >= 0) + continue; + cmds.add(cmd.GetCommandPath().replace('/', ' ')); + } + } + return cmds.toArray(new String[cmds.size()]); + } } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java index 192651d..3674973 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/HelpCommand.java @@ -21,7 +21,7 @@ public final class HelpCommand extends UCommandBase { sender.sendMessage(new String[] { "§6---- TBMC Help ----", "Do /u help for more info", - "Alternatively, you can do /u help [subcommands] for more info about a command", + "Do /u help [subcommands] for more info about a command", "Topics:", "flairs: The flairs are the numbers near your name", "commands: See all the commands from this plugin", @@ -32,12 +32,11 @@ public final class HelpCommand extends UCommandBase { sender.sendMessage(new String[] { "§6---- About flairs ----", "" }); // TODO else if (args[0].equalsIgnoreCase("commands")) { ArrayList text = new ArrayList(); - int i = 0; - text.set(i++, "§6---- Command list ----"); + text.add("§6---- Command list ----"); for (TBMCCommandBase cmd : CommandCaller.GetCommands().values()) if (!cmd.GetCommandPath().contains("/")) - text.set(i++, "/" + cmd.GetCommandPath()); - sender.sendMessage((String[]) text.toArray()); + text.add("/" + cmd.GetCommandPath()); + sender.sendMessage(text.toArray(new String[text.size()])); } else { String path = args[0]; for (int i = 1; i < args.length; i++) @@ -57,4 +56,9 @@ public final class HelpCommand extends UCommandBase { public String GetUCommandPath() { return "help"; } + + @Override + public boolean GetPlayerOnly() { + return false; + } } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java index 41782b1..824bc18 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommand.java @@ -1,5 +1,8 @@ package io.github.norbipeti.thebuttonmcchat.commands.ucmds; +import java.util.ArrayList; + +import io.github.norbipeti.thebuttonmcchat.commands.CommandCaller; import io.github.norbipeti.thebuttonmcchat.commands.TBMCCommandBase; import org.bukkit.command.CommandSender; @@ -8,8 +11,7 @@ public final class UCommand extends TBMCCommandBase { @Override public String[] GetHelpText(String alias) { - return new String[] { "§6---- U commands ----", - "Subcommands: help, accept, ignore, admin" }; // TODO + return CommandCaller.GetSubCommands(this); } @Override diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java index a415543..0a80582 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/UCommandBase.java @@ -8,10 +8,10 @@ public abstract class UCommandBase extends TBMCCommandBase { @Override public String GetCommandPath() { - return "u/" + GetUCommandPath(); //TODO: This for others + return "u/" + GetUCommandPath(); } - public abstract String GetUCommandPath(); // TODO: Help for /u commands + public abstract String GetUCommandPath(); @Override public boolean GetPlayerOnly() { 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 ab572c4..ad69146 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommand.java @@ -1,5 +1,6 @@ package io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin; +import io.github.norbipeti.thebuttonmcchat.commands.CommandCaller; import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommandBase; import org.bukkit.command.CommandSender; @@ -8,13 +9,11 @@ public final class AdminCommand extends UCommandBase { @Override public String[] GetHelpText(String alias) { - return new String[] { "§6---- Admin ----", - "These commands are for mods only.", "Subcommands: reload, " }; // TODO + return CommandCaller.GetSubCommands(this); } @Override - public boolean OnCommand(CommandSender sender, String alias, - String[] args) { + public boolean OnCommand(CommandSender sender, String alias, String[] args) { return false; } @@ -22,4 +21,9 @@ public final class AdminCommand extends UCommandBase { public String GetUCommandPath() { return "admin"; } + + @Override + public boolean GetPlayerOnly() { + 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 48cd973..aaf3f58 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/admin/AdminCommandBase.java @@ -4,7 +4,7 @@ import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommandBase; public abstract class AdminCommandBase extends UCommandBase { - public abstract String[] GetHelpText(String alias); + public abstract String[] GetHelpText(String alias); //TODO: Require permissionű @Override public String GetUCommandPath() { diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommand.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommand.java index f55ef0e..8cc5f7b 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommand.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommand.java @@ -1,5 +1,6 @@ package io.github.norbipeti.thebuttonmcchat.commands.ucmds.announce; +import io.github.norbipeti.thebuttonmcchat.commands.CommandCaller; import io.github.norbipeti.thebuttonmcchat.commands.ucmds.UCommandBase; import org.bukkit.command.CommandSender; @@ -8,8 +9,7 @@ public class AnnounceCommand extends UCommandBase { @Override public String[] GetHelpText(String alias) { - return new String[] { "§6---- Announce ----", - "Subcommands: add, settime, remove, list, edit" }; // TODO + return CommandCaller.GetSubCommands(this); } @Override @@ -22,4 +22,8 @@ public class AnnounceCommand extends UCommandBase { return "announce"; } + @Override + public boolean GetPlayerOnly() { + return false; + } } diff --git a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommandBase.java b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommandBase.java index 698d1ae..e8ae923 100644 --- a/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommandBase.java +++ b/src/io/github/norbipeti/thebuttonmcchat/commands/ucmds/announce/AnnounceCommandBase.java @@ -8,9 +8,13 @@ public abstract class AnnounceCommandBase extends UCommandBase { @Override public String GetUCommandPath() { - return "announce"; + return "announce/" + GetAnnounceCommandPath(); } public abstract String GetAnnounceCommandPath(); + @Override + public boolean GetPlayerOnly() { + return false; + } }