Rewrote fastbreak to take into account the power of each shovel

This commit is contained in:
h31ix committed 2012-12-15 12:40:10 -05:00
1 parent c029e656f8
commit 1a4e1c4f15
2 files changed
+39 -60

No files matched your search

@@ -733,71 +733,31 @@ public class Backend
public boolean checkFastBreak(Player player, Block block) public boolean checkFastBreak(Player player, Block block)
{ {
int violations = magic.FASTBREAK_MAXVIOLATIONS; int violations = player.getGameMode() == GameMode.CREATIVE ? magic.FASTBREAK_MAXVIOLATIONS_CREATIVE : magic.FASTBREAK_MAXVIOLATIONS;
int timemax = magic.FASTBREAK_TIMEMAX;
if (player.getGameMode() == GameMode.CREATIVE)
{
violations = magic.FASTBREAK_MAXVIOLATIONS_CREATIVE;
timemax = magic.FASTBREAK_TIMEMAX_CREATIVE;
}
String name = player.getName(); String name = player.getName();
if (!player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !Utilities.isInstantBreak(block.getType()) && !isInstantBreakExempt(player) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES)) if (!player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !Utilities.isInstantBreak(block.getType()) && !isInstantBreakExempt(player) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES))
{ {
if (!fastBreakViolation.containsKey(name)) long expectedTime = Utilities.getTime(player.getInventory().getItemInHand().getType());
if(!fastBreaks.containsKey(name))
{ {
fastBreaks.put(name, 0);
lastBlockBroken.put(name, System.currentTimeMillis());
fastBreakViolation.put(name, 0); fastBreakViolation.put(name, 0);
} }
else else
{ {
Long math = System.currentTimeMillis() - lastBlockBroken.get(name); long realTime = System.currentTimeMillis()-lastBlockBroken.get(name);
if (fastBreakViolation.get(name) > violations && math < magic.FASTBREAK_MAXVIOLATIONTIME) if(realTime < expectedTime)
{
lastBlockBroken.put(name, System.currentTimeMillis());
player.sendMessage(ChatColor.RED + "[AntiCheat] Fastbreaking detected. Please wait 10 seconds before breaking blocks.");
return true;
}
else if (fastBreakViolation.get(name) > 0 && math > magic.FASTBREAK_MAXVIOLATIONTIME)
{
fastBreakViolation.put(name, 0);
}
}
if (!fastBreaks.containsKey(name) || !lastBlockBroken.containsKey(name))
{
if (!lastBlockBroken.containsKey(name))
{
lastBlockBroken.put(name, System.currentTimeMillis());
}
fastBreaks.put(name, 0);
}
else
{
Long math = System.currentTimeMillis() - lastBlockBroken.get(name);
if (math < timemax && (math != 0L && player.getGameMode() != GameMode.CREATIVE))
{ {
fastBreaks.put(name, fastBreaks.get(name) + 1); fastBreaks.put(name, fastBreaks.get(name) + 1);
blockBreakHolder.put(name, false);
} }
if (fastBreaks.get(name) >= magic.FASTBREAK_LIMIT && math < timemax) lastBlockBroken.put(name, System.currentTimeMillis());
if(fastBreaks.get(name) > violations)
{ {
fastBreaks.put(name, 1);
fastBreakViolation.put(name, fastBreakViolation.get(name) + 1);
return true; return true;
} }
else if (fastBreaks.get(name) >= magic.FASTBREAK_LIMIT)
{
if (!blockBreakHolder.containsKey(name) || !blockBreakHolder.get(name))
{
blockBreakHolder.put(name, true);
}
else
{
fastBreaks.put(name, fastBreaks.get(name) - 1);
blockBreakHolder.put(name, false);
}
}
} }
lastBlockBroken.put(name, System.currentTimeMillis()); // always keep a log going.
} }
return false; return false;
} }
@@ -67,8 +67,8 @@ public final class Utilities
{ {
return !canStand(block) && cantStandClose(block) && cantStandFar(block); return !canStand(block) && cantStandClose(block) && cantStandFar(block);
} }
public static boolean cantStandAtExp(Location block) public static boolean cantStandAtExp(Location block)
{ {
// This is a experimental check for checking whether you can't stand at or whatever. // This is a experimental check for checking whether you can't stand at or whatever.
Block nblock = new Location(block.getWorld(), fixXAxis(block.getX()), block.getY() - 0.01D, block.getBlockZ()).getBlock(); Block nblock = new Location(block.getWorld(), fixXAxis(block.getX()), block.getY() - 0.01D, block.getBlockZ()).getBlock();
@@ -89,21 +89,21 @@ public final class Utilities
{ {
return !(block.isLiquid() || block.getType() == Material.AIR); return !(block.isLiquid() || block.getType() == Material.AIR);
} }
public static boolean isFullyInWater(Location player) public static boolean isFullyInWater(Location player)
{ {
double touchedX = fixXAxis(player.getX()); double touchedX = fixXAxis(player.getX());
// Yes, this doesn't make sense, but it's supposed to fix some false positives in water walk. // Yes, this doesn't make sense, but it's supposed to fix some false positives in water walk.
// Think of it as 2 negatives = a positive :) // Think of it as 2 negatives = a positive :)
if(!(new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && !(new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid()) if(!(new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && !(new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid())
{ {
return true; return true;
} }
return (new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && (new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid(); return (new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && (new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid();
} }
public static double fixXAxis(double x) public static double fixXAxis(double x)
{ {
/* Really really really useful function for those who are on the edges of blocks */ /* Really really really useful function for those who are on the edges of blocks */
@@ -116,7 +116,7 @@ public final class Utilities
} }
return touchedX; return touchedX;
} }
public static boolean isHoveringOverWater(Location player, int blocks) public static boolean isHoveringOverWater(Location player, int blocks)
{ {
for(int i = player.getBlockY(); i > player.getBlockY() - blocks; i--) for(int i = player.getBlockY(); i > player.getBlockY() - blocks; i--)
@@ -127,11 +127,11 @@ public final class Utilities
else if (newloc.getTypeId() != 0) else if (newloc.getTypeId() != 0)
return false; return false;
} }
return false; return false;
} }
public static boolean isHoveringOverWater(Location player) public static boolean isHoveringOverWater(Location player)
{ {
return isHoveringOverWater(player, 25); return isHoveringOverWater(player, 25);
} }
@@ -209,6 +209,25 @@ public final class Utilities
return x; return x;
} }
public static long getTime(Material m)
{
switch(m)
{
case WOOD_SPADE:
return 500;
case STONE_SPADE:
return 450;
case IRON_SPADE:
return 370;
case GOLD_SPADE:
return 200;
case DIAMOND_SPADE:
return 200;
default:
return 800;
}
}
static static
{ {
INSTANT_BREAK.add(Material.RED_MUSHROOM); INSTANT_BREAK.add(Material.RED_MUSHROOM);