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;
|
||||||
@ -68,8 +68,16 @@ public class FishingListener implements Listener {
|
|||||||
private final int total, exp;
|
private final int total, exp;
|
||||||
|
|
||||||
private int pulls;
|
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 long last = System.currentTimeMillis();
|
||||||
|
|
||||||
|
private static final long TIME_OUT = 1000;
|
||||||
|
|
||||||
public FishingData(Player player, FishHook hook, FishingDropTable table) {
|
public FishingData(Player player, FishHook hook, FishingDropTable table) {
|
||||||
this.location = hook.getLocation();
|
this.location = hook.getLocation();
|
||||||
this.caught = table.getRandomItem();
|
this.caught = table.getRandomItem();
|
||||||
@ -89,19 +97,25 @@ public class FishingListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTimedOut() {
|
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() {
|
public boolean pull() {
|
||||||
last = System.currentTimeMillis();
|
last = System.currentTimeMillis();
|
||||||
return pulls++ > total;
|
return pulls++ > total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Critical fish's means you catch the fish on the very first try
|
||||||
|
*/
|
||||||
public boolean isCrit() {
|
public boolean isCrit() {
|
||||||
return pulls > total + 1;
|
return pulls > total + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
private void close() {
|
||||||
fishing.remove(player.getUniqueId());
|
fishing.remove(player.getUniqueId());
|
||||||
hook.remove();
|
hook.remove();
|
||||||
|
|
||||||
@ -119,12 +133,9 @@ public class FishingListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void a(PlayerFishEvent event) {
|
public void a(PlayerFishEvent event) {
|
||||||
if (event.getPlayer().equals(player) && !player.hasMetadata("NPC")
|
if (event.getPlayer().equals(player) && (event.getState() == State.CAUGHT_FISH || event.getState() == State.FAILED_ATTEMPT || event.getState() == State.REEL_IN)) {
|
||||||
&& (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);
|
event.setCancelled(true);
|
||||||
if (isTimedOut()) {
|
if (isTimedOut()) {
|
||||||
close();
|
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)
|
if (pulls == 0 && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_CHANCE) / 100)
|
||||||
criticalFish();
|
criticalFish();
|
||||||
|
|
||||||
/*
|
// Check if enough pulls; if not, wait till the next fish event
|
||||||
* Checks for enough pulls. if not, return and wait for next
|
|
||||||
* fish event.
|
|
||||||
*/
|
|
||||||
if (!pull())
|
if (!pull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
// The fish is successfully looted from here
|
||||||
* Successfully pulls the fish
|
|
||||||
*/
|
|
||||||
close();
|
close();
|
||||||
|
|
||||||
ItemStack mainhand = player.getInventory().getItem(EquipmentSlot.HAND);
|
ItemStack mainhand = player.getInventory().getItem(EquipmentSlot.HAND);
|
||||||
@ -168,7 +174,7 @@ public class FishingListener implements Listener {
|
|||||||
if (called.isCancelled())
|
if (called.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// calculate velocity
|
// Calculate yeet velocity
|
||||||
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
|
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
|
||||||
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
|
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
|
||||||
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message());
|
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message());
|
||||||
|
Loading…
Reference in New Issue
Block a user