mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Add constant for null future
This commit is contained in:
parent
7cf5821341
commit
6cdf8a9ab9
@ -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<EntityEvent>, 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<Void> setInstance(@NotNull Instance instance, @NotNull Pos spawnPosition) {
|
||||
Check.stateCondition(!instance.isRegistered(),
|
||||
@ -860,7 +861,7 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
||||
instance.UNSAFE_addEntity(this);
|
||||
spawn();
|
||||
EventDispatcher.call(new EntitySpawnEvent(this, instance));
|
||||
return CompletableFuture.completedFuture(null);
|
||||
return AsyncUtils.NULL_FUTURE;
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> setInstance(@NotNull Instance instance, @NotNull Point spawnPosition) {
|
||||
|
@ -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,
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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<Void> completableFuture = new CompletableFuture<>();
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
|
@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class AsyncUtils {
|
||||
public static final CompletableFuture<Void> NULL_FUTURE = CompletableFuture.completedFuture(null);
|
||||
|
||||
public static @NotNull CompletableFuture<Void> runAsync(@NotNull Runnable runnable) {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
@ -16,5 +17,4 @@ public final class AsyncUtils {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user