mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
hollow-cube/editentitymeta_function (#62)
* Add editEntityMeta
* Log entityType instead
* finally
(cherry picked from commit 30699ec3fd
)
This commit is contained in:
parent
b1b33b9df8
commit
7174ce2b21
@ -291,6 +291,21 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
|
||||
return this.entityMeta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do a batch edit of this entity's metadata.
|
||||
*/
|
||||
public <TMeta extends EntityMeta> void editEntityMeta(Class<TMeta> metaClass, Consumer<TMeta> editor) {
|
||||
entityMeta.setNotifyAboutChanges(false);
|
||||
try {
|
||||
TMeta casted = metaClass.cast(entityMeta);
|
||||
editor.accept(casted);
|
||||
} catch (Throwable t) {
|
||||
throw new RuntimeException("Error editing entity " + id + " " + entityType.name() + " meta", t);
|
||||
} finally {
|
||||
entityMeta.setNotifyAboutChanges(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports the entity only if the chunk at {@code position} is loaded or if
|
||||
* {@link Instance#hasEnabledAutoChunkLoad()} returns true.
|
||||
|
Loading…
Reference in New Issue
Block a user