Solved Potion effect players in radius who are on opposing team

Discussion in 'Plugin Development' started by kember007, Sep 27, 2015.

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

    kember007

    So first of all, I have 2 teams (red/blue), they're held in a hashmap:
    Code:java
    1. public static Map<Player, String> teams = new HashMap<Player, String>();

    I want to have an ability for players to use that can apply a potion effect to nearby players who are on the opposing team.
    I've use this code but it doesn't work:
    Code:java
    1. String atkTeam = teams.get(player);
    2. for(Entity en : player.getNearbyEntities(5, 5, 5))
    3. {
    4. if(en instanceof LivingEntity && en instanceof Player)
    5. {
    6. Player p = (Player) en;
    7. String enTeam = teams.get(p);
    8. if(enTeam != null && atkTeam != null && !enTeam.equals(atkTeam))
    9. {
    10. PotionEffect slowness = PotionEffectType.SLOW.createEffect(10, 1);
    11. p.addPotionEffect(slowness);
    12. }
    13. else
    14. {
    15. PotionEffect slowness = PotionEffectType.SLOW.createEffect(10, 1);
    16. p.addPotionEffect(slowness);
    17. p.sendMessage("test");
    18. }
    19. }
    20. else if(en instanceof LivingEntity)
    21. {
    22. PotionEffect slowness = PotionEffectType.HARM.createEffect(1, 1);
    23. ((LivingEntity) en).addPotionEffect(slowness);
    24. }
    25. }
     
  2. Offline

    RoboticPlayer

    Add more debug statements to check where the code went wrong.
     
  3. Offline

    finalblade1234

    Could you show me the rest of the code? (Where is this code called from?) Also, 10 should be 10*20, since 10 = 1/2 a second
     
    kember007 likes this.
  4. Offline

    RoboticPlayer

    Also, why are you using createEffect? Just do
    Code:
    PotionEffect slowness = new PotionEffect(PotionEffectType.SLOWNESS, int duration, int amplifier);
    // Remember that the duration is stored in ticks
    // And the amplifier starts at 0
    p.addPotionEffect(slowness);
     
  5. Offline

    kember007

    @finalblade1234 I changed 10 to 40 and it seems to be working now, thanks :)
     
Thread Status:
Not open for further replies.

Share This Page