From 78b25cc13af178250318d44de9c9caf276643131 Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Wed, 14 Aug 2024 03:20:47 +0800 Subject: [PATCH] anti auto fishing mod --- .../api/mechanic/config/ConfigManager.java | 5 +++ .../api/mechanic/fishing/AntiAutoFishing.java | 44 +++++++++++++++++++ .../fishing/hook/VanillaMechanic.java | 16 ++++++- .../bukkit/config/BukkitConfigManager.java | 2 + core/src/main/resources/config.yml | 2 + gradle.properties | 5 +-- 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/AntiAutoFishing.java diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java index 1004d8cc..561328e3 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/config/ConfigManager.java @@ -107,6 +107,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable { protected Requirement[] autoFishingRequirements; protected boolean enableBag; protected boolean baitAnimation; + protected boolean antiAutoFishingMod; protected List, Integer>> globalEffects; protected ConfigManager(BukkitCustomFishingPlugin plugin) { @@ -218,6 +219,10 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable { return instance.baitAnimation; } + public static boolean antiAutoFishingMod() { + return instance.antiAutoFishingMod; + } + public static List durabilityLore() { return instance.durabilityLore; } diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/AntiAutoFishing.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/AntiAutoFishing.java new file mode 100644 index 00000000..e5b739c8 --- /dev/null +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/AntiAutoFishing.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) <2024> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customfishing.api.mechanic.fishing; + +import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; +import net.momirealms.customfishing.api.BukkitCustomFishingPlugin; +import net.momirealms.customfishing.common.util.RandomUtils; +import net.momirealms.sparrow.heart.SparrowHeart; +import org.bukkit.entity.FishHook; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +public class AntiAutoFishing { + + public static void prevent(Player player, FishHook hook) { + BukkitCustomFishingPlugin.getInstance().debug("Try preventing player " + player.getName() + " from auto fishing"); + BukkitCustomFishingPlugin.getInstance().getSenderFactory().getAudience(player) + .playSound(Sound.sound( + Key.key("minecraft", "entity.fishing_bobber.splash"), + Sound.Source.NEUTRAL, + 0f, + 1f + ), hook.getX(), hook.getY(), hook.getZ()); + double motion = -0.4 * RandomUtils.generateRandomDouble(0.6, 1.0); + SparrowHeart.getInstance().sendClientSideEntityMotion(player, new Vector(0, motion,0), hook.getEntityId()); + SparrowHeart.getInstance().sendClientSideEntityMotion(player, new Vector(0, 0,0), hook.getEntityId()); + } +} diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VanillaMechanic.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VanillaMechanic.java index 485966c2..7ceb9f3c 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VanillaMechanic.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/fishing/hook/VanillaMechanic.java @@ -24,8 +24,10 @@ import net.momirealms.customfishing.api.mechanic.context.Context; import net.momirealms.customfishing.api.mechanic.context.ContextKeys; import net.momirealms.customfishing.api.mechanic.effect.Effect; import net.momirealms.customfishing.api.mechanic.effect.EffectProperties; +import net.momirealms.customfishing.api.mechanic.fishing.AntiAutoFishing; import net.momirealms.customfishing.api.util.EventUtils; import net.momirealms.customfishing.common.plugin.scheduler.SchedulerTask; +import net.momirealms.customfishing.common.util.RandomUtils; import net.momirealms.sparrow.heart.SparrowHeart; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; @@ -79,7 +81,7 @@ public class VanillaMechanic implements HookMechanic { } private void setWaitTime(FishHook hook, Effect effect) { - BukkitCustomFishingPlugin.getInstance().getScheduler().sync().runLater(() -> { + BukkitCustomFishingPlugin.getInstance().getScheduler().sync().run(() -> { if (!ConfigManager.overrideVanillaWaitTime()) { int before = Math.max(hook.getWaitTime(), 0); int after = (int) Math.max(100, before * effect.waitTimeMultiplier() + effect.waitTimeAdder()); @@ -91,7 +93,17 @@ public class VanillaMechanic implements HookMechanic { hook.setWaitTime(after); BukkitCustomFishingPlugin.getInstance().debug("Wait time: " + before + " -> " + after + " ticks"); } - }, 1, hook.getLocation()); + int lureTime = RandomUtils.generateRandomInt(20, 80); + hook.setLureTime(lureTime, lureTime); + if (ConfigManager.antiAutoFishingMod()) { + BukkitCustomFishingPlugin.getInstance().getScheduler().sync().runLater(() -> { + Player player = context.getHolder(); + if (player.isOnline() && hook.isValid()) { + AntiAutoFishing.prevent(player, hook); + } + }, RandomUtils.generateRandomInt(20, hook.getWaitTime() + lureTime - 5), hook.getLocation()); + } + }, hook.getLocation()); } @Override diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java index 7bf39292..47784afa 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/config/BukkitConfigManager.java @@ -218,6 +218,8 @@ public class BukkitConfigManager extends ConfigManager { eventPriority = EventPriority.valueOf(config.getString("other-settings.event-priority", "NORMAL").toUpperCase(Locale.ENGLISH)); + antiAutoFishingMod = config.getBoolean("other-settings.anti-auto-fishing-mod", false); + mechanicRequirements = plugin.getRequirementManager().parseRequirements(config.getSection("mechanics.mechanic-requirements"), true); skipGameRequirements = plugin.getRequirementManager().parseRequirements(config.getSection("mechanics.skip-game-requirements"), true); autoFishingRequirements = plugin.getRequirementManager().parseRequirements(config.getSection("mechanics.auto-fishing-requirements"), true); diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index ea448ec4..bc725f9d 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -394,6 +394,8 @@ mechanics: bait-animation: true # Other settings other-settings: + # Anti auto fishing mod + anti-auto-fishing-mod: false # It's recommended to use MiniMessage format. If you insist on using legacy color code "&", enable the support below. # Disable this would improve performance legacy-color-code-support: true diff --git a/gradle.properties b/gradle.properties index 20207eb7..a209eea9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=2.2.16 -config_version=35 +project_version=2.2.17 +config_version=36 project_group=net.momirealms # Dependency settings @@ -39,7 +39,6 @@ rtag_version=6290733498 jedis_version=5.1.4 exp4j_version=0.4.8 placeholder_api_version=2.11.6 -#invui_version=1.32 vault_version=1.7 guava_version=33.2.0-jre lz4_version=1.8.0