Wiring up Fishing config values

This commit is contained in:
nossr50 2019-04-10 04:56:59 -07:00
parent 856e6f0447
commit c41a650415
5 changed files with 60 additions and 19 deletions

View File

@ -26,6 +26,7 @@ Version 2.2.0
Expanded settings relating to purging users who have not leveled or users who had not logged in for many months
Acrobatic's Dodge XP increased from 120 -> 480
Fishing's always catch fish setting now defaults to true instead of false
Optimized code related to Fishing
NOTE: Not every config key that was renamed will be listed here
Admins will now be notified if a player trips over-fishing exploit detection 3+ times in a row (Locale: "Fishing.OverFishingDetected")
Note: Admins are players who are op or have adminchat permission.

View File

@ -16,4 +16,12 @@ public class ConfigFishing {
public boolean isAlwaysCatchFish() {
return fishingGeneral.isAlwaysCatchFish();
}
public double getLureLuckModifier() {
return fishingGeneral.getLureLuckModifier();
}
public boolean isOverrideVanillaTreasures() {
return fishingGeneral.isOverrideVanillaTreasures();
}
}

View File

@ -7,12 +7,32 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
public class ConfigFishingGeneral {
private static final boolean ALWAYS_CATCH_FISH_DEFAULT = true;
private static final boolean OVERRIDE_VANILLA_TREASURES = true;
public static final double LURE_MODIFIER_DEFAULT = 4.0D;
@Setting(value = "Always-Catch-Fish", comment = "Enables fish to be caught alongside treasure." +
"\nDefault value: "+ALWAYS_CATCH_FISH_DEFAULT)
private boolean alwaysCatchFish = ALWAYS_CATCH_FISH_DEFAULT;
@Setting(value = "Override-Vanilla-Fishing-Treasures", comment = "When set to true, mcMMO fishing loot tables will be used instead of vanilla." +
"\nIt is recommended you use vanilla mcMMO fishing tables, as they are configurable." +
"\nDefault value: "+OVERRIDE_VANILLA_TREASURES)
private boolean overrideVanillaTreasures = OVERRIDE_VANILLA_TREASURES;
@Setting(value = "Lure-Luck-Modifier", comment = "Lure luck modifier is used to determine how much to" +
" increase drop chance by for fishing rods with the Luck enchantment." +
"\nDefault value: "+LURE_MODIFIER_DEFAULT)
private double lureLuckModifier = LURE_MODIFIER_DEFAULT;
public double getLureLuckModifier() {
return lureLuckModifier;
}
public boolean isAlwaysCatchFish() {
return alwaysCatchFish;
}
public boolean isOverrideVanillaTreasures() {
return overrideVanillaTreasures;
}
}

View File

