2011-10-19 00:37:00 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_RadarData;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2013-03-19 22:05:20 +00:00
|
|
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.ONLY_IN_GAME)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(description = "Shows nearby people sorted by distance.", usage = "/<command> [range]")
|
2011-10-19 00:37:00 +00:00
|
|
|
public class Command_radar extends TFM_Command
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
2011-10-19 16:04:44 +00:00
|
|
|
Location sender_pos = sender_p.getLocation();
|
2011-10-19 00:37:00 +00:00
|
|
|
|
|
|
|
List<TFM_RadarData> radar_data = new ArrayList<TFM_RadarData>();
|
|
|
|
|
2011-10-19 16:04:44 +00:00
|
|
|
for (Player p : sender_pos.getWorld().getPlayers())
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2011-10-19 16:04:44 +00:00
|
|
|
if (!p.equals(sender_p))
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2011-10-28 00:37:30 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
radar_data.add(new TFM_RadarData(p, sender_pos.distance(p.getLocation()), p.getLocation()));
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException ex)
|
|
|
|
{
|
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-19 22:05:20 +00:00
|
|
|
|
2011-10-19 16:04:44 +00:00
|
|
|
if (radar_data.isEmpty())
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("You are the only player in this world. (" + ChatColor.GREEN + "Forever alone..." + ChatColor.YELLOW + ")", ChatColor.YELLOW); //lol
|
2011-10-19 16:04:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
|
|
|
|
Collections.sort(radar_data, new TFM_RadarData());
|
|
|
|
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("People nearby in " + sender_pos.getWorld().getName() + ":", ChatColor.YELLOW);
|
2011-10-19 00:37:00 +00:00
|
|
|
|
|
|
|
int countmax = 5;
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-10-19 02:52:32 +00:00
|
|
|
countmax = Math.max(1, Math.min(64, Integer.parseInt(args[0])));
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
|
|
|
catch (NumberFormatException nfex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 22:05:20 +00:00
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
for (TFM_RadarData i : radar_data)
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg(String.format("%s - %d",
|
2011-10-19 00:37:00 +00:00
|
|
|
i.player.getName(),
|
2013-03-19 22:05:20 +00:00
|
|
|
Math.round(i.distance)), ChatColor.YELLOW);
|
|
|
|
|
2011-10-19 16:04:44 +00:00
|
|
|
if (--countmax <= 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|