Hello, Thanks for the people that helped yesterday. I now have an issue when registering my events, it doesn't seem to register them for any method I have tried. If someone could direct me in the right area on how to do this that would be amazing. Here is the code I have so far: Spoiler: Code Code (Java): @EventHandler(priority = EventPriority.MONITOR) public void punish(InventoryClickEvent e) { Inventory inv = e.getInventory(); Player p = (Player) e.getWhoClicked(); if (!inv.getTitle().equals(config.getString("GUI.Main.Name")) || !inv.getName().equals(config.getString("GUI.Main.Name"))) { return; } else if (inv.getTitle() .equals(config.getString("GUI.Main.Name").replace("%target%", PunishCommand.target.getName()) .replace("%reason%", PunishCommand.reason).replace("&", "§"))) { e.setCancelled(true); ItemStack item = e.getCurrentItem(); if (item == null || item.getType() == Material.AIR || !item.hasItemMeta()) { p.closeInventory(); return; } for (int i = 54; i < 54; i++) { String itemName = item.getItemMeta().getDisplayName(); if (config.getString("GUI.Items." + i + ".Name").equals(itemName)) { String command = config.getString("GUI.Items." + e.getSlot() + 1 + ".Command") .replace("%target%", PunishCommand.target.getName()) .replace("%reason%", PunishCommand.reason); p.performCommand(command); p.closeInventory(); e.setCancelled(true); } } } } Thank you in advance.
1. Create Main Class where create method onEnable onDisable implement JavaPlugin.. 2. Create Events Class put your code + implement it listener 3. Go to Main class put to onEnable Code (Text): Bukkit.getPluginManager().registerEvents(new Events(), this); Finish
Spoiler: Main Class Code (Java): package me.mrfishcakes.punishmentgui; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import me.mrfishcakes.punishmentgui.command.PunishCommand; import me.mrfishcakes.punishmentgui.events.PunishEvent; public class PunishmentGUI extends JavaPlugin { public static PunishmentGUI plugin; public void onEnable() { plugin = this; getCommand("punish").setExecutor(new PunishCommand()); getCommand("punishgui").setExecutor(new PunishCommand()); Bukkit.getServer().getPluginManager().registerEvents(new PunishEvent(), this); saveDefaultConfig(); } } Spoiler: PunishEvent Code (Java): package me.mrfishcakes.punishmentgui.events; import org.bukkit.Material; import org.bukkit.configuration.Configuration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import me.mrfishcakes.punishmentgui.PunishmentGUI; import me.mrfishcakes.punishmentgui.command.PunishCommand; public class PunishEvent implements Listener { static Configuration config = PunishmentGUI.plugin.getConfig(); @EventHandler(priority = EventPriority.MONITOR) public void punish(InventoryClickEvent e) { Inventory inv = e.getInventory(); Player p = (Player) e.getWhoClicked(); if (!inv.getTitle().equals(config.getString("GUI.Main.Name")) || !inv.getName().equals(config.getString("GUI.Main.Name"))) { return; } else if (inv.getTitle() .equals(config.getString("GUI.Main.Name").replace("%target%", PunishCommand.target.getName()) .replace("%reason%", PunishCommand.reason).replace("&", "§"))) { e.setCancelled(true); ItemStack item = e.getCurrentItem(); if (item == null || item.getType() == Material.AIR || !item.hasItemMeta()) { p.closeInventory(); return; } for (int i = 54; i < 54; i++) { String itemName = item.getItemMeta().getDisplayName(); if (config.getString("GUI.Items." + i + ".Name").equals(itemName)) { String command = config.getString("GUI.Items." + e.getSlot() + 1 + ".Command") .replace("%target%", PunishCommand.target.getName()) .replace("%reason%", PunishCommand.reason); p.performCommand(command); p.closeInventory(); e.setCancelled(true); } } } } } Spoiler: plugin.yml Code (YAML): main: me.mrfishcakes.punishmentgui.PunishmentGUI name: PunishmentGUI version: 5.0 author: MrFishCakes description: Punish players in a fancy GUI. commands: punish: description: Open up the GUI. aliases: [p, punishment] punishgui: description: Main command.
Extends Check if the listener catches the event. Code (Text): @EventHandler(priority = EventPriority.MONITOR) public void punish(InventoryClickEvent e) { System.out.println("yes, we catched it"); Inventory inv = e.getInventory(); Player p = (Player) e.getWhoClicked(); if (!inv.getTitle().equals(config.getString("GUI.Main.Name")) || !inv.getName().equals(config.getString("GUI.Main.Name"))) { return; } else if (inv.getTitle() If it is printed in the console, check if the plugin is enabled successfully.
We are catching it, now I just need to have the command execute and we are all done. Best way to do this would be to do it how?
Command not firing for some reason? We cancel the item moving and that is it. Here is the current code: https://paste.md-5.net/neqetekewa.avrasm
Debug more. Does if (itemName.equals(name)) { ? To be sure, print something. if (itemName.equals(name)) { System.out.println("it does equal");
Debugged a little more and we now get to here: https://paste.md-5.net/jajihogiqi.avrasm http://prntscr.com/ezx0mj So it is when we check the name that fails? Edit: Just imported the correct ChatColor
Try stripping the itemname of colors. ChatColor.stripColor(itemName).equals(name). The chatcolors might be conflicting.
no real need for an else-if statement at the top. code would execute as follows. ex: Code (Java): if (statement == 2) { A(); return; } if (statement == 3) { B(); return; } or if (statement == 2) { A(); return; } //anything that isn't 2 B();
debug. check to what extent the code is running what is actually being fetched the from the config (the values)
https://paste.md-5.net/tenadetati.avrasm http://prntscr.com/ezy9b9 Up to getting the strings is where we stop