use of org.spongepowered.api.util.RespawnLocation in project Skree by Skelril.
the class RespawnServiceImpl method getDefault.
@Override
public Location<World> getDefault(Player target) {
WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
Optional<Map<UUID, RespawnLocation>> optRespawnLocations = target.get(Keys.RESPAWN_LOCATIONS);
if (optRespawnLocations.isPresent()) {
BuildWorldWrapper buildWrapper = service.getEffectWrapper(BuildWorldWrapper.class).get();
UUID buildWorldId = buildWrapper.getPrimaryWorld().getUniqueId();
RespawnLocation targetLocation = optRespawnLocations.get().get(buildWorldId);
if (targetLocation != null) {
Optional<Location<World>> optLocation = targetLocation.asLocation();
if (optLocation.isPresent()) {
return optLocation.get();
}
}
}
return service.getEffectWrapper(MainWorldWrapper.class).get().getPrimaryWorld().getSpawnLocation();
}
use of org.spongepowered.api.util.RespawnLocation in project SpongeCommon by SpongePowered.
the class PlayerRespawnData method fixTagCompound.
@Override
public NBTTagCompound fixTagCompound(NBTTagCompound compound) {
final Map<UUID, RespawnLocation> spawnLocations = Maps.newHashMap();
if (compound.hasKey(NbtDataUtil.USER_SPAWN_X, NbtDataUtil.TAG_ANY_NUMERIC) && compound.hasKey(NbtDataUtil.USER_SPAWN_Y, NbtDataUtil.TAG_ANY_NUMERIC) && compound.hasKey(NbtDataUtil.USER_SPAWN_Z, NbtDataUtil.TAG_ANY_NUMERIC)) {
Vector3d pos = new Vector3d(compound.getInteger(NbtDataUtil.USER_SPAWN_X), compound.getInteger(NbtDataUtil.USER_SPAWN_Y), compound.getInteger(NbtDataUtil.USER_SPAWN_Z));
// final UUID key = WorldPropertyRegistryModule.dimIdToUuid(0);
// spawnLocations.put(key, RespawnLocation.builder().world(key).position(pos).build());
// This is the point where we need to check the old data, if it is available.
}
NBTTagList spawnlist = compound.getTagList(NbtDataUtil.USER_SPAWN_LIST, NbtDataUtil.TAG_COMPOUND);
// we can at least start moving all of this to our own compound and overwrite as necessary
for (int i = 0; i < spawnlist.tagCount(); i++) {
NBTTagCompound spawndata = spawnlist.getCompoundTagAt(i);
// UUID uuid = WorldPropertyRegistryModule.dimIdToUuid(spawndata.getInteger(NbtDataUtil.USER_SPAWN_DIM));
// if (uuid != null) {
// spawnLocations.put(uuid, RespawnLocation.builder().world(uuid).position(
// new Vector3d(spawndata.getInteger(NbtDataUtil.USER_SPAWN_X),
// spawndata.getInteger(NbtDataUtil.USER_SPAWN_Y),
// spawndata.getInteger(NbtDataUtil.USER_SPAWN_Z))).build());
// }
}
return compound;
}
use of org.spongepowered.api.util.RespawnLocation in project SpongeCommon by SpongePowered.
the class SpongeUser method writeToNbt.
public void writeToNbt(NBTTagCompound compound) {
this.loadInventory();
compound.setTag(NbtDataUtil.Minecraft.INVENTORY, this.inventory.writeToNBT(new NBTTagList()));
compound.setInteger(NbtDataUtil.Minecraft.SELECTED_ITEM_SLOT, this.inventory.currentItem);
compound.setTag(NbtDataUtil.ENTITY_POSITION, NbtDataUtil.newDoubleNBTList(this.posX, this.posY, this.posZ));
compound.setInteger(NbtDataUtil.ENTITY_DIMENSION, this.dimension);
compound.setTag(NbtDataUtil.ENTITY_ROTATION, NbtDataUtil.newFloatNBTList(this.rotationYaw, this.rotationPitch));
final NBTTagCompound forgeCompound = compound.getCompoundTag(NbtDataUtil.FORGE_DATA);
final NBTTagCompound spongeCompound = forgeCompound.getCompoundTag(NbtDataUtil.SPONGE_DATA);
spongeCompound.removeTag(NbtDataUtil.USER_SPAWN_LIST);
final NBTTagList spawnList = new NBTTagList();
for (Entry<UUID, RespawnLocation> entry : this.spawnLocations.entrySet()) {
final RespawnLocation respawn = entry.getValue();
final NBTTagCompound spawnCompound = new NBTTagCompound();
spawnCompound.setUniqueId(NbtDataUtil.UUID, entry.getKey());
spawnCompound.setDouble(NbtDataUtil.USER_SPAWN_X, respawn.getPosition().getX());
spawnCompound.setDouble(NbtDataUtil.USER_SPAWN_Y, respawn.getPosition().getY());
spawnCompound.setDouble(NbtDataUtil.USER_SPAWN_Z, respawn.getPosition().getZ());
// No way to know
spawnCompound.setBoolean(NbtDataUtil.USER_SPAWN_FORCED, false);
spawnList.appendTag(spawnCompound);
}
if (!spawnList.hasNoTags()) {
spongeCompound.setTag(NbtDataUtil.USER_SPAWN_LIST, spawnList);
forgeCompound.setTag(NbtDataUtil.SPONGE_DATA, spongeCompound);
compound.setTag(NbtDataUtil.FORGE_DATA, forgeCompound);
}
CustomDataNbtUtil.writeCustomData(spongeCompound, ((DataHolder) this));
}
use of org.spongepowered.api.util.RespawnLocation in project LanternServer by LanternPowered.
the class UserStore method deserializeValues.
@Override
public void deserializeValues(T player, SimpleValueContainer valueContainer, DataView dataView) {
// Try to convert old bukkit values first
dataView.getLong(BUKKIT_FIRST_DATE_PLAYED).ifPresent(v -> valueContainer.set(Keys.FIRST_DATE_PLAYED, Instant.ofEpochMilli(v)));
dataView.getLong(BUKKIT_LAST_DATE_PLAYED).ifPresent(v -> valueContainer.set(Keys.LAST_DATE_PLAYED, Instant.ofEpochMilli(v)));
// Deserialize sponge data
dataView.getView(DataQueries.EXTENDED_SPONGE_DATA).ifPresent(view -> {
view.getLong(FIRST_DATE_PLAYED).ifPresent(v -> valueContainer.set(Keys.FIRST_DATE_PLAYED, Instant.ofEpochMilli(v)));
view.getLong(LAST_DATE_PLAYED).ifPresent(v -> valueContainer.set(Keys.LAST_DATE_PLAYED, Instant.ofEpochMilli(v)));
});
dataView.getView(ABILITIES).ifPresent(view -> {
view.getInt(FLYING).ifPresent(v -> valueContainer.set(Keys.IS_FLYING, v > 0));
view.getDouble(FLYING_SPEED).ifPresent(v -> valueContainer.set(Keys.FLYING_SPEED, v));
view.getInt(CAN_FLY).ifPresent(v -> valueContainer.set(Keys.CAN_FLY, v > 0));
});
final Map<UUID, RespawnLocation> respawnLocations = new HashMap<>();
// Overworld respawn location is saved in the root container
final Optional<Double> optSpawnX = dataView.getDouble(RESPAWN_LOCATIONS_X);
final Optional<Double> optSpawnY = dataView.getDouble(RESPAWN_LOCATIONS_Y);
final Optional<Double> optSpawnZ = dataView.getDouble(RESPAWN_LOCATIONS_Z);
if (optSpawnX.isPresent() && optSpawnY.isPresent() && optSpawnZ.isPresent()) {
UUID uniqueId = Lantern.getWorldManager().getWorldProperties(0).get().getUniqueId();
respawnLocations.put(uniqueId, deserializeRespawnLocation(dataView, uniqueId, optSpawnX.get(), optSpawnY.get(), optSpawnZ.get()));
}
dataView.getViewList(RESPAWN_LOCATIONS).ifPresent(v -> v.forEach(view -> {
int dimensionId = view.getInt(RESPAWN_LOCATIONS_DIMENSION).get();
Lantern.getWorldManager().getWorldProperties(dimensionId).ifPresent(props -> {
UUID uniqueId = props.getUniqueId();
double x = view.getDouble(RESPAWN_LOCATIONS_X).get();
double y = view.getDouble(RESPAWN_LOCATIONS_Y).get();
double z = view.getDouble(RESPAWN_LOCATIONS_Z).get();
respawnLocations.put(uniqueId, deserializeRespawnLocation(view, uniqueId, x, y, z));
});
}));
valueContainer.set(Keys.RESPAWN_LOCATIONS, respawnLocations);
dataView.getInt(SCORE).ifPresent(v -> valueContainer.set(LanternKeys.SCORE, v));
final GameMode gameMode = dataView.getInt(GAME_MODE).flatMap(v -> GameModeRegistryModule.get().getByInternalId(v)).orElse(GameModes.NOT_SET);
valueContainer.set(Keys.GAME_MODE, gameMode);
player.getInventory().getHotbar().setSelectedSlotIndex(dataView.getInt(SELECTED_ITEM_SLOT).orElse(0));
// Deserialize the player inventory
dataView.getViewList(INVENTORY).ifPresent(views -> deserializePlayerInventory(player.getInventory(), views));
// Deserialize the ender chest inventory
dataView.getViewList(ENDER_CHEST_INVENTORY).ifPresent(views -> deserializeEnderChest(player.getEnderChestInventory(), views));
dataView.getView(RECIPE_BOOK).ifPresent(view -> {
view.getInt(RECIPE_BOOK_FILTER_ACTIVE).ifPresent(v -> valueContainer.set(LanternKeys.RECIPE_BOOK_FILTER_ACTIVE, v > 0));
view.getInt(RECIPE_BOOK_GUI_OPEN).ifPresent(v -> valueContainer.set(LanternKeys.RECIPE_BOOK_GUI_OPEN, v > 0));
});
dataView.getString(OPEN_ADVANCEMENT_TREE).ifPresent(id -> valueContainer.set(LanternKeys.OPEN_ADVANCEMENT_TREE, AdvancementTreeRegistryModule.get().getById(id)));
super.deserializeValues(player, valueContainer, dataView);
}
use of org.spongepowered.api.util.RespawnLocation in project LanternServer by LanternPowered.
the class UserStore method serializeValues.
@Override
public void serializeValues(T player, SimpleValueContainer valueContainer, DataView dataView) {
valueContainer.remove(Keys.IS_SPRINTING);
valueContainer.remove(Keys.IS_SNEAKING);
valueContainer.remove(LanternKeys.ACTIVE_HAND);
final DataView abilities = dataView.createView(ABILITIES);
abilities.set(FLYING, (byte) (valueContainer.remove(Keys.IS_FLYING).orElse(false) ? 1 : 0));
abilities.set(FLYING_SPEED, valueContainer.remove(Keys.FLYING_SPEED).orElse(0.1).floatValue());
abilities.set(CAN_FLY, (byte) (valueContainer.remove(Keys.CAN_FLY).orElse(false) ? 1 : 0));
final DataView spongeData = getOrCreateView(dataView, DataQueries.EXTENDED_SPONGE_DATA);
spongeData.set(FIRST_DATE_PLAYED, valueContainer.remove(Keys.FIRST_DATE_PLAYED).orElse(Instant.now()).toEpochMilli());
spongeData.set(LAST_DATE_PLAYED, valueContainer.remove(Keys.LAST_DATE_PLAYED).orElse(Instant.now()).toEpochMilli());
spongeData.set(UNIQUE_ID, player.getUniqueId().toString());
spongeData.set(Queries.CONTENT_VERSION, 1);
final Map<UUID, RespawnLocation> respawnLocations = valueContainer.remove(Keys.RESPAWN_LOCATIONS).get();
final List<DataView> respawnLocationViews = new ArrayList<>();
for (RespawnLocation respawnLocation : respawnLocations.values()) {
Lantern.getWorldManager().getWorldDimensionId(respawnLocation.getWorldUniqueId()).ifPresent(dimensionId -> {
// Overworld respawn location is saved in the root container
if (dimensionId == 0) {
serializeRespawnLocationTo(dataView, respawnLocation);
} else {
respawnLocationViews.add(serializeRespawnLocationTo(DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED), respawnLocation).set(RESPAWN_LOCATIONS_DIMENSION, dimensionId));
}
});
}
dataView.set(RESPAWN_LOCATIONS, respawnLocationViews);
dataView.set(GAME_MODE, ((LanternGameMode) valueContainer.remove(Keys.GAME_MODE).orElse(GameModes.NOT_SET)).getInternalId());
dataView.set(SELECTED_ITEM_SLOT, player.getInventory().getHotbar().getSelectedSlotIndex());
dataView.set(SCORE, valueContainer.remove(LanternKeys.SCORE).get());
// Serialize the player inventory
dataView.set(INVENTORY, serializePlayerInventory(player.getInventory()));
// Serialize the ender chest inventory
dataView.set(ENDER_CHEST_INVENTORY, serializeEnderChest(player.getEnderChestInventory()));
final DataView recipeBook = dataView.createView(RECIPE_BOOK);
recipeBook.set(RECIPE_BOOK_FILTER_ACTIVE, (byte) (valueContainer.remove(LanternKeys.RECIPE_BOOK_FILTER_ACTIVE).orElse(false) ? 1 : 0));
recipeBook.set(RECIPE_BOOK_GUI_OPEN, (byte) (valueContainer.remove(LanternKeys.RECIPE_BOOK_GUI_OPEN).orElse(false) ? 1 : 0));
valueContainer.remove(LanternKeys.OPEN_ADVANCEMENT_TREE).ifPresent(o -> {
if (o.isPresent()) {
dataView.set(OPEN_ADVANCEMENT_TREE, o.get().getId());
}
});
super.serializeValues(player, valueContainer, dataView);
}
Aggregations