More work on the calibrator and respect mcMMO greenthumb events

This commit is contained in:
h31ix committed 2012-10-06 00:32:39 -04:00
1 parent 989540d73b
commit f43c152f16
3 files changed
+138 -27

No files matched your search

@@ -666,14 +666,14 @@ public class Backend
public boolean checkSwing(Player player, Block block) public boolean checkSwing(Player player, Block block)
{ {
if(!player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES)) if(!isInstantBreakExempt(player))
{ {
return !justAnimated(player); if(!player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES))
} {
else return !justAnimated(player);
{ }
return false;
} }
return false;
} }
public boolean checkFastBreak(Player player, Block block) public boolean checkFastBreak(Player player, Block block)
@@ -2,12 +2,16 @@ package net.h31ix.anticheat.util;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class Calibrator implements Listener public class Calibrator implements Listener
{ {
@@ -20,8 +24,11 @@ public class Calibrator implements Listener
private long [] longs = new long[10]; private long [] longs = new long[10];
private double [] doubles = new double[10]; private double [] doubles = new double[10];
private int [] ints = new int[10]; private int [] ints = new int[10];
private int times = 0;
// Value-specific calculations // Value-specific calculations
private long projectileTime;
private long dropItemTime;
private long punchAvg; private long punchAvg;
private double blockBreakMax; private double blockBreakMax;
private double blockPlaceMax; private double blockPlaceMax;
@@ -38,6 +45,16 @@ public class Calibrator implements Listener
switch(step) switch(step)
{ {
case 0: case 0:
sendStep();
player.getInventory().setItemInHand(new ItemStack(Material.BOW));
player.getInventory().addItem(new ItemStack(Material.ARROW, 64));
player.sendMessage("Fire arrows as fast as possible (don't pull all the way back)");
break;
case 2:
player.getInventory().clear();
player.getInventory().setItemInHand(new ItemStack(Material.DIRT, 64));
player.sendMessage("Drop items as fast as possible.");
/*case 0:
sendStep(); sendStep();
player.sendMessage("Spam the left mouse button as fast as possible."); player.sendMessage("Spam the left mouse button as fast as possible.");
break; break;
@@ -47,7 +64,7 @@ public class Calibrator implements Listener
break; break;
case 3: case 3:
player.sendMessage("Place blocks from as far away as you can possibly get from them."); player.sendMessage("Place blocks from as far away as you can possibly get from them.");
break; break;*/
} }
} }
@@ -84,10 +101,19 @@ public class Calibrator implements Listener
{ {
longs[i] = 0; longs[i] = 0;
} }
for(int i =0;i<ints.length;i++)
{
ints[i] = 0;
}
for(int i =0;i<doubles.length;i++) for(int i =0;i<doubles.length;i++)
{ {
doubles[i] = 0; doubles[i] = 0;
} }
lastInt = 0;
lastDouble = 0;
lastLong = 0;
times = 0;
} }
private void sendStep() private void sendStep()
@@ -96,7 +122,8 @@ public class Calibrator implements Listener
player.sendMessage(ChatColor.GREEN+"Step "+step+"/"+TOTAL); player.sendMessage(ChatColor.GREEN+"Step "+step+"/"+TOTAL);
} }
private void getAvgLong(long avg) // Find the average time it takes to do a task
private long getAvgLong()
{ {
int count = getLongCount(); int count = getLongCount();
if(count < 10) if(count < 10)
@@ -113,20 +140,23 @@ public class Calibrator implements Listener
} }
else else
{ {
long avg = 0;
for(long l : longs) for(long l : longs)
{ {
avg+=l; avg+=l;
} }
lastLong = 0;
clear(); clear();
avg/=10; avg/=10;
player.sendMessage(ChatColor.AQUA+"Done. Average calculated at "+ChatColor.WHITE+avg); player.sendMessage(ChatColor.AQUA+"Done. Average calculated at "+ChatColor.WHITE+avg);
sendStep(); sendStep();
calibrate(); calibrate();
return avg;
} }
return -1;
} }
private void getMaxDouble(double max, double length) // Find the maximum time it takes to do a task
private double getMaxDouble(double length)
{ {
int count = getDoubleCount(); int count = getDoubleCount();
System.out.println(count); System.out.println(count);
@@ -136,6 +166,7 @@ public class Calibrator implements Listener
} }
else else
{ {
double max = 0;
for(double d : doubles) for(double d : doubles)
{ {
if(max == 0 || d > max) if(max == 0 || d > max)
@@ -147,41 +178,128 @@ public class Calibrator implements Listener
player.sendMessage(ChatColor.AQUA+"Done. Maximum calculated at "+ChatColor.WHITE+max); player.sendMessage(ChatColor.AQUA+"Done. Maximum calculated at "+ChatColor.WHITE+max);
sendStep(); sendStep();
calibrate(); calibrate();
return max;
} }
return -1;
}
// Get the absolute time it takes to do something X times
private long getAbsoluteLong()
{
int count = getLongCount();
if(count < 10)
{
if(lastLong == 0)
{
lastLong = System.currentTimeMillis();
}
else
{
longs[count] = System.currentTimeMillis();
lastLong = System.currentTimeMillis();
}
}
else
{
long val = longs[9]-longs[0];
clear();
player.sendMessage(ChatColor.AQUA+"Done. Value calculated at "+ChatColor.WHITE+val);
sendStep();
calibrate();
return val;
}
return -1;
} }
// Begin event listeners // Begin event listeners
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event)
{
if(event.getPlayer() == player)
{
if(step == 2)
{
long v = getAbsoluteLong();
if(v != -1)
{
dropItemTime = v;
}
}
}
}
@EventHandler
public void onEntityShootBow(EntityShootBowEvent event)
{
if(event.getEntity() instanceof Player && ((Player)event.getEntity()) == player)
{
if(step == 1)
{
long v = getAbsoluteLong();
if(v != -1)
{
projectileTime = v;
}
}
}
}
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{ {
if(step == 1) if(event.getPlayer() == player)
{ {
getAvgLong(punchAvg); if(step == -1)
{
long v = getAvgLong();
if(v != -1)
{
punchAvg = v;
}
}
else if(step == 1)
{
}
} }
} }
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent event) public void onBlockBreak(BlockBreakEvent event)
{ {
if(step == 2) if(event.getPlayer() == player)
{ {
double lengthX = Math.abs(event.getBlock().getX()-event.getPlayer().getLocation().getX()); if(step == -1)
double lengthZ = Math.abs(event.getBlock().getZ()-event.getPlayer().getLocation().getZ()); {
getMaxDouble(blockBreakMax, lengthX >= lengthZ ? lengthX : lengthZ); double lengthX = Math.abs(event.getBlock().getX()-event.getPlayer().getLocation().getX());
double lengthZ = Math.abs(event.getBlock().getZ()-event.getPlayer().getLocation().getZ());
double v = getMaxDouble(lengthX >= lengthZ ? lengthX : lengthZ);
if(v != -1)
{
blockBreakMax = v;
}
}
} }
} }
@EventHandler @EventHandler
public void onBlockPlace(BlockPlaceEvent event) public void onBlockPlace(BlockPlaceEvent event)
{ {
if(step == 3) if(event.getPlayer() == player)
{ {
double lengthX = Math.abs(event.getBlock().getX()-event.getPlayer().getLocation().getX()); if(step == -1)
double lengthZ = Math.abs(event.getBlock().getZ()-event.getPlayer().getLocation().getZ()); {
getMaxDouble(blockPlaceMax, lengthX >= lengthZ ? lengthX : lengthZ); double lengthX = Math.abs(event.getBlock().getX()-event.getPlayer().getLocation().getX());
double lengthZ = Math.abs(event.getBlock().getZ()-event.getPlayer().getLocation().getZ());
double v = getMaxDouble(lengthX >= lengthZ ? lengthX : lengthZ);
if(v != -1)
{
blockPlaceMax = v;
}
}
} }
} }
} }
@@ -18,10 +18,8 @@
package net.h31ix.anticheat.util; package net.h31ix.anticheat.util;
import net.h31ix.anticheat.Anticheat;
import net.h31ix.anticheat.util.yaml.CommentedConfiguration; import net.h31ix.anticheat.util.yaml.CommentedConfiguration;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
/** /**
* Magic number class. Modifications to values in magic.yml will be accepted here. * Magic number class. Modifications to values in magic.yml will be accepted here.
@@ -83,10 +81,6 @@ public class Magic
* Time to exempt a player from moving because of taking damage from an explosion; Type=system, +Leniency=Increase. * Time to exempt a player from moving because of taking damage from an explosion; Type=system, +Leniency=Increase.
*/ */
public final long EXPLOSION_DAMAGE_TIME; public final long EXPLOSION_DAMAGE_TIME;
/**
* Time to wait in between item drops; Type=system, +Leniency=Decrease.
*/
public final int DROPPED_ITEM_TIME;
/** /**
* Minimum time it takes to fire X projectiles; Type=system, +Leniency=Decrease. * Minimum time it takes to fire X projectiles; Type=system, +Leniency=Decrease.
*/ */
@@ -333,7 +327,6 @@ public class Magic
DAMAGE_TIME = getLong("DAMAGE_TIME"); DAMAGE_TIME = getLong("DAMAGE_TIME");
KNOCKBACK_DAMAGE_TIME = getLong("KNOCKBACK_DAMAGE_TIME"); KNOCKBACK_DAMAGE_TIME = getLong("KNOCKBACK_DAMAGE_TIME");
EXPLOSION_DAMAGE_TIME = getLong("EXPLOSION_DAMAGE_TIME"); EXPLOSION_DAMAGE_TIME = getLong("EXPLOSION_DAMAGE_TIME");
DROPPED_ITEM_TIME = getInt("DROPPED_ITEM_TIME");
PROJECTILE_TIME_MIN = getInt("PROJECTILE_TIME_MIN"); PROJECTILE_TIME_MIN = getInt("PROJECTILE_TIME_MIN");
PROJECTILE_CHECK = getInt("PROJECTILE_CHECK"); PROJECTILE_CHECK = getInt("PROJECTILE_CHECK");
DROP_TIME_MIN = getInt("DROP_TIME_MIN"); DROP_TIME_MIN = getInt("DROP_TIME_MIN");