use of com.denizenscript.denizen.objects.PlayerTag in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNetworkManagerImpl method processDisguiseForPacket.
public boolean processDisguiseForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
if (DisguiseCommand.disguises.isEmpty() || antiDuplicate) {
return false;
}
try {
int ider = -1;
if (packet instanceof ClientboundSetEntityDataPacket) {
ider = ((ClientboundSetEntityDataPacket) packet).getId();
}
if (packet instanceof ClientboundUpdateAttributesPacket) {
ider = ((ClientboundUpdateAttributesPacket) packet).getEntityId();
}
if (packet instanceof ClientboundAddPlayerPacket) {
ider = ((ClientboundAddPlayerPacket) packet).getEntityId();
} else if (packet instanceof ClientboundAddEntityPacket) {
ider = ((ClientboundAddEntityPacket) packet).getId();
} else if (packet instanceof ClientboundAddMobPacket) {
ider = ((ClientboundAddMobPacket) packet).getId();
}
if (ider != -1) {
Entity e = player.getLevel().getEntity(ider);
if (e == null) {
return false;
}
HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(e.getUUID());
if (playerMap == null) {
return false;
}
DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUUID());
if (disguise == null) {
disguise = playerMap.get(null);
if (disguise == null) {
return false;
}
}
if (!disguise.isActive) {
return false;
}
if (NMSHandler.debugPackets) {
doPacketOutput("DISGUISED packet " + packet.getClass().getName() + " for entity " + ider + " to player " + player.getScoreboardName());
}
if (packet instanceof ClientboundSetEntityDataPacket) {
ClientboundSetEntityDataPacket metadataPacket = (ClientboundSetEntityDataPacket) packet;
if (e.getId() == player.getId()) {
if (!disguise.shouldFake) {
return false;
}
List<SynchedEntityData.DataItem<?>> data = metadataPacket.getUnpackedData();
for (SynchedEntityData.DataItem item : data) {
EntityDataAccessor<?> watcherObject = item.getAccessor();
int watcherId = watcherObject.getId();
if (watcherId == 0) {
// Entity flags
ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(copyPacket(metadataPacket));
data = new ArrayList<>(data);
ENTITY_METADATA_LIST.set(altPacket, data);
data.remove(item);
byte flags = (byte) item.getValue();
// Invisible flag
flags |= 0x20;
data.add(new SynchedEntityData.DataItem(watcherObject, flags));
ClientboundSetEntityDataPacket updatedPacket = getModifiedMetadataFor(altPacket);
oldManager.send(updatedPacket == null ? altPacket : updatedPacket, genericfuturelistener);
return true;
}
}
} else {
ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(e.getId(), ((CraftEntity) disguise.toOthers.entity.entity).getHandle().getEntityData(), true);
oldManager.send(altPacket, genericfuturelistener);
return true;
}
return false;
}
if (packet instanceof ClientboundUpdateAttributesPacket) {
FakeEntity fake = ider == player.getId() ? disguise.fakeToSelf : disguise.toOthers;
if (fake == null) {
return false;
}
if (fake.entity.entity instanceof LivingEntity) {
return false;
}
// Non-living don't have attributes
return true;
}
antiDuplicate = true;
disguise.sendTo(Collections.singletonList(new PlayerTag(player.getBukkitEntity())));
antiDuplicate = false;
return true;
}
} catch (Throwable ex) {
antiDuplicate = false;
Debug.echoError(ex);
}
return false;
}
Aggregations