forked from SteamWar/SteamWar
Implement CheckCommand for Checkers not having Check perm
This commit is contained in:
@@ -151,7 +151,7 @@ public final class GameModeConfig<M, W> {
|
||||
*
|
||||
* @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()) {
|
||||
|
||||
@@ -72,80 +72,79 @@ public class CheckCommand extends SWCommand {
|
||||
|
||||
public CheckCommand() {
|
||||
super("check");
|
||||
|
||||
VelocityCore.schedule(() -> sendReminder(Chatter.allStream())).repeat(10, TimeUnit.MINUTES).schedule();
|
||||
VelocityCore.schedule(() -> Chatter.allStream().forEach(CheckCommand::sendReminder)).repeat(10, TimeUnit.MINUTES).schedule();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasPermission(SimpleCommand.Invocation invocation) {
|
||||
return mayCheck(Chatter.of(invocation.source()).user());
|
||||
}
|
||||
|
||||
private boolean mayCheck(SteamwarUser user) {
|
||||
SteamwarUser user = Chatter.of(invocation.source()).user();
|
||||
if (user.perms().contains(UserPerm.CHECK)) return true;
|
||||
return GameModeConfig.getAll()
|
||||
.stream()
|
||||
.filter(GameModeConfig::isActive)
|
||||
.flatMap(gameMode -> gameMode.Checkers.stream())
|
||||
.anyMatch(integer -> integer == user.getId());
|
||||
.anyMatch(gameMode -> gameMode.Checkers.contains(user.getId()));
|
||||
}
|
||||
|
||||
private boolean hasThingsToCheck(SteamwarUser user) {
|
||||
return getSchemsToCheck().stream().anyMatch(schematicNode -> mayCheck(user, schematicNode));
|
||||
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());
|
||||
if (checkSession == null) {
|
||||
map.put(schematicNode, null);
|
||||
} else {
|
||||
map.put(schematicNode, checkSession.checker.user());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private boolean mayCheck(SteamwarUser user, SchematicNode schematic) {
|
||||
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());
|
||||
}
|
||||
|
||||
private boolean needsCheck(SchematicNode schematicNode) {
|
||||
return currentSchems.containsKey(schematicNode.getId());
|
||||
}
|
||||
|
||||
public static void sendReminder(Chatter chatter) {
|
||||
List<SchematicNode> schematics = getSchemsToCheck();
|
||||
if (schematics.size() == currentCheckers.size()) return;
|
||||
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"), schematics.size() - currentCheckers.size());
|
||||
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");
|
||||
}
|
||||
for (Map.Entry<SchematicNode, SteamwarUser> entry : schematics.entrySet()) {
|
||||
ClickEvent clickEvent;
|
||||
Message hoverMessage;
|
||||
if (entry.getValue() == null) {
|
||||
clickEvent = ClickEvent.runCommand("/check schematic " + entry.getKey().getId());
|
||||
hoverMessage = new Message("CHECK_LIST_TO_CHECK_HOVER");
|
||||
} else {
|
||||
clickEvent = ClickEvent.runCommand("/join " + entry.getValue().getUserName());
|
||||
hoverMessage = new Message("CHECK_LIST_CHECKING_HOVER");
|
||||
}
|
||||
|
||||
if (current == null) {
|
||||
if (entry.getValue() == null) {
|
||||
sender.prefixless("CHECK_LIST_TO_CHECK",
|
||||
hoverMessage,
|
||||
clickEvent,
|
||||
getWaitTime(schematic),
|
||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName());
|
||||
getWaitTime(entry.getKey()),
|
||||
entry.getKey().getSchemtype().getKuerzel(), SteamwarUser.byId(entry.getKey().getOwner()).getUserName(), entry.getKey().getName());
|
||||
} else {
|
||||
sender.prefixless("CHECK_LIST_CHECKING",
|
||||
hoverMessage,
|
||||
clickEvent,
|
||||
getWaitTime(schematic),
|
||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.user().getUserName());
|
||||
getWaitTime(entry.getKey()),
|
||||
entry.getKey().getSchemtype().getKuerzel(), SteamwarUser.byId(entry.getKey().getOwner()).getUserName(), entry.getKey().getName(), entry.getValue().getUserName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.velocitycore.commands;
|
||||
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CheckCommand2 extends SWCommand {
|
||||
|
||||
public CheckCommand2() {
|
||||
super("check");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasPermission(SimpleCommand.Invocation invocation) {
|
||||
return false; // TODO: Implement!
|
||||
}
|
||||
|
||||
public static List<SchematicNode> getSchemsToCheck() {
|
||||
List<SchematicNode> schematicList = new ArrayList<>();
|
||||
|
||||
for (SchematicType type : SchematicType.values()) {
|
||||
if (type.check()) {
|
||||
schematicList.addAll(SchematicNode.getAllSchematicsOfType(type));
|
||||
}
|
||||
}
|
||||
return schematicList;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user