From f5450886f10ce6c75306ac82f91583808ece91bd Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 16 Oct 2011 04:02:29 -0500 Subject: [PATCH] Fix for Bukkit "unknown command" error when using console commands handling for extra commas in "baseCommandAliases" in conf.json adding null values --- plugin.yml | 4 ++++ .../massivecraft/factions/cmd/FCmdRoot.java | 3 +++ .../zcore/MPluginSecretServerListener.java | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/plugin.yml b/plugin.yml index e50c05e5..1a2d9f80 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,6 +3,10 @@ version: 1.6.0_dev main: com.massivecraft.factions.P authors: [Olof Larsson, Brett Flannigan] softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, nChat, ChatManager, CAPI, AuthMe, Register, Spout, WorldEdit, WorldGuard] +commands: + factions: + description: Reference command for Factions. + aliases: [f] permissions: factions.kit.admin: description: All faction permissions. diff --git a/src/com/massivecraft/factions/cmd/FCmdRoot.java b/src/com/massivecraft/factions/cmd/FCmdRoot.java index 8babf412..52e1a22d 100644 --- a/src/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/com/massivecraft/factions/cmd/FCmdRoot.java @@ -1,5 +1,7 @@ package com.massivecraft.factions.cmd; +import java.util.Collections; + import com.massivecraft.factions.Conf; public class FCmdRoot extends FCommand @@ -55,6 +57,7 @@ public class FCmdRoot extends FCommand { super(); this.aliases.addAll(Conf.baseCommandAliases); + this.aliases.removeAll(Collections.singletonList(null)); // remove any nulls from extra commas this.allowNoSlashAccess = Conf.allowNoSlashCommand; //this.requiredArgs.add(""); diff --git a/src/com/massivecraft/factions/zcore/MPluginSecretServerListener.java b/src/com/massivecraft/factions/zcore/MPluginSecretServerListener.java index b51a2ae8..90e62220 100644 --- a/src/com/massivecraft/factions/zcore/MPluginSecretServerListener.java +++ b/src/com/massivecraft/factions/zcore/MPluginSecretServerListener.java @@ -1,17 +1,31 @@ package com.massivecraft.factions.zcore; +import java.util.Map; + import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.event.server.ServerListener; public class MPluginSecretServerListener extends ServerListener { private MPlugin p; + private String refCommand; + public MPluginSecretServerListener(MPlugin p) { this.p = p; + refCommand = ""; + + // attempt to get first command defined in plugin.yml as reference command, if any commands are defined in there + // reference command will be used to prevent "unknown command" console messages + try + { + Map refCmd = (Map) p.getDescription().getCommands(); + if (refCmd != null && !refCmd.isEmpty()) + refCommand = (String)(refCmd.keySet().toArray()[0]); + } + catch (ClassCastException ex) {} } - // This method is not perfect. It says unknown console command. @Override public void onServerCommand(ServerCommandEvent event) { @@ -19,7 +33,7 @@ public class MPluginSecretServerListener extends ServerListener if (p.handleCommand(event.getSender(), event.getCommand())) { - event.setCommand(""); + event.setCommand(refCommand); } }