diff --git a/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java b/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java index f14e73f..8a3084e 100644 --- a/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java +++ b/src/main/java/com/songoda/epicfurnaces/EpicFurnaces.java @@ -40,10 +40,7 @@ import org.bukkit.plugin.PluginManager; import java.io.File; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; public class EpicFurnaces extends SongodaPlugin { @@ -102,8 +99,7 @@ public class EpicFurnaces extends SongodaPlugin { if (Bukkit.getPluginManager().isPluginEnabled("FabledSkyBlock")) { new FabledSkyBlockLoader(); } - - + // Register commands this.commandManager = new CommandManager(this); this.commandManager.addMainCommand("ef") @@ -244,11 +240,18 @@ public class EpicFurnaces extends SongodaPlugin { } List usableList = list.stream().map(UUID::fromString).collect(Collectors.toList()); + Map toLevel = new HashMap<>(); + List toLevelCompiled = row.get("tolevelnew").asStringList(); + for (String line : toLevelCompiled) { + String[] split = line.split(":"); + toLevel.put(CompatibleMaterial.getMaterial(split[0]), Integer.parseInt(split[1])); + } + Furnace furnace = new FurnaceBuilder(location) .setLevel(levelManager.getLevel(row.get("level").asInt())) .setNickname(row.get("nickname").asString()) .setUses(row.get("uses").asInt()) - .setToLevel(row.get("tolevel").asInt()) + .setToLevel(toLevel) .setAccessList(usableList) .setPlacedBy(placedBy).build(); @@ -314,7 +317,15 @@ public class EpicFurnaces extends SongodaPlugin { int overheat = levels.getInt("Overheat"); int fuelShare = levels.getInt("Fuel-share"); - levelManager.addLevel(level, costExperiance, costEconomy, performance, reward, fuelDuration, overheat, fuelShare); + Map materials = new LinkedHashMap<>(); + if (levels.contains("Cost-item")) { + for (String materialStr : levels.getStringList("Cost-item")) { + String[] materialSplit = materialStr.split(":"); + materials.put(CompatibleMaterial.getMaterial(materialSplit[0]), Integer.parseInt(materialSplit[1])); + } + } + + levelManager.addLevel(level, costExperiance, costEconomy, performance, reward, fuelDuration, overheat, fuelShare, materials); } } diff --git a/src/main/java/com/songoda/epicfurnaces/furnace/Furnace.java b/src/main/java/com/songoda/epicfurnaces/furnace/Furnace.java index 2c44a2c..8011c01 100644 --- a/src/main/java/com/songoda/epicfurnaces/furnace/Furnace.java +++ b/src/main/java/com/songoda/epicfurnaces/furnace/Furnace.java @@ -1,5 +1,6 @@ package com.songoda.epicfurnaces.furnace; +import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.gui.GuiManager; import com.songoda.core.hooks.EconomyManager; @@ -34,7 +35,10 @@ public class Furnace { private Level level = plugin.getLevelManager().getLowestLevel(); private String nickname = null; private UUID placedBy = null; - private int uses, tolevel, radiusOverheatLast, radiusFuelshareLast = 0; + private int uses, radiusOverheatLast, radiusFuelshareLast = 0; + + private final Map toLevel = new HashMap<>(); + private final List radiusOverheat = new ArrayList<>(); private final List radiusFuelshare = new ArrayList<>(); private final List accessList = new ArrayList<>(); @@ -57,10 +61,15 @@ public class Furnace { this.uses++; - if (Settings.UPGRADE_COST.getMaterial().matches(event.getResult())) - this.tolevel++; + CompatibleMaterial material = CompatibleMaterial.getMaterial(event.getResult()); + int needed = -1; + + + if (level.getMaterials().containsKey(material)) { + addToLevel(material, 1); + needed = level.getMaterials().get(material) - getToLevel(material); + } - int multi = Settings.LEVEL_MULTIPLIER.getInt(); if (level.getReward() == null) return; @@ -80,13 +89,10 @@ public class Furnace { } } - - int needed = ((multi * level.getLevel()) - tolevel) - 1; - if (Settings.UPGRADE_BY_SMELTING.getBoolean() && needed <= 0 && plugin.getLevelManager().getLevel(level.getLevel() + 1) != null) { - tolevel = 0; + this.toLevel.remove(material); level = plugin.getLevelManager().getLevel(this.level.getLevel() + 1); } @@ -329,12 +335,22 @@ public class Furnace { this.uses = uses; } - public int getTolevel() { - return tolevel; + public int getToLevel(CompatibleMaterial material) { + if (!this.toLevel.containsKey(material)) + return 0; + return this.toLevel.get(material); } - public void setTolevel(int tolevel) { - this.tolevel = tolevel; + public Map getToLevel() { + return Collections.unmodifiableMap(toLevel); + } + + public void addToLevel(CompatibleMaterial material, int amount) { + if (this.toLevel.containsKey(material)) { + this.toLevel.put(material, this.toLevel.get(material) + amount); + return; + } + this.toLevel.put(material, amount); } public int getRadiusOverheatLast() { diff --git a/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceBuilder.java b/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceBuilder.java index f18f270..cf4aca2 100644 --- a/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceBuilder.java +++ b/src/main/java/com/songoda/epicfurnaces/furnace/FurnaceBuilder.java @@ -1,9 +1,11 @@ package com.songoda.epicfurnaces.furnace; +import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.epicfurnaces.furnace.levels.Level; import org.bukkit.Location; import java.util.List; +import java.util.Map; import java.util.UUID; public class FurnaceBuilder { @@ -31,8 +33,9 @@ public class FurnaceBuilder { return this; } - public FurnaceBuilder setToLevel(int toLevel) { - this.furnace.setTolevel(toLevel); + public FurnaceBuilder setToLevel(Map toLevel) { + for (Map.Entry entry : toLevel.entrySet()) + this.furnace.addToLevel(entry.getKey(), entry.getValue()); return this; } diff --git a/src/main/java/com/songoda/epicfurnaces/furnace/levels/Level.java b/src/main/java/com/songoda/epicfurnaces/furnace/levels/Level.java index dd26f5c..7176bec 100644 --- a/src/main/java/com/songoda/epicfurnaces/furnace/levels/Level.java +++ b/src/main/java/com/songoda/epicfurnaces/furnace/levels/Level.java @@ -1,19 +1,21 @@ package com.songoda.epicfurnaces.furnace.levels; +import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.epicfurnaces.EpicFurnaces; -import java.util.ArrayList; -import java.util.List; +import java.util.*; public class Level { private int level, costExperience, costEconomy, performance, fuelDuration, overheat, fuelShare; + private Map materials = new LinkedHashMap<>(); + private String reward; private List description = new ArrayList<>(); - Level(int level, int costExperience, int costEconomy, int performance, String reward, int fuelDuration, int overheat, int fuelShare) { + Level(int level, int costExperience, int costEconomy, int performance, String reward, int fuelDuration, int overheat, int fuelShare, Map materials) { this.level = level; this.costExperience = costExperience; this.costEconomy = costEconomy; @@ -22,6 +24,7 @@ public class Level { this.fuelDuration = fuelDuration; this.overheat = overheat; this.fuelShare = fuelShare; + this.materials = materials; EpicFurnaces plugin = EpicFurnaces.getInstance(); @@ -90,4 +93,8 @@ public class Level { public int getCostEconomy() { return costEconomy; } + + public Map getMaterials() { + return Collections.unmodifiableMap(materials); + } } diff --git a/src/main/java/com/songoda/epicfurnaces/furnace/levels/LevelManager.java b/src/main/java/com/songoda/epicfurnaces/furnace/levels/LevelManager.java index 90a1ddc..283653b 100644 --- a/src/main/java/com/songoda/epicfurnaces/furnace/levels/LevelManager.java +++ b/src/main/java/com/songoda/epicfurnaces/furnace/levels/LevelManager.java @@ -1,5 +1,7 @@ package com.songoda.epicfurnaces.furnace.levels; +import com.songoda.core.compatibility.CompatibleMaterial; + import java.util.Collections; import java.util.Map; import java.util.NavigableMap; @@ -10,8 +12,8 @@ public class LevelManager { private final NavigableMap registeredLevels = new TreeMap<>(); - public void addLevel(int level, int costExperiance, int costEconomy, int performance, String reward, int fuelDuration, int overheat, int fuelShare) { - registeredLevels.put(level, new Level(level, costExperiance, costEconomy, performance, reward, fuelDuration, overheat, fuelShare)); + public void addLevel(int level, int costExperiance, int costEconomy, int performance, String reward, int fuelDuration, int overheat, int fuelShare, Map materials) { + registeredLevels.put(level, new Level(level, costExperiance, costEconomy, performance, reward, fuelDuration, overheat, fuelShare, materials)); } diff --git a/src/main/java/com/songoda/epicfurnaces/gui/GUIOverview.java b/src/main/java/com/songoda/epicfurnaces/gui/GUIOverview.java index 998c278..972d8b5 100644 --- a/src/main/java/com/songoda/epicfurnaces/gui/GUIOverview.java +++ b/src/main/java/com/songoda/epicfurnaces/gui/GUIOverview.java @@ -17,10 +17,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; +import java.util.*; public class GUIOverview extends Gui { @@ -63,7 +60,7 @@ public class GUIOverview extends Gui { setItem(1, 4, GuiUtils.createButtonItem( CompatibleMaterial.getMaterial(furnace.getLocation().getBlock().getType()), plugin.getLocale().getMessage("interface.furnace.currentlevel") - .processPlaceholder("level", level.getLevel()).getMessage(), + .processPlaceholder("level", level.getLevel()).getMessage(), getFurnaceDescription(furnace, level, nextLevel))); // check how many info icons we have to show @@ -91,47 +88,47 @@ public class GUIOverview extends Gui { Settings.PERFORMANCE_ICON.getMaterial(CompatibleMaterial.REDSTONE), plugin.getLocale().getMessage("interface.furnace.performancetitle").getMessage(), plugin.getLocale().getMessage("interface.furnace.performanceinfo") - .processPlaceholder("amount", level.getPerformance()).getMessage().split("\\|"))); + .processPlaceholder("amount", level.getPerformance()).getMessage().split("\\|"))); } if (level.getReward() != null) { setItem(infoIconOrder[num][current++], GuiUtils.createButtonItem( Settings.REWARD_ICON.getMaterial(CompatibleMaterial.GOLDEN_APPLE), plugin.getLocale().getMessage("interface.furnace.rewardtitle").getMessage(), plugin.getLocale().getMessage("interface.furnace.rewardinfo") - .processPlaceholder("amount", level.getReward().split(":")[0].replace("%", "")) - .getMessage().split("\\|"))); + .processPlaceholder("amount", level.getReward().split(":")[0].replace("%", "")) + .getMessage().split("\\|"))); } if (level.getFuelDuration() != 0) { setItem(infoIconOrder[num][current++], GuiUtils.createButtonItem( Settings.FUEL_DURATION_ICON.getMaterial(CompatibleMaterial.COAL), plugin.getLocale().getMessage("interface.furnace.fueldurationtitle").getMessage(), plugin.getLocale().getMessage("interface.furnace.fueldurationinfo") - .processPlaceholder("amount", level.getFuelDuration()) - .getMessage().split("\\|"))); + .processPlaceholder("amount", level.getFuelDuration()) + .getMessage().split("\\|"))); } if (level.getFuelShare() != 0) { setItem(infoIconOrder[num][current++], GuiUtils.createButtonItem( Settings.FUEL_SHARE_ICON.getMaterial(CompatibleMaterial.COAL_BLOCK), plugin.getLocale().getMessage("interface.furnace.fuelsharetitle").getMessage(), plugin.getLocale().getMessage("interface.furnace.fuelshareinfo") - .processPlaceholder("amount", level.getOverheat() * 3) - .getMessage().split("\\|"))); + .processPlaceholder("amount", level.getOverheat() * 3) + .getMessage().split("\\|"))); } if (level.getOverheat() != 0) { setItem(infoIconOrder[num][current++], GuiUtils.createButtonItem( Settings.OVERHEAT_ICON.getMaterial(CompatibleMaterial.FIRE_CHARGE), plugin.getLocale().getMessage("interface.furnace.overheattitle").getMessage(), plugin.getLocale().getMessage("interface.furnace.overheatinfo") - .processPlaceholder("amount", level.getOverheat() * 3) - .getMessage().split("\\|"))); + .processPlaceholder("amount", level.getOverheat() * 3) + .getMessage().split("\\|"))); } - + // remote control if (Settings.REMOTE.getBoolean() && player.hasPermission("EpicFurnaces.Remote")) { setButton(4, GuiUtils.createButtonItem( - CompatibleMaterial.TRIPWIRE_HOOK, - plugin.getLocale().getMessage("interface.furnace.remotefurnace").getMessage(), - getFurnaceRemoteLore(furnace)), + CompatibleMaterial.TRIPWIRE_HOOK, + plugin.getLocale().getMessage("interface.furnace.remotefurnace").getMessage(), + getFurnaceRemoteLore(furnace)), ClickType.LEFT, (event) -> { player.sendMessage(furnace.getNickname() == null ? "Enter a nickname" : furnace.getNickname()); @@ -153,10 +150,10 @@ public class GUIOverview extends Gui { }).setOnClose(this::constructGUI); }).setAction(4, ClickType.RIGHT, (event) -> { - if (!furnace.isOnAccessList(player)) - furnace.addToAccessList(player); - constructGUI(); - }); + if (!furnace.isOnAccessList(player)) + furnace.addToAccessList(player); + constructGUI(); + }); } if (Settings.UPGRADE_WITH_XP.getBoolean() @@ -185,9 +182,9 @@ public class GUIOverview extends Gui { .processPlaceholder("cost", Methods.formatEconomy(nextLevel.getCostEconomy())).getMessage() : plugin.getLocale().getMessage("interface.furnace.alreadymaxed").getMessage()), (event) -> { - furnace.upgrade(player, CostType.ECONOMY); - furnace.overview(guiManager, player); - }); + furnace.upgrade(player, CostType.ECONOMY); + furnace.overview(guiManager, player); + }); } } @@ -212,10 +209,12 @@ public class GUIOverview extends Gui { lore.addAll(nextLevel.getDescription()); if (Settings.UPGRADE_BY_SMELTING.getBoolean()) { - lore.add(plugin.getLocale().getMessage("interface.furnace.tolevel") - .processPlaceholder("amount", (Settings.LEVEL_MULTIPLIER.getInt() * level.getLevel()) - furnace.getTolevel()) - .processPlaceholder("type", Methods.cleanString(Settings.UPGRADE_COST.getString())) - .getMessage()); + lore.add(plugin.getLocale().getMessage("interface.furnace.itemsneeded").getMessage()); + for (Map.Entry entry : level.getMaterials().entrySet()) + lore.add(plugin.getLocale().getMessage("interface.furnace.neededitem") + .processPlaceholder("amount", entry.getValue() - furnace.getToLevel(entry.getKey())) + .processPlaceholder("type", Methods.cleanString(entry.getKey().name())) + .getMessage()); } } diff --git a/src/main/java/com/songoda/epicfurnaces/settings/Settings.java b/src/main/java/com/songoda/epicfurnaces/settings/Settings.java index d6840db..e96ae22 100644 --- a/src/main/java/com/songoda/epicfurnaces/settings/Settings.java +++ b/src/main/java/com/songoda/epicfurnaces/settings/Settings.java @@ -27,8 +27,6 @@ public class Settings { "restarts. With that said it is advised to keep this enabled.", "If however you enjoy living on the edge, feel free to turn it off."); - public static final ConfigSetting LEVEL_MULTIPLIER = new ConfigSetting(config, "Main.Level Cost Multiplier", 50); - public static final ConfigSetting FURNACE_ITEM = new ConfigSetting(config, "Main.Remember Furnace Item Levels", true, "Should furnace levels be remembered when broken?"); @@ -42,7 +40,6 @@ public class Settings { public static final ConfigSetting REDSTONE_DEACTIVATES = new ConfigSetting(config, "Main.Redstone Deactivates Furnaces", true); - public static final ConfigSetting UPGRADE_COST = new ConfigSetting(config, "Main.Furnace Upgrade Cost", "IRON_INGOT"); 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); diff --git a/src/main/java/com/songoda/epicfurnaces/storage/Storage.java b/src/main/java/com/songoda/epicfurnaces/storage/Storage.java index 44a5cf3..8f497f1 100644 --- a/src/main/java/com/songoda/epicfurnaces/storage/Storage.java +++ b/src/main/java/com/songoda/epicfurnaces/storage/Storage.java @@ -1,12 +1,15 @@ package com.songoda.epicfurnaces.storage; +import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.configuration.Config; import com.songoda.epicfurnaces.EpicFurnaces; import com.songoda.epicfurnaces.boost.BoostData; import com.songoda.epicfurnaces.furnace.Furnace; import com.songoda.epicfurnaces.utils.Methods; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; @@ -39,10 +42,14 @@ public abstract class Storage { || furnace.getLevel() == null) continue; String locationStr = Methods.serializeLocation(furnace.getLocation()); + List toLevel = new ArrayList<>(); + for (Map.Entry entry : furnace.getToLevel().entrySet()) + toLevel.add(entry.getKey().name() + ":" + entry.getValue()); + prepareSaveItem("charged", new StorageItem("location", locationStr), new StorageItem("level", furnace.getLevel().getLevel()), new StorageItem("uses", furnace.getUses()), - new StorageItem("tolevel", furnace.getTolevel()), + new StorageItem("tolevelnew", toLevel), new StorageItem("nickname", furnace.getNickname()), new StorageItem("accesslist", furnace.getAccessList().stream().map(UUID::toString).collect(Collectors.toList())), new StorageItem("placedby", furnace.getPlacedBy() == null ? null : furnace.getPlacedBy().toString())); diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang index 851c841..c95e149 100644 --- a/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -36,7 +36,8 @@ interface: rewardinfo: '&7This furnace currently |&7has a &6%amount%%&7 chance of |&7producing multiple resources.' fueldurationinfo: '&7This furnaces fuel duration is |&7currently boosted by &6%amount%%&7. | |&7Fuel Duration boosts how long |&7fuel in the furnace lasts.' smeltedx: '&7Smelted &6%amount% Materials&7.' - tolevel: '&6%amount% %type%s &7away from leveling up.' + itemsneeded: '&7You need one of the following to level up:' + neededitem: '&6%amount% %type%s' remotefurnace: '&5&lRemote Control' remotefurnacelore: '&7Left-Click to assign a nickname.|&7Right-Click to give yourself |&7remote access.|&7Current nickname is: &6%nickname%&7.' utilize: '|&7To utilize remote access|&7use the command:|&6/EF Remote %nickname%' diff --git a/src/main/resources/levels.yml b/src/main/resources/levels.yml index 080587e..23c3625 100644 --- a/src/main/resources/levels.yml +++ b/src/main/resources/levels.yml @@ -1,23 +1,35 @@ Level-1: Performance: 10% Reward: 10%:1 + Cost-item: + - "IRON_INGOT:50" + - "DIAMOND:5" Cost-xp: 20 Cost-eco: 5000 Level-2: Performance: 25% Reward: 20%:1-2 + Cost-item: + - "IRON_INGOT:100" + - "DIAMOND:10" Cost-xp: 25 Cost-eco: 7500 Level-3: Performance: 40% Reward: 35%:2-3 Fuel-duration: 10% + Cost-item: + - "IRON_INGOT:150" + - "DIAMOND:15" Cost-xp: 30 Cost-eco: 10000 Level-4: Performance: 55% Reward: 50%:2-4 Fuel-duration: 25% + Cost-item: + - "IRON_INGOT:200" + - "DIAMOND:20" Cost-xp: 35 Cost-eco: 12000 Level-5: @@ -25,6 +37,9 @@ Level-5: Reward: 70%:3-4 Fuel-duration: 45% Overheat: 1 + Cost-item: + - "IRON_INGOT:250" + - "DIAMOND:25" Cost-xp: 40 Cost-eco: 15000 Level-6: @@ -33,5 +48,8 @@ Level-6: Fuel-duration: 45% Overheat: 2 Fuel-share: 1 + Cost-item: + - "IRON_INGOT:300" + - "DIAMOND:30" Cost-xp: 40 Cost-eco: 15000