Hi Guys, I got an problem. I want that players get an item with the name WorldPainter and the lore will we arg 2 of the command. I tryd this code but is doesnt work! Code:java ItemStack wp = new ItemStack(Material.STICK, 1); ItemMeta im = wp.getItemMeta(); im.setDisplayName(ChatColor.RED + "World Painter"); lore = im.getLore(); System.out.println(lore); lore.add(args[0]); im.setLore(lore); wp.setItemMeta(im); player.getPlayer().getInventory().addItem(wp); I hope someone can help me out!
Okay so you pretty much did everything right , The Error: is on - Line 9 , For Ex. Your Error , Line 9 , You Gaved an Unknown Item. Code:java player.getPlayer().getInventory().addItem(wp); Try Telling the server about the new ItemStack you maked, Ex. Code:java player.getInventory().addItem(new ItemStack[] { wp }); That's The Only Error I Found , If You Still have an Error or Something, just Message me.
It tryd it! The code will now look like this: Code:java ItemStack wp = new ItemStack(Material.STICK, 1); ItemMeta im = wp.getItemMeta(); im.setDisplayName(ChatColor.RED + "World Painter"); wp.setItemMeta(im); lore = im.getLore(); System.out.println(lore); lore.add(args[0]); im.setLore(lore); player.getInventory().addItem(new ItemStack[] { wp }); But when I test it wil gives this error: Code: 12:46:18 [INFO] null 12:46:18 [SEVERE] null org.bukkit.command.CommandException: Unhandled exception executing command 'pain ter' in plugin WorldPainter v1.0 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19 2) at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServe r.java:528) at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerCon nection.java:968) at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.j ava:886) at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java :837) at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49) at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296 ) at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java :116) at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37) at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:3 0) at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:5 92) at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:2 27) at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:4 88) at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java :421) at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:5 83) Caused by: java.lang.NullPointerException at com.itsmees.worldpainter.commands.CommandExecutor_Painter.onCommand(C ommandExecutor_Painter.java:57) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ... 15 more Maybe are there args wrong! The command is: /painter <ID>
ItsMees Did you add the @EventHandler on top For Ex. Code:java @EventHandlerItemStack wp = new ItemStack(Material.STICK, 1); ItemMeta im = wp.getItemMeta(); im.setDisplayName(ChatColor.RED + "World Painter"); wp.setItemMeta(im); lore = im.getLore(); System.out.println(lore); lore.add(args[0]); im.setLore(lore); player.getInventory().addItem(new ItemStack[] { wp }); *Remember* to have imported implements Listener.
Code:java ItemStack item = new ItemStack(Material.STICK, 1);if(item.hasItemMeta()) { ItemMeta im = item.getItemMeta(); ArrayList<String> lore = new ArrayList<String>(); lore.add("Lore goes here"); im.setLore(lore); item.setItemMeta(im);} Wrote this without an IDE, might've gotten some methods wrong or something