Add y modifier to disguises

This commit is contained in:
libraryaddict 2020-10-09 10:55:38 +13:00
parent 1795e03e31
commit 6505d7530f
7 changed files with 79 additions and 21 deletions

View File

@ -62,6 +62,8 @@ public class FlagWatcher {
private Float pitchLock; private Float pitchLock;
@Getter @Getter
private Float yawLock; private Float yawLock;
@Getter
private float yModifier;
public FlagWatcher(Disguise disguise) { public FlagWatcher(Disguise disguise) {
this.disguise = (TargetedDisguise) disguise; this.disguise = (TargetedDisguise) disguise;
@ -80,11 +82,41 @@ public class FlagWatcher {
setPitchLock(pitchLocked ? 0F : null); setPitchLock(pitchLocked ? 0F : null);
} }
public void setYModifier(float yModifier) {
if (!DisguiseConfig.isMovementPacketsEnabled()) {
return;
}
double diff = yModifier - getYModifier();
this.yModifier = yModifier;
if (!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 boolean isYawLocked() { public boolean isYawLocked() {
return yawLock != null; return yawLock != null;
} }
public void setYawLocked(boolean yawLocked) { public void setYawLocked(boolean yawLocked) {
if (!DisguiseConfig.isMovementPacketsEnabled()) {
return;
}
if (isYawLocked() == yawLocked) { if (isYawLocked() == yawLocked) {
return; return;
} }
@ -93,6 +125,10 @@ public class FlagWatcher {
} }
public void setPitchLock(Float pitch) { public void setPitchLock(Float pitch) {
if (!DisguiseConfig.isMovementPacketsEnabled()) {
return;
}
this.pitchLock = pitch; this.pitchLock = pitch;
if (!getDisguise().isDisguiseInUse()) { if (!getDisguise().isDisguiseInUse()) {

View File

@ -2311,8 +2311,6 @@ public class DisguiseUtilities {
} }
} }
Location loc = player.getLocation();
// Resend any active potion effects // Resend any active potion effects
for (PotionEffect potionEffect : player.getActivePotionEffects()) { for (PotionEffect potionEffect : player.getActivePotionEffects()) {
Object mobEffect = ReflectionManager.createMobEffect(potionEffect); Object mobEffect = ReflectionManager.createMobEffect(potionEffect);
@ -2939,7 +2937,7 @@ public class DisguiseUtilities {
Location loc = disguise.getEntity().getLocation(); Location loc = disguise.getEntity().getLocation();
packet.getDoubles().write(0, loc.getX()); packet.getDoubles().write(0, loc.getX());
packet.getDoubles().write(1, loc.getY() + height + (0.28 * i)); packet.getDoubles().write(1, loc.getY() + height + disguise.getWatcher().getYModifier() + (0.28 * i));
packet.getDoubles().write(2, loc.getZ()); packet.getDoubles().write(2, loc.getZ());
packets.add(packet); packets.add(packet);

View File

@ -235,7 +235,7 @@ public class PlayerSkinHandler implements Listener {
PacketContainer teleport = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT); PacketContainer teleport = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
StructureModifier<Object> mods = teleport.getModifier(); StructureModifier<Object> mods = teleport.getModifier();
Location loc = disguise.getEntity().getLocation(); Location loc = disguise.getEntity().getLocation().add(0, disguise.getWatcher().getYModifier(), 0);
Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null; Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null;
Float yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null; Float yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null;

View File

@ -81,6 +81,8 @@ public class PacketHandlerMovement implements IPacketHandler {
return; return;
} }
double yMod = disguise.getWatcher().getYModifier();
// If falling block should be appearing in center of blocks // If falling block should be appearing in center of blocks
if (disguise.getType() == DisguiseType.FALLING_BLOCK && if (disguise.getType() == DisguiseType.FALLING_BLOCK &&
((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) { ((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
@ -91,11 +93,10 @@ public class PacketHandlerMovement implements IPacketHandler {
} }
PacketContainer movePacket = sentPacket.shallowClone(); PacketContainer movePacket = sentPacket.shallowClone();
Location loc = entity.getLocation();
// If not relational movement // If not relational movement
if (movePacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT) { if (movePacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT) {
Location loc = entity.getLocation();
StructureModifier<Double> doubles = movePacket.getDoubles(); StructureModifier<Double> doubles = movePacket.getDoubles();
// Center the block // Center the block
doubles.write(0, loc.getBlockX() + 0.5); doubles.write(0, loc.getBlockX() + 0.5);
@ -104,29 +105,27 @@ public class PacketHandlerMovement implements IPacketHandler {
y += (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0); y += (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0);
doubles.write(1, y); doubles.write(1, y + yMod);
doubles.write(2, loc.getBlockZ() + 0.5); doubles.write(2, loc.getBlockZ() + 0.5);
} else { } else {
StructureModifier<Short> shorts = movePacket.getShorts(); StructureModifier<Short> shorts = movePacket.getShorts();
Location origLoc = entity.getLocation();
Vector diff = new Vector(shorts.read(0) / 4096D, shorts.read(1) / 4096D, shorts.read(2) / 4096D); Vector diff = new Vector(shorts.read(0) / 4096D, shorts.read(1) / 4096D, shorts.read(2) / 4096D);
Location newLoc = origLoc.clone().subtract(diff); Location newLoc = loc.clone().subtract(diff);
double origY = double origY = loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0);
origLoc.getBlockY() + (origLoc.getY() % 1 >= 0.85 ? 1 : origLoc.getY() % 1 >= 0.35 ? .5 : 0);
double newY = newLoc.getBlockY() + (newLoc.getY() % 1 >= 0.85 ? 1 : newLoc.getY() % 1 >= 0.35 ? .5 : 0); double newY = newLoc.getBlockY() + (newLoc.getY() % 1 >= 0.85 ? 1 : newLoc.getY() % 1 >= 0.35 ? .5 : 0);
boolean sameBlock = origLoc.getBlockX() == newLoc.getBlockX() && newY == origY && boolean sameBlock =
origLoc.getBlockZ() == newLoc.getBlockZ(); loc.getBlockX() == newLoc.getBlockX() && newY == origY && loc.getBlockZ() == newLoc.getBlockZ();
if (sameBlock) { if (sameBlock) {
// Make no modifications but don't send anything // Make no modifications but don't send anything
return; return;
} else { } else {
shorts.write(0, conRel(origLoc.getBlockX(), newLoc.getBlockX())); shorts.write(0, conRel(loc.getBlockX(), newLoc.getBlockX()));
shorts.write(1, conRel(origY, newY)); shorts.write(1, conRel(origY, newY));
shorts.write(2, conRel(origLoc.getBlockZ(), newLoc.getBlockZ())); shorts.write(2, conRel(loc.getBlockZ(), newLoc.getBlockZ()));
} }
} }
@ -186,7 +185,6 @@ public class PacketHandlerMovement implements IPacketHandler {
pitchValue = DisguiseUtilities.getPitch(disguise.getType(), pitchValue); pitchValue = DisguiseUtilities.getPitch(disguise.getType(), pitchValue);
} else { } else {
pitchValue = DisguiseUtilities.getPitch(disguise.getType(), entity.getType(), pitchValue); pitchValue = DisguiseUtilities.getPitch(disguise.getType(), entity.getType(), pitchValue);
} }
if (yawLock != null) { if (yawLock != null) {
@ -242,6 +240,21 @@ public class PacketHandlerMovement implements IPacketHandler {
movePacket.getBooleans().write(0, false); movePacket.getBooleans().write(0, false);
} }
if (yMod != 0 && sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT) {
PacketContainer packet = packets.getPackets().get(0);
if (packet == sentPacket) {
packet = packet.shallowClone();
packets.clear();
packets.addPacket(packet);
}
StructureModifier<Double> doubles = packet.getDoubles();
doubles.write(1, doubles.read(1) + yMod);
}
} }
} }
} }

View File

@ -103,7 +103,8 @@ public class PacketHandlerSpawn implements IPacketHandler {
} }
} }
Location loc = disguisedEntity.getLocation().clone().add(0, DisguiseUtilities.getYModifier(disguise), 0); Location loc = disguisedEntity.getLocation().clone()
.add(0, DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier(), 0);
Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null; Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null;
Float yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null; Float yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null;
@ -350,9 +351,12 @@ public class PacketHandlerSpawn implements IPacketHandler {
} }
if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) { if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
double yMod = disguise.getWatcher().getYModifier();
y -= yMod;
// Center the block // Center the block
x = loc.getBlockX() + 0.5; x = loc.getBlockX() + 0.5;
y = loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0); y = Math.floor(y) + yMod + (y % 1 >= 0.85 ? 1 : y % 1 >= 0.35 ? .5 : 0);
z = loc.getBlockZ() + 0.5; z = loc.getBlockZ() + 0.5;
} }
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) { } else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) {

View File

@ -5,6 +5,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
import org.bukkit.entity.Animals; import org.bukkit.entity.Animals;
import org.bukkit.entity.Monster; import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
@ -44,7 +45,7 @@ public class DisguisePermissions {
private boolean wildcardCommand; private boolean wildcardCommand;
public ParsedPermission(DisguisePerm[] disguisePerm, HashMap<String, Boolean> options, byte inheritance, public ParsedPermission(DisguisePerm[] disguisePerm, HashMap<String, Boolean> options, byte inheritance,
boolean wildcardCommand) { boolean wildcardCommand) {
this.disguisePerm = new Vector<>(Arrays.asList(disguisePerm)); this.disguisePerm = new Vector<>(Arrays.asList(disguisePerm));
this.options = options; this.options = options;
this.inheritance = inheritance; this.inheritance = inheritance;
@ -381,6 +382,11 @@ public class DisguisePermissions {
storage.negatedOptions.add("setinvisible"); storage.negatedOptions.add("setinvisible");
} }
if (sender instanceof Player && !sender.isOp()) {
storage.permittedOptions.remove("setYModifier");
storage.negatedOptions.add("setYModifier");
}
disguises.add(storage); disguises.add(storage);
} }
} }
@ -474,7 +480,8 @@ public class DisguisePermissions {
} }
// If the user is using a forbidden option, return false. Otherwise true // If the user is using a forbidden option, return false. Otherwise true
return disguiseOptions.stream().noneMatch(option -> storage.negatedOptions.contains(option.toLowerCase(Locale.ENGLISH))); return disguiseOptions.stream()
.noneMatch(option -> storage.negatedOptions.contains(option.toLowerCase(Locale.ENGLISH)));
} }
public boolean isAllowedDisguise(DisguisePerm disguisePerm) { public boolean isAllowedDisguise(DisguisePerm disguisePerm) {

View File

@ -210,7 +210,7 @@ NameAboveHeadAlwaysVisible: true
# Two placeholders can be used. # Two placeholders can be used.
# %simple% = The very basic name, 'libraryaddict' # %simple% = The very basic name, 'libraryaddict'
# %complex% = Name will be grabbed from scoreboard or display name if scoreboard fails. # %complex% = Name will be grabbed from scoreboard or display name if scoreboard fails.
NameAboveDisguise: %complex% NameAboveDisguise: '%complex%'
# This modifies the bounding box, This is stuff like can a arrow hit them. # This modifies the bounding box, This is stuff like can a arrow hit them.
# If you turn this to true, arrows will act like they hit the disguise in the right place! # If you turn this to true, arrows will act like they hit the disguise in the right place!