Skip to content

Commit

Permalink
remove updateHologram and add getHologramOrCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed May 30, 2024
1 parent 508f9af commit 208e227
Showing 1 changed file with 10 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ private void purge() {
}
}

/**
* @see HologramsService#getHologram(Location, boolean)
*/
@Nonnull
private Hologram getHologramOrCreate(@Nonnull Location loc) {
return getHologram(loc, true);
}

/**
* This returns the {@link Hologram} associated with the given {@link Location}.
* If createIfNoneExists is set to true a new {@link ArmorStand} will be spawned
Expand Down Expand Up @@ -237,31 +245,6 @@ private Hologram getAsHologram(@Nonnull BlockPosition position, @Nonnull Entity
}
}

/**
* This updates the {@link Hologram}.
* You can use it to set the nametag or other properties.
* <p>
* <strong>This method must be executed on the main {@link Server} {@link Thread}.</strong>
*
* @param loc
* The {@link Location}
*/
@Nullable
private Hologram updateHologram(@Nonnull Location loc) {
Validate.notNull(loc, "Location must not be null");

if (!Bukkit.isPrimaryThread()) {
throw new UnsupportedOperationException("You cannot update a hologram asynchronously");
}

try {
return getHologram(loc, true);
} catch (Exception | LinkageError x) {
Slimefun.logger().log(Level.SEVERE, "Hologram located at {0}", new BlockPosition(loc));
throw new RuntimeException("Something went wrong while trying to update this hologram", x);
}
}

/**
* This removes the {@link Hologram} at that given {@link Location}.
* <p>
Expand Down Expand Up @@ -308,10 +291,8 @@ public boolean removeHologram(@Nonnull Location loc) {
public void setHologramLabel(@Nonnull Location loc, @Nullable String label) {
Validate.notNull(loc, "Location must not be null");

Hologram hologram = updateHologram(loc);
if (hologram != null) {
hologram.setLabel(label);
}
Hologram hologram = getHologramOrCreate(loc);
hologram.setLabel(label);
}

}

0 comments on commit 208e227

Please sign in to comment.