Help with the awesome coolness.

Discussion in 'Plugin Development' started by DatCookiez, Jan 25, 2014.

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

    DatCookiez

    Hey Guys,
    i was just wondering if there was a way to check if there was no one in the radius of the nearbyPlayers.... Like if no player is in range, it sends a message to the player saying so.

    Code:
    Code:java
    1. @EventHandler
    2. public void onPlayerFreeze(PlayerInteractEvent e){
    3. Player p = e.getPlayer();
    4. List<Entity> nearbyEntities = p.getNearbyEntities(10, 10, 10);
    5. ArrayList<Player> nearbyPlayers = new ArrayList<Player>();
    6. if ((e.getAction() == Action.LEFT_CLICK_BLOCK && e.getPlayer().getItemInHand().getType()
    7. == Material.SNOW_BLOCK
    8. || e.getAction() == Action.LEFT_CLICK_AIR && e.getPlayer().getItemInHand().getType()
    9. == Material.SNOW_BLOCK)){
    10.  
    11. int cooldownTime = 20; // Get number of seconds from wherever you want
    12. if(snow.containsKey(p.getName())) {
    13. long secondsLeft = ((snow.get(p.getName())/1000)+cooldownTime) - (System.currentTimeMillis()/1000);
    14. if(secondsLeft>0) {
    15. // Still cooling down
    16. p.sendMessage(ChatColor.RED + "Wait " + ChatColor.GOLD + secondsLeft + ChatColor.RED + " seconds to use this again!");
    17. return;
    18. }
    19. }
    20. // No cooldown found or cooldown has expired, save new cooldown
    21. snow.put(p.getName(), System.currentTimeMillis());
    22.  
    23. p.getLocation().getWorld();
    24. for (Entity e1 : nearbyEntities) {
    25. if (e1 instanceof Player) {
    26. nearbyPlayers.add((Player) e1);
    27. for (Player p1 : nearbyPlayers) {
    28. p1.getLocation().getWorld();
    29. Snow.add(p1.getName());
    30. p1.sendMessage(ChatColor.GOLD + p.getName() + ChatColor.RED + " has frozen you!!");
    31.  
    32.  
    33. }
    34. }
    35. }
    36. }
    37. }
     
  2. Offline

    Ironraptor3

    just use getNearbyEntities like you have been doing, check if the entity is a player, and if it is, send the player a message and break the for loop
     
  3. Offline

    DatCookiez

  4. Offline

    xTrollxDudex

    DatCookiez
    Isn't "loop through get nearby entities" enough detail already?
     
Thread Status:
Not open for further replies.

Share This Page