Update CommandTPSLimiter to new SWCommand system
Dieser Commit ist enthalten in:
Ursprung
e03a37676d
Commit
64b7814dd5
@ -76,8 +76,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new CommandTrace();
|
new CommandTrace();
|
||||||
getCommand("tpslimit").setExecutor(new CommandTPSLimiter());
|
new CommandTPSLimiter();
|
||||||
getCommand("tpslimit").setTabCompleter(new CommandTPSLimiterTabComplete());
|
|
||||||
getCommand("nightvision").setExecutor(new CommandNV());
|
getCommand("nightvision").setExecutor(new CommandNV());
|
||||||
getCommand("reset").setExecutor(new CommandReset());
|
getCommand("reset").setExecutor(new CommandReset());
|
||||||
getCommand("speed").setExecutor(new CommandSpeed());
|
getCommand("speed").setExecutor(new CommandSpeed());
|
||||||
|
@ -23,18 +23,22 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.world.TPSUtils;
|
import de.steamwar.bausystem.world.TPSUtils;
|
||||||
import de.steamwar.bausystem.world.Welt;
|
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 de.steamwar.core.VersionedRunnable;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
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.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
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 final World WORLD = Bukkit.getWorlds().get(0);
|
||||||
private static double currentTPSLimit = 20;
|
private static double currentTPSLimit = 20;
|
||||||
@ -48,6 +52,56 @@ public class CommandTPSLimiter implements CommandExecutor {
|
|||||||
|
|
||||||
private BukkitTask tpsLimiter = null;
|
private BukkitTask tpsLimiter = null;
|
||||||
|
|
||||||
|
private List<String> arguments = new ArrayList<>(Arrays.asList("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()) {
|
||||||
|
arguments.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(BauSystem.PREFIX + "Ändere das TPS limit mit: §8/§etpslimit §8[§7TPS§8|§edefault§8]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register({"default"})
|
||||||
|
public void defaultCommand(Player p) {
|
||||||
|
if (!permissionCheck(p)) return;
|
||||||
|
currentTPSLimit = 20;
|
||||||
|
sendNewTPSLimitMessage();
|
||||||
|
tpsLimiter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
|
public void valueCommand(Player p, String tpsLimit) {
|
||||||
|
try {
|
||||||
|
double tpsLimitDouble = Double.parseDouble(tpsLimit.replace(',', '.'));
|
||||||
|
if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSUtils.isWarpAllowed() ? 40 : 20)) {
|
||||||
|
sendInvalidArgumentMessage(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentTPSLimit = tpsLimitDouble;
|
||||||
|
sendNewTPSLimitMessage();
|
||||||
|
tpsLimiter();
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
sendInvalidArgumentMessage(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ClassMapper(value = double.class, local = true)
|
||||||
|
public TypeMapper<Double> doubleTypeMapper() {
|
||||||
|
return SWCommandUtils.createMapper(s -> {
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(s.replace(',', '.'));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, s -> arguments);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean permissionCheck(Player player) {
|
private boolean permissionCheck(Player player) {
|
||||||
if (Welt.noPermission(player, Permission.world)) {
|
if (Welt.noPermission(player, Permission.world)) {
|
||||||
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TPS-Limiter nutzen");
|
player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den TPS-Limiter nutzen");
|
||||||
@ -56,42 +110,6 @@ public class CommandTPSLimiter implements CommandExecutor {
|
|||||||
return true;
|
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() {
|
private void sendNewTPSLimitMessage() {
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§eTPS limit auf " + currentTPSLimit + " gesetzt.")));
|
Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§eTPS limit auf " + currentTPSLimit + " gesetzt.")));
|
||||||
}
|
}
|
||||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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<String> 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<String> 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -12,7 +12,6 @@ commands:
|
|||||||
debugstick:
|
debugstick:
|
||||||
tnt:
|
tnt:
|
||||||
fire:
|
fire:
|
||||||
tpslimit:
|
|
||||||
testblock:
|
testblock:
|
||||||
aliases: tb
|
aliases: tb
|
||||||
reset:
|
reset:
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren