GUI only showing kits you have perms for

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, Nov 8, 2014.

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

    Fhbgsdhkfbl

    Hey bukkit forums, I'm currently working on a kitpvp plugin, and I have a GUI, but I only want it to show the kits you have access to in the GUI, instead of all the kits showing up.

    How would I go about doing that?

    I do have an enum for permissions, and I use it for my kitlist, I just don't know I would do it with the GUI
    Thanks!
     
  2. Offline

    teej107

    pseudo code.
    Code:
    for loop through kits/kit permissions
    if player has kit permission
    add kit to inventory.
     
  3. Offline

    Fhbgsdhkfbl

    teej107
    Now, how would I add it to the next open spot between, lets say 10-53 since my first line is used for something else.
     
  4. Offline

    teej107

    start the for loop at 10. stop at 53
     
  5. Offline

    BeefySticks

    Or you could just add the item when the player opens the inventory.
     
  6. Offline

    Fhbgsdhkfbl

    teej107 BeefySticks

    I need specific items with the names of the kits, Idk how I would have different items for each kit.
     
  7. Offline

    BeefySticks

  8. Offline

    Fhbgsdhkfbl

    BeefySticks
    I know how to make a GUI, but this is a different way I'm trying to do it.
     
  9. Offline

    BeefySticks


    I don't get what you are trying to do?
    Just make a look checking if they have permission.

    Such as

    Code:java
    1. if(player.hasPermission("mymom.com")) {
    2. mymom.addItem(new ItemStack(Material.GLASS));
     
  10. Offline

    Fhbgsdhkfbl

    BeefySticks
    You want me to do that, with over 50 permission nodes?
     
  11. Offline

    BeefySticks

    Erm, that's pretty much the only way to do it. You can find shortcuts such as:
    Code:java
    1. if(player.hasPermission("mymom.com") || player.hasPermission("mymom.net")) {
    2. mymom.addItem(new ItemStack(Material.GLASS));

    Also I really don't understand why would you have over 50 permission nodes? How else would you expect to do this? Sometimes you have to take the long way.
     
  12. Offline

    Fhbgsdhkfbl

    BeefySticks
    Would I do a for loop for only 10 - 53 slots?
     
  13. Offline

    BeefySticks

    I mean you could, or just keep adding the item.
     
  14. Offline

    Fhbgsdhkfbl

    BeefySticks
    Code:java
    1. for(int i = 10; i < 53; i++) {
    2. if(p.hasPermission("k.knight")) {
    3. ItemStack knight = new ItemStack(Material.DIAMOND_SWORD);
    4. ItemMeta knightmeta = knight.getItemMeta();
    5. knightmeta.setDisplayName(ChatColor.GOLD + "Knight Kit");
    6. kits.addItem(knight);
    7. }
    8. }

    So basically like this?

    edit:
    http://gyazo.com/034670ca2b0cfcc24d8a1ecaa939135c
    that did not work. xD
     
  15. Offline

    BeefySticks

    Of course it didn't work. What your doing is getting every slot in the inventory that is not null and adding a diamond sword to it.
     
  16. Offline

    Fhbgsdhkfbl

    BeefySticks
    So, how would I get slot 10, add the item, and if they have access to a different kit, add the kit to the next slot.
     
  17. Offline

    BeefySticks

    Code:java
    1. kits.setItem(9, knight);


    Sorry for late responses! Working on a minigame :p
     
  18. Offline

    Fhbgsdhkfbl

    BeefySticks
    Sir, if they don't have permission for that kit, and the next one, it will be uneven.

    if they have kits.(11, archer);

    it will be completely uneven. that's why if they have permission for one kit and it's at like 53, I need it to be at 10
     
  19. Offline

    BeefySticks

    The only way I can think of right now is setting the slots you don't want to items to go to as a item or a changing item :/
     
  20. Offline

    iMurder

    Fhbgsdhkfbl
    Make a int, starting at 10, add to it each time you add a item, and for the next time, set the next item slot to that int.
     
  21. Offline

    BeefySticks


    Code:java
    1. int lol = 10;
    2. mymom.setItem(lol+1, Material.GLASS);

    Like that?
     
  22. Offline

    Fhbgsdhkfbl

    iMurder
    Isn't that what I kind of did?
     
  23. Offline

    teej107

    Loop through all your kits (I assume you keep them in a collection, if not, use one) and check their permission, add them to a separate collection, then loop through the separate collection and add the kits to the inventory.
     
  24. Offline

    Fhbgsdhkfbl

    Yes, I have an enum of all my kits into one class, the question is, how would I get items of them?
     
  25. Offline

    iMurder

    Fhbgsdhkfbl
    For checking, but it would still set it to whatever slot it's checking.

    BeefySticks
    More or less yeah.
     
  26. Offline

    teej107

    Fhbgsdhkfbl Define items. ItemStacks? Don't you have a getter method to get an "item" for your enum?
     
  27. Offline

    Fhbgsdhkfbl

  28. Offline

    teej107

    Fhbgsdhkfbl Well then I also have the same question.
    How would you if you don't have a method to get any?
     
  29. Offline

    Fhbgsdhkfbl

    teej107
    How would I make the getter for ItemStack for the inventoryclickevent?
    Here's an example of my kit enum
    Code:
    Knight {
            public void give(Player p ) {
                Utils.clearInv(p);
                PlayerInventory inv = p.getInventory();
                ItemStack pvp = new ItemStack(Material.DIAMOND_SWORD);
                pvp.addEnchantment(Enchantment.DAMAGE_ALL, 1);
                inv.addItem(pvp);
                inv.setHelmet(new ItemStack(Material.IRON_HELMET));
                inv.setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
                inv.setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                inv.setBoots(new ItemStack(Material.IRON_BOOTS));
                Utils.giveSoup(p);
            }
            public String getPermission() {
                return "k.knight";
            }
            public String getName() {
                return "Knight";
            }
        };
     
    public abstract void give(Player p);
        public abstract String getPermission();
        public abstract String getName();
     
    }
     
  30. Offline

    teej107

    Fhbgsdhkfbl The same way you make the getters for the permissions and the name.
     
Thread Status:
Not open for further replies.

Share This Page