My code doesnt work

Discussion in 'Plugin Development' started by john2342, Jul 28, 2014.

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

    john2342

    A little nooby of me, but this little bit of code doesnt work, help?
    Code:java
    1. @EventHandler
    2. public void onHit(EntityDamageByEntityEvent e) {
    3. Player dmgd = (Player) e.getEntity();
    4.  
    5. if(e.getEntity() instanceof Player && e.getDamager() instanceof Arrow) {
    6. dmgd.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 1, 5));
    7. }
    8. }
     
  2. Offline

    theguynextdoor

    You cast e.getEntity() before checking it.
     
  3. Offline

    john2342

    I tried adding dmgd.sendMessage("hi"); and it worked, with the potion thing in there, but the potion part didnt work
     
  4. Offline

    theguynextdoor

    Increase the duration of the potion effect to something much higher. Try something like 1000, then go from there.
     
  5. Offline

    zDylann

    Code:java
    1. dmgd.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 1, 5));

    The 1 in that new PotionEffect represents 1 tick. There are 20 ticks in 1 second. If you want the potion effect to last longer just add how many seconds in ticks.

    Example:
    Code:java
    1. dmgd.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 200, 5));
    2. //200 = 10 seconds.
     
  6. Offline

    john2342

    Ahhh, it represents ticks. Yeah I'm familiar with ticks, I forgot thats the primary numeration tool in Bukkit XD.
     
Thread Status:
Not open for further replies.

Share This Page