Getting players withing a certain radius

Discussion in 'Plugin Development' started by ColaCraft, Jul 29, 2013.

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

    ColaCraft

    Hey guys, I am trying to grab the players within a certain radius of a player of the "Healer" class.

    Here is the whole Listener class:

    Code:java
    1. package me.PorterK.RPG;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Arrow;
    5. import org.bukkit.entity.Entity;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.EventPriority;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.entity.CreatureSpawnEvent;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.potion.PotionEffect;
    14. import org.bukkit.potion.PotionEffectType;
    15.  
    16. public class ClassListener implements Listener{
    17.  
    18. private static main plugin;
    19.  
    20. public ClassListener(main instance) {
    21. plugin = instance;
    22. }
    23.  
    24. @EventHandler
    25. public void onPlayerInteractEvent(PlayerInteractEvent event){
    26. Player p = event.getPlayer();
    27. String name = p.getName();
    28.  
    29. if((event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) && event.getPlayer().getInventory().getItemInHand().getType().equals(Material.BOW)){
    30.  
    31. if(plugin.getConfig().getString("users." + name + ".class").equalsIgnoreCase("Archer")){
    32. Arrow ar = (Arrow) p.getWorld().spawn(p.getEyeLocation(), Arrow.class);
    33. ar.setShooter(p);
    34. ar.setVelocity(p.getLocation().getDirection().multiply(1.6));
    35. }
    36.  
    37. }
    38.  
    39.  
    40. if((event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) && event.getPlayer().getInventory().getItemInHand().getType().equals(Material.MELON_STEM)){
    41.  
    42. if(plugin.getConfig().getString("users." + name + ".class").equalsIgnoreCase("Healer")){
    43.  
    44.  
    45. for(Entity entity : p.getNearbyEntities(5.0D, 5.0D, 5.0D)){
    46. if(entity instanceof Player){
    47. Player nearby = (Player) entity;
    48. nearby.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 420, 5));
    49. nearby.sendMessage("Works");
    50.  
    51. }
    52. }
    53. }
    54. }
    55.  
    56. }
    57.  
    58.  
    59. @EventHandler(priority = EventPriority.NORMAL)
    60. public void onCreatureSpawn(CreatureSpawnEvent event) {
    61. if(event.getLocation().getWorld().getName() != "world_nether") {
    62. if(event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.SPAWNER || event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.CUSTOM) {
    63. event.setCancelled(true);
    64. }
    65. }
    66. }
    67.  
    68.  
    69. }


    Here is the block you should be focusing on:

    Code:java
    1. if((event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) && event.getPlayer().getInventory().getItemInHand().getType().equals(Material.MELON_STEM)){
    2.  
    3. if(plugin.getConfig().getString("users." + name + ".class").equalsIgnoreCase("Healer")){
    4.  
    5.  
    6. for(Entity entity : p.getNearbyEntities(5.0D, 5.0D, 5.0D)){
    7. if(entity instanceof Player){
    8. Player nearby = (Player) entity;
    9. nearby.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 420, 5));
    10. nearby.sendMessage("Works");
    11.  
    12. }
    13. }
    14. }
    15. }


    This block does pretty much nothing :/.

    Please help, thanks!
     
  2. Offline

    Pawnguy7

    Does the for loop trigger?
     
  3. Offline

    ColaCraft


    Don't think so.
     
  4. Offline

    Pawnguy7

    Try printing out a line right before the for loop. See if it runs. Maybe the config line is false, or something else.
     
    ColaCraft likes this.
  5. Offline

    ColaCraft

    Found the issue. Wasn't in the healer rank. :p Thanks for pointing that out! Like for you :)
     
Thread Status:
Not open for further replies.

Share This Page