From d47c2cd53371b70aba123b876ec56ee8f17f034e Mon Sep 17 00:00:00 2001 From: asofold Date: Thu, 6 Dec 2012 05:43:30 +0100 Subject: [PATCH] Added MunchHausen check. --- .../nocheatplus/checks/CheckType.java | 1 + .../checks/combined/CombinedConfig.java | 7 ++++ .../checks/combined/CombinedData.java | 1 + .../checks/combined/CombinedListener.java | 12 +++++++ .../checks/combined/MunchHausen.java | 33 +++++++++++++++++++ .../nocheatplus/config/ConfPaths.java | 3 ++ .../nocheatplus/config/DefaultConfig.java | 4 +++ .../nocheatplus/permissions/Permissions.java | 1 + 8 files changed, 62 insertions(+) create mode 100644 src/fr/neatmonster/nocheatplus/checks/combined/MunchHausen.java diff --git a/src/fr/neatmonster/nocheatplus/checks/CheckType.java b/src/fr/neatmonster/nocheatplus/checks/CheckType.java index 139489de..42beec38 100644 --- a/src/fr/neatmonster/nocheatplus/checks/CheckType.java +++ b/src/fr/neatmonster/nocheatplus/checks/CheckType.java @@ -70,6 +70,7 @@ public enum CheckType { COMBINED(CombinedConfig.factory, CombinedData.factory, Permissions.COMBINED), COMBINED_BEDLEAVE(COMBINED, Permissions.COMBINED_BEDLEAVE), COMBINED_IMPROBABLE(COMBINED, Permissions.COMBINED_IMPROBABLE), + COMBINED_MUNCHHAUSEN(COMBINED, Permissions.COMBINED_MUNCHHAUSEN), FIGHT(FightConfig.factory, FightData.factory, Permissions.FIGHT), FIGHT_ANGLE(FIGHT, Permissions.FIGHT_ANGLE), diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java index 97498bd2..acecfa53 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java @@ -63,6 +63,9 @@ public class CombinedConfig extends ACheckConfig { public final int invulnerableModifierDefault; public final boolean invulnerableTriggerAlways; public final boolean invulnerableTriggerFallDistance; + + public final boolean munchHausenCheck; + public final ActionList munchHausenActions; // Last yaw tracking public final float yawRate; @@ -117,6 +120,10 @@ public class CombinedConfig extends ACheckConfig { if (error) LogUtil.logInfo("[NoCheatPlus] Damage causes can be: " + CheckUtils.join(Arrays.asList(DamageCause.values()), ", ")); invulnerableTriggerAlways = config.getBoolean(ConfPaths.COMBINED_INVULNERABLE_TRIGGERS_ALWAYS); invulnerableTriggerFallDistance = config.getBoolean(ConfPaths.COMBINED_INVULNERABLE_TRIGGERS_FALLDISTANCE); + + munchHausenCheck = config.getBoolean(ConfPaths.COMBINED_MUNCHHAUSEN_CHECK); + munchHausenActions = config.getOptimizedActionList(ConfPaths.COMBINED_MUNCHHAUSEN_ACTIONS, Permissions.COMBINED_MUNCHHAUSEN); + yawRate = config.getInt(ConfPaths.COMBINED_YAWRATE_RATE); yawRateImprobable = config.getBoolean(ConfPaths.COMBINED_YAWRATE_IMPROBABLE); yawRatePenaltyFactor = (float) config.getDouble(ConfPaths.COMBINED_YAWRATE_PENALTY_FACTOR); diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java index bac2e050..59d401eb 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java @@ -53,6 +53,7 @@ public class CombinedData extends ACheckData { // VLs public double bedLeaveVL = 0; public double improbableVL = 0; + public double munchHausenVL = 0; // Invulnerable management: /** This is the tick from which on the player is vulnerable again. */ diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java index bea7f502..94f44510 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java @@ -9,6 +9,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; @@ -25,6 +26,8 @@ import fr.neatmonster.nocheatplus.utilities.TickTask; public class CombinedListener extends CheckListener { protected final Improbable improbable; + + protected final MunchHausen munchHausen = new MunchHausen(); public CombinedListener(){ super(CheckType.COMBINED); @@ -101,5 +104,14 @@ public class CombinedListener extends CheckListener { // Check also in case of cancelled events. if (Improbable.check(event.getPlayer(), 0.35f, System.currentTimeMillis())) event.setCancelled(true); } + + @EventHandler(priority=EventPriority.LOWEST) + public void onPlayerFish(final PlayerFishEvent event){ + // Check also in case of cancelled events. + final Player player = event.getPlayer(); + if (munchHausen.isEnabled(player) && munchHausen.checkFish(player, event.getCaught(), event.getState())){ + event.setCancelled(true); + } + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/MunchHausen.java b/src/fr/neatmonster/nocheatplus/checks/combined/MunchHausen.java new file mode 100644 index 00000000..a68debcc --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/checks/combined/MunchHausen.java @@ -0,0 +1,33 @@ +package fr.neatmonster.nocheatplus.checks.combined; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerFishEvent.State; + +import fr.neatmonster.nocheatplus.checks.Check; +import fr.neatmonster.nocheatplus.checks.CheckType; + +/** + * Very, very important check. + * @author mc_dev + * + */ +public class MunchHausen extends Check { + public MunchHausen(){ + super(CheckType.COMBINED_MUNCHHAUSEN); + } + + public boolean checkFish(final Player player, final Entity caught, final State state) { + if (caught == null || !(caught instanceof Player)) return false; + final Player caughtPlayer = (Player) caught; + final CombinedData data = CombinedData.getData(player); + if (player.equals(caughtPlayer)){ + data.munchHausenVL += 1.0; + if (executeActions(player, data.munchHausenVL, 1.0, CombinedConfig.getConfig(player).munchHausenActions)){ + return true; + } + } + else data.munchHausenVL *= 0.96; + return false; + } +} diff --git a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java index 14a0d3f4..5e567920 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -322,6 +322,9 @@ public abstract class ConfPaths { public static final String COMBINED_INVULNERABLE_TRIGGERS_ALWAYS = COMBINED_INVULNERABLE_TRIGGERS + "always"; public static final String COMBINED_INVULNERABLE_TRIGGERS_FALLDISTANCE = COMBINED_INVULNERABLE_TRIGGERS + "falldistance"; + public static final String COMBINED_MUNCHHAUSEN = COMBINED + "munchhausen."; + public static final String COMBINED_MUNCHHAUSEN_CHECK = COMBINED_MUNCHHAUSEN + "active"; + public static final String COMBINED_MUNCHHAUSEN_ACTIONS = COMBINED_MUNCHHAUSEN + "actions"; private static final String COMBINED_YAWRATE = COMBINED + "yawrate."; public static final String COMBINED_YAWRATE_RATE = COMBINED_YAWRATE + "rate"; diff --git a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 9fa52993..449d2bd9 100644 --- a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -253,6 +253,9 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.COMBINED_INVULNERABLE_IGNORE, Arrays.asList("FALL")); set(ConfPaths.COMBINED_INVULNERABLE_MODIFIERS + ".all", 0); + set(ConfPaths.COMBINED_MUNCHHAUSEN_CHECK, false); + set(ConfPaths.COMBINED_MUNCHHAUSEN_ACTIONS, "cancel vl>100 cancel log:munchhausen:0:60:if"); + set(ConfPaths.COMBINED_YAWRATE_RATE , 380); set(ConfPaths.COMBINED_YAWRATE_PENALTY_FACTOR, 1.0); set(ConfPaths.COMBINED_YAWRATE_PENALTY_MIN, 250); @@ -442,6 +445,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.STRINGS + ".kickwb", "ncp kick [player] Block breaking out of sync!"); set(ConfPaths.STRINGS + ".knockback", start + "tried to do a knockback but wasn't technically sprinting" + end); set(ConfPaths.STRINGS + ".morepackets", start + "sent [packets] more packet(s) than expected" + end); + set(ConfPaths.STRINGS + ".munchhausen", start + "almost made it off the pit" + end); set(ConfPaths.STRINGS + ".nofall", start + "tried to avoid fall damage" + end); set(ConfPaths.STRINGS + ".chatfast", start + "acted like spamming (IP: [ip])" + end); set(ConfPaths.STRINGS + ".noswing", start + "didn't swing arm" + end); diff --git a/src/fr/neatmonster/nocheatplus/permissions/Permissions.java b/src/fr/neatmonster/nocheatplus/permissions/Permissions.java index d88f7592..601b0374 100644 --- a/src/fr/neatmonster/nocheatplus/permissions/Permissions.java +++ b/src/fr/neatmonster/nocheatplus/permissions/Permissions.java @@ -122,6 +122,7 @@ public class Permissions { public static final String COMBINED = CHECKS + ".combined"; public static final String COMBINED_BEDLEAVE = COMBINED + ".bedleave"; public static final String COMBINED_IMPROBABLE = COMBINED + ".improbable"; + public static final String COMBINED_MUNCHHAUSEN = COMBINED + ".munchhausen"; /* * 888'Y88 ,e, 888 d8