Added the possibility to give vanilla exp with fishing drop items.

This commit is contained in:
Ka0rX 2023-06-24 22:46:45 +01:00
parent 8000bc9b89
commit 9b7d0c35b7
2 changed files with 51 additions and 43 deletions

View File

@ -11,55 +11,63 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class FishingDropItem implements Weighted { public class FishingDropItem implements Weighted {
private final RandomAmount experience, tugs; private final RandomAmount experience, tugs, vanillaExp;
private final DropItem dropItem; private final DropItem dropItem;
public FishingDropItem(MMOLineConfig config) { public FishingDropItem(MMOLineConfig config) {
config.validateKeys("tugs", "experience"); config.validateKeys("tugs", "experience");
tugs = new RandomAmount(config.getString("tugs")); tugs = new RandomAmount(config.getString("tugs"));
experience = new RandomAmount(config.getString("experience")); 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();
}
/** public DropItem getItem() {
* An item cannot have a negative weight. Since drop items have 0 weight return dropItem;
* 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() { public RandomAmount getExperience() {
return dropItem; return experience;
} }
public RandomAmount getExperience() { public RandomAmount getVanillaExp() {
return experience; return vanillaExp;
} }
public RandomAmount getTugs() { public RandomAmount getTugs() {
return tugs; return tugs;
} }
public int rollExperience() { public int rollExperience() {
return experience.calculateInt(); return experience.calculateInt();
} }
public int rollTugs() { public int rollVanillaExp() {
return tugs.calculateInt(); return vanillaExp.calculateInt();
} }
public DropItem getDropItem() { public int rollTugs() {
return dropItem; return tugs.calculateInt();
} }
@Nullable public DropItem getDropItem() {
public ItemStack collect(LootBuilder builder) { return dropItem;
dropItem.collect(builder); }
return builder.getLoot().stream().findAny().orElse(null);
} @Nullable
public ItemStack collect(LootBuilder builder) {
dropItem.collect(builder);
return builder.getLoot().stream().findAny().orElse(null);
}
} }

View File

@ -61,7 +61,7 @@ public class FishingListener implements Listener {
private final Player player; private final Player player;
private final FishHook hook; private final FishHook hook;
private final int fishStrength, experienceDropped; private final int fishStrength, experienceDropped, vanillaExpDropped;
private int currentPulls; 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.fishStrength = (int) Math.floor(caught.rollTugs() * (1 - PlayerData.get(player).getStats().getStat("FISHING_STRENGTH") / 100));
this.experienceDropped = caught.rollExperience(); this.experienceDropped = caught.rollExperience();
this.vanillaExpDropped = caught.rollVanillaExp();
fishing.add(player.getUniqueId()); fishing.add(player.getUniqueId());
runTaskTimer(MMOCore.plugin, 0, 2); runTaskTimer(MMOCore.plugin, 0, 2);
Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin); 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); player.getWorld().playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 1, 0);
for (int j = 0; j < 8; j++) 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); 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()) if (MMOCore.plugin.fishingManager.hasLinkedProfession())
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), experienceDropped, EXPSource.FISHING, location, true); playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), experienceDropped, EXPSource.FISHING, location, true);
} }