52 lines
1.4 KiB
Java
52 lines
1.4 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.entity.Entity;
|
|
import game.entity.npc.EntityNPC;
|
|
import game.network.Player;
|
|
|
|
public class PlayerEntityListParser extends PlayerEntityParser {
|
|
public PlayerEntityListParser(String name, boolean useSender) {
|
|
super(name, useSender);
|
|
}
|
|
|
|
public Object parse(CommandEnvironment env, String input) {
|
|
if(input.equals("*")) {
|
|
List<Entity> list = Lists.newArrayList();
|
|
for(Player plr : env.getServer().getPlayers()) {
|
|
if(plr.getPresentEntity() != null)
|
|
list.add(plr.getPresentEntity());
|
|
}
|
|
if(list.isEmpty())
|
|
throw new RunException("Keine Spieler gefunden");
|
|
return list;
|
|
}
|
|
Set<EntityNPC> set = Sets.newHashSet();
|
|
for(String tok : input.split(",", -1)) {
|
|
set.add((EntityNPC)super.parse(env, tok));
|
|
}
|
|
if(set.isEmpty())
|
|
throw new RunException("Keine Spieler gefunden");
|
|
return Lists.newArrayList(set);
|
|
}
|
|
|
|
public Object getDefault(CommandEnvironment env) {
|
|
EntityNPC entity = (EntityNPC)super.getDefault(env);
|
|
return entity == null ? null : Lists.newArrayList(entity);
|
|
}
|
|
|
|
public Collection<String> getCompletions(CommandEnvironment env) {
|
|
Collection<String> comp = super.getCompletions(env);
|
|
comp.add("*");
|
|
return comp;
|
|
}
|
|
|
|
public Class<?> getTypeClass() {
|
|
return List.class;
|
|
}
|
|
}
|