From 5663b713874f66102d056dc3f620618183833797 Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Tue, 9 Oct 2018 21:48:47 -0400 Subject: [PATCH] Some of these should not have been blockdata, also this should check age of crops. --- .../config/experience/ExperienceConfig.java | 32 ++++++---- .../config/mods/CustomBlockConfig.java | 43 ++++++-------- .../nossr50/skills/excavation/Excavation.java | 13 ++--- .../skills/herbalism/HerbalismManager.java | 12 ++-- .../gmail/nossr50/skills/mining/Mining.java | 2 +- .../nossr50/skills/smelting/Smelting.java | 13 ++--- .../skills/woodcutting/Woodcutting.java | 2 +- .../com/gmail/nossr50/util/BlockUtils.java | 18 +++++- .../com/gmail/nossr50/util/MaterialUtils.java | 6 +- .../com/gmail/nossr50/util/ModManager.java | 58 +++++++++---------- 10 files changed, 104 insertions(+), 95 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java index 32df534e2..c6c3f77c6 100644 --- a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java +++ b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java @@ -1,18 +1,17 @@ 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.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.skills.MaterialType; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage; 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 { private static ExperienceConfig instance; @@ -218,7 +217,20 @@ public class ExperienceConfig extends AutoUpdateConfigLoader { return config.getInt(wildcardString); 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) { String baseString = "Experience." + StringUtils.getCapitalized(skill.toString()) + "."; @@ -229,9 +241,7 @@ public class ExperienceConfig extends AutoUpdateConfigLoader { if (config.contains(friendlyString)) return true; String wildcardString = baseString + StringUtils.getWildcardConfigBlockDataString(data); - if (config.contains(wildcardString)) - return true; - return false; + return config.contains(wildcardString); } /* Acrobatics */ diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomBlockConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomBlockConfig.java index df11ac212..2b30ec0cf 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomBlockConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomBlockConfig.java @@ -1,29 +1,27 @@ 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.HashMap; import java.util.List; 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 { private boolean needsUpdate = false; - public List customExcavationBlocks = new ArrayList(); - public List customHerbalismBlocks = new ArrayList(); - public List customMiningBlocks = new ArrayList(); - public List customOres = new ArrayList(); - public List customLogs = new ArrayList(); - public List customLeaves = new ArrayList(); - public List customAbilityBlocks = new ArrayList(); + public List customExcavationBlocks = new ArrayList<>(); + public List customHerbalismBlocks = new ArrayList<>(); + public List customMiningBlocks = new ArrayList<>(); + public List customOres = new ArrayList<>(); + public List customLogs = new ArrayList<>(); + public List customLeaves = new ArrayList<>(); + public List customAbilityBlocks = new ArrayList<>(); - public HashMap customBlockMap = new HashMap(); + public HashMap customBlockMap = new HashMap<>(); protected CustomBlockConfig(String fileName) { super("mods", fileName); @@ -44,7 +42,7 @@ public class CustomBlockConfig extends ConfigLoader { } } - private void loadBlocks(String skillType, List blockList) { + private void loadBlocks(String skillType, List blockList) { if (needsUpdate) { return; } @@ -72,11 +70,8 @@ public class CustomBlockConfig extends ConfigLoader { continue; } - byte blockData = (blockInfo.length == 2) ? Byte.valueOf(blockInfo[1]) : 0; - BlockData blockBlockData = blockMaterial.createBlockData(); - if (blockList != null) { - blockList.add(blockBlockData); + blockList.add(blockMaterial); } if (skillType.equals("Ability_Blocks")) { @@ -87,20 +82,20 @@ public class CustomBlockConfig extends ConfigLoader { int smeltingXp = 0; 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); } else if (skillType.equals("Woodcutting")) { if (config.getBoolean(skillType + "." + blockName + ".Is_Log")) { - customLogs.add(blockBlockData); + customLogs.add(blockMaterial); } else { - customLeaves.add(blockBlockData); + customLeaves.add(blockMaterial); 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)); } } } diff --git a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java index daba54a66..3c87130be 100644 --- a/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/excavation/Excavation.java @@ -1,16 +1,15 @@ 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.treasure.TreasureConfig; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; +import org.bukkit.block.BlockState; + +import java.util.ArrayList; +import java.util.List; public class Excavation { /** @@ -27,7 +26,7 @@ public class Excavation { } 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)) { xp = mcMMO.getModManager().getBlock(blockState).getXpGain(); diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 1f5e7357f..64b61aedf 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -13,15 +13,13 @@ import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.*; 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.data.Ageable; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; 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 java.util.Collection; @@ -136,10 +134,10 @@ public class HerbalismManager extends SkillManager { } } else { - if(material == Material.CHORUS_FLOWER && blockState.getRawData() != 5) { + if (!BlockUtils.isHarvestable(blockState)) 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)) { drops = blockState.getBlock().getDrops(); diff --git a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java index 7445db8af..cfd4bdc39 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/Mining.java @@ -16,7 +16,7 @@ public class Mining { * @param blockState The {@link BlockState} to check ability activation for */ 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)) { xp = mcMMO.getModManager().getBlock(blockState).getXpGain(); diff --git a/src/main/java/com/gmail/nossr50/skills/smelting/Smelting.java b/src/main/java/com/gmail/nossr50/skills/smelting/Smelting.java index 0ee84d598..db1f101bc 100644 --- a/src/main/java/com/gmail/nossr50/skills/smelting/Smelting.java +++ b/src/main/java/com/gmail/nossr50/skills/smelting/Smelting.java @@ -1,13 +1,10 @@ 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.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.mcMMO; +import org.bukkit.inventory.ItemStack; public class Smelting { // 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; - private Tier(int numerical) { + Tier(int numerical) { this.numerical = numerical; } @@ -47,8 +44,6 @@ public class Smelting { public static double fluxMiningChance = AdvancedConfig.getInstance().getFluxMiningChance(); protected static int getResourceXp(ItemStack smelting) { - BlockData data = smelting.getType().createBlockData(); - - return mcMMO.getModManager().isCustomOre(data) ? mcMMO.getModManager().getBlock(data).getSmeltingXpGain() : ExperienceConfig.getInstance().getXp(SkillType.SMELTING, data); + return mcMMO.getModManager().isCustomOre(smelting.getType()) ? mcMMO.getModManager().getBlock(smelting.getType()).getSmeltingXpGain() : ExperienceConfig.getInstance().getXp(SkillType.SMELTING, smelting.getType()); } } diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java index 6b75a79e3..132dbf448 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/Woodcutting.java @@ -42,7 +42,7 @@ public final class Woodcutting { return mcMMO.getModManager().getBlock(blockState).getXpGain(); } - return ExperienceConfig.getInstance().getXp(SkillType.WOODCUTTING, blockState.getBlockData()); + return ExperienceConfig.getInstance().getXp(SkillType.WOODCUTTING, blockState.getType()); } /** diff --git a/src/main/java/com/gmail/nossr50/util/BlockUtils.java b/src/main/java/com/gmail/nossr50/util/BlockUtils.java index 3e8aa5405..3579cca10 100644 --- a/src/main/java/com/gmail/nossr50/util/BlockUtils.java +++ b/src/main/java/com/gmail/nossr50/util/BlockUtils.java @@ -7,6 +7,8 @@ import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.salvage.Salvage; import org.bukkit.Material; import org.bukkit.block.BlockState; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.BlockData; import java.util.HashSet; @@ -134,7 +136,7 @@ public final class BlockUtils { * @return true if the block is an ore, false otherwise */ 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 */ public static boolean affectedByGreenTerra(BlockState blockState) { - if (ExperienceConfig.getInstance().isSkillBlock(SkillType.HERBALISM, blockState.getBlockData())) { + if (ExperienceConfig.getInstance().isSkillBlock(SkillType.HERBALISM, blockState.getType())) { return true; } @@ -352,4 +354,16 @@ public final class BlockUtils { 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; + } } diff --git a/src/main/java/com/gmail/nossr50/util/MaterialUtils.java b/src/main/java/com/gmail/nossr50/util/MaterialUtils.java index 108ea31c9..8951a098a 100644 --- a/src/main/java/com/gmail/nossr50/util/MaterialUtils.java +++ b/src/main/java/com/gmail/nossr50/util/MaterialUtils.java @@ -1,13 +1,13 @@ package com.gmail.nossr50.util; import com.gmail.nossr50.mcMMO; -import org.bukkit.block.data.BlockData; +import org.bukkit.Material; public final class MaterialUtils { private MaterialUtils() {} - protected static boolean isOre(BlockData data) { - switch (data.getMaterial()) { + protected static boolean isOre(Material data) { + switch (data) { case COAL_ORE: case DIAMOND_ORE: case NETHER_QUARTZ_ORE: diff --git a/src/main/java/com/gmail/nossr50/util/ModManager.java b/src/main/java/com/gmail/nossr50/util/ModManager.java index 16239bee6..025775801 100644 --- a/src/main/java/com/gmail/nossr50/util/ModManager.java +++ b/src/main/java/com/gmail/nossr50/util/ModManager.java @@ -1,18 +1,5 @@ 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.mods.CustomArmorConfig; 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.CustomEntity; import com.gmail.nossr50.datatypes.mods.CustomTool; +import com.gmail.nossr50.mcMMO; 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 { private List repairables = new ArrayList(); @@ -33,14 +31,14 @@ public class ModManager { private List customLeggings = new ArrayList(); // Block Mods - private List customExcavationBlocks = new ArrayList(); - private List customHerbalismBlocks = new ArrayList(); - private List customMiningBlocks = new ArrayList(); - private List customOres = new ArrayList(); - private List customLogs = new ArrayList(); - private List customLeaves = new ArrayList(); - private List customAbilityBlocks = new ArrayList(); - private HashMap customBlockMap = new HashMap(); + private List customExcavationBlocks = new ArrayList(); + private List customHerbalismBlocks = new ArrayList(); + private List customMiningBlocks = new ArrayList(); + private List customOres = new ArrayList(); + private List customLogs = new ArrayList(); + private List customLeaves = new ArrayList(); + private List customAbilityBlocks = new ArrayList(); + private HashMap customBlockMap = new HashMap<>(); // Entity Mods private HashMap customEntityClassMap = new HashMap(); @@ -130,39 +128,39 @@ public class ModManager { return Config.getInstance().getToolModsEnabled() && customSwords.contains(material); } - public boolean isCustomOre(BlockData data) { + public boolean isCustomOre(Material data) { return Config.getInstance().getBlockModsEnabled() && customOres.contains(data); } 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) { - return Config.getInstance().getBlockModsEnabled() && customLeaves.contains(state.getData()); + return Config.getInstance().getBlockModsEnabled() && customLeaves.contains(state.getType()); } 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) { - return Config.getInstance().getBlockModsEnabled() && customExcavationBlocks.contains(state.getData()); + return Config.getInstance().getBlockModsEnabled() && customExcavationBlocks.contains(state.getType()); } 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) { - return Config.getInstance().getBlockModsEnabled() && customMiningBlocks.contains(state.getData()); + return Config.getInstance().getBlockModsEnabled() && customMiningBlocks.contains(state.getType()); } 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); }