Code for StaffGUI

Discussion in 'Plugin Development' started by TheMinecraftKnight, Apr 30, 2016.

Thread Status:
Not open for further replies.
  1. I'm making a staff GUI plugin that means when you do /staff a gui pops up with all the staff online. You can right click the staff's heads to insert /msg [name] into the chat. But... I have no idea what the code for a GUI is, can someone tell me please?
     
  2. Offline

    Gonmarte

    We are not going to give you code. If you are looking for it, you shoud ask it on Plugin Requests section.
    What have you done so far? If nothing, i suggest you google about creating inventories in bukkit. There is also many resources about that.
     
  3. Err... thanks?
    Is there meant to be a separate class for the actual GUI?

    Got some code, messed around with it a bit and got.... This
    Code:
    package com.knightzmc.staffgui;
    
    
    import org.bukkit.plugin.java.JavaPlugin;
    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.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class Staff extends JavaPlugin {
    
    
    
        public boolean onCommand(CommandSender sender,
                Command command,
                String label,
                String[] args) {
            if (command.getName().equalsIgnoreCase("staff")) {
                    return true;
    
    
                openGUI(sender);
    
    
            return false;}
            return true;}
    
       
    
    
           
       
    
    
    
        private void openGUI(CommandSender senderCommandSender) {
    
              Inventory inv = Bukkit.createInventory(null, 54, ChatColor.GREEN
    
                    + "Warp Selector");
    
    
          ItemStack KnightzYT = new ItemStack(Material.EMERALD_BLOCK);
    
            ItemMeta KnightzYTMeta = KnightzYT.getItemMeta();
    
    
            inv.setItem(0, KnightzYT);
    
          }}
    
     
    
    
    
    Any help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 30, 2016
  4. Offline

    mine-care

    @TheMinecraftKnight Please fix your code indentation to make it more readable.
    What is the problem? Where do you need our help?

    The outline as i imagine it is:
    1. open an inventory to the player that contains heads of staff members
    2. listen to InventoryClickEvent and when a head is clicked, perform some action.

    What else?
     
  5. That's exactly what what what what what what what whq
    That's exactly want, it should look a bit like this:
    [​IMG]
    I have no idea how to do it though :/
     
  6. Offline

    mine-care

  7. In this bit
    Code:
          openGUI(sender);
    
    it says Unreachable code

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Apr 30, 2016
  8. Offline

    mine-care

    Please learn Java before bukkit. Its required, and without it simple mistakes are made.

    Here you return, and then try to do something that obviously isnt happening since the method is terminated.
     
  9. Offline

    Zombie_Striker

    Or if I fix the formatting for your code
    Code:
        if (command.getName().equalsIgnoreCase("staff")) {
     return true;
      openGUI(sender);
      return false;
    }
    
    Do you see the problem now?
     
  10. EDIT: PART OF YOUR POST DIDN'T SHOW UP. GOING TO EAT DINNER AND REPLY SOON

    My code is now this:
    Code:
    package com.knightzmc.staffgui;r
    
    
    
    
    
    
    
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    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.inventory.Inventory;
    
    import org.bukkit.inventory.ItemStack;
    
    import org.bukkit.inventory.meta.ItemMeta;
    
    
    
    
    public class Main extends JavaPlugin {
    
    
    
    
    
    
    
    
    
    
        public boolean onCommand(CommandSender sender,
    
                Command command,
    
                String label,
    
                String[] args) {
    
            if (command.getName().equalsIgnoreCase("staff")) {
                return true;
    
    
    
    
    
                 openGUI(sender);
    
    
    
    
                return false;}}
          
    
    
    
     
    
    
    
    
    
    
    
         
    
     
    
    
    
    
    
    
    
    
    
    
        private void openGUI(CommandSender senderCommandSender) {
    
    
    
    
              Inventory inv = Bukkit.createInventory(null, 54, ChatColor.GREEN
    
    
    
    
                    + "Warp Selector");
    
    
    
    
    
    
    
          ItemStack KnightzYT = new ItemStack(Material.EMERALD_BLOCK);
    
    
    
    
            ItemMeta KnightzYTMeta = KnightzYT.getItemMeta();
    
    
    
    
    
    
    
            inv.setItem(0, KnightzYT);
    
    
          }}
    
    
    
    I followed your instructions, yet there's still something wrong?
     
  11. Offline

    Zombie_Striker

    @TheMinecraftKnight
    Does not seem like it. You are returning to soon. Please:
    Please learn Java, and then come back to bukkit. You cannot do bukkit before/while you are learning Java, as learning Java first prevents you from making simple mistakes, such as this one. Please take a week (that's all you need) to learn Java and come back to bukkit after that. You should know what the problem is/how to fix it after that. Here are some tutorials where you can learn Java.
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/
     
    TheMinecraftKnight and mine-care like this.
  12. Offline

    Gonmarte

    1 week??
    Sinse when you learn java within one week?
    (IMO)It should take at least one month.
     
  13. Offline

    mine-care

    @Gonmarte Actually it depends on the person. But it is absolutely possible to learn the basics in a week if you are enaged. Having the basic knowledge means you can continue learning in a much faster pace and much more efficiently and fix minor mistakes along the way. Doesn't mean that in a week you would know everything whatsoever.

    Also considering that for some it is now the easter break from school/work that makes it even easyer ;)
     
Thread Status:
Not open for further replies.

Share This Page