Skip to content

Commit

Permalink
Merge branch 'main' into dev/fancysitula
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter authored Aug 8, 2024
2 parents c4f0dc2 + d2de091 commit ed8e7d0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Build plugin

on:
push:
pull_request:
types:
- opened

jobs:
build-plugin:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runPaper.folia.registerTask()
allprojects {
group = "de.oliver"
val buildId = System.getenv("BUILD_ID")
version = "2.3.0" + (if (buildId != null) ".$buildId" else "")
version = "2.3.1" + (if (buildId != null) ".$buildId" else "")
description = "Simple, lightweight and fast hologram plugin using display entities"

repositories {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
minecraftVersion=1.21
fancyNpcsVersion=2.2.1
fancyLibVersion=1.0.28
fancyLibVersion=1.0.31
fancySitulaVersion=0.0.5
viaversionVersion=5.0.1
chatcolorhandlerVersion=v2.5.3
2 changes: 1 addition & 1 deletion src/main/java/de/oliver/fancyholograms/FancyHolograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Please update the server to one of (%s).
public void onEnable() {
getHologramConfiguration().reload(this); // initialize configuration

FancyLib.setPlugin(this);
FancyLib.setPlugin(this, getFile());

if (!ServerSoftware.isPaper()) {
getLogger().warning("""
Expand Down
50 changes: 31 additions & 19 deletions src/main/java/de/oliver/fancyholograms/HologramManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public void removeHologram(@NotNull final Hologram hologram) {
Optional<Hologram> optionalHologram = Optional.ofNullable(this.holograms.remove(name.toLowerCase(Locale.ROOT)));

optionalHologram.ifPresent(hologram -> {
for (UUID viewer : hologram.getViewers()) {
Player player = Bukkit.getPlayer(viewer);
if (player != null) {
FancyHolograms.get().getHologramThread().submit(() -> hologram.forceHideHologram(player));
for (UUID viewer : hologram.getViewers()) {
Player player = Bukkit.getPlayer(viewer);
if (player != null) {
FancyHolograms.get().getHologramThread().submit(() -> hologram.forceHideHologram(player));
}
}
}

FancyHolograms.get().getHologramThread().submit(() -> plugin.getHologramStorage().delete(hologram));
}
FancyHolograms.get().getHologramThread().submit(() -> plugin.getHologramStorage().delete(hologram));
}
);

return optionalHologram;
Expand Down Expand Up @@ -152,7 +152,7 @@ public void loadHolograms() {
}
isLoaded = true;

Bukkit.getPluginManager().callEvent(new HologramsLoadedEvent(ImmutableList.copyOf(allLoaded)));
FancyHolograms.get().getHologramThread().submit(() -> Bukkit.getPluginManager().callEvent(new HologramsLoadedEvent(ImmutableList.copyOf(allLoaded))));

FancyHolograms.get().getLogger().info(String.format("Loaded %d holograms for all loaded worlds", allLoaded.size()));
}
Expand Down Expand Up @@ -188,8 +188,8 @@ void initializeTasks() {
});

final var updateTimes = CacheBuilder.newBuilder()
.expireAfterAccess(Duration.ofMinutes(5))
.<String, Long>build();
.expireAfterAccess(Duration.ofMinutes(5))
.<String, Long>build();

hologramThread.scheduleAtFixedRate(() -> {
final var time = System.currentTimeMillis();
Expand All @@ -204,24 +204,32 @@ void initializeTasks() {
if (data instanceof TextHologramData) {
updateTimes.put(hologram.getData().getName(), time);
}
} else if (data instanceof TextHologramData textData) {
}
}
}, 50, 1000, TimeUnit.MILLISECONDS);

hologramThread.scheduleAtFixedRate(() -> {
final var time = System.currentTimeMillis();

for (final var hologram : getHolograms()) {
if (hologram.getData() instanceof TextHologramData textData) {
final var interval = textData.getTextUpdateInterval();
if (interval < 1) {
continue; // doesn't update
}

final var lastUpdate = updateTimes.asMap().get(data.getName());
final var lastUpdate = updateTimes.asMap().get(textData.getName());
if (lastUpdate != null && time < (lastUpdate + interval)) {
continue;
}

if (lastUpdate == null || time > (lastUpdate + interval)) {
hologram.refreshForViewersInWorld();
updateTimes.put(data.getName(), time);
updateTimes.put(textData.getName(), time);
}
}
}
}, 50, 1000, TimeUnit.MILLISECONDS);
}, 50, 50, TimeUnit.MILLISECONDS);
}

/**
Expand All @@ -233,15 +241,19 @@ public void reloadHolograms() {
}

public void unloadHolograms() {
final var online = List.copyOf(Bukkit.getOnlinePlayers());

FancyHolograms.get().getHologramThread().submit(() -> {
List<Hologram> unloaded = new ArrayList<>();

for (final var hologram : this.getPersistentHolograms()) {
this.holograms.remove(hologram.getName());
unloaded.add(hologram);
online.forEach(hologram::forceHideHologram);

for (UUID viewer : hologram.getViewers()) {
Player player = Bukkit.getPlayer(viewer);
if (player != null) {
hologram.forceHideHologram(player);
}
}
}

Bukkit.getPluginManager().callEvent(new HologramsUnloadedEvent(ImmutableList.copyOf(unloaded)));
Expand All @@ -253,8 +265,8 @@ public void unloadHolograms(String world) {

FancyHolograms.get().getHologramThread().submit(() -> {
List<Hologram> h = getPersistentHolograms().stream()
.filter(hologram -> hologram.getData().getLocation().getWorld().getName().equals(world))
.toList();
.filter(hologram -> hologram.getData().getLocation().getWorld().getName().equals(world))
.toList();

FancyHolograms.get().getHologramStorage().saveBatch(h, true);

Expand Down

0 comments on commit ed8e7d0

Please sign in to comment.