From 6cdf8a9ab9824ce3129e0a24ecd23578ff0ca91b Mon Sep 17 00:00:00 2001 From: TheMode Date: Sun, 11 Jul 2021 03:35:17 +0200 Subject: [PATCH] Add constant for null future --- src/main/java/net/minestom/server/entity/Entity.java | 5 +++-- src/main/java/net/minestom/server/entity/Player.java | 7 ++++--- .../java/net/minestom/server/instance/AnvilLoader.java | 9 +++++---- .../java/net/minestom/server/instance/IChunkLoader.java | 3 ++- .../java/net/minestom/server/utils/async/AsyncUtils.java | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index c6a6a9ded..d64dca2eb 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -40,6 +40,7 @@ import net.minestom.server.potion.TimedPotion; import net.minestom.server.tag.Tag; import net.minestom.server.tag.TagHandler; import net.minestom.server.thread.ThreadProvider; +import net.minestom.server.utils.async.AsyncUtils; import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.entity.EntityUtils; import net.minestom.server.utils.player.PlayerUtils; @@ -844,8 +845,8 @@ public class Entity implements Viewable, Tickable, EventHandler, Da * * @param instance the new instance of the entity * @param spawnPosition the spawn position for the entity. - * @throws IllegalStateException if {@code instance} has not been registered in {@link InstanceManager} * @return + * @throws IllegalStateException if {@code instance} has not been registered in {@link InstanceManager} */ public CompletableFuture setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) { Check.stateCondition(!instance.isRegistered(), @@ -860,7 +861,7 @@ public class Entity implements Viewable, Tickable, EventHandler, Da instance.UNSAFE_addEntity(this); spawn(); EventDispatcher.call(new EntitySpawnEvent(this, instance)); - return CompletableFuture.completedFuture(null); + return AsyncUtils.NULL_FUTURE; } public CompletableFuture setInstance(@NotNull Instance instance, @NotNull Point spawnPosition) { diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 6d74982de..4c892b064 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -69,7 +69,7 @@ import net.minestom.server.sound.SoundCategory; import net.minestom.server.sound.SoundEvent; import net.minestom.server.stat.PlayerStatistic; import net.minestom.server.utils.*; -import net.minestom.server.utils.chunk.ChunkCallback; +import net.minestom.server.utils.async.AsyncUtils; import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.entity.EntityUtils; import net.minestom.server.utils.identity.NamedAndIdentified; @@ -519,7 +519,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable, *

* Be aware that because chunk operations are expensive, * it is possible for this method to be non-blocking when retrieving chunks is required. - * @param instance the new player instance + * + * @param instance the new player instance * @param spawnPosition the new position of the player * @return */ @@ -550,7 +551,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, // The player already has the good version of all the chunks. // We just need to refresh his entity viewing list and add him to the instance spawnPlayer(instance, spawnPosition, false, false, false); - return CompletableFuture.completedFuture(null); + return AsyncUtils.NULL_FUTURE; } } diff --git a/src/main/java/net/minestom/server/instance/AnvilLoader.java b/src/main/java/net/minestom/server/instance/AnvilLoader.java index 97aa9e2bc..e5c470bdb 100644 --- a/src/main/java/net/minestom/server/instance/AnvilLoader.java +++ b/src/main/java/net/minestom/server/instance/AnvilLoader.java @@ -5,6 +5,7 @@ import net.minestom.server.exception.ExceptionManager; import net.minestom.server.instance.block.Block; import net.minestom.server.instance.block.BlockHandler; import net.minestom.server.instance.block.BlockManager; +import net.minestom.server.utils.async.AsyncUtils; import net.minestom.server.world.biomes.Biome; import net.minestom.server.world.biomes.BiomeManager; import org.jetbrains.annotations.NotNull; @@ -196,7 +197,7 @@ public class AnvilLoader implements IChunkLoader { } catch (AnvilException | IOException e) { LOGGER.error("Failed to save chunk " + chunkX + ", " + chunkZ, e); EXCEPTION_MANAGER.handleException(e); - return CompletableFuture.completedFuture(null); + return AsyncUtils.NULL_FUTURE; } } } @@ -206,7 +207,7 @@ public class AnvilLoader implements IChunkLoader { } catch (AnvilException | IOException e) { LOGGER.error("Failed to save chunk " + chunkX + ", " + chunkZ, e); EXCEPTION_MANAGER.handleException(e); - return CompletableFuture.completedFuture(null); + return AsyncUtils.NULL_FUTURE; } save(chunk, column); try { @@ -215,9 +216,9 @@ public class AnvilLoader implements IChunkLoader { } catch (IOException e) { LOGGER.error("Failed to save chunk " + chunkX + ", " + chunkZ, e); EXCEPTION_MANAGER.handleException(e); - return CompletableFuture.completedFuture(null); + return AsyncUtils.NULL_FUTURE; } - return CompletableFuture.completedFuture(null); + return AsyncUtils.NULL_FUTURE; } private void save(Chunk chunk, ChunkColumn chunkColumn) { diff --git a/src/main/java/net/minestom/server/instance/IChunkLoader.java b/src/main/java/net/minestom/server/instance/IChunkLoader.java index 7d4a2b773..7938cf8cd 100644 --- a/src/main/java/net/minestom/server/instance/IChunkLoader.java +++ b/src/main/java/net/minestom/server/instance/IChunkLoader.java @@ -1,6 +1,7 @@ package net.minestom.server.instance; import net.minestom.server.MinecraftServer; +import net.minestom.server.utils.async.AsyncUtils; import net.minestom.server.utils.thread.MinestomThread; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -55,7 +56,7 @@ public interface IChunkLoader { } catch (InterruptedException e) { MinecraftServer.getExceptionManager().handleException(e); } - return CompletableFuture.completedFuture(null); + return AsyncUtils.NULL_FUTURE; } else { CompletableFuture completableFuture = new CompletableFuture<>(); AtomicInteger counter = new AtomicInteger(); diff --git a/src/main/java/net/minestom/server/utils/async/AsyncUtils.java b/src/main/java/net/minestom/server/utils/async/AsyncUtils.java index e2c1cd4ba..3e0beccf0 100644 --- a/src/main/java/net/minestom/server/utils/async/AsyncUtils.java +++ b/src/main/java/net/minestom/server/utils/async/AsyncUtils.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import java.util.concurrent.CompletableFuture; public final class AsyncUtils { + public static final CompletableFuture NULL_FUTURE = CompletableFuture.completedFuture(null); public static @NotNull CompletableFuture runAsync(@NotNull Runnable runnable) { return CompletableFuture.runAsync(() -> { @@ -16,5 +17,4 @@ public final class AsyncUtils { } }); } - }