mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-12-27 20:27:37 +00:00
Give TFM commands priority over other plugins.
This commit is contained in:
parent
fdfa30b349
commit
aad8f17455
@ -1,6 +1,6 @@
|
||||
#Sun, 14 Jul 2013 14:08:44 +0200
|
||||
#Fri, 19 Jul 2013 19:19:28 -0400
|
||||
|
||||
program.VERSION=2.21
|
||||
program.BUILDNUM=311
|
||||
program.BUILDDATE=07/14/2013 02\:08 PM
|
||||
program.BUILDNUM=318
|
||||
program.BUILDDATE=07/19/2013 07\:19 PM
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Sun Jul 14 14:08:44 CEST 2013
|
||||
build.number=312
|
||||
#Fri Jul 19 19:19:28 EDT 2013
|
||||
build.number=319
|
||||
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||
import java.security.CodeSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -23,7 +24,6 @@ import org.bukkit.plugin.Plugin;
|
||||
public class TFM_CommandLoader
|
||||
{
|
||||
public static final Pattern COMMAND_CLASS_PATTERN = Pattern.compile(TotalFreedomMod.COMMAND_PATH.replace('.', '/') + "/(" + TotalFreedomMod.COMMAND_PREFIX + "[^\\$]+)\\.class");
|
||||
public static CommandMap commandMap;
|
||||
private List<TFM_CommandInfo> commandList = null;
|
||||
|
||||
private TFM_CommandLoader()
|
||||
@ -32,10 +32,10 @@ public class TFM_CommandLoader
|
||||
|
||||
public void scan()
|
||||
{
|
||||
commandMap = TFM_Util.getField(Bukkit.getServer().getPluginManager(), "commandMap");
|
||||
CommandMap commandMap = getCommandMap();
|
||||
if (commandMap == null)
|
||||
{
|
||||
TFM_Log.severe("Error loading command map.");
|
||||
TFM_Log.severe("Error loading commandMap.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -59,9 +59,82 @@ public class TFM_CommandLoader
|
||||
description = "OP Command - " + description;
|
||||
break;
|
||||
}
|
||||
|
||||
TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo.getCommandName(), description, commandInfo.getUsage(), commandInfo.getAliases());
|
||||
|
||||
Command existing = commandMap.getCommand(dynamicCommand.getName());
|
||||
if (existing != null)
|
||||
{
|
||||
TFM_Log.info("Replacing command: " + existing.getName());
|
||||
unregisterCommand(existing, commandMap);
|
||||
}
|
||||
|
||||
commandMap.register(TotalFreedomMod.plugin.getDescription().getName(), dynamicCommand);
|
||||
}
|
||||
|
||||
TFM_Log.info("TFM commands loaded.");
|
||||
}
|
||||
|
||||
public void unregisterCommand(String commandName)
|
||||
{
|
||||
CommandMap commandMap = getCommandMap();
|
||||
if (commandMap != null)
|
||||
{
|
||||
Command command = commandMap.getCommand(commandName.toLowerCase());
|
||||
if (command != null)
|
||||
{
|
||||
unregisterCommand(command, commandMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterCommand(Command command, CommandMap commandMap)
|
||||
{
|
||||
try
|
||||
{
|
||||
command.unregister(commandMap);
|
||||
HashMap<String, Command> knownCommands = getKnownCommands(commandMap);
|
||||
if (knownCommands != null)
|
||||
{
|
||||
knownCommands.remove(command.getName());
|
||||
for (String alias : command.getAliases())
|
||||
{
|
||||
knownCommands.remove(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CommandMap getCommandMap()
|
||||
{
|
||||
Object commandMap = TFM_Util.getField(Bukkit.getServer().getPluginManager(), "commandMap");
|
||||
if (commandMap != null)
|
||||
{
|
||||
if (commandMap instanceof CommandMap)
|
||||
{
|
||||
return (CommandMap) commandMap;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public HashMap<String, Command> getKnownCommands(CommandMap commandMap)
|
||||
{
|
||||
Object knownCommands = TFM_Util.getField(commandMap, "knownCommands");
|
||||
if (knownCommands != null)
|
||||
{
|
||||
if (knownCommands instanceof HashMap)
|
||||
{
|
||||
return (HashMap<String, Command>) knownCommands;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static List<TFM_CommandInfo> getCommands()
|
||||
|
@ -26,7 +26,7 @@ public class TFM_CommandBlocker
|
||||
if (!(usedcommand + " ").startsWith(parts[2] + " "))
|
||||
{
|
||||
|
||||
CommandMap commandMap = TFM_CommandLoader.commandMap;
|
||||
CommandMap commandMap = TFM_CommandLoader.getInstance().getCommandMap();
|
||||
if (commandMap == null)
|
||||
{
|
||||
continue;
|
||||
|
@ -106,8 +106,6 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
// Heartbeat
|
||||
server.getScheduler().scheduleSyncRepeatingTask(this, new TFM_Heartbeat(this), HEARTBEAT_RATE * 20L, HEARTBEAT_RATE * 20L);
|
||||
|
||||
TFM_CommandLoader.getInstance().scan();
|
||||
|
||||
// metrics @ http://mcstats.org/plugin/TotalFreedomMod
|
||||
try
|
||||
{
|
||||
@ -120,6 +118,15 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
}
|
||||
|
||||
TFM_Log.info("Plugin Enabled - Version: " + TotalFreedomMod.pluginVersion + "." + TotalFreedomMod.buildNumber + " by Madgeek1450 and DarthSalamon");
|
||||
|
||||
server.getScheduler().runTaskLater(this, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
TFM_CommandLoader.getInstance().scan();
|
||||
}
|
||||
}, 20L);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user