Skip to content

Commit cb011a8

Browse files
Add moisture-change flag (#1879) (#2096)
* Create and implement moisture-change flag * Fix imports * Add comment * Actually read the value from config. Closes #1879 --------- Co-authored-by: wizjany <wizjany@gmail.com>
1 parent 0f3ea50 commit cb011a8

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public void loadConfiguration() {
283283
disableSculkGrowth = getBoolean("dynamics.disable-sculk-growth", false);
284284
disableCropGrowth = getBoolean("dynamics.disable-crop-growth", false);
285285
disableSoilDehydration = getBoolean("dynamics.disable-soil-dehydration", false);
286+
disableSoilMoistureChange = getBoolean("dynamics.disable-soil-moisture-change", false);
286287
disableCoralBlockFade = getBoolean("dynamics.disable-coral-block-fade", false);
287288
disableCopperBlockFade = getBoolean("dynamics.disable-copper-block-fade", false);
288289
allowedSnowFallOver = new HashSet<>(convertLegacyBlocks(getStringList("dynamics.snow-fall-blocks", null)));

worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardBlockListener.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.bukkit.event.block.BlockSpreadEvent;
5757
import org.bukkit.event.block.EntityBlockFormEvent;
5858
import org.bukkit.event.block.LeavesDecayEvent;
59+
import org.bukkit.event.block.MoistureChangeEvent;
5960
import org.bukkit.inventory.ItemStack;
6061
import org.bukkit.inventory.meta.Damageable;
6162
import org.bukkit.inventory.meta.ItemMeta;
@@ -726,4 +727,24 @@ public void onBlockExplode(BlockExplodeEvent event) {
726727
}
727728
}
728729

730+
/**
731+
* Called when the moisture level of a block changes
732+
*/
733+
@EventHandler(ignoreCancelled = true)
734+
public void onMoistureChange(MoistureChangeEvent event) {
735+
WorldConfiguration wcfg = getWorldConfig(event.getBlock().getWorld());
736+
737+
if (wcfg.disableSoilMoistureChange) {
738+
event.setCancelled(true);
739+
return;
740+
}
741+
742+
if (wcfg.useRegions) {
743+
if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
744+
.queryState(BukkitAdapter.adapt(event.getBlock().getLocation()), (RegionAssociable) null, Flags.MOISTURE_CHANGE))) {
745+
event.setCancelled(true);
746+
}
747+
}
748+
}
749+
729750
}

worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public abstract class WorldConfiguration {
167167
public boolean disableEndermanGriefing;
168168
public boolean disableSnowmanTrails;
169169
public boolean disableSoilDehydration;
170+
public boolean disableSoilMoistureChange;
170171
public boolean disableCoralBlockFade;
171172
public boolean disableCopperBlockFade;
172173
public Set<String> allowedSnowFallOver;

worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/Flags.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public final class Flags {
130130
public static final StateFlag COPPER_FADE = register(new StateFlag("copper-fade", true));
131131
public static final StateFlag WATER_FLOW = register(new StateFlag("water-flow", true));
132132
public static final StateFlag LAVA_FLOW = register(new StateFlag("lava-flow", true));
133+
public static final StateFlag MOISTURE_CHANGE = register(new StateFlag("moisture-change", true));
133134

134135
public static final RegistryFlag<WeatherType> WEATHER_LOCK = register(new RegistryFlag<>("weather-lock", WeatherType.REGISTRY));
135136
public static final StringFlag TIME_LOCK = register(new StringFlag("time-lock"));

0 commit comments

Comments
 (0)