Archiviert
1
0

Modularising ArenaMode + adding support for different server versions

Dieser Commit ist enthalten in:
Lixfel 2019-11-11 09:18:48 +01:00
Ursprung b1721bce08
Commit 3044544724
7 geänderte Dateien mit 125 neuen und 109 gelöschten Zeilen

Datei anzeigen

@ -1,12 +1,93 @@
package de.steamwar.bungeecore; package de.steamwar.bungeecore;
public enum ArenaMode { import net.md_5.bungee.config.Configuration;
AirShip,
import java.util.*;
public class ArenaMode {
/*AirShip,
WarShip, WarShip,
WarGear, WarGear,
MiniWarGear, MiniWarGear,
WarGear7, WarGear7,
GearUp, GearUp,
EisZeit, EisZeit,
UNKNOWN UNKNOWN;*/
private static Map<String, ArenaMode> byChat = new HashMap<>();
private static Map<String, ArenaMode> byInternal = new HashMap<>();
private static Random random = new Random();
static void init(Configuration config){
for(String internalName : config.getKeys()){
new ArenaMode(internalName, config.getSection(internalName));
}
}
public static ArenaMode getByChat(String name){
return byChat.get(name.toLowerCase());
}
public static ArenaMode getByInternal(String name){
return byInternal.get(name);
}
public static List<String> getAllChatNames() {
List<String> chatNames = new LinkedList<>();
for(ArenaMode mode : byInternal.values()){
chatNames.addAll(mode.chatNames);
}
return chatNames;
}
private final String internalName;
private final String displayName;
private final List<String> chatNames;
private final String serverJar;
private final List<String> maps;
private ArenaMode(String internalName, Configuration config){
this.internalName = internalName;
this.displayName = config.getString("displayName");
this.serverJar = config.getString("serverJar");
this.chatNames = config.getStringList("chatNames");
this.maps = config.getStringList("maps");
byInternal.put(internalName, this);
for(String name : chatNames){
byChat.put(name.toLowerCase(), this);
}
}
public String getInternalName() {
return internalName;
}
public String getDisplayName() {
return displayName;
}
public String serverJar() {
return serverJar;
}
public String hasMap(String map){
for(String m : maps){
if(m.equalsIgnoreCase(map))
return m;
}
return null;
}
public String getRandomMap(){
return maps.get(random.nextInt(maps.size()));
}
public List<String> getMaps() {
return maps;
}
public String getChatName(){
return chatNames.get(0);
}
} }

Datei anzeigen

