Solved GUI click makes code execute +1 everytime I click it

Discussion in 'Plugin Development' started by mehboss, Mar 19, 2017.

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

    mehboss

    Every time I click the item [slot 4] to ban the player using my GUI. Everything is normal, it closes the GUI, there are no errors, it shows the particles and bans the player. However, the second time I do it, it doubles the messages, doubles the particles, and bans the player two times. The third time doing it, it does the messages three times, does the particles three times, and bans the player three times, and so on for every time I do it. When I reload the server, it goes back to only doing it once. Does anyone know why? If you're confused and you need me to explain it better, I'll explain it more doing the best I can.
    PHP:
            if ((event.getInventory().getHolder() instanceof BanGUI2) && (event.getCurrentItem() != null)
                    && (
    event.getCurrentItem().getType() != Material.AIR)) {

                
    Player player = (Playerevent.getWhoClicked();

                if (
    event.getSlot() == 4) {

                    
    event.setCancelled(true);
                    
    event.getWhoClicked().closeInventory();

                    if (
    Animation.pl.hasPermission("essentials.tempban.exempt")) {
                        
    player.sendMessage(ChatColor.DARK_RED "You may not tempban that player.");
                        return;
                    }

                    
    int highest Animation.pl.getLocation().getWorld().getHighestBlockYAt(Animation.pl.getLocation());
                    
    double vel Animation.pl.getVelocity().getY() + 300;

                    
    Location newloc = new Location(Animation.pl.getWorld(), Animation.pl.getLocation().getX(), highest 1,
                            
    Animation.pl.getLocation().getZ(), Animation.pl.getLocation().getPitch(),
                            
    Animation.pl.getLocation().getYaw());

                    
    player.getWorld().playSound(player.getLocation(), Sound.EXPLODE11);
                  
                    
    Animation.pl.teleport(newloc);
                    
    Animation.pl.setFlying(false);
                    
    Animation.pl.setVelocity(Animation.pl.getVelocity().setY(vel));
        
    //shoots the player into the air

                    
    new BukkitRunnable() {

                        public 
    void run() {
                            
    Animation.pl.setFlying(true);
                            
    runHelix(Animation.pl.getLocation(), Animation.pl);

                            
    Animation.pl.sendMessage(
                                    
    ChatColor.translateAlternateColorCodes('&'"&c&l&oYou have been caught hacking!"));

                            if (!
    ban.contains(Animation.pl.getName())) {
                                
    ban.add(Animation.pl.getName());
        
    //runnable that does the particles
                            
    }
                        }
                    }.
    runTaskLater(Bukkit.getPluginManager().getPlugin("BanAnimation"), 35L);

                    new 
    BukkitRunnable() {

                        public 
    void run() {

                            if (
    ban.contains(Animation.pl.getName())) {
                                
    ban.remove(Animation.pl.getName());
                            }

                            if (
    Animation.usermenutempban.contains(Animation.pl.getName())) {
                                
    Animation.usermenutempban.remove(Animation.pl.getName());
                            }

                            
    player.performCommand("essentials:tempban " Animation.pl.getName() + " " clicked splitdone
                                    
    " " Menu.name);
          
    //runnable that bans the player
                        
    }
                    }.
    runTaskLater(Bukkit.getPluginManager().getPlugin("BanAnimation"), 125L);
     
  2. Offline

    Zombie_Striker

    @mehboss
    Do you have any for or while loops in this event that may be interacting with this bit of code?Its the only thing I can think of that would cause this.
     
  3. Offline

    mehboss

    @Zombie_Striker
    For-Loops only to set the items in the GUI, not in the interact event though. Any other ideas?

    I may accidentally be re-registering the event every time I open the GUI. I'll look at the code tomorrow, although I don't think I am.


    Sent from my iPhone using Tapatalk
     
  4. Offline

    mehboss

    It was indeed re-registering the event everytime the GUI was opened, whoops!
     
  5. Offline

    mehboss

    @Zombie_Striker
    bump + this problem still persists; however, it only does it when I do it on something else, not when I do it on myself. This is weird because the same code runs for both... Could this be server lag or a spigot/bukkit version bug?
     
  6. Offline

    Zombie_Striker

    @mehboss
    Can you post the code for doing it to someone else? What is the difference between those two cases?
     
  7. Offline

    mehboss

    @Zombie_Striker
    There is no difference... that's the thing. The same code runs because it is needed to have another argument in the command to even open the GUI, the argument would be a player name either way.

    All the for-loops are closed before they reach this point. I have breaks on some for-loops when I want to break out.. Nothing could cause this.

    Maybe lag?
     
    Last edited: Mar 24, 2017
Thread Status:
Not open for further replies.

Share This Page