Some of these should not have been blockdata, also this should check age of crops.

This commit is contained in:
t00thpick1 2018-10-09 21:48:47 -04:00
parent 2a43bce849
commit 5663b71387
10 changed files with 104 additions and 95 deletions

View File

@ -1,18 +1,17 @@
package com.gmail.nossr50.config.experience; package com.gmail.nossr50.config.experience;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.block.data.BlockData;
import com.gmail.nossr50.config.AutoUpdateConfigLoader; import com.gmail.nossr50.config.AutoUpdateConfigLoader;
import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.skills.MaterialType; import com.gmail.nossr50.datatypes.skills.MaterialType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage; import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.EntityType;
import java.util.ArrayList;
import java.util.List;
public class ExperienceConfig extends AutoUpdateConfigLoader { public class ExperienceConfig extends AutoUpdateConfigLoader {
private static ExperienceConfig instance; private static ExperienceConfig instance;
@ -218,7 +217,20 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
return config.getInt(wildcardString); return config.getInt(wildcardString);
return 0; return 0;
} }
public boolean isSkillBlock(SkillType skill, Material data)
{
String baseString = "Experience." + StringUtils.getCapitalized(skill.toString()) + ".";
String explicitString = baseString + StringUtils.getExplicitConfigMaterialString(data);
if (config.contains(explicitString))
return true;
String friendlyString = baseString + StringUtils.getFriendlyConfigMaterialString(data);
if (config.contains(friendlyString))
return true;
String wildcardString = baseString + StringUtils.getWildcardConfigMaterialString(data);
return config.contains(wildcardString);
}
public boolean isSkillBlock(SkillType skill, BlockData data) public boolean isSkillBlock(SkillType skill, BlockData data)
{ {
String baseString = "Experience." + StringUtils.getCapitalized(skill.toString()) + "."; String baseString = "Experience." + StringUtils.getCapitalized(skill.toString()) + ".";
@ -229,9 +241,7 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
if (config.contains(friendlyString)) if (config.contains(friendlyString))
return true; return true;
String wildcardString = baseString + StringUtils.getWildcardConfigBlockDataString(data); String wildcardString = baseString + StringUtils.getWildcardConfigBlockDataString(data);
if (config.contains(wildcardString)) return config.contains(wildcardString);
return true;
return false;
} }
/* Acrobatics */ /* Acrobatics */

View File

@ -1,29 +1,27 @@
package com.gmail.nossr50.config.mods; package com.gmail.nossr50.config.mods;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.block.data.BlockData;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.mods.CustomBlock;
public class CustomBlockConfig extends ConfigLoader { public class CustomBlockConfig extends ConfigLoader {
private boolean needsUpdate = false; private boolean needsUpdate = false;
public List<BlockData> customExcavationBlocks = new ArrayList<BlockData>(); public List<Material> customExcavationBlocks = new ArrayList<>();
public List<BlockData> customHerbalismBlocks = new ArrayList<BlockData>(); public List<Material> customHerbalismBlocks = new ArrayList<>();
public List<BlockData> customMiningBlocks = new ArrayList<BlockData>(); public List<Material> customMiningBlocks = new ArrayList<>();
public List<BlockData> customOres = new ArrayList<BlockData>(); public List<Material> customOres = new ArrayList<>();
public List<BlockData> customLogs = new ArrayList<BlockData>(); public List<Material> customLogs = new ArrayList<>();
public List<BlockData> customLeaves = new ArrayList<BlockData>(); public List<Material> customLeaves = new ArrayList<>();
public List<BlockData> customAbilityBlocks = new ArrayList<BlockData>(); public List<Material> customAbilityBlocks = new ArrayList<>();
public HashMap<BlockData, CustomBlock> customBlockMap = new HashMap<BlockData, CustomBlock>(); public HashMap<Material, CustomBlock> customBlockMap = new HashMap<>();
protected CustomBlockConfig(String fileName) { protected CustomBlockConfig(String fileName) {
super("mods", fileName); super("mods", fileName);
@ -44,7 +42,7 @@ public class CustomBlockConfig extends ConfigLoader {
} }
} }
private void loadBlocks(String skillType, List<BlockData> blockList) { private void loadBlocks(String skillType, List<Material> blockList) {
if (needsUpdate) { if (needsUpdate) {
return; return;
} }
@ -72,11 +70,8 @@ public class CustomBlockConfig extends ConfigLoader {
continue; continue;
} }
byte blockData = (blockInfo.length == 2) ? Byte.valueOf(blockInfo[1]) : 0;
BlockData blockBlockData = blockMaterial.createBlockData();
if (blockList != null) { if (blockList != null) {
blockList.add(blockBlockData); blockList.add(blockMaterial);
} }
if (skillType.equals("Ability_Blocks")) { if (skillType.equals("Ability_Blocks")) {
@ -87,20 +82,20 @@ public class CustomBlockConfig extends ConfigLoader {
int smeltingXp = 0; int smeltingXp = 0;
if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) { if (skillType.equals("Mining") && config.getBoolean(skillType + "." + blockName + ".Is_Ore")) {
customOres.add(blockBlockData); customOres.add(blockMaterial);
smeltingXp = config.getInt(skillType + "." + blockName + ".Smelting_XP_Gain", xp / 10); smeltingXp = config.getInt(skillType + "." + blockName + ".Smelting_XP_Gain", xp / 10);
} }
else if (skillType.equals("Woodcutting")) { else if (skillType.equals("Woodcutting")) {
if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) { if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) {
customLogs.add(blockBlockData); customLogs.add(blockMaterial);
} }
else { else {
customLeaves.add(blockBlockData); customLeaves.add(blockMaterial);
xp = 0; // Leaves don't grant XP xp = 0; // Leaves don't grant XP
} }
} }
customBlockMap.put(blockBlockData, new CustomBlock(xp, config.getBoolean(skillType + "." + blockName + ".Double_Drops_Enabled"), smeltingXp)); customBlockMap.put(blockMaterial, new CustomBlock(xp, config.getBoolean(skillType + "." + blockName + ".Double_Drops_Enabled"), smeltingXp));
} }
} }
} }

