1.8.8 GUI item actions in config

Discussion in 'Spigot Plugin Development' started by Lukacizek, Jan 14, 2022.

Thread Status:
Not open for further replies.
  1. In my post you have all the source code including an example. As for your "item utils", if you mean the ItemStack creation utils, you can use that as well.
     
  2. Code (Text):
    public ItemStack getQItemFromConfig(final FileConfiguration config, final String path, final PlaceholderReplacer loreReplacer) {
            ItemStack item;
            final ItemBuilder itemBuilder = new ItemBuilder(config.getString(path + ".Material", "BARRIER"), 1).setDurability(config.get(path + ".Durability", 0)).setGlow(config.getBoolean(path + ".Glow", false)).setName(config.getString(path + ".Name", "Invalid Name")).setLore(config.getStringList(path + ".Lore")).setSkull(config.getString(path + ".Skull", "")).setAmount(config.getInt(path + ".Amount", 1)).setColor(config.getInt(path + ".Color", 5));
            item = itemBuilder.parse();
            ItemMeta meta = item.getItemMeta();
            List<String> lore = meta.getLore();
            for (String string : lore) {
                if(loreReplacer != null){
                    meta.setLore(meta.getLore().stream()
                            .map(loreReplacer::parse)
                            .collect(Collectors.toList()));
                }
            }
            item.setItemMeta(meta);
            return item;
        }
    Code (Text):
    public Inventory getAM(final FileConfiguration config, final String path, final Player player, final PlaceholderReplacer loreReplacer) {
            Menu menu = new Menu(player,Commons.getInstance().getColorUtil().color(config.getString(path+".Title")),Integer.parseInt(config.getString(path+".Size")));
            Inventory gui = menu.createMenu();
            final ConfigurationSection menuSection = config.getConfigurationSection(path);
            for (String keys : config.getConfigurationSection(path + ".Borders").getKeys(false)) {
                ItemStack border = Commons.getInstance().getUtils().getItemFromConfig(config, path + ".Borders." + keys).parse();
                Iterator iterator = config.getIntegerList(path + ".Borders." + keys + ".Slots").iterator();
                while (iterator.hasNext()) {
                    int i = (Integer) iterator.next();
                    gui.setItem(i, border);
                }
            }
            final ConfigurationSection configItems = config.getConfigurationSection(path+".Items");
            configItems.getKeys(false).forEach(key -> {
                 ItemStack inventoryItem = getQItemFromConfig(config, path+".Items."+key, loreReplacer);
                 gui.setItem(config.getInt(path+".Items."+key+".Slot"), inventoryItem);
            });

            return gui;
        }
     
  3. The only difference will be that your method to create Inventory, returns GUI + there will be some changes in methods.
     
  4. Code (Java):
    package dev.minealert.utils;

    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;

    public class ItemBuilder {

        public static class Builder {

            private static Builder instance = null;

            public static Builder getInstance() {
                if(instance == null){
                    instance = new Builder();
                }

                return instance;
            }

            private Material material;

            private int amount;

            private byte id;

            private String name;

            private List<String> lore;

            private Map<Enchantment, Integer> enchantmentMap;

            public Builder itemType(Material material) {
                this.material = material;
                return this;
            }

            public Builder itemAmount(int amount) {
                this.amount = amount;
                return this;
            }

            public Builder itemID(byte id) {
                this.id = id;
                return this;
            }

            public Builder itemName(String name) {
                this.name = FormatUtils.color(name);
                return this;
            }

            public Builder itemLore(List<String> lores) {
                lore = lores.stream().map(FormatUtils::color).collect(Collectors.toList());
                return this;
            }

            public Builder itemEnchant(Map<Enchantment, Integer> enchants) {
                this.enchantmentMap = enchants;
                return this;
            }

            public ItemStack build() {
                ItemStack item;
                if (id != -1) {
                    item = new ItemStack(material, amount, id);
                } else {
                    item = new ItemStack(material, amount);
                }
                if (enchantmentMap != null) {
                    item.addUnsafeEnchantments(enchantmentMap);
                }
                ItemMeta meta = item.getItemMeta();
                if (meta != null) {
                    meta.setDisplayName(name);
                    meta.setLore(lore);
                }
                item.setItemMeta(meta);
                return item;
            }
        }
    }
    A simple item builder like this would just work fine with what @TheDevTec provided you.
     
    • Like Like x 1
    • Friendly Friendly x 1
  5. My builder is good enough
     
    • Funny Funny x 2
  6. So I'll write this one last time, either use my post or try to go through your... "code"... debug it and find bug.
    - StraikerinaCZ
     
  7. There is no bug do you guys even see whats the thread about
     
  8. I lost my last brain cell reading this
     
    • Agree Agree x 1
  9. Hii pace i remember you
     
  10. Man I am losing count for the amount of times of you demanding for big chunks of code. We're not here to spoon feed you an entire project as that is just silly of us to do, unless you're someone who likes doing that, but that is besides the point. The point I am making is all I've seen from you is high demand of code without any kind of testing, or show casing your work which is expected from someone who is asking for help. Asking for help is fine but being effortless is the problem.
     
  11. Dude i wanted an anwser to my simple question and you wanted me to change my whole code and make everything complicated
     
  12. The term “good” is subjective. You have to remember that there is always someone who can do things better than you. You may think you are good now, but 2 years from now, you are going to look back on your projects and see how bad they really were. (In terms of code)

    As @IceBlizzard__ has mentioned, you have been posting a lot for the past week which isn’t exactly “normal”. Usually people who post very frequently don’t know what they are doing and are relying on someone who will give them pieces of code to copy and paste. Just so they can hack together their idea.

    You’ve been given a pretty good solution to your issue, but refuse to take the help that you asked for in the first place. Seems a little counter-intuitive don’t you think?

    Regardless, what you are trying to achieve sounds very similar to what ChestCommands offers. Their config files have similar features to actions. Maybe give that a look if you don’t want to use the solution you have been offered.
     
    • Informative Informative x 1
  13. No, it is not chest commands,
    Either help or get out of the thread and stop wasting my time
     
  14. No more like providing solutions to your problem which simplifies it to make your life easier. You on the other hand: "No change is bad", will get you no where.
    Exactly!
     
    • Like Like x 1
  15. Someone else may understand what i want but you, no
     
    • Funny Funny x 4
  16. I give up!
    [​IMG]
     
    • Informative Informative x 1
  17. I would go back to this, just tweak it and it's a completely fully usable thing that will solve your problem.
     
  18. It wont, it will make all my menu creations 40 lines longer
     
    • Funny Funny x 3
  19. In terms meaning "Change is bad"
     
    • Funny Funny x 1
  20. Well then good luck getting help with this if you won’t take people’s advice under consideration.

    This is why I usually avoid 1.8 threads. Just thought I’d share how OPs idea sounded similar to chestcommands.
     
    • Funny Funny x 1
Thread Status:
Not open for further replies.