use of net.minecraft.network.packet.s2c.play.WorldEventS2CPacket in project meteor-rejects by AntiCope.
the class CoordLogger method onPacketReceive.
@EventHandler
private void onPacketReceive(PacketEvent.Receive event) {
// Teleports
if (event.packet instanceof EntityPositionS2CPacket) {
EntityPositionS2CPacket packet = (EntityPositionS2CPacket) event.packet;
try {
Entity entity = mc.world.getEntityById(packet.getId());
// Player teleport
if (entity.getType().equals(EntityType.PLAYER) && players.get()) {
Vec3d packetPosition = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
Vec3d playerPosition = entity.getPos();
if (playerPosition.distanceTo(packetPosition) >= minDistance.get()) {
info(formatMessage("Player '" + entity.getEntityName() + "' has teleported to ", packetPosition));
}
} else // World teleport
if (entity.getType().equals(EntityType.WOLF) && wolves.get()) {
Vec3d packetPosition = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
Vec3d wolfPosition = entity.getPos();
UUID ownerUuid = ((TameableEntity) entity).getOwnerUuid();
if (ownerUuid != null && wolfPosition.distanceTo(packetPosition) >= minDistance.get()) {
info(formatMessage("Wolf has teleported to ", packetPosition));
}
}
} catch (NullPointerException ignored) {
}
// World events
} else if (event.packet instanceof WorldEventS2CPacket) {
WorldEventS2CPacket worldEventS2CPacket = (WorldEventS2CPacket) event.packet;
if (worldEventS2CPacket.isGlobal()) {
// Min distance
if (PlayerUtils.distanceTo(worldEventS2CPacket.getPos()) <= minDistance.get())
return;
switch(worldEventS2CPacket.getEventId()) {
case 1023:
if (withers.get())
info(formatMessage("Wither spawned at ", worldEventS2CPacket.getPos()));
break;
case 1038:
if (endPortals.get())
info(formatMessage("End portal opened at ", worldEventS2CPacket.getPos()));
break;
case 1028:
if (enderDragons.get())
info(formatMessage("Ender dragon killed at ", worldEventS2CPacket.getPos()));
break;
default:
if (otherEvents.get())
info(formatMessage("Unknown global event at ", worldEventS2CPacket.getPos()));
}
}
}
}
Aggregations