Merge pull request #118 from SuperSpyTX/master

Improvement to Fastbreak Check
This commit is contained in:
H31IX committed 2012-11-21 06:07:20 -08:00
commit 3589671bb8
6 files changed
+80 -36

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>craftbukkit</artifactId>
<version>1.4.2-R0.1</version> <version>1.4.5-R0.2</version>
<type>jar</type> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@@ -59,7 +59,8 @@ public class Backend
private Map<String, Long> yAxisLastViolation = new HashMap<String, Long>(); private Map<String, Long> yAxisLastViolation = new HashMap<String, Long>();
private Map<String, Double> lastYcoord = new HashMap<String, Double>(); private Map<String, Double> lastYcoord = new HashMap<String, Double>();
private Map<String, Long> lastYtime = new HashMap<String, Long>(); private Map<String, Long> lastYtime = new HashMap<String, Long>();
private Map<String, Integer> blocksBroken = new HashMap<String, Integer>(); private Map<String, Integer> fastBreaks = new HashMap<String, Integer>();
private Map<String, Boolean> blockBreakHolder = new HashMap<String, Boolean>();
private Map<String, Long> lastBlockBroken = new HashMap<String, Long>(); private Map<String, Long> lastBlockBroken = new HashMap<String, Long>();
private Map<String, Integer> fastPlaceViolation = new HashMap<String, Integer>(); private Map<String, Integer> fastPlaceViolation = new HashMap<String, Integer>();
private Map<String, Integer> lastZeroHitPlace = new HashMap<String, Integer>(); private Map<String, Integer> lastZeroHitPlace = new HashMap<String, Integer>();
@@ -130,7 +131,8 @@ public class Backend
yAxisLastViolation.remove(pN); yAxisLastViolation.remove(pN);
lastYcoord.remove(pN); lastYcoord.remove(pN);
lastYtime.remove(pN); lastYtime.remove(pN);
blocksBroken.remove(pN); fastBreaks.remove(pN);
blockBreakHolder.remove(pN);
lastBlockBroken.remove(pN); lastBlockBroken.remove(pN);
fastPlaceViolation.remove(pN); fastPlaceViolation.remove(pN);
lastZeroHitPlace.remove(pN); lastZeroHitPlace.remove(pN);
@@ -143,6 +145,20 @@ public class Backend
velocitized.remove(pN); velocitized.remove(pN);
velocitytrack.remove(pN); velocitytrack.remove(pN);
animated.remove(pN); animated.remove(pN);
startEat.remove(pN);
lastHeal.remove(pN);
projectileTime.remove(pN);
bowWindUp.remove(pN);
instantBreakExempt.remove(pN);
sprinted.remove(pN);
brokenBlock.remove(pN);
placedBlock.remove(pN);
movingExempt.remove(pN);
blockTime.remove(pN);
blocksDropped.remove(pN);
lastInventoryTime.remove(pN);
inventoryTime.remove(pN);
inventoryChanges.remove(pN);
} }
public boolean checkFastBow(Player player, float force) public boolean checkFastBow(Player player, float force)
@@ -657,25 +673,10 @@ public class Backend
public boolean checkSwing(Player player, Block block) public boolean checkSwing(Player player, Block block)
{ {
String name = player.getName();
if (!isInstantBreakExempt(player)) if (!isInstantBreakExempt(player))
{ {
if (!player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES)) if (!player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES))
{
return !justAnimated(player);
}
}
return false;
}
public boolean checkFastBreak(Player player, Block block)
{
int violations = magic.FASTBREAK_MAXVIOLATIONS;
if (player.getGameMode() == GameMode.CREATIVE)
{
violations = magic.FASTBREAK_MAXVIOLATIONS_CREATIVE;
}
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 (blockPunches.get(name) != null && player.getGameMode() != GameMode.CREATIVE) if (blockPunches.get(name) != null && player.getGameMode() != GameMode.CREATIVE)
{ {
@@ -684,7 +685,28 @@ public class Backend
{ {
return true; return true;
} }
else
{
blockPunches.put(name, 0); // it should reset after EACH block break.
} }
}
}
}
return !justAnimated(player); //TODO: best way to implement other option?
}
public boolean checkFastBreak(Player player, Block block)
{
int violations = 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();
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)) if (!fastBreakViolation.containsKey(name))
{ {
fastBreakViolation.put(name, 0); fastBreakViolation.put(name, 0);
@@ -703,32 +725,47 @@ public class Backend
fastBreakViolation.put(name, 0); fastBreakViolation.put(name, 0);
} }
} }
if (!blocksBroken.containsKey(name) || !lastBlockBroken.containsKey(name)) if (!fastBreaks.containsKey(name) || !lastBlockBroken.containsKey(name))
{ {
if (!lastBlockBroken.containsKey(name)) if (!lastBlockBroken.containsKey(name))
{ {
lastBlockBroken.put(name, System.currentTimeMillis()); lastBlockBroken.put(name, System.currentTimeMillis());
} }
blocksBroken.put(name, 0); fastBreaks.put(name, 0);
} }
else else
{ {
blocksBroken.put(name, blocksBroken.get(name) + 1);
Long math = System.currentTimeMillis() - lastBlockBroken.get(name); Long math = System.currentTimeMillis() - lastBlockBroken.get(name);
if (blocksBroken.get(name) > magic.FASTBREAK_LIMIT && math < magic.FASTBREAK_TIMEMAX) if (math < timemax && (math != 0L && player.getGameMode() != GameMode.CREATIVE))
{ {
blocksBroken.put(name, 0); fastBreaks.put(name, fastBreaks.get(name) + 1);
lastBlockBroken.put(name, System.currentTimeMillis()); blockBreakHolder.put(name, false);
}
if (fastBreaks.get(name) >= magic.FASTBREAK_LIMIT && math < timemax)
{
fastBreaks.put(name, 1);
fastBreakViolation.put(name, fastBreakViolation.get(name) + 1); fastBreakViolation.put(name, fastBreakViolation.get(name) + 1);
return true; return true;
} }
else if (blocksBroken.get(name) > magic.FASTBREAK_LIMIT) else if (fastBreaks.get(name) >= magic.FASTBREAK_LIMIT)
{ {
lastBlockBroken.put(name, System.currentTimeMillis()); if(!blockBreakHolder.containsKey(name) || !blockBreakHolder.get(name))
blocksBroken.put(name, 0); {
blockBreakHolder.put(name, true);
}
else
{
fastBreaks.put(name, fastBreaks.get(name) - 1);
blockBreakHolder.put(name, false);
} }
} }
} }
System.out.println(System.currentTimeMillis() - lastBlockBroken.get(name));
System.out.println(fastBreaks.get(name));
lastBlockBroken.put(name, System.currentTimeMillis()); // always keep a log going.
}
return false; return false;
} }
@@ -892,7 +929,8 @@ public class Backend
inventoryTime.put(name, diff); inventoryTime.put(name, diff);
player.sendMessage(ChatColor.RED + "[AntiCheat] Inventory hack detected. Please wait 10 seconds before using inventories."); player.sendMessage(ChatColor.RED + "[AntiCheat] Inventory hack detected. Please wait 10 seconds before using inventories.");
return true; return true;
} else if (inventoryTime.get(name) > 0 && diff > magic.INVENTORY_MAXVIOLATIONTIME) }
else if (inventoryTime.get(name) > 0 && diff > magic.INVENTORY_MAXVIOLATIONTIME)
{ {
inventoryChanges.put(name, 0); inventoryChanges.put(name, 0);
} }
@@ -36,10 +36,10 @@ public class UserManager
private static final ChatColor YELLOW = ChatColor.YELLOW; private static final ChatColor YELLOW = ChatColor.YELLOW;
private static final ChatColor RED = ChatColor.RED; private static final ChatColor RED = ChatColor.RED;
public UserManager(Configuration config) public UserManager(Configuration conf)
{ {
this.config = config; config = conf;
lang = config.getLang(); lang = conf.getLang();
} }
public User getUser(String name) public User getUser(String name)
@@ -104,6 +104,10 @@ public class Magic
* Time to wait before checking block breaks; Type=system, +Leniency=Increase. * Time to wait before checking block breaks; Type=system, +Leniency=Increase.
*/ */
public final int FASTBREAK_TIMEMAX; public final int FASTBREAK_TIMEMAX;
/**
* Time to wait before checking block breaks in creative mode; Type=system, +Leniency=Increase.
*/
public final int FASTBREAK_TIMEMAX_CREATIVE;
/** /**
* Number of times fastbreak can be observed before taking action; Type=integer, +Leniency=Increase. * Number of times fastbreak can be observed before taking action; Type=integer, +Leniency=Increase.
*/ */
@@ -344,6 +348,7 @@ public class Magic
DROP_CHECK = getInt("DROP_CHECK"); DROP_CHECK = getInt("DROP_CHECK");
FASTBREAK_LIMIT = getInt("FASTBREAK_LIMIT"); FASTBREAK_LIMIT = getInt("FASTBREAK_LIMIT");
FASTBREAK_TIMEMAX = getInt("FASTBREAK_TIMEMAX"); FASTBREAK_TIMEMAX = getInt("FASTBREAK_TIMEMAX");
FASTBREAK_TIMEMAX_CREATIVE = getInt("FASTBREAK_TIMEMAX_CREATIVE");
FASTBREAK_MAXVIOLATIONS = getInt("FASTBREAK_MAXVIOLATIONS"); FASTBREAK_MAXVIOLATIONS = getInt("FASTBREAK_MAXVIOLATIONS");
FASTBREAK_MAXVIOLATIONS_CREATIVE = getInt("FASTBREAK_MAXVIOLATIONS_CREATIVE"); FASTBREAK_MAXVIOLATIONS_CREATIVE = getInt("FASTBREAK_MAXVIOLATIONS_CREATIVE");
FASTBREAK_MAXVIOLATIONTIME = getInt("FASTBREAK_MAXVIOLATIONTIME"); FASTBREAK_MAXVIOLATIONTIME = getInt("FASTBREAK_MAXVIOLATIONTIME");
@@ -132,7 +132,7 @@ public class PastebinReport
conn.setDoOutput(true); conn.setDoOutput(true);
OutputStream out = conn.getOutputStream(); OutputStream out = conn.getOutputStream();
out.write(("api_option=paste" + "&api_dev_key=" + URLEncoder.encode("c0616def494dcb5b7632304f8c52c0f1", "utf-8") + "&api_paste_code=" + URLEncoder.encode(report.toString(), "utf-8") + "&api_paste_private=" + URLEncoder.encode("0", "utf-8") + "&api_paste_name=" + URLEncoder.encode("", "utf-8") + "&api_paste_expire_date=" + URLEncoder.encode("1D", "utf-8") + "&api_paste_format=" + URLEncoder.encode("text", "utf-8") + "&api_user_key=" + URLEncoder.encode("", "utf-8")).getBytes()); out.write(("api_option=paste" + "&api_dev_key=" + URLEncoder.encode("c0616def494dcb5b7632304f8c52c0f1", "utf-8") + "&api_paste_code=" + URLEncoder.encode(report.toString(), "utf-8") + "&api_paste_private=" + URLEncoder.encode("1", "utf-8") + "&api_paste_name=" + URLEncoder.encode("", "utf-8") + "&api_paste_expire_date=" + URLEncoder.encode("1M", "utf-8") + "&api_paste_format=" + URLEncoder.encode("text", "utf-8") + "&api_user_key=" + URLEncoder.encode("", "utf-8")).getBytes());
out.flush(); out.flush();
out.close(); out.close();
+4 -3
View File
@@ -15,10 +15,11 @@ PROJECTILE_TIME_MIN: 1500
PROJECTILE_CHECK: 10 PROJECTILE_CHECK: 10
DROP_TIME_MIN: 800 DROP_TIME_MIN: 800
DROP_CHECK: 10 DROP_CHECK: 10
FASTBREAK_LIMIT: 3 FASTBREAK_LIMIT: 2
FASTBREAK_TIMEMAX: 500 FASTBREAK_TIMEMAX: 1000
FASTBREAK_TIMEMAX_CREATIVE: 100
FASTBREAK_MAXVIOLATIONS: 2 FASTBREAK_MAXVIOLATIONS: 2
FASTBREAK_MAXVIOLATIONS_CREATIVE: 3 FASTBREAK_MAXVIOLATIONS_CREATIVE: 4
FASTBREAK_MAXVIOLATIONTIME: 10000 FASTBREAK_MAXVIOLATIONTIME: 10000
FASTPLACE_ZEROLIMIT: 3 FASTPLACE_ZEROLIMIT: 3
FASTPLACE_TIMEMAX: 100 FASTPLACE_TIMEMAX: 100