Archiviert
1
0

Merge pull request 'Update CheckCommand' (#377) from CommandCheck into master

Reviewed-on: SteamWar/BungeeCore#377
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-06-16 13:00:46 +02:00
Commit 41f89f5f0a

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.bungeecore.sql.CheckedSchematic;
import de.steamwar.bungeecore.sql.SchematicNode; import de.steamwar.bungeecore.sql.SchematicNode;
import de.steamwar.bungeecore.sql.SchematicType; import de.steamwar.bungeecore.sql.SchematicType;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.command.SWCommand;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
@ -41,7 +42,7 @@ import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
public class CheckCommand extends BasicCommand { public class CheckCommand extends SWCommand {
private static Map<SchematicType, List<String>> checkQuestions = new HashMap<>(); private static Map<SchematicType, List<String>> checkQuestions = new HashMap<>();
private static Map<SchematicType, List<String>> ranks = new HashMap<>(); private static Map<SchematicType, List<String>> ranks = new HashMap<>();
@ -77,55 +78,8 @@ public class CheckCommand extends BasicCommand {
Message.send("CHECK_REMINDER", player, Message.parse("CHECK_REMINDER_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size()); Message.send("CHECK_REMINDER", player, Message.parse("CHECK_REMINDER_HOVER", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check list"), schematics.size() - currentCheckers.size());
} }
@Override @Register(value = "list", description = "CHECK_HELP_LIST")
public void execute(CommandSender sender, String[] args) { public void list(ProxiedPlayer player) {
if(!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
if(args.length == 0){
help(sender);
return;
}
switch(args[0].toLowerCase()){
case "list":
list(player);
break;
case "schematic":
schematic(player, args[1]);
break;
case "next":
case "accept":
next(player, args);
break;
case "cancel":
abort(player);
break;
case "decline":
decline(player, args);
break;
default:
help(player);
}
}
public static List<SchematicNode> getSchemsToCheck(){
List<SchematicNode> schematicList = new LinkedList<>();
for (SchematicType type : SchematicType.values()) {
if (type.check())
schematicList.addAll(SchematicNode.getAllSchematicsOfType(type.toDB()));
}
return schematicList;
}
public static String getChecker(SchematicNode schematic) {
if (currentSchems.get(schematic.getId()) == null) return null;
return currentSchems.get(schematic.getId()).checker.getName();
}
private void list(ProxiedPlayer player) {
List<SchematicNode> schematicList = getSchemsToCheck(); List<SchematicNode> schematicList = getSchemsToCheck();
Message.sendPrefixless("CHECK_LIST_HEADER", player, schematicList.size()); Message.sendPrefixless("CHECK_LIST_HEADER", player, schematicList.size());
@ -153,7 +107,8 @@ public class CheckCommand extends BasicCommand {
} }
} }
private void schematic(ProxiedPlayer player, String schemID){ @Register(value = "schematic", noTabComplete = true)
public void schematic(ProxiedPlayer player, String schemID) {
if(isChecking(player)){ if(isChecking(player)){
Message.send("CHECK_SCHEMATIC_ALREADY_CHECKING", player); Message.send("CHECK_SCHEMATIC_ALREADY_CHECKING", player);
return; return;
@ -171,6 +126,57 @@ public class CheckCommand extends BasicCommand {
new CheckSession(player, schem); new CheckSession(player, schem);
} }
@Register(value = "cancel", description = "CHECK_HELP_CANCEL")
@Register("abort")
public void abortCommand(ProxiedPlayer player) {
abort(player);
}
public static void abort(ProxiedPlayer player) {
if(notChecking(player))
return;
Message.send("CHECK_ABORT", player);
currentCheckers.get(player.getUniqueId()).abort();
}
@Register(value = "next", description = "CHECK_HELP_NEXT")
public void next(ProxiedPlayer player) {
next(player, new String[0]);
}
@Register(value = "accept")
public void accept(ProxiedPlayer player, @OptionalValue("") String rank) {
if (rank.equals("")) {
next(player, new String[0]);
} else {
next(player, new String[]{rank});
}
}
@Register(value = "decline", description = "CHECK_HELP_DECLINE")
public void decline(ProxiedPlayer player, String... message) {
if(notChecking(player))
return;
currentCheckers.get(player.getUniqueId()).decline(String.join(" ", message));
}
public static List<SchematicNode> getSchemsToCheck(){
List<SchematicNode> schematicList = new LinkedList<>();
for (SchematicType type : SchematicType.values()) {
if (type.check())
schematicList.addAll(SchematicNode.getAllSchematicsOfType(type.toDB()));
}
return schematicList;
}
public static String getChecker(SchematicNode schematic) {
if (currentSchems.get(schematic.getId()) == null) return null;
return currentSchems.get(schematic.getId()).checker.getName();
}
private static boolean notChecking(ProxiedPlayer player){ private static boolean notChecking(ProxiedPlayer player){
if(!isChecking(player)){ if(!isChecking(player)){
Message.send("CHECK_NOT_CHECKING", player); Message.send("CHECK_NOT_CHECKING", player);
@ -184,9 +190,9 @@ public class CheckCommand extends BasicCommand {
return; return;
int rank = 0; int rank = 0;
if(args.length > 1){ if(args.length > 0){
try{ try{
rank = Integer.parseInt(args[1]); rank = Integer.parseInt(args[0]);
}catch(NumberFormatException e){ }catch(NumberFormatException e){
Message.send("CHECK_INVALID_RANK", player); Message.send("CHECK_INVALID_RANK", player);
return; return;
@ -196,37 +202,6 @@ public class CheckCommand extends BasicCommand {
currentCheckers.get(player.getUniqueId()).next(rank); currentCheckers.get(player.getUniqueId()).next(rank);
} }
public static void abort(ProxiedPlayer player){
if(notChecking(player))
return;
Message.send("CHECK_ABORT", player);
currentCheckers.get(player.getUniqueId()).abort();
}
private void decline(ProxiedPlayer player, String[] args){
if(notChecking(player))
return;
if(args.length < 2) {
help(player);
return;
}
StringBuilder message = new StringBuilder();
for (int i = 1; i < args.length; i++)
message.append(args[i]).append(" ");
currentCheckers.get(player.getUniqueId()).decline(message.toString());
}
private void help(CommandSender sender){
Message.sendPrefixless("CHECK_HELP_LIST", sender);
Message.sendPrefixless("CHECK_HELP_NEXT", sender);
Message.sendPrefixless("CHECK_HELP_DECLINE", sender);
Message.sendPrefixless("CHECK_HELP_CANCEL", sender);
}
private static class CheckSession{ private static class CheckSession{
private final ProxiedPlayer checker; private final ProxiedPlayer checker;
private final SchematicNode schematic; private final SchematicNode schematic;