2011-03-30 04:03:21 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 19:59:39 +00:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2011-03-30 04:03:21 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2013-06-08 21:31:19 +00:00
|
|
|
import com.earth2me.essentials.utils.FormatUtil;
|
2015-08-01 21:38:09 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.Server;
|
2015-08-01 21:38:09 +00:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2011-03-30 04:03:21 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
|
|
|
|
|
|
public class Commandme extends EssentialsCommand {
|
|
|
|
public Commandme() {
|
|
|
|
super("me");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run(Server server, User user, String commandLabel, String[] args) throws Exception {
|
|
|
|
if (user.isMuted()) {
|
|
|
|
throw new Exception(tl("voiceSilenced"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length < 1) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
|
|
|
|
String message = getFinalArg(args, 0);
|
|
|
|
message = FormatUtil.formatMessage(user, "essentials.chat", message);
|
|
|
|
|
|
|
|
user.setDisplayNick();
|
2015-08-01 21:38:09 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-08-02 00:24:23 +00:00
|
|
|
} else {
|
|
|
|
outList.add(player); // Add yourself to the list.
|
2015-08-01 21:38:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outList.size() < 2) {
|
|
|
|
user.sendMessage(tl("localNoOne"));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Player onlinePlayer : outList) {
|
|
|
|
onlinePlayer.sendMessage(toSend);
|
|
|
|
}
|
2015-04-15 04:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception {
|
|
|
|
if (args.length < 1) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
|
|
|
|
String message = getFinalArg(args, 0);
|
|
|
|
message = FormatUtil.replaceFormat(message);
|
2011-03-30 04:03:21 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
ess.getServer().broadcastMessage(tl("action", "@", message));
|
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|