mirror of
https://github.com/songoda/EpicFurnaces.git
synced 2025-02-03 05:01:23 +01:00
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:
parent
cfef081b8d
commit
caa39d284a
@ -226,7 +226,6 @@ 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));
|
||||
});
|
||||
@ -267,76 +266,74 @@ public class EpicFurnaces extends SongodaPlugin {
|
||||
}
|
||||
|
||||
public void clearHologram(Furnace furnace) {
|
||||
furnace.removeHologram();
|
||||
HologramManager.removeHologram(furnace.getHologramId());
|
||||
}
|
||||
|
||||
public void updateHolograms(Collection<Furnace> furnaces) {
|
||||
// are holograms enabled?
|
||||
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) {
|
||||
// don't try to load furnaces in chunks that aren't loaded
|
||||
if (!furnace.isInLoadedChunk()) continue;
|
||||
|
||||
BlockState state = furnace.getLocation().getBlock().getState();
|
||||
|
||||
// verify that this is a furnace
|
||||
if (!(state instanceof org.bukkit.block.Furnace)) continue;
|
||||
|
||||
org.bukkit.block.Furnace furnaceBlock = ((org.bukkit.block.Furnace) state);
|
||||
|
||||
int performance = (furnaceBlock.getCookTime() - furnace.getPerformanceTotal(furnaceBlock.getType())) <= 0 ? 0 : furnace.getPerformanceTotal(furnaceBlock.getType());
|
||||
float percent = (float) (furnaceBlock.getCookTime() - performance) / (200 - performance);
|
||||
|
||||
int progressBars = (int) (6 * percent) + (percent == 0 ? 0 : 1);
|
||||
int leftOver = (6 - progressBars);
|
||||
|
||||
String progress;
|
||||
|
||||
if (furnaceBlock.getInventory().getFuel() != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < progressBars; i++) {
|
||||
sb.append("&a=");
|
||||
}
|
||||
for (int i = 0; i < leftOver; i++) {
|
||||
sb.append("&c=");
|
||||
}
|
||||
|
||||
progress = Methods.formatText(sb.toString());
|
||||
} else {
|
||||
progress = getLocale().getMessage("general.hologram.outoffuel").getMessage();
|
||||
}
|
||||
|
||||
int inAmt = 0;
|
||||
int outAmt = 0;
|
||||
if (furnaceBlock.getInventory().getSmelting() != null) {
|
||||
inAmt = furnaceBlock.getInventory().getSmelting().getAmount();
|
||||
}
|
||||
if (furnaceBlock.getInventory().getResult() != null) {
|
||||
outAmt = furnaceBlock.getInventory().getResult().getAmount();
|
||||
}
|
||||
|
||||
String stats = getLocale().getMessage("general.hologram.stats")
|
||||
.processPlaceholder("in", inAmt)
|
||||
.processPlaceholder("out", Math.min(outAmt, 64)).getMessage();
|
||||
|
||||
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(), getHologramLines(furnace));
|
||||
holograms.put(furnace.getHologramId(), hologramLines);
|
||||
}
|
||||
|
||||
// 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)) return Collections.emptyList();
|
||||
|
||||
org.bukkit.block.Furnace furnaceBlock = ((org.bukkit.block.Furnace) state);
|
||||
|
||||
int performance = (furnaceBlock.getCookTime() - furnace.getPerformanceTotal(furnaceBlock.getType())) <= 0 ? 0 : furnace.getPerformanceTotal(furnaceBlock.getType());
|
||||
float percent = (float) (furnaceBlock.getCookTime() - performance) / (200 - performance);
|
||||
|
||||
int progressBars = (int) (6 * percent) + (percent == 0 ? 0 : 1);
|
||||
int leftOver = (6 - progressBars);
|
||||
|
||||
String progress;
|
||||
|
||||
if (furnaceBlock.getInventory().getFuel() != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < progressBars; i++) {
|
||||
sb.append("&a=");
|
||||
}
|
||||
for (int i = 0; i < leftOver; i++) {
|
||||
sb.append("&c=");
|
||||
}
|
||||
|
||||
progress = Methods.formatText(sb.toString());
|
||||
} else {
|
||||
progress = getLocale().getMessage("general.hologram.outoffuel").getMessage();
|
||||
}
|
||||
|
||||
int inAmt = 0;
|
||||
int outAmt = 0;
|
||||
if (furnaceBlock.getInventory().getSmelting() != null) {
|
||||
inAmt = furnaceBlock.getInventory().getSmelting().getAmount();
|
||||
}
|
||||
if (furnaceBlock.getInventory().getResult() != null) {
|
||||
outAmt = furnaceBlock.getInventory().getResult().getAmount();
|
||||
}
|
||||
|
||||
String stats = getLocale().getMessage("general.hologram.stats")
|
||||
.processPlaceholder("in", inAmt)
|
||||
.processPlaceholder("out", Math.min(outAmt, 64)).getMessage();
|
||||
|
||||
return Arrays.asList(progress, stats);
|
||||
}
|
||||
|
||||
private void loadLevelManager() {
|
||||
if (!levelsFile.getFile().exists())
|
||||
this.saveResource("levels.yml", false);
|
||||
|
@ -4,9 +4,8 @@ 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.core.math.MathUtils;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
import com.songoda.epicfurnaces.boost.BoostData;
|
||||
import com.songoda.epicfurnaces.furnace.levels.Level;
|
||||
@ -40,13 +39,9 @@ import java.util.UUID;
|
||||
* Created by songoda on 3/7/2017.
|
||||
*/
|
||||
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();
|
||||
private final String hologramId = UUID.randomUUID().toString();
|
||||
|
||||
// Identifier for database use.
|
||||
private int id;
|
||||
@ -410,14 +405,6 @@ public class Furnace {
|
||||
}
|
||||
|
||||
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());
|
||||
return this.hologramId;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.epicfurnaces.listeners;
|
||||
|
||||
import com.songoda.core.hooks.HologramManager;
|
||||
import com.songoda.core.utils.PlayerUtils;
|
||||
import com.songoda.epicfurnaces.EpicFurnaces;
|
||||
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.inventory.ItemStack;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -92,7 +94,7 @@ public class BlockListeners implements Listener {
|
||||
plugin.getDataManager().createFurnace(furnace);
|
||||
plugin.getFurnaceManager().addFurnace(furnace);
|
||||
|
||||
furnace.createHologram();
|
||||
plugin.updateHolograms(Collections.singleton(furnace));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@ -130,4 +132,4 @@ public class BlockListeners implements Listener {
|
||||
plugin.getFurnaceManager().removeFurnace(block.getLocation());
|
||||
plugin.getDataManager().deleteFurnace(furnace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user