Expanding fishing exploit options

This commit is contained in:
nossr50 2019-03-20 14:26:30 -07:00
parent 133dadccec
commit 8f6f0e4a0f
4 changed files with 80 additions and 9 deletions

View File

@ -38,12 +38,16 @@ import com.gmail.nossr50.skills.salvage.salvageables.SimpleSalvageableManager;
import com.gmail.nossr50.util.experience.ExperienceMapManager; import com.gmail.nossr50.util.experience.ExperienceMapManager;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializerCollection;
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers; import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;
import org.bukkit.Material; import org.bukkit.Material;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.UUID;
/** /**
* *
@ -54,6 +58,8 @@ import java.util.HashMap;
*/ */
public final class ConfigManager { public final class ConfigManager {
/* UNLOAD REGISTER */ /* UNLOAD REGISTER */
private ArrayList<Unload> unloadables; private ArrayList<Unload> unloadables;
@ -163,9 +169,25 @@ public final class ConfigManager {
*/ */
/*
List of default serializers for reference
DEFAULT_SERIALIZERS.registerType(TypeToken.of(URI.class), new URISerializer());
DEFAULT_SERIALIZERS.registerType(TypeToken.of(URL.class), new URLSerializer());
DEFAULT_SERIALIZERS.registerType(TypeToken.of(UUID.class), new UUIDSerializer());
DEFAULT_SERIALIZERS.registerPredicate(input -> input.getRawType().isAnnotationPresent(ConfigSerializable.class), new AnnotatedObjectSerializer());
DEFAULT_SERIALIZERS.registerPredicate(NumberSerializer.getPredicate(), new NumberSerializer());
DEFAULT_SERIALIZERS.registerType(TypeToken.of(String.class), new StringSerializer());
DEFAULT_SERIALIZERS.registerType(TypeToken.of(Boolean.class), new BooleanSerializer());
DEFAULT_SERIALIZERS.registerType(new TypeToken<Map<?, ?>>() {}, new MapSerializer());
DEFAULT_SERIALIZERS.registerType(new TypeToken<List<?>>() {}, new ListSerializer());
DEFAULT_SERIALIZERS.registerType(new TypeToken<Enum<?>>() {}, new EnumValueSerializer());
DEFAULT_SERIALIZERS.registerType(TypeToken.of(Pattern.class), new PatternSerializer());
*/
TypeSerializers.getDefaultSerializers().registerType(new TypeToken<Material>() {}, new CustomEnumValueSerializer()); TypeSerializers.getDefaultSerializers().registerType(new TypeToken<Material>() {}, new CustomEnumValueSerializer());
TypeSerializers.getDefaultSerializers().registerType(new TypeToken<PartyFeature>() {}, new CustomEnumValueSerializer()); TypeSerializers.getDefaultSerializers().registerType(new TypeToken<PartyFeature>() {}, new CustomEnumValueSerializer());
mcMMO.p.getLogger().info("Deserializing configs..."); mcMMO.p.getLogger().info("Deserializing configs...");
//TODO: Not sure about the order of MainConfig //TODO: Not sure about the order of MainConfig
//Serialized Configs //Serialized Configs

View File

@ -3,13 +3,17 @@ package com.gmail.nossr50.config.hocon;
import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.config.ConfigConstants;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import ninja.leaping.configurate.ConfigurationOptions; import ninja.leaping.configurate.ConfigurationOptions;
import ninja.leaping.configurate.SimpleConfigurationNode;
import ninja.leaping.configurate.ValueType; import ninja.leaping.configurate.ValueType;
import ninja.leaping.configurate.commented.CommentedConfigurationNode; import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode; import ninja.leaping.configurate.commented.SimpleCommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader; import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.objectmapping.DefaultObjectMapperFactory;
import ninja.leaping.configurate.objectmapping.ObjectMapper; import ninja.leaping.configurate.objectmapping.ObjectMapper;
import ninja.leaping.configurate.objectmapping.ObjectMappingException; import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;
import ninja.leaping.configurate.util.ConfigurationNodeWalker; import ninja.leaping.configurate.util.ConfigurationNodeWalker;
import ninja.leaping.configurate.util.MapFactories;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -63,7 +67,6 @@ public class SerializedConfigLoader<T> {
"\nhttps://mcmmo.org/wiki - Keep in mind the wiki is a WIP and may not have information about everything in mcMMO!"; "\nhttps://mcmmo.org/wiki - Keep in mind the wiki is a WIP and may not have information about everything in mcMMO!";
private static final ConfigurationOptions LOADER_OPTIONS = ConfigurationOptions.defaults().setHeader(CONFIG_HEADER); private static final ConfigurationOptions LOADER_OPTIONS = ConfigurationOptions.defaults().setHeader(CONFIG_HEADER);
private static final String ROOT_NODE_ADDRESS = "mcMMO"; private static final String ROOT_NODE_ADDRESS = "mcMMO";
private final Path path; private final Path path;

View File

@ -7,6 +7,10 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
public class ConfigSectionExploitFishing { public class ConfigSectionExploitFishing {
private static final boolean PREVENT_FISHING_EXPLOITS_DEFAULT = true; private static final boolean PREVENT_FISHING_EXPLOITS_DEFAULT = true;
public static final int OVER_FISHING_LIMIT_DEFAULT = 3;
public static final boolean ADMINS_OVER_FISHING_DEFAULT = true;
public static final float OVER_FISHING_SIZE = 1.0F;
public static final int FISHING_ROD_SPAM_THRESHOLD_MILLISECONDS_DEFAULT = 200;
@Setting(value = "Prevent-Fishing-AFK-Farming", @Setting(value = "Prevent-Fishing-AFK-Farming",
comment = "Prevents many methods for automatically farming Fishing XP." + comment = "Prevents many methods for automatically farming Fishing XP." +
@ -15,7 +19,48 @@ public class ConfigSectionExploitFishing {
"\nDefault value: "+PREVENT_FISHING_EXPLOITS_DEFAULT) "\nDefault value: "+PREVENT_FISHING_EXPLOITS_DEFAULT)
private boolean preventFishingExploits = PREVENT_FISHING_EXPLOITS_DEFAULT; private boolean preventFishingExploits = PREVENT_FISHING_EXPLOITS_DEFAULT;
@Setting(value = "Overfishing-Limit", comment = "How many times a player can fish in the same spot before it becomes over-fished" +
"\nOver fishing is in place to prevent 99% of AFK fishing from working." +
"\nFishing in a new spot is all it takes to remove over-fishing from your previous location." +
"\nOver-fishing is based on where your fishing bobber actually lands and catches fish, it has nothing to do with where you are standing.")
private int overfishingLimit = OVER_FISHING_LIMIT_DEFAULT;
@Setting(value = "Overfishing-Area-Size-Radius", comment = "Over-Fishing tracks where you've caught fish from by making a bounding box around where your fishing rod's bobber lands." +
"\nThe bounding box starts from the center of your bobber and expands in all directions double the value of this parameter." +
"\nI wouldn't recommend making this value too large or it will be very troublesome for your players to fish." +
"\nA value of 1.0 would result in a bounding box that is 2.0 units (blocks) in size" +
"\nWhen you catch a new fish it makes a new bounding box at that location and checks to see if it overlaps with the bounding box of the last place you caught a fish," +
" if they intersect then that increases your fish counter, if you are at your fishing limit then you get nothing." +
"\nDefault value: "+OVER_FISHING_SIZE)
private float overFishingAreaSize = OVER_FISHING_SIZE;
@Setting(value = "Alert-Admins-To-Overfishing-Abuse", comment = "If someone is triggering over-fishing exploit detection too often, alert admins." +
"\nThis will send a message to ops in game and to the console, and to anyone with the admin chat permission node.")
private boolean alertAdminsOnOverFishing = ADMINS_OVER_FISHING_DEFAULT;
@Setting(value = "Fishing-Rod-Spam-Threshold-In-Milliseconds", comment = "How many milliseconds in between casting the fishing rod before a player suffers from fatigue." +
"\nFatigue causes a loss of 1 hunger and 5 durability damage to the currently held fishing rod." +
"\nThis is to prevent exploits for fishing that involve rapid fire auto clickers." +
"\nDefault value: "+FISHING_ROD_SPAM_THRESHOLD_MILLISECONDS_DEFAULT)
private long fishingRodSpamMilliseconds = FISHING_ROD_SPAM_THRESHOLD_MILLISECONDS_DEFAULT;
public long getFishingRodSpamMilliseconds() {
return fishingRodSpamMilliseconds;
}
public float getOverFishingAreaSize() {
return overFishingAreaSize;
}
public boolean isPreventFishingExploits() { public boolean isPreventFishingExploits() {
return preventFishingExploits; return preventFishingExploits;
} }
public int getOverfishingLimit() {
return overfishingLimit;
}
public boolean isAlertAdminsOnOverFishing() {
return alertAdminsOnOverFishing;
}
} }

View File

@ -43,22 +43,25 @@ import org.bukkit.util.Vector;
import java.util.*; import java.util.*;
public class FishingManager extends SkillManager { public class FishingManager extends SkillManager {
public static final int FISHING_ROD_CAST_CD_MILLISECONDS = 100;
public static final int OVERFISH_LIMIT = 4; public final long FISHING_ROD_CAST_CD_MILLISECONDS;
private final long FISHING_COOLDOWN_SECONDS = 1000L; public final int OVERFISH_LIMIT;
private long fishingRodCastTimestamp = 0L; private long fishingRodCastTimestamp = 0L;
private long fishHookSpawnTimestamp = 0L; private long fishHookSpawnTimestamp = 0L;
private long lastWarned = 0L; private long lastWarned = 0L;
private long lastWarnedExhaust = 0L; private long lastWarnedExhaust = 0L;
private FishHook fishHookReference;
private BoundingBox lastFishingBoundingBox; private BoundingBox lastFishingBoundingBox;
private Item fishingCatch; private Item fishingCatch;
private Location hookLocation; private Location hookLocation;
private int fishCaughtCounter = 1; private int fishCaughtCounter = 1;
private final float boundingBoxSize;
public FishingManager(McMMOPlayer mcMMOPlayer) { public FishingManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, PrimarySkillType.FISHING); super(mcMMOPlayer, PrimarySkillType.FISHING);
OVERFISH_LIMIT = mcMMO.getConfigManager().getConfigExploitPrevention().getConfigSectionExploitFishing().getOverfishingLimit() + 1;
FISHING_ROD_CAST_CD_MILLISECONDS = mcMMO.getConfigManager().getConfigExploitPrevention().getConfigSectionExploitFishing().getFishingRodSpamMilliseconds();
boundingBoxSize = mcMMO.getConfigManager().getConfigExploitPrevention().getConfigSectionExploitFishing().getOverFishingAreaSize();
} }
public boolean canShake(Entity target) { public boolean canShake(Entity target) {
@ -99,10 +102,8 @@ public class FishingManager extends SkillManager {
return; return;
fishHook.setMetadata(mcMMO.FISH_HOOK_REF_METAKEY, mcMMO.metadataValue); fishHook.setMetadata(mcMMO.FISH_HOOK_REF_METAKEY, mcMMO.metadataValue);
this.fishHookReference = fishHook;
fishHookSpawnTimestamp = System.currentTimeMillis(); fishHookSpawnTimestamp = System.currentTimeMillis();
fishingRodCastTimestamp = System.currentTimeMillis(); fishingRodCastTimestamp = System.currentTimeMillis();
} }
public boolean isFishingTooOften() public boolean isFishingTooOften()
@ -149,8 +150,8 @@ public class FishingManager extends SkillManager {
return sameTarget && fishCaughtCounter >= OVERFISH_LIMIT; return sameTarget && fishCaughtCounter >= OVERFISH_LIMIT;
} }
public static BoundingBox makeBoundingBox(Vector centerOfCastVector) { public BoundingBox makeBoundingBox(Vector centerOfCastVector) {
return BoundingBox.of(centerOfCastVector, 1, 1, 1); return BoundingBox.of(centerOfCastVector, boundingBoxSize, boundingBoxSize, boundingBoxSize);
} }
public void setFishingTarget() { public void setFishingTarget() {