make bukkit warning less obnoxious

This commit is contained in:
dfsek
2022-05-05 15:25:53 -07:00
parent d2c5f711ef
commit 977316c57f

View File

@@ -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 <T> Optional<T> access(int x, int y, int z, Supplier<T> 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());
}
}
}