I am creating a plugin for my server where you click an emerald to open up a GUI where you can view the ranks. If you click one it closes the chest GUI and tells you the donate link. I can't find errors with the code itself, and yet nothing happens when I click an emerald in-game (The chest GUI fails to show up). The plugin does enable correctly. Source (I realize only part of this is relevant but I want to check for all possible errors): Code:java package com.rnmc.chestdonate; import java.util.ArrayList;import java.util.List;import java.util.logging.Logger; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Material;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.block.Action;import org.bukkit.event.inventory.InventoryClickEvent;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.inventory.Inventory;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.ItemMeta;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin; public class chestdonate extends JavaPlugin{ public final Logger logger = Logger.getLogger("Minecraft"); public static chestdonate plugin; @Override public void onDisable() { PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " has been disabled!"); } @Override public void onEnable() { PluginDescriptionFile pdfFile = this.getDescription(); this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been enabled!"); } @EventHandler public void onInteract(PlayerInteractEvent event){ Player p = event.getPlayer(); if(p.hasPermission("cd.open")){ if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR){ if(p.getItemInHand().getType() == Material.EMERALD) { Inventory inv = Bukkit.getServer().createInventory(p, 9, "Donate! rn-mc.com/donate"); ItemStack slot0 = new ItemStack(Material.GOLD_NUGGET, 1); ItemStack slot1 = new ItemStack(Material.GOLD_INGOT, 1); ItemStack slot2 = new ItemStack(Material.GOLD_BLOCK, 1); ItemStack slot3 = new ItemStack(Material.BLAZE_ROD, 1); ItemMeta meta0 = slot0.getItemMeta(); ItemMeta meta1 = slot1.getItemMeta(); ItemMeta meta2 = slot2.getItemMeta(); ItemMeta meta3 = slot3.getItemMeta(); meta0.setDisplayName(ChatColor.GREEN + "VIP"); meta1.setDisplayName(ChatColor.GREEN + "VIP+"); meta2.setDisplayName(ChatColor.DARK_GREEN + "VIP++"); meta3.setDisplayName(ChatColor.DARK_PURPLE + "Premium"); List<String> lore1 = new ArrayList<String>(); lore1.add(ChatColor.WHITE + "Perks:"); lore1.add(ChatColor.WHITE + "A colored prefix"); lore1.add(ChatColor.WHITE + "VIP Classes in games"); lore1.add(ChatColor.WHITE + "/msg"); meta0.setLore(lore1); List<String> lore2 = new ArrayList<String>(); lore2.add(ChatColor.WHITE + "Perks:"); lore2.add(ChatColor.WHITE + "All VIP Perks"); lore2.add(ChatColor.WHITE + "/hat"); lore2.add(ChatColor.WHITE + "/enderchest"); lore2.add(ChatColor.WHITE + "/workbench"); meta1.setLore(lore2); List<String> lore3 = new ArrayList<String>(); lore3.add(ChatColor.GREEN + "Perks:"); lore3.add(ChatColor.GREEN + "All VIP+ Perks"); lore3.add(ChatColor.GREEN + "/repair"); lore3.add(ChatColor.GREEN + "/enchant"); meta2.setLore(lore3); List<String> lore4 = new ArrayList<String>(); lore4.add(ChatColor.LIGHT_PURPLE + "Perks:"); lore4.add(ChatColor.LIGHT_PURPLE + "All VIP++ Perks"); lore4.add(ChatColor.LIGHT_PURPLE + "White Chat Color"); lore4.add(ChatColor.LIGHT_PURPLE + "/fly"); lore4.add(ChatColor.LIGHT_PURPLE + "/afk"); lore4.add(ChatColor.LIGHT_PURPLE + "/tptoggle"); lore4.add(ChatColor.LIGHT_PURPLE + "/speed"); lore4.add(ChatColor.LIGHT_PURPLE + "/kit premium"); lore4.add(ChatColor.LIGHT_PURPLE + "/heal"); meta3.setLore(lore4); slot0.setItemMeta(meta0); slot1.setItemMeta(meta1); slot2.setItemMeta(meta2); slot3.setItemMeta(meta3); inv.setItem(1, slot0); inv.setItem(3, slot1); inv.setItem(5, slot2); inv.setItem(7, slot3); } } } } public void inventoryclick(InventoryClickEvent e){ Player p = (Player) e.getWhoClicked(); if (e.getInventory().getTitle().equals("Donate! rn-mc.com/donate")) { e.setCancelled(true); p.sendMessage(ChatColor.GREEN + "Donate at rn-mc.com/donate!"); p.closeInventory(); } } }
Code:java public class Chestdonate extends JavaPlugin implements Listener { @Override public void onEnable() { ... getServer().getPluginManager().registerEvents(this, this); } ... } You need to register your listener class (in this case your main class - must implement the Listener interface). Also you forgot Code:java p.sendInventory(inv); By setting the inventory holder to player you don't open that inventory to him I don't think, and actualy I would recommend setting the inventory holder to null since it might have some unexpected results. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
CraftedWarrior59 I did what you said and the menu now comes up, but the plugin is not doing what I want when I click on an item. Should I maybe substitute InventoryClickEvent for something else?
Code:java Change : public class Chestdonate extends JavaPlugin { topublic class Chestdonate extends JavaPlugin implements Listener {Interact : p.openInventory(inv); public void onEnable() {getServer().getPluginManager().registerEvents(this, this);}
CraftedWarrior59 Actually found this myself, but thanks for the help Mother__ The plugin works fine without that