From eedfc627ad85f4eb0f11551de5fc069623d9e370 Mon Sep 17 00:00:00 2001 From: LartyHD Date: Fri, 4 Oct 2019 20:31:53 +0200 Subject: [PATCH] improved code.... #SoNowITravelToUSAAndBuyAGun! --- src/main/kotlin/de/tutorialwork/Main.kt | 286 ++++++++-------- .../kotlin/de/tutorialwork/commands/Ban.kt | 52 +-- .../de/tutorialwork/commands/Blacklist.kt | 54 +-- .../de/tutorialwork/commands/ChatLog.kt | 44 +-- .../kotlin/de/tutorialwork/commands/IPBan.kt | 112 +++---- .../kotlin/de/tutorialwork/commands/Kick.kt | 28 +- .../kotlin/de/tutorialwork/commands/Report.kt | 68 ++-- .../de/tutorialwork/commands/Reports.kt | 72 ++-- .../de/tutorialwork/commands/Support.kt | 206 ++++++------ .../kotlin/de/tutorialwork/commands/UnBan.kt | 70 ++-- .../de/tutorialwork/commands/WebAccount.kt | 84 ++--- .../kotlin/de/tutorialwork/global/Vars.kt | 18 +- .../kotlin/de/tutorialwork/listener/Chat.kt | 163 ++++----- .../kotlin/de/tutorialwork/listener/Login.kt | 143 ++++---- .../kotlin/de/tutorialwork/listener/Quit.kt | 24 +- .../kotlin/de/tutorialwork/sql/Accounts.kt | 17 + .../kotlin/de/tutorialwork/sql/AppTokens.kt | 14 + src/main/kotlin/de/tutorialwork/sql/Bans.kt | 23 ++ src/main/kotlin/de/tutorialwork/sql/Chat.kt | 12 +- .../kotlin/de/tutorialwork/sql/ChatLog.kt | 20 ++ src/main/kotlin/de/tutorialwork/sql/Ips.kt | 20 ++ src/main/kotlin/de/tutorialwork/sql/Log.kt | 18 + .../kotlin/de/tutorialwork/sql/Reasons.kt | 20 ++ .../kotlin/de/tutorialwork/sql/Reports.kt | 20 ++ src/main/kotlin/de/tutorialwork/sql/UnBans.kt | 18 + .../de/tutorialwork/utils/BanFunctions.kt | 312 +++++++++--------- .../kotlin/de/tutorialwork/utils/Functions.kt | 92 +++--- .../de/tutorialwork/utils/LogManager.kt | 25 -- .../de/tutorialwork/utils/MySQLConnect.kt | 93 +++--- .../kotlin/de/tutorialwork/utils/SQLUtils.kt | 20 ++ 30 files changed, 1147 insertions(+), 1001 deletions(-) create mode 100644 src/main/kotlin/de/tutorialwork/sql/Accounts.kt create mode 100644 src/main/kotlin/de/tutorialwork/sql/AppTokens.kt create mode 100644 src/main/kotlin/de/tutorialwork/sql/Bans.kt create mode 100644 src/main/kotlin/de/tutorialwork/sql/ChatLog.kt create mode 100644 src/main/kotlin/de/tutorialwork/sql/Ips.kt create mode 100644 src/main/kotlin/de/tutorialwork/sql/Log.kt create mode 100644 src/main/kotlin/de/tutorialwork/sql/Reasons.kt create mode 100644 src/main/kotlin/de/tutorialwork/sql/Reports.kt create mode 100644 src/main/kotlin/de/tutorialwork/sql/UnBans.kt delete mode 100644 src/main/kotlin/de/tutorialwork/utils/LogManager.kt create mode 100644 src/main/kotlin/de/tutorialwork/utils/SQLUtils.kt diff --git a/src/main/kotlin/de/tutorialwork/Main.kt b/src/main/kotlin/de/tutorialwork/Main.kt index e26192d..a4fc667 100644 --- a/src/main/kotlin/de/tutorialwork/Main.kt +++ b/src/main/kotlin/de/tutorialwork/Main.kt @@ -9,165 +9,141 @@ import de.tutorialwork.utils.* import net.md_5.bungee.api.plugin.Command import net.md_5.bungee.api.plugin.Listener import net.md_5.bungee.api.plugin.Plugin -import java.io.File import java.util.concurrent.TimeUnit class Main : Plugin() { - init { - instance = this - } - - override fun onEnable() { - config() - mySQL() - registerCommands() - registerListeners() - //Konsolen Nachricht über das Plugin - proxy.console.msg( - "§8[]===================================[]", - "§e§lProfessionalBans §7§oReloaded §8| §7Version: §c$version", - "§7Developer: §e§lLartyHD, LeBaasti (((based by Tutorialwork)))", - "§8[]===================================[]" - ) - - - //Überprüft auf Bans aus dem Webinterface - proxy.scheduler.schedule(this, { - for (all in proxy.players) { - val uuid = all.uniqueId - if (uuid.isBanned) { - if (uuid.rawEnd == -1L) { - all.kick(config.getString("LAYOUT.BAN") - .replace("%grund%", uuid.reasonString).translateColors()) - } else all.sendTempBan() - } - } - }, 5, 5, TimeUnit.SECONDS) - } - - private fun config() { - if (!dataFolder.exists()) dataFolder.mkdirs() - if (!mysqlFile.exists()) { - mysqlFile.createNewFile() - mysqlConfig.set("HOST", "localhost") - mysqlConfig.set("DATENBANK", "Bans") - mysqlConfig.set("USER", "root") - mysqlConfig.set("PASSWORT", "deinpasswort") - saveConfig(mysqlConfig, mysqlFile) - } - if (!configFile.exists()) { - configFile.createNewFile() - config.set("PREFIX", "&e&lBANS &8• &7") - config.set("LAYOUT.BAN", "&8[]===================================[] \n\n &4&lDu wurdest GEBANNT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") - config.set("LAYOUT.KICK", "&8[]===================================[] \n\n &e&lDu wurdest GEKICKT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") - config.set("LAYOUT.TEMPBAN", "&8[]===================================[] \n\n &4&lDu wurdest temporär GEBANNT \n\n &eGrund: §c§l%grund% \n &eRestzeit: &c&l%dauer% \n\n&8[]===================================[]") - config.set("LAYOUT.MUTE", "&8[]===================================[] \n\n &4&lDu wurdest GEMUTET \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") - config.set("LAYOUT.TEMPMUTE", "&8[]===================================[] \n\n &4&lDu wurdest temporär GEMUTET \n\n &eGrund: §c§l%grund% \n &eRestzeit: &c&l%dauer% \n\n&8[]===================================[]") - config.set("LAYOUT.IPBAN", "&8[]===================================[] \n\n &4&lDeine IP-Adresse wurde GEBANNT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") - config.set("LAYOUT.TEMPIPBAN", "&8[]===================================[] \n\n &4&lDeine IP-Adresse wurde temporär GEBANNT \n\n &eGrund: §c§l%grund% \n &eRestzeit: &c&l%dauer% \n\n&8[]===================================[]") - config.set("VPN.BLOCKED", true) - config.set("VPN.KICK", true) - config.set("VPN.KICKMSG", "&7Das benutzen einer &4VPN &7ist auf unserem Netzwerk &cUNTERSAGT") - config.set("VPN.BAN", false) - config.set("VPN.BANID", 0) - ipwhitelist.add("8.8.8.8") - config.set("VPN.WHITELIST", ipwhitelist) - config.set("VPN.APIKEY", "Go to https://proxycheck.io/dashboard and register with your email and enter here your API Key") - config.set("REPORTS.ENABLED", true) - reportreasons.add("Hacking") - reportreasons.add("Verhalten") - reportreasons.add("Teaming") - reportreasons.add("TPA-Falle") - reportreasons.add("Werbung") - config.set("REPORTS.REASONS", reportreasons) - config.set("REPORTS.OFFLINEREPORTS", false) - config.set("CHATLOG.ENABLED", true) - config.set("CHATLOG.URL", "DeinServer.net/BanWebinterface/public/chatlog.php?id=") - config.set("AUTOMUTE.ENABLED", false) - config.set("AUTOMUTE.AUTOREPORT", true) - //config.set("AUTOMUTE.AUTOREPORT.REASON", "Automatischer Report"); - config.set("AUTOMUTE.MUTEID", 0) - config.set("AUTOMUTE.ADMUTEID", 0) - config.set("BANTIME-INCREASE.ENABLED", true) - config.set("BANTIME-INCREASE.PERCENTRATE", 50) - saveConfig() - } else { - if (config.getBoolean("VPN.KICK") && config.getBoolean("VPN.BAN")) { - console.msg("§8[]===================================[]") - console.msg("§c§lSINNLOSE EINSTELLUNG ENTDECKT") - console.msg("§7Wenn ein Spieler mit einer VPN das Netzwerk betritt kann er nicht gekickt UND gebannt werden.") - console.msg("§4§lÜberprüfe die VPN Einstellung in der CONFIG.YML") - console.msg("§8[]===================================[]") - //Setze VPN Einstellung zurück! - config.set("VPN.BLOCKED", true) - config.set("VPN.KICK", true) - config.set("VPN.KICKMSG", "&7Das benutzen einer &4VPN &7ist auf unserem Netzwerk &cUNTERSAGT") - config.set("VPN.BAN", false) - config.set("VPN.BANID", 0) - } - for (reasons in config.getStringList("REPORTS.REASONS")) reportreasons.add(reasons.toUpperCase()) - for (ips in config.getStringList("VPN.WHITELIST")) ipwhitelist.add(ips) - prefix = config.getString("PREFIX").translateColors() - increaseBans = config.getBoolean("BANTIME-INCREASE.ENABLED") - increaseValue = config.getInt("BANTIME-INCREASE.PERCENTRATE") - if (config.getString("VPN.APIKEY").length == 27) { - APIKey = config.getString("VPN.APIKEY") - } - saveConfig() - } - if (!blacklistFile.exists()) blacklistFile.createNewFile() - blacklistConfig.apply { - blacklist.addAll(getStringList("BLACKLIST")) - adblacklist.addAll(getStringList("ADBLACKLIST")) - adwhitelist.addAll(getStringList("ADWHITELIST").map { it.toUpperCase() }) - } - } - - private fun mySQL() { - val file = File(dataFolder.path, "mysql.yml") - val mysqlFile = configProvider.load(file) - MySQLConnect.HOST = mysqlFile.getString("HOST") - MySQLConnect.DATABASE = mysqlFile.getString("DATENBANK") - MySQLConnect.USER = mysqlFile.getString("USER") - MySQLConnect.PASSWORD = mysqlFile.getString("PASSWORT") - - mysql = MySQLConnect(MySQLConnect.HOST, MySQLConnect.DATABASE, MySQLConnect.USER, MySQLConnect.PASSWORD) - mysql.update("CREATE TABLE IF NOT EXISTS accounts(UUID varchar(64) UNIQUE, USERNAME varchar(255), PASSWORD varchar(255), RANK int(11), GOOGLE_AUTH varchar(255), AUTHCODE varchar(255));") - mysql.update("CREATE TABLE IF NOT EXISTS reasons(ID int(11) UNIQUE, REASON varchar(255), TIME int(255), TYPE int(11), ADDED_AT varchar(11), BANS int(11), PERMS varchar(255));") - mysql.update("CREATE TABLE IF NOT EXISTS bans(UUID varchar(64) UNIQUE, NAME varchar(64), BANNED int(11), MUTED int(11), REASON varchar(64), END long, TEAMUUID varchar(64), BANS int(11), MUTES int(11), FIRSTLOGIN varchar(255), LASTLOGIN varchar(255));") - mysql.update("CREATE TABLE IF NOT EXISTS ips(IP varchar(64) UNIQUE, USED_BY varchar(64), USED_AT varchar(64), BANNED int(11), REASON varchar(64), END long, TEAMUUID varchar(64), BANS int(11));") - mysql.update("CREATE TABLE IF NOT EXISTS reports(ID int(11) AUTO_INCREMENT UNIQUE, UUID varchar(64), REPORTER varchar(64), TEAM varchar(64), REASON varchar(64), LOG varchar(64), STATUS int(11), CREATED_AT long);") - mysql.update("CREATE TABLE IF NOT EXISTS chat(ID int(11) AUTO_INCREMENT UNIQUE, UUID varchar(64), SERVER varchar(64), MESSAGE varchar(2500), SENDDATE varchar(255));") - mysql.update("CREATE TABLE IF NOT EXISTS chatlog(ID int(11) AUTO_INCREMENT UNIQUE, LOGID varchar(255), UUID varchar(64), CREATOR_UUID varchar(64), SERVER varchar(64), MESSAGE varchar(2500), SENDDATE varchar(255), CREATED_AT varchar(255));") - mysql.update("CREATE TABLE IF NOT EXISTS log(ID int(11) AUTO_INCREMENT UNIQUE, UUID varchar(255), BYUUID varchar(255), ACTION varchar(255), NOTE varchar(255), DATE varchar(255));") - mysql.update("CREATE TABLE IF NOT EXISTS unbans(ID int(11) AUTO_INCREMENT UNIQUE, UUID varchar(255), FAIR int(11), MESSAGE varchar(10000), DATE varchar(255), STATUS int(11));") - mysql.update("CREATE TABLE IF NOT EXISTS apptokens(UUID varchar(36) UNIQUE, TOKEN varchar(555));") - //SQL Update 2.0 - mysql.update("ALTER TABLE accounts ADD IF NOT EXISTS AUTHSTATUS int(11);") - //SQL Update 2.2 - mysql.update("ALTER TABLE bans ADD IF NOT EXISTS FIRSTLOGIN varchar(255);") - mysql.update("ALTER TABLE bans ADD IF NOT EXISTS LASTLOGIN varchar(255);") - //SQL Update 2.4 - mysql.update("ALTER TABLE reasons ADD COLUMN SORTINDEX int(11)") - } - - private fun registerCommands() { - config - arrayOf(Ban, UnBan, Kick, WebAccount, Check, IPBan, Blacklist, WebVerify, Support).forEach(::register) - - if (config.getBoolean("REPORTS.ENABLED")) { - register(Report) - register(Reports) - } - if (config.getBoolean("CHATLOG.ENABLED")) register(ChatLog) - - } - - private fun registerListeners() = arrayOf(Login, Chat, Quit).forEach(::register) - - private fun register(command: Command) = proxy.pluginManager.registerCommand(this, command) - private fun register(listener: Listener) = proxy.pluginManager.registerListener(this, listener) + init { + instance = this + } + + override fun onEnable() { + registerConfig() + registerBlackListConfig() + + registerMySQL() + + registerCommands() + registerListeners() + + //Konsolen Nachricht über das Plugin + proxy.console.msg( + "§8[]===================================[]", + "§e§lProfessionalBans §7§oReloaded §8| §7Version: §c$version", + "§7Developer: §e§lLartyHD, LeBaasti (((based by Tutorialwork)))", + "§8[]===================================[]" + ) + + //Überprüft auf Bans aus dem Webinterface + proxy.scheduler.schedule(this, { + proxy.players.filter { it.uniqueId.isBanned }.forEach { it.sendBan() } + }, 5, 5, TimeUnit.SECONDS) + } + + private fun registerConfig() { + if (!dataFolder.exists()) dataFolder.mkdirs() + if (!configFile.exists()) { + configFile.createNewFile() + config.set("PREFIX", "&e&lBANS &8• &7") + config.set("LAYOUT.BAN", "&8[]===================================[] \n\n &4&lDu wurdest GEBANNT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") + config.set("LAYOUT.KICK", "&8[]===================================[] \n\n &e&lDu wurdest GEKICKT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") + config.set("LAYOUT.TEMPBAN", "&8[]===================================[] \n\n &4&lDu wurdest temporär GEBANNT \n\n &eGrund: §c§l%grund% \n &eRestzeit: &c&l%dauer% \n\n&8[]===================================[]") + config.set("LAYOUT.MUTE", "&8[]===================================[] \n\n &4&lDu wurdest GEMUTET \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") + config.set("LAYOUT.TEMPMUTE", "&8[]===================================[] \n\n &4&lDu wurdest temporär GEMUTET \n\n &eGrund: §c§l%grund% \n &eRestzeit: &c&l%dauer% \n\n&8[]===================================[]") + config.set("LAYOUT.IPBAN", "&8[]===================================[] \n\n &4&lDeine IP-Adresse wurde GEBANNT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") + config.set("LAYOUT.TEMPIPBAN", "&8[]===================================[] \n\n &4&lDeine IP-Adresse wurde temporär GEBANNT \n\n &eGrund: §c§l%grund% \n &eRestzeit: &c&l%dauer% \n\n&8[]===================================[]") + config.set("VPN.BLOCKED", true) + config.set("VPN.KICK", true) + config.set("VPN.KICKMSG", "&7Das benutzen einer &4VPN &7ist auf unserem Netzwerk &cUNTERSAGT") + config.set("VPN.BAN", false) + config.set("VPN.BANID", 0) + config.set("VPN.WHITELIST", ipWhiteList + "8.8.8.8") + config.set("VPN.APIKEY", "Go to https://proxycheck.io/dashboard and register with your email and enter here your API Key") + config.set("REPORTS.ENABLED", true) + config.set("REPORTS.REASONS", reportReasons + listOf("Hacking", "Verhalten", "Teaming", "TPA-Falle", "Werbung")) + config.set("REPORTS.OFFLINEREPORTS", false) + config.set("CHATLOG.ENABLED", true) + config.set("CHATLOG.URL", "DeinServer.net/BanWebinterface/public/chatlog.php?id=") + config.set("AUTOMUTE.ENABLED", false) + config.set("AUTOMUTE.AUTOREPORT", true) + //config.set("AUTOMUTE.AUTOREPORT.REASON", "Automatischer Report"); + config.set("AUTOMUTE.MUTEID", 0) + config.set("AUTOMUTE.ADMUTEID", 0) + config.set("BANTIME-INCREASE.ENABLED", true) + config.set("BANTIME-INCREASE.PERCENTRATE", 50) + saveConfig() + } + config.getStringList("REPORTS.REASONS").forEach { reportReasons.add(it.toUpperCase()) } + config.getStringList("VPN.WHITELIST").forEach { ipWhiteList.add(it) } + prefix = config.getString("PREFIX").translateColors() + increaseBans = config.getBoolean("BANTIME-INCREASE.ENABLED") + increaseValue = config.getInt("BANTIME-INCREASE.PERCENTRATE") + if (config.getString("VPN.APIKEY").length == 27) + APIKey = config.getString("VPN.APIKEY") + } + + private fun registerBlackListConfig() { + if (!blacklistFile.exists()) blacklistFile.createNewFile() + blacklistConfig.apply { + blacklist.addAll(getStringList("BLACKLIST")) + adBlackList.addAll(getStringList("ADBLACKLIST")) + adWhiteList.addAll(getStringList("ADWHITELIST").map { it.toUpperCase() }) + } + } + + private fun registerMySQLConfig() { + if (!mysqlFile.exists()) { + mysqlFile.createNewFile() + mysqlConfig.set("HOST", "localhost") + mysqlConfig.set("DATENBANK", "Bans") + mysqlConfig.set("USER", "root") + mysqlConfig.set("PASSWORT", "deinpasswort") + saveConfig(mysqlConfig, mysqlFile) + } + + MySQLConnect.HOST = mysqlConfig.getString("HOST") + MySQLConnect.DATABASE = mysqlConfig.getString("DATENBANK") + MySQLConnect.USER = mysqlConfig.getString("USER") + MySQLConnect.PASSWORD = mysqlConfig.getString("PASSWORT") + } + + private fun registerMySQL() { + registerMySQLConfig() + mysql = MySQLConnect(MySQLConnect.HOST, MySQLConnect.DATABASE, MySQLConnect.USER, MySQLConnect.PASSWORD) + mysql.update("CREATE TABLE IF NOT EXISTS accounts(UUID varchar(64) UNIQUE, USERNAME varchar(255), PASSWORD varchar(255), RANK int(11), GOOGLE_AUTH varchar(255), AUTHCODE varchar(255));") + mysql.update("CREATE TABLE IF NOT EXISTS reasons(ID int(11) UNIQUE, REASON varchar(255), TIME int(255), TYPE int(11), ADDED_AT varchar(11), BANS int(11), PERMS varchar(255));") + mysql.update("CREATE TABLE IF NOT EXISTS bans(UUID varchar(64) UNIQUE, NAME varchar(64), BANNED int(11), MUTED int(11), REASON varchar(64), END long, TEAMUUID varchar(64), BANS int(11), MUTES int(11), FIRSTLOGIN varchar(255), LASTLOGIN varchar(255));") + mysql.update("CREATE TABLE IF NOT EXISTS ips(IP varchar(64) UNIQUE, USED_BY varchar(64), USED_AT varchar(64), BANNED int(11), REASON varchar(64), END long, TEAMUUID varchar(64), BANS int(11));") + mysql.update("CREATE TABLE IF NOT EXISTS reports(ID int(11) AUTO_INCREMENT UNIQUE, UUID varchar(64), REPORTER varchar(64), TEAM varchar(64), REASON varchar(64), LOG varchar(64), STATUS int(11), CREATED_AT long);") + mysql.update("CREATE TABLE IF NOT EXISTS chat(ID int(11) AUTO_INCREMENT UNIQUE, UUID varchar(64), SERVER varchar(64), MESSAGE varchar(2500), SENDDATE varchar(255));") + mysql.update("CREATE TABLE IF NOT EXISTS chatlog(ID int(11) AUTO_INCREMENT UNIQUE, LOGID varchar(255), UUID varchar(64), CREATOR_UUID varchar(64), SERVER varchar(64), MESSAGE varchar(2500), SENDDATE varchar(255), CREATED_AT varchar(255));") + mysql.update("CREATE TABLE IF NOT EXISTS log(ID int(11) AUTO_INCREMENT UNIQUE, UUID varchar(255), BYUUID varchar(255), ACTION varchar(255), NOTE varchar(255), DATE varchar(255));") + mysql.update("CREATE TABLE IF NOT EXISTS unbans(ID int(11) AUTO_INCREMENT UNIQUE, UUID varchar(255), FAIR int(11), MESSAGE varchar(10000), DATE varchar(255), STATUS int(11));") + mysql.update("CREATE TABLE IF NOT EXISTS apptokens(UUID varchar(36) UNIQUE, TOKEN varchar(555));") + //SQL Update 2.0 + mysql.update("ALTER TABLE accounts ADD IF NOT EXISTS AUTHSTATUS int(11);") + //SQL Update 2.2 + mysql.update("ALTER TABLE bans ADD IF NOT EXISTS FIRSTLOGIN varchar(255);") + mysql.update("ALTER TABLE bans ADD IF NOT EXISTS LASTLOGIN varchar(255);") + //SQL Update 2.4 + mysql.update("ALTER TABLE reasons ADD COLUMN SORTINDEX int(11)") + } + + private fun registerCommands() { + arrayOf(Ban, UnBan, Kick, WebAccount, Check, IPBan, Blacklist, WebVerify, Support).forEach(::register) + + if (config.getBoolean("REPORTS.ENABLED")) { + register(Report) + register(Reports) + } + if (config.getBoolean("CHATLOG.ENABLED")) register(ChatLog) + + } + + private fun registerListeners() = arrayOf(Login, Chat, Quit).forEach(::register) + + private fun register(command: Command) = proxy.pluginManager.registerCommand(this, command) + private fun register(listener: Listener) = proxy.pluginManager.registerListener(this, listener) } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/Ban.kt b/src/main/kotlin/de/tutorialwork/commands/Ban.kt index c6e9499..9900b0e 100644 --- a/src/main/kotlin/de/tutorialwork/commands/Ban.kt +++ b/src/main/kotlin/de/tutorialwork/commands/Ban.kt @@ -9,30 +9,30 @@ import net.md_5.bungee.api.plugin.Command object Ban : Command(simpleName()) { - override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name.toLowerCase()) { - if (args.size != 2) { - sender.sendBanReasonsList() - sender.msg("$prefix/${name.toLowerCase()} ") - return - } - val uuid = UUIDFetcher.getUUID(args[0]) ?: return - if (!uuid.playerExists()) { - sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten") - return - } - if (uuid.isWebaccountAdmin) { - sender.msg("${prefix}§cDiesen Spieler kannst du nicht bannen/muten") - return - } - val id = args[1].toIntOrNull() ?: return //add fail message - val type = if (id.isBanReason) ActionType.Ban(id) else ActionType.Mute(id) - if (id.hasExtraPermissions && !sender.hasPermission(id.extraPermissions)) { - sender.msg("${prefix}§cDu hast keine Berechtigung diesen ${type::class.java.simpleName}grund zu nutzen") - return - } - val executor = sender.executor - type.execute(uuid, executor) - type.sendNotify(uuid.name, sender.name) - LogManager.createEntry(uuid.toString(), executor, type) - } + override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name.toLowerCase()) { + if (args.size != 2) { + sender.sendBanReasonsList() + sender.msg("$prefix/${name.toLowerCase()} ") + return + } + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + if (!uuid.playerExists()) { + sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten") + return + } + if (uuid.isWebaccountAdmin) { + sender.msg("${prefix}§cDiesen Spieler kannst du nicht bannen/muten") + return + } + val id = args[1].toIntOrNull() ?: return //add fail message + val type = if (id.isBanReason) ActionType.Ban(id) else ActionType.Mute(id) + if (id.hasExtraPermissions && !sender.hasPermission(id.extraPermissions)) { + sender.msg("${prefix}§cDu hast keine Berechtigung diesen ${type::class.java.simpleName}grund zu nutzen") + return + } + val executor = sender.executor + type.execute(uuid, executor) + type.sendNotify(uuid.name, sender.name) + uuid.createLogEntry(executor, type) + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/Blacklist.kt b/src/main/kotlin/de/tutorialwork/commands/Blacklist.kt index 6b90e70..56a4cf6 100644 --- a/src/main/kotlin/de/tutorialwork/commands/Blacklist.kt +++ b/src/main/kotlin/de/tutorialwork/commands/Blacklist.kt @@ -8,32 +8,32 @@ import net.md_5.bungee.api.plugin.Command object Blacklist : Command(simpleName()) { - override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name) { - if (args.size != 2) { - sender.msg("${prefix}Derzeit sind §e§l${blacklist.size} Wörter §7auf der Blacklist") - sender.msg("$prefix/${name.toLowerCase()} ") - return - } - val word = args[1] - val x = when (args[0].toLowerCase()) { - "add" -> { - blacklist.add(word) - "hinzugefügt" - } - "del" -> { - if (word !in blacklist) { - sender.msg("${prefix}§cDieses Wort steht nicht auf der Blacklist") - return - } - blacklist.remove(word) - "entfernt" - } - else -> return - } - LogManager.createEntry("", sender.executor, ActionType.Blacklist("${args[0].toUpperCase()}_WORD_BLACKLIST")) - sender.msg("${prefix}§e§l$word §7wurde zur Blacklist $x") - blacklistConfig.set("BLACKLIST", blacklist) - saveConfig(blacklistConfig, blacklistFile) - } + override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name) { + if (args.size != 2) { + sender.msg("${prefix}Derzeit sind §e§l${blacklist.size} Wörter §7auf der Blacklist") + sender.msg("$prefix/${name.toLowerCase()} ") + return + } + val word = args[1] + val x = when (args[0].toLowerCase()) { + "add" -> { + blacklist.add(word) + "hinzugefügt" + } + "del" -> { + if (word !in blacklist) { + sender.msg("${prefix}§cDieses Wort steht nicht auf der Blacklist") + return + } + blacklist.remove(word) + "entfernt" + } + else -> return + } + null.createLogEntry(sender.executor, ActionType.Blacklist("${args[0].toUpperCase()}_WORD_BLACKLIST")) + sender.msg("${prefix}§e§l$word §7wurde zur Blacklist $x") + blacklistConfig.set("BLACKLIST", blacklist) + saveConfig(blacklistConfig, blacklistFile) + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/ChatLog.kt b/src/main/kotlin/de/tutorialwork/commands/ChatLog.kt index eb88749..c75fe1c 100644 --- a/src/main/kotlin/de/tutorialwork/commands/ChatLog.kt +++ b/src/main/kotlin/de/tutorialwork/commands/ChatLog.kt @@ -12,28 +12,28 @@ import net.md_5.bungee.api.plugin.Command object ChatLog : Command(simpleName()) { - private val chatLogUrl by lazy { config.getString("CHATLOG.URL") } + private val chatLogUrl by lazy { config.getString("CHATLOG.URL") } - override fun execute(sender: CommandSender, args: Array) { - if (args.size != 1) { - sender.msg("$prefix/${name.toLowerCase()} ") - return - } - val target = args[0].getUUID(sender) ?: return - target.exists(sender) ?: return - if (sender is ProxiedPlayer && sender.uniqueId == target) { - sender.msg("${prefix}§cDu kannst kein ChatLog von dir selbst erstellen") - return - } - if (!Chat.hasMessages(target)) { - sender.msg("${prefix}§cDieser Spieler hat in der letzten Zeit keine Nachrichten verfasst") - return - } - val executor = sender.executor - val id = Chat.createChatLog(target, executor) - LogManager.createEntry(target.toString(), executor, ActionType.Chatlog("CREATE_CHATLOG", id)) - sender.msg("${prefix}Der ChatLog von §e§l${target.name} §7wurde erfolgreich erstellt") - sender.msg("${prefix}Link: §e§l$chatLogUrl$id") - } + override fun execute(sender: CommandSender, args: Array) { + if (args.size != 1) { + sender.msg("$prefix/${name.toLowerCase()} ") + return + } + val target = args[0].getUUID(sender) ?: return + target.exists(sender) ?: return + if (sender is ProxiedPlayer && sender.uniqueId == target) { + sender.msg("${prefix}§cDu kannst kein ChatLog von dir selbst erstellen") + return + } + if (!Chat.hasMessages(target)) { + sender.msg("${prefix}§cDieser Spieler hat in der letzten Zeit keine Nachrichten verfasst") + return + } + val executor = sender.executor + val id = Chat.createChatLog(target, executor) + target.createLogEntry(executor, ActionType.Chatlog("CREATE_CHATLOG", id)) + sender.msg("${prefix}Der ChatLog von §e§l${target.name} §7wurde erfolgreich erstellt") + sender.msg("${prefix}Link: §e§l$chatLogUrl$id") + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/IPBan.kt b/src/main/kotlin/de/tutorialwork/commands/IPBan.kt index 3c276d2..c38b99b 100644 --- a/src/main/kotlin/de/tutorialwork/commands/IPBan.kt +++ b/src/main/kotlin/de/tutorialwork/commands/IPBan.kt @@ -10,63 +10,63 @@ import net.md_5.bungee.api.plugin.Command object IPBan : Command(IPBan::class.java.simpleName) { - override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name.toLowerCase()) { - if (sender is ProxiedPlayer) { - if (args.isEmpty() || args.size == 1) { - for (zaehler in 1 until countReasons() + 1) { - if (zaehler.isBanReason) { - sender.sendBanReasonsList() - sender.msg("§7$zaehler §8| §e${zaehler.reason}") - } - } - sender.msg("$prefix/ipban ") - } else { - val ip = args[0] - val id = Integer.valueOf(args[1]) - if (validate(ip)) { - if (ip.ipExists) { - ip.ban(id, sender.uniqueId.toString()) - ip.bans += 1 - ActionType.IpBan(id).sendNotify(ip, sender.name) - } else { - ip.insertIP(sender.uniqueId) - ip.ban(id, sender.uniqueId.toString()) - ip.bans += 1 - ActionType.IpBan(id).sendNotify(ip, sender.name) - } - disconnectIPBannedPlayers(ip) - LogManager.createEntry("", sender.uniqueId.toString(), ActionType.IpBan("IPBAN_IP")) - } else { - val uuid = UUIDFetcher.getUUID(args[0]) ?: return - val dbip = uuid.ip - dbip.ban(id, sender.uniqueId.toString()) - ip.bans += 1 - ActionType.IpBan(id).sendNotify(dbip, sender.name) - disconnectIPBannedPlayers(dbip) - LogManager.createEntry("", sender.uniqueId.toString(), ActionType.IpBan("IPBAN_PLAYER")) - } - } - } - } + override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name.toLowerCase()) { + if (sender is ProxiedPlayer) { + if (args.isEmpty() || args.size == 1) { + for (zaehler in 1 until countReasons() + 1) { + if (zaehler.isBanReason) { + sender.sendBanReasonsList() + sender.msg("§7$zaehler §8| §e${zaehler.reason}") + } + } + sender.msg("$prefix/ipban ") + } else { + val ip = args[0] + val id = Integer.valueOf(args[1]) + if (validate(ip)) { + if (ip.ipExists) { + ip.ban(id, sender.uniqueId.toString()) + ip.bans += 1 + ActionType.IpBan(id).sendNotify(ip, sender.name) + } else { + ip.insertIP(sender.uniqueId) + ip.ban(id, sender.uniqueId.toString()) + ip.bans += 1 + ActionType.IpBan(id).sendNotify(ip, sender.name) + } + disconnectIPBannedPlayers(ip) + null.createLogEntry(sender.uniqueId.toString(), ActionType.IpBan("IPBAN_IP")) + } else { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + val dbip = uuid.ip + dbip.ban(id, sender.uniqueId.toString()) + ip.bans += 1 + ActionType.IpBan(id).sendNotify(dbip, sender.name) + disconnectIPBannedPlayers(dbip) + null.createLogEntry(sender.uniqueId.toString(), ActionType.IpBan("IPBAN_PLAYER")) + } + } + } + } - private fun disconnectIPBannedPlayers(ip: String) { - for (all in players) { - if (all.address.hostString == ip) { - if (ip.rawEnd == -1L) { - all.kick(config.getString("LAYOUT.IPBAN").replace("%grund%", ip.reason).translateColors()) - } else { - if (System.currentTimeMillis() < ip.rawEnd) { - var msg = config.getString("LAYOUT.TEMPIPBAN") - msg = msg.replace("%grund%", ip.reason) - msg = msg.replace("%dauer%", getEnd(ip)) - all.kick(msg.translateColors()) - } else ip.unBan() - } - } - } - } + private fun disconnectIPBannedPlayers(ip: String) { + for (all in players) { + if (all.address.hostString == ip) { + if (ip.rawEnd == -1L) { + all.kick(config.getString("LAYOUT.IPBAN").replace("%grund%", ip.reason).translateColors()) + } else { + if (System.currentTimeMillis() < ip.rawEnd) { + var msg = config.getString("LAYOUT.TEMPIPBAN") + msg = msg.replace("%grund%", ip.reason) + msg = msg.replace("%dauer%", getEnd(ip)) + all.kick(msg.translateColors()) + } else ip.unBan() + } + } + } + } - private val PATTERN = "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$".toPattern() - fun validate(ip: String): Boolean = PATTERN.matcher(ip).matches() + private val PATTERN = "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$".toPattern() + fun validate(ip: String): Boolean = PATTERN.matcher(ip).matches() } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/Kick.kt b/src/main/kotlin/de/tutorialwork/commands/Kick.kt index 7190581..22da966 100644 --- a/src/main/kotlin/de/tutorialwork/commands/Kick.kt +++ b/src/main/kotlin/de/tutorialwork/commands/Kick.kt @@ -11,18 +11,18 @@ import net.md_5.bungee.api.plugin.Command object Kick : Command(simpleName()) { - override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name.toLowerCase()) { - if (args.size != 2) { - sender.msg("$prefix/${name.toLowerCase()} ") - return - } - val tokick = proxyServer.getPlayer(args[0]) - if (tokick != null) { - val grund = args.joinToString(" ") - ActionType.Kick(grund).sendNotify(tokick.name, sender.name) - LogManager.createEntry(tokick.uniqueId.toString(), sender.executor, ActionType.Kick(grund)) - tokick.kick(config.getString("LAYOUT.KICK") - .replace("%grund%", grund).translateColors()) - } else sender.msg("${prefix}§cDieser Spieler ist nicht online") - } + override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name.toLowerCase()) { + if (args.size != 2) { + sender.msg("$prefix/${name.toLowerCase()} ") + return + } + val tokick = proxyServer.getPlayer(args[0]) + if (tokick != null) { + val grund = args.joinToString(" ") + ActionType.Kick(grund).sendNotify(tokick.name, sender.name) + tokick.uniqueId.createLogEntry(sender.executor, ActionType.Kick(grund)) + tokick.kick(config.getString("LAYOUT.KICK") + .replace("%grund%", grund).translateColors()) + } else sender.msg("${prefix}§cDieser Spieler ist nicht online") + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/Report.kt b/src/main/kotlin/de/tutorialwork/commands/Report.kt index f0c50c2..40733b9 100644 --- a/src/main/kotlin/de/tutorialwork/commands/Report.kt +++ b/src/main/kotlin/de/tutorialwork/commands/Report.kt @@ -9,39 +9,39 @@ import net.md_5.bungee.api.plugin.Command object Report : Command(simpleName()) { - override fun execute(sender: CommandSender, args: Array) { - if (sender !is ProxiedPlayer) { - console.msg("${prefix}§e§lReports §7sind nur als Spieler verfügbar") - return - } - if (args.size <= 1) { - val reasons = reportreasons.joinToString() - sender.msg("${prefix}Verfügbare Reportgründe: §e§l$reasons") - sender.msg("$prefix/${name.toLowerCase()} ") - } else { - if (args[0].toUpperCase() == sender.name.toUpperCase()) sender.msg("${prefix}§cDu kannst dich nicht selbst melden") - else { - val reason = args[1].toUpperCase() - if (reason in reportreasons) { - val target = proxyServer.getPlayer(args[0]) - if (target != null) { - target.uniqueId.createReport(sender.uniqueId.toString(), reason, null) - sender.msg("""${prefix}Der Spieler §e§l${target.name} §7wurde erfolgreich wegen §e§l$reason §7gemeldet""") - ActionType.Report(reason).sendNotify(target.name, sender.name) - LogManager.createEntry(target.uniqueId.toString(), sender.uniqueId.toString(), ActionType.Report(reason)) - } else { - if (config.getBoolean("REPORTS.OFFLINEREPORTS")) { - val uuid = UUIDFetcher.getUUID(args[0]) ?: return - if (uuid.playerExists()) { - uuid.createReport(sender.uniqueId.toString(), reason, null) - sender.msg("${prefix}Der Spieler §e§l${args[0]} §7(§4Offline§7) wurde erfolgreich wegen §e§l$reason §7gemeldet") - LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), ActionType.Report(reason)) - } else sender.msg("${prefix}§cDieser Spieler wurde nicht gefunden") - } else sender.msg("${prefix}§cDieser Spieler ist offline") + override fun execute(sender: CommandSender, args: Array) { + if (sender !is ProxiedPlayer) { + console.msg("${prefix}§e§lReports §7sind nur als Spieler verfügbar") + return + } + if (args.size <= 1) { + val reasons = reportReasons.joinToString() + sender.msg("${prefix}Verfügbare Reportgründe: §e§l$reasons") + sender.msg("$prefix/${name.toLowerCase()} ") + } else { + if (args[0].toUpperCase() == sender.name.toUpperCase()) sender.msg("${prefix}§cDu kannst dich nicht selbst melden") + else { + val reason = args[1].toUpperCase() + if (reason in reportReasons) { + val target = proxyServer.getPlayer(args[0]) + if (target != null) { + target.uniqueId.createReport(sender.uniqueId.toString(), reason, null) + sender.msg("""${prefix}Der Spieler §e§l${target.name} §7wurde erfolgreich wegen §e§l$reason §7gemeldet""") + ActionType.Report(reason).sendNotify(target.name, sender.name) + target.uniqueId.createLogEntry(sender.uniqueId.toString(), ActionType.Report(reason)) + } else { + if (config.getBoolean("REPORTS.OFFLINEREPORTS")) { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + if (uuid.playerExists()) { + uuid.createReport(sender.uniqueId.toString(), reason, null) + sender.msg("${prefix}Der Spieler §e§l${args[0]} §7(§4Offline§7) wurde erfolgreich wegen §e§l$reason §7gemeldet") + uuid.createLogEntry(sender.uniqueId.toString(), ActionType.Report(reason)) + } else sender.msg("${prefix}§cDieser Spieler wurde nicht gefunden") + } else sender.msg("${prefix}§cDieser Spieler ist offline") - } - } else sender.msg("${prefix}§cDer eingegebene Reportgrund wurde nicht gefunden") - } - } - } + } + } else sender.msg("${prefix}§cDer eingegebene Reportgrund wurde nicht gefunden") + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/Reports.kt b/src/main/kotlin/de/tutorialwork/commands/Reports.kt index 18dec30..c46b5ae 100644 --- a/src/main/kotlin/de/tutorialwork/commands/Reports.kt +++ b/src/main/kotlin/de/tutorialwork/commands/Reports.kt @@ -15,39 +15,41 @@ import net.md_5.bungee.api.plugin.Command object Reports : Command(simpleName()) { - override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name) { - if (sender !is ProxiedPlayer) { - console.msg("${prefix}§e§lReports §7sind nur als Spieler verfügbar") - return - } - if (args.isEmpty()) { - if (countOpenReports() != 0) { - sender.msg("§8[]===================================[]") - sender.msg("§e§loffene Reports §7(§8" + countOpenReports() + "§7)") - var offline = 0 - for (element in iDsFromOpenReports) { - val target = proxyServer.getPlayer(element.reportName) - if (target != null) { - val tc = TextComponent() - tc.text = "§e§l${target.name} §7gemeldet wegen §c§l ${element.reportReason} §8| §7Online auf §e§l${target.server.info.name}" - tc.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/${name.toLowerCase()} jump ${target.name} $element") - tc.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentBuilder("§7Klicken um §e§l${target.name} §7nachzuspringen").create()) - sender.sendMessage(tc) - } else offline++ - } - if (offline != 0) sender.msg("§4§o$offline Reports §7§ovon Spieler die offline sind ausgeblendet") - sender.msg("§8[]===================================[]") - } else sender.msg("${prefix}§cEs sind derzeit keine Reports offen") - } else if (args[0].equals("jump", ignoreCase = true)) { - val target = proxyServer.getPlayer(args[1]) - if (target != null) { - sender.connect(target.server.info) - val id = Integer.parseInt(args[2]) - id.setReportDone() - sender.uniqueId.reportTeam(id) - sender.msg("${prefix}Du hast den Report von §e§l${id.reportName} §7wegen §c§l${id.reportReason} §aangenommen") - LogManager.createEntry(sender.uniqueId.toString(), null, ActionType.Report("REPORT_ACCEPT")) - } else sender.msg("${prefix}§cDieser Spieler ist nicht mehr online") - } - } + override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name) { + if (sender !is ProxiedPlayer) { + console.msg("${prefix}§e§lReports §7sind nur als Spieler verfügbar") + return + } + if (args.isEmpty()) { + if (countOpenReports() != 0) { + sender.msg("§8[]===================================[]") + sender.msg("§e§loffene Reports §7(§8" + countOpenReports() + "§7)") + var offline = 0 + for (element in iDsFromOpenReports) { + val target = proxyServer.getPlayer(element.reportName) + if (target != null) { + val tc = TextComponent() + tc.text = "§e§l${target.name} §7gemeldet wegen §c§l ${element.reportReason} §8| §7Online auf §e§l${target.server.info.name}" + tc.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/${name.toLowerCase()} jump ${target.name} $element") + tc.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentBuilder("§7Klicken um §e§l${target.name} §7nachzuspringen").create()) + sender.sendMessage(tc) + } else offline++ + } + if (offline != 0) sender.msg("§4§o$offline Reports §7§ovon Spieler die offline sind ausgeblendet") + sender.msg("§8[]===================================[]") + } else sender.msg("${prefix}§cEs sind derzeit keine Reports offen") + } else if (args[0].equals("jump", ignoreCase = true)) { + val target = proxyServer.getPlayer(args[1]) + if (target == null) { + sender.msg("${prefix}§cDieser Spieler ist nicht mehr online") + return@hasPermission + } + sender.connect(target.server.info) + val id = args[2].toInt() + id.setReportDone() + sender.uniqueId.reportTeam(id) + sender.uniqueId.createLogEntry(null, ActionType.Report("REPORT_ACCEPT")) + sender.msg("${prefix}Du hast den Report von §e§l${id.reportName} §7wegen §c§l${id.reportReason} §aangenommen") + } + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/Support.kt b/src/main/kotlin/de/tutorialwork/commands/Support.kt index 2917c70..8a7602b 100644 --- a/src/main/kotlin/de/tutorialwork/commands/Support.kt +++ b/src/main/kotlin/de/tutorialwork/commands/Support.kt @@ -13,108 +13,108 @@ import net.md_5.bungee.api.plugin.Command object Support : Command(simpleName()) { - override fun execute(sender: CommandSender, args: Array) { - if (sender is ProxiedPlayer) { - if (args.isNotEmpty()) { - if (args[0].equals("end", ignoreCase = true)) { - if (activechats.containsValue(sender) || activechats.containsKey(sender)) { - for (key in activechats.keys) { - //Key has started the support chat - if (key === sender) { - activechats[sender]?.msg(prefix + "§e§l" + sender.name + " §7hat den Support Chat §cbeeendet") - activechats.remove(key) - } else { - key.msg(prefix + "§e§l" + sender.name + " §7hat den Support Chat §cbeeendet") - activechats.remove(key) - } - } - sender.msg("${prefix}§cDu hast den Support Chat beendet") - return - } else { - sender.msg("${prefix}§cDu hast derzeit keinen offenen Support Chat") - return - } - } - } - if (sender.hasPermission("professionalbans.supportchat")) { - //Team Member - if (args.isNotEmpty()) { - for (all in players) { - if (all.name == args[0]) { - if (openchats.containsKey(all)) { - activechats[all] = sender - openchats.remove(all) - all.msg("""${prefix}§e§l${sender.name} §7ist jetzt mit dir im Support Chat""") - all.msg("${prefix}§8§oDu kannst in den Support Chat schreiben in dem du einfach eine normale Nachricht schreibst") - all.msg("${prefix}§8§oDu kannst den Support Chat mit §7§o/support end §8§obeenden") - sender.msg("""${prefix}§e§l${all.name} §7ist jetzt im Support Chat mit dir""") - sender.msg("${prefix}§8§oDu kannst den Support Chat mit §7§o/support end §8§obeenden") - } else { - sender.msg("${prefix}§cDiese Anfrage ist ausgelaufen") - } - } - } - } else { - if (openchats.isNotEmpty()) { - sender.msg("§8[]===================================[]") - var i = 0 - for (key in openchats.keys) { - sender.msg("""§e§l$key §8• §9${openchats[key]}""") - val tc = TextComponent() - tc.text = "§aSupport Chat starten" - tc.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/support $key") - tc.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentBuilder("§7Klicken um den Chat mit §e§l$key §7zu starten").create()) - sender.sendMessage(tc) - i++ - } - sender.msg("§8[]===================================[]") - sender.msg("""${prefix}Es sind derzeit §e§l$i Support Chats §7Anfragen §aoffen""") - } else { - sender.msg("${prefix}§cDerzeit sind keine Support Chats Anfragen offen") - } - } - } else { - //Normal Member - if (args.isEmpty()) { - sender.msg("${prefix}Wenn du den §e§lSupport Chat §7starten möchtest gebe ein §8§oBetreff §7ein") - sender.msg("${prefix}Möchtest du eine Anfrage abbrechen? §8§o/support cancel") - } else { - var supporter = 0 - for (all in players) { - if (all.hasPermission("professionalbans.supportchat") || all.hasPermission("professionalbans.*")) { - supporter++ - } - } - if (!args[0].equals("cancel", ignoreCase = true)) { - val subject = args.drop(1).joinToString { " " } - if (!openchats.containsKey(sender)) { - if (supporter > 0) { - openchats[sender] = subject - sender.msg("${prefix}Du hast eine Anfrage mit dem Betreff §e§l$subject §7gestartet") - for (all in players) { - if (all.hasPermission("professionalbans.supportchat")) { - all.msg(prefix + "§e§l" + sender.name + " §7benötigt Support §8(§e§o" + subject + "§8)") - val tc = TextComponent() - tc.text = "§aSupport Chat starten" - tc.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/support " + sender.name) - tc.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentBuilder("""§7Klicken um den Chat mit §e§l${sender.name} + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (args.isNotEmpty()) { + if (args[0].equals("end", ignoreCase = true)) { + if (activeChats.containsValue(sender) || activeChats.containsKey(sender)) { + for (key in activeChats.keys) { + //Key has started the support chat + if (key === sender) { + activeChats[sender]?.msg(prefix + "§e§l" + sender.name + " §7hat den Support Chat §cbeeendet") + activeChats.remove(key) + } else { + key.msg(prefix + "§e§l" + sender.name + " §7hat den Support Chat §cbeeendet") + activeChats.remove(key) + } + } + sender.msg("${prefix}§cDu hast den Support Chat beendet") + return + } else { + sender.msg("${prefix}§cDu hast derzeit keinen offenen Support Chat") + return + } + } + } + if (sender.hasPermission("professionalbans.supportchat")) { + //Team Member + if (args.isNotEmpty()) { + for (all in players) { + if (all.name == args[0]) { + if (openChats.containsKey(all)) { + activeChats[all] = sender + openChats.remove(all) + all.msg("""${prefix}§e§l${sender.name} §7ist jetzt mit dir im Support Chat""") + all.msg("${prefix}§8§oDu kannst in den Support Chat schreiben in dem du einfach eine normale Nachricht schreibst") + all.msg("${prefix}§8§oDu kannst den Support Chat mit §7§o/support end §8§obeenden") + sender.msg("""${prefix}§e§l${all.name} §7ist jetzt im Support Chat mit dir""") + sender.msg("${prefix}§8§oDu kannst den Support Chat mit §7§o/support end §8§obeenden") + } else { + sender.msg("${prefix}§cDiese Anfrage ist ausgelaufen") + } + } + } + } else { + if (openChats.isNotEmpty()) { + sender.msg("§8[]===================================[]") + var i = 0 + for (key in openChats.keys) { + sender.msg("""§e§l$key §8• §9${openChats[key]}""") + val tc = TextComponent() + tc.text = "§aSupport Chat starten" + tc.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/support $key") + tc.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentBuilder("§7Klicken um den Chat mit §e§l$key §7zu starten").create()) + sender.sendMessage(tc) + i++ + } + sender.msg("§8[]===================================[]") + sender.msg("""${prefix}Es sind derzeit §e§l$i Support Chats §7Anfragen §aoffen""") + } else { + sender.msg("${prefix}§cDerzeit sind keine Support Chats Anfragen offen") + } + } + } else { + //Normal Member + if (args.isEmpty()) { + sender.msg("${prefix}Wenn du den §e§lSupport Chat §7starten möchtest gebe ein §8§oBetreff §7ein") + sender.msg("${prefix}Möchtest du eine Anfrage abbrechen? §8§o/support cancel") + } else { + var supporter = 0 + for (all in players) { + if (all.hasPermission("professionalbans.supportchat") || all.hasPermission("professionalbans.*")) { + supporter++ + } + } + if (!args[0].equals("cancel", ignoreCase = true)) { + val subject = args.drop(1).joinToString { " " } + if (!openChats.containsKey(sender)) { + if (supporter > 0) { + openChats[sender] = subject + sender.msg("${prefix}Du hast eine Anfrage mit dem Betreff §e§l$subject §7gestartet") + for (all in players) { + if (all.hasPermission("professionalbans.supportchat")) { + all.msg(prefix + "§e§l" + sender.name + " §7benötigt Support §8(§e§o" + subject + "§8)") + val tc = TextComponent() + tc.text = "§aSupport Chat starten" + tc.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/support " + sender.name) + tc.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, ComponentBuilder("""§7Klicken um den Chat mit §e§l${sender.name} |§7zu starten""".trimMargin()).create()) - all.sendMessage(tc) - } - } - } else sender.msg("${prefix}§cDerzeit ist kein Supporter online") - } else { - sender.msg(prefix + "Du hast bereits eine §e§lSupport Chat §7Anfrage gestellt") - sender.msg(prefix + "Möchtest du diese Anfrage §cabbrechen §7benutze §c§l/support cancel") - } - } else { - if (!openchats.containsKey(sender)) { - openchats.remove(sender) - sender.msg(prefix + "Deine Anfrage wurde erfolgreich §cgelöscht") - } else sender.msg("${prefix}§cDu hast derzeit keine offene Anfrage") - } - } - } - } else console.msg(prefix + "Der §e§lSupport Chat §7ist nur als Spieler verfügbar") - } + all.sendMessage(tc) + } + } + } else sender.msg("${prefix}§cDerzeit ist kein Supporter online") + } else { + sender.msg(prefix + "Du hast bereits eine §e§lSupport Chat §7Anfrage gestellt") + sender.msg(prefix + "Möchtest du diese Anfrage §cabbrechen §7benutze §c§l/support cancel") + } + } else { + if (!openChats.containsKey(sender)) { + openChats.remove(sender) + sender.msg(prefix + "Deine Anfrage wurde erfolgreich §cgelöscht") + } else sender.msg("${prefix}§cDu hast derzeit keine offene Anfrage") + } + } + } + } else console.msg(prefix + "Der §e§lSupport Chat §7ist nur als Spieler verfügbar") + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/UnBan.kt b/src/main/kotlin/de/tutorialwork/commands/UnBan.kt index 5921000..6d61509 100644 --- a/src/main/kotlin/de/tutorialwork/commands/UnBan.kt +++ b/src/main/kotlin/de/tutorialwork/commands/UnBan.kt @@ -10,39 +10,39 @@ import net.md_5.bungee.api.plugin.Command object UnBan : Command(simpleName()) { - override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name) { - if (args.isEmpty() || args.size >= 2) sender.msg("$prefix/unBan ") - else { - val executor = sender.executor - val uuid = UUIDFetcher.getUUID(args[0]) ?: return - if (IPBan.validate(args[0])) { - args[0].unBan() - UnBanIp.sendNotify(args[0], sender.name) - sender.msg("${prefix}§7Die IP-Adresse §e§l${args[0]} §7wurde §aerfolgreich §7entbannt") - LogManager.createEntry("", executor, UnBanIp) - } else { - if (uuid.playerExists()) { - if (uuid.ip.isBanned) { - uuid.ip.unBan() - sender.msg("${prefix}Die IP §e§l${uuid.ip} §7war gebannt und wurde ebenfalls §aentbannt") - } - when { - uuid.isBanned -> { - uuid.unBan() - ActionType.UnBan.sendNotify(uuid.name, sender.name) - sender.msg("${prefix}§e§l${uuid.name} §7wurde §aerfolgreich §7entbannt") - LogManager.createEntry(uuid.toString(), executor, ActionType.UnBan) - } - uuid.isMuted -> { - uuid.unMute() - ActionType.UnMute.sendNotify(uuid.name, sender.name) - sender.msg("${prefix}§e§l${uuid.name} §7wurde §aerfolgreich §7entmutet") - LogManager.createEntry(uuid.toString(), executor, ActionType.UnMute) - } - else -> sender.msg("${prefix}§e§l${uuid.name} §7ist weder gebannt oder gemutet") - } - } else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten") - } - } - } + override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name) { + if (args.isEmpty() || args.size >= 2) sender.msg("$prefix/unBan ") + else { + val executor = sender.executor + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + if (IPBan.validate(args[0])) { + args[0].unBan() + UnBanIp.sendNotify(args[0], sender.name) + sender.msg("${prefix}§7Die IP-Adresse §e§l${args[0]} §7wurde §aerfolgreich §7entbannt") + null.createLogEntry(executor, UnBanIp) + } else { + if (uuid.playerExists()) { + if (uuid.ip.isBanned) { + uuid.ip.unBan() + sender.msg("${prefix}Die IP §e§l${uuid.ip} §7war gebannt und wurde ebenfalls §aentbannt") + } + when { + uuid.isBanned -> { + uuid.unBan() + ActionType.UnBan.sendNotify(uuid.name, sender.name) + sender.msg("${prefix}§e§l${uuid.name} §7wurde §aerfolgreich §7entbannt") + uuid.createLogEntry(executor, ActionType.UnBan) + } + uuid.isMuted -> { + uuid.unMute() + ActionType.UnMute.sendNotify(uuid.name, sender.name) + sender.msg("${prefix}§e§l${uuid.name} §7wurde §aerfolgreich §7entmutet") + uuid.createLogEntry(executor, ActionType.UnMute) + } + else -> sender.msg("${prefix}§e§l${uuid.name} §7ist weder gebannt oder gemutet") + } + } else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten") + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/WebAccount.kt b/src/main/kotlin/de/tutorialwork/commands/WebAccount.kt index 292942f..05ead4b 100644 --- a/src/main/kotlin/de/tutorialwork/commands/WebAccount.kt +++ b/src/main/kotlin/de/tutorialwork/commands/WebAccount.kt @@ -10,47 +10,47 @@ import net.md_5.bungee.api.plugin.Command object WebAccount : Command(simpleName()) { - override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name) { - if (sender is ProxiedPlayer) { - if (args.size <= 1) sender.msg("$prefix/webaccount [Rank]") - else { - when (args[0].toLowerCase()) { - "create" -> { - if (args.size == 2) { - sender.msg("${prefix}Du musst noch ein Rang des Accounts angeben ${RankType.values().joinToString { "${it.color}${it.name}§7, " }}") - return - } - val uuid = UUIDFetcher.getUUID(args[1]) ?: return - if (uuid.playerExists()) { - if (!uuid.webaccountExists) { - val target = proxyServer.getPlayer(args[1]) - if (target != null) { - val password = 7.randomString() - val rankType = RankType.values().find { it.name == args[2].toUpperCase() } ?: return - uuid.createWebAccount(rankType, password, sender) - sender.msg("${prefix}Ein ${rankType.color}§l${rankType.name.toLowerCase().capitalize()} §7Account für §e§l${uuid.name} §7wurde §aerstellt") - target.msg( - "${prefix}§e§l${sender.name} §7hat einen WebAccount für dich erstellt", - "${prefix}Passwort: §c§l$password" - ) - } else sender.msg("$prefix§e§l${args[1]} §7ist derzeit nicht online") - } else sender.msg("${prefix}§cDieser Spieler hat bereits einen Zugang zum Webinterface") - } else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten") - } - "delete" -> { - val uuid = UUIDFetcher.getUUID(args[1]) ?: return - if (uuid.playerExists()) { - if (uuid.webaccountExists) { - uuid.deleteWebAccount() - sender.msg("${prefix}Der Zugang von dem Spieler §e§l${uuid.name} §7wurde erfolgreich §agelöscht") - LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), ActionType.WebAccount("DEL_WEBACCOUNT")) - } else sender.msg("${prefix}§cDieser Spieler hat keinen Zugang zum Webinterface") - } else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten") - } - else -> sender.msg("$prefix/webaccount [Rang]") - } - } - } else sender.msg("${prefix}Nur Spieler können §e§lWebAccounts §7erstellen/löschen") - } + override fun execute(sender: CommandSender, args: Array) = sender.hasPermission(name) { + if (sender is ProxiedPlayer) { + if (args.size <= 1) sender.msg("$prefix/webaccount [Rank]") + else { + when (args[0].toLowerCase()) { + "create" -> { + if (args.size == 2) { + sender.msg("${prefix}Du musst noch ein Rang des Accounts angeben ${RankType.values().joinToString { "${it.color}${it.name}§7, " }}") + return + } + val uuid = UUIDFetcher.getUUID(args[1]) ?: return + if (uuid.playerExists()) { + if (!uuid.webaccountExists) { + val target = proxyServer.getPlayer(args[1]) + if (target != null) { + val password = 7.randomString() + val rankType = RankType.values().find { it.name == args[2].toUpperCase() } ?: return + uuid.createWebAccount(rankType, password, sender) + sender.msg("${prefix}Ein ${rankType.color}§l${rankType.name.toLowerCase().capitalize()} §7Account für §e§l${uuid.name} §7wurde §aerstellt") + target.msg( + "${prefix}§e§l${sender.name} §7hat einen WebAccount für dich erstellt", + "${prefix}Passwort: §c§l$password" + ) + } else sender.msg("$prefix§e§l${args[1]} §7ist derzeit nicht online") + } else sender.msg("${prefix}§cDieser Spieler hat bereits einen Zugang zum Webinterface") + } else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten") + } + "delete" -> { + val uuid = UUIDFetcher.getUUID(args[1]) ?: return + if (uuid.playerExists()) { + if (uuid.webaccountExists) { + uuid.deleteWebAccount() + sender.msg("${prefix}Der Zugang von dem Spieler §e§l${uuid.name} §7wurde erfolgreich §agelöscht") + uuid.createLogEntry(sender.uniqueId.toString(), ActionType.WebAccount("DEL_WEBACCOUNT")) + } else sender.msg("${prefix}§cDieser Spieler hat keinen Zugang zum Webinterface") + } else sender.msg("${prefix}§cDieser Spieler hat den Server noch nie betreten") + } + else -> sender.msg("$prefix/webaccount [Rang]") + } + } + } else sender.msg("${prefix}Nur Spieler können §e§lWebAccounts §7erstellen/löschen") + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/global/Vars.kt b/src/main/kotlin/de/tutorialwork/global/Vars.kt index 06af98a..5458363 100644 --- a/src/main/kotlin/de/tutorialwork/global/Vars.kt +++ b/src/main/kotlin/de/tutorialwork/global/Vars.kt @@ -1,23 +1,25 @@ package de.tutorialwork.global -import de.tutorialwork.Main import de.tutorialwork.utils.MySQLConnect import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Plugin var prefix = "§e§lBANS §8• §7" val noPerms get() = "${prefix}§cDu hast keine Berechtigung diesen Befehl zu nutzen" -lateinit var instance: Main +lateinit var instance: Plugin lateinit var mysql: MySQLConnect var APIKey: String? = null -var openchats = mutableMapOf() -var activechats = mutableMapOf() -var reportreasons = mutableListOf() +var openChats = mutableMapOf() +var activeChats = mutableMapOf() +var reportReasons = mutableListOf() + var blacklist = mutableListOf() -var adblacklist = mutableListOf() -var adwhitelist = mutableListOf() -var ipwhitelist = mutableListOf() +var adBlackList = mutableListOf() +var adWhiteList = mutableListOf() + +var ipWhiteList = mutableListOf() var increaseBans = true var increaseValue: Int = 50 \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/listener/Chat.kt b/src/main/kotlin/de/tutorialwork/listener/Chat.kt index 269d009..feee6f7 100644 --- a/src/main/kotlin/de/tutorialwork/listener/Chat.kt +++ b/src/main/kotlin/de/tutorialwork/listener/Chat.kt @@ -13,91 +13,96 @@ import java.util.* object Chat : Listener { - @EventHandler - fun onChat(event: ChatEvent) { - val player = event.sender as ProxiedPlayer - if (event.message.startsWith("/")) return - if (player in activechats) { - event.isCancelled = true - val target = activechats[player] ?: return - val prefix = "§9§lSUPPORT §8• §c" - target.msg( - "$prefix§c${player.name} §8» ${event.message}", - "$prefix§aDu §8» ${event.message}" - ) - activechats.keys.forEach { it.msg("$prefix§c${player.name} §8» ${event.message}") } - } - val uuid = player.uniqueId - if (uuid.isMuted) { - if (System.currentTimeMillis() >= uuid.rawEnd) { - uuid.unMute() - return - } - event.isCancelled = true - player.sendMute() - } else { - insertMessage(uuid, event.message, player.server.info.name) - if (player.hasPermission("${permissionPrefix}blacklist.bypass")) return - val predicate: (String) -> Boolean = { it.toUpperCase() in event.message.toUpperCase() } - when { - config.getBoolean("AUTOMUTE.ENABLED") -> { - val a = if (blacklist.any(predicate)) "" else { - if (adblacklist.any(predicate) && event.message.toUpperCase() !in adwhitelist) "AD" else return - } - uuid.mute(config.getInt("AUTOMUTE.${a}MUTEID").reason, consoleName) - LogManager.createEntry(uuid.toString(), consoleName, ActionType.Blacklist("AUTOMUTE_${a}BLACKLIST")) - ActionType.Mute(config.getInt("AUTOMUTE.MUTEID")).sendNotify(uuid.name, consoleName) - player.sendMute() - } - config.getBoolean("AUTOMUTE.AUTOREPORT") -> { - val reason: String = if (blacklist.any(predicate)) { - player.msg("${prefix}§cAchte auf deine Wortwahl") - "VERHALTEN" - } else { - if (adblacklist.any(predicate) && event.message.toUpperCase() !in adwhitelist) { - player.msg("${prefix}§cDu darfst keine Werbung machen") - "WERBUNG" - } else return - } - val logId = createChatLog(uuid, consoleName) - uuid.createReport(consoleName, reason, logId) - ActionType.Report(reason).sendNotify(player.name, consoleName) - } - else -> return - } - event.isCancelled = true - } - } + @EventHandler + fun onChat(event: ChatEvent) { + if (event.message.startsWith("/")) return + val player = event.sender as? ProxiedPlayer ?: return + if (player in activeChats) { + event.isCancelled = true + val target = activeChats[player] ?: return + val prefix = "§9§lSUPPORT §8• §c" + target.msg( + "$prefix§c${player.name} §8» ${event.message}", + "$prefix§aDu §8» ${event.message}" + ) + activeChats.keys.forEach { it.msg("$prefix§c${player.name} §8» ${event.message}") } + } + val uuid = player.uniqueId + if (uuid.isMuted) { + if (System.currentTimeMillis() >= uuid.rawEnd) { + uuid.unMute() + return + } + event.isCancelled = true + player.sendMute() + } else { + insertMessage(uuid, event.message, player.server.info.name) + if (player.hasPermission("${permissionPrefix}blacklist.bypass")) return + val predicate: (String) -> Boolean = { it.toUpperCase() in event.message.toUpperCase() } + when { + config.getBoolean("AUTOMUTE.ENABLED") -> { + val a = when { + blacklist.any(predicate) -> "" + adBlackList.any(predicate) && event.message.toUpperCase() !in adWhiteList -> "AD" + else -> return + } + uuid.createLogEntry(consoleName, ActionType.Blacklist("AUTOMUTE_${a}BLACKLIST")) + ActionType.Mute(config.getInt("AUTOMUTE.${a}MUTEID")).run { + execute(uuid, consoleName) + sendNotify(uuid.name, consoleName) + } + } + config.getBoolean("AUTOMUTE.AUTOREPORT") -> { + val reason: String = when { + blacklist.any(predicate) -> { + player.msg("${prefix}§cAchte auf deine Wortwahl") + "VERHALTEN" + } + adBlackList.any(predicate) && event.message.toUpperCase() !in adWhiteList -> { + player.msg("${prefix}§cDu darfst keine Werbung machen") + "WERBUNG" + } + else -> return + } + val logId = createChatLog(uuid, consoleName) + uuid.createReport(consoleName, reason, logId) + ActionType.Report(reason).sendNotify(player.name, consoleName) + } + else -> return + } + event.isCancelled = true + } + } - private fun insertMessage(uuid: UUID, message: String, server: String) { - Chat.insert { - it[this.uuid] = uuid.toString() - it[this.server] = server - it[this.message] = message - it[this.sendDate] = System.currentTimeMillis() - } - } + private fun insertMessage(uuid: UUID, message: String, server: String) { + Chat.insert { + it[this.uuid] = uuid.toString() + it[this.server] = server + it[this.message] = message + it[this.sendDate] = System.currentTimeMillis() + } + } - fun createChatLog(uuid: UUID, createdUUID: String): String { - val query = Chat.getByUUID(uuid) - val id = 20.randomString() - val now = System.currentTimeMillis() - val tenMinutes = 10 * 60 * 1000 - query.forEach { - val tenAgo = System.currentTimeMillis() - tenMinutes - val sendDate = it[Chat.sendDate] - if (sendDate > tenAgo) { - mysql.update("""INSERT INTO chatlog(LOGID, uuid, CREATOR_UUID, SERVER, MESSAGE, SENDDATE, CREATED_AT) VALUES ('$id' + fun createChatLog(uuid: UUID, createdUUID: String): String { + val query = Chat.getByUUID(uuid) + val id = 20.randomString() + val now = System.currentTimeMillis() + val tenMinutes = 10 * 60 * 1000 + query.forEach { + val tenAgo = System.currentTimeMillis() - tenMinutes + val sendDate = it[Chat.sendDate] + if (sendDate > tenAgo) { + mysql.update("""INSERT INTO chatlog(LOGID, uuid, CREATOR_UUID, SERVER, MESSAGE, SENDDATE, CREATED_AT) VALUES ('$id' |,'$uuid', '$createdUUID', '${it[Chat.server]}', '${it[Chat.message]}' |, '${sendDate}', '$now')""".trimMargin()) - } - } - return id - } + } + } + return id + } - fun hasMessages(uuid: UUID): Boolean = Chat.getByUUID(uuid).any() + fun hasMessages(uuid: UUID): Boolean = Chat.getByUUID(uuid).any() - private fun Chat.getByUUID(uuid: UUID) = select { Chat.uuid.eq(uuid.toString()) } + private fun Chat.getByUUID(uuid: UUID) = select { Chat.uuid.eq(uuid.toString()) } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/listener/Login.kt b/src/main/kotlin/de/tutorialwork/listener/Login.kt index 902a536..668a3c2 100644 --- a/src/main/kotlin/de/tutorialwork/listener/Login.kt +++ b/src/main/kotlin/de/tutorialwork/listener/Login.kt @@ -10,84 +10,79 @@ import net.md_5.bungee.event.EventHandler object Login : Listener { - @EventHandler - fun onPreLoginEvent(event: PreLoginEvent) { - val uuid = UUIDFetcher.getUUID(event.connection.name) ?: return - val ip = event.connection.virtualHost.hostName - /*val ip = event.connection.address.hostString*/ - uuid.updatePlayer(event.connection.name) - ip.insertIP(uuid) - if (config.getBoolean("VPN.BLOCKED")) { - if (!ipwhitelist.contains(ip)) { - if (ip.isVpn) { - if (config.getBoolean("VPN.KICK")) { - event.isCancelled = true - event.cancelReason = config.getString("VPN.KICKMSG").translateColors() - } - if (config.getBoolean("VPN.BAN")) { - val id = config.getInt("VPN.BANID") - uuid.ban(id.reason, consoleName) - ActionType.IpBan(id).sendNotify(event.connection.address.hostString, consoleName) - event.isCancelled = true - if (uuid.rawEnd == -1L) { - event.cancelReason = config.getString("LAYOUT.IPBAN").replace("%grund%", id.reason).translateColors() - } else { - var msg = config.getString("LAYOUT.TEMPIPBAN") - msg = msg.replace("%grund%", uuid.reasonString) - msg = msg.replace("%dauer%", uuid.endTime) - event.cancelReason = msg.translateColors() - } - } - } - } - } + @EventHandler + fun onPreLoginEvent(event: PreLoginEvent) { + val uuid = UUIDFetcher.getUUID(event.connection.name) ?: return + val ip = event.connection.virtualHost.hostName + /*val ip = event.connection.address.hostString*/ + uuid.updatePlayer(event.connection.name) + ip.insertIP(uuid) + if (config.getBoolean("VPN.BLOCKED") && ip !in ipWhiteList && ip.isVpn) { + if (config.getBoolean("VPN.BAN")) { + val id = config.getInt("VPN.BANID") + uuid.ban(id.reason, consoleName) + ActionType.IpBan(id).sendNotify(event.connection.address.hostString, consoleName) + event.isCancelled = true + if (uuid.rawEnd == -1L) { + event.cancelReason = config.getString("LAYOUT.IPBAN").replace("%grund%", id.reason).translateColors() + } else { + var msg = config.getString("LAYOUT.TEMPIPBAN") + msg = msg.replace("%grund%", uuid.reasonString) + msg = msg.replace("%dauer%", uuid.endTime) + event.cancelReason = msg.translateColors() + } + } else if (config.getBoolean("VPN.KICK")) { + event.isCancelled = true + event.cancelReason = config.getString("VPN.KICKMSG").translateColors() + } + } - if (ip.isBanned) { + if (ip.isBanned) { - if (ip.rawEnd == -1L) { - event.isCancelled = true - event.setCancelReason(TextComponent(config.getString("LAYOUT.IPBAN").translateColors().replace("%grund%", ip.reason))) + if (ip.rawEnd == -1L) { + event.isCancelled = true + event.setCancelReason(TextComponent(config.getString("LAYOUT.IPBAN").translateColors().replace("%grund%", ip.reason))) - } else { - if (System.currentTimeMillis() < ip.rawEnd) { - event.isCancelled = true - var msg = config.getString("LAYOUT.TEMPIPBAN") - msg = msg.replace("%grund%", ip.reason) - msg = msg.replace("%dauer%", getEnd(ip)) - event.cancelReason = msg.translateColors() - } else { - ip.unBan() - } - } + } else { + if (System.currentTimeMillis() < ip.rawEnd) { + event.isCancelled = true + var msg = config.getString("LAYOUT.TEMPIPBAN") + msg = msg.replace("%grund%", ip.reason) + msg = msg.replace("%dauer%", getEnd(ip)) + event.cancelReason = msg.translateColors() + } else { + ip.unBan() + } + } - } - if (uuid.isBanned) { - if (uuid.rawEnd == -1L) { - event.isCancelled = true - event.cancelReason = config.getString("LAYOUT.BAN").replace("%grund%", uuid.reasonString).translateColors() - } else { - if (System.currentTimeMillis() < uuid.rawEnd) { - event.isCancelled = true - var msg = config.getString("LAYOUT.TEMPBAN") - msg = msg.replace("%grund%", uuid.reasonString) - msg = msg.replace("%dauer%", uuid.endTime) - event.cancelReason = msg.translateColors() - } else { - uuid.unBan() - } - } - } - } + } + if (uuid.isBanned) { + if (uuid.rawEnd == -1L) { + event.isCancelled = true + event.cancelReason = config.getString("LAYOUT.BAN").replace("%grund%", uuid.reasonString).translateColors() + } else { + if (System.currentTimeMillis() < uuid.rawEnd) { + event.isCancelled = true + var msg = config.getString("LAYOUT.TEMPBAN") + msg = msg.replace("%grund%", uuid.reasonString) + msg = msg.replace("%dauer%", uuid.endTime) + event.cancelReason = msg.translateColors() + } else { + uuid.unBan() + } + } + } + } - @EventHandler - fun onFinalLogin(e: PostLoginEvent) { - val p = e.player - if (p.hasPermission("${permissionPrefix}reports")) { - if (countOpenReports() != 0) p.msg("${prefix}Derzeit sind noch §l${countOpenReports()} Reports §7offen") - } - if (p.hasPermission("${permissionPrefix}supportchat")) { - if (openchats.isNotEmpty()) p.msg("${prefix}Derzeit sind noch §l${openchats.size} §7Support Chat Anfragen §aoffen") - } - } + @EventHandler + fun onFinalLogin(event: PostLoginEvent) { + val player = event.player + if (player.hasPermission("${permissionPrefix}reports")) { + val countOpenReports = countOpenReports() + if (countOpenReports != 0) player.msg("${prefix}Derzeit sind noch §l$countOpenReports Reports §7offen") + } + if (player.hasPermission("${permissionPrefix}supportchat")) + if (openChats.isNotEmpty()) player.msg("${prefix}Derzeit sind noch §l${openChats.size} §7Support Chat Anfragen §aoffen") + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/listener/Quit.kt b/src/main/kotlin/de/tutorialwork/listener/Quit.kt index dc18cd3..9e8f991 100644 --- a/src/main/kotlin/de/tutorialwork/listener/Quit.kt +++ b/src/main/kotlin/de/tutorialwork/listener/Quit.kt @@ -1,6 +1,6 @@ package de.tutorialwork.listener -import de.tutorialwork.global.activechats +import de.tutorialwork.global.activeChats import de.tutorialwork.global.prefix import de.tutorialwork.utils.msg import net.md_5.bungee.api.event.PlayerDisconnectEvent @@ -9,16 +9,16 @@ import net.md_5.bungee.event.EventHandler object Quit : Listener { - @EventHandler - fun onPlayerDisconnectEvent(event: PlayerDisconnectEvent) { - val player = event.player - if (!activechats.containsKey(player) && !activechats.containsValue(player)) return - for (key in activechats.keys) { - //Key has started the support chat - if (key === player) activechats[player]?.msg("${prefix}§event§l${player.name} §7hat den Support hat §cbeeendet") - else key.msg("${prefix}§event§l${player.name} §7hat den Support Chat §cbeeendet") - activechats.remove(key) - } - } + @EventHandler + fun onPlayerDisconnectEvent(event: PlayerDisconnectEvent) { + val player = event.player ?: return + if (!activeChats.containsKey(player) && !activeChats.containsValue(player)) return + val messages = "${prefix}§event§l${player.name} §7hat den Support Chat §cbeeendet" + activeChats[player]?.msg(messages) + activeChats.remove(player) + val find = activeChats.filter { it.value === player } + find.keys.forEach { it.msg(messages) } + find.forEach { activeChats.remove(it.key) } + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/Accounts.kt b/src/main/kotlin/de/tutorialwork/sql/Accounts.kt new file mode 100644 index 0000000..6a5edd7 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/sql/Accounts.kt @@ -0,0 +1,17 @@ +package de.tutorialwork.sql + +import org.jetbrains.exposed.sql.Table + +/** + * Created on 04.10.2019 19:46. + * @author Lars Artmann | LartyHD + */ +object Accounts : Table() { + var uuid = varchar("uuid", 36).primaryKey() + var username = varchar("username", 16) + var password = varchar("password", 255) + var rank = integer("rank") + var googleAuth = varchar("google_auth", 255) + var authCode = varchar("auth_code", 255) + var authStatus = integer("auth_status") +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/AppTokens.kt b/src/main/kotlin/de/tutorialwork/sql/AppTokens.kt new file mode 100644 index 0000000..d92ec17 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/sql/AppTokens.kt @@ -0,0 +1,14 @@ +package de.tutorialwork.sql + +import org.jetbrains.exposed.sql.Table + +/** + * Created on 04.10.2019 19:48. + * @author Lars Artmann | LartyHD + */ +object AppTokens : Table() { + + var uuid = varchar("uuid", 36).primaryKey() + var token = varchar("uuid", 555) + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/Bans.kt b/src/main/kotlin/de/tutorialwork/sql/Bans.kt new file mode 100644 index 0000000..d03719a --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/sql/Bans.kt @@ -0,0 +1,23 @@ +package de.tutorialwork.sql + +import org.jetbrains.exposed.sql.Table + +/** + * Created on 04.10.2019 19:47. + * @author Lars Artmann | LartyHD + */ +object Bans : Table() { + + var uuid = varchar("uuid", 36).primaryKey() + var name = varchar("username", 16) + var banned = integer("banned") + var muted = integer("muted") + var reason = varchar("reason", 64) + var end = long("end") + var teamUuid = varchar("team_uuid", 64) + var bans = integer("bans") + var mutes = integer("mutes") + var firstLogin = varchar("first_login", 255) + var lastLogin = varchar("last_login", 255) + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/Chat.kt b/src/main/kotlin/de/tutorialwork/sql/Chat.kt index 79ac864..dd7fbd0 100644 --- a/src/main/kotlin/de/tutorialwork/sql/Chat.kt +++ b/src/main/kotlin/de/tutorialwork/sql/Chat.kt @@ -3,9 +3,11 @@ package de.tutorialwork.sql import org.jetbrains.exposed.sql.Table object Chat : Table() { - val id = integer("id").autoIncrement().primaryKey() - var uuid = varchar("uuid", 36) - var server = varchar("server", 64) - var message = varchar("message", 2500) - var sendDate = long("senddate") + + val id = integer("id").autoIncrement().primaryKey() + var uuid = varchar("uuid", 36) + var server = varchar("server", 64) + var message = varchar("message", 2500) + var sendDate = long("send_date") + } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/ChatLog.kt b/src/main/kotlin/de/tutorialwork/sql/ChatLog.kt new file mode 100644 index 0000000..81ad1ad --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/sql/ChatLog.kt @@ -0,0 +1,20 @@ +package de.tutorialwork.sql + +import org.jetbrains.exposed.sql.Table + +/** + * Created on 04.10.2019 19:47. + * @author Lars Artmann | LartyHD + */ +object ChatLog : Table() { + + val id = integer("id").autoIncrement().primaryKey() + val logId = varchar("log_id", 255) + val uuid = varchar("uuid", 36) + val creatorUuid = varchar("creator_uuid", 36) + var server = varchar("server", 64) + var message = varchar("message", 2500) + var sendDate = long("send_date") + var createdAt = Reports.long("created_at") + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/Ips.kt b/src/main/kotlin/de/tutorialwork/sql/Ips.kt new file mode 100644 index 0000000..7bc4e25 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/sql/Ips.kt @@ -0,0 +1,20 @@ +package de.tutorialwork.sql + +import org.jetbrains.exposed.sql.Table + +/** + * Created on 04.10.2019 19:47. + * @author Lars Artmann | LartyHD + */ +object Ips : Table() { + + var ip = varchar("ip", 15).primaryKey() + val usedBy = varchar("used_by", 64) + val usedAt = varchar("used_at", 64) + val banned = integer("banned") + val reason = integer("reason") + val end = integer("end") + val timeUuid = varchar("time_uuid", 64) + val bans = integer("bans") + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/Log.kt b/src/main/kotlin/de/tutorialwork/sql/Log.kt new file mode 100644 index 0000000..ab25823 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/sql/Log.kt @@ -0,0 +1,18 @@ +package de.tutorialwork.sql + +import org.jetbrains.exposed.sql.Table + +/** + * Created on 04.10.2019 18:54. + * @author Lars Artmann | LartyHD + */ +object Log : Table() { + + val id = integer("id").autoIncrement().primaryKey() + val uuid = varchar("uuid", 36) + val byUuid = varchar("by_uuid", 36) + val action = varchar("action", 255) + val note = varchar("note", 255) + val date = long("date") + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/Reasons.kt b/src/main/kotlin/de/tutorialwork/sql/Reasons.kt new file mode 100644 index 0000000..1fc323d --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/sql/Reasons.kt @@ -0,0 +1,20 @@ +package de.tutorialwork.sql + +import org.jetbrains.exposed.sql.Table + +/** + * Created on 04.10.2019 19:46. + * @author Lars Artmann | LartyHD + */ +object Reasons : Table() { + + val id = integer("id").autoIncrement().primaryKey() + val reason = varchar("", 255) + val time = integer("time") + val type = integer("type") + val addedAt = varchar("added_at", 11) + val bans = integer("bans") + val perms = varchar("perms", 255) + val sortIndex = integer("sort_index") + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/Reports.kt b/src/main/kotlin/de/tutorialwork/sql/Reports.kt new file mode 100644 index 0000000..ae01a56 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/sql/Reports.kt @@ -0,0 +1,20 @@ +package de.tutorialwork.sql + +import org.jetbrains.exposed.sql.Table + +/** + * Created on 04.10.2019 19:47. + * @author Lars Artmann | LartyHD + */ +object Reports : Table() { + + val id = integer("id").autoIncrement().primaryKey() + var uuid = varchar("uuid", 36) + var reporter = varchar("reporter", 36) + var team = varchar("team", 36) + var reason = varchar("reason", 64) + var log = varchar("log", 64) + var status = integer("status") + var createdAt = long("created_at") + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/sql/UnBans.kt b/src/main/kotlin/de/tutorialwork/sql/UnBans.kt new file mode 100644 index 0000000..ed3a2f7 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/sql/UnBans.kt @@ -0,0 +1,18 @@ +package de.tutorialwork.sql + +import org.jetbrains.exposed.sql.Table + +/** + * Created on 04.10.2019 19:47. + * @author Lars Artmann | LartyHD + */ +object UnBans : Table() { + + val id = integer("id").autoIncrement().primaryKey() + val uuid = varchar("uuid", 36) + val fair = integer("fair") + val message = varchar("message", 10000) + val date = long("date") + val status = integer("status") + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/utils/BanFunctions.kt b/src/main/kotlin/de/tutorialwork/utils/BanFunctions.kt index 42ff39d..3a50eaa 100644 --- a/src/main/kotlin/de/tutorialwork/utils/BanFunctions.kt +++ b/src/main/kotlin/de/tutorialwork/utils/BanFunctions.kt @@ -10,159 +10,159 @@ private const val none = "none" private const val never = "never" val iDsFromOpenReports: List - get() { - val rs = mysql.query("SELECT ID FROM reports WHERE STATUS = 0") - val ids = ArrayList() - while (rs?.next() == true) ids.add(rs.getInt("ID")) - return ids - } + get() { + val rs = mysql.query("SELECT ID FROM reports WHERE STATUS = 0") + val ids = ArrayList() + while (rs?.next() == true) ids.add(rs.getInt("ID")) + return ids + } val UUID.endTime: String - get() { - val time = System.currentTimeMillis() - val end = rawEnd - val millis = end - time - return millis.formatTime() - } + get() { + val time = System.currentTimeMillis() + val end = rawEnd + val millis = end - time + return millis.formatTime() + } val UUID.rawEnd: Long - get() { - val rs = mysql.query("SELECT END FROM bans WHERE uuid='$this'") - return if (rs?.next() == true) rs.getLong("END") else 0 - } + get() { + val rs = mysql.query("SELECT END FROM bans WHERE uuid='$this'") + return if (rs?.next() == true) rs.getLong("END") else 0 + } val UUID.isBanned: Boolean - get() { - val rs = mysql.query("SELECT BANNED FROM bans WHERE UUID='$this'") - return if (rs?.next() == true) rs.getInt("BANNED") == 1 else false - } + get() { + val rs = mysql.query("SELECT BANNED FROM bans WHERE UUID='$this'") + return if (rs?.next() == true) rs.getInt("BANNED") == 1 else false + } val UUID.isMuted: Boolean - get() { - val rs = mysql.query("SELECT MUTED FROM bans WHERE uuid='$this'") - return if (rs?.next() == true) rs.getInt("MUTED") == 1 else false - } + get() { + val rs = mysql.query("SELECT MUTED FROM bans WHERE uuid='$this'") + return if (rs?.next() == true) rs.getInt("MUTED") == 1 else false + } var UUID.bans: Int - get() { - val rs = mysql.query("SELECT BANS FROM bans WHERE uuid='$this'") - return if (rs?.next() == true) rs.getInt("BANS") else 0 - } - private set(value) { - if (playerExists()) mysql.update("UPDATE bans SET BANS='$value' WHERE uuid='$this'") - } + get() { + val rs = mysql.query("SELECT BANS FROM bans WHERE uuid='$this'") + return if (rs?.next() == true) rs.getInt("BANS") else 0 + } + private set(value) { + if (playerExists()) mysql.update("UPDATE bans SET BANS='$value' WHERE uuid='$this'") + } var UUID.mutes: Int - get() { - val rs = mysql.query("SELECT MUTES FROM bans WHERE uuid='$this'") - return if (rs?.next() == true) rs.getInt("MUTES") else 0 - } - private set(value) { - if (playerExists()) mysql.update("UPDATE bans SET MUTES='$value' WHERE uuid='$this'") - } + get() { + val rs = mysql.query("SELECT MUTES FROM bans WHERE uuid='$this'") + return if (rs?.next() == true) rs.getInt("MUTES") else 0 + } + private set(value) { + if (playerExists()) mysql.update("UPDATE bans SET MUTES='$value' WHERE uuid='$this'") + } val UUID.webaccountExists: Boolean - get() { - val rs = mysql.query("SELECT UUID FROM accounts WHERE UUID='$this'") - return rs?.next() == true - } + get() { + val rs = mysql.query("SELECT UUID FROM accounts WHERE UUID='$this'") + return rs?.next() == true + } val UUID.isWebaccountAdmin: Boolean - get() { - val rs = mysql.query("SELECT RANK FROM accounts WHERE UUID='$this'") - return if (rs?.next() == true) rs.getInt("RANK") == 3 else false - } + get() { + val rs = mysql.query("SELECT RANK FROM accounts WHERE UUID='$this'") + return if (rs?.next() == true) rs.getInt("RANK") == 3 else false + } val UUID.hasAuthToken: Boolean - get() { - val rs = mysql.query("SELECT AUTHCODE FROM accounts WHERE UUID='$this'") - return rs?.next() == true - } + get() { + val rs = mysql.query("SELECT AUTHCODE FROM accounts WHERE UUID='$this'") + return rs?.next() == true + } val UUID.authCode: String - get() { - val rs = mysql.query("SELECT AUTHCODE FROM accounts WHERE UUID='$this'") - return if (rs?.next() == true) rs.getString("AUTHCODE") else none - } + get() { + val rs = mysql.query("SELECT AUTHCODE FROM accounts WHERE UUID='$this'") + return if (rs?.next() == true) rs.getString("AUTHCODE") else none + } val UUID.name: String - get() { - val rs = mysql.query("SELECT NAME FROM bans WHERE uuid='$this'") - return if (rs?.next() == true) rs.getString("NAME") else none - } + get() { + val rs = mysql.query("SELECT NAME FROM bans WHERE uuid='$this'") + return if (rs?.next() == true) rs.getString("NAME") else none + } val UUID.firstLogin: String - get() { - val rs = mysql.query("SELECT FIRSTLOGIN FROM bans WHERE UUID='$this'") - return if (rs?.next() == true) rs.getString("FIRSTLOGIN") else never - } + get() { + val rs = mysql.query("SELECT FIRSTLOGIN FROM bans WHERE UUID='$this'") + return if (rs?.next() == true) rs.getString("FIRSTLOGIN") else never + } val UUID.lastLogin: String - get() { - val rs = mysql.query("SELECT LASTLOGIN FROM bans WHERE UUID='$this'") - return if (rs?.next() == true) rs.getString("LASTLOGIN") else never - } + get() { + val rs = mysql.query("SELECT LASTLOGIN FROM bans WHERE UUID='$this'") + return if (rs?.next() == true) rs.getString("LASTLOGIN") else never + } val UUID.reasonString: String - get() { - val rs = mysql.query("SELECT REASON FROM bans WHERE uuid='$this'") - return if (rs?.next() == true) rs.getString("REASON") else none - } + get() { + val rs = mysql.query("SELECT REASON FROM bans WHERE uuid='$this'") + return if (rs?.next() == true) rs.getString("REASON") else none + } val Long.formatTime: String - get() = SimpleDateFormat("dd.MM.yyyy HH:mm").format(Date(this)) + get() = SimpleDateFormat("dd.MM.yyyy HH:mm").format(Date(this)) val String.reasonTime: Int - get() { - val rs = mysql.query("SELECT TIME FROM reasons WHERE REASON='$this'") - return if (rs?.next() == true) rs.getInt("TIME") else 0 - } + get() { + val rs = mysql.query("SELECT TIME FROM reasons WHERE REASON='$this'") + return if (rs?.next() == true) rs.getInt("TIME") else 0 + } val Int.reasonTime: Int - get() = reason.reasonTime + get() = reason.reasonTime val Int.isBanReason: Boolean - get() { - val rs = mysql.query("SELECT TYPE FROM reasons WHERE ID='$this'") - return if (rs?.next() == true) rs.getInt("TYPE") == 0 else false - } + get() { + val rs = mysql.query("SELECT TYPE FROM reasons WHERE ID='$this'") + return if (rs?.next() == true) rs.getInt("TYPE") == 0 else false + } var Int.reasonBans: Int - get() { - val rs = mysql.query("SELECT BANS FROM reasons WHERE ID='$this'") - return if (rs?.next() == true) rs.getInt("BANS") else 0 - } - set(value) = mysql.update("UPDATE reasons SET BANS='$value' WHERE ID='$this'") + get() { + val rs = mysql.query("SELECT BANS FROM reasons WHERE ID='$this'") + return if (rs?.next() == true) rs.getInt("BANS") else 0 + } + set(value) = mysql.update("UPDATE reasons SET BANS='$value' WHERE ID='$this'") val Int.extraPermissions: String - get() { - val rs = mysql.query("SELECT PERMS FROM reasons WHERE ID='$this'") - return if (rs?.next() == true) rs.getString("PERMS") else none - } + get() { + val rs = mysql.query("SELECT PERMS FROM reasons WHERE ID='$this'") + return if (rs?.next() == true) rs.getString("PERMS") else none + } val Int.hasExtraPermissions: Boolean - get() { - val rs = mysql.query("SELECT PERMS FROM reasons WHERE ID='$this'") - return rs?.next() == true - } + get() { + val rs = mysql.query("SELECT PERMS FROM reasons WHERE ID='$this'") + return rs?.next() == true + } val Int.reason: String - get() { - val rs = mysql.query("SELECT REASON FROM reasons WHERE ID='$this'") - return if (rs?.next() == true) rs.getString("REASON") else none - } + get() { + val rs = mysql.query("SELECT REASON FROM reasons WHERE ID='$this'") + return if (rs?.next() == true) rs.getString("REASON") else none + } val Int.reportName: String - get() { - val rs = mysql.query("SELECT UUID FROM reports WHERE ID='$this'") - return if (rs?.next() == true) UUID.fromString(rs.getString("UUID")).name else none - } + get() { + val rs = mysql.query("SELECT UUID FROM reports WHERE ID='$this'") + return if (rs?.next() == true) UUID.fromString(rs.getString("UUID")).name else none + } val Int.reportReason: String - get() { - val rs = mysql.query("SELECT REASON FROM reports WHERE ID='$this'") - return if (rs?.next() == true) rs.getString("REASON") else none - } + get() { + val rs = mysql.query("SELECT REASON FROM reports WHERE ID='$this'") + return if (rs?.next() == true) rs.getString("REASON") else none + } private val UUID.updateLastLogin get() = mysql.update("""UPDATE bans SET LASTLOGIN = '${System.currentTimeMillis()}' WHERE uuid = '$this'""") @@ -171,97 +171,97 @@ fun UUID.updateAuthStatus() = mysql.update("UPDATE accounts SET AUTHSTATUS = 1 W fun UUID.reportTeam(value: Int) = mysql.update("UPDATE reports SET TEAM = '$this' WHERE ID = $value") fun UUID.createReport(ReporterUUID: String, Reason: String, LogID: String?) { - mysql.update("""INSERT INTO reports(uuid, REPORTER, TEAM, REASON, LOG, STATUS, CREATED_AT) VALUES ('$this', '$ReporterUUID', 'null' + mysql.update("""INSERT INTO reports(uuid, REPORTER, TEAM, REASON, LOG, STATUS, CREATED_AT) VALUES ('$this', '$ReporterUUID', 'null' |, '$Reason', '$LogID', '0', '${System.currentTimeMillis()}')""".trimMargin()) } fun UUID.unMute() { - if (playerExists()) mysql.update("UPDATE bans SET MUTED='0' WHERE uuid='$this'") + if (playerExists()) mysql.update("UPDATE bans SET MUTED='0' WHERE uuid='$this'") } fun UUID.unBan() { - if (playerExists()) mysql.update("UPDATE bans SET BANNED='0' WHERE uuid='${this}'") + if (playerExists()) mysql.update("UPDATE bans SET BANNED='0' WHERE uuid='${this}'") } fun CommandSender.sendBanReasonsList() { - val rs = mysql.query("SELECT ID FROM reasons ORDER BY SORTINDEX ASC") - while (rs?.next() == true) { - val id = rs.getInt("ID") - if (hasPermission(id.extraPermissions)) - msg("§7$id §8| §e${id.reason}" + if (id.isBanReason) "" else " §8(§cMUTE§8)") - } + val rs = mysql.query("SELECT ID FROM reasons ORDER BY SORTINDEX ASC") + while (rs?.next() == true) { + val id = rs.getInt("ID") + if (hasPermission(id.extraPermissions)) + msg("§7$id §8| §e${id.reason}" + if (id.isBanReason) "" else " §8(§cMUTE§8)") + } } fun UUID.playerExists(): Boolean { - val rs = mysql.query("SELECT uuid FROM bans WHERE uuid='${this}'") - return if (rs?.next() == true) rs.getString("uuid") != null else false + val rs = mysql.query("SELECT uuid FROM bans WHERE uuid='${this}'") + return if (rs?.next() == true) rs.getString("uuid") != null else false } fun UUID.updatePlayer(name: String) { - if (!playerExists()) { - mysql.update("""INSERT INTO bans(uuid, NAME, BANNED, MUTED, REASON, END, TEAMUUID, BANS, MUTES, FIRSTLOGIN, LASTLOGIN) VALUES + if (!playerExists()) { + mysql.update("""INSERT INTO bans(uuid, NAME, BANNED, MUTED, REASON, END, TEAMUUID, BANS, MUTES, FIRSTLOGIN, LASTLOGIN) VALUES |('${this}', '$name', '0', '0', 'null', 'null', 'null', '0', '0', '${System.currentTimeMillis()}', '${System.currentTimeMillis()}')""".trimMargin()) - } else { - updateName(name) - updateLastLogin - } + } else { + updateName(name) + updateLastLogin + } } private fun UUID.updateName(newName: String) { - if (playerExists()) mysql.update("UPDATE bans SET NAME='$newName' WHERE uuid='${this}'") + if (playerExists()) mysql.update("UPDATE bans SET NAME='$newName' WHERE uuid='${this}'") } fun UUID.ban(reason: String, teamUUID: String, percentage: Int = increaseValue, increaseBans1: Boolean = increaseBans) { - val reasonTime = reason.reasonTime - val end = if (reasonTime == -1) -1 else { - //Temp Ban - //Formel: 1.50 * Anzahl an Tagen = Ergebniss (50%) - val bans = bans - val current = System.currentTimeMillis() - val endTime = current + reasonTime * 60000L - val increaseEnd = current + (percentage / 100).toLong() + 1 * reasonTime.toLong() * bans.toLong() * 60000L //Formel!!!!! - if (increaseBans1 && bans <= 0) increaseEnd else endTime - } - mysql.update("""UPDATE bans SET BANNED='1', REASON='${reason}', END='$end', TEAMUUID='$teamUUID' WHERE uuid='${this}'""") - bans++ + val reasonTime = reason.reasonTime + val end = if (reasonTime == -1) -1 else { + //Temp Ban + //Formel: 1.50 * Anzahl an Tagen = Ergebniss (50%) + val bans = bans + val current = System.currentTimeMillis() + val endTime = current + reasonTime * 60000L + val increaseEnd = current + (percentage / 100).toLong() + 1 * reasonTime.toLong() * bans.toLong() * 60000L //Formel!!!!! + if (increaseBans1 && bans <= 0) increaseEnd else endTime + } + mysql.update("""UPDATE bans SET BANNED='1', REASON='${reason}', END='$end', TEAMUUID='$teamUUID' WHERE uuid='${this}'""") + bans++ } fun UUID.mute(reason: String, teamUUID: String) { - val current = System.currentTimeMillis() - val reasonTime = reason.reasonTime - val end = if (reasonTime == -1) -1 else current + reasonTime * 60000L - mysql.update("""UPDATE bans SET MUTED='1', REASON='${reason}', END='$end', TEAMUUID='$teamUUID' WHERE UUID='$this'""") - mutes++ + val current = System.currentTimeMillis() + val reasonTime = reason.reasonTime + val end = if (reasonTime == -1) -1 else current + reasonTime * 60000L + mysql.update("""UPDATE bans SET MUTED='1', REASON='${reason}', END='$end', TEAMUUID='$teamUUID' WHERE UUID='$this'""") + mutes++ } fun UUID.createWebAccount(rank: RankType, password: String, sender: ProxiedPlayer) { - mysql.update("""INSERT INTO accounts(UUID, USERNAME, PASSWORD, RANK, GOOGLE_AUTH, AUTHCODE) VALUES ('$this', '$name' + mysql.update("""INSERT INTO accounts(UUID, USERNAME, PASSWORD, RANK, GOOGLE_AUTH, AUTHCODE) VALUES ('$this', '$name' |, '${BCrypt.hashpw(password, BCrypt.gensalt())}', '${rank.id}', 'null', 'initialpassword')""".trimMargin()) - LogManager.createEntry(this.toString(), sender.uniqueId.toString(), ActionType.WebAccount("ADD_WEBACCOUNT")) + this.createLogEntry(sender.uniqueId.toString(), ActionType.WebAccount("ADD_WEBACCOUNT")) } fun UUID.deleteWebAccount() = mysql.update("DELETE FROM accounts WHERE UUID='$this'") fun ActionType.sendNotify(bannedName: String, senderName: String) { - val message = prefix + message - .replace("%banned-name%", bannedName) - .replace("%sender-name%", senderName) - for (all in players) - if (all.hasPermission("${permissionPrefix}notify")) - all.msg(message) + val message = prefix + message + .replace("%banned-name%", bannedName) + .replace("%sender-name%", senderName) + for (all in players) + if (all.hasPermission("${permissionPrefix}notify")) + all.msg(message) } fun countOpenReports(): Int { - var i = 0 - val rs = mysql.query("SELECT * FROM reports WHERE STATUS = 0") - while (rs?.next() == true) i++ - return i + var i = 0 + val rs = mysql.query("SELECT * FROM reports WHERE STATUS = 0") + while (rs?.next() == true) i++ + return i } fun countReasons(): Int { - var i = 0 - val rs = mysql.query("SELECT * FROM reasons") - while (rs?.next() == true) i++ - return i + var i = 0 + val rs = mysql.query("SELECT * FROM reasons") + while (rs?.next() == true) i++ + return i } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/utils/Functions.kt b/src/main/kotlin/de/tutorialwork/utils/Functions.kt index 803f8d6..67f5b6f 100644 --- a/src/main/kotlin/de/tutorialwork/utils/Functions.kt +++ b/src/main/kotlin/de/tutorialwork/utils/Functions.kt @@ -8,26 +8,26 @@ import net.md_5.bungee.api.connection.ProxiedPlayer import net.md_5.bungee.config.Configuration import java.io.File import java.net.URL -import java.net.URLConnection import java.security.SecureRandom import java.util.* +import java.util.concurrent.TimeUnit import kotlin.math.abs fun saveConfig(configuration: Configuration = config, file: File = configFile) = configProvider.save(configuration, file) fun Int.randomString(): String { - val alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - val rnd = SecureRandom() - val sb = StringBuilder(this) - for (i in 0 until this) - sb.append(alphabet[rnd.nextInt(alphabet.length)]) - return sb.toString() + val alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + val rnd = SecureRandom() + val sb = StringBuilder(this) + for (i in 0 until this) + sb.append(alphabet[rnd.nextInt(alphabet.length)]) + return sb.toString() } private fun ProxiedPlayer.getLayout(type: String, temp: Boolean) = config.getString("LAYOUT.${if (temp) "TEMP" else ""}$type") - .replace("%grund%", uniqueId.reasonString) - .replace("%dauer%", uniqueId.endTime) - .translateColors() + .replace("%grund%", uniqueId.reasonString) + .replace("%dauer%", uniqueId.endTime) + .translateColors() private inline fun ProxiedPlayer.getLayout(temp: Boolean) = getLayout(T::class.java.simpleName.toUpperCase(), temp) fun ProxiedPlayer.sendTempBan() = kick(getLayout(true)) @@ -35,31 +35,31 @@ fun ProxiedPlayer.sendTempMute() = msg(getLayout(true)) fun ProxiedPlayer.sendBan() { - if (uniqueId.rawEnd == -1L) - kick(getLayout(false)) - else sendTempBan() + if (uniqueId.rawEnd == -1L) + kick(getLayout(false)) + else sendTempBan() } fun ProxiedPlayer.sendMute() = if (uniqueId.rawEnd == -1L) - msg(getLayout(false)) + msg(getLayout(false)) else sendTempMute() fun UUID.exists(sender: CommandSender): Unit? { - val exists = this.playerExists() - return if (exists) sender.msg("${prefix}§cDieser Spieler wurde nicht gefunden") - else null + val exists = this.playerExists() + return if (exists) sender.msg("${prefix}§cDieser Spieler wurde nicht gefunden") + else null } fun String.getUUID(sender: CommandSender): UUID? { - val uuid = UUIDFetcher.getUUID(this) - return if (uuid != null) uuid else { - sender.msg("${prefix}§cDieser Spieler wurde nicht gefunden") - null - } + val uuid = UUIDFetcher.getUUID(this) + return if (uuid != null) uuid else { + sender.msg("${prefix}§cDieser Spieler wurde nicht gefunden") + null + } } inline fun CommandSender.hasPermission(permission: String, code: () -> Unit) = - if (hasPermission("$permissionPrefix.$permission")) code() else msg(noPerms) + if (hasPermission("$permissionPrefix.$permission")) code() else msg(noPerms) fun CommandSender.msg(vararg messages: String) = sendMessage(*messages.map { TextComponent(it) }.toTypedArray()) @@ -69,30 +69,30 @@ fun String.translateColors(): String = ChatColor.translateAlternateColorCodes('& fun Long.formatTime(): String { - val IMPORTANT = ChatColor.DARK_GRAY - val TEXT = ChatColor.GRAY - - val time = abs(this) / 1000 - val sec = time % 60 - val min = time / 60 % 60 - val hour = time / 3600 % 24 - val day = time / 86400 - var remainingTime = "" - if (day == 1L) remainingTime += "${IMPORTANT}ein$TEXT Tag " - else if (day != 0L) remainingTime += "$IMPORTANT$day$TEXT Tage " - if (hour == 1L) remainingTime += "${IMPORTANT}eine$TEXT Stunde " - else if (hour != 0L) remainingTime += "$IMPORTANT$hour$TEXT Stunden " - if (min == 1L) remainingTime += "${IMPORTANT}eine$TEXT Minute " - else if (min != 0L) remainingTime += "$IMPORTANT$min$TEXT Minuten " - if (sec == 1L) remainingTime += "$IMPORTANT$sec$TEXT Sekunde " - else if (time != 0L) remainingTime += "$IMPORTANT$sec$TEXT Sekunden " - return if (remainingTime.isBlank()) "${IMPORTANT}0 ${TEXT}Sekunden" else remainingTime.dropLast(1) + val important = ChatColor.DARK_GRAY + val text = ChatColor.GRAY + + val time = abs(this) / 1000 + val sec = time % 60 + val min = time / 60 % 60 + val hour = time / 3600 % 24 + val day = time / 86400 + var remainingTime = "" + if (day == 1L) remainingTime += "${important}ein$text Tag " + else if (day != 0L) remainingTime += "$important$day$text Tage " + if (hour == 1L) remainingTime += "${important}eine$text Stunde " + else if (hour != 0L) remainingTime += "$important$hour$text Stunden " + if (min == 1L) remainingTime += "${important}eine$text Minute " + else if (min != 0L) remainingTime += "$important$min$text Minuten " + if (sec == 1L) remainingTime += "$important$sec$text Sekunde " + else if (time != 0L) remainingTime += "$important$sec$text Sekunden " + return if (remainingTime.isBlank()) "${important}0 ${text}Sekunden" else remainingTime.dropLast(1) } fun callURL(myURL: String): String { - val url = URL(myURL) - val urlConn: URLConnection? = url.openConnection() - if (urlConn != null) urlConn.readTimeout = 60 * 1000 - val inputStream = urlConn?.getInputStream() ?: return "" - return inputStream.reader().readText() + val url = URL(myURL) + val urlConn = url.openConnection() ?: return "" + urlConn.readTimeout = TimeUnit.MINUTES.toMillis(1).toInt() + val inputStream = urlConn.getInputStream() + return inputStream.reader().readText() } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/utils/LogManager.kt b/src/main/kotlin/de/tutorialwork/utils/LogManager.kt deleted file mode 100644 index 53419aa..0000000 --- a/src/main/kotlin/de/tutorialwork/utils/LogManager.kt +++ /dev/null @@ -1,25 +0,0 @@ -package de.tutorialwork.utils - -import de.tutorialwork.global.mysql - -object LogManager { - - //DATABASE STRUCTURE - //ID int(11) AUTO_INCREMENT UNIQUE, UUID varchar(255), BYUUID varchar(255), ACTION varchar(255), NOTE varchar(255), DATE varchar(255) - - //ACTION Codes - //BAN, MUTE, ADD_WORD_BLACKLIST, DEL_WORD_BLACKLIST, CREATE_CHATLOG, IPBAN_IP, IPBAN_PLAYER, KICK, REPORT, REPORT_OFFLINE, REPORT_ACCEPT, UNBAN_IP, UNBAN_BAN, UNBAN_MUTE, - // ADD_WEBACCOUNT, DEL_WEBACCOUNT, AUTOMUTE_ADBLACKLIST, AUTOMUTE_BLACKLIST - // - //UUID/BY_UUID = UUID des Spielers, null = keine Spieler verfügbar, "KONSOLE" = Befehl über Konsole ausgeführt - - fun createEntry(uuid: String, byUUID: String?, type: ActionType) = - mysql.update("INSERT INTO log(uuid, BYUUID, ACTION, NOTE, DATE) VALUES (" + - "'$uuid', " + - "'$byUUID', " + - "'${type.reason}', " + - "'${type.node}', " + - "'${System.currentTimeMillis()}'" + - ")") - -} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/utils/MySQLConnect.kt b/src/main/kotlin/de/tutorialwork/utils/MySQLConnect.kt index cc6f2e3..09de61d 100644 --- a/src/main/kotlin/de/tutorialwork/utils/MySQLConnect.kt +++ b/src/main/kotlin/de/tutorialwork/utils/MySQLConnect.kt @@ -9,61 +9,60 @@ import java.sql.SQLException class MySQLConnect(host: String, database: String, user: String, password: String) { - private var con: Connection? = null + private var con: Connection? = null - init { - HOST = host - DATABASE = database - USER = user - PASSWORD = password + init { + HOST = host + DATABASE = database + USER = user + PASSWORD = password - connect() - } + connect() + } - private fun connect() { - try { - con = DriverManager.getConnection("jdbc:mysql://$HOST:3306/$DATABASE?autoReconnect=true", USER, PASSWORD) - console.msg("${prefix}§aDie Verbindung mit der MySQL Datenbank wurde erfolgreich hergestellt") - } catch (e: SQLException) { - console.msg(prefix + "§cDie Verbindung mit der MySQL Datenbank ist fehlgeschlagen: §4" + e.message) - } + private fun connect() { + try { + con = DriverManager.getConnection("jdbc:mysql://$HOST:3306/$DATABASE?autoReconnect=true", USER, PASSWORD) + console.msg("${prefix}§aDie Verbindung mit der MySQL Datenbank wurde erfolgreich hergestellt") + } catch (e: SQLException) { + console.msg(prefix + "§cDie Verbindung mit der MySQL Datenbank ist fehlgeschlagen: §4" + e.message) + } + } - } + fun close() { + con?.close() + } - fun close() { - con?.close() - } + fun update(qry: String) { + try { + val st = con!!.createStatement() + st.executeUpdate(qry) + st.close() + } catch (e: SQLException) { + connect() + System.err.println(e) + } + } - fun update(qry: String) { - try { - val st = con!!.createStatement() - st.executeUpdate(qry) - st.close() - } catch (e: SQLException) { - connect() - System.err.println(e) - } - } + fun query(qry: String): ResultSet? { + var rs: ResultSet? = null - fun query(qry: String): ResultSet? { - var rs: ResultSet? = null + try { + val st = con!!.createStatement() + rs = st.executeQuery(qry) + } catch (e: SQLException) { + connect() + System.err.println(e) + } - try { - val st = con!!.createStatement() - rs = st.executeQuery(qry) - } catch (e: SQLException) { - connect() - System.err.println(e) - } + return rs + } - return rs - } + companion object { - companion object { - - lateinit var HOST: String - lateinit var DATABASE: String - lateinit var USER: String - lateinit var PASSWORD: String - } + lateinit var HOST: String + lateinit var DATABASE: String + lateinit var USER: String + lateinit var PASSWORD: String + } } \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/utils/SQLUtils.kt b/src/main/kotlin/de/tutorialwork/utils/SQLUtils.kt new file mode 100644 index 0000000..a34cc3d --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/utils/SQLUtils.kt @@ -0,0 +1,20 @@ +package de.tutorialwork.utils + +import de.tutorialwork.sql.Log +import org.jetbrains.exposed.sql.insert +import java.util.* + +/* + * Created on 04.10.2019 18:54. + * @author Lars Artmann | LartyHD + */ + +fun UUID?.createLogEntry(byUUID: String?, type: ActionType) { + Log.insert { + it[uuid] = this@createLogEntry.toString() + it[this.byUuid] = byUUID.toString() + it[action] = type.reason + it[note] = type.node.toString() + it[date] = System.currentTimeMillis() + } +}