Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // inside PlayerAnimationEvent -> PlayerAnimationType.ARM_SWING
- // get the difference between the last two animation hooks
- long diffHook = System.currentTimeMillis() - stats.getArmSwingAnimationHook();
- if (diffHook < 400) {
- stats.setSwings(stats.getSwings() + 1);
- } else {
- stats.setHits(stats.getHits() - 1);
- if (stats.getHits() < 0) {
- stats.setHits(0);
- }
- }
- /*
- *inside of the DamageEvent
- */
- // check if the enemy has moved enough to prevent false positives
- if (lastMob != null && lastMob.equals(mob)) {
- double distance = mob.getLocation().distance(lastMob.getLocation());
- if (distance <= 0.05 && attacker.getLocation().distance(mob.getLocation()) <= 1.0) {
- getOwner().castToAdmins(stats, "[combat] " + ChatColor.GREEN + "(ratio#) enemy has not moved enough ");
- stats.setSwings(stats.getSwings() - 1);
- } else {
- stats.setHits(stats.getHits() + 1);
- }
- }
- // make sure this value won't be negative
- if (stats.getSwings() < 0) {
- stats.setSwings(0);
- }
- // if the player has done 12 hits in total, we generate a ratio
- if (stats.getHits() >= 12 && !event.isCancelled()) {
- ChatColor color1 = ChatColor.GRAY;
- ChatColor color2 = ChatColor.DARK_GRAY;
- stats.setRatioAmount(stats.getRatioAmount() + 1);
- // Create the ratio. As far as my testing went, a legit player will maximally get the ratio up to 0.24,
- // RARELY to maximally 0.3. Haven't seen a value above this yet except with cheats.
- double ratio = ((double) stats.getHits()) / ((double) stats.getSwings());
- // create a total ratio from the last recorded ratios, again a legit player will be around less than 0.2 total ratio, cheats above 0.32
- double totalRatio = (ratio + stats.getRatio()) / stats.getRatioAmount();
- stats.setRatio(stats.getRatio() + ratio);
- // if we've recorded a total of more than 15 ratios
- if (stats.getRatioAmount() >= 15) {
- // check if the ratio is too high
- if (totalRatio >= 0.27 && ratio >= 0.27) {
- // the user is apparently cheating, preventing dealing damage n' stuff
- stats.addCombatDangerLevel(65);
- event.setCancelled(true);
- if (ratio >= 0.45) {
- stats.addCombatDangerLevel(45);
- color1 = ChatColor.RED;
- color2 = ChatColor.DARK_RED;
- } else {
- color1 = ChatColor.YELLOW;
- color2 = ChatColor.GOLD;
- }
- if (stats.getCombatDangerLevel() > 1500) {
- stats.setBlockDamage(7500);
- addBanDangerLevel(stats, 4, 2);
- } else if (stats.getCombatDangerLevel() > 500) {
- stats.setBlockDamage(4000);
- } else if (stats.getCombatDangerLevel() > 150) {
- stats.setBlockDamage(1500);
- }
- }
- }
- // I'm currently just printing out info to check what ratios the players are hitting at
- getOwner().alert(attacker, ChatColor.DARK_GRAY + "[INFO] " + color1 + attacker.getName() + color2 + " Hit/Swing Ratio: " + ChatColor.WHITE + ratio + ChatColor.DARK_GRAY + ", " + color2 + "/" + stats.getSwings() + ", TOTAL: " + ChatColor.WHITE + totalRatio + "/" + stats.getRatioAmount(), null, AlertPriority.LOW, stats.getCombatDangerLevel(), DetectionType.TEST);
- // reset the old swing/hit values for reusing
- stats.setHits(0);
- stats.setSwings(0);
- } else {
- // debug
- double ratio = ((double) stats.getHits()) / ((double) stats.getSwings());
- getOwner().castToAdmins(stats, "[combat] ratio " + ratio + ", " + stats.getHits() + "/" + stats.getSwings());
- }
Advertisement
Add Comment
Please, Sign In to add comment