command entities
This commit is contained in:
parent
e88958e2f4
commit
460a58e062
32 changed files with 293 additions and 37 deletions
|
@ -1,12 +1,14 @@
|
|||
package game.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.collect.Sets;
|
||||
import game.entity.Entity;
|
||||
import game.entity.EntityType;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.EntityRegistry;
|
||||
import game.network.Player;
|
||||
|
@ -45,26 +47,67 @@ public class EntityListParser extends EntityParser {
|
|||
throw new RunException("Keine Spieler gefunden");
|
||||
return list;
|
||||
}
|
||||
Set<Entity> set = Sets.newHashSet();
|
||||
Set<Class<? extends Entity>> classes = Sets.newHashSet();
|
||||
Set<EntityType> types = Sets.newHashSet();
|
||||
Set<Entity> entities = Sets.newHashSet();
|
||||
Set<Class<? extends Entity>> nclasses = Sets.newHashSet();
|
||||
Set<EntityType> ntypes = Sets.newHashSet();
|
||||
Set<Entity> nentities = Sets.newHashSet();
|
||||
Boolean living = null;
|
||||
Boolean player = null;
|
||||
for(String tok : input.split(",", -1)) {
|
||||
boolean negate = tok.startsWith("!");
|
||||
tok = negate ? tok.substring(1) : tok;
|
||||
Class<? extends Entity> clazz = EntityRegistry.getEntityClass(tok);
|
||||
if(clazz != null) {
|
||||
if(classes.contains(clazz) || nclasses.contains(clazz))
|
||||
throw new RunException("Objekttyp %s mehrfach angegeben", EntityRegistry.getEntityName(EntityRegistry.getEntityString(clazz)));
|
||||
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);
|
||||
}
|
||||
}
|
||||
(negate ? nclasses : classes).add(clazz);
|
||||
}
|
||||
else if(tok.equals("Player")) {
|
||||
if(player != null)
|
||||
throw new RunException("'Player' mehrfach angegeben");
|
||||
player = !negate;
|
||||
}
|
||||
else if(tok.equals("Living")) {
|
||||
if(living != null)
|
||||
throw new RunException("'Living' mehrfach angegeben");
|
||||
if(this.livingOnly)
|
||||
throw new RunException("Kann nicht 'Living' als Objekttypen angeben");
|
||||
living = !negate;
|
||||
}
|
||||
else {
|
||||
set.add((Entity)super.parse(env, tok));
|
||||
EntityType type = EntityType.getByName(tok);
|
||||
if(type != null) {
|
||||
if(types.contains(type) || ntypes.contains(type))
|
||||
throw new RunException("Objekttyp %s mehrfach angegeben", type.getDisplay());
|
||||
(negate ? ntypes : types).add(type);
|
||||
}
|
||||
else {
|
||||
Entity ent = (Entity)super.parse(env, tok);
|
||||
if(entities.contains(ent) || nentities.contains(ent))
|
||||
throw new RunException("Objekt '%s' mehrfach angegeben", tok);
|
||||
(negate ? nentities : entities).add(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(set.isEmpty())
|
||||
List<Entity> filtered = Lists.newArrayList(entities);
|
||||
boolean negateOnly = (living == null && player == null && types.isEmpty() && classes.isEmpty() && entities.isEmpty());
|
||||
for(WorldServer world : env.getServer().getWorlds()) {
|
||||
for(Entity ent : world.getEntities()) {
|
||||
if((!this.livingOnly || ent instanceof EntityLiving) &&
|
||||
(negateOnly || (living != null && living == (ent instanceof EntityLiving)) || (player != null && player == ent.isPlayer()) || types.contains(ent.getType()) ||
|
||||
classes.contains(ent.getClass())) &&
|
||||
(living == null || living == (ent instanceof EntityLiving)) && (player == null || player == ent.isPlayer()) &&
|
||||
!ntypes.contains(ent.getType()) && !nclasses.contains(ent.getClass()) && !nentities.contains(ent) && !entities.contains(ent))
|
||||
filtered.add(ent);
|
||||
}
|
||||
}
|
||||
if(filtered.isEmpty())
|
||||
throw new RunException("Keine Objekte gefunden");
|
||||
return Lists.newArrayList(set);
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public Object getDefault(CommandEnvironment env) {
|
||||
|
@ -79,7 +122,10 @@ public class EntityListParser extends EntityParser {
|
|||
if(!this.livingOnly || EntityLiving.class.isAssignableFrom(clazz))
|
||||
comp.add(EntityRegistry.getEntityString(clazz));
|
||||
}
|
||||
comp.add("**");
|
||||
for(EntityType type : EntityType.values()) {
|
||||
comp.add(type.getName());
|
||||
}
|
||||
Collections.addAll(comp, "Player", "Living", "**");
|
||||
return comp;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class EntityParser extends PlayerEntityParser {
|
|||
if(entity == null)
|
||||
throw new RunException("Objekt '%s' wurde nicht gefunden", input);
|
||||
else if(this.livingOnly && !(entity instanceof EntityLiving))
|
||||
throw new RunException("Objekt muss lebendig sein");
|
||||
throw new RunException("Objekt '%s' muss lebendig sein", input);
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,10 @@ 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;
|
||||
|
@ -23,7 +26,13 @@ public class PlayerEntityListParser extends PlayerEntityParser {
|
|||
throw new RunException("Keine Spieler gefunden");
|
||||
return list;
|
||||
}
|
||||
return Lists.newArrayList((EntityNPC)super.parse(env, input));
|
||||
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) {
|
||||
|
|
|
@ -2,7 +2,10 @@ 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 {
|
||||
|
@ -16,7 +19,13 @@ public class PlayerListParser extends PlayerParser {
|
|||
throw new RunException("Keine Spieler gefunden");
|
||||
return Lists.newArrayList(env.getServer().getPlayers());
|
||||
}
|
||||
return Lists.newArrayList((Player)super.parse(env, input));
|
||||
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) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import game.entity.Entity;
|
|||
import game.entity.types.EntityLiving;
|
||||
import game.init.EntityRegistry;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.network.Player;
|
||||
import game.util.Util;
|
||||
import game.world.Vec3;
|
||||
import game.world.WorldServer;
|
||||
|
@ -26,6 +27,7 @@ public class CommandSpawn extends Command {
|
|||
for(Class<? extends Entity> clazz : EntityRegistry.getAllClasses()) {
|
||||
names.add(EntityRegistry.getEntityString(clazz));
|
||||
}
|
||||
names.add("Lightning");
|
||||
this.addEnum("type", String.class, names);
|
||||
this.setParamsOptional();
|
||||
this.addVector("position", true, true);
|
||||
|
@ -38,30 +40,51 @@ public class CommandSpawn extends Command {
|
|||
}
|
||||
|
||||
public Object exec(CommandEnvironment env, Executor exec, String type, Vec3 pos, WorldServer world, NBTTagCompound tag, boolean noinit, int count, NBTTagCompound postTag) {
|
||||
List<String> spawned = Lists.newArrayList();
|
||||
for(int z = 0; z < count; z++) {
|
||||
Entity entity = EntityRegistry.createEntityByName(type, world);
|
||||
if(entity == null)
|
||||
throw new RunException("Objekt konnte nicht erzeugt werden");
|
||||
entity.setLocationAndAngles(pos.xCoord, pos.yCoord, pos.zCoord, world.rand.floatv() * 360.0f, 0.0f);
|
||||
if(tag != null) {
|
||||
NBTTagCompound ent = new NBTTagCompound();
|
||||
entity.writeToNBT(ent);
|
||||
ent.merge(tag);
|
||||
entity.readFromNBT(ent);
|
||||
if(type.equalsIgnoreCase("Lightning")) {
|
||||
for(int z = 0; z < count; z++) {
|
||||
int color = 0xffffff;
|
||||
if(tag != null && tag.hasKey("color", 3))
|
||||
color = tag.getInteger("color");
|
||||
else if(tag != null && tag.hasKey("color", 8)) {
|
||||
try {
|
||||
color = Integer.parseUnsignedInt(tag.getString("color"), 16);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
world.strikeLightning(pos.xCoord, pos.yCoord, pos.zCoord, color,
|
||||
tag != null && tag.hasKey("damage", 3) ? tag.getInteger("damage") : 0, tag != null && tag.hasKey("fire", 1) && tag.getBoolean("fire"),
|
||||
exec instanceof Player && tag != null && tag.hasKey("summoned", 1) && tag.getBoolean("summoned") ? ((Player)exec).getEntity() : null);
|
||||
}
|
||||
if(!noinit && (entity instanceof EntityLiving))
|
||||
((EntityLiving)entity).onInitialSpawn(null);
|
||||
world.spawnEntityInWorld(entity);
|
||||
if(postTag != null) {
|
||||
NBTTagCompound ent = new NBTTagCompound();
|
||||
entity.writeToNBT(ent);
|
||||
ent.merge(postTag);
|
||||
entity.readFromNBT(ent);
|
||||
}
|
||||
spawned.add("#" + entity.getId());
|
||||
exec.logConsole("%sBlitz bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false));
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
List<String> spawned = Lists.newArrayList();
|
||||
for(int z = 0; z < count; z++) {
|
||||
Entity entity = EntityRegistry.createEntityByName(type, world);
|
||||
if(entity == null)
|
||||
throw new RunException("Objekt konnte nicht erzeugt werden");
|
||||
entity.setLocationAndAngles(pos.xCoord, pos.yCoord, pos.zCoord, world.rand.floatv() * 360.0f, 0.0f);
|
||||
if(tag != null) {
|
||||
NBTTagCompound ent = new NBTTagCompound();
|
||||
entity.writeToNBT(ent);
|
||||
ent.merge(tag);
|
||||
entity.readFromNBT(ent);
|
||||
}
|
||||
if(!noinit && (entity instanceof EntityLiving))
|
||||
((EntityLiving)entity).onInitialSpawn(null);
|
||||
world.spawnEntityInWorld(entity);
|
||||
if(postTag != null) {
|
||||
NBTTagCompound ent = new NBTTagCompound();
|
||||
entity.writeToNBT(ent);
|
||||
ent.merge(postTag);
|
||||
entity.readFromNBT(ent);
|
||||
}
|
||||
spawned.add("#" + entity.getId());
|
||||
}
|
||||
exec.logConsole("%s%s bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), EntityRegistry.getEntityName(type), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false));
|
||||
return Util.buildLines(",", spawned);
|
||||
}
|
||||
exec.logConsole("%s%s bei %d, %d, %d in %s erschaffen", count == 1 ? "" : (count + "x "), EntityRegistry.getEntityName(type), (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord, world.dimension.getFormattedName(false));
|
||||
return Util.buildLines(",", spawned);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue