forked from SteamWar/SteamWar
Refactor schematic checks to handle unseen notifications
This commit is contained in:
@@ -37,15 +37,26 @@ public class CheckedSchematic {
|
||||
private static final SelectStatement<CheckedSchematic> nodeHistory = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
|
||||
private static final Statement insert = table.insertAll();
|
||||
|
||||
public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason){
|
||||
insert.update(nodeId, owner, name, validator, startTime, endTime, reason);
|
||||
private static final SelectStatement<CheckedSchematic> getUnseen = new SelectStatement<>(table, "SELECT * FROM CheckedSchematic WHERE Seen = 0 AND NodeOwner = ? ORDER BY StartTime DESC");
|
||||
private static final Statement updateSeen = new Statement("UPDATE CheckedSchematic SET Seen = ? WHERE StartTime = ? AND EndTime = ? AND NodeName = ?");
|
||||
|
||||
public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen, String nodeType) {
|
||||
insert.update(nodeId, owner, name, validator, startTime, endTime, reason, seen, nodeType);
|
||||
}
|
||||
|
||||
public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason){
|
||||
create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason);
|
||||
public static void create(int nodeId, String name, int owner, int validator, Timestamp startTime, Timestamp endTime, String reason, String nodeType) {
|
||||
create(nodeId, name, owner, validator, startTime, endTime, reason, true, nodeType);
|
||||
}
|
||||
|
||||
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){
|
||||
public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason, boolean seen) {
|
||||
create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, seen, node.getSchemtype().toDB());
|
||||
}
|
||||
|
||||
public static void create(SchematicNode node, int validator, Timestamp startTime, Timestamp endTime, String reason) {
|
||||
create(node.getId(), node.getName(), node.getOwner(), validator, startTime, endTime, reason, true, node.getSchemtype().toDB());
|
||||
}
|
||||
|
||||
public static List<CheckedSchematic> getLastDeclinedOfNode(int node) {
|
||||
return statusOfNode.listSelect(node);
|
||||
}
|
||||
|
||||
@@ -53,6 +64,10 @@ public class CheckedSchematic {
|
||||
return nodeHistory.listSelect(node.getId());
|
||||
}
|
||||
|
||||
public static List<CheckedSchematic> getUnseen(SteamwarUser owner) {
|
||||
return getUnseen.listSelect(owner);
|
||||
}
|
||||
|
||||
@Field(nullable = true)
|
||||
private final Integer nodeId;
|
||||
@Field
|
||||
@@ -71,6 +86,10 @@ public class CheckedSchematic {
|
||||
@Getter
|
||||
@Field
|
||||
private final String declineReason;
|
||||
@Getter
|
||||
private boolean seen;
|
||||
@Getter
|
||||
private final String nodeType;
|
||||
|
||||
public int getNode() {
|
||||
return nodeId;
|
||||
@@ -83,4 +102,9 @@ public class CheckedSchematic {
|
||||
public int getSchemOwner() {
|
||||
return nodeOwner;
|
||||
}
|
||||
|
||||
public void setSeen(boolean seen) {
|
||||
this.seen = seen;
|
||||
updateSeen.update(seen, startTime, endTime, nodeName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,12 +85,15 @@ public interface Chatter {
|
||||
else
|
||||
return withPlayer.apply(player);
|
||||
}
|
||||
default void withPlayerOrOffline(Consumer<Player> withPlayer, Runnable withOffline) {
|
||||
default boolean withPlayerOrOffline(Consumer<Player> withPlayer, Runnable withOffline) {
|
||||
Player player = getPlayer();
|
||||
if(player == null)
|
||||
if(player == null) {
|
||||
withOffline.run();
|
||||
else
|
||||
return false;
|
||||
} else {
|
||||
withPlayer.accept(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
default void withPlayer(Consumer<Player> function) {
|
||||
withPlayerOrOffline(function, () -> {});
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CheckCommand extends SWCommand {
|
||||
@@ -237,25 +238,29 @@ public class CheckCommand extends SWCommand {
|
||||
}
|
||||
|
||||
private void accept(){
|
||||
if(concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()))) {
|
||||
concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()), () -> {
|
||||
Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID());
|
||||
owner.withPlayerOrOffline(
|
||||
boolean isOnline = owner.withPlayerOrOffline(
|
||||
player -> owner.system("CHECK_ACCEPTED", schematic.getSchemtype().name(), schematic.getName()),
|
||||
() -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true)
|
||||
);
|
||||
notifyTeam(new Message("CHECK_ACCEPTED_TEAM", schematic.getName(), owner.user().getUserName()));
|
||||
}
|
||||
|
||||
return isOnline;
|
||||
});
|
||||
}
|
||||
|
||||
private void decline(String reason){
|
||||
if(concludeCheckSession(reason, SchematicType.Normal)) {
|
||||
concludeCheckSession(reason, SchematicType.Normal, () -> {
|
||||
Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID());
|
||||
owner.withPlayerOrOffline(
|
||||
boolean isOnline = owner.withPlayerOrOffline(
|
||||
player -> owner.system("CHECK_DECLINED", schematic.getSchemtype().name(), schematic.getName(), reason),
|
||||
() -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false)
|
||||
);
|
||||
notifyTeam(new Message("CHECK_DECLINED_TEAM", schematic.getName(), owner.user().getUserName(), reason));
|
||||
}
|
||||
|
||||
return isOnline;
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyTeam(Message message) {
|
||||
@@ -264,14 +269,12 @@ public class CheckCommand extends SWCommand {
|
||||
}
|
||||
|
||||
private void abort(){
|
||||
concludeCheckSession("Prüfvorgang abgebrochen", null);
|
||||
concludeCheckSession("Prüfvorgang abgebrochen", null, () -> true);
|
||||
}
|
||||
|
||||
private boolean concludeCheckSession(String reason, SchematicType type) {
|
||||
boolean exists = SchematicNode.getSchematicNode(schematic.getId()) != null;
|
||||
|
||||
if(exists) {
|
||||
CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason);
|
||||
private void concludeCheckSession(String reason, SchematicType type, Supplier<Boolean> sendMessageIsOnline) {
|
||||
if(SchematicNode.getSchematicNode(schematic.getId()) != null) {
|
||||
CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason, sendMessageIsOnline.get());
|
||||
if(type != null)
|
||||
schematic.setSchemtype(type);
|
||||
}
|
||||
@@ -282,7 +285,6 @@ public class CheckCommand extends SWCommand {
|
||||
if(subserver != null)
|
||||
subserver.stop();
|
||||
}).schedule();
|
||||
return exists;
|
||||
}
|
||||
|
||||
private void remove() {
|
||||
|
||||
@@ -28,6 +28,8 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import de.steamwar.messages.Chatter;
|
||||
import de.steamwar.messages.Message;
|
||||
import de.steamwar.persistent.Subserver;
|
||||
import de.steamwar.sql.CheckedSchematic;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import de.steamwar.velocitycore.commands.*;
|
||||
@@ -82,6 +84,16 @@ public class ConnectionListener extends BasicListener {
|
||||
}
|
||||
}
|
||||
|
||||
for (CheckedSchematic checkedSchematic : CheckedSchematic.getUnseen(user)) {
|
||||
SchematicType type = SchematicType.fromDB(checkedSchematic.getNodeType());
|
||||
if(type == null) continue;
|
||||
if (checkedSchematic.getDeclineReason().equals("freigegeben")) {
|
||||
chatter.system("CHECK_ACCEPTED", type.name(), checkedSchematic.getSchemName());
|
||||
} else {
|
||||
chatter.system("CHECK_DECLINED", type.name(), checkedSchematic.getSchemName(), checkedSchematic.getDeclineReason());
|
||||
}
|
||||
}
|
||||
|
||||
if(newPlayers.contains(player.getUniqueId())){
|
||||
Chatter.broadcast().system("JOIN_FIRST", player);
|
||||
newPlayers.remove(player.getUniqueId());
|
||||
|
||||
Reference in New Issue
Block a user