Get rid of the own implementation of ConsoleCommandSender in favour of

using the servers ConsoleCommandSender.
This commit is contained in:
Evenprime 2011-10-14 16:04:16 +02:00
parent 033fad0f54
commit bbec08d34d
4 changed files with 10 additions and 113 deletions

View File

@ -3,7 +3,7 @@ name: NoCheat
author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheat
version: 2.10
version: 2.11
commands:
nocheat:

View File

@ -24,13 +24,10 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData;
public class ActionExecutor {
private final Map<Player, ActionHistory> actionHistory = new HashMap<Player, ActionHistory>();
private final NoCheat plugin;
private final ConsoleCommandSender ccsender;
private final NoCheat plugin;
public ActionExecutor(NoCheat plugin) {
this.plugin = plugin;
this.ccsender = new ConsoleCommandSender(plugin.getServer());
}
public boolean executeActions(Player player, ActionList actions, int violationLevel, LogData data, ConfigurationCache cc) {
@ -72,6 +69,12 @@ public class ActionExecutor {
}
private void executeConsoleCommand(String command) {
ccsender.executeConsoleCommand(command);
try {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command);
} catch(Exception e) {
// TODO: Better error handling
System.out.println("[NoCheat] failed to execute the command '" + command + "', please check if everything is setup correct. ");
e.printStackTrace();
}
}
}

View File

@ -1,106 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.actions;
import java.util.Set;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissibleBase;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
/**
* The ConsoleCommandSender imitates the admin writing commands into the server
* console. It is used to execute consolecommand actions.
*
* @author Evenprime
*
*/
public class ConsoleCommandSender implements CommandSender {
private final Server server;
private final PermissibleBase perm;
public ConsoleCommandSender(Server server) {
this.server = server;
this.perm = new PermissibleBase(this);
}
public void sendMessage(String message) {
// We have no interest in returning messages
}
public boolean isOp() {
return true;
}
public void setOp(boolean value) {
// We are OP, or at least we claim to be :)
}
public boolean isPlayer() {
return false;
}
public Server getServer() {
return server;
}
public boolean isPermissionSet(String name) {
return perm.isPermissionSet(name);
}
public boolean isPermissionSet(Permission perm) {
return this.perm.isPermissionSet(perm);
}
public boolean hasPermission(String name) {
return true; // We have ALL permissions ;)
}
public boolean hasPermission(Permission perm) {
return true; // We have ALL permissions ;)
}
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
return perm.addAttachment(plugin, name, value);
}
public PermissionAttachment addAttachment(Plugin plugin) {
return perm.addAttachment(plugin);
}
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
return perm.addAttachment(plugin, name, value, ticks);
}
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
return perm.addAttachment(plugin, ticks);
}
public void removeAttachment(PermissionAttachment attachment) {
perm.removeAttachment(attachment);
}
public void recalculatePermissions() {
perm.recalculatePermissions();
}
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
return perm.getEffectivePermissions();
}
public void executeConsoleCommand(String command) {
try {
server.dispatchCommand(this, command);
} catch(Exception e) {
// TODO: Better error handling
System.out.println("[NoCheat] failed to execute the command '"+command + "', please check if everything is setup correct.");
}
}
public String getName() {
return "NoCheat";
}
}

View File

@ -142,7 +142,7 @@ public class DefaultConfiguration extends Configuration {
setValue(FIGHT_DIRECTION_CHECK, true);
setValue(FIGHT_DIRECTION_PRECISION, 75);
setValue(FIGHT_DIRECTION_PENALTYTIME, 400);
setValue(FIGHT_DIRECTION_PENALTYTIME, 500);
ActionList directionActionList = new ActionList();
directionActionList.setActions(0, action.getActions("fightDirectionLog fightCancel".split(" ")));