@ -17,10 +17,13 @@ import java.util.Set;
public final class Fishing {
private static HashMap<Material, List<Enchantment>> ENCHANTABLE_CACHE = new HashMap<>();
private HashMap<Material, List<Enchantment>> enchantableCache = new HashMap<>();
private HashMap<Material, Integer> fishingXpRewardMap;
private static Set<Biome> masterAnglerBiomes = BiomeAdapter.WATER_BIOMES;
private static Set<Biome> iceFishingBiomes = BiomeAdapter.ICE_BIOMES;
private Set<Biome> masterAnglerBiomes = BiomeAdapter.WATER_BIOMES;
private Set<Biome> iceFishingBiomes = BiomeAdapter.ICE_BIOMES;
private final long fishingRodCastCdMilliseconds;
private final int overfishLimit;
private final float boundingBoxSize;
public static Fishing instance;
@ -32,6 +35,9 @@ public final class Fishing {
}
public Fishing() {
overfishLimit = mcMMO.getConfigManager().getConfigExploitPrevention().getOverfishingLimit() + 1;
fishingRodCastCdMilliseconds = mcMMO.getConfigManager().getConfigExploitPrevention().getFishingRodSpamMilliseconds();
boundingBoxSize = mcMMO.getConfigManager().getConfigExploitPrevention().getOverFishingAreaSize();
initFishingXPRewardMap();
}
@ -94,7 +100,7 @@ public final class Fishing {
}
public HashMap<Material, List<Enchantment>> getEnchantableCache() {
return ENCHANTABLE_CACHE;
return enchantableCache;
}
public HashMap<Material, Integer> getFishingXpRewardMap() {
@ -109,9 +115,20 @@ public final class Fishing {
return iceFishingBiomes;
}
public int getFishXPValue(Material material)
{
return fishingXpRewardMap.get(material);
}
public long getFishingRodCastCdMilliseconds() {
return fishingRodCastCdMilliseconds;
}
public int getOverfishLimit() {
return overfishLimit;
}
public float getBoundingBoxSize() {
return boundingBoxSize;
}
}

View File

@ -45,9 +45,6 @@ import java.util.*;
public class FishingManager extends SkillManager {
public final long FISHING_ROD_CAST_CD_MILLISECONDS;
public final int OVERFISH_LIMIT;
private long fishingRodCastTimestamp;
private long fishHookSpawnTimestamp;
private long lastWarned;
@ -55,14 +52,11 @@ public class FishingManager extends SkillManager {
private BoundingBox lastFishingBoundingBox;
private Location hookLocation;
private int fishCaughtCounter;
private final float boundingBoxSize;
private int overFishCount;
public FishingManager(McMMOPlayer mcMMOPlayer) {
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();
fishCaughtCounter = 1;
}
@ -81,7 +75,7 @@ public class FishingManager extends SkillManager {
if(currentTime > fishHookSpawnTimestamp + 1000)
return;
if(currentTime < fishingRodCastTimestamp + FISHING_ROD_CAST_CD_MILLISECONDS)
if(currentTime < fishingRodCastTimestamp + Fishing.getInstance().getFishingRodCastCdMilliseconds())
{
getPlayer().setFoodLevel(Math.max(getPlayer().getFoodLevel() - 1, 0));
getPlayer().getInventory().getItemInMainHand().setDurability((short) (getPlayer().getInventory().getItemInMainHand().getDurability() + 5));
@ -131,6 +125,8 @@ public class FishingManager extends SkillManager {
return false;
}*/
int overfishLimit = Fishing.getInstance().getOverfishLimit();
BoundingBox newCastBoundingBox = makeBoundingBox(centerOfCastVector);
boolean sameTarget = lastFishingBoundingBox != null && lastFishingBoundingBox.overlaps(newCastBoundingBox);
@ -140,7 +136,7 @@ public class FishingManager extends SkillManager {
else
fishCaughtCounter = 1;
if(fishCaughtCounter + 1 == OVERFISH_LIMIT)
if(fishCaughtCounter + 1 == overfishLimit)
{
getPlayer().sendMessage(LocaleLoader.getString("Fishing.LowResources"));
}
@ -149,7 +145,7 @@ public class FishingManager extends SkillManager {
if(!sameTarget)
lastFishingBoundingBox = newCastBoundingBox;
if(sameTarget && fishCaughtCounter >= OVERFISH_LIMIT)
if(sameTarget && fishCaughtCounter >= overfishLimit)
{
overFishCount++;
} else
@ -166,10 +162,11 @@ public class FishingManager extends SkillManager {
}
}
return sameTarget && fishCaughtCounter >= OVERFISH_LIMIT;
return sameTarget && fishCaughtCounter >= overfishLimit;
}
public BoundingBox makeBoundingBox(Vector centerOfCastVector) {
double boundingBoxSize = Fishing.getInstance().getBoundingBoxSize();
return BoundingBox.of(centerOfCastVector, boundingBoxSize, boundingBoxSize, boundingBoxSize);
}
@ -330,8 +327,6 @@ public class FishingManager extends SkillManager {
if (mcMMO.getConfigManager().getConfigFishing().isAlwaysCatchFish()) {
Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());
//Add XP from Fish
fishXp+=Fishing.getInstance().getFishXPValue(fishingCatch.getItemStack().getType());
}
fishingCatch.setItemStack(treasureDrop);
@ -463,7 +458,7 @@ public class FishingManager extends SkillManager {
}
// Rather than subtracting luck (and causing a minimum 3% chance for every drop), scale by luck.
diceRoll *= (1.0 - luck * MainConfig.getInstance().getFishingLureModifier() / 100);
diceRoll *= (1.0 - luck * mcMMO.getConfigManager().getConfigFishing().getLureLuckModifier() / 100);
FishingTreasure treasure = null;