@ -25,7 +25,6 @@ import net.md_5.bungee.config.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -47,7 +46,6 @@ public class BungeeCore extends Plugin {
public static final Map<String, String> serverPermissions = new HashMap<>(); public static final Map<String, String> serverPermissions = new HashMap<>();
public static final Map<String, String> commands = new HashMap<>(); public static final Map<String, String> commands = new HashMap<>();
public static final Map<ArenaMode, List<String>> arenaMaps = new EnumMap<>(ArenaMode.class);
@Override @Override
public void onEnable(){ public void onEnable(){
@ -188,10 +186,7 @@ public class BungeeCore extends Plugin {
config.getString("db.password") config.getString("db.password")
); );
final Configuration maps = config.getSection("maps"); ArenaMode.init(config.getSection("games"));
for(final String modeName : maps.getKeys()){
arenaMaps.put(ArenaMode.valueOf(modeName), maps.getStringList(modeName));
}
final Configuration servers = config.getSection("servers"); final Configuration servers = config.getSection("servers");
for(final String serverName : servers.getKeys()){ for(final String serverName : servers.getKeys()){

Datei anzeigen

@ -30,15 +30,22 @@ public class SubserverSystem {
public static Subserver startArena(ArenaMode modus, String map){ public static Subserver startArena(ArenaMode modus, String map){
int port = freePort(2500); int port = freePort(2500);
String serverName = modus.name() + (port - 2500); String serverName = modus.getDisplayName() + (port - 2500);
return new Subserver(Servertype.ARENA, serverName, port, return new Subserver(Servertype.ARENA, serverName, port,
MC_SCRIPT, "-a", modus.name(), serverName, Integer.toString(port), map, "0"); MC_SCRIPT, "-a", modus.getInternalName(), serverName, Integer.toString(port), map, "0", modus.serverJar());
} }
public static Subserver startEventArena(EventFight eventFight, String serverName){ public static Subserver startEventArena(EventFight eventFight, String serverName){
int port = freePort(2500); int port = freePort(2500);
return new Subserver(Servertype.ARENA, serverName, port, return new Subserver(Servertype.ARENA, serverName, port,
MC_SCRIPT, "-a", eventFight.getSpielmodus().name(), serverName.replace(' ', '_') + eventFight.getStartTime().toLocalDateTime().format(EventCommand.TIME_FORMAT), Integer.toString(port), eventFight.getMap(), Integer.toString(eventFight.getFightID())); MC_SCRIPT, "-a", eventFight.getSpielmodus().getInternalName(), serverName.replace(' ', '_') + eventFight.getStartTime().toLocalDateTime().format(EventCommand.TIME_FORMAT), Integer.toString(port), eventFight.getMap(), Integer.toString(eventFight.getFightID()), eventFight.getSpielmodus().serverJar());
}
public static void sendToTestServer(ProxiedPlayer p, ArenaMode m, String map){
int port = freePort(4000);
new Bauserver(p.getName() + "s Bau", p.getUniqueId(), port,
MC_SCRIPT, "-a", m.getInternalName(), p.getName(), Integer.toString(port), map, "-1", m.serverJar()).sendPlayer(p);
} }
public static void sendToBauServer(ProxiedPlayer p, UUID owner){ public static void sendToBauServer(ProxiedPlayer p, UUID owner){
@ -77,20 +84,6 @@ public class SubserverSystem {
MC_SCRIPT, "-b", owner.toString(), Integer.toString(port)).sendPlayer(p); MC_SCRIPT, "-b", owner.toString(), Integer.toString(port)).sendPlayer(p);
} }
public static void sendToTestServer(ProxiedPlayer p, ArenaMode m, String map){
int port = freePort(4000);
new Bauserver(p.getName() + "s Bau", p.getUniqueId(), port,
MC_SCRIPT, "-a", m.name(), p.getName(), Integer.toString(port), map, "-1").sendPlayer(p);
}
public static void sendToHistoricTestServer(ProxiedPlayer p, ArenaMode m, String map){
int port = freePort(4000);
new Bauserver(p.getName() + "s Bau", p.getUniqueId(), port,
MC_SCRIPT, "-h", m.name(), p.getName(), Integer.toString(port), map, "-1").sendPlayer(p);
}
private static int freePort(int start){ private static int freePort(int start){
int port = start; int port = start;
boolean isFree = false; boolean isFree = false;

Datei anzeigen

@ -183,8 +183,8 @@ public class BauCommand {
return; return;
} }
ArenaMode mode = FightCommand.stringToArenaMode(command[2]); ArenaMode mode = ArenaMode.getByChat(command[2]);
if(mode == ArenaMode.UNKNOWN){ if(mode == null){
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + command[2]); BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + command[2]);
return; return;
} }
@ -196,10 +196,7 @@ public class BauCommand {
break; break;
} }
} }
if(mode == ArenaMode.WarGear7) SubserverSystem.sendToTestServer(p, mode, FightCommand.getMap(p, mode, new String[0]));
SubserverSystem.sendToHistoricTestServer(p, mode, FightCommand.getMap(p, mode, new String[0]));
else
SubserverSystem.sendToTestServer(p, mode, FightCommand.getMap(p, mode, new String[0]));
}); });
} }

Datei anzeigen

@ -46,8 +46,8 @@ public class ChallengeCommand extends BasicCommand {
return; return;
} }
ArenaMode mode = FightCommand.stringToArenaMode(args[1]); ArenaMode mode = ArenaMode.getByChat(args[1]);
if(mode == ArenaMode.UNKNOWN){ if(mode == null){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[1]); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[1]);
return; return;
} }
@ -63,7 +63,7 @@ public class ChallengeCommand extends BasicCommand {
arena.sendPlayer(player); arena.sendPlayer(player);
arena.sendPlayer(target); arena.sendPlayer(target);
BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§e" + mode.name() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName(), BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§e" + mode.getDisplayName() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName(),
"§aZuschauen", "§aZuschauen",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
}else{ }else{
@ -73,12 +73,12 @@ public class ChallengeCommand extends BasicCommand {
challenges.get(player).add(target); challenges.get(player).add(target);
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + target.getName() + " §7zu einem §e" + mode.name() + "-Kampf §7herausgefordert!"); BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + target.getName() + " §7zu einem §e" + mode.getDisplayName() + "-Kampf §7herausgefordert!");
BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§e" + player.getName() + " §7 hat dich zu einem §e" + mode.name() + "-Kampf §7herausgefordert!"); BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§e" + player.getName() + " §7 hat dich zu einem §e" + mode.getDisplayName() + "-Kampf §7herausgefordert!");
BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um die Herausforderung anzunehmen", BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um die Herausforderung anzunehmen",
"§aHerausforderung annehmen", "§aHerausforderung annehmen",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.name())); new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.getChatName()));
} }
} }

Datei anzeigen

