command entities

This commit is contained in:
Sen 2025-03-26 15:43:58 +01:00
parent e88958e2f4
commit 460a58e062
32 changed files with 293 additions and 37 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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,6 +40,26 @@ 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) {
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);
}
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);
@ -65,3 +87,4 @@ public class CommandSpawn extends Command {
return Util.buildLines(",", spawned);
}
}
}

View file

@ -2674,4 +2674,6 @@ public abstract class Entity
public Position getPos() {
return new Position(this.posX, this.posY, this.posZ, this.rotYaw, this.rotPitch, this.worldObj.dimension.getDimensionId());
}
public abstract EntityType getType();
}

View file

@ -0,0 +1,42 @@
package game.entity;
import java.util.Map;
import game.collect.Maps;
public enum EntityType {
OBJECT("Object", "Objekt"),
VEHICLE("Vehicle", "Fahrzeug"),
PROJECTILE("Projectile", "Projektil"),
EXPLOSIVE("Explosive", "Sprengstoff"),
ANIMAL("Animal", "Tier"),
NPC("NPC", "NPC");
private static final Map<String, EntityType> LOOKUP = Maps.newHashMap();
private final String name;
private final String display;
private EntityType(String name, String display) {
this.name = name;
this.display = display;
}
public String getName() {
return this.name;
}
public String getDisplay() {
return this.display;
}
public static EntityType getByName(String name) {
return LOOKUP.get(name);
}
static {
for(EntityType type : values()) {
LOOKUP.put(type.name, type);
}
}
}

View file

@ -3,6 +3,7 @@ package game.entity.animal;
import game.block.Block;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.npc.Alignment;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
@ -321,4 +322,8 @@ public class EntityBat extends EntityLiving
public Alignment getAlignment() {
return Alignment.NEUTRAL;
}
public EntityType getType() {
return EntityType.ANIMAL;
}
}

View file

@ -6,6 +6,7 @@ import game.collect.Lists;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.npc.Alignment;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
@ -617,4 +618,8 @@ public class EntityDragon extends EntityLiving implements IEntityMultiPart
public Alignment getAlignment() {
return Alignment.LAWFUL_EVIL;
}
public EntityType getType() {
return EntityType.ANIMAL;
}
}

View file

@ -2,6 +2,7 @@ package game.entity.animal;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.types.IEntityMultiPart;
import game.nbt.NBTTagCompound;
@ -72,4 +73,8 @@ public class EntityDragonPart extends Entity
public boolean isSendingVeloUpdates() {
return false;
}
public EntityType getType() {
return EntityType.ANIMAL;
}
}

View file

@ -6,6 +6,7 @@ import game.block.Block;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityDamageSourceIndirect;
import game.entity.EntityType;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
import game.init.Blocks;
@ -641,4 +642,8 @@ public class EntityBoat extends Entity
public Item getItem() {
return Items.boat;
}
public EntityType getType() {
return EntityType.VEHICLE;
}
}

View file

@ -5,6 +5,7 @@ import game.block.BlockRailBase;
import game.block.BlockRailPowered;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.types.EntityLiving;
import game.init.BlockRegistry;
import game.init.Blocks;
@ -1111,6 +1112,10 @@ public abstract class EntityCart extends Entity implements IWorldNameable
}
}
public EntityType getType() {
return EntityType.VEHICLE;
}
public static enum EnumMinecartType
{
RIDEABLE,

View file

@ -2,6 +2,7 @@ package game.entity.item;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.nbt.NBTTagCompound;
import game.world.World;
@ -122,4 +123,8 @@ public class EntityCrystal extends Entity
public boolean isSendingVeloUpdates() {
return false;
}
public EntityType getType() {
return EntityType.OBJECT;
}
}

View file

@ -1,6 +1,7 @@
package game.entity.item;
import game.entity.Entity;
import game.entity.EntityType;
import game.nbt.NBTTagCompound;
import game.world.Explosion;
import game.world.World;
@ -89,4 +90,8 @@ public class EntityExplosion extends Entity
public boolean isSendingVeloUpdates() {
return false;
}
public EntityType getType() {
return EntityType.EXPLOSIVE;
}
}

