Improved AFK Acrobatics prevention mechanism

This commit is contained in:
TfT_02 2013-10-25 22:01:49 +02:00
parent 0aea165a8f
commit 7b3fb46a9a
5 changed files with 30 additions and 2 deletions

View File

@ -69,6 +69,7 @@ Version 1.4.07-dev
! Admin and Party chat prefixes are now customizable
! Changed the color of party leader names in Party chat
! Improved "Tree Feller" algorithm (Thanks Riking!)
! Improved AFK Acrobatics prevention mechanism
! Improved profile saving
! Improved partial name matcher
! Improved update checker

View File

@ -430,6 +430,7 @@ public class Config extends AutoUpdateConfigLoader {
/* AFK Leveling */
public boolean getAcrobaticsAFKDisabled() { return config.getBoolean("Skills.Acrobatics.Prevent_AFK_Leveling", true); }
public int getAcrobaticsAFKMaxTries() { return config.getInt("Skills.Acrobatics.Max_Tries_At_Same_Location", 3); }
public boolean getHerbalismAFKDisabled() { return config.getBoolean("Skills.Herbalism.Prevent_AFK_Leveling", true); }
/* Level Caps */

View File

@ -23,7 +23,6 @@ public final class Acrobatics {
public static double featherFallXPModifier = ExperienceConfig.getInstance().getFeatherFallXPModifier();
public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled();
public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled();
private Acrobatics() {};

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
@ -7,6 +8,7 @@ import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
@ -18,6 +20,9 @@ import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class AcrobaticsManager extends SkillManager {
private int fallTries = 0;
Location lastFallLocation;
public AcrobaticsManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.ACROBATICS);
}
@ -25,7 +30,7 @@ public class AcrobaticsManager extends SkillManager {
public boolean canRoll() {
Player player = getPlayer();
return (player.getItemInHand().getType() != Material.ENDER_PEARL) && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player);
return (player.getItemInHand().getType() != Material.ENDER_PEARL) && !exploitPrevention() && Permissions.roll(player);
}
public boolean canDodge(Entity damager) {
@ -93,6 +98,8 @@ public class AcrobaticsManager extends SkillManager {
applyXpGain(calculateRollXP(damage, false));
}
lastFallLocation = player.getLocation();
return damage;
}
@ -118,6 +125,25 @@ public class AcrobaticsManager extends SkillManager {
return damage;
}
public boolean exploitPrevention() {
if (!Config.getInstance().getAcrobaticsAFKDisabled()) {
return false;
}
if (getPlayer().isInsideVehicle()) {
return true;
}
Location fallLocation = getPlayer().getLocation();
boolean sameLocation = (lastFallLocation != null && Misc.isNear(lastFallLocation, fallLocation, 2));
fallTries = sameLocation ? fallTries + 1 : Math.max(fallTries - 1, 0);
lastFallLocation = fallLocation;
return fallTries > Config.getInstance().getAcrobaticsAFKMaxTries();
}
private boolean isSuccessfulRoll(double maxChance, int maxLevel) {
return (maxChance / maxLevel) * Math.min(getSkillLevel(), maxLevel) > Misc.getRandom().nextInt(activationChance);
}

View File

@ -231,6 +231,7 @@ Skills:
Enabled_For_PVP: true
Enabled_For_PVE: true
Prevent_AFK_Leveling: true
Max_Tries_At_Same_Location: 3
Prevent_Dodge_Lightning: false
Prevent_XP_After_Teleport: true
Level_Cap: 0