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;
public enum ArenaMode {
AirShip,
import net.md_5.bungee.config.Configuration;
import java.util.*;
public class ArenaMode {
/*AirShip,
WarShip,
WarGear,
MiniWarGear,
WarGear7,
GearUp,
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.IOException;
import java.time.format.DateTimeFormatter;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
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> commands = new HashMap<>();
public static final Map<ArenaMode, List<String>> arenaMaps = new EnumMap<>(ArenaMode.class);
@Override
public void onEnable(){
@ -188,10 +186,7 @@ public class BungeeCore extends Plugin {
config.getString("db.password")
);
final Configuration maps = config.getSection("maps");
for(final String modeName : maps.getKeys()){
arenaMaps.put(ArenaMode.valueOf(modeName), maps.getStringList(modeName));
}
ArenaMode.init(config.getSection("games"));
final Configuration servers = config.getSection("servers");
for(final String serverName : servers.getKeys()){

Datei anzeigen

@ -30,15 +30,22 @@ public class SubserverSystem {
public static Subserver startArena(ArenaMode modus, String map){
int port = freePort(2500);
String serverName = modus.name() + (port - 2500);
String serverName = modus.getDisplayName() + (port - 2500);
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){
int port = freePort(2500);
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){
@ -77,20 +84,6 @@ public class SubserverSystem {
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){
int port = start;
boolean isFree = false;

Datei anzeigen

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

Datei anzeigen

@ -46,8 +46,8 @@ public class ChallengeCommand extends BasicCommand {
return;
}
ArenaMode mode = FightCommand.stringToArenaMode(args[1]);
if(mode == ArenaMode.UNKNOWN){
ArenaMode mode = ArenaMode.getByChat(args[1]);
if(mode == null){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[1]);
return;
}
@ -63,7 +63,7 @@ public class ChallengeCommand extends BasicCommand {
arena.sendPlayer(player);
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",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
}else{
@ -73,12 +73,12 @@ public class ChallengeCommand extends BasicCommand {
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(target, BungeeCore.CHAT_PREFIX + "§e" + player.getName() + " §7 hat dich zu 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.getDisplayName() + "-Kampf §7herausgefordert!");
BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um die Herausforderung anzunehmen",
"§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.connection.ProxiedPlayer;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.LinkedList;
public class FightCommand extends BasicCommand {
@ -21,38 +19,13 @@ public class FightCommand extends BasicCommand {
static String getMap(CommandSender sender, ArenaMode mode, String[] args){
if(args.length == 2){
String map = args[1].toLowerCase();
for(String realMap : BungeeCore.arenaMaps.get(mode)){
if(map.equalsIgnoreCase(realMap))
return realMap;
}
String realMap = mode.hasMap(args[1].toLowerCase());
if(realMap != null)
return realMap;
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDie gewünschte Arena gibt es nicht.");
return null;
}else{
List<String> l = BungeeCore.arenaMaps.get(mode);
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;
return mode.getRandomMap();
}
}
@ -77,37 +50,20 @@ public class FightCommand extends BasicCommand {
return;
}
String map = null;
Subserver arena;
ArenaMode mode = stringToArenaMode(args[0]);
ArenaMode mode = ArenaMode.getByChat(args[0]);
if(mode != ArenaMode.UNKNOWN){
map = getMap(sender, mode, args);
if(map == null)
return;
if(mode == null){
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[0]);
return;
}
switch(mode){
case AirShip:
arena = SubserverSystem.startArena(ArenaMode.AirShip, map);
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;
}
String map = getMap(sender, mode, args);
if(map == null)
return;
Subserver arena = SubserverSystem.startArena(mode, map);
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.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
ProxyServer.getInstance().broadcast(tc);
@ -116,20 +72,14 @@ public class FightCommand extends BasicCommand {
@Override
public Iterable<String> onTabComplete(CommandSender commandSender, String[] args) {
List<String> gamemodes = new ArrayList<>();
if(args.length == 1){
gamemodes.add("AirShip");
gamemodes.add("AS");
gamemodes.add("WarShip");
gamemodes.add("WS");
gamemodes.add("WarGear");
gamemodes.add("WG");
gamemodes.add("MiniWarGear");
gamemodes.add("MWG");
return ArenaMode.getAllChatNames();
}else if(args.length == 2){
ArenaMode mode = stringToArenaMode(args[1]);
gamemodes.addAll(BungeeCore.arenaMaps.get(mode));
ArenaMode mode = ArenaMode.getByChat(args[1]);
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");
fightID = rs.getInt("FightID");
startTime = rs.getTimestamp("StartTime");
spielmodus = ArenaMode.valueOf(rs.getString("Spielmodus"));
spielmodus = ArenaMode.getByInternal(rs.getString("Spielmodus"));
map = rs.getString("Map");
teamBlue = rs.getInt("TeamBlue");
teamRed = rs.getInt("TeamRed");