How to open this gui with a Command

Discussion in 'Plugin Development' started by TheLittleDeveloper, Jan 27, 2015.

Thread Status:
Not open for further replies.
  1. Hello,
    can someone help me with this?????

    I want to open this gui with a command this a part of the code:

    Code:
    package nl.mcw;
    
    import nl.mcw.Main;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.ItemFrame;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public abstract class Menu
      implements Listener, CommandExecutor
    {
               
      public static Inventory Menu = Bukkit.createInventory(null, 9, ChatColor.GOLD + "Menu Besturing");
     
      @EventHandler
      public void onClick(PlayerInteractEntityEvent e)
      {
        if ((e.getRightClicked() instanceof ItemFrame))
        {
          ItemFrame frame = (ItemFrame)e.getRightClicked();
          ItemStack item = frame.getItem();
          if (item == null)
          {
            e.setCancelled(true);
            return;
          }
          if ((item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "Besturing Menu")) && (
            (e.getPlayer().hasPermission("mct.bestuur.Menu")) || (e.getPlayer().hasPermission("mct.bestuur.*"))))
          {
            e.setCancelled(true);
            Main.createItem(Material.STAINED_CLAY, 13, 1, Menu, 0, ChatColor.GOLD + "Vrijgeven", "Start de Menu");
            Main.createItem(Material.STAINED_CLAY, 13, 1, Menu, 2, ChatColor.GOLD + "Poortjes", "Open/sluit de poortjes");
            Main.createItem(Material.STAINED_CLAY, 13, 1, Menu, 4, ChatColor.GOLD + "Ingang", "Open/sluit de ingang");
            if (MenuConfig.getCustomConfig().contains("Menu"))
            {
              boolean Menustatus = MenuConfig.getCustomConfig().getBoolean("Menu.open");
              boolean Menuvrijgeven = MenuConfig.getCustomConfig().getBoolean("Menu.starten");
              boolean Menupoortjes = MenuConfig.getCustomConfig().getBoolean("Menu.poortjes");
              if (Menustatus)
              {
                Main.createItem(Material.STAINED_CLAY, 13, 1, Menu, 4, ChatColor.GOLD + "Ingang", "Sluit de ingang");
                e.getPlayer().openInventory(Menu);
              }
              else
              {
                Main.createItem(Material.STAINED_CLAY, 14, 1, Menu, 4, ChatColor.GOLD + "Ingang", "Open de ingang");
                e.getPlayer().openInventory(Menu);
              }
              if (Menuvrijgeven) {
                Main.createItem(Material.STAINED_CLAY, 13, 1, Menu, 0, ChatColor.GOLD + "Vrijgeven", ChatColor.GREEN + "Toegestaan!");
              } else {
                Main.createItem(Material.STAINED_CLAY, 14, 1, Menu, 0, ChatColor.GOLD + "Vrijgeven", ChatColor.RED + "Afgewezen!");
              }
              if (Menupoortjes) {
                Main.createItem(Material.STAINED_CLAY, 13, 1, Menu, 2, ChatColor.GOLD + "Poortjes", "Sluit de poortjes");
              } else {
                Main.createItem(Material.STAINED_CLAY, 14, 1, Menu, 2, ChatColor.GOLD + "Poortjes", "Open de poortjes");
              }
            }
          }
        }
      }
      @EventHandler
      public void onClick(InventoryClickEvent e)
      {
        Player p = (Player)e.getWhoClicked();
        if (e.getInventory().getName().equalsIgnoreCase(Menu.getTitle()))
        {
          e.setCancelled(true);
          boolean Menustatus = MenuConfig.getCustomConfig().getBoolean("Menu.open");
          boolean Menustart = MenuConfig.getCustomConfig().getBoolean("Menu.starten");
          boolean Menupoortjes = MenuConfig.getCustomConfig().getBoolean("Menu.poortjes");
         
          if (e.getSlot() == 0) {
            if (Menustart)
            {
              p.closeInventory();
              p.performCommand("rsc Menustart");
              e.setCancelled(true);
            }
            else
            {
              p.closeInventory();
              p.sendMessage(ChatColor.GOLD + "De Menu is afgewezen om te starten dit kan verschillende oorzaken hebben!");
              e.setCancelled(true);
            }
          }
          if (e.getSlot() == 4) {
            if (Menustatus)
            {
              e.setCancelled(true);
              p.performCommand("rsc Menuingang");
              p.closeInventory();
            }
            else
            {
              e.setCancelled(true);
              e.setCancelled(true);
              p.performCommand("rsc Menuingang");
              p.closeInventory();
            }
          }
          if (e.getSlot() == 2) {
            if (Menupoortjes)
            {
              e.setCancelled(true);
              p.performCommand("rsc Menupoortjes");
              p.closeInventory();
            }
            else
            {
              e.setCancelled(true);
              p.performCommand("rsc Menupoortjes");
              p.closeInventory();
            }
          }
        }
      }
    }
    
     
  2. Online

    CraftCreeper6

  3. what?????

    and where must i place that>?????

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Jan 27, 2015
  4. Offline

    DemKazoo

    I strongly recommend you to learn java & the bukkit API first before trying to code a plugin..

    Anyway, you must use Player#openIventory(myInventory); within your command boolean.
     
  5. Where? Can you copy the Code and send it with the boolean?
     
  6. Offline

    BurnerDiamond

    @TheLittleDeveloper

    Take it from me. Learn Java before you start doing bukkit. I made the mistake of trying to act smart and let me tell you it doesn't work. In this section they do not spoon feed you, the give you what you have to do so you can learn.

    Did you even write this code or did you copy and paste it?

    Learn Java and don't do my mistake!
     
  7. Offline

    DemKazoo

    Your command boolean is what you used to write your commands within, did you ever use it?
    Creating a command is a bukkit basic. And the fact that the current code you have is way more advanced than creating a code determines that you've stolen/copied the source from somewhere.

    Anyway, I'm going to spoonfeed you, a little bit because I feel like it.


    Code:
      //This is your command boolean used to write your commands within
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
    //Here is your command
     if(cmd.getName().equalsIgnoreCase("command") & & #.hasPermission("permission.node") {
          myInventory(#);
           }
    else if(!(#.hasPermission("permission.node");
       #.sendMessage("nope");
           }
      return false;
    }
    
    "#" must be replaced with your player definition. I hope you know what that is, not really in the mood to tell you how to create a new instance for player.

    I wrote the code above without IDE, so don't become mad if I made some small mistakes :c
     
Thread Status:
Not open for further replies.

Share This Page