forked from SteamWar/SteamWar
Merge pull request 'Refactor schematic checks to handle unseen notifications' (#33) from add-offline-notify into main
Reviewed-on: SteamWar/SteamWar#33 Reviewed-by: YoyoNow <yoyonow@noreply.localhost>
This commit is contained in:
@@ -87,10 +87,11 @@ public interface Chatter {
|
||||
}
|
||||
default void withPlayerOrOffline(Consumer<Player> withPlayer, Runnable withOffline) {
|
||||
Player player = getPlayer();
|
||||
if(player == null)
|
||||
if(player == null) {
|
||||
withOffline.run();
|
||||
else
|
||||
} else {
|
||||
withPlayer.accept(player);
|
||||
}
|
||||
}
|
||||
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.BooleanSupplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CheckCommand extends SWCommand {
|
||||
@@ -271,25 +272,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(
|
||||
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 owner.getPlayer() != null;
|
||||
});
|
||||
}
|
||||
|
||||
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(
|
||||
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 owner.getPlayer() != null;
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyTeam(Message message) {
|
||||
@@ -298,14 +303,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, BooleanSupplier sendMessageIsOnline) {
|
||||
if(SchematicNode.getSchematicNode(schematic.getId()) != null) {
|
||||
CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason, sendMessageIsOnline.getAsBoolean());
|
||||
if(type != null)
|
||||
schematic.setSchemtype(type);
|
||||
}
|
||||
@@ -316,7 +319,6 @@ public class CheckCommand extends SWCommand {
|
||||
if(subserver != null)
|
||||
subserver.stop();
|
||||
}).schedule();
|
||||
return exists;
|
||||
}
|
||||
|
||||
private void remove() {
|
||||
|
||||
@@ -29,6 +29,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.EventStarter;
|
||||
@@ -84,6 +86,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