mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancyholograms-v3: Implement onModify callback for hologram modifications
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user