forked from SteamWar/SteamWar
Merge pull request 'VelocityCore /check command' (#430) from VelocityCore/CheckCommand into main
Reviewed-on: SteamWar/SteamWar#430 Reviewed-by: D4rkr34lm <dark@steamwar.de>
This commit is contained in:
@@ -146,12 +146,12 @@ public final class GameModeConfig<M, W> {
|
|||||||
public final List<String> CheckQuestions;
|
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.
|
* 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
|
* @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
|
* Bundle for countdowns during the fight
|
||||||
@@ -246,7 +246,7 @@ public final class GameModeConfig<M, W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CheckQuestions = loader.getStringList("CheckQuestions");
|
CheckQuestions = loader.getStringList("CheckQuestions");
|
||||||
Checkers = loader.getIntList("Checkers");
|
Checkers = loader.getIntSet("Checkers");
|
||||||
Times = new TimesConfig(loader.with("Times"));
|
Times = new TimesConfig(loader.with("Times"));
|
||||||
// Arena would be here to be in config order but needs Schematic.Size and EnterStages loaded afterwards
|
// Arena would be here to be in config order but needs Schematic.Size and EnterStages loaded afterwards
|
||||||
Schematic = new SchematicConfig<>(loader.with("Schematic"));
|
Schematic = new SchematicConfig<>(loader.with("Schematic"));
|
||||||
|
|||||||
@@ -139,6 +139,12 @@ final class YMLWrapper<M, W> {
|
|||||||
return get(path, o -> (List<Integer>) o);
|
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) {
|
public List<SchematicType> getSchematicTypeList(String path) {
|
||||||
List<String> list = getStringList(path);
|
List<String> list = getStringList(path);
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.command;
|
package de.steamwar.command;
|
||||||
|
|
||||||
import com.velocitypowered.api.command.SimpleCommand;
|
import com.velocitypowered.api.command.SimpleCommand;
|
||||||
|
import com.velocitypowered.api.command.SimpleCommand.Invocation;
|
||||||
import de.steamwar.messages.Chatter;
|
import de.steamwar.messages.Chatter;
|
||||||
import de.steamwar.messages.Message;
|
import de.steamwar.messages.Message;
|
||||||
import de.steamwar.sql.UserPerm;
|
import de.steamwar.sql.UserPerm;
|
||||||
@@ -91,11 +92,15 @@ public class SWCommand extends AbstractSWCommand<Chatter> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(Invocation invocation) {
|
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
|
@Override
|
||||||
public void unregister() {
|
public void unregister() {
|
||||||
if (command == null) return;
|
if (command == null) return;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.velocitycore.commands;
|
package de.steamwar.velocitycore.commands;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.command.SimpleCommand;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
@@ -62,61 +63,89 @@ public class CheckCommand extends SWCommand {
|
|||||||
|
|
||||||
public static Message getWaitTime(SchematicNode schematic) {
|
public static Message getWaitTime(SchematicNode schematic) {
|
||||||
long waitedMillis = Timestamp.from(Instant.now()).getTime() - schematic.getLastUpdate().getTime();
|
long waitedMillis = Timestamp.from(Instant.now()).getTime() - schematic.getLastUpdate().getTime();
|
||||||
String ce = waitedMillis > 86400000 ? "c" : "e";
|
String color;
|
||||||
String color = waitedMillis > 14400000 ? ce : "a";
|
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 hours = waitedMillis / 3600000;
|
||||||
long minutes = (waitedMillis - hours * 3600000) / 60000;
|
long minutes = (waitedMillis - hours * 3600000) / 60000;
|
||||||
return new Message("CHECK_LIST_WAIT", color, hours, (minutes < 10) ? "0" + minutes : minutes);
|
return new Message("CHECK_LIST_WAIT", color, hours, (minutes < 10) ? "0" + minutes : minutes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CheckCommand() {
|
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) {
|
public static void sendReminder(Chatter chatter) {
|
||||||
List<SchematicNode> schematics = getSchemsToCheck();
|
Map<SchematicNode, SteamwarUser> schematics = getSchematics(chatter.user());
|
||||||
if (schematics.size() == currentCheckers.size()) return;
|
if (schematics.isEmpty()) return;
|
||||||
|
long needsChecking = schematics.entrySet().stream().filter(entry -> entry.getValue() == null).count();
|
||||||
chatter.system("CHECK_REMINDER", new Message("CHECK_REMINDER_HOVER"), ClickEvent.runCommand("/check list"), schematics.size() - currentCheckers.size());
|
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")
|
@Register(value = "list", description = "CHECK_HELP_LIST")
|
||||||
public void list(Chatter sender) {
|
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) {
|
for (Map.Entry<SchematicNode, SteamwarUser> entry : schematics.entrySet()) {
|
||||||
GameModeConfig<String, String> gameModeConfig = ArenaMode.getBySchemType(schematic.getSchemtype());
|
String message;
|
||||||
if (gameModeConfig == null) gameModeConfig = GameModeConfig.getDefaults();
|
ClickEvent clickEvent;
|
||||||
CheckSession current = currentSchems.get(schematic.getId());
|
Message hoverMessage;
|
||||||
ClickEvent clickEvent = null;
|
String checker;
|
||||||
Message hoverMessage = null;
|
if (entry.getValue() == null) {
|
||||||
if (gameModeConfig.Checkers.isEmpty() || gameModeConfig.Checkers.contains(sender.user().getId())) {
|
message = "CHECK_LIST_TO_CHECK";
|
||||||
if (current == null) {
|
clickEvent = ClickEvent.runCommand("/check schematic " + entry.getKey().getId());
|
||||||
clickEvent = ClickEvent.runCommand("/check schematic " + schematic.getId());
|
|
||||||
hoverMessage = new Message("CHECK_LIST_TO_CHECK_HOVER");
|
hoverMessage = new Message("CHECK_LIST_TO_CHECK_HOVER");
|
||||||
|
checker = "";
|
||||||
} else {
|
} else {
|
||||||
clickEvent = ClickEvent.runCommand("/join " + current.checker.user().getUserName());
|
message = "CHECK_LIST_CHECKING";
|
||||||
|
clickEvent = ClickEvent.runCommand("/join " + entry.getValue().getUserName());
|
||||||
hoverMessage = new Message("CHECK_LIST_CHECKING_HOVER");
|
hoverMessage = new Message("CHECK_LIST_CHECKING_HOVER");
|
||||||
}
|
checker = entry.getValue().getUserName();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current == null) {
|
sender.prefixless(message,
|
||||||
sender.prefixless("CHECK_LIST_TO_CHECK",
|
|
||||||
hoverMessage,
|
hoverMessage,
|
||||||
clickEvent,
|
clickEvent,
|
||||||
getWaitTime(schematic),
|
getWaitTime(entry.getKey()),
|
||||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName());
|
entry.getKey().getSchemtype().getKuerzel(),
|
||||||
} else {
|
SteamwarUser.byId(entry.getKey().getOwner()).getUserName(),
|
||||||
sender.prefixless("CHECK_LIST_CHECKING",
|
entry.getKey().getName(),
|
||||||
hoverMessage,
|
checker);
|
||||||
clickEvent,
|
|
||||||
getWaitTime(schematic),
|
|
||||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.byId(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.user().getUserName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,8 +171,7 @@ public class CheckCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int playerTeam = sender.user().hasPerm(UserPerm.MODERATION) ? 0 : sender.user().getTeam();
|
int playerTeam = sender.user().hasPerm(UserPerm.MODERATION) ? 0 : sender.user().getTeam();
|
||||||
// Ignore 795 SteamWar Team
|
if (playerTeam != 0 && SteamwarUser.byId(schem.getOwner()).getTeam() == playerTeam) {
|
||||||
if (playerTeam != 0 && playerTeam != 795 && SteamwarUser.byId(schem.getOwner()).getTeam() == playerTeam) {
|
|
||||||
sender.system("CHECK_SCHEMATIC_OWN_TEAM");
|
sender.system("CHECK_SCHEMATIC_OWN_TEAM");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -209,11 +237,6 @@ public class CheckCommand extends SWCommand {
|
|||||||
return schematicList;
|
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) {
|
private static boolean notChecking(Player player) {
|
||||||
if (!isChecking(player)) {
|
if (!isChecking(player)) {
|
||||||
Chatter.of(player).system("CHECK_NOT_CHECKING");
|
Chatter.of(player).system("CHECK_NOT_CHECKING");
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ public class ConnectionListener extends BasicListener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||||
Chatter chatter = Chatter.of(player);
|
Chatter chatter = Chatter.of(player);
|
||||||
|
CheckCommand.sendReminder(chatter);
|
||||||
if (user.hasPerm(UserPerm.CHECK)) CheckCommand.sendReminder(chatter);
|
|
||||||
|
|
||||||
for (Subserver subserver : Subserver.getServerList()) {
|
for (Subserver subserver : Subserver.getServerList()) {
|
||||||
if (Subserver.isArena(subserver)) {
|
if (Subserver.isArena(subserver)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user