45 lines
1.2 KiB
Java
45 lines
1.2 KiB
Java
package game.command;
|
|
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
import game.collect.Lists;
|
|
import game.collect.Sets;
|
|
import game.network.Player;
|
|
|
|
public class PlayerListParser extends PlayerParser {
|
|
public PlayerListParser(String name, boolean useSender) {
|
|
super(name, useSender);
|
|
}
|
|
|
|
public Object parse(CommandEnvironment env, String input) {
|
|
if(input.equals("*")) {
|
|
if(env.getServer().getPlayers().isEmpty())
|
|
throw new RunException("Keine Spieler gefunden");
|
|
return Lists.newArrayList(env.getServer().getPlayers());
|
|
}
|
|
Set<Player> set = Sets.newHashSet();
|
|
for(String tok : input.split(",", -1)) {
|
|
set.add((Player)super.parse(env, tok));
|
|
}
|
|
if(set.isEmpty())
|
|
throw new RunException("Keine Spieler gefunden");
|
|
return Lists.newArrayList(set);
|
|
}
|
|
|
|
public Object getDefault(CommandEnvironment env) {
|
|
Player net = (Player)super.getDefault(env);
|
|
return net == null ? null : Lists.newArrayList(net);
|
|
}
|
|
|
|
public Collection<String> getCompletions(CommandEnvironment env) {
|
|
Collection<String> comp = super.getCompletions(env);
|
|
comp.add("*");
|
|
return comp;
|
|
}
|
|
|
|
public Class<?> getTypeClass() {
|
|
return List.class;
|
|
}
|
|
}
|