Custom commands can now execute plugin commands too + made nukeCheck

a bit more reliable and faster
This commit is contained in:
Evenprime 2011-07-09 16:14:20 +02:00
parent 67c8ca13d1
commit be9a728eda
5 changed files with 41 additions and 28 deletions

View File

@ -3,7 +3,7 @@ name: NoCheat
author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheat
version: 1.08
version: 1.08a
softdepend: [ Permissions, CraftIRC ]

View File

@ -10,6 +10,7 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
@ -401,9 +402,32 @@ public class NoCheat extends JavaPlugin implements CommandSender {
public void handleCustomAction(CustomAction a, Player player) {
Bukkit.getServer().dispatchCommand(this, a.command.replace("[player]", player.getName()));
//System.out.println("Would execute "+a.command + " now for Player " + player.getName() );
String command = a.command.replace("[player]", player.getName());
try {
String[] commandParts = command.split(" ", 2);
String commandName = commandParts[0];
PluginCommand com = Bukkit.getServer().getPluginCommand(commandName);
// If there's a plugin that can handle it
if(com != null) {
if(commandParts.length > 1) { // Command + parameters
String[] commandArgs = commandParts[1].split(" ");
com.execute(this, commandName, commandArgs);
}
else {
String[] commandArgs = new String[0];
com.execute(this, commandName, commandArgs);
}
}
else
{
// The standard server should do it
Bukkit.getServer().dispatchCommand(this, command);
}
}
catch(Exception e) {
this.log(Level.WARNING, "NoCheat couldn't execute custom server command: \""+command+"\"");
}
}
@Override

View File

@ -12,7 +12,7 @@ public class CustomAction extends Action {
public CustomAction(int firstAfter, boolean repeat, String command) {
super(firstAfter, repeat);
this.command = command;
this.command = command.trim();
}
public String getName() {

View File

@ -10,7 +10,6 @@ import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.util.Vector;
@ -63,20 +62,20 @@ public class NukeCheck extends Check {
Location eyes = event.getPlayer().getEyeLocation();
Vector direction = eyes.getDirection();
double x1 = (double)block.getX() - eyes.getX();
double y1 = (double)block.getY() - eyes.getY();
double z1 = (double)block.getZ() - eyes.getZ();
// Because it's not very precise on very short distances,
// consider the length of the side of a block to be 2.0 instead of 1.0
final double x1 = ((double)block.getX()) - eyes.getX() - 0.5;
final double y1 = ((double)block.getY()) - eyes.getY() - 0.5;
final double z1 = ((double)block.getZ()) - eyes.getZ() - 0.5;
double x2 = x1 + 1;
double y2 = y1 + 1;
double z2 = z1 + 1;
final double x2 = x1 + 2;
final double y2 = y1 + 2;
final double z2 = z1 + 2;
double factor = 1 + direction.distance(new Vector(x1 + 0.5, y1 + 0.5, z1 + 0.5));
double errorMargin = 1.2 / factor;
double factor = new Vector(x1 + 1, y1 + 1, z1 + 1).length();
if(factor * direction.getX() >= x1 - errorMargin && factor * direction.getY() >= y1 - errorMargin && factor * direction.getZ() >= z1 - errorMargin &&
factor * direction.getX() <= x2 + errorMargin && factor * direction.getY() <= y2 + errorMargin && factor * direction.getZ() <= z2 + errorMargin) {
if(factor * direction.getX() >= x1 && factor * direction.getY() >= y1 && factor * direction.getZ() >= z1 &&
factor * direction.getX() <= x2 && factor * direction.getY() <= y2 && factor * direction.getZ() <= z2) {
if(data.counter > 0) {
data.counter--;
}
@ -85,7 +84,7 @@ public class NukeCheck extends Check {
data.counter++;
event.setCancelled(true);
if(data.counter > 20) {
if(data.counter > 10) {
String log = String.format(Locale.US, logMessage, event.getPlayer().getName());
@ -99,9 +98,6 @@ public class NukeCheck extends Check {
}
public void check(BlockDamageEvent event) {
}
@Override
protected void registerListeners() {

View File

@ -1,7 +1,6 @@
package cc.co.evenprime.bukkit.nocheat.listeners;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockListener;
import cc.co.evenprime.bukkit.nocheat.checks.NukeCheck;
@ -14,12 +13,6 @@ public class NukeBlockListener extends BlockListener {
this.check = check;
}
@Override
public void onBlockDamage(BlockDamageEvent event) {
//System.out.println("Damage "+ event.getInstaBreak() + " " + event.getItemInHand() + " " + event.getBlock());
check.check(event);
}
@Override
public void onBlockBreak(BlockBreakEvent event) {