From 62999f1c61ed584b132969fab26a1f310f3297cf Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 31 Jan 2022 20:36:56 +0100 Subject: [PATCH] modified fishing drop item loading --- .../droptable/dropitem/fishing/FishingDropItem.java | 4 +--- .../mmocore/manager/profession/FishingManager.java | 13 +++++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/fishing/FishingDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/fishing/FishingDropItem.java index e18c9674..b1754716 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/fishing/FishingDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/fishing/FishingDropItem.java @@ -15,9 +15,7 @@ public class FishingDropItem { private final int weight; - public FishingDropItem(String value) { - MMOLineConfig config = new MMOLineConfig(value); - + public FishingDropItem(MMOLineConfig config) { config.validate("tugs", "experience"); tugs = new RandomAmount(config.getString("tugs")); diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java index 10aecdde..4c400de1 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java @@ -68,10 +68,10 @@ public class FishingManager extends SpecificProfessionManager { for (String str : list) try { - FishingDropItem dropItem = new FishingDropItem(str); + FishingDropItem dropItem = new FishingDropItem(new MMOLineConfig(str)); maxWeight += dropItem.getWeight(); items.add(dropItem); - } catch (IllegalArgumentException | IndexOutOfBoundsException exception) { + } catch (RuntimeException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load item '" + str + "' from fishing drop table '" + id + "': " + exception.getMessage()); } @@ -91,14 +91,11 @@ public class FishingManager extends SpecificProfessionManager { } public FishingDropItem getRandomItem() { - int weight = random.nextInt(maxWeight); + int randomCoefficient = random.nextInt(maxWeight); - for (FishingDropItem item : items) { - weight -= item.getWeight(); - - if (weight <= 0) + for (FishingDropItem item : items) + if ((randomCoefficient -= item.getWeight()) <= 0) return item; - } throw new NullPointerException("Could not find item in drop table"); }