use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.
the class RakNetInterface method handleEncapsulated.
@Override
public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) {
if (this.players.containsKey(identifier)) {
DataPacket pk = null;
try {
if (packet.buffer.length > 0) {
if (packet.buffer[0] == PING_DataPacket.ID) {
PING_DataPacket pingPacket = new PING_DataPacket();
pingPacket.buffer = packet.buffer;
pingPacket.decode();
this.networkLatency.put(identifier, (int) pingPacket.pingID);
return;
}
pk = this.getPacket(packet.buffer);
if (pk != null) {
pk.decode();
this.players.get(identifier).handleDataPacket(pk);
}
}
} catch (Exception e) {
this.server.getLogger().logException(e);
if (Nukkit.DEBUG > 1 && pk != null) {
MainLogger logger = this.server.getLogger();
// if (logger != null) {
logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer));
// logger.logException(e);
// }
}
if (this.players.containsKey(identifier)) {
this.handler.blockAddress(this.players.get(identifier).getAddress(), 5);
}
}
}
}
use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.
the class DestroyBlockParticle method encode.
@Override
public DataPacket[] encode() {
LevelEventPacket pk = new LevelEventPacket();
pk.evid = LevelEventPacket.EVENT_PARTICLE_DESTROY;
pk.x = (float) this.x;
pk.y = (float) this.y;
pk.z = (float) this.z;
pk.data = this.data;
return new DataPacket[] { pk };
}
use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.
the class FloatingTextParticle method encode.
@Override
public DataPacket[] encode() {
ArrayList<DataPacket> packets = new ArrayList<>();
if (this.entityId == -1) {
this.entityId = 1095216660480L + ThreadLocalRandom.current().nextLong(0, 0x7fffffffL);
} else {
RemoveEntityPacket pk = new RemoveEntityPacket();
pk.eid = this.entityId;
packets.add(pk);
}
if (!this.invisible) {
AddPlayerPacket pk = new AddPlayerPacket();
pk.uuid = UUID.randomUUID();
pk.username = "";
pk.entityUniqueId = this.entityId;
pk.entityRuntimeId = this.entityId;
pk.x = (float) this.x;
pk.y = (float) (this.y - 0.75);
pk.z = (float) this.z;
pk.speedX = 0;
pk.speedY = 0;
pk.speedZ = 0;
pk.yaw = 0;
pk.pitch = 0;
long flags = ((1L << Entity.DATA_FLAG_CAN_SHOW_NAMETAG) | (1L << Entity.DATA_FLAG_ALWAYS_SHOW_NAMETAG) | (1L << Entity.DATA_FLAG_IMMOBILE));
pk.metadata = new EntityMetadata().putLong(Entity.DATA_FLAGS, flags).putString(Entity.DATA_NAMETAG, this.title + (!this.text.isEmpty() ? "\n" + this.text : "")).putLong(Entity.DATA_LEAD_HOLDER_EID, -1).putFloat(Entity.DATA_SCALE, // zero causes problems on debug builds?
0.01f);
pk.item = Item.get(Item.AIR);
packets.add(pk);
}
return packets.stream().toArray(DataPacket[]::new);
}
use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.
the class MobSpawnParticle method encode.
@Override
public DataPacket[] encode() {
LevelEventPacket packet = new LevelEventPacket();
packet.evid = LevelEventPacket.EVENT_PARTICLE_SPAWN;
packet.x = (float) this.x;
packet.y = (float) this.y;
packet.z = (float) this.z;
packet.data = (this.width & 0xff) + ((this.height & 0xff) << 8);
return new DataPacket[] { packet };
}
use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.
the class PunchBlockParticle method encode.
@Override
public DataPacket[] encode() {
LevelEventPacket pk = new LevelEventPacket();
pk.evid = LevelEventPacket.EVENT_PARTICLE_PUNCH_BLOCK;
pk.x = (float) this.x;
pk.y = (float) this.y;
pk.z = (float) this.z;
pk.data = this.data;
return new DataPacket[] { pk };
}
Aggregations