I want to give a player a item with a custom displayname and lore. This dosen't work tho: Code (Text): List<String> lore = new ArrayList<String>(); public void onEnable(){ lore.add("Increases the Radius of sucktion of Hopper by 4!"); } public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]){ if(cmd.getName().equalsIgnoreCase("jumper")){ if(args.length == 1 && args[0].equalsIgnoreCase("reload")){ cfile = new File(getDataFolder(), "config.yml"); config = YamlConfiguration.loadConfiguration(cfile); sender.sendMessage(ChatColor.GOLD + "Config reloaded!"); }else if(args.length == 3 && args[0].equalsIgnoreCase("give")){ if(isInt(args[2])){ Player p = Bukkit.getServer().getPlayer(args[1]); if(p == null){ sender.sendMessage("Player is offline!"); } else { boolean bool = false; for(ItemStack is : p.getInventory().getContents()){ if(is == null){ bool = true; } } ItemStack is = new ItemStack(Material.HOPPER, Integer.parseInt(args[2])); ItemMeta meta = is.getItemMeta(); meta.setDisplayName(ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Jumper"); meta.setLore(lore); is.setItemMeta(meta); if(bool){ p.getInventory().addItem(is); p.sendMessage(ChatColor.GOLD + "" + Integer.parseInt(args[2]) + "Jumper(s) recieved!"); } else { p.sendMessage(ChatColor.GOLD + "No inventory space," + Integer.parseInt(args[2]) + "Jumper(s) not given!"); Bukkit.getLogger().info("Player " + p.getName() + " did not recieve" + Integer.parseInt(args[2]) +" Jumper(s) because his/her 's inventory was full!"); } } } else { sender.sendMessage(ChatColor.RED + "Use /jumper give <playername> <amount>"); } } else { sender.sendMessage(ChatColor.DARK_PURPLE + "Use /jumper <reload> or /jumper give <playername> <amount>"); } } return true; } No errors either, Thanks in advance.
You're calling lore.add outside a method which isn't allowed. Move that line into a method/constructor/static block.
While it is ok to initialize a field "directly" (i.e. at the same time the decleration happens), any other code must be inside a method (or (static/instance) initializer/constructor); you should move the list mutation inside a method.
Aw come on, i told you multiple times learn Java first. Why do you keep coming with such , (pardon) stupid questions? These arent beginner mistakes, these are mistakes of someone, who didnt even looked a little bit into Java first. This forum isnt here to teach you how to java, its something people should already have when writing here.
The thing with saying that someone knows or doesn't know Java is... How much knowledge do you need to know Java? What subjects do you need to know about?
Don't be sorry. @TheSilentHorizon should just stop telling everyone with this kind of question that they don't know Java. I've not worked with item meta before so I can't really tell (which of course means that TheSilentHorizon is going to tell me that I don't know Java, isn't he?).
Nah, he's a smart guy. He's helped me before. Idk about now, So will you give a proper answer @TheSilentHorizon?