commands, ...
This commit is contained in:
parent
66421e806e
commit
75f91dbf4c
44 changed files with 1035 additions and 631 deletions
|
@ -1,8 +1,10 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Sets;
|
||||
import game.entity.Entity;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.EntityRegistry;
|
||||
|
@ -14,7 +16,7 @@ public class EntityListParser extends EntityParser {
|
|||
super(name, useSender, livingOnly);
|
||||
}
|
||||
|
||||
public Object parse(ScriptEnvironment env, String input) {
|
||||
public Object parse(CommandEnvironment env, String input) {
|
||||
if(input.equals("**")) {
|
||||
List<Entity> list = Lists.newArrayList();
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
|
@ -29,7 +31,7 @@ public class EntityListParser extends EntityParser {
|
|||
}
|
||||
}
|
||||
if(list.isEmpty())
|
||||
throw new ScriptException(this.livingOnly ? "Keine lebendigen Objekte gefunden" : "Keine Objekte gefunden");
|
||||
throw new RunException(this.livingOnly ? "Keine lebendigen Objekte gefunden" : "Keine Objekte gefunden");
|
||||
return list;
|
||||
}
|
||||
else if(input.equals("*")) {
|
||||
|
@ -39,33 +41,37 @@ public class EntityListParser extends EntityParser {
|
|||
list.add(plr.getEntity());
|
||||
}
|
||||
if(list.isEmpty())
|
||||
throw new ScriptException("Keine Spieler gefunden");
|
||||
throw new RunException("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);
|
||||
Set<Entity> set = Sets.newHashSet();
|
||||
for(String tok : input.split(",", -1)) {
|
||||
Class<? extends Entity> clazz = EntityRegistry.getEntityClass(tok);
|
||||
if(clazz != null) {
|
||||
if(this.livingOnly && !EntityLiving.class.isAssignableFrom(clazz))
|
||||
throw new RunException("Objekttyp %s ist nicht lebendig", EntityRegistry.getEntityName(EntityRegistry.getEntityString(clazz)));
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
for(Entity ent : world.getEntities()) {
|
||||
if(clazz.isAssignableFrom(ent.getClass()))
|
||||
set.add(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(list.isEmpty())
|
||||
throw new ScriptException("Kein Objekt des Typs %s gefunden", EntityRegistry.getEntityName(EntityRegistry.getEntityString(clazz)));
|
||||
return list;
|
||||
else {
|
||||
set.add((Entity)super.parse(env, tok));
|
||||
}
|
||||
}
|
||||
return Lists.newArrayList((Entity)super.parse(env, input));
|
||||
if(set.isEmpty())
|
||||
throw new RunException("Keine Objekte gefunden");
|
||||
return Lists.newArrayList(set);
|
||||
}
|
||||
|
||||
public Object getDefault(ScriptEnvironment env) {
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
Entity entity = (Entity)super.getDefault(env);
|
||||
return entity == null ? null : Lists.newArrayList(entity);
|
||||
}
|
||||
|
||||
public String[] getCompletions(ScriptEnvironment env) {
|
||||
public String[] getCompletions(CommandEnvironment 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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue