I'm a bit of a noob to developing plugins, but up until this point I've been able to figure things out because of prior Java experience, the API's, some tutorials, etc. Now I'm having an issue that I can't seem to fix. I'm setting up a command for my server (/builders) which shows a list of the online builders who can be summoned to your location to give you building advice. I've made a system for sending the list of builders like this (don't ask why I called my command variable bobmc):
if (bobmc.getName().equalsIgnoreCase("builders") && sender instanceof Player) {
Player p = (Player) sender;
List<Player> onlineBuilders = new ArrayList<Player>();
for (Player players : Bukkit.getOnlinePlayers()) {
if (PermissionsEx.getPermissionManager().getUser(players).inGroup("builder")) {
onlineBuilders.add(players);
}
}
sender.sendMessage(ChatColor.BLUE + "Builders List: " + ChatColor.BOLD + "" + onlineBuilders);
return true;
}
The issue with this is that it prints this out:
I can't seem to remedy this, and there don't seem to be any other posts on the internet to help me.
Use a String
to print the names. There is no need to create a List
if you're only looking for the player names. To get the names you can use getName()
.
if (bobmc.getName().equalsIgnoreCase("builders") && sender instanceof Player) {
Player p = (Player) sender;
String onlineBuilders = "";
for (Player players : Bukkit.getOnlinePlayers()) {
if (PermissionsEx.getPermissionManager().getUser(players).inGroup("builder")) {
onlineBuilders += players.getName() + " ";
}
}
sender.sendMessage(ChatColor.BLUE + "Builders List: " + ChatColor.BOLD + "" + onlineBuilders.trim());
return true;
}