Fix error for self disguises refreshing or something

This commit is contained in:
libraryaddict 2020-08-31 10:02:50 +12:00
parent 4f0be27f0a
commit 6e4ceb37a9

View file

@ -34,8 +34,9 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
@Override @Override
public void onPacketSending(final PacketEvent event) { public void onPacketSending(final PacketEvent event) {
if (event.isCancelled()) if (event.isCancelled()) {
return; return;
}
try { try {
final Player observer = event.getPlayer(); final Player observer = event.getPlayer();
@ -70,15 +71,15 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
} }
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them. // Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
LibsPackets transformed = PacketsManager.getPacketsHandler() LibsPackets transformed =
.transformPacket(packet, disguise, observer, observer); PacketsManager.getPacketsHandler().transformPacket(packet, disguise, observer, observer);
if (transformed.isUnhandled()) { if (transformed.isUnhandled()) {
transformed.getPackets().add(packet); transformed.getPackets().add(packet);
} }
for (PacketContainer newPacket : transformed.getPackets()) { for (PacketContainer newPacket : transformed.getPackets()) {
if (newPacket.getType() != Server.PLAYER_INFO && if (newPacket.getType() != Server.PLAYER_INFO && newPacket.getType() != Server.ENTITY_DESTROY &&
newPacket.getIntegers().read(0) == observer.getEntityId()) { newPacket.getIntegers().read(0) == observer.getEntityId()) {
if (newPacket == packet) { if (newPacket == packet) {
newPacket = newPacket.shallowClone(); newPacket = newPacket.shallowClone();
@ -89,15 +90,14 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
try { try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, newPacket, false); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, newPacket, false);
} } catch (InvocationTargetException e) {
catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
for (ArrayList<PacketContainer> packets : transformed.getDelayedPackets()) { for (ArrayList<PacketContainer> packets : transformed.getDelayedPackets()) {
for (PacketContainer newPacket : packets) { for (PacketContainer newPacket : packets) {
if (newPacket.getType() == Server.PLAYER_INFO) { if (newPacket.getType() == Server.PLAYER_INFO || newPacket.getType() == Server.ENTITY_DESTROY) {
continue; continue;
} }
@ -139,20 +139,21 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
List<WrappedWatchableObject> watchableList = new ArrayList<>(); List<WrappedWatchableObject> watchableList = new ArrayList<>();
byte b = 1 << 5; byte b = 1 << 5;
if (observer.isSprinting()) if (observer.isSprinting()) {
b = (byte) (b | 1 << 3); b = (byte) (b | 1 << 3);
}
WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.ENTITY_META, b); WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.ENTITY_META, b);
if (watch != null) if (watch != null) {
watchableList.add(watch); watchableList.add(watch);
}
metaPacket.getWatchableCollectionModifier().write(0, watchableList); metaPacket.getWatchableCollectionModifier().write(0, watchableList);
try { try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, metaPacket); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, metaPacket);
} } catch (InvocationTargetException e) {
catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
} else if (event.getPacketType() == Server.ANIMATION) { } else if (event.getPacketType() == Server.ANIMATION) {
@ -179,8 +180,7 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
// Clear old velocity, this should only occur once. // Clear old velocity, this should only occur once.
DisguiseUtilities.setPlayerVelocity(null); DisguiseUtilities.setPlayerVelocity(null);
} }
} } catch (Throwable ex) {
catch (Throwable ex) {
event.setCancelled(true); event.setCancelled(true);
ex.printStackTrace(); ex.printStackTrace();
} }