use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class DataProviderRegistrator method spongeDataStore.
public void spongeDataStore(final ResourceKey datastoreKey, final int version, final DataContentUpdater[] contentUpdater, final Class dataHolder, final Key<? extends Value<?>>... dataKeys) {
final SpongeDataStoreBuilder builder = ((SpongeDataStoreBuilder) DataStore.builder()).pluginData(datastoreKey, version);
builder.updater(contentUpdater);
builder.holder(dataHolder);
for (Key dataKey : dataKeys) {
builder.key(dataKey, dataKey.key().value());
}
SpongeDataManager.getDatastoreRegistry().register(builder.build(), Arrays.asList(dataKeys));
}
use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class DataStoreRegistry method register.
public void register(final DataStore dataStore, Iterable<Key<?>> keys) {
keys.forEach(k -> this.dataStoreByValueKey.put(k, dataStore));
if (dataStore instanceof SpongeDataStore) {
final ResourceKey customDataKey = ((SpongeDataStore) dataStore).getDataStoreKey();
this.dataStoreByDataStoreKey.put(customDataKey, dataStore);
}
this.allDataStores.add(dataStore);
this.dataStoreCache.clear();
this.dataStoreByTokenCache.clear();
}
use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class BoatData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(Boat.class).create(Keys.BOAT_TYPE).get(h -> ((BoatType) (Object) h.getBoatType())).set((h, v) -> h.setType((Boat.Type) (Object) v)).asMutable(BoatAccessor.class).create(Keys.IS_IN_WATER).get(h -> h.accessor$status() == Boat.Status.IN_WATER).asMutable(BoatBridge.class).create(Keys.CAN_MOVE_ON_LAND).get(BoatBridge::bridge$getMoveOnLand).set(BoatBridge::bridge$setMoveOnLand).asMutable(BoatBridge.class).create(Keys.OCCUPIED_DECELERATION).get(BoatBridge::bridge$getOccupiedDecelerationSpeed).set(BoatBridge::bridge$setOccupiedDecelerationSpeed).asMutable(BoatBridge.class).create(Keys.MAX_SPEED).get(BoatBridge::bridge$getMaxSpeed).set(BoatBridge::bridge$setMaxSpeed).asMutable(BoatBridge.class).create(Keys.UNOCCUPIED_DECELERATION).get(BoatBridge::bridge$getUnoccupiedDecelerationSpeed).set(BoatBridge::bridge$setUnoccupiedDecelerationSpeed);
final ResourceKey boatDataStoreKey = ResourceKey.sponge("boat");
registrator.spongeDataStore(boatDataStoreKey, 2, new DataContentUpdater[] { BoatData.BOAT_UPDATER_BYTE_TO_BOOL_FIX }, BoatBridge.class, Keys.MAX_SPEED, Keys.CAN_MOVE_ON_LAND, Keys.OCCUPIED_DECELERATION, Keys.UNOCCUPIED_DECELERATION);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Boat.BOAT_MAX_SPEED, boatDataStoreKey, Keys.MAX_SPEED);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Boat.BOAT_MOVE_ON_LAND, boatDataStoreKey, Keys.CAN_MOVE_ON_LAND);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Boat.BOAT_OCCUPIED_DECELERATION_SPEED, boatDataStoreKey, Keys.OCCUPIED_DECELERATION);
SpongeDataManager.INSTANCE.registerLegacySpongeData(Constants.Entity.Boat.BOAT_UNOCCUPIED_DECELERATION_SPEED, boatDataStoreKey, Keys.UNOCCUPIED_DECELERATION);
}
use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method handlePlayPayload.
public boolean handlePlayPayload(final EngineConnection connection, final ServerboundCustomPayloadPacket packet) {
final ServerboundCustomPayloadPacketAccessor accessor = (ServerboundCustomPayloadPacketAccessor) packet;
final ResourceKey channel = (ResourceKey) (Object) accessor.accessor$identifier();
final ChannelBuf payload = (ChannelBuf) accessor.accessor$data();
return this.handlePlayPayload(connection, channel, payload);
}
use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method handleChannelRegistry.
private void handleChannelRegistry(final EngineConnection connection, final ChannelBuf payload) {
final Set<ResourceKey> registered = ConnectionUtil.getRegisteredChannels(connection);
registered.clear();
final int count = payload.readVarInt();
for (int i = 0; i < count; i++) {
final ResourceKey key = ResourceKey.resolve(payload.readString());
// type
payload.readByte();
registered.add(key);
}
}
Aggregations