Skip to content

Commit

Permalink
better method for prior commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 30, 2021
1 parent 295ca08 commit 870d485
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 46 deletions.
Expand Up @@ -527,7 +527,12 @@ else if (isPlayer()) {

public Entity getBukkitEntity() {
if (uuid != null && (entity == null || !entity.isValid())) {
isUnique(); // Trigger the isUnique() code to reset the entity if it needs to be.
if (!isFake) {
Entity backup = Bukkit.getEntity(uuid);
if (backup != null) {
entity = backup;
}
}
}
return entity;
}
Expand Down Expand Up @@ -671,6 +676,9 @@ public LocationTag getLocation() {

public LocationTag getEyeLocation() {
Entity entity = getBukkitEntity();
if (entity == null) {
return null;
}
if (isPlayer()) {
return new LocationTag(getPlayer().getEyeLocation());
}
Expand All @@ -695,23 +703,27 @@ public Location getTargetBlockSafe(Set<Material> mats, int range) {
}

public Vector getVelocity() {
if (!isGeneric()) {
return entity.getVelocity();
Entity entity = getBukkitEntity();
if (entity == null) {
return null;
}
return null;
return entity.getVelocity();
}

public void setVelocity(Vector vector) {
if (!isGeneric()) {
entity.setVelocity(vector);
Entity entity = getBukkitEntity();
if (entity == null) {
return;
}
entity.setVelocity(vector);
}

public World getWorld() {
if (!isGeneric()) {
return entity.getWorld();
Entity entity = getBukkitEntity();
if (entity == null) {
return null;
}
return null;
return entity.getWorld();
}

public void spawnAt(Location location) {
Expand Down Expand Up @@ -879,7 +891,6 @@ public boolean isSpawnedOrValidForTag() {
}
NMSHandler.getChunkHelper().changeChunkServerThread(entity.getWorld());
try {
isUnique(); // Trigger the isUnique() code to reset the entity if it needs to be.
return isValid() || rememberedEntities.containsKey(entity.getUniqueId());
}
finally {
Expand All @@ -892,7 +903,7 @@ public boolean isSpawned() {
}

public boolean isValid() {
isUnique(); // Trigger the isUnique() code to reset the entity if it needs to be.
Entity entity = getBukkitEntity();
return entity != null && (entity.isValid() || (isFake && isFakeValid));
}

Expand All @@ -909,8 +920,7 @@ else if (isFake) {
NMSHandler.getEntityHelper().look(entity, location.getYaw(), location.getPitch());
}
else {
isUnique(); // Trigger the isUnique() code to reset the entity if it needs to be.
entity.teleport(location);
getBukkitEntity().teleport(location);
if (entity.getWorld().equals(location.getWorld())) { // Force the teleport through (for things like mounts)
NMSHandler.getEntityHelper().teleport(entity, location);
}
Expand Down Expand Up @@ -1125,38 +1135,14 @@ public String identifySimple() {
return "null";
}

public String identifySimpleType() {
if (isCitizensNPC()) {
return "npc";
}
else if (isPlayer()) {
return "player";
}
else {
return entity_type.getLowercaseName();
}
}

@Override
public String toString() {
return identify();
}

public boolean uniqueTestInternal() {
return isPlayer() || isCitizensNPC() || isSpawned() || isLivingEntity() || (entity != null && rememberedEntities.containsKey(entity.getUniqueId())) || isFake; // || isSaved()
}

@Override
public boolean isUnique() {
boolean result = uniqueTestInternal();
if (result || uuid == null) {
return result;
}
Entity backup = Bukkit.getEntity(uuid);
if (backup != null) {
entity = backup;
}
return uniqueTestInternal();
return entity != null || uuid != null || isFake;
}

public static void registerTags() {
Expand Down
Expand Up @@ -87,11 +87,10 @@ public void execute(final ScriptEntry scriptEntry) {
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
WorldTag world = scriptEntry.getObjectTag("world");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (world == null ? "" : world.debug())
+ ArgumentHelper.debugList("entities", entities));
Debug.report(scriptEntry, getName(), world, ArgumentHelper.debugList("entities", entities));
}
for (EntityTag entity : entities) {
if (!entity.isGeneric()) {
if (entity.isUnique()) {
if (entity.isFake) {
FakeEntity fakeEnt = FakeEntity.idsToEntities.get(entity.getUUID());
if (fakeEnt != null) {
Expand All @@ -101,15 +100,14 @@ public void execute(final ScriptEntry scriptEntry) {
else if (entity.isCitizensNPC()) {
entity.getDenizenNPC().getCitizen().destroy();
}
else {
else if (entity.isSpawned()) {
entity.remove();
}
}
else {
if (entity.getUUID() != null) {
else {
Debug.echoError("Tried to remove already-removed entity.");
return;
}
}
else {
int removed = 0;
for (Entity worldEntity : world.getEntities()) {
if (entity.getEntityType().equals(DenizenEntityType.getByEntity(worldEntity))) {
Expand Down

0 comments on commit 870d485

Please sign in to comment.