From 2c997935c9ab8530b3ce5a42d5cd87ffc1801278 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Tue, 18 Jul 2017 12:33:07 -0400 Subject: [PATCH] Rewrite spawn meta for all living entities on 1.10 and up --- .../disguise/disguises/DisguiseCreature.java | 57 +++++++++++++++++-- .../disguise/disguises/DisguiseGuardian.java | 39 ++----------- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseCreature.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseCreature.java index d477ab3bc..55e62c217 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseCreature.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseCreature.java @@ -1,9 +1,16 @@ package mineplex.core.disguise.disguises; -import net.minecraft.server.v1_8_R3.MathHelper; -import net.minecraft.server.v1_8_R3.Packet; -import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; -import org.bukkit.entity.*; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import com.mineplex.MetaWrapper; +import com.mineplex.ProtocolVersion; + +import net.minecraft.server.v1_8_R3.*; +import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject; + +import org.bukkit.entity.EntityType; public abstract class DisguiseCreature extends DisguiseInsentient { @@ -70,4 +77,46 @@ public abstract class DisguiseCreature extends DisguiseInsentient return packet; } + + @Override + public Packet modifySpawnPacket(int protocol, Packet packet) + { + if (protocol >= ProtocolVersion.v1_10_PRE) + { + PacketPlayOutSpawnEntityLiving newSpawn = (PacketPlayOutSpawnEntityLiving) getSpawnPacket(); + newSpawn.m = processSpawnMeta(protocol, DataWatcher.c()); + return newSpawn; + } + + return packet; + } + + private List processSpawnMeta(int protocol, List list) + { + List newMeta = new ArrayList<>(); + for (WatchableObject meta : list) + { + MetaWrapper wrapper = new MetaWrapper(meta); + if (wrapper.getIndex() >= 5) // 1.10 + { + wrapper.setIndex(wrapper.getIndex() + 1); + } + + if (protocol < ProtocolVersion.v1_11) + { + newMeta.add(wrapper); + continue; + } + + if (getEntity() instanceof EntityArmorStand && wrapper.getIndex() >= 12) + { + // Armor stand meta conflicts with a lot of entities on 1.11+ + continue; + } + + newMeta.add(wrapper); + } + + return newMeta.stream().map(MetaWrapper::toWatchableObject).collect(Collectors.toList()); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseGuardian.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseGuardian.java index eaa367258..31222e6da 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseGuardian.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseGuardian.java @@ -71,15 +71,13 @@ public class DisguiseGuardian extends DisguiseCreature @Override public Packet modifySpawnPacket(int protocol, Packet packet) { - if (protocol >= ProtocolVersion.v1_11) + PacketPlayOutSpawnEntityLiving newSpawn = (PacketPlayOutSpawnEntityLiving) super.modifySpawnPacket(protocol, packet); + if (protocol >= ProtocolVersion.v1_11 && isElder()) { - PacketPlayOutSpawnEntityLiving newSpawn = (PacketPlayOutSpawnEntityLiving) getSpawnPacket(); - if (isElder()) newSpawn.b = 4; - newSpawn.m = processSpawnMeta(DataWatcher.c()); - return newSpawn; + newSpawn.b = 4; } - return packet; + return newSpawn; } @Override @@ -113,33 +111,4 @@ public class DisguiseGuardian extends DisguiseCreature return newMeta.stream().map(MetaWrapper::toWatchableObject).collect(Collectors.toList()); } - - private List processSpawnMeta(List list) - { - List newMeta = new ArrayList<>(); - for (WatchableObject meta : list) - { - MetaWrapper wrapper = new MetaWrapper(meta); - if (wrapper.getIndex() >= 5) // 1.10 - { - wrapper.setIndex(wrapper.getIndex() + 1); - } - - if (getEntity() instanceof EntityArmorStand && (wrapper.getIndex() == 12 || wrapper.getIndex() == 13)) - { - continue; - } - - if (wrapper.getIndex() < 12) // Skip higher ones in 1.11 - { - newMeta.add(wrapper); - } else if (wrapper.getIndex() == 12) - { - byte value = (byte) wrapper.getValue(); - newMeta.add(new MetaWrapper(12, DataType.BOOLEAN, (value & 0x02) != 0)); - } - } - - return newMeta.stream().map(MetaWrapper::toWatchableObject).collect(Collectors.toList()); - } }