How to detect if a snowball has hit the player.

Discussion in 'Spigot Plugin Development' started by MrMaster_, Jun 19, 2015.

  1. Hello! I'm new to the spigot forums and i am currently working on my second plugin! Its a snowball arena plugin and i need the players to be able to throw snowballs at each other, and if a player is hit, remove them from the arraylist. So, i have one variable in place : public boolean LobbyFull = false;

    Is there a way i can incorporate this variable into the snowball code to make sure it only detects the snowball hitting if the lobbyfull = true? I already have a load of code that does change lobbyfull, but i need help on the snowball detection! :)

    Finally on the right forum!!!
  2. What you do is in the EntityDamageByEntityEvent, you check if the damager is an instanceof a snowball, and then you check if the entity is an instanceof a player. If so you know that a snowball has hit a player, the you can get the thrower by casting the damager to a snowball and use the getShooter method. Then you check if the boolean lobbyfull is true and if that true you can do the code.
    Hope this helps!
  3. Thank you very much for the fast reply! But where do i put this in my code? Just in a block of its own inside of the class? Ive done this before with the event you listed above, but i cannot seem to get it to work.

    ... Ive been testing this event on myself by throwing a snowball in the air, is this why its not working? Do i need another player?
  4. Just to note you can also check for instanceof Projectile if you do not require the difference between snowball and arrow.
  5. I do want to only check if its a snowball, but thanks for the tip!
  6. I recommend only creating ONE thread
  7. I just looked into the EntitySnowball source code, I don't see any event triggers, except the ProjectileHitEvent. So you would need to use that. But I don't know how to get the entity you hit. You can see which player is on the same block as the snowball.
  8. Yes, but it turns out i posted it twice in the wrong place. I just really need help on this D:
  9. You could have hit the report button asking for it to be moved, users would have still helped
  10. Sorry, i'm really new to the forums. Thanks for telling me that! Anyway, does anyone have a answer to my problem?
  11. Please help? This is my second plugin and i urgently need help.
  12. Have you tried this?
  13. But i still need to get the player too. this is my main problem.
  14. Also, i am not too sure on how the ProjectileHitEvent works. D:
  15. You can also use the EntityDamageEvent check if it's a player that's getting damaged, and check if the last damager is an instanceof snowball
    • Agree Agree x 1
  16. ProjectileHitEvent has a method where you get the projectile. Check if(instanceof Snowball) first, then check if(projectile.getShooter() instanceof Player) and then cast projectile.getShooter() to Player.

    If you have any questions please check basic java tutorials first. for example oracle's