Add setPitchLock and setYawLock on FlagWatcher, closes #507
This commit is contained in:
parent
45d42b1c6b
commit
c1a8001b54
@ -1,5 +1,6 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
@ -25,12 +26,12 @@ import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
@ -58,12 +59,80 @@ public class FlagWatcher {
|
||||
@Getter
|
||||
private boolean upsideDown;
|
||||
private ChatColor glowColor;
|
||||
@Getter
|
||||
private Float pitchLock;
|
||||
@Getter
|
||||
private Float yawLock;
|
||||
|
||||
public FlagWatcher(Disguise disguise) {
|
||||
this.disguise = (TargetedDisguise) disguise;
|
||||
equipment = new LibsEquipment(this);
|
||||
}
|
||||
|
||||
public boolean isPitchLocked() {
|
||||
return pitchLock != null;
|
||||
}
|
||||
|
||||
public void setPitchLocked(boolean pitchLocked) {
|
||||
if (isPitchLocked() == pitchLocked) {
|
||||
return;
|
||||
}
|
||||
|
||||
setPitchLock(pitchLocked ? 0F : null);
|
||||
}
|
||||
|
||||
public boolean isYawLocked() {
|
||||
return yawLock != null;
|
||||
}
|
||||
|
||||
public void setYawLocked(boolean yawLocked) {
|
||||
if (isYawLocked() == yawLocked) {
|
||||
return;
|
||||
}
|
||||
|
||||
setYawLock(yawLocked ? 0F : null);
|
||||
}
|
||||
|
||||
public void setPitchLock(Float pitch) {
|
||||
this.pitchLock = pitch;
|
||||
|
||||
if (!getDisguise().isDisguiseInUse()) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendHeadPacket();
|
||||
}
|
||||
|
||||
private void sendHeadPacket() {
|
||||
PacketContainer rotateHead = new PacketContainer(Server.ENTITY_HEAD_ROTATION);
|
||||
|
||||
StructureModifier<Object> mods = rotateHead.getModifier();
|
||||
|
||||
mods.write(0, getDisguise().getEntity().getEntityId());
|
||||
|
||||
Location loc = getDisguise().getEntity().getLocation();
|
||||
|
||||
mods.write(1, (byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, rotateHead);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setYawLock(Float yaw) {
|
||||
this.yawLock = yaw;
|
||||
|
||||
if (!getDisguise().isDisguiseInUse()) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendHeadPacket();
|
||||
}
|
||||
|
||||
private byte addEntityAnimations(byte originalValue, byte entityValue) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations[i]) {
|
||||
|
@ -25,7 +25,11 @@ public class PacketHandlerHeadRotation implements IPacketHandler {
|
||||
@Override
|
||||
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
||||
Entity entity) {
|
||||
if (!disguise.getType().isPlayer() || entity.getType() == EntityType.PLAYER) {
|
||||
Float pitchLock = disguise.getWatcher().getPitchLock();
|
||||
Float yawLock = disguise.getWatcher().getYawLock();
|
||||
|
||||
if (pitchLock == null && yawLock == null &&
|
||||
(!disguise.getType().isPlayer() || entity.getType() == EntityType.PLAYER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -33,8 +37,16 @@ public class PacketHandlerHeadRotation implements IPacketHandler {
|
||||
|
||||
DisguiseType entityType = DisguiseType.getType(entity);
|
||||
|
||||
byte pitch;
|
||||
byte yaw;
|
||||
byte pitch = 0;
|
||||
byte yaw = 0;
|
||||
|
||||
if (pitchLock != null) {
|
||||
pitch = (byte) (int) (pitchLock * 256.0F / 360.0F);
|
||||
}
|
||||
|
||||
if (yawLock != null) {
|
||||
yaw = (byte) (int) (yawLock * 256.0F / 360.0F);
|
||||
}
|
||||
|
||||
switch (entityType) {
|
||||
case LLAMA_SPIT:
|
||||
@ -61,22 +73,38 @@ public class PacketHandlerHeadRotation implements IPacketHandler {
|
||||
case SNOWBALL:
|
||||
case PAINTING:
|
||||
case PRIMED_TNT:
|
||||
if (sentPacket.getBytes().read(0) == 0 && entity.getVelocity().lengthSquared() > 0) {
|
||||
if ((pitchLock == null || yawLock == null) && sentPacket.getBytes().read(0) == 0 &&
|
||||
entity.getVelocity().lengthSquared() > 0) {
|
||||
loc.setDirection(entity.getVelocity());
|
||||
pitch = DisguiseUtilities.getPitch(disguise.getType(), DisguiseType.PLAYER,
|
||||
(byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
||||
yaw = DisguiseUtilities.getYaw(disguise.getType(), DisguiseType.PLAYER,
|
||||
(byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
||||
|
||||
if (pitchLock == null) {
|
||||
pitch = DisguiseUtilities
|
||||
.getPitch(DisguiseType.PLAYER, (byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
if (yawLock == null) {
|
||||
yaw = DisguiseUtilities
|
||||
.getYaw(DisguiseType.PLAYER, (byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
pitch = DisguiseUtilities.getPitch(disguise.getType(), entity.getType(),
|
||||
if (pitchLock == null) {
|
||||
pitch = DisguiseUtilities.getPitch(DisguiseType.getType(entity.getType()),
|
||||
(byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
||||
yaw = DisguiseUtilities
|
||||
.getYaw(disguise.getType(), entity.getType(), (byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
if (yawLock == null) {
|
||||
yaw = DisguiseUtilities.getYaw(DisguiseType.getType(entity.getType()),
|
||||
(byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
pitch = DisguiseUtilities.getPitch(disguise.getType(), pitch);
|
||||
yaw = DisguiseUtilities.getYaw(disguise.getType(), yaw);
|
||||
|
||||
PacketContainer rotation = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||
|
||||
StructureModifier<Object> mods = rotation.getModifier();
|
||||
|
@ -122,14 +122,6 @@ public class PacketHandlerMovement implements IPacketHandler {
|
||||
}
|
||||
|
||||
packets.addPacket(movePacket);
|
||||
|
||||
StructureModifier<Byte> bytes = movePacket.getBytes();
|
||||
|
||||
byte yawValue = bytes.read(0);
|
||||
byte pitchValue = bytes.read(1);
|
||||
|
||||
bytes.write(0, DisguiseUtilities.getYaw(disguise.getType(), entity.getType(), yawValue));
|
||||
bytes.write(1, DisguiseUtilities.getPitch(disguise.getType(), entity.getType(), pitchValue));
|
||||
} else if (disguise.getType() == DisguiseType.RABBIT &&
|
||||
(sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE ||
|
||||
sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK)) {
|
||||
@ -157,7 +149,9 @@ public class PacketHandlerMovement implements IPacketHandler {
|
||||
statusPacket.getIntegers().write(0, entity.getEntityId());
|
||||
statusPacket.getBytes().write(0, (byte) 1);
|
||||
}
|
||||
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK &&
|
||||
}
|
||||
|
||||
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK &&
|
||||
disguise.getType() == DisguiseType.WITHER_SKULL) {
|
||||
// Stop wither skulls from looking
|
||||
packets.clear();
|
||||
@ -174,8 +168,26 @@ public class PacketHandlerMovement implements IPacketHandler {
|
||||
byte yawValue = bytes.read(0);
|
||||
byte pitchValue = bytes.read(1);
|
||||
|
||||
bytes.write(0, DisguiseUtilities.getYaw(disguise.getType(), entity.getType(), yawValue));
|
||||
bytes.write(1, DisguiseUtilities.getPitch(disguise.getType(), entity.getType(), pitchValue));
|
||||
Float pitchLock = disguise.getWatcher().getPitchLock();
|
||||
Float yawLock = disguise.getWatcher().getYawLock();
|
||||
|
||||
if (pitchLock != null) {
|
||||
pitchValue = (byte) (int) (pitchLock * 256.0F / 360.0F);
|
||||
pitchValue = DisguiseUtilities.getPitch(disguise.getType(), pitchValue);
|
||||
} else {
|
||||
pitchValue = DisguiseUtilities.getPitch(disguise.getType(), entity.getType(), pitchValue);
|
||||
|
||||
}
|
||||
|
||||
if (yawLock != null) {
|
||||
yawValue = (byte) (int) (yawLock * 256.0F / 360.0F);
|
||||
yawValue = DisguiseUtilities.getYaw(disguise.getType(), yawValue);
|
||||
} else {
|
||||
yawValue = DisguiseUtilities.getYaw(disguise.getType(), entity.getType(), yawValue);
|
||||
}
|
||||
|
||||
bytes.write(0, yawValue);
|
||||
bytes.write(1, pitchValue);
|
||||
|
||||
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT &&
|
||||
disguise.getType() == DisguiseType.ITEM_FRAME) {
|
||||
|
@ -106,12 +106,24 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
Location loc = disguisedEntity.getLocation().clone()
|
||||
.add(0, DisguiseUtilities.getYModifier(disguisedEntity, disguise), 0);
|
||||
|
||||
byte yaw = (byte) (int) (loc.getYaw() * 256.0F / 360.0F);
|
||||
byte pitch = (byte) (int) (loc.getPitch() * 256.0F / 360.0F);
|
||||
Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null;
|
||||
Float yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null;
|
||||
|
||||
byte yaw = (byte) (int) ((yawLock == null ? loc.getYaw() : yawLock) * 256.0F / 360.0F);
|
||||
byte pitch = (byte) (int) ((pitchLock == null ? loc.getPitch() : pitchLock) * 256.0F / 360.0F);
|
||||
|
||||
if (DisguiseConfig.isMovementPacketsEnabled()) {
|
||||
yaw = DisguiseUtilities.getYaw(disguise.getType(), disguisedEntity.getType(), yaw);
|
||||
pitch = DisguiseUtilities.getPitch(disguise.getType(), disguisedEntity.getType(), pitch);
|
||||
if (yawLock == null) {
|
||||
yaw = DisguiseUtilities.getYaw(DisguiseType.getType(disguisedEntity.getType()), yaw);
|
||||
}
|
||||
|
||||
if (pitchLock == null) {
|
||||
pitch = DisguiseUtilities.getPitch(DisguiseType.getType(disguisedEntity.getType()), pitch);
|
||||
}
|
||||
|
||||
yaw = DisguiseUtilities.getYaw(disguise.getType(), yaw);
|
||||
pitch = DisguiseUtilities.getPitch(disguise.getType(), pitch);
|
||||
|
||||
}
|
||||
|
||||
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
|
||||
@ -261,18 +273,24 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
double d2 = vec.getX();
|
||||
double d3 = vec.getY();
|
||||
double d4 = vec.getZ();
|
||||
if (d2 < -d1)
|
||||
if (d2 < -d1) {
|
||||
d2 = -d1;
|
||||
if (d3 < -d1)
|
||||
}
|
||||
if (d3 < -d1) {
|
||||
d3 = -d1;
|
||||
if (d4 < -d1)
|
||||
}
|
||||
if (d4 < -d1) {
|
||||
d4 = -d1;
|
||||
if (d2 > d1)
|
||||
}
|
||||
if (d2 > d1) {
|
||||
d2 = d1;
|
||||
if (d3 > d1)
|
||||
}
|
||||
if (d3 > d1) {
|
||||
d3 = d1;
|
||||
if (d4 > d1)
|
||||
}
|
||||
if (d4 > d1) {
|
||||
d4 = d1;
|
||||
}
|
||||
// endregion
|
||||
|
||||
mods.write(3, loc.getX());
|
||||
|
@ -135,6 +135,7 @@ public class ParamInfoTypes {
|
||||
paramInfos.add(new ParamInfoString(String.class, "Text", "A line of text"));
|
||||
paramInfos.add(new ParamInfoInteger("Number", "A whole number without decimals"));
|
||||
paramInfos.add(new ParamInfoFloat("Number.0", "A number which can have decimal places"));
|
||||
paramInfos.add(new ParamInfoFloatNullable("Number.0", "A number which can have decimal places or be null"));
|
||||
paramInfos.add(new ParamInfoDouble("Number.0", "A number which can have decimal places"));
|
||||
paramInfos.add(new ParamInfoSoundGroup());
|
||||
|
||||
|
@ -7,12 +7,7 @@ import me.libraryaddict.disguise.utilities.params.ParamInfo;
|
||||
*/
|
||||
public class ParamInfoFloat extends ParamInfo {
|
||||
public ParamInfoFloat(String name, String description) {
|
||||
super(Number.class, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParam(Class classType) {
|
||||
return classType == Float.class || classType == Float.TYPE;
|
||||
super(float.class, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,31 @@
|
||||
package me.libraryaddict.disguise.utilities.params.types.base;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfo;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 7/09/2018.
|
||||
*/
|
||||
public class ParamInfoFloatNullable extends ParamInfo {
|
||||
public ParamInfoFloatNullable(String name, String description) {
|
||||
super(Float.class, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object fromString(String string) {
|
||||
if (string == null || string.equals("null")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Float.parseFloat(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReturnNull() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object object) {
|
||||
return object == null ? "null" : object.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user