From 738a88ac0a2bbae89fbb0b1d3c42f09514c45491 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Apr 2021 20:36:18 +0200 Subject: [PATCH] Update CommandReset to new SWCommand system --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/commands/CommandReset.java | 69 ++++++++++++------- .../bausystem/commands/CommandTestblock.java | 4 +- BauSystem_Main/src/plugin.yml | 1 - 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index c6a4af8..47fe646 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -78,7 +78,7 @@ public class BauSystem extends JavaPlugin implements Listener { new CommandTrace(); new CommandTPSLimiter(); getCommand("nightvision").setExecutor(new CommandNV()); - getCommand("reset").setExecutor(new CommandReset()); + new CommandReset(); new CommandSpeed(); new CommandTNT(); new CommandBau(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index 0b8fcbb..2e9358e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -23,6 +23,7 @@ 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; @@ -30,42 +31,62 @@ 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 CommandReset implements CommandExecutor { +public class CommandReset 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 CommandReset() { + super("reset"); + } + @Register + public void genericResetCommand(Player p) { + if (!permissionCheck(p)) return; + Region region = regionCheck(p); + if (region == null) return; + try { + region.reset(null); + p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + } catch (IOException e) { + p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); + } + } + + @Register + public void schematicResetCommand(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.reset(null); + p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + } catch (IOException e) { + p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); + Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); + } + } + + private boolean permissionCheck(Player player) { if (Welt.noPermission(player, Permission.world)) { player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht die Region zurücksetzen"); return false; } + return true; + } + private Region regionCheck(Player player) { Region region = Region.getRegion(player.getLocation()); if (region == Region.GlobalRegion.getInstance()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); - return false; + return null; } - try { - if (args.length > 0) { - Schematic schem = Schematic.getSchemFromDB(args[0], player.getUniqueId()); - if (schem == null) { - player.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden"); - return false; - } - region.reset(schem); - } else { - region.fastreset(); - } - player.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); - } catch (Exception e) { - player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); - Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); - } - return false; + return region; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index 60b9a48..17bcfc3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -82,8 +82,8 @@ public class CommandTestblock extends SWCommand { Region region = Region.getRegion(player.getLocation()); if (!region.hasTestblock()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); - return region; + return null; } - return null; + return region; } } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index a619a73..afac841 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: - reset: protect: bauinfo: freeze: