From 504418ca6ec9eb8508048ec52837c4888b7a3ef5 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 1 Dec 2017 00:39:05 +0000 Subject: [PATCH] Sort of adjust the antlers for 1.8 clients --- .../reindeer/OutfitReindeerAntlers.java | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/reindeer/OutfitReindeerAntlers.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/reindeer/OutfitReindeerAntlers.java index 6fc872a69..9e6bdda9f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/reindeer/OutfitReindeerAntlers.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/outfit/reindeer/OutfitReindeerAntlers.java @@ -2,6 +2,11 @@ package mineplex.core.gadget.gadgets.outfit.reindeer; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; + +import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMove; +import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; import org.bukkit.Location; import org.bukkit.Material; @@ -10,13 +15,18 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.inventory.ItemStack; import org.bukkit.util.EulerAngle; +import org.bukkit.util.Vector; import mineplex.core.common.Pair; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.gadget.GadgetManager; +import mineplex.core.packethandler.IPacketHandler; +import mineplex.core.packethandler.PacketInfo; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -public class OutfitReindeerAntlers extends OutfitReindeer +public class OutfitReindeerAntlers extends OutfitReindeer implements IPacketHandler { private static final ItemStack HELMET = new ItemStack(Material.DEAD_BUSH); @@ -30,6 +40,8 @@ public class OutfitReindeerAntlers extends OutfitReindeer super(manager, "Antlers", ArmorSlot.HELMET, Material.DEAD_BUSH, (byte) 0); _antlers = new HashMap<>(); + + manager.getPacketManager().addPacketHandler(this, PacketPlayOutEntityTeleport.class); } @Override @@ -94,4 +106,51 @@ public class OutfitReindeerAntlers extends OutfitReindeer _antlers.forEach((player, pair) -> updateRotation(player, pair.getLeft(), pair.getRight())); } + + @Override + public void handle(PacketInfo packetInfo) + { + Player player = packetInfo.getPlayer(); + + if (UtilPlayer.is1_9(player)) + { + return; + } + + PacketPlayOutEntityTeleport packet = (PacketPlayOutEntityTeleport) packetInfo.getPacket(); + int id = packet.a; + + for (Entry> entry : _antlers.entrySet()) + { + Player other = entry.getKey(); + Pair pair = entry.getValue(); + ArmorStand left = pair.getLeft(); + ArmorStand right = pair.getRight(); + boolean isLeft = left.getEntityId() == id; + PacketPlayOutRelEntityMove + if (isLeft || right.getEntityId() == id) + { + Location location = isLeft ? left.getLocation() : right.getLocation(); + Location otherLocation = other.getLocation(); + otherLocation.setPitch(0); + Vector direction = otherLocation.getDirection(); + Vector offset; + + if (isLeft) + { + offset = UtilAlg.getRight(direction); + } + else + { + offset = UtilAlg.getLeft(direction); + } + + location.add(offset.multiply(0.4)); + + packet.b = MathHelper.floor(location.getX() * 32); + packet.d = MathHelper.floor(location.getZ() * 32); + return; + } + } + } }