mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-12-27 20:27:37 +00:00
fix wildcard and clean up command executor
This commit is contained in:
parent
9d7e0cdefc
commit
5421de0c2f
@ -1,6 +1,7 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
@ -41,6 +42,16 @@ public class CommandLoader extends FreedomService
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isAlias(String alias)
|
||||
{
|
||||
for (FreedomCommand command : commands)
|
||||
{
|
||||
if (Arrays.asList(command.getAliases().split(",")).contains(alias))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getCommandAmount()
|
||||
{
|
||||
return commands.size();
|
||||
|
@ -1,8 +1,11 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.nio.channels.FileLock;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -30,16 +33,30 @@ public class Command_wildcard extends FreedomCommand
|
||||
return false;
|
||||
}
|
||||
|
||||
FreedomCommand command = plugin.cl.getByName(args[0]);
|
||||
if (command == null)
|
||||
Command runCmd = server.getPluginCommand(args[0]);
|
||||
FreedomCommand fCmd = plugin.cl.getByName(args[0]);
|
||||
boolean alias = plugin.cl.isAlias(args[0]);
|
||||
if (runCmd == null && fCmd == null && !alias)
|
||||
{
|
||||
msg("Unknown command: " + args[0], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> aliases = new ArrayList<>();
|
||||
|
||||
if (runCmd != null)
|
||||
{
|
||||
aliases = runCmd.getAliases();
|
||||
}
|
||||
|
||||
if (fCmd != null)
|
||||
{
|
||||
aliases = Arrays.asList(fCmd.getAliases().split(","));
|
||||
}
|
||||
|
||||
for (String blockedCommand : BLOCKED_COMMANDS)
|
||||
{
|
||||
if (blockedCommand.equals(command.getName()) || command.getAliases().contains(blockedCommand))
|
||||
if (blockedCommand.equals(args[0].toLowerCase()) || aliases.contains(blockedCommand))
|
||||
{
|
||||
msg("Did you really think that was going to work?", ChatColor.RED);
|
||||
return true;
|
||||
|
@ -89,27 +89,22 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
||||
cmd.setExecutor(this);
|
||||
}
|
||||
|
||||
public static final CommandMap getCommandMap()
|
||||
public static CommandMap getCommandMap()
|
||||
{
|
||||
if (commandMap == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
final Field f = Bukkit.getServer().getPluginManager().getClass().getDeclaredField("commandMap");
|
||||
f.setAccessible(true);
|
||||
commandMap = (CommandMap) f.get(Bukkit.getServer());
|
||||
return getCommandMap();
|
||||
commandMap = (CommandMap) f.get(Bukkit.getServer().getPluginManager());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if (commandMap != null)
|
||||
{
|
||||
return commandMap;
|
||||
}
|
||||
return getCommandMap();
|
||||
return commandMap;
|
||||
}
|
||||
|
||||
private final class FCommand extends Command
|
||||
|
Loading…
Reference in New Issue
Block a user