svdragster

nobreakdelay

Oct 27th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. // We're inside the PlayerInteractEvent, make sure to check if event.getAction() is LEFT_CLICK_BLOCK or whatever it's called
  2.  
  3. /*
  4.  * NoBreakDelay
  5.  */
  6.  
  7. if (!player.getGameMode().equals(GameMode.CREATIVE)) {
  8.    
  9.     // Make sure that the currently clicked block and the last destroyed block aren't blocks that you can destroy instantly or almost instantly
  10.     if (event.getClickedBlock() != null && stats.getLastBlock() != null && Useful.isSemiSolid(event.getClickedBlock()) && Useful.isSolid(stats.getLastBlock())) {
  11.        
  12.         // Get the difference of now and the last broken block time
  13.         // Pretty much results in the time from breaking the last block and clicking a new block
  14.         double diff = System.currentTimeMillis() - stats.getBlockDestroyHook();
  15.        
  16.         DelayCheck:
  17.         if (diff <= 50) {
  18.            
  19.             // Make sure his item doesn't have efficiency
  20.             // I believe the Haste Potion effect alone does not create false positives, but you might want to double check that
  21.             ItemStack hand = player.getItemInHand();
  22.             if (hand != null) {
  23.                 if (hand.containsEnchantment(Enchantment.DIG_SPEED) && hand.getEnchantmentLevel(Enchantment.DIG_SPEED) >= 3) {
  24.                     break DelayCheck;
  25.                 }
  26.             }
  27.            
  28.             // Threshold stuff
  29.             stats.setClickDelayLevel(stats.getClickDelayLevel() + 5);
  30.             if (stats.getClickDelayLevel() > 10) {
  31.                
  32.                 // DangerLevel stuff
  33.                 stats.setBuildDangerLevel(stats.getBuildDangerLevel() + 50);
  34.                 if (stats.getBuildDangerLevel() > 200) {
  35.                     stats.setBlockDestroying(1000);
  36.                 }
  37.                 getOwner().alert(player, player.getName() + ": Tried to click block too quickly after breaking another one (" + diff + ")", null, AlertPriority.LOW, stats.getBuildDangerLevel(), DetectionType.CLICK_DELAY);
  38.                 event.setCancelled(true);
  39.                 stats.setClickDelayLevel(10);
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment