I have a PlayerInteractEvent that will glitch whenever a player macro or spam clicks it. How would I fix it? Code: PHP: int x; int y; int z; int planttid = 0; int checktid = 1; int planttime = 5; public static ArrayList<Player> plantFreeze = new ArrayList<Player>(); public static ArrayList<Material> disallowedBlocks = new ArrayList<Material>(); public static Location bombLocation; @EventHandler public void planting(PlayerInteractEvent e) { final Player p = e.getPlayer(); Block b = e.getClickedBlock(); if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (b.getType() == Material.REDSTONE_BLOCK && p.getItemInHand().getType() == Material.WOOD_SWORD) { if (p.getLocation().distance(SettingsManager.getBombSiteA(Game.gameID)) < 7 || p.getLocation().distance(SettingsManager.getBombSiteB(Game.gameID)) < 7 && Game.isInWarmup == false) { if (Game.terrorist.contains(p)) { Bukkit.getScheduler().scheduleSyncDelayedTask(MCCS.getInstance(), new Runnable() { public void run() { if (p.isBlocking()) { plantFreeze.add(p); planttime = 5; Bukkit.getScheduler().cancelTask(planttid); planttid = Bukkit.getScheduler().scheduleSyncRepeatingTask(MCCS.getInstance(), new Runnable() { public void run() { if (planttime > 0 && p.getTargetBlock(null, 2).getType() != Material.AIR && p.getTargetBlock(null, 2).getType() == Material.REDSTONE_BLOCK && p.getItemInHand().getType() == Material.WOOD_SWORD) { p.sendMessage("Planting in: " + planttime); planttime--; } else { Bukkit.broadcastMessage("Planted Bomb"); if (p.getTargetBlock(null, 2).getType() != Material.AIR && p.getTargetBlock(null, 2).getType() == Material.REDSTONE_BLOCK) { Bukkit.getScheduler().cancelTask(planttid); x = p.getTargetBlock(null, 1).getX(); y = p.getTargetBlock(null, 1).getY(); z = p.getTargetBlock(null, 1).getZ(); Location loc = new Location(p.getWorld(), x, y, z); loc.getBlock().setTypeIdAndData(44, (byte) 6, false); if (p.getInventory().getItemInHand().getAmount() > 1) p.getInventory().getItemInHand().setAmount(p.getInventory().getItemInHand().getAmount() - 1); else p.setItemInHand(null); bombLocation = loc; Game.bombCountdown(35); Game.isbombPlanted = true; plantFreeze.remove(p); } } } }, 0, 20); } checktid = Bukkit.getScheduler().scheduleSyncRepeatingTask(MCCS.getInstance(), new Runnable() { public void run() { if (planttime > 0) { if (!p.isBlocking() || p.getTargetBlock(null, 2).getType() != Material.REDSTONE_BLOCK || !(p.getItemInHand().getType() == Material.WOOD_SWORD)) { Bukkit.getScheduler().cancelTask(planttid); Bukkit.getScheduler().cancelTask(checktid); Bukkit.broadcastMessage("Player stopped planting bomb"); plantFreeze.remove(p); } } } }, 0, 5); } }, 1); } } } } } When the player macros it it will start spamming the last broadcast in the event. (Player stopped planting bomb) meaning the task isnt being cancelled but idk why EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Regablith Okay, So. the event works fine. But if a player uses a macro or spams right click. It will glitch and it will start spamming (Player stop planting bomb) And I don't know why. That's my problem because it will break the entire game.