Setblock Lore?

Discussion in 'Plugin Development' started by ItsMees, Nov 13, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ItsMees

    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
    1. Location loc = event.getPlayer().getTargetBlock(null, 256).getLocation();
    2.  
    3. int x1 = loc.getBlockX();
    4. int y1 = loc.getBlockY();
    5. int z1 = loc.getBlockZ();
    6.  
    7. int x2 = x1 + 3;
    8. int y2 = y1 + 3;
    9. int z2 = z1 + 3;
    10.  
    11. World world = loc.getWorld();
    12.  
    13. for (int xPoint = x1; xPoint <= x2; xPoint++) {
    14.  
    15. for (int yPoint = y1; yPoint <= y2; yPoint++) {
    16.  
    17. for (int zPoint = z1; zPoint <= z2; zPoint++) {
    18.  
    19. Block currentBlock = world.getBlockAt(xPoint, yPoint, zPoint);
    20.  
    21. List<String> id = new ArrayList<String>();
    22. id.addAll(player.getPlayer().getItemInHand().getItemMeta().getLore());
    23.  
    24. currentBlock.setType(id);
    25. }
    26. }
    27. }

    I hope someone can help me out!
     
  2. Offline

    qhenckel

    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.
     
  3. Offline

    maxben34

    To add on, the lore is part of the item meta. You can use getItemMeta() for this.
     
  4. Offline

    qhenckel

    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.
     
  5. Offline

    FireBreath14

    Set the lore:

    List<String> lore = new ArrayList<String>();

    lore.add("Your lore here");

    itemMetaObject.setLore(lore);
     
  6. Offline

    qhenckel

    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.
     
  7. Offline

    ItsMees

    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?
     
  8. Offline

    qhenckel

    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
     
  9. Offline

    ItsMees

    Ok, can you send me some code of that code from you? I don't no how to use it!
     
  10. Offline

    qhenckel

    ItsMees
    Code:java
    1. List<String> id = new ArrayList<String>();
    2. id.addAll(player.getPlayer().getItemInHand().getItemMeta().getLore());
    3. String typeid = id.get(index number);
    4. Material type = Material.matchMaterial(typeid);
    5. currentBlock.setType(type);

    Like that. just change 'index number' to an integer. also if the lore is a number not a material:
    Code:java
    1. List<String> id = new ArrayList<String>();
    2.  
    3. id.addAll(player.getPlayer().getItemInHand().getItemMeta().getLore());
    4.  
    5. int typeid = Integer.parsInt(id.get(index number));
    6.  
    7. currentBlock.setTypeId(typeid);

    Cheers!
     
  11. Offline

    ItsMees

    Sorry but what is an integer?
     
  12. Offline

    GusGold

    ItsMees
    A whole number from –2,147,483,648 to 2,147,483,647 ( 32 bytes)
     
    Jake6177 likes this.
  13. Offline

    ItsMees

    I did this:
    Code:java
    1. List<String> id = new ArrayList<String>();
    2.  
    3. id.addAll(player.getPlayer().getItemInHand().getItemMeta().getLore());
    4.  
    5. int typeid = Integer.parsInt(id.get(1));
    6.  
    7. currentBlock.setType(typeid);

    But it gives an error!
     
  14. Offline

    GusGold

    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 :)
     
    qhenckel likes this.
  15. Offline

    ItsMees

    Hahahaha I am good at java, I got already 3 plugins on bukkit but with this things I am new!
     
  16. Offline

    GusGold

  17. Offline

    ItsMees

    what is NPE?

    And I am using this in my code:
    Code:java
    1. int typeid = Integer.parsInt(id.get(1));

    But it gives an error!
     
  18. Offline

    ZeusAllMighty11

    ItsMees

    NPE is an abbreviation for NullPointerException
     
  19. Offline

    GusGold

    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)
     
  20. Offline

    FireBreath14

    And I'm the one being facepalmed xD really guys really rofl
     
Thread Status:
Not open for further replies.

Share This Page