From 9750bc56d52e6bd2c6ae782080838e54d64ddf06 Mon Sep 17 00:00:00 2001 From: rbluer <665978+rbluer@users.noreply.github.com> Date: Mon, 1 Jul 2024 03:00:15 -0400 Subject: [PATCH] Prison Entity support added! This is a major change to prison. Support for bukkit Entities has been added, which had to be worked in between the SpigotCommandSender and the players. This is a significant change since it does allow more complex support for other features, such as newer and enhanced support for mine bomb animations, which uses armour stands, which are entities. This will allow the animations to be moved to the core and be associated with the mine bomb package. --- .../prison/spigot/game/SpigotEntity.java | 282 ++++++++++++++++++ .../prison/spigot/game/SpigotEntityType.java | 49 +++ 2 files changed, 331 insertions(+) create mode 100644 prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotEntity.java create mode 100644 prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotEntityType.java diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotEntity.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotEntity.java new file mode 100644 index 000000000..13f42d3c2 --- /dev/null +++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotEntity.java @@ -0,0 +1,282 @@ +package tech.mcprison.prison.spigot.game; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import com.cryptomorin.xseries.XEntityType; + +import tech.mcprison.prison.internal.Entity; +import tech.mcprison.prison.internal.EntityType; +import tech.mcprison.prison.internal.World; +import tech.mcprison.prison.util.Location; +import tech.mcprison.prison.util.Vector; + +public class SpigotEntity + extends SpigotCommandSender + implements Entity { + + private org.bukkit.entity.Entity bukkitEntity; + + public SpigotEntity(org.bukkit.entity.Entity entity ) { + super( entity ); + + this.bukkitEntity = entity; + } + + + @Override + public UUID getUniqueId() { + return getBukkitEntity().getUniqueId(); + } + + @Override + public String getCustomName() { + return getBukkitEntity().getCustomName(); + } + + @Override + public int getEntityId() { + return getBukkitEntity().getEntityId(); + } + + @Override + public boolean eject() { + return getBukkitEntity().eject(); + } + + @Override + public Location getLocation() { + return new SpigotLocation( getBukkitEntity().getLocation() ); + } + + @Override + public Location getLocation(Location loc) { + return + new SpigotLocation( + getBukkitEntity().getLocation( ((SpigotLocation) loc).getBukkitLocation() )); + } + + @Override + public float getFallDistance() { + return getBukkitEntity().getFallDistance(); + } + + @Override + public int getFireTicks() { + return getBukkitEntity().getFireTicks(); + } + + @Override + public int getMaxFireTicks() { + return getBukkitEntity().getMaxFireTicks(); + } + + /** + * The parameter of radius is actually a cubic-radius, + * where the r is added to the location to produce a cube around the + * Entity or Player. + * + * @param r Radius around the Entity or Player + * @param eType + * @return + */ + public List getNearbyEntities( int r, EntityType eType ) { + Location loc = getLocation(); + List bEntities = getBukkitEntity() + .getNearbyEntities( loc.getX() + r, loc.getY() + r, loc.getZ() + r); + return convertEntities( bEntities, (SpigotEntityType) eType ); + } + + @Override + public List getNearbyEntities(double x, double y, double z) { + List bEntities = getBukkitEntity().getNearbyEntities(x, y, z); + return convertEntities( bEntities, null ); + } + + /** + * Converts all of the bukkit entities in to the SpigotEntityType, and if + * a SpigotEntityType is provided, it will also filter the results. + * + * @param bEntities + * @param seType + * @return + */ + private List convertEntities( + List bEntities, + SpigotEntityType seType ) { + List sEntities = new ArrayList<>(); + for (org.bukkit.entity.Entity entity : bEntities) { + + if ( seType == null || + seType.getxEType() == XEntityType.of(entity) ) { + + sEntities.add( new SpigotEntity( entity )); + } + } + return sEntities; + } + + + + @SuppressWarnings("deprecation") + @Override + public Entity getPassenger() { + return new SpigotEntity( getBukkitEntity().getPassenger() ); + } + + @Override + public int getTicksLived() { + return getBukkitEntity().getTicksLived(); + } + + @Override + public EntityType getType() { + + EntityType eType = new SpigotEntityType( getBukkitEntity().getType() ); + return eType; + } + + @Override + public Entity getVehicle() { + return new SpigotEntity( getBukkitEntity().getVehicle() ); + } + + @Override + public Vector getVelocity() { + + org.bukkit.util.Vector bVel = getBukkitEntity().getVelocity(); + Vector vec = new Vector( bVel.getX(), bVel.getY(), bVel.getZ() ); + + return vec; + } + + @Override + public World getWorld() { + return new SpigotWorld( getBukkitEntity().getWorld() ); + } + + @Override + public boolean isCustomNameVisible() { + return getBukkitEntity().isCustomNameVisible(); + } + + @Override + public void setCustomName(String name) { + getBukkitEntity().setCustomName(name); + } + + @Override + public void setCustomNameVisible(boolean flag) { + getBukkitEntity().setCustomNameVisible(flag); + } + + @Override + public boolean isDead() { + return getBukkitEntity().isDead(); + } + + @Override + public boolean isEmpty() { + return getBukkitEntity().isEmpty(); + } + + @Override + public boolean isInsideVehicle() { + return getBukkitEntity().isInsideVehicle(); + } + + @Override + public boolean isOnGround() { + return getBukkitEntity().isOnGround(); + } + + @Override + public boolean isValid() { + return getBukkitEntity().isValid(); + } + + @Override + public boolean leaveVehicle() { + return getBukkitEntity().leaveVehicle(); + } + + @Override + public void remove() { + getBukkitEntity().remove(); + } + + @Override + public void setFallDistance(float distance) { + getBukkitEntity().setFallDistance(distance); + } + + @Override + public void setFireTicks(int ticks) { + getBukkitEntity().setFireTicks(ticks); + } + + @SuppressWarnings("deprecation") + @Override + public boolean setPassenger(Entity passenger) { + return getBukkitEntity().setPassenger( ((SpigotEntity) passenger).getBukkitEntity() ); + } + + @Override + public void setTicksLived(int value) { + getBukkitEntity().setTicksLived(value); + } + + @Override + public void setVelocity(Vector velocity) { + + org.bukkit.util.Vector bVec = + new org.bukkit.util.Vector( + velocity.getX(), velocity.getY(), velocity.getZ() ); + + getBukkitEntity().setVelocity( bVec ); + } + + @Override + public boolean teleport(Entity destination) { + return getBukkitEntity().teleport( ((SpigotEntity) destination).getBukkitEntity() ); + } + + @Override + public boolean teleport(Location location) { + + org.bukkit.World world = ((SpigotWorld) location.getWorld()).getWrapper(); + org.bukkit.Location loc = new org.bukkit.Location( world, + location.getX(), location.getY(), location.getZ(), + location.getYaw(), location.getPitch()); + return getBukkitEntity().teleport( loc ); + } + + public org.bukkit.entity.Entity getBukkitEntity() { + return bukkitEntity; + } + + + @Override + public String getName() { + return bukkitEntity.getName(); + } + + + @Override + public boolean isPlayer() { + return false; + } + + + +// @Override +// public boolean doesSupportColors() { +// return false; +// } + + + + + +} diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotEntityType.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotEntityType.java new file mode 100644 index 000000000..0216facea --- /dev/null +++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/game/SpigotEntityType.java @@ -0,0 +1,49 @@ +package tech.mcprison.prison.spigot.game; + +import com.cryptomorin.xseries.XEntityType; + +import tech.mcprison.prison.internal.EntityType; + +public class SpigotEntityType + extends EntityType { + + private org.bukkit.entity.EntityType bEntityType; + private XEntityType xEType; + + public SpigotEntityType( String entityType ) { + super( entityType ); + + } + public SpigotEntityType( org.bukkit.entity.EntityType bEntityType ) { + super( "" ); + + this.bEntityType = bEntityType; + + XEntityType xEType = XEntityType.of( bEntityType ); + this.xEType = xEType; + + setEntityType( xEType.name() ); + } + public SpigotEntityType( XEntityType xEType ) { + super( xEType.name() ); + + this.xEType = xEType; + + this.bEntityType = xEType.get(); + } + + public org.bukkit.entity.EntityType getbEntityType() { + return bEntityType; + } + public void setbEntityType(org.bukkit.entity.EntityType bEntityType) { + this.bEntityType = bEntityType; + } + + public XEntityType getxEType() { + return xEType; + } + public void setxEType(XEntityType xEType) { + this.xEType = xEType; + } + +}