From 530252d96b994278b1e31511ae2309190436e375 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Apr 2021 19:37:50 +0200 Subject: [PATCH] Update CommandSpeed to new SWCommand system --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/commands/CommandSpeed.java | 62 +++++++++++-------- BauSystem_Main/src/plugin.yml | 1 - 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 5446e42..009683f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -79,7 +79,7 @@ public class BauSystem extends JavaPlugin implements Listener { new CommandTPSLimiter(); getCommand("nightvision").setExecutor(new CommandNV()); getCommand("reset").setExecutor(new CommandReset()); - getCommand("speed").setExecutor(new CommandSpeed()); + new CommandSpeed(); new CommandTNT(); getCommand("fire").setExecutor(new CommandFire()); getCommand("freeze").setExecutor(new CommandFreeze()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSpeed.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSpeed.java index 223af4d..1a4b31a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSpeed.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSpeed.java @@ -20,40 +20,50 @@ 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(BauSystem.PREFIX + "/speed [Geschwindigkeit]"); + } + + @Register({"default"}) + public void defaultCommand(Player p) { + speedCommand(p, 1); + } + + 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/plugin.yml b/BauSystem_Main/src/plugin.yml index 4d25ab9..241c660 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -14,7 +14,6 @@ commands: reset: protect: bauinfo: - speed: skull: freeze: aliases: stoplag