Recodes how the new hologram logic works

I partially reverted d601049117 and chose minimal logic changes. Got reports of holograms not enabling or not being removed so this should be easier and less to test


SD-8943
This commit is contained in:
Christian Koop 2022-01-18 13:48:37 +01:00
parent cfef081b8d
commit caa39d284a
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
3 changed files with 54 additions and 68 deletions

View File

@ -226,7 +226,6 @@ public class EpicFurnaces extends SongodaPlugin {
} }
this.dataManager.getFurnaces((furnaces) -> { this.dataManager.getFurnaces((furnaces) -> {
furnaces.values().forEach(Furnace::createHologram);
this.furnaceManager.addFurnaces(furnaces.values()); this.furnaceManager.addFurnaces(furnaces.values());
this.dataManager.getBoosts((boosts) -> this.boostManager.addBoosts(boosts)); this.dataManager.getBoosts((boosts) -> this.boostManager.addBoosts(boosts));
}); });
@ -267,35 +266,23 @@ public class EpicFurnaces extends SongodaPlugin {
} }
public void clearHologram(Furnace furnace) { public void clearHologram(Furnace furnace) {
furnace.removeHologram(); HologramManager.removeHologram(furnace.getHologramId());
} }
public void updateHolograms(Collection<Furnace> furnaces) { public void updateHolograms(Collection<Furnace> furnaces) {
// are holograms enabled? // are holograms enabled?
if (!Settings.HOLOGRAMS.getBoolean() || !HologramManager.getManager().isEnabled()) return; if (!Settings.HOLOGRAMS.getBoolean() || !HologramManager.getManager().isEnabled()) return;
Map<String, List<String>> holograms = new HashMap<>(furnaces.size()); Map<String, List<String>> holograms = new HashMap<>();
for (Furnace furnace : furnaces) { for (Furnace furnace : furnaces) {
// don't try to load furnaces in chunks that aren't loaded // don't try to load furnaces in chunks that aren't loaded
if (!furnace.isInLoadedChunk()) continue; if (!furnace.isInLoadedChunk()) continue;
if (!HologramManager.isHologramLoaded(furnace.getHologramId())) {
continue;
}
holograms.put(furnace.getHologramId(), getHologramLines(furnace));
}
// Update holograms
HologramManager.bulkUpdateHolograms(holograms);
}
public List<String> getHologramLines(Furnace furnace) {
BlockState state = furnace.getLocation().getBlock().getState(); BlockState state = furnace.getLocation().getBlock().getState();
// verify that this is a furnace // verify that this is a furnace
if (!(state instanceof org.bukkit.block.Furnace)) return Collections.emptyList(); if (!(state instanceof org.bukkit.block.Furnace)) continue;
org.bukkit.block.Furnace furnaceBlock = ((org.bukkit.block.Furnace) state); org.bukkit.block.Furnace furnaceBlock = ((org.bukkit.block.Furnace) state);
@ -334,7 +321,17 @@ public class EpicFurnaces extends SongodaPlugin {
.processPlaceholder("in", inAmt) .processPlaceholder("in", inAmt)
.processPlaceholder("out", Math.min(outAmt, 64)).getMessage(); .processPlaceholder("out", Math.min(outAmt, 64)).getMessage();
return Arrays.asList(progress, stats); List<String> hologramLines = Arrays.asList(progress, stats);
if (!HologramManager.isHologramLoaded(furnace.getHologramId())) {
HologramManager.createHologram(furnace.getHologramId(), furnace.getLocation().add(0, .15, 0), hologramLines);
continue;
}
holograms.put(furnace.getHologramId(), hologramLines);
}
// Update holograms
HologramManager.bulkUpdateHolograms(holograms);
} }
private void loadLevelManager() { private void loadLevelManager() {

View File

@ -4,9 +4,8 @@ import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.gui.GuiManager; import com.songoda.core.gui.GuiManager;
import com.songoda.core.hooks.EconomyManager; import com.songoda.core.hooks.EconomyManager;
import com.songoda.core.hooks.HologramManager;
import com.songoda.core.math.MathUtils;
import com.songoda.core.hooks.ProtectionManager; import com.songoda.core.hooks.ProtectionManager;
import com.songoda.core.math.MathUtils;
import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.EpicFurnaces;
import com.songoda.epicfurnaces.boost.BoostData; import com.songoda.epicfurnaces.boost.BoostData;
import com.songoda.epicfurnaces.furnace.levels.Level; import com.songoda.epicfurnaces.furnace.levels.Level;
@ -40,13 +39,9 @@ import java.util.UUID;
* Created by songoda on 3/7/2017. * Created by songoda on 3/7/2017.
*/ */
public class Furnace { public class Furnace {
private final EpicFurnaces plugin = EpicFurnaces.getInstance(); private final EpicFurnaces plugin = EpicFurnaces.getInstance();
// This is the unique identifier for this furnace. private final String hologramId = UUID.randomUUID().toString();
// It is reset on every plugin load.
// Used for holograms.
private final UUID uniqueId = UUID.randomUUID();
// Identifier for database use. // Identifier for database use.
private int id; private int id;
@ -410,14 +405,6 @@ public class Furnace {
} }
public String getHologramId() { public String getHologramId() {
return "EpicFurnaces-" + uniqueId; return this.hologramId;
}
public void createHologram() {
HologramManager.createHologram(getHologramId(), getLocation().add(0, 0.15, 0), plugin.getHologramLines(this));
}
public void removeHologram() {
HologramManager.removeHologram(getHologramId());
} }
} }

View File

@ -1,5 +1,6 @@
package com.songoda.epicfurnaces.listeners; package com.songoda.epicfurnaces.listeners;
import com.songoda.core.hooks.HologramManager;
import com.songoda.core.utils.PlayerUtils; import com.songoda.core.utils.PlayerUtils;
import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.EpicFurnaces;
import com.songoda.epicfurnaces.furnace.Furnace; import com.songoda.epicfurnaces.furnace.Furnace;
@ -18,6 +19,7 @@ import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -92,7 +94,7 @@ public class BlockListeners implements Listener {
plugin.getDataManager().createFurnace(furnace); plugin.getDataManager().createFurnace(furnace);
plugin.getFurnaceManager().addFurnace(furnace); plugin.getFurnaceManager().addFurnace(furnace);
furnace.createHologram(); plugin.updateHolograms(Collections.singleton(furnace));
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)