mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-06 23:41:25 +01:00
Unsafe methods should be called unsafe.
This commit is contained in:
parent
a6939b3695
commit
f91f7abb26
@ -658,8 +658,9 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
|||||||
/**
|
/**
|
||||||
* Gets the entity current instance.
|
* Gets the entity current instance.
|
||||||
*
|
*
|
||||||
* @return the entity instance
|
* @return the entity instance, can be null if the entity doesn't have an instance yet
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Instance getInstance() {
|
public Instance getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
@ -677,12 +678,12 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
|||||||
"Instances need to be registered, please use InstanceManager#registerInstance or InstanceManager#registerSharedInstance");
|
"Instances need to be registered, please use InstanceManager#registerInstance or InstanceManager#registerSharedInstance");
|
||||||
|
|
||||||
if (this.instance != null) {
|
if (this.instance != null) {
|
||||||
this.instance.removeEntity(this);
|
this.instance.UNSAFE_removeEntity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isActive = true;
|
this.isActive = true;
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
instance.addEntity(this);
|
instance.UNSAFE_addEntity(this);
|
||||||
spawn();
|
spawn();
|
||||||
EntitySpawnEvent entitySpawnEvent = new EntitySpawnEvent(this, instance);
|
EntitySpawnEvent entitySpawnEvent = new EntitySpawnEvent(this, instance);
|
||||||
callEvent(EntitySpawnEvent.class, entitySpawnEvent);
|
callEvent(EntitySpawnEvent.class, entitySpawnEvent);
|
||||||
@ -1191,7 +1192,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
|
|||||||
this.shouldRemove = true;
|
this.shouldRemove = true;
|
||||||
entityById.remove(id);
|
entityById.remove(id);
|
||||||
if (instance != null)
|
if (instance != null)
|
||||||
instance.removeEntity(this);
|
instance.UNSAFE_removeEntity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -606,7 +606,7 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
|
|
||||||
final boolean firstSpawn = this.instance == null; // TODO: Handle player reconnections, must be false in that case too
|
final boolean firstSpawn = this.instance == null; // TODO: Handle player reconnections, must be false in that case too
|
||||||
|
|
||||||
// true if the chunks need to be send to the client, can be false if the instances share the same chunks (eg SharedInstance)
|
// true if the chunks need to be sent to the client, can be false if the instances share the same chunks (eg SharedInstance)
|
||||||
final boolean needWorldRefresh = !InstanceUtils.areLinked(this.instance, instance);
|
final boolean needWorldRefresh = !InstanceUtils.areLinked(this.instance, instance);
|
||||||
|
|
||||||
if (needWorldRefresh) {
|
if (needWorldRefresh) {
|
||||||
|
@ -831,10 +831,10 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
|||||||
*
|
*
|
||||||
* @param entity the entity to add
|
* @param entity the entity to add
|
||||||
*/
|
*/
|
||||||
public void addEntity(@NotNull Entity entity) {
|
public void UNSAFE_addEntity(@NotNull Entity entity) {
|
||||||
final Instance lastInstance = entity.getInstance();
|
final Instance lastInstance = entity.getInstance();
|
||||||
if (lastInstance != null && lastInstance != this) {
|
if (lastInstance != null && lastInstance != this) {
|
||||||
lastInstance.removeEntity(entity); // If entity is in another instance, remove it from there and add it to this
|
lastInstance.UNSAFE_removeEntity(entity); // If entity is in another instance, remove it from there and add it to this
|
||||||
}
|
}
|
||||||
AddEntityToInstanceEvent event = new AddEntityToInstanceEvent(this, entity);
|
AddEntityToInstanceEvent event = new AddEntityToInstanceEvent(this, entity);
|
||||||
callCancellableEvent(AddEntityToInstanceEvent.class, event, () -> {
|
callCancellableEvent(AddEntityToInstanceEvent.class, event, () -> {
|
||||||
@ -874,7 +874,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
|||||||
*
|
*
|
||||||
* @param entity the entity to remove
|
* @param entity the entity to remove
|
||||||
*/
|
*/
|
||||||
public void removeEntity(@NotNull Entity entity) {
|
public void UNSAFE_removeEntity(@NotNull Entity entity) {
|
||||||
final Instance entityInstance = entity.getInstance();
|
final Instance entityInstance = entity.getInstance();
|
||||||
if (entityInstance != this)
|
if (entityInstance != this)
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user