View File

@ -1,16 +1,15 @@
package com.gmail.nossr50.skills.excavation; package com.gmail.nossr50.skills.excavation;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.block.BlockState;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig; import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import org.bukkit.block.BlockState;
import java.util.ArrayList;
import java.util.List;
public class Excavation { public class Excavation {
/** /**
@ -27,7 +26,7 @@ public class Excavation {
} }
protected static int getBlockXP(BlockState blockState) { protected static int getBlockXP(BlockState blockState) {
int xp = ExperienceConfig.getInstance().getXp(SkillType.EXCAVATION, blockState.getBlockData()); int xp = ExperienceConfig.getInstance().getXp(SkillType.EXCAVATION, blockState.getType());
if (xp == 0 && mcMMO.getModManager().isCustomExcavationBlock(blockState)) { if (xp == 0 && mcMMO.getModManager().isCustomExcavationBlock(blockState)) {
xp = mcMMO.getModManager().getBlock(blockState).getXpGain(); xp = mcMMO.getModManager().getBlock(blockState).getXpGain();

View File

@ -13,15 +13,13 @@ import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.*; import com.gmail.nossr50.util.*;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
import org.bukkit.*; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.data.Ageable; import org.bukkit.block.data.Ageable;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import org.bukkit.material.NetherWarts;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import java.util.Collection; import java.util.Collection;
@ -136,10 +134,10 @@ public class HerbalismManager extends SkillManager {
} }
} }
else { else {
if(material == Material.CHORUS_FLOWER && blockState.getRawData() != 5) { if (!BlockUtils.isHarvestable(blockState))
return; return;
}
xp = ExperienceConfig.getInstance().getXp(skill, blockState.getBlockData()); xp = ExperienceConfig.getInstance().getXp(skill, blockState.getType());
if (Config.getInstance().getDoubleDropsEnabled(skill, material) && Permissions.secondaryAbilityEnabled(player, SecondaryAbility.HERBALISM_DOUBLE_DROPS)) { if (Config.getInstance().getDoubleDropsEnabled(skill, material) && Permissions.secondaryAbilityEnabled(player, SecondaryAbility.HERBALISM_DOUBLE_DROPS)) {
drops = blockState.getBlock().getDrops(); drops = blockState.getBlock().getDrops();

View File

@ -16,7 +16,7 @@ public class Mining {
* @param blockState The {@link BlockState} to check ability activation for * @param blockState The {@link BlockState} to check ability activation for
*/ */
public static int getBlockXp(BlockState blockState) { public static int getBlockXp(BlockState blockState) {
int xp = ExperienceConfig.getInstance().getXp(SkillType.MINING, blockState.getBlockData()); int xp = ExperienceConfig.getInstance().getXp(SkillType.MINING, blockState.getType());
if (xp == 0 && mcMMO.getModManager().isCustomMiningBlock(blockState)) { if (xp == 0 && mcMMO.getModManager().isCustomMiningBlock(blockState)) {
xp = mcMMO.getModManager().getBlock(blockState).getXpGain(); xp = mcMMO.getModManager().getBlock(blockState).getXpGain();

View File

@ -1,13 +1,10 @@
package com.gmail.nossr50.skills.smelting; package com.gmail.nossr50.skills.smelting;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.block.data.BlockData;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.mcMMO;
import org.bukkit.inventory.ItemStack;
public class Smelting { public class Smelting {
// The order of the values is extremely important, a few methods depend on it to work properly // The order of the values is extremely important, a few methods depend on it to work properly
@ -23,7 +20,7 @@ public class Smelting {
int numerical; int numerical;
private Tier(int numerical) { Tier(int numerical) {
this.numerical = numerical; this.numerical = numerical;
} }
@ -47,8 +44,6 @@ public class Smelting {
public static double fluxMiningChance = AdvancedConfig.getInstance().getFluxMiningChance(); public static double fluxMiningChance = AdvancedConfig.getInstance().getFluxMiningChance();
protected static int getResourceXp(ItemStack smelting) { protected static int getResourceXp(ItemStack smelting) {
BlockData data = smelting.getType().createBlockData(); return mcMMO.getModManager().isCustomOre(smelting.getType()) ? mcMMO.getModManager().getBlock(smelting.getType()).getSmeltingXpGain() : ExperienceConfig.getInstance().getXp(SkillType.SMELTING, smelting.getType());
return mcMMO.getModManager().isCustomOre(data) ? mcMMO.getModManager().getBlock(data).getSmeltingXpGain() : ExperienceConfig.getInstance().getXp(SkillType.SMELTING, data);
} }
} }

View File

@ -42,7 +42,7 @@ public final class Woodcutting {
return mcMMO.getModManager().getBlock(blockState).getXpGain(); return mcMMO.getModManager().getBlock(blockState).getXpGain();
} }
return ExperienceConfig.getInstance().getXp(SkillType.WOODCUTTING, blockState.getBlockData()); return ExperienceConfig.getInstance().getXp(SkillType.WOODCUTTING, blockState.getType());
} }
/** /**

View File

@ -7,6 +7,8 @@ import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.salvage.Salvage; import com.gmail.nossr50.skills.salvage.Salvage;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
import java.util.HashSet; import java.util.HashSet;
@ -134,7 +136,7 @@ public final class BlockUtils {
* @return true if the block is an ore, false otherwise * @return true if the block is an ore, false otherwise
*/ */
public static boolean isOre(BlockState blockState) { public static boolean isOre(BlockState blockState) {
return MaterialUtils.isOre(blockState.getBlockData()); return MaterialUtils.isOre(blockState.getType());
} }
/** /**
@ -170,7 +172,7 @@ public final class BlockUtils {
* @return true if the block should affected by Green Terra, false otherwise * @return true if the block should affected by Green Terra, false otherwise
*/ */
public static boolean affectedByGreenTerra(BlockState blockState) { public static boolean affectedByGreenTerra(BlockState blockState) {
if (ExperienceConfig.getInstance().isSkillBlock(SkillType.HERBALISM, blockState.getBlockData())) { if (ExperienceConfig.getInstance().isSkillBlock(SkillType.HERBALISM, blockState.getType())) {
return true; return true;
} }
@ -352,4 +354,16 @@ public final class BlockUtils {
return transparentBlocks; return transparentBlocks;
} }
public static boolean isHarvestable(BlockState blockState) {
BlockData data = blockState.getBlockData();
if (data.getMaterial() == Material.CACTUS || data.getMaterial() == Material.SUGAR_CANE)
return true;
if (data instanceof Ageable)
{
Ageable ageable = (Ageable) data;
return ageable.getAge() == ageable.getMaximumAge();
}
return true;
}
} }

View File

@ -1,13 +1,13 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import org.bukkit.block.data.BlockData; import org.bukkit.Material;
public final class MaterialUtils { public final class MaterialUtils {
private MaterialUtils() {} private MaterialUtils() {}
protected static boolean isOre(BlockData data) { protected static boolean isOre(Material data) {
switch (data.getMaterial()) { switch (data) {
case COAL_ORE: case COAL_ORE:
case DIAMOND_ORE: case DIAMOND_ORE:
case NETHER_QUARTZ_ORE: case NETHER_QUARTZ_ORE:

View File

@ -1,18 +1,5 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.block.data.BlockData;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.mods.CustomArmorConfig; import com.gmail.nossr50.config.mods.CustomArmorConfig;
import com.gmail.nossr50.config.mods.CustomBlockConfig; import com.gmail.nossr50.config.mods.CustomBlockConfig;
@ -21,7 +8,18 @@ import com.gmail.nossr50.config.mods.CustomToolConfig;
import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.datatypes.mods.CustomBlock;
import com.gmail.nossr50.datatypes.mods.CustomEntity; import com.gmail.nossr50.datatypes.mods.CustomEntity;
import com.gmail.nossr50.datatypes.mods.CustomTool; import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.repairables.Repairable;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ModManager { public class ModManager {
private List<Repairable> repairables = new ArrayList<Repairable>(); private List<Repairable> repairables = new ArrayList<Repairable>();
@ -33,14 +31,14 @@ public class ModManager {
private List<Material> customLeggings = new ArrayList<Material>(); private List<Material> customLeggings = new ArrayList<Material>();
// Block Mods // Block Mods
private List<BlockData> customExcavationBlocks = new ArrayList<BlockData>(); private List<Material> customExcavationBlocks = new ArrayList<Material>();
private List<BlockData> customHerbalismBlocks = new ArrayList<BlockData>(); private List<Material> customHerbalismBlocks = new ArrayList<Material>();
private List<BlockData> customMiningBlocks = new ArrayList<BlockData>(); private List<Material> customMiningBlocks = new ArrayList<Material>();
private List<BlockData> customOres = new ArrayList<BlockData>(); private List<Material> customOres = new ArrayList<Material>();
private List<BlockData> customLogs = new ArrayList<BlockData>(); private List<Material> customLogs = new ArrayList<Material>();
private List<BlockData> customLeaves = new ArrayList<BlockData>(); private List<Material> customLeaves = new ArrayList<Material>();
private List<BlockData> customAbilityBlocks = new ArrayList<BlockData>(); private List<Material> customAbilityBlocks = new ArrayList<Material>();
private HashMap<BlockData, CustomBlock> customBlockMap = new HashMap<BlockData, CustomBlock>(); private HashMap<Material, CustomBlock> customBlockMap = new HashMap<>();
// Entity Mods // Entity Mods
private HashMap<String, CustomEntity> customEntityClassMap = new HashMap<String, CustomEntity>(); private HashMap<String, CustomEntity> customEntityClassMap = new HashMap<String, CustomEntity>();
@ -130,39 +128,39 @@ public class ModManager {
return Config.getInstance().getToolModsEnabled() && customSwords.contains(material); return Config.getInstance().getToolModsEnabled() && customSwords.contains(material);
} }
public boolean isCustomOre(BlockData data) { public boolean isCustomOre(Material data) {
return Config.getInstance().getBlockModsEnabled() && customOres.contains(data); return Config.getInstance().getBlockModsEnabled() && customOres.contains(data);
} }
public boolean isCustomLog(BlockState state) { public boolean isCustomLog(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customLogs.contains(state.getData()); return Config.getInstance().getBlockModsEnabled() && customLogs.contains(state.getType());
} }
public boolean isCustomLeaf(BlockState state) { public boolean isCustomLeaf(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customLeaves.contains(state.getData()); return Config.getInstance().getBlockModsEnabled() && customLeaves.contains(state.getType());
} }
public boolean isCustomAbilityBlock(BlockState state) { public boolean isCustomAbilityBlock(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customAbilityBlocks.contains(state.getData()); return Config.getInstance().getBlockModsEnabled() && customAbilityBlocks.contains(state.getType());
} }
public boolean isCustomExcavationBlock(BlockState state) { public boolean isCustomExcavationBlock(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customExcavationBlocks.contains(state.getData()); return Config.getInstance().getBlockModsEnabled() && customExcavationBlocks.contains(state.getType());
} }
public boolean isCustomHerbalismBlock(BlockState state) { public boolean isCustomHerbalismBlock(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customHerbalismBlocks.contains(state.getData()); return Config.getInstance().getBlockModsEnabled() && customHerbalismBlocks.contains(state.getType());
} }
public boolean isCustomMiningBlock(BlockState state) { public boolean isCustomMiningBlock(BlockState state) {
return Config.getInstance().getBlockModsEnabled() && customMiningBlocks.contains(state.getData()); return Config.getInstance().getBlockModsEnabled() && customMiningBlocks.contains(state.getType());
} }
public CustomBlock getBlock(BlockState state) { public CustomBlock getBlock(BlockState state) {
return customBlockMap.get(state.getData()); return customBlockMap.get(state.getType());
} }
public CustomBlock getBlock(BlockData data) { public CustomBlock getBlock(Material data) {
return customBlockMap.get(data); return customBlockMap.get(data);
} }