I want to add to confige Enchantment boolean: My code: Main Code: package me.bronzzze.wardrobe; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin { String message = ChatColor.translateAlternateColorCodes('&', getConfig() .getString("Message when you select Hat")); @Override public void onEnable() { this.getCommand("wardrobe").setExecutor(new Commands(this)); Bukkit.getServer().getPluginManager() .registerEvents(new MainEvent(this), this); Bukkit.getServer().getPluginManager() .registerEvents(new ChestEvent(this), this); Bukkit.getServer().getPluginManager() .registerEvents(new ArmourEvent(this), this); Bukkit.getServer().getPluginManager() .registerEvents(new HatEvent(this), this); Bukkit.getServer().getPluginManager() .registerEvents(new JoinEvent(this), this); ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); console.sendMessage(ChatColor.RED + "-------------------------"); console.sendMessage(ChatColor.BLUE + "Wardrobe Plugin enabled"); console.sendMessage(ChatColor.RED + "-------------------------"); final FileConfiguration config = this.getConfig(); config.options().copyDefaults(true); saveConfig(); } String prefix = ChatColor.translateAlternateColorCodes('&', getConfig() .getString("Chat Wardrobe Prefix")); } GUI Class: Code: package me.bronzzze.wardrobe; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; public class ArmourGUI { private ArmourGUI() { } private static ArmourGUI instance = new ArmourGUI(); public static ArmourGUI getInstance() { return instance; } Main plugin; public ArmourGUI(Main instance) { plugin = instance; } public void openInventory(Player p) { Inventory inv = Bukkit .getServer() .createInventory( null, 54, ("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Armour Selector")); if (plugin.getConfig().getBoolean("Enchantments") == true) { ItemStack item1 = new ItemStack(Material.LEATHER_HELMET, 1); item1.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1); LeatherArmorMeta itemM1 = (LeatherArmorMeta) item1.getItemMeta(); List<String> l1 = new ArrayList<String>(); l1.add(ChatColor.GOLD + "Click to Equip!"); itemM1.setLore(l1); itemM1.setDisplayName("" + ChatColor.YELLOW + ChatColor.BOLD + "Yellow Helmet"); itemM1.setColor(Color.YELLOW); item1.setItemMeta(itemM1); inv.setItem(10, item1); p.openInventory(inv); } if (plugin.getConfig().getBoolean("Enchantments") == false) { ItemStack item1 = new ItemStack(Material.LEATHER_HELMET, 1); LeatherArmorMeta itemM1 = (LeatherArmorMeta) item1.getItemMeta(); List<String> l1 = new ArrayList<String>(); l1.add(ChatColor.GOLD + "Click to Equip!"); itemM1.setLore(l1); itemM1.setDisplayName("" + ChatColor.YELLOW + ChatColor.BOLD + "Yellow Helmet"); itemM1.setColor(Color.YELLOW); item1.setItemMeta(itemM1); inv.setItem(21, item1); p.openInventory(inv); } } } Error: Code: [17:51:38] [Server thread/ERROR]: Could not pass event InventoryClickEvent to Wardrobe v1.0 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:297) ~[craftbukkit_server.jar:git-Bukkit-e87122e] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit_server.jar:git-Bukkit-e87122e] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit_server.jar:git-Bukkit-e87122e] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit_server.jar:git-Bukkit-e87122e] at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:1521) [craftbukkit_server.jar:git-Bukkit-e87122e] at net.minecraft.server.v1_8_R1.PacketPlayInWindowClick.a(SourceFile:31) [craftbukkit_server.jar:git-Bukkit-e87122e] at net.minecraft.server.v1_8_R1.PacketPlayInWindowClick.a(SourceFile:9) [craftbukkit_server.jar:git-Bukkit-e87122e] at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [craftbukkit_server.jar:git-Bukkit-e87122e] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_75] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_75] at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:643) [craftbukkit_server.jar:git-Bukkit-e87122e] at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284) [craftbukkit_server.jar:git-Bukkit-e87122e] at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:598) [craftbukkit_server.jar:git-Bukkit-e87122e] at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:506) [craftbukkit_server.jar:git-Bukkit-e87122e] at java.lang.Thread.run(Unknown Source) [?:1.7.0_75] Caused by: java.lang.NullPointerException at me.bronzzze.wardrobe.ArmourGUI.openInventory(ArmourGUI.java:41) ~[?:?] at me.bronzzze.wardrobe.MainEvent.onClick(MainEvent.java:51) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_75] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_75] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_75] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_75] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:295) ~[craftbukkit_server.jar:git-Bukkit-e87122e] ... 14 more Line 41 is: if (plugin.getConfig().getBoolean("Enchantments") == true) { and line 51 in event: i.openInventory(p);
Main Event: Code: package me.bronzzze.wardrobe; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Sound; 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.inventory.InventoryType.SlotType; public class MainEvent implements Listener { private final Main main; public MainEvent(Main main) { this.main = main; } ArmourGUI i = ArmourGUI.getInstance(); HatGUI i2 = HatGUI.getInstance(); @EventHandler public void onClick(InventoryClickEvent e) { Player p = (Player) e.getWhoClicked(); if (e.getSlotType() == SlotType.ARMOR) { if(!(p.getGameMode() == GameMode.CREATIVE || p.isOp())){ e.setCancelled(true); } } if (e.getInventory().getName() .equalsIgnoreCase("" + ChatColor.DARK_PURPLE + ChatColor.BOLD + "Main Menu")) { if (e.getCurrentItem() == null) { return; } e.setCancelled(true); if (e.getCurrentItem() != null && e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().hasDisplayName() && e.getCurrentItem() .getItemMeta() .getDisplayName() .contains("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Armour Selector")) { p.closeInventory(); i.openInventory(p); } if (e.getCurrentItem() != null && e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().hasDisplayName() && e.getCurrentItem() .getItemMeta() .getDisplayName() .contains("" + ChatColor.GOLD + ChatColor.BOLD + "Hat Selector")) { p.closeInventory(); i2.openInventory(p); } if (e.getCurrentItem() != null && e.getCurrentItem().hasItemMeta() && e.getCurrentItem().getItemMeta().hasDisplayName() && e.getCurrentItem() .getItemMeta() .getDisplayName() .contains("" + ChatColor.DARK_RED + ChatColor.BOLD + "Clear Armour")) { p.getInventory().setHelmet(null); p.getInventory().setChestplate(null); p.getInventory().setLeggings(null); p.getInventory().setBoots(null); p.getLocation().getWorld() .playSound(p.getLocation(), Sound.FIZZ, 5, 1); p.closeInventory(); p.sendMessage(main.prefix + ChatColor.translateAlternateColorCodes( '&', main.getConfig().getString( "Message when you clear Armour"))); } } } } Config: Code: Chat Wardrobe Prefix: '&5[&dWardrobe&5] ' Message when you open Main Menu: '&5Opening Wardrobe!' Message when you clear Armour: '&5Armour Cleared!' Message when you select Hat: '&5Hat Selected!' # When Player Join true = add a wardrobe chest false = don't add a wardrobe chest. On Join: false # Which slot in inventory should be set. Slot: 8 # Armour Enchantments true/false Enchantments: true
Code: public class Main extends JavaPlugin{ public static Main plugin; @Override public void onEnable(){ plugin = this; } so like this YamlConfiguration config =Main.plugin.getConfig();
I added this: Code: public static Main plugin; @Override public void onEnable(){ plugin = this; and still not working And added on onDisable(){ plugin=null Bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Not sure if this will help or not I don't do too much with Configs. But maybe try to add Code: getConfig().addDefault("Enchantments", Boolean.valueOf(true)); To your onEnable. And then use Code: if (getConfig().getBoolean("Enchantments", true)) { to call it on line 41 Just taking a guess here honestly.
You don't have to create any constructor in your Main class : 1) In your SecondaryClass Code: private final Main plugin; public SecondaryClass(Main i) { plugin = i; } 2) Boolean usage : Code: Using : if(plugin.getConfig().getBoolean("Enchantments")) {} //This already checks if the boolean is true if(!plugin.getConfig().getBoolean("Enchantments")) {} //If the boolean is false ... You also do it like this : if(plugin.getConfig().getBoolean("Enchantments")) { //Stuff if the boolean is true } else { //Stuff if the boolean is false } 3) Check if the path ain't null 4) Add some debug messages 5) You can use spaces on the config like that : Code: Chat Wardrobe Prefix: '&5[&dWardrobe&5] ' Message when you open Main Menu: '&5Opening Wardrobe!' Message when you clear Armour: '&5Armour Cleared!' Message when you select Hat: '&5Hat Selected!' # When Player Join true = add a wardrobe chest false = don't add a wardrobe chest. On Join: false # Which slot in inventory should be set. Slot: 8 # Armour Enchantments true/false Enchantments: true How to do it : Code: 'Here you can use spaces': 6) ¿ Do you any InventoryClickEvent ? Seems like the error can be there
@MaTaMoR_ I change it like this. Same Error. Code: package me.bronzzze.wardrobe; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; public class ArmourGUI { private ArmourGUI() { } private static ArmourGUI instance = new ArmourGUI(); public static ArmourGUI getInstance() { return instance; } Main plugin; public ArmourGUI(Main i) { this.plugin = i; } public void openInventory(Player p) { Inventory inv = Bukkit .getServer() .createInventory( null, 54, ("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Armour Selector")); if(plugin.getConfig().getBoolean("Enchantments")) { ItemStack item1 = new ItemStack(Material.LEATHER_HELMET, 1); item1.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1); LeatherArmorMeta itemM1 = (LeatherArmorMeta) item1.getItemMeta(); List<String> l1 = new ArrayList<String>(); l1.add(ChatColor.GOLD + "Click to Equip!"); itemM1.setLore(l1); itemM1.setDisplayName("" + ChatColor.YELLOW + ChatColor.BOLD + "Yellow Helmet"); itemM1.setColor(Color.YELLOW); item1.setItemMeta(itemM1); inv.setItem(10, item1); p.openInventory(inv); } else{ ItemStack item1 = new ItemStack(Material.LEATHER_HELMET, 1); LeatherArmorMeta itemM1 = (LeatherArmorMeta) item1.getItemMeta(); List<String> l1 = new ArrayList<String>(); l1.add(ChatColor.GOLD + "Click to Equip!"); itemM1.setLore(l1); itemM1.setDisplayName("" + ChatColor.YELLOW + ChatColor.BOLD + "Yellow Helmet"); itemM1.setColor(Color.YELLOW); item1.setItemMeta(itemM1); inv.setItem(21, item1); p.openInventory(inv); } } }