Solved Paintball teams not working

Discussion in 'Plugin Development' started by ZyphiorMC, Nov 23, 2014.

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

    ZyphiorMC

    I am making a paintball plugin, but I have run in to a little problem with my teams system...

    I did not forget to assign players to a team.

    When I hit my other account with a snowball, nothing happens except the account taking "damage", even though I have event.setCancelled(true);

    Code:java
    1. ArrayList<Player> blueTeam = new ArrayList<Player>();
    2. ArrayList<Player> greenTeam = new ArrayList<Player>();

    Code:java
    1. public void onSnowballHit(EntityDamageByEntityEvent event)
    2. {
    3. Entity damaged = event.getEntity();
    4. Entity damageEntity = event.getDamager();
    5. Snowball snowball = (Snowball) damageEntity;
    6. LivingEntity entityThrower = (LivingEntity) snowball.getShooter();
    7.  
    8. if(damaged instanceof Player)
    9. if(damageEntity instanceof Snowball)
    10. {
    11. if(entityThrower instanceof Player)
    12. {
    13. Player playerThrower = (Player) entityThrower;
    14. Player playerHit = (Player) damaged;
    15.  
    16. if((blueTeam.contains(playerHit)) && (blueTeam.contains(playerThrower)))
    17. {
    18. playerThrower.sendMessage(prefix + "Do not hit your own team mates!");
    19. event.setCancelled(true);
    20. }
    21. else if((greenTeam.contains(playerHit)) && (greenTeam.contains(playerThrower)))
    22. {
    23. playerThrower.sendMessage(prefix + "Do not hit your own team mates!");
    24. event.setCancelled(true);
    25. }
    26. else if((blueTeam.contains(playerHit)) && (greenTeam.contains(playerThrower)))
    27. {
    28. playerHit.sendMessage(prefix + ChatColor.YELLOW + "You were fragged by " + ChatColor.RED + playerThrower);
    29. playerThrower.sendMessage(prefix + ChatColor.YELLOW + "You fragged " + ChatColor.RED + playerHit);
    30. event.setCancelled(true);
    31. }
    32. else if((greenTeam.contains(playerHit)) && (blueTeam.contains(playerThrower)))
    33. {
    34. playerHit.sendMessage(prefix + ChatColor.YELLOW + "You were fragged by " + ChatColor.RED + playerThrower);
    35. playerThrower.sendMessage(prefix + ChatColor.YELLOW + "You fragged " + ChatColor.RED + playerHit);
    36. event.setCancelled(true);
    37. }
    38. }
    39. }
    40. }
     
  2. Offline

    MnMaxon

    ZyphiorMC I'm sorry I can't help you much with your problem, it looks like it should work. I did notice that you did not check if damageEntity is a snowball before casting a snowball to it. When I try to find bugs, I usually add Bukkit.broadcastMessage("1");, then Bukkit.broadcastMessage("2");... in different parts of my code to find where the code stops.
     
  3. Offline

    TGRHavoc

    ZyphiorMC
    Does your class extend "EventListener"?
    Do you put the "@EventHandler" annotation before the method you defined? These questions would have been answered if you showed all your code.

    Look at my suggestions, if they still don't solve your problem, post all your code so that we can help you better.
     
  4. Offline

    ZyphiorMC

    TGRHavoc MnMaxon
    I feel so stupid...
    I forgot to register the event in my onEnable :p
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(this, this);
     
    MnMaxon and TGRHavoc like this.
Thread Status:
Not open for further replies.

Share This Page