svdragster

ratio

Oct 27th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1. // inside PlayerAnimationEvent -> PlayerAnimationType.ARM_SWING
  2.  
  3. // get the difference between the last two animation hooks
  4. long diffHook = System.currentTimeMillis() - stats.getArmSwingAnimationHook();
  5. if (diffHook < 400) {
  6.     stats.setSwings(stats.getSwings() + 1);
  7. } else {
  8.     stats.setHits(stats.getHits() - 1);
  9.     if (stats.getHits() < 0) {
  10.         stats.setHits(0);
  11.     }
  12. }
  13.  
  14.  
  15.  
  16. /*
  17.  *inside of the DamageEvent
  18.  */
  19.  
  20. // check if the enemy has moved enough to prevent false positives
  21. if (lastMob != null && lastMob.equals(mob)) {
  22.     double distance = mob.getLocation().distance(lastMob.getLocation());
  23.     if (distance <= 0.05 && attacker.getLocation().distance(mob.getLocation()) <= 1.0) {
  24.         getOwner().castToAdmins(stats, "[combat] " + ChatColor.GREEN + "(ratio#) enemy has not moved enough ");
  25.         stats.setSwings(stats.getSwings() - 1);
  26.     } else {
  27.         stats.setHits(stats.getHits() + 1);
  28.     }
  29. }
  30.  
  31. // make sure this value won't be negative
  32. if (stats.getSwings() < 0) {
  33.     stats.setSwings(0);
  34. }
  35.  
  36. // if the player has done 12 hits in total, we generate a ratio
  37. if (stats.getHits() >= 12 && !event.isCancelled()) {
  38.     ChatColor color1 = ChatColor.GRAY;
  39.     ChatColor color2 = ChatColor.DARK_GRAY;
  40.     stats.setRatioAmount(stats.getRatioAmount() + 1);
  41.    
  42.     // Create the ratio. As far as my testing went, a legit player will maximally get the ratio up to 0.24,
  43.     // RARELY to maximally 0.3. Haven't seen a value above this yet except with cheats.
  44.     double ratio = ((double) stats.getHits()) / ((double) stats.getSwings());
  45.    
  46.     // 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
  47.     double totalRatio = (ratio + stats.getRatio()) / stats.getRatioAmount();
  48.     stats.setRatio(stats.getRatio() + ratio);
  49.    
  50.     // if we've recorded a total of more than 15 ratios
  51.     if (stats.getRatioAmount() >= 15) {
  52.        
  53.         // check if the ratio is too high
  54.         if (totalRatio >= 0.27 && ratio >= 0.27) {
  55.            
  56.             // the user is apparently cheating, preventing dealing damage n' stuff
  57.            
  58.             stats.addCombatDangerLevel(65);
  59.             event.setCancelled(true);
  60.             if (ratio >= 0.45) {
  61.                 stats.addCombatDangerLevel(45);
  62.                 color1 = ChatColor.RED;
  63.                 color2 = ChatColor.DARK_RED;
  64.             } else {
  65.                 color1 = ChatColor.YELLOW;
  66.                 color2 = ChatColor.GOLD;
  67.             }
  68.             if (stats.getCombatDangerLevel() > 1500) {
  69.                 stats.setBlockDamage(7500);
  70.                 addBanDangerLevel(stats, 4, 2);
  71.             } else if (stats.getCombatDangerLevel() > 500) {
  72.                 stats.setBlockDamage(4000);
  73.             } else if (stats.getCombatDangerLevel() > 150) {
  74.                 stats.setBlockDamage(1500);
  75.             }
  76.         }
  77.     }
  78.    
  79.     // I'm currently just printing out info to check what ratios the players are hitting at
  80.     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);
  81.    
  82.     // reset the old swing/hit values for reusing
  83.     stats.setHits(0);
  84.     stats.setSwings(0);
  85. } else {
  86.     // debug
  87.     double ratio = ((double) stats.getHits()) / ((double) stats.getSwings());
  88.     getOwner().castToAdmins(stats, "[combat] ratio " + ratio + ", " + stats.getHits() + "/" + stats.getSwings());
  89. }
Advertisement
Add Comment
Please, Sign In to add comment