View file

@ -10,6 +10,7 @@ import game.block.BlockFalling;
import game.block.ITileEntityProvider;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.types.IObjectData;
import game.init.BlockRegistry;
import game.init.Blocks;
@ -339,4 +340,8 @@ public class EntityFalling extends Entity implements IObjectData
// public boolean hasSpawnVelocity() {
// return false;
// }
public EntityType getType() {
return EntityType.OBJECT;
}
}

View file

@ -1,6 +1,7 @@
package game.entity.item;
import game.entity.Entity;
import game.entity.EntityType;
import game.init.SoundEvent;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
@ -232,4 +233,8 @@ public class EntityFireworks extends Entity
public boolean isSendingVeloUpdates() {
return true;
}
public EntityType getType() {
return EntityType.EXPLOSIVE;
}
}

View file

@ -3,6 +3,7 @@ package game.entity.item;
import game.color.TextColor;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
import game.init.Blocks;
@ -618,4 +619,8 @@ public class EntityItem extends Entity
return null;
return TextColor.DGREEN + "" + stack.stackSize;
}
public EntityType getType() {
return EntityType.OBJECT;
}
}

View file

@ -3,6 +3,7 @@ package game.entity.item;
import game.block.BlockFence;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
import game.init.Items;
@ -440,6 +441,10 @@ public class EntityLeashKnot extends Entity
return Items.lead;
}
public EntityType getType() {
return EntityType.OBJECT;
}
public static EntityLeashKnot createKnot(World worldIn, BlockPos fence)
{
EntityLeashKnot entityleashknot = new EntityLeashKnot(worldIn, fence);

View file

@ -1,6 +1,7 @@
package game.entity.item;
import game.entity.Entity;
import game.entity.EntityType;
import game.nbt.NBTTagCompound;
import game.renderer.particle.ParticleType;
import game.world.World;
@ -118,4 +119,8 @@ public class EntityNuke extends Entity
public boolean isSendingVeloUpdates() {
return true;
}
public EntityType getType() {
return EntityType.EXPLOSIVE;
}
}

View file

@ -1,6 +1,7 @@
package game.entity.item;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.types.EntityLiving;
import game.entity.types.IObjectData;
import game.nbt.NBTTagCompound;
@ -155,4 +156,8 @@ public class EntityTnt extends Entity implements IObjectData
// public boolean hasSpawnVelocity() {
// return false;
// }
public EntityType getType() {
return EntityType.EXPLOSIVE;
}
}

View file

@ -3,6 +3,7 @@ package game.entity.item;
import game.color.TextColor;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.npc.EntityNPC;
import game.entity.types.IObjectData;
import game.init.Config;
@ -404,4 +405,8 @@ public class EntityXp extends Entity implements IObjectData
// }
return this.hasCustomName() ? TextColor.GREEN + this.getCustomNameTag() : null;
}
public EntityType getType() {
return EntityType.OBJECT;
}
}

View file

@ -28,6 +28,7 @@ import game.enchantment.Enchantment;
import game.enchantment.EnchantmentHelper;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.animal.EntityDragonPart;
import game.entity.animal.EntityHorse;
import game.entity.animal.EntityPig;
@ -4643,4 +4644,8 @@ public abstract class EntityNPC extends EntityLiving
public void setHovering(boolean hover)
{
}
public EntityType getType() {
return EntityType.NPC;
}
}

View file

@ -6,6 +6,7 @@ import game.block.Block;
import game.enchantment.EnchantmentHelper;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.npc.EntityNPC;
import game.entity.types.EntityLiving;
import game.entity.types.IObjectData;
@ -631,4 +632,8 @@ public class EntityArrow extends Entity implements IProjectile, IObjectData
public boolean hasSpawnVelocity() {
return true;
}
public EntityType getType() {
return EntityType.PROJECTILE;
}
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import game.enchantment.EnchantmentHelper;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.types.EntityLiving;
import game.entity.types.IObjectData;
import game.entity.types.IProjectile;
@ -403,4 +404,8 @@ public class EntityBullet extends Entity implements IProjectile, IObjectData
public boolean hasSpawnVelocity() {
return true;
}
public EntityType getType() {
return EntityType.PROJECTILE;
}
}

