From 847b8ad6012fcf4c07203cfea91d44f6c215c17b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 17 Nov 2021 09:32:41 +0100 Subject: [PATCH] Add guards to everything up until by progress from multilingual Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + .../features/loader/LoaderCommand.java | 165 +++++++++--------- .../features/other/ClearCommand.java | 24 ++- .../features/other/DeclutterCommand.java | 1 - .../bausystem/features/other/TimeCommand.java | 30 ++-- .../features/region/ColorCommand.java | 27 +-- .../features/region/DamageCommand.java | 24 ++- .../features/region/FireCommand.java | 25 ++- .../features/region/FreezeCommand.java | 24 ++- .../features/region/ProtectCommand.java | 25 ++- .../features/region/RegionCommand.java | 51 +++--- .../features/region/ResetCommand.java | 27 +-- .../bausystem/features/region/TNTCommand.java | 29 +-- .../features/region/TestblockCommand.java | 28 +-- 14 files changed, 271 insertions(+), 210 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index a73b6c76..eacb7838 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -824,6 +824,7 @@ REGION_TNT_HELP_2=§8/§etnt §8[§7Mode§8] §8- §7Setzte das TNT verhalten au REGION_TNT_ON=§aTNT-Schaden aktiviert REGION_TNT_OFF=§cTNT-Schaden deaktiviert REGION_TNT_TB=§aTNT-Schaden außerhalb Baurahmen aktiviert +REGION_TNT_NO_PERMS=§cDu darfst hier nicht TNT-Schaden (de-)aktivieren REGION_TNT_BUILD=§cEine Explosion hätte Blöcke im Baubereich zerstört # Team LOCK_SCHEM_NO_USER=§7Dieser Spieler existiert nicht! diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java index 40546f20..8b4aeab8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java @@ -23,6 +23,9 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.GuardCheckType; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; import org.bukkit.entity.Player; @@ -57,127 +60,115 @@ public class LoaderCommand extends SWCommand { } @Register("setup") - public void setupLoader(Player p) { - if (permissionCheck(p)) { - if (Loader.getLoader(p) != null) { - Loader.getLoader(p).setup(); - BauSystem.MESSAGE.send("LOADER_BACK_SETUP", p); - } else { - Loader.newLoader(p); - BauSystem.MESSAGE.send("LOADER_NEW", p); - BauSystem.MESSAGE.send("LOADER_HOW_TO_START", p); - } + public void setupLoader(@Guard Player p) { + if (Loader.getLoader(p) != null) { + Loader.getLoader(p).setup(); + BauSystem.MESSAGE.send("LOADER_BACK_SETUP", p); + } else { + Loader.newLoader(p); + BauSystem.MESSAGE.send("LOADER_NEW", p); + BauSystem.MESSAGE.send("LOADER_HOW_TO_START", p); } } @Register("start") - public void startLoader(Player p) { - if (permissionCheck(p)) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.start(); - BauSystem.MESSAGE.send("LOADER_ACTIVE", p); + public void startLoader(@Guard Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; } + loader.start(); + BauSystem.MESSAGE.send("LOADER_ACTIVE", p); } @Register("stop") - public void stopLoader(Player p) { - if (permissionCheck(p)) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.stop(); - BauSystem.MESSAGE.send("LOADER_STOP", p); + public void stopLoader(@Guard Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; } + loader.stop(); + BauSystem.MESSAGE.send("LOADER_STOP", p); } @Register("pause") - public void pauseLoader(Player p) { - if (permissionCheck(p)) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.pause(); - BauSystem.MESSAGE.send("LOADER_PAUSED", p); + public void pauseLoader(@Guard Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; } + loader.pause(); + BauSystem.MESSAGE.send("LOADER_PAUSED", p); } @Register("resume") - public void resumeLoader(Player p) { - if (permissionCheck(p)) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.resume(); - BauSystem.MESSAGE.send("LOADER_RESUME", p); + public void resumeLoader(@Guard Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; } + loader.resume(); + BauSystem.MESSAGE.send("LOADER_RESUME", p); } @Register("wait") - public void shotDelayLoader(Player p, int delay) { - if (permissionCheck(p)) { - if (delay < 1) { - BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p); - return; - } - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - BauSystem.MESSAGE.send("LOADER_NEW_TIME", p, delay, loader.getTicksBetweenShots()); - loader.setTicksBetweenShots(delay); + public void shotDelayLoader(@Guard Player p, int delay) { + if (delay < 1) { + BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p); + return; } + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; + } + BauSystem.MESSAGE.send("LOADER_NEW_TIME", p, delay, loader.getTicksBetweenShots()); + loader.setTicksBetweenShots(delay); } @Register("speed") - public void speedLoader(Player p, int delay) { - if (permissionCheck(p)) { - if (delay < 1) { - BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p); - return; - } - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay, loader.getTicksBetweenBlocks()); - loader.setTicksBetweenBlocks(delay); + public void speedLoader(@Guard Player p, int delay) { + if (delay < 1) { + BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p); + return; } + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; + } + BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay, loader.getTicksBetweenBlocks()); + loader.setTicksBetweenBlocks(delay); } @Register("undo") - public void undoLast(Player p) { - if (permissionCheck(p)) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - BauSystem.MESSAGE.send("LOADER_UNDO", p); - loader.undo(); + public void undoLast(@Guard Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; } + BauSystem.MESSAGE.send("LOADER_UNDO", p); + loader.undo(); } @Register("clear") - public void clearLoader(Player p) { - if (permissionCheck(p)) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.clear(); + public void clearLoader(@Guard Player p) { + Loader loader = Loader.getLoader(p); + if (loaderNullCheck(loader, p)) { + return; } + loader.clear(); } - private boolean permissionCheck(Player player) { - if (!Permission.hasPermission(player, Permission.WORLD)) { - BauSystem.MESSAGE.send("LOADER_PERMS", player); - return false; - } - return true; + @ClassGuard(value = Player.class, local = true) + public GuardChecker loaderGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("LOADER_PERMS", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/ClearCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/ClearCommand.java index e41218f3..4f451b23 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/ClearCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/ClearCommand.java @@ -23,6 +23,9 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.GuardCheckType; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -49,19 +52,24 @@ public class ClearCommand extends SWCommand { } @Register - public void clearPlayerCommand(Player p, Player target) { - if (!permissionCheck(p)) return; + public void clearPlayerCommand(@Guard Player p, Player target) { clear(target); BauSystem.MESSAGE.send("OTHER_CLEAR_FROM", target, p.getName()); BauSystem.MESSAGE.send("OTHER_CLEAR_TO", p, target.getName()); } - private boolean permissionCheck(Player player) { - if (!Permission.hasPermission(player, Permission.WORLD)) { - BauSystem.MESSAGE.send("OTHER_CLEAR_NO_PERMS", player); - return false; - } - return true; + @ClassGuard(value = Player.class, local = true) + public GuardChecker loaderGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("OTHER_CLEAR_NO_PERMS", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } private void clear(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/DeclutterCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/DeclutterCommand.java index d06c1672..8f9e81db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/DeclutterCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/DeclutterCommand.java @@ -66,5 +66,4 @@ public class DeclutterCommand extends SWCommand { BauSystem.MESSAGE.send("OTHER_DECLUTTER_DONE", p); } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java index c9409f51..2efae3a6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java @@ -23,9 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; -import de.steamwar.command.SWCommand; -import de.steamwar.command.SWCommandUtils; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.*; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -48,21 +46,13 @@ public class TimeCommand extends SWCommand { } @Register - public void genericCommand(Player p, Time time) { - if (!Permission.hasPermission(p, Permission.WORLD)) { - BauSystem.MESSAGE.send("OTHER_TIME_NO_PERM", p); - return; - } + public void genericCommand(@Guard Player p, Time time) { Bukkit.getWorlds().get(0).setTime(time.getValue()); BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p); } @Register - public void genericCommand(Player p, int time) { - if (!Permission.hasPermission(p, Permission.WORLD)) { - BauSystem.MESSAGE.send("OTHER_TIME_NO_PERM", p); - return; - } + public void genericCommand(@Guard Player p, int time) { if (time < 0 || time > 24000) { BauSystem.MESSAGE.send("OTHER_TIME_INVALID", p); return; @@ -82,6 +72,20 @@ public class TimeCommand extends SWCommand { }, s -> tabCompletions); } + @ClassGuard(value = Player.class, local = true) + public GuardChecker loaderGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("OTHER_TIME_NO_PERM", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; + } + public enum Time { NIGHT(18000), DAY(6000), diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java index fc5557c6..921b20eb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ColorCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.region; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; @@ -30,6 +31,9 @@ import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.GuardCheckType; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; import org.bukkit.entity.Player; @@ -58,10 +62,7 @@ public class ColorCommand extends SWCommand { } @Register - public void genericColorSet(Player p, ColorMode color, ColorizationType colorizationType) { - if (!permissionCheck(p)) { - return; - } + public void genericColorSet(@Guard Player p, ColorMode color, ColorizationType colorizationType) { if (colorizationType == ColorizationType.GLOBAL) { Region.setGlobal(Flag.COLOR, color); BauSystem.MESSAGE.send("REGION_COLOR_GLOBAL", p, BauSystem.MESSAGE.parse(color.getChatValue(), p)); @@ -87,12 +88,18 @@ public class ColorCommand extends SWCommand { genericColorSet(p, color, colorizationType); } - private boolean permissionCheck(Player p) { - if (bauServer.getOwner().equals(p.getUniqueId())) { - return true; - } - BauSystem.MESSAGE.send("REGION_COLOR_NO_PERMS", p); - return false; + @ClassGuard(value = Player.class, local = true) + public GuardChecker loaderGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (bauServer.getOwner().equals(player.getUniqueId())) { + return GuardResult.ALLOWED; + } + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("REGION_COLOR_NO_PERMS", player); + } + return GuardResult.DENIED; + }; } public enum ColorizationType { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/DamageCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/DamageCommand.java index 7c64c2e8..ef5f7fbf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/DamageCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/DamageCommand.java @@ -27,6 +27,9 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.DamageMode; +import de.steamwar.command.GuardCheckType; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; import org.bukkit.entity.Player; @@ -45,8 +48,7 @@ public class DamageCommand extends SWCommand { } @Register - public void toggleCommand(Player p) { - if (!permissionCheck(p)) return; + public void toggleCommand(@Guard Player p) { Region region = Region.getRegion(p.getLocation()); if (toggle(region)) { RegionUtils.actionBar(region, getEnableMessage()); @@ -79,11 +81,17 @@ public class DamageCommand extends SWCommand { } } - private boolean permissionCheck(Player player) { - if (!Permission.hasPermission(player, Permission.WORLD)) { - BauSystem.MESSAGE.send(getNoPermMessage(), player); - return false; - } - return true; + @ClassGuard(value = Player.class, local = true) + public GuardChecker guard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send(getNoPermMessage(), player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireCommand.java index 04d31491..06473ca8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireCommand.java @@ -27,6 +27,9 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import de.steamwar.command.GuardCheckType; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; import org.bukkit.entity.Player; @@ -44,8 +47,7 @@ public class FireCommand extends SWCommand { } @Register - public void toggleCommand(Player p) { - if (!permissionCheck(p)) return; + public void toggleCommand(@Guard Player p) { Region region = Region.getRegion(p.getLocation()); if (toggle(region)) { RegionUtils.actionBar(region, getEnableMessage()); @@ -78,12 +80,17 @@ public class FireCommand extends SWCommand { } } - private boolean permissionCheck(Player player) { - if (!Permission.hasPermission(player, Permission.WORLD)) { - BauSystem.MESSAGE.send(getNoPermMessage(), player); - return false; - } - return true; + @ClassGuard(value = Player.class, local = true) + public GuardChecker guard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send(getNoPermMessage(), player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java index 0fd64700..2847bb50 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java @@ -27,6 +27,9 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; +import de.steamwar.command.GuardCheckType; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; import org.bukkit.entity.Player; @@ -44,8 +47,7 @@ public class FreezeCommand extends SWCommand { } @Register - public void toggleCommand(Player p) { - if (!permissionCheck(p)) return; + public void toggleCommand(@Guard Player p) { Region region = Region.getRegion(p.getLocation()); if (toggle(region)) { RegionUtils.actionBar(region, getEnableMessage()); @@ -78,11 +80,17 @@ public class FreezeCommand extends SWCommand { } } - private boolean permissionCheck(Player player) { - if (!Permission.hasPermission(player, Permission.WORLD)) { - BauSystem.MESSAGE.send(getNoPermMessage(), player); - return false; - } - return true; + @ClassGuard(value = Player.class, local = true) + public GuardChecker guard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send(getNoPermMessage(), player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectCommand.java index 11e90e2f..857e92e7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectCommand.java @@ -27,6 +27,9 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import de.steamwar.command.GuardCheckType; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; import org.bukkit.entity.Player; @@ -44,8 +47,7 @@ public class ProtectCommand extends SWCommand { } @Register - public void genericProtectCommand(Player p) { - if (!permissionCheck(p)) return; + public void genericProtectCommand(@Guard Player p) { Region region = regionCheck(p); if (region == null) return; switch (region.getPlain(Flag.PROTECT, ProtectMode.class)) { @@ -61,12 +63,18 @@ public class ProtectCommand extends SWCommand { } } - private boolean permissionCheck(Player player) { - if (!Permission.hasPermission(player, Permission.WORLDEDIT)) { - BauSystem.MESSAGE.send("REGION_PROTECT_NO_PERMS", player); - return false; - } - return true; + @ClassGuard(value = Player.class, local = true) + public GuardChecker guard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLDEDIT)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("REGION_PROTECT_NO_PERMS", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } private Region regionCheck(Player player) { @@ -77,5 +85,4 @@ public class ProtectCommand extends SWCommand { } return region; } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index 9e30068c..a46c2e5f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -31,8 +31,7 @@ import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.*; import de.steamwar.sql.Schematic; import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.Bukkit; @@ -86,8 +85,7 @@ public class RegionCommand extends SWCommand { } @Register("undo") - public void undoCommand(Player p) { - if(!permissionCheck(p, Permission.WORLDEDIT)) return; + public void undoCommand(@Guard("WORLD_EDIT") Player p) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) return; @@ -109,10 +107,7 @@ public class RegionCommand extends SWCommand { } @Register("redo") - public void redoCommand(Player p) { - if (!permissionCheck(p, Permission.WORLDEDIT)) { - return; - } + public void redoCommand(@Guard("WORLD_EDIT") Player p) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; @@ -126,8 +121,7 @@ public class RegionCommand extends SWCommand { } @Register("restore") - public void genericRestoreCommand(Player p) { - if (!permissionCheck(p, Permission.WORLDEDIT)) return; + public void genericRestoreCommand(@Guard("WORLD_EDIT") Player p) { Region region = Region.getRegion(p.getLocation()); if(checkGlobalRegion(region, p)) return; @@ -146,8 +140,7 @@ public class RegionCommand extends SWCommand { } @Register("restore") - public void schematicRestoreCommand(Player p, String s) { - if (!permissionCheck(p, Permission.WORLDEDIT)) return; + public void schematicRestoreCommand(@Guard("WORLD_EDIT") Player p, String s) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) return; @@ -206,8 +199,7 @@ public class RegionCommand extends SWCommand { @Register("changetype") @Register("type") - public void changeTypeCommand(Player p, @Mapper("regionTypeMapper") String s) { - if (!permissionCheck(p, Permission.WORLD)) return; + public void changeTypeCommand(@Guard("WORLD") Player p, @Mapper("regionTypeMapper") String s) { Region region = Region.getRegion(p.getLocation()); if (checkGlobalRegion(region, p)) { return; @@ -245,12 +237,31 @@ public class RegionCommand extends SWCommand { }; } - private boolean permissionCheck(Player player, Permission permission) { - if (Permission.hasPermission(player, permission)) { - return true; - } - BauSystem.MESSAGE.send("REGION_REGION_NO_PERMS", player); - return false; + @Guard(value = "WORLD", local = true) + public GuardChecker worldGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("REGION_REGION_NO_PERMS", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } + @Guard(value = "WORLD_EDIT", local = true) + public GuardChecker worldEditGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLDEDIT)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("REGION_REGION_NO_PERMS", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index 8da87846..7f038d57 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -27,6 +27,9 @@ import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.GuardCheckType; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -50,8 +53,7 @@ public class ResetCommand extends SWCommand { } @Register - public void genericResetCommand(Player p) { - if (!permissionCheck(p)) return; + public void genericResetCommand(@Guard Player p) { Region region = regionCheck(p); if (region == null) return; try { @@ -64,8 +66,7 @@ public class ResetCommand extends SWCommand { } @Register - public void schematicResetCommand(Player p, String s) { - if (!permissionCheck(p)) return; + public void schematicResetCommand(@Guard Player p, String s) { Region region = regionCheck(p); if (region == null) return; Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); @@ -82,12 +83,18 @@ public class ResetCommand extends SWCommand { } } - private boolean permissionCheck(Player player) { - if (Permission.hasPermission(player, Permission.WORLD)) { - return true; - } - BauSystem.MESSAGE.send("REGION_RESET_NO_PERMS", player); - return false; + @ClassGuard(value = Player.class, local = true) + public GuardChecker worldGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("REGION_RESET_NO_PERMS", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } private Region regionCheck(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java index d1cc2e93..6922d0d4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java @@ -28,9 +28,7 @@ import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.command.SWCommand; -import de.steamwar.command.SWCommandUtils; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.*; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -54,15 +52,13 @@ public class TNTCommand extends SWCommand { } @Register - public void toggleCommand(Player p) { - if (!permissionCheck(p)) return; + public void toggleCommand(@Guard Player p) { Region region = Region.getRegion(p.getLocation()); tntToggle(region, null, null); } @Register - public void setCommand(Player p, TNTMode tntMode) { - if (!permissionCheck(p)) return; + public void setCommand(@Guard Player p, TNTMode tntMode) { Region region = Region.getRegion(p.getLocation()); String requestedMessage = null; @@ -151,12 +147,17 @@ public class TNTCommand extends SWCommand { } } - private boolean permissionCheck(Player p) { - if (!Permission.hasPermission(p, Permission.WORLD)) { - p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"); - return false; - } - return true; + @ClassGuard(value = Player.class, local = true) + public GuardChecker worldGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLD)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("REGION_TNT_NO_PERMS", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index b0389386..7cfb3db7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -27,9 +27,7 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.command.SWCommand; -import de.steamwar.command.SWCommandUtils; -import de.steamwar.command.TypeMapper; +import de.steamwar.command.*; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -61,8 +59,7 @@ public class TestblockCommand extends SWCommand { } @Register - public void genericTestblockCommand(Player p, RegionExtensionType regionExtensionType) { - if (!permissionCheck(p)) return; + public void genericTestblockCommand(@Guard Player p, RegionExtensionType regionExtensionType) { Region region = regionCheck(p); if (region == null) return; try { @@ -85,8 +82,7 @@ public class TestblockCommand extends SWCommand { } @Register - public void schematicTestblockCommand(Player p, String s, RegionExtensionType regionExtensionType) { - if (!permissionCheck(p)) return; + public void schematicTestblockCommand(@Guard Player p, String s, RegionExtensionType regionExtensionType) { Region region = regionCheck(p); if (region == null) return; Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); @@ -118,12 +114,18 @@ public class TestblockCommand extends SWCommand { return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes); } - private boolean permissionCheck(Player player) { - if (Permission.hasPermission(player, Permission.WORLDEDIT)) { - return true; - } - BauSystem.MESSAGE.send("REGION_TB_NO_PERMS", player); - return false; + @ClassGuard(value = Player.class, local = true) + public GuardChecker worldGuard() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (!Permission.hasPermission(player, Permission.WORLDEDIT)) { + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("REGION_TB_NO_PERMS", player); + } + return GuardResult.DENIED; + } + return GuardResult.ALLOWED; + }; } private Region regionCheck(Player player) {