mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-08 12:00:19 +01:00
Have me command respect chat radius. Implements #118.
Adds similar functionality to that of chat in essentials chat.
This commit is contained in:
parent
76498e86f5
commit
792c7d5e91
@ -3,7 +3,14 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
@ -27,7 +34,47 @@ public class Commandme extends EssentialsCommand {
|
||||
message = FormatUtil.formatMessage(user, "essentials.chat", message);
|
||||
|
||||
user.setDisplayNick();
|
||||
ess.broadcastMessage(user, tl("action", user.getDisplayName(), message));
|
||||
int radius = ess.getSettings().getChatRadius();
|
||||
String toSend = tl("action", user.getDisplayName(), message);
|
||||
if (radius < 1) {
|
||||
ess.broadcastMessage(user, toSend);
|
||||
return;
|
||||
}
|
||||
|
||||
World world = user.getWorld();
|
||||
Location loc = user.getLocation();
|
||||
Set<Player> outList = new HashSet<>();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
final User onlineUser = ess.getUser(player);
|
||||
if (!onlineUser.equals(user)) {
|
||||
boolean abort = false;
|
||||
final Location playerLoc = onlineUser.getLocation();
|
||||
if (playerLoc.getWorld() != world) {
|
||||
abort = true;
|
||||
} else {
|
||||
final double delta = playerLoc.distanceSquared(loc);
|
||||
if (delta > radius) {
|
||||
abort = true;
|
||||
}
|
||||
}
|
||||
if (abort) {
|
||||
if (onlineUser.isAuthorized("essentials.chat.spy")) {
|
||||
outList.add(player); // Just use the same list unless we wanted to format spyying for this.
|
||||
}
|
||||
} else {
|
||||
outList.add(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (outList.size() < 2) {
|
||||
user.sendMessage(tl("localNoOne"));
|
||||
}
|
||||
|
||||
for (Player onlinePlayer : outList) {
|
||||
onlinePlayer.sendMessage(toSend);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user