Fix for Bukkit "unknown command" error when using console commands

handling for extra commas in "baseCommandAliases" in conf.json adding null values
This commit is contained in:
Brettflan 2011-10-16 04:02:29 -05:00
parent 61bd37c99b
commit f5450886f1
3 changed files with 23 additions and 2 deletions

View File

@ -3,6 +3,10 @@ version: 1.6.0_dev
main: com.massivecraft.factions.P main: com.massivecraft.factions.P
authors: [Olof Larsson, Brett Flannigan] authors: [Olof Larsson, Brett Flannigan]
softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, nChat, ChatManager, CAPI, AuthMe, Register, Spout, WorldEdit, WorldGuard] 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: permissions:
factions.kit.admin: factions.kit.admin:
description: All faction permissions. description: All faction permissions.

View File

@ -1,5 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import java.util.Collections;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
public class FCmdRoot extends FCommand public class FCmdRoot extends FCommand
@ -55,6 +57,7 @@ public class FCmdRoot extends FCommand
{ {
super(); super();
this.aliases.addAll(Conf.baseCommandAliases); this.aliases.addAll(Conf.baseCommandAliases);
this.aliases.removeAll(Collections.singletonList(null)); // remove any nulls from extra commas
this.allowNoSlashAccess = Conf.allowNoSlashCommand; this.allowNoSlashAccess = Conf.allowNoSlashCommand;
//this.requiredArgs.add(""); //this.requiredArgs.add("");

View File

@ -1,17 +1,31 @@
package com.massivecraft.factions.zcore; package com.massivecraft.factions.zcore;
import java.util.Map;
import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.event.server.ServerListener; import org.bukkit.event.server.ServerListener;
public class MPluginSecretServerListener extends ServerListener public class MPluginSecretServerListener extends ServerListener
{ {
private MPlugin p; private MPlugin p;
private String refCommand;
public MPluginSecretServerListener(MPlugin p) public MPluginSecretServerListener(MPlugin p)
{ {
this.p = 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<String, Object> refCmd = (Map<String, Object>) 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 @Override
public void onServerCommand(ServerCommandEvent event) public void onServerCommand(ServerCommandEvent event)
{ {
@ -19,7 +33,7 @@ public class MPluginSecretServerListener extends ServerListener
if (p.handleCommand(event.getSender(), event.getCommand())) if (p.handleCommand(event.getSender(), event.getCommand()))
{ {
event.setCommand(""); event.setCommand(refCommand);
} }
} }