From 4a45729c9ee71c283589cab95295273f5246f4b2 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 12 Dec 2023 13:53:10 +0000 Subject: [PATCH] feat: add projectile-change-block flag (#4185) - closes #4081 --- .../bukkit/listener/EntityEventListener.java | 5 ++- .../core/plot/flag/GlobalFlagContainer.java | 2 + .../ProjectileChangeBlockFlag.java | 39 +++++++++++++++++++ Core/src/main/resources/lang/messages_en.json | 1 + 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ProjectileChangeBlockFlag.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java index 783eacd2b..6a147185f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java @@ -35,6 +35,7 @@ import com.plotsquared.core.plot.flag.implementations.DisablePhysicsFlag; import com.plotsquared.core.plot.flag.implementations.EntityChangeBlockFlag; import com.plotsquared.core.plot.flag.implementations.ExplosionFlag; import com.plotsquared.core.plot.flag.implementations.InvincibleFlag; +import com.plotsquared.core.plot.flag.implementations.ProjectileChangeBlockFlag; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.PlotFlagUtil; @@ -358,13 +359,13 @@ public class EntityEventListener implements Listener { if (shooter instanceof Player) { PlotPlayer pp = BukkitUtil.adapt((Player) shooter); if (plot == null) { - if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) { + if (area.isRoadFlags() && !area.getRoadFlag(ProjectileChangeBlockFlag.class) && !pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) { entity.remove(); event.setCancelled(true); } return; } - if (plot.isAdded(pp.getUUID()) || pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { + if (plot.isAdded(pp.getUUID()) || plot.getFlag(ProjectileChangeBlockFlag.class) || pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { return; } entity.remove(); 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 fe2eb2398..cce9d1af3 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 @@ -89,6 +89,7 @@ import com.plotsquared.core.plot.flag.implementations.PlayerInteractFlag; import com.plotsquared.core.plot.flag.implementations.PlotTitleFlag; import com.plotsquared.core.plot.flag.implementations.PreventCreativeCopyFlag; import com.plotsquared.core.plot.flag.implementations.PriceFlag; +import com.plotsquared.core.plot.flag.implementations.ProjectileChangeBlockFlag; import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag; import com.plotsquared.core.plot.flag.implementations.PveFlag; import com.plotsquared.core.plot.flag.implementations.PvpFlag; @@ -185,6 +186,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(NoWorldeditFlag.NO_WORLDEDIT_FALSE); this.addFlag(PlayerInteractFlag.PLAYER_INTERACT_FALSE); this.addFlag(PreventCreativeCopyFlag.PREVENT_CREATIVE_COPY_FALSE); + this.addFlag(ProjectileChangeBlockFlag.PROJECTILE_CHANGE_BLOCK_FALSE); this.addFlag(PveFlag.PVE_FALSE); this.addFlag(PvpFlag.PVP_FALSE); this.addFlag(RedstoneFlag.REDSTONE_TRUE); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ProjectileChangeBlockFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ProjectileChangeBlockFlag.java new file mode 100644 index 000000000..ba957ff8e --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ProjectileChangeBlockFlag.java @@ -0,0 +1,39 @@ +/* + * 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 ProjectileChangeBlockFlag extends BooleanFlag { + + public static final ProjectileChangeBlockFlag PROJECTILE_CHANGE_BLOCK_TRUE = new ProjectileChangeBlockFlag(true); + public static final ProjectileChangeBlockFlag PROJECTILE_CHANGE_BLOCK_FALSE = new ProjectileChangeBlockFlag(false); + + private ProjectileChangeBlockFlag(boolean value) { + super(value, TranslatableCaption.of("flags.flag_description_projectile_change_block")); + } + + @Override + protected ProjectileChangeBlockFlag flagOf(@NonNull Boolean value) { + return value ? PROJECTILE_CHANGE_BLOCK_TRUE : PROJECTILE_CHANGE_BLOCK_FALSE; + } + +} diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 72e1f72c7..967520b59 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -589,6 +589,7 @@ "flags.flag_description_place": "Define a list of materials players should be able to place in the plot.", "flags.flag_description_player_interact": "Set to `true` to allow guests to interact with players in the plot.", "flags.flag_description_price": "Set a price for a plot. Must be a positive decimal number.", + "flags.flag_description_projectile_change_block": "Set to `true` to allow projectiles to change blocks (tnt, etc.) on the plot.", "flags.flag_description_pve": "Set to `true` to enable PVE inside the plot.", "flags.flag_description_pvp": "Set to `true` to enable PVP inside the plot.", "flags.flag_description_redstone": "Set to `false` to disable redstone in the plot.",