From b21247aff09cc690977fbb636ea45d67770416d0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 22 May 2020 11:50:26 +0200 Subject: [PATCH] Enables checking with the ranksystem Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../bungeecore/commands/CheckCommand.java | 46 +++++++++++++++---- src/de/steamwar/bungeecore/sql/Schematic.java | 4 ++ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 0eb04ce..85d43d7 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -199,6 +199,7 @@ public class BungeeCore extends Plugin { Broadcaster.setBroadCastMsgs(config.getStringList("broadcasts").toArray(new String[1])); PollSystem.init(config.getString("poll.question"), config.getStringList("poll.answers")); CheckCommand.loadCheckQuestions(config.getSection("checkquestions")); + CheckCommand.loadRanks(config.getSection("checkranks")); Persistent.setChatPrefix(CHAT_PREFIX); Persistent.setLobbyServer(LOBBY_SERVER); diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index a1ca681..a1e79ed 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -22,6 +22,7 @@ import java.util.logging.Level; public class CheckCommand extends BasicCommand { private static Map> checkQuestions = new HashMap<>(); + private static Map> ranks = new HashMap<>(); private static Map currentCheckers = new HashMap<>(); private static Map currentSchems = new HashMap<>(); @@ -32,6 +33,12 @@ public class CheckCommand extends BasicCommand { } } + public static void loadRanks(Configuration config){ + for(String schemType : config.getKeys()){ + ranks.put(SchematicType.fromDB(schemType), config.getStringList(schemType)); + } + } + public static boolean isChecking(ProxiedPlayer player){ return currentCheckers.containsKey(player); } @@ -41,7 +48,7 @@ public class CheckCommand extends BasicCommand { ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { List schematics = getSchemsToCheck(); - if(schematics.size() > 0) + if(!schematics.isEmpty()) ServerTeamchatCommand.sendToTeam("§7Es sind §e" + schematics.size() + " §7Schematics zu prüfen§8!"); }, 10, 10, TimeUnit.MINUTES); } @@ -66,7 +73,7 @@ public class CheckCommand extends BasicCommand { break; case "next": case "allow": - next(player); + next(player, args); break; case "cancel": abort(player); @@ -136,11 +143,21 @@ public class CheckCommand extends BasicCommand { return false; } - private void next(ProxiedPlayer player){ + private void next(ProxiedPlayer player, String[] args){ if(notChecking(player)) return; - currentCheckers.get(player).next(); + int rank = 0; + if(args.length > 1){ + try{ + rank = Integer.parseInt(args[1]); + }catch(NumberFormatException e){ + BungeeCore.send(player, "Der angegebene Rang ist ungültig!"); + return; + } + } + + currentCheckers.get(player).next(rank); } public static void abort(ProxiedPlayer player){ @@ -199,13 +216,13 @@ public class CheckCommand extends BasicCommand { SubserverSystem.sendToTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getSchemID()); currentCheckers.put(checker, this); currentSchems.put(schematic.getSchemID(), this); - next(); + next(0); }); } - private void next() { + private void next(int rank) { if(!checkList.hasNext()){ - accept(); + accept(rank); return; } @@ -215,6 +232,11 @@ public class CheckCommand extends BasicCommand { if(checkList.hasNext()){ next = new TextComponent("next "); next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next")); + }else if(ranks.containsKey(schematic.getSchemType())){ + next = new TextComponent(); + List r = ranks.get(schematic.getSchemType()); + for(int i = 0; i < r.size(); i++) + BungeeCore.send(checker, "Rang " + i + ": " + r.get(i), "§aMit diesem Rang freigeben", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check allow " + i)); }else{ next = new TextComponent("accept "); next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check allow")); @@ -229,7 +251,15 @@ public class CheckCommand extends BasicCommand { checker.sendMessage(next); } - private void accept(){ + private void accept(int rank){ + if(ranks.containsKey(schematic.getSchemType())){ + if(rank < 0 || ranks.get(schematic.getSchemType()).size() >= rank){ + BungeeCore.send(checker, "§cUnbekannter Schematic-Rang"); + return; + } + schematic.setRank(rank); + } + schematic.setSchemType(schematic.getSchemType().fightType()); CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(schematic.getSchemOwner()).getUuid()); diff --git a/src/de/steamwar/bungeecore/sql/Schematic.java b/src/de/steamwar/bungeecore/sql/Schematic.java index 3f2dc45..b0e3319 100644 --- a/src/de/steamwar/bungeecore/sql/Schematic.java +++ b/src/de/steamwar/bungeecore/sql/Schematic.java @@ -92,4 +92,8 @@ public class Schematic { this.schemType = schemType; SQL.update("UPDATE Schematic SET SchemType = ? WHERE SchemID = ?", schemType.toDB(), schemID); } + + public void setRank(int rank) { + SQL.update("UPDATE Schematic SET Rank = ? WHERE SchemID = ?", rank, schemID); + } }