@ -9,9 +9,7 @@ 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.util.ArrayList; import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class FightCommand extends BasicCommand { public class FightCommand extends BasicCommand {
@ -21,38 +19,13 @@ public class FightCommand extends BasicCommand {
static String getMap(CommandSender sender, ArenaMode mode, String[] args){ static String getMap(CommandSender sender, ArenaMode mode, String[] args){
if(args.length == 2){ if(args.length == 2){
String map = args[1].toLowerCase(); String realMap = mode.hasMap(args[1].toLowerCase());
for(String realMap : BungeeCore.arenaMaps.get(mode)){ if(realMap != null)
if(map.equalsIgnoreCase(realMap)) return realMap;
return realMap;
}
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDie gewünschte Arena gibt es nicht."); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDie gewünschte Arena gibt es nicht.");
return null; return null;
}else{ }else{
List<String> l = BungeeCore.arenaMaps.get(mode); return mode.getRandomMap();
Random rand = new Random();
return l.get(rand.nextInt(l.size()));
}
}
static ArenaMode stringToArenaMode(String input){
switch(input.toLowerCase()){
case "as":
case "airship":
return ArenaMode.AirShip;
case "ws":
case "warship":
return ArenaMode.WarShip;
case "wg":
case "wargear":
return ArenaMode.WarGear;
case "mwg":
case "miniwargear":
return ArenaMode.MiniWarGear;
case "wargear1.7":
return ArenaMode.WarGear7;
default:
return ArenaMode.UNKNOWN;
} }
} }
@ -77,37 +50,20 @@ public class FightCommand extends BasicCommand {
return; return;
} }
String map = null; ArenaMode mode = ArenaMode.getByChat(args[0]);
Subserver arena;
ArenaMode mode = stringToArenaMode(args[0]);
if(mode != ArenaMode.UNKNOWN){ if(mode == null){
map = getMap(sender, mode, args); BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[0]);
if(map == null) return;
return;
} }
switch(mode){ String map = getMap(sender, mode, args);
case AirShip: if(map == null)
arena = SubserverSystem.startArena(ArenaMode.AirShip, map); return;
break;
case WarShip:
arena = SubserverSystem.startArena(ArenaMode.WarShip, map);
break;
case WarGear:
arena = SubserverSystem.startArena(ArenaMode.WarGear, map);
break;
case MiniWarGear:
arena = SubserverSystem.startArena(ArenaMode.MiniWarGear, map);
break;
case UNKNOWN:
default:
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[0]);
return;
}
Subserver arena = SubserverSystem.startArena(mode, map);
arena.sendPlayer(player); arena.sendPlayer(player);
TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um §e" + mode.name() + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!"); TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um §e" + mode.getDisplayName() + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!");
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aGegen §7" + player.getName() + " §ekämpfen").create())); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aGegen §7" + player.getName() + " §ekämpfen").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
ProxyServer.getInstance().broadcast(tc); ProxyServer.getInstance().broadcast(tc);
@ -116,20 +72,14 @@ public class FightCommand extends BasicCommand {
@Override @Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) { public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
List<String> gamemodes = new ArrayList<>();
if(args.length == 1){ if(args.length == 1){
gamemodes.add("AirShip"); return ArenaMode.getAllChatNames();
gamemodes.add("AS");
gamemodes.add("WarShip");
gamemodes.add("WS");
gamemodes.add("WarGear");
gamemodes.add("WG");
gamemodes.add("MiniWarGear");
gamemodes.add("MWG");
}else if(args.length == 2){ }else if(args.length == 2){
ArenaMode mode = stringToArenaMode(args[1]); ArenaMode mode = ArenaMode.getByChat(args[1]);
gamemodes.addAll(BungeeCore.arenaMaps.get(mode)); if(mode == null)
return new LinkedList<>();
return mode.getMaps();
} }
return gamemodes; return new LinkedList<>();
} }
} }

Datei anzeigen

@ -28,7 +28,7 @@ public class EventFight implements Comparable<EventFight> {
eventID = rs.getInt("EventID"); eventID = rs.getInt("EventID");
fightID = rs.getInt("FightID"); fightID = rs.getInt("FightID");
startTime = rs.getTimestamp("StartTime"); startTime = rs.getTimestamp("StartTime");
spielmodus = ArenaMode.valueOf(rs.getString("Spielmodus")); spielmodus = ArenaMode.getByInternal(rs.getString("Spielmodus"));
map = rs.getString("Map"); map = rs.getString("Map");
teamBlue = rs.getInt("TeamBlue"); teamBlue = rs.getInt("TeamBlue");
teamRed = rs.getInt("TeamRed"); teamRed = rs.getInt("TeamRed");