diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index dd0232558..37e2fb2c2 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -42,6 +42,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.SoilD import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedAttackFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.UseFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleBreakFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleUseFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VillagerInteractFlag; @@ -2297,7 +2298,8 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(pp.getUUID())) { - if (Flags.USE.contains(plot, BukkitAdapter.asItemType(block.getType()))) { + List use = plot.getFlag(UseFlag.class); + if (use.contains(BukkitAdapter.asBlockType(block.getType()))) { return; } if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { @@ -2357,9 +2359,9 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> use = plot.getFlag(Flags.USE); + List use = plot.getFlag(UseFlag.class); Block block = event.getBlockClicked(); - if (use.isPresent() && use.get().contains(BukkitAdapter.asBlockType(block.getType()))) { + if (use.contains(BukkitAdapter.asBlockType(block.getType()))) { return; } if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java index eaa40af5c..83e1f8a34 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java @@ -622,6 +622,7 @@ public enum Captions implements Caption { FLAG_DESCRIPTION_TAMED_ATTACK("Set to `true` to allow guests to attack tamed animals in the plot.", "Flags"), FLAG_DESCRIPTION_TAMED_INTERACT("Set to `true` to allow guests to interact with tamed animals in the plot.", "Flags"), FLAG_DESCRIPTION_TITLES("Set to `false` to disable plot titles.", "Flags"), + FLAG_DESCRIPTION_USE("Define a list of materials players should be able to interact with in the plot.", "Flags"), FLAG_DESCRIPTION_VEHICLE_BREAK("Set to `true` to allow guests to break vehicles in the plot.", "Flags"), FLAG_DESCRIPTION_VEHICLE_CAP("Set to an integer value to limit the amount of vehicles on the plot.", "Flags"), FLAG_DESCRIPTION_VEHICLE_PLACE("Set to `true` to allow guests to place vehicles in the plot.", "Flags"), diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java index 74b7cbd4b..d58c3199d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java @@ -63,6 +63,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Tamed import com.github.intellectualsites.plotsquared.plot.flags.implementations.TamedInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.TitlesFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.UseFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleBreakFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleCapFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehicleUseFlag; @@ -163,7 +164,7 @@ public final class GlobalFlagContainer extends FlagContainer { // Block type list flags this.addFlag(BreakFlag.BREAK_NONE); this.addFlag(PlaceFlag.PLACE_NONE); - + this.addFlag(UseFlag.USE_NONE); // Misc this.addFlag(GamemodeFlag.GAMEMODE_FLAG_DEFAULT); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UseFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UseFlag.java new file mode 100644 index 000000000..fac7eb7b2 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UseFlag.java @@ -0,0 +1,21 @@ +package com.github.intellectualsites.plotsquared.plot.flags.implementations; + +import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.flags.types.BlockTypeListFlag; +import com.sk89q.worldedit.world.block.BlockType; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +public class UseFlag extends BlockTypeListFlag { + public static final UseFlag USE_NONE = new UseFlag(Collections.emptyList()); + + protected UseFlag(List blockTypeList) { + super(blockTypeList, Captions.FLAG_DESCRIPTION_USE); + } + + @Override protected UseFlag flagOf(@NotNull List value) { + return new UseFlag(value); + } +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java index 28e0fc3c3..4db1b1a14 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java @@ -9,6 +9,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Devic import com.github.intellectualsites.plotsquared.plot.flags.implementations.MiscPlaceFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MobPlaceFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlaceFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.UseFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.VehiclePlaceFlag; import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType; import com.github.intellectualsites.plotsquared.plot.object.Location; @@ -132,10 +133,8 @@ public abstract class EventUtil { Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), notifyPerms); } - Optional> flagValue = plot.getFlag(Flags.USE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(blockType)) { + List use = plot.getFlag(UseFlag.class); + if (!use.contains(BlockTypes.AIR) && !use.contains(blockType)) { return Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false) || !(!notifyPerms || MainUtil @@ -157,10 +156,8 @@ public abstract class EventUtil { if (plot.getFlag(DeviceInteractFlag.class)) { return true; } - Optional> flagValue = plot.getFlag(Flags.USE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(BlockTypes.AIR) && !value - .contains(blockType)) { + List use = plot.getFlag(UseFlag.class); + if (!use.contains(BlockTypes.AIR) && !use.contains(blockType)) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { diff --git a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java index b925ce2a2..4cf6d1404 100644 --- a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java +++ b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java @@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals; public class FlagTest { private ItemType testBlock; - private Flag> use = Flags.USE; @Before public void setUp() throws Exception { EventUtil.manager = new EventUtilTest();