hollow-cube/editentitymeta_function (#62)

* Add editEntityMeta

* Log entityType instead

* finally
This commit is contained in:
Samuel 2023-09-26 09:40:52 -04:00 committed by GitHub
parent 9e27053b15
commit 30699ec3fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

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