Make utility classes final and not constructable.

This commit is contained in:
Articdive 2020-08-07 08:10:10 +02:00
parent b7a720ee2d
commit d5b8ead337
No known key found for this signature in database
GPG Key ID: B069585F0F7D90DE
16 changed files with 77 additions and 24 deletions

View File

@ -4,7 +4,11 @@ import it.unimi.dsi.fastutil.ints.IntList;
import java.util.function.Supplier;
public class ArrayUtils {
public final class ArrayUtils {
private ArrayUtils() {
}
public static byte[] concenateByteArrays(byte[]... arrays) {
int totalLength = 0;

View File

@ -1,6 +1,10 @@
package net.minestom.server.utils;
public class MathUtils {
public final class MathUtils {
private MathUtils() {
}
public static int square(int num) {
return num * num;
@ -66,5 +70,4 @@ public class MathUtils {
public static float setBetween(float number, float min, float max) {
return number > max ? max : number < min ? min : number;
}
}

View File

@ -26,10 +26,14 @@ import java.util.Map;
import java.util.UUID;
// for lack of a better name
public class NBTUtils {
public final class NBTUtils {
private final static Logger LOGGER = LoggerFactory.getLogger(NBTUtils.class);
private NBTUtils() {
}
/**
* Loads all the items from the 'items' list into the given inventory
*

View File

@ -5,7 +5,11 @@ import io.netty.buffer.Unpooled;
import net.minestom.server.network.packet.PacketWriter;
import net.minestom.server.network.packet.server.ServerPacket;
public class PacketUtils {
public final class PacketUtils {
private PacketUtils() {
}
public static void writePacket(ByteBuf buf, ServerPacket packet) {
PacketWriter writer = new PacketWriter();

View File

@ -1,6 +1,10 @@
package net.minestom.server.utils;
public class SerializerUtils {
public final class SerializerUtils {
private SerializerUtils() {
}
public static long positionToLong(int x, int y, int z) {
return (((long) x & 0x3FFFFFF) << 38) | (((long) z & 0x3FFFFFF) << 12) | ((long) y & 0xFFF);

View File

@ -5,7 +5,11 @@ import net.minestom.server.instance.Chunk;
import net.minestom.server.network.packet.PacketWriter;
import net.minestom.server.utils.buffer.BufferWrapper;
public class Utils {
public final class Utils {
private Utils() {
}
public static int getVarIntSize(int input) {
return (input & 0xFFFFFF80) == 0

View File

@ -2,7 +2,11 @@ package net.minestom.server.utils.advancement;
import net.minestom.server.network.packet.server.play.AdvancementsPacket;
public class AdvancementUtils {
public final class AdvancementUtils {
private AdvancementUtils() {
}
/**
* Get an {@link AdvancementsPacket} which remove the specified identifiers
@ -19,5 +23,4 @@ public class AdvancementUtils {
return advancementsPacket;
}
}

View File

@ -4,9 +4,13 @@ import com.github.pbbl.heap.ByteBufferPool;
import java.nio.ByteBuffer;
public class BufferUtils {
public final class BufferUtils {
private static ByteBufferPool pool = new ByteBufferPool();
private static final ByteBufferPool pool = new ByteBufferPool();
private BufferUtils() {
}
public static BufferWrapper getBuffer(int size) {
return new BufferWrapper(pool.take(size));
@ -15,5 +19,4 @@ public class BufferUtils {
protected static void giveBuffer(ByteBuffer byteBuffer) {
pool.give(byteBuffer);
}
}

View File

@ -6,7 +6,7 @@ import java.nio.ByteBuffer;
public class BufferWrapper {
private ByteBuffer byteBuffer;
private final ByteBuffer byteBuffer;
private int size;
protected BufferWrapper(ByteBuffer byteBuffer) {

View File

@ -6,7 +6,11 @@ import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.Position;
public class ChunkUtils {
public final class ChunkUtils {
private ChunkUtils() {
}
/**
* @param chunk the chunk to check
@ -136,5 +140,4 @@ public class ChunkUtils {
public static int[] indexToChunkPosition(int index) {
return indexToPosition(index, 0, 0);
}
}

View File

@ -9,7 +9,11 @@ import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.Position;
import net.minestom.server.utils.chunk.ChunkUtils;
public class EntityUtils {
public final class EntityUtils {
private EntityUtils() {
}
public static boolean areVisible(Entity ent1, Entity ent2) {
if (ent1.getInstance() == null || ent2.getInstance() == null)

View File

@ -1,6 +1,6 @@
package net.minestom.server.utils.inventory;
public class PlayerInventoryUtils {
public final class PlayerInventoryUtils {
public static final int OFFSET = 9;
@ -16,6 +16,10 @@ public class PlayerInventoryUtils {
public static final int BOOTS_SLOT = 44;
public static final int OFFHAND_SLOT = 45;
private PlayerInventoryUtils() {
}
/**
* Convert a packet slot to an internal one
*

View File

@ -2,7 +2,11 @@ package net.minestom.server.utils.item;
import net.minestom.server.item.ItemStack;
public class ItemStackUtils {
public final class ItemStackUtils {
private ItemStackUtils() {
}
/**
* Ensure that the returned ItemStack won't be null
@ -24,5 +28,4 @@ public class ItemStackUtils {
public static boolean isVisible(ItemStack itemStack) {
return itemStack != null && !itemStack.isAir();
}
}

View File

@ -5,7 +5,11 @@ import net.minestom.server.entity.Player;
import net.minestom.server.network.player.NettyPlayerConnection;
import net.minestom.server.network.player.PlayerConnection;
public class PlayerUtils {
public final class PlayerUtils {
private PlayerUtils() {
}
public static boolean isNettyClient(PlayerConnection playerConnection) {
return playerConnection instanceof NettyPlayerConnection;

View File

@ -1,6 +1,10 @@
package net.minestom.server.utils.time;
public class CooldownUtils {
public final class CooldownUtils {
private CooldownUtils() {
}
/**
* Get if something is in cooldown based on the current time
@ -39,5 +43,4 @@ public class CooldownUtils {
public static boolean hasCooldown(long lastUpdate, TimeUnit timeUnit, int cooldown) {
return hasCooldown(System.currentTimeMillis(), lastUpdate, timeUnit, cooldown);
}
}

View File

@ -7,7 +7,11 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class URLUtils {
public final class URLUtils {
private URLUtils() {
}
public static String getText(String url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
@ -36,5 +40,4 @@ public class URLUtils {
return response.toString();
}
}