From bc277fe2f06b80897402e76066f47186c3820942 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 18 Feb 2022 04:31:44 +1300 Subject: [PATCH] Add setNameYModifier to change armorstand height --- .../disguise/disguisetypes/FlagWatcher.java | 24 +++++++++++++++++-- .../disguise/utilities/DisguiseUtilities.java | 2 +- .../packethandlers/PacketHandlerMovement.java | 2 +- .../utilities/parser/DisguisePermissions.java | 2 ++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index fd82dacc..b6ba7818 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -71,6 +71,8 @@ public class FlagWatcher { private Float yawLock; @Getter private float yModifier; + @Getter + private float nameYModifier; public FlagWatcher(Disguise disguise) { this.disguise = (TargetedDisguise) disguise; @@ -89,13 +91,30 @@ public class FlagWatcher { setPitchLock(pitchLocked ? 0F : null); } + public void setNameYModifier(float yModifier) { + this.nameYModifier = yModifier; + + if (!DisguiseConfig.isMovementPacketsEnabled() && !getDisguise().isDisguiseInUse()) { + return; + } + + PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.ENTITY_TELEPORT, getDisguise().getEntity()) + .createPacket(getDisguise().getEntity()); + + try { + for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); + } + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + public void setYModifier(float yModifier) { if (!DisguiseConfig.isMovementPacketsEnabled()) { return; } - double diff = yModifier - getYModifier(); - this.yModifier = yModifier; if (!getDisguise().isDisguiseInUse()) { @@ -208,6 +227,7 @@ public class FlagWatcher { cloned.pitchLock = pitchLock; cloned.yawLock = yawLock; cloned.yModifier = yModifier; + cloned.nameYModifier = nameYModifier; return cloned; } diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 632cbc27..4c99accd 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -3022,7 +3022,7 @@ public class DisguiseUtilities { } // Don't need to offset with DisguiseUtilities.getYModifier, because that's a visual offset and not an actual location offset - double height = disguise.getHeight() + disguise.getWatcher().getYModifier(); + double height = disguise.getHeight() + disguise.getWatcher().getYModifier() + disguise.getWatcher().getNameYModifier(); for (int i = 0; i < newNames.length; i++) { if (i < internalOldNames.length) { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerMovement.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerMovement.java index 303facb3..f3b2aac5 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerMovement.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerMovement.java @@ -50,7 +50,7 @@ public class PacketHandlerMovement implements IPacketHandler { } ArrayList toAdd = new ArrayList<>(); - double height = disguise.getHeight(); + double height = disguise.getHeight() + disguise.getWatcher().getNameYModifier(); for (PacketContainer packet : packets.getPackets()) { if (packet.getType() == PacketType.Play.Server.ENTITY_LOOK) { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguisePermissions.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguisePermissions.java index 8a50467d..29cec77c 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguisePermissions.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguisePermissions.java @@ -391,6 +391,8 @@ public class DisguisePermissions { if (sender instanceof Player && !sender.isOp() && !DisguiseConfig.isExplicitDisguisePermissions()) { storage.permittedOptions.remove("setYModifier"); storage.negatedOptions.add("setYModifier"); + storage.permittedOptions.remove("setNameYModifier"); + storage.negatedOptions.add("setNameYModifier"); } disguises.add(storage);