From 3bccedd95f58fa4b6d16d27063bcef47a19cda3b Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Mon, 17 Feb 2020 18:53:31 +0100 Subject: [PATCH] Port BreakFlag --- .../bukkit/listeners/PlayerEvents.java | 11 +++++----- .../plotsquared/plot/config/Captions.java | 1 + .../plot/flags/GlobalFlagContainer.java | 5 +++++ .../plot/flags/implementations/BreakFlag.java | 21 +++++++++++++++++++ .../plot/flags/types/BlockTypeListFlag.java | 10 +++------ 5 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/BreakFlag.java 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 97ab143f5..f207619ee 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 @@ -13,6 +13,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Anima import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.BreakFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyTeleportFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DisablePhysicsFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; @@ -1127,10 +1128,9 @@ import java.util.regex.Pattern; return; } if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + List destroy = plot.getFlag(BreakFlag.class); Block block = event.getBlock(); - if (destroy.isPresent() && destroy.get() - .contains(BukkitAdapter.asBlockType(block.getType()))) { + if (destroy.contains(BukkitAdapter.asBlockType(block.getType()))) { return; } if (Permissions @@ -1400,10 +1400,9 @@ import java.util.regex.Pattern; } PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + List destroy = plot.getFlag(BreakFlag.class); Block block = event.getBlock(); - if (destroy.isPresent() && destroy.get() - .contains(BukkitAdapter.asBlockType(block.getType())) || Permissions + if (destroy.contains(BukkitAdapter.asBlockType(block.getType())) || Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { return; } 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 4d11d2c22..4e157554a 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 @@ -577,6 +577,7 @@ public enum Captions implements Caption { FLAG_DESCRIPTION_ANIMAL_INTERACT("Set to `true` to allow animals to be interacted with in the plot.", "Flags"), FLAG_DESCRIPTION_BLOCK_BURN("Set to `true` to allow blocks to burn within the plot.", "Flags"), FLAG_DESCRIPTION_BLOCK_IGNITION("Set to `true` to allow blocks to ignite within the plot.", "Flags"), + FLAG_DESCRIPTION_BREAK("Define a list of materials players should be able to break even when they aren't added to the plot.", "Flags"), FLAG_DESCRIPTION_DEVICE_INTERACT("Set to `true` to allow devices to be interacted with in the plot.", "Flags"), FLAG_DESCRIPTION_DISABLE_PHYSICS("Set to `true` to disable block physics in the plot.", "Flags"), FLAG_DESCRIPTION_DROP_PROTECTION("Set to `true` to prevent dropped items from being picked up by non-members of 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 ed1123c7a..cdb69826f 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 @@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Anima import com.github.intellectualsites.plotsquared.plot.flags.implementations.AnimalInteractFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockBurnFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.BlockIgnitionFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.BreakFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyTeleportFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag; @@ -158,6 +159,10 @@ public final class GlobalFlagContainer extends FlagContainer { // Double flags this.addFlag(PriceFlag.PRICE_NOT_BUYABLE); + // Block type list flags + this.addFlag(BreakFlag.BREAK_NONE); + + // Misc this.addFlag(GamemodeFlag.GAMEMODE_FLAG_DEFAULT); this.addFlag(GuestGamemodeFlag.GUEST_GAMEMODE_FLAG_DEFAULT); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/BreakFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/BreakFlag.java new file mode 100644 index 000000000..93a5e095d --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/BreakFlag.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 BreakFlag extends BlockTypeListFlag { + public static final BreakFlag BREAK_NONE = new BreakFlag(Collections.emptyList()); + + protected BreakFlag(List blockTypeList) { + super(blockTypeList, Captions.FLAG_DESCRIPTION_BREAK); + } + + @Override protected BreakFlag flagOf(@NotNull List value) { + return new BreakFlag(value); + } +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/types/BlockTypeListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/types/BlockTypeListFlag.java index efb24edf7..bf2b08d09 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/types/BlockTypeListFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/types/BlockTypeListFlag.java @@ -11,13 +11,13 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -public class BlockTypeListFlag extends ListFlag { +public abstract class BlockTypeListFlag> extends ListFlag { - public BlockTypeListFlag(List blockTypeList, Caption description) { + protected BlockTypeListFlag(List blockTypeList, Caption description) { super(blockTypeList, Captions.FLAG_CATEGORY_BLOCK_LIST, description); } - @Override public BlockTypeListFlag parse(@NotNull String input) throws FlagParseException { + @Override public F parse(@NotNull String input) throws FlagParseException { final List parsedBlocks = new ArrayList<>(); final String[] split = input.split(",(?![^\\(\\[]*[\\]\\)])"); if (split.length == 0) { @@ -38,8 +38,4 @@ public class BlockTypeListFlag extends ListFlag { return "air,grass_block"; } - @Override protected BlockTypeListFlag flagOf(@NotNull List value) { - return new BlockTypeListFlag(value, getFlagDescription()); // copy the description - } - }