use of cn.nukkit.event.server.DataPacketSendEvent in project Nukkit by Nukkit.
the class Player method batchDataPacket.
public boolean batchDataPacket(DataPacket packet) {
if (!this.connected) {
return false;
}
try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
DataPacketSendEvent event = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
timing.stopTiming();
return false;
}
if (!this.batchedPackets.containsKey(packet.getChannel())) {
this.batchedPackets.put(packet.getChannel(), new ArrayList<>());
}
this.batchedPackets.get(packet.getChannel()).add(packet.clone());
}
return true;
}
use of cn.nukkit.event.server.DataPacketSendEvent in project Nukkit by Nukkit.
the class Player method directDataPacket.
public int directDataPacket(DataPacket packet, boolean needACK) {
if (!this.connected) {
return -1;
}
try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
timing.stopTiming();
return -1;
}
Integer identifier = this.interfaz.putPacket(this, packet, needACK, true);
if (needACK && identifier != null) {
this.needACK.put(identifier, Boolean.FALSE);
timing.stopTiming();
return identifier;
}
}
return 0;
}
use of cn.nukkit.event.server.DataPacketSendEvent in project Nukkit by Nukkit.
the class Player method dataPacket.
public int dataPacket(DataPacket packet, boolean needACK) {
if (!this.connected) {
return -1;
}
try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
timing.stopTiming();
return -1;
}
Integer identifier = this.interfaz.putPacket(this, packet, needACK, false);
if (needACK && identifier != null) {
this.needACK.put(identifier, Boolean.FALSE);
timing.stopTiming();
return identifier;
}
}
return 0;
}
Aggregations