Event won't fire after first one

Discussion in 'Plugin Development' started by FreeMotion45, Nov 5, 2015.

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

    FreeMotion45

    Hello community.

    Today something very strange happened to me.
    I am trying to figure this out all day but I have no idea why this happens.
    The code is completely okay.
    I have researched over 3 hours, and my code is okay.
    Anyways. I have 2 inventory click events.
    First one :
    You run a command.
    You click an item.
    Another inventory pops up.
    You clicked another item.
    Something other happened.

    But the inventory click for the second inventory, which pops up after the first one won't fire.
    I tried to debug them, I seperated them into 2 inventory events, but it still won't work. Otherwise,
    If you open the second inventory before the first one, the event will fire normally.

    Any ideas what may cause it ?

    I will be able to print out code if needed.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Zombie_Striker

    First off, you shouldn't even HAVE two. You should only have on type of event per plugin.

    Secondly, even though you shouldn't have two events that are the same, they should work. This means that there is something wrong/missing from your code. This does not mean that you should try to fix that second event. You should move all the code from from the "not working" event to the "working" event.
     
  4. Offline

    FreeMotion45

    As already said, I have moved it back & forth, and again back & forth but nothing seemed to change.

    Also, I have placed an else statements for other if statements that I have that will send me a message that contains " This is wrong "

    But no message was sent.

    First event :

    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void oninvet(InventoryClickEvent e){
            Player p = (Player) e.getWhoClicked();
            p.updateInventory();
            if(ChatColor.stripColor(this.getConfig().getString("Warp.FuelGUITitle")).equalsIgnoreCase(e.getInventory().getName()) || ChatColor.stripColor(this.getConfig().getString("Warp.FuelGUITitle")).equalsIgnoreCase(e.getInventory().getTitle())){
                if(e.getCurrentItem().hasItemMeta()){
                    ItemStack sgp = new ItemStack(Material.STAINED_GLASS_PANE, (byte)1,(byte)5);
                    if(e.getCurrentItem() == sgp){
                        if(economy.has(p, 100)){
                            if(fivefuel.contains(p.getName())){
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Warp.FuelIsMaxiumumMessage")));
                                e.setCancelled(true);
                                return;
                            }
                            if(fourfuel.contains(p.getName())){
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Warp.PlayerSuccessfullyBoughtFuelMessage")));
                                economy.withdrawPlayer(p, 100);
                                p.closeInventory();
                                fivefuel.add(p.getName());
                                fuel(p);
                                return;
                               
                            }
                        }else{
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Warp.NotEnoughMoneyMessage")));
                            e.setCancelled(true);
                            return;
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.StartDriveIcon"))){
                        if(fivefuel.contains(p.getName())){
                            fivefuel.remove(p.getName());
                            fourfuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                        }
                        else if(fourfuel.contains(p.getName())){
                            fourfuel.remove(p.getName());
                            threefuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                            return;
                        }
                        else if(threefuel.contains(p.getName())){
                            threefuel.remove(p.getName());
                            twofuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                            return;
                        }
                        else if(twofuel.contains(p.getName())){
                            twofuel.remove(p.getName());
                            onefuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                            return;
                        }
                        else if(onefuel.contains(p.getName())){
                            onefuel.remove(p.getName());
                            zerofuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                            return;
                        }
                        else if(zerofuel.contains(p.getName())){
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Warp.NoFuelLeftMessage")));
                            e.setCancelled(true);
                            return;
                        }
                    }
                }
            }
        }
    Second event :

    Code:
        @EventHandler
        public void inve(InventoryClickEvent e){
            Player p = (Player) e.getWhoClicked();
            if(ChatColor.stripColor(this.getConfig().getString("Warp.GUITitle")) == e.getInventory().getName() || ChatColor.stripColor(this.getConfig().getString("Warp.GUITitle")) == e.getInventory().getTitle()){
                if(e.getCurrentItem().hasItemMeta()){
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.One.Icon"))){
                        if(p.hasPermission("carwarps.warpone")){
                            double x = this.getConfig().getDouble("Warp.One.X");
                            double y = this.getConfig().getDouble("Warp.One.Y");
                            double z = this.getConfig().getDouble("Warp.One.Z");
                            double yaw = this.getConfig().getDouble("Warp.One.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.One.Pitch");
                            String wl = this.getConfig().getString("Warp.One.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.One.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Two.Icon"))){
                        if(p.hasPermission("carwarps.warptwo")){
                            double x = this.getConfig().getDouble("Warp.Two.X");
                            double y = this.getConfig().getDouble("Warp.Two.Y");
                            double z = this.getConfig().getDouble("Warp.Two.Z");
                            double yaw = this.getConfig().getDouble("Warp.Two.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Two.Pitch");
                            String wl = this.getConfig().getString("Warp.Two.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Two.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Three.Icon"))){
                        if(p.hasPermission("carwarps.warpthree")){
                            double x = this.getConfig().getDouble("Warp.Three.X");
                            double y = this.getConfig().getDouble("Warp.Three.Y");
                            double z = this.getConfig().getDouble("Warp.Three.Z");
                            double yaw = this.getConfig().getDouble("Warp.Three.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Three.Pitch");
                            String wl = this.getConfig().getString("Warp.Three.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Three.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Four.Icon"))){
                        if(p.hasPermission("carwarps.warpfour")){
                            double x = this.getConfig().getDouble("Warp.Four.X");
                            double y = this.getConfig().getDouble("Warp.Four.Y");
                            double z = this.getConfig().getDouble("Warp.Four.Z");
                            double yaw = this.getConfig().getDouble("Warp.Four.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Four.Pitch");
                            String wl = this.getConfig().getString("Warp.Four.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Four.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Five.Icon"))){
                        if(p.hasPermission("carwarps.warpfive")){
                            double x = this.getConfig().getDouble("Warp.Five.X");
                            double y = this.getConfig().getDouble("Warp.Five.Y");
                            double z = this.getConfig().getDouble("Warp.Five.Z");
                            double yaw = this.getConfig().getDouble("Warp.Five.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Five.Pitch");
                            String wl = this.getConfig().getString("Warp.Five.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Five.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Six.Icon"))){
                        if(p.hasPermission("carwarps.warpsix")){
                            double x = this.getConfig().getDouble("Warp.Six.X");
                            double y = this.getConfig().getDouble("Warp.Six.Y");
                            double z = this.getConfig().getDouble("Warp.Six.Z");
                            double yaw = this.getConfig().getDouble("Warp.Six.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Six.Pitch");
                            String wl = this.getConfig().getString("Warp.Six.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Six.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Seven.Icon"))){
                        if(p.hasPermission("carwarps.warpseven")){
                            double x = this.getConfig().getDouble("Warp.Seven.X");
                            double y = this.getConfig().getDouble("Warp.Seven.Y");
                            double z = this.getConfig().getDouble("Warp.Seven.Z");
                            double yaw = this.getConfig().getDouble("Warp.Seven.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Seven.Pitch");
                            String wl = this.getConfig().getString("Warp.Seven.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Seven.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Eight.Icon"))){
                        if(p.hasPermission("carwarps.warpeight")){
                            double x = this.getConfig().getDouble("Warp.Eight.X");
                            double y = this.getConfig().getDouble("Warp.Eight.Y");
                            double z = this.getConfig().getDouble("Warp.Eight.Z");
                            double yaw = this.getConfig().getDouble("Warp.Eight.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Eight.Pitch");
                            String wl = this.getConfig().getString("Warp.Eight.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Eight.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Nine.Icon"))){
                        if(p.hasPermission("carwarps.warpnine")){
                            double x = this.getConfig().getDouble("Warp.Nine.X");
                            double y = this.getConfig().getDouble("Warp.Nine.Y");
                            double z = this.getConfig().getDouble("Warp.Nine.Z");
                            double yaw = this.getConfig().getDouble("Warp.Nine.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Nine.Pitch");
                            String wl = this.getConfig().getString("Warp.Nine.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Nine.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                }
            }
        }
     
  5. Offline

    timtower Administrator Administrator Moderator

    @FreeMotion45 Is the title the same? Is the event registred? Is the event even running regardless of the checks that you are making? Are you aware that you can't compare strings using == ?
     
  6. Offline

    FreeMotion45

    The title is the same, the event IS registered, the event is running and it seems to work if I am running the second inventory event first.
     
  7. Offline

    timtower Administrator Administrator Moderator

    @FreeMotion45 Are they in the same class?
    Till where are the checks doing what they should be?
     
  8. Offline

    FreeMotion45

    They are in the same class.

    The checks are doing everything normally. And good.

    I placed else statement to check that.
    But if I inverted those then it would say my custom message. ( My Message is " Error is here " )
     
  9. Offline

    timtower Administrator Administrator Moderator

    @FreeMotion45 Did you change your string checking from == to equals already?
     
  10. Offline

    FreeMotion45

    To equalsIgnoreCase.
     
  11. Offline

    timtower Administrator Administrator Moderator

    Also good: see till where you checks get and why till that point, all I can do for today as it is time for bed here.
     
  12. Offline

    FreeMotion45

    I checked already and it all works fine. It is really strange why this won't work.
    If anybody has any idea why this happens.

    Thanks timtower for the help, I will continue checking what is wrong.
     
  13. Offline

    Zombie_Striker

    I'm not saying to move the code back and forth. I'm saying to keep both bits of code in the SAME method.

    Now, after you moved both bits of code into the same method, you must debug. At what line does it not work? Does is even get triggered (does it print out a message if System.out is the first line?)
     
  14. Offline

    FreeMotion45

    Yes it does.

    I was testing such things many many times.

    Every part of the code works
     
  15. Offline

    Scimiguy

    Ah good, can you mark the thread as solved then please?
     
  16. Offline

    FreeMotion45

    No, I can not. Because this problem is not solved.

    If I fire second inventory event first it works fine.
    If I fire it after first inventory event it doesn't work.

    Thats what strange....
     
  17. Offline

    Scimiguy

    Ok, so we're on the same, clean page; can you re-post your entire class please?
     
  18. Offline

    Zombie_Striker

    wat.

    How can it all work, and not even run? One of those posts are wrong.
     
  19. Offline

    FreeMotion45

    I don't know, something really strange is happening.
     
  20. Offline

    mcdorli

    Sorry for offtopic, but this is the first clue to finding, where timtower lives.
     
  21. Offline

    timtower Administrator Administrator Moderator

    No, it has not.
    Debug debug debug, see why it runs, and then why it stops running.
     
  22. Offline

    FreeMotion45

    Okay, so I got this now :

    BOTH events are just not working for the second inventory at all for some reason.

    I placed a p.sendMessage("Clicked");

    On both events.
    On Inv 1 = It said twice.
    On Inv 2 = Said Nothing.
     
  23. Offline

    timtower Administrator Administrator Moderator

  24. Offline

    FreeMotion45

    If you mean that I added it to test, then yes.
     
  25. Offline

    timtower Administrator Administrator Moderator

    No more as in could you post your updated code.
     
  26. Offline

    Zombie_Striker

    @FreeMotion45
    Aslo, post the WHOLE class(s), It will help seeing how your plugin is arranged.
     
  27. Offline

    FreeMotion45

    I can not post the whole class because it is more than 1000 lines....

    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void inve(InventoryClickEvent e){
            Player p = (Player) e.getWhoClicked();
            if(ChatColor.stripColor(this.getConfig().getString("Warp.GUITitle")).equalsIgnoreCase(e.getInventory().getName()) || ChatColor.stripColor(this.getConfig().getString("Warp.GUITitle")).equalsIgnoreCase(e.getInventory().getTitle())){
                p.sendMessage("Fine title");
                if(e.getCurrentItem().hasItemMeta()){
                    p.sendMessage("Fine item");
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.One.Icon"))){
                        p.sendMessage("Fine item checl");
                        if(p.hasPermission("carwarps.warpone")){
                            p.sendMessage("Fine perm");
                            double x = this.getConfig().getDouble("Warp.One.X");
                            double y = this.getConfig().getDouble("Warp.One.Y");
                            double z = this.getConfig().getDouble("Warp.One.Z");
                            double yaw = this.getConfig().getDouble("Warp.One.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.One.Pitch");
                            String wl = this.getConfig().getString("Warp.One.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.One.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Two.Icon"))){
                        if(p.hasPermission("carwarps.warptwo")){
                            double x = this.getConfig().getDouble("Warp.Two.X");
                            double y = this.getConfig().getDouble("Warp.Two.Y");
                            double z = this.getConfig().getDouble("Warp.Two.Z");
                            double yaw = this.getConfig().getDouble("Warp.Two.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Two.Pitch");
                            String wl = this.getConfig().getString("Warp.Two.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Two.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Three.Icon"))){
                        if(p.hasPermission("carwarps.warpthree")){
                            double x = this.getConfig().getDouble("Warp.Three.X");
                            double y = this.getConfig().getDouble("Warp.Three.Y");
                            double z = this.getConfig().getDouble("Warp.Three.Z");
                            double yaw = this.getConfig().getDouble("Warp.Three.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Three.Pitch");
                            String wl = this.getConfig().getString("Warp.Three.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Three.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Four.Icon"))){
                        if(p.hasPermission("carwarps.warpfour")){
                            double x = this.getConfig().getDouble("Warp.Four.X");
                            double y = this.getConfig().getDouble("Warp.Four.Y");
                            double z = this.getConfig().getDouble("Warp.Four.Z");
                            double yaw = this.getConfig().getDouble("Warp.Four.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Four.Pitch");
                            String wl = this.getConfig().getString("Warp.Four.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Four.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Five.Icon"))){
                        if(p.hasPermission("carwarps.warpfive")){
                            double x = this.getConfig().getDouble("Warp.Five.X");
                            double y = this.getConfig().getDouble("Warp.Five.Y");
                            double z = this.getConfig().getDouble("Warp.Five.Z");
                            double yaw = this.getConfig().getDouble("Warp.Five.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Five.Pitch");
                            String wl = this.getConfig().getString("Warp.Five.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Five.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Six.Icon"))){
                        if(p.hasPermission("carwarps.warpsix")){
                            double x = this.getConfig().getDouble("Warp.Six.X");
                            double y = this.getConfig().getDouble("Warp.Six.Y");
                            double z = this.getConfig().getDouble("Warp.Six.Z");
                            double yaw = this.getConfig().getDouble("Warp.Six.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Six.Pitch");
                            String wl = this.getConfig().getString("Warp.Six.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Six.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Seven.Icon"))){
                        if(p.hasPermission("carwarps.warpseven")){
                            double x = this.getConfig().getDouble("Warp.Seven.X");
                            double y = this.getConfig().getDouble("Warp.Seven.Y");
                            double z = this.getConfig().getDouble("Warp.Seven.Z");
                            double yaw = this.getConfig().getDouble("Warp.Seven.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Seven.Pitch");
                            String wl = this.getConfig().getString("Warp.Seven.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Seven.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Eight.Icon"))){
                        if(p.hasPermission("carwarps.warpeight")){
                            double x = this.getConfig().getDouble("Warp.Eight.X");
                            double y = this.getConfig().getDouble("Warp.Eight.Y");
                            double z = this.getConfig().getDouble("Warp.Eight.Z");
                            double yaw = this.getConfig().getDouble("Warp.Eight.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Eight.Pitch");
                            String wl = this.getConfig().getString("Warp.Eight.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Eight.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.Nine.Icon"))){
                        if(p.hasPermission("carwarps.warpnine")){
                            double x = this.getConfig().getDouble("Warp.Nine.X");
                            double y = this.getConfig().getDouble("Warp.Nine.Y");
                            double z = this.getConfig().getDouble("Warp.Nine.Z");
                            double yaw = this.getConfig().getDouble("Warp.Nine.Yaw");
                            double pitch = this.getConfig().getDouble("Warp.Nine.Pitch");
                            String wl = this.getConfig().getString("Warp.Nine.World");
                            World world = Bukkit.getServer().getWorld(wl);
                            if(world == null){
                                p.sendMessage(colorize(this.getConfig().getString("Warp.MessageWarpDoesntExist")));
                                e.setCancelled(true);
                                return;
                            }
                            Location wo = new Location(world, x, y, z, (float)yaw, (float)pitch);
                            p.teleport(wo);
                            p.sendMessage(colorize(this.getConfig().getString("Warp.Nine.Message")));
                            p.closeInventory();
                            return;
                        }else{
                            p.sendMessage(colorize(this.getConfig().getString("Warp.NoPermissionMessage")));
                        }
                    }
                }
            }
        }

    Second event :

    Code:
    @SuppressWarnings("deprecation")
        @EventHandler
        public void oninvet(InventoryClickEvent e){
            Player p = (Player) e.getWhoClicked();
            p.updateInventory();
            if(ChatColor.stripColor(this.getConfig().getString("Warp.FuelGUITitle")).equalsIgnoreCase(e.getInventory().getName()) || ChatColor.stripColor(this.getConfig().getString("Warp.FuelGUITitle")).equalsIgnoreCase(e.getInventory().getTitle())){
                if(e.getCurrentItem().hasItemMeta()){
                    ItemStack sgp = new ItemStack(Material.STAINED_GLASS_PANE, (byte)1,(byte)5);
                    if(e.getCurrentItem() == sgp){
                        if(economy.has(p, 100)){
                            if(fivefuel.contains(p.getName())){
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Warp.FuelIsMaxiumumMessage")));
                                e.setCancelled(true);
                                return;
                            }
                            if(fourfuel.contains(p.getName())){
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Warp.PlayerSuccessfullyBoughtFuelMessage")));
                                economy.withdrawPlayer(p, 100);
                                p.closeInventory();
                                fivefuel.add(p.getName());
                                fuel(p);
                                return;
                               
                            }
                        }else{
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Warp.NotEnoughMoneyMessage")));
                            e.setCancelled(true);
                            return;
                        }
                    }
                    if(e.getCurrentItem().getType() == Material.getMaterial(this.getConfig().getInt("Warp.StartDriveIcon"))){
                        if(fivefuel.contains(p.getName())){
                            fivefuel.remove(p.getName());
                            fourfuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                        }
                        else if(fourfuel.contains(p.getName())){
                            fourfuel.remove(p.getName());
                            threefuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                            return;
                        }
                        else if(threefuel.contains(p.getName())){
                            threefuel.remove(p.getName());
                            twofuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                            return;
                        }
                        else if(twofuel.contains(p.getName())){
                            twofuel.remove(p.getName());
                            onefuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                            return;
                        }
                        else if(onefuel.contains(p.getName())){
                            onefuel.remove(p.getName());
                            zerofuel.add(p.getName());
                            p.closeInventory();
                            warpGUI(p);
                            return;
                        }
                        else if(zerofuel.contains(p.getName())){
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Warp.NoFuelLeftMessage")));
                            e.setCancelled(true);
                            return;
                        }
                    }
                }
            }
        }
     
  28. Offline

    Zombie_Striker

    @FreeMotion45
    OMG THE D.R.Y ABUSE. (Don't Repeat Yourself)

    Since the only thing that changes in each if statement (for first), you should have something like "Warp."+number+".X" to get the X, instead of having 8 lines that would do the same thing.

    Also, I see you're using "return" a lot. This means the rest of the method will not be read. Since you want to have two things happen, you should have do/while loops that you can "break" out of. That way, you can stop one without stopping the other.

    Again, as I said, before KEEP THEM TOGETHER. They both use the same event, so they should be inside the same method.

    TL.DR: Clean up redundancies, and add do/while loops, replace return with break, and KEEP IT TOGETHER!
     
  29. Offline

    FreeMotion45

    Yes, I know what return means.

    But this is not the point. ( Thanks for the tips though :) )
    Because the second event still works If I open that inv first.
     
  30. Offline

    mcdorli

    1000 line? A warp plugin. Let me check... Yeah, currently, my java openGl project, wich renders a 3d model, add lighting and shadows, is (with the shaders too) 1256 lines.
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page