Adding support to multiple arenas
Dieser Commit ist enthalten in:
Ursprung
c4390df7fa
Commit
ffa69b1929
@ -1,8 +1,8 @@
|
|||||||
package de.steamwar.bungeecore;
|
package de.steamwar.bungeecore;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.arenasystem.ArenaMode;
|
||||||
import de.steamwar.bungeecore.arenasystem.ArenaSystem;
|
import de.steamwar.bungeecore.arenasystem.ArenaSystem;
|
||||||
import de.steamwar.bungeecore.commands.*;
|
import de.steamwar.bungeecore.commands.*;
|
||||||
import de.warking.bungeecore.commands.*;
|
|
||||||
import de.steamwar.bungeecore.sql.sql;
|
import de.steamwar.bungeecore.sql.sql;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
@ -16,12 +16,12 @@ import java.io.IOException;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class BungeeCore extends Plugin {
|
public class BungeeCore extends Plugin {
|
||||||
|
|
||||||
private Configuration config;
|
|
||||||
public static BungeeCore instance;
|
public static BungeeCore instance;
|
||||||
public static String ChatPrefix;
|
public static String ChatPrefix;
|
||||||
public static final String TeamchatPrefix = "§4T§7c§r §e";
|
public static final String TeamchatPrefix = "§4T§7c§r §e";
|
||||||
@ -29,12 +29,14 @@ public class BungeeCore extends Plugin {
|
|||||||
public static String LobbyServer;
|
public static String LobbyServer;
|
||||||
public static String [] BroadCastMsgs;
|
public static String [] BroadCastMsgs;
|
||||||
public static int LastBroadCast = 0;
|
public static int LastBroadCast = 0;
|
||||||
public static final HashMap<String, String> serverPermissions = new HashMap<>();
|
public static final Map<String, String> serverPermissions = new HashMap<>();
|
||||||
public static final HashMap<String, String> commands = new HashMap<>();
|
public static final Map<String, String> commands = new HashMap<>();
|
||||||
|
public static final Map<ArenaMode, List<String>> arenaMaps = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
instance = this;
|
instance = this;
|
||||||
|
Configuration config;
|
||||||
try{
|
try{
|
||||||
if(!getDataFolder().exists()){
|
if(!getDataFolder().exists()){
|
||||||
getDataFolder().mkdir();
|
getDataFolder().mkdir();
|
||||||
@ -89,11 +91,15 @@ public class BungeeCore extends Plugin {
|
|||||||
commands.put("/bau", "");
|
commands.put("/bau", "");
|
||||||
commands.remove("/bauserver");
|
commands.remove("/bauserver");
|
||||||
|
|
||||||
|
final Configuration maps = config.getSection("maps");
|
||||||
|
for(final String modeName : maps.getKeys()){
|
||||||
|
arenaMaps.put(ArenaMode.valueOf(modeName), maps.getStringList(modeName));
|
||||||
|
}
|
||||||
|
|
||||||
addCmd(new TeamchatCommand());
|
addCmd(new TeamchatCommand());
|
||||||
addCmd(new MsgCommand());
|
addCmd(new MsgCommand());
|
||||||
addCmd(new RCommand());
|
addCmd(new RCommand());
|
||||||
addCmd(new PingCommand());
|
addCmd(new PingCommand());
|
||||||
//addCmd(new DenyCommand("list", "pl", "plugins", "ver", "version", "about"));
|
|
||||||
addCmd(new WebpwCommand());
|
addCmd(new WebpwCommand());
|
||||||
addCmd(new AlertCommand());
|
addCmd(new AlertCommand());
|
||||||
addCmd(new KickCommand());
|
addCmd(new KickCommand());
|
||||||
@ -109,7 +115,7 @@ public class BungeeCore extends Plugin {
|
|||||||
if(LastBroadCast == BroadCastMsgs.length){
|
if(LastBroadCast == BroadCastMsgs.length){
|
||||||
LastBroadCast = 0;
|
LastBroadCast = 0;
|
||||||
}
|
}
|
||||||
}, 5, 5, TimeUnit.MINUTES);
|
}, 10, 10, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,29 +16,27 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Arena implements Runnable{
|
public class Arena implements Runnable{
|
||||||
|
|
||||||
public final String serverName;
|
final String serverName;
|
||||||
public final int arenenNummer;
|
final int arenenNummer;
|
||||||
public final ArenaMode spielModus;
|
public final ArenaMode spielModus;
|
||||||
|
|
||||||
private Process p;
|
private Process p;
|
||||||
private PrintWriter writer;
|
private PrintWriter writer;
|
||||||
public ServerInfo server;
|
public ServerInfo server;
|
||||||
private String map;
|
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
|
|
||||||
private final List<ProxiedPlayer> cachedPlayers = new ArrayList<>();
|
private final List<ProxiedPlayer> cachedPlayers = new ArrayList<>();
|
||||||
private final List<ProxiedPlayer> players = new ArrayList<>();
|
private final List<ProxiedPlayer> players = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
public Arena(ArenaMode modus, int id, String map){
|
Arena(ArenaMode modus, int id, String map){
|
||||||
spielModus = modus;
|
spielModus = modus;
|
||||||
arenenNummer = id;
|
arenenNummer = id;
|
||||||
serverName = modus.name() + id;
|
serverName = modus.name() + id;
|
||||||
this.map = map;
|
|
||||||
int port = 2500 + arenenNummer;
|
int port = 2500 + arenenNummer;
|
||||||
ProcessBuilder pb = new ProcessBuilder(
|
ProcessBuilder pb = new ProcessBuilder(
|
||||||
"/home/minecraft/mc",
|
"/home/minecraft/mc",
|
||||||
"-a", modus.name(), serverName, Integer.toString(port), "Arena");
|
"-a", modus.name(), serverName, Integer.toString(port), map);
|
||||||
try{
|
try{
|
||||||
p = pb.start();
|
p = pb.start();
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, this);
|
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, this);
|
||||||
@ -108,7 +106,7 @@ public class Arena implements Runnable{
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean inArena(ProxiedPlayer p){
|
boolean inArena(ProxiedPlayer p){
|
||||||
for(ProxiedPlayer ap : cachedPlayers)
|
for(ProxiedPlayer ap : cachedPlayers)
|
||||||
if(ap.equals(p))
|
if(ap.equals(p))
|
||||||
return true;
|
return true;
|
||||||
|
@ -25,8 +25,8 @@ public class ArenaSystem {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Arena startServer(ArenaMode modus){
|
public static Arena startServer(ArenaMode modus, String map){
|
||||||
Arena arena = new Arena(modus, freeId());
|
Arena arena = new Arena(modus, freeId(), map);
|
||||||
arenen.add(arena);
|
arenen.add(arena);
|
||||||
return arena;
|
return arena;
|
||||||
}
|
}
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|
||||||
|
|
||||||
public class DenyCommand extends Command {
|
|
||||||
|
|
||||||
public DenyCommand(String cmd, String ...aliases) {
|
|
||||||
super(cmd, "", aliases);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
|
||||||
if(sender instanceof ProxiedPlayer){
|
|
||||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
|
||||||
player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cUnbekannter Befehl."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -14,6 +14,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class FightCommand extends Command {
|
public class FightCommand extends Command {
|
||||||
|
|
||||||
@ -21,9 +22,25 @@ public class FightCommand extends Command {
|
|||||||
super("fight", "");
|
super("fight", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private 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;
|
||||||
|
}
|
||||||
|
sender.sendMessage(BungeeCore.ChatPrefix + "§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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(args.length != 1){
|
if(args.length != 1 && args.length != 2){
|
||||||
sender.sendMessage(BungeeCore.ChatPrefix + "§7Mit §e/fight §7kannst du einen neuen Kampf starten!");
|
sender.sendMessage(BungeeCore.ChatPrefix + "§7Mit §e/fight §7kannst du einen neuen Kampf starten!");
|
||||||
sender.sendMessage(BungeeCore.ChatPrefix + "/fight AirShip §8- §7Starte einen §eAirShip§8-§7Kampf§8!");
|
sender.sendMessage(BungeeCore.ChatPrefix + "/fight AirShip §8- §7Starte einen §eAirShip§8-§7Kampf§8!");
|
||||||
sender.sendMessage(BungeeCore.ChatPrefix + "/fight WarShip §8- §7Starte einen §eWarShip§8-§7Kampf§8!");
|
sender.sendMessage(BungeeCore.ChatPrefix + "/fight WarShip §8- §7Starte einen §eWarShip§8-§7Kampf§8!");
|
||||||
@ -40,23 +57,36 @@ public class FightCommand extends Command {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String map;
|
||||||
Arena arena;
|
Arena arena;
|
||||||
switch(args[0].toLowerCase()){
|
switch(args[0].toLowerCase()){
|
||||||
case "as":
|
case "as":
|
||||||
case "airship":
|
case "airship":
|
||||||
arena = ArenaSystem.startServer(ArenaMode.AirShip);
|
map = getMap(sender, ArenaMode.AirShip, args);
|
||||||
|
if(map == null)
|
||||||
|
return;
|
||||||
|
arena = ArenaSystem.startServer(ArenaMode.AirShip, map);
|
||||||
break;
|
break;
|
||||||
case "ws":
|
case "ws":
|
||||||
case "warship":
|
case "warship":
|
||||||
arena = ArenaSystem.startServer(ArenaMode.WarShip);
|
map = getMap(sender, ArenaMode.WarShip, args);
|
||||||
|
if(map == null)
|
||||||
|
return;
|
||||||
|
arena = ArenaSystem.startServer(ArenaMode.WarShip, map);
|
||||||
break;
|
break;
|
||||||
case "wg":
|
case "wg":
|
||||||
case "wargear":
|
case "wargear":
|
||||||
arena = ArenaSystem.startServer(ArenaMode.WarGear);
|
map = getMap(sender, ArenaMode.WarGear, args);
|
||||||
|
if(map == null)
|
||||||
|
return;
|
||||||
|
arena = ArenaSystem.startServer(ArenaMode.WarGear, map);
|
||||||
break;
|
break;
|
||||||
case "mwg":
|
case "mwg":
|
||||||
case "miniwargear":
|
case "miniwargear":
|
||||||
arena = ArenaSystem.startServer(ArenaMode.MiniWarGear);
|
map = getMap(sender, ArenaMode.MiniWarGear, args);
|
||||||
|
if(map == null)
|
||||||
|
return;
|
||||||
|
arena = ArenaSystem.startServer(ArenaMode.MiniWarGear, map);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[0]);
|
sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[0]);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren