mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
2.2.31
This commit is contained in:
@@ -74,6 +74,7 @@ public class CustomFishingHook {
|
||||
private Loot nextLoot;
|
||||
private GamingPlayer gamingPlayer;
|
||||
private BaitAnimationTask baitAnimationTask;
|
||||
private boolean valid = true;
|
||||
|
||||
private static TriFunction<FishHook, Context<Player>, Effect, List<HookMechanic>> mechanicProviders = defaultMechanicProviders();
|
||||
|
||||
@@ -237,10 +238,12 @@ public class CustomFishingHook {
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void stop() {
|
||||
if (task != null) task.cancel();
|
||||
if (hook.isValid()) hook.remove();
|
||||
if (hookMechanic != null) hookMechanic.destroy();
|
||||
if (gamingPlayer != null) gamingPlayer.destroy();
|
||||
if (!this.valid) return;
|
||||
this.valid = false;
|
||||
if (this.task != null) this.task.cancel();
|
||||
if (this.hook.isValid()) this.hook.remove();
|
||||
if (this.hookMechanic != null) hookMechanic.destroy();
|
||||
if (this.gamingPlayer != null) gamingPlayer.destroy();
|
||||
if (this.baitAnimationTask != null) {
|
||||
this.baitAnimationTask.cancel();
|
||||
this.baitAnimationTask = null;
|
||||
@@ -251,7 +254,12 @@ public class CustomFishingHook {
|
||||
* Ends the life of the custom fishing hook.
|
||||
*/
|
||||
public void destroy() {
|
||||
plugin.getFishingManager().destroyHook(context.holder().getUniqueId());
|
||||
// if the hook exists in cache
|
||||
this.plugin.getFishingManager().destroyHook(this.context.holder().getUniqueId());
|
||||
// if not, then destroy the tasks. This should never happen
|
||||
if (this.valid) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +268,7 @@ public class CustomFishingHook {
|
||||
* @return the context.
|
||||
*/
|
||||
public Context<Player> getContext() {
|
||||
return context;
|
||||
return this.context;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,7 +278,7 @@ public class CustomFishingHook {
|
||||
*/
|
||||
@NotNull
|
||||
public FishHook getHookEntity() {
|
||||
return hook;
|
||||
return this.hook;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,7 +312,7 @@ public class CustomFishingHook {
|
||||
|
||||
public boolean isHookValid() {
|
||||
if (hook == null) return false;
|
||||
return hook.isValid();
|
||||
return hook.isValid() && valid;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,6 +449,8 @@ public class CustomFishingHook {
|
||||
*/
|
||||
public void handleFailedFishing() {
|
||||
|
||||
if (!valid) return;
|
||||
|
||||
// update the hook location
|
||||
context.arg(ContextKeys.OTHER_LOCATION, hook.getLocation());
|
||||
context.arg(ContextKeys.OTHER_X, hook.getLocation().getBlockX());
|
||||
@@ -456,6 +466,8 @@ public class CustomFishingHook {
|
||||
*/
|
||||
public void handleSuccessfulFishing() {
|
||||
|
||||
if (!valid) return;
|
||||
|
||||
// update the hook location
|
||||
Location hookLocation = hook.getLocation();
|
||||
context.arg(ContextKeys.OTHER_LOCATION, hookLocation);
|
||||
|
||||
@@ -66,8 +66,8 @@ public abstract class AbstractGamingPlayer implements GamingPlayer, Runnable {
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (task != null) task.cancel();
|
||||
valid = false;
|
||||
if (task != null) task.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -77,17 +77,7 @@ public class BukkitFishingManager implements FishingManager, Listener {
|
||||
|
||||
@Override
|
||||
public Optional<CustomFishingHook> getFishHook(UUID player) {
|
||||
CustomFishingHook hook = castHooks.get(player);
|
||||
if (hook != null) {
|
||||
if (hook.isHookValid()) {
|
||||
return Optional.of(hook);
|
||||
} else {
|
||||
hook.stop();
|
||||
this.castHooks.remove(player);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
return Optional.ofNullable(castHooks.get(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -266,19 +256,19 @@ public class BukkitFishingManager implements FishingManager, Listener {
|
||||
hook.get().onReelIn();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
if (itemStack.getType() != Material.FISHING_ROD) itemStack = player.getInventory().getItemInOffHand();
|
||||
if (plugin.getItemManager().hasCustomMaxDamage(itemStack)) {
|
||||
event.getHook().pullHookedEntity();
|
||||
event.getHook().remove();
|
||||
event.setCancelled(true);
|
||||
event.getHook().pullHookedEntity();
|
||||
hook.get().destroy();
|
||||
plugin.getItemManager().increaseDamage(player, itemStack, event.getCaught() instanceof Item ? 3 : 5, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onReelIn(PlayerFishEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@@ -324,9 +314,13 @@ public class BukkitFishingManager implements FishingManager, Listener {
|
||||
if (EventUtils.fireAndCheckCancel(new RodCastEvent(event, gears))) {
|
||||
return;
|
||||
}
|
||||
plugin.debug(context);
|
||||
plugin.debug(context::toString);
|
||||
CustomFishingHook customHook = new CustomFishingHook(plugin, hook, gears, context);
|
||||
this.castHooks.put(player.getUniqueId(), customHook);
|
||||
CustomFishingHook previous = this.castHooks.put(player.getUniqueId(), customHook);
|
||||
if (previous != null) {
|
||||
plugin.debug("Previous hook is still in cache, which is not an expected behavior");
|
||||
previous.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void onInGround(PlayerFishEvent event) {
|
||||
@@ -377,9 +371,9 @@ public class BukkitFishingManager implements FishingManager, Listener {
|
||||
|
||||
@Override
|
||||
public void destroyHook(UUID uuid) {
|
||||
this.getFishHook(uuid).ifPresent(hook -> {
|
||||
CustomFishingHook hook = this.castHooks.remove(uuid);
|
||||
if (hook != null) {
|
||||
hook.stop();
|
||||
this.castHooks.remove(uuid);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,12 +273,13 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
|
||||
boolean mainOrOff = section.getString("hand","main").equalsIgnoreCase("main");
|
||||
int amount = section.getInt("amount", 1);
|
||||
List<String> items = ListUtils.toList(section.get("item"));
|
||||
boolean any = items.contains("any") || items.contains("*");
|
||||
return context -> {
|
||||
ItemStack itemStack = mainOrOff ?
|
||||
context.holder().getInventory().getItemInMainHand()
|
||||
: context.holder().getInventory().getItemInOffHand();
|
||||
String id = plugin.getItemManager().getItemID(itemStack);
|
||||
if (items.contains(id) && itemStack.getAmount() >= amount) return true;
|
||||
if ((items.contains(id) || any) && itemStack.getAmount() >= amount) return true;
|
||||
if (runActions) ActionManager.trigger(context, actions);
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=2.2.30
|
||||
project_version=2.2.31
|
||||
config_version=36
|
||||
project_group=net.momirealms
|
||||
|
||||
|
||||
Reference in New Issue
Block a user