From b546a873e3cf3fcf6fe33df1ef9f36c7a048eb60 Mon Sep 17 00:00:00 2001 From: TheMode Date: Fri, 9 Jul 2021 11:23:18 +0200 Subject: [PATCH] Remove unnecessary cast --- .../server/thread/PerChunkThreadProvider.java | 2 +- .../server/thread/PerInstanceThreadProvider.java | 2 +- .../server/thread/SingleThreadProvider.java | 2 +- .../net/minestom/server/thread/ThreadProvider.java | 14 ++------------ 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/minestom/server/thread/PerChunkThreadProvider.java b/src/main/java/net/minestom/server/thread/PerChunkThreadProvider.java index ccd4365b8..aa6836d6a 100644 --- a/src/main/java/net/minestom/server/thread/PerChunkThreadProvider.java +++ b/src/main/java/net/minestom/server/thread/PerChunkThreadProvider.java @@ -17,7 +17,7 @@ public class PerChunkThreadProvider extends ThreadProvider { } @Override - public long findThread(@NotNull Chunk chunk) { + public int findThread(@NotNull Chunk chunk) { return chunk.hashCode(); } diff --git a/src/main/java/net/minestom/server/thread/PerInstanceThreadProvider.java b/src/main/java/net/minestom/server/thread/PerInstanceThreadProvider.java index baba20527..e1f5dbcf2 100644 --- a/src/main/java/net/minestom/server/thread/PerInstanceThreadProvider.java +++ b/src/main/java/net/minestom/server/thread/PerInstanceThreadProvider.java @@ -18,7 +18,7 @@ public class PerInstanceThreadProvider extends ThreadProvider { } @Override - public long findThread(@NotNull Chunk chunk) { + public int findThread(@NotNull Chunk chunk) { return chunk.getInstance().hashCode(); } diff --git a/src/main/java/net/minestom/server/thread/SingleThreadProvider.java b/src/main/java/net/minestom/server/thread/SingleThreadProvider.java index 34fa99b98..40b584a07 100644 --- a/src/main/java/net/minestom/server/thread/SingleThreadProvider.java +++ b/src/main/java/net/minestom/server/thread/SingleThreadProvider.java @@ -13,7 +13,7 @@ public class SingleThreadProvider extends ThreadProvider { } @Override - public long findThread(@NotNull Chunk chunk) { + public int findThread(@NotNull Chunk chunk) { return 0; } diff --git a/src/main/java/net/minestom/server/thread/ThreadProvider.java b/src/main/java/net/minestom/server/thread/ThreadProvider.java index e5cd2fab0..1b9a84bf7 100644 --- a/src/main/java/net/minestom/server/thread/ThreadProvider.java +++ b/src/main/java/net/minestom/server/thread/ThreadProvider.java @@ -69,7 +69,7 @@ public abstract class ThreadProvider { * * @param chunk the chunk */ - public abstract long findThread(@NotNull Chunk chunk); + public abstract int findThread(@NotNull Chunk chunk); /** * Defines how often chunks thread should be updated. @@ -245,7 +245,7 @@ public abstract class ThreadProvider { private @NotNull ChunkEntry setChunkThread(@NotNull Chunk chunk, @NotNull Function chunkEntrySupplier) { - final int threadId = getThreadId(chunk); + final int threadId = Math.abs(findThread(chunk)) % threads.size(); TickThread thread = threads.get(threadId); var chunks = threadChunkMap.computeIfAbsent(thread, tickThread -> ConcurrentHashMap.newKeySet()); @@ -267,16 +267,6 @@ public abstract class ThreadProvider { this.chunks.remove(chunk); } - /** - * Finds the thread id associated to a {@link Chunk}. - * - * @param chunk the chunk to find the thread id from - * @return the chunk thread id - */ - private int getThreadId(@NotNull Chunk chunk) { - return (int) (Math.abs(findThread(chunk)) % threads.size()); - } - private void processRemovedEntities() { if (removedEntities.isEmpty()) return;