2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2011-10-19 00:37:00 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2013-08-03 20:08:16 +00:00
|
|
|
import java.util.Comparator;
|
2011-10-19 00:37:00 +00:00
|
|
|
import java.util.List;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2011-10-19 00:37:00 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.NON_OP, source = SourceType.ONLY_IN_GAME)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(description = "Shows nearby people sorted by distance.", usage = "/<command> [range]")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_radar extends FreedomCommand
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
Location playerSenderos = playerSender.getLocation();
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2018-01-02 02:46:35 +00:00
|
|
|
List<RadarData> radar_data = new ArrayList<>();
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
for (Player player : playerSenderos.getWorld().getPlayers())
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
if (!player.equals(playerSender))
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2011-10-28 00:37:30 +00:00
|
|
|
try
|
|
|
|
{
|
2018-01-02 02:46:35 +00:00
|
|
|
radar_data.add(new RadarData(player, playerSenderos.distance(player.getLocation()), player.getLocation()));
|
2011-10-28 00:37:30 +00:00
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (IllegalArgumentException ex)
|
2011-10-28 00:37:30 +00:00
|
|
|
{
|
|
|
|
}
|
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())
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("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
|
|
|
|
2018-01-02 02:46:35 +00:00
|
|
|
Collections.sort(radar_data, new RadarData());
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("People nearby in " + playerSenderos.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
|
|
|
|
2018-01-02 02:46:35 +00:00
|
|
|
for (RadarData i : radar_data)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg(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;
|
|
|
|
}
|
2013-08-03 20:08:16 +00:00
|
|
|
|
2018-01-02 02:46:35 +00:00
|
|
|
private class RadarData implements Comparator<RadarData>
|
2013-08-03 20:08:16 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2013-08-03 20:08:16 +00:00
|
|
|
public Player player;
|
|
|
|
public double distance;
|
|
|
|
public Location location;
|
|
|
|
|
2018-01-02 02:46:35 +00:00
|
|
|
public RadarData(Player player, double distance, Location location)
|
2013-08-03 20:08:16 +00:00
|
|
|
{
|
|
|
|
this.player = player;
|
|
|
|
this.distance = distance;
|
|
|
|
this.location = location;
|
|
|
|
}
|
|
|
|
|
2018-01-02 02:46:35 +00:00
|
|
|
public RadarData()
|
2013-08-03 20:08:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-01-02 02:46:35 +00:00
|
|
|
public int compare(RadarData t1, RadarData t2)
|
2013-08-03 20:08:16 +00:00
|
|
|
{
|
|
|
|
if (t1.distance > t2.distance)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (t1.distance < t2.distance)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|