diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java
index 78869bc..86d425a 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java
@@ -21,7 +21,6 @@ package de.steamwar.bausystem;
import de.steamwar.bausystem.commands.*;
import de.steamwar.bausystem.world.*;
-import de.steamwar.core.CommandRemover;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.scoreboard.SWScoreboard;
@@ -44,7 +43,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import java.util.UUID;
-import java.util.logging.Level;
public class BauSystem extends JavaPlugin implements Listener {
private static BauSystem plugin;
@@ -63,47 +61,36 @@ public class BauSystem extends JavaPlugin implements Listener {
owner = null;
}
- try {
- CommandRemover.removeAll("tp", "gamemode", "time", "clear");
- CommandInjector.injectCommand(new CommandTeleport());
- CommandInjector.injectCommand(new CommandGamemode());
- CommandInjector.injectCommand(new CommandTime());
- CommandInjector.injectCommand(new CommandClear());
- } catch (Exception e) {
- getLogger().log(Level.SEVERE, "Failed to replace commands", e);
- Bukkit.shutdown();
- return;
- }
+ Mapper.init();
- getCommand("trace").setExecutor(new CommandTrace());
- getCommand("trace").setTabCompleter(new CommandTraceTabCompleter());
- getCommand("tpslimit").setExecutor(new CommandTPSLimiter());
- getCommand("tpslimit").setTabCompleter(new CommandTPSLimiterTabComplete());
- 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());
- getCommand("fire").setExecutor(new CommandFire());
- getCommand("freeze").setExecutor(new CommandFreeze());
- getCommand("testblock").setExecutor(new CommandTestblock());
- getCommand("bau").setExecutor(new CommandBau());
- getCommand("bauinfo").setExecutor(new CommandInfo());
- getCommand("protect").setExecutor(new CommandProtect());
- getCommand("skull").setExecutor(new CommandSkull());
- getCommand("loader").setExecutor(new CommandLoader());
- getCommand("lockschem").setExecutor(new CommandLockschem());
- getCommand("debugstick").setExecutor(new CommandDebugStick());
- getCommand("watervision").setExecutor(new CommandGills());
- getCommand("detonator").setExecutor(new CommandDetonator());
- getCommand("detonator").setTabCompleter(new CommandDetonatorTabCompleter());
- getCommand("script").setExecutor(new CommandScript());
- getCommand("scriptvars").setExecutor(new CommandScriptVars());
- getCommand("scriptvars").setTabCompleter(new CommandScriptVarsTabCompleter());
- getCommand("simulator").setExecutor(new CommandSimulator());
- getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter());
- getCommand("redstonetester").setExecutor(new CommandRedstoneTester());
- getCommand("gui").setExecutor(new CommandGUI());
+ new CommandTrace();
+ new CommandTPSLimiter();
+ new CommandNV();
+ new CommandReset();
+ new CommandSpeed();
+ new CommandTNT();
+ new CommandBau();
+ new CommandGamemode();
+ new CommandClear();
+ new CommandTime();
+ new CommandTeleport();
+ new CommandFire();
+ new CommandFreeze();
+ new CommandTestblock();
+ new CommandInfo();
+ new CommandProtect();
+ new CommandSkull();
+ new CommandLoader();
+ new CommandLockschem();
+ new CommandDebugStick();
+ new CommandGills();
+ new CommandDetonator();
+ new CommandScript();
+ new CommandScriptVars();
+ new CommandSimulator();
+ new CommandRedstoneTester();
+ new CommandGUI();
+ new CommandWorldSpawn();
Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Mapper.java b/BauSystem_Main/src/de/steamwar/bausystem/Mapper.java
new file mode 100644
index 0000000..8dee240
--- /dev/null
+++ b/BauSystem_Main/src/de/steamwar/bausystem/Mapper.java
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import de.steamwar.bausystem.tracer.show.ShowModeParameterType;
+import de.steamwar.command.SWCommandUtils;
+import de.steamwar.command.TypeMapper;
+import de.steamwar.sql.BauweltMember;
+import de.steamwar.sql.SteamwarUser;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+
+public class Mapper {
+
+ private Mapper() {
+ throw new IllegalStateException("Utility Class");
+ }
+
+ public static void init() {
+ SWCommandUtils.addMapper(ShowModeParameterType.class, showModeParameterTypesTypeMapper());
+ SWCommandUtils.addMapper(BauweltMember.class, bauweltMemberTypeMapper());
+ }
+
+ private static TypeMapper showModeParameterTypesTypeMapper() {
+ Map showModeParameterTypesMap = new HashMap<>();
+ showModeParameterTypesMap.put("-water", ShowModeParameterType.WATER);
+
+ showModeParameterTypesMap.put("-interpolatey", ShowModeParameterType.INTERPOLATE_Y);
+ showModeParameterTypesMap.put("-interpolate-y", ShowModeParameterType.INTERPOLATE_Y);
+ showModeParameterTypesMap.put("-interpolate_y", ShowModeParameterType.INTERPOLATE_Y);
+ showModeParameterTypesMap.put("-y", ShowModeParameterType.INTERPOLATE_Y);
+
+ showModeParameterTypesMap.put("-interpolatex", ShowModeParameterType.INTERPOLATE_XZ);
+ showModeParameterTypesMap.put("-interpolate-x", ShowModeParameterType.INTERPOLATE_XZ);
+ showModeParameterTypesMap.put("-interpolate_x", ShowModeParameterType.INTERPOLATE_XZ);
+ showModeParameterTypesMap.put("-x", ShowModeParameterType.INTERPOLATE_XZ);
+
+ showModeParameterTypesMap.put("-interpolatez", ShowModeParameterType.INTERPOLATE_XZ);
+ showModeParameterTypesMap.put("-interpolate-z", ShowModeParameterType.INTERPOLATE_XZ);
+ showModeParameterTypesMap.put("-interpolate_z", ShowModeParameterType.INTERPOLATE_XZ);
+ showModeParameterTypesMap.put("-z", ShowModeParameterType.INTERPOLATE_XZ);
+
+ showModeParameterTypesMap.put("-interpolatexz", ShowModeParameterType.INTERPOLATE_XZ);
+ showModeParameterTypesMap.put("-interpolate-xz", ShowModeParameterType.INTERPOLATE_XZ);
+ showModeParameterTypesMap.put("-interpolate_xz", ShowModeParameterType.INTERPOLATE_XZ);
+ showModeParameterTypesMap.put("-xz", ShowModeParameterType.INTERPOLATE_XZ);
+
+ showModeParameterTypesMap.put("-advanced", ShowModeParameterType.ADVANCED);
+ showModeParameterTypesMap.put("advanced", ShowModeParameterType.ADVANCED);
+ showModeParameterTypesMap.put("a", ShowModeParameterType.ADVANCED);
+
+ List tabCompletes = new ArrayList<>(showModeParameterTypesMap.keySet());
+ return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes);
+ }
+
+ private static TypeMapper bauweltMemberTypeMapper() {
+ return SWCommandUtils.createMapper(s -> BauweltMember.getMembers(BauSystem.getOwnerID())
+ .stream()
+ .filter(m -> SteamwarUser.get(m.getMemberID()).getUserName().equals(s)).findFirst().orElse(null),
+ s -> BauweltMember.getMembers(BauSystem.getOwnerID())
+ .stream()
+ .map(m -> SteamwarUser.get(m.getMemberID()).getUserName())
+ .collect(Collectors.toList()));
+ }
+}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBau.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBau.java
index 083ee4a..a02e6bb 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBau.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandBau.java
@@ -1,37 +1,79 @@
-/*
- 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 .
-*/
+/*
+ * 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.BauSystem;
import de.steamwar.bausystem.world.Welt;
+import de.steamwar.command.SWCommand;
+import de.steamwar.command.SWCommandUtils;
+import de.steamwar.command.TypeMapper;
import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
+import java.util.stream.Collectors;
import org.bukkit.entity.Player;
-public class CommandBau implements CommandExecutor {
- private void onToggleBD(Player p, String arg) {
- SteamwarUser id = SteamwarUser.get(arg);
+public class CommandBau extends SWCommand {
+
+ public CommandBau() {
+ super("bau", "b", "gs");
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§ebau togglebuild §8[§7Player§8] §8- §7Editiere die Bau Rechte eines Spielers");
+ p.sendMessage("§8/§ebau togglewe §8[§7Player§8] §8- §7Editiere die WorldEdit Rechte eines Spielers");
+ p.sendMessage("§8/§ebau toggleworld §8[§7Player§8] §8- §7Editiere die Werlt Rechte eines Spielers");
+ }
+
+ @Register("info")
+ public void infoCommand(Player p) {
+ CommandInfo.sendBauInfo(p);
+ }
+
+ @Register("togglebuild")
+ public void toggleBuildCommand(Player p, SteamwarUser user) {
+ if (!permissionCheck(p)) {
+ return;
+ }
+ onToggleBD(p, user);
+ }
+
+ @Register("togglewe")
+ public void toggleWECommand(Player p, SteamwarUser user) {
+ if (!permissionCheck(p)) {
+ return;
+ }
+ onToggleWE(p, user);
+ }
+
+ @Register("toggleworld")
+ public void toggleWorldCommand(Player p, SteamwarUser user) {
+ if (!permissionCheck(p)) {
+ return;
+ }
+ onToggleWorld(p, user);
+ }
+
+
+ private void onToggleBD(Player p, SteamwarUser id) {
if (negativeToggleCheck(p, id)) {
return;
}
@@ -40,8 +82,7 @@ public class CommandBau implements CommandExecutor {
Welt.toggleBuild(p, target);
}
- private void onToggleWE(Player p, String arg) {
- SteamwarUser id = SteamwarUser.get(arg);
+ private void onToggleWE(Player p, SteamwarUser id) {
if (negativeToggleCheck(p, id)) {
return;
}
@@ -50,8 +91,7 @@ public class CommandBau implements CommandExecutor {
Welt.toggleWE(p, target);
}
- private void onToggleWorld(Player p, String arg) {
- SteamwarUser id = SteamwarUser.get(arg);
+ private void onToggleWorld(Player p, SteamwarUser id) {
if (negativeToggleCheck(p, id)) {
return;
}
@@ -74,23 +114,34 @@ public class CommandBau implements CommandExecutor {
return false;
}
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
- if (!BauSystem.getOwner().equals(player.getUniqueId())) {
- player.sendMessage(BauSystem.PREFIX + "§cDies ist nicht deine Welt!");
- return false;
- }
- if (args[0].equalsIgnoreCase("togglebuild")) {
- onToggleBD(player, args[1]);
- } else if (args[0].equalsIgnoreCase("togglewe")) {
- onToggleWE(player, args[1]);
- } else if (args[0].equalsIgnoreCase("toggleworld")) {
- onToggleWorld(player, args[1]);
+ private boolean permissionCheck(Player p) {
+ if (!BauSystem.getOwner().equals(p.getUniqueId())) {
+ p.sendMessage(BauSystem.PREFIX + "§cDies ist nicht deine Welt!");
+ return false;
+ } else {
+ return true;
}
- return false;
}
-}
+
+
+ @ClassMapper(value = SteamwarUser.class, local = true)
+ private TypeMapper steamwarUserTypeMapper() {
+ return SWCommandUtils.createMapper(s -> BauweltMember.getMembers(BauSystem.getOwnerID())
+ .stream()
+ .map(m -> SteamwarUser.get(m.getMemberID()))
+ .filter(u -> u.getUserName().equals(s))
+ .findFirst()
+ .orElse(null),
+ (c, s) -> {
+ if (!(c instanceof Player)) {
+ return null;
+ }
+ Player p = (Player) c;
+ return BauweltMember.getMembers(SteamwarUser.get(p.getUniqueId()).getId())
+ .stream()
+ .map(m -> SteamwarUser.get(m.getMemberID()).getUserName())
+ .collect(Collectors.toList());
+ });
+ }
+}
\ No newline at end of file
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java
index e976c13..81225a8 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java
@@ -1,66 +1,64 @@
-/*
- 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 .
-*/
+/*
+ * 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.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Welt;
-import org.bukkit.Bukkit;
+import de.steamwar.command.SWCommand;
import org.bukkit.Material;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
-public class CommandClear extends BukkitCommand {
+public class CommandClear extends SWCommand {
public CommandClear() {
super("clear");
- description = "Leere dein Inventar oder das eines anderen Spielers.";
- usageMessage = "/clear [Spieler]";
}
- public boolean execute(CommandSender sender, String currentAlias, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
- if (args.length == 0) {
- clear(player);
- player.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde geleert.");
- return true;
- }
- // check if admin
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§eclear §8- §7Leere dein Inventar");
+ p.sendMessage("§8/§ebau clear §8[§7Player§8] §8- §7Leere ein Spieler Inventar");
+ }
+
+ @Register
+ public void genericClearCommand(Player p) {
+ clear(p);
+ p.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde geleert.");
+ }
+
+ @Register
+ public void clearPlayerCommand(Player p, Player target) {
+ if (!permissionCheck(p)) return;
+ clear(target);
+ target.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde von" + p.getDisplayName() + " §7geleert.");
+ p.sendMessage(BauSystem.PREFIX + "Das Inventar von " + target.getDisplayName() + " §7wurde geleert.");
+ }
+
+ private boolean permissionCheck(Player player) {
if (Welt.noPermission(player, Permission.world)) {
player.sendMessage(BauSystem.PREFIX + "$cDu darfst hier keine fremden Inventare leeren.");
return false;
}
- Player target = Bukkit.getPlayerExact(args[0]);
- if (!(target instanceof Player)) {
- player.sendMessage(BauSystem.PREFIX + "§cDas ist kein Spieler.");
- return false;
- }
- clear(target);
- target.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde von" + player.getDisplayName() + " §7geleert.");
- player.sendMessage(BauSystem.PREFIX + "Das Inventar von " + target.getDisplayName() + " §7wurde geleert.");
return true;
-
}
private void clear(Player player) {
@@ -70,4 +68,4 @@ public class CommandClear extends BukkitCommand {
player.getInventory().setLeggings(new ItemStack(Material.AIR));
player.getInventory().setBoots(new ItemStack(Material.AIR));
}
-}
+}
\ No newline at end of file
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDebugStick.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDebugStick.java
index b3ac2bf..604122f 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDebugStick.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDebugStick.java
@@ -1,49 +1,49 @@
-/*
- 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 .
-*/
+/*
+ * 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.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Welt;
+import de.steamwar.command.SWCommand;
import de.steamwar.core.VersionedRunnable;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-public class CommandDebugStick implements CommandExecutor {
+public class CommandDebugStick extends SWCommand {
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
-
- if (Welt.noPermission(player, Permission.build)) {
- player.sendMessage(BauSystem.PREFIX + "§cKein Debugstick für dich hier.");
- return false;
- }
-
- VersionedRunnable.call(new VersionedRunnable(() -> player.sendMessage(BauSystem.PREFIX + "§cDen Debugstick gibt es nicht in der 1.12."), 8),
- new VersionedRunnable(() -> CommandDebugStick_15.giveStick(player), 15));
- return false;
+ public CommandDebugStick() {
+ super("debugstick");
}
-}
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§edebugstick §8- §7Erhalte einen DebugStick");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ if (Welt.noPermission(p, Permission.build)) {
+ p.sendMessage(BauSystem.PREFIX + "§cKein Debugstick für dich hier.");
+ } else {
+ VersionedRunnable.call(new VersionedRunnable(() -> p.sendMessage(BauSystem.PREFIX + "§cDen Debugstick gibt es nicht in der 1.12."), 8),
+ new VersionedRunnable(() -> CommandDebugStick_15.giveStick(p), 15));
+ }
+ }
+}
\ No newline at end of file
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java
index 1528920..226e498 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java
@@ -1,21 +1,21 @@
/*
- 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 .
-*/
+ * 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;
@@ -24,18 +24,84 @@ import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.world.Detonator;
import de.steamwar.bausystem.world.Welt;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
+import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
-public class CommandDetonator implements CommandExecutor {
+public class CommandDetonator extends SWCommand {
- private void help(Player player) {
- player.sendMessage("§8/§edetonator wand §8- §7Legt den Fernzünder ins Inventar");
- player.sendMessage("§8/§edetonator detonate §8- §7Benutzt den nächst besten Fernzünder");
- player.sendMessage("§8/§edetonator reset §8- §7Löscht alle markierten Positionen");
- player.sendMessage("§8/§edetonator remove §8- §7Entfernt den Fernzünder");
+ public CommandDetonator() {
+ super ("detonator", "dt");
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§edetonator wand §8- §7Legt den Fernzünder ins Inventar");
+ p.sendMessage("§8/§edetonator detonate §8- §7Benutzt den nächst besten Fernzünder");
+ p.sendMessage("§8/§edetonator reset §8- §7Löscht alle markierten Positionen");
+ p.sendMessage("§8/§edetonator remove §8- §7Entfernt den Fernzünder");
+ }
+
+ @Register("wand")
+ public void wandCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ SWUtils.giveItemToPlayer(p, Detonator.WAND);
+ }
+
+ @Register("detonator")
+ public void detonatorCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ SWUtils.giveItemToPlayer(p, Detonator.WAND);
+ }
+
+ @Register("item")
+ public void itemCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ SWUtils.giveItemToPlayer(p, Detonator.WAND);
+ }
+
+
+ @Register("remove")
+ public void removeCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ p.getInventory().removeItem(Detonator.WAND);
+ }
+
+
+ @Register("detonate")
+ public void detonateCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ Detonator.execute(p);
+ }
+
+ @Register("click")
+ public void clickCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ Detonator.execute(p);
+ }
+
+ @Register("use")
+ public void useCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ Detonator.execute(p);
+ }
+
+
+ @Register("clear")
+ public void clearCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ p.getInventory().setItemInMainHand(Detonator.clearDetonator(p.getInventory().getItemInMainHand()));
+ }
+
+ @Register("delete")
+ public void deleteCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ p.getInventory().setItemInMainHand(Detonator.clearDetonator(p.getInventory().getItemInMainHand()));
+ }
+
+ @Register("reset")
+ public void resetCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ p.getInventory().setItemInMainHand(Detonator.clearDetonator(p.getInventory().getItemInMainHand()));
}
private boolean permissionCheck(Player player) {
@@ -45,44 +111,4 @@ public class CommandDetonator implements CommandExecutor {
}
return true;
}
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
-
- if (args.length == 0) {
- help(player);
- return false;
- }
-
- if (!permissionCheck(player)) return false;
-
- switch (args[0].toLowerCase()) {
- case "wand":
- case "detonator":
- case "item":
- SWUtils.giveItemToPlayer(player, Detonator.WAND);
- player.updateInventory();
- break;
- case "remove":
- player.getInventory().removeItem(Detonator.WAND);
- break;
- case "detonate":
- case "click":
- case "use":
- Detonator.execute(player);
- break;
- case "clear":
- case "delete":
- case "reset":
- player.getInventory().setItemInMainHand(Detonator.clearDetonator(player.getInventory().getItemInMainHand()));
- break;
- default:
- help(player);
- }
-
- return true;
- }
-}
+}
\ No newline at end of file
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java
deleted file mode 100644
index f4a166a..0000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java
+++ /dev/null
@@ -1,44 +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 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 CommandDetonatorTabCompleter implements TabCompleter {
-
- private List arguments = new ArrayList<>(Arrays.asList("wand", "reset", "detonate", "remove"));
-
- @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/de/steamwar/bausystem/commands/CommandFire.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java
index a1ea0e3..0c9d5c2 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFire.java
@@ -19,34 +19,66 @@
package de.steamwar.bausystem.commands;
+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 org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockSpreadEvent;
-public class CommandFire extends RegionToggleCommand {
+public class CommandFire extends SWCommand implements Listener {
- @Override
- String getNoPermMessage() {
+ public CommandFire() {
+ super("fire");
+ Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§efire §8- §7Toggle Feuerschaden");
+ }
+
+ @Register
+ public void toggleCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ Region region = Region.getRegion(p.getLocation());
+ if (toggle(region)) {
+ RegionUtils.actionBar(region, getEnableMessage());
+ } else {
+ RegionUtils.actionBar(region, getDisableMessage());
+ }
+ }
+
+ private String getNoPermMessage() {
return "§cDu darfst hier nicht Feuerschaden (de-)aktivieren";
}
- @Override
- String getEnableMessage() {
- return "§cFeuerschaden deaktiviert";
+ private String getEnableMessage() {
+ return "§cRegions Feuerschaden deaktiviert";
}
- @Override
- String getDisableMessage() {
- return "§aFeuerschaden aktiviert";
+ private String getDisableMessage() {
+ return "§aRegions Feuerschaden aktiviert";
}
- @Override
- boolean toggle(Region region) {
+ private boolean toggle(Region region) {
region.setFire(!region.isFire());
return region.isFire();
}
+ private boolean permissionCheck(Player player) {
+ if (Welt.noPermission(player, Permission.world)) {
+ player.sendMessage(BauSystem.PREFIX + getNoPermMessage());
+ return false;
+ }
+ return true;
+ }
+
@EventHandler
public void onFireDamage(BlockBurnEvent e) {
if (Region.getRegion(e.getBlock().getLocation()).isFire()) e.setCancelled(true);
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java
index 47953a3..2baeb2a 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java
@@ -20,38 +20,70 @@
package de.steamwar.bausystem.commands;
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.core.Core;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
-public class CommandFreeze extends RegionToggleCommand {
+public class CommandFreeze extends SWCommand implements Listener {
- @Override
- String getNoPermMessage() {
+ public CommandFreeze() {
+ super("freeze", "stoplag");
+ Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§efreeze §8- §7Toggle Freeze");
+ }
+
+ @Register
+ public void toggleCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ Region region = Region.getRegion(p.getLocation());
+ if (toggle(region)) {
+ RegionUtils.actionBar(region, getEnableMessage());
+ } else {
+ RegionUtils.actionBar(region, getDisableMessage());
+ }
+ }
+
+ private String getNoPermMessage() {
return "§cDu darfst diese Welt nicht einfrieren";
}
- @Override
- String getEnableMessage(){
- return "§cWelt eingefroren";
- }
- @Override
- String getDisableMessage(){
- return "§aWelt aufgetaut";
+
+ private String getEnableMessage(){
+ return "§cRegion eingefroren";
}
- @Override
- boolean toggle(Region region) {
+ private String getDisableMessage(){
+ return "§aRegion aufgetaut";
+ }
+
+ private boolean toggle(Region region) {
region.setFreeze(!region.isFreeze());
return region.isFreeze();
}
+ private boolean permissionCheck(Player player) {
+ if (Welt.noPermission(player, Permission.world)) {
+ player.sendMessage(BauSystem.PREFIX + getNoPermMessage());
+ return false;
+ }
+ return true;
+ }
+
@EventHandler
public void onEntitySpawn(EntitySpawnEvent e) {
if (!Region.getRegion(e.getLocation()).isFreeze()) return;
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java
index 5038659..b2fa3db 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java
@@ -1,3 +1,22 @@
+/*
+ * 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.BauSystem;
@@ -6,6 +25,7 @@ import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.tracer.show.TraceShowManager;
import de.steamwar.bausystem.world.*;
+import de.steamwar.command.SWCommand;
import de.steamwar.core.Core;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
@@ -19,9 +39,6 @@ import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
-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;
@@ -34,7 +51,7 @@ import org.bukkit.potion.PotionEffectType;
import java.util.*;
-public class CommandGUI implements CommandExecutor, Listener {
+public class CommandGUI extends SWCommand implements Listener {
private static final Set OPEN_INVS = new HashSet<>();
private static final Set OPEN_TRACER_INVS = new HashSet<>();
@@ -42,9 +59,27 @@ public class CommandGUI implements CommandExecutor, Listener {
private static boolean isRefreshing = false;
public CommandGUI() {
+ super("gui");
Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getPlugin(), LAST_F_PLAYER::clear, 0, 20);
}
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§egui §8- §7Öffne die GUI");
+ p.sendMessage("§8/§egui item §8- §7Gebe das GUI item");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ openBauGui(p);
+ OPEN_INVS.add(p);
+ }
+
+ @Register({"item"})
+ public void itemCommand(Player p) {
+ SWUtils.giveItemToPlayer(p, new ItemStack(Material.NETHER_STAR));
+ }
+
public static void openBauGui(Player player) {
Region region = Region.getRegion(player.getLocation());
SWInventory inv = new SWInventory(player, 5 * 9, SteamwarUser.get(BauSystem.getOwner()).getUserName() + "s Bau");
@@ -584,20 +619,6 @@ public class CommandGUI implements CommandExecutor, Listener {
return base;
}
- @Override
- public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
- if (!(commandSender instanceof Player))
- return false;
- Player player = ((Player) commandSender);
- if (strings.length == 0) {
- openBauGui(player);
- OPEN_INVS.add(player);
- } else if ("item".equalsIgnoreCase(strings[0])) {
- SWUtils.giveItemToPlayer(player, new ItemStack(Material.NETHER_STAR));
- }
- return true;
- }
-
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGamemode.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGamemode.java
index 757f08d..8747a1c 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGamemode.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGamemode.java
@@ -1,60 +1,58 @@
-/*
- 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 .
-*/
+/*
+ * 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 com.google.common.collect.ImmutableList;
import de.steamwar.bausystem.BauSystem;
+import de.steamwar.command.SWCommand;
import de.steamwar.sql.BauweltMember;
-import org.apache.commons.lang.Validate;
import org.bukkit.GameMode;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
-import org.bukkit.util.StringUtil;
-import java.util.ArrayList;
-import java.util.List;
-
-public class CommandGamemode extends BukkitCommand {
- private static final List GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival",
- "spectator");
+public class CommandGamemode extends SWCommand {
public CommandGamemode() {
- super("gamemode");
- List aliases = new ArrayList<>();
- aliases.add("gm");
- this.setAliases(aliases);
- this.description = "Ändert den Spielmodus eines Spielers";
- this.usageMessage = "/gm [Spielmodus]";
+ super("gamemode", "gm", "g");
}
- public boolean execute(CommandSender sender, String currentAlias, String[] args) {
- if (!(sender instanceof Player)) {
- return false;
- } else if (args.length == 0) {
- sender.sendMessage(BauSystem.PREFIX + this.usageMessage);
- return false;
+ @Register(help = true)
+ public void gamemodeHelp(Player p, String... args) {
+ p.sendMessage("§cUnbekannter Spielmodus");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ if (p.getGameMode() == GameMode.CREATIVE) {
+ p.setGameMode(GameMode.SPECTATOR);
+ } else {
+ p.setGameMode(GameMode.CREATIVE);
}
+ }
- Player p = (Player) sender;
+ @Register
+ public void gamemodeCommand(Player p, GameMode gameMode) {
+ if (!permissionCheck(p)) return;
+ p.setGameMode(gameMode);
+ }
+ private boolean permissionCheck(Player p) {
if (!p.getUniqueId().equals(BauSystem.getOwner())) {
BauweltMember member = BauweltMember.getBauMember(BauSystem.getOwner(), p.getUniqueId());
if (member == null || !member.isBuild()) {
@@ -62,47 +60,6 @@ public class CommandGamemode extends BukkitCommand {
return false;
}
}
-
- GameMode mode = createMode(args[0]);
-
- if (mode == null) {
- p.sendMessage(BauSystem.PREFIX + "§cUnbekannter Spielmodus");
- return false;
- }
-
- p.setGameMode(mode);
return true;
}
-
- @SuppressWarnings("deprecation")
- private GameMode createMode(String modeArg) {
- try {
- return GameMode.getByValue(Integer.parseInt(modeArg));
- } catch (NumberFormatException ignored) {
- if ((modeArg.equalsIgnoreCase("creative")) || (modeArg.equalsIgnoreCase("c")))
- return GameMode.CREATIVE;
- else if ((modeArg.equalsIgnoreCase("adventure")) || (modeArg.equalsIgnoreCase("a")))
- return GameMode.ADVENTURE;
- else if ((modeArg.equalsIgnoreCase("spectator")) || (modeArg.equalsIgnoreCase("sp")))
- return GameMode.SPECTATOR;
- else if ((modeArg.equalsIgnoreCase("survival")) || (modeArg.equalsIgnoreCase("s")))
- return GameMode.SURVIVAL;
- }
- return null;
- }
-
- @Override
- public List tabComplete(CommandSender sender, String alias, String[] args) {
- Validate.notNull(sender, "Sender cannot be null");
- Validate.notNull(args, "Arguments cannot be null");
- Validate.notNull(alias, "Alias cannot be null");
-
- if (args.length == 1)
- return StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES,
- new ArrayList<>(GAMEMODE_NAMES.size()));
- if (args.length == 2) {
- return super.tabComplete(sender, alias, args);
- }
- return ImmutableList.of();
- }
-}
+}
\ No newline at end of file
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGills.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGills.java
index 8095e91..051ea10 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGills.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGills.java
@@ -20,22 +20,25 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
+import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
-public class CommandGills implements CommandExecutor {
+public class CommandGills extends SWCommand {
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
- toggleGills(player);
- return false;
+ public CommandGills() {
+ super("watervision", "wv");
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§ewatervision §8- §7Toggle WaterBreathing");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ toggleGills(p);
}
public static void toggleGills(Player player) {
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java
index 6043e74..93873dc 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInfo.java
@@ -22,30 +22,36 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.TPSUtils;
+import de.steamwar.command.SWCommand;
import de.steamwar.core.TPSWatcher;
import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import static de.steamwar.bausystem.world.TPSUtils.getTps;
-public class CommandInfo implements CommandExecutor {
+public class CommandInfo 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 CommandInfo() {
+ super("bauinfo");
+ }
- sender.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName());
- Region region = Region.getRegion(player.getLocation());
- sender.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS"));
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§ebauinfo §8- §7Gibt Informationen über den Bau");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ CommandInfo.sendBauInfo(p);
+ }
+
+ public static void sendBauInfo(Player p) {
+ p.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(BauSystem.getOwnerID()).getUserName());
+ Region region = Region.getRegion(p.getLocation());
+ p.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.getTntMode().getName() + " §eFire§8: " + (region.isFire() ? "§aAUS" : "§cAN") + " §eFreeze§8: " + (region.isFreeze() ? "§aAN" : "§cAUS"));
List members = BauweltMember.getMembers(BauSystem.getOwnerID());
StringBuilder membermessage = new StringBuilder().append(BauSystem.PREFIX).append("Mitglieder: ");
@@ -56,7 +62,7 @@ public class CommandInfo implements CommandExecutor {
membermessage.append(member.isWorldEdit() ? "§a" : "§c").append("WE").append("§8,");
membermessage.append(member.isWorld() ? "§a" : "§c").append("W").append("§8]").append(" ");
}
- sender.sendMessage(membermessage.toString());
+ p.sendMessage(membermessage.toString());
StringBuilder tpsMessage = new StringBuilder();
tpsMessage.append(BauSystem.PREFIX).append("TPS:§e");
@@ -67,8 +73,6 @@ public class CommandInfo implements CommandExecutor {
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES));
tpsMessage.append(" ").append(TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES));
}
- sender.sendMessage(tpsMessage.toString());
- return false;
+ p.sendMessage(tpsMessage.toString());
}
-
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInjector.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInjector.java
deleted file mode 100644
index b1b322e..0000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandInjector.java
+++ /dev/null
@@ -1,43 +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 org.bukkit.Bukkit;
-import org.bukkit.command.Command;
-import org.bukkit.command.SimpleCommandMap;
-
-import java.lang.reflect.Field;
-
-public class CommandInjector {
-
- private CommandInjector() {
- }
-
- private static final String PACKAGE_NAME = Bukkit.getServer().getClass().getPackage().getName();
- private static final String VERSION = PACKAGE_NAME.substring(PACKAGE_NAME.lastIndexOf('.') + 1);
-
- public static void injectCommand(Command cmd) throws Exception {
- Class serverClass = Class.forName("org.bukkit.craftbukkit." + VERSION + ".CraftServer");
- Field f1 = serverClass.getDeclaredField("commandMap");
- f1.setAccessible(true);
- SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer());
- commandMap.register("BauSystem", cmd);
- }
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLoader.java
index 0cd79d0..fb3f5d6 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLoader.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLoader.java
@@ -23,62 +23,68 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.AutoLoader;
import de.steamwar.bausystem.world.Welt;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
+import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
-public class CommandLoader implements CommandExecutor {
+public class CommandLoader extends SWCommand {
- private void help(Player player) {
- player.sendMessage("§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen");
- player.sendMessage("§8/§7loader undo §8- §7Entfernt die zuletzt aufgenommene Aktion");
- player.sendMessage("§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab");
- player.sendMessage("§8/§7loader wait §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Schüssen");
- player.sendMessage("§8/§7loader speed §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Aktionen");
- player.sendMessage("§8/§eloader stop §8- §7Stoppt die Aufnahme bzw. das Abspielen");
- player.sendMessage("§7Der AutoLader arbeitet mit §eIngame§8-§eTicks §8(20 Ticks pro Sekunde)");
+ public CommandLoader() {
+ super("loader");
}
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen");
+ p.sendMessage("§8/§7loader undo §8- §7Entfernt die zuletzt aufgenommene Aktion");
+ p.sendMessage("§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab");
+ p.sendMessage("§8/§7loader wait §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Schüssen");
+ p.sendMessage("§8/§7loader speed §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Aktionen");
+ p.sendMessage("§8/§eloader stop §8- §7Stoppt die Aufnahme bzw. das Abspielen");
+ p.sendMessage("§7Der AutoLader arbeitet mit §eIngame§8-§eTicks §8(20 Ticks pro Sekunde)");
+ }
+ @Register({"setup"})
+ public void setupCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ setup(p);
+ }
+
+ @Register({"undo"})
+ public void undoCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ undo(p);
+ }
+
+ @Register({"start"})
+ public void startCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ start(p);
+ }
+
+ @Register({"stop"})
+ public void stopCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ stop(p);
+ }
+
+ @Register({"wait"})
+ public void waitCommand(Player p, int time) {
+ if (!permissionCheck(p)) return;
+ wait(p, time);
+ }
+
+ @Register({"speed"})
+ public void speedCommand(Player p, int time) {
+ if (!permissionCheck(p)) return;
+ speed(p, time);
+ }
+
+ private boolean permissionCheck(Player player) {
if (Welt.noPermission(player, Permission.build)) {
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den AutoLader verwenden");
return false;
}
-
- if (args.length == 0) {
- help(player);
- return false;
- }
-
- switch (args[0].toLowerCase()) {
- case "setup":
- setup(player);
- break;
- case "undo":
- undo(player);
- break;
- case "start":
- start(player);
- break;
- case "stop":
- stop(player);
- break;
- case "wait":
- wait(player, args);
- break;
- case "speed":
- speed(player, args);
- break;
- default:
- help(player);
- }
- return false;
+ return true;
}
private void setup(Player player) {
@@ -114,43 +120,26 @@ public class CommandLoader implements CommandExecutor {
AutoLoader.getLoader(player).stop();
}
- private void wait(Player player, String[] args) {
- if (args.length != 2) {
- help(player);
- return;
- }
-
+ private void wait(Player player, int time) {
AutoLoader loader = loader(player);
- if (loader == null)
+ if (loader == null) {
loader = AutoLoader.getLoader(player);
-
- try {
- loader.wait(Integer.parseInt(args[1]));
- } catch (NumberFormatException e) {
- player.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Ganzzahl an");
}
+ loader.wait(time);
}
- private void speed(Player player, String[] args) {
- if (args.length != 2) {
- help(player);
- return;
- }
-
+ private void speed(Player player, int time) {
AutoLoader loader = loader(player);
- if (loader == null)
+ if (loader == null) {
loader = AutoLoader.getLoader(player);
-
- try {
- loader.blockWait(Integer.parseInt(args[1]));
- } catch (NumberFormatException e) {
- player.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Ganzzahl an");
}
+ loader.blockWait(time);
}
private AutoLoader loader(Player player) {
- if (AutoLoader.hasLoader(player))
+ if (AutoLoader.hasLoader(player)) {
return AutoLoader.getLoader(player);
+ }
player.sendMessage(BauSystem.PREFIX + "§cDu hast keinen aktiven AutoLader");
player.sendMessage(BauSystem.PREFIX + "§7Es wird ein neuer AutoLader gestartet");
setup(player);
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLockschem.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLockschem.java
index 6ac4742..08a4f57 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLockschem.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandLockschem.java
@@ -20,54 +20,63 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
+import de.steamwar.command.SWCommand;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SchematicType;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserGroup;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-public class CommandLockschem implements CommandExecutor {
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
+public class CommandLockschem extends SWCommand {
- SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
+ public CommandLockschem() {
+ super("lockschem");
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ SteamwarUser steamwarUser = SteamwarUser.get(p.getUniqueId());
UserGroup userGroup = steamwarUser.getUserGroup();
if (userGroup != UserGroup.Admin &&
userGroup != UserGroup.Developer &&
userGroup != UserGroup.Moderator &&
- userGroup != UserGroup.Supporter)
- return false;
-
- if (args.length != 2) {
- sendHelp(player);
- return false;
+ userGroup != UserGroup.Supporter) {
+ return;
}
- SteamwarUser schemOwner = SteamwarUser.get(args[0]);
+ sendHelp(p);
+ }
+
+ @Register
+ public void genericCommand(Player p, String owner, String schematicName) {
+ SteamwarUser steamwarUser = SteamwarUser.get(p.getUniqueId());
+ UserGroup userGroup = steamwarUser.getUserGroup();
+
+ if (userGroup != UserGroup.Admin &&
+ userGroup != UserGroup.Developer &&
+ userGroup != UserGroup.Moderator &&
+ userGroup != UserGroup.Supporter) {
+ return;
+ }
+
+ SteamwarUser schemOwner = SteamwarUser.get(owner);
if (schemOwner == null) {
- player.sendMessage(BauSystem.PREFIX + "Dieser Spieler existiert nicht!");
- return false;
+ p.sendMessage(BauSystem.PREFIX + "Dieser Spieler existiert nicht!");
+ return;
}
- Schematic schematic = Schematic.getSchemFromDB(args[1], schemOwner.getUUID());
+ Schematic schematic = Schematic.getSchemFromDB(schematicName, schemOwner.getUUID());
if (schematic == null) {
- player.sendMessage(BauSystem.PREFIX + "Dieser Spieler besitzt keine Schematic mit diesem Namen!");
- return false;
+ p.sendMessage(BauSystem.PREFIX + "Dieser Spieler besitzt keine Schematic mit diesem Namen!");
+ return;
}
- player.sendMessage(BauSystem.PREFIX + "Schematic " + schematic.getSchemName() + " von " +
+ p.sendMessage(BauSystem.PREFIX + "Schematic " + schematic.getSchemName() + " von " +
SteamwarUser.get(schematic.getSchemOwner()).getUserName() + " von " + schematic.getSchemType().toString() +
" auf NORMAL zurückgesetzt!");
schematic.setSchemType(SchematicType.Normal);
- return false;
}
private void sendHelp(Player player) {
- player.sendMessage(BauSystem.PREFIX + "/schemlock [OWNER] [SCHEM NAME]");
+ player.sendMessage("§8/§eschemlock §8[§7Owner§8] §8[§7Schematic§8] §8- §7 Sperre eine Schematic");
}
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandNV.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandNV.java
index 196887d..7b232a2 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandNV.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandNV.java
@@ -20,22 +20,25 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
+import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
-public class CommandNV implements CommandExecutor {
+public class CommandNV extends SWCommand {
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
- toggleNightvision(player);
- return false;
+ public CommandNV() {
+ super("nightvision", "nv");
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§enightvision §8- §7Toggle NightVision");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ toggleNightvision(p);
}
public static void toggleNightvision(Player player) {
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java
index 92e83bc..fed21f5 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandProtect.java
@@ -23,48 +23,73 @@ 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(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§eprotect §8- §7Schütze die Region");
+ p.sendMessage("§8/§eprotect §8[§7Schematic§8] §8- §7Schütze die Region mit einer Schematic");
+ }
+
+ @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/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java
index 08c794a..3038690 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java
@@ -24,13 +24,32 @@ import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.world.RedstoneListener;
import de.steamwar.bausystem.world.Welt;
+import de.steamwar.command.SWCommand;
import de.steamwar.core.VersionedRunnable;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-public class CommandRedstoneTester implements CommandExecutor {
+public class CommandRedstoneTester extends SWCommand {
+
+ public CommandRedstoneTester() {
+ super("redstonetester", "rt");
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§eredstonetester §8- §7Gibt den RedstoneTester");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ VersionedRunnable.call(new VersionedRunnable(() -> {
+ p.sendMessage(BauSystem.PREFIX + "Der RedstoneTester ist nicht in der 1.12 verfügbar");
+ }, 8), new VersionedRunnable(() -> {
+ if (!permissionCheck(p)) return;
+ p.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten");
+ SWUtils.giveItemToPlayer(p, RedstoneListener.WAND);
+ }, 15));
+ }
+
private boolean permissionCheck(Player player) {
if (Welt.noPermission(player, Permission.build)) {
@@ -40,21 +59,4 @@ public class CommandRedstoneTester implements CommandExecutor {
return true;
}
- @Override
- public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
- if (!(commandSender instanceof Player))
- return false;
- Player player = (Player) commandSender;
- VersionedRunnable.call(new VersionedRunnable(() -> {
- player.sendMessage(BauSystem.PREFIX + "Der RedstoneTester ist nicht in der 1.12 verfügbar");
- }, 8), new VersionedRunnable(() -> {
- if (!permissionCheck(player)) {
- return;
- }
- player.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten");
- SWUtils.giveItemToPlayer(player, RedstoneListener.WAND);
- }, 15));
- return false;
- }
-
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java
index 0b8fcbb..5c7b31b 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java
@@ -23,49 +23,73 @@ 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 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(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§ereset §8- §7Setzte die Region zurück");
+ p.sendMessage("§8/§ereset §8[§7Schematic§8] §8- §7Setzte die Region mit einer Schematic zurück");
+ }
+
+ @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/CommandScript.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java
index 1af6767..8e071ea 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java
@@ -22,10 +22,8 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.SWUtils;
+import de.steamwar.command.SWCommand;
import org.bukkit.Material;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
@@ -33,7 +31,11 @@ import org.bukkit.inventory.meta.BookMeta;
import java.util.ArrayList;
import java.util.List;
-public class CommandScript implements CommandExecutor {
+public class CommandScript extends SWCommand {
+
+ public CommandScript() {
+ super("script");
+ }
public static final ItemStack BOOK = new ItemStack(Material.WRITTEN_BOOK, 1);
@@ -79,13 +81,14 @@ public class CommandScript implements CommandExecutor {
BOOK.setItemMeta(bookMeta);
}
- @Override
- public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
- if (!(sender instanceof Player)) {
- return false;
- }
- SWUtils.giveItemToPlayer((Player) sender, BOOK);
- return false;
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§escript §8- §7Gibt das Script Buch");
+ }
+
+ @Register
+ public void giveCommand(Player p) {
+ SWUtils.giveItemToPlayer(p, BOOK);
}
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java
index 946e07b..f352fca 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java
@@ -1,68 +1,120 @@
+/*
+ * 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.BauSystem;
import de.steamwar.bausystem.world.ScriptListener;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
+import de.steamwar.command.SWCommand;
+import de.steamwar.command.SWCommandUtils;
+import de.steamwar.command.TypeMapper;
import org.bukkit.entity.Player;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
-public class CommandScriptVars implements CommandExecutor {
+public class CommandScriptVars extends SWCommand {
- @Override
- public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
- if (!(sender instanceof Player)) {
- return false;
- }
- Player player = (Player) sender;
- if (args.length == 0) {
- Map globalVariables = ScriptListener.GLOBAL_VARIABLES.get(player);
- if (globalVariables == null) {
- player.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
- return false;
- }
- int i = 0;
- player.sendMessage(BauSystem.PREFIX + globalVariables.size() + " Variable(n)");
- for (Map.Entry var : globalVariables.entrySet()) {
- if (i++ >= 40) break;
- player.sendMessage("- " + var.getKey() + "=" + var.getValue());
- }
- return false;
- }
- String varName = args[0];
- if (args.length == 1) {
- Map globalVariables = ScriptListener.GLOBAL_VARIABLES.get(player);
- if (globalVariables == null) {
- player.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
- return false;
- }
- if (!globalVariables.containsKey(varName)) {
- player.sendMessage(BauSystem.PREFIX + "§cUnbekannte Variable");
- return false;
- }
- player.sendMessage(BauSystem.PREFIX + varName + "=" + globalVariables.get(varName));
- return false;
- }
- switch (args[1].toLowerCase()) {
- case "delete":
- case "clear":
- case "remove":
- if (!ScriptListener.GLOBAL_VARIABLES.containsKey(player)) {
- player.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
- break;
- }
- ScriptListener.GLOBAL_VARIABLES.get(player).remove(varName);
- player.sendMessage(BauSystem.PREFIX + "Variable " + varName + " gelöscht");
- break;
- default:
- int value = ScriptListener.parseValue(args[1]);
- ScriptListener.GLOBAL_VARIABLES.computeIfAbsent(player, p -> new HashMap<>()).put(varName, value);
- player.sendMessage(BauSystem.PREFIX + varName + " auf " + value + " gesetzt");
- }
- return false;
+ public CommandScriptVars() {
+ super("scripvars");
}
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§escriptvars §8- §7Zähle alle globalen Variablen auf");
+ p.sendMessage("§8/§escriptvars §8[§7Variable§8] §8- §7Gebe den Wert der Variable zurück");
+ p.sendMessage("§8/§escriptvars §8[§7Variable§8] §8[§7Value§8] §8- §7Setzte eine Variable auf einen Wert");
+ p.sendMessage("§8/§escriptvars §8[§7Variable§8] §8<§7remove§8|§7delete§8|§7clear§8> §8- §7Lösche eine Variable");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ Map globalVariables = ScriptListener.GLOBAL_VARIABLES.get(p);
+ if (globalVariables == null) {
+ p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
+ return;
+ }
+ int i = 0;
+ p.sendMessage(BauSystem.PREFIX + globalVariables.size() + " Variable(n)");
+ for (Map.Entry var : globalVariables.entrySet()) {
+ if (i++ >= 40) break;
+ p.sendMessage("- " + var.getKey() + "=" + var.getValue());
+ }
+ }
+
+ @Register
+ public void removeCommand(Player p, String varName) {
+ Map globalVariables = ScriptListener.GLOBAL_VARIABLES.get(p);
+ if (globalVariables == null) {
+ p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
+ return;
+ }
+ if (!globalVariables.containsKey(varName)) {
+ p.sendMessage(BauSystem.PREFIX + "§cUnbekannte Variable");
+ return;
+ }
+ p.sendMessage(BauSystem.PREFIX + varName + "=" + globalVariables.get(varName));
+ }
+
+ @Register
+ public void booleanValueCommand(Player p, String varName, int value) {
+ ScriptListener.GLOBAL_VARIABLES.computeIfAbsent(p, player -> new HashMap<>()).put(varName, value);
+ p.sendMessage(BauSystem.PREFIX + varName + " auf " + value + " gesetzt");
+ }
+
+ @Register
+ public void removeCommand(Player p, String varName, @Mapper(value = "Delete") String remove) {
+ if (!ScriptListener.GLOBAL_VARIABLES.containsKey(p)) {
+ p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
+ return;
+ }
+ ScriptListener.GLOBAL_VARIABLES.get(p).remove(varName);
+ p.sendMessage(BauSystem.PREFIX + "Variable " + varName + " gelöscht");
+ }
+
+ @ClassMapper(value = String.class, local = true)
+ public TypeMapper stringTypeMapper() {
+ return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> {
+ if (commandSender instanceof Player) {
+ Player player = (Player) commandSender;
+ return new ArrayList<>(ScriptListener.GLOBAL_VARIABLES.getOrDefault(player, new HashMap<>()).keySet());
+ }
+ return null;
+ });
+ }
+
+ @Mapper(value = "Delete", local = true)
+ public TypeMapper clearStringTypeMapper() {
+ List tabCompletes = Arrays.asList("delete", "clear", "remove");
+ return SWCommandUtils.createMapper(s -> {
+ if (s.equalsIgnoreCase("delete") || s.equalsIgnoreCase("clear") || s.equalsIgnoreCase("remove")) {
+ return s;
+ }
+ return null;
+ }, s -> tabCompletes);
+ }
+
+ @ClassMapper(value = int.class, local = true)
+ public TypeMapper integerTypeMapper() {
+ List tabCompletes = Arrays.asList("true", "false", "yes", "no");
+ return SWCommandUtils.createMapper(s -> {
+ if (s.equalsIgnoreCase("remove") || s.equalsIgnoreCase("clear") || s.equalsIgnoreCase("delete")) return null;
+ return ScriptListener.parseValue(s);
+ }, s -> tabCompletes);
+ }
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVarsTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVarsTabCompleter.java
deleted file mode 100644
index f9fa6ef..0000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVarsTabCompleter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package de.steamwar.bausystem.commands;
-
-import de.steamwar.bausystem.SWUtils;
-import de.steamwar.bausystem.world.ScriptListener;
-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.HashMap;
-import java.util.List;
-
-public class CommandScriptVarsTabCompleter implements TabCompleter {
-
- @Override
- public List onTabComplete(CommandSender sender, Command command, String s, String[] args) {
- if (!(sender instanceof Player)) {
- return new ArrayList<>();
- }
- Player player = (Player) sender;
- if (args.length == 1) {
- List variables = new ArrayList<>(ScriptListener.GLOBAL_VARIABLES.getOrDefault(player, new HashMap<>()).keySet());
- return SWUtils.manageList(variables, args);
- }
- if (args.length != 2) {
- return new ArrayList<>();
- }
- int value = ScriptListener.GLOBAL_VARIABLES.getOrDefault(player, new HashMap<>()).getOrDefault(args[0], 0);
- return SWUtils.manageList(Arrays.asList(value + "", "true", "false", "yes", "no", "delete", "clear", "remove"), args);
- }
-
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java
index ad876df..10e603d 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java
@@ -25,18 +25,45 @@ import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.world.TNTSimulator;
import de.steamwar.bausystem.world.Welt;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
+import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
-public class CommandSimulator implements CommandExecutor {
+public class CommandSimulator extends SWCommand {
- private void help(Player player) {
- player.sendMessage("§8/§esimulator §8- §7Öffnet die Simulations GUI");
- player.sendMessage("§8/§esimulator start §8- §7Startet die Simulation");
- player.sendMessage("§8/§esimulator wand §8- §7Legt dir den Simulatorstab ins Inventar");
- player.sendMessage("§8/§esimulator delete §8- §7Löscht alle TNT");
+ public CommandSimulator() {
+ super("simulator", "sim");
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§esimulator §8- §7Öffnet die Simulations GUI");
+ p.sendMessage("§8/§esimulator start §8- §7Startet die Simulation");
+ p.sendMessage("§8/§esimulator wand §8- §7Legt dir den Simulatorstab ins Inventar");
+ p.sendMessage("§8/§esimulator delete §8- §7Löscht alle TNT");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ TNTSimulator.openSimulator(p);
+ }
+
+ @Register({"wand"})
+ public void wandCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ SWUtils.giveItemToPlayer(p, TNTSimulator.WAND);
+ }
+
+ @Register({"start"})
+ public void startCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ TNTSimulator.get(p).start();
+ }
+
+ @Register({"delete"})
+ public void deleteCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ TNTSimulator.get(p).delete();
}
private boolean permissionCheck(Player player) {
@@ -47,33 +74,4 @@ public class CommandSimulator implements CommandExecutor {
return true;
}
- @Override
- public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
- if (!(commandSender instanceof Player))
- return false;
- Player player = (Player) commandSender;
- if (!permissionCheck(player)) {
- return false;
- }
-
- if (args.length == 1) {
- switch (args[0].toLowerCase()) {
- case "wand":
- SWUtils.giveItemToPlayer(player, TNTSimulator.WAND);
- break;
- case "start":
- TNTSimulator.get(player).start();
- break;
- case "delete":
- TNTSimulator.get(player).delete();
- default:
- help(player);
- break;
- }
- return false;
- }
- TNTSimulator.openSimulator(player);
- return false;
- }
-
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java
deleted file mode 100644
index 9ece2fd..0000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java
+++ /dev/null
@@ -1,46 +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 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 CommandSimulatorTabCompleter implements TabCompleter {
-
- private List arguments = new ArrayList<>(Arrays.asList("wand", "start", "delete"));
-
- @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/de/steamwar/bausystem/commands/CommandSkull.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java
index 7cbab3a..ca98a7e 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java
@@ -19,36 +19,31 @@
package de.steamwar.bausystem.commands;
-import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils;
+import de.steamwar.command.SWCommand;
import de.steamwar.inventory.SWItem;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
-public class CommandSkull implements CommandExecutor {
+public class CommandSkull extends SWCommand {
- @Override
- public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
- if (!(commandSender instanceof Player))
- return false;
- Player p = (Player) commandSender;
+ public CommandSkull() {
+ super("skull");
+ }
- if (args.length != 1) {
- p.sendMessage(BauSystem.PREFIX + "§8/§eskull §8[§eSpieler§8]");
- return false;
- }
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§eskull §8[§eSpieler§8] §8- §7Gibt einen SpielerKopf");
+ }
- ItemStack is = SWItem.getPlayerSkull(args[0]).getItemStack();
+ @Register
+ public void giveCommand(Player p, String skull) {
+ ItemStack is = SWItem.getPlayerSkull(skull).getItemStack();
SkullMeta sm = (SkullMeta) is.getItemMeta();
assert sm != null;
- sm.setDisplayName("§e" + args[0] + "§8s Kopf");
+ sm.setDisplayName("§e" + skull + "§8s Kopf");
is.setItemMeta(sm);
SWUtils.giveItemToPlayer(p, is);
-
- return false;
}
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSpeed.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSpeed.java
index 223af4d..195cefc 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSpeed.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSpeed.java
@@ -20,40 +20,51 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
+import de.steamwar.command.SWCommand;
+import de.steamwar.command.SWCommandUtils;
+import de.steamwar.command.TypeMapper;
import org.bukkit.entity.Player;
-public class CommandSpeed implements CommandExecutor {
+import java.util.Arrays;
+import java.util.List;
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
+public class CommandSpeed extends SWCommand {
- if (args.length == 0) {
- player.sendMessage(BauSystem.PREFIX + "/speed [Geschwindigkeit]");
- return false;
- }
+ public CommandSpeed() {
+ super("speed");
+ }
- float speed;
- try {
- speed = Float.parseFloat(args[0]);
- } catch (NumberFormatException e) {
- player.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Zahl zwischen 0 und 10 an");
- return false;
- }
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§espeed §8[§7Geschwindigkeit§8] §8- §7Setzte deine Flug- und Gehgeschwindigkeit");
+ }
+
+ @Register({"default"})
+ public void defaultCommand(Player p) {
+ speedCommand(p, 1);
+ }
+
+ @Register
+ public void speedCommand(Player p, float speed) {
if (speed < 0 || speed > 10) {
- player.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Zahl zwischen 0 und 10 an");
- return false;
+ p.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Zahl zwischen 0 und 10 an");
+ return;
}
- player.sendMessage("§aGeschwindigkeit wurde auf §6" + speed + " §agesetzt");
+ p.sendMessage("§aGeschwindigkeit wurde auf §6" + speed + " §agesetzt");
+ p.setFlySpeed(speed / 10);
+ p.setWalkSpeed((speed >= 9 ? speed : speed + 1) / 10);
+ }
- player.setFlySpeed(speed / 10);
- player.setWalkSpeed((speed >= 9 ? speed : speed + 1) / 10);
- return false;
+ @ClassMapper(value = float.class, local = true)
+ public TypeMapper doubleTypeMapper() {
+ List tabCompletes = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
+ return SWCommandUtils.createMapper(s -> {
+ try {
+ return Float.parseFloat(s.replace(',', '.'));
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }, s -> tabCompletes);
}
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java
index d528f37..c96ff53 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,70 @@ public class CommandTNT implements CommandExecutor, Listener {
public String getName() {
return name;
}
-
}
public CommandTNT() {
+ super("tnt");
Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
}
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§etnt §8- §7Ändere das TNT verhalten");
+ p.sendMessage("§8/§etnt §8[§7Mode§8] §8- §7Setzte das TNT verhalten auf einen Modus");
+ }
+
+ @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,65 +129,25 @@ 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);
- RegionToggleCommand.actionBar(region, requestedMessage);
+ RegionUtils.actionBar(region, requestedMessage);
return;
}
switch (region.getTntMode()) {
case ON:
case ONLY_TB:
region.setTntMode(TNTMode.OFF);
- RegionToggleCommand.actionBar(region, getDisableMessage());
+ RegionUtils.actionBar(region, getDisableMessage());
break;
case OFF:
if (Region.buildAreaEnabled() && region.hasTestblock()) {
region.setTntMode(TNTMode.ONLY_TB);
- RegionToggleCommand.actionBar(region, getTestblockEnableMessage());
+ RegionUtils.actionBar(region, getTestblockEnableMessage());
} else {
region.setTntMode(TNTMode.ON);
- RegionToggleCommand.actionBar(region, getEnableMessage());
+ RegionUtils.actionBar(region, getEnableMessage());
}
break;
}
@@ -137,15 +159,14 @@ public class CommandTNT implements CommandExecutor, Listener {
Region region = Region.getRegion(block.getLocation());
if (region.getTntMode() == TNTMode.ON) return false;
if (region.hasBuildRegion() && region.inBuildRegion(block.getLocation())) {
- RegionToggleCommand.actionBar(region, "§cEine Explosion hätte Blöcke im Baubereich zerstört");
+ RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Baubereich zerstört");
return true;
}
if (region.hasBuildRegion() && region.inBuildRegionExtension(block.getLocation())) {
- RegionToggleCommand.actionBar(region, "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört");
+ RegionUtils.actionBar(region, "§cEine Explosion hätte Blöcke im Ausfahrbereich zerstört");
return true;
}
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/de/steamwar/bausystem/commands/CommandTPSLimiter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java
index 58f79ea..4169f1f 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiter.java
@@ -23,18 +23,22 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.TPSUtils;
import de.steamwar.bausystem.world.Welt;
+import de.steamwar.command.SWCommand;
+import de.steamwar.command.SWCommandUtils;
+import de.steamwar.command.TypeMapper;
import de.steamwar.core.VersionedRunnable;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.World;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
-public class CommandTPSLimiter implements CommandExecutor {
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class CommandTPSLimiter extends SWCommand {
private static final World WORLD = Bukkit.getWorlds().get(0);
private static double currentTPSLimit = 20;
@@ -48,6 +52,52 @@ public class CommandTPSLimiter implements CommandExecutor {
private BukkitTask tpsLimiter = null;
+ private List tabCompletions = new ArrayList<>(Arrays.asList("0,5", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"));
+
+ public CommandTPSLimiter() {
+ super("tpslimit");
+ if (TPSUtils.isWarpAllowed()) {
+ tabCompletions.addAll(Arrays.asList("21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"));
+ }
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage(BauSystem.PREFIX + "Jetziges TPS limit: " + currentTPSLimit);
+ p.sendMessage("§8/§etpslimit §8[§7TPS§8|§edefault§8] §8- §7Setzte die TPS auf dem Bau");
+ }
+
+ @Register({"default"})
+ public void defaultCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ currentTPSLimit = 20;
+ sendNewTPSLimitMessage();
+ tpsLimiter();
+ }
+
+ @Register
+ public void valueCommand(Player p, double tpsLimitDouble) {
+ if (!permissionCheck(p)) return;
+ if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSUtils.isWarpAllowed() ? 40 : 20)) {
+ sendInvalidArgumentMessage(p);
+ return;
+ }
+ currentTPSLimit = tpsLimitDouble;
+ sendNewTPSLimitMessage();
+ tpsLimiter();
+ }
+
+ @ClassMapper(value = double.class, local = true)
+ public TypeMapper doubleTypeMapper() {
+ return SWCommandUtils.createMapper(s -> {
+ try {
+ return Double.parseDouble(s.replace(',', '.'));
+ } catch (NumberFormatException e) {
+ return 0D;
+ }
+ }, s -> tabCompletions);
+ }
+
private boolean permissionCheck(Player player) {
if (Welt.noPermission(player, Permission.world)) {
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TPS-Limiter nutzen");
@@ -56,42 +106,6 @@ public class CommandTPSLimiter implements CommandExecutor {
return true;
}
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player)) {
- return false;
- } else if (args.length == 0) {
- sender.sendMessage(BauSystem.PREFIX + "Jetziges TPS limit: " + currentTPSLimit);
- sender.sendMessage(BauSystem.PREFIX + "Ändere das TPS limit mit: §8/§etpslimit §8[§7TPS§8|§edefault§8]");
- return false;
- }
- Player player = (Player) sender;
- if (!permissionCheck(player)) return false;
-
- String tpsLimit = args[0];
- if (tpsLimit.equals("default")) {
- currentTPSLimit = 20;
- sendNewTPSLimitMessage();
- tpsLimiter();
- return false;
- }
-
- try {
- double tpsLimitDouble = Double.parseDouble(tpsLimit.replace(',', '.'));
- if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSUtils.isWarpAllowed() ? 40 : 20)) {
- sendInvalidArgumentMessage(player);
- return false;
- }
- currentTPSLimit = tpsLimitDouble;
- sendNewTPSLimitMessage();
- tpsLimiter();
- } catch (NumberFormatException e) {
- sendInvalidArgumentMessage(player);
- }
-
- return false;
- }
-
private void sendNewTPSLimitMessage() {
Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§eTPS limit auf " + currentTPSLimit + " gesetzt.")));
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java
deleted file mode 100644
index cfd10a1..0000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTPSLimiterTabComplete.java
+++ /dev/null
@@ -1,51 +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.TPSUtils;
-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 CommandTPSLimiterTabComplete implements TabCompleter {
-
- private List arguments = new ArrayList<>(Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"));
-
- public CommandTPSLimiterTabComplete() {
- if (TPSUtils.isWarpAllowed())
- arguments.addAll(Arrays.asList("21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"));
- }
-
- @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/de/steamwar/bausystem/commands/CommandTeleport.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTeleport.java
index 27f37e9..769da8f 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTeleport.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTeleport.java
@@ -1,81 +1,56 @@
-/*
- 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 .
-*/
+/*
+ * 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.BauSystem;
+import de.steamwar.command.SWCommand;
import de.steamwar.sql.BauweltMember;
-import org.apache.commons.lang.Validate;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
-import java.util.List;
+public class CommandTeleport extends SWCommand {
-public class CommandTeleport extends BukkitCommand {
public CommandTeleport() {
- super("tp");
- description = "Teleportiert dich zu einem genannten Spieler.";
- usageMessage = "/tp [Spieler]";
+ super("teleport", "tp");
}
- public boolean execute(CommandSender sender, String currentAlias, String[] args) {
- if (!(sender instanceof Player))
- return false;
- else if (args.length != 1) {
- sender.sendMessage(BauSystem.PREFIX + usageMessage);
- return false;
- }
-
- Player p = (Player) sender;
-
- Player target = Bukkit.getPlayerExact(args[0]);
-
- if (target == null) {
- p.sendMessage(BauSystem.PREFIX + "§cDieser Spieler ist derzeit offline.");
- return true;
- }
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§etp §8[§7Player§8] §8- §7Teleportiere dich zu einem Spieler");
+ }
+ @Register
+ public void genericCommand(Player p, Player target) {
if (p.getUniqueId().equals(target.getUniqueId())) {
p.sendMessage(BauSystem.PREFIX + "§cSei eins mit dir selbst!");
- return false;
+ return;
}
if (!BauSystem.getOwner().equals(p.getUniqueId())) {
BauweltMember member = BauweltMember.getBauMember(BauSystem.getOwner(), p.getUniqueId());
if (member == null || !member.isBuild()) {
p.sendMessage(BauSystem.PREFIX + "§cDu darfst dich auf dieser Welt nicht teleportieren!");
- return false;
+ return;
}
}
p.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND);
- return true;
}
-
- public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
- Validate.notNull(sender, "Sender cannot be null");
- Validate.notNull(args, "Arguments cannot be null");
- Validate.notNull(alias, "Alias cannot be null");
-
- return super.tabComplete(sender, alias, args);
- }
-}
+}
\ No newline at end of file
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java
index ce431a7..a340d02 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java
@@ -23,48 +23,73 @@ 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 CommandTestblock implements CommandExecutor {
+public class CommandTestblock 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 CommandTestblock() {
+ super("testblock", "tb");
+ }
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§etestblock §8- §7Setzte den Testblock zurück");
+ p.sendMessage("§8/§etestblock §8[§7Schematic§8] §8- §7Setzte den Testblock mit einer Schematic zurück");
+ }
+
+ @Register
+ public void genericTestblockCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ Region region = regionCheck(p);
+ if (region == null) return;
+ try {
+ region.resetTestblock(null);
+ p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
+ } catch (IOException e) {
+ p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");
+ Bukkit.getLogger().log(Level.WARNING, "Failed testblock", 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.resetTestblock(null);
+ p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
+ } catch (IOException e) {
+ p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");
+ Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
+ }
+ }
+
+ private boolean permissionCheck(Player player) {
if (Welt.noPermission(player, Permission.worldedit)) {
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Testblock zurücksetzen");
return false;
}
+ return true;
+ }
+ private Region regionCheck(Player player) {
Region region = Region.getRegion(player.getLocation());
if (!region.hasTestblock()) {
player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner 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.resetTestblock(schem);
- player.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
- } catch (Exception e) {
- player.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");
- Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
- }
- return false;
+ return region;
}
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTime.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTime.java
index 425658f..ce07c8a 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTime.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTime.java
@@ -1,67 +1,99 @@
-/*
- 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 .
-*/
+/*
+ * 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.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Welt;
+import de.steamwar.command.SWCommand;
+import de.steamwar.command.SWCommandUtils;
+import de.steamwar.command.TypeMapper;
+import java.util.Arrays;
+import java.util.List;
import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
-public class CommandTime extends BukkitCommand {
+public class CommandTime extends SWCommand {
+
+ private static List tabCompletions = Arrays.asList("0", "6000", "12000", "18000");
public CommandTime() {
super("time");
- this.description = "Ändert die Zeit auf der Spielwelt";
- this.usageMessage = "/time ";
}
- public boolean execute(CommandSender sender, String currentAlias, String[] args) {
- if (!(sender instanceof Player)) {
- return false;
- } else if (args.length == 0) {
- sender.sendMessage(BauSystem.PREFIX + this.usageMessage);
- return false;
- }
- Player player = (Player) sender;
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§etime §8<§7Zeit 0=Morgen§8, §76000=Mittag§8, §718000=Mitternacht§8> §8- §7Setzt die Zeit auf dem Bau");
+ }
- if (Welt.noPermission(player, Permission.world)) {
- player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht die Zeit ändern");
- return false;
- }
-
- int time;
- try {
- time = Integer.valueOf(args[0]);
- } catch (NumberFormatException e) {
- player.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Zahl zwischen 0 und 24000 an");
- return false;
+ @Register
+ public void genericCommand(Player p, int time) {
+ if (Welt.noPermission(p, Permission.world)) {
+ p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht die Zeit ändern");
+ return;
}
if (time < 0 || time > 24000) {
- player.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Zahl zwischen 0 und 24000 an");
- return false;
+ p.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Zahl zwischen 0 und 24000 an");
+ return;
+ }
+ Bukkit.getWorlds().get(0).setTime(time);
+ }
+
+ @Register
+ public void genericCommand(Player p, Time time) {
+ if (Welt.noPermission(p, Permission.world)) {
+ p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht die Zeit ändern");
+ return;
+ }
+ Bukkit.getWorlds().get(0).setTime(time.getValue());
+ }
+
+ @ClassMapper(value = int.class, local = true)
+ public TypeMapper doubleTypeMapper() {
+ return SWCommandUtils.createMapper(s -> {
+ try {
+ return Integer.parseInt(s);
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }, s -> tabCompletions);
+ }
+
+ public enum Time {
+ NIGHT(18000),
+ DAY(6000),
+ DAWN(0),
+ SUNSET(12000),
+ NACHT(18000),
+ TAG(6000),
+ MORGEN(0),
+ ABEND(12000);
+
+ private int value;
+
+ private Time(int value) {
+ this.value = value;
}
- Bukkit.getWorlds().get(0).setTime(time);
- return false;
+ public int getValue() {
+ return value;
+ }
}
-}
+}
\ No newline at end of file
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java
index 529a118..fc32547 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java
@@ -24,30 +24,102 @@ import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.gui.GuiTraceShow;
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.tracer.show.ShowModeParameter;
-import de.steamwar.bausystem.tracer.show.StoredRecords;
+import de.steamwar.bausystem.tracer.show.ShowModeParameterType;
import de.steamwar.bausystem.tracer.show.TraceShowManager;
import de.steamwar.bausystem.tracer.show.mode.EntityShowMode;
import de.steamwar.bausystem.world.Welt;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
+import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
-public class CommandTrace implements CommandExecutor {
+public class CommandTrace extends SWCommand {
- private void help(Player player) {
- player.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen");
- player.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer");
- player.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart");
- player.sendMessage("§8/§etrace show gui §8- §7Zeigt die Trace show gui");
- player.sendMessage("§8/§etrace show §8<§edefault§8|§eadvanced§8> §8<§e-water§8|§e-interpolate-xz§8|§e-interpolate-y§8> §8- §7Zeigt alle TNT-Positionen");
- player.sendMessage("§8/§etrace hide §8- §7Versteckt alle TNT-Positionen");
- player.sendMessage("§8/§etrace delete §8- §7Löscht alle TNT-Positionen");
- // player.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf");
- // player.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an");
- // player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]");
+ public CommandTrace() {
+ super("trace");
}
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen");
+ p.sendMessage("§8/§etrace stop §8- §7Stoppt den TNT-Tracer");
+ p.sendMessage("§8/§etrace toggleauto §8- §7Automatischer Aufnahmenstart");
+ p.sendMessage("§8/§etrace show gui §8- §7Zeigt die Trace show gui");
+ p.sendMessage("§8/§etrace show §8<§e-water§8|§e-interpolate-xz§8|§e-interpolate-y§8> §8- §7Zeigt alle TNT-Positionen");
+ p.sendMessage("§8/§etrace hide §8- §7Versteckt alle TNT-Positionen");
+ p.sendMessage("§8/§etrace delete §8- §7Löscht alle TNT-Positionen");
+ // p.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf");
+ // p.sendMessage("§8/§etrace gui §8- §7Zeigt die Trace Oberfläche an");
+ // p.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]");
+ }
+
+ @Register({"start"})
+ public void startCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ RecordStateMachine.commandStart();
+ p.sendMessage(BauSystem.PREFIX + "§aTNT-Tracer gestartet");
+ }
+
+ @Register({"stop"})
+ public void stopCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ RecordStateMachine.commandStop();
+ p.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
+ }
+
+ @Register({"toggleauto"})
+ public void toggleAutoCommand(Player p) {
+ autoCommand(p);
+ }
+
+ @Register({"auto"})
+ public void autoCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ RecordStateMachine.commandAuto();
+ p.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getAutoMessage());
+ }
+
+ @Register({"clear"})
+ public void clearCommand(Player p) {
+ deleteCommand(p);
+ }
+
+ @Register({"delete"})
+ public void deleteCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ p.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
+ }
+
+ @Register({"show"})
+ public void showCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ TraceShowManager.show(p, new EntityShowMode(p, new ShowModeParameter()));
+ p.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
+ }
+
+ @Register({"show"})
+ public void showCommand(Player p, ShowModeParameterType... showModeParameterTypes) {
+ if (!permissionCheck(p)) return;
+ ShowModeParameter showModeParameter = new ShowModeParameter();
+ for (ShowModeParameterType showModeParameterType : showModeParameterTypes) {
+ showModeParameterType.getShowModeParameterConsumer().accept(showModeParameter);
+ }
+ TraceShowManager.show(p, new EntityShowMode(p, new ShowModeParameter()));
+ p.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
+ }
+
+ @Register({"show", "gui"})
+ public void showGuiCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ GuiTraceShow.openGui(p);
+ }
+
+ @Register({"hide"})
+ public void hideCommand(Player p) {
+ if (!permissionCheck(p)) return;
+ TraceShowManager.hide(p);
+ p.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen ausgeblendet");
+ }
+
+
private boolean permissionCheck(Player player) {
if (Welt.noPermission(player, Permission.world)) {
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TNT-Tracer nutzen");
@@ -55,61 +127,4 @@ public class CommandTrace implements CommandExecutor {
}
return true;
}
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player)) return false;
- Player player = (Player) sender;
-
- if (args.length == 0) {
- help(player);
- return false;
- }
-
- if (!permissionCheck(player)) return false;
-
- switch (args[0].toLowerCase()) {
- case "start":
- RecordStateMachine.commandStart();
- player.sendMessage(BauSystem.PREFIX + "§aTNT-Tracer gestartet");
- break;
- case "stop":
- RecordStateMachine.commandStop();
- player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer gestoppt");
- break;
- case "toggleauto":
- case "auto":
- RecordStateMachine.commandAuto();
- player.sendMessage(BauSystem.PREFIX + RecordStateMachine.getRecordStatus().getAutoMessage());
- break;
- case "clear":
- case "delete":
- StoredRecords.clear();
- player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen gelöscht");
- break;
- case "show":
- if (args.length < 2) {
- TraceShowManager.show(player, new EntityShowMode(player, new ShowModeParameter()));
- } else {
- if (args[1].equalsIgnoreCase("gui")) {
- GuiTraceShow.openGui(player);
- return false;
- }
- ShowModeParameter showModeParameter = ShowModeParameter.parseArguments(args, 1);
- TraceShowManager.show(player, new EntityShowMode(player, showModeParameter));
- }
- player.sendMessage(BauSystem.PREFIX + "§aAlle TNT-Positionen angezeigt");
- break;
- case "hide":
- TraceShowManager.hide(player);
- player.sendMessage(BauSystem.PREFIX + "§cAlle TNT-Positionen ausgeblendet");
- break;
- case "list":
- case "gui":
- break;
- default:
- help(player);
- }
- return false;
- }
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java
deleted file mode 100644
index 3ad0680..0000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java
+++ /dev/null
@@ -1,81 +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.tracer.record.RecordStateMachine;
-import de.steamwar.bausystem.tracer.record.RecordStatus;
-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;
-import java.util.function.BiPredicate;
-
-public class CommandTraceTabCompleter implements TabCompleter {
-
- private static List tabCompletes = new ArrayList<>();
-
- static {
- tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO), "start"));
- tabCompletes.add(new TabComplete((player, args) -> args.length == 1 && (RecordStateMachine.getRecordStatus() != RecordStatus.IDLE && RecordStateMachine.getRecordStatus() != RecordStatus.IDLE_AUTO), "stop"));
- tabCompletes.add(new TabComplete((player, args) -> args.length == 1, "toggleauto", "auto", "show", "hide", "delete", "clear"));
- tabCompletes.add(new TabComplete((player, args) -> args.length == 2 && args[0].equalsIgnoreCase("show"), "gui", "-interpolate-xz", "-interpolate-y", "-water", "-advanced", "advanced"));
- tabCompletes.add(new TabComplete((player, args) -> args.length > 2 && args[0].equalsIgnoreCase("show") && !args[1].equalsIgnoreCase("gui"), "-interpolate-xz", "-interpolate-y", "-water", "-advanced"));
- }
-
- @Override
- public List onTabComplete(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player)) return new ArrayList<>();
- return tracerTabComplete((Player) sender, args);
- }
-
- private List tracerTabComplete(Player player, java.lang.String[] args) {
- List tabComplete = new ArrayList<>();
- for (TabComplete tab : tabCompletes) {
- if (tab.test(player, args)) tabComplete.addAll(Arrays.asList(tab.getTabCompletes()));
- }
- return SWUtils.manageList(tabComplete, args);
- }
-
- private static class TabComplete {
-
- private BiPredicate function;
- private String[] tabCompletes;
-
- private TabComplete(BiPredicate function, String... tabCompletes) {
- this.function = function;
- this.tabCompletes = tabCompletes;
- }
-
- public boolean test(Player player, String[] args) {
- return function.test(player, args);
- }
-
- public String[] getTabCompletes() {
- return tabCompletes;
- }
-
- }
-
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandWorldSpawn.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandWorldSpawn.java
new file mode 100644
index 0000000..2f9c134
--- /dev/null
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandWorldSpawn.java
@@ -0,0 +1,45 @@
+/*
+ * 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.command.SWCommand;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerTeleportEvent;
+
+public class CommandWorldSpawn extends SWCommand {
+
+ private World world = Bukkit.getWorlds().get(0);
+
+ public CommandWorldSpawn() {
+ super("worldspawn");
+ }
+
+ @Register(help = true)
+ public void genericHelp(Player p, String... args) {
+ p.sendMessage("§8/§eworldspawn §8- §7Teleportiere dich zum Spawn");
+ }
+
+ @Register
+ public void genericCommand(Player p) {
+ p.teleport(world.getSpawnLocation(), PlayerTeleportEvent.TeleportCause.COMMAND);
+ }
+}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java
deleted file mode 100644
index 5b8c549..0000000
--- a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionToggleCommand.java
+++ /dev/null
@@ -1,82 +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.BauSystem;
-import de.steamwar.bausystem.Permission;
-import de.steamwar.bausystem.world.Region;
-import de.steamwar.bausystem.world.Welt;
-import net.md_5.bungee.api.ChatMessageType;
-import net.md_5.bungee.api.chat.TextComponent;
-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.Listener;
-
-public abstract class RegionToggleCommand implements CommandExecutor, Listener {
-
- public RegionToggleCommand() {
- Bukkit.getPluginManager().registerEvents(this, BauSystem.getPlugin());
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (!(sender instanceof Player))
- return false;
- Player player = (Player) sender;
-
- if (Welt.noPermission(player, Permission.world)) {
- player.sendMessage(BauSystem.PREFIX + getNoPermMessage());
- return false;
- }
-
- Region region = Region.getRegion(player.getLocation());
- if (toggle(region)) {
- actionBar(region, getEnableMessage());
- } else {
- actionBar(region, getDisableMessage());
- }
- return false;
- }
-
- public static void actionBar(Region region, String s) {
- if (Region.GlobalRegion.isGlobalRegion(region)) {
- Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
- } else {
- Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
- }
- }
-
- abstract String getNoPermMessage();
-
- abstract String getEnableMessage();
-
- abstract String getDisableMessage();
-
- /**
- * {@code true} for {@link #getEnableMessage()}, {@code false} for {@link #getDisableMessage()}
- */
- abstract boolean toggle(Region region);
-
-}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java
new file mode 100644
index 0000000..24dcedd
--- /dev/null
+++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/RegionUtils.java
@@ -0,0 +1,37 @@
+/*
+ * 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.world.Region;
+import net.md_5.bungee.api.ChatMessageType;
+import net.md_5.bungee.api.chat.TextComponent;
+import org.bukkit.Bukkit;
+
+public class RegionUtils {
+
+ public static void actionBar(Region region, String s) {
+ if (Region.GlobalRegion.isGlobalRegion(region)) {
+ Bukkit.getOnlinePlayers().stream().filter(player -> Region.getRegion(player.getLocation()) == null).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
+ } else {
+ Bukkit.getOnlinePlayers().stream().filter(player -> region.inRegion(player.getLocation())).forEach(player -> player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(s)));
+ }
+ }
+
+}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java
index 7c4722d..ba67f71 100644
--- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java
+++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameter.java
@@ -54,49 +54,4 @@ public class ShowModeParameter {
public void setInterpolate_XZ(boolean interpolate_XZ) {
this.interpolate_XZ = interpolate_XZ;
}
-
- public boolean isAdvanced() {
- return interpolate_Y || interpolate_XZ;
- }
-
- public static ShowModeParameter parseArguments(String[] args, int index) {
- ShowModeParameter showModeParameter = new ShowModeParameter();
- for (int i = index; i < args.length; i++) {
- switch (args[i].toLowerCase()) {
- case "-water":
- showModeParameter.water = true;
- break;
- case "-interpolatey":
- case "-interpolate-y":
- case "-interpolate_y":
- case "-y":
- showModeParameter.interpolate_Y = true;
- break;
- case "-interpolatex":
- case "-interpolate-x":
- case "-interpolate_x":
- case "-x":
- case "-interpolatez":
- case "-interpolate-z":
- case "-interpolate_z":
- case "-z":
- case "-interpolatexz":
- case "-interpolate-xz":
- case "-interpolate_xz":
- case "-xz":
- showModeParameter.interpolate_XZ = true;
- break;
- case "advanced":
- case "-advanced":
- case "-a":
- showModeParameter.interpolate_Y = true;
- showModeParameter.interpolate_XZ = true;
- break;
- default:
- break;
- }
- }
- return showModeParameter;
- }
-
}
diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameterType.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameterType.java
new file mode 100644
index 0000000..5cb046c
--- /dev/null
+++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/ShowModeParameterType.java
@@ -0,0 +1,44 @@
+/*
+ * 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.tracer.show;
+
+import java.util.function.Consumer;
+
+public enum ShowModeParameterType {
+
+ WATER(showModeParameter -> showModeParameter.setWater(true)),
+ INTERPOLATE_Y(showModeParameter -> showModeParameter.setInterpolate_Y(true)),
+ INTERPOLATE_XZ(showModeParameter -> showModeParameter.setInterpolate_XZ(true)),
+ ADVANCED(showModeParameter -> {
+ showModeParameter.setInterpolate_Y(true);
+ showModeParameter.setInterpolate_XZ(true);
+ });
+
+ private final Consumer showModeParameterConsumer;
+
+ public Consumer getShowModeParameterConsumer() {
+ return showModeParameterConsumer;
+ }
+
+ ShowModeParameterType(Consumer showModeParameterConsumer) {
+ this.showModeParameterConsumer = showModeParameterConsumer;
+ }
+
+}
diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml
index dd285ac..ac778a3 100644
--- a/BauSystem_Main/src/plugin.yml
+++ b/BauSystem_Main/src/plugin.yml
@@ -1,5 +1,5 @@
name: BauSystem
-authors: [Lixfel, YoyoNow, Chaoscaot]
+authors: [Lixfel, YoyoNow, Chaoscaot, Zeanon]
version: "1.0"
depend: [WorldEdit, SpigotCore, ProtocolLib]
load: POSTWORLD
@@ -9,36 +9,3 @@ website: "https://steamwar.de"
description: "So unseriös wie wir sind: BauSystem nur besser."
commands:
- debugstick:
- tnt:
- fire:
- trace:
- tpslimit:
- testblock:
- aliases: tb
- reset:
- bau:
- aliases:
- - gs
- - b
- protect:
- bauinfo:
- speed:
- skull:
- freeze:
- aliases: stoplag
- loader:
- nightvision:
- aliases: nv
- watervision:
- aliases: wv
- lockschem:
- detonator:
- aliases: dt
- script:
- scriptvars:
- simulator:
- aliases: sim
- gui:
- redstonetester:
- aliases: rt
\ No newline at end of file