diff --git a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java index f8b27f59..d22d8978 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java +++ b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java @@ -146,12 +146,12 @@ public final class GameModeConfig { public final List CheckQuestions; /** - * The allowed checkers to check this schematic type denoted by a list of SteamWar ids. + * The allowed checkers to check this schematic type denoted by a list of SteamwarUser ids. * The people need the {@link UserPerm#CHECK} to be able to check though. * * @implSpec {@code []} by default -> denoting every person with {@link UserPerm#CHECK} can check it */ - public final List Checkers; + public final Set Checkers; /** * Bundle for countdowns during the fight @@ -246,7 +246,7 @@ public final class GameModeConfig { } CheckQuestions = loader.getStringList("CheckQuestions"); - Checkers = loader.getIntList("Checkers"); + Checkers = loader.getIntSet("Checkers"); Times = new TimesConfig(loader.with("Times")); // Arena would be here to be in config order but needs Schematic.Size and EnterStages loaded afterwards Schematic = new SchematicConfig<>(loader.with("Schematic")); diff --git a/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java b/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java index 39eff9bb..567524ff 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java +++ b/CommonCore/SQL/src/de/steamwar/sql/YMLWrapper.java @@ -139,6 +139,12 @@ final class YMLWrapper { return get(path, o -> (List) o); } + public Set getIntSet(String path) { + List list = get(path, o -> (List) o); + if (list.isEmpty()) return Collections.emptySet(); + return Collections.unmodifiableSet(new HashSet<>(list)); + } + public List getSchematicTypeList(String path) { List list = getStringList(path); if (list.isEmpty()) { diff --git a/VelocityCore/src/de/steamwar/command/SWCommand.java b/VelocityCore/src/de/steamwar/command/SWCommand.java index 2fdf204f..e1e0c066 100644 --- a/VelocityCore/src/de/steamwar/command/SWCommand.java +++ b/VelocityCore/src/de/steamwar/command/SWCommand.java @@ -20,6 +20,7 @@ package de.steamwar.command; import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.command.SimpleCommand.Invocation; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.sql.UserPerm; @@ -91,11 +92,15 @@ public class SWCommand extends AbstractSWCommand { @Override public boolean hasPermission(Invocation invocation) { - return permission == null || Chatter.of(invocation.source()).user().perms().contains(permission); + return SWCommand.this.hasPermission(invocation); } }; } + protected boolean hasPermission(Invocation invocation) { + return permission == null || Chatter.of(invocation.source()).user().perms().contains(permission); + } + @Override public void unregister() { if (command == null) return; diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java index 637218e3..b0183aa5 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/CheckCommand.java @@ -19,6 +19,7 @@ package de.steamwar.velocitycore.commands; +import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; import de.steamwar.command.SWCommand; @@ -62,61 +63,89 @@ public class CheckCommand extends SWCommand { public static Message getWaitTime(SchematicNode schematic) { long waitedMillis = Timestamp.from(Instant.now()).getTime() - schematic.getLastUpdate().getTime(); - String ce = waitedMillis > 86400000 ? "c" : "e"; - String color = waitedMillis > 14400000 ? ce : "a"; + String color; + if (waitedMillis > 48L * 60 * 60 * 1000) color = "4"; + else if (waitedMillis > 24L * 60 * 60 * 1000) color = "c"; + else if (waitedMillis > 12L * 60 * 60 * 1000) color = "6"; + else if (waitedMillis > 4L * 60 * 60 * 1000) color = "e"; + else color = "a"; long hours = waitedMillis / 3600000; long minutes = (waitedMillis - hours * 3600000) / 60000; return new Message("CHECK_LIST_WAIT", color, hours, (minutes < 10) ? "0" + minutes : minutes); } public CheckCommand() { - super("check", UserPerm.CHECK); + super("check"); + VelocityCore.schedule(() -> Chatter.allStream().forEach(CheckCommand::sendReminder)).delay(10, TimeUnit.MINUTES).repeat(10, TimeUnit.MINUTES).schedule(); + } - VelocityCore.schedule(() -> sendReminder(Chatter.serverteam())).repeat(10, TimeUnit.MINUTES).schedule(); + @Override + protected boolean hasPermission(SimpleCommand.Invocation invocation) { + SteamwarUser user = Chatter.of(invocation.source()).user(); + if (user.perms().contains(UserPerm.CHECK)) return true; + return GameModeConfig.getAll() + .stream() + .filter(GameModeConfig::isActive) + .anyMatch(gameMode -> gameMode.Checkers.contains(user.getId())); + } + + private static Map getSchematics(SteamwarUser user) { + Map map = new HashMap<>(); + for (SchematicNode schematicNode : getSchemsToCheck()) { + if (!mayCheck(user, schematicNode)) continue; + CheckSession checkSession = currentSchems.get(schematicNode.getId()); + map.put(schematicNode, checkSession == null ? null : checkSession.checker.user()); + } + return map; + } + + private static boolean mayCheck(SteamwarUser user, SchematicNode schematic) { + GameModeConfig gameModeConfig = ArenaMode.getBySchemType(schematic.getSchemtype()); + if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults(); + if (user.hasPerm(UserPerm.ADMINISTRATION)) return true; + if (gameModeConfig.Checkers.isEmpty() && user.hasPerm(UserPerm.CHECK)) return true; + return gameModeConfig.Checkers.contains(user.getId()); } public static void sendReminder(Chatter chatter) { - List schematics = getSchemsToCheck(); - if (schematics.size() == currentCheckers.size()) return; - - chatter.system("CHECK_REMINDER", new Message("CHECK_REMINDER_HOVER"), ClickEvent.runCommand("/check list"), schematics.size() - currentCheckers.size()); + Map schematics = getSchematics(chatter.user()); + if (schematics.isEmpty()) return; + long needsChecking = schematics.entrySet().stream().filter(entry -> entry.getValue() == null).count(); + if (needsChecking == 0) return; + chatter.system("CHECK_REMINDER", new Message("CHECK_REMINDER_HOVER"), ClickEvent.runCommand("/check list"), needsChecking); } @Register(value = "list", description = "CHECK_HELP_LIST") public void list(Chatter sender) { - List schematicList = getSchemsToCheck(); + Map schematics = getSchematics(sender.user()); - sender.system("CHECK_LIST_HEADER", schematicList.size()); + sender.system("CHECK_LIST_HEADER", schematics.size()); - for (SchematicNode schematic : schematicList) { - GameModeConfig gameModeConfig = ArenaMode.getBySchemType(schematic.getSchemtype()); - if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults(); - CheckSession current = currentSchems.get(schematic.getId()); - ClickEvent clickEvent = null; - Message hoverMessage = null; - if (gameModeConfig.Checkers.isEmpty() || gameModeConfig.Checkers.contains(sender.user().getId())) { - if (current == null) { - clickEvent = ClickEvent.runCommand("/check schematic " + schematic.getId()); - hoverMessage = new Message("CHECK_LIST_TO_CHECK_HOVER"); - } else { - clickEvent = ClickEvent.runCommand("/join " + current.checker.user().getUserName()); - hoverMessage = new Message("CHECK_LIST_CHECKING_HOVER"); - } - } - - if (current == null) { - sender.prefixless("CHECK_LIST_TO_CHECK", - hoverMessage, - clickEvent, - getWaitTime(schematic), - schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName()); + for (Map.Entry entry : schematics.entrySet()) { + String message; + ClickEvent clickEvent; + Message hoverMessage; + String checker; + if (entry.getValue() == null) { + message = "CHECK_LIST_TO_CHECK"; + clickEvent = ClickEvent.runCommand("/check schematic " + entry.getKey().getId()); + hoverMessage = new Message("CHECK_LIST_TO_CHECK_HOVER"); + checker = ""; } else { - sender.prefixless("CHECK_LIST_CHECKING", - hoverMessage, - clickEvent, - getWaitTime(schematic), - schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.user().getUserName()); + message = "CHECK_LIST_CHECKING"; + clickEvent = ClickEvent.runCommand("/join " + entry.getValue().getUserName()); + hoverMessage = new Message("CHECK_LIST_CHECKING_HOVER"); + checker = entry.getValue().getUserName(); } + + sender.prefixless(message, + hoverMessage, + clickEvent, + getWaitTime(entry.getKey()), + entry.getKey().getSchemtype().getKuerzel(), + SteamwarUser.byId(entry.getKey().getOwner()).getUserName(), + entry.getKey().getName(), + checker); } } @@ -142,8 +171,7 @@ public class CheckCommand extends SWCommand { } int playerTeam = sender.user().hasPerm(UserPerm.MODERATION) ? 0 : sender.user().getTeam(); - // Ignore 795 SteamWar Team - if (playerTeam != 0 && playerTeam != 795 && SteamwarUser.byId(schem.getOwner()).getTeam() == playerTeam) { + if (playerTeam != 0 && SteamwarUser.byId(schem.getOwner()).getTeam() == playerTeam) { sender.system("CHECK_SCHEMATIC_OWN_TEAM"); return; } @@ -209,11 +237,6 @@ public class CheckCommand extends SWCommand { return schematicList; } - public static String getChecker(SchematicNode schematic) { - if (currentSchems.get(schematic.getId()) == null) return null; - return currentSchems.get(schematic.getId()).checker.user().getUserName(); - } - private static boolean notChecking(Player player) { if (!isChecking(player)) { Chatter.of(player).system("CHECK_NOT_CHECKING"); diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java index 7e39c822..021f65d0 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java @@ -84,8 +84,7 @@ public class ConnectionListener extends BasicListener { Player player = event.getPlayer(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Chatter chatter = Chatter.of(player); - - if (user.hasPerm(UserPerm.CHECK)) CheckCommand.sendReminder(chatter); + CheckCommand.sendReminder(chatter); for (Subserver subserver : Subserver.getServerList()) { if (Subserver.isArena(subserver)) {