Help With Configs And GUI Actions

Discussion in 'Spigot Plugin Development' started by Karatechimp29, May 9, 2015.

  1. for those of you who may not understand, here is what i want to do:

    Main Class:
    Code (Text):
    package me.karatechimp29.bukkit;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    public class Main extends JavaPlugin implements Listener{
        public void onEnable()
            this.getServer().getPluginManager().registerEvents((Listener) new VoteMenu(), this);
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
                if(sender instanceof Player)
                    Player player = (Player) sender;
            return false;

    Gui Class:
    Code (Text):
    package me.karatechimp29.bukkit;

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

    public class VoteMenu {
        static void openGUI(Player player)
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.GOLD + "Vote Menu");
            ItemStack Rewards = new ItemStack(Material.WRITTEN_BOOK);
            ItemMeta RewardsMeta = Rewards.getItemMeta();
            ItemStack Link1 = new ItemStack(Material.DIAMOND);
            ItemMeta Link1Meta = Link1.getItemMeta();
            ItemStack Link2 = new ItemStack(Material.DIAMOND);
            ItemMeta Link2Meta = Link1.getItemMeta();
            ItemStack Link3 = new ItemStack(Material.DIAMOND);
            ItemMeta Link3Meta = Link3.getItemMeta();
            ItemStack Link4 = new ItemStack(Material.DIAMOND);
            ItemMeta Link4Meta = Link4.getItemMeta();
            ItemStack Link5 = new ItemStack(Material.DIAMOND);
            ItemMeta Link5Meta = Link5.getItemMeta();
            ItemStack About = new ItemStack(Material.WRITTEN_BOOK);
            ItemMeta AboutMeta = About.getItemMeta();
            RewardsMeta.setDisplayName(ChatColor.AQUA + "Rewards");
            Link1Meta.setDisplayName(ChatColor.YELLOW + "Vote #1");
            Link2Meta.setDisplayName(ChatColor.YELLOW + "Vote #2");
            Link3Meta.setDisplayName(ChatColor.YELLOW + "Vote #3");
            Link4Meta.setDisplayName(ChatColor.YELLOW + "Vote #4");
            Link5Meta.setDisplayName(ChatColor.YELLOW + "Vote #5");
            AboutMeta.setDisplayName(ChatColor.AQUA+ "About");
            inv.setItem(0, Rewards);
            inv.setItem(2, Link1);
            inv.setItem(3, Link2);
            inv.setItem(4, Link3);
            inv.setItem(5, Link4);
            inv.setItem(6, Link5);
            inv.setItem(8, About);
        public void onClick(InventoryClickEvent ev){
            if(ev.getInventory() != null){
                // We now know that an inventory slot was clicked.
                if(ev.getInventory().getSize() == 9){
                    // We now know that the inventory that was clicked has 9 slots, so it's the same size as your custom one.
                    if(ev.getInventory().getTitle().equals(ChatColor.GOLD + "Vote Menu")){
                        // We now know that the clicked inventory is the same size and title as your custom inventory.
                        // This means we are probably dealing with your inventory and can do stuff now.
                        ev.setCancelled(true); // This cancels the normal reaction to that click.
                        // ev.getRawSlot() returns which slot was clicked, 0 being the first slot. In this case, there are slots 0 - 8.
                        // These are the same numbers you used with setItem() when building the inventory.
                        if(ev.getRawSlot() == 0){
                        else if(ev.getRawSlot() == 1){


    Code (Text):
    # Post Your 1st Vote Page Here (URL)
    Link1: Vote Link #1

    # Post Your 2nd Vote Page Here (URL)
    Link2: Vote Link #2

    # Post Your 3rd Vote Page Here (URL)
    Link3: Vote Link #3

    # Post Your 4th Vote Page Here (URL)
    Link4: Vote Link #4

    # Post Your 5th Vote Page Here (URL)
    Link5: Vote Link #5
    i want the gui "diamonds" to display a message to the player when the "button" is clicked. but read the message to send to player from the config "Link1" and so forth...
  2. Would doing it if someone clicks on a itemstack for example Vote 1 and then do stuff but I don't get your message. What is the problem here ?
  3. ok so where i have "if(ev.getRawSlot() == 0)" i basically want it to first send the player a message that is read from that config file. for example i would put a url with "Vote1: <URL HERE>" from the config and send that in the message to the player...
    • Agree Agree x 1
  4. What is exactly you want? I mean you kinda told us what you want to do but not what is not working / what you do not know how to do

    Grabbing Strings from a config? Look here and here on how to use configs and then grabbing a Value from it
  5. The think is, their is no "problem" the case is I simply don't know how to get it to read a string from my config and use it in selected areas
  6. Then read the two links I provided. They give you the answers you are looking for
    • Agree Agree x 1
  7. Thanks, will do!

    (please lock thread)
  8. one last thing, how can i get a lore on my items?
  9. Check if the click is valid, it will return -1 if the inventory is clicked but a slot wont.
    if(e.getSlot() == -1){
    cancel event
  10. item.getItemMeta().getLore() returns a List<String>.