Need Help Making a GUI plugin

Discussion in 'Plugin Development' started by TommyPlayzOG, Aug 3, 2018.

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

    TommyPlayzOG

    Im make a permissions plugin and I need help with making the GUI...
    Heres my code:

    Code:
    package me.tommyplayzog;
    
    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.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class EasyPerms extends JavaPlugin implements Listener {
        public Inventory SelectPlayerMenu;
        public ItemStack SelectPlayer = new ItemStack(Material.EMERALD_BLOCK);
        @Override
        public void onEnable() {
            getLogger().info("EasyPerms has been Enabled!");
            new PlayerListener(this);
        }
       
        @Override
        public void onDisable() {
            getLogger().info("EasyPerms has been Disabled. ):");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            SelectPlayerMenu = Bukkit.createInventory(null, 27, ChatColor.RED + "Easy Perms Menu");
            ItemMeta SelectPlayerMeta = SelectPlayer.getItemMeta();
            SelectPlayerMeta.setDisplayName(ChatColor.GOLD + "Select Player" );
            SelectPlayerMenu.setItem(13, SelectPlayer);
            if (cmd.getName().equalsIgnoreCase("permmenu") && sender instanceof Player) {
                Player player = (Player) sender;
                player.openInventory(SelectPlayerMenu);
            }
            return false;
        }
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
        Player player = (Player) event.getWhoClicked();
        ItemStack clicked = event.getCurrentItem();
        Inventory inventory = event.getInventory();
        if (inventory.getName().equals(SelectPlayerMenu.getName())) {
        if (clicked.getType().equals(SelectPlayer)) {
        event.setCancelled(true);
        player.closeInventory();
        player.getInventory().addItem(SelectPlayer);
        }
        }
        }
    
    }
     
  2. Online

    timtower Ninja on the waves Moderator

  3. Offline

    TommyPlayzOG

    I cant make it so they can't take items out of the gui
     
  4. Offline

    Xydez

    You should generally explain what you've tried so far, what errors you get, and why you think you get those errors. People will generally be much faster to answer your post since they don't have to read through 200 lines of irrelevant code. Try reading "How to create a Minimal, Complete, and Verifiable example". Also, your code is not indented correctly.

    Firstly, your variables are wrongly named. SelectPlayerMenu should be selectPlayerMenu.
    SelectPlayer should be selectPlayer.

    ItemStack#getType() returns a Material, but you are comparing it to SelectPlayer, which is an ItemStack. In other words, you are checking if a Material is the same as an ItemStack. To fix this, do
    Code:java
    1. if (clicked.getType() == selectPlayer.getType())
    which checks if they share the same material. You can do == instead of .equals() because Material is an enum.
     
Thread Status:
Not open for further replies.

Share This Page