Update configurations and skill block checks to be more configurable.

This commit is contained in:
t00thpick1
2017-06-10 13:47:20 -04:00
parent 5c267663a2
commit 15436b44da
11 changed files with 475 additions and 471 deletions

View File

@ -13,16 +13,20 @@ import org.bukkit.material.NetherWarts;
import org.bukkit.material.SmoothBrick;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.salvage.Salvage;
public final class BlockUtils {
private BlockUtils() {}
/**
* Checks to see if a given block awards XP.
*
* @param blockState The {@link BlockState} of the block to check
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block awards XP, false otherwise
*/
public static boolean shouldBeWatched(BlockState blockState) {
@ -32,59 +36,61 @@ public final class BlockUtils {
/**
* Check if a given block should allow for the activation of abilities
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block should allow ability activation, false otherwise
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block should allow ability activation, false
* otherwise
*/
public static boolean canActivateAbilities(BlockState blockState) {
switch (blockState.getType()) {
case BED_BLOCK:
case BREWING_STAND:
case BOOKSHELF:
case BURNING_FURNACE:
case CAKE_BLOCK:
case CHEST:
case DISPENSER:
case ENCHANTMENT_TABLE:
case ENDER_CHEST:
case FENCE_GATE:
case ACACIA_FENCE_GATE:
case DARK_OAK_FENCE_GATE:
case SPRUCE_FENCE_GATE:
case BIRCH_FENCE_GATE:
case JUNGLE_FENCE_GATE:
case FURNACE:
case IRON_DOOR_BLOCK:
case JUKEBOX:
case LEVER:
case NOTE_BLOCK:
case STONE_BUTTON:
case WOOD_BUTTON:
case TRAP_DOOR:
case WALL_SIGN:
case WOODEN_DOOR:
case WORKBENCH:
case BEACON:
case ANVIL:
case DROPPER:
case HOPPER:
case TRAPPED_CHEST:
case IRON_DOOR:
case IRON_TRAPDOOR:
case ACACIA_DOOR:
case SPRUCE_DOOR:
case BIRCH_DOOR:
case JUNGLE_DOOR:
case DARK_OAK_DOOR:
case FENCE:
case ACACIA_FENCE:
case DARK_OAK_FENCE:
case BIRCH_FENCE:
case JUNGLE_FENCE:
case SPRUCE_FENCE:
case ARMOR_STAND:
case BED_BLOCK :
case BREWING_STAND :
case BOOKSHELF :
case BURNING_FURNACE :
case CAKE_BLOCK :
case CHEST :
case DISPENSER :
case ENCHANTMENT_TABLE :
case ENDER_CHEST :
case FENCE_GATE :
case ACACIA_FENCE_GATE :
case DARK_OAK_FENCE_GATE :
case SPRUCE_FENCE_GATE :
case BIRCH_FENCE_GATE :
case JUNGLE_FENCE_GATE :
case FURNACE :
case IRON_DOOR_BLOCK :
case JUKEBOX :
case LEVER :
case NOTE_BLOCK :
case STONE_BUTTON :
case WOOD_BUTTON :
case TRAP_DOOR :
case WALL_SIGN :
case WOODEN_DOOR :
case WORKBENCH :
case BEACON :
case ANVIL :
case DROPPER :
case HOPPER :
case TRAPPED_CHEST :
case IRON_DOOR :
case IRON_TRAPDOOR :
case ACACIA_DOOR :
case SPRUCE_DOOR :
case BIRCH_DOOR :
case JUNGLE_DOOR :
case DARK_OAK_DOOR :
case FENCE :
case ACACIA_FENCE :
case DARK_OAK_FENCE :
case BIRCH_FENCE :
case JUNGLE_FENCE :
case SPRUCE_FENCE :
case ARMOR_STAND :
return false;
default:
default :
return !isMcMMOAnvil(blockState) && !mcMMO.getModManager().isCustomAbilityBlock(blockState);
}
}
@ -92,7 +98,8 @@ public final class BlockUtils {
/**
* Check if a given block is an ore
*
* @param blockState The {@link BlockState} of the block to check
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block is an ore, false otherwise
*/
public static boolean isOre(BlockState blockState) {
@ -102,23 +109,24 @@ public final class BlockUtils {
/**
* Determine if a given block can be made mossy
*
* @param blockState The {@link BlockState} of the block to check
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block can be made mossy, false otherwise
*/
public static boolean canMakeMossy(BlockState blockState) {
switch (blockState.getType()) {
case COBBLESTONE:
case DIRT:
case GRASS_PATH:
case COBBLESTONE :
case DIRT :
case GRASS_PATH :
return true;
case SMOOTH_BRICK:
case SMOOTH_BRICK :
return ((SmoothBrick) blockState.getData()).getMaterial() == Material.STONE;
case COBBLE_WALL:
case COBBLE_WALL :
return blockState.getRawData() == (byte) 0x0;
default:
default :
return false;
}
}
@ -126,134 +134,73 @@ public final class BlockUtils {
/**
* Determine if a given block should be affected by Green Terra
*
* @param blockState The {@link BlockState} of the block to check
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block should affected by Green Terra, false otherwise
*/
public static boolean affectedByGreenTerra(BlockState blockState) {
switch (blockState.getType()) {
case BROWN_MUSHROOM:
case CACTUS:
case CHORUS_PLANT:
case CHORUS_FLOWER:
case DOUBLE_PLANT:
case MELON_BLOCK:
case LONG_GRASS:
case PUMPKIN:
case RED_MUSHROOM:
case RED_ROSE:
case SUGAR_CANE_BLOCK:
case VINE:
case WATER_LILY:
case YELLOW_FLOWER:
return true;
if (ExperienceConfig.getInstance().isSkillBlock(SkillType.HERBALISM, blockState.getData()))
return true;
case BEETROOT_BLOCK:
case CARROT:
case POTATO:
case CROPS:
return ((Crops) blockState.getData()).getState() == CropState.RIPE;
case NETHER_WARTS:
return ((NetherWarts) blockState.getData()).getState() == NetherWartsState.RIPE;
case COCOA:
return ((CocoaPlant) blockState.getData()).getSize() == CocoaPlantSize.LARGE;
default:
return mcMMO.getModManager().isCustomHerbalismBlock(blockState);
}
return mcMMO.getModManager().isCustomHerbalismBlock(blockState);
}
/**
* Determine if a given block should be affected by Super Breaker
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block should affected by Super Breaker, false otherwise
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block should affected by Super Breaker, false
* otherwise
*/
public static Boolean affectedBySuperBreaker(BlockState blockState) {
switch (blockState.getType()) {
case END_BRICKS:
case ENDER_STONE:
case GLOWSTONE:
case HARD_CLAY:
case MOSSY_COBBLESTONE:
case NETHERRACK:
case OBSIDIAN:
case PACKED_ICE:
case PURPUR_BLOCK:
case PURPUR_PILLAR:
case PURPUR_SLAB:
case PURPUR_STAIRS:
case SANDSTONE:
case STAINED_CLAY:
case STONE:
case PRISMARINE:
case RED_SANDSTONE:
return true;
if (ExperienceConfig.getInstance().isSkillBlock(SkillType.MINING, blockState.getData()))
return true;
default:
return isOre(blockState) || mcMMO.getModManager().isCustomMiningBlock(blockState);
}
return isOre(blockState) || mcMMO.getModManager().isCustomMiningBlock(blockState);
}
/**
* Determine if a given block should be affected by Giga Drill Breaker
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block should affected by Giga Drill Breaker, false otherwise
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block should affected by Giga Drill Breaker, false
* otherwise
*/
public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
switch (blockState.getType()) {
case CLAY:
case DIRT:
case GRASS:
case GRASS_PATH:
case GRAVEL:
case MYCEL:
case SAND:
case SNOW:
case SNOW_BLOCK:
case SOUL_SAND:
return true;
default:
return mcMMO.getModManager().isCustomExcavationBlock(blockState);
}
if (ExperienceConfig.getInstance().isSkillBlock(SkillType.EXCAVATION, blockState.getData()))
return true;
return mcMMO.getModManager().isCustomExcavationBlock(blockState);
}
/**
* Check if a given block is a log
*
* @param blockState The {@link BlockState} of the block to check
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block is a log, false otherwise
*/
public static boolean isLog(BlockState blockState) {
switch (blockState.getType()) {
case LOG:
case LOG_2:
case HUGE_MUSHROOM_1:
case HUGE_MUSHROOM_2:
return true;
default:
return mcMMO.getModManager().isCustomLog(blockState);
}
if (ExperienceConfig.getInstance().isSkillBlock(SkillType.WOODCUTTING, blockState.getData()))
return true;
return mcMMO.getModManager().isCustomLog(blockState);
}
/**
* Check if a given block is a leaf
*
* @param blockState The {@link BlockState} of the block to check
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block is a leaf, false otherwise
*/
public static boolean isLeaves(BlockState blockState) {
switch (blockState.getType()) {
case LEAVES:
case LEAVES_2:
case LEAVES :
case LEAVES_2 :
return true;
default:
default :
return mcMMO.getModManager().isCustomLeaf(blockState);
}
}
@ -261,16 +208,17 @@ public final class BlockUtils {
/**
* Determine if a given block should be affected by Flux Mining
*
* @param blockState The {@link BlockState} of the block to check
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block should affected by Flux Mining, false otherwise
*/
public static boolean affectedByFluxMining(BlockState blockState) {
switch (blockState.getType()) {
case IRON_ORE:
case GOLD_ORE:
case IRON_ORE :
case GOLD_ORE :
return true;
default:
default :
return false;
}
}
@ -278,18 +226,20 @@ public final class BlockUtils {
/**
* Determine if a given block can activate Herbalism abilities
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block can be activate Herbalism abilities, false otherwise
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block can be activate Herbalism abilities, false
* otherwise
*/
public static boolean canActivateHerbalism(BlockState blockState) {
switch (blockState.getType()) {
case DIRT:
case GRASS:
case GRASS_PATH:
case SOIL:
case DIRT :
case GRASS :
case GRASS_PATH :
case SOIL :
return false;
default:
default :
return true;
}
}
@ -297,15 +247,17 @@ public final class BlockUtils {
/**
* Determine if a given block should be affected by Block Cracker
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block should affected by Block Cracker, false otherwise
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block should affected by Block Cracker, false
* otherwise
*/
public static boolean affectedByBlockCracker(BlockState blockState) {
switch (blockState.getType()) {
case SMOOTH_BRICK:
case SMOOTH_BRICK :
return ((SmoothBrick) blockState.getData()).getMaterial() == Material.STONE;
default:
default :
return false;
}
}
@ -313,17 +265,18 @@ public final class BlockUtils {
/**
* Determine if a given block can be made into Mycelium
*
* @param blockState The {@link BlockState} of the block to check
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block can be made into Mycelium, false otherwise
*/
public static boolean canMakeShroomy(BlockState blockState) {
switch (blockState.getType()) {
case DIRT:
case GRASS:
case GRASS_PATH:
case DIRT :
case GRASS :
case GRASS_PATH :
return true;
default:
default :
return false;
}
}
@ -331,7 +284,8 @@ public final class BlockUtils {
/**
* Determine if a given block is an mcMMO anvil
*
* @param blockState The {@link BlockState} of the block to check
* @param blockState
* The {@link BlockState} of the block to check
* @return true if the block is an mcMMO anvil, false otherwise
*/
public static boolean isMcMMOAnvil(BlockState blockState) {

View File

@ -1,18 +1,30 @@
package com.gmail.nossr50.util;
import org.bukkit.CropState;
import org.bukkit.GrassSpecies;
import org.bukkit.Material;
import org.bukkit.NetherWartsState;
import org.bukkit.TreeSpecies;
import org.bukkit.entity.EntityType;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.Crops;
import org.bukkit.material.LongGrass;
import org.bukkit.material.MaterialData;
import org.bukkit.material.NetherWarts;
import org.bukkit.material.Tree;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import com.gmail.nossr50.datatypes.party.PartyFeature;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
public class StringUtils {
/**
* Gets a capitalized version of the target string.
*
* @param target String to capitalize
* @param target
* String to capitalize
* @return the capitalized string
*/
public static String getCapitalized(String target) {
@ -35,19 +47,296 @@ public class StringUtils {
return createPrettyEnumString(species.toString());
}
public static String getFriendlyConfigMaterialDataString(MaterialData data) {
switch (data.getItemType()) {
case LOG :
case LOG_2 : {
TreeSpecies species = TreeSpecies.GENERIC;
if (data instanceof Tree) {
Tree tree = (Tree) data;
species = tree.getSpecies();
}
return createPrettyEnumString(species.name()).replace(" ", "_");
}
case LONG_GRASS : {
LongGrass grass = (LongGrass) data;
GrassSpecies species = grass.getSpecies();
switch (species) {
case DEAD :
return "Dead_Bush";
case FERN_LIKE :
return "Small_Fern";
case NORMAL :
return "Small_Grass";
}
break;
}
case RED_ROSE : {
switch (data.getData()) {
case 0x0 :
return "Poppy";
case 0x1 :
return "Blue_Orchid";
case 0x2 :
return "Allium";
case 0x3 :
return "Azure_Bluet";
case 0x4 :
return "Red_Tulip";
case 0x5 :
return "Orange_Tulip";
case 0x6 :
return "White_Tulip";
case 0x7 :
return "Pink_Tulip";
case 0x8 :
return "Oxeye_Daisy";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case DOUBLE_PLANT : {
switch (data.getData()) {
case 0x0 :
return "Sunflower";
case 0x1 :
return "Lilac";
case 0x2 :
return "Tall_Grass";
case 0x3 :
return "Tall_Fern";
case 0x4 :
return "Rose_Bush";
case 0x5 :
return "Peony";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case RAW_FISH : {
switch (data.getData()) {
case 0x0 :
return "Raw_Fish";
case 0x1 :
return "Raw_Salmon";
case 0x2 :
return "Clownfish";
case 0x3 :
return "Pufferfish";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case COOKED_FISH : {
switch (data.getData()) {
case 0x0 :
return "Cooked_Fish";
case 0x1 :
return "Cooked_Salmon";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case DIRT : {
switch (data.getData()) {
case 0x0 :
return "Dirt";
case 0x1 :
return "Coarse_Dirt";
case 0x2 :
return "Podzol";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case SAND : {
switch (data.getData()) {
case 0x0 :
return "Sand";
case 0x1 :
return "Red_Sand";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case QUARTZ_BLOCK : {
switch (data.getData()) {
case 0x0 :
return "Quartz_Block";
case 0x1 :
return "Chiseled_Quartz_Block";
case 0x2 :
case 0x3 :
case 0x4 :
return "Quartz_Pillar";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case SPONGE : {
switch (data.getData()) {
case 0x0 :
return "Sponge";
case 0x1 :
return "Wet_Sponge";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case PRISMARINE : {
switch (data.getData()) {
case 0x0 :
return "Prismarine";
case 0x1 :
return "Prismarine_Brick";
case 0x2 :
return "Dark_Prismarine";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case STONE : {
switch (data.getData()) {
case 0x0 :
return "Stone";
case 0x1 :
return "Granite";
case 0x2 :
return "Polished_Granite";
case 0x3 :
return "Diorite";
case 0x4 :
return "Polished_Diorite";
case 0x5 :
return "Andesite";
case 0x6 :
return "Polished_Andesite";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case WOOD : {
switch (data.getData()) {
case 0x0 :
return "Oak_Planks";
case 0x1 :
return "Spruce_Planks";
case 0x2 :
return "Birch_Planks";
case 0x3 :
return "Jungle_Planks";
case 0x4 :
return "Acacia_Planks";
case 0x5 :
return "Dark_Oak_Planks";
default :
return getExplicitConfigMaterialDataString(data);
}
}
case GLOWING_REDSTONE_ORE :
return getPrettyItemString(Material.REDSTONE_ORE).replace(" ", "_");
case BEETROOT_BLOCK :
case CARROT :
case POTATO :
case CROPS : {
if (((Crops) data).getState() == CropState.RIPE) {
return getPrettyItemString(data.getItemType()).replace(" ", "_");
}
return getPrettyItemString(data.getItemType()).replace(" ", "_") + "_UNGROWN";
}
case NETHER_WARTS : {
if (((NetherWarts) data).getState() == NetherWartsState.RIPE) {
return getPrettyItemString(data.getItemType()).replace(" ", "_");
}
return getPrettyItemString(data.getItemType()).replace(" ", "_") + "_UNGROWN";
}
case COCOA : {
if (((CocoaPlant) data).getSize() == CocoaPlantSize.LARGE) {
return getPrettyItemString(data.getItemType()).replace(" ", "_");
}
return getPrettyItemString(data.getItemType()).replace(" ", "_") + "_UNGROWN";
}
case SMOOTH_BRICK :
case WOOL :
case INK_SACK :
case STAINED_CLAY :
case STAINED_GLASS :
case FLOWER_POT :
case MONSTER_EGGS :
return getExplicitConfigMaterialDataString(data);
default :
break;
}
return getPrettyItemString(data.getItemType()).replace(" ", "_");
}
public static String getExplicitConfigMaterialDataString(MaterialData data) {
return StringUtils.getPrettyItemString(data.getItemType()).replace(" ", "_") + "|" + data.getData();
}
public static String getPrettySecondaryAbilityString(SecondaryAbility secondaryAbility) {
switch (secondaryAbility) {
case HERBALISM_DOUBLE_DROPS:
case MINING_DOUBLE_DROPS:
case WOODCUTTING_DOUBLE_DROPS:
case HERBALISM_DOUBLE_DROPS :
case MINING_DOUBLE_DROPS :
case WOODCUTTING_DOUBLE_DROPS :
return "Double Drops";
case FISHING_TREASURE_HUNTER:
case EXCAVATION_TREASURE_HUNTER:
case FISHING_TREASURE_HUNTER :
case EXCAVATION_TREASURE_HUNTER :
return "Treasure Hunter";
case GREEN_THUMB_BLOCK:
case GREEN_THUMB_PLANT:
case GREEN_THUMB_BLOCK :
case GREEN_THUMB_PLANT :
return "Green Thumb";
default:
default :
return createPrettyEnumString(secondaryAbility.toString());
}
}
@ -77,15 +366,15 @@ public class StringUtils {
/**
* Determine if a string represents an Integer
*
* @param string String to check
* @param string
* String to check
* @return true if the string is an Integer, false otherwise
*/
public static boolean isInt(String string) {
try {
Integer.parseInt(string);
return true;
}
catch (NumberFormatException nFE) {
} catch (NumberFormatException nFE) {
return false;
}
}
@ -93,15 +382,15 @@ public class StringUtils {
/**
* Determine if a string represents a Double
*
* @param string String to check
* @param string
* String to check
* @return true if the string is a Double, false otherwise
*/
public static boolean isDouble(String string) {
try {
Double.parseDouble(string);
return true;
}
catch (NumberFormatException nFE) {
} catch (NumberFormatException nFE) {
return false;
}
}