Problem with IconMenu

Discussion in 'Plugin Development' started by skipperguy12, Jun 25, 2013.

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

    skipperguy12

    Hello! I'm trying to make a server selector GUI using the IconsMenu class posted in the resource section. I got it all to work, except there's one tiny problem: It sends 1 more message every time you click on an icon.

    Here's my code:
    Code:Java
    1. private BungeeBookUtils BungeeBookUtils = new BungeeBookUtils();
    2. private IconMenu serversmenu;
    3.  
    4. private IconMenu.OptionClickEventHandler clickeventhandler = new IconMenu.OptionClickEventHandler() {
    5. @Override
    6. public void onOptionClick(IconMenu.OptionClickEvent event) {
    7. event.getPlayer().sendMessage(ChatColor.DARK_PURPLE + " " + event.getName());
    8. // TODO: Use the Bungee API in BungeeBookUtils.java
    9. // to actually try and teleport the player
    10. event.setWillClose(true);
    11. }
    12. };
    13.  
    14.  
    15. private void updateMenuInfo(IconMenu menu) {
    16. serversmenu = new IconMenu(ChatColor.AQUA + "" + ChatColor.BOLD + "HungerGames Servers", 9, clickeventhandler, Database.get()).setOption(0, new ItemStack(Material.DIAMOND_SWORD, 1), ChatColor.AQUA + "" + ChatColor.BOLD + "0", "0")
    17.  
    18. .setOption(1, new ItemStack(Material.DIAMOND_SWORD, 1), ChatColor.AQUA + "" + ChatColor.BOLD + "1", "1")
    19. .setOption(2, new ItemStack(Material.DIAMOND_SWORD, 1), ChatColor.AQUA + "" + ChatColor.BOLD + "2", "2");
    20. }
    21.  
    22. @EventHandler(priority = EventPriority.MONITOR)
    23. public void onPlayerInteract(PlayerInteractEvent event) {
    24. // Check if the player is holding a stick
    25. if (event.getItem() != null && event.getItem().getType() == Material.STICK) {
    26. updateMenuInfo(serversmenu);
    27. event.getPlayer().closeInventory();
    28. serversmenu.open(event.getPlayer());
    29. }
    30. }
    31. }


    I did remove a lot of code before posting this, because it is repetitive, so if something looks like it won't work and it's a blatant error that has nothing to do with the messages, it's not actually a problem in my real code.

    Does anyone know why I get 1 more message every time? I'd assume it's me making multiple OptionClickEventHandlers, but when I made sure I only made the Handler once, it still didn't work.

    One more thing, if anyone knows how I can use the BungeeCord API to switch a players server, please help me! I'd love to save some time, I already tried, but to no success.

    Solved the first problem (replicating items) by setting it to destroy itself.

    Does anyone have a solution to problem 2?
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
Thread Status:
Not open for further replies.

Share This Page