Is this a good way to make a menu?

Discussion in 'Spigot Plugin Development' started by TheDarkPlay, Jul 14, 2018.

Thread Status:
Not open for further replies.
  1. Hello, I would like to know if the way I made my menu, is a good way, or there are unnecessary or wrong things in it, I would like tips to improve if possible ...

    Code (Java):
    package com.ziixs.beatrankup.menus;

    import java.util.ArrayList;
    import java.util.List;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryCloseEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    import com.ziixs.beatrankup.Main;
    import com.ziixs.beatrankup.utils.YMLConfig;

    public class ggg implements Listener {

        private static Main plugin = Main.getPlugin();
        private static YMLConfig config = plugin.getConfig();

        Inventory inv;
        Player p;

        public ggg(Player p) {
            this.p = p;

            inv = Bukkit.createInventory(null, 6*9, ChatColor.translateAlternateColorCodes('&', config.getString("RanksMenu.Nome")));
            ItemStack rankup = new ItemStack(Material.EMERALD, 1);
            ItemMeta rankupmeta = rankup.getItemMeta();
            rankupmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getString("RanksMenu.RankUP.Nome")));
            List<String> newlore2 = new ArrayList<String>();
            for (String s : config.getStringList("RanksMenu.RankUP.Lore")) {
                newlore2.add(ChatColor.translateAlternateColorCodes('&', s));
            inv.setItem(50, rankup);
            plugin.getServer().getPluginManager().registerEvents(this, plugin);

        public void abrir() {
            p.playSound(p.getLocation(), Sound.ORB_PICKUP, 10, 1);

        public void onPlayerClick(InventoryClickEvent e) {
            if (e.getWhoClicked() instanceof Player) {
                if (e.getInventory().equals(inv)) {
                    if (e.getClickedInventory().equals(inv)) {
                        if (e.getSlot() == 50) {

        public void onPlayerClose(InventoryCloseEvent e) {
            if (e.getPlayer() == p && e.getInventory().equals(inv)) {


                try {
                } catch (Throwable e1) {

  2. What's wrong with 54

    Regarding the rest
    I'd honestly save these config values as variables on startup / restart / config reload (and so on) so you can load these in in that way, rather than making your server go into your configuration file to look it up every single time, it's not as efficient ^^
  3. Ah yes, this is a good tip, but I did this class to use variables (replace), for each player, for example money, etc ...
  4. I don't get what you're trying to tell me here

    EDIT: Actually, as I said, you should make variables for these
    Sounds as if you're making it per-player
  5. Actually, when you do config.get(str), you don't look at the actual file, but the parsed object version of it in memory.
    But, it also does take time to search for the value of the specified key, so it could be more efficient by storing each value in a unique variable.
  6. 6*9 is faster, hahaha
  7. Which is what I tried to say, thanks :wink:

    Excuse me?
Thread Status:
Not open for further replies.