From 7bbb0951562a131b23b5b570e19cafb45f61f568 Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Tue, 24 Nov 2020 22:56:12 +0100 Subject: [PATCH] Fixed Player#setInstance not refreshing chunks when already in an instance --- .../command/builder/CommandDispatcher.java | 5 ++- .../net/minestom/server/entity/Entity.java | 7 ++-- .../net/minestom/server/entity/Player.java | 4 +++ .../server/entity/task/EntityTask.java | 36 ------------------- 4 files changed, 9 insertions(+), 43 deletions(-) delete mode 100644 src/main/java/net/minestom/server/entity/task/EntityTask.java diff --git a/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java b/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java index d8d2d51d9..8a46cf015 100644 --- a/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java +++ b/src/main/java/net/minestom/server/command/builder/CommandDispatcher.java @@ -37,9 +37,9 @@ public class CommandDispatcher { this.commands.add(command); } - public void unregister(Command command) { + public void unregister(@NotNull Command command) { commandMap.remove(command.getName().toLowerCase()); - for(String alias : command.getAliases()) { + for (String alias : command.getAliases()) { this.commandMap.remove(alias.toLowerCase()); } commands.remove(command); @@ -248,7 +248,6 @@ public class CommandDispatcher { // Get closest valid syntax if (!syntaxesSuggestions.isEmpty()) { final int max = syntaxesSuggestions.firstKey(); // number of correct arguments - // Check if at least 1 argument of the syntax is correct if (max > 0) { // Get the data of the closest syntax diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 2bd8b971f..ff1f0ac61 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -1175,17 +1175,16 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P /** * Triggers {@link #remove()} after the specified time. * - * @param delay the time before removing the entity + * @param delay the time before removing the entity, + * 0 to cancel the removing * @param timeUnit the unit of the delay */ public void scheduleRemove(long delay, @NotNull TimeUnit timeUnit) { - delay = timeUnit.toMilliseconds(delay); - if (delay == 0) { // Cancel the scheduled remove this.scheduledRemoveTime = 0; return; } - this.scheduledRemoveTime = System.currentTimeMillis() + delay; + this.scheduledRemoveTime = System.currentTimeMillis() + timeUnit.toMilliseconds(delay); } /** diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 985e3391e..968c82046 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -703,12 +703,14 @@ public class Player extends LivingEntity implements CommandSender { for (Chunk viewableChunk : viewableChunks) { viewableChunk.removeViewer(this); } + // Send the new dimension if (this.instance != null) { final DimensionType instanceDimensionType = instance.getDimensionType(); if (dimensionType != instanceDimensionType) sendDimension(instanceDimensionType); } + // Load all the required chunks final Position pos = firstSpawn ? getRespawnPoint() : position; final long[] visibleChunks = ChunkUtils.getChunksInRange(pos, getChunkRange()); @@ -757,6 +759,8 @@ public class Player extends LivingEntity implements CommandSender { if (firstSpawn) { teleport(getRespawnPoint()); + } else { + refreshVisibleChunks(getChunk()); } PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn); diff --git a/src/main/java/net/minestom/server/entity/task/EntityTask.java b/src/main/java/net/minestom/server/entity/task/EntityTask.java deleted file mode 100644 index 263aaffa0..000000000 --- a/src/main/java/net/minestom/server/entity/task/EntityTask.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.minestom.server.entity.task; - -import net.minestom.server.entity.LivingEntity; - -public abstract class EntityTask { - - /** - * Whether the task should begin executing for this entity. - * - * @param entity the entity in question. - * @return true if the task should start, false otherwise. - */ - public abstract boolean shouldStart(LivingEntity entity); - - /** - * Invoked when this task is about to start for this entity. - * - * @param entity the entity in question. - */ - public abstract void start(LivingEntity entity); - - /** - * Invoked when this task is being ended for this entity. - * - * @param entity the entity in question. - */ - public abstract void end(LivingEntity entity); - - /** - * Invoked each tick when this task is being executed for this entity. - * - * @param entity the entity in question. - */ - public abstract void execute(LivingEntity entity); - -}