Update for the new HologramManager changes.

This commit is contained in:
Fernando Pettinelli 2021-12-20 19:34:57 -03:00
parent 3b25d337a4
commit d601049117
4 changed files with 73 additions and 47 deletions

View File

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

View File

@ -4,6 +4,7 @@ import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.gui.GuiManager;
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.epicfurnaces.EpicFurnaces;
@ -42,6 +43,11 @@ public class Furnace {
private final EpicFurnaces plugin = EpicFurnaces.getInstance();
// This is the unique identifier for this furnace.
// It is reset on every plugin load.
// Used for holograms.
private final UUID uniqueId = UUID.randomUUID();
// Identifier for database use.
private int id;
@ -402,4 +408,16 @@ public class Furnace {
if (result != null)
world.dropItemNaturally(location, result);
}
public String getHologramId() {
return "EpicFurnaces-" + uniqueId;
}
public void createHologram() {
HologramManager.createHologram(getHologramId(), getLocation().add(0, 0.15, 0), plugin.getHologramLines(this));
}
public void removeHologram() {
HologramManager.removeHologram(getHologramId());
}
}

View File

@ -18,7 +18,6 @@ import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.List;
/**
@ -90,10 +89,10 @@ public class BlockListeners implements Listener {
.setPlacedBy(event.getPlayer().getUniqueId()).build()
: new FurnaceBuilder(location).setPlacedBy(event.getPlayer().getUniqueId()).build();
plugin.getFurnaceManager().addFurnace(furnace);
plugin.getDataManager().createFurnace(furnace);
plugin.getFurnaceManager().addFurnace(furnace);
plugin.updateHolograms(Collections.singleton(furnace));
furnace.createHologram();
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@ -1,7 +1,7 @@
name: EpicFurnaces
description: EpicFurnaces
version: maven-version-number
softdepend: [ FabledSkyBlock, HolographicDisplays, PlotSquared, GriefPrevention, USkyBlock, SkyBlock, WorldGuard, Factions, Lands, RedProtect, UltimateClaims, BentoBox, Vault ]
softdepend: [ FabledSkyBlock, HolographicDisplays, PlotSquared, GriefPrevention, USkyBlock, SkyBlock, WorldGuard, Factions, Lands, RedProtect, UltimateClaims, BentoBox, Vault, DecentHolograms ]
main: com.songoda.epicfurnaces.EpicFurnaces
author: songoda
api-version: 1.13