diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 74b66d3..917921b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -80,8 +80,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("nightvision").setExecutor(new CommandNV()); getCommand("reset").setExecutor(new CommandReset()); getCommand("speed").setExecutor(new CommandSpeed()); - getCommand("tnt").setExecutor(new CommandTNT()); - getCommand("tnt").setTabCompleter(new CommandTNTTabComplete()); + new CommandTNT(); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); getCommand("testblock").setExecutor(new CommandTestblock()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index d528f37..0909302 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -23,16 +23,21 @@ 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.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; 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 org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; -public class CommandTNT implements CommandExecutor, Listener { +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CommandTNT extends SWCommand implements Listener { public enum TNTMode { ON("§aan"), @@ -48,13 +53,65 @@ public class CommandTNT implements CommandExecutor, Listener { public String getName() { return name; } - } public CommandTNT() { + super("tnt"); Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin()); } + @Register + public void toggleCommand(Player p) { + if (!permissionCheck(p)) return; + Region region = Region.getRegion(p.getLocation()); + tntToggle(region, null, null); + } + + + @Register + public void setCommand(Player p, TNTMode tntMode) { + if (!permissionCheck(p)) return; + Region region = Region.getRegion(p.getLocation()); + tntToggle(region, null, null); + + String requestedMessage = null; + switch (tntMode) { + case ON: + requestedMessage = getEnableMessage(); + break; + case OFF: + requestedMessage = getDisableMessage(); + break; + case ONLY_TB: + requestedMessage = getTestblockEnableMessage(); + break; + } + tntToggle(region, tntMode, requestedMessage); + } + + private boolean permissionCheck(Player p) { + if (Welt.noPermission(p, Permission.world)) { + p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"); + return false; + } + return true; + } + + @ClassMapper(value = TNTMode.class, local = true) + public TypeMapper tntModeTypeMapper() { + Map tntModeMap = new HashMap<>(); + tntModeMap.put("an", TNTMode.ON); + tntModeMap.put("on", TNTMode.ON); + tntModeMap.put("aus", TNTMode.OFF); + tntModeMap.put("off", TNTMode.OFF); + if (Region.buildAreaEnabled()) { + tntModeMap.put("testblock", TNTMode.ONLY_TB); + tntModeMap.put("tb", TNTMode.ONLY_TB); + } + List tabCompletes = new ArrayList<>(tntModeMap.keySet()); + return SWCommandUtils.createMapper(s -> tntModeMap.getOrDefault(s, null), s -> tabCompletes); + } + private String getEnableMessage() { return "§aTNT-Schaden aktiviert"; } @@ -67,46 +124,6 @@ public class CommandTNT implements CommandExecutor, Listener { return "§aTNT-Schaden außerhalb Baurahmen aktiviert"; } - @Override - public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { - if (!(sender instanceof Player)) return false; - Player player = (Player) sender; - - if (Welt.noPermission(player, Permission.world)) { - player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht TNT-Schaden (de-)aktivieren"); - return false; - } - - TNTMode requestedMode = null; - String requestedMessage = null; - if (args.length != 0) { - switch (args[0].toLowerCase()) { - case "an": - case "on": - requestedMode = TNTMode.ON; - requestedMessage = getEnableMessage(); - break; - case "aus": - case "off": - requestedMode = TNTMode.OFF; - requestedMessage = getDisableMessage(); - break; - case "testblock": - case "tb": - if (!Region.buildAreaEnabled()) break; - requestedMode = TNTMode.ONLY_TB; - requestedMessage = getTestblockEnableMessage(); - break; - default: - break; - } - } - - Region region = Region.getRegion(player.getLocation()); - tntToggle(region, requestedMode, requestedMessage); - return false; - } - private void tntToggle(Region region, TNTMode requestedMode, String requestedMessage) { if (requestedMode != null && region.hasTestblock()) { region.setTntMode(requestedMode); @@ -147,5 +164,4 @@ public class CommandTNT implements CommandExecutor, Listener { return region.getTntMode() == TNTMode.OFF; }); } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java deleted file mode 100644 index 26dea52..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.commands; - -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.world.Region; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class CommandTNTTabComplete implements TabCompleter { - - private List arguments = new ArrayList<>(Arrays.asList("an", "on", "aus", "off")); - - public CommandTNTTabComplete() { - if (Region.buildAreaEnabled()) arguments.addAll(Arrays.asList("testblock", "tb")); - } - - @Override - public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) return new ArrayList<>(); - if (args.length != 1) { - return new ArrayList<>(); - } - return SWUtils.manageList(arguments, args); - } - -} diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index ec636de..ad1ec2e 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: debugstick: - tnt: fire: testblock: aliases: tb