Merge branch 'master' of github.com:mcMMO-Dev/mcmmo into configurable

This commit is contained in:
nossr50
2020-02-20 17:43:58 -08:00
2 changed files with 32 additions and 6 deletions

View File

@ -6,8 +6,11 @@ import com.gmail.nossr50.mcMMO;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.scheduler.BukkitRunnable;
@ -19,6 +22,7 @@ public class DelayedCropReplant extends BukkitRunnable {
private boolean wasImmaturePlant;
private final BlockBreakEvent blockBreakEvent;
private final mcMMO pluginRef;
private BlockFace cropFace;
/**
* Replants a crop after a delay setting the age to desiredCropAge
@ -27,6 +31,13 @@ public class DelayedCropReplant extends BukkitRunnable {
*/
public DelayedCropReplant(mcMMO pluginRef, BlockBreakEvent blockBreakEvent, BlockState cropState, int desiredCropAge, boolean wasImmaturePlant) {
this.pluginRef = pluginRef;
BlockData cropData = cropState.getBlockData();
if(cropData instanceof Directional) {
Directional cropDir = (Directional) cropData;
cropFace = cropDir.getFacing();
}
//The plant was either immature or something cancelled the event, therefor we need to treat it differently
this.blockBreakEvent = blockBreakEvent;
this.wasImmaturePlant = wasImmaturePlant;
@ -53,22 +64,33 @@ public class DelayedCropReplant extends BukkitRunnable {
//The space is not currently occupied by a block so we can fill it
cropBlock.setType(cropMaterial);
//Get new state (necessary?)
BlockState newState = cropBlock.getState();
// newState.update();
BlockData newData = newState.getBlockData();
Ageable ageable = (Ageable) newState.getBlockData();
int age = 0;
//Crop age should always be 0 if the plant was immature
if(wasImmaturePlant) {
ageable.setAge(0);
} else {
if(!wasImmaturePlant) {
age = desiredCropAge;
//Otherwise make the plant the desired age
ageable.setAge(desiredCropAge);
}
if(newData instanceof Directional) {
//Cocoa Version
Directional directional = (Directional) newState.getBlockData();
directional.setFacing(cropFace);
newState.setBlockData(directional);
}
//Age the crop
Ageable ageable = (Ageable) newState.getBlockData();
ageable.setAge(age);
newState.setBlockData(ageable);
newState.update(true);
//Play an effect