Archiviert
1
0

First full ranked system implementation

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-07-19 15:25:12 +02:00
Ursprung 7cd45601f7
Commit 361e91997d
4 geänderte Dateien mit 145 neuen und 25 gelöschten Zeilen

Datei anzeigen

@ -35,6 +35,15 @@ public class ArenaMode {
return chatNames; return chatNames;
} }
public static List<String> getAllRankedChatNames(){
List<String> chatNames = new LinkedList<>();
for(ArenaMode mode : byInternal.values()){
if(mode.isRanked())
chatNames.addAll(mode.chatNames);
}
return chatNames;
}
public static ArenaMode getByCheckSchemType(String checkSchemType){ public static ArenaMode getByCheckSchemType(String checkSchemType){
return byCheckSchemType.get(checkSchemType); return byCheckSchemType.get(checkSchemType);
} }
@ -50,6 +59,7 @@ public class ArenaMode {
private final List<String> maps; private final List<String> maps;
private final boolean historic; private final boolean historic;
private final boolean ranked; private final boolean ranked;
private final String schemType;
private ArenaMode(String internalName, Configuration config){ private ArenaMode(String internalName, Configuration config){
this.internalName = internalName; this.internalName = internalName;
@ -57,8 +67,9 @@ public class ArenaMode {
this.serverJar = config.getString("serverJar"); this.serverJar = config.getString("serverJar");
this.chatNames = config.getStringList("chatNames"); this.chatNames = config.getStringList("chatNames");
this.maps = config.getStringList("maps"); this.maps = config.getStringList("maps");
this.historic = config.getBoolean("historic"); this.historic = config.getBoolean("historic", false);
this.ranked = config.getBoolean("ranked"); this.ranked = config.getBoolean("ranked", false);
this.schemType = config.getString("schemType", null);
allModes.add(this); allModes.add(this);
byInternal.put(internalName, this); byInternal.put(internalName, this);
@ -113,4 +124,8 @@ public class ArenaMode {
public boolean isRanked() { public boolean isRanked() {
return ranked; return ranked;
} }
public String getSchemType() {
return schemType;
}
} }

Datei anzeigen

@ -62,10 +62,13 @@ public class SubserverSystem {
* For event, test and normal arenas: The UUID of the designated leader for the red team * For event, test and normal arenas: The UUID of the designated leader for the red team
* or null (no designated leader). * or null (no designated leader).
* *
* @param ranked
* If the game is a ranked game.
*
* @return * @return
* The new started subserver. * The new started subserver.
*/ */
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, String serverName, String mapName, UUID player1, UUID player2){ public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, String serverName, String mapName, UUID player1, UUID player2, boolean ranked){
//Generate missing parameters //Generate missing parameters
int port = freePort(2500); int port = freePort(2500);
@ -98,6 +101,8 @@ public class SubserverSystem {
cmd.add("-DredLeader=" + player2.toString()); cmd.add("-DredLeader=" + player2.toString());
if(checkSchemID != 0) if(checkSchemID != 0)
cmd.add("-DcheckSchemID=" + checkSchemID); cmd.add("-DcheckSchemID=" + checkSchemID);
if(ranked)
cmd.add("-Dranked=true");
cmd.add("-Xmx2G"); cmd.add("-Xmx2G");
cmd.addAll(JVM_ARGS); cmd.addAll(JVM_ARGS);
cmd.add("-jar"); cmd.add("-jar");
@ -136,6 +141,10 @@ public class SubserverSystem {
}); });
} }
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, String serverName, String mapName, UUID player1, UUID player2){
return startArena(modus, map, eventFightID, checkSchemID, serverName, mapName, player1, player2, false);
}
public static Subserver startArena(ArenaMode modus, String map){ public static Subserver startArena(ArenaMode modus, String map){
return startArena(modus, map, 0, 0, null, null, null, null); return startArena(modus, map, 0, 0, null, null, null, null);
} }

Datei anzeigen

@ -1,6 +1,14 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.Elo;
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 java.util.ArrayList;
import java.util.List;
public class RankCommand extends BasicCommand { public class RankCommand extends BasicCommand {
public RankCommand() { public RankCommand() {
@ -9,6 +17,29 @@ public class RankCommand extends BasicCommand {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7§lPlatzierungen");
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
for(ArenaMode mode : ArenaMode.getAllModes()){
if(!mode.isRanked())
continue;
int elo = Elo.getElo(user.getId(), mode.getSchemType());
int placement = Elo.getPlacement(user.getId(), mode.getSchemType());
BungeeCore.send(player, "§e" + placement + "§8. §7mit §e" + elo + " §7Elo§8.");
}
}
@Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
if(args.length > 1)
return new ArrayList<>();
List<String> result = ArenaMode.getAllRankedChatNames();
result.removeIf(name -> !name.startsWith(args[0]));
return result;
} }
} }

Datei anzeigen

@ -1,13 +1,15 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.bungeecore.sql.Elo; import de.steamwar.bungeecore.sql.Elo;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
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 net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.*; import java.util.*;
@ -15,7 +17,7 @@ import java.util.concurrent.TimeUnit;
public class RankedCommand extends BasicCommand { public class RankedCommand extends BasicCommand {
private static Map<ArenaMode, WaitingQueue> queues = new HashMap(); private static Map<ArenaMode, WaitingQueue> queues = new HashMap<>();
public RankedCommand() { public RankedCommand() {
super("ranked", null); super("ranked", null);
@ -29,7 +31,7 @@ public class RankedCommand extends BasicCommand {
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(args.length < 1){ if(args.length < 1){
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§7ranked §8[§eSpielmodus§8]"); getModes(sender, "/ranked");
return; return;
}else if(!(sender instanceof ProxiedPlayer)) }else if(!(sender instanceof ProxiedPlayer))
return; return;
@ -43,14 +45,43 @@ public class RankedCommand extends BasicCommand {
} }
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
queues.get(mode) queues.get(mode).togglePlayer(player);
}
@Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
if(args.length > 1)
return new ArrayList<>();
List<String> result = ArenaMode.getAllRankedChatNames();
result.removeIf(name -> !name.startsWith(args[0]));
return result;
}
static void getModes(CommandSender sender, String precommand){
TextComponent start = new TextComponent();
TextComponent current = start;
for(ArenaMode mode : ArenaMode.getAllModes()){
if(!mode.hasChatName() || !mode.isRanked())
continue;
String command = precommand + mode.getChatName();
current.setBold(true);
current.setColor(ChatColor.GRAY);
current.setText(mode.getChatName() + " ");
current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e" + command).create()));
current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
if(current != start)
start.addExtra(current);
current = new TextComponent();
}
sender.sendMessage(start);
} }
private void checkForGames(){ private void checkForGames(){
for(WaitingQueue queue : queues.values()){ for(WaitingQueue queue : queues.values())
queue.checkForGames(); queue.checkForGames();
} }
}
private static class WaitingQueue{ private static class WaitingQueue{
@ -61,23 +92,63 @@ public class RankedCommand extends BasicCommand {
this.mode = mode; this.mode = mode;
} }
private void addPlayer(ProxiedPlayer player){ private void togglePlayer(ProxiedPlayer player){
players.add(new WaitingPlayer(player, mode)); for(WaitingPlayer wp : players){
if(wp.player == player){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cRanglistenspiel-Warteschlange verlassen");
players.remove(wp);
return;
}
}
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§aRanglistenspiel-Warteschlange betreten");
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Wiederhole den Befehl zum Verlassen der Warteschlange");
players.add(new WaitingPlayer(player, mode.getSchemType()));
}
private void removeFromAll(ProxiedPlayer player){
for(WaitingQueue queue : queues.values()){
Iterator<WaitingPlayer> it = queue.players.iterator();
while(it.hasNext()){
WaitingPlayer wp = it.next();
if(wp.player == player){
it.remove();
break;
}
}
}
} }
private void checkForGames(){ private void checkForGames(){
players.removeIf(wp -> !wp.doesStillWait()); players.removeIf(wp -> !wp.doesStillWait());
Map<WaitingPlayer, WaitingPlayer> inRange = new HashMap<>();
//Find games
for(WaitingPlayer wp1 : players){ for(WaitingPlayer wp1 : players){
for(WaitingPlayer wp2 : players){ if(inRange.containsValue(wp1))
if(wp1 == wp2)
continue; continue;
if(wp1.inRange(wp2)){ for(WaitingPlayer wp2 : players){
//TODO: Open game opportunity if(wp1 == wp2 || inRange.containsKey(wp2) || inRange.containsValue(wp2))
} continue;
if(wp1.inRange(wp2))
inRange.putIfAbsent(wp1, wp2);
} }
wp1.increment(); wp1.increment();
} }
for(Map.Entry<WaitingPlayer, WaitingPlayer> entry : inRange.entrySet()){
WaitingPlayer wp1 = entry.getKey();
WaitingPlayer wp2 = entry.getValue();
BungeeCore.send(wp1.player, BungeeCore.CHAT_PREFIX + "§eGegner gefunden! Ranglistenspiel startet.");
BungeeCore.send(wp2.player, BungeeCore.CHAT_PREFIX + "§eGegner gefunden! Ranglistenspiel startet.");
removeFromAll(wp1.player);
removeFromAll(wp2.player);
String serverName = wp1.player.getName() + " vs " + wp2.player.getName();
SubserverSystem.startArena(mode, mode.getRandomMap(), 0, 0, serverName, serverName.replace(' ', '_'), wp1.player.getUniqueId(), wp2.player.getUniqueId(), true);
}
} }
} }
@ -105,21 +176,15 @@ public class RankedCommand extends BasicCommand {
if(!player.isConnected()) if(!player.isConnected())
return false; return false;
//TODO: Check if has open match
Subserver subserver = Subserver.getSubserver(player); Subserver subserver = Subserver.getSubserver(player);
if(subserver == null) if(subserver == null)
return true; return true;
if(subserver.getType() == Servertype.ARENA){ if(subserver.getType() == Servertype.ARENA){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cRanglistenspiel-Warteschlange abgebrochen"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cRanglistenspiel-Warteschlange verlassen");
return false; return false;
} }
return true; return true;
} }
} }
private static class OpenMatch{
//TODO: Open matches
}
} }