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;
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.PacketType.Play.Server;
|
import com.comphenix.protocol.PacketType.Play.Server;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
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.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scoreboard.Team;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -58,12 +59,80 @@ public class FlagWatcher {
|
|||||||
@Getter
|
@Getter
|
||||||
private boolean upsideDown;
|
private boolean upsideDown;
|
||||||
private ChatColor glowColor;
|
private ChatColor glowColor;
|
||||||
|
@Getter
|
||||||
|
private Float pitchLock;
|
||||||
|
@Getter
|
||||||
|
private Float yawLock;
|
||||||
|
|
||||||
public FlagWatcher(Disguise disguise) {
|
public FlagWatcher(Disguise disguise) {
|
||||||
this.disguise = (TargetedDisguise) disguise;
|
this.disguise = (TargetedDisguise) disguise;
|
||||||
equipment = new LibsEquipment(this);
|
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) {
|
private byte addEntityAnimations(byte originalValue, byte entityValue) {
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations[i]) {
|
if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations[i]) {
|
||||||
|
@ -24,8 +24,12 @@ public class PacketHandlerHeadRotation implements IPacketHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
||||||
Entity entity) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,8 +37,16 @@ public class PacketHandlerHeadRotation implements IPacketHandler {
|
|||||||
|
|
||||||
DisguiseType entityType = DisguiseType.getType(entity);
|
DisguiseType entityType = DisguiseType.getType(entity);
|
||||||
|
|
||||||
byte pitch;
|
byte pitch = 0;
|
||||||
byte yaw;
|
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) {
|
switch (entityType) {
|
||||||
case LLAMA_SPIT:
|
case LLAMA_SPIT:
|
||||||
@ -61,22 +73,38 @@ public class PacketHandlerHeadRotation implements IPacketHandler {
|
|||||||
case SNOWBALL:
|
case SNOWBALL:
|
||||||
case PAINTING:
|
case PAINTING:
|
||||||
case PRIMED_TNT:
|
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());
|
loc.setDirection(entity.getVelocity());
|
||||||
pitch = DisguiseUtilities.getPitch(disguise.getType(), DisguiseType.PLAYER,
|
|
||||||
(byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
if (pitchLock == null) {
|
||||||
yaw = DisguiseUtilities.getYaw(disguise.getType(), DisguiseType.PLAYER,
|
pitch = DisguiseUtilities
|
||||||
(byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
.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;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
pitch = DisguiseUtilities.getPitch(disguise.getType(), entity.getType(),
|
if (pitchLock == null) {
|
||||||
(byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
pitch = DisguiseUtilities.getPitch(DisguiseType.getType(entity.getType()),
|
||||||
yaw = DisguiseUtilities
|
(byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
||||||
.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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pitch = DisguiseUtilities.getPitch(disguise.getType(), pitch);
|
||||||
|
yaw = DisguiseUtilities.getYaw(disguise.getType(), yaw);
|
||||||
|
|
||||||
PacketContainer rotation = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
PacketContainer rotation = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||||
|
|
||||||
StructureModifier<Object> mods = rotation.getModifier();
|
StructureModifier<Object> mods = rotation.getModifier();
|
||||||
|
@ -122,14 +122,6 @@ public class PacketHandlerMovement implements IPacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
packets.addPacket(movePacket);
|
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 &&
|
} else if (disguise.getType() == DisguiseType.RABBIT &&
|
||||||
(sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE ||
|
(sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE ||
|
||||||
sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK)) {
|
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.getIntegers().write(0, entity.getEntityId());
|
||||||
statusPacket.getBytes().write(0, (byte) 1);
|
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) {
|
disguise.getType() == DisguiseType.WITHER_SKULL) {
|
||||||
// Stop wither skulls from looking
|
// Stop wither skulls from looking
|
||||||
packets.clear();
|
packets.clear();
|
||||||
@ -174,8 +168,26 @@ public class PacketHandlerMovement implements IPacketHandler {
|
|||||||
byte yawValue = bytes.read(0);
|
byte yawValue = bytes.read(0);
|
||||||
byte pitchValue = bytes.read(1);
|
byte pitchValue = bytes.read(1);
|
||||||
|
|
||||||
bytes.write(0, DisguiseUtilities.getYaw(disguise.getType(), entity.getType(), yawValue));
|
Float pitchLock = disguise.getWatcher().getPitchLock();
|
||||||
bytes.write(1, DisguiseUtilities.getPitch(disguise.getType(), entity.getType(), pitchValue));
|
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 &&
|
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT &&
|
||||||
disguise.getType() == DisguiseType.ITEM_FRAME) {
|
disguise.getType() == DisguiseType.ITEM_FRAME) {
|
||||||
|
@ -58,7 +58,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
||||||
Entity entity) {
|
Entity entity) {
|
||||||
|
|
||||||
packets.clear();
|
packets.clear();
|
||||||
|
|
||||||
@ -106,12 +106,24 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
|||||||
Location loc = disguisedEntity.getLocation().clone()
|
Location loc = disguisedEntity.getLocation().clone()
|
||||||
.add(0, DisguiseUtilities.getYModifier(disguisedEntity, disguise), 0);
|
.add(0, DisguiseUtilities.getYModifier(disguisedEntity, disguise), 0);
|
||||||
|
|
||||||
byte yaw = (byte) (int) (loc.getYaw() * 256.0F / 360.0F);
|
Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null;
|
||||||
byte pitch = (byte) (int) (loc.getPitch() * 256.0F / 360.0F);
|
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()) {
|
if (DisguiseConfig.isMovementPacketsEnabled()) {
|
||||||
yaw = DisguiseUtilities.getYaw(disguise.getType(), disguisedEntity.getType(), yaw);
|
if (yawLock == null) {
|
||||||
pitch = DisguiseUtilities.getPitch(disguise.getType(), disguisedEntity.getType(), pitch);
|
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) {
|
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
|
||||||
@ -261,18 +273,24 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
|||||||
double d2 = vec.getX();
|
double d2 = vec.getX();
|
||||||
double d3 = vec.getY();
|
double d3 = vec.getY();
|
||||||
double d4 = vec.getZ();
|
double d4 = vec.getZ();
|
||||||
if (d2 < -d1)
|
if (d2 < -d1) {
|
||||||
d2 = -d1;
|
d2 = -d1;
|
||||||
if (d3 < -d1)
|
}
|
||||||
|
if (d3 < -d1) {
|
||||||
d3 = -d1;
|
d3 = -d1;
|
||||||
if (d4 < -d1)
|
}
|
||||||
|
if (d4 < -d1) {
|
||||||
d4 = -d1;
|
d4 = -d1;
|
||||||
if (d2 > d1)
|
}
|
||||||
|
if (d2 > d1) {
|
||||||
d2 = d1;
|
d2 = d1;
|
||||||
if (d3 > d1)
|
}
|
||||||
|
if (d3 > d1) {
|
||||||
d3 = d1;
|
d3 = d1;
|
||||||
if (d4 > d1)
|
}
|
||||||
|
if (d4 > d1) {
|
||||||
d4 = d1;
|
d4 = d1;
|
||||||
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
mods.write(3, loc.getX());
|
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 ParamInfoString(String.class, "Text", "A line of text"));
|
||||||
paramInfos.add(new ParamInfoInteger("Number", "A whole number without decimals"));
|
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 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 ParamInfoDouble("Number.0", "A number which can have decimal places"));
|
||||||
paramInfos.add(new ParamInfoSoundGroup());
|
paramInfos.add(new ParamInfoSoundGroup());
|
||||||
|
|
||||||
|
@ -7,12 +7,7 @@ import me.libraryaddict.disguise.utilities.params.ParamInfo;
|
|||||||
*/
|
*/
|
||||||
public class ParamInfoFloat extends ParamInfo {
|
public class ParamInfoFloat extends ParamInfo {
|
||||||
public ParamInfoFloat(String name, String description) {
|
public ParamInfoFloat(String name, String description) {
|
||||||
super(Number.class, name, description);
|
super(float.class, name, description);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isParam(Class classType) {
|
|
||||||
return classType == Float.class || classType == Float.TYPE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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