From 1b69e4c648642215069a5015c676f0e179201e34 Mon Sep 17 00:00:00 2001 From: Fernando Pettinelli Date: Thu, 25 Feb 2021 14:18:11 -0300 Subject: [PATCH] Added "Allow Normal Furnaces" option. --- .../java/com/songoda/epicfurnaces/EpicFurnaces.java | 7 +++++++ .../songoda/epicfurnaces/furnace/FurnaceManager.java | 3 ++- .../songoda/epicfurnaces/listeners/BlockListeners.java | 10 ++++++++++ .../epicfurnaces/listeners/FurnaceListeners.java | 5 ++++- .../epicfurnaces/listeners/InteractListeners.java | 10 ++++++++-- .../epicfurnaces/listeners/InventoryListeners.java | 7 +++++-- .../com/songoda/epicfurnaces/settings/Settings.java | 4 ++++ 7 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java b/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java index d403dd8..6de341f 100644 --- a/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java +++ b/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java @@ -391,6 +391,13 @@ public class EpicFurnaces extends SongodaPlugin { } } + public boolean isLeveledFurnace(ItemStack itemStack) { + NBTCore nbt = NmsManager.getNbt(); + NBTItem nbtItem = nbt.of(itemStack); + + return nbtItem.has("level") && nbtItem.has("uses"); + } + public ItemStack createLeveledFurnace(Material material, int level, int uses) { ItemStack item = new ItemStack(material, 1); diff --git a/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceManager.java b/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceManager.java index ca2dfe5..cca60c5 100644 --- a/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceManager.java +++ b/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceManager.java @@ -2,6 +2,7 @@ package com.songoda.epicfurnaces.furnace; import com.google.common.collect.Multimap; import com.google.common.collect.MultimapBuilder; +import com.songoda.epicfurnaces.settings.Settings; import com.songoda.epicfurnaces.utils.GameArea; import org.bukkit.Location; import org.bukkit.block.Block; @@ -36,7 +37,7 @@ public class FurnaceManager { } public Furnace getFurnace(Location location) { - if (!registeredFurnaces.containsKey(location)) { + if (!Settings.ALLOW_NORMAL_FURNACES.getBoolean() && !registeredFurnaces.containsKey(location)) { addFurnace(new FurnaceBuilder(location).build()); } return registeredFurnaces.get(location); diff --git a/src/main/java/com/songoda/epicfurnaces/listeners/BlockListeners.java b/src/main/java/com/songoda/epicfurnaces/listeners/BlockListeners.java index e1b7ba6..b84e9b4 100644 --- a/src/main/java/com/songoda/epicfurnaces/listeners/BlockListeners.java +++ b/src/main/java/com/songoda/epicfurnaces/listeners/BlockListeners.java @@ -3,6 +3,7 @@ package com.songoda.epicfurnaces.listeners; import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.furnace.Furnace; import com.songoda.epicfurnaces.furnace.FurnaceBuilder; +import com.songoda.epicfurnaces.settings.Settings; import com.songoda.epicfurnaces.utils.GameArea; import org.bukkit.Location; import org.bukkit.Material; @@ -57,6 +58,10 @@ public class BlockListeners implements Listener { ItemStack item = event.getItemInHand(); + if (!plugin.isLeveledFurnace(item) && Settings.ALLOW_NORMAL_FURNACES.getBoolean()) { + return; + } + Location location = event.getBlock().getLocation(); Furnace furnace = event.getItemInHand().getItemMeta().hasDisplayName() && plugin.getFurnaceLevel(item) != 1 @@ -83,6 +88,11 @@ public class BlockListeners implements Listener { return; Furnace furnace = plugin.getFurnaceManager().getFurnace(block); + + if (furnace == null) { + return; + } + int level = plugin.getFurnaceManager().getFurnace(block).getLevel().getLevel(); plugin.clearHologram(furnace); diff --git a/src/main/java/com/songoda/epicfurnaces/listeners/FurnaceListeners.java b/src/main/java/com/songoda/epicfurnaces/listeners/FurnaceListeners.java index dd2c533..6d7ec13 100644 --- a/src/main/java/com/songoda/epicfurnaces/listeners/FurnaceListeners.java +++ b/src/main/java/com/songoda/epicfurnaces/listeners/FurnaceListeners.java @@ -36,8 +36,11 @@ public class FurnaceListeners implements Listener { @EventHandler public void onFuel(FurnaceBurnEvent event) { Furnace furnace = plugin.getFurnaceManager().getFurnace(event.getBlock().getLocation()); + if (furnace == null) { + return; + } - Level level = furnace != null ? furnace.getLevel() : plugin.getLevelManager().getLowestLevel(); + Level level = furnace.getLevel(); if (level.getFuelDuration() != 0) return; diff --git a/src/main/java/com/songoda/epicfurnaces/listeners/InteractListeners.java b/src/main/java/com/songoda/epicfurnaces/listeners/InteractListeners.java index 1e65e6e..a4022bd 100644 --- a/src/main/java/com/songoda/epicfurnaces/listeners/InteractListeners.java +++ b/src/main/java/com/songoda/epicfurnaces/listeners/InteractListeners.java @@ -2,6 +2,7 @@ package com.songoda.epicfurnaces.listeners; import com.songoda.core.gui.GuiManager; import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.furnace.Furnace; import com.songoda.skyblock.SkyBlock; import org.bukkit.Bukkit; import org.bukkit.block.Block; @@ -52,9 +53,14 @@ public class InteractListeners implements Listener { return; } - + + Furnace furnace = plugin.getFurnaceManager().getFurnace(block.getLocation()); + if (furnace == null) { + return; + } + event.setCancelled(true); - plugin.getFurnaceManager().getFurnace(block.getLocation()).overview(guiManager, player); + furnace.overview(guiManager, player); } } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicfurnaces/listeners/InventoryListeners.java b/src/main/java/com/songoda/epicfurnaces/listeners/InventoryListeners.java index 597c404..e209784 100644 --- a/src/main/java/com/songoda/epicfurnaces/listeners/InventoryListeners.java +++ b/src/main/java/com/songoda/epicfurnaces/listeners/InventoryListeners.java @@ -1,6 +1,7 @@ package com.songoda.epicfurnaces.listeners; import com.songoda.epicfurnaces.EpicFurnaces; +import com.songoda.epicfurnaces.furnace.Furnace; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -29,8 +30,10 @@ public class InventoryListeners implements Listener { || event.getDestination().getItem(0).getAmount() != 1) { return; } - plugin.getFurnaceManager().getFurnace(((org.bukkit.block.Furnace) - event.getDestination().getHolder()).getLocation()).updateCook(); + Furnace furnace = plugin.getFurnaceManager().getFurnace(((org.bukkit.block.Furnace) + event.getDestination().getHolder()).getLocation()); + if (furnace != null) + furnace.updateCook(); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/songoda/epicfurnaces/settings/Settings.java b/src/main/java/com/songoda/epicfurnaces/settings/Settings.java index ece6a38..fd3f41c 100644 --- a/src/main/java/com/songoda/epicfurnaces/settings/Settings.java +++ b/src/main/java/com/songoda/epicfurnaces/settings/Settings.java @@ -54,6 +54,10 @@ public class Settings { public static final ConfigSetting CUSTOM_RECIPES = new ConfigSetting(config, "Main.Use Custom Recipes", true); public static final ConfigSetting NO_REWARDS_FROM_RECIPES = new ConfigSetting(config, "Main.No Rewards From Custom Recipes", true); + public static final ConfigSetting ALLOW_NORMAL_FURNACES = new ConfigSetting(config, "Main.Allow Normal Furnaces", false, + "Should normal furnaces not be converted into", + "Epic Furnaces?"); + public static final ConfigSetting PARTICLE_TYPE = new ConfigSetting(config, "Main.Upgrade Particle Type", "SPELL_WITCH", "The type of particle shown when a furnace is upgraded.");