Removed permanent storage of config value in Woodcutting

This commit is contained in:
bm01 2013-01-30 00:21:34 +01:00
parent 48b0050451
commit 20aa312173
4 changed files with 28 additions and 22 deletions

View File

@ -20,6 +20,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
@ -184,7 +186,7 @@ public class BlockListener implements Listener {
Woodcutting.beginTreeFeller(event); Woodcutting.beginTreeFeller(event);
} }
else { else {
if (Woodcutting.REQUIRES_TOOL) { if (Config.getInstance().getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(heldItem)) { if (ItemChecks.isAxe(heldItem)) {
Woodcutting.beginWoodcutting(player, block); Woodcutting.beginWoodcutting(player, block);
} }
@ -362,9 +364,9 @@ public class BlockListener implements Listener {
miningManager.superBreakerBlockCheck(block); miningManager.superBreakerBlockCheck(block);
} }
} }
else if ((profile.getSkillLevel(SkillType.WOODCUTTING) >= Woodcutting.LEAF_BLOWER_UNLOCK_LEVEL) && BlockChecks.isLeaves(block)) { else if ((profile.getSkillLevel(SkillType.WOODCUTTING) >= AdvancedConfig.getInstance().getLeafBlowUnlockLevel()) && BlockChecks.isLeaves(block)) {
if (SkillTools.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) { if (SkillTools.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
if (Woodcutting.REQUIRES_TOOL) { if (Config.getInstance().getWoodcuttingRequiresTool()) {
if (ItemChecks.isAxe(heldItem)) { if (ItemChecks.isAxe(heldItem)) {
event.setInstaBreak(true); event.setInstaBreak(true);
Woodcutting.beginLeafBlower(player, block); Woodcutting.beginLeafBlower(player, block);

View File

@ -117,7 +117,7 @@ public final class TreeFeller {
treeFellerBlocks.add(block); treeFellerBlocks.add(block);
if (treeFellerBlocks.size() > Woodcutting.TREE_FELLER_THRESHOLD) { if (treeFellerBlocks.size() > Woodcutting.CONFIG.getTreeFellerThreshold()) {
treeFellerReachedThreshold = true; treeFellerReachedThreshold = true;
return; return;
} }

View File

@ -22,18 +22,14 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public final class Woodcutting { public final class Woodcutting {
static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance();
static final Config CONFIG = Config.getInstance();
protected enum ExperienceGainMethod { protected enum ExperienceGainMethod {
DEFAULT, DEFAULT,
TREE_FELLER, TREE_FELLER,
}; };
public static final int DOUBLE_DROP_MAX_LEVEL = AdvancedConfig.getInstance().getMiningDoubleDropMaxLevel();
public static final double DOUBLE_DROP_CHANCE = AdvancedConfig.getInstance().getMiningDoubleDropChance();
public static final int LEAF_BLOWER_UNLOCK_LEVEL = AdvancedConfig.getInstance().getLeafBlowUnlockLevel();
public static final boolean DOUBLE_DROP_DISABLED = Config.getInstance().woodcuttingDoubleDropsDisabled();
public static final int TREE_FELLER_THRESHOLD = Config.getInstance().getTreeFellerThreshold();
public static final boolean REQUIRES_TOOL = Config.getInstance().getWoodcuttingRequiresTool();
private Woodcutting() {} private Woodcutting() {}
/** /**
@ -130,14 +126,17 @@ public final class Woodcutting {
* @param block Block being broken * @param block Block being broken
*/ */
protected static void checkForDoubleDrop(Player player, Block block) { protected static void checkForDoubleDrop(Player player, Block block) {
int chance = (int) ((DOUBLE_DROP_CHANCE / DOUBLE_DROP_MAX_LEVEL) * Users.getProfile(player).getSkillLevel(SkillType.WOODCUTTING)); double configDoubleDropChance = ADVANCED_CONFIG.getWoodcuttingDoubleDropChance();
int configDoubleDropMaxLevel = ADVANCED_CONFIG.getWoodcuttingDoubleDropMaxLevel();
int probability = (int) ((configDoubleDropChance / configDoubleDropMaxLevel) * Users.getProfile(player).getSkillLevel(SkillType.WOODCUTTING));
int activationChance = Misc.calculateActivationChance(Permissions.luckyWoodcutting(player)); int activationChance = Misc.calculateActivationChance(Permissions.luckyWoodcutting(player));
if (chance > DOUBLE_DROP_CHANCE) { if (probability > configDoubleDropChance) {
chance = (int) DOUBLE_DROP_CHANCE; probability = (int) configDoubleDropChance;
} }
if (chance <= Misc.getRandom().nextInt(activationChance)) { if (probability <= Misc.getRandom().nextInt(activationChance)) {
return; return;
} }

View File

@ -1,5 +1,7 @@
package com.gmail.nossr50.skills.woodcutting; package com.gmail.nossr50.skills.woodcutting;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillCommand; import com.gmail.nossr50.skills.SkillCommand;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.SkillType;
@ -27,7 +29,8 @@ public class WoodcuttingCommand extends SkillCommand {
treeFellerLengthEndurance = treeFellerStrings[1]; treeFellerLengthEndurance = treeFellerStrings[1];
//DOUBLE DROPS //DOUBLE DROPS
String[] doubleDropStrings = calculateAbilityDisplayValues(Woodcutting.DOUBLE_DROP_MAX_LEVEL, Woodcutting.DOUBLE_DROP_CHANCE); AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
String[] doubleDropStrings = calculateAbilityDisplayValues(advancedConfig.getWoodcuttingDoubleDropMaxLevel(), advancedConfig.getWoodcuttingDoubleDropChance());
doubleDropChance = doubleDropStrings[0]; doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1]; doubleDropChanceLucky = doubleDropStrings[1];
} }
@ -41,7 +44,7 @@ public class WoodcuttingCommand extends SkillCommand {
@Override @Override
protected boolean effectsHeaderPermissions() { protected boolean effectsHeaderPermissions() {
return (canDoubleDrop && !Woodcutting.DOUBLE_DROP_DISABLED) || canLeafBlow || canTreeFell; return (canDoubleDrop && !Config.getInstance().woodcuttingDoubleDropsDisabled()) || canLeafBlow || canTreeFell;
} }
@Override @Override
@ -56,28 +59,30 @@ public class WoodcuttingCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Woodcutting.Effect.2"), LocaleLoader.getString("Woodcutting.Effect.3") })); player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Woodcutting.Effect.2"), LocaleLoader.getString("Woodcutting.Effect.3") }));
} }
if (canDoubleDrop && !Woodcutting.DOUBLE_DROP_DISABLED) { if (canDoubleDrop && !Config.getInstance().woodcuttingDoubleDropsDisabled()) {
player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Woodcutting.Effect.4"), LocaleLoader.getString("Woodcutting.Effect.5") })); player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Woodcutting.Effect.4"), LocaleLoader.getString("Woodcutting.Effect.5") }));
} }
} }
@Override @Override
protected boolean statsHeaderPermissions() { protected boolean statsHeaderPermissions() {
return (canDoubleDrop && !Woodcutting.DOUBLE_DROP_DISABLED) || canLeafBlow || canTreeFell; return (canDoubleDrop && !Config.getInstance().woodcuttingDoubleDropsDisabled()) || canLeafBlow || canTreeFell;
} }
@Override @Override
protected void statsDisplay() { protected void statsDisplay() {
if (canLeafBlow) { if (canLeafBlow) {
if (skillValue < Woodcutting.LEAF_BLOWER_UNLOCK_LEVEL) { int leafBlowerUnlockLevel = AdvancedConfig.getInstance().getLeafBlowUnlockLevel();
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", new Object[] { LocaleLoader.getString("Woodcutting.Ability.Locked.0", new Object[] { Woodcutting.LEAF_BLOWER_UNLOCK_LEVEL }) }));
if (skillValue < leafBlowerUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", new Object[] { LocaleLoader.getString("Woodcutting.Ability.Locked.0", new Object[] { leafBlowerUnlockLevel }) }));
} }
else { else {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", new Object[] { LocaleLoader.getString("Woodcutting.Ability.0"), LocaleLoader.getString("Woodcutting.Ability.1") })); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template", new Object[] { LocaleLoader.getString("Woodcutting.Ability.0"), LocaleLoader.getString("Woodcutting.Ability.1") }));
} }
} }
if (canDoubleDrop && !Woodcutting.DOUBLE_DROP_DISABLED) { if (canDoubleDrop && !Config.getInstance().woodcuttingDoubleDropsDisabled()) {
if (isLucky) { if (isLucky) {
player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", new Object[] { doubleDropChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { doubleDropChanceLucky })); player.sendMessage(LocaleLoader.getString("Woodcutting.Ability.Chance.DDrop", new Object[] { doubleDropChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { doubleDropChanceLucky }));
} }