make bukkit warning less obnoxious

This commit is contained in:
dfsek committed 2022-05-05 15:25:53 -07:00
1 parent d2c5f711ef
commit 977316c57f
1 file changed
+12 -3
@@ -6,6 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.dfsek.terra.api.block.entity.BlockEntity; import com.dfsek.terra.api.block.entity.BlockEntity;
@@ -29,6 +30,8 @@ public class BukkitProtoWorld implements ProtoWorld {
private final LimitedRegion delegate; private final LimitedRegion delegate;
private final BlockState air; private final BlockState air;
private static final AtomicBoolean warn = new AtomicBoolean(true);
public BukkitProtoWorld(LimitedRegion delegate, BlockState air) { public BukkitProtoWorld(LimitedRegion delegate, BlockState air) {
this.delegate = delegate; this.delegate = delegate;
this.air = air; this.air = air;
@@ -114,19 +117,25 @@ public class BukkitProtoWorld implements ProtoWorld {
private <T> Optional<T> access(int x, int y, int z, Supplier<T> action) { private <T> Optional<T> access(int x, int y, int z, Supplier<T> action) {
if(delegate.isInRegion(x, y, z)) { if(delegate.isInRegion(x, y, z)) {
return Optional.of(action.get()); 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, LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
delegate.getCenterChunkX(), delegate.getCenterChunkZ()); 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) { private void access(int x, int y, int z, Runnable action) {
if(delegate.isInRegion(x, y, z)) { if(delegate.isInRegion(x, y, z)) {
action.run(); action.run();
} else { } else if(warn.getAndSet(false)) {
LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z, LOGGER.warn("Detected world access at coordinates out of bounds: ({}, {}, {}) accessed for region [{}, {}]", x, y, z,
delegate.getCenterChunkX(), delegate.getCenterChunkZ()); 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());
} }
} }
} }