Fix holograms showing up on server start although they've been disabled

SD-9522
This commit is contained in:
Christian Koop 2023-03-29 20:23:50 +02:00
parent 537430ca89
commit 9847c567df
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3

View File

@ -269,7 +269,7 @@ public class UltimateKits extends SongodaPlugin {
if (kit == null) { if (kit == null) {
dataFile.set("BlockData." + key, null); dataFile.set("BlockData." + key, null);
} else { } else {
createHologram(kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride)); updateHologram(kitManager.addKitToLocation(kit, location, type, holograms, particles, displayItems, itemOverride));
} }
} }
} }
@ -280,8 +280,10 @@ public class UltimateKits extends SongodaPlugin {
Bukkit.getScheduler().runTaskLater(this, () -> Bukkit.getScheduler().runTaskLater(this, () ->
this.dataManager.getBlockData((blockData) -> { this.dataManager.getBlockData((blockData) -> {
this.kitManager.setKitLocations(blockData); this.kitManager.setKitLocations(blockData);
if (HologramManager.isEnabled()) {
loadHolograms(); Collection<KitBlockData> kitBlocks = getKitManager().getKitLocations().values();
for (KitBlockData data : kitBlocks) {
updateHologram(data);
} }
}), 20L); }), 20L);
@ -340,7 +342,7 @@ public class UltimateKits extends SongodaPlugin {
public void onConfigReload() { public void onConfigReload() {
setLocale(Settings.LANGUGE_MODE.getString(), true); setLocale(Settings.LANGUGE_MODE.getString(), true);
dataManager.bulkUpdateBlockData(this.getKitManager().getKitLocations()); dataManager.bulkUpdateBlockData(getKitManager().getKitLocations());
kitConfig.load(); kitConfig.load();
categoryConfig.load(); categoryConfig.load();
keyFile.load(); keyFile.load();
@ -349,9 +351,7 @@ public class UltimateKits extends SongodaPlugin {
} }
public void removeHologram(KitBlockData data) { public void removeHologram(KitBlockData data) {
if (HologramManager.isEnabled()) { HologramManager.removeHologram(data.getHologramId());
HologramManager.removeHologram(data.getHologramId());
}
} }
public void updateHologram(Kit kit) { public void updateHologram(Kit kit) {
@ -364,7 +364,7 @@ public class UltimateKits extends SongodaPlugin {
} }
} }
public void createHologram(KitBlockData data) { private void createHologram(KitBlockData data) {
List<String> lines = formatHologram(data); List<String> lines = formatHologram(data);
Location location = getKitLocation(data, lines.size()); Location location = getKitLocation(data, lines.size());
HologramManager.createHologram(data.getHologramId(), location, lines); HologramManager.createHologram(data.getHologramId(), location, lines);
@ -388,28 +388,22 @@ public class UltimateKits extends SongodaPlugin {
} }
public void updateHologram(KitBlockData data) { public void updateHologram(KitBlockData data) {
if (data != null && data.isInLoadedChunk() && HologramManager.isEnabled()) { if (data == null || !data.isInLoadedChunk() || !HologramManager.isEnabled()) {
List<String> lines = formatHologram(data); return;
if (!lines.isEmpty()) {
if (!data.showHologram()) {
HologramManager.removeHologram(data.getHologramId());
} else if (HologramManager.isHologramLoaded(data.getHologramId())) {
HologramManager.updateHologram(data.getHologramId(), lines);
} else {
createHologram(data);
}
}
} }
}
private void loadHolograms() { List<String> lines = formatHologram(data);
Collection<KitBlockData> kitBlocks = getKitManager().getKitLocations().values(); if (lines.isEmpty() || !data.showHologram()) {
if (kitBlocks.isEmpty()) return; HologramManager.removeHologram(data.getHologramId());
return;
}
for (KitBlockData data : kitBlocks) { if (!HologramManager.isHologramLoaded(data.getHologramId())) {
createHologram(data); createHologram(data);
return;
} }
HologramManager.updateHologram(data.getHologramId(), lines);
} }
private List<String> formatHologram(KitBlockData data) { private List<String> formatHologram(KitBlockData data) {