Fixed Player#setInstance not refreshing chunks when already in an instance

This commit is contained in:
Felix Cravic 2020-11-24 22:56:12 +01:00
parent 38bcb755c2
commit 7bbb095156
4 changed files with 9 additions and 43 deletions

View File

@ -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

View File

@ -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);
}
/**

View File

@ -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);

View File

@ -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);
}