Icon Menu

Discussion in 'Resources' started by nisovin, Oct 30, 2012.

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

    xCyanide

    Compressions
    This will fix your problem, event.setWillDestroy(true);
     
  2. Offline

    Compressions

    TheNokar likes this.
  3. Offline

    ZeusAllMighty11



    I had this issue, but as stated by Compressions , destroying the inventory will destroy the listener and create a new one each time. Not really efficient, but it works
     
  4. Offline

    Theodossis

    I am having a problem. When the player closes the menu without clicking anything, the next time he clicks the code will be executed 2 times.
    Code:
    Code:java
    1. @Override
    2. public void openMenuAt(final Player p) {
    3. IconMenu menu = new IconMenu(ChatColor.DARK_PURPLE + "Quick Teleporter", 9, new IconMenu.OptionClickEventHandler() {
    4. @Override
    5. public void onOptionClick(OptionClickEvent e) {
    6. e.setWillDestroy(true);
    7. if(e.getPosition() == 0) {
    8. Bukkit.dispatchCommand(p, "server raid");
    9. return;
    10. }
    11. else{
    12. e.setWillClose(true);
    13. }
    14. e.setWillClose(true);
    15. }
    16. }, PGLobby.getInstance())
    17. .setOption(0, new ItemStack(Material.REDSTONE), ChatColor.RED + "PowredGaming Raid", "Teleport to " + ChatColor.RED + "PoweredGaming Raid");
    18. menu.open(p);
    19. }

    Thanks,
    Theodossis
     
  5. Offline

    MisterErwin

    Theodossis: That's because you've generated the iconmenu 2 times!

    I would create an IconMenu in onEnable and just open it to the players!

    (Or have fun coding a Manager for that ;) )
     
  6. Offline

    Theodossis

    What do you mean?
     
  7. Offline

    MisterErwin

    Theodossis:
    Code:
    public class myPlugin extends JavaPlugin {
    IconMenu im;
     
    public void onEnable(){
      this.im = new IconMenu(...); //create new menu
    }
     
    public void open(Player p){
      this.im.open(p);
    }
     
    }
    ;)
     
  8. Offline

    Theodossis

    Is there anyway to fix it with my current code?
    Thanks,
    Theodossis
     
  9. Offline

    MisterErwin


    This should work:
    Code:
    public class <plugin> extends JavaPlugin{
     
    public IconMenu menu;
     
    public void onEnable(){
      //create the menu
      this.menu = new IconMenu(ChatColor.DARK_PURPLE + "Quick Teleporter", 9, new IconMenu.OptionClickEventHandler() {
                @Override
                public void onOptionClick(OptionClickEvent e) {
                    e.setWillDestroy(true);
                    if(e.getPosition() == 0) {
                        Bukkit.dispatchCommand(p, "server raid");
                        return;
                    }
                    else{
                        e.setWillClose(true);
                    }
                    e.setWillClose(true);
                }
            }, PGLobby.getInstance())
            .setOption(0, new ItemStack(Material.REDSTONE), ChatColor.RED + "PowredGaming Raid", "Teleport to " + ChatColor.RED + "PoweredGaming Raid");
    }
     
    public void opemMenuat(Player p){
      //Open the menu
      this.menu.open(p)
    }
     
    }
    ;)
     
    Theodossis likes this.
  10. Offline

    Theodossis

    Thank you so much :D
     
  11. Offline

    moose517

    would it be possible to get like the crafting grid? not just an inventory screen like i've seen?
     
  12. Offline

    Quantum64

    This is super awesome stuff! So glad to have this and not need some super complicated/glitchy api like MenuService. Have to do abit of work on it because I want dynamic menu content, but it looks great!
     
  13. Offline

    Goblom

    IconMenu is great an all but in my opinion is missing some much needed documentation. Like, how do we get slot clicked or item clicked, & what each method returns...
     
    timtower likes this.
  14. Offline

    CraftBang

    Does anyone know how to edit the iconmenu name from another function ?
    you can do items in the inventory but not the name?
     
  15. Offline

    timtower Administrator Administrator Moderator

    Only way to do this is by recreating a menu every time
     
  16. Offline

    CraftBang

    timtower yes I found that out by the time xD, but thanks for your response :)
     
    timtower likes this.
  17. Offline

    Goblom

    timtower CraftBang Although that is how you have to do it with the code that nisovin has on the main post. Doesnt mean its the only way to do that ;)

    In my Manager GUI plugin i customized the IconMenu so that i can edit the size, name & data of the IconMenu AFTER the IconMenu is created. Here is the code to do so, but, i do have to warn you. It might bug out sometimes.

    Here is what i added to IconMenu.class
    Code:java
    1.  
    2. /*
    3.  * Reset all options that have been added to the IconMenu.
    4.  * This does not affect IconMenu size or name.
    5. */
    6. public IconMenu resetOptions() {
    7. this.optionNames = new String[this.size];
    8. this.optionIcons = new ItemStack[this.size];
    9. }
    10.  
    11. /*
    12.  * Lets change the name of our IconMenu
    13.  */
    14. public void updateName(String name) {
    15. this.name = name;
    16. }
    17. public String getName() {
    18. return this.name;
    19. }
    20.  
    21. /*
    22.  * Lets Update the size of our IconMenu
    23.  */
    24. public void updateSize(int size) {
    25. this.size = size;
    26. }
    27. public int getSize() {
    28. return this.size;
    29. }
     
  18. Offline

    CraftBang

    Goblom , I guess I'll use the safe way than. Anyway thanks for your share!
    I might try it out thanks :p
     
  19. Offline

    TekkitSense

    i have an error at }, plugin) My code
    Code:java
    1. import org.bukkit.Material;
    2. import org.bukkit.command.Command;
    3. import org.bukkit.command.CommandSender;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.EventPriority;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13.  
    14. public class Main extends JavaPlugin implements Listener{
    15.  
    16.  
    17. @Override
    18. public void onEnable(){
    19. getLogger().info("myplugin has been Enabled.");
    20. }
    21.  
    22. @Override
    23. public void onDisable(){
    24. getLogger().info("myplugin has been Disabled.");
    25. }
    26.  
    27. IconMenu menu = new IconMenu("My Fancy Menu", 9, new IconMenu.OptionClickEventHandler() {
    28. @Override
    29. public void onOptionClick(IconMenu.OptionClickEvent event) {
    30. event.getPlayer().sendMessage("You have chosen " + event.getName());
    31. event.setWillClose(true);
    32. }
    33. }, plugin)
    34. .setOption(3, new ItemStack(Material.APPLE, 1), "Food", "The food is delicious")
    35. .setOption(4, new ItemStack(Material.IRON_SWORD, 1), "Weapon", "Weapons are for awesome people")
    36. .setOption(5, new ItemStack(Material.EMERALD, 1), "Money", "Money brings happiness");
    37.  
    38. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    39. Player user = (Player) sender;
    40. if(cmd.getName().equalsIgnoreCase("test")){
    41. menu.open(user);
    42. return true;
    43. }
    44. return false;
    45. }
    46.  
    47. }
     
  20. Offline

    timtower Administrator Administrator Moderator

    TekkitSense Hover your mouse over it, it will tell you where
     
  21. Offline

    Goblom

    TekkitSense You have not yet initialized the "plugin" variable and since you are putting the menu in your main class you can just replace ", plugin)" with ", this)"

    Doing that would fix your error.
     
  22. Offline

    TekkitSense

    Thanks! Also how would i go about making a menu open another menu?
     
  23. Offline

    Goblom

    TekkitSense Learn Runnables ;) and Java. That should do it
     
  24. Offline

    CraftBang

    Goblom I have a wierd thing, so I made 2 menus, I open up one and than the other.
    The problem is WITHOUT a delay between it it won't open (it does but closes like in 1 ms xD)
    So I made a task for 5 ticks, than it does open but just very wierd, the first one if I press the item just goes crazy!

    My code :
    Code:
    public class MoneyGenerator implements Listener {
    ChatColor p = ChatColor.GOLD;
    ChatColor b = ChatColor.AQUA;
    ChatColor bo = ChatColor.BOLD;
    //INVENTORYS
    IconMenu GoldGen1 = new IconMenu(ChatColor.GOLD + "Gold Generator 1", 9, new IconMenu.OptionClickEventHandler() {
            @Override
            public void onOptionClick(IconMenu.OptionClickEvent event) {
           if(event.getName().contains(ChatColor.GOLD + "Upgrade")){
          event.getPlayer().sendMessage(p + "You upgraded (TEST)");
           }
            }
        }, Main.plugin);
     
    IconMenu goldmenu = new IconMenu(ChatColor.GOLD + "Gold Generators", 9, new IconMenu.OptionClickEventHandler() {
            @Override
            public void onOptionClick(IconMenu.OptionClickEvent event) {
           if(event.getName().contains(ChatColor.GOLD + "Gold Generator 1")){
           final Player playerr = event.getPlayer();
           Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable(){
            public void run() {
            GoldGen1.open(playerr);
         playerr.sendMessage("HOOOO");
            }
         }
         , 5L);
           }
            }
        }, Main.plugin);
     
     
     
        @EventHandler
    public void onPlayerInteract(final PlayerInteractEvent e) {
       int levelgen1 = 1;
     
       if(e.getAction() == Action.RIGHT_CLICK_AIR && e.getPlayer().getItemInHand().getType() == Material.FURNACE || e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getPlayer().getItemInHand().getType() == Material.FURNACE){
       if(e.getPlayer().getItemInHand().getItemMeta().getLore().contains(p + "Gold Generators!") || e.getPlayer().getItemInHand().getItemMeta().getLore().contains(ChatColor.DARK_PURPLE + "SoulBound")){
       goldmenu.setOption(0, new ItemStack (Material.FURNACE), ChatColor.GOLD + "Gold Generator 1", ChatColor.AQUA + "Level : " + levelgen1);
       GoldGen1.setOption(1, new ItemStack (Material.FURNACE), ChatColor.GOLD + "Upgrade", ChatColor.AQUA + "Level : " + levelgen1);
       
       goldmenu.open(e.getPlayer());
       
       e.setCancelled(true);
       
       }
       }
        }
    }
    
     
  25. Offline

    bobacadodl

    Not sure if you're being sarcastic or not...
    But if you know basic java, just look through the class.... there's not much to it.
    If you're good enough to understand making bukkit plugins, you should be able to understand this.
     
    Garris0n and timtower like this.
  26. Offline

    Goblom

    As stated, it is missing documentation, i did not mention that i do not know how to do something. I also stated this as an opinion regarding other people who are wanting to make something with this.

    PS. Have you looked at my signature... Im 9001% sure i know enough about Bukkit plugins and IconMenu...

    CraftBang Try adding a event.setWillClose(true); before you create the delayed task.
     
  27. Offline

    CraftBang

    Goblom I just tested some things, and it automaticly closes when I click on the item.
    So I tried to do setwillclose false. Now it duplicates the item on a very buggy way..
    Is it possible to fix this?
     
  28. Offline

    Reddcola

  29. Offline

    HeavyMine13

    how can I make a player dispatch a command when he chooses option 1?
     
  30. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page