Prevent Check#notNull from concatenating strings unnecessarily

This commit is contained in:
themode 2021-03-26 22:23:41 +01:00
parent ea3f558d8a
commit 66ab1bb53d
2 changed files with 10 additions and 2 deletions

View File

@ -1312,8 +1312,8 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
final Chunk lastChunk = instance.getChunkAt(lastX, lastZ);
final Chunk newChunk = instance.getChunkAt(x, z);
Check.notNull(lastChunk, "The entity " + getEntityId() + " was in an unloaded chunk at " + lastX + ";" + lastZ);
Check.notNull(newChunk, "The entity " + getEntityId() + " tried to move in an unloaded chunk at " + x + ";" + z);
Check.notNull(lastChunk, "The entity {0} was in an unloaded chunk at {1};{2}", getEntityId(), lastX, lastZ);
Check.notNull(newChunk, "The entity {0} tried to move in an unloaded chunk at {1};{2}", getEntityId(), x, z);
if (lastChunk != newChunk) {
instance.UNSAFE_switchEntityChunk(this, lastChunk, newChunk);

View File

@ -4,6 +4,7 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.text.MessageFormat;
import java.util.Objects;
/**
@ -22,6 +23,13 @@ public final class Check {
}
}
@Contract("null, _, _ -> fail")
public static void notNull(@Nullable Object object, @NotNull String reason, Object... arguments) {
if (Objects.isNull(object)) {
throw new NullPointerException(MessageFormat.format(reason, arguments));
}
}
@Contract("true, _ -> fail")
public static void argCondition(boolean condition, @NotNull String reason) {
if (condition) {