Skip to content

Commit b72c0b4

Browse files
ryanbarlow97claude
andcommitted
fix: skip malformed xp values instead of throwing
XP is now paid after the item drops. An exception there would skip the caller's station cleanup and let the player brand the station again for a second item. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent ba59dc6 commit b72c0b4

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎src/main/java/net/tfminecraft/advancedcrafting/objects/crafting/CraftingStation.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ private void giveXP(Player p) {
278278
Ingredient ingredient = IngredientLoader.getByString(mId); // Assuming you have a method like this
279279
if (ingredient != null && ingredient.getIngredientData().hasXP()) {
280280
String raw = ingredient.getIngredientData().getXP();
281-
xpPerUnit = Double.parseDouble(raw.split("\\(")[1].replace(")", ""));
281+
xpPerUnit = parseXPAmount(raw);
282282
skill = raw.split("\\(")[0]; // Assuming you store "agriculturist" here
283283
}
284284
} else if (type.equalsIgnoreCase("alloy")) {
285285
Alloy alloy = AlloyManager.getAlloyById(mId); // Likewise for alloy
286286
if (alloy != null && alloy.getData().hasXP()) {
287287
String raw = alloy.getData().getXP();
288-
xpPerUnit = Double.parseDouble(raw.split("\\(")[1].replace(")", ""));
288+
xpPerUnit = parseXPAmount(raw);
289289
skill = raw.split("\\(")[0]; // Assuming you store "agriculturist" here
290290
}
291291
}
@@ -307,6 +307,16 @@ private void giveXP(Player p) {
307307
}
308308

309309

310+
// XP is paid after the item drops, so a bad value must not throw and leave the station uncleared.
311+
private double parseXPAmount(String raw) {
312+
try {
313+
return Double.parseDouble(raw.split("\\(")[1].replace(")", ""));
314+
} catch (RuntimeException e) {
315+
Bukkit.getLogger().warning("AC: Invalid xp value '" + raw + "', expected skill(amount)");
316+
return 0.0;
317+
}
318+
}
319+
310320
private boolean checkItems(Player p) {
311321
boolean complete = true;
312322
for(IngredientType t : types.keySet()) {

0 commit comments

Comments
 (0)