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.api.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
|
||||
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@ -45,7 +45,7 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
|
||||
continue;
|
||||
if (source.crop && !MythicLib.plugin.getVersion().getWrapper().isCropFullyGrown(event.getBlock()))
|
||||
continue;
|
||||
if ((!source.playerPlaced) && event.getBlock().hasMetadata("player_placed"))
|
||||
if (!source.playerPlaced && event.getBlock().hasMetadata("player_placed"))
|
||||
continue;
|
||||
|
||||
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.manager.profession.ExperienceSourceManager;
|
||||
|
||||
/**
|
||||
* Atrocious API that really needs rewriting
|
||||
*
|
||||
* @author cympe
|
||||
*/
|
||||
public abstract class ExperienceSource<T> {
|
||||
private final ExperienceDispenser dispenser;
|
||||
|
||||
|
@ -2,13 +2,13 @@ package net.Indyuce.mmocore.listener.profession;
|
||||
|
||||
import io.lumine.mythic.lib.version.VersionSound;
|
||||
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.experience.EXPSource;
|
||||
import net.Indyuce.mmocore.loot.LootBuilder;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -68,8 +68,16 @@ public class FishingListener implements Listener {
|
||||
private final int total, exp;
|
||||
|
||||
private int pulls;
|
||||
|
||||
/**
|
||||
* Used to track the last time the player swung the fishing rod.
|
||||
* If the player does not swing the rod at least once every second,
|
||||
* the fish will go away and drops will be lost.
|
||||
*/
|
||||
private long last = System.currentTimeMillis();
|
||||
|
||||
private static final long TIME_OUT = 1000;
|
||||
|
||||
public FishingData(Player player, FishHook hook, FishingDropTable table) {
|
||||
this.location = hook.getLocation();
|
||||
this.caught = table.getRandomItem();
|
||||
@ -89,19 +97,25 @@ public class FishingListener implements Listener {
|
||||
}
|
||||
|
||||
public boolean isTimedOut() {
|
||||
return last + 1000 < System.currentTimeMillis();
|
||||
return last + TIME_OUT < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If the fish is weak enough to be looted by the player.
|
||||
*/
|
||||
public boolean pull() {
|
||||
last = System.currentTimeMillis();
|
||||
return pulls++ > total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Critical fish's means you catch the fish on the very first try
|
||||
*/
|
||||
public boolean isCrit() {
|
||||
return pulls > total + 1;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
private void close() {
|
||||
fishing.remove(player.getUniqueId());
|
||||
hook.remove();
|
||||
|
||||
@ -119,12 +133,9 @@ public class FishingListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void a(PlayerFishEvent event) {
|
||||
if (event.getPlayer().equals(player) && !player.hasMetadata("NPC")
|
||||
&& (event.getState() == State.CAUGHT_FISH || event.getState() == State.FAILED_ATTEMPT || event.getState() == State.REEL_IN)) {
|
||||
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!
|
||||
*/
|
||||
// Lose the catch if the current fish is gone!
|
||||
event.setCancelled(true);
|
||||
if (isTimedOut()) {
|
||||
close();
|
||||
@ -135,16 +146,11 @@ public class FishingListener implements Listener {
|
||||
if (pulls == 0 && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_CHANCE) / 100)
|
||||
criticalFish();
|
||||
|
||||
/*
|
||||
* Checks for enough pulls. if not, return and wait for next
|
||||
* fish event.
|
||||
*/
|
||||
// Check if enough pulls; if not, wait till the next fish event
|
||||
if (!pull())
|
||||
return;
|
||||
|
||||
/*
|
||||
* Successfully pulls the fish
|
||||
*/
|
||||
// The fish is successfully looted from here
|
||||
close();
|
||||
|
||||
ItemStack mainhand = player.getInventory().getItem(EquipmentSlot.HAND);
|
||||
@ -168,7 +174,7 @@ public class FishingListener implements Listener {
|
||||
if (called.isCancelled())
|
||||
return;
|
||||
|
||||
// calculate velocity
|
||||
// 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());
|
||||
|
Loading…
Reference in New Issue
Block a user