From 00f8819832642d62c77d1690a6479d7451d43315 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 8 Nov 2024 16:18:20 +0100 Subject: [PATCH 1/4] add InteractionInteractFlag --- .../bukkit/listener/PlayerEventListener.java | 6 ++++++ .../plotsquared/bukkit/util/BukkitUtil.java | 2 ++ .../core/plot/flag/GlobalFlagContainer.java | 2 ++ .../InteractionInteractFlag.java | 21 +++++++++++++++++++ .../core/util/entity/EntityCategories.java | 1 + Core/src/main/resources/lang/messages_en.json | 1 + 6 files changed, 33 insertions(+) create mode 100644 Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InteractionInteractFlag.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index 45e5a3b2c6..a10fc01e88 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -54,6 +54,7 @@ import com.plotsquared.core.plot.flag.implementations.HangingBreakFlag; import com.plotsquared.core.plot.flag.implementations.HangingPlaceFlag; import com.plotsquared.core.plot.flag.implementations.HostileInteractFlag; +import com.plotsquared.core.plot.flag.implementations.InteractionInteractFlag; import com.plotsquared.core.plot.flag.implementations.ItemDropFlag; import com.plotsquared.core.plot.flag.implementations.KeepInventoryFlag; import com.plotsquared.core.plot.flag.implementations.LecternReadBookFlag; @@ -1737,6 +1738,11 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { return; } + if (EntityCategories.INTERACTION.contains(entityType) && flagContainer + .getFlag(InteractionInteractFlag.class).getValue()) { + return; + } + if (EntityCategories.VILLAGER.contains(entityType) && flagContainer .getFlag(VillagerInteractFlag.class).getValue()) { return; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 124e766e9b..79ed1eaa0c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -75,6 +75,7 @@ import org.bukkit.entity.Firework; import org.bukkit.entity.Ghast; import org.bukkit.entity.Hanging; +import org.bukkit.entity.Interaction; import org.bukkit.entity.IronGolem; import org.bukkit.entity.Item; import org.bukkit.entity.LightningStrike; @@ -470,6 +471,7 @@ public void setFoodLevel(final @NonNull PlotPlayer player, @NonNegative final allowedInterfaces.add(Firework.class); } case "player" -> allowedInterfaces.add(Player.class); + case "interaction" -> allowedInterfaces.add(Interaction.class); default -> LOGGER.error("Unknown entity category requested: {}", category); } final Set types = new HashSet<>(); 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 3e704a021a..0780493ab3 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 @@ -65,6 +65,7 @@ import com.plotsquared.core.plot.flag.implementations.IceFormFlag; import com.plotsquared.core.plot.flag.implementations.IceMeltFlag; import com.plotsquared.core.plot.flag.implementations.InstabreakFlag; +import com.plotsquared.core.plot.flag.implementations.InteractionInteractFlag; import com.plotsquared.core.plot.flag.implementations.InvincibleFlag; import com.plotsquared.core.plot.flag.implementations.ItemDropFlag; import com.plotsquared.core.plot.flag.implementations.KeepFlag; @@ -172,6 +173,7 @@ private GlobalFlagContainer() { this.addFlag(IceFormFlag.ICE_FORM_FALSE); this.addFlag(IceMeltFlag.ICE_MELT_FALSE); this.addFlag(InstabreakFlag.INSTABREAK_FALSE); + this.addFlag(InteractionInteractFlag.INTERACTION_INTERACT_FALSE); this.addFlag(InvincibleFlag.INVINCIBLE_FALSE); this.addFlag(ItemDropFlag.ITEM_DROP_TRUE); this.addFlag(KeepInventoryFlag.KEEP_INVENTORY_FALSE); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InteractionInteractFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InteractionInteractFlag.java new file mode 100644 index 0000000000..45c99f2519 --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InteractionInteractFlag.java @@ -0,0 +1,21 @@ +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 InteractionInteractFlag extends BooleanFlag { + + public static final InteractionInteractFlag INTERACTION_INTERACT_TRUE = new InteractionInteractFlag(true); + public static final InteractionInteractFlag INTERACTION_INTERACT_FALSE = new InteractionInteractFlag(false); + + private InteractionInteractFlag(boolean value) { + super(value, TranslatableCaption.of("flags.flag_description_interaction_interact")); + } + + @Override + protected InteractionInteractFlag flagOf(@NonNull Boolean value) { + return value ? INTERACTION_INTERACT_TRUE : INTERACTION_INTERACT_FALSE; + } + +} diff --git a/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategories.java b/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategories.java index 686048133f..d4125cd068 100644 --- a/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategories.java +++ b/Core/src/main/java/com/plotsquared/core/util/entity/EntityCategories.java @@ -41,6 +41,7 @@ public class EntityCategories { public static final EntityCategory PROJECTILE = register("projectile"); public static final EntityCategory OTHER = register("other"); public static final EntityCategory PLAYER = register("player"); + public static final EntityCategory INTERACTION = register("interaction"); public static EntityCategory register(final String id) { final EntityCategory entityCategory = new EntityCategory(PlotSquared.platform().worldUtil(), id); diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 53e42cbad0..b081e554af 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -572,6 +572,7 @@ "flags.flag_description_ice_form": "Set to `true` to allow ice to form in the plot.", "flags.flag_description_ice_melt": "Set to `false` to disable ice melting in the plot.", "flags.flag_description_instabreak": "Set to `true` to allow blocks to be instantaneously broken in survival mode.", + "flags.flag_description_interaction_interact": "Set to `true` to allow guests to interact with interaction entities in the plot.", "flags.flag_description_invincible": "Set to `true` to prevent players from taking damage inside the plot.", "flags.flag_description_item_drop": "Set to `false` to prevent items from being dropped inside the plot.", "flags.flag_description_kelp_grow": "Set to `false` to prevent kelp from growing in the plot.", From fad73758256a109c5f7de0baaca02d190ab48dc3 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 8 Nov 2024 16:28:52 +0100 Subject: [PATCH 2/4] apply spotless --- .../InteractionInteractFlag.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InteractionInteractFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InteractionInteractFlag.java index 45c99f2519..b11bcd7e78 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InteractionInteractFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InteractionInteractFlag.java @@ -1,3 +1,21 @@ +/* + * 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; From 2ee3f911c81ef5b9e5fd707b6f92b180b4bb0569 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 8 Nov 2024 16:46:59 +0100 Subject: [PATCH 3/4] add version check --- .../main/java/com/plotsquared/bukkit/util/BukkitUtil.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 79ed1eaa0c..d85721f092 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -471,7 +471,12 @@ public void setFoodLevel(final @NonNull PlotPlayer player, @NonNegative final allowedInterfaces.add(Firework.class); } case "player" -> allowedInterfaces.add(Player.class); - case "interaction" -> allowedInterfaces.add(Interaction.class); + case "interaction" -> { + final int[] version = PlotSquared.platform().serverVersion(); + if (version[1] >= 19 && version[2] >= 4) { + allowedInterfaces.add(Interaction.class); + } + } default -> LOGGER.error("Unknown entity category requested: {}", category); } final Set types = new HashSet<>(); From 854294210e75d14c446ed55a73300d67eedef1a0 Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 18 Nov 2024 19:21:56 +0100 Subject: [PATCH 4/4] adjust version check --- .../main/java/com/plotsquared/bukkit/util/BukkitUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index d85721f092..d588a66a47 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -433,6 +433,7 @@ public void setFoodLevel(final @NonNull PlotPlayer player, @NonNegative final @Override public @NonNull Set getTypesInCategory(final @NonNull String category) { final Collection> allowedInterfaces = new HashSet<>(); + final int[] version = PlotSquared.platform().serverVersion(); switch (category) { case "animal" -> { allowedInterfaces.add(IronGolem.class); @@ -440,7 +441,7 @@ public void setFoodLevel(final @NonNull PlotPlayer player, @NonNegative final allowedInterfaces.add(Animals.class); allowedInterfaces.add(WaterMob.class); allowedInterfaces.add(Ambient.class); - if (PlotSquared.platform().serverVersion()[1] >= 19) { + if (version[1] >= 19) { allowedInterfaces.add(Allay.class); } } @@ -472,8 +473,7 @@ public void setFoodLevel(final @NonNull PlotPlayer player, @NonNegative final } case "player" -> allowedInterfaces.add(Player.class); case "interaction" -> { - final int[] version = PlotSquared.platform().serverVersion(); - if (version[1] >= 19 && version[2] >= 4) { + if ((version[1] > 19) || (version[1] == 19 && version[2] >= 4)) { allowedInterfaces.add(Interaction.class); } }