mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Added radar command.
Signed-off-by: Steven Lawson <steven@smlawson.com>
This commit is contained in:
parent
4007a8c37a
commit
c7427f492f
28
src/me/StevenLawson/TotalFreedomMod/RadarData.java
Normal file
28
src/me/StevenLawson/TotalFreedomMod/RadarData.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package me.StevenLawson.TotalFreedomMod;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class RadarData implements Comparator<RadarData>
|
||||||
|
{
|
||||||
|
Player player;
|
||||||
|
double distance;
|
||||||
|
|
||||||
|
public RadarData(Player inplayer, double indistance)
|
||||||
|
{
|
||||||
|
this.player = inplayer;
|
||||||
|
this.distance = indistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RadarData()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(RadarData t1, RadarData t2)
|
||||||
|
{
|
||||||
|
if (t1.distance > t2.distance) return 1;
|
||||||
|
else if (t1.distance < t2.distance) return -1;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -2,12 +2,14 @@ package me.StevenLawson.TotalFreedomMod;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -576,6 +578,51 @@ public class TotalFreedomMod extends JavaPlugin
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (cmd.getName().equalsIgnoreCase("radar"))
|
||||||
|
{
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
sender.sendMessage("This command can only be used in-game.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player sender_player = Bukkit.getPlayerExact(sender.getName());
|
||||||
|
Location sender_pos = sender_player.getLocation();
|
||||||
|
String sender_world = sender_player.getWorld().getName();
|
||||||
|
|
||||||
|
List<RadarData> radar_data = new ArrayList<RadarData>();
|
||||||
|
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
if (sender_world.equals(p.getWorld().getName()))
|
||||||
|
{
|
||||||
|
radar_data.add(new RadarData(p, sender_pos.distance(p.getLocation())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(radar_data, new RadarData());
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.YELLOW + "People nearby in " + sender_world + ":");
|
||||||
|
|
||||||
|
int countmax = 5;
|
||||||
|
if (args.length == 1)
|
||||||
|
{
|
||||||
|
countmax = Integer.parseInt(args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for (RadarData i : radar_data)
|
||||||
|
{
|
||||||
|
if (count++ > countmax)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(ChatColor.YELLOW + String.format("%s - %d", i.player.getName(), Math.round(i.distance)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,9 @@ commands:
|
|||||||
qop:
|
qop:
|
||||||
description: Quick Op - op someone based on a partial name.
|
description: Quick Op - op someone based on a partial name.
|
||||||
usage: /<command> <partialname>
|
usage: /<command> <partialname>
|
||||||
|
radar:
|
||||||
|
description: Shows nearby people sorted by distance.
|
||||||
|
usage: /<command>
|
||||||
say:
|
say:
|
||||||
description: Broadcasts the given message as the console, includes sender.
|
description: Broadcasts the given message as the console, includes sender.
|
||||||
usage: /<command> <message>
|
usage: /<command> <message>
|
||||||
|
Loading…
Reference in New Issue
Block a user