From 5febb15458ca7c6233cd2a8b3d95bf305f8a0a64 Mon Sep 17 00:00:00 2001 From: GB6 Date: Mon, 21 Jan 2019 13:53:01 +0100 Subject: [PATCH] Added the option to not have HolographicDisplays installed. --- core/pom.xml | 6 +++++ .../songoda/epicfurnaces/EpicFurnaces.java | 24 ++++++++++++++----- .../epicfurnaces/managers/FurnaceManager.java | 11 ++++++--- .../epicfurnaces/tasks/HologramTask.java | 2 +- core/src/main/resources/plugin.yml | 4 ++-- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index d3ea45d..7dccda6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -181,5 +181,11 @@ 4.1.0 compile + + com.songoda + craftbukkit-1-13 + 4.1.0 + compile + diff --git a/core/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java b/core/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java index 5d8ceaa..0b9ae7a 100644 --- a/core/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java +++ b/core/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java @@ -5,7 +5,10 @@ import com.songoda.epicfurnaces.command.CommandManager; import com.songoda.epicfurnaces.handlers.BlacklistHandler; import com.songoda.epicfurnaces.hook.CraftBukkitHook; import com.songoda.epicfurnaces.hooks.*; -import com.songoda.epicfurnaces.listeners.*; +import com.songoda.epicfurnaces.listeners.BlockListeners; +import com.songoda.epicfurnaces.listeners.FurnaceListeners; +import com.songoda.epicfurnaces.listeners.InteractListeners; +import com.songoda.epicfurnaces.listeners.InventoryListeners; import com.songoda.epicfurnaces.managers.*; import com.songoda.epicfurnaces.storage.Storage; import com.songoda.epicfurnaces.storage.types.StorageMysql; @@ -32,12 +35,16 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Optional; import static com.songoda.epicfurnaces.utils.StringUtils.formatText; import static java.util.Arrays.asList; @@ -69,6 +76,8 @@ public class EpicFurnaces extends JavaPlugin { return; } + Bukkit.getConsoleSender().sendMessage(formatText("Holographic displays " + (Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays") ? "found, enabling support for holograms!" : "not found, holograms will not work."))); + for (String name : asList("config", "data", "hooks", "blacklist", "Furnace Recipes")) { File file = new File(getDataFolder(), name + ".yml"); if (!file.exists()) { @@ -102,11 +111,14 @@ public class EpicFurnaces extends JavaPlugin { this.boostManager = new BoostManager(this); this.blacklistHandler = new BlacklistHandler(this); this.bukkitEnums = new BukkitEnums(this); - this.hologramManager = new HologramManager(this); this.levelManager = new LevelManager(this); this.hookManager = new HookManager(this); this.economy = getServer().getServicesManager().getRegistration(Economy.class).getProvider(); + if (Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) { + this.hologramManager = new HologramManager(this); + } + checkStorage(); levelManager.loadLevelManager(); setupRecipes(); @@ -154,7 +166,7 @@ public class EpicFurnaces extends JavaPlugin { Bukkit.getConsoleSender().sendMessage(formatText("&7EpicFurnaces " + this.getDescription().getVersion() + " by &5Songoda <3&7!")); Bukkit.getConsoleSender().sendMessage(formatText("&7Action: &cDisabling&7...")); Bukkit.getConsoleSender().sendMessage(formatText("&a=============================")); - hologramManager.clearAll(); + getHologramManager().ifPresent(HologramManager::clearAll); saveToFile(); } @@ -301,8 +313,8 @@ public class EpicFurnaces extends JavaPlugin { return bukkitEnums; } - public HologramManager getHologramManager() { - return hologramManager; + public Optional getHologramManager() { + return Optional.ofNullable(hologramManager); } public HookManager getHookManager() { diff --git a/core/src/main/java/com/songoda/epicfurnaces/managers/FurnaceManager.java b/core/src/main/java/com/songoda/epicfurnaces/managers/FurnaceManager.java index 6d15a3c..a3450f2 100644 --- a/core/src/main/java/com/songoda/epicfurnaces/managers/FurnaceManager.java +++ b/core/src/main/java/com/songoda/epicfurnaces/managers/FurnaceManager.java @@ -26,7 +26,7 @@ public class FurnaceManager { } public FurnaceObject addFurnace(Location location, FurnaceObject furnace) { - instance.getHologramManager().updateHologram(furnace); + instance.getHologramManager().ifPresent(manager -> manager.updateHologram(furnace)); registeredFurnaces.put(roundLocation(location), furnace); return furnace; } @@ -40,7 +40,7 @@ public class FurnaceManager { } public void removeFurnace(Location location) { - instance.getHologramManager().remove(registeredFurnaces.remove(location)); + instance.getHologramManager().ifPresent(manager -> manager.remove(registeredFurnaces.remove(location))); } public Optional getFurnace(Location location) { @@ -118,7 +118,12 @@ public class FurnaceManager { instance.getBoostManager().addBoostToPlayer(boostData); } } - getFurnaces().values().forEach(furnace -> instance.getHologramManager().updateHologram(furnace)); + + if (!instance.getConfig().getBoolean("Main.Furnaces Have Holograms")) { + return; + } + + getFurnaces().values().forEach(furnace -> instance.getHologramManager().ifPresent(manager -> manager.updateHologram(furnace))); } public void saveToFile() { diff --git a/core/src/main/java/com/songoda/epicfurnaces/tasks/HologramTask.java b/core/src/main/java/com/songoda/epicfurnaces/tasks/HologramTask.java index c096afb..2f6058f 100644 --- a/core/src/main/java/com/songoda/epicfurnaces/tasks/HologramTask.java +++ b/core/src/main/java/com/songoda/epicfurnaces/tasks/HologramTask.java @@ -31,6 +31,6 @@ public class HologramTask extends BukkitRunnable { instance.getFurnaceManager().getFurnaces().values().stream() .filter(furnace -> furnace.getLocation() != null && furnace.getLocation().getWorld() != null && furnace.getLocation().getBlock() != null) - .forEach(furnace -> instance.getHologramManager().updateHologram(furnace)); + .forEach(furnace -> instance.getHologramManager().ifPresent(manager -> manager.updateHologram(furnace))); } } diff --git a/core/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml index 6f65003..eb5dc26 100644 --- a/core/src/main/resources/plugin.yml +++ b/core/src/main/resources/plugin.yml @@ -3,8 +3,8 @@ version: ${project.version} main: com.songoda.epicfurnaces.EpicFurnaces authors: [Brianna, GB6] website: https://songoda.com/ -depend: [HolographicDisplays, Vault] -softdepend: [PlotSquared, GriefPrevention, USkyBlock, SkyBlock, WorldGuard, Factions] +depend: [Vault] +softdepend: [PlotSquared, GriefPrevention, USkyBlock, SkyBlock, WorldGuard, Factions, HolographicDisplays] commands: epicfurnaces: description: Default command for the EpicFurnaces plugin.