Register client interact async, use unsafe disguise from entity id for main listener

This commit is contained in:
libraryaddict 2019-06-24 17:20:56 +12:00
parent a46178b04c
commit 5e1ed00434
2 changed files with 6 additions and 10 deletions

View File

@ -35,8 +35,7 @@ public class PacketsManager {
clientInteractEntityListener = new PacketListenerClientInteract(libsDisguises);
PacketListener tabListListener = new PacketListenerTabList(libsDisguises);
ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(clientInteractEntityListener)
.syncStart();
ProtocolLibrary.getProtocolManager().addPacketListener(clientInteractEntityListener);
ProtocolLibrary.getProtocolManager().addPacketListener(tabListListener);
// Now I call this and the main listener is registered!

View File

@ -40,23 +40,20 @@ public class PacketListenerMain extends PacketAdapter {
int entityId = event.getPacket().getIntegers().read(Server.COLLECT == event.getPacketType() ? 1 : 0);
Entity entity = DisguiseUtilities.getEntity(observer.getWorld(), entityId);
final Disguise disguise = DisguiseUtilities.getDisguise(observer, entityId);
// If the entity is the same as the sender. Don't disguise!
// Prevents problems and there is no advantage to be gained.
// Or if they are null and there's no disguise
if (entity == observer || entity == null)
return;
final Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise == null)
if (disguise == null || disguise.getEntity() == observer) {
return;
}
LibsPackets packets;
try {
packets = PacketsManager.getPacketsHandler().transformPacket(event.getPacket(), disguise, observer, entity);
packets = PacketsManager.getPacketsHandler()
.transformPacket(event.getPacket(), disguise, observer, disguise.getEntity());
}
catch (Exception ex) {
ex.printStackTrace();