Add setNameYModifier to change armorstand height

This commit is contained in:
libraryaddict 2022-02-18 04:31:44 +13:00
parent d4a18b3c11
commit bc277fe2f0
4 changed files with 26 additions and 4 deletions

@ -71,6 +71,8 @@ public class FlagWatcher {
private Float yawLock; private Float yawLock;
@Getter @Getter
private float yModifier; private float yModifier;
@Getter
private float nameYModifier;
public FlagWatcher(Disguise disguise) { public FlagWatcher(Disguise disguise) {
this.disguise = (TargetedDisguise) disguise; this.disguise = (TargetedDisguise) disguise;
@ -89,13 +91,30 @@ public class FlagWatcher {
setPitchLock(pitchLocked ? 0F : null); 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) { public void setYModifier(float yModifier) {
if (!DisguiseConfig.isMovementPacketsEnabled()) { if (!DisguiseConfig.isMovementPacketsEnabled()) {
return; return;
} }
double diff = yModifier - getYModifier();
this.yModifier = yModifier; this.yModifier = yModifier;
if (!getDisguise().isDisguiseInUse()) { if (!getDisguise().isDisguiseInUse()) {
@ -208,6 +227,7 @@ public class FlagWatcher {
cloned.pitchLock = pitchLock; cloned.pitchLock = pitchLock;
cloned.yawLock = yawLock; cloned.yawLock = yawLock;
cloned.yModifier = yModifier; cloned.yModifier = yModifier;
cloned.nameYModifier = nameYModifier;
return cloned; return cloned;
} }

@ -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 // 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++) { for (int i = 0; i < newNames.length; i++) {
if (i < internalOldNames.length) { if (i < internalOldNames.length) {

@ -50,7 +50,7 @@ public class PacketHandlerMovement implements IPacketHandler {
} }
ArrayList<PacketContainer> toAdd = new ArrayList<>(); ArrayList<PacketContainer> toAdd = new ArrayList<>();
double height = disguise.getHeight(); double height = disguise.getHeight() + disguise.getWatcher().getNameYModifier();
for (PacketContainer packet : packets.getPackets()) { for (PacketContainer packet : packets.getPackets()) {
if (packet.getType() == PacketType.Play.Server.ENTITY_LOOK) { if (packet.getType() == PacketType.Play.Server.ENTITY_LOOK) {

@ -391,6 +391,8 @@ public class DisguisePermissions {
if (sender instanceof Player && !sender.isOp() && !DisguiseConfig.isExplicitDisguisePermissions()) { if (sender instanceof Player && !sender.isOp() && !DisguiseConfig.isExplicitDisguisePermissions()) {
storage.permittedOptions.remove("setYModifier"); storage.permittedOptions.remove("setYModifier");
storage.negatedOptions.add("setYModifier"); storage.negatedOptions.add("setYModifier");
storage.permittedOptions.remove("setNameYModifier");
storage.negatedOptions.add("setNameYModifier");
} }
disguises.add(storage); disguises.add(storage);