Skip to content

Commit

Permalink
improve logging and fix condition
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 4, 2024
1 parent 6b8f4bf commit 97975e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,24 @@ public void disable() {
}

@Override
@SuppressWarnings("DataFlowIssue")
public void onPacketSend(PacketSendEvent event) {
if (event.isCancelled() && !measuredPacketTypes.contains(event.getPacketType())) return;
if (event.isCancelled() || !measuredPacketTypes.contains(event.getPacketType())) return;

PlayerData data = playerDataCache.get(event.getUser().getUUID(), PlayerData::new);

if (data.cooldownResumeTime.get() > System.currentTimeMillis()) {
event.setCancelled(true);
return;
}

long servedBytes = data.servedSetSlotBytes.addAndGet(ByteBufHelper.readableBytes(event.getByteBuf()));
if (log) info("Player '" + event.getUser().getName() + "' requested " + servedBytes + " bytes in ItemStacks.");
if (log) info("Player '" + event.getUser().getName() + "' requested " + servedBytes + " bytes in ItemStacks. " +
"(PacketType: " + event.getPacketType() + ")");

if (servedBytes <= lockoutBytes) {
return;
}

if (data.cooldownResumeTime.get() > System.currentTimeMillis()) {
event.setCancelled(true);
return;
}

data.cooldownResumeTime.set(System.currentTimeMillis() + lockoutMillis);

if (log) warn("Player '" + event.getUser().getName() + "' is now on LOCKOUT as they exceeded" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,23 @@ public void disable() {

@Override
public void onPacketSend(PacketSendEvent event) {
if (event.isCancelled() && !measuredPacketTypes.contains(event.getPacketType())) return;
if (event.isCancelled() || !measuredPacketTypes.contains(event.getPacketType())) return;

PlayerData data = playerDataCache.get(event.getUser().getUUID(), PlayerData::new);

if (data.cooldownResumeTime.get() > System.currentTimeMillis()) {
event.setCancelled(true);
return;
}

long servedBytes = data.servedSetSlotBytes.addAndGet(ByteBufHelper.readableBytes(event.getByteBuf()));
if (log) info("Player '" + event.getUser().getName() + "' requested " + servedBytes + " bytes in ItemStacks.");
if (log) info("Player '" + event.getUser().getName() + "' requested " + servedBytes + " bytes in ItemStacks. " +
"(PacketType: " + event.getPacketType() + ")");

if (servedBytes <= lockoutBytes) {
return;
}

if (data.cooldownResumeTime.get() > System.currentTimeMillis()) {
event.setCancelled(true);
return;
}

data.cooldownResumeTime.set(System.currentTimeMillis() + lockoutMillis);

if (log) warn("Player '" + event.getUser().getName() + "' is now on LOCKOUT as they exceeded" +
Expand Down

0 comments on commit 97975e4

Please sign in to comment.