2018-09-12 16:06:02 +00:00
|
|
|
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;
|
2018-09-15 21:20:31 +00:00
|
|
|
import xyz.etztech.qol.EtzTechUtil;
|
2018-09-12 16:06:02 +00:00
|
|
|
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;
|
2020-07-09 14:42:58 +00:00
|
|
|
plugin.getCommand("worldinfo").setExecutor(this);
|
2018-09-12 16:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
if (!sender.hasPermission("qol.worldinfo")) {
|
2018-09-15 21:20:31 +00:00
|
|
|
EtzTechUtil.sms(sender, Lang.NO_PERMISSION.getDef());
|
|
|
|
return true;
|
2018-09-12 16:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|