diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/HighFreqBlockEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/HighFreqBlockEventListener.java index 24a01eb996..82ebd407c7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/HighFreqBlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/HighFreqBlockEventListener.java @@ -28,6 +28,7 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.flag.implementations.DisableBlockUpdateFlag; import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag; import com.plotsquared.core.plot.flag.implementations.RedstoneFlag; import com.plotsquared.core.plot.world.PlotAreaManager; @@ -47,6 +48,7 @@ import org.bukkit.event.block.BlockRedstoneEvent; import org.checkerframework.checker.nullness.qual.NonNull; +import java.util.Locale; import java.util.Set; import java.util.UUID; @@ -152,6 +154,7 @@ public void onRedstoneEvent(BlockRedstoneEvent event) { @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPhysicsEvent(BlockPhysicsEvent event) { Block block = event.getBlock(); + Block sourceBlock = event.getSourceBlock(); Location location = BukkitUtil.adapt(block.getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { @@ -167,6 +170,18 @@ public void onPhysicsEvent(BlockPhysicsEvent event) { plot.debug("Prevented block physics and resent block change because disable-physics = true"); return; } + if (plot.getFlag(DisableBlockUpdateFlag.class)) { + if (!event.getChangedType().hasGravity()) { + if (sourceBlock.getType().isAir() || block.getType().isAir()) { + return; + } + if (!sourceBlock.getType().name().toLowerCase(Locale.ROOT).contains("snow") + || !block.getLocation().add(0, -1, 0).getBlock().getType().equals(Material.GRASS_BLOCK)) { + event.setCancelled(true); + plot.debug("Prevented block update because disable-block-update = true"); + } + } + } if (event.getChangedType() == Material.COMPARATOR) { if (!plot.getFlag(RedstoneFlag.class)) { event.setCancelled(true); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java index 0780493ab3..1cdc7eb4c6 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/GlobalFlagContainer.java @@ -39,6 +39,7 @@ import com.plotsquared.core.plot.flag.implementations.DenyTeleportFlag; import com.plotsquared.core.plot.flag.implementations.DescriptionFlag; import com.plotsquared.core.plot.flag.implementations.DeviceInteractFlag; +import com.plotsquared.core.plot.flag.implementations.DisableBlockUpdateFlag; import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.DropProtectionFlag; @@ -158,6 +159,7 @@ private GlobalFlagContainer() { this.addFlag(DenyPortalTravelFlag.DENY_PORTAL_TRAVEL_FALSE); this.addFlag(DeviceInteractFlag.DEVICE_INTERACT_FALSE); this.addFlag(DisablePhysicsFlag.DISABLE_PHYSICS_FALSE); + this.addFlag(DisableBlockUpdateFlag.DISABLE_BLOCK_UPDATE_FLAG_FALSE); this.addFlag(DropProtectionFlag.DROP_PROTECTION_FALSE); this.addFlag(EditSignFlag.EDIT_SIGN_FALSE); this.addFlag(EntityChangeBlockFlag.ENTITY_CHANGE_BLOCK_FALSE); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DisableBlockUpdateFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DisableBlockUpdateFlag.java new file mode 100644 index 0000000000..c53007c871 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DisableBlockUpdateFlag.java @@ -0,0 +1,38 @@ +/* + * PlotSquared, a land and world management plugin for Minecraft. + * Copyright (C) IntellectualSites + * Copyright (C) IntellectualSites team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.plotsquared.core.plot.flag.implementations; + +import com.plotsquared.core.configuration.caption.TranslatableCaption; +import com.plotsquared.core.plot.flag.types.BooleanFlag; +import org.checkerframework.checker.nullness.qual.NonNull; + +public class DisableBlockUpdateFlag extends BooleanFlag { + + public static final DisableBlockUpdateFlag DISABLE_BLOCK_UPDATE_FLAG_TRUE = new DisableBlockUpdateFlag(true); + public static final DisableBlockUpdateFlag DISABLE_BLOCK_UPDATE_FLAG_FALSE = new DisableBlockUpdateFlag(false); + + private DisableBlockUpdateFlag(boolean value) { + super(value, TranslatableCaption.of("flags.flag_description_disable_block_update")); + } + + @Override + protected DisableBlockUpdateFlag flagOf(@NonNull Boolean value) { + return value ? DISABLE_BLOCK_UPDATE_FLAG_TRUE : DISABLE_BLOCK_UPDATE_FLAG_FALSE; + } +} diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index ead61d08fe..ca913c4caa 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -560,6 +560,7 @@ "flags.flag_description_concrete_harden": "Set to `false` to disable concrete powder forming to concrete with water.", "flags.flag_description_device_interact": "Set to `true` to allow devices to be interacted with in the plot.", "flags.flag_description_disable_physics": "Set to `true` to disable block physics in the plot.", + "flags.flag_description_disable_block_update": "Set to `true` to disable block update in the plot.", "flags.flag_description_drop_protection": "Set to `true` to prevent dropped items from being picked up by non-members of the plot.", "flags.flag_description_edit_sign": "Set to `true` to allow editing signs in the plot.", "flags.flag_description_feed": "Specify an interval in seconds and an optional amount by which the players will be fed (amount is 1 by default).",