geforkt von SteamWar/BungeeCore
Merge pull request 'Arena Merging 2.0' (#329) from arena_merging_2.0 into master
Reviewed-on: SteamWar/BungeeCore#329 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
0a5c89b8b7
@ -95,11 +95,13 @@ public class ArenaMode {
|
||||
private final String config;
|
||||
private final List<String> maps;
|
||||
private final boolean historic;
|
||||
private final String internalName;
|
||||
|
||||
private final boolean ranked;
|
||||
private final String schemType;
|
||||
|
||||
private ArenaMode(String internalName, Configuration config){
|
||||
this.internalName = internalName;
|
||||
this.folder = config.getString("Server.Folder");
|
||||
this.serverJar = config.getString("Server.ServerJar");
|
||||
this.config = internalName + ".yml";
|
||||
@ -172,4 +174,8 @@ public class ArenaMode {
|
||||
public String getSchemType() {
|
||||
return schemType;
|
||||
}
|
||||
|
||||
public String getInternalName() {
|
||||
return internalName;
|
||||
}
|
||||
}
|
||||
|
@ -37,10 +37,13 @@ public class ServerStarter {
|
||||
private Portrange portrange = BAU_PORTS;
|
||||
private Function<Integer, String> serverNameProvider = port -> node.getName() + port;
|
||||
private BooleanSupplier startCondition = () -> true;
|
||||
private ServerConstructor constructor = (serverName, port, builder, shutdownCallback) -> new Subserver(Servertype.ARENA, serverName, port, builder, shutdownCallback);
|
||||
private Runnable worldSetup = () -> {};
|
||||
private String worldName = null;
|
||||
private Runnable worldCleanup = () -> {};
|
||||
private boolean allowMerge = false;
|
||||
private String fightMap = null;
|
||||
private String gameMode = null;
|
||||
private ServerConstructor constructor = (serverName, port, builder, shutdownCallback) -> new Arenaserver(serverName, gameMode, fightMap, allowMerge, port, builder, shutdownCallback);
|
||||
|
||||
private final Set<ProxiedPlayer> playersToSend = new HashSet<>();
|
||||
private final Map<String, String> arguments = new HashMap<>();
|
||||
@ -49,6 +52,9 @@ public class ServerStarter {
|
||||
portrange = ARENA_PORTS;
|
||||
serverNameProvider = port -> mode.getDisplayName() + (port - portrange.start);
|
||||
serverJar = mode.serverJar();
|
||||
allowMerge = true;
|
||||
fightMap = map;
|
||||
gameMode = mode.getInternalName();
|
||||
directory = new File(SERVER_PATH, mode.getFolder());
|
||||
arguments.put("config", mode.getConfig());
|
||||
tempWorld(SERVER_PATH + mode.getFolder() + "/arenas/" + map);
|
||||
@ -61,6 +67,8 @@ public class ServerStarter {
|
||||
worldDir = EVENT_PATH;
|
||||
worldCleanup = () -> {};
|
||||
arguments.put("fightID", String.valueOf(eventFight.getFightID()));
|
||||
fightMap = eventFight.getMap();
|
||||
gameMode = eventFight.getSpielmodus().getInternalName();
|
||||
|
||||
String serverName = Team.get(eventFight.getTeamBlue()).getTeamKuerzel() + " vs " + Team.get(eventFight.getTeamRed()).getTeamKuerzel();
|
||||
serverNameProvider = port -> serverName;
|
||||
|
@ -262,7 +262,7 @@ public class BauCommand extends BasicCommand {
|
||||
}
|
||||
|
||||
private static void testarena(ProxiedPlayer p, String[] args){
|
||||
FightCommand.createArena(p, "/bau testarena ", args, 1, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, map, p).start()));
|
||||
FightCommand.createArena(p, "/bau testarena ", false, args, 1, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, map, p).start()));
|
||||
}
|
||||
|
||||
private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){
|
||||
|
@ -71,7 +71,7 @@ public class ChallengeCommand extends BasicCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
FightCommand.createArena(sender, "/challenge " + target.getName() + " ", args, 1, false, (player, mode, map) -> {
|
||||
FightCommand.createArena(sender, "/challenge " + target.getName() + " ", false, args, 1, false, (player, mode, map) -> {
|
||||
if(challenges.containsKey(target) && challenges.get(target).contains(player)){
|
||||
challenges.remove(target);
|
||||
challenges.remove(player);
|
||||
|
@ -20,6 +20,8 @@
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.bungeecore.inventory.SWInventory;
|
||||
import de.steamwar.bungeecore.inventory.SWItem;
|
||||
import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.messages.ChatSender;
|
||||
@ -42,6 +44,7 @@ import java.util.LinkedList;
|
||||
* Sollte der ArenaMode fehlen, kann er mit getMode() bestimmt werden.
|
||||
* Sollte die Map fehlen, kann sie mit getMap() bestimmt werden.
|
||||
*/
|
||||
|
||||
public class FightCommand extends BasicCommand {
|
||||
|
||||
public FightCommand() {
|
||||
@ -126,7 +129,7 @@ public class FightCommand extends BasicCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void createArena(CommandSender s, String precommand, String[] args, int startArg, boolean historic, FightCallback callback){
|
||||
static void createArena(CommandSender s, String precommand, boolean allowMerging, String[] args, int startArg, boolean historic, FightCallback callback){
|
||||
if(!(s instanceof ProxiedPlayer))
|
||||
return;
|
||||
|
||||
@ -167,12 +170,55 @@ public class FightCommand extends BasicCommand {
|
||||
if(map == null)
|
||||
return;
|
||||
|
||||
callback.run(player, mode, map);
|
||||
if(!allowMerging) {
|
||||
callback.run(player, mode, map);
|
||||
} else {
|
||||
suggestMerging(player, mode, map, callback);
|
||||
}
|
||||
}
|
||||
|
||||
public static void suggestMerging(ProxiedPlayer player, ArenaMode mode, String map, FightCallback declineMerge) {
|
||||
Arenaserver mergable = null;
|
||||
synchronized (Subserver.getServerList()) {
|
||||
for (Subserver subserver : Subserver.getServerList()) {
|
||||
if(subserver instanceof Arenaserver) {
|
||||
Arenaserver arenaserver = (Arenaserver) subserver;
|
||||
if(mode.getInternalName().equals(arenaserver.getMode()) && map.equals(arenaserver.getMap()) && arenaserver.isAllowMerge() && arenaserver.getServer().getPlayers().size() == 1) {
|
||||
mergable = arenaserver;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mergable == null) {
|
||||
declineMerge.run(player, mode, map);
|
||||
return;
|
||||
}
|
||||
|
||||
SWInventory inventory = new SWInventory(player, 9, Message.parse("FIGHT_MERGE_TITLE", player));
|
||||
inventory.addItem(0, new SWItem(Message.parse("FIGHT_MERGE_DECLINE", player), 1), click -> {
|
||||
inventory.close();
|
||||
declineMerge.run(player, mode, map);
|
||||
});
|
||||
Arenaserver finalMergable = mergable;
|
||||
SWItem item = new SWItem(Message.parse("FIGHT_MERGE_INFO", player, mode.getDisplayName(), finalMergable.getMap()), 11);
|
||||
item.addLore(Message.parse("FIGHT_MERGE_INFO_LORE_1", player, finalMergable.getServer().getPlayers().toArray(new ProxiedPlayer[1])[0].getName()));
|
||||
inventory.addItem(4, item, click -> {});
|
||||
inventory.addItem(8, new SWItem(Message.parse("FIGHT_MERGE_ACCEPT", player), 10), click -> {
|
||||
if(Subserver.getServerList().contains(finalMergable)) {
|
||||
finalMergable.sendPlayer(player);
|
||||
} else {
|
||||
Message.send("FIGHT_MERGE_OFFLINE", player);
|
||||
declineMerge.run(player, mode, map);
|
||||
}
|
||||
});
|
||||
inventory.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
createArena(sender, "/fight ", args, 0, false, (player, mode, map) -> {
|
||||
createArena(sender, "/fight ", true, args, 0, false, (player, mode, map) -> {
|
||||
Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).start();
|
||||
Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER"
|
||||
, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName());
|
||||
|
@ -35,7 +35,7 @@ public class HistoricCommand extends BasicCommand {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
FightCommand.createArena(sender, "/historic ", args, 0, true, (player, mode, map) -> {
|
||||
FightCommand.createArena(sender, "/historic ", true, args, 0, true, (player, mode, map) -> {
|
||||
Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).start();
|
||||
Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER"
|
||||
, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName());
|
||||
|
@ -610,3 +610,11 @@ RANK_NEEDED_FIGHTS_LEFT={0} §8(§7noch §e{1}§7 Kämpfe nötig§8)
|
||||
MODIFICATION_BAN_MESSAGE=Du hast probiert den FabricModSender zu umgehen / zu modifizieren!
|
||||
MODIFICATION_BAN_LOG={0} hat probiert den Fabric Mod Sender zu editieren / umzugehen!
|
||||
MODIFICATION_CHECK_SUCCESS=§eDeine Mods wurden geprüft und du darfst nun auf Arenen joinen!
|
||||
|
||||
#Arena Merging
|
||||
FIGHT_MERGE_TITLE=Gleicher Kampf gefunden!
|
||||
FIGHT_MERGE_DECLINE=Neue Arena starten
|
||||
FIGHT_MERGE_ACCEPT=Kampf beitreten
|
||||
FIGHT_MERGE_INFO_LORE_1=§8Von: §e{0}
|
||||
FIGHT_MERGE_OFFLINE=§7Die vorgeschlagene Arena wurde in der Zwischenzeit beendet, es wird eine neue Arena gestartet.
|
||||
FIGHT_MERGE_INFO=§e{0}§8: §e{1}
|
In neuem Issue referenzieren
Einen Benutzer sperren