Compare commits

..

6 Commits

Author SHA1 Message Date
YoyoNow 6522fc77f2 Improve color gradient
Pull Request Build / Build (pull_request) Successful in 1m21s
2026-06-17 11:14:53 +02:00
YoyoNow 27e01a56ae Improve CheckCommand
Pull Request Build / Build (pull_request) Successful in 1m24s
2026-06-17 11:09:32 +02:00
YoyoNow ed89770c0f Fix ConcurrentModificationException
Pull Request Build / Build (pull_request) Successful in 1m22s
2026-06-17 11:04:07 +02:00
YoyoNow 3ec3c90f04 Fix message on join
Pull Request Build / Build (pull_request) Successful in 1m22s
2026-06-17 10:57:04 +02:00
YoyoNow 73d4ed26c8 Implement CheckCommand for Checkers not having Check perm
Pull Request Build / Build (pull_request) Successful in 1m23s
2026-06-17 10:52:32 +02:00
YoyoNow 256bcfb1bf Update CheckCommand 2026-06-17 10:52:32 +02:00
5 changed files with 83 additions and 50 deletions
@@ -146,12 +146,12 @@ public final class GameModeConfig<M, W> {
public final List<String> 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<Integer> Checkers;
public final Set<Integer> Checkers;
/**
* Bundle for countdowns during the fight
@@ -246,7 +246,7 @@ public final class GameModeConfig<M, W> {
}
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"));
@@ -139,6 +139,12 @@ final class YMLWrapper<M, W> {
return get(path, o -> (List<Integer>) o);
}
public Set<Integer> getIntSet(String path) {
List<Integer> list = get(path, o -> (List<Integer>) o);
if (list.isEmpty()) return Collections.emptySet();
return Collections.unmodifiableSet(new HashSet<>(list));
}
public List<SchematicType> getSchematicTypeList(String path) {
List<String> list = getStringList(path);
if (list.isEmpty()) {
@@ -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<Chatter> {
@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;
@@ -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<SchematicNode, SteamwarUser> getSchematics(SteamwarUser user) {
Map<SchematicNode, SteamwarUser> 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<String, String> 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<SchematicNode> 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<SchematicNode, SteamwarUser> 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<SchematicNode> schematicList = getSchemsToCheck();
Map<SchematicNode, SteamwarUser> schematics = getSchematics(sender.user());
sender.system("CHECK_LIST_HEADER", schematicList.size());
sender.system("CHECK_LIST_HEADER", schematics.size());
for (SchematicNode schematic : schematicList) {
GameModeConfig<String, String> 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<SchematicNode, SteamwarUser> 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");
@@ -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)) {