mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
anti auto fishing mod
This commit is contained in:
@@ -107,6 +107,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable {
|
||||
protected Requirement<Player>[] autoFishingRequirements;
|
||||
protected boolean enableBag;
|
||||
protected boolean baitAnimation;
|
||||
protected boolean antiAutoFishingMod;
|
||||
protected List<TriConsumer<Effect, Context<Player>, 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<String> durabilityLore() {
|
||||
return instance.durabilityLore;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) <2024> <XiaoMoMi>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user