mirror of
https://github.com/songoda/EpicFurnaces.git
synced 2025-02-09 08:01:36 +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) -> {
|
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,76 +266,74 @@ 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;
|
||||||
|
|
||||||
|
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())) {
|
if (!HologramManager.isHologramLoaded(furnace.getHologramId())) {
|
||||||
|
HologramManager.createHologram(furnace.getHologramId(), furnace.getLocation().add(0, .15, 0), hologramLines);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
holograms.put(furnace.getHologramId(), getHologramLines(furnace));
|
holograms.put(furnace.getHologramId(), hologramLines);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update holograms
|
// Update holograms
|
||||||
HologramManager.bulkUpdateHolograms(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() {
|
private void loadLevelManager() {
|
||||||
if (!levelsFile.getFile().exists())
|
if (!levelsFile.getFile().exists())
|
||||||
this.saveResource("levels.yml", false);
|
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.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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
@ -130,4 +132,4 @@ public class BlockListeners implements Listener {
|
|||||||
plugin.getFurnaceManager().removeFurnace(block.getLocation());
|
plugin.getFurnaceManager().removeFurnace(block.getLocation());
|
||||||
plugin.getDataManager().deleteFurnace(furnace);
|
plugin.getDataManager().deleteFurnace(furnace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user