/* 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.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import org.bukkit.entity.Player; import java.util.Arrays; import java.util.List; public class CommandSpeed extends SWCommand { public CommandSpeed() { super("speed"); } @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) { p.sendMessage(BauSystem.PREFIX + "§cBitte gib eine Zahl zwischen 0 und 10 an"); return; } p.sendMessage("§aGeschwindigkeit wurde auf §6" + speed + " §agesetzt"); p.setFlySpeed(speed / 10); p.setWalkSpeed((speed >= 9 ? speed : speed + 1) / 10); } @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); } }