Skip to content

Commit

Permalink
Fix not disappearing holograms
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed May 29, 2024
1 parent 45601c8 commit feb3a7e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.Nonnull;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.util.Vector;
Expand All @@ -25,15 +26,28 @@ public interface HologramOwner extends ItemAttribute {
/**
* This will update the hologram text for the given {@link Block}.
*
* @param b
* @param hologramOwnerBlock
* The {@link Block} to which the hologram belongs
*
* @param text
* The nametag for the hologram
*/
default void updateHologram(@Nonnull Block b, @Nonnull String text) {
Location loc = b.getLocation().add(getHologramOffset(b));
Slimefun.getHologramsService().setHologramLabel(loc, ChatColors.color(text));
default void updateHologram(@Nonnull Block hologramOwnerBlock, @Nonnull String text) {
Runnable runnable = () -> {
// Fix not disappearing holograms (#3176)
if (Slimefun.getTickerTask().isDeletedSoon(hologramOwnerBlock.getLocation())) {
return;
}

Location loc = hologramOwnerBlock.getLocation().add(getHologramOffset(hologramOwnerBlock));
Slimefun.getHologramsService().setHologramLabel(loc, ChatColors.color(text));
};

if (Bukkit.isPrimaryThread()) {
runnable.run();
} else {
Slimefun.runSync(runnable);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,19 @@ private void updateHologram(@Nonnull Location loc, @Nonnull Consumer<Hologram> c
Validate.notNull(loc, "Location must not be null");
Validate.notNull(consumer, "Callbacks must not be null");

Runnable runnable = () -> {
try {
Hologram hologram = getHologram(loc, true);
if (!Bukkit.isPrimaryThread()) {
throw new UnsupportedOperationException("You cannot update a hologram asynchronously");
}

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

if (Bukkit.isPrimaryThread()) {
runnable.run();
} else {
Slimefun.runSync(runnable);
if (hologram != null) {
consumer.accept(hologram);
}
} catch (Exception | LinkageError x) {
Slimefun.logger().log(Level.SEVERE, "Hologram located at {0}", new BlockPosition(loc));
Slimefun.logger().log(Level.SEVERE, "Something went wrong while trying to update this hologram", x);
}
}

Expand Down

0 comments on commit feb3a7e

Please sign in to comment.