mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-01 16:19:53 +01:00
BonusDrops (Double/Triple) are now managed by BonusDropManager
This commit is contained in:
parent
ac67e006d8
commit
5c6f0e8cbf
60
src/main/java/com/gmail/nossr50/config/BonusDropManager.java
Normal file
60
src/main/java/com/gmail/nossr50/config/BonusDropManager.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.gmail.nossr50.config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Manages a collection of whitelisted materials for Double Drops
|
||||
*/
|
||||
public class BonusDropManager implements Unload {
|
||||
|
||||
private HashMap<Material, Boolean> bonusDropWhitelist;
|
||||
|
||||
public BonusDropManager()
|
||||
{
|
||||
bonusDropWhitelist = new HashMap<>();
|
||||
|
||||
//Start by setting all Materials to false to avoid null checks
|
||||
for(Material material : Material.values())
|
||||
{
|
||||
registerMaterial(material, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
bonusDropWhitelist.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds materials to the bonus drop whitelist
|
||||
* @param materials target material list
|
||||
*/
|
||||
public void addToWhitelist(List<Material> materials)
|
||||
{
|
||||
for(Material material : materials)
|
||||
{
|
||||
registerMaterial(material, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a material to the bonus drop whitelist
|
||||
* @param material target material
|
||||
*/
|
||||
private void registerMaterial(Material material, boolean isWhitelisted) {
|
||||
bonusDropWhitelist.put(material, isWhitelisted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a material can provide bonus drops
|
||||
* @param material target material
|
||||
* @return true if the material can provide bonus drops
|
||||
*/
|
||||
public boolean isBonusDropWhitelisted(Material material)
|
||||
{
|
||||
return bonusDropWhitelist.get(material);
|
||||
}
|
||||
}
|
@ -78,6 +78,7 @@ public final class ConfigManager {
|
||||
|
||||
private RepairableManager repairableManager;
|
||||
private SalvageableManager salvageableManager;
|
||||
private BonusDropManager bonusDropManager;
|
||||
|
||||
/* MOD MANAGERS */
|
||||
|
||||
@ -89,13 +90,6 @@ public final class ConfigManager {
|
||||
|
||||
private ExperienceMapManager experienceMapManager;
|
||||
|
||||
//private ModManager modManager;
|
||||
|
||||
/*private ToolConfigManager toolConfigManager;
|
||||
private ArmorConfigManager armorConfigManager;
|
||||
private BlockConfigManager blockConfigManager;
|
||||
private EntityConfigManager entityConfigManager;*/
|
||||
|
||||
/* CONFIG INSTANCES */
|
||||
|
||||
private SerializedConfigLoader<ConfigDatabase> configDatabase;
|
||||
@ -147,14 +141,10 @@ public final class ConfigManager {
|
||||
private CoreSkillsConfig coreSkillsConfig;
|
||||
private SoundConfig soundConfig;
|
||||
private RankConfig rankConfig;
|
||||
// private RepairConfig repairConfig;
|
||||
// private SalvageConfig salvageConfig;
|
||||
|
||||
private HashMap<Material, Integer> partyItemWeights;
|
||||
private HashMap<PartyFeature, Integer> partyFeatureUnlocks;
|
||||
|
||||
|
||||
|
||||
/* CONFIG ERRORS */
|
||||
|
||||
private ArrayList<String> configErrors; //Collect errors to whine about to server admins
|
||||
@ -258,6 +248,9 @@ public final class ConfigManager {
|
||||
partyItemWeights = Maps.newHashMap(configParty.getConfig().getPartyItemShare().getItemShareMap()); //Item Share Weights
|
||||
partyFeatureUnlocks = Maps.newHashMap(configParty.getConfig().getPartyXP().getPartyLevel().getPartyFeatureUnlockMap()); //Party Progression
|
||||
|
||||
//Register Bonus Drops
|
||||
registerBonusDrops();
|
||||
|
||||
//YAML Configs
|
||||
mainConfig = new MainConfig();
|
||||
|
||||
@ -278,10 +271,6 @@ public final class ConfigManager {
|
||||
|
||||
rankConfig = new RankConfig();
|
||||
|
||||
// repairConfig = new RepairConfig();
|
||||
|
||||
// salvageConfig = new SalvageConfig();
|
||||
|
||||
/*
|
||||
* Managers
|
||||
*/
|
||||
@ -325,6 +314,10 @@ public final class ConfigManager {
|
||||
// Handles registration of salvageables
|
||||
salvageableManager = new SalvageableManager(getSalvageables());
|
||||
unloadables.add(salvageableManager);
|
||||
|
||||
// Handles registration of bonus drops
|
||||
bonusDropManager = new BonusDropManager();
|
||||
unloadables.add(bonusDropManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -381,6 +374,16 @@ public final class ConfigManager {
|
||||
userFiles.add(userFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers bonus drops from several skill configs
|
||||
*/
|
||||
public void registerBonusDrops()
|
||||
{
|
||||
bonusDropManager.addToWhitelist(configMining.getBonusDrops());
|
||||
bonusDropManager.addToWhitelist(configHerbalism.getBonusDrops());
|
||||
bonusDropManager.addToWhitelist(configWoodcutting.getBonusDrops());
|
||||
}
|
||||
|
||||
/*
|
||||
* GETTER BOILER PLATE
|
||||
*/
|
||||
@ -586,6 +589,15 @@ public final class ConfigManager {
|
||||
return configSalvage.getConfig();
|
||||
}
|
||||
|
||||
public BonusDropManager getBonusDropManager() {
|
||||
return bonusDropManager;
|
||||
}
|
||||
|
||||
public boolean isBonusDropsEnabled(Material material)
|
||||
{
|
||||
return getBonusDropManager().isBonusDropWhitelisted(material);
|
||||
}
|
||||
|
||||
public double getSkillMaxBonusLevel(SubSkillType subSkillType)
|
||||
{
|
||||
return skillPropertiesManager.getMaxBonusLevel(subSkillType);
|
||||
|
@ -181,7 +181,7 @@ public class HerbalismManager extends SkillManager {
|
||||
*/
|
||||
public boolean checkDoubleDrop(BlockState blockState)
|
||||
{
|
||||
return BlockUtils.checkDoubleDrops(getPlayer(), blockState, skill, SubSkillType.HERBALISM_DOUBLE_DROPS);
|
||||
return BlockUtils.checkDoubleDrops(getPlayer(), blockState, SubSkillType.HERBALISM_DOUBLE_DROPS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
@ -38,9 +36,9 @@ public final class BlockUtils {
|
||||
* @param blockState the blockstate
|
||||
* @return true if the player succeeded in the check
|
||||
*/
|
||||
public static boolean checkDoubleDrops(Player player, BlockState blockState, PrimarySkillType skillType, SubSkillType subSkillType)
|
||||
public static boolean checkDoubleDrops(Player player, BlockState blockState, SubSkillType subSkillType)
|
||||
{
|
||||
if(Config.getInstance().getDoubleDropsEnabled(skillType, blockState.getType()) && Permissions.isSubSkillEnabled(player, subSkillType))
|
||||
if(mcMMO.getConfigManager().isBonusDropsEnabled(blockState.getType()) && Permissions.isSubSkillEnabled(player, subSkillType))
|
||||
{
|
||||
return RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType, true));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user