56 lines
1.7 KiB
Java
56 lines
1.7 KiB
Java
package xyz.etztech.qol.commands;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import xyz.etztech.qol.QoL;
|
|
|
|
import java.util.*;
|
|
|
|
public class ListCommand implements CommandExecutor {
|
|
|
|
QoL plugin;
|
|
|
|
public ListCommand(QoL plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
|
|
|
|
Map<String, List<String>> list = new HashMap<>();
|
|
List<String> groups = plugin.getConfig().getStringList("list");
|
|
|
|
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
|
for (String group : groups) {
|
|
if (player.hasPermission("qol.list." + group)) {
|
|
List<String> names = list.containsKey(group) ? list.get(group) : new ArrayList<String>();
|
|
names.add(player.getName());
|
|
list.put(group, names);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
StringBuilder message = new StringBuilder();
|
|
for (String key : list.keySet()) {
|
|
List<String> parts = Arrays.asList(key.split("_"));
|
|
parts.forEach(StringUtils::capitalize);
|
|
message.append(ChatColor.GOLD)
|
|
.append(StringUtils.join(parts, " "))
|
|
.append(": ")
|
|
.append(ChatColor.YELLOW)
|
|
.append(StringUtils.join(list.get(key), ", "))
|
|
.append("\n");
|
|
}
|
|
|
|
commandSender.sendMessage(message.toString());
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|