fancyholograms-v3: Implement onModify callback for hologram modifications

This commit is contained in:
Oliver
2025-05-18 13:04:18 +02:00
parent 239c00b447
commit e141528f7c
4 changed files with 22 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ public class HologramData implements YamlData {
private Location location;
private String worldName;
private boolean hasChanges = false;
private Runnable onModify;
private int visibilityDistance = DEFAULT_VISIBILITY_DISTANCE;
private Visibility visibility = DEFAULT_VISIBILITY;
private boolean persistent = DEFAULT_PERSISTENCE;
@@ -114,6 +115,13 @@ public class HologramData implements YamlData {
*/
public final void setHasChanges(boolean hasChanges) {
this.hasChanges = hasChanges;
if (hasChanges && onModify != null) {
onModify.run();
}
}
public void setOnModify(Runnable onModify) {
this.onModify = onModify;
}
public int getVisibilityDistance() {

View File

@@ -38,6 +38,7 @@ public abstract class Hologram {
this.data = data;
this.viewers = new HashSet<>();
this.traitTrait = new HologramTraitTrait(this);
this.data.setOnModify(this.traitTrait::onModify);
}
/**

View File

@@ -60,6 +60,12 @@ public abstract class HologramTrait {
public void onDespawn(Player player) {
}
/**
* Called when the hologram is modified.
*/
public void onModify() {
}
/**
* Called when the hologram is registered in the registry.
*/

View File

@@ -110,6 +110,13 @@ public class HologramTraitTrait extends HologramTrait {
}
}
@Override
public void onModify() {
for (HologramTrait trait : this.traits) {
trait.onModify();
}
}
@Override
public void onRegister() {
for (HologramTrait trait : this.traits) {