Skip to content

Commit

Permalink
Added sanity check incase NBT fails to create the new one
Browse files Browse the repository at this point in the history
- added the forgotten feature flag TELEPORT_FOLLOWERS
  • Loading branch information
KrisTheCanadian committed Feb 12, 2025
1 parent 7eb67fb commit 76b6373
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public final class EssentialCommandsConfig extends Config<EssentialCommandsConfi
@ConfigOption public final Option<Boolean> TELEPORT_INTERRUPT_ON_MOVE = new Option<>("teleport_interrupt_on_move", false, Boolean::parseBoolean);
@ConfigOption public final Option<Double> TELEPORT_INTERRUPT_ON_MOVE_AMOUNT = new Option<>("teleport_interrupt_on_move_max_blocks", 3D, ConfigUtil::parseDouble);
@ConfigOption public final Option<Boolean> ALLOW_TELEPORT_BETWEEN_DIMENSIONS = new Option<>("allow_teleport_between_dimensions", true, Boolean::parseBoolean);
@ConfigOption public final Option<Boolean> ALLOW_TELEPORT_WITH_FOLLOWERS = new Option<>("allow_teleport_with_followers", true, Boolean::parseBoolean);
@ConfigOption public final Option<Boolean> TELEPORT_WITH_FOLLOWERS = new Option<>("teleport_with_followers", false, Boolean::parseBoolean);
@ConfigOption public final Option<Double> TELEPORT_WITH_FOLLOWERS_RADIUS = new Option<>("teleport_with_followers_radius", 100D, ConfigUtil::parseDouble);
@ConfigOption public final Option<Boolean> OPS_BYPASS_TELEPORT_RULES = new Option<>("ops_bypass_teleport_rules", true, Boolean::parseBoolean);
@ConfigOption public final Option<Boolean> NICKNAMES_IN_PLAYER_LIST = new Option<>("nicknames_in_player_list", true, Boolean::parseBoolean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private EssentialCommandsConfigSnapshot(EssentialCommandsConfig config) {
this.TELEPORT_INTERRUPT_ON_MOVE = config.TELEPORT_INTERRUPT_ON_MOVE.getValue();
this.TELEPORT_INTERRUPT_ON_MOVE_AMOUNT = config.TELEPORT_INTERRUPT_ON_MOVE_AMOUNT.getValue();
this.ALLOW_TELEPORT_BETWEEN_DIMENSIONS = config.ALLOW_TELEPORT_BETWEEN_DIMENSIONS.getValue();
this.TELEPORT_FOLLOWERS = config.ALLOW_TELEPORT_WITH_FOLLOWERS.getValue();
this.TELEPORT_FOLLOWERS = config.TELEPORT_WITH_FOLLOWERS.getValue();
this.TELEPORT_FOLLOWERS_RADIUS = config.TELEPORT_WITH_FOLLOWERS_RADIUS.getValue();
this.OPS_BYPASS_TELEPORT_RULES = config.OPS_BYPASS_TELEPORT_RULES.getValue();
this.NICKNAMES_IN_PLAYER_LIST = config.NICKNAMES_IN_PLAYER_LIST.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ private static void execTeleport(ServerPlayerEntity playerEntity, MinecraftLocat
BlockPos playerPos = playerEntity.getBlockPos();
Vec3d targetVec = new Vec3d(dest.pos().x, dest.pos().y, dest.pos().z);

List<TameableEntity> pets = detectTamedPets(playerEntity, playerPos);

playerEntity.teleport(targetWorld, targetVec.x, targetVec.y, targetVec.z, Set.of(), dest.headYaw(), dest.pitch(), false);

teleportTamedEntities(pets, targetWorld, targetVec, playerEntity);
if (CONFIG.TELEPORT_FOLLOWERS) {
List<TameableEntity> pets = detectTamedPets(playerEntity, playerPos);
teleportTamedEntities(pets, targetWorld, targetVec, playerEntity);
}

sendTeleportMessage(playerEntity, destName, dest);
}
Expand All @@ -118,9 +119,6 @@ private static List<TameableEntity> detectTamedPets(ServerPlayerEntity playerEnt
boolean isSameOwner = ownerUuid != null && ownerUuid.equals(playerEntity.getUuid());
boolean isSitting = pet.isSitting();

LOGGER.info("Checking pet {} ({}) - Tamed: {}, Owner Matches: {}, Sitting: {}",
pet.getType().getTranslationKey(), pet.getUuid(), isTamed, isSameOwner, isSitting);

return isTamed && isSameOwner && !isSitting;
});
}
Expand Down Expand Up @@ -169,9 +167,16 @@ private static boolean transferEntityToWorld(TameableEntity pet, ServerWorld tar
newTamedPet.setOwner(playerEntity);
targetWorld.spawnEntity(newTamedPet);

// sanity check to make sure the entity has spawned
if (newTamedPet.isRemoved()) {
LOGGER.error("Failed to spawn pet {} ({}) in {}", newTamedPet.getType().getTranslationKey(), newTamedPet.getUuid(), targetWorld.getRegistryKey().getValue());
return false;
}

pet.discard();
return true;
} else {
// Failed to create entity from NBT
LOGGER.error("Failed to create entity from NBT for pet ({})!", pet.getUuid());
return false;
}
Expand Down

0 comments on commit 76b6373

Please sign in to comment.