Hi Guys, I got an problem with my new plugin! Can someone help me? The problem is with the currentBlock.Settype(id) I want to set the selection to the item lore your holding in your hand! The code: Code:java Location loc = event.getPlayer().getTargetBlock(null, 256).getLocation(); int x1 = loc.getBlockX(); int y1 = loc.getBlockY(); int z1 = loc.getBlockZ(); int x2 = x1 + 3; int y2 = y1 + 3; int z2 = z1 + 3; World world = loc.getWorld(); for (int xPoint = x1; xPoint <= x2; xPoint++) { for (int yPoint = y1; yPoint <= y2; yPoint++) { for (int zPoint = z1; zPoint <= z2; zPoint++) { Block currentBlock = world.getBlockAt(xPoint, yPoint, zPoint); List<String> id = new ArrayList<String>(); id.addAll(player.getPlayer().getItemInHand().getItemMeta().getLore()); currentBlock.setType(id); } } } I hope someone can help me out!
Lore is not the same a material id. very different. use 'getPlayer().getItemInHand().getTypeId()' or something like that. The lore of an item is a bunch of text about the item. the type is what the material is.
maxben34 Don't confuse the poor guy. for this they have to use something to get an integer to set all the blocks to that type.
Set the lore: List<String> lore = new ArrayList<String>(); lore.add("Your lore here"); itemMetaObject.setLore(lore);
FireBreath14 (Face Palm) Did you read the OP? he wants to set an area of blocks to be the same as the block in his hand. the only way lore got in here was because he made the mistake of thinking it contained the block material type.
I now that the lore is text! And I don't want to set the block the same as the block holding is my hand! I use the lore because the text is an ID! How can I use that?
ItsMees oooohhhhh... ok. so problem is you are using List<String> when you need an int. so you need to pars the list like: 'int intid = id.get(index);' somthing like that. You might also need to use 'Integer.parsInt(String);' =) hope i helped. cheers
ItsMees Code:java List<String> id = new ArrayList<String>();id.addAll(player.getPlayer().getItemInHand().getItemMeta().getLore());String typeid = id.get(index number);Material type = Material.matchMaterial(typeid);currentBlock.setType(type); Like that. just change 'index number' to an integer. also if the lore is a number not a material: Code:java List<String> id = new ArrayList<String>(); id.addAll(player.getPlayer().getItemInHand().getItemMeta().getLore()); int typeid = Integer.parsInt(id.get(index number)); currentBlock.setTypeId(typeid); Cheers!
I did this: Code:java List<String> id = new ArrayList<String>(); id.addAll(player.getPlayer().getItemInHand().getItemMeta().getLore()); int typeid = Integer.parsInt(id.get(1)); currentBlock.setType(typeid); But it gives an error!
ItsMees Because Lists start at index 0, and on line 5, you are trying to get the String at index 1 (of which doesn't exists, and I assume your error is a NullPointerException. Change line 5 from .get(1) to .get(0); 0th index = 1st entry, 1st index = 2nd entry I think your setup is quite off too. Might want to read up on java before attempting plugins
ItsMees You will also have to change line 7 because .setType() expects a Material, and you are giving it an int. Try the method .setTypeId() although this is deprecated. I would suggest that you use (but watch out for NPE): Code:java currentBlock.setType(Material.getMaterial(typeid)); More info: http://jd.bukkit.org/dev/doxygen/d6...terial.html#abf76c4b28ff8cc3a9e6242872672eee9
what is NPE? And I am using this in my code: Code:java int typeid = Integer.parsInt(id.get(1)); But it gives an error!
ItsMees As Zeus says, NullPointerException, meaning that you are trying to do something with varible (or object) that is equal to null. Null means nothing (not 0 or an empty string (""), but actually nothing) and you can't do anything with nothing (similar to how you can't divide by 0). The reason I warned you of it is because if you try Material.getMaterial(id) with an id that doesn't link to a material, it will return null rather than a Material. Then when you try .setType(null), you will get your NPE because you can't set something in game to nothing (if you were wanting to remove the block, use Material.AIR)