Added the ability to require more items for levelup.

This commit is contained in:
Brianna 2020-07-15 17:53:53 -05:00
parent c0f0d8ed8e
commit 76b52b4fd8
10 changed files with 122 additions and 61 deletions

View File

@ -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<UUID> usableList = list.stream().map(UUID::fromString).collect(Collectors.toList());
Map<CompatibleMaterial, Integer> toLevel = new HashMap<>();
List<String> 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<CompatibleMaterial, Integer> 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);
}
}

View File

@ -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<CompatibleMaterial, Integer> toLevel = new HashMap<>();
private final List<Location> radiusOverheat = new ArrayList<>();
private final List<Location> radiusFuelshare = new ArrayList<>();
private final List<UUID> 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<CompatibleMaterial, Integer> 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() {

View File

@ -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<CompatibleMaterial, Integer> toLevel) {
for (Map.Entry<CompatibleMaterial, Integer> entry : toLevel.entrySet())
this.furnace.addToLevel(entry.getKey(), entry.getValue());
return this;
}

View File

@ -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<CompatibleMaterial, Integer> materials = new LinkedHashMap<>();
private String reward;
private List<String> 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<CompatibleMaterial, Integer> 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<CompatibleMaterial, Integer> getMaterials() {
return Collections.unmodifiableMap(materials);
}
}

View File

@ -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<Integer, Level> 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<CompatibleMaterial, Integer> materials) {
registeredLevels.put(level, new Level(level, costExperiance, costEconomy, performance, reward, fuelDuration, overheat, fuelShare, materials));
}

View File

@ -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<CompatibleMaterial, Integer> 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());
}
}

View File

@ -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);

View File

@ -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<String> toLevel = new ArrayList<>();
for (Map.Entry<CompatibleMaterial, Integer> 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()));

View File

@ -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%'

View File

@ -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