SteamWar/BungeeCore
Archiviert
13
2

Check refactoring: Using Message, informing about previous checks

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-12-19 14:12:19 +01:00
Ursprung bf0bd042a8
Commit 31f325421a
3 geänderte Dateien mit 124 neuen und 42 gelöschten Zeilen

Datei anzeigen

@ -68,7 +68,7 @@ public class CheckCommand extends BasicCommand {
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
List<Schematic> schematics = getSchemsToCheck(); List<Schematic> schematics = getSchemsToCheck();
if(schematics.size() != currentCheckers.size()) if(schematics.size() != currentCheckers.size())
ServerTeamchatCommand.sendToTeam("§7Es sind §e" + (schematics.size() - currentCheckers.size()) + " §7Schematics zu prüfen§8!"); Message.team("CHECK_REMINDER", schematics.size() - currentCheckers.size());
}, 10, 10, TimeUnit.MINUTES); }, 10, 10, TimeUnit.MINUTES);
} }
@ -91,7 +91,7 @@ public class CheckCommand extends BasicCommand {
schematic(player, args[1]); schematic(player, args[1]);
break; break;
case "next": case "next":
case "allow": case "accept":
next(player, args); next(player, args);
break; break;
case "cancel": case "cancel":
@ -118,27 +118,27 @@ public class CheckCommand extends BasicCommand {
private void list(ProxiedPlayer player) { private void list(ProxiedPlayer player) {
List<Schematic> schematicList = getSchemsToCheck(); List<Schematic> schematicList = getSchemsToCheck();
BungeeCore.send(player, "§e§lZu prüfen sind " + schematicList.size() + " Schematics"); Message.sendPrefixless("CHECK_LIST_HEADER", player, schematicList.size());
for (Schematic schematic : schematicList) { for (Schematic schematic : schematicList) {
CheckSession current = currentSchems.get(schematic.getSchemID()); CheckSession current = currentSchems.get(schematic.getSchemID());
if (current == null) { if (current == null) {
BungeeCore.send(player, Message.sendPrefixless("CHECK_LIST_TO_CHECK", player,
"§8" + schematic.getSchemType().getKuerzel() + " §7" + SteamwarUser.get(schematic.getSchemOwner()).getUserName() + " §e" + schematic.getSchemName(), Message.parse("CHECK_LIST_TO_CHECK_HOVER", player),
"§eSchematic prüfen", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getSchemID()),
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getSchemID())); schematic.getSchemType().getKuerzel(), SteamwarUser.get(schematic.getSchemOwner()).getUserName(), schematic.getSchemName());
} else { } else {
BungeeCore.send(player, Message.sendPrefixless("CHECK_LIST_CHECKING", player,
"§8" + schematic.getSchemType().getKuerzel() + " §7" + SteamwarUser.get(schematic.getSchemOwner()).getUserName() + " §e" + schematic.getSchemName() + " §7wird geprüft von §e" + current.checker.getName(), Message.parse("CHECK_LIST_CHECKING_HOVER", player),
"§eZum Prüfer", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName()),
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName())); schematic.getSchemType().getKuerzel(), SteamwarUser.get(schematic.getSchemOwner()).getUserName(), schematic.getSchemName(), current.checker.getName());
} }
} }
} }
private void schematic(ProxiedPlayer player, String schemID){ private void schematic(ProxiedPlayer player, String schemID){
if(isChecking(player)){ if(isChecking(player)){
BungeeCore.send(player, "§cDu prüfst schon eine Schematic!"); Message.send("CHECK_SCHEMATIC_ALREADY_CHECKING", player);
return; return;
} }
@ -147,7 +147,7 @@ public class CheckCommand extends BasicCommand {
ProxyServer.getInstance().getLogger().log(Level.SEVERE, player.getName() + " tried to check an uncheckable schematic!"); ProxyServer.getInstance().getLogger().log(Level.SEVERE, player.getName() + " tried to check an uncheckable schematic!");
return; return;
}else if(schem.getSchemOwner() == SteamwarUser.get(player.getUniqueId()).getId()) { }else if(schem.getSchemOwner() == SteamwarUser.get(player.getUniqueId()).getId()) {
BungeeCore.send(player, "§cDu kannst nicht deine eigenen Schematics prüfen"); Message.send("CHECK_SCHEMATIC_OWN", player);
return; return;
} }
@ -156,7 +156,7 @@ public class CheckCommand extends BasicCommand {
private static boolean notChecking(ProxiedPlayer player){ private static boolean notChecking(ProxiedPlayer player){
if(!isChecking(player)){ if(!isChecking(player)){
BungeeCore.send(player, "§cDu prüfst derzeit nicht."); Message.send("CHECK_NOT_CHECKING", player);
return true; return true;
} }
return false; return false;
@ -171,7 +171,7 @@ public class CheckCommand extends BasicCommand {
try{ try{
rank = Integer.parseInt(args[1]); rank = Integer.parseInt(args[1]);
}catch(NumberFormatException e){ }catch(NumberFormatException e){
BungeeCore.send(player, "Der angegebene Rang ist ungültig!"); Message.send("CHECK_INVALID_RANK", player);
return; return;
} }
} }
@ -183,7 +183,7 @@ public class CheckCommand extends BasicCommand {
if(notChecking(player)) if(notChecking(player))
return; return;
BungeeCore.send(player, "§aDer Prüfvorgang wurde abgebrochen!"); Message.send("CHECK_ABORT", player);
currentCheckers.get(player.getUniqueId()).abort(); currentCheckers.get(player.getUniqueId()).abort();
} }
@ -204,11 +204,10 @@ public class CheckCommand extends BasicCommand {
} }
private void help(CommandSender sender){ private void help(CommandSender sender){
BungeeCore.send(sender, "§8/§echeck list §8- §7Zeigt die Liste der ungeprüften Schematics"); Message.sendPrefixless("CHECK_HELP_LIST", sender);
BungeeCore.send(sender, "§8/§echeck next §8- §7Nächste Prüffrage"); Message.sendPrefixless("CHECK_HELP_NEXT", sender);
BungeeCore.send(sender, "§8/§echeck allow §8- §7Schematic freigeben"); Message.sendPrefixless("CHECK_HELP_DECLINE", sender);
BungeeCore.send(sender, "§8/§echeck decline [Grund] §8- §7Schematic nicht freigeben"); Message.sendPrefixless("CHECK_HELP_CANCEL", sender);
BungeeCore.send(sender, "§8/§echeck cancel §8- §7Bricht das Prüfen ab");
} }
private static class CheckSession{ private static class CheckSession{
@ -235,6 +234,8 @@ public class CheckCommand extends BasicCommand {
SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getSchemID()); SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getSchemID());
currentCheckers.put(checker.getUniqueId(), this); currentCheckers.put(checker.getUniqueId(), this);
currentSchems.put(schematic.getSchemID(), this); currentSchems.put(schematic.getSchemID(), this);
for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic.getSchemName(), schematic.getSchemOwner()))
Message.sendPrefixless("CHECK_SCHEMATIC_PREVIOUS", checker, previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getReason());
next(0); next(0);
}); });
} }
@ -245,26 +246,28 @@ public class CheckCommand extends BasicCommand {
return; return;
} }
BungeeCore.send(checker, checkList.next()); checker.sendMessage(TextComponent.fromLegacyText(checkList.next()));
TextComponent next; TextComponent next = new TextComponent();
next.setColor(ChatColor.GREEN);
if(checkList.hasNext()){ if(checkList.hasNext()){
next = new TextComponent("next "); next.setText(Message.parse("CHECK_NEXT", checker));
next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next")); next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next"));
}else if(ranks.containsKey(schematic.getSchemType())){ }else if(ranks.containsKey(schematic.getSchemType())){
next = new TextComponent();
List<String> r = ranks.get(schematic.getSchemType()); List<String> r = ranks.get(schematic.getSchemType());
for(int i = 0; i < r.size(); i++){ for(int i = 0; i < r.size(); i++){
BungeeCore.send(checker, "§aRang " + (i+1) + ": " + r.get(i), "§aMit diesem Rang freigeben", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check allow " + (i+1))); Message.sendPrefixless("CHECK_RANK", checker,
BungeeCore.send(checker, ""); Message.parse("CHECK_RANK_HOVER", checker),
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check allow " + (i+1)),
i+1, r.get(i));
Message.sendPrefixless("SPACER", checker);
} }
}else{ }else{
next = new TextComponent("accept "); next.setText(Message.parse("CHECK_ACCEPT", checker));
next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check allow")); next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept"));
} }
next.setColor(ChatColor.GREEN);
TextComponent decline = new TextComponent("decline"); TextComponent decline = new TextComponent(" " + Message.parse("CHECK_DECLINE", checker));
decline.setColor(ChatColor.RED); decline.setColor(ChatColor.RED);
decline.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/check decline ")); decline.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/check decline "));
@ -275,7 +278,7 @@ public class CheckCommand extends BasicCommand {
private void accept(int rank){ private void accept(int rank){
if(ranks.containsKey(schematic.getSchemType())){ if(ranks.containsKey(schematic.getSchemType())){
if(rank <= 0 || ranks.get(schematic.getSchemType()).size() < rank){ if(rank <= 0 || ranks.get(schematic.getSchemType()).size() < rank){
BungeeCore.send(checker, "§cUnbekannter Schematic-Rang"); Message.send("CHECK_INVALID_RANK", checker);
return; return;
} }
schematic.setRank(rank); schematic.setRank(rank);
@ -283,24 +286,31 @@ public class CheckCommand extends BasicCommand {
schematic.setSchemType(schematic.getSchemType().fightType()); schematic.setSchemType(schematic.getSchemType().fightType());
CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben"); CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "freigegeben");
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(schematic.getSchemOwner()).getUuid()); SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner());
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
if(player != null) if(player != null)
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§aDein §e" + schematic.getSchemType().name() + " " + schematic.getSchemName() + " §ewurde freigegeben§8!"); Message.send("CHECK_ACCEPTED", player, schematic.getSchemType().name(), schematic.getSchemName());
ServerTeamchatCommand.sendToTeam("§aDie Schematic §e" + schematic.getSchemName() + " §avon §e" + SteamwarUser.get(schematic.getSchemOwner()).getUserName() + " §aist nun freigegeben!"); Message.team("CHECK_ACCEPTED_TEAM", schematic.getSchemName(), user.getUserName());
abort(); stop();
} }
private void decline(String reason){ private void decline(String reason){
schematic.setSchemType(SchematicType.Normal); schematic.setSchemType(SchematicType.Normal);
CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason);
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(schematic.getSchemOwner()).getUuid()); SteamwarUser user = SteamwarUser.get(schematic.getSchemOwner());
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUuid());
if(player != null) if(player != null)
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDein §e" + schematic.getSchemType().name() + " " + schematic.getSchemName() + " §cwurde abgelehnt§8: §c" + reason); Message.send("CHECK_DECLINED", player, schematic.getSchemType().name(), schematic.getSchemName(), reason);
ServerTeamchatCommand.sendToTeam("§aDie Schematic §e" + schematic.getSchemName() + " §avon §e" + SteamwarUser.get(schematic.getSchemOwner()).getUserName() + " §awurde aufgrund von §e" + reason + " §aabgelehnt!"); Message.team("CHECK_DECLINED_TEAM", schematic.getSchemName(), user.getUserName(), reason);
abort(); stop();
} }
private void abort(){ private void abort(){
CheckedSchematic.create(schematic.getSchemName(), schematic.getSchemOwner(), SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), "Prüfvorgang abgebrochen");
stop();
}
private void stop(){
currentCheckers.remove(checker.getUniqueId()); currentCheckers.remove(checker.getUniqueId());
currentSchems.remove(schematic.getSchemID()); currentSchems.remove(schematic.getSchemID());
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {

Datei anzeigen

@ -19,13 +19,57 @@
package de.steamwar.bungeecore.sql; package de.steamwar.bungeecore.sql;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
public class CheckedSchematic { public class CheckedSchematic {
private CheckedSchematic(){}
private final String schemName;
private final int schemOwner;
private final int validator;
private final Timestamp startTime;
private final Timestamp endTime;
private final String reason;
private CheckedSchematic(ResultSet rs) throws SQLException {
schemName = rs.getString("SchemName");
schemOwner = rs.getInt("SchemOwner");
validator = rs.getInt("Validator");
startTime = rs.getTimestamp("StartTime");
endTime = rs.getTimestamp("EndTime");
reason = rs.getString("Reason");
}
public static void create(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String reason){ public static void create(String schemName, int schemOwner, int validator, Timestamp startTime, Timestamp endTime, String reason){
SQL.update("INSERT INTO CheckedSchematic (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)", SQL.update("INSERT INTO CheckedSchematic (SchemName, SchemOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?, ?)",
schemName, schemOwner, validator, startTime, endTime, reason); schemName, schemOwner, validator, startTime, endTime, reason);
} }
public static List<CheckedSchematic> previousChecks(String schemName, int schemOwner){
ResultSet rs = SQL.select("SELECT FROM CheckedSchematics WHERE SchemName = ? AND SchemOwner = ? ORDER BY EndTime ASC", schemName, schemOwner);
List<CheckedSchematic> schematics = new ArrayList<>();
try {
while(rs.next())
schematics.add(new CheckedSchematic(rs));
} catch (SQLException e) {
throw new SecurityException("Could not load previous checks", e);
}
return schematics;
}
public int getValidator() {
return validator;
}
public Timestamp getEndTime() {
return endTime;
}
public String getReason() {
return reason;
}
} }

Datei anzeigen

@ -1,4 +1,5 @@
PREFIX=§eSteam§8War» PREFIX=§eSteam§8War»
SPACER=
UNKNOWN_COMMAND=§cUnbekannter Befehl. UNKNOWN_COMMAND=§cUnbekannter Befehl.
UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht. UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht.
@ -113,4 +114,31 @@ POLLRESULT_LIST=§e{0}§8: §7{1}
#BauCommand #BauCommand
BAU_DELETE_GUI_NAME=§eWirklich Welt löschen? BAU_DELETE_GUI_NAME=§eWirklich Welt löschen?
BAU_DELETE_GUI_CANCEL=§cAbbrechen BAU_DELETE_GUI_CANCEL=§cAbbrechen
BAU_DELETE_GUI_DELETE=§aLöschen BAU_DELETE_GUI_DELETE=§aLöschen
#CheckCommand
CHECK_REMINDER=§7Es sind §e{0} §7Schematics zu prüfen§8!
CHECK_NOT_CHECKING=§cDu prüfst derzeit nicht.
CHECK_HELP_LIST=§8/§echeck list §8- §7Zeigt die Liste der ungeprüften Schematics
CHECK_HELP_NEXT=§8/§echeck next §8- §7Nächste Prüffrage§8/§7freigeben
CHECK_HELP_DECLINE=§8/§echeck decline §8[§eGrund§8] - §7Schematic ablehnen
CHECK_HELP_CANCEL=§8/§echeck cancel §8- §7Bricht den Prüfvorgang ab
CHECK_LIST_HEADER=§e§lZu prüfen sind {0} Schematics
CHECK_LIST_TO_CHECK=§8{0} §7{1} §e{2}
CHECK_LIST_TO_CHECK_HOVER=§eSchematic prüfen
CHECK_LIST_CHECKING=§8{0} §7{1} §e{2} §7wird geprüft von §e{3}
CHECK_LIST_CHECKING_HOVER=§eZum Prüfer
CHECK_SCHEMATIC_ALREADY_CHECKING=§cDu prüfst schon eine Schematic!
CHECK_SCHEMATIC_OWN=§cDu kannst nicht deine eigenen Schematics prüfen.
CHECK_SCHEMATIC_PREVIOUS=§7{0} von {1}§8: §e{2}
CHECK_INVALID_RANK=§cUnbekannter Schematicrang.
CHECK_ABORT=§aDer Prüfvorgang wurde abgebrochen!
CHECK_NEXT=Nächste Frage
CHECK_ACCEPT=Annehmen
CHECK_DECLINE=Ablehnen
CHECK_RANK=§aRang {0}: {1}
CHECK_RANK_HOVER=§aMit diesem Rang freigeben
CHECK_ACCEPTED=§aDein §e{0} {1} §ewurde freigegeben§8!
CHECK_ACCEPTED_TEAM=§7Die Schematic §e{0} §7von §e{1} §7ist nun freigegeben!
CHECK_DECLINED=§cDein §e{0} {1} §cwurde abgelehnt§8: §c{2}
CHECK_DECLINED_TEAM=§7Die Schematic §e{0} §7von §e{1} §awurde aufgrund von §e{2} §7abgelehnt!