diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..b2835bf --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..478fc30 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index e208459..acc3158 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,11 @@ + + + + + + diff --git a/.idea/modules/ProfessionalBans-Reloaded.main.iml b/.idea/modules/ProfessionalBans-Reloaded.main.iml new file mode 100644 index 0000000..8c9e56e --- /dev/null +++ b/.idea/modules/ProfessionalBans-Reloaded.main.iml @@ -0,0 +1,12 @@ + + + + + + + BUNGEECORD + + + + + \ No newline at end of file diff --git a/.idea/saveactions_settings.xml b/.idea/saveactions_settings.xml new file mode 100644 index 0000000..1e9ec9d --- /dev/null +++ b/.idea/saveactions_settings.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fba39c4..902408d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,5 +1,8 @@ + + @@ -7,12 +10,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -126,7 +877,6 @@ @@ -169,11 +919,12 @@ - ProfessionalBans Reloaded + main|ProfessionalBans-Reloaded diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..da45b4c --- /dev/null +++ b/build.gradle @@ -0,0 +1,115 @@ +/* + * © Copyright - Lars Artmann aka. LartyHD 2019. + */ + + +buildscript { + ext { + kotlinVersion = '1.3.21' + } + repositories { + mavenCentral() + } + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}") + classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}") + } +} + + +apply plugin: 'java' +apply plugin: 'kotlin' +apply plugin: 'idea' + +group = pluginGroup +version = pluginVersion + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +repositories { + mavenCentral() + jcenter() + maven { + name = 'spigotmc-repo' + url = 'https://hub.spigotmc.org/nexus/content/groups/public/' + } + maven { + name = 'sonatype' + url = 'https://oss.sonatype.org/content/groups/public/' + } + maven { url = "http://maven.elmakers.com/repository/" } + maven { url = ("https://jitpack.io") } + maven { url = "https://repo.velocitypowered.com/snapshots/" } + maven { url = "https://oss.sonatype.org/content/repositories/snapshots" } + +} + + +configurations { + // configuration that holds jars to include in the jar + compile.extendsFrom jarLibs +} + +dependencies { + compileOnly 'net.md-5:bungeecord-api:1.14-SNAPSHOT' + /*compileOnly 'com.velocitypowered:velocity-api:1.0.0-SNAPSHOT'*/ + +// compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5' + + jarLibs "org.jetbrains.kotlin:kotlin-stdlib" + jarLibs "org.jetbrains.kotlin:kotlin-reflect" + jarLibs "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1" + + testCompileOnly "org.jetbrains.kotlin:kotlin-test" + testCompileOnly "org.jetbrains.kotlin:kotlin-test-junit5" + testCompileOnly "org.mockito:mockito-all:2.0.2-beta" + testCompileOnly "org.junit.jupiter:junit-jupiter-api:5.3.1" + + +} + +jar { + from { + configurations.jarLibs.collect { it.isDirectory() ? it : zipTree(it) } + } +} + +wrapper { + gradleVersion = '5.2' + doFirst { + def tree = fileTree('src/main').include('**/*.kt') + tree.each { File file -> + def lines = file.readLines() + def list = [] + lines.each { String line -> + list += line.replace("ProxyServer.getInstance().getConsole()", "console") + } + file.write(list.join("\n"), "UTF-8") + } + } +} + +compileKotlin { + kotlinOptions { + freeCompilerArgs = ['-Xjsr305=strict'] + jvmTarget = '1.8' + suppressWarnings = true + } +} + +compileTestKotlin { + kotlinOptions { + freeCompilerArgs = ['-Xjsr305=strict'] + jvmTarget = '1.8' + suppressWarnings = true + } +} + +import org.apache.tools.ant.filters.ReplaceTokens + +processResources { + from(sourceSets.main.resources.srcDirs) { + filter ReplaceTokens, tokens: [version: version] + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..c0a8c8c --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +pluginGroup=de.tutorialwork +pluginVersion=1.0-SNAPSHOT diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..83f2acf --- /dev/null +++ b/gradlew @@ -0,0 +1,188 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..9618d8d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,100 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.grade b/settings.grade new file mode 100644 index 0000000..fce24d8 --- /dev/null +++ b/settings.grade @@ -0,0 +1 @@ +rootProject.name = 'ProfessionalBans-Reloaded' \ No newline at end of file diff --git a/src/de/tutorialwork/commands/Ban.java b/src/de/tutorialwork/commands/Ban.java deleted file mode 100644 index 25b7f5e..0000000 --- a/src/de/tutorialwork/commands/Ban.java +++ /dev/null @@ -1,188 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.LogManager; -import de.tutorialwork.utils.UUIDFetcher; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; - -public class Ban extends Command { - public Ban(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer p = (ProxiedPlayer) sender; - if(p.hasPermission("professionalbans.ban") || p.hasPermission("professionalbans.*")){ - if(args.length == 0 || args.length == 1){ - BanManager.getBanReasonsList(p); - p.sendMessage(Main.Prefix+"/ban "); - } else { - String UUID = UUIDFetcher.getUUID(args[0]); - int ID = Integer.valueOf(args[1]); - if(BanManager.playerExists(UUID)){ - if(BanManager.isWebaccountAdmin(UUID)){ - p.sendMessage(Main.Prefix+"§cDiesen Spieler kannst du nicht bannen/muten"); - return; - } - if(BanManager.getReasonByID(ID) != null){ - BanManager.setReasonBans(ID, BanManager.getReasonBans(ID) + 1); - if(BanManager.isBanReason(ID)){ - if(BanManager.hasExtraPerms(ID)){ - if(!p.hasPermission(BanManager.getExtraPerms(ID))){ - p.sendMessage(Main.Prefix+"§cDu hast keine Berechtigung diesen Bangrund zu nutzen"); - return; - } - } - BanManager.ban(UUID, ID, p.getUniqueId().toString(), Main.increaseValue, Main.increaseBans); - LogManager.createEntry(UUID, p.getUniqueId().toString(), "BAN", String.valueOf(ID)); - BanManager.setBans(UUID, BanManager.getBans(UUID) + 1); - BanManager.sendNotify("BAN", BanManager.getNameByUUID(UUID), p.getName(), BanManager.getReasonByID(ID)); - ProxiedPlayer banned = BungeeCord.getInstance().getPlayer(args[0]); - if(banned != null){ - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - if(BanManager.getRAWEnd(banned.getUniqueId().toString()) == -1L){ - banned.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.BAN").replace("%grund%", BanManager.getReasonByID(ID)))); - } else { - String MSG = configcfg.getString("LAYOUT.TEMPBAN"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(UUID)); - MSG = MSG.replace("%dauer%", BanManager.getEnd(UUID)); - banned.disconnect(ChatColor.translateAlternateColorCodes('&', MSG)); - } - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e) { - e.printStackTrace(); - } - } - } else { - if(BanManager.hasExtraPerms(ID)){ - if(!p.hasPermission(BanManager.getExtraPerms(ID))){ - p.sendMessage(Main.Prefix+"§cDu hast keine Berechtigung diesen Mutegrund zu nutzen"); - return; - } - } - BanManager.mute(UUID, ID, p.getUniqueId().toString()); - LogManager.createEntry(UUID, p.getUniqueId().toString(), "MUTE", String.valueOf(ID)); - BanManager.setMutes(UUID, BanManager.getMutes(UUID) + 1); - BanManager.sendNotify("MUTE", BanManager.getNameByUUID(UUID), p.getName(), BanManager.getReasonByID(ID)); - ProxiedPlayer banned = BungeeCord.getInstance().getPlayer(args[0]); - if(banned != null){ - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - if(BanManager.getRAWEnd(banned.getUniqueId().toString()) == -1L){ - banned.sendMessage(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.MUTE").replace("%grund%", BanManager.getReasonByID(ID)))); - } else { - String MSG = configcfg.getString("LAYOUT.TEMPMUTE"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(UUID)); - MSG = MSG.replace("%dauer%", BanManager.getEnd(UUID)); - banned.sendMessage(ChatColor.translateAlternateColorCodes('&', MSG)); - } - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Grund existiert nicht"); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler hat den Server noch nie betreten"); - } - } - } else { - p.sendMessage(Main.NoPerms); - } - } else { - if(args.length == 0 || args.length == 1){ - for(int zaehler = 1;zaehler < BanManager.countReasons()+1;zaehler++) { - if(BanManager.isBanReason(zaehler)){ - BungeeCord.getInstance().getConsole().sendMessage("§7"+zaehler+" §8| §e"+BanManager.getReasonByID(zaehler)); - } else { - BungeeCord.getInstance().getConsole().sendMessage("§7"+zaehler+" §8| §e"+BanManager.getReasonByID(zaehler)+" §8(§cMUTE§8)"); - } - } - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"/ban "); - } else { - String UUID = UUIDFetcher.getUUID(args[0]); - int ID = Integer.valueOf(args[1]); - if(BanManager.playerExists(UUID)){ - if(BanManager.isWebaccountAdmin(UUID)){ - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cDiesen Spieler kannst du nicht bannen/muten"); - return; - } - if(BanManager.getReasonByID(ID) != null){ - BanManager.setReasonBans(ID, BanManager.getReasonBans(ID) + 1); - if(BanManager.isBanReason(ID)){ - BanManager.ban(UUID, ID, "KONSOLE", Main.increaseValue, Main.increaseBans); - LogManager.createEntry(UUID, "KONSOLE", "BAN", String.valueOf(ID)); - BanManager.setBans(UUID, BanManager.getBans(UUID) + 1); - BanManager.sendNotify("BAN", BanManager.getNameByUUID(UUID), "KONSOLE", BanManager.getReasonByID(ID)); - ProxiedPlayer banned = BungeeCord.getInstance().getPlayer(args[0]); - if(banned != null){ - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - if(BanManager.getRAWEnd(banned.getUniqueId().toString()) == -1L){ - banned.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.BAN").replace("%grund%", BanManager.getReasonByID(ID)))); - } else { - String MSG = configcfg.getString("LAYOUT.TEMPBAN"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(UUID)); - MSG = MSG.replace("%dauer%", BanManager.getEnd(UUID)); - banned.disconnect(ChatColor.translateAlternateColorCodes('&', MSG)); - } - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e) { - e.printStackTrace(); - } - } - } else { - BanManager.mute(UUID, ID, "KONSOLE"); - LogManager.createEntry(UUID, "KONSOLE", "MUTE", String.valueOf(ID)); - BanManager.setMutes(UUID, BanManager.getMutes(UUID) + 1); - BanManager.sendNotify("MUTE", BanManager.getNameByUUID(UUID), "KONSOLE", BanManager.getReasonByID(ID)); - ProxiedPlayer banned = BungeeCord.getInstance().getPlayer(args[0]); - if(banned != null){ - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - if(BanManager.getRAWEnd(banned.getUniqueId().toString()) == -1L){ - banned.sendMessage(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.MUTE").replace("%grund%", BanManager.getReasonByID(ID)))); - } else { - String MSG = configcfg.getString("LAYOUT.TEMPMUTE"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(UUID)); - MSG = MSG.replace("%dauer%", BanManager.getEnd(UUID)); - banned.sendMessage(ChatColor.translateAlternateColorCodes('&', MSG)); - } - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cDieser Grund existiert nicht"); - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cDieser Spieler hat den Server noch nie betreten"); - } - } - } - } -} diff --git a/src/de/tutorialwork/commands/Blacklist.java b/src/de/tutorialwork/commands/Blacklist.java deleted file mode 100644 index 1dd6194..0000000 --- a/src/de/tutorialwork/commands/Blacklist.java +++ /dev/null @@ -1,130 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.LogManager; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; - -public class Blacklist extends Command { - public Blacklist(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer) { - ProxiedPlayer p = (ProxiedPlayer) sender; - if(p.hasPermission("professionalbans.blacklist") || p.hasPermission("professionalbans.*")){ - if(args.length == 0 || args.length == 1){ - p.sendMessage(Main.Prefix+"Derzeit sind §e§l"+Main.blacklist.size()+" Wörter §7auf der Blacklist"); - p.sendMessage(Main.Prefix+"/blacklist "); - } else if(args.length == 2){ - File blacklist = new File(Main.main.getDataFolder(), "blacklist.yml"); - try { - Configuration cfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(blacklist); - - ArrayList tempblacklist = new ArrayList<>(); - - if(args[0].equalsIgnoreCase("add")){ - String Wort = args[1]; - for(String congigstr : cfg.getStringList("BLACKLIST")){ - tempblacklist.add(congigstr); - } - tempblacklist.add(Wort); - Main.blacklist.add(Wort); - cfg.set("BLACKLIST", tempblacklist); - p.sendMessage(Main.Prefix+"§e§l"+Wort+" §7wurde zur Blacklist hinzugefügt"); - LogManager.createEntry(null, p.getUniqueId().toString(), "ADD_WORD_BLACKLIST", Wort); - } else if(args[0].equalsIgnoreCase("del")){ - String Wort = args[1]; - if(Main.blacklist.contains(Wort)){ - for(String congigstr : cfg.getStringList("BLACKLIST")){ - tempblacklist.add(congigstr); - } - tempblacklist.remove(Wort); - Main.blacklist.remove(Wort); - cfg.set("BLACKLIST", tempblacklist); - p.sendMessage(Main.Prefix+"§e§l"+Wort+" §7wurde von der Blacklist entfernt"); - LogManager.createEntry(null, p.getUniqueId().toString(), "DEL_WORD_BLACKLIST", Wort); - } else { - p.sendMessage(Main.Prefix+"§cDieses Wort steht nicht auf der Blacklist"); - } - } else { - p.sendMessage(Main.Prefix+"Derzeit sind §e§l"+Main.blacklist.size()+" Wörter §7auf der Blacklist"); - p.sendMessage(Main.Prefix+"/blacklist "); - } - - ConfigurationProvider.getProvider(YamlConfiguration.class).save(cfg, blacklist); - tempblacklist.clear(); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - p.sendMessage(Main.Prefix+"Derzeit sind §e§l"+Main.blacklist.size()+" Wörter §7auf der Blacklist"); - p.sendMessage(Main.Prefix+"/blacklist "); - } - } else { - p.sendMessage(Main.NoPerms); - } - } else { - //KONSOLE - if(args.length == 0 || args.length == 1){ - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"Derzeit sind §e§l"+Main.blacklist.size()+" Wörter §7auf der Blacklist"); - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"/blacklist "); - } else if(args.length == 2){ - File blacklist = new File(Main.main.getDataFolder(), "blacklist.yml"); - try { - Configuration cfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(blacklist); - - ArrayList tempblacklist = new ArrayList<>(); - - if(args[0].equalsIgnoreCase("add")){ - String Wort = args[1]; - for(String congigstr : cfg.getStringList("BLACKLIST")){ - tempblacklist.add(congigstr); - } - tempblacklist.add(Wort); - Main.blacklist.add(Wort); - cfg.set("BLACKLIST", tempblacklist); - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§e§l"+Wort+" §7wurde zur Blacklist hinzugefügt"); - LogManager.createEntry(null, "KONSOLE", "ADD_WORD_BLACKLIST", Wort); - } else if(args[0].equalsIgnoreCase("del")){ - String Wort = args[1]; - if(Main.blacklist.contains(Wort)){ - for(String congigstr : cfg.getStringList("BLACKLIST")){ - tempblacklist.add(congigstr); - } - tempblacklist.remove(Wort); - Main.blacklist.remove(Wort); - cfg.set("BLACKLIST", tempblacklist); - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§e§l"+Wort+" §7wurde von der Blacklist entfernt"); - LogManager.createEntry(null, "KONSOLE", "DEL_WORD_BLACKLIST", Wort); - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cDieses Wort steht nicht auf der Blacklist"); - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"Derzeit sind §e§l"+Main.blacklist.size()+" Wörter §7auf der Blacklist"); - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"/blacklist "); - } - - ConfigurationProvider.getProvider(YamlConfiguration.class).save(cfg, blacklist); - tempblacklist.clear(); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"Derzeit sind §e§l"+Main.blacklist.size()+" Wörter §7auf der Blacklist"); - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"/blacklist "); - } - } - } -} diff --git a/src/de/tutorialwork/commands/Chatlog.java b/src/de/tutorialwork/commands/Chatlog.java deleted file mode 100644 index b91e78a..0000000 --- a/src/de/tutorialwork/commands/Chatlog.java +++ /dev/null @@ -1,62 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.listener.Chat; -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.LogManager; -import de.tutorialwork.utils.UUIDFetcher; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.File; -import java.io.IOException; - -public class Chatlog extends Command { - public Chatlog(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer p = (ProxiedPlayer) sender; - if(args.length == 0){ - p.sendMessage(Main.Prefix+"/chatlog "); - } else { - String UUID = UUIDFetcher.getUUID(args[0]); - if(UUID != null){ - if(BanManager.playerExists(UUID)){ - if(!p.getUniqueId().toString().equals(UUID)){ - if(Chat.hasMessages(UUID)){ - String ID = Chat.createChatlog(UUID, p.getUniqueId().toString()); - p.sendMessage(Main.Prefix+"Der Chatlog von §e§l"+BanManager.getNameByUUID(UUID)+" §7wurde erfolgreich erstellt"); - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration cfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - p.sendMessage(Main.Prefix+"Link: §e§l"+cfg.getString("CHATLOG.URL")+ID); - } catch (IOException e) { - e.printStackTrace(); - } - LogManager.createEntry(UUID, p.getUniqueId().toString(), "CREATE_CHATLOG", ID); - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler hat in der letzten Zeit keine Nachrichten verfasst"); - } - } else { - p.sendMessage(Main.Prefix+"§cDu kannst kein Chatlog von dir selbst erstellen"); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler wurde nicht gefunden"); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler wurde nicht gefunden"); - } - } - } else { - - } - } -} diff --git a/src/de/tutorialwork/commands/Check.java b/src/de/tutorialwork/commands/Check.java deleted file mode 100644 index 74fdc3d..0000000 --- a/src/de/tutorialwork/commands/Check.java +++ /dev/null @@ -1,142 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.IPManager; -import de.tutorialwork.utils.UUIDFetcher; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; - -public class Check extends Command { - public Check(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer p = (ProxiedPlayer) sender; - if(p.hasPermission("professionalbans.check") || p.hasPermission("professionalbans.*")){ - if(args.length == 0){ - p.sendMessage(Main.Prefix+"/check "); - } else { - String UUID = UUIDFetcher.getUUID(args[0]); - if(IPBan.validate(args[0])){ - String IP = args[0]; - if(IPManager.IPExists(IP)){ - p.sendMessage("§8[]===================================[]"); - if(IPManager.getPlayerFromIP(IP) != null){ - p.sendMessage("§7Spieler: §e§l"+BanManager.getNameByUUID(IPManager.getPlayerFromIP(IP))); - } else { - p.sendMessage("§7Spieler: §c§lKeiner"); - } - if(IPManager.isBanned(IP)){ - p.sendMessage("§7IP-Ban: §c§lJa §8/ "+IPManager.getReasonString(IPManager.getIPFromPlayer(UUID))); - } else { - p.sendMessage("§7IP-Ban: §a§lNein"); - } - p.sendMessage("§7Bans: §e§l"+IPManager.getBans(IP)); - p.sendMessage("§7Zuletzt genutzt: §e§l"+BanManager.formatTimestamp(IPManager.getLastUseLong(IP))); - p.sendMessage("§8[]===================================[]"); - } else { - p.sendMessage(Main.Prefix+"§cZu dieser IP-Adresse sind keine Informationen verfügbar"); - } - } else { - if(BanManager.playerExists(UUID)){ - p.sendMessage("§8[]===================================[]"); - p.sendMessage("§7Spieler: §e§l"+BanManager.getNameByUUID(UUID)); - if(BanManager.isBanned(UUID)){ - p.sendMessage("§7Gebannt: §c§lJa §8/ "+BanManager.getReasonString(UUID)); - } else { - p.sendMessage("§7Gebannt: §a§lNein"); - } - if(BanManager.isMuted(UUID)){ - p.sendMessage("§7Gemutet: §c§lJa §8/ "+BanManager.getReasonString(UUID)); - } else { - p.sendMessage("§7Gemutet: §a§lNein"); - } - if(IPManager.isBanned(IPManager.getIPFromPlayer(UUID))){ - p.sendMessage("§7IP-Ban: §c§lJa §8/ "+IPManager.getReasonString(IPManager.getIPFromPlayer(UUID))); - } else { - p.sendMessage("§7IP-Ban: §a§lNein"); - } - p.sendMessage("§7Bans: §e§l"+BanManager.getBans(UUID)); - p.sendMessage("§7Mutes: §e§l"+BanManager.getMutes(UUID)); - if(BanManager.getLastLogin(UUID) != null){ - p.sendMessage("§7Letzter Login: §e§l"+BanManager.formatTimestamp(Long.valueOf(BanManager.getLastLogin(UUID)))); - } - if(BanManager.getFirstLogin(UUID) != null){ - p.sendMessage("§7Erster Login: §e§l"+BanManager.formatTimestamp(Long.valueOf(BanManager.getFirstLogin(UUID)))); - } - p.sendMessage("§8[]===================================[]"); - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler hat den Server noch nie betreten"); - } - } - } - } else { - p.sendMessage(Main.NoPerms); - } - } else { - if(args.length == 0){ - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"/check "); - } else { - String UUID = UUIDFetcher.getUUID(args[0]); - if(IPBan.validate(args[0])){ - String IP = args[0]; - if(IPManager.IPExists(IP)){ - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - if(IPManager.getPlayerFromIP(IP) != null){ - BungeeCord.getInstance().getConsole().sendMessage("§7Spieler: §e§l"+BanManager.getNameByUUID(IPManager.getPlayerFromIP(IP))); - } else { - BungeeCord.getInstance().getConsole().sendMessage("§7Spieler: §c§lKeiner"); - } - if(IPManager.isBanned(IP)){ - BungeeCord.getInstance().getConsole().sendMessage("§7IP-Ban: §c§lJa §8/ "+IPManager.getReasonString(IPManager.getIPFromPlayer(UUID))); - } else { - BungeeCord.getInstance().getConsole().sendMessage("§7IP-Ban: §a§lNein"); - } - BungeeCord.getInstance().getConsole().sendMessage("§7Bans: §e§l"+IPManager.getBans(IP)); - BungeeCord.getInstance().getConsole().sendMessage("§7Zuletzt genutzt: §e§l"+BanManager.formatTimestamp(IPManager.getLastUseLong(IP))); - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cZu dieser IP-Adresse sind keine Informationen verfügbar"); - } - } else { - if(BanManager.playerExists(UUID)){ - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - BungeeCord.getInstance().getConsole().sendMessage("§7Spieler: §e§l"+BanManager.getNameByUUID(UUID)); - if(BanManager.isBanned(UUID)){ - BungeeCord.getInstance().getConsole().sendMessage("§7Gebannt: §c§lJa §8/ "+BanManager.getReasonString(UUID)); - } else { - BungeeCord.getInstance().getConsole().sendMessage("§7Gebannt: §a§lNein"); - } - if(BanManager.isMuted(UUID)){ - BungeeCord.getInstance().getConsole().sendMessage("§7Gemutet: §c§lJa §8/ "+BanManager.getReasonString(UUID)); - } else { - BungeeCord.getInstance().getConsole().sendMessage("§7Gemutet: §a§lNein"); - } - if(IPManager.isBanned(IPManager.getIPFromPlayer(UUID))){ - BungeeCord.getInstance().getConsole().sendMessage("§7IP-Ban: §c§lJa §8/ "+IPManager.getReasonString(IPManager.getIPFromPlayer(UUID))); - } else { - BungeeCord.getInstance().getConsole().sendMessage("§7IP-Ban: §a§lNein"); - } - BungeeCord.getInstance().getConsole().sendMessage("§7Bans: §e§l"+BanManager.getBans(UUID)); - BungeeCord.getInstance().getConsole().sendMessage("§7Mutes: §e§l"+BanManager.getMutes(UUID)); - if(BanManager.getLastLogin(UUID) != null){ - BungeeCord.getInstance().getConsole().sendMessage("§7Letzter Login: §e§l"+BanManager.formatTimestamp(Long.valueOf(BanManager.getLastLogin(UUID)))); - } - if(BanManager.getFirstLogin(UUID) != null){ - BungeeCord.getInstance().getConsole().sendMessage("§7Erster Login: §e§l"+BanManager.formatTimestamp(Long.valueOf(BanManager.getFirstLogin(UUID)))); - } - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cDieser Spieler hat den Server noch nie betreten"); - } - } - } - } - } -} diff --git a/src/de/tutorialwork/commands/IPBan.java b/src/de/tutorialwork/commands/IPBan.java deleted file mode 100644 index 600f54c..0000000 --- a/src/de/tutorialwork/commands/IPBan.java +++ /dev/null @@ -1,111 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.IPManager; -import de.tutorialwork.utils.LogManager; -import de.tutorialwork.utils.UUIDFetcher; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.File; -import java.io.IOException; -import java.util.regex.Pattern; - -public class IPBan extends Command { - public IPBan(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer p = (ProxiedPlayer) sender; - if(p.hasPermission("professionalbans.ipban") || p.hasPermission("professionalbans.*")){ - if(args.length == 0 || args.length == 1){ - for(int zaehler = 1; zaehler < BanManager.countReasons()+1; zaehler++) { - if(BanManager.isBanReason(zaehler)){ - p.sendMessage("§7"+zaehler+" §8| §e"+BanManager.getReasonByID(zaehler)); - } - } - p.sendMessage(Main.Prefix+"/ipban "); - } else { - String IP = args[0]; - int ID = Integer.valueOf(args[1]); - if(validate(IP)){ - if(BanManager.getReasonByID(ID) != null){ - if(IPManager.IPExists(IP)){ - IPManager.ban(IP, ID, p.getUniqueId().toString()); - IPManager.addBan(IP); - BanManager.sendNotify("IPBAN", IP, p.getName(), BanManager.getReasonByID(ID)); - } else { - IPManager.insertIP(IP, null); - IPManager.ban(IP, ID, p.getUniqueId().toString()); - IPManager.addBan(IP); - BanManager.sendNotify("IPBAN", IP, p.getName(), BanManager.getReasonByID(ID)); - } - disconnectIPBannedPlayers(IP); - LogManager.createEntry(null, p.getUniqueId().toString(), "IPBAN_IP", IP); - } else { - p.sendMessage(Main.Prefix+"§cDieser Grund existiert nicht"); - } - } else { - String UUID = UUIDFetcher.getUUID(args[0]); - if(IPManager.getIPFromPlayer(UUID) != null){ - String DBIP = IPManager.getIPFromPlayer(UUID); - IPManager.ban(DBIP, ID, p.getUniqueId().toString()); - IPManager.addBan(DBIP); - BanManager.sendNotify("IPBAN", DBIP, p.getName(), BanManager.getReasonByID(ID)); - disconnectIPBannedPlayers(DBIP); - LogManager.createEntry(UUID, p.getUniqueId().toString(), "IPBAN_PLAYER", String.valueOf(ID)); - } else { - p.sendMessage(Main.Prefix+"§cZu diesem Spieler ist keine IP-Adresse gespeichert"); - } - } - } - } else { - p.sendMessage(Main.NoPerms); - } - } - } - - public static void disconnectIPBannedPlayers(String IP){ - for(ProxiedPlayer all : Main.getInstance().getProxy().getPlayers()){ - if(all.getAddress().getHostString().equals(IP)){ - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - - if(IPManager.getRAWEnd(IP) == -1L){ - all.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.IPBAN").replace("%grund%", IPManager.getReasonString(IP)))); - } else { - if(System.currentTimeMillis() < IPManager.getRAWEnd(IP)){ - String MSG = configcfg.getString("LAYOUT.TEMPIPBAN"); - MSG = MSG.replace("%grund%", IPManager.getReasonString(IP)); - MSG = MSG.replace("%dauer%", IPManager.getEnd(IP)); - all.disconnect(ChatColor.translateAlternateColorCodes('&', MSG)); - } else { - IPManager.unban(IP); - } - } - - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e2) { - e2.printStackTrace(); - } - } - } - } - - private static final Pattern PATTERN = Pattern.compile( - "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); - - public static boolean validate(final String ip) { - return PATTERN.matcher(ip).matches(); - } -} diff --git a/src/de/tutorialwork/commands/Kick.java b/src/de/tutorialwork/commands/Kick.java deleted file mode 100644 index 111b20e..0000000 --- a/src/de/tutorialwork/commands/Kick.java +++ /dev/null @@ -1,80 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.LogManager; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.File; -import java.io.IOException; - -public class Kick extends Command { - public Kick(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer p = (ProxiedPlayer) sender; - if(p.hasPermission("professionalbans.kick") || p.hasPermission("professionalbans.*")){ - if(args.length == 0 || args.length == 1){ - p.sendMessage(Main.Prefix+"/kick "); - } else { - ProxiedPlayer tokick = BungeeCord.getInstance().getPlayer(args[0]); - if(tokick != null){ - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - String grund = ""; - for(int i = 1; i < args.length; i++){ - grund = grund + " " + args[i]; - } - BanManager.sendNotify("KICK", tokick.getName(), p.getName(), grund); - LogManager.createEntry(tokick.getUniqueId().toString(), p.getUniqueId().toString(), "KICK", grund); - tokick.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.KICK").replace("%grund%", grund))); - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler ist nicht online"); - } - } - } else { - p.sendMessage(Main.NoPerms); - } - } else { - if(args.length == 0 || args.length == 1){ - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"/kick "); - } else { - ProxiedPlayer tokick = BungeeCord.getInstance().getPlayer(args[0]); - if(tokick != null){ - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - String grund = ""; - for(int i = 1; i < args.length; i++){ - grund = grund + " " + args[i]; - } - BanManager.sendNotify("KICK", tokick.getName(), "KONSOLE", grund); - LogManager.createEntry(tokick.getUniqueId().toString(), "KONSOLE", "KICK", grund); - tokick.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.KICK").replace("%grund%", grund))); - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cDieser Spieler ist nicht online"); - } - } - } - } -} diff --git a/src/de/tutorialwork/commands/ProfessionalBans.java b/src/de/tutorialwork/commands/ProfessionalBans.java deleted file mode 100644 index 8a9f6c4..0000000 --- a/src/de/tutorialwork/commands/ProfessionalBans.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; - -public class ProfessionalBans extends Command { - public ProfessionalBans(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - ProxiedPlayer p = (ProxiedPlayer) sender; - p.sendMessage(""); - p.sendMessage("§8[]===================================[]"); - p.sendMessage("§e§lProfessionalBans §7§oReloaded §8• §7Version §8» §c"+ Main.Version); - p.sendMessage("§7Developer §8» §e§lTutorialwork"); - p.sendMessage("§5YT §7Kanal §8» §cyoutube.com/Tutorialwork"); - p.sendMessage("§8[]===================================[]"); - p.sendMessage(""); - } -} diff --git a/src/de/tutorialwork/commands/Report.java b/src/de/tutorialwork/commands/Report.java deleted file mode 100644 index ffd3ab4..0000000 --- a/src/de/tutorialwork/commands/Report.java +++ /dev/null @@ -1,84 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.LogManager; -import de.tutorialwork.utils.UUIDFetcher; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.File; -import java.io.IOException; - -public class Report extends Command { - public Report(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer) { - ProxiedPlayer p = (ProxiedPlayer) sender; - if(args.length == 0 || args.length == 1){ - String reasons = ""; - int komma = Main.reportreasons.size(); - for(String reason : Main.reportreasons){ - komma--; - if(komma != 0){ - reasons = reasons + reason + ", "; - } else { - reasons = reasons + reason; - } - } - p.sendMessage(Main.Prefix+"Verfügbare Reportgründe: §e§l"+reasons); - p.sendMessage(Main.Prefix+"/report "); - } else { - if(args[0].toUpperCase().equals(p.getName().toUpperCase())){ - p.sendMessage(Main.Prefix+"§cDu kannst dich nicht selbst melden"); - return; - } - if(Main.reportreasons.contains(args[1].toUpperCase())){ - ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[0]); - if(target != null){ - BanManager.createReport(target.getUniqueId().toString(), p.getUniqueId().toString(), args[1].toUpperCase(), null); - p.sendMessage(Main.Prefix+"Der Spieler §e§l"+target.getName()+" §7wurde erfolgreich wegen §e§l"+args[1].toUpperCase()+" §7gemeldet"); - BanManager.sendNotify("REPORT", target.getName(), p.getName(), args[1].toUpperCase()); - LogManager.createEntry(target.getUniqueId().toString(), p.getUniqueId().toString(), "REPORT", args[1].toUpperCase()); - } else { - try{ - File file = new File(Main.main.getDataFolder(), "config.yml"); - Configuration cfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); - if(cfg.getBoolean("REPORTS.OFFLINEREPORTS")){ - String UUID = UUIDFetcher.getUUID(args[0]); - if(UUID != null){ - if(BanManager.playerExists(UUID)){ - BanManager.createReport(UUID, p.getUniqueId().toString(), args[1].toUpperCase(), null); - p.sendMessage(Main.Prefix+"Der Spieler §e§l"+target.getName()+" §7(§4Offline§7) wurde erfolgreich wegen §e§l"+args[1].toUpperCase()+" §7gemeldet"); - LogManager.createEntry(UUID, p.getUniqueId().toString(), "REPORT_OFFLINE", args[1].toUpperCase()); - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler wurde nicht gefunden"); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler wurde nicht gefunden"); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler ist offline"); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } else { - p.sendMessage(Main.Prefix+"§cDer eingegebene Reportgrund wurde nicht gefunden"); - } - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§e§lReports §7sind nur als Spieler verfügbar"); - } - } -} diff --git a/src/de/tutorialwork/commands/Reports.java b/src/de/tutorialwork/commands/Reports.java deleted file mode 100644 index d09e0c6..0000000 --- a/src/de/tutorialwork/commands/Reports.java +++ /dev/null @@ -1,77 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.LogManager; -import de.tutorialwork.utils.UUIDFetcher; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.File; -import java.io.IOException; - -public class Reports extends Command { - public Reports(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer) { - ProxiedPlayer p = (ProxiedPlayer) sender; - if(p.hasPermission("professionalbans.reports") || p.hasPermission("professionalbans.*")){ - if(args.length == 0){ - if(BanManager.countOpenReports() != 0){ - p.sendMessage("§8[]===================================[]"); - p.sendMessage("§e§loffene Reports §7(§8"+BanManager.countOpenReports()+"§7)"); - int offline = 0; - for(int i = 0; i < BanManager.getIDsFromOpenReports().size(); ++i) { - int id = (int) BanManager.getIDsFromOpenReports().get(i); - ProxiedPlayer target = BungeeCord.getInstance().getPlayer(BanManager.getNameByReportID(id)); - if(target != null){ - TextComponent tc = new TextComponent(); - tc.setText("§e§l"+target.getName()+" §7gemeldet wegen §c§l "+BanManager.getReasonByReportID(id)+" §8| §7Online auf §e§l"+target.getServer().getInfo().getName()); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reports jump "+target.getName()+" "+id)); - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Klicken um §e§l"+target.getName()+" §7nachzuspringen").create())); - p.sendMessage(tc); - } else { - offline++; - } - } - if(offline != 0){ - p.sendMessage("§4§o"+offline+" Reports §7§ovon Spieler die offline sind ausgeblendet"); - } - p.sendMessage("§8[]===================================[]"); - } else { - p.sendMessage(Main.Prefix+"§cEs sind derzeit keine Reports offen"); - } - } else if(args[0].equalsIgnoreCase("jump")){ - ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[1]); - if(target != null){ - p.connect(target.getServer().getInfo()); - int id = Integer.parseInt(args[2]); - BanManager.setReportDone(id); - BanManager.setReportTeamUUID(id, p.getUniqueId().toString()); - p.sendMessage(Main.Prefix+"Du hast den Report von §e§l"+BanManager.getNameByReportID(id)+" §7wegen §c§l"+BanManager.getReasonByReportID(id)+" §aangenommen"); - LogManager.createEntry(p.getUniqueId().toString(), null, "REPORT_ACCEPT", String.valueOf(id)); - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler ist nicht mehr online"); - } - } - } else { - p.sendMessage(Main.NoPerms); - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§e§lReports §7sind nur als Spieler verfügbar"); - } - } -} diff --git a/src/de/tutorialwork/commands/SupportChat.java b/src/de/tutorialwork/commands/SupportChat.java deleted file mode 100644 index e7d6df1..0000000 --- a/src/de/tutorialwork/commands/SupportChat.java +++ /dev/null @@ -1,137 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; - -import java.util.HashMap; - -public class SupportChat extends Command { - public SupportChat(String name) { - super(name); - } - - public static HashMap openchats = new HashMap<>(); - public static HashMap activechats = new HashMap<>(); - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer p = (ProxiedPlayer) sender; - if(args.length != 0){ - if(args[0].equalsIgnoreCase("end")){ - if(activechats.containsValue(p) || activechats.containsKey(p)){ - for(ProxiedPlayer key : SupportChat.activechats.keySet()){ - //Key has started the support chat - if(key == p){ - SupportChat.activechats.get(p).sendMessage(Main.Prefix+"§e§l"+p.getName()+" §7hat den Support Chat §cbeeendet"); - activechats.remove(key); - } else { - key.sendMessage(Main.Prefix+"§e§l"+p.getName()+" §7hat den Support Chat §cbeeendet"); - activechats.remove(key); - } - } - p.sendMessage(Main.Prefix+"§cDu hast den Support Chat beendet"); - return; - } else { - p.sendMessage(Main.Prefix+"§cDu hast derzeit keinen offenen Support Chat"); - return; - } - } - } - if(p.hasPermission("professionalbans.supportchat") || p.hasPermission("professionalbans.*")){ - //Team Member - if(args.length > 0){ - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.getName().equals(args[0])){ - if (openchats.containsKey(all)) { - activechats.put(all, p); - openchats.remove(all); - all.sendMessage(Main.Prefix+"§e§l"+p.getName()+" §7ist jetzt mit dir im Support Chat"); - all.sendMessage(Main.Prefix+"§8§oDu kannst in den Support Chat schreiben in dem du einfach eine normale Nachricht schreibst"); - all.sendMessage(Main.Prefix+"§8§oDu kannst den Support Chat mit §7§o/support end §8§obeenden"); - p.sendMessage(Main.Prefix+"§e§l"+all.getName()+" §7ist jetzt im Support Chat mit dir"); - p.sendMessage(Main.Prefix+"§8§oDu kannst den Support Chat mit §7§o/support end §8§obeenden"); - } else { - p.sendMessage(Main.Prefix+"§cDiese Anfrage ist ausgelaufen"); - } - } - } - } else { - if(SupportChat.openchats.size() != 0){ - p.sendMessage("§8[]===================================[]"); - int i = 0; - for(ProxiedPlayer key : SupportChat.openchats.keySet()){ - p.sendMessage("§e§l"+key+" §8• §9"+SupportChat.openchats.get(key)); - TextComponent tc = new TextComponent(); - tc.setText("§aSupport Chat starten"); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/support "+key)); - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Klicken um den Chat mit §e§l"+key+" §7zu starten").create())); - p.sendMessage(tc); - i++; - } - p.sendMessage("§8[]===================================[]"); - p.sendMessage(Main.Prefix+"Es sind derzeit §e§l"+i+" Support Chats §7Anfragen §aoffen"); - } else { - p.sendMessage(Main.Prefix+"§cDerzeit sind keine Support Chats Anfragen offen"); - } - } - } else { - //Normal Member - if(args.length == 0){ - p.sendMessage(Main.Prefix+"Wenn du den §e§lSupport Chat §7starten möchtest gebe ein §8§oBetreff §7ein"); - p.sendMessage(Main.Prefix+"Möchtest du eine Anfrage abbrechen? §8§o/support cancel"); - } else { - int supporter = 0; - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.supportchat") || all.hasPermission("professionalbans.*")){ - supporter++; - } - } - if(!args[0].equalsIgnoreCase("cancel")){ - String subject = ""; - for(int i = 0; i < args.length; i++){ - subject = subject + " " + args[i]; - } - if(!openchats.containsKey(p)){ - if(supporter > 0){ - openchats.put(p, subject); - p.sendMessage(Main.Prefix+"Du hast eine Anfrage mit dem Betreff §e§l"+subject+" §7gestartet"); - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.supportchat") || all.hasPermission("professionalbans.*")){ - all.sendMessage(Main.Prefix+"§e§l"+p.getName()+" §7benötigt Support §8(§e§o"+subject+"§8)"); - TextComponent tc = new TextComponent(); - tc.setText("§aSupport Chat starten"); - tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/support "+p.getName())); - tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Klicken um den Chat mit §e§l"+p.getName()+" §7zu starten").create())); - all.sendMessage(tc); - } - } - } else { - p.sendMessage(Main.Prefix+"§cDerzeit ist kein Supporter online"); - } - } else { - p.sendMessage(Main.Prefix+"Du hast bereits eine §e§lSupport Chat §7Anfrage gestellt"); - p.sendMessage(Main.Prefix+"Möchtest du diese Anfrage §cabbrechen §7benutze §c§l/support cancel"); - } - } else { - if(!openchats.containsKey(p)){ - openchats.remove(p); - p.sendMessage(Main.Prefix+"Deine Anfrage wurde erfolgreich §cgelöscht"); - } else { - p.sendMessage(Main.Prefix+"§cDu hast derzeit keine offene Anfrage"); - } - } - } - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"Der §e§lSupport Chat §7ist nur als Spieler verfügbar"); - } - } -} diff --git a/src/de/tutorialwork/commands/Unban.java b/src/de/tutorialwork/commands/Unban.java deleted file mode 100644 index a6e8655..0000000 --- a/src/de/tutorialwork/commands/Unban.java +++ /dev/null @@ -1,95 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.IPManager; -import de.tutorialwork.utils.LogManager; -import de.tutorialwork.utils.UUIDFetcher; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; - -public class Unban extends Command { - public Unban(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer p = (ProxiedPlayer) sender; - if(p.hasPermission("professionalbans.unban") || p.hasPermission("professionalbans.*")){ - if(args.length == 0){ - p.sendMessage(Main.Prefix+"/unban "); - } else { - String UUID = UUIDFetcher.getUUID(args[0]); - if(IPBan.validate(args[0])){ - IPManager.unban(args[0]); - BanManager.sendNotify("UNBANIP", args[0], p.getName(), null); - p.sendMessage(Main.Prefix+"§7Die IP-Adresse §e§l"+args[0]+" §7wurde §aerfolgreich §7entbannt"); - LogManager.createEntry(null, p.getUniqueId().toString(), "UNBAN_IP", args[0]); - } else { - if(BanManager.playerExists(UUID)){ - if(IPManager.isBanned(IPManager.getIPFromPlayer(UUID))){ - IPManager.unban(IPManager.getIPFromPlayer(UUID)); - p.sendMessage(Main.Prefix+"Die IP §e§l"+IPManager.getIPFromPlayer(UUID)+ " §7war gebannt und wurde ebenfalls §aentbannt"); - } - if(BanManager.isBanned(UUID)){ - BanManager.unban(UUID); - BanManager.sendNotify("UNBAN", BanManager.getNameByUUID(UUID), p.getName(), "null"); - p.sendMessage(Main.Prefix+"§e§l"+BanManager.getNameByUUID(UUID)+" §7wurde §aerfolgreich §7entbannt"); - LogManager.createEntry(UUID, p.getUniqueId().toString(), "UNBAN_BAN", null); - } else if(BanManager.isMuted(UUID)) { - BanManager.unmute(UUID); - BanManager.sendNotify("UNMUTE", BanManager.getNameByUUID(UUID), p.getName(), "null"); - p.sendMessage(Main.Prefix+"§e§l"+BanManager.getNameByUUID(UUID)+" §7wurde §aerfolgreich §7entmutet"); - LogManager.createEntry(UUID, p.getUniqueId().toString(), "UNBAN_MUTE", null); - } else { - p.sendMessage(Main.Prefix+"§e§l"+BanManager.getNameByUUID(UUID)+" §7ist weder gebannt oder gemutet"); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler hat den Server noch nie betreten"); - } - } - } - } else { - p.sendMessage(Main.NoPerms); - } - } else { - if(args.length == 0){ - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"/unban "); - } else { - String UUID = UUIDFetcher.getUUID(args[0]); - if(IPBan.validate(args[0])){ - IPManager.unban(args[0]); - BanManager.sendNotify("UNBANIP", args[0], "KONSOLE", null); - BungeeCord.getInstance().getConsole().sendMessage((Main.Prefix+"§7Die IP-Adresse §e§l"+args[0]+" §7wurde §aerfolgreich §7entbannt")); - LogManager.createEntry(null, "KONSOLE", "UNBAN_IP", args[0]); - } else { - if(BanManager.playerExists(UUID)){ - if(IPManager.isBanned(IPManager.getIPFromPlayer(UUID))){ - IPManager.unban(IPManager.getIPFromPlayer(UUID)); - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"Die IP §e§l"+IPManager.getIPFromPlayer(UUID)+ " §7war gebannt und wurde ebenfalls §aentbannt"); - } - if(BanManager.isBanned(UUID)){ - BanManager.unban(UUID); - BanManager.sendNotify("UNBAN", BanManager.getNameByUUID(UUID), "KONSOLE", "null"); - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§e§l"+BanManager.getNameByUUID(UUID)+" §7wurde §aerfolgreich §7entbannt"); - LogManager.createEntry(UUID, "KONSOLE", "UNBAN_BAN", null); - } else if(BanManager.isMuted(UUID)) { - BanManager.unmute(UUID); - BanManager.sendNotify("UNMUTE", BanManager.getNameByUUID(UUID), "KONSOLE", "null"); - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§e§l"+BanManager.getNameByUUID(UUID)+" §7wurde §aerfolgreich §7entmutet"); - LogManager.createEntry(UUID, "KONSOLE", "UNBAN_MUTE", null); - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§e§l"+BanManager.getNameByUUID(UUID)+" §7ist weder gebannt oder gemutet"); - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cDieser Spieler hat den Server noch nie betreten"); - } - } - } - } - } -} diff --git a/src/de/tutorialwork/commands/WebAccount.java b/src/de/tutorialwork/commands/WebAccount.java deleted file mode 100644 index 32bce8c..0000000 --- a/src/de/tutorialwork/commands/WebAccount.java +++ /dev/null @@ -1,93 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BCrypt; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.LogManager; -import de.tutorialwork.utils.UUIDFetcher; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; - -import java.util.Random; - -public class WebAccount extends Command { - public WebAccount(String name) { - super(name); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer p = (ProxiedPlayer) sender; - if(p.hasPermission("professionalbans.webaccount") || p.hasPermission("professionalbans.*")){ - if(args.length == 0 || args.length == 1){ - p.sendMessage(Main.Prefix+"/webaccount [Rang]"); - } else { - if(args[0].equalsIgnoreCase("erstellen")){ - if(args.length == 2){ - p.sendMessage(Main.Prefix+"Du musst noch ein Rang des Accounts angeben §4Admin§7, §cMod§7, §9Sup"); - return; - } - String UUID = UUIDFetcher.getUUID(args[1]); - if(BanManager.playerExists(UUID)){ - if(!BanManager.webaccountExists(UUID)){ - ProxiedPlayer target = BungeeCord.getInstance().getPlayer(args[1]); - if(target != null){ - String rowPW = randomString(7); - String Hash = BCrypt.hashpw(rowPW, BCrypt.gensalt()); - if(args[2].equalsIgnoreCase("Admin")){ - BanManager.createWebAccount(UUID, BanManager.getNameByUUID(UUID), 3, Hash); - p.sendMessage(Main.Prefix+"Ein §4§lAdmin §7Account für §e§l"+BanManager.getNameByUUID(UUID)+" §7wurde §aerstellt"); - } else if(args[2].equalsIgnoreCase("Mod")){ - BanManager.createWebAccount(UUID, BanManager.getNameByUUID(UUID), 2, Hash); - p.sendMessage(Main.Prefix+"Ein §c§lMod §7Account für §e§l"+BanManager.getNameByUUID(UUID)+" §7wurde §aerstellt"); - } else if(args[2].equalsIgnoreCase("Sup")){ - BanManager.createWebAccount(UUID, BanManager.getNameByUUID(UUID), 1, Hash); - p.sendMessage(Main.Prefix+"Ein §9§lSup §7Account für §e§l"+BanManager.getNameByUUID(UUID)+" §7wurde §aerstellt"); - } - target.sendMessage(Main.Prefix+"§e§l"+p.getName()+" §7hat einen Webaccount für dich erstellt"); - target.sendMessage(Main.Prefix+"Passwort: §c§l"+rowPW); - LogManager.createEntry(UUID, p.getUniqueId().toString(), "ADD_WEBACCOUNT", args[2]); - } else { - p.sendMessage(Main.Prefix+"§e§l"+args[1]+" §7ist derzeit nicht online"); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler hat bereits einen Zugang zum Webinterface"); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler hat den Server noch nie betreten"); - } - } else if(args[0].equalsIgnoreCase("löschen")){ - String UUID = UUIDFetcher.getUUID(args[1]); - if(BanManager.playerExists(UUID)){ - if(BanManager.webaccountExists(UUID)){ - BanManager.deleteWebAccount(UUID); - p.sendMessage(Main.Prefix+"Der Zugang von dem Spieler §e§l"+BanManager.getNameByUUID(UUID)+" §7wurde erfolgreich §agelöscht"); - LogManager.createEntry(UUID, p.getUniqueId().toString(), "DEL_WEBACCOUNT", null); - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler hat keinen Zugang zum Webinterface"); - } - } else { - p.sendMessage(Main.Prefix+"§cDieser Spieler hat den Server noch nie betreten"); - } - } else { - p.sendMessage(Main.Prefix+"§cDiese Aktion ist nicht gültig"); - } - } - } else { - p.sendMessage(Main.NoPerms); - } - } - } - static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; - static Random rnd = new Random(); - - private static String randomString(int length){ - StringBuilder sb = new StringBuilder(length); - for(int i = 0; i < length; i++) - sb.append(AB.charAt(rnd.nextInt(AB.length()))); - return sb.toString(); - } -} diff --git a/src/de/tutorialwork/commands/WebVerify.java b/src/de/tutorialwork/commands/WebVerify.java deleted file mode 100644 index 283c3eb..0000000 --- a/src/de/tutorialwork/commands/WebVerify.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.tutorialwork.commands; - -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; - -public class WebVerify extends Command { - public WebVerify(String cmd) { - super(cmd); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer p = (ProxiedPlayer) sender; - if(args.length == 0){ - p.sendMessage(Main.Prefix+"/webverify "); - } else { - String UUID = p.getUniqueId().toString(); - if(BanManager.webaccountExists(UUID)){ - if(BanManager.hasAuthToken(UUID)){ - if(args[0].length() == 25){ - if(BanManager.getAuthCode(UUID).equals(args[0])){ - BanManager.updateAuthStatus(UUID); - p.sendMessage(Main.Prefix+"§a§lErfolgreich! §7Du kannst jetzt dein Passwort festlegen."); - } else { - p.sendMessage(Main.Prefix+"§cDer eingegebene Token ist ungültig"); - } - } else { - p.sendMessage(Main.Prefix+"§cDer eingegebene Token ist ungültig"); - } - } else { - p.sendMessage(Main.Prefix+"§cEs wurde keine Verifizierungsanfrage von dir gefunden"); - } - } else { - p.sendMessage(Main.Prefix+"§cDu hast keinen Account im Webinterface"); - } - } - } else { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cDieser Befehl ist nur als Spieler nutzbar"); - } - } -} diff --git a/src/de/tutorialwork/listener/Chat.java b/src/de/tutorialwork/listener/Chat.java deleted file mode 100644 index f2f892b..0000000 --- a/src/de/tutorialwork/listener/Chat.java +++ /dev/null @@ -1,204 +0,0 @@ -package de.tutorialwork.listener; - -import de.tutorialwork.commands.SupportChat; -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.LogManager; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.ChatEvent; -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; -import net.md_5.bungee.event.EventHandler; - -import java.io.File; -import java.io.IOException; -import java.security.SecureRandom; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Map; - -public class Chat implements Listener { - - @EventHandler - public void onChat(ChatEvent e){ - ProxiedPlayer p = (ProxiedPlayer) e.getSender(); - if(!e.getMessage().startsWith("/")){ - if(SupportChat.activechats.containsKey(p)){ - e.setCancelled(true); - ProxiedPlayer target = SupportChat.activechats.get(p); - target.sendMessage("§9§lSUPPORT §8• §c"+p.getName()+" §8» "+e.getMessage()); - p.sendMessage("§9§lSUPPORT §8• §aDu §8» "+e.getMessage()); - } - if(SupportChat.activechats.containsValue(p)){ - e.setCancelled(true); - for(ProxiedPlayer key : SupportChat.activechats.keySet()){ - //Key has started the support chat - key.sendMessage("§9§lSUPPORT §8• §c"+p.getName()+" §8» "+e.getMessage()); - } - p.sendMessage("§9§lSUPPORT §8• §aDu §8» "+e.getMessage()); - } - if(BanManager.isMuted(p.getUniqueId().toString())){ - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - - if(BanManager.getRAWEnd(p.getUniqueId().toString()) == -1L){ - e.setCancelled(true); - p.sendMessage(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.MUTE").replace("%grund%", BanManager.getReasonString(p.getUniqueId().toString())))); - } else { - if(System.currentTimeMillis() < BanManager.getRAWEnd(p.getUniqueId().toString())){ - e.setCancelled(true); - String MSG = configcfg.getString("LAYOUT.TEMPMUTE"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(p.getUniqueId().toString())); - MSG = MSG.replace("%dauer%", BanManager.getEnd(p.getUniqueId().toString())); - p.sendMessage(ChatColor.translateAlternateColorCodes('&', MSG)); - } else { - BanManager.unmute(p.getUniqueId().toString()); - } - } - - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e2) { - e2.printStackTrace(); - } - } else { - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - - if(!p.hasPermission("professionalbans.blacklist.bypass") || !p.hasPermission("professionalbans.*")){ - if(configcfg.getBoolean("AUTOMUTE.ENABLED")){ - insertMessage(p.getUniqueId().toString(), e.getMessage(), p.getServer().getInfo().getName()); - for(String blacklist : Main.blacklist){ - if(e.getMessage().toUpperCase().contains(blacklist.toUpperCase())){ - e.setCancelled(true); - BanManager.mute(p.getUniqueId().toString(), configcfg.getInt("AUTOMUTE.MUTEID"), "KONSOLE"); - LogManager.createEntry(p.getUniqueId().toString(), "KONSOLE", "AUTOMUTE_BLACKLIST", e.getMessage()); - BanManager.setMutes(p.getUniqueId().toString(), BanManager.getMutes(p.getUniqueId().toString()) + 1); - BanManager.sendNotify("MUTE", BanManager.getNameByUUID(p.getUniqueId().toString()), "KONSOLE", BanManager.getReasonByID(configcfg.getInt("AUTOMUTE.MUTEID"))); - if(BanManager.getRAWEnd(p.getUniqueId().toString()) == -1L){ - p.sendMessage(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.MUTE").replace("%grund%", BanManager.getReasonByID(configcfg.getInt("AUTOMUTE.MUTEID"))))); - } else { - String MSG = configcfg.getString("LAYOUT.TEMPMUTE"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(p.getUniqueId().toString())); - MSG = MSG.replace("%dauer%", BanManager.getEnd(p.getUniqueId().toString())); - p.sendMessage(ChatColor.translateAlternateColorCodes('&', MSG)); - } - return; - } - } - for(String adblacklist : Main.adblacklist){ - if(e.getMessage().toUpperCase().contains(adblacklist.toUpperCase())){ - if(!Main.adwhitelist.contains(e.getMessage().toUpperCase())){ - e.setCancelled(true); - BanManager.mute(p.getUniqueId().toString(), configcfg.getInt("AUTOMUTE.ADMUTEID"), "KONSOLE"); - LogManager.createEntry(p.getUniqueId().toString(), "KONSOLE", "AUTOMUTE_ADBLACKLIST", e.getMessage()); - BanManager.setMutes(p.getUniqueId().toString(), BanManager.getMutes(p.getUniqueId().toString()) + 1); - BanManager.sendNotify("MUTE", BanManager.getNameByUUID(p.getUniqueId().toString()), "KONSOLE", BanManager.getReasonByID(configcfg.getInt("AUTOMUTE.ADMUTEID"))); - if(BanManager.getRAWEnd(p.getUniqueId().toString()) == -1L){ - p.sendMessage(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.MUTE").replace("%grund%", BanManager.getReasonByID(configcfg.getInt("AUTOMUTE.MUTEID"))))); - } else { - String MSG = configcfg.getString("LAYOUT.TEMPMUTE"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(p.getUniqueId().toString())); - MSG = MSG.replace("%dauer%", BanManager.getEnd(p.getUniqueId().toString())); - p.sendMessage(ChatColor.translateAlternateColorCodes('&', MSG)); - } - return; - } - } - } - } else { - insertMessage(p.getUniqueId().toString(), e.getMessage(), p.getServer().getInfo().getName()); - if(configcfg.getBoolean("AUTOMUTE.AUTOREPORT")){ - for(String blacklist : Main.blacklist){ - if(e.getMessage().toUpperCase().contains(blacklist.toUpperCase())){ - e.setCancelled(true); - p.sendMessage(Main.Prefix+"§cAchte auf deine Wortwahl"); - String LogID = Chat.createChatlog(p.getUniqueId().toString(), "KONSOLE"); - BanManager.createReport(p.getUniqueId().toString(),"KONSOLE", "VERHALTEN", LogID); - BanManager.sendNotify("REPORT", p.getName(), "KONSOLE", "VERHALTEN"); - return; - } - } - for(String adblacklist : Main.adblacklist){ - if(e.getMessage().toUpperCase().contains(adblacklist.toUpperCase())){ - if(!Main.adwhitelist.contains(e.getMessage().toUpperCase())){ - e.setCancelled(true); - p.sendMessage(Main.Prefix+"§cDu darfst keine Werbung machen"); - String LogID = Chat.createChatlog(p.getUniqueId().toString(), "KONSOLE"); - BanManager.createReport(p.getUniqueId().toString(),"KONSOLE", "WERBUNG", LogID); - BanManager.sendNotify("REPORT", p.getName(), "KONSOLE", "WERBUNG"); - return; - } - } - } - } - } - } else { - insertMessage(p.getUniqueId().toString(), e.getMessage(), p.getServer().getInfo().getName()); - } - - } catch (IOException e2) { - e2.printStackTrace(); - } - } - } - } - - public static void insertMessage(String UUID, String Message, String Server){ - Main.mysql.update("INSERT INTO chat(UUID, SERVER, MESSAGE, SENDDATE) " + - "VALUES ('" + UUID + "', '" + Server + "', '" + Message + "', '" + System.currentTimeMillis() + "')"); - } - - public static String createChatlog(String UUID, String CreatedUUID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM chat WHERE UUID='" + UUID + "'"); - String ID = randomString(20); - Long now = System.currentTimeMillis(); - while (rs.next()){ - int TEN_MINUTES = 10 * 60 * 1000; - long tenAgo = System.currentTimeMillis() - TEN_MINUTES; - if (Long.valueOf(rs.getString("SENDDATE")) > tenAgo) { - Main.mysql.update("INSERT INTO chatlog(LOGID, UUID, CREATOR_UUID, SERVER, MESSAGE, SENDDATE, CREATED_AT) " + - "VALUES ('" + ID + "' ,'" + UUID + "', '" + CreatedUUID + "', '" + rs.getString("SERVER") + "', '" + rs.getString("MESSAGE") + "', '" + rs.getString("SENDDATE") + "', '" + now + "')"); - } - } - return ID; - } catch (SQLException exc){ - - } - return null; - } - - public static boolean hasMessages(String UUID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM chat WHERE UUID='" + UUID + "'"); - int i = 0; - while (rs.next()){ - i++; - } - if(i != 0){ - return true; - } else { - return false; - } - } catch (SQLException exc){ - - } - return false; - } - - static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - static SecureRandom rnd = new SecureRandom(); - - public static String randomString(int len){ - StringBuilder sb = new StringBuilder( len ); - for( int i = 0; i < len; i++ ) - sb.append( AB.charAt( rnd.nextInt(AB.length()) ) ); - return sb.toString(); - } - -} diff --git a/src/de/tutorialwork/listener/Login.java b/src/de/tutorialwork/listener/Login.java deleted file mode 100644 index 0133aa8..0000000 --- a/src/de/tutorialwork/listener/Login.java +++ /dev/null @@ -1,135 +0,0 @@ -package de.tutorialwork.listener; - -import de.tutorialwork.commands.SupportChat; -import de.tutorialwork.main.Main; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.IPManager; -import de.tutorialwork.utils.UUIDFetcher; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.PostLoginEvent; -import net.md_5.bungee.api.event.PreLoginEvent; -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; -import net.md_5.bungee.event.EventHandler; - -import java.io.File; -import java.io.IOException; - -public class Login implements Listener { - - @EventHandler - public void onJoin(PreLoginEvent e){ - String UUID = UUIDFetcher.getUUID(e.getConnection().getName()); - String IP = e.getConnection().getAddress().getHostString(); - BanManager.createPlayer(UUID, e.getConnection().getName()); - IPManager.insertIP(IP, UUID); - File config = new File(Main.main.getDataFolder(), "config.yml"); - try{ - Configuration cfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - if(cfg.getBoolean("VPN.BLOCKED")){ - if(!Main.ipwhitelist.contains(IP)){ - if(IPManager.isVPN(IP)){ - if(cfg.getBoolean("VPN.KICK")){ - e.setCancelled(true); - e.setCancelReason(ChatColor.translateAlternateColorCodes('&', cfg.getString("VPN.KICKMSG"))); - } - if(cfg.getBoolean("VPN.BAN")){ - int id = cfg.getInt("VPN.BANID"); - BanManager.ban(UUID, id, "KONSOLE", Main.increaseValue, Main.increaseBans); - BanManager.sendNotify("IPBAN", e.getConnection().getAddress().getHostString(), "KONSOLE", BanManager.getReasonByID(id)); - e.setCancelled(true); - if(BanManager.getRAWEnd(UUID) == -1L){ - e.setCancelReason(ChatColor.translateAlternateColorCodes('&', cfg.getString("LAYOUT.IPBAN").replace("%grund%", BanManager.getReasonByID(id)))); - } else { - String MSG = cfg.getString("LAYOUT.TEMPIPBAN"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(UUID)); - MSG = MSG.replace("%dauer%", BanManager.getEnd(UUID)); - e.setCancelReason(ChatColor.translateAlternateColorCodes('&', MSG)); - } - } - } - } - } - } catch (IOException er){ - er.printStackTrace(); - } - if(IPManager.isBanned(IP)){ - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - - if(IPManager.getRAWEnd(IP) == -1L){ - e.setCancelled(true); - e.setCancelReason(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.IPBAN").replace("%grund%", IPManager.getReasonString(IP)))); - } else { - if(System.currentTimeMillis() < IPManager.getRAWEnd(IP)){ - e.setCancelled(true); - String MSG = configcfg.getString("LAYOUT.TEMPIPBAN"); - MSG = MSG.replace("%grund%", IPManager.getReasonString(IP)); - MSG = MSG.replace("%dauer%", IPManager.getEnd(IP)); - e.setCancelReason(ChatColor.translateAlternateColorCodes('&', MSG)); - } else { - IPManager.unban(IP); - } - } - - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e2) { - e2.printStackTrace(); - } - } - if(BanManager.isBanned(UUID)){ - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - - if(BanManager.getRAWEnd(UUID) == -1L){ - e.setCancelled(true); - e.setCancelReason(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.BAN").replace("%grund%", BanManager.getReasonString(UUID)))); - } else { - if(System.currentTimeMillis() < BanManager.getRAWEnd(UUID)){ - e.setCancelled(true); - String MSG = configcfg.getString("LAYOUT.TEMPBAN"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(UUID)); - MSG = MSG.replace("%dauer%", BanManager.getEnd(UUID)); - e.setCancelReason(ChatColor.translateAlternateColorCodes('&', MSG)); - } else { - BanManager.unban(UUID); - } - } - - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e2) { - e2.printStackTrace(); - } - } - } - - @EventHandler - public void onFinalLogin(PostLoginEvent e){ - ProxiedPlayer p = e.getPlayer(); - if(p.hasPermission("professionalbans.reports") || p.hasPermission("professionalbans.*")){ - if(BanManager.countOpenReports() != 0){ - p.sendMessage(Main.Prefix+"Derzeit sind noch §e§l"+BanManager.countOpenReports()+" Reports §7offen"); - } - } - if(p.hasPermission("professionalbans.supportchat") || p.hasPermission("professionalbans.*")){ - if(SupportChat.openchats.size() != 0){ - p.sendMessage(Main.Prefix+"Derzeit sind noch §e§l"+SupportChat.openchats.size()+" §7Support Chat Anfragen §aoffen"); - } - } - //Update Check - if(p.hasPermission("professionalbans.*")){ - if(!Main.callURL("https://api.spigotmc.org/legacy/update.php?resource=63657").equals(Main.Version)){ - p.sendMessage("§8[]===================================[]"); - p.sendMessage("§e§lProfessionalBans §7Reloaded §8| §7Version §c"+Main.Version); - p.sendMessage("§cDu benutzt eine §c§lVERALTETE §cVersion des Plugins!"); - p.sendMessage("§7Update: §4§lhttps://spigotmc.org/resources/63657"); - p.sendMessage("§8[]===================================[]"); - } - } - } - -} diff --git a/src/de/tutorialwork/listener/Quit.java b/src/de/tutorialwork/listener/Quit.java deleted file mode 100644 index ffaa01b..0000000 --- a/src/de/tutorialwork/listener/Quit.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.tutorialwork.listener; - -import de.tutorialwork.commands.SupportChat; -import de.tutorialwork.main.Main; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.PlayerDisconnectEvent; -import net.md_5.bungee.api.plugin.Listener; -import net.md_5.bungee.event.EventHandler; - -public class Quit implements Listener { - - @EventHandler - public static void onQuit(PlayerDisconnectEvent e){ - ProxiedPlayer p = e.getPlayer(); - if(SupportChat.activechats.containsKey(p) || SupportChat.activechats.containsValue(p)){ - for(ProxiedPlayer key : SupportChat.activechats.keySet()){ - //Key has started the support chat - if(key == p){ - SupportChat.activechats.get(p).sendMessage(Main.Prefix+"§e§l"+p.getName()+" §7hat den Support hat §cbeeendet"); - SupportChat.activechats.remove(p); - } else { - key.sendMessage(Main.Prefix+"§e§l"+p.getName()+" §7hat den Support Chat §cbeeendet"); - SupportChat.activechats.remove(key); - } - } - } - } - -} diff --git a/src/de/tutorialwork/main/Main.java b/src/de/tutorialwork/main/Main.java deleted file mode 100644 index 1cf56af..0000000 --- a/src/de/tutorialwork/main/Main.java +++ /dev/null @@ -1,483 +0,0 @@ -package de.tutorialwork.main; - -import de.tutorialwork.commands.Blacklist; -import de.tutorialwork.commands.*; -import de.tutorialwork.listener.Chat; -import de.tutorialwork.listener.Login; -import de.tutorialwork.listener.Quit; -import de.tutorialwork.utils.BanManager; -import de.tutorialwork.utils.Metrics; -import de.tutorialwork.utils.MySQLConnect; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Plugin; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.concurrent.TimeUnit; - -public class Main extends Plugin { - - public static Main main; - public static MySQLConnect mysql; - public static String Prefix = "§e§lBANS §8• §7"; - public static String NoPerms = Prefix + "§cDu hast keine Berechtigung diesen Befehl zu nutzen"; - - public static ArrayList reportreasons = new ArrayList<>(); - public static ArrayList blacklist = new ArrayList<>(); - public static ArrayList adblacklist = new ArrayList<>(); - public static ArrayList adwhitelist = new ArrayList<>(); - public static ArrayList ipwhitelist = new ArrayList<>(); - - public static boolean increaseBans = true; - public static Integer increaseValue = 50; - - public static String APIKey = null; - - //============================================== - //Plugin Informationen - public static String Version = "2.4"; - //============================================== - - @Override - public void onEnable() { - main = this; - Config(); - MySQL(); - Commands(); - Listener(); - //============================================== - //Konsolen Nachricht über das Plugin - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - BungeeCord.getInstance().getConsole().sendMessage("§e§lProfessionalBans §7§oReloaded §8| §7Version: §c"+Version); - BungeeCord.getInstance().getConsole().sendMessage("§7Developer: §e§lTutorialwork"); - BungeeCord.getInstance().getConsole().sendMessage("§5YT §7Kanal: §cyoutube.com/Tutorialwork"); - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - //============================================== - //============================================== - //Überprüft auf Bans aus dem Webinterface - getProxy().getScheduler().schedule(this, new Runnable() { - @Override - public void run() { - File config = new File(Main.main.getDataFolder(), "config.yml"); - try { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - for(ProxiedPlayer all : getProxy().getPlayers()){ - if(BanManager.isBanned(all.getUniqueId().toString())){ - if(BanManager.getRAWEnd(all.getUniqueId().toString()) == -1L){ - all.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.BAN").replace("%grund%", BanManager.getReasonString(all.getUniqueId().toString())))); - } else { - String MSG = configcfg.getString("LAYOUT.TEMPBAN"); - MSG = MSG.replace("%grund%", BanManager.getReasonString(all.getUniqueId().toString())); - MSG = MSG.replace("%dauer%", BanManager.getEnd(all.getUniqueId().toString())); - all.disconnect(ChatColor.translateAlternateColorCodes('&', MSG)); - } - } - } - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } catch (IOException e) { - e.printStackTrace(); - } - } - }, 5, 5, TimeUnit.SECONDS); - //============================================== - //============================================== - //Updater - if(!callURL("https://api.spigotmc.org/legacy/update.php?resource=63657").equals(Version)){ - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - BungeeCord.getInstance().getConsole().sendMessage("§e§lProfessionalBans §7Reloaded §8| §7Version §c"+Version); - BungeeCord.getInstance().getConsole().sendMessage("§cDu benutzt eine §c§lVERALTETE §cVersion des Plugins!"); - BungeeCord.getInstance().getConsole().sendMessage("§7Update: §4§lhttps://spigotmc.org/resources/63657"); - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - } - //============================================== - Metrics metrics = new Metrics(this); - } - - private void Config() { - if(!getDataFolder().exists()){ - getDataFolder().mkdir(); - } - File file = new File(getDataFolder().getPath(), "mysql.yml"); - File config = new File(getDataFolder().getPath(), "config.yml"); - File blacklistfile = new File(getDataFolder().getPath(), "blacklist.yml"); - try { - if(!file.exists()){ - file.createNewFile(); - Configuration mysql = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); - mysql.set("HOST", "localhost"); - mysql.set("DATENBANK", "Bans"); - mysql.set("USER", "root"); - mysql.set("PASSWORT", "deinpasswort"); - ConfigurationProvider.getProvider(YamlConfiguration.class).save(mysql, file); - } - if(!config.exists()){ - config.createNewFile(); - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - configcfg.set("PREFIX", "&e&lBANS &8• &7"); - configcfg.set("LAYOUT.BAN", "&8[]===================================[] \n\n &4&lDu wurdest GEBANNT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]"); - configcfg.set("LAYOUT.KICK", "&8[]===================================[] \n\n &e&lDu wurdest GEKICKT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]"); - configcfg.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[]===================================[]"); - configcfg.set("LAYOUT.MUTE", "&8[]===================================[] \n\n &4&lDu wurdest GEMUTET \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]"); - configcfg.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[]===================================[]"); - configcfg.set("LAYOUT.IPBAN", "&8[]===================================[] \n\n &4&lDeine IP-Adresse wurde GEBANNT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]"); - configcfg.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[]===================================[]"); - configcfg.set("VPN.BLOCKED", true); - configcfg.set("VPN.KICK", true); - configcfg.set("VPN.KICKMSG", "&7Das benutzen einer &4VPN &7ist auf unserem Netzwerk &cUNTERSAGT"); - configcfg.set("VPN.BAN", false); - configcfg.set("VPN.BANID", 0); - ipwhitelist.add("8.8.8.8"); - configcfg.set("VPN.WHITELIST", ipwhitelist); - configcfg.set("VPN.APIKEY", "Go to https://proxycheck.io/dashboard and register with your email and enter here your API Key"); - configcfg.set("REPORTS.ENABLED", true); - reportreasons.add("Hacking"); - reportreasons.add("Verhalten"); - reportreasons.add("Teaming"); - reportreasons.add("TPA-Falle"); - reportreasons.add("Werbung"); - configcfg.set("REPORTS.REASONS", reportreasons); - configcfg.set("REPORTS.OFFLINEREPORTS", false); - configcfg.set("CHATLOG.ENABLED", true); - configcfg.set("CHATLOG.URL", "DeinServer.net/BanWebinterface/public/chatlog.php?id="); - configcfg.set("AUTOMUTE.ENABLED", false); - configcfg.set("AUTOMUTE.AUTOREPORT", true); - //configcfg.set("AUTOMUTE.AUTOREPORT.REASON", "Automatischer Report"); - configcfg.set("AUTOMUTE.MUTEID", 0); - configcfg.set("AUTOMUTE.ADMUTEID", 0); - configcfg.set("BANTIME-INCREASE.ENABLED", true); - configcfg.set("BANTIME-INCREASE.PERCENTRATE", 50); - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } else { - Configuration configcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config); - if(configcfg.getBoolean("VPN.KICK") && configcfg.getBoolean("VPN.BAN")){ - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - BungeeCord.getInstance().getConsole().sendMessage("§c§lSINNLOSE EINSTELLUNG ENTDECKT"); - BungeeCord.getInstance().getConsole().sendMessage("§7Wenn ein Spieler mit einer VPN das Netzwerk betritt kann er nicht gekickt UND gebannt werden."); - BungeeCord.getInstance().getConsole().sendMessage("§4§lÜberprüfe die VPN Einstellung in der CONFIG.YML"); - BungeeCord.getInstance().getConsole().sendMessage("§8[]===================================[]"); - //Setze VPN Einstellung zurück! - configcfg.set("VPN.BLOCKED", true); - configcfg.set("VPN.KICK", true); - configcfg.set("VPN.KICKMSG", "&7Das benutzen einer &4VPN &7ist auf unserem Netzwerk &cUNTERSAGT"); - configcfg.set("VPN.BAN", false); - configcfg.set("VPN.BANID", 0); - } - for(String reasons : configcfg.getStringList("REPORTS.REASONS")){ - reportreasons.add(reasons.toUpperCase()); - } - for(String ips : configcfg.getStringList("VPN.WHITELIST")){ - ipwhitelist.add(ips); - } - Prefix = configcfg.getString("PREFIX").replace("&", "§"); - increaseBans = configcfg.getBoolean("BANTIME-INCREASE.ENABLED"); - increaseValue = configcfg.getInt("BANTIME-INCREASE.PERCENTRATE"); - if(configcfg.getString("VPN.APIKEY").length() == 27){ - APIKey = configcfg.getString("VPN.APIKEY"); - } - ConfigurationProvider.getProvider(YamlConfiguration.class).save(configcfg, config); - } - if(!blacklistfile.exists()){ - blacklistfile.createNewFile(); - Configuration blacklistcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(blacklistfile); - adwhitelist.add("DeinServer.net"); - adwhitelist.add("forum.DeinServer.net"); - adwhitelist.add("ts.DeinServer.net"); - blacklistcfg.set("ADWHITELIST", adwhitelist); - adblacklist.add(".com"); - adblacklist.add(".org"); - adblacklist.add(".net"); - adblacklist.add(".us"); - adblacklist.add(".co"); - adblacklist.add(".de"); - adblacklist.add(".biz"); - adblacklist.add(".info"); - adblacklist.add(".name"); - adblacklist.add(".yt"); - adblacklist.add(".tv"); - adblacklist.add(".xyz"); - adblacklist.add(".fr"); - adblacklist.add(".ch"); - adblacklist.add(".au"); - adblacklist.add(".at"); - adblacklist.add(".in"); - adblacklist.add(".jp"); - adblacklist.add(".nl"); - adblacklist.add(".uk"); - adblacklist.add(".no"); - adblacklist.add(".ru"); - adblacklist.add(".br"); - adblacklist.add(".tk"); - adblacklist.add(".ml"); - adblacklist.add(".ga"); - adblacklist.add(".cf"); - adblacklist.add(".gq"); - adblacklist.add(".ip"); - adblacklist.add(".dee"); - adblacklist.add(".d e"); - adblacklist.add("[punkt]"); - adblacklist.add("(punkt)"); - adblacklist.add("join now"); - adblacklist.add("join"); - adblacklist.add("mein server"); - adblacklist.add("mein netzwerk"); - adblacklist.add("www"); - adblacklist.add("[.]"); - adblacklist.add("(,)"); - adblacklist.add("(.)"); - blacklistcfg.set("ADBLACKLIST", adblacklist); - blacklist.add("anal"); - blacklist.add("anus"); - blacklist.add("b1tch"); - blacklist.add("bang"); - blacklist.add("banger"); - blacklist.add("bastard"); - blacklist.add("biatch"); - blacklist.add("bitch"); - blacklist.add("bitches"); - blacklist.add("blow job"); - blacklist.add("blow"); - blacklist.add("blowjob"); - blacklist.add("boob"); - blacklist.add("boobs"); - blacklist.add("bullshit"); - blacklist.add("bull shit"); - blacklist.add("c0ck"); - blacklist.add("cock"); - blacklist.add("d1ck"); - blacklist.add("d1ld0"); - blacklist.add("d1ldo"); - blacklist.add("dick"); - blacklist.add("doggie-style"); - blacklist.add("doggy-style"); - blacklist.add("f.u.c.k"); - blacklist.add("fack"); - blacklist.add("faggit"); - blacklist.add("faggot"); - blacklist.add("fagot"); - blacklist.add("fuck"); - blacklist.add("f-u-c-k"); - blacklist.add("ficken"); - blacklist.add("fick"); - blacklist.add("fuckoff"); - blacklist.add("fucks"); - blacklist.add("fuk"); - blacklist.add("fvck"); - blacklist.add("fxck"); - blacklist.add("gai"); - blacklist.add("gay"); - blacklist.add("schwul"); - blacklist.add("schwuchtel"); - blacklist.add("h0m0"); - blacklist.add("h0mo"); - blacklist.add("hitler"); - blacklist.add("homo"); - blacklist.add("lesbe"); - blacklist.add("nigga"); - blacklist.add("niggah"); - blacklist.add("nigger"); - blacklist.add("nippel"); - blacklist.add("pedo"); - blacklist.add("pedo"); - blacklist.add("penis"); - blacklist.add("porn"); - blacklist.add("porno"); - blacklist.add("pornografie"); - blacklist.add("sex"); - blacklist.add("sh1t"); - blacklist.add("s-h-1-t"); - blacklist.add("shit"); - blacklist.add("s-h-i-t"); - blacklist.add("scheiße"); - blacklist.add("scheisse"); - blacklist.add("xxx"); - blacklist.add("Fotze"); - blacklist.add("Hackfresse"); - blacklist.add("Hurensohn"); - blacklist.add("Huso"); - blacklist.add("Hure"); - blacklist.add("hirnamputiert"); - blacklist.add("Honk"); - blacklist.add("kek"); - blacklist.add("Loser"); - blacklist.add("Mongo"); - blacklist.add("Pimmel"); - blacklist.add("Pimmelfresse"); - blacklist.add("Schlampe"); - blacklist.add("Spastard"); - blacklist.add("abspritzer"); - blacklist.add("afterlecker"); - blacklist.add("arschficker"); - blacklist.add("arschgeburt"); - blacklist.add("arschgeige"); - blacklist.add("arschgesicht"); - blacklist.add("arschlecker"); - blacklist.add("arschloch"); - blacklist.add("arschlöcher"); - blacklist.add("assi"); - blacklist.add("beklopter"); - blacklist.add("bummsen"); - blacklist.add("bumsen"); - blacklist.add("drecksack"); - blacklist.add("drecksau"); - blacklist.add("drecksfotze"); - blacklist.add("drecksnigger"); - blacklist.add("drecksnutte"); - blacklist.add("dreckspack"); - blacklist.add("dreckvotze"); - blacklist.add("fagette"); - blacklist.add("fagitt"); - blacklist.add("ficker"); - blacklist.add("fickfehler"); - blacklist.add("fickfresse"); - blacklist.add("fickgesicht"); - blacklist.add("ficknudel"); - blacklist.add("ficksau"); - blacklist.add("hackfresse"); - blacklist.add("lusche"); - blacklist.add("heil"); - blacklist.add("missgeburt"); - blacklist.add("mißgeburt"); - blacklist.add("miststück"); - blacklist.add("nazi"); - blacklist.add("nazis"); - blacklist.add("penner"); - blacklist.add("scheisser"); - blacklist.add("sieg heil"); - blacklist.add("vollidiot"); - blacklist.add("volldepp"); - blacklist.add("wanker"); - blacklist.add("wichser"); - blacklist.add("wichsvorlage"); - blacklist.add("wixa"); - blacklist.add("wixen"); - blacklist.add("wixer"); - blacklist.add("wixxer"); - blacklist.add("wixxxer"); - blacklist.add("wixxxxer"); - blacklistcfg.set("BLACKLIST", blacklist); - ConfigurationProvider.getProvider(YamlConfiguration.class).save(blacklistcfg, blacklistfile); - } else { - Configuration blacklistcfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(blacklistfile); - for(String congigstr : blacklistcfg.getStringList("BLACKLIST")){ - blacklist.add(congigstr); - } - for(String congigstr : blacklistcfg.getStringList("ADBLACKLIST")){ - adblacklist.add(congigstr); - } - for(String congigstr : blacklistcfg.getStringList("ADWHITELIST")){ - adwhitelist.add(congigstr.toUpperCase()); - } - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - private void MySQL() { - try { - File file = new File(getDataFolder().getPath(), "mysql.yml"); - Configuration mysql = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); - MySQLConnect.HOST = mysql.getString("HOST"); - MySQLConnect.DATABASE = mysql.getString("DATENBANK"); - MySQLConnect.USER = mysql.getString("USER"); - MySQLConnect.PASSWORD = mysql.getString("PASSWORT"); - } catch (IOException e){ - e.printStackTrace(); - } - mysql = new 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 void Commands() { - try{ - File file = new File(getDataFolder().getPath(), "config.yml"); - Configuration cfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); - getProxy().getPluginManager().registerCommand(this, new Ban("ban")); - getProxy().getPluginManager().registerCommand(this, new Unban("unban")); - getProxy().getPluginManager().registerCommand(this, new Kick("kick")); - getProxy().getPluginManager().registerCommand(this, new WebAccount("webaccount")); - getProxy().getPluginManager().registerCommand(this, new Check("check")); - getProxy().getPluginManager().registerCommand(this, new ProfessionalBans("professionalbans")); - getProxy().getPluginManager().registerCommand(this, new IPBan("ipban")); - if(cfg.getBoolean("REPORTS.ENABLED")){ - getProxy().getPluginManager().registerCommand(this, new Report("report")); - getProxy().getPluginManager().registerCommand(this, new Reports("reports")); - } - if(cfg.getBoolean("CHATLOG.ENABLED")){ - getProxy().getPluginManager().registerCommand(this, new Chatlog("chatlog")); - } - getProxy().getPluginManager().registerCommand(this, new Blacklist("blacklist")); - getProxy().getPluginManager().registerCommand(this, new WebVerify("webverify")); - getProxy().getPluginManager().registerCommand(this, new SupportChat("support")); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private void Listener() { - getProxy().getPluginManager().registerListener(this, new Login()); - getProxy().getPluginManager().registerListener(this, new Chat()); - getProxy().getPluginManager().registerListener(this, new Quit()); - } - - public static Main getInstance(){ - return main; - } - - public static String callURL(String myURL) { - StringBuilder sb = new StringBuilder(); - URLConnection urlConn = null; - InputStreamReader in = null; - try { - URL url = new URL(myURL); - urlConn = url.openConnection(); - if (urlConn != null) - urlConn.setReadTimeout(60 * 1000); - if (urlConn != null && urlConn.getInputStream() != null) { - in = new InputStreamReader(urlConn.getInputStream(), - Charset.defaultCharset()); - BufferedReader bufferedReader = new BufferedReader(in); - if (bufferedReader != null) { - int cp; - while ((cp = bufferedReader.read()) != -1) { - sb.append((char) cp); - } - bufferedReader.close(); - } - } - in.close(); - } catch (Exception e) { - throw new RuntimeException("Exception while calling URL:"+ myURL, e); - } - - return sb.toString(); - } - -} diff --git a/src/de/tutorialwork/utils/BanManager.java b/src/de/tutorialwork/utils/BanManager.java deleted file mode 100644 index 43fef59..0000000 --- a/src/de/tutorialwork/utils/BanManager.java +++ /dev/null @@ -1,654 +0,0 @@ -package de.tutorialwork.utils; - -import de.tutorialwork.main.Main; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.TimeZone; - -public class BanManager { - - //DATENBANK Struktur - //UUID varchar(64) UNIQUE, NAME varchar(64), BANNED int(11), MUTED int(11), REASON varchar(64), END long(255), TEAMUUID varchar(64), BANS int(11), MUTES int(11) - - public static boolean playerExists(String UUID){ - try { - - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getString("UUID") != null; - } - - } catch (SQLException exc){ - - } - - return false; - - } - - public static void createPlayer(String UUID, String Name){ - if(!playerExists(UUID)){ - Main.mysql.update("INSERT INTO bans(UUID, NAME, BANNED, MUTED, REASON, END, TEAMUUID, BANS, MUTES, FIRSTLOGIN, LASTLOGIN) " + - "VALUES ('" + UUID + "', '" + Name + "', '0', '0', 'null', 'null', 'null', '0', '0', '" + System.currentTimeMillis() + "', '" + System.currentTimeMillis() + "')"); - } else { - updateName(UUID, Name); - updateLastLogin(UUID); - } - } - - public static void getBanReasonsList(ProxiedPlayer p){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reasons ORDER BY SORTINDEX ASC"); - while(rs.next()){ - int id = rs.getInt("ID"); - if(BanManager.isBanReason(id)){ - p.sendMessage("§7"+id+" §8| §e"+BanManager.getReasonByID(id)); - } else { - p.sendMessage("§7"+id+" §8| §e"+BanManager.getReasonByID(id)+" §8(§cMUTE§8)"); - } - } - } catch (SQLException exc){ } - } - - public static String getNameByUUID(String UUID){ - if(playerExists(UUID)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getString("NAME"); - } - } catch (SQLException exc){ - - } - } - return null; - } - - public static String getUUIDByName(String Name){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE NAME='" + Name + "'"); - if(rs.next()){ - return rs.getString("UUID"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static void updateName(String UUID, String newName){ - if(playerExists(UUID)){ - Main.mysql.update("UPDATE bans SET NAME='" + newName + "' WHERE UUID='" + UUID + "'"); - } - } - - public static void ban(String UUID, int GrundID, String TeamUUID, int Prozentsatz, boolean increaseBans){ - if(getReasonTime(GrundID) == -1){ - //Perma Ban - Main.mysql.update("UPDATE bans SET BANNED='1', REASON='" + getReasonByID(GrundID) + "', END='-1', TEAMUUID='" + TeamUUID + "' WHERE UUID='" + UUID + "'"); - } else { - //Temp Ban - //Formel: 1.50 * Anzahl an Tagen = Ergebniss (50%) - int bans = getBans(UUID); - int defaultmins = getReasonTime(GrundID); - long current = System.currentTimeMillis(); - long end = current + getReasonTime(GrundID) * 60000L; - long increaseEnd = current + Prozentsatz / 100 + 1 * defaultmins * bans * 60000L; //Formel!!!!! - if(increaseBans){ - if(bans > 0){ - Main.mysql.update("UPDATE bans SET BANNED='1', REASON='" + getReasonByID(GrundID) + "', END='" + end + "', TEAMUUID='" + TeamUUID + "' WHERE UUID='" + UUID + "'"); - } else { - Main.mysql.update("UPDATE bans SET BANNED='1', REASON='" + getReasonByID(GrundID) + "', END='" + increaseEnd + "', TEAMUUID='" + TeamUUID + "' WHERE UUID='" + UUID + "'"); - } - } else { - Main.mysql.update("UPDATE bans SET BANNED='1', REASON='" + getReasonByID(GrundID) + "', END='" + end + "', TEAMUUID='" + TeamUUID + "' WHERE UUID='" + UUID + "'"); - } - } - } - - public static void mute(String UUID, int GrundID, String TeamUUID){ - long current = System.currentTimeMillis(); - long end = current + getReasonTime(GrundID) * 60000L; - if(getReasonTime(GrundID) == -1){ - //Perma Mute - Main.mysql.update("UPDATE bans SET MUTED='1', REASON='" + getReasonByID(GrundID) + "', END='-1', TEAMUUID='" + TeamUUID + "' WHERE UUID='" + UUID + "'"); - } else { - //Temp Mute - Main.mysql.update("UPDATE bans SET MUTED='1', REASON='" + getReasonByID(GrundID) + "', END='" + end + "', TEAMUUID='" + TeamUUID + "' WHERE UUID='" + UUID + "'"); - } - } - - public static Long getRAWEnd(String UUID){ - if(playerExists(UUID)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getLong("END"); - } - } catch (SQLException exc){ - - } - } - return null; - } - - public static String getEnd(String UUID) { - long uhrzeit = System.currentTimeMillis(); - long end = getRAWEnd(UUID); - - long millis = end - uhrzeit; - - long sekunden = 0L; - long minuten = 0L; - long stunden = 0L; - long tage = 0L; - while (millis > 1000L) - { - millis -= 1000L; - sekunden += 1L; - } - while (sekunden > 60L) - { - sekunden -= 60L; - minuten += 1L; - } - while (minuten > 60L) - { - minuten -= 60L; - stunden += 1L; - } - while (stunden > 24L) - { - stunden -= 24L; - tage += 1L; - } - if(tage != 0){ - return "§a" + tage + " §7Tag(e) §a" + stunden + " §7Stunde(n) §a" + minuten + " §7Minute(n)"; - } else if(tage == 0 && stunden != 0){ - return "§a" + stunden + " §7Stunde(n) §a" + minuten + " §7Minute(n) §a" + sekunden + " §7Sekunde(n)"; - } else if(tage == 0 && stunden == 0 && minuten != 0){ - return "§a" + minuten + " §7Minute(n) §a" + sekunden + " §7Sekunde(n)"; - } else if(tage == 0 && stunden == 0 && minuten == 0 && sekunden != 0) { - return "§a" + sekunden + " §7Sekunde(n)"; - } else { - return "§4Fehler in der Berechnung!"; - } - //Alter Code - //return "§a" + tage + " §7Tag(e) §a" + stunden + " §7Stunde(n) §a" + minuten + " §7Minute(n) §a" + sekunden + " §7Sekunde(n)"; - } - - public static boolean isBanned(String UUID){ - if(playerExists(UUID)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - if(rs.getInt("BANNED") == 1){ - return true; - } else { - return false; - } - } - } catch (SQLException exc){ - - } - } - return false; - } - - public static boolean isMuted(String UUID){ - if(playerExists(UUID)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - if(rs.getInt("MUTED") == 1){ - return true; - } else { - return false; - } - } - } catch (SQLException exc){ - - } - } - return false; - } - - public static void unban(String UUID){ - if(playerExists(UUID)){ - Main.mysql.update("UPDATE bans SET BANNED='0' WHERE UUID='" + UUID + "'"); - } - } - - public static void unmute(String UUID){ - if(playerExists(UUID)){ - Main.mysql.update("UPDATE bans SET MUTED='0' WHERE UUID='" + UUID + "'"); - } - } - - public static String getReasonString(String UUID){ - if(playerExists(UUID)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getString("REASON"); - } - } catch (SQLException exc){ - - } - } - return null; - } - - public static void sendNotify(String Type, String BannedName, String TeamName, String Grund){ - if(Type.toUpperCase().equals("BAN")){ - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.notify")){ - all.sendMessage(Main.Prefix+"§e§l"+BannedName+" §7wurde von §c§l"+TeamName+" §cgebannt §7wegen §a"+Grund); - } - } - } - if(Type.toUpperCase().equals("IPBAN")){ - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.notify")){ - all.sendMessage(Main.Prefix+"§7Die IP §e§l"+BannedName+" §7wurde von §c§l"+TeamName+" §cgebannt §7wegen §a"+Grund); - } - } - } - if(Type.toUpperCase().equals("MUTE")){ - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")){ - all.sendMessage(Main.Prefix+"§e§l"+BannedName+" §7wurde von §c§l"+TeamName+" §cgemutet §7wegen §a"+Grund); - } - } - } - if(Type.toUpperCase().equals("KICK")){ - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")){ - all.sendMessage(Main.Prefix+"§e§l"+BannedName+" §7wurde von §c§l"+TeamName+" §cgekickt §7wegen §a"+Grund); - } - } - } - if(Type.toUpperCase().equals("UNBAN")){ - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")){ - all.sendMessage(Main.Prefix+"§c§l"+TeamName+" §7hat §e§l"+BannedName+" §aentbannt"); - } - } - } - if(Type.toUpperCase().equals("UNBANIP")){ - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")){ - all.sendMessage(Main.Prefix+"§c§l"+TeamName+" §7hat die IP-Adresse §e§l"+BannedName+" §aentbannt"); - } - } - } - if(Type.toUpperCase().equals("UNMUTE")){ - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")){ - all.sendMessage(Main.Prefix+"§c§l"+TeamName+" §7hat §e§l"+BannedName+" §aentmutet"); - } - } - } - if(Type.toUpperCase().equals("REPORT")){ - for(ProxiedPlayer all : BungeeCord.getInstance().getPlayers()){ - if(all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")){ - all.sendMessage(Main.Prefix+"§c§l"+TeamName+" §7hat §e§l"+BannedName+" §7wegen §a"+Grund+" §7gemeldet"); - } - } - } - } - - public static Integer getBans(String UUID){ - if(playerExists(UUID)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getInt("BANS"); - } - } catch (SQLException exc){ - - } - } - return null; - } - - public static void setBans(String UUID, int Bans){ - if(playerExists(UUID)){ - Main.mysql.update("UPDATE bans SET BANS='" + Bans + "' WHERE UUID='" + UUID + "'"); - } - } - - public static Integer getMutes(String UUID){ - if(playerExists(UUID)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getInt("MUTES"); - } - } catch (SQLException exc){ - - } - } - return null; - } - - public static void setMutes(String UUID, int Mutes){ - if(playerExists(UUID)){ - Main.mysql.update("UPDATE bans SET MUTES='" + Mutes + "' WHERE UUID='" + UUID + "'"); - } - } - - public static Integer countReasons(){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reasons"); - int i = 0; - while (rs.next()){ - i++; - } - return i; - } catch (SQLException exc){ - - } - return null; - } - - public static String getReasonByID(int Reason){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='" + Reason + "'"); - if(rs.next()){ - return rs.getString("REASON"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static Integer getReasonTime(int ID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='" + ID + "'"); - if(rs.next()){ - return rs.getInt("TIME"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static boolean isBanReason(int ID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='" + ID + "'"); - if(rs.next()){ - if(rs.getInt("TYPE") == 0){ - return true; - } else { - return false; - } - } - } catch (SQLException exc){ - - } - return false; - } - - public static Integer getReasonBans(int ReasonID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='" + ReasonID + "'"); - if(rs.next()){ - return rs.getInt("BANS"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static void setReasonBans(int ReasonID, int Bans){ - Main.mysql.update("UPDATE reasons SET BANS='" + Bans + "' WHERE ID='" + ReasonID + "'"); - } - - public static boolean hasExtraPerms(int ReasonID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='" + ReasonID + "'"); - if(rs.next()){ - if(rs.getString("PERMS").equals("null")){ - return false; - } else { - return true; - } - } - } catch (SQLException exc){ - - } - return false; - } - - public static String getExtraPerms(int ReasonID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='" + ReasonID + "'"); - if(rs.next()){ - return rs.getString("PERMS"); - } - } catch (SQLException exc){ - - } - return null; - } - - - public static boolean webaccountExists(String UUID){ - try { - - ResultSet rs = Main.mysql.query("SELECT * FROM accounts WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getString("UUID") != null; - } - - } catch (SQLException exc){ - - } - - return false; - - } - - public static void createWebAccount(String UUID, String Name, int Rank, String PasswordHash){ - Main.mysql.update("INSERT INTO accounts(UUID, USERNAME, PASSWORD, RANK, GOOGLE_AUTH, AUTHCODE) " + - "VALUES ('" + UUID + "', '" + Name + "', '" + PasswordHash + "', '" + Rank + "', 'null', 'initialpassword')"); - } - - public static void deleteWebAccount(String UUID){ - Main.mysql.update("DELETE FROM accounts WHERE UUID='"+UUID+"'"); - } - - public static boolean isWebaccountAdmin(String UUID){ - if(webaccountExists(UUID)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM accounts WHERE UUID='" + UUID + "'"); - if(rs.next()){ - if(rs.getInt("RANK") == 3){ - return true; - } else { - return false; - } - } - } catch (SQLException exc){ - - } - } else { - return false; - } - return false; - } - - public static boolean hasAuthToken(String UUID){ - if(webaccountExists(UUID)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM accounts WHERE UUID='" + UUID + "'"); - if(rs.next()){ - if(rs.getString("AUTHCODE") == "null"){ - return false; - } else { - return true; - } - } - } catch (SQLException exc){ - - } - } else { - return false; - } - return false; - } - - public static String getAuthCode(String UUID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM accounts WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getString("AUTHCODE"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static void updateAuthStatus(String UUID){ - Main.mysql.update("UPDATE accounts SET AUTHSTATUS = 1 WHERE UUID = '"+UUID+"'"); - } - - public static void createReport(String UUID, String ReporterUUID, String Reason, String LogID){ - Main.mysql.update("INSERT INTO reports(UUID, REPORTER, TEAM, REASON, LOG, STATUS, CREATED_AT) " + - "VALUES ('" + UUID + "', '" + ReporterUUID + "', 'null', '" + Reason + "', '" + LogID + "', '0', '" + System.currentTimeMillis() + "')"); - } - - public static Integer countOpenReports(){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reports WHERE STATUS = 0"); - int i = 0; - while (rs.next()){ - i++; - } - return i; - } catch (SQLException exc){ - - } - return null; - } - - public static ArrayList getIDsFromOpenReports(){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reports WHERE STATUS = 0"); - ArrayList ids = new ArrayList<>(); - while (rs.next()){ - ids.add(rs.getInt("ID")); - } - return ids; - } catch (SQLException exc){ - - } - return null; - } - - public static String getNameByReportID(int ReportID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reports WHERE ID='" + ReportID + "'"); - if(rs.next()){ - return getNameByUUID(rs.getString("UUID")); - } - } catch (SQLException exc){ - - } - return null; - } - - public static String getReasonByReportID(int ReportID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reports WHERE ID='" + ReportID + "'"); - if(rs.next()){ - return rs.getString("REASON"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static void setReportDone(int ID){ - Main.mysql.update("UPDATE reports SET STATUS = 1 WHERE ID = "+ID); - } - - public static void setReportTeamUUID(int ID, String UUID){ - Main.mysql.update("UPDATE reports SET TEAM = '"+UUID+"' WHERE ID = "+ID); - } - - public static boolean isChatlogAvailable(int ID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reports WHERE ID='" + ID + "'"); - if(rs.next()){ - if(rs.getString("LOG") != "null"){ - return true; - } else { - return false; - } - } - } catch (SQLException exc){ - - } - return false; - } - - public static String getChatlogbyReportID(int ReportID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM reports WHERE ID='" + ReportID + "'"); - if(rs.next()){ - return rs.getString("LOG"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static void updateLastLogin(String UUID){ - Main.mysql.update("UPDATE bans SET LASTLOGIN = '" + System.currentTimeMillis() + "' WHERE UUID = '"+UUID+"'"); - } - - public static String getLastLogin(String UUID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getString("LASTLOGIN"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static String getFirstLogin(String UUID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='" + UUID + "'"); - if(rs.next()){ - return rs.getString("FIRSTLOGIN"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static String formatTimestamp(long timestamp){ - Date date = new Date(timestamp); - SimpleDateFormat jdf = new SimpleDateFormat("dd.MM.yyyy HH:mm"); - return jdf.format(date); - } - -} diff --git a/src/de/tutorialwork/utils/IPManager.java b/src/de/tutorialwork/utils/IPManager.java deleted file mode 100644 index 60e5c7c..0000000 --- a/src/de/tutorialwork/utils/IPManager.java +++ /dev/null @@ -1,250 +0,0 @@ -package de.tutorialwork.utils; - -import de.tutorialwork.main.Main; -import java.sql.ResultSet; -import java.sql.SQLException; - -public class IPManager { - - //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)); - - public static boolean IPExists(String IP){ - try { - - ResultSet rs = Main.mysql.query("SELECT * FROM ips WHERE IP='" + IP + "'"); - if(rs.next()){ - return rs.getString("IP") != null; - } - - } catch (SQLException exc){ - - } - - return false; - - } - - public static void insertIP(String IP, String UUID){ - if(!IPExists(IP)){ - Main.mysql.update("INSERT INTO ips(IP, USED_BY, USED_AT, BANNED, REASON, END, TEAMUUID, BANS) " + - "VALUES ('" + IP + "', '" + UUID + "', '" + System.currentTimeMillis() + "', '0', 'null', 'null', 'null', '0')"); - } else { - updateIPInfos(IP, UUID); - } - } - - public static void updateIPInfos(String IP, String newUUID){ - if(IPExists(IP)){ - Main.mysql.update("UPDATE ips SET USED_BY = '"+newUUID+"', USED_AT='" + System.currentTimeMillis() + "' WHERE IP='" + IP + "'"); - } - } - - public static void ban(String IP, int GrundID, String TeamUUID){ - long current = System.currentTimeMillis(); - long end = current + BanManager.getReasonTime(GrundID) * 60000L; - if(BanManager.getReasonTime(GrundID) == -1){ - //Perma Ban - Main.mysql.update("UPDATE ips SET BANNED='1', REASON='" + BanManager.getReasonByID(GrundID) + "', END='-1', TEAMUUID='" + TeamUUID + "' WHERE IP='" + IP + "'"); - } else { - //Temp Ban - Main.mysql.update("UPDATE ips SET BANNED='1', REASON='" + BanManager.getReasonByID(GrundID) + "', END='" + end + "', TEAMUUID='" + TeamUUID + "' WHERE IP='" + IP + "'"); - } - } - - - public static boolean isBanned(String IP){ - if(IPExists(IP)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM ips WHERE IP='" + IP + "'"); - if(rs.next()){ - if(rs.getInt("BANNED") == 1){ - return true; - } else { - return false; - } - } - } catch (SQLException exc){ - - } - } - return false; - } - - public static String getReasonString(String IP){ - if(IPExists(IP)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM ips WHERE IP='" + IP + "'"); - if(rs.next()){ - return rs.getString("REASON"); - } - } catch (SQLException exc){ - - } - } - return null; - } - - public static Long getRAWEnd(String IP){ - if(IPExists(IP)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM ips WHERE IP='" + IP + "'"); - if(rs.next()){ - return rs.getLong("END"); - } - } catch (SQLException exc){ - - } - } - return null; - } - - public static String getEnd(String UUID) { - long uhrzeit = System.currentTimeMillis(); - long end = getRAWEnd(UUID); - - long millis = end - uhrzeit; - - long sekunden = 0L; - long minuten = 0L; - long stunden = 0L; - long tage = 0L; - while (millis > 1000L) - { - millis -= 1000L; - sekunden += 1L; - } - while (sekunden > 60L) - { - sekunden -= 60L; - minuten += 1L; - } - while (minuten > 60L) - { - minuten -= 60L; - stunden += 1L; - } - while (stunden > 24L) - { - stunden -= 24L; - tage += 1L; - } - if(tage != 0){ - return "§a" + tage + " §7Tag(e) §a" + stunden + " §7Stunde(n) §a" + minuten + " §7Minute(n)"; - } else if(tage == 0 && stunden != 0){ - return "§a" + stunden + " §7Stunde(n) §a" + minuten + " §7Minute(n) §a" + sekunden + " §7Sekunde(n)"; - } else if(tage == 0 && stunden == 0 && minuten != 0){ - return "§a" + minuten + " §7Minute(n) §a" + sekunden + " §7Sekunde(n)"; - } else if(tage == 0 && stunden == 0 && minuten == 0 && sekunden != 0) { - return "§a" + sekunden + " §7Sekunde(n)"; - } else { - return "§4Fehler in der Berechnung!"; - } - //Alter Code - //return "§a" + tage + " §7Tag(e) §a" + stunden + " §7Stunde(n) §a" + minuten + " §7Minute(n) §a" + sekunden + " §7Sekunde(n)"; - } - - public static void unban(String IP){ - if(IPExists(IP)){ - Main.mysql.update("UPDATE ips SET BANNED='0' WHERE IP='" + IP + "'"); - } - } - - public static boolean isVPN(String IP){ - if(!IP.equals("127.0.0.1")){ - if(Main.APIKey != null){ - String json = Main.callURL("http://proxycheck.io/v2/"+IP+"?key="+Main.APIKey); - json = json.replace("{\n" + - " \"status\": \"ok\",\n" + - " \""+IP+"\": {\n" + - " \"proxy\": \"", ""); - json = json.replace("\"\n" + - " }\n" + - "}", ""); - if(json.equals("yes")){ - return true; - } else { - return false; - } - } else { - String json = Main.callURL("http://proxycheck.io/v2/"+IP+"?key=318n07-0o7054-y9y82a-75o3hr"); - json = json.replace("{\n" + - " \"status\": \"ok\",\n" + - " \""+IP+"\": {\n" + - " \"proxy\": \"", ""); - json = json.replace("\"\n" + - " }\n" + - "}", ""); - if(json.equals("yes")){ - return true; - } else { - return false; - } - } - } else { - return false; - } - } - - public static String getIPFromPlayer(String UUID){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM ips WHERE USED_BY='" + UUID + "'"); - if(rs.next()){ - return rs.getString("IP"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static String getPlayerFromIP(String IP){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM ips WHERE IP='" + IP + "'"); - if(rs.next()){ - return rs.getString("USED_BY"); - } - } catch (SQLException exc){ - - } - return null; - } - - public static Integer getBans(String IP){ - if(IPExists(IP)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM ips WHERE IP='" + IP + "'"); - if(rs.next()){ - return rs.getInt("BANS"); - } - } catch (SQLException exc){ - - } - } - return null; - } - - public static void setBans(String IP, int Bans){ - if(IPExists(IP)){ - Main.mysql.update("UPDATE ips SET BANS='" + Bans + "' WHERE IP='" + IP + "'"); - } - } - - public static void addBan(String IP){ - setBans(IP, getBans(IP) + 1); - } - - public static long getLastUseLong(String IP){ - if(IPExists(IP)){ - try { - ResultSet rs = Main.mysql.query("SELECT * FROM ips WHERE IP='" + IP + "'"); - if(rs.next()){ - return Long.valueOf(rs.getString("USED_AT")); - } - } catch (SQLException exc){ - - } - } - return 0; - } - -} diff --git a/src/de/tutorialwork/utils/Metrics.java b/src/de/tutorialwork/utils/Metrics.java deleted file mode 100644 index c5dceec..0000000 --- a/src/de/tutorialwork/utils/Metrics.java +++ /dev/null @@ -1,754 +0,0 @@ -package de.tutorialwork.utils; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import net.md_5.bungee.api.plugin.Plugin; -import net.md_5.bungee.config.Configuration; -import net.md_5.bungee.config.ConfigurationProvider; -import net.md_5.bungee.config.YamlConfiguration; - -import javax.net.ssl.HttpsURLConnection; -import java.io.*; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.zip.GZIPOutputStream; - -/** - * bStats collects some data for plugin authors. - *

- * Check out https://bStats.org/ to learn more about bStats! - */ -@SuppressWarnings({"WeakerAccess", "unused"}) -public class Metrics { - - static { - // You can use the property to disable the check in your test environment - if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { - // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D - final String defaultPackage = new String( - new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'n', 'g', 'e', 'e', 'c', 'o', 'r', 'd'}); - final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); - // We want to make sure nobody just copy & pastes the example and use the wrong package names - if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) { - throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); - } - } - } - - // The version of this bStats class - public static final int B_STATS_VERSION = 1; - - // The url to which the data is sent - private static final String URL = "https://bStats.org/submitData/bungeecord"; - - // The plugin - private final Plugin plugin; - - // Is bStats enabled on this server? - private boolean enabled; - - // The uuid of the server - private String serverUUID; - - // Should failed requests be logged? - private boolean logFailedRequests = false; - - // Should the sent data be logged? - private static boolean logSentData; - - // Should the response text be logged? - private static boolean logResponseStatusText; - - // A list with all known metrics class objects including this one - private static final List knownMetricsInstances = new ArrayList<>(); - - // A list with all custom charts - private final List charts = new ArrayList<>(); - - public Metrics(Plugin plugin) { - this.plugin = plugin; - - try { - loadConfig(); - } catch (IOException e) { - // Failed to load configuration - plugin.getLogger().log(Level.WARNING, "Failed to load bStats config!", e); - return; - } - - // We are not allowed to send data about this server :( - if (!enabled) { - return; - } - - Class usedMetricsClass = getFirstBStatsClass(); - if (usedMetricsClass == null) { - // Failed to get first metrics class - return; - } - if (usedMetricsClass == getClass()) { - // We are the first! :) - linkMetrics(this); - startSubmitting(); - } else { - // We aren't the first so we link to the first metrics class - try { - usedMetricsClass.getMethod("linkMetrics", Object.class).invoke(null, this); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Failed to link to first metrics class " + usedMetricsClass.getName() + "!", e); - } - } - } - } - - /** - * Checks if bStats is enabled. - * - * @return Whether bStats is enabled or not. - */ - public boolean isEnabled() { - return enabled; - } - - /** - * Adds a custom chart. - * - * @param chart The chart to add. - */ - public void addCustomChart(CustomChart chart) { - if (chart == null) { - plugin.getLogger().log(Level.WARNING, "Chart cannot be null"); - } - charts.add(chart); - } - - /** - * Links an other metrics class with this class. - * This method is called using Reflection. - * - * @param metrics An object of the metrics class to link. - */ - public static void linkMetrics(Object metrics) { - knownMetricsInstances.add(metrics); - } - - /** - * Gets the plugin specific data. - * This method is called using Reflection. - * - * @return The plugin specific data. - */ - public JsonObject getPluginData() { - JsonObject data = new JsonObject(); - - String pluginName = plugin.getDescription().getName(); - String pluginVersion = plugin.getDescription().getVersion(); - - data.addProperty("pluginName", pluginName); - data.addProperty("pluginVersion", pluginVersion); - - JsonArray customCharts = new JsonArray(); - for (CustomChart customChart : charts) { - // Add the data of the custom charts - JsonObject chart = customChart.getRequestJsonObject(plugin.getLogger(), logFailedRequests); - if (chart == null) { // If the chart is null, we skip it - continue; - } - customCharts.add(chart); - } - data.add("customCharts", customCharts); - - return data; - } - - private void startSubmitting() { - // The data collection is async, as well as sending the data - // Bungeecord does not have a main thread, everything is async - plugin.getProxy().getScheduler().schedule(plugin, this::submitData, 2, 30, TimeUnit.MINUTES); - // Submit the data every 30 minutes, first time after 2 minutes to give other plugins enough time to start - // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! - // WARNING: Just don't do it! - } - - /** - * Gets the server specific data. - * - * @return The server specific data. - */ - private JsonObject getServerData() { - // Minecraft specific data - int playerAmount = plugin.getProxy().getOnlineCount(); - playerAmount = playerAmount > 500 ? 500 : playerAmount; - int onlineMode = plugin.getProxy().getConfig().isOnlineMode() ? 1 : 0; - String bungeecordVersion = plugin.getProxy().getVersion(); - int managedServers = plugin.getProxy().getServers().size(); - - // OS/Java specific data - String javaVersion = System.getProperty("java.version"); - String osName = System.getProperty("os.name"); - String osArch = System.getProperty("os.arch"); - String osVersion = System.getProperty("os.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - JsonObject data = new JsonObject(); - - data.addProperty("serverUUID", serverUUID); - - data.addProperty("playerAmount", playerAmount); - data.addProperty("managedServers", managedServers); - data.addProperty("onlineMode", onlineMode); - data.addProperty("bungeecordVersion", bungeecordVersion); - - data.addProperty("javaVersion", javaVersion); - data.addProperty("osName", osName); - data.addProperty("osArch", osArch); - data.addProperty("osVersion", osVersion); - data.addProperty("coreCount", coreCount); - - return data; - } - - /** - * Collects the data and sends it afterwards. - */ - private void submitData() { - final JsonObject data = getServerData(); - - final JsonArray pluginData = new JsonArray(); - // Search for all other bStats Metrics classes to get their plugin data - for (Object metrics : knownMetricsInstances) { - try { - Object plugin = metrics.getClass().getMethod("getPluginData").invoke(metrics); - if (plugin instanceof JsonObject) { - pluginData.add((JsonObject) plugin); - } - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } - } - - data.add("plugins", pluginData); - - try { - // Send the data - sendData(plugin, data); - } catch (Exception e) { - // Something went wrong! :( - if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats!", e); - } - } - } - - /** - * Loads the bStats configuration. - * - * @throws IOException If something did not work :( - */ - private void loadConfig() throws IOException { - Path configPath = plugin.getDataFolder().toPath().getParent().resolve("bStats"); - configPath.toFile().mkdirs(); - File configFile = new File(configPath.toFile(), "config.yml"); - if (!configFile.exists()) { - writeFile(configFile, - "#bStats collects some data for plugin authors like how many servers are using their plugins.", - "#To honor their work, you should not disable it.", - "#This has nearly no effect on the server performance!", - "#Check out https://bStats.org/ to learn more :)", - "enabled: true", - "serverUuid: \"" + UUID.randomUUID().toString() + "\"", - "logFailedRequests: false", - "logSentData: false", - "logResponseStatusText: false"); - } - - Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); - - // Load configuration - enabled = configuration.getBoolean("enabled", true); - serverUUID = configuration.getString("serverUuid"); - logFailedRequests = configuration.getBoolean("logFailedRequests", false); - logSentData = configuration.getBoolean("logSentData", false); - logResponseStatusText = configuration.getBoolean("logResponseStatusText", false); - } - - /** - * Gets the first bStat Metrics class. - * - * @return The first bStats metrics class. - */ - private Class getFirstBStatsClass() { - Path configPath = plugin.getDataFolder().toPath().getParent().resolve("bStats"); - configPath.toFile().mkdirs(); - File tempFile = new File(configPath.toFile(), "temp.txt"); - - try { - String className = readFile(tempFile); - if (className != null) { - try { - // Let's check if a class with the given name exists. - return Class.forName(className); - } catch (ClassNotFoundException ignored) { } - } - writeFile(tempFile, getClass().getName()); - return getClass(); - } catch (IOException e) { - if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Failed to get first bStats class!", e); - } - return null; - } - } - - /** - * Reads the first line of the file. - * - * @param file The file to read. Cannot be null. - * @return The first line of the file or null if the file does not exist or is empty. - * @throws IOException If something did not work :( - */ - private String readFile(File file) throws IOException { - if (!file.exists()) { - return null; - } - try ( - FileReader fileReader = new FileReader(file); - BufferedReader bufferedReader = new BufferedReader(fileReader); - ) { - return bufferedReader.readLine(); - } - } - - /** - * Writes a String to a file. It also adds a note for the user, - * - * @param file The file to write to. Cannot be null. - * @param lines The lines to write. - * @throws IOException If something did not work :( - */ - private void writeFile(File file, String... lines) throws IOException { - if (!file.exists()) { - file.createNewFile(); - } - try ( - FileWriter fileWriter = new FileWriter(file); - BufferedWriter bufferedWriter = new BufferedWriter(fileWriter) - ) { - for (String line : lines) { - bufferedWriter.write(line); - bufferedWriter.newLine(); - } - } - } - - /** - * Sends the data to the bStats server. - * - * @param plugin Any plugin. It's just used to get a logger instance. - * @param data The data to send. - * @throws Exception If the request failed. - */ - private static void sendData(Plugin plugin, JsonObject data) throws Exception { - if (data == null) { - throw new IllegalArgumentException("Data cannot be null"); - } - if (logSentData) { - plugin.getLogger().info("Sending data to bStats: " + data.toString()); - } - - HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); - - // Compress the data to save bandwidth - byte[] compressedData = compress(data.toString()); - - // Add headers - connection.setRequestMethod("POST"); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request - connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); - connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format - connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); - - // Send data - connection.setDoOutput(true); - DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); - outputStream.write(compressedData); - outputStream.flush(); - outputStream.close(); - - InputStream inputStream = connection.getInputStream(); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); - - StringBuilder builder = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - builder.append(line); - } - bufferedReader.close(); - if (logResponseStatusText) { - plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString()); - } - } - - /** - * Gzips the given String. - * - * @param str The string to gzip. - * @return The gzipped String. - * @throws IOException If the compression failed. - */ - private static byte[] compress(final String str) throws IOException { - if (str == null) { - return null; - } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - GZIPOutputStream gzip = new GZIPOutputStream(outputStream); - gzip.write(str.getBytes(StandardCharsets.UTF_8)); - gzip.close(); - return outputStream.toByteArray(); - } - - - /** - * Represents a custom chart. - */ - public static abstract class CustomChart { - - // The id of the chart - private final String chartId; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - */ - CustomChart(String chartId) { - if (chartId == null || chartId.isEmpty()) { - throw new IllegalArgumentException("ChartId cannot be null or empty!"); - } - this.chartId = chartId; - } - - private JsonObject getRequestJsonObject(Logger logger, boolean logFailedRequests) { - JsonObject chart = new JsonObject(); - chart.addProperty("chartId", chartId); - try { - JsonObject data = getChartData(); - if (data == null) { - // If the data is null we don't send the chart. - return null; - } - chart.add("data", data); - } catch (Throwable t) { - if (logFailedRequests) { - logger.log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t); - } - return null; - } - return chart; - } - - protected abstract JsonObject getChartData() throws Exception; - - } - - /** - * Represents a custom simple pie. - */ - public static class SimplePie extends CustomChart { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimplePie(String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - String value = callable.call(); - if (value == null || value.isEmpty()) { - // Null = skip the chart - return null; - } - data.addProperty("value", value); - return data; - } - } - - /** - * Represents a custom advanced pie. - */ - public static class AdvancedPie extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedPie(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - continue; // Skip this invalid - } - allSkipped = false; - values.addProperty(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - } - - /** - * Represents a custom drilldown pie. - */ - public static class DrilldownPie extends CustomChart { - - private final Callable>> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public DrilldownPie(String chartId, Callable>> callable) { - super(chartId); - this.callable = callable; - } - - @Override - public JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map> map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean reallyAllSkipped = true; - for (Map.Entry> entryValues : map.entrySet()) { - JsonObject value = new JsonObject(); - boolean allSkipped = true; - for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { - value.addProperty(valueEntry.getKey(), valueEntry.getValue()); - allSkipped = false; - } - if (!allSkipped) { - reallyAllSkipped = false; - values.add(entryValues.getKey(), value); - } - } - if (reallyAllSkipped) { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - } - - /** - * Represents a custom single line chart. - */ - public static class SingleLineChart extends CustomChart { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SingleLineChart(String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - int value = callable.call(); - if (value == 0) { - // Null = skip the chart - return null; - } - data.addProperty("value", value); - return data; - } - - } - - /** - * Represents a custom multi line chart. - */ - public static class MultiLineChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public MultiLineChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - continue; // Skip this invalid - } - allSkipped = false; - values.addProperty(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - - } - - /** - * Represents a custom simple bar chart. - */ - public static class SimpleBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimpleBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - for (Map.Entry entry : map.entrySet()) { - JsonArray categoryValues = new JsonArray(); - categoryValues.add(new JsonPrimitive(entry.getValue())); - values.add(entry.getKey(), categoryValues); - } - data.add("values", values); - return data; - } - - } - - /** - * Represents a custom advanced bar chart. - */ - public static class AdvancedBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue().length == 0) { - continue; // Skip this invalid - } - allSkipped = false; - JsonArray categoryValues = new JsonArray(); - for (int categoryValue : entry.getValue()) { - categoryValues.add(new JsonPrimitive(categoryValue)); - } - values.add(entry.getKey(), categoryValues); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - - } - -} \ No newline at end of file diff --git a/src/de/tutorialwork/utils/MySQLConnect.java b/src/de/tutorialwork/utils/MySQLConnect.java deleted file mode 100644 index 93fa340..0000000 --- a/src/de/tutorialwork/utils/MySQLConnect.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.tutorialwork.utils; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -import de.tutorialwork.main.Main; -import net.md_5.bungee.BungeeCord; - -public class MySQLConnect { - - public static String HOST; - public static String DATABASE; - public static String USER; - public static String PASSWORD; - - private Connection con; - - public MySQLConnect(String host, String database, String user, String password) { - this.HOST = host; - this.DATABASE = database; - this.USER = user; - this.PASSWORD = password; - - connect(); - } - - public void connect() { - try { - con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":3306/" + DATABASE + "?autoReconnect=true", USER, PASSWORD); - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§aDie Verbindung mit der MySQL Datenbank wurde erfolgreich hergestellt"); - } catch (SQLException e) { - BungeeCord.getInstance().getConsole().sendMessage(Main.Prefix+"§cDie Verbindung mit der MySQL Datenbank ist fehlgeschlagen: §4" + e.getMessage()); - } - } - - public void close() { - try { - if(con != null) { - con.close(); - } - } catch (SQLException e) { - } - } - - public void update(String qry) { - try { - Statement st = con.createStatement(); - st.executeUpdate(qry); - st.close(); - } catch (SQLException e) { - connect(); - System.err.println(e); - } - } - - public ResultSet query(String qry) { - ResultSet rs = null; - - try { - Statement st = con.createStatement(); - rs = st.executeQuery(qry); - } catch (SQLException e) { - connect(); - System.err.println(e); - } - return rs; - } -} \ No newline at end of file diff --git a/src/de/tutorialwork/utils/RandomString.java b/src/de/tutorialwork/utils/RandomString.java deleted file mode 100644 index c045a80..0000000 --- a/src/de/tutorialwork/utils/RandomString.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.tutorialwork.utils; - -import java.security.SecureRandom; - -public class RandomString { - private static final String ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_"; - private static final SecureRandom RANDOM = new SecureRandom(); - - /** - * Generates random string of given length from Base65 alphabet (numbers, lowercase letters, uppercase letters). - * - * @param count length - * @return random string of given length - */ - public static String generate(int count) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < count; ++i) { - sb.append(ALPHABET.charAt(RANDOM.nextInt(ALPHABET.length()))); - } - return sb.toString(); - } -} \ No newline at end of file diff --git a/src/de/tutorialwork/utils/UUIDFetcher.java b/src/de/tutorialwork/utils/UUIDFetcher.java deleted file mode 100644 index 5440784..0000000 --- a/src/de/tutorialwork/utils/UUIDFetcher.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.tutorialwork.utils; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.HashMap; - -public class UUIDFetcher -{ - private static HashMap uuidCache = new HashMap(); - - public static String getUUID(String username) - { - if (uuidCache.containsKey(username)) { - return (String)uuidCache.get(username); - } - try - { - URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + username); - InputStream stream = url.openStream(); - InputStreamReader inr = new InputStreamReader(stream); - BufferedReader reader = new BufferedReader(inr); - String s = null; - StringBuilder sb = new StringBuilder(); - while ((s = reader.readLine()) != null) { - sb.append(s); - } - String result = sb.toString(); - JsonElement element = new JsonParser().parse(result); - JsonObject obj = element.getAsJsonObject(); - String api = obj.get("id").toString(); - api = api.substring(1); - api = api.substring(0, api.length() - 1); - StringBuffer sbu = new StringBuffer(api); - sbu.insert(8, "-").insert(13, "-").insert(18, "-").insert(23, "-"); - String uuid = sbu.toString(); - uuidCache.put(username, uuid); - return uuid; - } - catch (IOException|IllegalStateException localIOException) {} - return null; - } -} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/Global.kt b/src/main/kotlin/de/tutorialwork/Global.kt new file mode 100644 index 0000000..c7dfe54 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/Global.kt @@ -0,0 +1,7 @@ +package de.tutorialwork + +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.ProxyServer + +val console: CommandSender get() = ProxyServer.getInstance().console + diff --git a/src/main/kotlin/de/tutorialwork/commands/Ban.kt b/src/main/kotlin/de/tutorialwork/commands/Ban.kt new file mode 100644 index 0000000..6d2424f --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/Ban.kt @@ -0,0 +1,179 @@ +package de.tutorialwork.commands + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.LogManager +import de.tutorialwork.utils.UUIDFetcher +import net.md_5.bungee.api.ChatColor +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.ProxyServer +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command +import net.md_5.bungee.config.ConfigurationProvider +import net.md_5.bungee.config.YamlConfiguration +import java.io.File +import java.io.IOException + +class Ban(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (sender.hasPermission("professionalbans.ban")) { + if (args.size == 1) { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + val id = args[1].toIntOrNull() ?: return //add fail message + if (BanManager.playerExists(uuid)) { + if (BanManager.isWebaccountAdmin(uuid)) { + sender.sendMessage(Main.prefix + "§cDiesen Spieler kannst du nicht bannen/muten") + return + } + BanManager.setReasonBans(id, BanManager.getReasonBans(id) ?: 0 + 1) + if (BanManager.isBanReason(id)) { + if (BanManager.hasExtraPerms(id)) { + if (!sender.hasPermission(BanManager.getExtraPerms(id))) { + sender.sendMessage(Main.prefix + "§cDu hast keine Berechtigung diesen Bangrund zu nutzen") + return + } + } + BanManager.ban(uuid, id, sender.uniqueId.toString(), Main.increaseValue, Main.increaseBans) + LogManager.createEntry("", sender.uniqueId.toString(), "BAN", id.toString()) + BanManager.setBans(uuid, BanManager.getBans(uuid) + 1) + BanManager.sendNotify("BAN", BanManager.getNameByUUID(uuid).toString(), sender.name, BanManager.getReasonByID(id)) + val banned = Main.instance.proxy.getPlayer(args[0]) + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + if (BanManager.getRAWEnd(banned.uniqueId) == -1L) { + banned.disconnect(ChatColor.translateAlternateColorCodes('&', + configcfg.getString("LAYOUT.BAN").replace("%grund%", BanManager.getReasonByID(id).toString()))) + } else { + var msg = configcfg.getString("LAYOUT.TEMPBAN") + msg = msg.replace("%grund%", BanManager.getReasonString(uuid)) + msg = msg.replace("%dauer%", BanManager.getEnd(uuid)) + banned.disconnect(ChatColor.translateAlternateColorCodes('&', msg)) + } + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e: IOException) { + e.printStackTrace() + } + + } else { + if (BanManager.hasExtraPerms(id)) { + if (!sender.hasPermission(BanManager.getExtraPerms(id))) { + sender.sendMessage(Main.prefix + "§cDu hast keine Berechtigung diesen Mutegrund zu nutzen") + return + } + } + BanManager.mute(uuid, id, sender.uniqueId.toString()) + LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), "MUTE", id.toString()) + BanManager.setMutes(uuid, BanManager.getMutes(uuid) ?: 0 + 1) + BanManager.sendNotify("MUTE", BanManager.getNameByUUID(uuid).toString(), sender.name, BanManager.getReasonByID(id).toString()) + val banned = ProxyServer.getInstance().getPlayer(args[0]) + if (banned != null) { + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + if (BanManager.getRAWEnd(banned.uniqueId) == -1L) { + banned.sendMessage(ChatColor.translateAlternateColorCodes('&', + configcfg.getString("LAYOUT.MUTE").replace("%grund%", BanManager.getReasonByID(id).toString()))) + } else { + var MSG = configcfg.getString("LAYOUT.TEMPMUTE") + MSG = MSG.replace("%grund%", BanManager.getReasonString(uuid)) + MSG = MSG.replace("%dauer%", BanManager.getEnd(uuid)) + banned.sendMessage(ChatColor.translateAlternateColorCodes('&', MSG)) + } + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e: IOException) { + e.printStackTrace() + } + + } + } + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler hat den Server noch nie betreten") + } + } else { + BanManager.getBanReasonsList(sender) + sender.sendMessage(Main.prefix + "/ban ") + } + } else { + sender.sendMessage(Main.noPerms) + } + } else { + if (args.isEmpty() || args.size == 1) { + for (zaehler in 1 until (BanManager.countReasons() ?: 0) + 1) { + if (BanManager.isBanReason(zaehler)) { + console.sendMessage("§7" + zaehler + " §8| §e" + BanManager.getReasonByID(zaehler)) + } else { + console.sendMessage("§7" + zaehler + " §8| §e" + BanManager.getReasonByID(zaehler) + " §8(§cMUTE§8)") + } + } + console.sendMessage(Main.prefix + "/ban ") + } else { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + val id = Integer.valueOf(args[1]) + if (BanManager.playerExists(uuid)) { + if (BanManager.isWebaccountAdmin(uuid)) { + console.sendMessage(Main.prefix + "§cDiesen Spieler kannst du nicht bannen/muten") + return + } + BanManager.setReasonBans(id, BanManager.getReasonBans(id) ?: 0 + 1) + if (BanManager.isBanReason(id)) { + BanManager.ban(uuid, id, "KONSOLE", Main.increaseValue, Main.increaseBans) + LogManager.createEntry(uuid.toString(), "KONSOLE", "BAN", id.toString()) + BanManager.setBans(uuid, BanManager.getBans(uuid) ?: 0 + 1) + BanManager.sendNotify("BAN", BanManager.getNameByUUID(uuid).toString(), "KONSOLE", BanManager.getReasonByID(id).toString()) + val banned = ProxyServer.getInstance().getPlayer(args[0]) + if (banned != null) { + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + if (BanManager.getRAWEnd(banned.uniqueId) == -1L) { + banned.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.BAN") + .replace("%grund%", BanManager.getReasonByID(id).toString()))) + } else { + var MSG = configcfg.getString("LAYOUT.TEMPBAN") + MSG = MSG.replace("%grund%", BanManager.getReasonString(uuid).toString()) + MSG = MSG.replace("%dauer%", BanManager.getEnd(uuid)) + banned.disconnect(ChatColor.translateAlternateColorCodes('&', MSG)) + } + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e: IOException) { + e.printStackTrace() + } + + } + } else { + BanManager.mute(uuid, id, "KONSOLE") + LogManager.createEntry(uuid.toString(), "KONSOLE", "MUTE", id.toString()) + BanManager.setMutes(uuid, BanManager.getMutes(uuid) ?: 0 + 1) + BanManager.sendNotify("MUTE", BanManager.getNameByUUID(uuid).toString(), "KONSOLE", BanManager.getReasonByID(id).toString()) + val banned = ProxyServer.getInstance().getPlayer(args[0]) + if (banned != null) { + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + if (BanManager.getRAWEnd(banned.uniqueId) == -1L) { + banned.sendMessage(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.MUTE") + .replace("%grund%", BanManager.getReasonByID(id).toString()))) + } else { + var msg = configcfg.getString("LAYOUT.TEMPMUTE") + msg = msg.replace("%grund%", BanManager.getReasonString(uuid).toString()) + msg = msg.replace("%dauer%", BanManager.getEnd(uuid)) + banned.sendMessage(ChatColor.translateAlternateColorCodes('&', msg)) + } + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e: IOException) { + e.printStackTrace() + } + + } + } + } else { + console.sendMessage(Main.prefix + "§cDieser Spieler hat den Server noch nie betreten") + } + } + } + } +} \ 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 new file mode 100644 index 0000000..7a17515 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/Blacklist.kt @@ -0,0 +1,125 @@ +package de.tutorialwork.commands + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import de.tutorialwork.utils.LogManager +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command +import net.md_5.bungee.config.ConfigurationProvider +import net.md_5.bungee.config.YamlConfiguration +import java.io.File +import java.io.IOException +import java.util.* + +class Blacklist(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (sender.hasPermission("professionalbans.blacklist") || sender.hasPermission("professionalbans.*")) { + if (args.isEmpty() || args.size == 1) { + sender.sendMessage(Main.prefix + "Derzeit sind §e§l" + Main.blacklist.size + " Wörter §7auf der Blacklist") + sender.sendMessage(Main.prefix + "/blacklist ") + } else if (args.size == 2) { + val blacklist = File(Main.instance.dataFolder, "blacklist.yml") + try { + val cfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(blacklist) + + val tempblacklist = ArrayList() + + if (args[0].equals("add", ignoreCase = true)) { + val word = args[1] + for (congigstr in cfg.getStringList("BLACKLIST")) { + tempblacklist.add(congigstr) + } + tempblacklist.add(word) + Main.blacklist.add(word) + cfg.set("BLACKLIST", tempblacklist) + sender.sendMessage(Main.prefix + "§e§l" + word + " §7wurde zur Blacklist hinzugefügt") + LogManager.createEntry("", sender.uniqueId.toString(), "ADD_WORD_BLACKLIST", word) + } else if (args[0].equals("del", ignoreCase = true)) { + val Wort = args[1] + if (Main.blacklist.contains(Wort)) { + for (congigstr in cfg.getStringList("BLACKLIST")) { + tempblacklist.add(congigstr) + } + tempblacklist.remove(Wort) + Main.blacklist.remove(Wort) + cfg.set("BLACKLIST", tempblacklist) + sender.sendMessage(Main.prefix + "§e§l" + Wort + " §7wurde von der Blacklist entfernt") + LogManager.createEntry("", sender.uniqueId.toString(), "DEL_WORD_BLACKLIST", Wort) + } else { + sender.sendMessage(Main.prefix + "§cDieses Wort steht nicht auf der Blacklist") + } + } else { + sender.sendMessage(Main.prefix + "Derzeit sind §e§l" + Main.blacklist.size + " Wörter §7auf der Blacklist") + sender.sendMessage(Main.prefix + "/blacklist ") + } + + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(cfg, blacklist) + tempblacklist.clear() + } catch (e: IOException) { + e.printStackTrace() + } + + } else { + sender.sendMessage(Main.prefix + "Derzeit sind §e§l" + Main.blacklist.size + " Wörter §7auf der Blacklist") + sender.sendMessage(Main.prefix + "/blacklist ") + } + } else { + sender.sendMessage(Main.noPerms) + } + } else { + //KONSOLE + if (args.isEmpty() || args.size == 1) { + console.sendMessage(Main.prefix + "Derzeit sind §e§l" + Main.blacklist.size + " Wörter §7auf der Blacklist") + console.sendMessage(Main.prefix + "/blacklist ") + } else if (args.size == 2) { + val blacklist = File(Main.instance.dataFolder, "blacklist.yml") + try { + val cfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(blacklist) + + val tempblacklist = ArrayList() + + if (args[0].equals("add", ignoreCase = true)) { + val Wort = args[1] + for (congigstr in cfg.getStringList("BLACKLIST")) { + tempblacklist.add(congigstr) + } + tempblacklist.add(Wort) + Main.blacklist.add(Wort) + cfg.set("BLACKLIST", tempblacklist) + console.sendMessage(Main.prefix + "§e§l" + Wort + " §7wurde zur Blacklist hinzugefügt") + LogManager.createEntry("", "KONSOLE", "ADD_WORD_BLACKLIST", Wort) + } else if (args[0].equals("del", ignoreCase = true)) { + val Wort = args[1] + if (Main.blacklist.contains(Wort)) { + for (congigstr in cfg.getStringList("BLACKLIST")) { + tempblacklist.add(congigstr) + } + tempblacklist.remove(Wort) + Main.blacklist.remove(Wort) + cfg.set("BLACKLIST", tempblacklist) + console.sendMessage(Main.prefix + "§e§l" + Wort + " §7wurde von der Blacklist entfernt") + LogManager.createEntry("", "KONSOLE", "DEL_WORD_BLACKLIST", Wort) + } else { + console.sendMessage(Main.prefix + "§cDieses Wort steht nicht auf der Blacklist") + } + } else { + console.sendMessage(Main.prefix + "Derzeit sind §e§l" + Main.blacklist.size + " Wörter §7auf der Blacklist") + console.sendMessage(Main.prefix + "/blacklist ") + } + + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(cfg, blacklist) + tempblacklist.clear() + } catch (e: IOException) { + e.printStackTrace() + } + + } else { + console.sendMessage(Main.prefix + "Derzeit sind §e§l" + Main.blacklist.size + " Wörter §7auf der Blacklist") + console.sendMessage(Main.prefix + "/blacklist ") + } + } + } +} \ 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 new file mode 100644 index 0000000..590ee8c --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/Chatlog.kt @@ -0,0 +1,43 @@ +package de.tutorialwork.commands + +import de.tutorialwork.listener.Chat +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.LogManager +import de.tutorialwork.utils.exists +import de.tutorialwork.utils.getUUID +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command +import net.md_5.bungee.config.ConfigurationProvider +import net.md_5.bungee.config.YamlConfiguration +import java.io.File + +class Chatlog(name: String) : Command(name) { + + private val chatLogUrl by lazy { + val config = File(Main.instance.dataFolder, "config.yml") + val cfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + cfg.getString("CHATLOG.URL") + } + + + override fun execute(sender: CommandSender, args: Array) { + if (sender !is ProxiedPlayer) return + if (args.size != 1) { + + val target = args[0].getUUID(sender) ?: return + target.exists(sender) ?: return + + if (sender.uniqueId != target) { + if (Chat.hasMessages(target)) { + val id = Chat.createChatlog(target, sender.uniqueId.toString()) ?: return + sender.sendMessage(Main.prefix + "Der Chatlog von §e§l" + BanManager.getNameByUUID(target) + " §7wurde erfolgreich erstellt") + sender.sendMessage(Main.prefix + "Link: §e§l$chatLogUrl$id") + LogManager.createEntry(target.toString(), sender.uniqueId.toString(), "CREATE_CHATLOG", id) + } else sender.sendMessage(Main.prefix + "§cDieser Spieler hat in der letzten Zeit keine Nachrichten verfasst") + } else sender.sendMessage(Main.prefix + "§cDu kannst kein Chatlog von dir selbst erstellen") + } else sender.sendMessage(Main.prefix + "/chatlog ") + } + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/Check.kt b/src/main/kotlin/de/tutorialwork/commands/Check.kt new file mode 100644 index 0000000..3e978f7 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/Check.kt @@ -0,0 +1,135 @@ +package de.tutorialwork.commands + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.IPManager +import de.tutorialwork.utils.UUIDFetcher +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command + +class Check(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (sender.hasPermission("professionalbans.check") || sender.hasPermission("professionalbans.*")) { + if (args.isEmpty()) { + sender.sendMessage(Main.prefix + "/check ") + } else { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + if (IPBan.validate(args[0])) { + val ip = args[0] + if (IPManager.ipExists(ip)) { + sender.sendMessage("§8[]===================================[]") + if (IPManager.getPlayerFromIP(ip) != null) { + sender.sendMessage("§7Spieler: §e§l" + BanManager.getNameByUUID(IPManager.getPlayerFromIP(ip) + ?: return)) + } else { + sender.sendMessage("§7Spieler: §c§lKeiner") + } + if (IPManager.isBanned(ip)) { + sender.sendMessage("§7IP-Ban: §c§lJa §8/ " + IPManager.getReasonString(IPManager.getIPFromPlayer(uuid))) + } else { + sender.sendMessage("§7IP-Ban: §a§lNein") + } + sender.sendMessage("§7Bans: §e§l" + IPManager.getBans(ip)) + sender.sendMessage("§7Zuletzt genutzt: §e§l" + BanManager.formatTimestamp(IPManager.getLastUseLong(ip))) + sender.sendMessage("§8[]===================================[]") + } else { + sender.sendMessage(Main.prefix + "§cZu dieser IP-Adresse sind keine Informationen verfügbar") + } + } else { + if (BanManager.playerExists(uuid)) { + sender.sendMessage("§8[]===================================[]") + sender.sendMessage("§7Spieler: §e§l" + BanManager.getNameByUUID(uuid)) + if (BanManager.isBanned(uuid)) { + sender.sendMessage("§7Gebannt: §c§lJa §8/ " + BanManager.getReasonString(uuid)) + } else { + sender.sendMessage("§7Gebannt: §a§lNein") + } + if (BanManager.isMuted(uuid)) { + sender.sendMessage("§7Gemutet: §c§lJa §8/ " + BanManager.getReasonString(uuid)) + } else { + sender.sendMessage("§7Gemutet: §a§lNein") + } + if (IPManager.isBanned(IPManager.getIPFromPlayer(uuid).toString())) { + sender.sendMessage("§7IP-Ban: §c§lJa §8/ " + IPManager.getReasonString(IPManager.getIPFromPlayer(uuid).toString())) + } else { + sender.sendMessage("§7IP-Ban: §a§lNein") + } + sender.sendMessage("§7Bans: §e§l" + BanManager.getBans(uuid)) + sender.sendMessage("§7Mutes: §e§l" + BanManager.getMutes(uuid)) + sender.sendMessage("§7Letzter Login: §e§l" + BanManager.formatTimestamp(java.lang.Long.valueOf(BanManager.getLastLogin(uuid)))) + sender.sendMessage("§7Erster Login: §e§l" + BanManager.formatTimestamp(java.lang.Long.valueOf(BanManager.getFirstLogin(uuid)))) + sender.sendMessage("§8[]===================================[]") + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler hat den Server noch nie betreten") + } + } + } + } else { + sender.sendMessage(Main.noPerms) + } + } else { + if (args.isEmpty()) { + console.sendMessage(Main.prefix + "/check ") + } else { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + if (IPBan.validate(args[0])) { + val ip = args[0] + if (IPManager.ipExists(ip)) { + console.sendMessage("§8[]===================================[]") + if (IPManager.getPlayerFromIP(ip) != null) { + console.sendMessage("§7Spieler: §e§l" + BanManager.getNameByUUID(IPManager.getPlayerFromIP(ip) + ?: return)) + } else { + console.sendMessage("§7Spieler: §c§lKeiner") + } + if (IPManager.isBanned(ip)) { + console.sendMessage("§7IP-Ban: §c§lJa §8/ " + IPManager.getReasonString(IPManager.getIPFromPlayer(uuid).toString())) + } else { + console.sendMessage("§7IP-Ban: §a§lNein") + } + console.sendMessage("§7Bans: §e§l" + IPManager.getBans(ip)) + console.sendMessage("§7Zuletzt genutzt: §e§l" + BanManager.formatTimestamp(IPManager.getLastUseLong(ip))) + console.sendMessage("§8[]===================================[]") + } else { + console.sendMessage(Main.prefix + "§cZu dieser IP-Adresse sind keine Informationen verfügbar") + } + } else { + if (BanManager.playerExists(uuid)) { + console.sendMessage("§8[]===================================[]") + console.sendMessage("§7Spieler: §e§l" + BanManager.getNameByUUID(uuid)) + if (BanManager.isBanned(uuid)) { + console.sendMessage("§7Gebannt: §c§lJa §8/ " + BanManager.getReasonString(uuid)) + } else { + console.sendMessage("§7Gebannt: §a§lNein") + } + if (BanManager.isMuted(uuid)) { + console.sendMessage("§7Gemutet: §c§lJa §8/ " + BanManager.getReasonString(uuid)) + } else { + console.sendMessage("§7Gemutet: §a§lNein") + } + if (IPManager.isBanned(IPManager.getIPFromPlayer(uuid).toString())) { + console.sendMessage("§7IP-Ban: §c§lJa §8/ " + IPManager.getReasonString(IPManager.getIPFromPlayer(uuid).toString())) + } else { + console.sendMessage("§7IP-Ban: §a§lNein") + } + console.sendMessage("§7Bans: §e§l" + BanManager.getBans(uuid)) + console.sendMessage("§7Mutes: §e§l" + BanManager.getMutes(uuid)) + if (BanManager.getLastLogin(uuid) != null) { + console.sendMessage("§7Letzter Login: §e§l" + BanManager.formatTimestamp(java.lang.Long.valueOf(BanManager.getLastLogin(uuid)))) + } + if (BanManager.getFirstLogin(uuid) != null) { + console.sendMessage("§7Erster Login: §e§l" + BanManager.formatTimestamp(java.lang.Long.valueOf(BanManager.getFirstLogin(uuid)))) + } + console.sendMessage("§8[]===================================[]") + } else { + console.sendMessage(Main.prefix + "§cDieser Spieler hat den Server noch nie betreten") + } + } + } + } + } +} \ 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 new file mode 100644 index 0000000..6254a76 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/IPBan.kt @@ -0,0 +1,101 @@ +package de.tutorialwork.commands + +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.IPManager +import de.tutorialwork.utils.LogManager +import de.tutorialwork.utils.UUIDFetcher +import net.md_5.bungee.api.ChatColor +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command +import net.md_5.bungee.config.ConfigurationProvider +import net.md_5.bungee.config.YamlConfiguration + +import java.io.File +import java.io.IOException +import java.util.regex.Pattern + +class IPBan(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (sender.hasPermission("professionalbans.ipban") || sender.hasPermission("professionalbans.*")) { + if (args.isEmpty() || args.size == 1) { + for (zaehler in 1 until BanManager.countReasons()!! + 1) { + if (BanManager.isBanReason(zaehler)) { + sender.sendMessage("§7" + zaehler + " §8| §e" + BanManager.getReasonByID(zaehler)) + } + } + sender.sendMessage(Main.prefix + "/ipban ") + } else { + val ip = args[0] + val id = Integer.valueOf(args[1]) + if (validate(ip)) { + if (IPManager.ipExists(ip)) { + IPManager.ban(ip, id, sender.uniqueId.toString()) + IPManager.addBan(ip) + BanManager.sendNotify("IPBAN", ip, sender.name, BanManager.getReasonByID(id).toString()) + } else { + IPManager.insertIP(ip, sender.uniqueId) + IPManager.ban(ip, id, sender.uniqueId.toString()) + IPManager.addBan(ip) + BanManager.sendNotify("IPBAN", ip, sender.name, BanManager.getReasonByID(id).toString()) + } + disconnectIPBannedPlayers(ip) + LogManager.createEntry("", sender.uniqueId.toString(), "IPBAN_IP", ip) + } else { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + val dbip = IPManager.getIPFromPlayer(uuid) + IPManager.ban(dbip, id, sender.uniqueId.toString()) + IPManager.addBan(dbip) + BanManager.sendNotify("IPBAN", dbip, sender.name, BanManager.getReasonByID(id).toString()) + disconnectIPBannedPlayers(dbip) + LogManager.createEntry("", sender.uniqueId.toString(), "IPBAN_PLAYER", id.toString()) + } + } + } else { + sender.sendMessage(Main.noPerms) + } + } + } + + companion object { + + fun disconnectIPBannedPlayers(IP: String) { + for (all in Main.instance.proxy.players) { + if (all.address.hostString == IP) { + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + + if (IPManager.getRAWEnd(IP) == -1L) { + all.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.IPBAN").replace("%grund%", IPManager.getReasonString(IP)!!))) + } else { + if (System.currentTimeMillis() < IPManager.getRAWEnd(IP) ?: 0) { + var MSG = configcfg.getString("LAYOUT.TEMPIPBAN") + MSG = MSG.replace("%grund%", IPManager.getReasonString(IP)!!) + MSG = MSG.replace("%dauer%", IPManager.getEnd(IP)) + all.disconnect(ChatColor.translateAlternateColorCodes('&', MSG)) + } else { + IPManager.unban(IP) + } + } + + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e2: IOException) { + e2.printStackTrace() + } + + } + } + } + + private val PATTERN = Pattern.compile( + "^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$") + + fun validate(ip: String): Boolean { + return 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 new file mode 100644 index 0000000..f7ebba0 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/Kick.kt @@ -0,0 +1,79 @@ +package de.tutorialwork.commands + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.LogManager +import net.md_5.bungee.api.ChatColor +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.ProxyServer +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command +import net.md_5.bungee.config.ConfigurationProvider +import net.md_5.bungee.config.YamlConfiguration + +import java.io.File +import java.io.IOException + +class Kick(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (sender.hasPermission("professionalbans.kick") || sender.hasPermission("professionalbans.*")) { + if (args.isEmpty() || args.size == 1) { + sender.sendMessage(Main.prefix + "/kick ") + } else { + val tokick = ProxyServer.getInstance().getPlayer(args[0]) + if (tokick != null) { + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + var grund = "" + for (i in 1 until args.size) { + grund = grund + " " + args[i] + } + BanManager.sendNotify("KICK", tokick.name, sender.name, grund) + LogManager.createEntry(tokick.uniqueId.toString(), sender.uniqueId.toString(), "KICK", grund) + tokick.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.KICK") + .replace("%grund%", grund))) + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e: IOException) { + e.printStackTrace() + } + + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler ist nicht online") + } + } + } else { + sender.sendMessage(Main.noPerms) + } + } else { + if (args.isEmpty() || args.size == 1) { + console.sendMessage(Main.prefix + "/kick ") + } else { + val tokick = ProxyServer.getInstance().getPlayer(args[0]) + if (tokick != null) { + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + var grund = "" + for (i in 1 until args.size) { + grund = grund + " " + args[i] + } + BanManager.sendNotify("KICK", tokick.name, "KONSOLE", grund) + LogManager.createEntry(tokick.uniqueId.toString(), "KONSOLE", "KICK", grund) + tokick.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.KICK") + .replace("%grund%", grund))) + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e: IOException) { + e.printStackTrace() + } + + } else { + console.sendMessage(Main.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 new file mode 100644 index 0000000..9982c61 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/Report.kt @@ -0,0 +1,76 @@ +package de.tutorialwork.commands + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.LogManager +import de.tutorialwork.utils.UUIDFetcher +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.ProxyServer +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command +import net.md_5.bungee.config.ConfigurationProvider +import net.md_5.bungee.config.YamlConfiguration + +import java.io.File +import java.io.IOException + +class Report(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (args.isEmpty() || args.size == 1) { + var reasons = "" + var komma = Main.reportreasons.size + for (reason in Main.reportreasons) { + komma-- + reasons = if (komma != 0) { + "$reasons$reason, " + } else { + reasons + reason + } + } + sender.sendMessage(Main.prefix + "Verfügbare Reportgründe: §e§l" + reasons) + sender.sendMessage(Main.prefix + "/report ") + } else { + if (args[0].toUpperCase() == sender.name.toUpperCase()) { + sender.sendMessage(Main.prefix + "§cDu kannst dich nicht selbst melden") + return + } + if (Main.reportreasons.contains(args[1].toUpperCase())) { + val target = ProxyServer.getInstance().getPlayer(args[0]) + if (target != null) { + BanManager.createReport(target.uniqueId, sender.uniqueId.toString(), args[1].toUpperCase(), null) + sender.sendMessage(Main.prefix + "Der Spieler §e§l" + target.name + " §7wurde erfolgreich wegen §e§l" + args[1].toUpperCase() + " §7gemeldet") + BanManager.sendNotify("REPORT", target.name, sender.name, args[1].toUpperCase()) + LogManager.createEntry(target.uniqueId.toString(), sender.uniqueId.toString(), "REPORT", args[1].toUpperCase()) + } else { + try { + val file = File(Main.instance.dataFolder, "config.yml") + val cfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(file) + if (cfg.getBoolean("REPORTS.OFFLINEREPORTS")) { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + if (BanManager.playerExists(uuid)) { + BanManager.createReport(uuid, sender.uniqueId.toString(), args[1].toUpperCase(), null) + sender.sendMessage(Main.prefix + "Der Spieler §e§l" + args[0] + " §7(§4Offline§7) wurde erfolgreich wegen §e§l" + args[1].toUpperCase() + " §7gemeldet") + LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), "REPORT_OFFLINE", args[1].toUpperCase()) + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler wurde nicht gefunden") + } + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler ist offline") + } + } catch (e: IOException) { + e.printStackTrace() + } + + } + } else { + sender.sendMessage(Main.prefix + "§cDer eingegebene Reportgrund wurde nicht gefunden") + } + } + } else { + console.sendMessage(Main.prefix + "§e§lReports §7sind nur als Spieler verfügbar") + } + } +} \ 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 new file mode 100644 index 0000000..94f4efe --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/Reports.kt @@ -0,0 +1,67 @@ +package de.tutorialwork.commands + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.LogManager +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.ProxyServer +import net.md_5.bungee.api.chat.ClickEvent +import net.md_5.bungee.api.chat.ComponentBuilder +import net.md_5.bungee.api.chat.HoverEvent +import net.md_5.bungee.api.chat.TextComponent +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command + +class Reports(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (sender.hasPermission("professionalbans.reports") || sender.hasPermission("professionalbans.*")) { + if (args.isEmpty()) { + if (BanManager.countOpenReports() != 0) { + sender.sendMessage("§8[]===================================[]") + sender.sendMessage("§e§loffene Reports §7(§8" + BanManager.countOpenReports() + "§7)") + var offline = 0 + for (element in BanManager.iDsFromOpenReports) { + val target = ProxyServer.getInstance().getPlayer(BanManager.getNameByReportID(element)) + if (target != null) { + val tc = TextComponent() + tc.text = "§e§l" + target.name + " §7gemeldet wegen §c§l " + + BanManager.getReasonByReportID(element) + " §8| §7Online auf §e§l" + target.server.info.name + tc.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reports 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.sendMessage("§4§o$offline Reports §7§ovon Spieler die offline sind ausgeblendet") + } + sender.sendMessage("§8[]===================================[]") + } else { + sender.sendMessage(Main.prefix + "§cEs sind derzeit keine Reports offen") + } + } else if (args[0].equals("jump", ignoreCase = true)) { + val target = ProxyServer.getInstance().getPlayer(args[1]) + if (target != null) { + sender.connect(target.server.info) + val id = Integer.parseInt(args[2]) + BanManager.setReportDone(id) + BanManager.setReportTeamUUID(id, sender.uniqueId.toString()) + sender.sendMessage(Main.prefix + "Du hast den Report von §e§l" + BanManager.getNameByReportID(id) + " §7wegen §c§l" + BanManager.getReasonByReportID(id) + " §aangenommen") + LogManager.createEntry(sender.uniqueId.toString(), null, "REPORT_ACCEPT", id.toString()) + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler ist nicht mehr online") + } + } + } else { + sender.sendMessage(Main.noPerms) + } + } else { + console.sendMessage(Main.prefix + "§e§lReports §7sind nur als Spieler verfügbar") + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/SupportChat.kt b/src/main/kotlin/de/tutorialwork/commands/SupportChat.kt new file mode 100644 index 0000000..8580e13 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/SupportChat.kt @@ -0,0 +1,135 @@ +package de.tutorialwork.commands + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.ProxyServer +import net.md_5.bungee.api.chat.ClickEvent +import net.md_5.bungee.api.chat.ComponentBuilder +import net.md_5.bungee.api.chat.HoverEvent +import net.md_5.bungee.api.chat.TextComponent +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command +import java.util.* + +class SupportChat(name: String) : Command(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]?.sendMessage(Main.prefix + "§e§l" + sender.name + " §7hat den Support Chat §cbeeendet") + activechats.remove(key) + } else { + key.sendMessage(Main.prefix + "§e§l" + sender.name + " §7hat den Support Chat §cbeeendet") + activechats.remove(key) + } + } + sender.sendMessage(Main.prefix + "§cDu hast den Support Chat beendet") + return + } else { + sender.sendMessage(Main.prefix + "§cDu hast derzeit keinen offenen Support Chat") + return + } + } + } + if (sender.hasPermission("professionalbans.supportchat") || sender.hasPermission("professionalbans.*")) { + //Team Member + if (args.isNotEmpty()) { + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.getName() == args[0]) { + if (openchats.containsKey(all)) { + activechats[all] = sender + openchats.remove(all) + all.sendMessage(Main.prefix + "§e§l" + sender.name + " §7ist jetzt mit dir im Support Chat") + all.sendMessage(Main.prefix + "§8§oDu kannst in den Support Chat schreiben in dem du einfach eine normale Nachricht schreibst") + all.sendMessage(Main.prefix + "§8§oDu kannst den Support Chat mit §7§o/support end §8§obeenden") + sender.sendMessage(Main.prefix + "§e§l" + all.getName() + " §7ist jetzt im Support Chat mit dir") + sender.sendMessage(Main.prefix + "§8§oDu kannst den Support Chat mit §7§o/support end §8§obeenden") + } else { + sender.sendMessage(Main.prefix + "§cDiese Anfrage ist ausgelaufen") + } + } + } + } else { + if (openchats.size != 0) { + sender.sendMessage("§8[]===================================[]") + var i = 0 + for (key in SupportChat.openchats.keys) { + sender.sendMessage("§e§l" + key + " §8• §9" + SupportChat.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.sendMessage("§8[]===================================[]") + sender.sendMessage(Main.prefix + "Es sind derzeit §e§l" + i + " Support Chats §7Anfragen §aoffen") + } else { + sender.sendMessage(Main.prefix + "§cDerzeit sind keine Support Chats Anfragen offen") + } + } + } else { + //Normal Member + if (args.isEmpty()) { + sender.sendMessage(Main.prefix + "Wenn du den §e§lSupport Chat §7starten möchtest gebe ein §8§oBetreff §7ein") + sender.sendMessage(Main.prefix + "Möchtest du eine Anfrage abbrechen? §8§o/support cancel") + } else { + var supporter = 0 + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.supportchat") || all.hasPermission("professionalbans.*")) { + supporter++ + } + } + if (!args[0].equals("cancel", ignoreCase = true)) { + var subject = "" + for (i in args.indices) { + subject = subject + " " + args[i] + } + if (!openchats.containsKey(sender)) { + if (supporter > 0) { + openchats[sender] = subject + sender.sendMessage(Main.prefix + "Du hast eine Anfrage mit dem Betreff §e§l" + subject + " §7gestartet") + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.supportchat") || all.hasPermission("professionalbans.*")) { + all.sendMessage(Main.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").create()) + all.sendMessage(tc) + } + } + } else { + sender.sendMessage(Main.prefix + "§cDerzeit ist kein Supporter online") + } + } else { + sender.sendMessage(Main.prefix + "Du hast bereits eine §e§lSupport Chat §7Anfrage gestellt") + sender.sendMessage(Main.prefix + "Möchtest du diese Anfrage §cabbrechen §7benutze §c§l/support cancel") + } + } else { + if (!openchats.containsKey(sender)) { + openchats.remove(sender) + sender.sendMessage(Main.prefix + "Deine Anfrage wurde erfolgreich §cgelöscht") + } else { + sender.sendMessage(Main.prefix + "§cDu hast derzeit keine offene Anfrage") + } + } + } + } + } else { + console.sendMessage(Main.prefix + "Der §e§lSupport Chat §7ist nur als Spieler verfügbar") + } + } + + companion object { + + var openchats = HashMap() + var activechats = HashMap() + } +} \ 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 new file mode 100644 index 0000000..34a3894 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/Unban.kt @@ -0,0 +1,94 @@ +package de.tutorialwork.commands + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.IPManager +import de.tutorialwork.utils.LogManager +import de.tutorialwork.utils.UUIDFetcher +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command + +class Unban(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (sender.hasPermission("professionalbans.unban") || sender.hasPermission("professionalbans.*")) { + if (args.isEmpty()) { + sender.sendMessage(Main.prefix + "/unban ") + } else { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + if (IPBan.validate(args[0])) { + IPManager.unban(args[0]) + BanManager.sendNotify("UNBANIP", args[0], sender.name, null) + sender.sendMessage(Main.prefix + "§7Die IP-Adresse §e§l" + args[0] + " §7wurde §aerfolgreich §7entbannt") + LogManager.createEntry("", sender.uniqueId.toString(), "UNBAN_IP", args[0]) + } else { + if (BanManager.playerExists(uuid)) { + if (IPManager.isBanned(IPManager.getIPFromPlayer(uuid).toString())) { + IPManager.unban(IPManager.getIPFromPlayer(uuid).toString()) + sender.sendMessage(Main.prefix + "Die IP §e§l" + IPManager.getIPFromPlayer(uuid) + " §7war gebannt und wurde ebenfalls §aentbannt") + } + when { + BanManager.isBanned(uuid) -> { + BanManager.unban(uuid) + BanManager.sendNotify("UNBAN", BanManager.getNameByUUID(uuid).toString(), sender.name, "null") + sender.sendMessage(Main.prefix + "§e§l" + BanManager.getNameByUUID(uuid) + " §7wurde §aerfolgreich §7entbannt") + LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), "UNBAN_BAN", null) + } + BanManager.isMuted(uuid) -> { + BanManager.unmute(uuid) + BanManager.sendNotify("UNMUTE", BanManager.getNameByUUID(uuid).toString(), sender.name, "null") + sender.sendMessage(Main.prefix + "§e§l" + BanManager.getNameByUUID(uuid) + " §7wurde §aerfolgreich §7entmutet") + LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), "UNBAN_MUTE", null) + } + else -> sender.sendMessage(Main.prefix + "§e§l" + BanManager.getNameByUUID(uuid) + " §7ist weder gebannt oder gemutet") + } + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler hat den Server noch nie betreten") + } + } + } + } else { + sender.sendMessage(Main.noPerms) + } + } else { + if (args.isEmpty()) { + console.sendMessage(Main.prefix + "/unban ") + } else { + val uuid = UUIDFetcher.getUUID(args[0]) ?: return + if (IPBan.validate(args[0])) { + IPManager.unban(args[0]) + BanManager.sendNotify("UNBANIP", args[0], "KONSOLE", null) + console.sendMessage(Main.prefix + "§7Die IP-Adresse §e§l" + args[0] + " §7wurde §aerfolgreich §7entbannt") + LogManager.createEntry("", "KONSOLE", "UNBAN_IP", args[0]) + } else { + if (BanManager.playerExists(uuid)) { + if (IPManager.isBanned(IPManager.getIPFromPlayer(uuid).toString())) { + IPManager.unban(IPManager.getIPFromPlayer(uuid).toString()) + console.sendMessage(Main.prefix + "Die IP §e§l" + IPManager.getIPFromPlayer(uuid) + " §7war gebannt und wurde ebenfalls §aentbannt") + } + when { + BanManager.isBanned(uuid) -> { + BanManager.unban(uuid) + BanManager.sendNotify("UNBAN", BanManager.getNameByUUID(uuid).toString(), "KONSOLE", "null") + console.sendMessage(Main.prefix + "§e§l" + BanManager.getNameByUUID(uuid) + " §7wurde §aerfolgreich §7entbannt") + LogManager.createEntry(uuid.toString(), "KONSOLE", "UNBAN_BAN", null) + } + BanManager.isMuted(uuid) -> { + BanManager.unmute(uuid) + BanManager.sendNotify("UNMUTE", BanManager.getNameByUUID(uuid).toString(), "KONSOLE", "null") + console.sendMessage(Main.prefix + "§e§l" + BanManager.getNameByUUID(uuid) + " §7wurde §aerfolgreich §7entmutet") + LogManager.createEntry(uuid.toString(), "KONSOLE", "UNBAN_MUTE", null) + } + else -> console.sendMessage(Main.prefix + "§e§l" + BanManager.getNameByUUID(uuid) + " §7ist weder gebannt oder gemutet") + } + } else { + console.sendMessage(Main.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 new file mode 100644 index 0000000..6a0565b --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/WebAccount.kt @@ -0,0 +1,94 @@ +package de.tutorialwork.commands + +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BCrypt +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.LogManager +import de.tutorialwork.utils.UUIDFetcher +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.ProxyServer +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command +import java.util.* + +class WebAccount(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (sender.hasPermission("professionalbans.webaccount") || sender.hasPermission("professionalbans.*")) { + if (args.isEmpty() || args.size == 1) { + sender.sendMessage(Main.prefix + "/webaccount [Rang]") + } else { + if (args[0].equals("erstellen", ignoreCase = true)) { + if (args.size == 2) { + sender.sendMessage(Main.prefix + "Du musst noch ein Rang des Accounts angeben §4Admin§7, §cMod§7, §9Sup") + return + } + val uuid = UUIDFetcher.getUUID(args[1]) ?: return + if (BanManager.playerExists(uuid)) { + if (!BanManager.webaccountExists(uuid)) { + val target = ProxyServer.getInstance().getPlayer(args[1]) + if (target != null) { + val rowPW = randomString(7) + val hash = BCrypt.hashpw(rowPW, BCrypt.gensalt()) + when { + args[2].equals("Admin", ignoreCase = true) -> { + BanManager.createWebAccount(uuid, BanManager.getNameByUUID(uuid).toString(), 3, hash) + sender.sendMessage(Main.prefix + "Ein §4§lAdmin §7Account für §e§l" + BanManager.getNameByUUID(uuid) + " §7wurde §aerstellt") + } + args[2].equals("Mod", ignoreCase = true) -> { + BanManager.createWebAccount(uuid, BanManager.getNameByUUID(uuid).toString(), 2, hash) + sender.sendMessage(Main.prefix + "Ein §c§lMod §7Account für §e§l" + BanManager.getNameByUUID(uuid) + " §7wurde §aerstellt") + } + args[2].equals("Sup", ignoreCase = true) -> { + BanManager.createWebAccount(uuid, BanManager.getNameByUUID(uuid).toString(), 1, hash) + sender.sendMessage(Main.prefix + "Ein §9§lSup §7Account für §e§l" + BanManager.getNameByUUID(uuid) + " §7wurde §aerstellt") + } + } + target.sendMessage(Main.prefix + "§e§l" + sender.name + " §7hat einen Webaccount für dich erstellt") + target.sendMessage(Main.prefix + "Passwort: §c§l" + rowPW) + LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), "ADD_WEBACCOUNT", args[2]) + } else { + sender.sendMessage(Main.prefix + "§e§l" + args[1] + " §7ist derzeit nicht online") + } + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler hat bereits einen Zugang zum Webinterface") + } + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler hat den Server noch nie betreten") + } + } else if (args[0].equals("löschen", ignoreCase = true)) { + val uuid = UUIDFetcher.getUUID(args[1]) ?: return + if (BanManager.playerExists(uuid)) { + if (BanManager.webaccountExists(uuid)) { + BanManager.deleteWebAccount(uuid) + sender.sendMessage(Main.prefix + "Der Zugang von dem Spieler §e§l" + BanManager.getNameByUUID(uuid) + " §7wurde erfolgreich §agelöscht") + LogManager.createEntry(uuid.toString(), sender.uniqueId.toString(), "DEL_WEBACCOUNT", null) + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler hat keinen Zugang zum Webinterface") + } + } else { + sender.sendMessage(Main.prefix + "§cDieser Spieler hat den Server noch nie betreten") + } + } else { + sender.sendMessage(Main.prefix + "§cDiese Aktion ist nicht gültig") + } + } + } else { + sender.sendMessage(Main.noPerms) + } + } + } + + companion object { + private val AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz" + private var rnd = Random() + + private fun randomString(length: Int): String { + val sb = StringBuilder(length) + for (i in 0 until length) + sb.append(AB[rnd.nextInt(AB.length)]) + return sb.toString() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/commands/WebVerify.kt b/src/main/kotlin/de/tutorialwork/commands/WebVerify.kt new file mode 100644 index 0000000..d356e34 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/commands/WebVerify.kt @@ -0,0 +1,41 @@ +package de.tutorialwork.commands + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import net.md_5.bungee.api.CommandSender +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.plugin.Command + +class WebVerify(name: String) : Command(name) { + + override fun execute(sender: CommandSender, args: Array) { + if (sender is ProxiedPlayer) { + if (args.isEmpty()) { + sender.sendMessage(Main.prefix + "/webverify ") + } else { + val uuid = sender.uniqueId + if (BanManager.webaccountExists(uuid)) { + if (BanManager.hasAuthToken(uuid)) { + if (args[0].length == 25) { + if (BanManager.getAuthCode(uuid) == args[0]) { + BanManager.updateAuthStatus(uuid) + sender.sendMessage(Main.prefix + "§a§lErfolgreich! §7Du kannst jetzt dein Passwort festlegen.") + } else { + sender.sendMessage(Main.prefix + "§cDer eingegebene Token ist ungültig") + } + } else { + sender.sendMessage(Main.prefix + "§cDer eingegebene Token ist ungültig") + } + } else { + sender.sendMessage(Main.prefix + "§cEs wurde keine Verifizierungsanfrage von dir gefunden") + } + } else { + sender.sendMessage(Main.prefix + "§cDu hast keinen Account im Webinterface") + } + } + } else { + console.sendMessage(Main.prefix + "§cDieser Befehl ist nur als Spieler nutzbar") + } + } +} \ 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 new file mode 100644 index 0000000..9490860 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/listener/Chat.kt @@ -0,0 +1,206 @@ +package de.tutorialwork.listener + +import de.tutorialwork.commands.SupportChat +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.LogManager +import net.md_5.bungee.api.ChatColor +import net.md_5.bungee.api.connection.ProxiedPlayer +import net.md_5.bungee.api.event.ChatEvent +import net.md_5.bungee.api.plugin.Listener +import net.md_5.bungee.config.ConfigurationProvider +import net.md_5.bungee.config.YamlConfiguration +import net.md_5.bungee.event.EventHandler +import java.io.File +import java.io.IOException +import java.security.SecureRandom +import java.sql.SQLException +import java.util.* + +class Chat : Listener { + + @EventHandler + fun onChat(e: ChatEvent) { + val p = e.sender as ProxiedPlayer + if (!e.message.startsWith("/")) { + if (SupportChat.activechats.containsKey(p)) { + e.isCancelled = true + val target = SupportChat.activechats[p] ?: return + target.sendMessage("§9§lSUPPORT §8• §c" + p.name + " §8» " + e.message) + p.sendMessage("§9§lSUPPORT §8• §aDu §8» " + e.message) + } + if (SupportChat.activechats.containsValue(p)) { + e.isCancelled = true + for (key in SupportChat.activechats.keys) { + //Key has started the support chat + key.sendMessage("§9§lSUPPORT §8• §c" + p.name + " §8» " + e.message) + } + p.sendMessage("§9§lSUPPORT §8• §aDu §8» " + e.message) + } + val uuid = p.uniqueId + if (BanManager.isMuted(uuid)) { + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + + if (BanManager.getRAWEnd(uuid) == -1L) { + e.isCancelled = true + p.sendMessage(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.MUTE").replace("%grund%", BanManager.getReasonString(uuid)))) + } else { + if (System.currentTimeMillis() < BanManager.getRAWEnd(uuid) ?: 0) { + e.isCancelled = true + var MSG = configcfg.getString("LAYOUT.TEMPMUTE") + MSG = MSG.replace("%grund%", BanManager.getReasonString(uuid)) + MSG = MSG.replace("%dauer%", BanManager.getEnd(uuid)) + p.sendMessage(ChatColor.translateAlternateColorCodes('&', MSG)) + } else { + BanManager.unmute(uuid) + } + } + + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e2: IOException) { + e2.printStackTrace() + } + + } else { + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + + if (!p.hasPermission("professionalbans.blacklist.bypass") || !p.hasPermission("professionalbans.*")) { + if (configcfg.getBoolean("AUTOMUTE.ENABLED")) { + insertMessage(uuid, e.message, p.server.info.name) + for (blacklist in Main.blacklist) { + if (e.message.toUpperCase().contains(blacklist.toUpperCase())) { + e.isCancelled = true + BanManager.mute(uuid, configcfg.getInt("AUTOMUTE.MUTEID"), "KONSOLE") + LogManager.createEntry(uuid.toString(), "KONSOLE", "AUTOMUTE_BLACKLIST", e.message) + BanManager.setMutes(uuid, BanManager.getMutes(uuid) + 1) + BanManager.sendNotify("MUTE", BanManager.getNameByUUID(uuid).toString() + , "KONSOLE", BanManager.getReasonByID(configcfg.getInt("AUTOMUTE.MUTEID"))) + if (BanManager.getRAWEnd(uuid) == -1L) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.MUTE") + .replace("%grund%", BanManager.getReasonByID(configcfg.getInt("AUTOMUTE.MUTEID")).toString()))) + } else { + var MSG = configcfg.getString("LAYOUT.TEMPMUTE") + MSG = MSG.replace("%grund%", BanManager.getReasonString(uuid)) + MSG = MSG.replace("%dauer%", BanManager.getEnd(uuid)) + p.sendMessage(ChatColor.translateAlternateColorCodes('&', MSG)) + } + return + } + } + for (adblacklist in Main.adblacklist) { + if (e.message.toUpperCase().contains(adblacklist.toUpperCase())) { + if (!Main.adwhitelist.contains(e.message.toUpperCase())) { + e.isCancelled = true + BanManager.mute(uuid, configcfg.getInt("AUTOMUTE.ADMUTEID"), "KONSOLE") + LogManager.createEntry(uuid.toString(), "KONSOLE", "AUTOMUTE_ADBLACKLIST", e.message) + BanManager.setMutes(uuid, BanManager.getMutes(uuid) + 1) + BanManager.sendNotify("MUTE", BanManager.getNameByUUID(uuid).toString(), "KONSOLE", BanManager.getReasonByID(configcfg.getInt("AUTOMUTE.ADMUTEID"))) + if (BanManager.getRAWEnd(uuid) == -1L) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.MUTE") + .replace("%grund%", BanManager.getReasonByID(configcfg.getInt("AUTOMUTE.MUTEID"))))) + } else { + var msg = configcfg.getString("LAYOUT.TEMPMUTE") + msg = msg.replace("%grund%", BanManager.getReasonString(uuid)) + msg = msg.replace("%dauer%", BanManager.getEnd(uuid)) + p.sendMessage(ChatColor.translateAlternateColorCodes('&', msg)) + } + return + } + } + } + } else { + insertMessage(uuid, e.message, p.server.info.name) + if (configcfg.getBoolean("AUTOMUTE.AUTOREPORT")) { + for (blacklist in Main.blacklist) { + if (e.message.toUpperCase().contains(blacklist.toUpperCase())) { + e.isCancelled = true + p.sendMessage(Main.prefix + "§cAchte auf deine Wortwahl") + val LogID = Chat.createChatlog(uuid, "KONSOLE") + BanManager.createReport(uuid, "KONSOLE", "VERHALTEN", LogID) + BanManager.sendNotify("REPORT", p.name, "KONSOLE", "VERHALTEN") + return + } + } + for (adblacklist in Main.adblacklist) { + if (e.message.toUpperCase().contains(adblacklist.toUpperCase())) { + if (!Main.adwhitelist.contains(e.message.toUpperCase())) { + e.isCancelled = true + p.sendMessage(Main.prefix + "§cDu darfst keine Werbung machen") + val LogID = Chat.createChatlog(uuid, "KONSOLE") + BanManager.createReport(uuid, "KONSOLE", "WERBUNG", LogID) + BanManager.sendNotify("REPORT", p.name, "KONSOLE", "WERBUNG") + return + } + } + } + } + } + } else { + insertMessage(uuid, e.message, p.server.info.name) + } + + } catch (e2: IOException) { + e2.printStackTrace() + } + + } + } + } + + companion object { + + fun insertMessage(uuid: UUID, Message: String, Server: String) { + Main.mysql.update("INSERT INTO chat(UUID, SERVER, MESSAGE, SENDDATE) " + + "VALUES ('" + uuid + "', '" + Server + "', '" + Message + "', '" + System.currentTimeMillis() + "')") + } + + fun createChatlog(uuid: UUID, createdUUID: String): String { + try { + val rs = Main.mysql.query("SELECT * FROM chat WHERE uuid='$uuid'") ?: return "Null" + val id = randomString(20) + val now = System.currentTimeMillis() + while (rs.next()) { + val tenMinutes = 10 * 60 * 1000 + val tenAgo = System.currentTimeMillis() - tenMinutes + if (java.lang.Long.valueOf(rs.getString("SENDDATE")) > tenAgo) { + Main.mysql.update("INSERT INTO chatlog(LOGID, uuid, CREATOR_UUID, SERVER, MESSAGE, SENDDATE, CREATED_AT) " + + "VALUES ('" + id + "' ,'" + uuid + "', '" + createdUUID + "', '" + rs.getString("SERVER") + "', '" + rs.getString("MESSAGE") + "', '" + rs.getString("SENDDATE") + "', '" + now + "')") + } + } + return id + } catch (exc: SQLException) { + + } + + return "Null" + } + + fun hasMessages(uuid: UUID): Boolean { + return try { + val rs = Main.mysql.query("SELECT * FROM chat WHERE uuid='$uuid'") ?: return false + var i = 0 + while (rs.next()) { + i++ + } + i != 0 + } catch (exc: SQLException) { + false + } + } + + private const val alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + private var rnd = SecureRandom() + + private fun randomString(len: Int): String { + val sb = StringBuilder(len) + for (i in 0 until len) + sb.append(alphabet[rnd.nextInt(alphabet.length)]) + return sb.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 new file mode 100644 index 0000000..1a3301a --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/listener/Login.kt @@ -0,0 +1,136 @@ +package de.tutorialwork.listener + +import de.tutorialwork.commands.SupportChat +import de.tutorialwork.main.Main +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.IPManager +import de.tutorialwork.utils.UUIDFetcher +import net.md_5.bungee.api.ChatColor +import net.md_5.bungee.api.event.PostLoginEvent +import net.md_5.bungee.api.event.PreLoginEvent +import net.md_5.bungee.api.plugin.Listener +import net.md_5.bungee.config.ConfigurationProvider +import net.md_5.bungee.config.YamlConfiguration +import net.md_5.bungee.event.EventHandler + +import java.io.File +import java.io.IOException + +class 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*/ + BanManager.createPlayer(uuid, event.connection.name) + IPManager.insertIP(ip, uuid) + val config = File(Main.instance.dataFolder, "config.yml") + try { + val cfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + if (cfg.getBoolean("VPN.BLOCKED")) { + if (!Main.ipwhitelist.contains(ip)) { + if (IPManager.isVPN(ip)) { + if (cfg.getBoolean("VPN.KICK")) { + event.isCancelled = true + event.cancelReason = ChatColor.translateAlternateColorCodes('&', cfg.getString("VPN.KICKMSG")) + } + if (cfg.getBoolean("VPN.BAN")) { + val id = cfg.getInt("VPN.BANID") + BanManager.ban(uuid, id, "KONSOLE", Main.increaseValue, Main.increaseBans) + BanManager.sendNotify("IPBAN", event.connection.address.hostString, "KONSOLE", BanManager.getReasonByID(id)) + event.isCancelled = true + if (BanManager.getRAWEnd(uuid) == -1L) { + event.cancelReason = ChatColor.translateAlternateColorCodes('&', cfg.getString("LAYOUT.IPBAN").replace("%grund%", BanManager.getReasonByID(id)!!)) + } else { + var MSG = cfg.getString("LAYOUT.TEMPIPBAN") + MSG = MSG.replace("%grund%", BanManager.getReasonString(uuid)!!) + MSG = MSG.replace("%dauer%", BanManager.getEnd(uuid)) + event.cancelReason = ChatColor.translateAlternateColorCodes('&', MSG) + } + } + } + } + } + } catch (er: IOException) { + er.printStackTrace() + } + + if (IPManager.isBanned(ip)) { + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + + if (IPManager.getRAWEnd(ip) == -1L) { + event.isCancelled = true + event.cancelReason = ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.IPBAN").replace("%grund%", IPManager.getReasonString(ip)!!)) + } else { + if (System.currentTimeMillis() < IPManager.getRAWEnd(ip) ?: 0) { + event.isCancelled = true + var msg = configcfg.getString("LAYOUT.TEMPIPBAN") + msg = msg.replace("%grund%", IPManager.getReasonString(ip)!!) + msg = msg.replace("%dauer%", IPManager.getEnd(ip)) + event.cancelReason = ChatColor.translateAlternateColorCodes('&', msg) + } else { + IPManager.unban(ip) + } + } + + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e2: IOException) { + e2.printStackTrace() + } + + } + if (BanManager.isBanned(uuid)) { + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + + if (BanManager.getRAWEnd(uuid) == -1L) { + event.isCancelled = true + event.cancelReason = ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.BAN").replace("%grund%", BanManager.getReasonString(uuid)!!)) + } else { + if (System.currentTimeMillis() < BanManager.getRAWEnd(uuid) ?: 0) { + event.isCancelled = true + var msg = configcfg.getString("LAYOUT.TEMPBAN") + msg = msg.replace("%grund%", BanManager.getReasonString(uuid)!!) + msg = msg.replace("%dauer%", BanManager.getEnd(uuid)) + event.cancelReason = ChatColor.translateAlternateColorCodes('&', msg) + } else { + BanManager.unban(uuid) + } + } + + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e2: IOException) { + e2.printStackTrace() + } + + } + } + + @EventHandler + fun onFinalLogin(e: PostLoginEvent) { + val p = e.player + if (p.hasPermission("professionalbans.reports") || p.hasPermission("professionalbans.*")) { + if (BanManager.countOpenReports() != 0) { + p.sendMessage(Main.prefix + "Derzeit sind noch §e§l" + BanManager.countOpenReports() + " Reports §7offen") + } + } + if (p.hasPermission("professionalbans.supportchat") || p.hasPermission("professionalbans.*")) { + if (SupportChat.openchats.size != 0) { + p.sendMessage(Main.prefix + "Derzeit sind noch §e§l" + SupportChat.openchats.size + " §7Support Chat Anfragen §aoffen") + } + } + //Update Check + if (p.hasPermission("professionalbans.*")) { + if (Main.callURL("https://api.spigotmc.org/legacy/update.php?resource=63657") != Main.Version) { + p.sendMessage("§8[]===================================[]") + p.sendMessage("§e§lProfessionalBans §7Reloaded §8| §7Version §c" + Main.Version) + p.sendMessage("§cDu benutzt eine §c§lVERALTETE §cVersion des Plugins!") + p.sendMessage("§7Update: §4§lhttps://spigotmc.org/resources/63657") + p.sendMessage("§8[]===================================[]") + } + } + } + +} \ 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 new file mode 100644 index 0000000..97b03e3 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/listener/Quit.kt @@ -0,0 +1,28 @@ +package de.tutorialwork.listener + +import de.tutorialwork.commands.SupportChat +import de.tutorialwork.main.Main +import net.md_5.bungee.api.event.PlayerDisconnectEvent +import net.md_5.bungee.api.plugin.Listener +import net.md_5.bungee.event.EventHandler + +class Quit : Listener { + + @EventHandler + fun onPlayerDisconnectEvent(event: PlayerDisconnectEvent) { + val player = event.player + if (SupportChat.activechats.containsKey(player) || SupportChat.activechats.containsValue(player)) { + for (key in SupportChat.activechats.keys) { + //Key has started the support chat + if (key === player) { + SupportChat.activechats[player]?.sendMessage(Main.prefix + "§event§l" + player.name + " §7hat den Support hat §cbeeendet") + SupportChat.activechats.remove(player) + } else { + key.sendMessage(Main.prefix + "§event§l" + player.name + " §7hat den Support Chat §cbeeendet") + SupportChat.activechats.remove(key) + } + } + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/de/tutorialwork/main/Main.kt b/src/main/kotlin/de/tutorialwork/main/Main.kt new file mode 100644 index 0000000..adc88e2 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/main/Main.kt @@ -0,0 +1,261 @@ +package de.tutorialwork.main + +import de.tutorialwork.commands.* +import de.tutorialwork.console +import de.tutorialwork.listener.Chat +import de.tutorialwork.listener.Login +import de.tutorialwork.listener.Quit +import de.tutorialwork.utils.BanManager +import de.tutorialwork.utils.MySQLConnect +import net.md_5.bungee.api.ChatColor +import net.md_5.bungee.api.plugin.Command +import net.md_5.bungee.api.plugin.Plugin +import net.md_5.bungee.config.ConfigurationProvider +import net.md_5.bungee.config.YamlConfiguration +import java.io.File +import java.io.IOException +import java.net.URL +import java.net.URLConnection +import java.util.* +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.apply { + sendMessage("§8[]===================================[]") + sendMessage("§e§lProfessionalBans §7§oReloaded §8| §7Version: §c$Version") + sendMessage("§7Developer: §e§lTutorialwork, LeBaasti") + sendMessage("§5YT §7Kanal: §cyoutube.com/Tutorialwork") + sendMessage("§8[]===================================[]") + } + + + //Überprüft auf Bans aus dem Webinterface + proxy.scheduler.schedule(this, { + val config = File(Main.instance.dataFolder, "config.yml") + try { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + for (all in proxy.players) { + val uuid = all.uniqueId + if (BanManager.isBanned(uuid)) { + if (BanManager.getRAWEnd(uuid) == -1L) { + all.disconnect(ChatColor.translateAlternateColorCodes('&', configcfg.getString("LAYOUT.BAN") + .replace("%grund%", BanManager.getReasonString(uuid)))) + } else { + var msg = configcfg.getString("LAYOUT.TEMPBAN") + msg = msg.replace("%grund%", BanManager.getReasonString(uuid)) + msg = msg.replace("%dauer%", BanManager.getEnd(uuid)) + all.disconnect(ChatColor.translateAlternateColorCodes('&', msg)) + } + } + } + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } catch (e: IOException) { + e.printStackTrace() + } + }, 5, 5, TimeUnit.SECONDS) + } + + private fun config() { + if (!dataFolder.exists()) dataFolder.mkdir() + val file = File(dataFolder.path, "mysql.yml") + val config = File(dataFolder.path, "config.yml") + val blacklistfile = File(dataFolder.path, "blacklist.yml") + try { + if (!file.exists()) { + file.createNewFile() + val mysql = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(file) + mysql.set("HOST", "localhost") + mysql.set("DATENBANK", "Bans") + mysql.set("USER", "root") + mysql.set("PASSWORT", "deinpasswort") + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(mysql, file) + } + if (!config.exists()) { + config.createNewFile() + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + configcfg.set("PREFIX", "&e&lBANS &8• &7") + configcfg.set("LAYOUT.BAN", "&8[]===================================[] \n\n &4&lDu wurdest GEBANNT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") + configcfg.set("LAYOUT.KICK", "&8[]===================================[] \n\n &e&lDu wurdest GEKICKT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") + configcfg.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[]===================================[]") + configcfg.set("LAYOUT.MUTE", "&8[]===================================[] \n\n &4&lDu wurdest GEMUTET \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") + configcfg.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[]===================================[]") + configcfg.set("LAYOUT.IPBAN", "&8[]===================================[] \n\n &4&lDeine IP-Adresse wurde GEBANNT \n\n &eGrund: §c§l%grund% \n\n&8[]===================================[]") + configcfg.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[]===================================[]") + configcfg.set("VPN.BLOCKED", true) + configcfg.set("VPN.KICK", true) + configcfg.set("VPN.KICKMSG", "&7Das benutzen einer &4VPN &7ist auf unserem Netzwerk &cUNTERSAGT") + configcfg.set("VPN.BAN", false) + configcfg.set("VPN.BANID", 0) + ipwhitelist.add("8.8.8.8") + configcfg.set("VPN.WHITELIST", ipwhitelist) + configcfg.set("VPN.APIKEY", "Go to https://proxycheck.io/dashboard and register with your email and enter here your API Key") + configcfg.set("REPORTS.ENABLED", true) + reportreasons.add("Hacking") + reportreasons.add("Verhalten") + reportreasons.add("Teaming") + reportreasons.add("TPA-Falle") + reportreasons.add("Werbung") + configcfg.set("REPORTS.REASONS", reportreasons) + configcfg.set("REPORTS.OFFLINEREPORTS", false) + configcfg.set("CHATLOG.ENABLED", true) + configcfg.set("CHATLOG.URL", "DeinServer.net/BanWebinterface/public/chatlog.php?id=") + configcfg.set("AUTOMUTE.ENABLED", false) + configcfg.set("AUTOMUTE.AUTOREPORT", true) + //configcfg.set("AUTOMUTE.AUTOREPORT.REASON", "Automatischer Report"); + configcfg.set("AUTOMUTE.MUTEID", 0) + configcfg.set("AUTOMUTE.ADMUTEID", 0) + configcfg.set("BANTIME-INCREASE.ENABLED", true) + configcfg.set("BANTIME-INCREASE.PERCENTRATE", 50) + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } else { + val configcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(config) + if (configcfg.getBoolean("VPN.KICK") && configcfg.getBoolean("VPN.BAN")) { + console.sendMessage("§8[]===================================[]") + console.sendMessage("§c§lSINNLOSE EINSTELLUNG ENTDECKT") + console.sendMessage("§7Wenn ein Spieler mit einer VPN das Netzwerk betritt kann er nicht gekickt UND gebannt werden.") + console.sendMessage("§4§lÜberprüfe die VPN Einstellung in der CONFIG.YML") + console.sendMessage("§8[]===================================[]") + //Setze VPN Einstellung zurück! + configcfg.set("VPN.BLOCKED", true) + configcfg.set("VPN.KICK", true) + configcfg.set("VPN.KICKMSG", "&7Das benutzen einer &4VPN &7ist auf unserem Netzwerk &cUNTERSAGT") + configcfg.set("VPN.BAN", false) + configcfg.set("VPN.BANID", 0) + } + for (reasons in configcfg.getStringList("REPORTS.REASONS")) { + reportreasons.add(reasons.toUpperCase()) + } + for (ips in configcfg.getStringList("VPN.WHITELIST")) { + ipwhitelist.add(ips) + } + prefix = configcfg.getString("PREFIX").replace("&", "§") + increaseBans = configcfg.getBoolean("BANTIME-INCREASE.ENABLED") + increaseValue = configcfg.getInt("BANTIME-INCREASE.PERCENTRATE") + if (configcfg.getString("VPN.APIKEY").length == 27) { + APIKey = configcfg.getString("VPN.APIKEY") + } + ConfigurationProvider.getProvider(YamlConfiguration::class.java).save(configcfg, config) + } + if (!blacklistfile.exists()) blacklistfile.createNewFile() + val blacklistcfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(blacklistfile) + for (congigstr in blacklistcfg.getStringList("BLACKLIST")) blacklist.add(congigstr) + for (congigstr in blacklistcfg.getStringList("ADBLACKLIST")) adblacklist.add(congigstr) + for (congigstr in blacklistcfg.getStringList("ADWHITELIST")) adwhitelist.add(congigstr.toUpperCase()) + } catch (e: IOException) { + e.printStackTrace() + } + + } + + private fun mySQL() { + try { + val file = File(dataFolder.path, "mysql.yml") + val mysql = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(file) + MySQLConnect.HOST = mysql.getString("HOST") + MySQLConnect.DATABASE = mysql.getString("DATENBANK") + MySQLConnect.USER = mysql.getString("USER") + MySQLConnect.PASSWORD = mysql.getString("PASSWORT") + } catch (e: IOException) { + e.printStackTrace() + } + + 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() { + try { + val file = File(dataFolder.path, "config.yml") + val cfg = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(file) + arrayOf(Ban("ban"), + Unban("unban"), + Kick("kick"), + WebAccount("webaccount"), + Check("check"), + IPBan("ipban"), + Blacklist("blacklist"), + WebVerify("webverify"), + SupportChat("support") + ).forEach { it.register() } + + + if (cfg.getBoolean("REPORTS.ENABLED")) { + Report("report").register() + Reports("reports").register() + } + if (cfg.getBoolean("CHATLOG.ENABLED")) Chatlog("chatlog").register() + } catch (e: IOException) { + e.printStackTrace() + } + + } + + private fun registerListeners() { + proxy.pluginManager.registerListener(this, Login()) + proxy.pluginManager.registerListener(this, Chat()) + proxy.pluginManager.registerListener(this, Quit()) + } + + companion object { + + lateinit var instance: Main + lateinit var mysql: MySQLConnect + var prefix = "§e§lBANS §8• §7" + var noPerms = "$prefix§cDu hast keine Berechtigung diesen Befehl zu nutzen" + + var reportreasons = mutableListOf() + var blacklist = ArrayList() + var adblacklist = ArrayList() + var adwhitelist = ArrayList() + var ipwhitelist = ArrayList() + + var increaseBans = true + var increaseValue: Int = 50 + + var APIKey: String? = null + + //============================================== + //Plugin Informationen + var Version = "2.4" + + 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() + } + } + + private fun Command.register() = proxy.pluginManager.registerCommand(this@Main, this) + +} \ No newline at end of file diff --git a/src/de/tutorialwork/utils/BCrypt.java b/src/main/kotlin/de/tutorialwork/utils/BCrypt.java similarity index 87% rename from src/de/tutorialwork/utils/BCrypt.java rename to src/main/kotlin/de/tutorialwork/utils/BCrypt.java index 500e75e..a805495 100644 --- a/src/de/tutorialwork/utils/BCrypt.java +++ b/src/main/kotlin/de/tutorialwork/utils/BCrypt.java @@ -1,21 +1,6 @@ -// Copyright (c) 2006 Damien Miller -// -// Permission to use, copy, modify, and distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - package de.tutorialwork.utils; import java.io.UnsupportedEncodingException; - import java.security.SecureRandom; /** @@ -378,10 +363,10 @@ public class BCrypt { * encoding scheme. Note that this is *not* compatible with * the standard MIME-base64 encoding. * - * @param d the byte array to encode - * @param len the number of bytes to encode - * @return base64-encoded string - * @exception IllegalArgumentException if the length is invalid + * @param d the byte array to encode + * @param len the number of bytes to encode + * @return base64-encoded string + * @throws IllegalArgumentException if the length is invalid */ private static String encode_base64(byte d[], int len) throws IllegalArgumentException { @@ -390,7 +375,7 @@ private static String encode_base64(byte d[], int len) int c1, c2; if (len <= 0 || len > d.length) - throw new IllegalArgumentException ("Invalid len"); + throw new IllegalArgumentException("Invalid len"); while (off < len) { c1 = d[off++] & 0xff; @@ -419,22 +404,24 @@ private static String encode_base64(byte d[], int len) /** * Look up the 3 bits base64-encoded by the specified character, * range-checking againt conversion table - * @param x the base64-encoded value - * @return the decoded value of x + * + * @param x the base64-encoded value + * @return the decoded value of x */ private static byte char64(char x) { - if ((int)x < 0 || (int)x > index_64.length) + if ((int) x < 0 || (int) x > index_64.length) return -1; - return index_64[(int)x]; + return index_64[(int) x]; } /** * Decode a string encoded using bcrypt's base64 scheme to a * byte array. Note that this is *not* compatible with * the standard MIME-base64 encoding. - * @param s the string to decode - * @param maxolen the maximum number of bytes to decode - * @return an array containing the decoded bytes + * + * @param s the string to decode + * @param maxolen the maximum number of bytes to decode + * @return an array containing the decoded bytes * @throws IllegalArgumentException if maxolen is invalid */ private static byte[] decode_base64(String s, int maxolen) @@ -445,50 +432,51 @@ private static byte[] decode_base64(String s, int maxolen) byte c1, c2, c3, c4, o; if (maxolen <= 0) - throw new IllegalArgumentException ("Invalid maxolen"); + throw new IllegalArgumentException("Invalid maxolen"); while (off < slen - 1 && olen < maxolen) { c1 = char64(s.charAt(off++)); c2 = char64(s.charAt(off++)); if (c1 == -1 || c2 == -1) break; - o = (byte)(c1 << 2); + o = (byte) (c1 << 2); o |= (c2 & 0x30) >> 4; - rs.append((char)o); + rs.append((char) o); if (++olen >= maxolen || off >= slen) break; c3 = char64(s.charAt(off++)); if (c3 == -1) break; - o = (byte)((c2 & 0x0f) << 4); + o = (byte) ((c2 & 0x0f) << 4); o |= (c3 & 0x3c) >> 2; - rs.append((char)o); + rs.append((char) o); if (++olen >= maxolen || off >= slen) break; c4 = char64(s.charAt(off++)); - o = (byte)((c3 & 0x03) << 6); + o = (byte) ((c3 & 0x03) << 6); o |= c4; - rs.append((char)o); + rs.append((char) o); ++olen; } ret = new byte[olen]; for (off = 0; off < olen; off++) - ret[off] = (byte)rs.charAt(off); + ret[off] = (byte) rs.charAt(off); return ret; } /** * Blowfish encipher a single 64-bit block encoded as * two 32-bit halves - * @param lr an array containing the two 32-bit half blocks - * @param off the position in the array of the blocks + * + * @param lr an array containing the two 32-bit half blocks + * @param off the position in the array of the blocks */ private final void encipher(int lr[], int off) { int i, n, l = lr[off], r = lr[off + 1]; l ^= P[0]; - for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) { + for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2; ) { // Feistel substitution on left word n = S[(l >> 24) & 0xff]; n += S[0x100 | ((l >> 16) & 0xff)]; @@ -509,10 +497,11 @@ private final void encipher(int lr[], int off) { /** * Cycically extract a word of key material - * @param data the string to extract the data from - * @param offp a "pointer" (as a one-entry array) to the - * current offset into data - * @return the next word of material from data + * + * @param data the string to extract the data from + * @param offp a "pointer" (as a one-entry array) to the + * current offset into data + * @return the next word of material from data */ private static int streamtoword(byte data[], int offp[]) { int i; @@ -532,18 +521,19 @@ private static int streamtoword(byte data[], int offp[]) { * Initialise the Blowfish key schedule */ private void init_key() { - P = (int[])P_orig.clone(); - S = (int[])S_orig.clone(); + P = (int[]) P_orig.clone(); + S = (int[]) S_orig.clone(); } /** * Key the Blowfish cipher - * @param key an array containing the key + * + * @param key an array containing the key */ private void key(byte key[]) { int i; - int koffp[] = { 0 }; - int lr[] = { 0, 0 }; + int koffp[] = {0}; + int lr[] = {0, 0}; int plen = P.length, slen = S.length; for (i = 0; i < plen; i++) @@ -566,13 +556,14 @@ private void key(byte key[]) { * Perform the "enhanced key schedule" step described by * Provos and Mazieres in "A Future-Adaptable Password Scheme" * http://www.openbsd.org/papers/bcrypt-paper.ps - * @param data salt information - * @param key password information + * + * @param data salt information + * @param key password information */ private void ekskey(byte data[], byte key[]) { int i; - int koffp[] = { 0 }, doffp[] = { 0 }; - int lr[] = { 0, 0 }; + int koffp[] = {0}, doffp[] = {0}; + int lr[] = {0, 0}; int plen = P.length, slen = S.length; for (i = 0; i < plen; i++) @@ -598,23 +589,24 @@ private void ekskey(byte data[], byte key[]) { /** * Perform the central password hashing step in the * bcrypt scheme - * @param password the password to hash - * @param salt the binary salt to hash with the password - * @param log_rounds the binary logarithm of the number - * of rounds of hashing to apply - * @return an array containing the binary hashed password + * + * @param password the password to hash + * @param salt the binary salt to hash with the password + * @param log_rounds the binary logarithm of the number + * of rounds of hashing to apply + * @return an array containing the binary hashed password */ private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) { int rounds, i, j; - int cdata[] = (int[])bf_crypt_ciphertext.clone(); + int cdata[] = (int[]) bf_crypt_ciphertext.clone(); int clen = cdata.length; byte ret[]; if (log_rounds < 4 || log_rounds > 31) - throw new IllegalArgumentException ("Bad number of rounds"); + throw new IllegalArgumentException("Bad number of rounds"); rounds = 1 << log_rounds; if (salt.length != BCRYPT_SALT_LEN) - throw new IllegalArgumentException ("Bad salt length"); + throw new IllegalArgumentException("Bad salt length"); init_key(); ekskey(salt, password); @@ -630,43 +622,44 @@ private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) { ret = new byte[clen * 4]; for (i = 0, j = 0; i < clen; i++) { - ret[j++] = (byte)((cdata[i] >> 24) & 0xff); - ret[j++] = (byte)((cdata[i] >> 16) & 0xff); - ret[j++] = (byte)((cdata[i] >> 8) & 0xff); - ret[j++] = (byte)(cdata[i] & 0xff); + ret[j++] = (byte) ((cdata[i] >> 24) & 0xff); + ret[j++] = (byte) ((cdata[i] >> 16) & 0xff); + ret[j++] = (byte) ((cdata[i] >> 8) & 0xff); + ret[j++] = (byte) (cdata[i] & 0xff); } return ret; } /** * Hash a password using the OpenBSD bcrypt scheme - * @param password the password to hash - * @param salt the salt to hash with (perhaps generated - * using BCrypt.gensalt) - * @return the hashed password + * + * @param password the password to hash + * @param salt the salt to hash with (perhaps generated + * using BCrypt.gensalt) + * @return the hashed password */ public static String hashpw(String password, String salt) { BCrypt B; String real_salt; byte passwordb[], saltb[], hashed[]; - char minor = (char)0; + char minor = (char) 0; int rounds, off = 0; StringBuffer rs = new StringBuffer(); if (salt.charAt(0) != '$' || salt.charAt(1) != '2') - throw new IllegalArgumentException ("Invalid salt version"); + throw new IllegalArgumentException("Invalid salt version"); if (salt.charAt(2) == '$') off = 3; else { minor = salt.charAt(2); if (minor != 'a' || salt.charAt(3) != '$') - throw new IllegalArgumentException ("Invalid salt revision"); + throw new IllegalArgumentException("Invalid salt revision"); off = 4; } // Extract number of rounds if (salt.charAt(off + 2) > '$') - throw new IllegalArgumentException ("Missing salt rounds"); + throw new IllegalArgumentException("Missing salt rounds"); rounds = Integer.parseInt(salt.substring(off, off + 2)); real_salt = salt.substring(off + 3, off + 25); @@ -697,11 +690,12 @@ public static String hashpw(String password, String salt) { /** * Generate a salt for use with the BCrypt.hashpw() method - * @param log_rounds the log2 of the number of rounds of - * hashing to apply - the work factor therefore increases as - * 2**log_rounds. - * @param random an instance of SecureRandom to use - * @return an encoded salt value + * + * @param log_rounds the log2 of the number of rounds of + * hashing to apply - the work factor therefore increases as + * 2**log_rounds. + * @param random an instance of SecureRandom to use + * @return an encoded salt value */ public static String gensalt(int log_rounds, SecureRandom random) { StringBuffer rs = new StringBuffer(); @@ -720,10 +714,11 @@ public static String gensalt(int log_rounds, SecureRandom random) { /** * Generate a salt for use with the BCrypt.hashpw() method - * @param log_rounds the log2 of the number of rounds of - * hashing to apply - the work factor therefore increases as - * 2**log_rounds. - * @return an encoded salt value + * + * @param log_rounds the log2 of the number of rounds of + * hashing to apply - the work factor therefore increases as + * 2**log_rounds. + * @return an encoded salt value */ public static String gensalt(int log_rounds) { return gensalt(log_rounds, new SecureRandom()); @@ -733,7 +728,8 @@ public static String gensalt(int log_rounds) { * Generate a salt for use with the BCrypt.hashpw() method, * selecting a reasonable default for the number of hashing * rounds to apply - * @return an encoded salt value + * + * @return an encoded salt value */ public static String gensalt() { return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS); @@ -742,11 +738,12 @@ public static String gensalt() { /** * Check that a plaintext password matches a previously hashed * one - * @param plaintext the plaintext password to verify - * @param hashed the previously-hashed password - * @return true if the passwords match, false otherwise + * + * @param plaintext the plaintext password to verify + * @param hashed the previously-hashed password + * @return true if the passwords match, false otherwise */ public static boolean checkpw(String plaintext, String hashed) { return (hashed.compareTo(hashpw(plaintext, hashed)) == 0); } -} \ No newline at end of file +} diff --git a/src/main/kotlin/de/tutorialwork/utils/BanManager.kt b/src/main/kotlin/de/tutorialwork/utils/BanManager.kt new file mode 100644 index 0000000..2870708 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/utils/BanManager.kt @@ -0,0 +1,628 @@ +package de.tutorialwork.utils + +import de.tutorialwork.main.Main +import net.md_5.bungee.api.ProxyServer +import net.md_5.bungee.api.connection.ProxiedPlayer +import java.sql.SQLException +import java.text.SimpleDateFormat +import java.util.* + +object BanManager { + + val iDsFromOpenReports: List + get() { + return try { + val rs = Main.mysql.query("SELECT * FROM reports WHERE STATUS = 0") + val ids = ArrayList() + while (rs!!.next()) { + ids.add(rs.getInt("ID")) + } + ids + } catch (exc: SQLException) { + emptyList() + } + } + + //DATENBANK Struktur + //UUID varchar(64) UNIQUE, NAME varchar(64), BANNED int(11), MUTED int(11), REASON varchar(64), END long(255), TEAMUUID varchar(64), BANS int(11), MUTES int(11) + + fun playerExists(uuid: UUID): Boolean { + val rs = Main.mysql.query("SELECT * FROM bans WHERE uuid='$uuid'") ?: return false + return if (rs.next()) rs.getString("uuid") != null + else false + } + + fun createPlayer(uuid: UUID, name: String) { + if (!playerExists(uuid)) { + Main.mysql.update("INSERT INTO bans(uuid, NAME, BANNED, MUTED, REASON, END, TEAMUUID, BANS, MUTES, FIRSTLOGIN, LASTLOGIN) " + + "VALUES ('" + uuid + "', '" + name + "', '0', '0', 'null', 'null', 'null', '0', '0', '" + System.currentTimeMillis() + "', '" + System.currentTimeMillis() + "')") + } else { + updateName(uuid, name) + updateLastLogin(uuid) + } + } + + fun getBanReasonsList(p: ProxiedPlayer) { + try { + val rs = Main.mysql.query("SELECT * FROM reasons ORDER BY SORTINDEX ASC") + while (rs!!.next()) { + val id = rs.getInt("ID") + if (isBanReason(id)) { + p.sendMessage("§7" + id + " §8| §e" + getReasonByID(id)) + } else { + p.sendMessage("§7" + id + " §8| §e" + getReasonByID(id) + " §8(§cMUTE§8)") + } + } + } catch (exc: SQLException) { + } + + } + + fun getNameByUUID(uuid: UUID): String? { + if (playerExists(uuid)) { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE uuid='$uuid'") + if (rs!!.next()) { + return rs.getString("NAME") + } + } catch (exc: SQLException) { + + } + + } + return null + } + + fun getUUIDByName(name: String): String? { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE NAME='$name'") + if (rs!!.next()) { + return rs.getString("UUID") + } + } catch (exc: SQLException) { + + } + + return null + } + + private fun updateName(uuid: UUID, newName: String) { + if (playerExists(uuid)) Main.mysql.update("UPDATE bans SET NAME='$newName' WHERE uuid='$uuid'") + } + + fun ban(uuid: UUID, GrundID: Int, TeamUUID: String, Prozentsatz: Int, increaseBans: Boolean) { + if (getReasonTime(GrundID) == -1) { + //Perma Ban + Main.mysql.update("UPDATE bans SET BANNED='1', REASON='" + getReasonByID(GrundID) + "', END='-1', TEAMUUID='" + TeamUUID + "' WHERE uuid='" + uuid + "'") + } else { + //Temp Ban + //Formel: 1.50 * Anzahl an Tagen = Ergebniss (50%) + val bans = getBans(uuid) + val defaultmins = getReasonTime(GrundID)!! + val current = System.currentTimeMillis() + val end = current + getReasonTime(GrundID)!! * 60000L + val increaseEnd = current + (Prozentsatz / 100).toLong() + 1 * defaultmins.toLong() * bans.toLong() * 60000L //Formel!!!!! + if (increaseBans) { + if (bans > 0) { + Main.mysql.update("UPDATE bans SET BANNED='1', REASON='" + getReasonByID(GrundID) + "', END='" + end + "', TEAMUUID='" + TeamUUID + "' WHERE uuid='" + uuid + "'") + } else { + Main.mysql.update("UPDATE bans SET BANNED='1', REASON='" + getReasonByID(GrundID) + "', END='" + increaseEnd + "', TEAMUUID='" + TeamUUID + "' WHERE uuid='" + uuid + "'") + } + } else { + Main.mysql.update("UPDATE bans SET BANNED='1', REASON='" + getReasonByID(GrundID) + "', END='" + end + "', TEAMUUID='" + TeamUUID + "' WHERE uuid='" + uuid + "'") + } + } + } + + fun mute(uuid: UUID, GrundID: Int, TeamUUID: String) { + val current = System.currentTimeMillis() + val end = current + getReasonTime(GrundID)!! * 60000L + if (getReasonTime(GrundID) == -1) { + //Perma Mute + Main.mysql.update("UPDATE bans SET MUTED='1', REASON='" + getReasonByID(GrundID) + "', END='-1', TEAMUUID='" + TeamUUID + "' WHERE UUID='" + uuid + "'") + } else { + //Temp Mute + Main.mysql.update("UPDATE bans SET MUTED='1', REASON='" + getReasonByID(GrundID) + "', END='" + end + "', TEAMUUID='" + TeamUUID + "' WHERE UUID='" + uuid + "'") + } + } + + fun getRAWEnd(uuid: UUID): Long? { + if (playerExists(uuid)) { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE uuid='$uuid'") + if (rs!!.next()) { + return rs.getLong("END") + } + } catch (exc: SQLException) { + + } + + } + return null + } + + fun getEnd(uuid: UUID): String { + val uhrzeit = System.currentTimeMillis() + val end = getRAWEnd(uuid)!! + + var millis = end - uhrzeit + + var sekunden = 0L + var minuten = 0L + var stunden = 0L + var tage = 0L + while (millis > 1000L) { + millis -= 1000L + sekunden += 1L + } + while (sekunden > 60L) { + sekunden -= 60L + minuten += 1L + } + while (minuten > 60L) { + minuten -= 60L + stunden += 1L + } + while (stunden > 24L) { + stunden -= 24L + tage += 1L + } + return if (tage != 0L) { + "§a$tage §7Tag(e) §a$stunden §7Stunde(n) §a$minuten §7Minute(n)" + } else if (tage == 0L && stunden != 0L) { + "§a$stunden §7Stunde(n) §a$minuten §7Minute(n) §a$sekunden §7Sekunde(n)" + } else if (tage == 0L && stunden == 0L && minuten != 0L) { + "§a$minuten §7Minute(n) §a$sekunden §7Sekunde(n)" + } else if (tage == 0L && stunden == 0L && minuten == 0L && sekunden != 0L) { + "§a$sekunden §7Sekunde(n)" + } else { + "§4Fehler in der Berechnung!" + } + //Alter Code + //return "§a" + tage + " §7Tag(e) §a" + stunden + " §7Stunde(n) §a" + minuten + " §7Minute(n) §a" + sekunden + " §7Sekunde(n)"; + } + + fun isBanned(uuid: UUID): Boolean { + if (playerExists(uuid)) { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='$uuid'") + if (rs!!.next()) { + return rs.getInt("BANNED") == 1 + } + } catch (exc: SQLException) { + + } + + } + return false + } + + fun isMuted(uuid: UUID): Boolean { + if (playerExists(uuid)) { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE uuid='$uuid'") + if (rs!!.next()) { + return rs.getInt("MUTED") == 1 + } + } catch (exc: SQLException) { + + } + + } + return false + } + + fun unban(uuid: UUID) { + if (playerExists(uuid)) Main.mysql.update("UPDATE bans SET BANNED='0' WHERE uuid='$uuid'") + } + + fun unmute(uuid: UUID) { + if (playerExists(uuid)) { + Main.mysql.update("UPDATE bans SET MUTED='0' WHERE uuid='$uuid'") + } + } + + fun getReasonString(uuid: UUID): String { + if (playerExists(uuid)) { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE uuid='$uuid'") + if (rs!!.next()) { + return rs.getString("REASON") + } + } catch (exc: SQLException) { + + } + + } + return "Nothing" + } + + fun sendNotify(Type: String, BannedName: String, TeamName: String, Grund: String?) { + if (Type.toUpperCase() == "BAN") { + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.notify")) { + all.sendMessage(Main.prefix + "§e§l" + BannedName + " §7wurde von §c§l" + TeamName + " §cgebannt §7wegen §a" + Grund) + } + } + } + if (Type.toUpperCase() == "IPBAN") { + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.notify")) { + all.sendMessage(Main.prefix + "§7Die IP §e§l" + BannedName + " §7wurde von §c§l" + TeamName + " §cgebannt §7wegen §a" + Grund) + } + } + } + if (Type.toUpperCase() == "MUTE") { + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")) { + all.sendMessage(Main.prefix + "§e§l" + BannedName + " §7wurde von §c§l" + TeamName + " §cgemutet §7wegen §a" + Grund) + } + } + } + if (Type.toUpperCase() == "KICK") { + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")) { + all.sendMessage(Main.prefix + "§e§l" + BannedName + " §7wurde von §c§l" + TeamName + " §cgekickt §7wegen §a" + Grund) + } + } + } + if (Type.toUpperCase() == "UNBAN") { + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")) { + all.sendMessage(Main.prefix + "§c§l" + TeamName + " §7hat §e§l" + BannedName + " §aentbannt") + } + } + } + if (Type.toUpperCase() == "UNBANIP") { + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")) { + all.sendMessage(Main.prefix + "§c§l" + TeamName + " §7hat die IP-Adresse §e§l" + BannedName + " §aentbannt") + } + } + } + if (Type.toUpperCase() == "UNMUTE") { + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")) { + all.sendMessage(Main.prefix + "§c§l" + TeamName + " §7hat §e§l" + BannedName + " §aentmutet") + } + } + } + if (Type.toUpperCase() == "REPORT") { + for (all in ProxyServer.getInstance().getPlayers()) { + if (all.hasPermission("professionalbans.notify") || all.hasPermission("professionalbans.*")) { + all.sendMessage(Main.prefix + "§c§l" + TeamName + " §7hat §e§l" + BannedName + " §7wegen §a" + Grund + " §7gemeldet") + } + } + } + } + + fun getBans(uuid: UUID): Int { + if (playerExists(uuid)) { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE uuid='$uuid'") + if (rs!!.next()) { + return rs.getInt("BANS") + } + } catch (exc: SQLException) { + + } + + } + return 0 + } + + fun setBans(uuid: UUID, Bans: Int) { + if (playerExists(uuid)) { + Main.mysql.update("UPDATE bans SET BANS='$Bans' WHERE uuid='$uuid'") + } + } + + fun getMutes(uuid: UUID): Int { + if (playerExists(uuid)) { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE uuid='$uuid'") + if (rs!!.next()) { + return rs.getInt("MUTES") + } + } catch (exc: SQLException) { + + } + + } + return 0 + } + + fun setMutes(uuid: UUID, Mutes: Int) { + if (playerExists(uuid)) { + Main.mysql.update("UPDATE bans SET MUTES='$Mutes' WHERE uuid='$uuid'") + } + } + + fun countReasons(): Int? { + try { + val rs = Main.mysql.query("SELECT * FROM reasons") + var i = 0 + while (rs!!.next()) { + i++ + } + return i + } catch (exc: SQLException) { + + } + + return null + } + + fun getReasonByID(Reason: Int): String { + try { + val rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='$Reason'") ?: return "Nothing" + if (rs.next()) { + return rs.getString("REASON") + } + } catch (exc: SQLException) { + + } + + return "Nothing" + } + + fun getReasonTime(ID: Int): Int? { + try { + val rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='$ID'") + if (rs!!.next()) { + return rs.getInt("TIME") + } + } catch (exc: SQLException) { + + } + + return null + } + + fun isBanReason(ID: Int): Boolean { + try { + val rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='$ID'") + if (rs!!.next()) { + return rs.getInt("TYPE") == 0 + } + } catch (exc: SQLException) { + + } + + return false + } + + fun getReasonBans(ReasonID: Int): Int? { + try { + val rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='$ReasonID'") + if (rs!!.next()) { + return rs.getInt("BANS") + } + } catch (exc: SQLException) { + + } + + return null + } + + fun setReasonBans(ReasonID: Int, Bans: Int) { + Main.mysql.update("UPDATE reasons SET BANS='$Bans' WHERE ID='$ReasonID'") + } + + fun hasExtraPerms(ReasonID: Int): Boolean { + try { + val rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='$ReasonID'") + if (rs!!.next()) { + return rs.getString("PERMS") != "null" + } + } catch (exc: SQLException) { + + } + + return false + } + + fun getExtraPerms(ReasonID: Int): String? { + try { + val rs = Main.mysql.query("SELECT * FROM reasons WHERE ID='$ReasonID'") + if (rs!!.next()) { + return rs.getString("PERMS") + } + } catch (exc: SQLException) { + + } + + return null + } + + + fun webaccountExists(uuid: UUID): Boolean { + try { + val rs = Main.mysql.query("SELECT * FROM accounts WHERE UUID='$uuid'") ?: return false + if (rs.next()) { + return rs.getString("UUID") != null + } + + } catch (exc: SQLException) { + + } + + return false + + } + + fun createWebAccount(uuid: UUID, Name: String, Rank: Int, PasswordHash: String) { + Main.mysql.update("INSERT INTO accounts(UUID, USERNAME, PASSWORD, RANK, GOOGLE_AUTH, AUTHCODE) " + + "VALUES ('" + uuid + "', '" + Name + "', '" + PasswordHash + "', '" + Rank + "', 'null', 'initialpassword')") + } + + fun deleteWebAccount(uuid: UUID) { + Main.mysql.update("DELETE FROM accounts WHERE UUID='$uuid'") + } + + fun isWebaccountAdmin(uuid: UUID): Boolean { + if (webaccountExists(uuid)) { + try { + val rs = Main.mysql.query("SELECT * FROM accounts WHERE UUID='$uuid'") + if (rs!!.next()) { + return rs.getInt("RANK") == 3 + } + } catch (exc: SQLException) { + + } + + } else { + return false + } + return false + } + + fun hasAuthToken(uuid: UUID): Boolean { + if (webaccountExists(uuid)) { + try { + val rs = Main.mysql.query("SELECT * FROM accounts WHERE UUID='$uuid'") + if (rs!!.next()) { + return rs.getString("AUTHCODE") !== "null" + } + } catch (exc: SQLException) { + + } + + } else { + return false + } + return false + } + + fun getAuthCode(uuid: UUID): String? { + try { + val rs = Main.mysql.query("SELECT * FROM accounts WHERE UUID='$uuid'") + if (rs!!.next()) { + return rs.getString("AUTHCODE") + } + } catch (exc: SQLException) { + + } + + return null + } + + fun updateAuthStatus(uuid: UUID) { + Main.mysql.update("UPDATE accounts SET AUTHSTATUS = 1 WHERE UUID = '$uuid'") + } + + fun createReport(uuid: UUID, ReporterUUID: String, Reason: String, LogID: String?) { + Main.mysql.update("INSERT INTO reports(uuid, REPORTER, TEAM, REASON, LOG, STATUS, CREATED_AT) " + + "VALUES ('" + uuid + "', '" + ReporterUUID + "', 'null', '" + Reason + "', '" + LogID + "', '0', '" + System.currentTimeMillis() + "')") + } + + fun countOpenReports(): Int { + try { + val rs = Main.mysql.query("SELECT * FROM reports WHERE STATUS = 0") + var i = 0 + while (rs!!.next()) { + i++ + } + return i + } catch (exc: SQLException) { + + } + + return 0 + } + + fun getNameByReportID(ReportID: Int): String? { + try { + val rs = Main.mysql.query("SELECT * FROM reports WHERE ID='$ReportID'") + if (rs!!.next()) { + return getNameByUUID(UUID.fromString(rs.getString("UUID"))) + } + } catch (exc: SQLException) { + + } + + return null + } + + fun getReasonByReportID(ReportID: Int): String? { + try { + val rs = Main.mysql.query("SELECT * FROM reports WHERE ID='$ReportID'") + if (rs!!.next()) { + return rs.getString("REASON") + } + } catch (exc: SQLException) { + + } + + return null + } + + fun setReportDone(ID: Int) { + Main.mysql.update("UPDATE reports SET STATUS = 1 WHERE ID = $ID") + } + + fun setReportTeamUUID(ID: Int, UUID: String) { + Main.mysql.update("UPDATE reports SET TEAM = '$UUID' WHERE ID = $ID") + } + + fun isChatlogAvailable(ID: Int): Boolean { + try { + val rs = Main.mysql.query("SELECT * FROM reports WHERE ID='$ID'") + if (rs!!.next()) { + return rs.getString("LOG") !== "null" + } + } catch (exc: SQLException) { + + } + + return false + } + + fun getChatlogbyReportID(ReportID: Int): String? { + try { + val rs = Main.mysql.query("SELECT * FROM reports WHERE ID='$ReportID'") + if (rs!!.next()) { + return rs.getString("LOG") + } + } catch (exc: SQLException) { + + } + + return null + } + + private fun updateLastLogin(uuid: UUID) = Main.mysql.update("UPDATE bans SET LASTLOGIN = '" + System.currentTimeMillis() + "' WHERE uuid = '" + uuid + "'") + + fun getLastLogin(uuid: UUID): String { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='$uuid'") + if (rs!!.next()) { + return rs.getString("LASTLOGIN") + } + } catch (exc: SQLException) { + + } + + return "None" + } + + fun getFirstLogin(uuid: UUID): String { + try { + val rs = Main.mysql.query("SELECT * FROM bans WHERE UUID='$uuid'") ?: return "none" + if (rs.next()) { + return rs.getString("FIRSTLOGIN") + } + } catch (exc: SQLException) { + + } + + return "none" + } + + fun formatTimestamp(timestamp: Long): String { + val date = Date(timestamp) + val jdf = SimpleDateFormat("dd.MM.yyyy HH:mm") + return jdf.format(date) + } + +} \ 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 new file mode 100644 index 0000000..8e9bd02 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/utils/Functions.kt @@ -0,0 +1,20 @@ +package de.tutorialwork.utils + +import de.tutorialwork.main.Main +import net.md_5.bungee.api.CommandSender +import java.util.* + + +fun UUID.exists(sender: CommandSender): Unit? { + val exists = BanManager.playerExists(this) + return if (exists) sender.sendMessage(Main.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.sendMessage(Main.prefix + "§cDieser Spieler wurde nicht gefunden") + null + } +} diff --git a/src/main/kotlin/de/tutorialwork/utils/IPManager.kt b/src/main/kotlin/de/tutorialwork/utils/IPManager.kt new file mode 100644 index 0000000..40ea83a --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/utils/IPManager.kt @@ -0,0 +1,240 @@ +package de.tutorialwork.utils + +import de.tutorialwork.main.Main +import java.sql.SQLException +import java.util.* + +object IPManager { + + //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)); + + fun ipExists(IP: String): Boolean { + try { + + val rs = Main.mysql.query("SELECT * FROM ips WHERE IP='$IP'") + if (rs!!.next()) { + return rs.getString("IP") != null + } + + } catch (exc: SQLException) { + + } + + return false + + } + + fun insertIP(IP: String, uuid: UUID) { + if (!ipExists(IP)) { + Main.mysql.update("INSERT INTO ips(IP, USED_BY, USED_AT, BANNED, REASON, END, TEAMUUID, BANS) " + + "VALUES ('" + IP + "', '" + uuid + "', '" + System.currentTimeMillis() + "', '0', 'null', 'null', 'null', '0')") + } else { + updateIPInfos(IP, uuid) + } + } + + private fun updateIPInfos(IP: String, newUUID: UUID) { + if (ipExists(IP)) { + Main.mysql.update("UPDATE ips SET USED_BY = '" + newUUID + "', USED_AT='" + System.currentTimeMillis() + "' WHERE IP='" + IP + "'") + } + } + + fun ban(IP: String, GrundID: Int, TeamUUID: String) { + val current = System.currentTimeMillis() + val end = current + BanManager.getReasonTime(GrundID)!! * 60000L + if (BanManager.getReasonTime(GrundID) == -1) { + //Perma Ban + Main.mysql.update("UPDATE ips SET BANNED='1', REASON='" + BanManager.getReasonByID(GrundID) + "', END='-1', TEAMUUID='" + TeamUUID + "' WHERE IP='" + IP + "'") + } else { + //Temp Ban + Main.mysql.update("UPDATE ips SET BANNED='1', REASON='" + BanManager.getReasonByID(GrundID) + "', END='" + end + "', TEAMUUID='" + TeamUUID + "' WHERE IP='" + IP + "'") + } + } + + + fun isBanned(IP: String): Boolean { + if (ipExists(IP)) { + try { + val rs = Main.mysql.query("SELECT * FROM ips WHERE IP='$IP'") + if (rs!!.next()) { + return rs.getInt("BANNED") == 1 + } + } catch (exc: SQLException) { + + } + + } + return false + } + + fun getReasonString(IP: String): String? { + if (ipExists(IP)) { + try { + val rs = Main.mysql.query("SELECT * FROM ips WHERE IP='$IP'") + if (rs!!.next()) { + return rs.getString("REASON") + } + } catch (exc: SQLException) { + + } + + } + return null + } + + fun getRAWEnd(IP: String): Long? { + if (ipExists(IP)) { + try { + val rs = Main.mysql.query("SELECT * FROM ips WHERE IP='$IP'") + if (rs!!.next()) { + return rs.getLong("END") + } + } catch (exc: SQLException) { + + } + + } + return null + } + + fun getEnd(UUID: String): String { + val uhrzeit = System.currentTimeMillis() + val end = getRAWEnd(UUID)!! + + var millis = end - uhrzeit + + var sekunden = 0L + var minuten = 0L + var stunden = 0L + var tage = 0L + while (millis > 1000L) { + millis -= 1000L + sekunden += 1L + } + while (sekunden > 60L) { + sekunden -= 60L + minuten += 1L + } + while (minuten > 60L) { + minuten -= 60L + stunden += 1L + } + while (stunden > 24L) { + stunden -= 24L + tage += 1L + } + return if (tage != 0L) { + "§a$tage §7Tag(e) §a$stunden §7Stunde(n) §a$minuten §7Minute(n)" + } else if (tage == 0L && stunden != 0L) { + "§a$stunden §7Stunde(n) §a$minuten §7Minute(n) §a$sekunden §7Sekunde(n)" + } else if (tage == 0L && stunden == 0L && minuten != 0L) { + "§a$minuten §7Minute(n) §a$sekunden §7Sekunde(n)" + } else if (tage == 0L && stunden == 0L && minuten == 0L && sekunden != 0L) { + "§a$sekunden §7Sekunde(n)" + } else { + "§4Fehler in der Berechnung!" + } + //Alter Code + //return "§a" + tage + " §7Tag(e) §a" + stunden + " §7Stunde(n) §a" + minuten + " §7Minute(n) §a" + sekunden + " §7Sekunde(n)"; + } + + fun unban(IP: String) { + if (ipExists(IP)) { + Main.mysql.update("UPDATE ips SET BANNED='0' WHERE IP='$IP'") + } + } + + fun isVPN(IP: String): Boolean { + if (IP != "127.0.0.1") { + if (Main.APIKey != null) { + var json = Main.callURL("http://proxycheck.io/v2/" + IP + "?key=" + Main.APIKey) + json = json.replace("{\n" + + " \"status\": \"ok\",\n" + + " \"" + IP + "\": {\n" + + " \"proxy\": \"", "") + json = json.replace("\"\n" + + " }\n" + + "}", "") + return json == "yes" + } else { + var json = Main.callURL("http://proxycheck.io/v2/$IP?key=318n07-0o7054-y9y82a-75o3hr") + json = json.replace("{\n" + + " \"status\": \"ok\",\n" + + " \"" + IP + "\": {\n" + + " \"proxy\": \"", "") + json = json.replace("\"\n" + + " }\n" + + "}", "") + return json == "yes" + } + } else { + return false + } + } + + fun getIPFromPlayer(uuid: UUID): String { + try { + val rs = Main.mysql.query("SELECT * FROM ips WHERE USED_BY='$uuid'") ?: return "" + if (rs.next()) { + return rs.getString("IP") + } + } catch (exc: SQLException) { + + } + return "" + } + + fun getPlayerFromIP(IP: String): UUID? { + try { + val rs = Main.mysql.query("SELECT * FROM ips WHERE IP='$IP'") + if (rs!!.next()) { + return UUID.fromString(rs.getString("USED_BY")) + } + } catch (exc: SQLException) { + + } + + return null + } + + fun getBans(IP: String): Int? { + if (ipExists(IP)) { + try { + val rs = Main.mysql.query("SELECT * FROM ips WHERE IP='$IP'") + if (rs!!.next()) { + return rs.getInt("BANS") + } + } catch (exc: SQLException) { + + } + + } + return null + } + + private fun setBans(IP: String, Bans: Int) { + if (ipExists(IP)) { + Main.mysql.update("UPDATE ips SET BANS='$Bans' WHERE IP='$IP'") + } + } + + fun addBan(IP: String) { + setBans(IP, getBans(IP)!! + 1) + } + + fun getLastUseLong(IP: String): Long { + if (ipExists(IP)) { + try { + val rs = Main.mysql.query("SELECT * FROM ips WHERE IP='$IP'") + if (rs!!.next()) { + return java.lang.Long.valueOf(rs.getString("USED_AT")) + } + } catch (exc: SQLException) { + + } + + } + return 0 + } + +} \ No newline at end of file diff --git a/src/de/tutorialwork/utils/LogManager.java b/src/main/kotlin/de/tutorialwork/utils/LogManager.kt similarity index 67% rename from src/de/tutorialwork/utils/LogManager.java rename to src/main/kotlin/de/tutorialwork/utils/LogManager.kt index fa5ef85..02c2851 100644 --- a/src/de/tutorialwork/utils/LogManager.java +++ b/src/main/kotlin/de/tutorialwork/utils/LogManager.kt @@ -1,8 +1,8 @@ -package de.tutorialwork.utils; +package de.tutorialwork.utils -import de.tutorialwork.main.Main; +import de.tutorialwork.main.Main -public class LogManager { +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) @@ -13,9 +13,9 @@ public class LogManager { // //UUID/BY_UUID = UUID des Spielers, null = keine Spieler verfügbar, "KONSOLE" = Befehl über Konsole ausgeführt - public static void createEntry(String UUID, String ByUUID, String Action, String Note){ - Main.mysql.update("INSERT INTO log(UUID, BYUUID, ACTION, NOTE, DATE) " + - "VALUES ('" + UUID + "', '" + ByUUID + "', '" + Action + "', '" + Note + "', '" + System.currentTimeMillis() + "')"); + fun createEntry(uuid: String, ByUUID: String?, Action: String, Note: String?) { + Main.mysql.update("INSERT INTO log(uuid, BYUUID, ACTION, NOTE, DATE) " + + "VALUES ('" + uuid + "', '" + ByUUID + "', '" + Action + "', '" + Note + "', '" + 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 new file mode 100644 index 0000000..1af42fe --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/utils/MySQLConnect.kt @@ -0,0 +1,76 @@ +package de.tutorialwork.utils + +import de.tutorialwork.console +import de.tutorialwork.main.Main +import java.sql.Connection +import java.sql.DriverManager +import java.sql.ResultSet +import java.sql.SQLException + +class MySQLConnect(host: String, database: String, user: String, password: String) { + + private var con: Connection? = null + + init { + HOST = host + DATABASE = database + USER = user + PASSWORD = password + + connect() + } + + private fun connect() { + try { + con = DriverManager.getConnection("jdbc:mysql://$HOST:3306/$DATABASE?autoReconnect=true", USER, PASSWORD) + console.sendMessage(Main.prefix + "§aDie Verbindung mit der MySQL Datenbank wurde erfolgreich hergestellt") + } catch (e: SQLException) { + console.sendMessage(Main.prefix + "§cDie Verbindung mit der MySQL Datenbank ist fehlgeschlagen: §4" + e.message) + } + + } + + fun close() { + try { + if (con != null) { + con!!.close() + } + } catch (e: SQLException) { + } + + } + + 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 + + try { + val st = con!!.createStatement() + rs = st.executeQuery(qry) + } catch (e: SQLException) { + connect() + System.err.println(e) + } + + return rs + } + + companion object { + + 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/UUIDFetcher.kt b/src/main/kotlin/de/tutorialwork/utils/UUIDFetcher.kt new file mode 100644 index 0000000..b483925 --- /dev/null +++ b/src/main/kotlin/de/tutorialwork/utils/UUIDFetcher.kt @@ -0,0 +1,36 @@ +package de.tutorialwork.utils + +import com.google.gson.JsonParser +import java.io.IOException +import java.net.URL +import java.util.* + +object UUIDFetcher { + private val uuidCache = mutableMapOf() + + fun getUUID(username: String): UUID? { + if (uuidCache.containsKey(username)) return uuidCache[username] + try { + val url = URL("https://api.mojang.com/users/profiles/minecraft/$username") + val stream = url.openStream() + + val result = stream.reader().readText() + + + val element = JsonParser().parse(result) + val obj = element.asJsonObject + var api = obj.get("id").toString() + .substring(1) + api = api.substring(0, api.length - 1) + val sbu = StringBuffer(api) + sbu.insert(8, "-").insert(13, "-").insert(18, "-").insert(23, "-") + val uuid = UUID.fromString(sbu.toString()) + uuidCache[username] = uuid + return uuid + } catch (localIOException: IOException) { + } catch (localIOException: IllegalStateException) { + } + + return null + } +} \ No newline at end of file diff --git a/src/plugin.yml b/src/main/resources/plugin.yml similarity index 100% rename from src/plugin.yml rename to src/main/resources/plugin.yml