mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-07 11:20:32 +01:00
Rewrote the who-command. Fixes #467.
This commit is contained in:
parent
772d5a222d
commit
e7573d3bd7
@ -15,7 +15,6 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,11 +27,14 @@ public class WhoCommand extends MultiverseCommand {
|
|||||||
public WhoCommand(MultiverseCore plugin) {
|
public WhoCommand(MultiverseCore plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
this.setName("Who?");
|
this.setName("Who?");
|
||||||
this.setCommandUsage("/mv who" + ChatColor.GOLD + " [WORLD]");
|
this.setCommandUsage("/mv who" + ChatColor.GOLD + " [WORLD|--all]");
|
||||||
this.setArgRange(0, 1);
|
this.setArgRange(0, 1);
|
||||||
this.addKey("mv who");
|
this.addKey("mv who");
|
||||||
this.addKey("mvw");
|
this.addKey("mvw");
|
||||||
this.addKey("mvwho");
|
this.addKey("mvwho");
|
||||||
|
this.addCommandExample("/mv who");
|
||||||
|
this.addCommandExample(String.format("/mv who %s--all", ChatColor.GREEN));
|
||||||
|
this.addCommandExample(String.format("/mv who %smyworld", ChatColor.GOLD));
|
||||||
this.setPermission("multiverse.core.list.who", "States who is in what world.", PermissionDefault.OP);
|
this.setPermission("multiverse.core.list.who", "States who is in what world.", PermissionDefault.OP);
|
||||||
this.worldManager = this.plugin.getMVWorldManager();
|
this.worldManager = this.plugin.getMVWorldManager();
|
||||||
}
|
}
|
||||||
@ -48,57 +50,57 @@ public class WhoCommand extends MultiverseCommand {
|
|||||||
showAll = false;
|
showAll = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MultiverseWorld> worlds = new ArrayList<MultiverseWorld>();
|
if (args.size() == 1) {
|
||||||
|
|
||||||
if (args.size() > 0) {
|
|
||||||
MultiverseWorld world = this.worldManager.getMVWorld(args.get(0));
|
|
||||||
if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) {
|
if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) {
|
||||||
showAll = true;
|
showAll = true;
|
||||||
worlds = new ArrayList<MultiverseWorld>(this.worldManager.getMVWorlds());
|
|
||||||
} else if (world != null) {
|
|
||||||
if (!world.isHidden()) {
|
|
||||||
worlds.add(world);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + "World does not exist");
|
// single world mode
|
||||||
|
MultiverseWorld world = this.worldManager.getMVWorld(args.get(0));
|
||||||
|
if (world == null) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "That world does not exist.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
worlds = new ArrayList<MultiverseWorld>(this.worldManager.getMVWorlds());
|
if (!this.plugin.getMVPerms().canEnterWorld(p, world)) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "You aren't allowed to access to this world!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worlds.size() == 0) {
|
sender.sendMessage(String.format("%s--- Players in %s%s ---", ChatColor.AQUA,
|
||||||
sender.sendMessage("Multiverse does not know about any of your worlds :(");
|
world.getColoredWorldString(), ChatColor.AQUA));
|
||||||
} else if (worlds.size() == 1) {
|
sender.sendMessage(buildPlayerString(world));
|
||||||
sender.sendMessage(ChatColor.AQUA + "--- Players in" + worlds.get(0).getColoredWorldString() + ChatColor.AQUA + " ---");
|
return;
|
||||||
} else {
|
}
|
||||||
sender.sendMessage(ChatColor.AQUA + "--- There are players in ---");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MultiverseWorld world : worlds) {
|
// multiworld mode
|
||||||
if (!(this.worldManager.isMVWorld(world.getName()))) {
|
sender.sendMessage(ChatColor.AQUA + "--- Worlds and their players ---");
|
||||||
continue;
|
boolean shownOne = false;
|
||||||
|
for (MultiverseWorld world : this.worldManager.getMVWorlds()) {
|
||||||
|
if (this.plugin.getMVPerms().canEnterWorld(p, world)) { // only show world if the player can access it
|
||||||
|
if (showAll || !world.getCBWorld().getPlayers().isEmpty()) { // either show all or show if the world is not empty
|
||||||
|
sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world)));
|
||||||
|
shownOne = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!shownOne) {
|
||||||
|
sender.sendMessage("No worlds found.");
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p != null && (!this.plugin.getMVPerms().canEnterWorld(p, world))) {
|
private String buildPlayerString(MultiverseWorld world) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
List<Player> players = world.getCBWorld().getPlayers();
|
List<Player> players = world.getCBWorld().getPlayers();
|
||||||
|
if (players.size() == 0) {
|
||||||
String result = "";
|
return "No players found.";
|
||||||
if (players.size() <= 0 && !showAll) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (players.size() <= 0) {
|
|
||||||
result = "Empty";
|
|
||||||
} else {
|
} else {
|
||||||
|
StringBuilder playerBuilder = new StringBuilder();
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
result += player.getDisplayName() + " " + ChatColor.WHITE;
|
playerBuilder.append(player.getDisplayName()).append(", ");
|
||||||
}
|
}
|
||||||
}
|
String bString = playerBuilder.toString();
|
||||||
|
return bString.substring(0, bString.length() - 2);
|
||||||
sender.sendMessage(world.getColoredWorldString() + ChatColor.WHITE + " - " + result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user