mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-23 03:54:56 +00:00
Added radar command.
Signed-off-by: Steven Lawson <steven@smlawson.com>
This commit is contained in:
parent
4007a8c37a
commit
c7427f492f
3 changed files with 86 additions and 8 deletions
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;
|
||||||
|
@ -185,7 +187,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||||
if (isUserSuperadmin(sender.getName()) || player == null)
|
if (isUserSuperadmin(sender.getName()) || player == null)
|
||||||
{
|
{
|
||||||
tfBroadcastMessage(String.format("(%s: De-opping everyone)", sender.getName()), ChatColor.GRAY);
|
tfBroadcastMessage(String.format("(%s: De-opping everyone)", sender.getName()), ChatColor.GRAY);
|
||||||
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (!isUserSuperadmin(p.getName()) && !p.getName().equals(sender.getName()))
|
if (!isUserSuperadmin(p.getName()) && !p.getName().equals(sender.getName()))
|
||||||
|
@ -207,7 +209,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||||
if (isUserSuperadmin(sender.getName()) || player == null)
|
if (isUserSuperadmin(sender.getName()) || player == null)
|
||||||
{
|
{
|
||||||
tfBroadcastMessage(String.format("(%s: Opping everyone)", sender.getName()), ChatColor.GRAY);
|
tfBroadcastMessage(String.format("(%s: Opping everyone)", sender.getName()), ChatColor.GRAY);
|
||||||
|
|
||||||
boolean doSetGamemode = false;
|
boolean doSetGamemode = false;
|
||||||
GameMode targetGamemode = GameMode.CREATIVE;
|
GameMode targetGamemode = GameMode.CREATIVE;
|
||||||
if (args.length != 0)
|
if (args.length != 0)
|
||||||
|
@ -228,7 +230,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||||
{
|
{
|
||||||
p.setOp(true);
|
p.setOp(true);
|
||||||
p.sendMessage(YOU_ARE_OP);
|
p.sendMessage(YOU_ARE_OP);
|
||||||
|
|
||||||
if (doSetGamemode)
|
if (doSetGamemode)
|
||||||
{
|
{
|
||||||
p.setGameMode(targetGamemode);
|
p.setGameMode(targetGamemode);
|
||||||
|
@ -255,7 +257,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||||
for (Player p : Bukkit.matchPlayer(args[0]))
|
for (Player p : Bukkit.matchPlayer(args[0]))
|
||||||
{
|
{
|
||||||
matched_player = true;
|
matched_player = true;
|
||||||
|
|
||||||
tfBroadcastMessage(String.format("(%s: Opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
|
tfBroadcastMessage(String.format("(%s: Opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
|
||||||
p.setOp(true);
|
p.setOp(true);
|
||||||
p.sendMessage(YOU_ARE_OP);
|
p.sendMessage(YOU_ARE_OP);
|
||||||
|
@ -285,7 +287,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||||
for (Player p : Bukkit.matchPlayer(args[0]))
|
for (Player p : Bukkit.matchPlayer(args[0]))
|
||||||
{
|
{
|
||||||
matched_player = true;
|
matched_player = true;
|
||||||
|
|
||||||
tfBroadcastMessage(String.format("(%s: De-opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
|
tfBroadcastMessage(String.format("(%s: De-opping %s)", sender.getName(), p.getName()), ChatColor.GRAY);
|
||||||
p.setOp(false);
|
p.setOp(false);
|
||||||
p.sendMessage(YOU_ARE_NOT_OP);
|
p.sendMessage(YOU_ARE_NOT_OP);
|
||||||
|
@ -480,7 +482,7 @@ public class TotalFreedomMod extends JavaPlugin
|
||||||
if (player == null || isUserSuperadmin(sender.getName()))
|
if (player == null || isUserSuperadmin(sender.getName()))
|
||||||
{
|
{
|
||||||
tfBroadcastMessage("Server is going offline.", ChatColor.GRAY);
|
tfBroadcastMessage("Server is going offline.", ChatColor.GRAY);
|
||||||
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
p.kickPlayer("Server is going offline, come back in a few minutes.");
|
p.kickPlayer("Server is going offline, come back in a few minutes.");
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -583,13 +630,13 @@ public class TotalFreedomMod extends JavaPlugin
|
||||||
public static void tfBroadcastMessage(String message, ChatColor color)
|
public static void tfBroadcastMessage(String message, ChatColor color)
|
||||||
{
|
{
|
||||||
log.info(message);
|
log.info(message);
|
||||||
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
p.sendMessage(color + message);
|
p.sendMessage(color + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String implodeStringList(String glue, List<String> pieces)
|
private static String implodeStringList(String glue, List<String> pieces)
|
||||||
{
|
{
|
||||||
StringBuilder output = new StringBuilder();
|
StringBuilder output = new StringBuilder();
|
||||||
|
|
|
@ -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 a new issue