When i click on any of the ingots it doesnt even close the gui

Discussion in 'Plugin Development' started by GodzillaFlame42, Jul 8, 2018.

Thread Status:
Not open for further replies.
  1. im making a punish gui and when i open it and click on for example iron ingot doesnt mute me and i cant figure out why.

    PunishGUI:

    Code:
    package gui;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.UUID;
    
    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.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class PunishGUI implements CommandExecutor {
      
        public List<UUID> muted = new ArrayList<UUID>();
        public Player playerPunished;
        public UUID uuid;
      
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
                if (!(sender instanceof Player)) {
                    sender.sendMessage("You must be a player to use this command!");
                return false;
            }
          
            if(args.length == 1) {
                Player player = (Player) sender;
                openGUI(player);
                playerPunished = Bukkit.getPlayer(args[0]);
                uuid = playerPunished.getUniqueId();
                return true;
            } else {
                Player player = (Player) sender;
                player.sendMessage("Invalid name!");
              
            return false;
          
            }
        }
          
            public void openGUI(Player player) {
                Inventory inv = Bukkit.createInventory(null, 54, ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "Punish");
              
                ItemStack mutepunish = new ItemStack(Material.BOOK_AND_QUILL);
                ItemMeta mpMeta = mutepunish.getItemMeta();
              
                ItemStack severity1 = new ItemStack(Material.IRON_INGOT);
                ItemMeta sev1Meta = severity1.getItemMeta();
              
                ItemStack severity2 = new ItemStack(Material.GOLD_INGOT);
                ItemMeta sev2Meta = severity2.getItemMeta();
              
                ItemStack severity3 = new ItemStack(Material.DIAMOND);
                ItemMeta sev3Meta = severity2.getItemMeta();
              
             
                mpMeta.setDisplayName(ChatColor.GRAY + "" + ChatColor.BOLD + "< " + ChatColor.GREEN + "" + ChatColor.BOLD + "Chat Offense" + ChatColor.GRAY + "" + ChatColor.BOLD + " >");
                mutepunish.setItemMeta(mpMeta);
           
                sev1Meta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "Severity 1");
                severity1.setItemMeta(sev1Meta);
             
                sev2Meta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "Severity 2");
                severity2.setItemMeta(sev2Meta);
              
                sev3Meta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "Severity 3");
                severity3.setItemMeta(sev3Meta);
             
              
                inv.setItem(11, mutepunish);
                inv.setItem(20, severity1);
                inv.setItem(29, severity2);
                inv.setItem(38, severity3);
             
                player.openInventory(inv);
        }
     
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
                if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Punishment Menu")) {
                        return;
                }
             
                Player player = (Player) event.getWhoClicked();
                event.setCancelled(true);
             
                if(event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR || !event.getCurrentItem().hasItemMeta()) {
                        player.closeInventory();
                        return;
                }
             
                switch(event.getCurrentItem().getType()) {
                case IRON_INGOT:
                        if(muted.contains(uuid)) {
                                muted.remove(uuid);
                                player.closeInventory();
                                player.sendMessage("The player has been unmuted!");
                        } else {
                                muted.add(uuid);
                                player.closeInventory();
                                player.sendMessage("The player has been muted!");
                        }
                        break;
                case GOLD_INGOT:
                        player.closeInventory();
                        break;
                case DIAMOND:
                        player.closeInventory();
                        break;
                default:
                        player.closeInventory();
                        break;
                }
        }
     
        @EventHandler
        public void onPlayerChatEvent(AsyncPlayerChatEvent event) {
                if (muted.contains(event.getPlayer().getUniqueId())) {
                                event.getPlayer().sendMessage(ChatColor.GRAY + "Shh, you're muted");
                                event.setCancelled(true);
                }
        }
    
    }
    I also need help putting multiple lines for the items
     
  2. Offline

    CommonSenze

  3. @CommonSenze
    When i try registering it, it wont reconize the class

    Code:
    package main;
    
    import gui.PunishGUI;
    
    import org.apache.logging.log4j.core.config.plugins.Plugin;
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import commands.GMC;
    import commands.GMS;
    
    public class Main extends JavaPlugin {
    
        public void onEnable() {
            System.out.println(ChatColor.BLUE + "Essentials> " + ChatColor.GRAY + "Plugin has been: " + ChatColor.GREEN + "ACTIVATED.");
                //commands
                    this.getCommand("gmc").setExecutor((CommandExecutor) new GMC());
                    this.getCommand("gms").setExecutor((CommandExecutor) new GMS());
                    this.getCommand("p").setExecutor((CommandExecutor) new PunishGUI());
          
                //listeners
                    this.getServer().getPluginManager().registerEvents(PluginGUI, this);
            }
        public void Disable() {
            System.out.println(ChatColor.BLUE + "Essentials> " + ChatColor.GRAY + "Plugin has been: " + ChatColor.RED + "DEACTIVATED.");
        }
    }
    
     
  4. Offline

    CommonSenze

    @GodzillaFlame42
    You forgot to implements Listener on that class. Also you did "PluginGUI" It needs to be new PunishGUI()
     
  5. @CommonSenze
    it still is not recognizing the class and idk why

    Code:
    package main;
    
    import gui.PunishGUI;
    
    import org.apache.logging.log4j.core.config.plugins.Plugin;
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import commands.GMC;
    import commands.GMS;
    
    public class Main extends JavaPlugin implements Listener {
    
        public void onEnable() {
            System.out.println(ChatColor.BLUE + "Essentials> " + ChatColor.GRAY + "Plugin has been: " + ChatColor.GREEN + "ACTIVATED.");
                //commands
                    this.getCommand("gmc").setExecutor((CommandExecutor) new GMC());
                    this.getCommand("gms").setExecutor((CommandExecutor) new GMS());
                    this.getCommand("p").setExecutor((CommandExecutor) new PunishGUI());
           
                //listeners
                    this.getServer().getPluginManager().registerEvents(PluginGUI(), this);
            }
        public void Disable() {
            System.out.println(ChatColor.BLUE + "Essentials> " + ChatColor.GRAY + "Plugin has been: " + ChatColor.RED + "DEACTIVATED.");
        }
    }
    
    ok so i figured out how to register it and now it still wont do anything. I click iron ingot it wont mute me, i click on the others and it wont close inv.

    PunishGUI:
    Code:
    package gui;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.UUID;
    
    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.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class PunishGUI implements CommandExecutor, Listener {
       
        public List<UUID> muted = new ArrayList<UUID>();
        public Player playerPunished;
        public UUID uuid;
       
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
                if (!(sender instanceof Player)) {
                    sender.sendMessage("You must be a player to use this command!");
                return false;
            }
           
            if(args.length == 1) {
                Player player = (Player) sender;
                openGUI(player);
                playerPunished = Bukkit.getPlayer(args[0]);
                uuid = playerPunished.getUniqueId();
                return true;
            } else {
                Player player = (Player) sender;
                player.sendMessage("Invalid name!");
               
            return false;
           
            }
        }
           
            public void openGUI(Player player) {
                Inventory inv = Bukkit.createInventory(null, 54, ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "Punish");
               
                ItemStack mutepunish = new ItemStack(Material.BOOK_AND_QUILL);
                ItemMeta mpMeta = mutepunish.getItemMeta();
               
                ItemStack severity1 = new ItemStack(Material.IRON_INGOT);
                ItemMeta sev1Meta = severity1.getItemMeta();
               
                ItemStack severity2 = new ItemStack(Material.GOLD_INGOT);
                ItemMeta sev2Meta = severity2.getItemMeta();
               
                ItemStack severity3 = new ItemStack(Material.DIAMOND);
                ItemMeta sev3Meta = severity2.getItemMeta();
               
              
                mpMeta.setDisplayName(ChatColor.GRAY + "" + ChatColor.BOLD + "< " + ChatColor.GREEN + "" + ChatColor.BOLD + "Chat Offense" + ChatColor.GRAY + "" + ChatColor.BOLD + " >");
                mutepunish.setItemMeta(mpMeta);
            
                sev1Meta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "Severity 1");
                severity1.setItemMeta(sev1Meta);
              
                sev2Meta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "Severity 2");
                severity2.setItemMeta(sev2Meta);
               
                sev3Meta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "Severity 3");
                severity3.setItemMeta(sev3Meta);
              
               
                inv.setItem(11, mutepunish);
                inv.setItem(20, severity1);
                inv.setItem(29, severity2);
                inv.setItem(38, severity3);
              
                player.openInventory(inv);
        }
      
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
                if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Punishment Menu")) {
                        return;
                }
              
                Player player = (Player) event.getWhoClicked();
                event.setCancelled(true);
              
                if(event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR || !event.getCurrentItem().hasItemMeta()) {
                        player.closeInventory();
                        return;
                }
              
                switch(event.getCurrentItem().getType()) {
                case IRON_INGOT:
                        if(muted.contains(uuid)) {
                                muted.remove(uuid);
                                player.closeInventory();
                                player.sendMessage("The player has been unmuted!");
                        } else {
                                muted.add(uuid);
                                player.closeInventory();
                                player.sendMessage("The player has been muted!");
                        }
                        break;
                case GOLD_INGOT:
                        player.closeInventory();
                        break;
                case DIAMOND:
                        player.closeInventory();
                        break;
                default:
                        player.closeInventory();
                        break;
                }
        }
      
        @EventHandler
        public void onPlayerChatEvent(AsyncPlayerChatEvent event) {
                if (muted.contains(event.getPlayer().getUniqueId())) {
                                event.getPlayer().sendMessage(ChatColor.GRAY + "Shh, you're muted");
                                event.setCancelled(true);
                }
        }
    
    }
    Main:
    Code:
    package main;
    
    import gui.PunishGUI;
    
    import org.apache.logging.log4j.core.config.plugins.Plugin;
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import commands.GMC;
    import commands.GMS;
    
    public class Main extends JavaPlugin implements Listener {
    
        public void onEnable() {
            System.out.println(ChatColor.BLUE + "Essentials> " + ChatColor.GRAY + "Plugin has been: " + ChatColor.GREEN + "ACTIVATED.");
                //commands
                    this.getCommand("gmc").setExecutor((CommandExecutor) new GMC());
                    this.getCommand("gms").setExecutor((CommandExecutor) new GMS());
                    this.getCommand("p").setExecutor((CommandExecutor) new PunishGUI());
           
                //listeners
                    this.getServer().getPluginManager().registerEvents(new PunishGUI(), this);
            }
        public void Disable() {
            System.out.println(ChatColor.BLUE + "Essentials> " + ChatColor.GRAY + "Plugin has been: " + ChatColor.RED + "DEACTIVATED.");
        }
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  6. Offline

    tkuiyeager1

    @GodzillaFlame42
    Code:
    getServer().getPluginManager().registerEvents(new PunishGUI(), this);
    Edit: this doesn't work?
     
  7. @tkuiyeager1
    i tried it, it does not work unfortunately. Any other recommendations?
     
  8. Try with public static void
     
  9. Offline

    CommonSenze

    @GodzillaFlame42
    Just put your Event methods in your Main class and replace new PunishGUI() in the registerEvents with this.
     
  10. Online

    timtower Administrator Administrator Moderator

    Please don't teach public static. Using static is never needed in Bukkit.
     
  11. Offline

    johnny boy

    on the topic of static, and you're good at explaining, if you wouldn't mind, what is static in Java?
     
  12. Online

    timtower Administrator Administrator Moderator

    Normally you have a variable for each instance of a class.
    Static means that it is the same one for all instances.
    Bukkit can't / doesn't clean them though so memory leaks are a thing there.
    Not to mention that I haven't encountered a situation where you need it.
     
  13. Offline

    johnny boy

    ok thanks
     
Thread Status:
Not open for further replies.

Share This Page