Merge branch 'master' into arena_merging_2.0
Dieser Commit ist enthalten in:
Commit
081a1d42ff
@ -132,6 +132,7 @@ public class BungeeCore extends Plugin {
|
||||
new PunishmentCommand("noschemsharing", Punishment.PunishmentType.NoSchemSharing);
|
||||
new PunishmentCommand("noschemsubmitting", Punishment.PunishmentType.NoSchemSubmitting);
|
||||
new PunishmentCommand("nodev", Punishment.PunishmentType.NoDevServer);
|
||||
new PunishmentCommand("nofight", Punishment.PunishmentType.NoFightServer);
|
||||
|
||||
if(!EVENT_MODE){
|
||||
new BauCommand();
|
||||
@ -272,12 +273,6 @@ public class BungeeCore extends Plugin {
|
||||
Persistent.setChatPrefix(CHAT_PREFIX);
|
||||
Persistent.setLobbyServer(LOBBY_SERVER);
|
||||
|
||||
Statement.connect(
|
||||
config.getString("db.url"),
|
||||
config.getString("db.username"),
|
||||
config.getString("db.password")
|
||||
);
|
||||
|
||||
if (config.contains("discord")) {
|
||||
SteamwarDiscordBotConfig.loadConfig(config.getSection("discord"));
|
||||
}
|
||||
|
@ -20,7 +20,6 @@
|
||||
package de.steamwar.bungeecore;
|
||||
|
||||
import de.steamwar.bungeecore.sql.SWException;
|
||||
import de.steamwar.bungeecore.sql.Statement;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
@ -63,7 +62,7 @@ public class ErrorLogger extends Handler {
|
||||
SWException.log("Bungee", "DDOS", ddosRate + "");
|
||||
}
|
||||
return;
|
||||
} else if (!Statement.connectionStable()) {
|
||||
} else if (stacktrace.contains("ErrorLogger")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -88,6 +87,7 @@ public class ErrorLogger extends Handler {
|
||||
contains.add("Error authenticating ");
|
||||
contains.add("read timed out");
|
||||
contains.add("Connection reset by peer");
|
||||
contains.add("No client connected for pending server");
|
||||
ignoreContains = Collections.unmodifiableList(contains);
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.Servertype;
|
||||
import de.steamwar.bungeecore.Subserver;
|
||||
import de.steamwar.bungeecore.SubserverSystem;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -40,6 +42,11 @@ public class ArenaCommand extends BasicCommand {
|
||||
return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player);
|
||||
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerInfo server = ProxyServer.getInstance().getServerInfo(String.join(" ", args));
|
||||
if(server == null) {
|
||||
Message.send("ARENA_NOT_FOUND", player);
|
||||
|
@ -130,18 +130,20 @@ public class CheckCommand extends BasicCommand {
|
||||
CheckSession current = currentSchems.get(schematic.getId());
|
||||
long waitedMillis = Timestamp.from(Instant.now()).getTime() - schematic.getLastUpdate().getTime();
|
||||
String color = waitedMillis > 14400000 ? (waitedMillis > 86400000 ? "§c" : "§e") : "§a";
|
||||
String waitTime = Timestamp.from(Instant.ofEpochMilli(waitedMillis)).toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("CHECK_LIST_WAIT", player, color)));
|
||||
long hours = waitedMillis / 3600000;
|
||||
long minutes = (waitedMillis - hours * 3600000) / 60000;
|
||||
String waitTime = color + Message.parse("CHECK_LIST_WAIT", player, hours, (minutes < 10) ? "0" + minutes : minutes);
|
||||
if (current == null) {
|
||||
Message.sendPrefixless("CHECK_LIST_TO_CHECK", player,
|
||||
waitTime,
|
||||
Message.parse("CHECK_LIST_TO_CHECK_HOVER", player),
|
||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check schematic " + schematic.getId()),
|
||||
waitTime,
|
||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName());
|
||||
} else {
|
||||
Message.sendPrefixless("CHECK_LIST_CHECKING", player,
|
||||
waitTime,
|
||||
Message.parse("CHECK_LIST_CHECKING_HOVER", player),
|
||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName()),
|
||||
waitTime,
|
||||
schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.getName());
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.bungeecore.inventory.SWInventory;
|
||||
import de.steamwar.bungeecore.inventory.SWItem;
|
||||
import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
@ -130,6 +132,12 @@ public class FightCommand extends BasicCommand {
|
||||
return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player);
|
||||
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(alreadyInArena(player))
|
||||
return;
|
||||
|
||||
|
@ -19,7 +19,10 @@
|
||||
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.bungeecore.ArenaMode;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.ServerStarter;
|
||||
import de.steamwar.bungeecore.Subserver;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
|
||||
|
@ -24,6 +24,7 @@ import de.steamwar.bungeecore.inventory.SWItem;
|
||||
import de.steamwar.bungeecore.inventory.SWListInv;
|
||||
import de.steamwar.bungeecore.inventory.SWStreamInv;
|
||||
import de.steamwar.bungeecore.sql.Fight;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.bungeecore.sql.SchematicType;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@ -45,6 +46,11 @@ public class ReplayCommand extends BasicCommand {
|
||||
return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player);
|
||||
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
new SWStreamInv<>(player, Message.parse("REPLAY_TITLE", player), (click, fight) -> {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
ArenaMode mode = fight.getGameMode();
|
||||
|
@ -20,10 +20,7 @@
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.bungeecore.sql.BauweltMember;
|
||||
import de.steamwar.bungeecore.sql.Event;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.bungeecore.sql.Team;
|
||||
import de.steamwar.bungeecore.sql.*;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -50,6 +47,7 @@ public class TpCommand extends BasicCommand {
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!(sender instanceof ProxiedPlayer))
|
||||
return;
|
||||
|
||||
if(!onTp((ProxiedPlayer) sender, args))
|
||||
Message.send("TP_NOT_FOUND", sender);
|
||||
}
|
||||
@ -91,6 +89,14 @@ public class TpCommand extends BasicCommand {
|
||||
if(server == null || server == player.getServer().getInfo())
|
||||
return false;
|
||||
|
||||
// Check if player is allowed to join fights
|
||||
if (Subserver.getSubserver(server).getType() == Servertype.ARENA) {
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player);
|
||||
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
teleport(player, server);
|
||||
return true;
|
||||
}
|
||||
|
@ -21,9 +21,10 @@ package de.steamwar.bungeecore.comms;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.comms.handlers.*;
|
||||
import de.steamwar.bungeecore.comms.packets.FightEndsPacket;
|
||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
@ -46,7 +47,7 @@ public class SpigotReceiver extends BasicListener {
|
||||
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
||||
Byte handler = in.readByte();
|
||||
handlerMap.get(handler).handle(in, ((Server) event.getSender()).getInfo());
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> handlerMap.get(handler).handle(in, ((Server) event.getSender()).getInfo()));
|
||||
}
|
||||
|
||||
public static void registerHandler(Byte id, SpigotHandler handler) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bungeecore.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.sql.BannedUserIPs;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
@ -40,54 +41,58 @@ public class BanListener extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(LoginEvent event) {
|
||||
SteamwarUser user = SteamwarUser.getOrCreate(event.getConnection());
|
||||
if (user.isPunished(Punishment.PunishmentType.Ban)) {
|
||||
user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress());
|
||||
event.setCancelled(true);
|
||||
event.setCancelReason(user.punishmentMessage(Punishment.PunishmentType.Ban, ProxyServer.getInstance().getPlayer(event.getConnection().getUniqueId())));
|
||||
return;
|
||||
}
|
||||
event.registerIntent(BungeeCore.get());
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
||||
SteamwarUser user = SteamwarUser.getOrCreate(event.getConnection());
|
||||
if (user.isPunished(Punishment.PunishmentType.Ban)) {
|
||||
user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress());
|
||||
event.setCancelled(true);
|
||||
event.setCancelReason(user.punishmentMessage(Punishment.PunishmentType.Ban, ProxyServer.getInstance().getPlayer(event.getConnection().getUniqueId())));
|
||||
return;
|
||||
}
|
||||
|
||||
List<BannedUserIPs> ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress());
|
||||
if(!ips.isEmpty()){
|
||||
List<BannedUserIPs> ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress());
|
||||
if(!ips.isEmpty()){
|
||||
|
||||
Timestamp highestBan = ips.get(0).getTimestamp();
|
||||
boolean perma = false;
|
||||
for(BannedUserIPs banned : ips) {
|
||||
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
|
||||
if (bannedUser.isPunished(Punishment.PunishmentType.Ban)) {
|
||||
Punishment ban = bannedUser.getPunishment(Punishment.PunishmentType.Ban);
|
||||
if(ban.isPerma()) {
|
||||
perma = true;
|
||||
break;
|
||||
Timestamp highestBan = ips.get(0).getTimestamp();
|
||||
boolean perma = false;
|
||||
for(BannedUserIPs banned : ips) {
|
||||
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
|
||||
if (bannedUser.isPunished(Punishment.PunishmentType.Ban)) {
|
||||
Punishment ban = bannedUser.getPunishment(Punishment.PunishmentType.Ban);
|
||||
if(ban.isPerma()) {
|
||||
perma = true;
|
||||
break;
|
||||
}
|
||||
if(ban.getEndTime().after(highestBan))
|
||||
highestBan = ban.getEndTime();
|
||||
}
|
||||
}
|
||||
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ban " + user.getUserName() + " "
|
||||
+ (perma?"perma":highestBan.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy_HH:mm")))
|
||||
+ " Bannumgehung");
|
||||
|
||||
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
if ((target.hasPermission("bungeecore.teamchat"))
|
||||
&& (target.getChatMode() == ProxiedPlayer.ChatMode.COMMANDS_ONLY
|
||||
|| target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN)){
|
||||
StringBuilder potentialBan = new StringBuilder();
|
||||
potentialBan.append(Message.parsePrefixed("BAN_AVOIDING_ALERT", target, user.getUserName()));
|
||||
|
||||
for(BannedUserIPs banned : ips) {
|
||||
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
|
||||
potentialBan.append(Message.parse("BAN_AVOIDING_LIST", target, bannedUser.getUserName(),
|
||||
banned.getTimestamp().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", target)))));
|
||||
}
|
||||
|
||||
TextComponent msg = new TextComponent(potentialBan.toString());
|
||||
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("BAN_AVOIDING_BAN_HOVER", target)).create()));
|
||||
msg.setClickEvent(clickEvent);
|
||||
target.sendMessage(msg);
|
||||
}
|
||||
if(ban.getEndTime().after(highestBan))
|
||||
highestBan = ban.getEndTime();
|
||||
}
|
||||
}
|
||||
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ban " + user.getUserName() + " "
|
||||
+ (perma?"perma":highestBan.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy_HH:mm")))
|
||||
+ " Bannumgehung");
|
||||
|
||||
for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()){
|
||||
if ((target.hasPermission("bungeecore.teamchat"))
|
||||
&& (target.getChatMode() == ProxiedPlayer.ChatMode.COMMANDS_ONLY
|
||||
|| target.getChatMode() == ProxiedPlayer.ChatMode.SHOWN)){
|
||||
StringBuilder potentialBan = new StringBuilder();
|
||||
potentialBan.append(Message.parsePrefixed("BAN_AVOIDING_ALERT", target, user.getUserName()));
|
||||
|
||||
for(BannedUserIPs banned : ips) {
|
||||
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
|
||||
potentialBan.append(Message.parse("BAN_AVOIDING_LIST", target, bannedUser.getUserName(),
|
||||
banned.getTimestamp().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", target)))));
|
||||
}
|
||||
|
||||
TextComponent msg = new TextComponent(potentialBan.toString());
|
||||
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Message.parse("BAN_AVOIDING_BAN_HOVER", target)).create()));
|
||||
msg.setClickEvent(clickEvent);
|
||||
target.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
event.completeIntent(BungeeCore.get());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class ChatListener extends BasicListener {
|
||||
return;
|
||||
|
||||
e.setCancelled(true);
|
||||
publicChat(user, sender, e.getMessage());
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> publicChat(user, sender, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ public class ChatListener extends BasicListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message){
|
||||
private void publicChat(SteamwarUser user, ProxiedPlayer sender, String message) {
|
||||
String name = UserElo.getEmblem(user) + sender.getDisplayName();
|
||||
String chatcolor = user.getUserGroup().getChatColorCode();
|
||||
|
||||
|
@ -19,8 +19,10 @@
|
||||
|
||||
package de.steamwar.bungeecore.listeners;
|
||||
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.sql.Session;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
@ -40,7 +42,8 @@ public class SessionManager extends BasicListener {
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerDisconnectEvent e){
|
||||
Timestamp timestamp = sessions.remove(e.getPlayer());
|
||||
if(timestamp != null)
|
||||
Session.insertSession(SteamwarUser.get(e.getPlayer()).getId(), timestamp);
|
||||
if(timestamp != null) {
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> Session.insertSession(SteamwarUser.get(e.getPlayer()).getId(), timestamp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ public class Fabric extends BasicListener {
|
||||
|
||||
private final Set<String> neededMods = new HashSet<>();
|
||||
|
||||
public static final Map<ProxiedPlayer, Integer> checkedPlayers = new HashMap<>();
|
||||
|
||||
{
|
||||
neededMods.add("java");
|
||||
neededMods.add("minecraft");
|
||||
@ -108,8 +110,17 @@ public class Fabric extends BasicListener {
|
||||
}
|
||||
|
||||
if(Utils.handleMods(player,mods)) {
|
||||
if (checkedPlayers.containsKey(player)) {
|
||||
long current = checkedPlayers.get(player);
|
||||
if (current != dataString.hashCode()) {
|
||||
banPlayer(user, player);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Message.send("MODIFICATION_CHECK_SUCCESS", player);
|
||||
checkedPlayers.put(player, dataString.hashCode());
|
||||
}
|
||||
Storage.fabricPlayers.remove(player);
|
||||
Message.send("MODIFICATION_CHECK_SUCCESS", player);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ public class ModLoaderBlocker extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerDisconnectEvent e){
|
||||
Fabric.checkedPlayers.remove(e.getPlayer());
|
||||
Storage.fabricPlayers.remove(e.getPlayer());
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,9 @@ public class Punishment {
|
||||
NoSchemReceiving(false, "NOSCHEMRECEIVING_TEAM", "NOSCHEMRECEIVING_PERMA", "NOSCHEMRECEIVING_UNTIL", "UNNOSCHEMRECEIVING_ERROR", "UNNOSCHEMRECEIVING"),
|
||||
NoSchemSharing(false, "NOSCHEMSHARING_TEAM", "NOSCHEMSHARING_PERMA", "NOSCHEMSHARING_UNTIL", "UNNOSCHEMSHARING_ERROR", "UNNOSCHEMSHARING"),
|
||||
NoSchemSubmitting(true, "NOSCHEMSUBMITTING_TEAM", "NOSCHEMSUBMITTING_PERMA", "NOSCHEMSUBMITTING_UNTIL", "UNNOSCHEMSUBMITTING_ERROR", "UNNOSCHEMSUBMITTING"),
|
||||
NoDevServer(true, "NODEVSERVER_TEAM", "NODEVSERVER_PERMA", "NODEVSERVER_UNTIL", "UNNODEVSERVER_ERROR", "UNNODEVSERVER");
|
||||
NoDevServer(true, "NODEVSERVER_TEAM", "NODEVSERVER_PERMA", "NODEVSERVER_UNTIL", "UNNODEVSERVER_ERROR", "UNNODEVSERVER"),
|
||||
NoFightServer(false, "NOFIGHTSERVER_TEAM", "NOFIGHTSERVER_PERMA", "NOFIGHTSERVER_UNTIL", "UNNOFIGHTSERVER_ERROR", "UNNOFIGHTSERVER"),
|
||||
;
|
||||
|
||||
private final boolean needsAdmin;
|
||||
private final String teamMessage;
|
||||
|
@ -21,128 +21,167 @@ package de.steamwar.bungeecore.sql;
|
||||
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Statement implements AutoCloseable {
|
||||
|
||||
private static final Logger logger = BungeeCore.get().getLogger();
|
||||
|
||||
private static final List<Statement> statements = new ArrayList<>();
|
||||
private static final Deque<Connection> connections = new ArrayDeque<>();
|
||||
|
||||
private static Connection con;
|
||||
private static String url;
|
||||
private static String user;
|
||||
private static String password;
|
||||
private static final String URL;
|
||||
private static final String USER;
|
||||
private static final String PASSWORD;
|
||||
|
||||
public static void connect(String url, String user, String password) {
|
||||
Statement.url = url;
|
||||
Statement.user = user;
|
||||
Statement.password = password;
|
||||
static {
|
||||
File file = new File(BungeeCore.get().getDataFolder(), "MySQL.yml");
|
||||
Configuration config;
|
||||
try {
|
||||
con = DriverManager.getConnection(url + "?autoReconnect=true&useServerPrepStmts=true", user, password);
|
||||
} catch (SQLException e) {
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||
} catch (IOException e) {
|
||||
ProxyServer.getInstance().stop();
|
||||
throw new SecurityException("Could not start SQL-Connection", e);
|
||||
throw new SecurityException("Could not load SQL connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void reset() {
|
||||
closeAll();
|
||||
connect(url, user, password);
|
||||
try {
|
||||
for (Statement statement : statements) {
|
||||
statement.init();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Could not reprepare SQL statements", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
BungeeCore.get().getLogger().log(Level.INFO, "Could not close statement", e);
|
||||
}
|
||||
statements.remove(this);
|
||||
URL = "jdbc:mysql://" + config.getString("HOST") + ":" + config.getString("PORT") + "/" + config.getString("DATABASE");
|
||||
USER = config.getString("USER");
|
||||
PASSWORD = config.getString("PASSWORD");
|
||||
}
|
||||
|
||||
public static void closeAll() {
|
||||
synchronized (statements) {
|
||||
for (Statement statement : statements) {
|
||||
synchronized (connections) {
|
||||
for(Connection connection : connections) {
|
||||
try {
|
||||
statement.st.close();
|
||||
synchronized (statements) {
|
||||
statements.forEach(statement -> statement.close(connection));
|
||||
}
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
BungeeCore.get().getLogger().log(Level.INFO, "Could not close statement", e);
|
||||
logger.log(Level.INFO, "Could not close SQL connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
BungeeCore.get().getLogger().log(Level.INFO, "Could not close SQL connection", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean connectionStable() {
|
||||
try {
|
||||
return !con.isClosed();
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
connections.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private final String sql;
|
||||
private PreparedStatement st;
|
||||
private final Map<Connection, PreparedStatement> cachedStatements = new HashMap<>();
|
||||
|
||||
public Statement(String sql) {
|
||||
this.sql = sql;
|
||||
statements.add(this);
|
||||
try {
|
||||
init();
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Could not init SQL statement", e);
|
||||
synchronized (statements) {
|
||||
statements.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void init() throws SQLException {
|
||||
st = con.prepareStatement(sql);
|
||||
}
|
||||
|
||||
public <T> T select(ResultSetUser<T> user, Object... objects) {
|
||||
synchronized (statements) {
|
||||
return prepare(() -> {
|
||||
ResultSet rs = st.executeQuery();
|
||||
T result = user.use(rs);
|
||||
rs.close();
|
||||
return result;
|
||||
}, objects);
|
||||
}
|
||||
return withConnection(st -> {
|
||||
ResultSet rs = st.executeQuery();
|
||||
T result = user.use(rs);
|
||||
rs.close();
|
||||
return result;
|
||||
}, objects);
|
||||
}
|
||||
|
||||
public void update(Object... objects) {
|
||||
synchronized (statements) {
|
||||
prepare(st::executeUpdate, objects);
|
||||
}
|
||||
withConnection(PreparedStatement::executeUpdate, objects);
|
||||
}
|
||||
|
||||
private <T> T prepare(SQLRunnable<T> runnable, Object... objects) {
|
||||
private <T> T withConnection(SQLRunnable<T> runnable, Object... objects) {
|
||||
Connection connection = aquireConnection();
|
||||
|
||||
T result;
|
||||
try {
|
||||
setObjects(objects);
|
||||
return runnable.run();
|
||||
result = tryWithConnection(connection, runnable, objects);
|
||||
} catch (SQLException e) {
|
||||
reset();
|
||||
throw new SecurityException("Could not execute SQL statement", e);
|
||||
closeConnection(connection);
|
||||
connection = aquireConnection();
|
||||
try {
|
||||
result = tryWithConnection(connection, runnable, objects);
|
||||
} catch (SQLException ex) {
|
||||
closeConnection(connection);
|
||||
throw new SecurityException("Could not execute statement", ex);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized (connections) {
|
||||
connections.push(connection);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void setObjects(Object... objects) throws SQLException {
|
||||
private <T> T tryWithConnection(Connection connection, SQLRunnable<T> runnable, Object... objects) throws SQLException {
|
||||
PreparedStatement st = cachedStatements.get(connection);
|
||||
if(st == null) {
|
||||
st = connection.prepareStatement(sql);
|
||||
cachedStatements.put(connection, st);
|
||||
}
|
||||
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
st.setObject(i + 1, objects[i]);
|
||||
}
|
||||
|
||||
return runnable.run(st);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
cachedStatements.values().forEach(st -> closeStatement(st, false));
|
||||
cachedStatements.clear();
|
||||
synchronized (statements) {
|
||||
statements.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void close(Connection connection) {
|
||||
PreparedStatement st = cachedStatements.remove(connection);
|
||||
if(st != null)
|
||||
closeStatement(st, true);
|
||||
}
|
||||
|
||||
private static Connection aquireConnection() {
|
||||
synchronized (connections) {
|
||||
if(!connections.isEmpty())
|
||||
return connections.pop();
|
||||
}
|
||||
try {
|
||||
return DriverManager.getConnection(URL + "?autoReconnect=true&useServerPrepStmts=true", USER, PASSWORD);
|
||||
} catch (SQLException e) {
|
||||
throw new SecurityException("Could not open connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeConnection(Connection connection) {
|
||||
synchronized (statements) {
|
||||
for (Statement statement : statements) {
|
||||
statement.close(connection);
|
||||
}
|
||||
}
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
logger.log(Level.INFO, "Could not close connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeStatement(PreparedStatement st, boolean silent) {
|
||||
try {
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
if(!silent)
|
||||
logger.log(Level.INFO, "Could not close statement", e);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ResultSetUser<T> {
|
||||
@ -150,6 +189,6 @@ public class Statement implements AutoCloseable {
|
||||
}
|
||||
|
||||
private interface SQLRunnable<T> {
|
||||
T run() throws SQLException;
|
||||
T run(PreparedStatement st) throws SQLException;
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,12 @@ import java.util.stream.Collectors;
|
||||
|
||||
public enum UserGroup {
|
||||
|
||||
Admin("§4", "§e", "Obererzieher", true, true, true, true),
|
||||
Developer("§3", "§f", "Seelsorger", true, true, true, true),
|
||||
Moderator("§c", "§f", "Schichtleiter", true, true, true, true),
|
||||
Supporter("§9", "§f", "Kindergärtner", false, true, true, true),
|
||||
Builder("§2", "§f", "Hausmeister", false, true, false, true),
|
||||
YouTuber("§5", "§f", "Reporter", false, false, false, true),
|
||||
Admin("§4", "§e", "Admin", true, true, true, true),
|
||||
Developer("§3", "§f", "Dev", true, true, true, true),
|
||||
Moderator("§c", "§f", "Mod", true, true, true, true),
|
||||
Supporter("§9", "§f", "Sup", false, true, true, true),
|
||||
Builder("§2", "§f", "Arch", false, true, false, true),
|
||||
YouTuber("§5", "§f", "YT", false, false, false, true),
|
||||
Member("§7", "§7", "", false, false, false, false);
|
||||
|
||||
private final String colorCode;
|
||||
|
@ -130,29 +130,35 @@ MUTE_UNTIL=§7Du bist §ebis zum {0} §e§lgemuted§8. §7Grund§8: §e{1}
|
||||
UNMUTE_ERROR=§cDer Spieler ist nicht gemuted.
|
||||
UNMUTE=§7Du hast §e{0} §e§lentmuted.
|
||||
|
||||
NOSCHEMRECEIVING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematicerhalten ausgeschlossen§8. §7Grund§8: §f{4}
|
||||
NOSCHEMRECEIVING_PERMA=§7Du bist §epermanent §7vom Erhalten von §e§lSchematics ausgeschlossen§8. §7Grund§8: §e{0}
|
||||
NOSCHEMRECEIVING_UNTIL=§7Du bist §ebis zum {0} §7vom Erhalten von §e§lSchematics ausgeschlossen§8. §7Grund§8: §e{1}
|
||||
NOSCHEMRECEIVING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematicerhalten§7 ausgeschlossen§8. §7Grund§8: §f{4}
|
||||
NOSCHEMRECEIVING_PERMA=§7Du bist §epermanent §7vom Erhalten von §e§lSchematics§7 ausgeschlossen§8. §7Grund§8: §e{0}
|
||||
NOSCHEMRECEIVING_UNTIL=§7Du bist §ebis zum {0} §7vom Erhalten von §e§lSchematics§7 ausgeschlossen§8. §7Grund§8: §e{1}
|
||||
UNNOSCHEMRECEIVING_ERROR=§cDer Spieler ist nicht vom Erhalten von Schematics ausgeschlossen.
|
||||
UNNOSCHEMRECEIVING=§e{0} §7darf nun wieder §e§lSchematics erhalten§8.
|
||||
UNNOSCHEMRECEIVING=§e{0} §7darf nun wieder §e§lSchematics§7 erhalten§8.
|
||||
|
||||
NOSCHEMSHARING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematicverteilen ausgeschlossen§8. §7Grund§8: §f{4}
|
||||
NOSCHEMSHARING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematicverteilen§7 ausgeschlossen§8. §7Grund§8: §f{4}
|
||||
NOSCHEMSHARING_PERMA=§7Du bist §epermanent §7vom §e§lVerteilen von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{0}
|
||||
NOSCHEMSHARING_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lVerteilen von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{1}
|
||||
UNNOSCHEMSHARING_ERROR=§cDer Spieler ist nicht vom Verteilen von Schematics ausgeschlossen.
|
||||
UNNOSCHEMSHARING=§e{0} §7darf nun wieder §e§lSchematics verteilen§8.
|
||||
UNNOSCHEMSHARING=§e{0} §7darf nun wieder §e§lSchematics§7 verteilen§8.
|
||||
|
||||
NOSCHEMSUBMITTING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematiceinsenden ausgeschlossen§8. §7Grund§8: §f{4}
|
||||
NOSCHEMSUBMITTING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematiceinsenden§7 ausgeschlossen§8. §7Grund§8: §f{4}
|
||||
NOSCHEMSUBMITTING_PERMA=§7Du bist §epermanent §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{0}
|
||||
NOSCHEMSUBMITTING_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8. §7Grund§8: §e{1}
|
||||
UNNOSCHEMSUBMITTING_ERROR=§cDer Spieler ist nicht vom Einsenden von Schematics ausgeschlossen.
|
||||
UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis einsenden§8.
|
||||
UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis§7 einsenden§8.
|
||||
|
||||
NODEVSERVER_TEAM={0} §e{1} §7hat §e{2} §7mit Grund §f{4}§7 zu generft und hat daher §e§lDevserververbot §7erhalten§8, §e{3}
|
||||
NODEVSERVER_PERMA=§7Du bist §epermanent §7vom §e§lDevserver §7ausgeschlossen§8. §7Grund§8: §e{0}
|
||||
NODEVSERVER_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lDevserver §7ausgeschlossen§8. §7Grund§8: §e{1}
|
||||
NODEVSERVER_TEAM={0} §e{1} §7hat §e{2} §7mit Grund §f{4}§7 zu generft und hat daher §e§lDevserververbot§7 erhalten§8, §f{3}
|
||||
NODEVSERVER_PERMA=§7Du bist §epermanent §7vom §e§lDevserver§7 ausgeschlossen§8. §7Grund§8: §e{0}
|
||||
NODEVSERVER_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lDevserver§7 ausgeschlossen§8. §7Grund§8: §e{1}
|
||||
UNNODEVSERVER_ERROR=§cDer Spieler ist nicht vom Devserver ausgeschlossen.
|
||||
UNNODEVSERVER=§e{0} §7darf nun wieder dem §e§lDevserver beitreten§8.
|
||||
UNNODEVSERVER=§e{0} §7darf nun wieder dem §e§lDevserver§7 beitreten§8.
|
||||
|
||||
NOFIGHTSERVER_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lKämpfen§7 ausgeschlossen§8. §7Grund§8: §f{4}
|
||||
NOFIGHTSERVER_PERMA=§7Du bist §epermanent §7vom §e§lKämpfen§7 ausgeschlossen§8. §7Grund§8: §e{0}
|
||||
NOFIGHTSERVER_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lKämpfen§7 ausgeschlossen§8. §7Grund§8: §e{1}
|
||||
UNNOFIGHTSERVER_ERROR=§cDer Spieler ist nicht vom Kämpfen ausgeschlossen.
|
||||
UNNOFIGHTSERVER=§e{0} §7darf nun wieder §e§lKämpfen§7 beitreten§8.
|
||||
|
||||
#BugCommand
|
||||
BUG_MESSAGE=§7Dein Bugreport wurde gespeichert.
|
||||
@ -246,7 +252,7 @@ CHECK_HELP_DECLINE=§8/§7check decline §8[§eGrund§8] - §7Schematic ablehnen
|
||||
CHECK_HELP_CANCEL=§8/§7check cancel §8- §7Bricht den Prüfvorgang ab
|
||||
CHECK_LIST_HEADER=§e§lZu prüfen sind {0} Schematics
|
||||
CHECK_LIST_TO_CHECK={0} §8{1} §7{2} §e{3}
|
||||
CHECK_LIST_WAIT={0}d HH:mm
|
||||
CHECK_LIST_WAIT={0}:{1}
|
||||
CHECK_LIST_TO_CHECK_HOVER=§eSchematic prüfen
|
||||
CHECK_LIST_CHECKING={0} §8{1} §7{2} §e{3} §7wird geprüft von §e{4}
|
||||
CHECK_LIST_CHECKING_HOVER=§eZum Prüfer
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren