Fix falling block grid lock not working on 1.12 and 1.13, fixes #605
This commit is contained in:
parent
46b4b21feb
commit
aa709c791d
@ -12,6 +12,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|||||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||||
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
|
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
|
||||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||||
|
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||||
import org.apache.commons.lang.math.RandomUtils;
|
import org.apache.commons.lang.math.RandomUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.AbstractHorse;
|
import org.bukkit.entity.AbstractHorse;
|
||||||
@ -26,13 +27,12 @@ import java.util.ArrayList;
|
|||||||
* Created by libraryaddict on 3/01/2019.
|
* Created by libraryaddict on 3/01/2019.
|
||||||
*/
|
*/
|
||||||
public class PacketHandlerMovement implements IPacketHandler {
|
public class PacketHandlerMovement implements IPacketHandler {
|
||||||
private final boolean invalid =
|
private final boolean invalid = LibsPremium.getUserID().matches("[0-9]+") && Integer.parseInt(LibsPremium.getUserID()) < 2;
|
||||||
LibsPremium.getUserID().matches("[0-9]+") && Integer.parseInt(LibsPremium.getUserID()) < 2;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PacketType[] getHandledPackets() {
|
public PacketType[] getHandledPackets() {
|
||||||
return new PacketType[]{PacketType.Play.Server.REL_ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_LOOK,
|
return new PacketType[]{PacketType.Play.Server.REL_ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_LOOK, PacketType.Play.Server.ENTITY_TELEPORT,
|
||||||
PacketType.Play.Server.ENTITY_TELEPORT, PacketType.Play.Server.REL_ENTITY_MOVE};
|
PacketType.Play.Server.REL_ENTITY_MOVE};
|
||||||
}
|
}
|
||||||
|
|
||||||
private short conRel(double oldCord, double newCord) {
|
private short conRel(double oldCord, double newCord) {
|
||||||
@ -40,8 +40,7 @@ public class PacketHandlerMovement 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) {
|
|
||||||
handle2(disguise, sentPacket, packets, observer, entity);
|
handle2(disguise, sentPacket, packets, observer, entity);
|
||||||
|
|
||||||
int len = disguise.getMultiNameLength();
|
int len = disguise.getMultiNameLength();
|
||||||
@ -74,8 +73,7 @@ public class PacketHandlerMovement implements IPacketHandler {
|
|||||||
packets.getPackets().addAll(toAdd);
|
packets.getPackets().addAll(toAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handle2(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
public void handle2(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) {
|
||||||
Entity entity) {
|
|
||||||
if (invalid && RandomUtils.nextDouble() < 0.1) {
|
if (invalid && RandomUtils.nextDouble() < 0.1) {
|
||||||
packets.clear();
|
packets.clear();
|
||||||
return;
|
return;
|
||||||
@ -84,8 +82,7 @@ public class PacketHandlerMovement implements IPacketHandler {
|
|||||||
double yMod = DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier();
|
double yMod = DisguiseUtilities.getYModifier(disguise) + 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()) {
|
|
||||||
packets.clear();
|
packets.clear();
|
||||||
|
|
||||||
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK) {
|
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK) {
|
||||||
@ -108,32 +105,60 @@ public class PacketHandlerMovement implements IPacketHandler {
|
|||||||
doubles.write(1, y + yMod);
|
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();
|
int x;
|
||||||
|
int y;
|
||||||
|
int z;
|
||||||
|
|
||||||
Vector diff = new Vector(shorts.read(0) / 4096D, shorts.read(1) / 4096D, shorts.read(2) / 4096D);
|
if (NmsVersion.v1_14.isSupported()) {
|
||||||
|
StructureModifier<Short> shorts = movePacket.getShorts();
|
||||||
|
|
||||||
|
x = shorts.read(0);
|
||||||
|
y = shorts.read(1);
|
||||||
|
z = shorts.read(2);
|
||||||
|
} else {
|
||||||
|
StructureModifier<Integer> ints = movePacket.getIntegers();
|
||||||
|
|
||||||
|
x = ints.read(0);
|
||||||
|
y = ints.read(1);
|
||||||
|
z = ints.read(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector diff = new Vector(x / 4096D, y / 4096D, z / 4096D);
|
||||||
Location newLoc = loc.clone().subtract(diff);
|
Location newLoc = loc.clone().subtract(diff);
|
||||||
|
|
||||||
double origY = loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.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);
|
double newY = newLoc.getBlockY() + (newLoc.getY() % 1 >= 0.85 ? 1 : newLoc.getY() % 1 >= 0.35 ? .5 : 0);
|
||||||
|
|
||||||
boolean sameBlock =
|
boolean sameBlock = loc.getBlockX() == newLoc.getBlockX() && newY == origY && loc.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(loc.getBlockX(), newLoc.getBlockX()));
|
x = conRel(loc.getBlockX(), newLoc.getBlockX());
|
||||||
shorts.write(1, conRel(origY, newY));
|
y = conRel(origY, newY);
|
||||||
shorts.write(2, conRel(loc.getBlockZ(), newLoc.getBlockZ()));
|
z = conRel(loc.getBlockZ(), newLoc.getBlockZ());
|
||||||
|
|
||||||
|
if (NmsVersion.v1_14.isSupported()) {
|
||||||
|
StructureModifier<Short> shorts = movePacket.getShorts();
|
||||||
|
|
||||||
|
shorts.write(0, (short) x);
|
||||||
|
shorts.write(1, (short) y);
|
||||||
|
shorts.write(2, (short) z);
|
||||||
|
} else {
|
||||||
|
StructureModifier<Integer> ints = movePacket.getIntegers();
|
||||||
|
|
||||||
|
ints.write(0, x);
|
||||||
|
ints.write(1, y);
|
||||||
|
ints.write(2, z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
packets.addPacket(movePacket);
|
packets.addPacket(movePacket);
|
||||||
return;
|
return;
|
||||||
} 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)) {
|
|
||||||
// When did the rabbit disguise last hop
|
// When did the rabbit disguise last hop
|
||||||
long lastHop = 999999;
|
long lastHop = 999999;
|
||||||
|
|
||||||
@ -148,8 +173,7 @@ public class PacketHandlerMovement implements IPacketHandler {
|
|||||||
if (lastHop < 100 || lastHop > 500) {
|
if (lastHop < 100 || lastHop > 500) {
|
||||||
if (lastHop > 500) {
|
if (lastHop > 500) {
|
||||||
entity.removeMetadata("LibsRabbitHop", LibsDisguises.getInstance());
|
entity.removeMetadata("LibsRabbitHop", LibsDisguises.getInstance());
|
||||||
entity.setMetadata("LibsRabbitHop",
|
entity.setMetadata("LibsRabbitHop", new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis()));
|
||||||
new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketContainer statusPacket = new PacketContainer(PacketType.Play.Server.ENTITY_STATUS);
|
PacketContainer statusPacket = new PacketContainer(PacketType.Play.Server.ENTITY_STATUS);
|
||||||
@ -160,8 +184,7 @@ public class PacketHandlerMovement implements IPacketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
} else {
|
} else {
|
||||||
@ -197,8 +220,7 @@ public class PacketHandlerMovement implements IPacketHandler {
|
|||||||
bytes.write(0, yawValue);
|
bytes.write(0, yawValue);
|
||||||
bytes.write(1, pitchValue);
|
bytes.write(1, pitchValue);
|
||||||
|
|
||||||
if (entity == observer.getVehicle() &&
|
if (entity == observer.getVehicle() && AbstractHorse.class.isAssignableFrom(disguise.getType().getEntityClass())) {
|
||||||
AbstractHorse.class.isAssignableFrom(disguise.getType().getEntityClass())) {
|
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||||
|
|
||||||
packet.getIntegers().write(0, DisguiseAPI.getEntityAttachmentId());
|
packet.getIntegers().write(0, DisguiseAPI.getEntityAttachmentId());
|
||||||
@ -206,8 +228,7 @@ public class PacketHandlerMovement implements IPacketHandler {
|
|||||||
packet.getBytes().write(1, pitchValue);
|
packet.getBytes().write(1, pitchValue);
|
||||||
|
|
||||||
packets.addPacket(packet);
|
packets.addPacket(packet);
|
||||||
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT &&
|
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) {
|
||||||
disguise.getType() == DisguiseType.ITEM_FRAME) {
|
|
||||||
StructureModifier<Double> doubles = movePacket.getDoubles();
|
StructureModifier<Double> doubles = movePacket.getDoubles();
|
||||||
|
|
||||||
Location loc = entity.getLocation();
|
Location loc = entity.getLocation();
|
||||||
|
Loading…
Reference in New Issue
Block a user