Macro Spamming

Discussion in 'Plugin Development' started by leet4044, Aug 24, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    leet4044

    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<PlayerplantFreeze = new ArrayList<Player>();
        public static 
    ArrayList<MaterialdisallowedBlocks = 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)) < || p.getLocation().distance(SettingsManager.getBombSiteB(Game.gameID)) < && 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 && p.getTargetBlock(null2).getType() != Material.AIR && p.getTargetBlock(null2).getType() == Material.REDSTONE_BLOCK && p.getItemInHand().getType() == Material.WOOD_SWORD) {
                                                    
    p.sendMessage("Planting in: " planttime);
                                                    
    planttime--;
                                                } else {
                                                    
    Bukkit.broadcastMessage("Planted Bomb");
                                                    if (
    p.getTargetBlock(null2).getType() != Material.AIR && p.getTargetBlock(null2).getType() == Material.REDSTONE_BLOCK) {
                                                        
    Bukkit.getScheduler().cancelTask(planttid);
                                                        
    p.getTargetBlock(null1).getX();
                                                        
    p.getTargetBlock(null1).getY();
                                                        
    p.getTargetBlock(null1).getZ();
                                                        
    Location loc = new Location(p.getWorld(), xyz);
                                                        
    loc.getBlock().setTypeIdAndData(44, (byte6false);
                                                        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);
                                                    }
                                                }
                                            }
                                        }, 
    020);
                                    }
                                    
    checktid Bukkit.getScheduler().scheduleSyncRepeatingTask(MCCS.getInstance(), new Runnable() {
                                        public 
    void run() {
                                            if (
    planttime 0) {
                                                if (!
    p.isBlocking() || p.getTargetBlock(null2).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);
                                                }
                                            }
                                        }
                                    }, 
    05);
                                }
                            }, 
    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.
     
    Last edited by a moderator: Jun 10, 2016
  2. Offline

    Regablith

  3. Offline

    leet4044

    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.
     
  4. Offline

    Regablith

    Add a cooldown or the event?
     
Thread Status:
Not open for further replies.

Share This Page