QoL/src/main/java/xyz/etztech/qol/commands/WorldInfoCommand.java

62 lines
2.1 KiB
Java

package xyz.etztech.qol.commands;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.etztech.qol.EtzTechUtil;
import xyz.etztech.qol.Lang;
import xyz.etztech.qol.QoL;
import java.util.*;
public class WorldInfoCommand implements CommandExecutor {
QoL plugin;
public WorldInfoCommand(QoL plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!sender.hasPermission("qol.worldinfo")) {
EtzTechUtil.sms(sender, Lang.NO_PERMISSION.getDef());
return true;
}
Map<String, List<String>> worlds = new HashMap<>();
for (World world : Bukkit.getServer().getWorlds()) {
for (Player player : world.getPlayers()) {
if (worlds.containsKey(world.getName())) {
worlds.get(world.getName()).add(getName(world.getName(), player));
} else {
worlds.put(world.getName(), new ArrayList<>(Arrays.asList(getName(world.getName(), player))));
}
}
}
StringBuilder message = new StringBuilder(ChatColor.GOLD + "===== World Info =====");
for (String world : worlds.keySet()) {
message.append("\n").append(ChatColor.YELLOW).append(world).append(": ").append(StringUtils.join(worlds.get(world).toArray(), ChatColor.YELLOW + ", "));
}
sender.sendMessage(message.toString());
return true;
}
private String getName(String world, Player player) {
int range = plugin.getConfig().getInt("worldinfo." + world, 0);
ChatColor color = ChatColor.GREEN;
if (range > 0 && (player.getLocation().getBlockX() > range || player.getLocation().getBlockZ() > range)) {
color = ChatColor.RED;
}
return color + player.getName();
}
}