mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +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;
|
package me.totalfreedom.totalfreedommod.command;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||||
@ -41,6 +42,16 @@ public class CommandLoader extends FreedomService
|
|||||||
return null;
|
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()
|
public int getCommandAmount()
|
||||||
{
|
{
|
||||||
return commands.size();
|
return commands.size();
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package me.totalfreedom.totalfreedommod.command;
|
package me.totalfreedom.totalfreedommod.command;
|
||||||
|
|
||||||
|
import java.nio.channels.FileLock;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||||
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -30,16 +33,30 @@ public class Command_wildcard extends FreedomCommand
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FreedomCommand command = plugin.cl.getByName(args[0]);
|
Command runCmd = server.getPluginCommand(args[0]);
|
||||||
if (command == null)
|
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);
|
msg("Unknown command: " + args[0], ChatColor.RED);
|
||||||
return true;
|
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)
|
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);
|
msg("Did you really think that was going to work?", ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
|
@ -89,28 +89,23 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
|||||||
cmd.setExecutor(this);
|
cmd.setExecutor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final CommandMap getCommandMap()
|
public static CommandMap getCommandMap()
|
||||||
{
|
{
|
||||||
if (commandMap == null)
|
if (commandMap == null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
final Field f = Bukkit.getServer().getPluginManager().getClass().getDeclaredField("commandMap");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
commandMap = (CommandMap) f.get(Bukkit.getServer());
|
commandMap = (CommandMap) f.get(Bukkit.getServer().getPluginManager());
|
||||||
return getCommandMap();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (commandMap != null)
|
|
||||||
{
|
|
||||||
return commandMap;
|
return commandMap;
|
||||||
}
|
}
|
||||||
return getCommandMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class FCommand extends Command
|
private final class FCommand extends Command
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user