From f49ddb819d69bbc2455c626b3ab9023f26d47883 Mon Sep 17 00:00:00 2001 From: Bernhard Date: Wed, 4 May 2022 23:21:24 +0200 Subject: [PATCH] Add Plot flag for projectiles (#3581) * feature: add flag for projectiles * build: add License to ProjectilesFlag.java Co-authored-by: Alexander Brandes --- .../bukkit/listener/PaperListener.java | 17 ++++--- .../listener/ProjectileEventListener.java | 19 ++++---- .../core/plot/flag/GlobalFlagContainer.java | 2 + .../flag/implementations/ProjectilesFlag.java | 46 +++++++++++++++++++ Core/src/main/resources/lang/messages_en.json | 1 + 5 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ProjectilesFlag.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java index 012fee6ff..079d04fe3 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -44,6 +44,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.DoneFlag; +import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.Permissions; import net.kyori.adventure.text.minimessage.Template; @@ -352,13 +353,15 @@ public class PaperListener implements Listener { event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { - pp.sendMessage( - TranslatableCaption.of("permission.no_permission_event"), - Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) - ); - entity.remove(); - event.setCancelled(true); + if (!plot.getFlag(ProjectilesFlag.class)) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { + pp.sendMessage( + TranslatableCaption.of("permission.no_permission_event"), + Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) + ); + entity.remove(); + event.setCancelled(true); + } } } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java index 8754c4520..a09cf6943 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java @@ -35,6 +35,7 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotHandler; +import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.Permissions; import net.kyori.adventure.text.minimessage.Template; @@ -128,13 +129,15 @@ public class ProjectileEventListener implements Listener { event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { - pp.sendMessage( - TranslatableCaption.of("permission.no_permission_event"), - Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) - ); - entity.remove(); - event.setCancelled(true); + if (!plot.getFlag(ProjectilesFlag.class)) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { + pp.sendMessage( + TranslatableCaption.of("permission.no_permission_event"), + Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) + ); + entity.remove(); + event.setCancelled(true); + } } } } @@ -162,7 +165,7 @@ public class ProjectileEventListener implements Listener { return; } if (plot.isAdded(pp.getUUID()) || Permissions - .hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { + .hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_OTHER) || plot.getFlag(ProjectilesFlag.class)) { 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 3b7c572d7..052086464 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 @@ -93,6 +93,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.ProjectilesFlag; import com.plotsquared.core.plot.flag.implementations.PveFlag; import com.plotsquared.core.plot.flag.implementations.PvpFlag; import com.plotsquared.core.plot.flag.implementations.RedstoneFlag; @@ -198,6 +199,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(VehicleUseFlag.VEHICLE_USE_FALSE); this.addFlag(VillagerInteractFlag.VILLAGER_INTERACT_FALSE); this.addFlag(VineGrowFlag.VINE_GROW_TRUE); + this.addFlag(ProjectilesFlag.PROJECTILES_FALSE); // Double flags this.addFlag(PriceFlag.PRICE_NOT_BUYABLE); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ProjectilesFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ProjectilesFlag.java new file mode 100644 index 000000000..a8953b084 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ProjectilesFlag.java @@ -0,0 +1,46 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2014 - 2022 IntellectualSites + * + * 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 ProjectilesFlag extends BooleanFlag { + + public static final ProjectilesFlag PROJECTILES_TRUE = new ProjectilesFlag(true); + public static final ProjectilesFlag PROJECTILES_FALSE = new ProjectilesFlag(false); + + private ProjectilesFlag(boolean value){ + super(value, TranslatableCaption.of("flags.flag_description_projectiles")); + } + + @Override + protected ProjectilesFlag flagOf(@NonNull final Boolean value) { + return value ? PROJECTILES_TRUE : PROJECTILES_FALSE; + } + +} diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 50b3639df..bc189c8c9 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -613,6 +613,7 @@ "flags.flag_description_lectern_read_book": "Prevent players taking books from lecterns.", "flags.flag_description_prevent_creative_copy": "Prevents people from copying item NBT data in the plot unless they're added as members.", "flags.flag_description_leaf_decay": "Set to `false` to prevent leaves from decaying.", + "flags.flag_description_projectiles": "Prevents guests from shooting projectiles on the plot when set to false.", "flags.flag_error_boolean": "Flag value must be a boolean (true | false).", "flags.flag_error_enum": "Must be one of: ", "flags.flag_error_integer": "Flag value must be a whole positive number.",