use of de.Keyle.MyPet.api.entity.MyPetBukkitPart in project MyPet by xXKeyleXx.
the class ProtocolLibHook method registerSyncEnderDragonInteractionFix.
private void registerSyncEnderDragonInteractionFix() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(MyPetApi.getPlugin(), PacketType.Play.Client.USE_ENTITY) {
@Override
public void onPacketReceiving(PacketEvent event) {
if ((checkTemporaryPlayers && event.isPlayerTemporary()) || event.isCancelled()) {
return;
}
PacketContainer packet = event.getPacket();
if (packet.getType() == PacketType.Play.Client.USE_ENTITY) {
try {
Entity ent = Bukkit.getServer().getScheduler().callSyncMethod(MyPetApi.getPlugin(), () -> {
int id = packet.getIntegers().read(0);
Entity entity = null;
try {
entity = packet.getEntityModifier(event).readSafely(0);
} catch (RuntimeException ignored) {
}
if (entity == null && event.getPlayer() != null) {
entity = MyPetApi.getPlatformHelper().getEntity(id, event.getPlayer().getWorld());
}
if (entity instanceof MyPetBukkitPart) {
entity = ((MyPetBukkitPart) entity).getPetOwner();
}
return entity;
}).get();
if (ent != null) {
packet.getIntegers().write(0, ent.getEntityId());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
Aggregations