diff --git a/pom.xml b/pom.xml
index e161fac..3676631 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,7 +48,6 @@
net.sourceforge.htmlcleaner:htmlcleaner
- org.reflections:reflections
org.javassist:javassist
diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java
index afc7d11..eb20145 100644
--- a/src/main/java/buttondevteam/chat/PluginMain.java
+++ b/src/main/java/buttondevteam/chat/PluginMain.java
@@ -14,7 +14,6 @@ import org.bukkit.scoreboard.Scoreboard;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
-import buttondevteam.chat.commands.CommandCaller;
import buttondevteam.chat.commands.YeehawCommand;
import buttondevteam.chat.listener.PlayerListener;
import buttondevteam.lib.TBMCCoreAPI;
@@ -105,7 +104,6 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
};
t = new Thread(r);
t.start();
- Bukkit.getScheduler().runTaskLater(this, () -> CommandCaller.RegisterCommands(), 0);
}
public Boolean stop = false;
diff --git a/src/main/java/buttondevteam/chat/commands/CommandCaller.java b/src/main/java/buttondevteam/chat/commands/CommandCaller.java
deleted file mode 100644
index 12ffd8c..0000000
--- a/src/main/java/buttondevteam/chat/commands/CommandCaller.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package buttondevteam.chat.commands;
-
-import java.util.Arrays;
-import java.util.Map.Entry;
-
-import org.bukkit.Bukkit;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.command.PluginCommand;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.java.JavaPlugin;
-import buttondevteam.chat.PluginMain;
-import buttondevteam.lib.TBMCCoreAPI;
-import buttondevteam.lib.chat.TBMCChatAPI;
-import buttondevteam.lib.chat.TBMCCommandBase;
-
-public class CommandCaller implements CommandExecutor {
-
- private static final String REGISTER_ERROR_MSG = "An error occured while registering commands";
-
- private CommandCaller() {
- }
-
- private static CommandCaller instance;
-
- public static void RegisterCommands() {
- if (instance == null)
- instance = new CommandCaller();
- for (Entry entry : TBMCChatAPI.GetCommands().entrySet()) {
- TBMCCommandBase c = entry.getValue();
- if (c == null) {
- TBMCCoreAPI.SendException(REGISTER_ERROR_MSG,
- new Exception("Null command found at " + entry.getKey() + "!"));
- continue;
- }
- if (c.GetCommandPath() == null) {
- TBMCCoreAPI.SendException(REGISTER_ERROR_MSG,
- new Exception("Command " + entry.getKey() + " has no command path!"));
- continue;
- }
- if (c.getPlugin() == null) {
- TBMCCoreAPI.SendException(REGISTER_ERROR_MSG,
- new Exception("Command " + entry.getKey() + " has no plugin!"));
- continue;
- }
- int i;
- String topcmd;
- if ((i = (topcmd = c.GetCommandPath()).indexOf(' ')) != -1) // Get top-level command
- topcmd = c.GetCommandPath().substring(0, i);
- {
- PluginCommand pc = ((JavaPlugin) c.getPlugin()).getCommand(topcmd);
- if (pc == null)
- TBMCCoreAPI.SendException(REGISTER_ERROR_MSG, new Exception("Top level command " + topcmd
- + " not registered in plugin.yml for plugin: " + c.getPlugin().getName()));
- else
- pc.setExecutor(instance);
- }
- }
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
- String path = command.getName().toLowerCase();
- for (String arg : args)
- path += " " + arg;
- TBMCCommandBase cmd = TBMCChatAPI.GetCommands().get(path);
- int argc = 0;
- while (cmd == null && path.contains(" ")) {
- path = path.substring(0, path.lastIndexOf(' '));
- argc++;
- cmd = TBMCChatAPI.GetCommands().get(path);
- }
- if (cmd == null) {
- String[] subcmds = TBMCChatAPI.GetSubCommands(path, sender);
- if (subcmds.length > 0)
- sender.sendMessage(subcmds);
- else {
- final String errormsg = "§cYou don't have access to any of this command's subcommands.";
- sender.sendMessage(errormsg);
- if (!(sender instanceof ConsoleCommandSender))
- Bukkit.getConsoleSender().sendMessage(errormsg);
- }
- return true;
- }
- if (cmd.GetModOnly() && !PluginMain.permission.has(sender, "tbmc.admin")) {
- sender.sendMessage("§cYou need to be a mod to use this command.");
- return true;
- }
- if (cmd.GetPlayerOnly() && !(sender instanceof Player)) {
- sender.sendMessage("§cOnly ingame players can use this command.");
- return true;
- }
- final String[] cmdargs = args.length > 0 ? Arrays.copyOfRange(args, args.length - argc, args.length) : args;
- try {
- if (!cmd.OnCommand(sender, alias, cmdargs)) {
- if (cmd.GetHelpText(alias) == null) {
- sender.sendMessage("Wrong usage, but there's no help text! Error is being reported to devs.");
- throw new NullPointerException("GetHelpText is null for comand /" + cmd.GetCommandPath());
- } else
- sender.sendMessage(cmd.GetHelpText(alias));
- }
- } catch (Exception e) {
- TBMCCoreAPI.SendException("Failed to execute command /" + cmd.GetCommandPath() + " with arguments "
- + Arrays.toString(cmdargs), e);
- }
- return true;
- }
-}
diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java
index ad9874c..a8b697c 100644
--- a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java
+++ b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java
@@ -58,12 +58,16 @@ public final class HelpCommand extends UCommandBase {
} else {
String path = args[0];
for (int i = 1; i < args.length; i++)
- path += "/" + args[i];
+ path += " " + args[i];
TBMCCommandBase cmd = TBMCChatAPI.GetCommands().get(path);
- if (cmd == null)
- sender.sendMessage(new String[] { "§cError: Command not found: " + path.replace('/', ' '),
- "Usage example: /u accept --> /u help u accept" });
- else
+ if (cmd == null) {
+ String[] subcmds = TBMCChatAPI.GetSubCommands(path, sender);
+ if (subcmds.length > 0)
+ sender.sendMessage(subcmds);
+ else
+ sender.sendMessage(new String[] { "§cError: Command not found or you don't have permission for it: " + path,
+ "Usage example: /u accept --> /u help u accept" });
+ } else
sender.sendMessage(cmd.GetHelpText(args[0]));
}
return true;
diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java
index 5297600..1937981 100644
--- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java
+++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java
@@ -66,10 +66,10 @@ public class PlayerListener implements Listener {
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled())
return;
- event.setCancelled(true);
TBMCChatAPI.SendChatMessage(
TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel,
event.getPlayer(), event.getMessage());
+ event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST)