SteamWar/BungeeCore
Archiviert
13
2

Nice Replay display
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-12-27 19:36:51 +01:00
Ursprung d6e01e6bae
Commit 7ad4d73674
5 geänderte Dateien mit 64 neuen und 37 gelöschten Zeilen

Datei anzeigen

@ -28,7 +28,9 @@ import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.util.Date;
import java.util.Locale;
import java.util.ResourceBundle;
@ -71,6 +73,8 @@ public class Message {
if(params[i] instanceof Message) {
Message msg = (Message) params[i];
params[i] = parse(msg.getMessage(), sender, msg.getParams());
} else if(params[i] instanceof Date) {
params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format((Date) params[i]);
}
}
return format.format(params);

Datei anzeigen

@ -1,15 +1,19 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.SubserverSystem;
import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.inventory.SWStreamInv;
import de.steamwar.bungeecore.sql.Fight;
import de.steamwar.bungeecore.sql.SchematicType;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class ReplayCommand extends BasicCommand {
@ -22,34 +26,39 @@ public class ReplayCommand extends BasicCommand {
public void execute(CommandSender sender, String[] args) {
if(!(sender instanceof ProxiedPlayer))
return;
//TODO Translate
ProxiedPlayer player = (ProxiedPlayer) sender;
new SWStreamInv<>(player, "Letzte Kämpfe", (click, fight) -> {
new SWStreamInv<>(player, Message.parse("REPLAY_TITLE", player), (click, fight) -> {
if(!fight.isReplayAvailable()) {
player.sendMessage("Replay nicht möglich");
Message.send("REPLAY_UNAVAILABLE", player);
return;
}
ArenaMode mode = fight.getGameMode();
if(mode == null){
player.sendMessage("Replay kann aufgrund deaktivertem Spielmodus nicht gestartet werden");
return;
}
SubserverSystem.startArena(mode, mode.getRandomMap(), 0, 0, 0, fight.getFightID(), null, null, null, null, false).sendPlayer(player);
}, page -> Fight.getPage(page, 45).stream().map(fight -> new SWListInv.SWListEntry<>(getFightItem(player, fight), fight)).collect(Collectors.toList())).open();
}
private SWItem getFightItem(ProxiedPlayer player, Fight fight) {
String title = "§3" + (fight.getWin() == 1 ? "§l" : "") + fight.getBlueLeader().getUserName() + " §r§8vs §c" + (fight.getWin() == 2 ? "§l" : "") + fight.getRedLeader().getUserName();
SWItem item = new SWItem(fight.isReplayAvailable() ? "JUKEBOX" : "STONE", title);
item.setLore(Arrays.asList(
"§7" + fight.getStartTime().toString(),
"§7" + fight.getServer(),
"§7" + fight.getWinCondition() + " §8nach §e" + fight.getDuration() + "§8s",
fight.getBluePlayers().size() > 1 ? "§3+" + (fight.getBluePlayers().size() - 1) + " §8Spieler" : "",
fight.getRedPlayers().size() > 1 ? "§c+" + (fight.getRedPlayers().size() - 1) + " §8Spieler" : ""
));
SchematicType type = fight.getSchemType();
SWItem item = new SWItem(type != null ? type.getMaterial() : "BARRIER", parseLeader(player, fight.getBlueLeader(), fight.getBluePlayers().size(), fight.getWin() == 1));
List<String> lore = new ArrayList<>();
lore.add(parseLeader(player, fight.getRedLeader(), fight.getRedPlayers().size(), fight.getWin() == 2));
lore.add(Message.parse("REPLAY_TIME", player, fight.getStartTime()));
lore.add("");
lore.add(Message.parse("REPLAY_SERVER", player, fight.getServer()));
if(!fight.isReplayAvailable())
lore.add(Message.parse("REPLAY_UNAVAILABLE", player));
item.setLore(lore);
if(fight.isReplayAvailable())
item.setEnchanted(true);
return item;
}
private String parseLeader(ProxiedPlayer player, SteamwarUser leader, int players, boolean winner) {
return Message.parse(winner ? (players > 1 ? "REPLAY_WINNER" : "REPLAY_SOLO_WINNER") : (players > 1 ? "REPLAY_LOSER" : "REPLAY_SOLO_LOSER"), player, leader.getUserName(), players - 1);
}
}

Datei anzeigen

@ -5,13 +5,14 @@ import de.steamwar.bungeecore.ArenaMode;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Fight {
private static final Statement getPage = new Statement("SELECT FightID, GameMode, Server, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition, Replay is not NULL AS ReplayAvailable FROM Fight ORDER BY FightID DESC LIMIT ?, ?");
private static final Statement getPage = new Statement("SELECT FightID, GameMode, Server, StartTime, Duration, BlueLeader, RedLeader, BlueSchem, RedSchem, Win, WinCondition, ReplayLock, Replay is not NULL AS ReplayAvailable FROM Fight ORDER BY FightID DESC LIMIT ?, ?");
private final int fightID;
private final String gameMode;
@ -25,6 +26,8 @@ public class Fight {
private final int redSchem;
private final int win;
private final String winCondition;
private final Timestamp replayLock;
private final boolean replayAvailable;
private final List<FightPlayer> bluePlayers = new ArrayList<>();
@ -42,6 +45,7 @@ public class Fight {
redSchem = rs.getInt("RedSchem");
win = rs.getInt("Win");
winCondition = rs.getString("WinCondition");
replayLock = rs.getTimestamp("ReplayLock");
replayAvailable = rs.getBoolean("ReplayAvailable");
}
@ -75,17 +79,17 @@ public class Fight {
return fights;
}
public SchematicType getSchemType() {
return SchematicType.fromDB(gameMode);
}
public ArenaMode getGameMode() {
SchematicType schemType = SchematicType.fromDB(gameMode);
SchematicType schemType = getSchemType();
if(schemType == null)
return null;
return ArenaMode.getBySchemType(schemType);
}
public String getRawGameMode() {
return gameMode;
}
public int getFightID() {
return fightID;
}
@ -94,10 +98,6 @@ public class Fight {
return startTime;
}
public int getDuration() {
return duration;
}
public SteamwarUser getBlueLeader() {
return SteamwarUser.get(blueLeader);
}
@ -114,10 +114,6 @@ public class Fight {
return server;
}
public String getWinCondition() {
return winCondition;
}
public List<FightPlayer> getBluePlayers() {
return bluePlayers;
}
@ -127,6 +123,6 @@ public class Fight {
}
public boolean isReplayAvailable() {
return replayAvailable;
return replayAvailable && replayLock.before(Timestamp.from(Instant.now())) && getGameMode() != null;
}
}

Datei anzeigen

@ -30,7 +30,7 @@ import java.io.IOException;
import java.util.*;
public class SchematicType {
public static final SchematicType Normal = new SchematicType("Normal", "", Type.NORMAL, null); //Has to stay publicly availible
public static final SchematicType Normal = new SchematicType("Normal", "", null, Type.NORMAL, null); //Has to stay publicly availible
private static final Map<String, SchematicType> fromDB;
private static final Map<SchematicType, SchematicType> fightType;
@ -64,15 +64,17 @@ public class SchematicType {
if(tmpFromDB.containsKey(type.toLowerCase()))
continue;
String material = config.getString("Schematic.Material");
SchematicType checktype = null;
if(!config.getStringList("CheckQuestions").isEmpty()) {
checktype = new SchematicType("C" + type, "C" + shortcut, Type.CHECK_TYPE, null);
checktype = new SchematicType("C" + type, "C" + shortcut, material, Type.CHECK_TYPE, null);
tmpTypes.add(checktype);
tmpFromDB.put(checktype.toDB(), checktype);
CheckCommand.setCheckQuestions(checktype, config);
}
SchematicType current = new SchematicType(type, shortcut, config.getKeys().contains("Server") ? Type.FIGHT_TYPE : Type.NORMAL, checktype);
SchematicType current = new SchematicType(type, shortcut, material, config.getKeys().contains("Server") ? Type.FIGHT_TYPE : Type.NORMAL, checktype);
if(checktype != null)
tmpFightType.put(checktype, current);
tmpFromDB.put(type.toLowerCase(), current);
@ -86,12 +88,14 @@ public class SchematicType {
private final String name;
private final String kuerzel;
private final String material;
private final Type type;
private final SchematicType checkType;
private SchematicType(String name, String kuerzel, Type type, SchematicType checkType){
private SchematicType(String name, String kuerzel, String material, Type type, SchematicType checkType){
this.name = name;
this.kuerzel = kuerzel;
this.material = material != null && !"".equals(material) ? material : "STONE_BUTTON";
this.type = type;
this.checkType = checkType;
}
@ -124,6 +128,10 @@ public class SchematicType {
return name;
}
public String getMaterial() {
return material;
}
public String getKuerzel() {
return kuerzel;
}

Datei anzeigen

@ -337,6 +337,16 @@ REGELN_WS=§eWarShip§8-§7Regelwerk
REGELN_WS_HOVER=§7https://steamwar.de/spielmodi/warship-regelwerk/
REGELN_WS_URL=https://steamwar.de/spielmodi/warship-regelwerk/
#ReplayCommand
REPLAY_TITLE=Letzte Kämpfe
REPLAY_UNAVAILABLE=§cReplay nicht möglich
REPLAY_SOLO_WINNER=§e§l{0}
REPLAY_WINNER=§e§l{0} §7+§e{1}
REPLAY_SOLO_LOSER=§e{0}
REPLAY_LOSER=§e{0} §7+§e{1}
REPLAY_TIME=§7{0}
REPLAY_SERVER=§7{0}
#ServerTeamchatCommand
STC_USAGE=§8/§7stc §8[§eNachricht an das Team§8]
STC_FORMAT=§8STC §e{0}» §r{1}