Util Mineplex Shop Menu's

Discussion in 'Resources' started by sethrem, Feb 18, 2015.

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

    sethrem

    Hello,
    Since I'm basically done with Bukkit and most things Minecraft related because I got back into developing Rsps's I thought it would be nice if I released something to the community. This is nothing special so yea here it is.

    Pictures
    Pictures (open)

    Sample Picture Of Sample Code:
    [​IMG]


    The Code:
    Code:
    package me.menus;
    
    import java.util.Arrays;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    /**
    *
    * @author Seth Davis <[email protected]>
    *
    */
    
    public abstract class Shopmenu implements Listener {
    
        public abstract void onConfirmClick(Player p);
     
        private JavaPlugin plugin;
        private Material itemMaterial;
        private int gemPrice;
        private int inventoryStackSize;
        private Inventory inv;
        private String inventoryName = "            Confirmation";
        public ItemStack ok, cancel, price, item;
        private String itemName;
        private String[] itemLore;
     
        public Shopmenu(Material itemMaterial, int gemPrice, int inventoryStackSize, JavaPlugin plugin, String itemName, String... itemLore) {
            this.setItemMaterial(itemMaterial);
            this.setGemPrice(gemPrice);
            this.setInventoryStackSize(inventoryStackSize);
            this.setPlugin(plugin);
            this.setItemName(itemName);
            this.setItemLore(itemLore);
            createInventory();
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
     
        public void createInventory() {
            this.inv = plugin.getServer().createInventory(null, 54, inventoryName);
            this.inv.setMaxStackSize(inventoryStackSize);
            ok = createItem(Material.EMERALD_BLOCK, ChatColor.GREEN + "OK");
            cancel = createItem(Material.REDSTONE_BLOCK, ChatColor.RED + "CANCEL");
            price = createItem(Material.DIAMOND, ChatColor.GREEN + "" + ChatColor.BOLD + "Gems");
            item = createItem(getItemMaterial(), ChatColor.GREEN + "" + ChatColor.BOLD + getItemName());
            buildInvSquare();
        }
     
        private ItemStack createItem(Material mat, String name) {
            ItemStack i = new ItemStack(mat, 1);
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(name);
            if (name.equalsIgnoreCase(ChatColor.GREEN + "" + ChatColor.BOLD + "Gems"))
            im.setLore(Arrays.asList(ChatColor.GRAY + "" + gemPrice + " Gems will be deducted from your account balance."));
            if (name.equalsIgnoreCase(ChatColor.GREEN + "" + ChatColor.BOLD + getItemName()))
            im.setLore(Arrays.asList(getItemLore()));
            i.setItemMeta(im);
            return i;
        } 
     
        public void buildInvSquare() {
            inv.setItem(4, price);
            inv.setItem(22, item);     
            int ok = 27;
            for (int i = 0; i <9; i++) {
                if (i == 3) ok = 36;
                if (i == 6) ok = 45;
                inv.setItem(ok++, this.ok);
            }     
            int no = 33;
            for (int i = 0; i < 9; i++) {
                if (i == 3) no = 42;
                if (i == 6) no = 51;
                inv.setItem(no++, this.cancel);
            }
        }
     
        @EventHandler
        public void onClick(InventoryClickEvent e) {
            if (e.getInventory().getMaxStackSize() == getInventoryStackSize()) {
                Player p = (Player) e.getWhoClicked();
                e.setCancelled(true);
                if (!e.getInventory().getName().equalsIgnoreCase(getInventoryName()))
                    return;
                if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR || !e.getCurrentItem().hasItemMeta()) {
                    e.setCancelled(true);
                    p.closeInventory();
                    return;
                }
                if (ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase("ok")) {
                    e.setCancelled(true);
                    onConfirmClick(p);
                    p.closeInventory();
                }
                if (ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase("cancel")) {
                    e.setCancelled(true);
                    p.closeInventory();
                }     
            }
        }
     
        public String getLowGemMsg() {
            return ChatColor.BLUE + "Kit> " + ChatColor.GRAY + "You do not have enough" + ChatColor.GREEN + " Gems"     + ChatColor.GRAY + ".";
        }
    
        public Material getItemMaterial() {
            return itemMaterial;
        }
    
        public void setItemMaterial(Material itemMaterial) {
            this.itemMaterial = itemMaterial;
        }
    
        public int getGemPrice() {
            return gemPrice;
        }
    
        public void setGemPrice(int gemPrice) {
            this.gemPrice = gemPrice;
        }
    
        public int getInventoryStackSize() {
            return inventoryStackSize;
        }
    
        public void setInventoryStackSize(int inventoryStackSize) {
            this.inventoryStackSize = inventoryStackSize;
        }
    
        public String getInventoryName() {
            return inventoryName;
        }
    
        public void setInventoryName(String inventoryName) {
            this.inventoryName = inventoryName;
        }
    
        public JavaPlugin getPlugin() {
            return plugin;
        }
    
        public void setPlugin(JavaPlugin plugin) {
            this.plugin = plugin;
        }
    
        public String[] getItemLore() {
            return itemLore;
        }
    
        public void setItemLore(String[] itemLore) {
            this.itemLore = itemLore;
        }
    
        public String getItemName() {
            return itemName;
        }
    
        public void setItemName(String itemName) {
            this.itemName = itemName;
        }
     
        public Inventory getInv() {
            return inv;
        }
     
    }
    

    Sample Code (open)

    Code:
    package me.menus;
    
    import me.DeathTag;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    
    /**
    *
    * @author Seth Davis <[email protected]>
    *
    */
    
    public class Testinv extends Shopmenu {
    
        public Testinv() {
            super(Material.BONE, 2000, 1005, DeathTag.plugin, "Bone Man!", ChatColor.AQUA + "He Can Kill With His Bone!", ChatColor.GOLD + "Next Line");
        }
    
        @Override
        public void onConfirmClick(Player p) {
            p.sendMessage("Your a boss!");
        }
     
        public void showInv(Player p) {
            p.openInventory(getInv());
        }
    
    }
    


    Disclaimer: I know this isn't a very good way to do this so that's why I released it and also because I made a better system for doing this. So yea just enjoy don't hate.

    Enjoy Everyone. Sethrem Out :D
     
    Last edited: Feb 18, 2015
  2. Offline

    ProStriker123

  3. Offline

    sethrem

  4. Offline

    xTrollxDudex

    So you made two versions and released the one that wasn't as good....?
     
    Hawktasard and Avygeil like this.
  5. Offline

    sethrem

    @xTrollxDudex Well the other version is not not a "Single Class" it is hooked into my mysql system which is hooked to my minigames plugin which has custom events which is called when you buy kits like in mineplex, so yea basically the other one is rather a system not a "Util". So yea <3.
     
    Last edited: Feb 19, 2015
Thread Status:
Not open for further replies.

Share This Page