TF-EssentialsX/Essentials/src/main/java/com/earth2me/essentials/commands/Commandme.java

107 lines
3.8 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DateUtil;
2013-06-08 21:31:19 +00:00
import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
2011-11-18 17:42:26 +00:00
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
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
2020-10-03 17:46:05 +00:00
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
2015-04-15 04:06:16 +00:00
if (user.isMuted()) {
2020-10-03 17:46:05 +00:00
final String dateDiff = user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : null;
if (dateDiff == null) {
throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReason", user.getMuteReason()) : tl("voiceSilenced"));
}
throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff));
2015-04-15 04:06:16 +00:00
}
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
String message = getFinalArg(args, 0);
message = FormatUtil.formatMessage(user, "essentials.chat", message);
user.setDisplayNick();
2020-10-03 17:46:05 +00:00
final int radius = ess.getSettings().getChatRadius();
final String toSend = tl("action", user.getDisplayName(), message);
if (radius < 1) {
ess.broadcastMessage(user, toSend);
return;
}
2020-10-03 17:46:05 +00:00
final World world = user.getWorld();
final Location loc = user.getLocation();
final Set<Player> outList = new HashSet<>();
2020-10-03 17:46:05 +00:00
for (final 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 if (onlineUser.isIgnoredPlayer(user)) {
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.
}
}
if (outList.size() < 2) {
user.sendMessage(tl("localNoOne"));
}
2020-10-03 17:46:05 +00:00
for (final Player onlinePlayer : outList) {
onlinePlayer.sendMessage(toSend);
}
2015-04-15 04:06:16 +00:00
}
@Override
2020-10-03 17:46:05 +00:00
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
2015-04-15 04:06:16 +00:00
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
String message = getFinalArg(args, 0);
message = FormatUtil.replaceFormat(message);
2015-04-15 04:06:16 +00:00
ess.getServer().broadcastMessage(tl("action", "@", message));
}
@Override
2020-10-03 17:46:05 +00:00
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
return Collections.emptyList();
}
}