MetaData Help.

Discussion in 'Plugin Development' started by Kerooker, Jul 1, 2014.

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

    Kerooker

    Hello Community!
    I'm trying to develop my first plugin, and the only difficulty I've found so far is using MetaData to identify that a WitherSkull is differente from a Fireball when both are thrown.


    The IteminHand was set previously.
    The code I have for the Fireball is:
    Code:java
    1. if (p2.getItemInHand().equals(stickFireball) && (p2.hasPermission("minecraftando.evento") || p2.isOp()) ){
    2. if (e.getAction() == Action.RIGHT_CLICK_AIR){
    3. p2.launchProjectile(SmallFireball.class).setVelocity(p2.getLocation().getDirection().multiply(0.5));
    4. }else if (e.getAction() == Action.LEFT_CLICK_AIR){
    5. p2.launchProjectile(Fireball.class).setVelocity(p2.getLocation().getDirection().multiply(0.5));
    6. }
    7.  


    And the code for the WitherSkull is:
    Code:java
    1. if (p2.getItemInHand().equals(witherStick) && (p2.hasPermission("minecraftando.evento") || p2.isOp()) ){
    2. WitherSkull cabeca = p2.launchProjectile(WitherSkull.class);
    3. cabeca.setVelocity(p2.getLocation().getDirection().multiply(3.5));
    4. cabeca.setFireTicks(0);
    5. cabeca.setIsIncendiary(false);
    6. cabeca.setMetadata("cabeca", new FixedMetadataValue(plugin3, "cabecao"));
    7. }


    When recovering them, I use:
    Code:java
    1. if(r.getDamager() instanceof Fireball && r.getEntity() instanceof Player && Vip.ReturnEvento() == true && r.getEntity().hasMetadata("cabeca") == false){
    2. Player s = (Player) r.getEntity();
    3. Fireball bola = (Fireball) r.getDamager();
    4. Player atirador = (Player)bola.getShooter();
    5. atirador.sendMessage("Bateu com fireball: " + r.getEntity());
    6. s.damage(5.0);
    7. s.setFireTicks(40);
    8.  
    9. }

    &
    Code:java
    1. else if (r.getDamager() instanceof Entity && r.getEntity() instanceof Player && Vip.ReturnEvento() == true && r.getEntity().hasMetadata("cabeca") == true ){
    2. Player s = (Player) r.getEntity();
    3. WitherSkull bola = (WitherSkull) r.getDamager();
    4. Player atirador = (Player) bola.getShooter();
    5. atirador.sendMessage("Bateu com wither em: " + r.getEntity());
    6. s.damage(1.0);
    7. s.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 100, 1));
    8. s.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 140, 1));
    9. }


    But i'm not able to differ both using the metaData "cabeca"

    Could anybody point me forward?

    Also tried using EntityExplodeEvent instead of EntityDamageByEntityEvent

    Also tried checking if it was instanceof Fireball
    No success.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page