Skip to content

Commit

Permalink
feat: Add DisableBlockUpdateFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
AerWyn81 committed Jan 11, 2025
1 parent fa52149 commit 5a9dea3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* 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 <https://www.gnu.org/licenses/>.
*/
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<DisableBlockUpdateFlag> {

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;
}
}
1 change: 1 addition & 0 deletions Core/src/main/resources/lang/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@
"flags.flag_description_concrete_harden": "<gray>Set to `false` to disable concrete powder forming to concrete with water.</gray>",
"flags.flag_description_device_interact": "<gray>Set to `true` to allow devices to be interacted with in the plot.</gray>",
"flags.flag_description_disable_physics": "<gray>Set to `true` to disable block physics in the plot.</gray>",
"flags.flag_description_disable_block_update": "<gray>Set to `true` to disable block update in the plot.</gray>",
"flags.flag_description_drop_protection": "<gray>Set to `true` to prevent dropped items from being picked up by non-members of the plot.</gray>",
"flags.flag_description_edit_sign": "<gray>Set to `true` to allow editing signs in the plot.</gray>",
"flags.flag_description_feed": "<gray>Specify an interval in seconds and an optional amount by which the players will be fed (amount is 1 by default).</gray>",
Expand Down

0 comments on commit 5a9dea3

Please sign in to comment.