forked from Upstream/mmocore
small cleanup
This commit is contained in:
parent
8e6ac4c716
commit
3cf8886349
@ -2,9 +2,9 @@ package net.Indyuce.mmocore.experience.source;
|
|||||||
|
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
|
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
|
||||||
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
|
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
|
||||||
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
|
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -45,7 +45,7 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
|
|||||||
continue;
|
continue;
|
||||||
if (source.crop && !MythicLib.plugin.getVersion().getWrapper().isCropFullyGrown(event.getBlock()))
|
if (source.crop && !MythicLib.plugin.getVersion().getWrapper().isCropFullyGrown(event.getBlock()))
|
||||||
continue;
|
continue;
|
||||||
if ((!source.playerPlaced) && event.getBlock().hasMetadata("player_placed"))
|
if (!source.playerPlaced && event.getBlock().hasMetadata("player_placed"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (source.matches(data, event.getBlock().getType()))
|
if (source.matches(data, event.getBlock().getType()))
|
||||||
|
@ -4,11 +4,6 @@ import net.Indyuce.mmocore.api.player.PlayerData;
|
|||||||
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
|
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
|
||||||
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
|
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
|
||||||
|
|
||||||
/**
|
|
||||||
* Atrocious API that really needs rewriting
|
|
||||||
*
|
|
||||||
* @author cympe
|
|
||||||
*/
|
|
||||||
public abstract class ExperienceSource<T> {
|
public abstract class ExperienceSource<T> {
|
||||||
private final ExperienceDispenser dispenser;
|
private final ExperienceDispenser dispenser;
|
||||||
|
|
||||||
|
@ -2,13 +2,13 @@ package net.Indyuce.mmocore.listener.profession;
|
|||||||
|
|
||||||
import io.lumine.mythic.lib.version.VersionSound;
|
import io.lumine.mythic.lib.version.VersionSound;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem;
|
|
||||||
import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent;
|
import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent;
|
||||||
import net.Indyuce.mmocore.experience.EXPSource;
|
|
||||||
import net.Indyuce.mmocore.loot.LootBuilder;
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||||
|
import net.Indyuce.mmocore.experience.EXPSource;
|
||||||
|
import net.Indyuce.mmocore.loot.LootBuilder;
|
||||||
|
import net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem;
|
||||||
import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable;
|
import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -34,158 +34,164 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class FishingListener implements Listener {
|
public class FishingListener implements Listener {
|
||||||
private final Set<UUID> fishing = new HashSet<>();
|
private final Set<UUID> fishing = new HashSet<>();
|
||||||
|
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void a(PlayerFishEvent event) {
|
public void a(PlayerFishEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
FishHook hook = event.getHook();
|
FishHook hook = event.getHook();
|
||||||
|
|
||||||
if (event.getState() == State.BITE && !fishing.contains(player.getUniqueId()) && !player.hasMetadata("NPC")) {
|
if (event.getState() == State.BITE && !fishing.contains(player.getUniqueId()) && !player.hasMetadata("NPC")) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks for drop tables. If no drop table, just plain vanilla
|
* Checks for drop tables. If no drop table, just plain vanilla
|
||||||
* fishing OTHERWISE initialize fishing, register other listener.
|
* fishing OTHERWISE initialize fishing, register other listener.
|
||||||
*/
|
*/
|
||||||
FishingDropTable table = MMOCore.plugin.fishingManager.calculateDropTable(player);
|
FishingDropTable table = MMOCore.plugin.fishingManager.calculateDropTable(player);
|
||||||
if (table == null)
|
if (table == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
new FishingData(player, hook, table);
|
new FishingData(player, hook, table);
|
||||||
MMOCoreUtils.displayIndicator(hook.getLocation().add(0, 1.25, 0), MMOCore.plugin.configManager.getSimpleMessage("caught-fish").message());
|
MMOCoreUtils.displayIndicator(hook.getLocation().add(0, 1.25, 0), MMOCore.plugin.configManager.getSimpleMessage("caught-fish").message());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FishingData extends BukkitRunnable implements Listener {
|
public class FishingData extends BukkitRunnable implements Listener {
|
||||||
private final Location location;
|
private final Location location;
|
||||||
private final FishingDropItem caught;
|
private final FishingDropItem caught;
|
||||||
private final PlayerData playerData;
|
private final PlayerData playerData;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final FishHook hook;
|
private final FishHook hook;
|
||||||
|
|
||||||
private final int total, exp;
|
private final int total, exp;
|
||||||
|
|
||||||
private int pulls;
|
private int pulls;
|
||||||
private long last = System.currentTimeMillis();
|
|
||||||
|
|
||||||
public FishingData(Player player, FishHook hook, FishingDropTable table) {
|
/**
|
||||||
this.location = hook.getLocation();
|
* Used to track the last time the player swung the fishing rod.
|
||||||
this.caught = table.getRandomItem();
|
* If the player does not swing the rod at least once every second,
|
||||||
this.playerData = PlayerData.get(this.player = player);
|
* the fish will go away and drops will be lost.
|
||||||
this.hook = hook;
|
*/
|
||||||
|
private long last = System.currentTimeMillis();
|
||||||
|
|
||||||
this.total = (int) (caught.rollTugs() * (1 - PlayerData.get(player).getStats().getStat(StatType.FISHING_STRENGTH) / 100));
|
private static final long TIME_OUT = 1000;
|
||||||
this.exp = caught.rollExperience();
|
|
||||||
|
|
||||||
fishing.add(player.getUniqueId());
|
public FishingData(Player player, FishHook hook, FishingDropTable table) {
|
||||||
runTaskTimer(MMOCore.plugin, 0, 2);
|
this.location = hook.getLocation();
|
||||||
Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin);
|
this.caught = table.getRandomItem();
|
||||||
}
|
this.playerData = PlayerData.get(this.player = player);
|
||||||
|
this.hook = hook;
|
||||||
|
|
||||||
public void criticalFish() {
|
this.total = (int) (caught.rollTugs() * (1 - PlayerData.get(player).getStats().getStat(StatType.FISHING_STRENGTH) / 100));
|
||||||
pulls = total + 2;
|
this.exp = caught.rollExperience();
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTimedOut() {
|
fishing.add(player.getUniqueId());
|
||||||
return last + 1000 < System.currentTimeMillis();
|
runTaskTimer(MMOCore.plugin, 0, 2);
|
||||||
}
|
Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean pull() {
|
public void criticalFish() {
|
||||||
last = System.currentTimeMillis();
|
pulls = total + 2;
|
||||||
return pulls++ > total;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCrit() {
|
public boolean isTimedOut() {
|
||||||
return pulls > total + 1;
|
return last + TIME_OUT < System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
/**
|
||||||
fishing.remove(player.getUniqueId());
|
* @return If the fish is weak enough to be looted by the player.
|
||||||
hook.remove();
|
*/
|
||||||
|
public boolean pull() {
|
||||||
|
last = System.currentTimeMillis();
|
||||||
|
return pulls++ > total;
|
||||||
|
}
|
||||||
|
|
||||||
HandlerList.unregisterAll(this);
|
/**
|
||||||
cancel();
|
* Critical fish's means you catch the fish on the very first try
|
||||||
}
|
*/
|
||||||
|
public boolean isCrit() {
|
||||||
|
return pulls > total + 1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
private void close() {
|
||||||
public void run() {
|
fishing.remove(player.getUniqueId());
|
||||||
if (isTimedOut())
|
hook.remove();
|
||||||
close();
|
|
||||||
|
|
||||||
location.getWorld().spawnParticle(Particle.CRIT, location, 0, 2 * (random.nextDouble() - .5), 3, 2 * (random.nextDouble() - .5), .6);
|
HandlerList.unregisterAll(this);
|
||||||
}
|
cancel();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@Override
|
||||||
public void a(PlayerFishEvent event) {
|
public void run() {
|
||||||
if (event.getPlayer().equals(player) && !player.hasMetadata("NPC")
|
if (isTimedOut())
|
||||||
&& (event.getState() == State.CAUGHT_FISH || event.getState() == State.FAILED_ATTEMPT || event.getState() == State.REEL_IN)) {
|
close();
|
||||||
|
|
||||||
/*
|
location.getWorld().spawnParticle(Particle.CRIT, location, 0, 2 * (random.nextDouble() - .5), 3, 2 * (random.nextDouble() - .5), .6);
|
||||||
* Lose the catch if the current fish is gone!
|
}
|
||||||
*/
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (isTimedOut()) {
|
|
||||||
close();
|
|
||||||
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, hook.getLocation(), 16, 0, 0, 0, .1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pulls == 0 && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_CHANCE) / 100)
|
@EventHandler
|
||||||
criticalFish();
|
public void a(PlayerFishEvent event) {
|
||||||
|
if (event.getPlayer().equals(player) && (event.getState() == State.CAUGHT_FISH || event.getState() == State.FAILED_ATTEMPT || event.getState() == State.REEL_IN)) {
|
||||||
|
|
||||||
/*
|
// Lose the catch if the current fish is gone!
|
||||||
* Checks for enough pulls. if not, return and wait for next
|
event.setCancelled(true);
|
||||||
* fish event.
|
if (isTimedOut()) {
|
||||||
*/
|
close();
|
||||||
if (!pull())
|
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, hook.getLocation(), 16, 0, 0, 0, .1);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
if (pulls == 0 && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_CHANCE) / 100)
|
||||||
* Successfully pulls the fish
|
criticalFish();
|
||||||
*/
|
|
||||||
close();
|
|
||||||
|
|
||||||
ItemStack mainhand = player.getInventory().getItem(EquipmentSlot.HAND);
|
// Check if enough pulls; if not, wait till the next fish event
|
||||||
MMOCoreUtils.decreaseDurability(player,
|
if (!pull())
|
||||||
(mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND, 1);
|
return;
|
||||||
|
|
||||||
if (!isCrit() && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_FAILURE_CHANCE) / 100) {
|
// The fish is successfully looted from here
|
||||||
player.setVelocity(hook.getLocation().subtract(player.getLocation()).toVector().setY(0).multiply(3).setY(.5));
|
close();
|
||||||
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack collect = caught.collect(new LootBuilder(playerData, 0));
|
ItemStack mainhand = player.getInventory().getItem(EquipmentSlot.HAND);
|
||||||
if (collect == null) {
|
MMOCoreUtils.decreaseDurability(player,
|
||||||
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
|
(mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND, 1);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomPlayerFishEvent called = new CustomPlayerFishEvent(playerData, collect);
|
if (!isCrit() && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_FAILURE_CHANCE) / 100) {
|
||||||
Bukkit.getPluginManager().callEvent(called);
|
player.setVelocity(hook.getLocation().subtract(player.getLocation()).toVector().setY(0).multiply(3).setY(.5));
|
||||||
if (called.isCancelled())
|
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// calculate velocity
|
ItemStack collect = caught.collect(new LootBuilder(playerData, 0));
|
||||||
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
|
if (collect == null) {
|
||||||
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
|
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message());
|
return;
|
||||||
Vector vec = player.getLocation().subtract(hook.getLocation()).toVector();
|
}
|
||||||
vec.setY(vec.getY() * .031 + vec.length() * .05);
|
|
||||||
vec.setX(vec.getX() * .08);
|
|
||||||
vec.setZ(vec.getZ() * .08);
|
|
||||||
item.setVelocity(vec);
|
|
||||||
player.getWorld().playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 1, 0);
|
|
||||||
for (int j = 0; j < 16; j++)
|
|
||||||
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (random.nextDouble() - .5), 2,
|
|
||||||
4 * (random.nextDouble() - .5), .05);
|
|
||||||
|
|
||||||
if (MMOCore.plugin.professionManager.has("fishing"))
|
CustomPlayerFishEvent called = new CustomPlayerFishEvent(playerData, collect);
|
||||||
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, EXPSource.FISHING,
|
Bukkit.getPluginManager().callEvent(called);
|
||||||
location);
|
if (called.isCancelled())
|
||||||
}
|
return;
|
||||||
}
|
|
||||||
}
|
// Calculate yeet velocity
|
||||||
|
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
|
||||||
|
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
|
||||||
|
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message());
|
||||||
|
Vector vec = player.getLocation().subtract(hook.getLocation()).toVector();
|
||||||
|
vec.setY(vec.getY() * .031 + vec.length() * .05);
|
||||||
|
vec.setX(vec.getX() * .08);
|
||||||
|
vec.setZ(vec.getZ() * .08);
|
||||||
|
item.setVelocity(vec);
|
||||||
|
player.getWorld().playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 1, 0);
|
||||||
|
for (int j = 0; j < 16; j++)
|
||||||
|
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (random.nextDouble() - .5), 2,
|
||||||
|
4 * (random.nextDouble() - .5), .05);
|
||||||
|
|
||||||
|
if (MMOCore.plugin.professionManager.has("fishing"))
|
||||||
|
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, EXPSource.FISHING,
|
||||||
|
location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user