Add crop-growth flag/config option.

Fixes WORLDGUARD-4088.
This commit is contained in:
wizjany 2019-05-27 20:42:17 -04:00
parent ce35798f67
commit 029f867a41
5 changed files with 37 additions and 0 deletions

View File

@ -145,6 +145,7 @@ public abstract class WorldConfiguration {
public boolean disableGrassGrowth;
public boolean disableMyceliumSpread;
public boolean disableVineGrowth;
public boolean disableCropGrowth;
public boolean disableEndermanGriefing;
public boolean disableSnowmanTrails;
public boolean disableSoilDehydration;

View File

@ -114,6 +114,7 @@ public final class Flags {
public static final StateFlag GRASS_SPREAD = register(new StateFlag("grass-growth", true));
public static final StateFlag MYCELIUM_SPREAD = register(new StateFlag("mycelium-spread", true));
public static final StateFlag VINE_GROWTH = register(new StateFlag("vine-growth", true));
public static final StateFlag CROP_GROWTH = register(new StateFlag("crop-growth", true));
public static final StateFlag SOIL_DRY = register(new StateFlag("soil-dry", true));
public static final StateFlag WATER_FLOW = register(new StateFlag("water-flow", true));
public static final StateFlag LAVA_FLOW = register(new StateFlag("lava-flow", true));

View File

@ -244,6 +244,7 @@ public void loadConfiguration() {
disableGrassGrowth = getBoolean("dynamics.disable-grass-growth", false);
disableMyceliumSpread = getBoolean("dynamics.disable-mycelium-spread", false);
disableVineGrowth = getBoolean("dynamics.disable-vine-growth", false);
disableCropGrowth = getBoolean("dynamics.disable-crop-growth", false);
disableSoilDehydration = getBoolean("dynamics.disable-soil-dehydration", false);
allowedSnowFallOver = new HashSet<>(convertLegacyBlocks(getStringList("dynamics.snow-fall-blocks", null)));

View File

@ -45,6 +45,7 @@
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.block.BlockPhysicsEvent;
@ -616,6 +617,25 @@ public void onBlockSpread(BlockSpreadEvent event) {
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockGrow(BlockGrowEvent event) {
WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
final Material type = event.getBlock().getType();
if (Materials.isCrop(type)) {
if (wcfg.disableCropGrowth) {
event.setCancelled(false);
return;
}
if (wcfg.useRegions && !StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.CROP_GROWTH))) {
event.setCancelled(true);
return;
}
}
}
/*
* Called when a block fades.
*/

View File

@ -1148,6 +1148,20 @@ public static boolean isBed(Material material) {
}
}
/**
* Test whether the material is a crop.
* @param type the material
* @return true if the material is a crop
*/
public static boolean isCrop(Material type) {
return type == Material.WHEAT
|| type == Material.CARROTS
|| type == Material.POTATOES
|| type == Material.BEETROOTS
|| type == Material.MELON_STEM
|| type == Material.PUMPKIN_STEM;
}
/**
* Test whether the given material is affected by
* {@link Flags#USE}.