From 977316c57fb1588ee4c53d45ffb5352f0df79421 Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 5 May 2022 15:25:53 -0700 Subject: [PATCH] make bukkit warning less obnoxious --- .../terra/bukkit/world/BukkitProtoWorld.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitProtoWorld.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitProtoWorld.java index 1b2dbd880..6a81bdb7c 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitProtoWorld.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitProtoWorld.java @@ -6,6 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; import com.dfsek.terra.api.block.entity.BlockEntity; @@ -29,6 +30,8 @@ public class BukkitProtoWorld implements ProtoWorld { private final LimitedRegion delegate; private final BlockState air; + private static final AtomicBoolean warn = new AtomicBoolean(true); + public BukkitProtoWorld(LimitedRegion delegate, BlockState air) { this.delegate = delegate; this.air = air; @@ -114,19 +117,25 @@ public class BukkitProtoWorld implements ProtoWorld { private Optional access(int x, int y, int z, Supplier action) { if(delegate.isInRegion(x, y, z)) { return Optional.of(action.get()); - } else { + } else if(warn.getAndSet(false)) { LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z, delegate.getCenterChunkX(), delegate.getCenterChunkZ()); - return Optional.empty(); + } else { + LOGGER.debug("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z, + delegate.getCenterChunkX(), delegate.getCenterChunkZ()); } + return Optional.empty(); } private void access(int x, int y, int z, Runnable action) { if(delegate.isInRegion(x, y, z)) { action.run(); - } else { + } else if(warn.getAndSet(false)) { LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z, delegate.getCenterChunkX(), delegate.getCenterChunkZ()); + } else { + LOGGER.debug("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z, + delegate.getCenterChunkX(), delegate.getCenterChunkZ()); } } }