mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 20:29:20 +00:00
![KHobbits](/assets/img/avatar_default.png)
Replace essentials.teleport.hidden with essentials.vanish.interact Fix perm checks in tpall and tpaall
116 lines
2.7 KiB
Java
116 lines
2.7 KiB
Java
package com.earth2me.essentials.commands;
|
|
|
|
import static com.earth2me.essentials.I18n._;
|
|
import com.earth2me.essentials.User;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Server;
|
|
import org.bukkit.World;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
public class Commandnear extends EssentialsCommand
|
|
{
|
|
public Commandnear()
|
|
{
|
|
super("near");
|
|
}
|
|
|
|
@Override
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
|
{
|
|
long radius = 200;
|
|
User otherUser = null;
|
|
|
|
if (args.length > 0)
|
|
{
|
|
try
|
|
{
|
|
radius = Long.parseLong(args[0]);
|
|
}
|
|
catch (NumberFormatException e)
|
|
{
|
|
try
|
|
{
|
|
otherUser = getPlayer(server, user, args, 0);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
if (args.length > 1 && otherUser != null)
|
|
{
|
|
try
|
|
{
|
|
radius = Long.parseLong(args[1]);
|
|
}
|
|
catch (NumberFormatException e)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
if (otherUser == null || user.isAuthorized("essentials.near.others"))
|
|
{
|
|
user.sendMessage(_("nearbyPlayers", getLocal(server, otherUser == null ? user : otherUser, radius)));
|
|
}
|
|
else
|
|
{
|
|
user.sendMessage(_("noAccessCommand"));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
|
{
|
|
if (args.length == 0)
|
|
{
|
|
throw new NotEnoughArgumentsException();
|
|
}
|
|
final User otherUser = getPlayer(server, args, 0, true, false);
|
|
long radius = 200;
|
|
if (args.length > 1)
|
|
{
|
|
try
|
|
{
|
|
radius = Long.parseLong(args[1]);
|
|
}
|
|
catch (NumberFormatException e)
|
|
{
|
|
}
|
|
}
|
|
sender.sendMessage(_("nearbyPlayers", getLocal(server, otherUser, radius)));
|
|
}
|
|
|
|
private String getLocal(final Server server, final User user, final long radius)
|
|
{
|
|
final Location loc = user.getLocation();
|
|
final World world = loc.getWorld();
|
|
final StringBuilder output = new StringBuilder();
|
|
final long radiusSquared = radius * radius;
|
|
boolean showHidden = user.isAuthorized("essentials.vanish.interact");
|
|
|
|
for (Player onlinePlayer : server.getOnlinePlayers())
|
|
{
|
|
final User player = ess.getUser(onlinePlayer);
|
|
if (!player.equals(user) && (!player.isHidden() || showHidden))
|
|
{
|
|
final Location playerLoc = player.getLocation();
|
|
if (playerLoc.getWorld() != world)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
final long delta = (long)playerLoc.distanceSquared(loc);
|
|
if (delta < radiusSquared)
|
|
{
|
|
if (output.length() > 0)
|
|
{
|
|
output.append(", ");
|
|
}
|
|
output.append(player.getDisplayName()).append("§f(§4").append((long)Math.sqrt(delta)).append("m§f)");
|
|
}
|
|
}
|
|
}
|
|
return output.length() > 1 ? output.toString() : _("none");
|
|
}
|
|
}
|