Update CommandTrace to new SWCommand system
Dieser Commit ist enthalten in:
Ursprung
09ea9fd417
Commit
e03a37676d
@ -75,8 +75,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
getCommand("trace").setExecutor(new CommandTrace());
|
||||
getCommand("trace").setTabCompleter(new CommandTraceTabCompleter());
|
||||
new CommandTrace();
|
||||
getCommand("tpslimit").setExecutor(new CommandTPSLimiter());
|
||||
getCommand("tpslimit").setTabCompleter(new CommandTPSLimiterTabComplete());
|
||||
getCommand("nightvision").setExecutor(new CommandNV());
|
||||
|
73
BauSystem_Main/src/de/steamwar/bausystem/Mapper.java
Normale Datei
73
BauSystem_Main/src/de/steamwar/bausystem/Mapper.java
Normale Datei
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import de.steamwar.bausystem.tracer.show.ShowModeParameterType;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Mapper {
|
||||
|
||||
private Mapper() {
|
||||
throw new IllegalStateException("Utility Class");
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
SWCommandUtils.addMapper(ShowModeParameterType.class, showModeParameterTypesTypeMapper());
|
||||
}
|
||||
|
||||
private static TypeMapper<ShowModeParameterType> showModeParameterTypesTypeMapper() {
|
||||
Map<String, ShowModeParameterType> 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<String> tabCompletes = new ArrayList<>(showModeParameterTypesMap.keySet());
|
||||
return SWCommandUtils.createMapper(s -> showModeParameterTypesMap.getOrDefault(s, null), s -> tabCompletes);
|
||||
}
|
||||
|
||||
}
|
@ -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<§edefault§8|§eadvanced§8> §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;
|
||||
}
|
||||
}
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<TabComplete> 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<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player)) return new ArrayList<>();
|
||||
return tracerTabComplete((Player) sender, args);
|
||||
}
|
||||
|
||||
private List<String> tracerTabComplete(Player player, java.lang.String[] args) {
|
||||
List<java.lang.String> 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<Player, String[]> function;
|
||||
private String[] tabCompletes;
|
||||
|
||||
private TabComplete(BiPredicate<Player, String[]> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<ShowModeParameter> showModeParameterConsumer;
|
||||
|
||||
public Consumer<ShowModeParameter> getShowModeParameterConsumer() {
|
||||
return showModeParameterConsumer;
|
||||
}
|
||||
|
||||
ShowModeParameterType(Consumer<ShowModeParameter> showModeParameterConsumer) {
|
||||
this.showModeParameterConsumer = showModeParameterConsumer;
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,6 @@ commands:
|
||||
debugstick:
|
||||
tnt:
|
||||
fire:
|
||||
trace:
|
||||
tpslimit:
|
||||
testblock:
|
||||
aliases: tb
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren