forked from SteamWar/SteamWar
Merge pull request 'Add enhance ReplayCommand' (#115) from add-fight-id into main
Reviewed-on: SteamWar/SteamWar#115 Reviewed-by: YoyoNow <yoyonow@noreply.localhost>
This commit is contained in:
@@ -35,7 +35,8 @@ import java.util.stream.Collectors;
|
||||
public class Fight {
|
||||
|
||||
private static final Table<Fight> table = new Table<>(Fight.class);
|
||||
private static final SelectStatement<Fight> getPage = new SelectStatement<>(table, "SELECT f.*, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?");
|
||||
private static final SelectStatement<Fight> getPage = new SelectStatement<>(table, "SELECT f.*, (b.NodeId IS NULL OR b.Config & 2) AND (r.NodeId IS NULL OR r.Config & 2) AS ReplayAllowed FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?");
|
||||
private static final SelectStatement<Fight> getById = new SelectStatement<>(table, "SELECT f.*, (b.NodeId IS NULL OR b.Config & 2) AND (r.NodeId IS NULL OR r.Config & 2) AS ReplayAllowed FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId WHERE FightId = ?");
|
||||
private static final Statement insert = table.insertFields(true, "GameMode", "Server", "StartTime", "Duration", "BlueLeader", "RedLeader", "BlueSchem", "RedSchem", "Win", "WinCondition");
|
||||
private static final Statement updateReplayAvailable = table.update(Table.PRIMARY, "ReplayAvailable");
|
||||
|
||||
@@ -51,6 +52,10 @@ public class Fight {
|
||||
return fights;
|
||||
}
|
||||
|
||||
public static Fight getById(int fightID) {
|
||||
return getById.select(fightID);
|
||||
}
|
||||
|
||||
public static int create(String gamemode, String server, Timestamp starttime, int duration, int blueleader, int redleader, Integer blueschem, Integer redschem, int win, String wincondition){
|
||||
return insert.insertGetKey(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition);
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ 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}
|
||||
REPLAY_SERVER=§7{0} #{1}
|
||||
|
||||
#TutorialCommand
|
||||
TUTORIAL_TITLE=Tutorials
|
||||
|
||||
@@ -38,31 +38,51 @@ public class ReplayCommand extends SWCommand {
|
||||
super("replay");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(PlayerChatter sender, int replayId, @StaticValue(value = {"", "-a"}, allowISE=true) @OptionalValue("") boolean isAdmin, @OptionalValue("") String optionalMap) {
|
||||
Fight fight = Fight.getById(replayId);
|
||||
|
||||
if (fight == null) {
|
||||
sender.system("REPLAY_UNAVAILABLE");
|
||||
return;
|
||||
}
|
||||
|
||||
startReplay(sender, isAdmin, optionalMap, fight);
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(PlayerChatter sender, @OptionalValue("") String optionalMap) {
|
||||
if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer))
|
||||
return;
|
||||
|
||||
new SWStreamInv<>(sender, new Message("REPLAY_TITLE"), (click, fight) -> {
|
||||
ArenaMode mode = ArenaMode.getBySchemType(fight.getSchemType());
|
||||
ServerStarter starter = new ServerStarter().replay(fight.getFightID()).blueLeader(sender.getPlayer());
|
||||
|
||||
String map = mode.getRandomMap();
|
||||
if (!optionalMap.equals("")) {
|
||||
String tMap = mode.hasMap(optionalMap);
|
||||
if (tMap != null) map = tMap;
|
||||
}
|
||||
|
||||
if (sender.user().hasPerm(UserPerm.MODERATION) && click.isShiftClick() && fight.replayExists()) {
|
||||
starter.test(mode, map, sender.getPlayer()).start();
|
||||
} else if(!fight.replayAllowed()) {
|
||||
sender.system("REPLAY_UNAVAILABLE");
|
||||
} else {
|
||||
starter.arena(mode, map).start();
|
||||
}
|
||||
startReplay(sender, click.isShiftClick(), optionalMap, fight);
|
||||
}, page -> Fight.getPage(page, 45).stream().map(fight -> new SWListInv.SWListEntry<>(getFightItem(fight), fight)).toList()).open();
|
||||
}
|
||||
|
||||
private void startReplay(PlayerChatter sender, boolean isAdmin, String optionalMap, Fight fight) {
|
||||
if (PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer))
|
||||
return;
|
||||
|
||||
ArenaMode mode = ArenaMode.getBySchemType(fight.getSchemType());
|
||||
ServerStarter starter = new ServerStarter().replay(fight.getFightID()).blueLeader(sender.getPlayer());
|
||||
|
||||
String map = mode.getRandomMap();
|
||||
if (!optionalMap.isEmpty()) {
|
||||
String tMap = mode.hasMap(optionalMap);
|
||||
if (tMap != null) map = tMap;
|
||||
}
|
||||
|
||||
if (sender.user().hasPerm(UserPerm.MODERATION) && isAdmin && fight.replayExists()) {
|
||||
System.out.println("Starting admin replay");
|
||||
starter.test(mode, map, sender.getPlayer()).start();
|
||||
} else if(!fight.replayAllowed()) {
|
||||
sender.system("REPLAY_UNAVAILABLE");
|
||||
} else {
|
||||
starter.arena(mode, map).start();
|
||||
}
|
||||
}
|
||||
|
||||
private SWItem getFightItem(Fight fight) {
|
||||
SchematicType type = fight.getSchemType();
|
||||
SWItem item = new SWItem(type != null ? type.getMaterial() : "BARRIER", parseLeader(fight.getBlueLeader(), fight.getBluePlayers().size(), fight.getWin() == 1));
|
||||
@@ -71,7 +91,7 @@ public class ReplayCommand extends SWCommand {
|
||||
lore.add(parseLeader(fight.getRedLeader(), fight.getRedPlayers().size(), fight.getWin() == 2));
|
||||
lore.add(new Message("REPLAY_TIME", fight.getStartTime()));
|
||||
lore.add(new Message("SPACER"));
|
||||
lore.add(new Message("REPLAY_SERVER", fight.getServer()));
|
||||
lore.add(new Message("REPLAY_SERVER", fight.getServer(), Integer.toString(fight.getFightID())));
|
||||
if(!fight.replayAllowed())
|
||||
lore.add(new Message("REPLAY_UNAVAILABLE"));
|
||||
item.setLore(lore);
|
||||
|
||||
Reference in New Issue
Block a user