View file

@ -1,6 +1,7 @@
package game.entity.projectile;
import game.entity.DamageSource;
import game.entity.EntityType;
import game.entity.types.EntityLiving;
import game.entity.types.EntityThrowable;
import game.entity.types.IObjectData;
@ -77,4 +78,8 @@ public class EntityDynamite extends EntityThrowable implements IObjectData
// public boolean hasSpawnVelocity() {
// return false;
// }
public EntityType getType() {
return EntityType.EXPLOSIVE;
}
}

View file

@ -6,6 +6,7 @@ import game.block.Block;
import game.enchantment.EnchantmentHelper;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.item.EntityItem;
import game.entity.item.EntityXp;
import game.entity.npc.EntityNPC;
@ -662,6 +663,10 @@ public class EntityHook extends Entity implements IObjectData
return this.angler != null ? this.angler.getId() : this.getId();
}
public EntityType getType() {
return EntityType.PROJECTILE;
}
// public boolean hasSpawnVelocity() {
// return false;
// }

View file

@ -5,6 +5,7 @@ import java.util.List;
import game.block.Block;
import game.entity.DamageSource;
import game.entity.Entity;
import game.entity.EntityType;
import game.entity.types.EntityLiving;
import game.init.BlockRegistry;
import game.nbt.NBTTagCompound;
@ -385,4 +386,8 @@ public abstract class EntityProjectile extends Entity
// public boolean hasSpawnVelocity() {
// return false;
// }
public EntityType getType() {
return EntityType.PROJECTILE;
}
}

View file

@ -6,6 +6,7 @@ import game.collect.Sets;
import game.block.Block;
import game.entity.DamageSource;
import game.entity.EntityType;
import game.entity.npc.Alignment;
import game.entity.npc.EntityNPC;
import game.init.Blocks;
@ -315,4 +316,8 @@ public abstract class EntityAnimal extends EntityLiving
public Alignment getAlignment() {
return Alignment.LAWFUL;
}
public EntityType getType() {
return EntityType.ANIMAL;
}
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import game.block.Block;
import game.block.BlockPortal;
import game.entity.Entity;
import game.entity.EntityType;
import game.init.BlockRegistry;
import game.init.Blocks;
import game.nbt.NBTTagCompound;
@ -389,4 +390,8 @@ public abstract class EntityThrowable extends Entity implements IProjectile
public boolean isSendingVeloUpdates() {
return true;
}
public EntityType getType() {
return EntityType.PROJECTILE;
}
}

View file

@ -1,6 +1,7 @@
package game.entity.types;
import game.entity.DamageSource;
import game.entity.EntityType;
import game.entity.npc.EntityNPC;
import game.init.Config;
import game.world.World;
@ -108,4 +109,8 @@ public abstract class EntityWaterMob extends EntityLiving
{
return this.posY > 45.0D && this.posY < (double)this.worldObj.getSeaLevel();
}
public EntityType getType() {
return EntityType.ANIMAL;
}
}

View file

@ -1,6 +1,7 @@
package game.entity.types;
import game.entity.Entity;
import game.entity.EntityType;
import game.nbt.NBTTagCompound;
import game.world.World;
@ -29,4 +30,8 @@ public abstract class EntityWeatherEffect extends Entity {
protected final void writeEntityToNBT(NBTTagCompound tagCompound) {
}
public final EntityType getType() {
return EntityType.OBJECT;
}
}

View file

@ -2,6 +2,7 @@ package game.renderer.particle;
import game.Game;
import game.entity.Entity;
import game.entity.EntityType;
import game.nbt.NBTTagCompound;
import game.renderer.RenderBuffer;
import game.renderer.texture.TextureAtlasSprite;
@ -282,4 +283,8 @@ public class EntityFX extends Entity
public boolean isSendingVeloUpdates() {
return false;
}
public EntityType getType() {
return EntityType.OBJECT;
}
}