Add y modifier to disguises
This commit is contained in:
parent
1795e03e31
commit
6505d7530f
@ -62,6 +62,8 @@ public class FlagWatcher {
|
||||
private Float pitchLock;
|
||||
@Getter
|
||||
private Float yawLock;
|
||||
@Getter
|
||||
private float yModifier;
|
||||
|
||||
public FlagWatcher(Disguise disguise) {
|
||||
this.disguise = (TargetedDisguise) disguise;
|
||||
@ -80,11 +82,41 @@ public class FlagWatcher {
|
||||
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() {
|
||||
return yawLock != null;
|
||||
}
|
||||
|
||||
public void setYawLocked(boolean yawLocked) {
|
||||
if (!DisguiseConfig.isMovementPacketsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isYawLocked() == yawLocked) {
|
||||
return;
|
||||
}
|
||||
@ -93,6 +125,10 @@ public class FlagWatcher {
|
||||
}
|
||||
|
||||
public void setPitchLock(Float pitch) {
|
||||
if (!DisguiseConfig.isMovementPacketsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pitchLock = pitch;
|
||||
|
||||
if (!getDisguise().isDisguiseInUse()) {
|
||||
|
@ -2311,8 +2311,6 @@ public class DisguiseUtilities {
|
||||
}
|
||||
}
|
||||
|
||||
Location loc = player.getLocation();
|
||||
|
||||
// Resend any active potion effects
|
||||
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
|
||||
Object mobEffect = ReflectionManager.createMobEffect(potionEffect);
|
||||
@ -2939,7 +2937,7 @@ public class DisguiseUtilities {
|
||||
Location loc = disguise.getEntity().getLocation();
|
||||
|
||||
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());
|
||||
packets.add(packet);
|
||||
|
||||
|
@ -235,7 +235,7 @@ public class PlayerSkinHandler implements Listener {
|
||||
PacketContainer teleport = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
|
||||
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 yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null;
|
||||
|
@ -81,6 +81,8 @@ public class PacketHandlerMovement implements IPacketHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
double yMod = disguise.getWatcher().getYModifier();
|
||||
|
||||
// If falling block should be appearing in center of blocks
|
||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK &&
|
||||
((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
|
||||
@ -91,11 +93,10 @@ public class PacketHandlerMovement implements IPacketHandler {
|
||||
}
|
||||
|
||||
PacketContainer movePacket = sentPacket.shallowClone();
|
||||
Location loc = entity.getLocation();
|
||||
|
||||
// If not relational movement
|
||||
if (movePacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT) {
|
||||
Location loc = entity.getLocation();
|
||||
|
||||
StructureModifier<Double> doubles = movePacket.getDoubles();
|
||||
// Center the block
|
||||
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);
|
||||
|
||||
doubles.write(1, y);
|
||||
doubles.write(1, y + yMod);
|
||||
doubles.write(2, loc.getBlockZ() + 0.5);
|
||||
} else {
|
||||
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);
|
||||
Location newLoc = origLoc.clone().subtract(diff);
|
||||
Location newLoc = loc.clone().subtract(diff);
|
||||
|
||||
double origY =
|
||||
origLoc.getBlockY() + (origLoc.getY() % 1 >= 0.85 ? 1 : origLoc.getY() % 1 >= 0.35 ? .5 : 0);
|
||||
double origY = loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.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 &&
|
||||
origLoc.getBlockZ() == newLoc.getBlockZ();
|
||||
boolean sameBlock =
|
||||
loc.getBlockX() == newLoc.getBlockX() && newY == origY && loc.getBlockZ() == newLoc.getBlockZ();
|
||||
|
||||
if (sameBlock) {
|
||||
// Make no modifications but don't send anything
|
||||
return;
|
||||
} 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(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);
|
||||
} else {
|
||||
pitchValue = DisguiseUtilities.getPitch(disguise.getType(), entity.getType(), pitchValue);
|
||||
|
||||
}
|
||||
|
||||
if (yawLock != null) {
|
||||
@ -242,6 +240,21 @@ public class PacketHandlerMovement implements IPacketHandler {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null;
|
||||
@ -350,9 +351,12 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
}
|
||||
|
||||
if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
|
||||
double yMod = disguise.getWatcher().getYModifier();
|
||||
y -= yMod;
|
||||
|
||||
// Center the block
|
||||
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;
|
||||
}
|
||||
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) {
|
||||
|
@ -5,6 +5,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
@ -44,7 +45,7 @@ public class DisguisePermissions {
|
||||
private boolean wildcardCommand;
|
||||
|
||||
public ParsedPermission(DisguisePerm[] disguisePerm, HashMap<String, Boolean> options, byte inheritance,
|
||||
boolean wildcardCommand) {
|
||||
boolean wildcardCommand) {
|
||||
this.disguisePerm = new Vector<>(Arrays.asList(disguisePerm));
|
||||
this.options = options;
|
||||
this.inheritance = inheritance;
|
||||
@ -381,6 +382,11 @@ public class DisguisePermissions {
|
||||
storage.negatedOptions.add("setinvisible");
|
||||
}
|
||||
|
||||
if (sender instanceof Player && !sender.isOp()) {
|
||||
storage.permittedOptions.remove("setYModifier");
|
||||
storage.negatedOptions.add("setYModifier");
|
||||
}
|
||||
|
||||
disguises.add(storage);
|
||||
}
|
||||
}
|
||||
@ -474,7 +480,8 @@ public class DisguisePermissions {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
@ -210,7 +210,7 @@ NameAboveHeadAlwaysVisible: true
|
||||
# Two placeholders can be used.
|
||||
# %simple% = The very basic name, 'libraryaddict'
|
||||
# %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.
|
||||
# If you turn this to true, arrows will act like they hit the disguise in the right place!
|
||||
|
Loading…
Reference in New Issue
Block a user