diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 018509743..15968fac2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -79,6 +79,7 @@ import com.plotsquared.core.plot.flag.implementations.MobPlaceFlag; import com.plotsquared.core.plot.flag.implementations.MycelGrowFlag; import com.plotsquared.core.plot.flag.implementations.PlaceFlag; import com.plotsquared.core.plot.flag.implementations.PlayerInteractFlag; +import com.plotsquared.core.plot.flag.implementations.PreventCreativeCopyFlag; import com.plotsquared.core.plot.flag.implementations.PveFlag; import com.plotsquared.core.plot.flag.implementations.PvpFlag; import com.plotsquared.core.plot.flag.implementations.RedstoneFlag; @@ -173,6 +174,7 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; @@ -1677,6 +1679,19 @@ public class PlayerEvents extends PlotListener implements Listener { ItemStack newItem = event.getCursor(); ItemMeta newMeta = newItem.getItemMeta(); ItemMeta oldMeta = newItem.getItemMeta(); + + if (event.getClick() == ClickType.CREATIVE) { + final Plot plot = pp.getCurrentPlot(); + if (plot != null && + plot.getFlag(PreventCreativeCopyFlag.class) && + !plot.isAdded(player.getUniqueId()) && + !Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_OTHER)) { + final ItemStack newStack = new ItemStack(newItem.getType(), newItem.getAmount()); + event.setCursor(newStack); + } + return; + } + String newLore = ""; if (newMeta != null) { List lore = newMeta.getLore(); diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Captions.java b/Core/src/main/java/com/plotsquared/core/configuration/Captions.java index 1e0e50080..5909b119f 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Captions.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Captions.java @@ -675,6 +675,7 @@ public enum Captions implements Caption { FLAG_DESCRIPTION_BLOCKED_CMDS("A list of commands that are blocked in the plot.", "Flags"), FLAG_DESCRIPTION_KEEP("Prevents the plot from expiring. Can be set to: true, false, the number of milliseconds to keep the plot for or a timestamp (3w 2d 5h).", "Flags"), FLAG_DESCRIPTION_KEEP_INVENTORY("Prevents players from dropping their items when they die inside of the plot.", "Flags"), + FLAG_DESCRIPTION_PREVENT_CREATIVE_COPY("Prevents people from copying item NBT data in the plot unless they're added as members.", "Flags"), // // FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", false, "Flags"), 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 42965ef39..4d7fdd396 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 @@ -82,6 +82,7 @@ import com.plotsquared.core.plot.flag.implementations.NotifyEnterFlag; import com.plotsquared.core.plot.flag.implementations.NotifyLeaveFlag; import com.plotsquared.core.plot.flag.implementations.PlaceFlag; import com.plotsquared.core.plot.flag.implementations.PlayerInteractFlag; +import com.plotsquared.core.plot.flag.implementations.PreventCreativeCopyFlag; import com.plotsquared.core.plot.flag.implementations.PriceFlag; import com.plotsquared.core.plot.flag.implementations.PveFlag; import com.plotsquared.core.plot.flag.implementations.PvpFlag; @@ -178,6 +179,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(MiscPlaceFlag.MISC_PLACE_FALSE); this.addFlag(MiscInteractFlag.MISC_INTERACT_FALSE); this.addFlag(KeepInventoryFlag.KEEP_INVENTORY_FALSE); + this.addFlag(PreventCreativeCopyFlag.PREVENT_CREATIVE_COPY_FALSE); // Enum Flags this.addFlag(WeatherFlag.PLOT_WEATHER_FLAG_OFF); diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PreventCreativeCopyFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PreventCreativeCopyFlag.java new file mode 100644 index 000000000..0236167db --- /dev/null +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PreventCreativeCopyFlag.java @@ -0,0 +1,45 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) 2020 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.Captions; +import com.plotsquared.core.plot.flag.types.BooleanFlag; +import org.jetbrains.annotations.NotNull; + +public class PreventCreativeCopyFlag extends BooleanFlag { + + public static final PreventCreativeCopyFlag PREVENT_CREATIVE_COPY_TRUE = new PreventCreativeCopyFlag(true); + public static final PreventCreativeCopyFlag PREVENT_CREATIVE_COPY_FALSE = new PreventCreativeCopyFlag(false); + + private PreventCreativeCopyFlag(@NotNull final Boolean value) { + super(value, Captions.FLAG_DESCRIPTION_PREVENT_CREATIVE_COPY); + } + + @Override protected PreventCreativeCopyFlag flagOf(@NotNull final Boolean value) { + return value ? PREVENT_CREATIVE_COPY_TRUE : PREVENT_CREATIVE_COPY_FALSE; + } + +}