effect command
This commit is contained in:
parent
6c0bd5481f
commit
66421e806e
16 changed files with 393 additions and 16 deletions
84
java/src/game/command/EntityListParser.java
Normal file
84
java/src/game/command/EntityListParser.java
Normal file
|
@ -0,0 +1,84 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.entity.Entity;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.EntityRegistry;
|
||||
import game.network.NetHandlerPlayServer;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class EntityListParser extends EntityParser {
|
||||
public EntityListParser(String name, boolean useSender, boolean livingOnly) {
|
||||
super(name, useSender, livingOnly);
|
||||
}
|
||||
|
||||
public Object parse(ScriptEnvironment env, String input) {
|
||||
if(input.equals("**")) {
|
||||
List<Entity> list = Lists.newArrayList();
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
if(this.livingOnly) {
|
||||
for(Entity ent : world.getEntities()) {
|
||||
if(ent instanceof EntityLiving)
|
||||
list.add(ent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
list.addAll(world.getEntities());
|
||||
}
|
||||
}
|
||||
if(list.isEmpty())
|
||||
throw new ScriptException(this.livingOnly ? "Keine lebendigen Objekte gefunden" : "Keine Objekte gefunden");
|
||||
return list;
|
||||
}
|
||||
else if(input.equals("*")) {
|
||||
List<Entity> list = Lists.newArrayList();
|
||||
for(NetHandlerPlayServer plr : env.getServer().getPlayers()) {
|
||||
if(plr.getEntity() != null)
|
||||
list.add(plr.getEntity());
|
||||
}
|
||||
if(list.isEmpty())
|
||||
throw new ScriptException("Keine Spieler gefunden");
|
||||
return list;
|
||||
}
|
||||
Class<? extends Entity> clazz = EntityRegistry.getEntityClass(input);
|
||||
if(clazz != null) {
|
||||
if(this.livingOnly && !EntityLiving.class.isAssignableFrom(clazz))
|
||||
throw new ScriptException("Objekttyp %s ist nicht lebendig", EntityRegistry.getEntityName(EntityRegistry.getEntityString(clazz)));
|
||||
List<Entity> list = Lists.newArrayList();
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
for(Entity ent : world.getEntities()) {
|
||||
if(clazz.isAssignableFrom(ent.getClass()))
|
||||
list.add(ent);
|
||||
}
|
||||
}
|
||||
if(list.isEmpty())
|
||||
throw new ScriptException("Kein Objekt des Typs %s gefunden", EntityRegistry.getEntityName(EntityRegistry.getEntityString(clazz)));
|
||||
return list;
|
||||
}
|
||||
return Lists.newArrayList((Entity)super.parse(env, input));
|
||||
}
|
||||
|
||||
public Object getDefault(ScriptEnvironment env) {
|
||||
Entity entity = (Entity)super.getDefault(env);
|
||||
return entity == null ? null : Lists.newArrayList(entity);
|
||||
}
|
||||
|
||||
public String[] getCompletions(ScriptEnvironment env) {
|
||||
Entity target = env.getExecutor().getPointedEntity();
|
||||
List<String> comp = target == null || (this.livingOnly && !(target instanceof EntityLiving)) ? Lists.newArrayList() : Lists.newArrayList("#" + target.getId());
|
||||
comp.addAll(env.getServer().getAllUsernames());
|
||||
comp.add("*");
|
||||
for(Class<? extends Entity> clazz : EntityRegistry.getAllClasses()) {
|
||||
if(!this.livingOnly || EntityLiving.class.isAssignableFrom(clazz))
|
||||
comp.add(EntityRegistry.getEntityString(clazz));
|
||||
}
|
||||
comp.add("**");
|
||||
return comp.toArray(new String[comp.size()]);
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
return List.class;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue