SteamWar/BungeeCore
Archiviert
13
2

Reintegrating with PersistentBungeeCore

Dieser Commit ist enthalten in:
Travis CI 2019-06-22 23:38:01 +02:00
Ursprung 7b2cc88718
Commit 5ab0bd32a7
14 geänderte Dateien mit 164 neuen und 653 gelöschten Zeilen

1
.gitignore vendored
Datei anzeigen

@ -1,3 +1,2 @@
.idea .idea
target target
dependency-reduced-pom.xml

11
pom.xml
Datei anzeigen

@ -19,6 +19,10 @@
<id>bungeecord-repo</id> <id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url> <url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository> </repository>
<repository>
<id>steamwar</id>
<url>https://steamwar.de:81/maven</url>
</repository>
</repositories> </repositories>
<build> <build>
@ -51,5 +55,12 @@
<type>jar</type> <type>jar</type>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>steamwar</groupId>
<artifactId>PersistentBungeeCore</artifactId>
<version>1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

Datei anzeigen

@ -1,4 +1,4 @@
package de.steamwar.bungeecore.arenasystem; package de.steamwar.bungeecore;
public enum ArenaMode { public enum ArenaMode {
AirShip, AirShip,

Datei anzeigen

@ -1,8 +1,5 @@
package de.steamwar.bungeecore; package de.steamwar.bungeecore;
import de.steamwar.bungeecore.arenasystem.ArenaMode;
import de.steamwar.bungeecore.arenasystem.ArenaSystem;
import de.steamwar.bungeecore.bausystem.BauSystem;
import de.steamwar.bungeecore.commands.*; import de.steamwar.bungeecore.commands.*;
import de.steamwar.bungeecore.sql.WarkingUser; import de.steamwar.bungeecore.sql.WarkingUser;
import de.steamwar.bungeecore.sql.sql; import de.steamwar.bungeecore.sql.sql;
@ -31,8 +28,8 @@ public class BungeeCore extends Plugin {
public static final String TeamchatPrefix = "§4T§7c§r §e"; public static final String TeamchatPrefix = "§4T§7c§r §e";
public static final DateTimeFormatter DateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy"); public static final DateTimeFormatter DateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy");
public static String LobbyServer; public static String LobbyServer;
public static String [] BroadCastMsgs; private static String [] BroadCastMsgs;
public static int LastBroadCast = 0; private static int LastBroadCast = 0;
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 HashMap<>(); public static final Map<ArenaMode, List<String>> arenaMaps = new HashMap<>();
@ -123,16 +120,14 @@ public class BungeeCore extends Plugin {
} }
}, 10, 10, TimeUnit.MINUTES); }, 10, 10, TimeUnit.MINUTES);
Persistent.setChatPrefix(ChatPrefix);
Persistent.setLobbyServer(LobbyServer);
getProxy().getScheduler().schedule(this, WarkingUser::clearCache, 1, 1, TimeUnit.HOURS); getProxy().getScheduler().schedule(this, WarkingUser::clearCache, 1, 1, TimeUnit.HOURS);
} }
@Override @Override
public void onDisable(){ public void onDisable(){
ArenaSystem.shutdown();
BauSystem.shutdown();
sql.close(); sql.close();
getProxy().getPluginManager().unregisterCommands(this);
getProxy().getPluginManager().unregisterListeners(this);
} }
static void log(final String message, final ServerInfo server){ static void log(final String message, final ServerInfo server){

Datei anzeigen

@ -1,11 +1,5 @@
package de.steamwar.bungeecore; package de.steamwar.bungeecore;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import de.steamwar.bungeecore.arenasystem.Arena;
import de.steamwar.bungeecore.arenasystem.ArenaSystem;
import de.steamwar.bungeecore.bausystem.BauServer;
import de.steamwar.bungeecore.bausystem.BauSystem;
import de.steamwar.bungeecore.commands.BauCommand; import de.steamwar.bungeecore.commands.BauCommand;
import de.steamwar.bungeecore.sql.BannedUserIPs; import de.steamwar.bungeecore.sql.BannedUserIPs;
import de.steamwar.bungeecore.sql.WarkingUser; import de.steamwar.bungeecore.sql.WarkingUser;
@ -17,14 +11,13 @@ import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; 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.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.Connection;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.*; import net.md_5.bungee.api.event.*;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
@ -70,7 +63,6 @@ public class PlayerListener implements Listener {
} }
} }
} }
} }
@EventHandler @EventHandler
@ -118,22 +110,12 @@ public class PlayerListener implements Listener {
break; break;
} }
if(player.getPendingConnection().getVersion() < 335){ Map<String, String> modlist = player.getModList();
player.sendMessage(BungeeCore.ChatPrefix + "§cWir empfehlen die Minecraft-Version 1.12.2"); for(String key : modlist.keySet()){
System.out.println(key + " > " + modlist.get(key));
} }
if(player.isForgeUser())
ByteArrayDataOutput output = ByteStreams.newDataOutput(); System.out.println("Forge user!");
output.writeUTF("FML|HS");
if(player.getPendingConnection().getVersion() > 340){
//1.13+
player.sendData("minecraft:register", output.toByteArray());
}else{
//1.12-
player.sendData("REGISTER", output.toByteArray());
}
player.sendData("FML|HS", new byte[]{0, 2, 0, 0, 0, 0});
} }
/** To redirect players to the lobby in case of server closure. */ /** To redirect players to the lobby in case of server closure. */
@ -163,21 +145,6 @@ public class PlayerListener implements Listener {
ev.setCancelServer(kickTo); ev.setCancelServer(kickTo);
} }
@EventHandler
public void onServerSwitchEvent(ServerSwitchEvent e){
ProxiedPlayer p = e.getPlayer();
Arena a = ArenaSystem.getArena(p);
if(a != null && !p.getServer().getInfo().equals(a.server)){
a.removePlayer(p);
return;
}
BauServer bau = BauSystem.getBau(p);
if(bau != null && !p.getServer().getInfo().equals(bau.getServer())){
bau.removePlayer(p);
}
}
@EventHandler @EventHandler
public void onChatEvent(ChatEvent e){ public void onChatEvent(ChatEvent e){
if(e.getMessage().startsWith("/")){ if(e.getMessage().startsWith("/")){
@ -199,7 +166,9 @@ public class PlayerListener implements Listener {
e.setCancelled(true); e.setCancelled(true);
return; return;
} }
if(ArenaSystem.inArena(sender))
Subserver subserver = Subserver.getSubserver(sender);
if(subserver != null && subserver.getType() == Servertype.ARENA)
return; return;
String name = sender.getDisplayName(); String name = sender.getDisplayName();
@ -224,7 +193,8 @@ public class PlayerListener implements Listener {
String msg = name + chatsuffix + message; String msg = name + chatsuffix + message;
for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){ for(ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
if(target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN && !ArenaSystem.inArena(target)){ Subserver targetServer = Subserver.getSubserver(target);
if(target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN && (targetServer == null || targetServer.getType() != Servertype.ARENA)){
target.sendMessage(msg); target.sendMessage(msg);
} }
} }
@ -265,93 +235,4 @@ public class PlayerListener implements Listener {
} }
} }
} }
@EventHandler
public void onPluginMessageEvent(PluginMessageEvent e){
System.out.println(e.getSender().getAddress().getHostString() + " " + e.getTag() + " " + Arrays.toString(e.getData()));
if(!e.getTag().equals("FML|HS")){
return;
}
e.setCancelled(true);
byte[] data = e.getData();
ProxiedPlayer p = getPlayer(e.getSender());
switch(data[0]){
case 2:
int numMods = readVarInt(data, 1);
System.out.println("Number of mods: " + numMods);
int bytePos = 1 + readVarIntLength(data, 1);
for(int i = 0; i < numMods; i++){
byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1);
bytePos += 1 + data[bytePos];
byte[] version = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1);
bytePos += 1 + data[bytePos];
System.out.println(new String(name) + " " + new String(version));
}
p.sendData("FML|HS", new byte[]{2, 0});
//p.sendData("FML|HS", new byte[]{2, 1, 9, 109, 105, 110, 101, 99, 114, 97, 102, 116, 6, 49, 46, 49, 50, 46, 50});
break;
case -1:
switch(data[1]){
case 2:
p.sendData("FML|HS", new byte[]{3, 0, 1, 97, 0, 0, 0});
break;
case 3:
p.sendData("FML|HS", new byte[]{-1, 2});
break;
case 4:
p.sendData("FML|HS", new byte[]{-1, 3});
break;
default:
break;
}
break;
case 1:
default:
break;
}
}
private static ProxiedPlayer getPlayer(Connection c){
for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()){
if(p.getPendingConnection().getAddress().equals(c.getAddress())){
return p;
}
}
return null;
}
private static int readVarInt(byte[] array, int startPos) {
int numRead = 0;
int result = 0;
byte read;
do {
read = array[startPos + numRead];
int value = (read & 0b01111111);
result |= (value << (7 * numRead));
numRead++;
if (numRead > 5) {
break;
}
} while ((read & 0b10000000) != 0);
return result;
}
private static int readVarIntLength(byte[] array, int startPos) {
int numRead = 0;
byte read;
do {
read = array[startPos + numRead];
numRead++;
if (numRead > 5) {
break;
}
} while ((read & 0b10000000) != 0);
return numRead;
}
} }

Datei anzeigen

@ -0,0 +1,85 @@
package de.steamwar.bungeecore;
import de.steamwar.bungeecore.sql.Bauwelt;
import de.steamwar.bungeecore.sql.WarkingUser;
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 java.io.File;
import java.io.IOException;
import java.util.UUID;
public class SubserverSystem {
private SubserverSystem(){}
public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){
ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner);
if(o == null)
return;
o.sendMessage(BungeeCore.ChatPrefix + "§e" + p.getName() + " §7möchte auf deine Bauwelt.");
TextComponent tc = new TextComponent("§7Klicke §ehier§7, wenn du das erlauben möchtest.");
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e/bau addmember " + p.getName()).create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName()));
o.sendMessage(tc);
}
public static Subserver startArena(ArenaMode modus, String map){
int port = freePort(2500);
String serverName = modus.name() + (port - 2500);
return new Subserver(Servertype.ARENA, serverName, port,
"/home/minecraft/mc", "-a", modus.name(), serverName, Integer.toString(port), map);
}
public static void sendToBauServer(ProxiedPlayer p, UUID owner){
for(Subserver subserver : Subserver.getServerList()){
if(subserver.getType() == Servertype.BAUSERVER && ((Bauserver)subserver).getOwner().equals(owner)){
subserver.sendPlayer(p);
return;
}
}
File w = new File(BungeeCore.WorldFolder + owner);
if (!w.exists() || !w.isDirectory()){
try {
Process pr;
ProcessBuilder pb = new ProcessBuilder(
"cp", "-r", BungeeCore.BauweltPrototyp, BungeeCore.WorldFolder + owner);
pr = pb.start();
pr.waitFor();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
p.sendMessage(BungeeCore.ChatPrefix + "§cDas Erstellen der Welt ist fehlgeschlagen.");
return;
}
if(Bauwelt.getBauwelt(owner) == null)
new Bauwelt(owner, false, false);
}
WarkingUser user = WarkingUser.get(owner);
int port = freePort(4000);
new Bauserver(user.getUserName() + "s Bau", owner, port,
"/home/minecraft/mc", "-b", owner.toString(), Integer.toString(port)).sendPlayer(p);
}
private static int freePort(int start){
int port = start;
boolean isFree = false;
while(!isFree){
port++;
isFree = true;
for(Subserver server : Subserver.getServerList()){
if(server.getServer().getAddress().getPort() == port){
isFree = false;
break;
}
}
}
return port;
}
}

Datei anzeigen

@ -1,158 +0,0 @@
package de.steamwar.bungeecore.arenasystem;
import de.steamwar.bungeecore.BungeeCore;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Arena implements Runnable{
final String serverName;
final int arenenNummer;
public final ArenaMode spielModus;
private Process p;
private PrintWriter writer;
public ServerInfo server;
private boolean started = false;
private final List<ProxiedPlayer> cachedPlayers = new ArrayList<>();
private final List<ProxiedPlayer> players = new ArrayList<>();
Arena(ArenaMode modus, int id, String map){
spielModus = modus;
arenenNummer = id;
serverName = modus.name() + id;
int port = 2500 + arenenNummer;
ProcessBuilder pb = new ProcessBuilder(
"/home/minecraft/mc",
"-a", modus.name(), serverName, Integer.toString(port), map);
try{
p = pb.start();
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, this);
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
server = ProxyServer.getInstance().constructServerInfo(
serverName, address, "SteamWar.de - Arena", false);
ProxyServer.getInstance().getServers().put(serverName, server);
writer = new PrintWriter( p.getOutputStream(), true);
}catch(IOException e) {
e.printStackTrace();
stop();
}
}
public void sendPlayer(ProxiedPlayer p){
if(!started){
p.sendMessage(BungeeCore.ChatPrefix + "§7Die Arena wird gestartet, einen Moment bitte...");
cachedPlayers.add(p);
}else{
p.connect(server);
players.add(p);
}
}
public void removePlayer(ProxiedPlayer p){
Iterator<ProxiedPlayer> it = cachedPlayers.iterator();
while(it.hasNext()){
if(it.next().equals(p)){
it.remove();
return;
}
}
it = players.iterator();
while(it.hasNext()){
if(it.next().equals(p)){
it.remove();
return;
}
}
}
void stop(){
ProxyServer.getInstance().getServers().remove(serverName);
if(p != null && p.isAlive()){
for(ProxiedPlayer player : server.getPlayers()){
player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer));
}
writer.println("stop");
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, ()->{
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
ArenaSystem.arenen.remove(this);
});
}else
ArenaSystem.arenen.remove(this);
}
private void fatalError(){
for(ProxiedPlayer cached : cachedPlayers){
cached.sendMessage(BungeeCore.ChatPrefix + "§cUnerwarteter Fehler beim Arenenstart.");
}
for(ProxiedPlayer player : server.getPlayers()){
player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer));
player.sendMessage(BungeeCore.ChatPrefix + "§cUnerwarteter Fehler in der Arena.");
}
stop();
}
boolean inArena(ProxiedPlayer p){
for(ProxiedPlayer ap : cachedPlayers)
if(ap.equals(p))
return true;
for(ProxiedPlayer ap : players)
if(ap.equals(p))
return true;
return false;
}
@Override
public void run() {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while (!started && (line = reader.readLine()) != null) {
started = line.contains(" INFO]: Done ("); //Problematisch
}
if(line == null){
BungeeCore.log("Arena "+serverName+" stopped to early!");
fatalError();
return;
}
Thread.sleep(1000);
sendPlayer(cachedPlayers.get(0));
Thread.sleep(200);
for(int i = 1; i < cachedPlayers.size(); i++){
sendPlayer(cachedPlayers.get(i));
}
cachedPlayers.clear();
p.waitFor();
}catch(IOException e){
e.printStackTrace();
fatalError();
}catch(InterruptedException e){
BungeeCore.log("Arena "+serverName+" was interrupted!");
fatalError();
}
stop();
}
}

Datei anzeigen

@ -1,63 +0,0 @@
package de.steamwar.bungeecore.arenasystem;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.ArrayList;
public class ArenaSystem {
private ArenaSystem(){}
static ArrayList<Arena> arenen = new ArrayList<>();
private static int freeId(){
int id = 0;
boolean isFree = false;
while(!isFree){
id++;
isFree = true;
for(Arena arena : arenen){
if(arena.arenenNummer == id){
isFree = false;
break;
}
}
}
return id;
}
public static Arena startServer(ArenaMode modus, String map){
Arena arena = new Arena(modus, freeId(), map);
arenen.add(arena);
return arena;
}
public static void shutdown(){
while(!arenen.isEmpty())
arenen.get(0).stop();
}
public static boolean inArena(ProxiedPlayer p){
for(Arena a : arenen){
if(a.inArena(p))
return true;
}
return false;
}
public static Arena getArena(ProxiedPlayer p){
for(Arena a : arenen){
if(a.inArena(p))
return a;
}
return null;
}
public static Arena getArena(String serverName){
for(Arena a : arenen)
if(a.serverName.equals(serverName))
return a;
return null;
}
}

Datei anzeigen

@ -1,174 +0,0 @@
package de.steamwar.bungeecore.bausystem;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.WarkingUser;
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.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class BauServer implements Runnable{
private final UUID owner;
private final int id;
private final String name;
private Process p;
private PrintWriter writer;
private ServerInfo server;
private boolean started = false;
private boolean stopped = false;
private final List<ProxiedPlayer> cachedPlayers = new ArrayList<>();
private final List<ProxiedPlayer> players = new ArrayList<>();
BauServer(int id, UUID owner){
this.id = id;
this.owner = owner;
this.name = new WarkingUser(owner).getUserName() + "s Bau";
int port = 4000 + id;
ProcessBuilder pb = new ProcessBuilder(
"/home/minecraft/mc",
"-b", owner.toString(), Integer.toString(port));
try{
p = pb.start();
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, this);
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
server = ProxyServer.getInstance().constructServerInfo(
name, address, "SteamWar.de - BauServer", false);
ProxyServer.getInstance().getServers().put(name, server);
writer = new PrintWriter( p.getOutputStream(), true);
}catch(IOException e) {
e.printStackTrace();
stop();
}
}
public void stop(){
ProxyServer.getInstance().getServers().remove(name);
if(p != null && p.isAlive()) {
for (ProxiedPlayer player : server.getPlayers()) {
player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer));
}
stopped = true;
writer.println("stop");
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, ()->{
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
BauSystem.server.remove(owner);
});
}else
BauSystem.server.remove(owner);
}
void sendPlayer(ProxiedPlayer p){
if(stopped) {
p.sendMessage(BungeeCore.ChatPrefix + "§7Die Bauwelt derzeit entladen, bitte versuche es später erneut.");
}else if(!started){
p.sendMessage(BungeeCore.ChatPrefix + "§7Die Bauwelt wird geladen, einen Moment bitte...");
cachedPlayers.add(p);
}else{
p.connect(server);
players.add(p);
}
}
boolean onBau(ProxiedPlayer p){
for(ProxiedPlayer ap : cachedPlayers)
if(ap.equals(p))
return true;
for(ProxiedPlayer ap : players)
if(ap.equals(p))
return true;
return false;
}
public void removePlayer(ProxiedPlayer p){
cachedPlayers.remove(p);
players.remove(p);
}
private void fatalError(){
for(ProxiedPlayer cached : cachedPlayers){
cached.sendMessage(BungeeCore.ChatPrefix + "§cUnerwarteter Fehler beim Laden der Bauwelt.");
}
for(ProxiedPlayer player : server.getPlayers()){
player.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer));
player.sendMessage(BungeeCore.ChatPrefix + "§cUnerwarteter Fehler in der Bauwelt.");
}
stop();
}
@Override
public void run() {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while (!started && (line = reader.readLine()) != null) {
started = line.contains(" INFO]: Done (");
}
if(line == null){
BungeeCore.log("Bau "+name+" stopped to early!");
fatalError();
return;
}
Thread.sleep(1000);
for(ProxiedPlayer player : cachedPlayers){
sendPlayer(player);
}
cachedPlayers.clear();
p.waitFor();
}catch(IOException e){
e.printStackTrace();
fatalError();
}catch(InterruptedException e){
BungeeCore.log("Bau "+name+" was interrupted!");
fatalError();
}
stop();
}
public UUID getOwner() {
return owner;
}
public int getId() {
return id;
}
public ServerInfo getServer() {
return server;
}
public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){
ProxiedPlayer o = ProxyServer.getInstance().getPlayer(owner);
if(o == null)
return;
o.sendMessage(BungeeCore.ChatPrefix + "§e" + p.getName() + " §7möchte auf deine Bauwelt.");
TextComponent tc = new TextComponent("§7Klicke §ehier§7, wenn du das erlauben möchtest.");
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e/bau addmember " + p.getName()).create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/bau addmember " + p.getName()));
o.sendMessage(tc);
}
}

Datei anzeigen

@ -1,75 +0,0 @@
package de.steamwar.bungeecore.bausystem;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.Bauwelt;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.UUID;
public class BauSystem {
private BauSystem(){}
static HashMap<UUID, BauServer> server = new HashMap<>();
private static int freeId(){
int id = 0;
boolean isFree = false;
while(!isFree){
id++;
isFree = true;
for(BauServer bau : server.values()){
if(bau.getId() == id){
isFree = false;
break;
}
}
}
return id;
}
public static void sendToServer(ProxiedPlayer p, UUID owner){
if(server.containsKey(owner)){
server.get(owner).sendPlayer(p);
}else{
File w = new File(BungeeCore.WorldFolder + owner);
if (!w.exists() || !w.isDirectory()){
try {
Process pr;
ProcessBuilder pb = new ProcessBuilder(
"cp", "-r", BungeeCore.BauweltPrototyp, BungeeCore.WorldFolder + owner);
pr = pb.start();
pr.waitFor();
} catch (InterruptedException | IOException e) {
e.printStackTrace();
p.sendMessage(BungeeCore.ChatPrefix + "§cDas Erstellen der Welt ist fehlgeschlagen.");
return;
}
if(Bauwelt.getBauwelt(owner) == null)
new Bauwelt(owner, false, false);
}
BauServer bau = new BauServer(freeId(), owner);
server.put(owner, bau);
bau.sendPlayer(p);
}
}
public static BauServer getBau(ProxiedPlayer p){
for(BauServer bau : server.values()){
if(bau.onBau(p))
return bau;
}
return null;
}
public static void shutdown(){
Iterator<BauServer> it = server.values().iterator();
while(it.hasNext()){
it.next().stop();
}
}
}

Datei anzeigen

@ -1,8 +1,6 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.bausystem.BauServer;
import de.steamwar.bungeecore.bausystem.BauSystem;
import de.steamwar.bungeecore.sql.Bauwelt; import de.steamwar.bungeecore.sql.Bauwelt;
import de.steamwar.bungeecore.sql.BauweltMember; import de.steamwar.bungeecore.sql.BauweltMember;
import de.steamwar.bungeecore.sql.Permission; import de.steamwar.bungeecore.sql.Permission;
@ -20,12 +18,13 @@ public class BauCommand {
public static void onBau(ChatEvent e, String[] command){ public static void onBau(ChatEvent e, String[] command){
ProxiedPlayer p = (ProxiedPlayer) e.getSender(); ProxiedPlayer p = (ProxiedPlayer) e.getSender();
BauServer bau = BauSystem.getBau(p); Subserver server = Subserver.getSubserver(p);
Bauserver bau = server != null && server.getType() == Servertype.BAUSERVER ? (Bauserver)server : null;
boolean ownBau = bau != null && bau.getOwner().equals(p.getUniqueId()); boolean ownBau = bau != null && bau.getOwner().equals(p.getUniqueId());
e.setCancelled(true); e.setCancelled(true);
if(command.length == 1){ if(command.length == 1){
BauSystem.sendToServer(p, p.getUniqueId()); SubserverSystem.sendToBauServer(p, p.getUniqueId());
}else if(ownBau && command.length != 2 && ( }else if(ownBau && command.length != 2 && (
command[1].equalsIgnoreCase("togglebuild") || command[1].equalsIgnoreCase("togglebuild") ||
command[1].equalsIgnoreCase("togglewe") || command[1].equalsIgnoreCase("togglewe") ||
@ -65,11 +64,11 @@ public class BauCommand {
p.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spieler"); p.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spieler");
return; return;
}else if (!hasPermission(worldOwner, p, Permission.member)){ }else if (!hasPermission(worldOwner, p, Permission.member)){
BauServer.sendDeniedMessage(p, worldOwner); SubserverSystem.sendDeniedMessage(p, worldOwner);
p.sendMessage(BungeeCore.ChatPrefix + "§cDu darfst dich nicht auf diese Welt teleportieren"); p.sendMessage(BungeeCore.ChatPrefix + "§cDu darfst dich nicht auf diese Welt teleportieren");
return; return;
} }
BauSystem.sendToServer(p, worldOwner); SubserverSystem.sendToBauServer(p, worldOwner);
}else if(command[1].equalsIgnoreCase("togglebuild")){ }else if(command[1].equalsIgnoreCase("togglebuild")){
if (command.length == 2) { if (command.length == 2) {
p.sendMessage(BungeeCore.ChatPrefix + "/bau togglebuild <Spieler>"); p.sendMessage(BungeeCore.ChatPrefix + "/bau togglebuild <Spieler>");
@ -125,12 +124,16 @@ public class BauCommand {
}else if(command[1].equalsIgnoreCase("resetall") || }else if(command[1].equalsIgnoreCase("resetall") ||
command[1].equalsIgnoreCase("delete")){ command[1].equalsIgnoreCase("delete")){
p.sendMessage(BungeeCore.ChatPrefix + "§aDeine Welt wird zurückgesetzt. Einen Moment bitte..."); p.sendMessage(BungeeCore.ChatPrefix + "§aDeine Welt wird zurückgesetzt. Einen Moment bitte...");
BauServer bauserver = BauSystem.getBau(p); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, () -> {
if(bauserver != null){ for(Subserver subserver : Subserver.getServerList()){
bauserver.stop(); if(subserver.getType() == Servertype.BAUSERVER && ((Bauserver)subserver).getOwner().equals(p.getUniqueId())){
subserver.stop();
break;
}
} }
File directory = new File(BungeeCore.WorldFolder + p.getUniqueId().toString()); File directory = new File(BungeeCore.WorldFolder + p.getUniqueId().toString());
del(directory); del(directory);
});
}else{ }else{
HelpCommand.sendBauHelp(p); HelpCommand.sendBauHelp(p);
} }
@ -192,8 +195,8 @@ public class BauCommand {
ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID()); ProxiedPlayer z = ProxyServer.getInstance().getPlayer(WarkingUser.get(target.getMemberID()).getUUID());
if(z != null){ if(z != null){
z.sendMessage(BungeeCore.ChatPrefix + "§cDu wurdest von der Welt von §6" + p.getName() + " §centfernt."); z.sendMessage(BungeeCore.ChatPrefix + "§cDu wurdest von der Welt von §6" + p.getName() + " §centfernt.");
BauServer server = BauSystem.getBau(z); Subserver server = Subserver.getSubserver(z);
if(server != null && server.getOwner().equals(p.getUniqueId())) if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId()))
z.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer)); z.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LobbyServer));
} }
p.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler wurde entfernt."); p.sendMessage(BungeeCore.ChatPrefix + "§cDer Spieler wurde entfernt.");

Datei anzeigen

@ -1,9 +1,10 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.arenasystem.Arena; import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.arenasystem.ArenaMode; import de.steamwar.bungeecore.Subserver;
import de.steamwar.bungeecore.arenasystem.ArenaSystem; import de.steamwar.bungeecore.SubserverSystem;
import de.steamwar.bungeecore.ArenaMode;
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.ClickEvent;
@ -52,41 +53,47 @@ public class FightCommand extends Command {
if(sender instanceof ProxiedPlayer){ if(sender instanceof ProxiedPlayer){
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
if(ArenaSystem.inArena(player)){ Subserver subserver = Subserver.getSubserver(player);
if(subserver != null && subserver.getType() == Servertype.ARENA){
sender.sendMessage(BungeeCore.ChatPrefix + "§cDu befindest dich bereits in einer Arena."); sender.sendMessage(BungeeCore.ChatPrefix + "§cDu befindest dich bereits in einer Arena.");
return; return;
} }
String map; String map;
Arena arena; Subserver arena;
String spielModus;
switch(args[0].toLowerCase()){ switch(args[0].toLowerCase()){
case "as": case "as":
case "airship": case "airship":
map = getMap(sender, ArenaMode.AirShip, args); map = getMap(sender, ArenaMode.AirShip, args);
if(map == null) if(map == null)
return; return;
arena = ArenaSystem.startServer(ArenaMode.AirShip, map); arena = SubserverSystem.startArena(ArenaMode.AirShip, map);
spielModus = "AirShip";
break; break;
case "ws": case "ws":
case "warship": case "warship":
map = getMap(sender, ArenaMode.WarShip, args); map = getMap(sender, ArenaMode.WarShip, args);
if(map == null) if(map == null)
return; return;
arena = ArenaSystem.startServer(ArenaMode.WarShip, map); arena = SubserverSystem.startArena(ArenaMode.WarShip, map);
spielModus = "WarShip";
break; break;
case "wg": case "wg":
case "wargear": case "wargear":
map = getMap(sender, ArenaMode.WarGear, args); map = getMap(sender, ArenaMode.WarGear, args);
if(map == null) if(map == null)
return; return;
arena = ArenaSystem.startServer(ArenaMode.WarGear, map); arena = SubserverSystem.startArena(ArenaMode.WarGear, map);
spielModus = "WarGear";
break; break;
case "mwg": case "mwg":
case "miniwargear": case "miniwargear":
map = getMap(sender, ArenaMode.MiniWarGear, args); map = getMap(sender, ArenaMode.MiniWarGear, args);
if(map == null) if(map == null)
return; return;
arena = ArenaSystem.startServer(ArenaMode.MiniWarGear, map); arena = SubserverSystem.startArena(ArenaMode.MiniWarGear, map);
spielModus = "MiniWarGear";
break; break;
default: default:
sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[0]); sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[0]);
@ -94,7 +101,7 @@ public class FightCommand extends Command {
} }
arena.sendPlayer(player); arena.sendPlayer(player);
TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§7Klicke §ehier§7, um §e" + arena.spielModus + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!"); TextComponent tc = new TextComponent(BungeeCore.ChatPrefix + "§7Klicke §ehier§7, um §e" + spielModus + " §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);

Datei anzeigen

@ -1,10 +1,6 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.arenasystem.Arena;
import de.steamwar.bungeecore.arenasystem.ArenaSystem;
import de.steamwar.bungeecore.bausystem.BauServer;
import de.steamwar.bungeecore.bausystem.BauSystem;
import de.steamwar.bungeecore.sql.BauweltMember; import de.steamwar.bungeecore.sql.BauweltMember;
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;
@ -46,19 +42,22 @@ public class JoinmeCommand extends Command {
} }
ServerInfo server = target.getServer().getInfo(); ServerInfo server = target.getServer().getInfo();
String ServerPerm = BungeeCore.serverPermissions.get(server.getName()); String ServerPerm = BungeeCore.serverPermissions.get(server.getName());
Arena arena = ArenaSystem.getArena(target); Subserver subserver = Subserver.getSubserver(target);
BauServer bauserver = BauSystem.getBau(target);
if(arena != null) { if(subserver != null) {
arena.sendPlayer(player); Servertype type = subserver.getType();
}else if(bauserver != null){ if (type == Servertype.ARENA) {
if(bauserver.getOwner().equals(player.getUniqueId()) || subserver.sendPlayer(player);
BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null){ } else if (type == Servertype.BAUSERVER) {
BauSystem.sendToServer(player, bauserver.getOwner()); Bauserver bauserver = (Bauserver) subserver;
}else{ if (bauserver.getOwner().equals(player.getUniqueId()) ||
BauServer.sendDeniedMessage(player, bauserver.getOwner()); BauweltMember.getBauMember(bauserver.getOwner(), player.getUniqueId()) != null) {
subserver.sendPlayer(player);
} else {
SubserverSystem.sendDeniedMessage(player, bauserver.getOwner());
player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE); player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE);
} }
}
}else if(ServerPerm != null && !player.hasPermission(ServerPerm)){ }else if(ServerPerm != null && !player.hasPermission(ServerPerm)){
player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE); player.sendMessage(BungeeCore.ChatPrefix + DENY_MESSAGE);
}else if(ServerPerm == null && !player.getGroups().contains("team")) { }else if(ServerPerm == null && !player.getGroups().contains("team")) {

Datei anzeigen

@ -2,3 +2,4 @@ name: BungeeCore
main: de.steamwar.bungeecore.BungeeCore main: de.steamwar.bungeecore.BungeeCore
version: 1.0 version: 1.0
author: Lixfel author: Lixfel
depend: [PersistentBungeeCore]