From 90d3c49c12ca4077ab0247842e13e82adb9aac09 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Thu, 24 Oct 2024 21:59:29 +0200 Subject: [PATCH] Catches a potential error when starting a new session --- .../net/knarcraft/blacksmith/trait/BlacksmithTrait.java | 7 ++++++- .../net/knarcraft/blacksmith/trait/ScrapperTrait.java | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java b/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java index 80bc932..f3980e8 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java @@ -94,7 +94,12 @@ public class BlacksmithTrait extends CustomTrait { //Start a new reforge session for the player currentSessionStartTime = System.currentTimeMillis(); - session = new ReforgeSession(this, player, npc, config); + try { + session = new ReforgeSession(this, player, npc, config); + } catch (IllegalArgumentException exception) { + BlacksmithPlugin.error(exception.getMessage()); + return; + } //Tell the player the cost of repairing the item String cost = EconomyManager.formatBlacksmithCost(player); diff --git a/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java b/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java index 8fef8f3..e8138d9 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java @@ -109,8 +109,13 @@ public class ScrapperTrait extends CustomTrait { //Start a new scrapper session for the player currentSessionStartTime = System.currentTimeMillis(); - session = new SalvageSession(this, player, npc, getSettings(), result.salvage(), - result.salvageMethod(), result.requiredAmount()); + try { + session = new SalvageSession(this, player, npc, getSettings(), result.salvage(), + result.salvageMethod(), result.requiredAmount()); + } catch (IllegalArgumentException exception) { + BlacksmithPlugin.error(exception.getMessage()); + return; + } // Print the cost to the player printCostMessage(player, itemInHand, EconomyManager.formatSalvageCost(result.salvageMethod()), result.salvageMethod());