Connected standard command handler getCommand("f"), for it to work with other plugins which directly execute commands using that interface.
This commit is contained in:
parent
2c6191b73f
commit
c0308940c8
@ -2,16 +2,18 @@ package com.massivecraft.factions;
|
|||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import com.massivecraft.factions.adapters.FFlagTypeAdapter;
|
import com.massivecraft.factions.adapters.FFlagTypeAdapter;
|
||||||
import com.massivecraft.factions.adapters.FLocToStringSetTypeAdapter;
|
import com.massivecraft.factions.adapters.FLocToStringSetTypeAdapter;
|
||||||
@ -36,6 +38,7 @@ import com.massivecraft.factions.struct.FPerm;
|
|||||||
import com.massivecraft.factions.struct.Rel;
|
import com.massivecraft.factions.struct.Rel;
|
||||||
import com.massivecraft.factions.util.AutoLeaveTask;
|
import com.massivecraft.factions.util.AutoLeaveTask;
|
||||||
import com.massivecraft.factions.zcore.MPlugin;
|
import com.massivecraft.factions.zcore.MPlugin;
|
||||||
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
@ -112,6 +115,9 @@ public class P extends MPlugin
|
|||||||
getServer().getPluginManager().registerEvents(blockListener, this);
|
getServer().getPluginManager().registerEvents(blockListener, this);
|
||||||
getServer().getPluginManager().registerEvents(serverListener, this);
|
getServer().getPluginManager().registerEvents(serverListener, this);
|
||||||
|
|
||||||
|
// since some other plugins execute commands directly through this command interface, provide it
|
||||||
|
this.getCommand(this.refCommand).setExecutor(this);
|
||||||
|
|
||||||
postEnable();
|
postEnable();
|
||||||
this.loadSuccessful = true;
|
this.loadSuccessful = true;
|
||||||
}
|
}
|
||||||
@ -186,6 +192,17 @@ public class P extends MPlugin
|
|||||||
return super.handleCommand(sender, commandString, testOnly);
|
return super.handleCommand(sender, commandString, testOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] split)
|
||||||
|
{
|
||||||
|
// if bare command at this point, it has already been handled by MPlugin's command listeners
|
||||||
|
if (split == null || split.length == 0) return true;
|
||||||
|
|
||||||
|
// otherwise, needs to be handled; presumably another plugin directly ran the command
|
||||||
|
String cmd = Conf.baseCommandAliases.isEmpty() ? "/f" : "/" + Conf.baseCommandAliases.get(0);
|
||||||
|
return handleCommand(sender, cmd + " " + TextUtil.implode(Arrays.asList(split), " "), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -36,6 +36,7 @@ public abstract class MPlugin extends JavaPlugin
|
|||||||
protected boolean loadSuccessful = false;
|
protected boolean loadSuccessful = false;
|
||||||
public boolean getAutoSave() {return this.autoSave;}
|
public boolean getAutoSave() {return this.autoSave;}
|
||||||
public void setAutoSave(boolean val) {this.autoSave = val;}
|
public void setAutoSave(boolean val) {this.autoSave = val;}
|
||||||
|
public String refCommand = "";
|
||||||
|
|
||||||
// Listeners
|
// Listeners
|
||||||
private MPluginSecretPlayerListener mPluginSecretPlayerListener;
|
private MPluginSecretPlayerListener mPluginSecretPlayerListener;
|
||||||
@ -69,6 +70,16 @@ public abstract class MPlugin extends JavaPlugin
|
|||||||
this.txt = new TextUtil();
|
this.txt = new TextUtil();
|
||||||
initTXT();
|
initTXT();
|
||||||
|
|
||||||
|
// 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, Map<String, Object>> refCmd = this.getDescription().getCommands();
|
||||||
|
if (refCmd != null && !refCmd.isEmpty())
|
||||||
|
this.refCommand = (String)(refCmd.keySet().toArray()[0]);
|
||||||
|
}
|
||||||
|
catch (ClassCastException ex) {}
|
||||||
|
|
||||||
// Create and register listeners
|
// Create and register listeners
|
||||||
this.mPluginSecretPlayerListener = new MPluginSecretPlayerListener(this);
|
this.mPluginSecretPlayerListener = new MPluginSecretPlayerListener(this);
|
||||||
this.mPluginSecretServerListener = new MPluginSecretServerListener(this);
|
this.mPluginSecretServerListener = new MPluginSecretServerListener(this);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.massivecraft.factions.zcore;
|
package com.massivecraft.factions.zcore;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -10,22 +8,10 @@ import org.bukkit.event.server.ServerCommandEvent;
|
|||||||
public class MPluginSecretServerListener implements Listener
|
public class MPluginSecretServerListener implements Listener
|
||||||
{
|
{
|
||||||
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, Map<String, Object>> refCmd = p.getDescription().getCommands();
|
|
||||||
if (refCmd != null && !refCmd.isEmpty())
|
|
||||||
refCommand = (String)(refCmd.keySet().toArray()[0]);
|
|
||||||
}
|
|
||||||
catch (ClassCastException ex) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
@ -35,7 +21,7 @@ public class MPluginSecretServerListener implements Listener
|
|||||||
|
|
||||||
if (p.handleCommand(event.getSender(), event.getCommand()))
|
if (p.handleCommand(event.getSender(), event.getCommand()))
|
||||||
{
|
{
|
||||||
event.setCommand(refCommand);
|
event.setCommand(p.refCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user