2018-03-27 01:42:26 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.FPlayer;
|
|
|
|
import com.massivecraft.factions.FPlayers;
|
2019-09-14 21:13:01 +02:00
|
|
|
import com.massivecraft.factions.FactionsPlugin;
|
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2018-03-27 01:42:26 +02:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
public class CmdNear extends FCommand {
|
2019-09-15 11:19:06 +02:00
|
|
|
public CmdNear() {
|
|
|
|
super();
|
|
|
|
this.aliases.add("near");
|
|
|
|
this.aliases.add("nearby");
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.NEAR)
|
|
|
|
.playerOnly()
|
|
|
|
.memberOnly()
|
|
|
|
.build();
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
@Override
|
|
|
|
public void perform(CommandContext context) {
|
|
|
|
if (!FactionsPlugin.getInstance().getConfig().getBoolean("fnear.Enabled")) {
|
|
|
|
context.msg(TL.COMMAND_NEAR_DISABLED_MSG);
|
|
|
|
return;
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
double range = FactionsPlugin.getInstance().getConfig().getInt("fnear.Radius");
|
|
|
|
String format = TL.COMMAND_NEAR_FORMAT.toString();
|
|
|
|
context.msg(TL.COMMAND_NEAR_USE_MSG);
|
|
|
|
for (Entity e : context.player.getNearbyEntities(range, 255, range)) {
|
|
|
|
if (e instanceof Player) {
|
|
|
|
Player player = (((Player) e).getPlayer());
|
|
|
|
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
|
|
|
|
if (context.faction == fplayer.getFaction()) {
|
|
|
|
double distance = context.player.getLocation().distance(player.getLocation());
|
|
|
|
context.sendMessage(format.replace("{playername}", player.getDisplayName()).replace("{distance}", (int) distance + ""));
|
|
|
|
}
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_NEAR_DESCRIPTION;
|
|
|
|
}
|
2018-03-27 01:42:26 +02:00
|
|
|
}
|