geforkt von SteamWar/BungeeCore
Merge branch 'master' into schem_aleart
Dieser Commit ist enthalten in:
Commit
588ecebb3f
@ -84,6 +84,7 @@ public class BungeeCore extends Plugin {
|
|||||||
new CheckListener();
|
new CheckListener();
|
||||||
new ModLoaderBlocker();
|
new ModLoaderBlocker();
|
||||||
new WorldDownloader();
|
new WorldDownloader();
|
||||||
|
new BrandListener();
|
||||||
|
|
||||||
commands.put("/b", null);
|
commands.put("/b", null);
|
||||||
commands.put("/gs", null);
|
commands.put("/gs", null);
|
||||||
|
@ -28,8 +28,10 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SubserverSystem {
|
public class SubserverSystem {
|
||||||
private SubserverSystem(){}
|
private SubserverSystem(){}
|
||||||
@ -41,13 +43,13 @@ public class SubserverSystem {
|
|||||||
private static final String SERVER_PATH = BACKBONE + "server/";
|
private static final String SERVER_PATH = BACKBONE + "server/";
|
||||||
private static final String EVENT_PATH = BACKBONE + "event/";
|
private static final String EVENT_PATH = BACKBONE + "event/";
|
||||||
|
|
||||||
private static final int firstArenaPort;
|
private static final int FIRST_ARENA_PORT;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if(BungeeCore.EVENT_MODE)
|
if(BungeeCore.EVENT_MODE)
|
||||||
firstArenaPort = 6000;
|
FIRST_ARENA_PORT = 6000;
|
||||||
else
|
else
|
||||||
firstArenaPort = 2500;
|
FIRST_ARENA_PORT = 2500;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,13 +91,13 @@ public class SubserverSystem {
|
|||||||
*/
|
*/
|
||||||
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, int prepareSchemID, String serverName, String mapName, UUID player1, UUID player2, boolean ranked){
|
public static Subserver startArena(ArenaMode modus, String map, int eventFightID, int checkSchemID, int prepareSchemID, String serverName, String mapName, UUID player1, UUID player2, boolean ranked){
|
||||||
//Generate missing parameters
|
//Generate missing parameters
|
||||||
int port = freePort(firstArenaPort);
|
int port = freePort(FIRST_ARENA_PORT);
|
||||||
|
|
||||||
if(serverName == null){
|
if(serverName == null){
|
||||||
if(ranked)
|
if(ranked)
|
||||||
serverName = "Ranked" + (port - firstArenaPort);
|
serverName = "Ranked" + (port - FIRST_ARENA_PORT);
|
||||||
else
|
else
|
||||||
serverName = modus.getDisplayName() + (port - firstArenaPort);
|
serverName = modus.getDisplayName() + (port - FIRST_ARENA_PORT);
|
||||||
}
|
}
|
||||||
if(mapName == null)
|
if(mapName == null)
|
||||||
mapName = serverName;
|
mapName = serverName;
|
||||||
@ -109,8 +111,11 @@ public class SubserverSystem {
|
|||||||
//Copy world
|
//Copy world
|
||||||
try {
|
try {
|
||||||
new ProcessBuilder("cp", "-r", SERVER_PATH + modus.getFolder() + "/arenas/" + map, worldDir + mapName).start().waitFor();
|
new ProcessBuilder("cp", "-r", SERVER_PATH + modus.getFolder() + "/arenas/" + map, worldDir + mapName).start().waitFor();
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException e) {
|
||||||
throw new SecurityException("Could not copy folder", e);
|
throw new SecurityException("Could not copy folder", e);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Interrupted while copying folder", e);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> cmd = serverStartCommand(
|
List<String> cmd = serverStartCommand(
|
||||||
@ -125,8 +130,8 @@ public class SubserverSystem {
|
|||||||
"ranked=" + ranked,
|
"ranked=" + ranked,
|
||||||
"checkSchemID=" + checkSchemID,
|
"checkSchemID=" + checkSchemID,
|
||||||
"prepareSchemID=" + prepareSchemID,
|
"prepareSchemID=" + prepareSchemID,
|
||||||
player1 != null && eventFightID != -1 ? "blueLeader=" + player1.toString() : null,
|
player1 != null && eventFightID != -1 ? "blueLeader=" + player1 : null,
|
||||||
player2 != null ? "redLeader=" + player2.toString() : null);
|
player2 != null ? "redLeader=" + player2 : null);
|
||||||
|
|
||||||
//Start server
|
//Start server
|
||||||
ProcessBuilder process = new ProcessBuilder(cmd);
|
ProcessBuilder process = new ProcessBuilder(cmd);
|
||||||
@ -134,26 +139,26 @@ public class SubserverSystem {
|
|||||||
|
|
||||||
String finalMapName = mapName;
|
String finalMapName = mapName;
|
||||||
if(eventFightID == -1)
|
if(eventFightID == -1)
|
||||||
return new Bauserver(serverName, player1, port, process, () -> {
|
return new Bauserver(serverName, player1, port, process, () -> deleteFolder(ARENA_PATH + finalMapName));
|
||||||
try {
|
|
||||||
new ProcessBuilder("rm", "-r", ARENA_PATH + finalMapName).start().waitFor();
|
|
||||||
} catch (IOException | InterruptedException e) {
|
|
||||||
throw new SecurityException("Could not clean up folder", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
else
|
else
|
||||||
return new Subserver(Servertype.ARENA, serverName, port, process, () -> {
|
return new Subserver(Servertype.ARENA, serverName, port, process, () -> {
|
||||||
if(eventFightID > 0)
|
if(eventFightID > 0)
|
||||||
return;
|
return;
|
||||||
|
deleteFolder(ARENA_PATH + finalMapName);
|
||||||
try {
|
|
||||||
new ProcessBuilder("rm", "-r", ARENA_PATH + finalMapName).start().waitFor();
|
|
||||||
} catch (IOException | InterruptedException e) {
|
|
||||||
throw new SecurityException("Could not clean up folder", e);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void deleteFolder(String worldName){
|
||||||
|
try {
|
||||||
|
new ProcessBuilder("rm", "-r", worldName).start().waitFor();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException("Could not clean up folder", e);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Interrupted while deleting folder", e);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Subserver startEventArena(EventFight eventFight, String serverName){
|
public static Subserver startEventArena(EventFight eventFight, String serverName){
|
||||||
return startArena(
|
return startArena(
|
||||||
eventFight.getSpielmodus(),
|
eventFight.getSpielmodus(),
|
||||||
@ -172,50 +177,44 @@ public class SubserverSystem {
|
|||||||
startArena(m, map, -1, checkSchemId, prepareSchemId, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null, false).sendPlayer(p);
|
startArena(m, map, -1, checkSchemId, prepareSchemId, p.getName() + "s Bau", p.getName(), p.getUniqueId(), null, false).sendPlayer(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendToBauServer(ProxiedPlayer p, UUID owner){
|
private static void sendToBau(ProxiedPlayer p, UUID owner, String prototype, String worldFolder, String serverJar, String worldDir, String worldName, String xmx, String serverName){
|
||||||
if(bauRunning(p, owner))
|
if(bauRunning(p, owner))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SteamwarUser user = SteamwarUser.get(owner);
|
SteamwarUser user = SteamwarUser.get(owner);
|
||||||
copyBauweltIfRequired(p, BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER + owner.toString());
|
copyBauweltIfRequired(p, prototype, worldFolder + worldName);
|
||||||
int port = freePort(4000);
|
int port = freePort(4000);
|
||||||
|
|
||||||
List<String> cmd = serverStartCommand(
|
List<String> cmd = serverStartCommand(
|
||||||
"spigot-1.12.2.jar",
|
serverJar,
|
||||||
"/home/minecraft/userworlds",
|
worldDir,
|
||||||
owner.toString(),
|
worldName,
|
||||||
port,
|
port,
|
||||||
"256M",
|
xmx,
|
||||||
"logPath=" + owner.toString());
|
"logPath=" + worldName);
|
||||||
|
|
||||||
//Start server
|
//Start server
|
||||||
ProcessBuilder process = new ProcessBuilder(cmd);
|
ProcessBuilder process = new ProcessBuilder(cmd);
|
||||||
process.directory(new File(SERVER_PATH, "UserBau"));
|
process.directory(new File(SERVER_PATH, serverName));
|
||||||
|
|
||||||
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
|
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendToBau15(ProxiedPlayer p, UUID owner){
|
public static void sendToBauServer(ProxiedPlayer p, UUID owner){
|
||||||
if(bauRunning(p, owner))
|
sendToBau(p, owner, BungeeCore.BAUWELT_PROTOTYP, BungeeCore.WORLD_FOLDER, "spigot-1.12.2.jar", "/home/minecraft/userworlds", owner.toString(), "256M", "UserBau");
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
private static void sendToBau15(ProxiedPlayer p, UUID owner, String serverJar){
|
||||||
SteamwarUser user = SteamwarUser.get(owner);
|
SteamwarUser user = SteamwarUser.get(owner);
|
||||||
copyBauweltIfRequired(p, BungeeCore.BAUWELT15, BungeeCore.USERWORLDS15 + user.getId());
|
sendToBau(p, owner, BungeeCore.BAUWELT15, BungeeCore.USERWORLDS15, serverJar, "/home/minecraft/userworlds15", String.valueOf(user.getId()), "512M", "Bau15");
|
||||||
int port = freePort(4000);
|
}
|
||||||
|
|
||||||
List<String> cmd = serverStartCommand(
|
public static void sendToBau15(ProxiedPlayer p, UUID owner){
|
||||||
"spigot-1.15.2.jar",
|
sendToBau15(p, owner, "spigot-1.15.2.jar");
|
||||||
"/home/minecraft/userworlds15",
|
}
|
||||||
String.valueOf(user.getId()),
|
|
||||||
port,
|
|
||||||
"512M",
|
|
||||||
"logPath=" + user.getId());
|
|
||||||
|
|
||||||
//Start server
|
public static void sendToBau15paper(ProxiedPlayer p, UUID owner){
|
||||||
ProcessBuilder process = new ProcessBuilder(cmd);
|
sendToBau15(p, owner, "paper-1.15.2.jar");
|
||||||
process.directory(new File(SERVER_PATH, "Bau15"));
|
|
||||||
|
|
||||||
new Bauserver(user.getUserName() + "s Bau", owner, port, process, () -> {}).sendPlayer(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){
|
public static void sendDeniedMessage(ProxiedPlayer p, UUID owner){
|
||||||
@ -274,11 +273,7 @@ public class SubserverSystem {
|
|||||||
File w = new File(targetPath);
|
File w = new File(targetPath);
|
||||||
if (!w.exists() || !w.isDirectory()){
|
if (!w.exists() || !w.isDirectory()){
|
||||||
try {
|
try {
|
||||||
Process pr;
|
new ProcessBuilder("cp", "-r", sourcePath, targetPath).start().waitFor();
|
||||||
ProcessBuilder pb = new ProcessBuilder(
|
|
||||||
"cp", "-r", sourcePath, targetPath);
|
|
||||||
pr = pb.start();
|
|
||||||
pr.waitFor();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Message.send("SERVER_WORLD_ERROR", p);
|
Message.send("SERVER_WORLD_ERROR", p);
|
||||||
throw new SecurityException("Could not create Bauwelt", e);
|
throw new SecurityException("Could not create Bauwelt", e);
|
||||||
@ -298,7 +293,7 @@ public class SubserverSystem {
|
|||||||
port++;
|
port++;
|
||||||
isFree = true;
|
isFree = true;
|
||||||
for(Subserver server : Subserver.getServerList()){
|
for(Subserver server : Subserver.getServerList()){
|
||||||
if(server.getServer().getAddress().getPort() == port){
|
if(((InetSocketAddress)server.getServer().getSocketAddress()).getPort() == port){
|
||||||
isFree = false;
|
isFree = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class BanCommand extends BasicCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SteamwarUser target = user(sender, args[0]);
|
SteamwarUser target = unsafeUser(sender, args[0]);
|
||||||
if(target == null)
|
if(target == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -53,10 +53,17 @@ abstract class BasicCommand extends Command implements TabExecutor {
|
|||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SteamwarUser user(CommandSender sender, String arg){
|
protected SteamwarUser existingUser(CommandSender sender, String arg){
|
||||||
SteamwarUser target = SteamwarUser.get(arg);
|
SteamwarUser target = SteamwarUser.get(arg);
|
||||||
if(target == null)
|
if(target == null)
|
||||||
Message.send("UNKNOWN_PLAYER", sender);
|
Message.send("UNKNOWN_PLAYER", sender);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected SteamwarUser unsafeUser(CommandSender sender, String arg){
|
||||||
|
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(arg);
|
||||||
|
if(target == null)
|
||||||
|
Message.send("UNKNOWN_PLAYER", sender);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,6 @@ import net.md_5.bungee.api.ProxyServer;
|
|||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.ChatEvent;
|
import net.md_5.bungee.api.event.ChatEvent;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class BauCommand {
|
public class BauCommand {
|
||||||
|
|
||||||
private BauCommand(){}
|
private BauCommand(){}
|
||||||
@ -70,6 +68,9 @@ public class BauCommand {
|
|||||||
case "1.15":
|
case "1.15":
|
||||||
SubserverSystem.sendToBau15(p, p.getUniqueId());
|
SubserverSystem.sendToBau15(p, p.getUniqueId());
|
||||||
break;
|
break;
|
||||||
|
case "paper":
|
||||||
|
SubserverSystem.sendToBau15paper(p, p.getUniqueId());
|
||||||
|
break;
|
||||||
case "addmember":
|
case "addmember":
|
||||||
addmember(p, command);
|
addmember(p, command);
|
||||||
break;
|
break;
|
||||||
@ -251,8 +252,7 @@ public class BauCommand {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File directory = new File(world);
|
SubserverSystem.deleteFolder(world);
|
||||||
del(directory);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,19 +318,4 @@ public class BauCommand {
|
|||||||
Message.send("BAU_MEMBER_TOGGLE_OFF", p, what);
|
Message.send("BAU_MEMBER_TOGGLE_OFF", p, what);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void del(File dir){
|
|
||||||
if (dir.isDirectory()){
|
|
||||||
String[] entries = dir.list();
|
|
||||||
assert entries != null;
|
|
||||||
for (String entry : entries) {
|
|
||||||
File aktFile = new File(dir.getPath(), entry);
|
|
||||||
del(aktFile);
|
|
||||||
}
|
|
||||||
dir.delete();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
dir.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class MuteCommand extends BasicCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SteamwarUser target = user(sender, args[0]);
|
SteamwarUser target = unsafeUser(sender, args[0]);
|
||||||
if(target == null)
|
if(target == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -179,6 +179,7 @@ public class TeamCommand extends BasicCommand {
|
|||||||
|
|
||||||
Team.create(args[1], args[2], user);
|
Team.create(args[1], args[2], user);
|
||||||
user.setTeam(Team.get(args[1]).getTeamId());
|
user.setTeam(Team.get(args[1]).getTeamId());
|
||||||
|
user.setLeader(true);
|
||||||
Message.send("TEAM_CREATE_CREATED", player, args[2]);
|
Message.send("TEAM_CREATE_CREATED", player, args[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +256,7 @@ public class TeamCommand extends BasicCommand {
|
|||||||
user.setTeam(0);
|
user.setTeam(0);
|
||||||
|
|
||||||
if(user.isLeader() && team.size() > 0){
|
if(user.isLeader() && team.size() > 0){
|
||||||
team.disband();
|
team.disband(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
Message.send("TEAM_LEAVE_LEFT", player);
|
Message.send("TEAM_LEAVE_LEFT", player);
|
||||||
|
@ -39,7 +39,7 @@ public class UnbanCommand extends BasicCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SteamwarUser target = user(sender, args[0]);
|
SteamwarUser target = existingUser(sender, args[0]);
|
||||||
if(target == null)
|
if(target == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
65
src/de/steamwar/bungeecore/listeners/BrandListener.java
Normale Datei
65
src/de/steamwar/bungeecore/listeners/BrandListener.java
Normale Datei
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bungeecore.listeners;
|
||||||
|
|
||||||
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
import de.steamwar.bungeecore.Message;
|
||||||
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
|
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class BrandListener extends BasicListener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerSwitch(PluginMessageEvent event) {
|
||||||
|
if(event.getTag().equals("minecraft:brand") || event.getTag().equals("MC|Brand")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.getReceiver().getAddress().getHostName().contains("localhost")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||||
|
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||||
|
|
||||||
|
String channel = player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand";
|
||||||
|
StringBuilder serverBrand = new StringBuilder();
|
||||||
|
for (byte b:event.getData()) {
|
||||||
|
serverBrand.append((char) b);
|
||||||
|
}
|
||||||
|
|
||||||
|
String brandString = Message.parse("STEAMWAR_BRAND", player, BungeeCore.get().getProxy().getName(), player.getServer().getInfo().getName(), serverBrand.substring(1));
|
||||||
|
|
||||||
|
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
|
||||||
|
DefinedPacket.writeString(brandString, brand);
|
||||||
|
player.sendData(channel, DefinedPacket.toArray(brand));
|
||||||
|
brand.release();
|
||||||
|
}, 50, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
}
|
@ -19,10 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.bungeecore.sql;
|
package de.steamwar.bungeecore.sql;
|
||||||
|
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
import de.steamwar.bungeecore.Message;
|
import de.steamwar.bungeecore.Message;
|
||||||
import de.steamwar.bungeecore.commands.WebregisterCommand;
|
import de.steamwar.bungeecore.commands.WebregisterCommand;
|
||||||
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Scanner;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
@ -38,6 +43,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public class SteamwarUser {
|
public class SteamwarUser {
|
||||||
private final int id;
|
private final int id;
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
@ -51,6 +57,8 @@ public class SteamwarUser {
|
|||||||
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
|
||||||
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
|
||||||
private static final InetAddress LIXFEL_DE;
|
private static final InetAddress LIXFEL_DE;
|
||||||
|
private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/";
|
||||||
|
private static final JsonParser jsonParser = new JsonParser();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@ -85,8 +93,7 @@ public class SteamwarUser {
|
|||||||
user.userName = userName;
|
user.userName = userName;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')", connection.getUniqueId().toString(), connection.getName());
|
user = SteamwarUser.createUserInDatabase(connection.getUniqueId(), connection.getName());
|
||||||
user = dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", connection.getUniqueId().toString()));
|
|
||||||
if(user == null)
|
if(user == null)
|
||||||
throw new SecurityException("user == null");
|
throw new SecurityException("user == null");
|
||||||
ConnectionListener.newPlayer(user.uuid);
|
ConnectionListener.newPlayer(user.uuid);
|
||||||
@ -97,6 +104,25 @@ public class SteamwarUser {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SteamwarUser getOrCreateOfflinePlayer(String name){
|
||||||
|
SteamwarUser user = SteamwarUser.get(name);
|
||||||
|
if (user != null) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
UUID uuid = SteamwarUser.loadUUID(name);
|
||||||
|
if (uuid == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SteamwarUser.createUserInDatabase(uuid, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SteamwarUser createUserInDatabase(UUID uuid, String name) {
|
||||||
|
SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')", uuid.toString(), name);
|
||||||
|
return dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", uuid.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
public static SteamwarUser get(String userName){
|
public static SteamwarUser get(String userName){
|
||||||
userName = userName.toLowerCase();
|
userName = userName.toLowerCase();
|
||||||
if(usersByName.containsKey(userName))
|
if(usersByName.containsKey(userName))
|
||||||
@ -126,6 +152,22 @@ public class SteamwarUser {
|
|||||||
usersByUUID.clear();
|
usersByUUID.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UUID loadUUID(String playerName) {
|
||||||
|
try {
|
||||||
|
final URL url = new URL(API_URL + playerName);
|
||||||
|
return getUniqueIdFromString(jsonParser.parse(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UUID getUniqueIdFromString(String uuid) {
|
||||||
|
return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
|
||||||
|
}
|
||||||
|
|
||||||
public void setTeam(int team){
|
public void setTeam(int team){
|
||||||
this.team = team;
|
this.team = team;
|
||||||
SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id);
|
SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id);
|
||||||
|
@ -53,7 +53,6 @@ public class Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void create(String kuerzel, String name, SteamwarUser user){
|
public static void create(String kuerzel, String name, SteamwarUser user){
|
||||||
user.setLeader(true);
|
|
||||||
SQL.update("INSERT INTO Team (TeamKuerzel, TeamName) VALUES (?, ?)", kuerzel, name);
|
SQL.update("INSERT INTO Team (TeamKuerzel, TeamName) VALUES (?, ?)", kuerzel, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,8 +153,9 @@ public class Team {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disband(){
|
public void disband(SteamwarUser user){
|
||||||
SQL.update("UPDATE Team SET TeamDeleted = 1, TeamLeader = NULL WHERE TeamID = ?", teamId);
|
user.setLeader(false);
|
||||||
|
SQL.update("UPDATE Team SET TeamDeleted = 1", teamId);
|
||||||
teamCache.remove(this);
|
teamCache.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ UNKNOWN_PLAYER=§cDiesen Spieler gibt es nicht.
|
|||||||
UNKNOWN_TEAM=§cDieses Team gibt es nicht.
|
UNKNOWN_TEAM=§cDieses Team gibt es nicht.
|
||||||
INVALID_TIME=§cUngültige Zeitangabe.
|
INVALID_TIME=§cUngültige Zeitangabe.
|
||||||
|
|
||||||
|
STEAMWAR_BRAND=§eSteam§8War.de §7({0}) §r<- §e{1} §7({2})§r
|
||||||
|
|
||||||
#ModLoader blocker
|
#ModLoader blocker
|
||||||
MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten.
|
MODLOADER_INSTALLED=§7Du hast §e{0} §7installiert. Daher kannst du keinen Arenen beitreten.
|
||||||
MODLOADER_DENIED=§cMit Fabric, Forge und LiteLoader kannst du keinen Arenen beitreten.
|
MODLOADER_DENIED=§cMit Fabric, Forge und LiteLoader kannst du keinen Arenen beitreten.
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren