From 9b7d0c35b71007c97c66fed1fd483b74515a0ad8 Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Sat, 24 Jun 2023 22:46:45 +0100 Subject: [PATCH] Added the possibility to give vanilla exp with fishing drop items. --- .../mmocore/loot/fishing/FishingDropItem.java | 88 ++++++++++--------- .../listener/profession/FishingListener.java | 6 +- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/fishing/FishingDropItem.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/fishing/FishingDropItem.java index 3cc25cbd..50161246 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/fishing/FishingDropItem.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/fishing/FishingDropItem.java @@ -11,55 +11,63 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; public class FishingDropItem implements Weighted { - private final RandomAmount experience, tugs; - private final DropItem dropItem; + private final RandomAmount experience, tugs, vanillaExp; + private final DropItem dropItem; - public FishingDropItem(MMOLineConfig config) { - config.validateKeys("tugs", "experience"); + public FishingDropItem(MMOLineConfig config) { + config.validateKeys("tugs", "experience"); - tugs = new RandomAmount(config.getString("tugs")); - experience = new RandomAmount(config.getString("experience")); + tugs = new RandomAmount(config.getString("tugs")); + experience = new RandomAmount(config.getString("experience")); + vanillaExp = config.contains("vanilla-exp") ? new RandomAmount(config.getString("vanilla-experience")) : new RandomAmount(0, 0); + dropItem = MMOCore.plugin.loadManager.loadDropItem(config); + } - dropItem = MMOCore.plugin.loadManager.loadDropItem(config); - } + /** + * An item cannot have a negative weight. Since drop items have 0 weight + * by default, MMOCore takes 1 as minimum value if the item weight is + * negative or equal to 0 + */ + @Override + public double getWeight() { + return dropItem.getWeight() <= 0 ? 1 : dropItem.getWeight(); + } - /** - * An item cannot have a negative weight. Since drop items have 0 weight - * by default, MMOCore takes 1 as minimum value if the item weight is - * negative or equal to 0 - */ - @Override - public double getWeight() { - return dropItem.getWeight() <= 0 ? 1 : dropItem.getWeight(); - } + public DropItem getItem() { + return dropItem; + } - public DropItem getItem() { - return dropItem; - } + public RandomAmount getExperience() { + return experience; + } - public RandomAmount getExperience() { - return experience; - } + public RandomAmount getVanillaExp() { + return vanillaExp; + } - public RandomAmount getTugs() { - return tugs; - } + public RandomAmount getTugs() { + return tugs; + } - public int rollExperience() { - return experience.calculateInt(); - } + public int rollExperience() { + return experience.calculateInt(); + } - public int rollTugs() { - return tugs.calculateInt(); - } + public int rollVanillaExp() { + return vanillaExp.calculateInt(); + } - public DropItem getDropItem() { - return dropItem; - } + public int rollTugs() { + return tugs.calculateInt(); + } - @Nullable - public ItemStack collect(LootBuilder builder) { - dropItem.collect(builder); - return builder.getLoot().stream().findAny().orElse(null); - } + public DropItem getDropItem() { + return dropItem; + } + + @Nullable + public ItemStack collect(LootBuilder builder) { + dropItem.collect(builder); + return builder.getLoot().stream().findAny().orElse(null); + } } diff --git a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java index 4dadc341..47e78d5b 100644 --- a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java +++ b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java @@ -61,7 +61,7 @@ public class FishingListener implements Listener { private final Player player; private final FishHook hook; - private final int fishStrength, experienceDropped; + private final int fishStrength, experienceDropped, vanillaExpDropped; private int currentPulls; @@ -82,7 +82,7 @@ public class FishingListener implements Listener { this.fishStrength = (int) Math.floor(caught.rollTugs() * (1 - PlayerData.get(player).getStats().getStat("FISHING_STRENGTH") / 100)); this.experienceDropped = caught.rollExperience(); - + this.vanillaExpDropped = caught.rollVanillaExp(); fishing.add(player.getUniqueId()); runTaskTimer(MMOCore.plugin, 0, 2); Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin); @@ -195,7 +195,7 @@ public class FishingListener implements Listener { player.getWorld().playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 1, 0); for (int j = 0; j < 8; j++) location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (RANDOM.nextDouble() - .5), RANDOM.nextDouble() + 1, 4 * (RANDOM.nextDouble() - .5), .08); - + player.giveExp(vanillaExpDropped); if (MMOCore.plugin.fishingManager.hasLinkedProfession()) playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), experienceDropped, EXPSource.FISHING, location, true); }