From 5344efd1b73d2bc6c61df0649d91d36ab54552d4 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 2 Mar 2024 13:43:16 +0100 Subject: [PATCH] feat: introduce a fishing flag (#4343) * introduce fishing flag * fixed typo in description * added details to the flags description --- .../bukkit/listener/PaperListener.java | 6 +++ .../listener/ProjectileEventListener.java | 10 ++++- .../core/plot/flag/GlobalFlagContainer.java | 2 + .../flag/implementations/FishingFlag.java | 39 +++++++++++++++++++ Core/src/main/resources/lang/messages_en.json | 1 + 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FishingFlag.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 6bd528d3b..9570cf3c2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -40,6 +40,7 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.flag.FlagContainer; import com.plotsquared.core.plot.flag.implementations.BeaconEffectsFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; +import com.plotsquared.core.plot.flag.implementations.FishingFlag; import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag; import com.plotsquared.core.plot.flag.types.BooleanFlag; import com.plotsquared.core.plot.world.PlotAreaManager; @@ -348,6 +349,11 @@ public class PaperListener implements Listener { event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { + if (entity.getType().equals(EntityType.FISHING_HOOK)) { + if (plot.getFlag(FishingFlag.class)) { + return; + } + } if (!plot.getFlag(ProjectilesFlag.class)) { if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { pp.sendMessage( 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 e84695445..8c79b29d3 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java @@ -28,12 +28,14 @@ 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.FishingFlag; import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.PlotFlagUtil; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; @@ -132,6 +134,11 @@ public class ProjectileEventListener implements Listener { event.setCancelled(true); } } else if (!plot.isAdded(pp.getUUID())) { + if (entity.getType().equals(EntityType.FISHING_HOOK)) { + if (plot.getFlag(FishingFlag.class)) { + return; + } + } if (!plot.getFlag(ProjectilesFlag.class)) { if (!pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER)) { pp.sendMessage( @@ -187,7 +194,8 @@ public class ProjectileEventListener implements Listener { return; } if (plot.isAdded(pp.getUUID()) || pp.hasPermission(Permission.PERMISSION_ADMIN_PROJECTILE_OTHER) || plot.getFlag( - ProjectilesFlag.class)) { + ProjectilesFlag.class) || (entity.getType().equals(EntityType.FISHING_HOOK) && plot.getFlag( + FishingFlag.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 cce9d1af3..2183b008f 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 @@ -48,6 +48,7 @@ import com.plotsquared.core.plot.flag.implementations.EntityChangeBlockFlag; import com.plotsquared.core.plot.flag.implementations.ExplosionFlag; import com.plotsquared.core.plot.flag.implementations.FarewellFlag; import com.plotsquared.core.plot.flag.implementations.FeedFlag; +import com.plotsquared.core.plot.flag.implementations.FishingFlag; import com.plotsquared.core.plot.flag.implementations.FlyFlag; import com.plotsquared.core.plot.flag.implementations.ForcefieldFlag; import com.plotsquared.core.plot.flag.implementations.GamemodeFlag; @@ -158,6 +159,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(EditSignFlag.EDIT_SIGN_FALSE); this.addFlag(EntityChangeBlockFlag.ENTITY_CHANGE_BLOCK_FALSE); this.addFlag(ExplosionFlag.EXPLOSION_FALSE); + this.addFlag(FishingFlag.FISHING_FALSE); this.addFlag(ForcefieldFlag.FORCEFIELD_FALSE); this.addFlag(GrassGrowFlag.GRASS_GROW_TRUE); this.addFlag(HangingBreakFlag.HANGING_BREAK_FALSE); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FishingFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FishingFlag.java new file mode 100644 index 000000000..7cbe03f67 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FishingFlag.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 FishingFlag extends BooleanFlag { + + public static final FishingFlag FISHING_TRUE = new FishingFlag(true); + public static final FishingFlag FISHING_FALSE = new FishingFlag(false); + + private FishingFlag(boolean value) { + super(value, TranslatableCaption.of("flags.flag_description_fishing")); + } + + @Override + protected FishingFlag flagOf(@NonNull final Boolean value) { + return value ? FISHING_TRUE : FISHING_FALSE; + } + +} diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index a0d4e42d1..06cbd5209 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -559,6 +559,7 @@ "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).", + "flags.flag_description_fishing": "Set to `true` to allow guests to use a fishing rod in the plot.", "flags.flag_description_forcefield": "Set to `true` to enable member forcefield in the plot.", "flags.flag_description_grass_grow": "Set to `false` to prevent grass from growing within the plot.", "flags.flag_description_hanging_break": "Set to `true` to allow guests to break hanging objects in the plot.",