Skip to content

Commit

Permalink
Merge pull request #824 from TonytheMacaroni/main
Browse files Browse the repository at this point in the history
Allow spaces in magic item costs, fix changing experience
  • Loading branch information
Chronoken authored Dec 21, 2023
2 parents b0b903d + 864bba3 commit bfab821
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
53 changes: 35 additions & 18 deletions core/src/main/java/com/nisovin/magicspells/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit bfab821

Please sign in to comment.