From 853b475b74234182cc6dc393a84ca575f4905dff Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Apr 2021 20:41:58 +0200 Subject: [PATCH] Update CommandProtect to new SWCommand system --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/commands/CommandProtect.java | 73 ++++++++++++------- BauSystem_Main/src/plugin.yml | 1 - 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 04da67b..40a3694 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -86,7 +86,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("freeze").setExecutor(new CommandFreeze()); new CommandTestblock(); getCommand("bauinfo").setExecutor(new CommandInfo()); - getCommand("protect").setExecutor(new CommandProtect()); + new CommandProtect(); new CommandSkull(); getCommand("loader").setExecutor(new CommandLoader()); getCommand("lockschem").setExecutor(new CommandLockschem()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java index 92e83bc..31d9ac2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java @@ -23,48 +23,67 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Welt; +import de.steamwar.command.SWCommand; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.io.IOException; import java.util.logging.Level; -public class CommandProtect implements CommandExecutor { +public class CommandProtect extends SWCommand { - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) - return false; - Player player = (Player) sender; + public CommandProtect() { + super("protect"); + } + @Register + public void genericTestblockCommand(Player p) { + if (!permissionCheck(p)) return; + Region region = regionCheck(p); + if (region == null) return; + try { + region.protect(null); + p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + } catch (IOException e) { + p.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed protect", e); + } + } + + @Register + public void schematicTestblockCommand(Player p, String s) { + if (!permissionCheck(p)) return; + Region region = regionCheck(p); + if (region == null) return; + Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId()); + if (schem == null) { + p.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); + return; + } + try { + region.protect(null); + p.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); + } catch (IOException e) { + p.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed protect", e); + } + } + + private boolean permissionCheck(Player player) { if (Welt.noPermission(player, Permission.worldedit)) { player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Boden schützen"); return false; } + return true; + } + private Region regionCheck(Player player) { Region region = Region.getRegion(player.getLocation()); - if (region == null || !region.hasProtection()) { + if (!region.hasProtection()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner (M)WG-Region"); - return false; + return null; } - try { - Schematic schem = null; - if (args.length > 0) { - schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); - if (schem == null) { - player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return false; - } - } - region.protect(schem); - player.sendMessage(BauSystem.PREFIX + "§7Boden geschützt"); - } catch (Exception e) { - player.sendMessage(BauSystem.PREFIX + "§cFehler beim Schützen der Region"); - Bukkit.getLogger().log(Level.WARNING, "Failed protect", e); - } - return false; + return region; } } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index c59d1a4..f1fa10e 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -10,7 +10,6 @@ description: "So unseriös wie wir sind: BauSystem nur besser." commands: fire: - protect: bauinfo: freeze: aliases: stoplag