ItemMeta

Discussion in 'Plugin Development' started by Wazup93, Nov 23, 2013.

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

    Wazup93

    Hi Guys :)
    I Got a Very small Problem About ItemMeta Or MetaData In ProjectileHitEvent ...
    The Thing is When you Throw An Egg With The Name Of "Death Egg" With a certain Color Its Spawns Some Monsters .. The Code i Made
    Code:java
    1. @EventHandler
    2. public void FearDeathEggAbility(ProjectileHitEvent e){
    3. Entity entity = e.getEntity();
    4.  
    5. if(entity instanceof Egg) {
    6.  
    7. Egg egg = (Egg) entity;
    8. Entity shooter = egg.getShooter();
    9.  
    10. if(shooter instanceof Player) {
    11.  
    12. Player p = (Player) shooter;
    13.  
    14. Location loc = egg.getLocation();
    15.  
    16. double x = loc.getX();
    17. double y = loc.getY();
    18. double z = loc.getZ();
    19. Location spawn = new Location(null, x, y, z);
    20.  
    21. if(egg.hasMetadata(ChatColor.DARK_RED + "Death Egg")) {
    22. p.getLocation().getWorld().spawnEntity(spawn, EntityType.CREEPER);
    23. p.getLocation().getWorld().spawnEntity(spawn, EntityType.ZOMBIE);
    24. p.getLocation().getWorld().spawnEntity(spawn, EntityType.SPIDER);
    25. }
    26. }
    27. }
    28. }

    But this is Not Working Even in The Normal Egg ..
    And I was Thinking Too at A Thing Which is SIMILAR To it
    How Can I Get A Name Of A Bow Which Shot A Certain Arrow ?
    WithTheMeaningOf When The Bow Shoots An Arrow With The Name Of "Poison" It Checks The Bows Name And If The Bow Name Was "Poisoner" It Gives Out a Splash Of Poison ...
    Wish I Gave It Good .. I Made This Code Too
    Code:java
    1. @EventHandler
    2. public void FearFreakBowAbility(ProjectileHitEvent event) {
    3.  
    4. Entity entity = event.getEntity();
    5.  
    6. if(entity instanceof Arrow) {
    7.  
    8. Arrow arrow = (Arrow) entity;
    9. Entity shooter = arrow.getShooter();
    10.  
    11. if(shooter instanceof Player) {
    12.  
    13. Player player = (Player) shooter;
    14. PlayerInventory inv = player.getInventory();
    15.  
    16. Location loc = arrow.getLocation();
    17. double x = loc.getX();
    18. double y = loc.getY();
    19. double z = loc.getZ();
    20. Location spawn = new Location(null, x, y, z);
    21. if(arrow.hasMetadata(ChatColor.GREEN + "Poisened Arrow") && inv.getItemInHand() == FreakCraft.FreakBow && FreakCraft.FreakBow.hasItemMeta()) {
    22. Potion potion = new Potion(PotionType.POISON, 1);
    23. potion.setSplash(true);
    24. ItemStack iStack = new ItemStack(Material.POTION);
    25. potion.apply(iStack);
    26. ThrownPotion thrownPotion = (ThrownPotion) player.getWorld().spawnEntity(spawn, EntityType.SPLASH_POTION);
    27. thrownPotion.setItem(iStack);
    28. }
    29. }
    30. }
    31. }

    But The Same .. Its Not Working And What Makes Me Feel Bad is Its Not Giving Out ANY Single Error ...
    Any One Could Help Me So Please Do :)
    At Any Success Help .. I'll Be Thankful
    ThezKiller
     
  2. Offline

    L33m4n123

    This code is NOT tested and I do NOT quarantee that it works but it should give you a hint into the right direction
    Code:java
    1.  
    2. if(egg.getItemMeta() != null && egg.getItemMeta().getDisplayName().equals("Death Egg")) {
    3. // spawn it
    4. }
     
  3. Offline

    xTrollxDudex

    Wazup93
    You can't check for Metadata if you plan on using ItemMeta
     
  4. Offline

    Wazup93

    When i Just Saw It .. I'll Say To You .. I Searched First For ItemMeta But Theres No Option For It On Egg :)
    Just MetaData
    ThezKiller

    I Dont Know Anything About MetaData .. But If We Say The MEaning .. Its The Nearest To ItemMeta ...
    ThezKiller

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  5. Offline

    L33m4n123


    Ok. Didn't know that ;) Let me see if I can find something^^
     
  6. Offline

    Wazup93

    Tyt
    ThezKiller
     
  7. Offline

    xTrollxDudex

    Wazup93
    Ohmigod. Please Stahp Typeing Like This. It hurts my eyes, and you can type faster if you didn't do it...

    You can't check itemmeta on a thrown entity......
     
  8. Offline

    Wazup93

    Ok Sorry .. I dont want to check on the thrown item after its throw .. maybe i check on it before ?
    ThezKiller
     
  9. Offline

    xTrollxDudex

    Wazup93
    Try storing the arrow's UUID and check if the UUID of the arrow is contained in on ProjectileHitEvent, then do your stuff
     
  10. Offline

    Wazup93

    Just to make you notice .. i dont know what is UUID or how to store it .. + Maybe when i'm storing i store something else than the correct arrow .. what do you mean ?? xD
    ThezKiller
     
  11. Offline

    xTrollxDudex

    Wazup93
    When an arrow is launched and it has the correct itemmeta, store it in an ArrayList<UUID> by using arrow.getUniqueId() and on ProjectileHitEvent, check if the ArrayList contains arrow.getUniqueId()
     
  12. Offline

    Wazup93

    Didnt Work ... Maybe i've done it wrong but this is it .. first i got the entity as en then i checked if en is an arrow .. then when i'm trying to get its itemmeta it just gives out one choice which is metadata .. Notice i've done this on projectile launch event Any other ideas ...
    ThezKiller
     
  13. Offline

    xTrollxDudex

    Wazup93
    Try getting the itemmeta of throw, IMO you should put the itemmeta on the item which the player shoots the arrow from, not the arrow itself
     
  14. Offline

    Wazup93

    Your not getting it i want it to be like 1 bow and 3 arrows 1 arrow poison and any other too .. when i shoot the first arrow which is poison something happen but a deal to be the bow name a certain name .. Wish you got it
    ThezKiller
     
  15. Offline

    Wingzzz

    Okay, you want the effects of an arrow to correspond with the name of the arrow.

    ie: Lightning Arrow => "Strikes lightning at the target!"
    Undead Arrow => "Raises the undead to the overworld!"

    So on and so on... Am I correct?
     
  16. Offline

    Gater12

    Wazup93 xTrollxDudex perfectly gets it. Wouldn't the bow just shoot the 3 arrows then the poison arrow and AHH wacky stuff happens cause you have different arrows and I don't if you can make a bow shoot a specified arrow (Unless you throw the rest on the ground). I also wondered about this.... But in the end i decided to have different bows (Come on, a Lightning Hawk Bow is cool a name).
     
    xTrollxDudex likes this.
  17. Offline

    Wazup93

    Yes ... But the bow name must be a certain name
    ThezKiller

    Ok this didnt help o.o
    + When i throw a certain named arrow from a certained named bow something happens .. not from any normal bow ...
    ThezKiller

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  18. Offline

    maxben34

    Wazup93

    This is off topic, however i just wanted to let you know that you can put
    ThezKiller in a signature instead of having to type it after every post.

    maxben34(hehe)
     
Thread Status:
Not open for further replies.

Share This Page