mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
Remove blocked commands from the CommandMap. Resolves #622
Temporarily workaround: Remove blocked command from the CommandMap In Spigot 1.8.3, cancelling PlayerCommandPreprocessEvent will have no effect This results in TFM failing to block player commands: The player will get a message, but the command will still execute. Removing the command from the CommandMap is a temporary workaround untill the related Spigot issue has been fixed. https://hub.spigotmc.org/jira/browse/SPIGOT-879
This commit is contained in:
parent
e2d0e9e754
commit
17f3a4ca3d
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Tue May 12 16:41:20 CEST 2015
|
||||
build.number=1011
|
||||
#Tue May 12 16:51:12 CEST 2015
|
||||
build.number=1014
|
||||
|
@ -57,8 +57,8 @@ javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
||||
javac.deprecation=false
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.7
|
||||
javac.target=1.7
|
||||
javac.source=1.6
|
||||
javac.target=1.6
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
|
@ -125,7 +125,6 @@ blocked_commands:
|
||||
- 's:b:/reload:_'
|
||||
|
||||
# Superadmin commands - Auto-eject
|
||||
- 's:a:/stop:_'
|
||||
- 's:a:/save-all:_'
|
||||
- 's:a:/save-on:_'
|
||||
- 's:a:/save-off:_'
|
||||
|
@ -1,8 +1,11 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
|
||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -10,6 +13,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TFM_CommandBlocker
|
||||
@ -90,6 +94,35 @@ public class TFM_CommandBlocker
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
// Temporarily workaround: Remove blocked command from the CommandMap
|
||||
// In Spigot 1.8.3, cancelling PlayerCommandPreprocessEvent will have no effect
|
||||
// This results in TFM failing to block player commands: The player will get a message,
|
||||
// but the command will still execute. Removing the command from the CommandMap is a
|
||||
// temporary workaround untill the related Spigot issue has been fixed.
|
||||
// https://hub.spigotmc.org/jira/browse/SPIGOT-879
|
||||
try
|
||||
{
|
||||
Field field = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
field.setAccessible(true);
|
||||
Map<?, ?> knownCommands = (Map) field.get(commandMap);
|
||||
|
||||
Iterator<?> it = knownCommands.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
final Object e = it.next();
|
||||
if (command.equals(((Entry) e).getValue()))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.severe("Could not nullify command: " + command.getName());
|
||||
TFM_Log.severe(ex);
|
||||
}
|
||||
// End Temporary workaround
|
||||
|
||||
for (String alias : command.getAliases())
|
||||
{
|
||||
BLOCKED_COMMANDS.put(alias.toLowerCase(), blockedCommandEntry);
|
||||
@ -120,7 +153,8 @@ public class TFM_CommandBlocker
|
||||
return true;
|
||||
}
|
||||
|
||||
if (command.startsWith("/")) {
|
||||
if (command.startsWith("/"))
|
||||
{
|
||||
command = command.substring(1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user