From c37588ace4af4ef4b703a63aef98a3f558a07967 Mon Sep 17 00:00:00 2001 From: TonytheMacaroni Date: Thu, 21 Dec 2023 14:08:56 -0500 Subject: [PATCH 1/2] Fix changing experience --- .../main/java/com/nisovin/magicspells/util/ExperienceUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/nisovin/magicspells/util/ExperienceUtils.java b/core/src/main/java/com/nisovin/magicspells/util/ExperienceUtils.java index df79cccd6..4908d2765 100644 --- a/core/src/main/java/com/nisovin/magicspells/util/ExperienceUtils.java +++ b/core/src/main/java/com/nisovin/magicspells/util/ExperienceUtils.java @@ -45,7 +45,7 @@ public static void setExperience(Player player, int experience) { } public static void changeExp(Player player, int amount) { - int totalExperience = Math.min(getExperience(player) + amount, 0); + int totalExperience = Math.max(getExperience(player) + amount, 0); setExperience(player, totalExperience); } From 864bba3f116a34d2298f1e6403c7b9149b1b3b6f Mon Sep 17 00:00:00 2001 From: TonytheMacaroni Date: Thu, 21 Dec 2023 14:09:14 -0500 Subject: [PATCH 2/2] Allow spaces in magic item costs --- .../java/com/nisovin/magicspells/Spell.java | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/com/nisovin/magicspells/Spell.java b/core/src/main/java/com/nisovin/magicspells/Spell.java index 32a57cff7..18115c261 100644 --- a/core/src/main/java/com/nisovin/magicspells/Spell.java +++ b/core/src/main/java/com/nisovin/magicspells/Spell.java @@ -476,45 +476,62 @@ protected SpellReagents getConfigReagents(String option) { for (String costVal : costList) { try { // Parse cost data - data = costVal.split(" "); + data = costVal.trim().split(" ", 2); switch (data[0].toLowerCase()) { case "health" -> { - if (data.length > 1) reagents.setHealth(Double.parseDouble(data[1])); + reagents.setHealth(Double.parseDouble(data[1])); + continue; } case "mana" -> { - if (data.length > 1) reagents.setMana(Integer.parseInt(data[1])); + reagents.setMana(Integer.parseInt(data[1])); + continue; } case "hunger" -> { - if (data.length > 1) reagents.setHunger(Integer.parseInt(data[1])); + reagents.setHunger(Integer.parseInt(data[1])); + continue; } case "experience" -> { - if (data.length > 1) reagents.setExperience(Integer.parseInt(data[1])); + reagents.setExperience(Integer.parseInt(data[1])); + continue; } case "levels" -> { - if (data.length > 1) reagents.setLevels(Integer.parseInt(data[1])); + reagents.setLevels(Integer.parseInt(data[1])); + continue; } case "durability" -> { - if (data.length > 1) reagents.setDurability(Integer.parseInt(data[1])); + reagents.setDurability(Integer.parseInt(data[1])); + continue; } case "money" -> { - if (data.length > 1) reagents.setMoney(Float.parseFloat(data[1])); + reagents.setMoney(Float.parseFloat(data[1])); + continue; } case "variable" -> { - if (data.length > 2) reagents.addVariable(data[1], Double.parseDouble(data[2])); + String[] variableData = data[1].split(" ", 2); + reagents.addVariable(variableData[0], Double.parseDouble(variableData[1])); + continue; } + } - default -> { - int amount = 1; - if (data.length > 1) amount = Integer.parseInt(data[1]); - MagicItemData itemData = MagicItems.getMagicItemDataFromString(data[0]); - if (itemData == null) { - MagicSpells.error("Failed to process cost value for " + internalName + " spell: " + costVal); - continue; - } - reagents.addItem(new SpellReagents.ReagentItem(itemData, amount)); + int i = costVal.lastIndexOf(' '); + + int amount = 1; + if (i != -1) { + try { + amount = Integer.parseInt(costVal.substring(i + 1)); + } catch (NumberFormatException e) { + i = -1; } } + + MagicItemData itemData = MagicItems.getMagicItemDataFromString(i != -1 ? costVal.substring(0, i) : costVal); + if (itemData == null) { + MagicSpells.error("Failed to process cost value for " + internalName + " spell: " + costVal); + continue; + } + + reagents.addItem(new SpellReagents.ReagentItem(itemData, amount)); } catch (Exception e) { MagicSpells.error("Failed to process cost value for " + internalName + " spell: " + costVal); }