mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 05:36:46 +01:00
Attempting to make Herbalism cleaner...
This commit is contained in:
parent
f5259decab
commit
2aec202e6d
@ -4,6 +4,7 @@ import org.bukkit.DyeColor;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
@ -14,7 +15,6 @@ import org.bukkit.material.MaterialData;
|
|||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.AdvancedConfig;
|
import com.gmail.nossr50.config.AdvancedConfig;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
|
||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||||
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
@ -50,6 +50,13 @@ public class Herbalism {
|
|||||||
public static boolean greenTerraDirt = Config.getInstance().getHerbalismGreenThumbDirtToGrass();
|
public static boolean greenTerraDirt = Config.getInstance().getHerbalismGreenThumbDirtToGrass();
|
||||||
public static boolean greenTerraCobble = Config.getInstance().getHerbalismGreenThumbCobbleToMossy();
|
public static boolean greenTerraCobble = Config.getInstance().getHerbalismGreenThumbCobbleToMossy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the farmers diet skill.
|
||||||
|
*
|
||||||
|
* @param player The player to activate the skill for
|
||||||
|
* @param rankChange The # of levels to change rank for the food
|
||||||
|
* @param event The actual FoodLevelChange event
|
||||||
|
*/
|
||||||
public static void farmersDiet(Player player, int rankChange, FoodLevelChangeEvent event) {
|
public static void farmersDiet(Player player, int rankChange, FoodLevelChangeEvent event) {
|
||||||
if (!Permissions.farmersDiet(player)) {
|
if (!Permissions.farmersDiet(player)) {
|
||||||
return;
|
return;
|
||||||
@ -115,6 +122,20 @@ public class Herbalism {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int calculateCatciAndSugarDrops(Block block) {
|
||||||
|
Material blockType = block.getType();
|
||||||
|
int dropAmount = 0;
|
||||||
|
|
||||||
|
for (int y = 0; y <= 2; y++) {
|
||||||
|
Block relativeBlock = block.getRelative(BlockFace.UP, y);
|
||||||
|
if (relativeBlock.getType().equals(blockType) && !mcMMO.placeStore.isTrue(relativeBlock)) {
|
||||||
|
dropAmount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dropAmount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for extra Herbalism drops.
|
* Check for extra Herbalism drops.
|
||||||
*
|
*
|
||||||
@ -124,303 +145,68 @@ public class Herbalism {
|
|||||||
* @param plugin mcMMO plugin instance
|
* @param plugin mcMMO plugin instance
|
||||||
*/
|
*/
|
||||||
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
||||||
final PlayerProfile profile = Users.getProfile(player);
|
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerProfile profile = Users.getProfile(player);
|
||||||
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
||||||
int id = block.getTypeId();
|
Material blockType = block.getType();
|
||||||
Material type = block.getType();
|
|
||||||
|
|
||||||
Location location = block.getLocation();
|
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
|
||||||
Material mat = null;
|
CustomBlock customBlock = null;
|
||||||
|
|
||||||
int xp = 0;
|
int xp = 0;
|
||||||
int catciDrops = 0;
|
int dropAmount = 1;
|
||||||
int caneDrops = 0;
|
ItemStack dropItem = null;
|
||||||
|
|
||||||
boolean customPlant = false;
|
if (herbalismBlock != null) {
|
||||||
|
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
|
||||||
int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player));
|
dropItem = herbalismBlock.getDropItem();
|
||||||
|
dropAmount = calculateCatciAndSugarDrops(block);
|
||||||
float chance = (float) ((doubleDropsMaxChance / doubleDropsMaxLevel) * herbLevel);
|
xp = herbalismBlock.getXpGain() * dropAmount;
|
||||||
if (chance > doubleDropsMaxChance) chance = (float) doubleDropsMaxChance;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case BROWN_MUSHROOM:
|
|
||||||
case RED_MUSHROOM:
|
|
||||||
if (!mcMMO.placeStore.isTrue(block)) {
|
|
||||||
mat = Material.getMaterial(id);
|
|
||||||
xp = Config.getInstance().getHerbalismXPMushrooms();
|
|
||||||
}
|
}
|
||||||
break;
|
else if (herbalismBlock.hasGreenThumbPermission(player)){
|
||||||
|
dropItem = herbalismBlock.getDropItem();
|
||||||
|
xp = herbalismBlock.getXpGain();
|
||||||
|
|
||||||
case CACTUS:
|
|
||||||
for (int y = 0; y <= 2; y++) {
|
|
||||||
Block b = block.getRelative(0, y, 0);
|
|
||||||
if (b.getType().equals(Material.CACTUS)) {
|
|
||||||
mat = Material.CACTUS;
|
|
||||||
if (!mcMMO.placeStore.isTrue(b)) {
|
|
||||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
|
||||||
catciDrops++;
|
|
||||||
}
|
|
||||||
xp += Config.getInstance().getHerbalismXPCactus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CROPS:
|
|
||||||
mat = Material.WHEAT;
|
|
||||||
xp = Config.getInstance().getHerbalismXPWheat();
|
|
||||||
|
|
||||||
if (Permissions.greenThumbWheat(player)) {
|
|
||||||
greenThumbWheat(block, player, event, plugin);
|
greenThumbWheat(block, player, event, plugin);
|
||||||
}
|
}
|
||||||
break;
|
else {
|
||||||
|
|
||||||
case MELON_BLOCK:
|
|
||||||
if (!mcMMO.placeStore.isTrue(block)) {
|
if (!mcMMO.placeStore.isTrue(block)) {
|
||||||
mat = Material.MELON;
|
dropItem = herbalismBlock.getDropItem();
|
||||||
xp = Config.getInstance().getHerbalismXPMelon();
|
xp = herbalismBlock.getXpGain();
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NETHER_WARTS:
|
|
||||||
mat = Material.NETHER_STALK;
|
|
||||||
xp = Config.getInstance().getHerbalismXPNetherWart();
|
|
||||||
|
|
||||||
if (Permissions.greenThumbNetherwart(player)) {
|
|
||||||
greenThumbWheat(block, player, event, plugin);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PUMPKIN:
|
|
||||||
if (!mcMMO.placeStore.isTrue(block)) {
|
|
||||||
mat = Material.getMaterial(id);
|
|
||||||
xp = Config.getInstance().getHerbalismXPPumpkin();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RED_ROSE:
|
|
||||||
case YELLOW_FLOWER:
|
|
||||||
if (!mcMMO.placeStore.isTrue(block)) {
|
|
||||||
mat = Material.getMaterial(id);
|
|
||||||
xp = Config.getInstance().getHerbalismXPFlowers();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SUGAR_CANE_BLOCK:
|
|
||||||
for (int y = 0; y <= 2; y++) {
|
|
||||||
Block b = block.getRelative(0, y, 0);
|
|
||||||
if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) {
|
|
||||||
mat = Material.SUGAR_CANE;
|
|
||||||
if (!mcMMO.placeStore.isTrue(b)) {
|
|
||||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
|
||||||
caneDrops++;
|
|
||||||
}
|
|
||||||
xp += Config.getInstance().getHerbalismXPSugarCane();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
else {
|
||||||
|
customBlock = ModChecks.getCustomBlock(block);
|
||||||
case VINE:
|
dropItem = customBlock.getItemDrop();
|
||||||
if (!mcMMO.placeStore.isTrue(block)) {
|
xp = customBlock.getXpGain();
|
||||||
mat = type;
|
|
||||||
xp = Config.getInstance().getHerbalismXPVines();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WATER_LILY:
|
|
||||||
if (!mcMMO.placeStore.isTrue(block)) {
|
|
||||||
mat = type;
|
|
||||||
xp = Config.getInstance().getHerbalismXPLilyPads();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COCOA:
|
|
||||||
mat = type;
|
|
||||||
xp = Config.getInstance().getHerbalismXPCocoa();
|
|
||||||
|
|
||||||
if (Permissions.greenThumbCocoa(player)) {
|
|
||||||
greenThumbWheat(block, player, event, plugin);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CARROT:
|
|
||||||
mat = Material.CARROT;
|
|
||||||
xp = Config.getInstance().getHerbalismXPCarrot();
|
|
||||||
|
|
||||||
if (Permissions.greenThumbCarrots(player)) {
|
|
||||||
greenThumbWheat(block, player, event, plugin);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case POTATO:
|
|
||||||
mat = Material.POTATO;
|
|
||||||
xp = Config.getInstance().getHerbalismXPPotato();
|
|
||||||
|
|
||||||
if (Permissions.greenThumbPotatoes(player)) {
|
|
||||||
greenThumbWheat(block, player, event, plugin);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// We REALLY shouldn't have to check this again, given that we check it in the BlockChecks before this function is even called.
|
|
||||||
// Safe to remove?
|
|
||||||
|
|
||||||
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
|
||||||
|
|
||||||
if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
|
|
||||||
customPlant = true;
|
|
||||||
xp = ModChecks.getCustomBlock(block).getXpGain();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mat == null && !customPlant) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Permissions.herbalismDoubleDrops(player)) {
|
if (Permissions.herbalismDoubleDrops(player)) {
|
||||||
ItemStack is = null;
|
int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player));
|
||||||
|
double chance = (doubleDropsMaxChance / doubleDropsMaxLevel) * Misc.skillCheck(herbLevel, doubleDropsMaxLevel);
|
||||||
if (customPlant) {
|
|
||||||
is = new ItemStack(ModChecks.getCustomBlock(block).getItemDrop());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (mat == Material.COCOA) {
|
|
||||||
try {
|
|
||||||
is = new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData());
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
is = new ItemStack(Material.INK_SACK, 1, (short) 3);
|
|
||||||
}
|
|
||||||
catch (NoSuchMethodError e) {
|
|
||||||
is = new ItemStack(Material.INK_SACK, 1, (short) 3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (mat == Material.CARROT) {
|
|
||||||
is = new ItemStack(Material.CARROT_ITEM);
|
|
||||||
}
|
|
||||||
else if (mat == Material.POTATO) {
|
|
||||||
is = new ItemStack(Material.POTATO_ITEM);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
is = new ItemStack(mat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||||
Config configInstance = Config.getInstance();
|
Location location = block.getLocation();
|
||||||
|
|
||||||
switch (type) {
|
if (herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
|
||||||
case BROWN_MUSHROOM:
|
Misc.dropItems(location, dropItem, dropAmount);
|
||||||
if (configInstance.getBrownMushroomsDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
}
|
||||||
break;
|
else if (customBlock != null){
|
||||||
|
|
||||||
case CACTUS:
|
|
||||||
if (configInstance.getCactiDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItems(location, is, catciDrops);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CROPS:
|
|
||||||
if (configInstance.getWheatDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MELON_BLOCK:
|
|
||||||
if (configInstance.getMelonsDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NETHER_WARTS:
|
|
||||||
if (configInstance.getNetherWartsDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PUMPKIN:
|
|
||||||
if (configInstance.getPumpkinsDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RED_MUSHROOM:
|
|
||||||
if (configInstance.getRedMushroomsDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SUGAR_CANE_BLOCK:
|
|
||||||
if (configInstance.getSugarCaneDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItems(location, is, caneDrops);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VINE:
|
|
||||||
if (configInstance.getVinesDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WATER_LILY:
|
|
||||||
if (configInstance.getWaterLiliesDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case YELLOW_FLOWER:
|
|
||||||
if (configInstance.getYellowFlowersDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case COCOA:
|
|
||||||
if (configInstance.getCocoaDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CARROT:
|
|
||||||
if (configInstance.getCarrotDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case POTATO:
|
|
||||||
if (configInstance.getPotatoDoubleDropsEnabled()) {
|
|
||||||
Misc.dropItem(location, is);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (customPlant) {
|
|
||||||
CustomBlock customBlock = ModChecks.getCustomBlock(block);
|
|
||||||
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
||||||
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
||||||
|
|
||||||
is = customBlock.getItemDrop();
|
|
||||||
|
|
||||||
if (minimumDropAmount != maximumDropAmount) {
|
if (minimumDropAmount != maximumDropAmount) {
|
||||||
Misc.dropItems(location, is, minimumDropAmount);
|
Misc.randomDropItems(location, dropItem, 50, maximumDropAmount - minimumDropAmount);
|
||||||
Misc.randomDropItems(location, is, 50, maximumDropAmount - minimumDropAmount);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Misc.dropItems(location, is, minimumDropAmount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle())
|
Misc.dropItems(location, dropItem, minimumDropAmount);
|
||||||
return;
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SkillTools.xpProcessing(player, profile, SkillType.HERBALISM, xp);
|
SkillTools.xpProcessing(player, profile, SkillType.HERBALISM, xp);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
package com.gmail.nossr50.skills.herbalism;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.config.Config;
|
||||||
|
import com.gmail.nossr50.util.Permissions;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
public enum HerbalismBlock {
|
||||||
|
BROWN_MUSHROOM(Material.BROWN_MUSHROOM, Config.getInstance().getHerbalismXPMushrooms(), Config.getInstance().getBrownMushroomsDoubleDropsEnabled()),
|
||||||
|
CACTUS(Material.CACTUS, Config.getInstance().getHerbalismXPCactus(), Config.getInstance().getCactiDoubleDropsEnabled()),
|
||||||
|
CARROT(Material.CARROT, Material.CARROT_ITEM, Config.getInstance().getHerbalismXPCarrot(), Config.getInstance().getCarrotDoubleDropsEnabled()),
|
||||||
|
COCOA(Material.COCOA, new ItemStack(Material.INK_SACK, 1, (short) 3), Config.getInstance().getHerbalismXPCocoa(), Config.getInstance().getCocoaDoubleDropsEnabled()), //Change to DyeColor.BROWN once we remove backwards compatibility
|
||||||
|
CROPS(Material.CROPS, Material.WHEAT, Config.getInstance().getHerbalismXPWheat(), Config.getInstance().getWheatDoubleDropsEnabled()),
|
||||||
|
MELON_BLOCK(Material.MELON_BLOCK, Material.MELON, Config.getInstance().getHerbalismXPMelon(), Config.getInstance().getMelonsDoubleDropsEnabled()),
|
||||||
|
NETHER_WARTS(Material.NETHER_WARTS, Material.NETHER_STALK, Config.getInstance().getHerbalismXPNetherWart(), Config.getInstance().getNetherWartsDoubleDropsEnabled()),
|
||||||
|
POTATO(Material.POTATO, Material.POTATO_ITEM, Config.getInstance().getHerbalismXPPotato(), Config.getInstance().getPotatoDoubleDropsEnabled()),
|
||||||
|
PUMPKIN(Material.PUMPKIN, Config.getInstance().getHerbalismXPPumpkin(), Config.getInstance().getPumpkinsDoubleDropsEnabled()),
|
||||||
|
RED_MUSHROOM(Material.RED_MUSHROOM, Config.getInstance().getHerbalismXPMushrooms(), Config.getInstance().getRedMushroomsDoubleDropsEnabled()),
|
||||||
|
RED_ROSE(Material.RED_ROSE, Config.getInstance().getHerbalismXPFlowers(), Config.getInstance().getRedRosesDoubleDropsEnabled()),
|
||||||
|
SUGAR_CANE_BLOCK(Material.SUGAR_CANE_BLOCK, Material.SUGAR_CANE, Config.getInstance().getHerbalismXPSugarCane(), Config.getInstance().getSugarCaneDoubleDropsEnabled()),
|
||||||
|
VINE(Material.VINE, Config.getInstance().getHerbalismXPVines(), Config.getInstance().getVinesDoubleDropsEnabled()),
|
||||||
|
WATER_LILY(Material.WATER_LILY, Config.getInstance().getHerbalismXPLilyPads(), Config.getInstance().getWaterLiliesDoubleDropsEnabled()),
|
||||||
|
YELLOW_FLOWER(Material.YELLOW_FLOWER, Config.getInstance().getHerbalismXPFlowers(), Config.getInstance().getYellowFlowersDoubleDropsEnabled());
|
||||||
|
|
||||||
|
private Material blockType;
|
||||||
|
private ItemStack dropItem;
|
||||||
|
private int xpGain;
|
||||||
|
private boolean doubleDropsEnabled;
|
||||||
|
private final static Map<Material, HerbalismBlock> BY_MATERIAL = Maps.newHashMap();
|
||||||
|
|
||||||
|
private HerbalismBlock(Material blockType, int xpGain, boolean doubleDropsEnabled) {
|
||||||
|
this(blockType, new ItemStack(blockType), xpGain, doubleDropsEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HerbalismBlock(Material blockType, Material dropType, int xpGain, boolean doubleDropsEnabled) {
|
||||||
|
this(blockType, new ItemStack(dropType), xpGain, doubleDropsEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HerbalismBlock(Material blockType, ItemStack dropItem, int xpGain, boolean doubleDropsEnabled) {
|
||||||
|
this.blockType = blockType;
|
||||||
|
this.dropItem = dropItem;
|
||||||
|
this.xpGain = xpGain;
|
||||||
|
this.doubleDropsEnabled = doubleDropsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (HerbalismBlock herbalismBlock : values()) {
|
||||||
|
BY_MATERIAL.put(herbalismBlock.blockType, herbalismBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getDropItem() {
|
||||||
|
return dropItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getXpGain() {
|
||||||
|
return xpGain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canDoubleDrop() {
|
||||||
|
return doubleDropsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasGreenThumbPermission(Player player) {
|
||||||
|
switch (this) {
|
||||||
|
case CARROT:
|
||||||
|
return Permissions.greenThumbCarrots(player);
|
||||||
|
case COCOA:
|
||||||
|
return Permissions.greenThumbCocoa(player);
|
||||||
|
case CROPS:
|
||||||
|
return Permissions.greenThumbWheat(player);
|
||||||
|
case POTATO:
|
||||||
|
return Permissions.greenThumbPotatoes(player);
|
||||||
|
case NETHER_WARTS:
|
||||||
|
return Permissions.greenThumbNetherwart(player);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HerbalismBlock getHerbalismBlock(Material blockType) {
|
||||||
|
return BY_MATERIAL.get(blockType);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user