添加了记录的上限

This commit is contained in:
17146 2024-05-21 17:25:42 +08:00
parent eb2ca0f08d
commit 585033e51f
2 changed files with 4 additions and 0 deletions

View file

@ -13,6 +13,7 @@ import java.util.Queue;
public class KillMessageHandler { public class KillMessageHandler {
public static Queue<PlayerKillRecord> QUEUE = new ArrayDeque<>(); public static Queue<PlayerKillRecord> QUEUE = new ArrayDeque<>();
public static final int MAX_SIZE = 10;
@SubscribeEvent @SubscribeEvent
public static void onClientTick(TickEvent.ClientTickEvent event) { public static void onClientTick(TickEvent.ClientTickEvent event) {

View file

@ -23,6 +23,9 @@ public class ClientPacketHandler {
public static void handlePlayerKillMessage(Player attacker, Entity target, boolean headshot, ResourceKey<DamageType> damageType, Supplier<NetworkEvent.Context> ctx) { public static void handlePlayerKillMessage(Player attacker, Entity target, boolean headshot, ResourceKey<DamageType> damageType, Supplier<NetworkEvent.Context> ctx) {
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) { if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
if (KillMessageHandler.QUEUE.size() >= KillMessageHandler.MAX_SIZE) {
KillMessageHandler.QUEUE.poll();
}
KillMessageHandler.QUEUE.offer(new PlayerKillRecord(attacker, target, attacker.getMainHandItem(), headshot, damageType)); KillMessageHandler.QUEUE.offer(new PlayerKillRecord(attacker, target, attacker.getMainHandItem(), headshot, damageType));
} }
} }