Archiviert
1
0

Nice Replay display

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.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.text.DateFormat;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -71,6 +73,8 @@ public class Message {
if(params[i] instanceof Message) { if(params[i] instanceof Message) {
Message msg = (Message) params[i]; Message msg = (Message) params[i];
params[i] = parse(msg.getMessage(), sender, msg.getParams()); 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); return format.format(params);

Datei anzeigen

@ -1,15 +1,19 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.SubserverSystem; import de.steamwar.bungeecore.SubserverSystem;
import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.inventory.SWStreamInv;
import de.steamwar.bungeecore.sql.Fight; 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.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; 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; import java.util.stream.Collectors;
public class ReplayCommand extends BasicCommand { public class ReplayCommand extends BasicCommand {
@ -22,34 +26,39 @@ public class ReplayCommand extends BasicCommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(!(sender instanceof ProxiedPlayer)) if(!(sender instanceof ProxiedPlayer))
return; return;
//TODO Translate
ProxiedPlayer player = (ProxiedPlayer) sender; 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()) { if(!fight.isReplayAvailable()) {
player.sendMessage("Replay nicht möglich"); Message.send("REPLAY_UNAVAILABLE", player);
return; return;
} }
ArenaMode mode = fight.getGameMode(); 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); 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(); }, 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) { 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(); SchematicType type = fight.getSchemType();
SWItem item = new SWItem(fight.isReplayAvailable() ? "JUKEBOX" : "STONE", title); SWItem item = new SWItem(type != null ? type.getMaterial() : "BARRIER", parseLeader(player, fight.getBlueLeader(), fight.getBluePlayers().size(), fight.getWin() == 1));
item.setLore(Arrays.asList(
"§7" + fight.getStartTime().toString(), List<String> lore = new ArrayList<>();
"§7" + fight.getServer(), lore.add(parseLeader(player, fight.getRedLeader(), fight.getRedPlayers().size(), fight.getWin() == 2));
"§7" + fight.getWinCondition() + " §8nach §e" + fight.getDuration() + "§8s", lore.add(Message.parse("REPLAY_TIME", player, fight.getStartTime()));
fight.getBluePlayers().size() > 1 ? "§3+" + (fight.getBluePlayers().size() - 1) + " §8Spieler" : "", lore.add("");
fight.getRedPlayers().size() > 1 ? "§c+" + (fight.getRedPlayers().size() - 1) + " §8Spieler" : "" 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; 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.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Fight { 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 int fightID;
private final String gameMode; private final String gameMode;
@ -25,6 +26,8 @@ public class Fight {
private final int redSchem; private final int redSchem;
private final int win; private final int win;
private final String winCondition; private final String winCondition;
private final Timestamp replayLock;
private final boolean replayAvailable; private final boolean replayAvailable;
private final List<FightPlayer> bluePlayers = new ArrayList<>(); private final List<FightPlayer> bluePlayers = new ArrayList<>();
@ -42,6 +45,7 @@ public class Fight {
redSchem = rs.getInt("RedSchem"); redSchem = rs.getInt("RedSchem");
win = rs.getInt("Win"); win = rs.getInt("Win");
winCondition = rs.getString("WinCondition"); winCondition = rs.getString("WinCondition");
replayLock = rs.getTimestamp("ReplayLock");
replayAvailable = rs.getBoolean("ReplayAvailable"); replayAvailable = rs.getBoolean("ReplayAvailable");
} }
@ -75,17 +79,17 @@ public class Fight {
return fights; return fights;
} }
public SchematicType getSchemType() {
return SchematicType.fromDB(gameMode);
}
public ArenaMode getGameMode() { public ArenaMode getGameMode() {
SchematicType schemType = SchematicType.fromDB(gameMode); SchematicType schemType = getSchemType();
if(schemType == null) if(schemType == null)
return null; return null;
return ArenaMode.getBySchemType(schemType); return ArenaMode.getBySchemType(schemType);
} }
public String getRawGameMode() {
return gameMode;
}
public int getFightID() { public int getFightID() {
return fightID; return fightID;
} }
@ -94,10 +98,6 @@ public class Fight {
return startTime; return startTime;
} }
public int getDuration() {
return duration;
}
public SteamwarUser getBlueLeader() { public SteamwarUser getBlueLeader() {
return SteamwarUser.get(blueLeader); return SteamwarUser.get(blueLeader);
} }
@ -114,10 +114,6 @@ public class Fight {
return server; return server;
} }
public String getWinCondition() {
return winCondition;
}
public List<FightPlayer> getBluePlayers() { public List<FightPlayer> getBluePlayers() {
return bluePlayers; return bluePlayers;
} }
@ -127,6 +123,6 @@ public class Fight {
} }
public boolean isReplayAvailable() { 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.*; import java.util.*;
public class SchematicType { 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<String, SchematicType> fromDB;
private static final Map<SchematicType, SchematicType> fightType; private static final Map<SchematicType, SchematicType> fightType;
@ -64,15 +64,17 @@ public class SchematicType {
if(tmpFromDB.containsKey(type.toLowerCase())) if(tmpFromDB.containsKey(type.toLowerCase()))
continue; continue;
String material = config.getString("Schematic.Material");
SchematicType checktype = null; SchematicType checktype = null;
if(!config.getStringList("CheckQuestions").isEmpty()) { 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); tmpTypes.add(checktype);
tmpFromDB.put(checktype.toDB(), checktype); tmpFromDB.put(checktype.toDB(), checktype);
CheckCommand.setCheckQuestions(checktype, config); 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) if(checktype != null)
tmpFightType.put(checktype, current); tmpFightType.put(checktype, current);
tmpFromDB.put(type.toLowerCase(), current); tmpFromDB.put(type.toLowerCase(), current);
@ -86,12 +88,14 @@ public class SchematicType {
private final String name; private final String name;
private final String kuerzel; private final String kuerzel;
private final String material;
private final Type type; private final Type type;
private final SchematicType checkType; 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.name = name;
this.kuerzel = kuerzel; this.kuerzel = kuerzel;
this.material = material != null && !"".equals(material) ? material : "STONE_BUTTON";
this.type = type; this.type = type;
this.checkType = checkType; this.checkType = checkType;
} }
@ -124,6 +128,10 @@ public class SchematicType {
return name; return name;
} }
public String getMaterial() {
return material;
}
public String getKuerzel() { public String getKuerzel() {
return kuerzel; return kuerzel;
} }

Datei anzeigen

@ -337,6 +337,16 @@ REGELN_WS=§eWarShip§8-§7Regelwerk
REGELN_WS_HOVER=§7https://steamwar.de/spielmodi/warship-regelwerk/ REGELN_WS_HOVER=§7https://steamwar.de/spielmodi/warship-regelwerk/
REGELN_WS_URL=https://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 #ServerTeamchatCommand
STC_USAGE=§8/§7stc §8[§eNachricht an das Team§8] STC_USAGE=§8/§7stc §8[§eNachricht an das Team§8]
STC_FORMAT=§8STC §e{0}» §r{1} STC_FORMAT=§8STC §e{0}» §r{1}