Blocked command aliases from being executed when that command is blocked, removed debug message

This commit is contained in:
Jerom van der Sar 2013-07-05 13:50:10 +02:00
parent 93914370a1
commit 4cbbf10871
5 changed files with 46 additions and 17 deletions

View File

@ -1,5 +1,5 @@
#Thu, 04 Jul 2013 23:31:51 +0200
#Fri, 05 Jul 2013 13:49:09 +0200
program.VERSION=2.21
program.BUILDNUM=266
program.BUILDDATE=07/04/2013 11\:31 PM
program.BUILDNUM=286
program.BUILDDATE=07/05/2013 01\:49 PM

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Thu Jul 04 23:31:51 CEST 2013
build.number=267
#Fri Jul 05 13:49:09 CEST 2013
build.number=287

View File

@ -22,7 +22,8 @@ import org.bukkit.plugin.Plugin;
public class TFM_CommandLoader
{
public static Pattern COMMAND_CLASS_PATTERN = Pattern.compile(TotalFreedomMod.COMMAND_PATH.replace('.', '/') + "/(" + TotalFreedomMod.COMMAND_PREFIX + "[^\\$]+)\\.class");
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()
@ -31,7 +32,7 @@ public class TFM_CommandLoader
public void scan()
{
CommandMap commandMap = TFM_Util.getField(Bukkit.getServer().getPluginManager(), "commandMap");
commandMap = TFM_Util.getField(Bukkit.getServer().getPluginManager(), "commandMap");
if (commandMap == null)
{
TFM_Log.severe("Error loading command map.");

View File

@ -1,18 +1,20 @@
package me.StevenLawson.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.server.RemoteServerCommandEvent;
public class TFM_CommandBlocker
{
public static boolean isCommandBlocked(String command, CommandSender sender)
public static boolean isCommandBlocked(String usedcommand, CommandSender sender)
{
String name = sender.getName();
command = command.toLowerCase().trim();
usedcommand = usedcommand.toLowerCase().trim();
for (String blocked_command : TotalFreedomMod.blockedCommands)
{
@ -22,11 +24,38 @@ public class TFM_CommandBlocker
continue;
}
if (!(command + " ").startsWith(parts[2] + " "))
if (!(usedcommand + " ").startsWith(parts[2] + " "))
{
continue;
CommandMap commandMap = TFM_CommandLoader.commandMap;
if (commandMap == null)
{
continue;
}
Command command = commandMap.getCommand(parts[2].replaceAll("/", ""));
if (command == null)
{
continue;
}
boolean block = false;
for (String alias : command.getAliases())
{
if (usedcommand.replaceAll("/", "").startsWith(alias))
{
block = true;
break;
}
}
if (!block)
{
continue;
}
}
if (SenderRank.hasPermissions(sender, parts[0]))
{
continue;
@ -47,8 +76,6 @@ public class TFM_CommandBlocker
}
}
TFM_Log.info("Player Rank: " + SenderRank.getSenderRank(sender).rank);
// Action
if ("b".equals(parts[1]))
{
@ -58,7 +85,7 @@ public class TFM_CommandBlocker
{
if (SenderRank.getSenderRank(sender).rank < 2) // Only auto-eject Ops and non-ops
{
TFM_Util.autoEject((Player) sender, "You used a prohibited command: " + command);
TFM_Util.autoEject((Player) sender, "You used a prohibited command: " + usedcommand);
TFM_Util.bcastMsg(name + " was automatically kicked for using harmful commands.", ChatColor.RED);
}
return true;

View File

@ -1049,6 +1049,7 @@ public class TFM_Util
ChatColor.RED,
ChatColor.LIGHT_PURPLE,
ChatColor.YELLOW);
private static final Random RANDOM = new Random();
public static ChatColor randomChatColor()
{