diff --git a/SpongeAPI b/SpongeAPI index 5ea62150a66..9d589c77ea7 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 5ea62150a66332c66c29ff4bda7abdb4d91c3d34 +Subproject commit 9d589c77ea73695905f01e3821635b0e3ee7d5d3 diff --git a/src/main/java/org/spongepowered/common/data/DataRegistrar.java b/src/main/java/org/spongepowered/common/data/DataRegistrar.java index 419702c31e3..a37b3b66bf1 100644 --- a/src/main/java/org/spongepowered/common/data/DataRegistrar.java +++ b/src/main/java/org/spongepowered/common/data/DataRegistrar.java @@ -377,6 +377,12 @@ public static void setupSerialization() { DataUtil.registerDualProcessor(SkinData.class, SpongeSkinData.class, ImmutableSkinData.class, ImmutableSpongeSkinData.class, new SkinDataProcessor()); + DataUtil.registerDualProcessor(SkinTextureData.class, SpongeSkinTextureData.class, ImmutableSkinTextureData.class, + ImmutableSpongeSkinTextureData.class, new SkinTextureDataProcessor()); + + DataUtil.registerDualProcessor(SkinSignatureData.class, SpongeSkinSignatureData.class, ImmutableSkinSignatureData.class, + ImmutableSpongeSkinSignatureData.class, new SkinSignatureDataProcessor()); + DataUtil.registerDualProcessor(ExpOrbData.class, SpongeExpOrbData.class, ImmutableExpOrbData.class, ImmutableSpongeExpOrbData.class, new ExpOrbDataProcessor()); diff --git a/src/main/java/org/spongepowered/common/data/manipulator/immutable/entity/ImmutableSpongeSkinSignatureData.java b/src/main/java/org/spongepowered/common/data/manipulator/immutable/entity/ImmutableSpongeSkinSignatureData.java new file mode 100644 index 00000000000..e0e8a6baf81 --- /dev/null +++ b/src/main/java/org/spongepowered/common/data/manipulator/immutable/entity/ImmutableSpongeSkinSignatureData.java @@ -0,0 +1,66 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.data.manipulator.immutable.entity; + +import org.spongepowered.api.data.DataContainer; +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.data.manipulator.immutable.entity.ImmutableSkinSignatureData; +import org.spongepowered.api.data.manipulator.mutable.entity.SkinSignatureData; +import org.spongepowered.api.data.value.immutable.ImmutableValue; +import org.spongepowered.common.data.manipulator.immutable.common.AbstractImmutableSingleData; +import org.spongepowered.common.data.manipulator.mutable.entity.SpongeSkinSignatureData; +import org.spongepowered.common.data.value.immutable.ImmutableSpongeValue; + +public class ImmutableSpongeSkinSignatureData extends AbstractImmutableSingleData implements ImmutableSkinSignatureData { + + private final ImmutableSpongeValue skinValue; + + public ImmutableSpongeSkinSignatureData(String value) { + super(ImmutableSkinSignatureData.class, value, Keys.SKIN_SIGNATURE); + this.skinValue = new ImmutableSpongeValue<>(Keys.SKIN_SIGNATURE, value); + } + + @Override + public SkinSignatureData asMutable() { + return new SpongeSkinSignatureData(this.value); + } + + @Override + public DataContainer toContainer() { + return super.toContainer() + .set(Keys.SKIN_SIGNATURE.getQuery(), this.value.toString()); + } + + @Override + public ImmutableValue skinSignature() { + return this.skinValue; + } + + @Override + protected ImmutableValue getValueGetter() { + return skinSignature(); + } + +} diff --git a/src/main/java/org/spongepowered/common/data/manipulator/immutable/entity/ImmutableSpongeSkinTextureData.java b/src/main/java/org/spongepowered/common/data/manipulator/immutable/entity/ImmutableSpongeSkinTextureData.java new file mode 100644 index 00000000000..4e103e9200d --- /dev/null +++ b/src/main/java/org/spongepowered/common/data/manipulator/immutable/entity/ImmutableSpongeSkinTextureData.java @@ -0,0 +1,66 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.data.manipulator.immutable.entity; + +import org.spongepowered.api.data.DataContainer; +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.data.manipulator.immutable.entity.ImmutableSkinTextureData; +import org.spongepowered.api.data.manipulator.mutable.entity.SkinTextureData; +import org.spongepowered.api.data.value.immutable.ImmutableValue; +import org.spongepowered.common.data.manipulator.immutable.common.AbstractImmutableSingleData; +import org.spongepowered.common.data.manipulator.mutable.entity.SpongeSkinTextureData; +import org.spongepowered.common.data.value.immutable.ImmutableSpongeValue; + +public class ImmutableSpongeSkinTextureData extends AbstractImmutableSingleData implements ImmutableSkinTextureData { + + private final ImmutableSpongeValue skinValue; + + public ImmutableSpongeSkinTextureData(String value) { + super(ImmutableSkinTextureData.class, value, Keys.SKIN_TEXTURE); + this.skinValue = new ImmutableSpongeValue<>(Keys.SKIN_TEXTURE, value); + } + + @Override + public SkinTextureData asMutable() { + return new SpongeSkinTextureData(this.value); + } + + @Override + public DataContainer toContainer() { + return super.toContainer() + .set(Keys.SKIN_TEXTURE.getQuery(), this.value.toString()); + } + + @Override + public ImmutableValue skinTexture() { + return this.skinValue; + } + + @Override + protected ImmutableValue getValueGetter() { + return skinTexture(); + } + +} diff --git a/src/main/java/org/spongepowered/common/data/manipulator/mutable/entity/SpongeSkinSignatureData.java b/src/main/java/org/spongepowered/common/data/manipulator/mutable/entity/SpongeSkinSignatureData.java new file mode 100644 index 00000000000..d027701e956 --- /dev/null +++ b/src/main/java/org/spongepowered/common/data/manipulator/mutable/entity/SpongeSkinSignatureData.java @@ -0,0 +1,73 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.data.manipulator.mutable.entity; + +import org.spongepowered.api.data.DataContainer; +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.data.manipulator.immutable.entity.ImmutableSkinSignatureData; +import org.spongepowered.api.data.manipulator.mutable.entity.SkinSignatureData; +import org.spongepowered.api.data.value.mutable.Value; +import org.spongepowered.common.data.manipulator.immutable.entity.ImmutableSpongeSkinSignatureData; +import org.spongepowered.common.data.manipulator.mutable.common.AbstractSingleData; +import org.spongepowered.common.data.value.mutable.SpongeValue; +import org.spongepowered.common.util.Constants; + +public class SpongeSkinSignatureData extends AbstractSingleData implements SkinSignatureData { + + public SpongeSkinSignatureData() { + super(SkinSignatureData.class, "", Keys.SKIN_SIGNATURE); + } + + public SpongeSkinSignatureData(String Signature) { + super(SkinSignatureData.class, Signature, Keys.SKIN_SIGNATURE); + } + + @Override + public SkinSignatureData copy() { + return new SpongeSkinSignatureData(getValue()); + } + + @Override + public ImmutableSkinSignatureData asImmutable() { + return new ImmutableSpongeSkinSignatureData(getValue()); + } + + @Override + public DataContainer toContainer() { + return super.toContainer() + .set(Constants.GameProfile.SKIN_SIGNATURE, getValue()); + } + + @Override + public Value skinSignature() { + return new SpongeValue<>(Keys.SKIN_SIGNATURE, getValue()); + } + + @Override + protected Value getValueGetter() { + return skinSignature(); + } + +} diff --git a/src/main/java/org/spongepowered/common/data/manipulator/mutable/entity/SpongeSkinTextureData.java b/src/main/java/org/spongepowered/common/data/manipulator/mutable/entity/SpongeSkinTextureData.java new file mode 100644 index 00000000000..9a638276ccb --- /dev/null +++ b/src/main/java/org/spongepowered/common/data/manipulator/mutable/entity/SpongeSkinTextureData.java @@ -0,0 +1,73 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.data.manipulator.mutable.entity; + +import org.spongepowered.api.data.DataContainer; +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.data.manipulator.immutable.entity.ImmutableSkinTextureData; +import org.spongepowered.api.data.manipulator.mutable.entity.SkinTextureData; +import org.spongepowered.api.data.value.mutable.Value; +import org.spongepowered.common.data.manipulator.immutable.entity.ImmutableSpongeSkinTextureData; +import org.spongepowered.common.data.manipulator.mutable.common.AbstractSingleData; +import org.spongepowered.common.data.value.mutable.SpongeValue; +import org.spongepowered.common.util.Constants; + +public class SpongeSkinTextureData extends AbstractSingleData implements SkinTextureData { + + public SpongeSkinTextureData() { + super(SkinTextureData.class, "", Keys.SKIN_TEXTURE); + } + + public SpongeSkinTextureData(String texture) { + super(SkinTextureData.class, texture, Keys.SKIN_TEXTURE); + } + + @Override + public SkinTextureData copy() { + return new SpongeSkinTextureData(getValue()); + } + + @Override + public ImmutableSkinTextureData asImmutable() { + return new ImmutableSpongeSkinTextureData(getValue()); + } + + @Override + public DataContainer toContainer() { + return super.toContainer() + .set(Constants.GameProfile.SKIN_TEXTURE, getValue()); + } + + @Override + public Value skinTexture() { + return new SpongeValue<>(Keys.SKIN_TEXTURE, getValue()); + } + + @Override + protected Value getValueGetter() { + return skinTexture(); + } + +} diff --git a/src/main/java/org/spongepowered/common/data/processor/data/entity/SkinSignatureDataProcessor.java b/src/main/java/org/spongepowered/common/data/processor/data/entity/SkinSignatureDataProcessor.java new file mode 100644 index 00000000000..33cb9b02358 --- /dev/null +++ b/src/main/java/org/spongepowered/common/data/processor/data/entity/SkinSignatureDataProcessor.java @@ -0,0 +1,82 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.data.processor.data.entity; + +import org.spongepowered.api.data.DataTransactionResult; +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.data.manipulator.immutable.entity.ImmutableSkinSignatureData; +import org.spongepowered.api.data.manipulator.mutable.entity.SkinSignatureData; +import org.spongepowered.api.data.value.ValueContainer; +import org.spongepowered.api.data.value.immutable.ImmutableValue; +import org.spongepowered.api.data.value.mutable.Value; +import org.spongepowered.common.data.manipulator.mutable.entity.SpongeSkinSignatureData; +import org.spongepowered.common.data.processor.common.AbstractEntitySingleDataProcessor; +import org.spongepowered.common.data.value.immutable.ImmutableSpongeValue; +import org.spongepowered.common.data.value.mutable.SpongeValue; +import org.spongepowered.common.entity.living.human.EntityHuman; + +import java.util.Optional; + +public class SkinSignatureDataProcessor extends + AbstractEntitySingleDataProcessor, SkinSignatureData, ImmutableSkinSignatureData> { + + public SkinSignatureDataProcessor() { + super(EntityHuman.class, Keys.SKIN_SIGNATURE); + } + + @Override + public DataTransactionResult removeFrom(ValueContainer container) { + if (!(container instanceof EntityHuman)) { + return DataTransactionResult.failNoData(); + } + return ((EntityHuman) container).removeSkinSignature(); + } + + @Override + protected Value constructValue(String actualValue) { + return new SpongeValue<>(Keys.SKIN_SIGNATURE, actualValue); + } + + @Override + protected boolean set(EntityHuman entity, String value) { + return entity.setSkinSignature(value); + } + + @Override + protected Optional getVal(EntityHuman entity) { + return Optional.ofNullable(entity.getSkinSignature()); + } + + @Override + protected ImmutableValue constructImmutableValue(String value) { + return new ImmutableSpongeValue(Keys.SKIN_SIGNATURE, value); + } + + @Override + protected SkinSignatureData createManipulator() { + return new SpongeSkinSignatureData(); + } + +} diff --git a/src/main/java/org/spongepowered/common/data/processor/data/entity/SkinTextureDataProcessor.java b/src/main/java/org/spongepowered/common/data/processor/data/entity/SkinTextureDataProcessor.java new file mode 100644 index 00000000000..eb2db6c5a73 --- /dev/null +++ b/src/main/java/org/spongepowered/common/data/processor/data/entity/SkinTextureDataProcessor.java @@ -0,0 +1,82 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.data.processor.data.entity; + +import org.spongepowered.api.data.DataTransactionResult; +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.data.manipulator.immutable.entity.ImmutableSkinTextureData; +import org.spongepowered.api.data.manipulator.mutable.entity.SkinTextureData; +import org.spongepowered.api.data.value.ValueContainer; +import org.spongepowered.api.data.value.immutable.ImmutableValue; +import org.spongepowered.api.data.value.mutable.Value; +import org.spongepowered.common.data.manipulator.mutable.entity.SpongeSkinTextureData; +import org.spongepowered.common.data.processor.common.AbstractEntitySingleDataProcessor; +import org.spongepowered.common.data.value.immutable.ImmutableSpongeValue; +import org.spongepowered.common.data.value.mutable.SpongeValue; +import org.spongepowered.common.entity.living.human.EntityHuman; + +import java.util.Optional; + +public class SkinTextureDataProcessor extends + AbstractEntitySingleDataProcessor, SkinTextureData, ImmutableSkinTextureData> { + + public SkinTextureDataProcessor() { + super(EntityHuman.class, Keys.SKIN_TEXTURE); + } + + @Override + public DataTransactionResult removeFrom(ValueContainer container) { + if (!(container instanceof EntityHuman)) { + return DataTransactionResult.failNoData(); + } + return ((EntityHuman) container).removeSkinTexture(); + } + + @Override + protected Value constructValue(String actualValue) { + return new SpongeValue<>(Keys.SKIN_TEXTURE, actualValue); + } + + @Override + protected boolean set(EntityHuman entity, String value) { + return entity.setSkinTexture(value); + } + + @Override + protected Optional getVal(EntityHuman entity) { + return Optional.ofNullable(entity.getSkinTexture()); + } + + @Override + protected ImmutableValue constructImmutableValue(String value) { + return new ImmutableSpongeValue(Keys.SKIN_TEXTURE, value); + } + + @Override + protected SkinTextureData createManipulator() { + return new SpongeSkinTextureData(); + } + +} diff --git a/src/main/java/org/spongepowered/common/entity/living/human/EntityHuman.java b/src/main/java/org/spongepowered/common/entity/living/human/EntityHuman.java index f6581aec8be..be452a5afb8 100644 --- a/src/main/java/org/spongepowered/common/entity/living/human/EntityHuman.java +++ b/src/main/java/org/spongepowered/common/entity/living/human/EntityHuman.java @@ -29,6 +29,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.Maps; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; @@ -54,6 +55,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.world.GameType; import net.minecraft.world.World; + import org.spongepowered.api.data.DataTransactionResult; import org.spongepowered.api.data.key.Keys; import org.spongepowered.api.data.value.immutable.ImmutableValue; @@ -68,8 +70,10 @@ import org.spongepowered.common.mixin.core.network.play.server.SPacketSpawnPlayerAccessor; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -102,6 +106,8 @@ public PropertyMap load(final UUID uuid) throws Exception { private GameProfile fakeProfile; @Nullable private UUID skinUuid; + @Nullable private String skinTexture; + @Nullable private String skinSignature; private boolean aiDisabled = false, leftHanded = false; public EntityHuman(final World worldIn) { @@ -128,7 +134,7 @@ protected void entityInit() { // EntityPlayer this.dataManager.register(EntityPlayerAccessor.accessor$getAbsorptionParameter(), Float.valueOf(0.0F)); this.dataManager.register(EntityPlayerAccessor.accessor$getPlayerScoreParameter(), Integer.valueOf(0)); - this.dataManager.register(EntityPlayerAccessor.accessor$getPlayerModelFlagParameter(), Byte.valueOf((byte)0)); + this.dataManager.register(EntityPlayerAccessor.accessor$getPlayerModelFlagParameter(), Byte.valueOf((byte)127)); this.dataManager.register(EntityPlayerAccessor.accessor$getMainHandParameter(), Byte.valueOf((byte)1)); } @@ -172,7 +178,11 @@ public void setCustomNameTag(String name) { public void readEntityFromNBT(final NBTTagCompound tagCompund) { super.readEntityFromNBT(tagCompund); final String skinUuidString = ((DataCompoundHolder) this).data$getSpongeCompound().getString("skinUuid"); - if (!skinUuidString.isEmpty()) { + final String skinTextureString = ((DataCompoundHolder) this).data$getSpongeCompound().getString("skinTexture"); + final String skinSignatureString = ((DataCompoundHolder) this).data$getSpongeCompound().getString("skinSignature"); + if (!skinTextureString.isEmpty()) { + this.updateFakeProfileWithSkinTexture(skinTextureString, skinSignatureString.isEmpty() ? Optional.empty() : Optional.of(skinSignatureString)); + } else if (!skinUuidString.isEmpty()) { this.updateFakeProfileWithSkin(UUID.fromString(skinUuidString)); } } @@ -186,6 +196,16 @@ public void writeEntityToNBT(final NBTTagCompound tagCompound) { } else { spongeData.removeTag("skinUuid"); } + if (this.skinTexture != null) { + spongeData.setString("skinTexture", this.skinTexture); + } else { + spongeData.removeTag("skinTexture"); + } + if (this.skinSignature != null) { + spongeData.setString("skinSignature", this.skinSignature); + } else { + spongeData.removeTag("skinSignature"); + } } @Override @@ -202,6 +222,8 @@ public void setNoAI(final boolean disable) { @Override public void setLeftHanded(final boolean leftHanded) { this.leftHanded = leftHanded; + this.getDataManager().set(EntityPlayerAccessor.accessor$getMainHandParameter(), + Byte.valueOf((byte) (leftHanded ? 0 : 1))); } @Override @@ -328,6 +350,7 @@ private void renameProfile(final String newName) { this.fakeProfile.getProperties().putAll(props); } + // update with skin from a player uuid private boolean updateFakeProfileWithSkin(final UUID skin) { final PropertyMap properties = PROPERTIES_CACHE.getUnchecked(skin); if (properties.isEmpty()) { @@ -335,6 +358,37 @@ private boolean updateFakeProfileWithSkin(final UUID skin) { } this.fakeProfile.getProperties().replaceValues("textures", properties.get("textures")); this.skinUuid = skin; + this.skinTexture = null; + this.skinSignature = null; + return true; + } + + private boolean updateFakeProfileWithSkinTexture(final String texture) { + return updateFakeProfileWithSkinTexture(texture, Optional.of(this.skinSignature)); + } + + private boolean updateFakeProfileWithSkinSignature(final String signature) { + // just update the signature until there is a texture to go with it + if (this.skinTexture == null) + { + this.skinSignature = signature; + return true; + } + return updateFakeProfileWithSkinTexture(this.skinTexture, Optional.of(signature)); + } + + // update with skin texture + private boolean updateFakeProfileWithSkinTexture(final String texture, final Optional skinSignature) { + Property property; + if (skinSignature.isPresent() && skinSignature.get() != null) { + property = new Property("textures", texture, skinSignature.get()); + } else { + property = new Property("textures", texture); + } + this.skinTexture = texture; + if (skinSignature.isPresent()) this.skinSignature = skinSignature.get(); + this.fakeProfile.getProperties().replaceValues("textures", Collections.singleton(property)); + this.skinUuid = null; return true; } @@ -373,6 +427,51 @@ public UUID getSkinUuid() { return this.skinUuid; } + public boolean setSkinTexture(final String texture) { + if (!SpongeImpl.getServer().isServerInOnlineMode()) { + // Skins only work when online-mode = true + return false; + } + if (texture.equals(this.skinTexture)) { + return true; + } + if (!updateFakeProfileWithSkinTexture(texture)) { + return false; + } + if (this.isAliveAndInWorld()) { + this.respawnOnClient(); + } + return true; + } + + @Nullable + public String getSkinTexture() { + return this.skinTexture; + } + + public boolean setSkinSignature(final String signature) { + if (!SpongeImpl.getServer().isServerInOnlineMode()) { + // Skins only work when online-mode = true + return false; + } + if (signature.equals(this.skinSignature)) { + return true; + } + // just update the signature until there is a texture to go with it + if (!updateFakeProfileWithSkinSignature(signature)) { + return false; + } + if (this.isAliveAndInWorld()) { + this.respawnOnClient(); + } + return true; + } + + @Nullable + public String getSkinSignature() { + return this.skinSignature; + } + public DataTransactionResult removeSkin() { if (this.skinUuid == null) { return DataTransactionResult.successNoData(); @@ -386,6 +485,32 @@ public DataTransactionResult removeSkin() { return DataTransactionResult.builder().result(DataTransactionResult.Type.SUCCESS).replace(oldValue).build(); } + public DataTransactionResult removeSkinTexture() { + if (this.skinTexture == null) { + return DataTransactionResult.successNoData(); + } + this.fakeProfile.getProperties().removeAll("textures"); + final ImmutableValue oldValue = new ImmutableSpongeValue<>(Keys.SKIN_TEXTURE, this.skinTexture); + this.skinTexture = null; + if (this.isAliveAndInWorld()) { + this.respawnOnClient(); + } + return DataTransactionResult.builder().result(DataTransactionResult.Type.SUCCESS).replace(oldValue).build(); + } + + public DataTransactionResult removeSkinSignature() { + if (this.skinSignature == null) { + return DataTransactionResult.successNoData(); + } + this.fakeProfile.getProperties().removeAll("textures"); + final ImmutableValue oldValue = new ImmutableSpongeValue<>(Keys.SKIN_SIGNATURE, this.skinSignature); + this.skinSignature = null; + if (this.isAliveAndInWorld()) { + this.respawnOnClient(); + } + return DataTransactionResult.builder().result(DataTransactionResult.Type.SUCCESS).replace(oldValue).build(); + } + private boolean isAliveAndInWorld() { return this.world.getEntityByID(this.getEntityId()) == this && !this.isDead; } diff --git a/src/main/java/org/spongepowered/common/registry/type/data/KeyRegistryModule.java b/src/main/java/org/spongepowered/common/registry/type/data/KeyRegistryModule.java index 19b2f0689a7..eaa115f6d0e 100644 --- a/src/main/java/org/spongepowered/common/registry/type/data/KeyRegistryModule.java +++ b/src/main/java/org/spongepowered/common/registry/type/data/KeyRegistryModule.java @@ -403,6 +403,10 @@ public void registerDefaults() { this.register("skin_unique_id", Key.builder().type(TypeTokens.UUID_VALUE_TOKEN).id("skin_uuid").name("Skin UUID").query(of("SkinUUID")).build()); + this.register("skin_texture", Key.builder().type(TypeTokens.STRING_VALUE_TOKEN).id("skin_texture").name("Skin Texture").query(of("SkinTexture")).build()); + + this.register("skin_signature", Key.builder().type(TypeTokens.STRING_VALUE_TOKEN).id("skin_signature").name("Skin Signature").query(of("SkinSignature")).build()); + this.register("moisture", Key.builder().type(TypeTokens.BOUNDED_INTEGER_VALUE_TOKEN).id("moisture").name("Moisture").query(of("Moisture")).build()); this.register("angry", Key.builder().type(TypeTokens.BOOLEAN_VALUE_TOKEN).id("angry").name("Angry").query(of("Angry")).build()); diff --git a/src/main/java/org/spongepowered/common/util/Constants.java b/src/main/java/org/spongepowered/common/util/Constants.java index b507e051830..a00d17db6fd 100644 --- a/src/main/java/org/spongepowered/common/util/Constants.java +++ b/src/main/java/org/spongepowered/common/util/Constants.java @@ -1093,6 +1093,8 @@ private Legacy() { public static final class GameProfile { public static final DataQuery SKIN_UUID = of("SkinUUID"); + public static final DataQuery SKIN_TEXTURE = of("SkinTexture"); + public static final DataQuery SKIN_SIGNATURE = of("SkinSignature"); // RepresentedPlayerData public static final DataQuery GAME_PROFILE_ID = of("Id"); public static final DataQuery GAME_PROFILE_NAME = of("Name");