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