Prevent accidentally breaking regrown crops

Adds #828
This commit is contained in:
TfT_02 2014-04-06 14:41:40 +02:00
parent 56e625a9df
commit 618cfad100
5 changed files with 22 additions and 0 deletions

View File

@ -8,6 +8,7 @@ Key:
- Removal
Version 1.5.01-dev
+ Added new feature to Herbalism. Instantly-regrown crops are protected from being broken for 1 second
+ Added option to config.yml to show the /mcstats scoreboard automatically after logging in
+ Added support for `MATERIAL|data` format in treasures.yml
= Fixed bug where the Updater was running on the main thread.

View File

@ -34,6 +34,7 @@ import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.runnables.StickyPistonTrackerTask;
import com.gmail.nossr50.skills.alchemy.Alchemy;
import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.smelting.SmeltingManager;
@ -227,6 +228,11 @@ public class BlockListener implements Listener {
BlockState blockState = event.getBlock().getState();
ItemStack heldItem = player.getItemInHand();
if (Herbalism.isRecentlyRegrown(blockState)) {
event.setCancelled(true);
return;
}
if (ItemUtils.isSword(heldItem)) {
HerbalismManager herbalismManager = UserManager.getPlayer(player).getHerbalismManager();

View File

@ -107,6 +107,7 @@ public class mcMMO extends JavaPlugin {
public final static String customDamageKey = "mcMMO: Custom Damage";
public final static String disarmedItemKey = "mcMMO: Disarmed Item";
public final static String playerDataKey = "mcMMO: Player Data";
public final static String greenThumbDataKey = "mcMMO: Green Thumb";
public static FixedMetadataValue metadataValue;

View File

@ -8,6 +8,7 @@ import org.bukkit.material.SmoothBrick;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.util.skills.SkillUtils;
public class Herbalism {
public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
@ -93,4 +94,14 @@ public class Herbalism {
return false;
}
}
/**
* Check if the block has a recently grown crop from Green Thumb
*
* @param blockState The {@link BlockState} to check green thumb regrown for
* @return true if the block is recently regrown, false otherwise
*/
public static boolean isRecentlyRegrown(BlockState blockState) {
return blockState.hasMetadata(mcMMO.greenThumbDataKey) && !SkillUtils.cooldownExpired(blockState.getMetadata(mcMMO.greenThumbDataKey).get(0).asInt(), 1);
}
}

View File

@ -14,6 +14,7 @@ import org.bukkit.material.CocoaPlant;
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
import org.bukkit.material.Crops;
import org.bukkit.material.NetherWarts;
import org.bukkit.metadata.FixedMetadataValue;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
@ -330,6 +331,8 @@ public class HerbalismManager extends SkillManager {
private boolean handleBlockState(BlockState blockState, boolean greenTerra) {
byte greenThumbStage = getGreenThumbStage();
blockState.setMetadata(mcMMO.greenThumbDataKey, new FixedMetadataValue(mcMMO.p, (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR)));
switch (blockState.getType()) {
case CROPS:
Crops crops = (Crops) blockState.getData();