From 95a1b0612fdcbd4a48aaf3782a082a8d93c4e90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 17 Feb 2020 19:29:25 +0100 Subject: [PATCH] Port blocked-cmds flag --- .../bukkit/listeners/PlayerEvents.java | 8 ++--- .../plotsquared/plot/config/Captions.java | 1 + .../plotsquared/plot/flag/Flags.java | 1 - .../plot/flags/GlobalFlagContainer.java | 2 ++ .../implementations/BlockedCmdsFlag.java | 33 +++++++++++++++++++ 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/BlockedCmdsFlag.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 37e2fb2c2..45a8d6c35 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,7 +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.BlockedCmdsFlag; 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; @@ -672,10 +672,10 @@ import java.util.regex.Pattern; if (plot == null) { return; } - Optional> flag = plot.getFlag(Flags.BLOCKED_CMDS); - if (flag.isPresent() && !Permissions + + List blockedCommands = plot.getFlag(BlockedCmdsFlag.class); + if (!blockedCommands.isEmpty() && !Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_INTERACT_BLOCKED_CMDS)) { - List blockedCommands = flag.get(); String part = parts[0]; if (parts[0].contains(":")) { part = parts[0].split(":")[1]; 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 83e1f8a34..cebdfa470 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 @@ -632,6 +632,7 @@ public enum Captions implements Caption { FLAG_DESCRIPTION_DENY_TELEPORT("Deny a certain group from teleporting to the plot. Available groups: members, nonmembers, trusted, nontrusted, nonowners", "Flags"), FLAG_DESCRIPTION_GAMEMODE("Determines the gamemode in the plot.", "Flags"), FLAG_DESCRIPTION_GUEST_GAMEMODE("Determines the guest gamemode in the plot.", "Flags"), + FLAG_DESCRIPTION_BLOCKED_CMDS("A list of commands that are blocked in the plot.", "Flags"), // // FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"), diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index a3f086d89..4684c1776 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -7,7 +7,6 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan; public final class Flags { public static final LongFlag TIME = new LongFlag("time"); - public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds"); public static final Flag KEEP = new Flag(Captions.FLAG_CATEGORY_MIXED, "keep") { @Override public String valueToString(Object value) { return value.toString(); 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 d58c3199d..031207757 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.BlockedCmdsFlag; 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; @@ -169,6 +170,7 @@ public final class GlobalFlagContainer extends FlagContainer { // Misc this.addFlag(GamemodeFlag.GAMEMODE_FLAG_DEFAULT); this.addFlag(GuestGamemodeFlag.GUEST_GAMEMODE_FLAG_DEFAULT); + this.addFlag(BlockedCmdsFlag.BLOCKED_CMDS_FLAG_NONE); // Internal flags this.addFlag(new AnalysisFlag(Collections.emptyList())); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/BlockedCmdsFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/BlockedCmdsFlag.java new file mode 100644 index 000000000..72bf5e6cf --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/BlockedCmdsFlag.java @@ -0,0 +1,33 @@ +package com.github.intellectualsites.plotsquared.plot.flags.implementations; + +import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException; +import com.github.intellectualsites.plotsquared.plot.flags.types.ListFlag; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class BlockedCmdsFlag extends ListFlag { + + public static final BlockedCmdsFlag BLOCKED_CMDS_FLAG_NONE = new BlockedCmdsFlag(Collections.emptyList()); + + protected BlockedCmdsFlag(List valueList) { + super(valueList, Captions.FLAG_CATEGORY_STRING_LIST, Captions.FLAG_DESCRIPTION_BLOCKED_CMDS); + } + + @Override public BlockedCmdsFlag parse(@NotNull String input) throws FlagParseException { + return flagOf(Arrays.asList(input.split(","))); + } + + @Override public String getExample() { + return "gamemode survival, spawn"; + } + + @Override protected BlockedCmdsFlag flagOf(@NotNull List value) { + return new BlockedCmdsFlag(value); + + } + +}