I know this is a simple question but how do I set a item name? For example I have something like this: Code: ItemStack bucket = new ItemStack(Material.LAVA_BUCKET); How do I name the lava bucket GOLD?
Code:java ItemStack bucket = new ItemStack(Material.LAVA_BUCKET);ItemMeta im = bucket.getItemMeta();im.setDisplayName("Gold");bucket.setItemMeta(im);
This is not right!!! This is what I currently have and it does not name it!!! Code: ItemStack bucket = new ItemStack(Material.LAVA_BUCKET); ItemMeta im = bucket.getItemMeta(); int goldlevel = getGold(name); im.setDisplayName(ChatColor.BOLD + "" + ChatColor.GOLD + "Gold: " + goldlevel); p1.getInventory().setItem(8, bucket); It just gives the player a regular LavaBucket?
TheMcScavenger wow, i'm sorry, i never thought you needed to use proper grammar to help someone. my apologies.
You don't. You do however need to use capitalisation and punctuation in order for your comment to look good, before you start calling things "crap".
TheMcScavenger i didn't call anyone's code crap i was just saying give the custom itemstack its own method so your code doesn't look horrible..
B3N909 no i didn't? i said if you put your code for the itemstack in the same place as your if-statements or whatever then your code will look horrible and unorganized
Lets not be rude on a public forums TheMcScavenger hankered Can you guys actually help me now? And not try to make yourself look good? How do I remove items with a custom meta? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
custm meta? i think if you make a for loop and go through all the items with #hasItemMeta and remove them. but I'm sure every item has a itemmeta so.
Code:java for(ItemStack stack : player.getInventory().getContents()){ ItemMeta meta = stack.getItemMeta(); String displayName = meta.getDisplayName(); if(displayName.equals("My name")){ player.getInventory().remove(stack); }}
TheMcScavenger Gater12 I just tried and it would not check for my Lava Bucket. I am using PlayerClickEvent to see if the player clicks it. If they do it should cancell it. BUT if you shift and click you can dupe the item. That is what I am trying to fix!
Gater12 sorry InventoryClickEvent Gater12 is there any way to make the first item in the players inventory to 0 or air. So when they shift click it just sets to zero? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Gater12 Code: @EventHandler public void onClickSlot(InventoryClickEvent event){ if(event.getSlot() == 8){ event.setResult(Result.DENY); event.setCancelled(true); String p = event.getWhoClicked().getName(); Player usr = (Player)event.getWhoClicked(); usr.closeInventory(); int goldLevel = getGold(usr.getName().toLowerCase()); usr.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Gold: " + goldLevel); UI(p); } } UI(p); sets the player so he/she has a bucket with the correct gold level.