modified fishing drop item loading

This commit is contained in:
Jules 2022-01-31 20:36:56 +01:00
parent d4f1477bea
commit 62999f1c61
2 changed files with 6 additions and 11 deletions

View File

@ -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"));

View File

@ -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");
}