diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 67cd9d6..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,143 +0,0 @@
-# Created by https://www.gitignore.io/api/java,linux,gradle,intellij
-# Edit at https://www.gitignore.io/?templates=java,linux,gradle,intellij
-
-### Intellij ###
-# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
-# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
-
-# User-specific stuff
-.idea/**/workspace.xml
-.idea/**/tasks.xml
-.idea/**/usage.statistics.xml
-.idea/**/dictionaries
-.idea/**/shelf
-
-# Generated files
-.idea/**/contentModel.xml
-
-# Sensitive or high-churn files
-.idea/**/dataSources/
-.idea/**/dataSources.ids
-.idea/**/dataSources.local.xml
-.idea/**/sqlDataSources.xml
-.idea/**/dynamic.xml
-.idea/**/uiDesigner.xml
-.idea/**/dbnavigator.xml
-
-# Gradle
-.idea/**/gradle.xml
-.idea/**/libraries
-
-# Gradle and Maven with auto-import
-# When using Gradle or Maven with auto-import, you should exclude module files,
-# since they will be recreated, and may cause churn. Uncomment if using
-# auto-import.
-# .idea/modules.xml
-# .idea/*.iml
-# .idea/modules
-
-# CMake
-cmake-build-*/
-
-# Mongo Explorer plugin
-.idea/**/mongoSettings.xml
-
-# File-based project format
-*.iws
-
-# IntelliJ
-out/
-
-# mpeltonen/sbt-idea plugin
-.idea_modules/
-
-# JIRA plugin
-atlassian-ide-plugin.xml
-
-# Cursive Clojure plugin
-.idea/replstate.xml
-
-# Crashlytics plugin (for Android Studio and IntelliJ)
-com_crashlytics_export_strings.xml
-crashlytics.properties
-crashlytics-build.properties
-fabric.properties
-
-# Editor-based Rest Client
-.idea/httpRequests
-
-# Android studio 3.1+ serialized cache file
-.idea/caches/build_file_checksums.ser
-
-### Intellij Patch ###
-# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
-
-# *.iml
-# modules.xml
-# .idea/misc.xml
-# *.ipr
-
-# Sonarlint plugin
-.idea/sonarlint
-
-### Java ###
-# Compiled class file
-*.class
-
-# Log file
-*.log
-
-# BlueJ files
-*.ctxt
-
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
-
-# Package Files #
-*.jar
-*.war
-*.nar
-*.ear
-*.zip
-*.tar.gz
-*.rar
-
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
-
-### Linux ###
-*~
-
-# temporary files which can be created if a process still has a handle open of a deleted file
-.fuse_hidden*
-
-# KDE directory preferences
-.directory
-
-# Linux trash folder which might appear on any partition or disk
-.Trash-*
-
-# .nfs files are created when an open file is removed but is still being accessed
-.nfs*
-
-### Gradle ###
-.gradle
-build/
-bin/
-
-# Ignore Gradle GUI config
-gradle-app.setting
-
-# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
-!gradle-wrapper.jar
-
-# Cache of project
-.gradletasknamecache
-
-# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
-# gradle/wrapper/gradle-wrapper.properties
-
-### Gradle Patch ###
-**/build/
-
-# End of https://www.gitignore.io/api/java,linux,gradle,intellij
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100644
index 69ba39f..0000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- GETTERS_AND_SETTERS
- KEEP
-
-
- DEPENDENT_METHODS
- BREADTH_FIRST
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
deleted file mode 100644
index 79ee123..0000000
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index fba829b..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index 15a15b2..0000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 3e68e4d..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
- Manifest
-
-
- Spelling
-
-
-
-
- SpellCheckingInspection
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index aab47ff..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/ModuleLoader.main.iml b/.idea/modules/ModuleLoader.main.iml
deleted file mode 100644
index 50a1428..0000000
--- a/.idea/modules/ModuleLoader.main.iml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/ModuleLoader.test.iml b/.idea/modules/ModuleLoader.test.iml
deleted file mode 100644
index b9fa95c..0000000
--- a/.idea/modules/ModuleLoader.test.iml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index ab48fcd..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-language: java
-
-jdk:
- - openjdk8
- - oraclejdk8
diff --git a/LICENSE.txt b/LICENSE.txt
deleted file mode 100644
index 3bbbc1e..0000000
--- a/LICENSE.txt
+++ /dev/null
@@ -1,116 +0,0 @@
-CC0 1.0 Universal
-
-Statement of Purpose
-
-The laws of most jurisdictions throughout the world automatically confer
-exclusive Copyright and Related Rights (defined below) upon the creator and
-subsequent owner(s) (each and all, an "owner") of an original work of
-authorship and/or a database (each, a "Work").
-
-Certain owners wish to permanently relinquish those rights to a Work for the
-purpose of contributing to a commons of creative, cultural and scientific
-works ("Commons") that the public can reliably and without fear of later
-claims of infringement build upon, modify, incorporate in other works, reuse
-and redistribute as freely as possible in any form whatsoever and for any
-purposes, including without limitation commercial purposes. These owners may
-contribute to the Commons to promote the ideal of a free culture and the
-further production of creative, cultural and scientific works, or to gain
-reputation or greater distribution for their Work in part through the use and
-efforts of others.
-
-For these and/or other purposes and motivations, and without any expectation
-of additional consideration or compensation, the person associating CC0 with a
-Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
-and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
-and publicly distribute the Work under its terms, with knowledge of his or her
-Copyright and Related Rights in the Work and the meaning and intended legal
-effect of CC0 on those rights.
-
-1. Copyright and Related Rights. A Work made available under CC0 may be
-protected by copyright and related or neighboring rights ("Copyright and
-Related Rights"). Copyright and Related Rights include, but are not limited
-to, the following:
-
- i. the right to reproduce, adapt, distribute, perform, display, communicate,
- and translate a Work;
-
- ii. moral rights retained by the original author(s) and/or performer(s);
-
- iii. publicity and privacy rights pertaining to a person's image or likeness
- depicted in a Work;
-
- iv. rights protecting against unfair competition in regards to a Work,
- subject to the limitations in paragraph 4(a), below;
-
- v. rights protecting the extraction, dissemination, use and reuse of data in
- a Work;
-
- vi. database rights (such as those arising under Directive 96/9/EC of the
- European Parliament and of the Council of 11 March 1996 on the legal
- protection of databases, and under any national implementation thereof,
- including any amended or successor version of such directive); and
-
- vii. other similar, equivalent or corresponding rights throughout the world
- based on applicable law or treaty, and any national implementations thereof.
-
-2. Waiver. To the greatest extent permitted by, but not in contravention of,
-applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
-unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
-and Related Rights and associated claims and causes of action, whether now
-known or unknown (including existing as well as future claims and causes of
-action), in the Work (i) in all territories worldwide, (ii) for the maximum
-duration provided by applicable law or treaty (including future time
-extensions), (iii) in any current or future medium and for any number of
-copies, and (iv) for any purpose whatsoever, including without limitation
-commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
-the Waiver for the benefit of each member of the public at large and to the
-detriment of Affirmer's heirs and successors, fully intending that such Waiver
-shall not be subject to revocation, rescission, cancellation, termination, or
-any other legal or equitable action to disrupt the quiet enjoyment of the Work
-by the public as contemplated by Affirmer's express Statement of Purpose.
-
-3. Public License Fallback. Should any part of the Waiver for any reason be
-judged legally invalid or ineffective under applicable law, then the Waiver
-shall be preserved to the maximum extent permitted taking into account
-Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
-is so judged Affirmer hereby grants to each affected person a royalty-free,
-non transferable, non sublicensable, non exclusive, irrevocable and
-unconditional license to exercise Affirmer's Copyright and Related Rights in
-the Work (i) in all territories worldwide, (ii) for the maximum duration
-provided by applicable law or treaty (including future time extensions), (iii)
-in any current or future medium and for any number of copies, and (iv) for any
-purpose whatsoever, including without limitation commercial, advertising or
-promotional purposes (the "License"). The License shall be deemed effective as
-of the date CC0 was applied by Affirmer to the Work. Should any part of the
-License for any reason be judged legally invalid or ineffective under
-applicable law, such partial invalidity or ineffectiveness shall not
-invalidate the remainder of the License, and in such case Affirmer hereby
-affirms that he or she will not (i) exercise any of his or her remaining
-Copyright and Related Rights in the Work or (ii) assert any associated claims
-and causes of action with respect to the Work, in either case contrary to
-Affirmer's express Statement of Purpose.
-
-4. Limitations and Disclaimers.
-
- a. No trademark or patent rights held by Affirmer are waived, abandoned,
- surrendered, licensed or otherwise affected by this document.
-
- b. Affirmer offers the Work as-is and makes no representations or warranties
- of any kind concerning the Work, express, implied, statutory or otherwise,
- including without limitation warranties of title, merchantability, fitness
- for a particular purpose, non infringement, or the absence of latent or
- other defects, accuracy, or the present or absence of errors, whether or not
- discoverable, all to the greatest extent permissible under applicable law.
-
- c. Affirmer disclaims responsibility for clearing rights of other persons
- that may apply to the Work or any use thereof, including without limitation
- any person's Copyright and Related Rights in the Work. Further, Affirmer
- disclaims responsibility for obtaining any necessary consents, permissions
- or other rights required for any use of the Work.
-
- d. Affirmer understands and acknowledges that Creative Commons is not a
- party to this document and has no duty or obligation with respect to this
- CC0 or use of the Work.
-
-For more information, please see
-
\ No newline at end of file
diff --git a/ModuleLoader.iml b/ModuleLoader.iml
deleted file mode 100644
index 558676c..0000000
--- a/ModuleLoader.iml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
deleted file mode 100644
index a1ece9c..0000000
--- a/build.gradle
+++ /dev/null
@@ -1,51 +0,0 @@
-buildscript {
- repositories {
- jcenter()
- }
- dependencies {
- classpath "com.github.jengelman.gradle.plugins:shadow:4.0.2"
- }
-}
-
-apply plugin: "com.github.johnrengelman.shadow"
-apply plugin: "java"
-
-repositories {
- jcenter()
- maven { url "https://jitpack.io" }
-
- maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
- maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
-}
-
-dependencies {
- implementation "com.github.RedstonerServer:CommandManager:v1"
- implementation "com.github.RedstonerServer:ChatAPI:v1"
-
- compile group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.11.1'
-
- compileOnly 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
-}
-
-jar {
- manifest {
- attributes "Class-Path": "../lib/CommandManager.jar ../lib/ChatAPI.jar"
- }
-}
-
-task sourceJar(type: Jar, dependsOn: classes) {
- classifier 'sources'
- from sourceSets.main.allSource
-}
-
-sourceSets {
- main {
- resources {
- srcDir 'src/main/java'
- include '**/*.cmd'
-
- srcDir 'src/main/resources'
- include '**/*.yml'
- }
- }
-}
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
deleted file mode 100644
index 28861d2..0000000
Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
deleted file mode 100644
index 115e6ac..0000000
--- a/gradle/wrapper/gradle-wrapper.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
deleted file mode 100755
index cccdd3d..0000000
--- a/gradlew
+++ /dev/null
@@ -1,172 +0,0 @@
-#!/usr/bin/env sh
-
-##############################################################################
-##
-## 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=""
-
-# 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, switch paths to Windows format before running java
-if $cygwin ; 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
deleted file mode 100644
index e95643d..0000000
--- a/gradlew.bat
+++ /dev/null
@@ -1,84 +0,0 @@
-@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=
-
-@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/plugin.yml b/plugin.yml
new file mode 100644
index 0000000..f6362a2
--- /dev/null
+++ b/plugin.yml
@@ -0,0 +1,4 @@
+name: JavaUtils
+version: 1.0.0
+authors: [pepich1851]
+main: com.redstoner.misc.Main
\ No newline at end of file
diff --git a/src/com/redstoner/annotations/AutoRegisterListener.java b/src/com/redstoner/annotations/AutoRegisterListener.java
new file mode 100644
index 0000000..fabdb5f
--- /dev/null
+++ b/src/com/redstoner/annotations/AutoRegisterListener.java
@@ -0,0 +1,15 @@
+package com.redstoner.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/** The auto register annotation, to be put onto Classes that implement listener when you are too lazy to register the events yourself.
+ *
+ * @author Pepich */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Version(major = 1, minor = 0, revision = 1, compatible = 1)
+public @interface AutoRegisterListener
+{}
diff --git a/src/com/redstoner/annotations/Debugable.java b/src/com/redstoner/annotations/Debugable.java
new file mode 100644
index 0000000..be6ec1c
--- /dev/null
+++ b/src/com/redstoner/annotations/Debugable.java
@@ -0,0 +1,14 @@
+package com.redstoner.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/** Debugable annotation, to be added to methods that invoke the Debugger.notifyMethod method for debugging purposes.
+ *
+ * @author Pepich */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Debugable
+{}
diff --git a/src/com/redstoner/annotations/Version.java b/src/com/redstoner/annotations/Version.java
new file mode 100644
index 0000000..52d5145
--- /dev/null
+++ b/src/com/redstoner/annotations/Version.java
@@ -0,0 +1,32 @@
+package com.redstoner.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/** The Version annotation, to be applied to all Classes that are part of the project.
+ *
+ * @author Pepich */
+@Target(ElementType.TYPE)
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Version
+{
+ /** The major indicator of the version. Will be used for compatibility detection.
+ *
+ * @return the major version as an int */
+ int major();
+
+ int minor();
+
+ int revision();
+
+ /** The compatibility part of the version number. Will be used for compatibility detection.
+ * Set to -1 if it is supposed to be always compatible.
+ * Defaults to 1.
+ *
+ * @return the smallest compatible version as an int. */
+ int compatible() default 1;
+}
diff --git a/src/com/redstoner/coremods/debugger/Debugger.java b/src/com/redstoner/coremods/debugger/Debugger.java
new file mode 100644
index 0000000..8aa7ef9
--- /dev/null
+++ b/src/com/redstoner/coremods/debugger/Debugger.java
@@ -0,0 +1,172 @@
+package com.redstoner.coremods.debugger;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Listener;
+
+import com.nemez.cmdmgr.Command;
+import com.nemez.cmdmgr.CommandManager;
+import com.redstoner.annotations.Debugable;
+import com.redstoner.annotations.Version;
+import com.redstoner.misc.Main;
+import com.redstoner.misc.Utils;
+import com.redstoner.modules.CoreModule;
+
+/** The Debugger class, first Module to be loaded, responsible for debug interactions such as subscribing to method calls and getting field values on runtime.
+ *
+ * @author Pepich */
+@Version(major = 1, minor = 0, revision = 4, compatible = -1)
+public final class Debugger implements CoreModule, Listener
+{
+ private static Debugger instance;
+ private static HashMap> subs;
+
+ private Debugger()
+ {
+ subs = new HashMap<>();
+ }
+
+ public static void init()
+ {
+ if (instance == null)
+ instance = new Debugger();
+ CommandManager.registerCommand(instance.getCommandString(), instance, Main.plugin);
+ }
+
+ public static void notifyMethod(Object... params)
+ {
+ Exception e = new Exception();
+ String method = e.getStackTrace()[1].getMethodName();
+ String classname = e.getStackTrace()[1].getClassName();
+ for (Player p : Bukkit.getOnlinePlayers())
+ if (subs.containsKey(p))
+ {
+ boolean subscribed = false;
+ for (String s : subs.get(p))
+ {
+ if (s.equals(classname + "." + method))
+ {
+ subscribed = true;
+ break;
+ }
+ }
+ if (subscribed)
+ {
+ StringBuilder sb = new StringBuilder(method);
+ sb.append("(");
+ if (params != null)
+ {
+ for (Object obj : params)
+ {
+ if (obj == null)
+ sb.append("NULL");
+ else
+ sb.append(obj.toString());
+ sb.append(", ");
+ }
+ sb.delete(sb.length() - 2, sb.length());
+ }
+ sb.append(")\nTypes:\n");
+ int i = 0;
+ for (Object obj : params)
+ sb.append(i++ + ": " + (obj == null ? "NULL" : obj.getClass().getName()) + "\n");
+ p.sendMessage(sb.toString());
+ }
+ }
+ CommandSender p = Bukkit.getConsoleSender();
+ if (subs.containsKey(p))
+ {
+ boolean subscribed = false;
+ for (String s : subs.get(p))
+ {
+ if (s.equals(classname + "." + method))
+ {
+ subscribed = true;
+ break;
+ }
+ }
+ if (subscribed)
+ {
+ StringBuilder sb = new StringBuilder(method);
+ sb.append("(");
+ if (params != null)
+ {
+ for (Object obj : params)
+ {
+ if (obj == null)
+ sb.append("NULL");
+ else
+ sb.append(obj.toString());
+ sb.append(", ");
+ }
+ sb.delete(sb.length() - 2, sb.length());
+ }
+ sb.append(")\nTypes:\n");
+ int i = 0;
+ for (Object obj : params)
+ sb.append(i++ + ": " + (obj == null ? "NULL" : obj.getClass().getName()) + "\n");
+ p.sendMessage(sb.toString());
+ }
+ }
+ }
+
+ // @noformat
+ @Override
+ public String getCommandString()
+ {
+ return "command debugger {\n" +
+ " subscribe [string:classname] [string:methodname] {\n" +
+ " help Subscribes to all calls of the corresponding debugable method.;\n" +
+ " perm jutils.debugger.subscribe;\n" +
+ " run subscribe classname methodname;\n" +
+ " }\n" +
+ "}";
+ }
+ // @format
+
+ @Command(hook = "subscribe")
+ @Debugable
+ public boolean subscribeCommand(CommandSender sender, String classname, String methodname)
+ {
+ Utils.sendMessage(sender, null, "Debugger is currently disabled!");
+ return true;
+ // Class> clazz = null;
+ // try
+ // {
+ // clazz = Class.forName(classname);
+ // }
+ // catch (ClassNotFoundException e)
+ // {
+ // e.printStackTrace();
+ // // TODO: Add error message
+ // return true;
+ // }
+ // boolean found = false;
+ // for (Method m : clazz.getMethods())
+ // {
+ // if (m.getName().matches(methodname))
+ // {
+ // if (m.isAnnotationPresent(Debugable.class))
+ // {
+ // found = true;
+ // if (!subs.containsKey(sender))
+ // subs.put(sender, new ArrayList());
+ // subs.get(sender).add(classname + "." + methodname);
+ // break;
+ // }
+ // }
+ // }
+ // if (!found)
+ // {
+ // System.err.println("2");
+ // // TODO: Add error message
+ // return true;
+ // }
+ // Utils.sendMessage(sender, null, "YAY");
+ // return true;
+ }
+}
diff --git a/src/com/redstoner/coremods/moduleLoader/ModuleLoader.java b/src/com/redstoner/coremods/moduleLoader/ModuleLoader.java
new file mode 100644
index 0000000..5a305b1
--- /dev/null
+++ b/src/com/redstoner/coremods/moduleLoader/ModuleLoader.java
@@ -0,0 +1,191 @@
+package com.redstoner.coremods.moduleLoader;
+
+import java.util.ArrayList;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.event.Listener;
+
+import com.nemez.cmdmgr.Command;
+import com.nemez.cmdmgr.Command.AsyncType;
+import com.nemez.cmdmgr.CommandManager;
+import com.redstoner.annotations.AutoRegisterListener;
+import com.redstoner.annotations.Debugable;
+import com.redstoner.annotations.Version;
+import com.redstoner.coremods.debugger.Debugger;
+import com.redstoner.misc.Main;
+import com.redstoner.misc.Utils;
+import com.redstoner.modules.CoreModule;
+import com.redstoner.modules.Module;
+
+/** The module loader, mother of all modules. Responsible for loading and taking care of all modules.
+ *
+ * @author Pepich */
+@Version(major = 1, minor = 3, revision = 2, compatible = -1)
+public final class ModuleLoader implements CoreModule
+{
+ private static ModuleLoader instance;
+ private static final ArrayList modules = new ArrayList();
+
+ private ModuleLoader()
+ {}
+
+ public static void init()
+ {
+ if (instance == null)
+ instance = new ModuleLoader();
+ CommandManager.registerCommand(instance.getCommandString(), instance, Main.plugin);
+ }
+
+ /** This method will add a module to the module list, without enabling it
+ *
+ * @param clazz The class of the module to be added. */
+ @Debugable
+ public static final void addModule(Class extends Module> clazz)
+ {
+ Debugger.notifyMethod(clazz);
+ try
+ {
+ Module module = clazz.newInstance();
+ modules.add(module);
+ }
+ catch (InstantiationException | IllegalAccessException e)
+ {
+ Utils.error("Could not add " + clazz.getName() + " to the list, constructor not accessible.");
+ }
+ }
+
+ /** Call this to enable all not-yet enabled modules that are known to the loader. */
+ @Debugable
+ public static final void enableModules()
+ {
+ Debugger.notifyMethod();
+ for (Module module : modules)
+ {
+ if (module.enabled())
+ continue;
+ try
+ {
+ if (module.enable())
+ {
+ CommandManager.registerCommand(module.getCommandString(), module, Main.plugin);
+ if (module.getClass().isAnnotationPresent(AutoRegisterListener.class)
+ && (module instanceof Listener))
+ {
+ Bukkit.getPluginManager().registerEvents((Listener) module, Main.plugin);
+ }
+ Utils.log("Loaded module " + module.getClass().getName());
+ }
+ else
+ Utils.error("Failed to load module " + module.getClass().getName());
+ }
+ catch (Exception e)
+ {
+ Utils.error("Failed to load module " + module.getClass().getName());
+ }
+ }
+ }
+
+ /** This method enables a specific module. If no module with that name is known to the loader yet it will be added to the list.
+ *
+ * @param clazz The class of the module to be enabled.
+ * @return true, when the module was successfully enabled. */
+ @Debugable
+ public static final boolean enableModule(Class extends Module> clazz)
+ {
+ Debugger.notifyMethod(clazz);
+ for (Module m : modules)
+ {
+ if (m.getClass().equals(clazz))
+ {
+ if (m.enable())
+ {
+ if (m.getClass().isAnnotationPresent(AutoRegisterListener.class) && (m instanceof Listener))
+ {
+ Bukkit.getPluginManager().registerEvents((Listener) m, Main.plugin);
+ }
+ Utils.log("Loaded module " + m.getClass().getName());
+ return true;
+ }
+ else
+ {
+ Utils.error("Failed to load module " + m.getClass().getName());
+ return false;
+ }
+ }
+ }
+ try
+ {
+ Module m = clazz.newInstance();
+ modules.add(m);
+ m.onEnable();
+ if (m.enabled())
+ {
+ if (m.getClass().isAnnotationPresent(AutoRegisterListener.class) && (m instanceof Listener))
+ {
+ Bukkit.getPluginManager().registerEvents((Listener) m, Main.plugin);
+ }
+ Utils.log("Loaded module " + m.getClass().getName());
+ return true;
+ }
+ else
+ {
+ Utils.error("Failed to load module " + m.getClass().getName());
+ return false;
+ }
+ }
+ catch (InstantiationException | IllegalAccessException e)
+ {
+ Utils.error("Could not add " + clazz.getName() + " to the list, constructor not accessible.");
+ return false;
+ }
+ }
+
+ // @noformat
+ @Override
+ public String getCommandString()
+ {
+ return "command modules {\n" +
+ " list{\n" +
+ " help Lists all modules. Color indicates status: §aENABLED §cDISABLED;\n" +
+ " perm jutils.admin;\n" +
+ " run list;\n" +
+ " }\n" +
+ "}";
+ }
+ // @format
+
+ /** This method lists all modules to the specified CommandSender. The modules will be color coded correspondingly to their enabled status.
+ *
+ * @param sender The person to send the info to, usually the issuer of the command or the console sender.
+ * @return true. */
+ @Command(hook = "list", async = AsyncType.ALWAYS)
+ public boolean listModulesCommand(CommandSender sender)
+ {
+ Utils.sendModuleHeader(sender);
+ StringBuilder sb = new StringBuilder("Modules:\n");
+ for (Module m : modules)
+ {
+ String[] classPath = m.getClass().getName().split("\\.");
+ String classname = classPath[classPath.length - 1];
+ sb.append(m.enabled() ? "&a" : "&c");
+ sb.append(classname);
+ sb.append(", ");
+ }
+ sb.delete(sb.length() - 2, sb.length());
+ Utils.sendMessage(sender, " §e", sb.toString(), '&');
+ Utils.sendMessage(sender, " §7", "For more detailed information, consult the debugger.");
+ return true;
+ }
+
+ public static void disableModules()
+ {
+ for (Module module : modules)
+ {
+ if (module.enabled())
+ {
+ module.onDisable();
+ }
+ }
+ }
+}
diff --git a/src/com/redstoner/exceptions/MissingVersionException.java b/src/com/redstoner/exceptions/MissingVersionException.java
new file mode 100644
index 0000000..62032b6
--- /dev/null
+++ b/src/com/redstoner/exceptions/MissingVersionException.java
@@ -0,0 +1,22 @@
+package com.redstoner.exceptions;
+
+import com.redstoner.annotations.Version;
+
+/** To be thrown when a module is not annotated with its version. If this gets thrown, then oh boy, you're in trouble now.
+ *
+ * @author Pepich */
+@Version(major = 1, minor = 0, revision = 0, compatible = -1)
+public class MissingVersionException extends Exception
+{
+ private static final long serialVersionUID = 4940161335512222539L;
+
+ public MissingVersionException()
+ {
+ super();
+ }
+
+ public MissingVersionException(String message)
+ {
+ super(message);
+ }
+}
diff --git a/src/com/redstoner/exceptions/NonSaveableConfigException.java b/src/com/redstoner/exceptions/NonSaveableConfigException.java
new file mode 100644
index 0000000..df33bff
--- /dev/null
+++ b/src/com/redstoner/exceptions/NonSaveableConfigException.java
@@ -0,0 +1,9 @@
+package com.redstoner.exceptions;
+
+public class NonSaveableConfigException extends Exception {
+ private static final long serialVersionUID = -7271481973389455510L;
+
+ public NonSaveableConfigException() {
+ super("This config does not support saving!");
+ }
+}
diff --git a/src/com/redstoner/misc/BroadcastFilter.java b/src/com/redstoner/misc/BroadcastFilter.java
new file mode 100644
index 0000000..1f0ce04
--- /dev/null
+++ b/src/com/redstoner/misc/BroadcastFilter.java
@@ -0,0 +1,14 @@
+package com.redstoner.misc;
+
+import org.bukkit.command.CommandSender;
+
+import com.redstoner.annotations.Version;
+
+/** Classes implementing this interface can be used to define a filter for the Utils.broadcast method for sending a message to more than one, but less than all users.
+ *
+ * @author Pepich */
+@Version(major = 1, minor = 0, revision = 0, compatible = 1)
+public interface BroadcastFilter
+{
+ public boolean sendTo(CommandSender recipient);
+}
diff --git a/src/com/redstoner/misc/JsonManager.java b/src/com/redstoner/misc/JsonManager.java
new file mode 100644
index 0000000..998d137
--- /dev/null
+++ b/src/com/redstoner/misc/JsonManager.java
@@ -0,0 +1,127 @@
+package com.redstoner.misc;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import com.redstoner.annotations.Version;
+
+/** This class provides simple JSON handling, like storing and loading from and to files.
+ *
+ * @author Pepich */
+@Version(major = 1, minor = 0, revision = 1, compatible = -1)
+public class JsonManager
+{
+ private JsonManager()
+ {}
+
+ /** Loads a JSONObject from a file.
+ *
+ * @param source the file to load from.
+ * @return the JSONObject or null if the source does not contain a valid JSONObject. */
+ public static JSONObject getObject(File source)
+ {
+ if (!source.exists())
+ return null;
+ JSONParser parser = new JSONParser();
+ try
+ {
+ FileReader reader = new FileReader(source);
+ Object rawObject = parser.parse(reader);
+ reader.close();
+ JSONObject jsonObject = (JSONObject) rawObject;
+ return jsonObject;
+ }
+ catch (IOException | ParseException e)
+ {}
+ return null;
+ }
+
+ /** Saves a JSONObject to a file. Will create the necessary FileStructure like folders and the file itself.
+ * Note that this operation will be run on a different thread and you do not need to take care of that yourself.
+ *
+ * @param object the JSONObject to save.
+ * @param destination the file to write to. */
+ public static void save(JSONObject object, File destination)
+ {
+ Thread t = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ if (destination.exists())
+ destination.delete();
+ else if (!destination.getParentFile().exists())
+ destination.getParentFile().mkdirs();
+ try
+ {
+ destination.createNewFile();
+ FileWriter writer = new FileWriter(destination);
+ object.writeJSONString(writer);
+ writer.flush();
+ writer.close();
+ }
+ catch (IOException e)
+ {}
+ }
+ });
+ t.start();
+ }
+
+ /** Loads a JSONArray from a file.
+ *
+ * @param source the file to load from.
+ * @return the JSONArray or null if the source does not contain a valid JSONArray. */
+ public static JSONArray getArray(File source)
+ {
+ if (!source.exists())
+ return null;
+ JSONParser parser = new JSONParser();
+ try
+ {
+ Object rawObject = parser.parse(new FileReader(source));
+ JSONArray jsonArray = (JSONArray) rawObject;
+ return jsonArray;
+ }
+ catch (IOException | ParseException e)
+ {}
+ return null;
+ }
+
+ /** Saves a JSONArray to a file. Will create the necessary FileStructure like folders and the file itself.
+ * Note that this operation will be run on a different thread and you do not need to take care of that yourself.
+ *
+ * @param object the JSONArray to save.
+ * @param destination the file to write to. */
+ public static void save(JSONArray array, File destination)
+ {
+ Thread t = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ if (destination.exists())
+ destination.delete();
+ else if (!destination.getParentFile().exists())
+ destination.getParentFile().mkdirs();
+ try
+ {
+ destination.createNewFile();
+ FileWriter writer = new FileWriter(destination);
+ array.writeJSONString(writer);
+ writer.flush();
+ writer.close();
+ }
+ catch (IOException e)
+ {}
+ }
+ });
+ t.start();
+ }
+}
diff --git a/src/com/redstoner/misc/Main.java b/src/com/redstoner/misc/Main.java
new file mode 100644
index 0000000..e7d4707
--- /dev/null
+++ b/src/com/redstoner/misc/Main.java
@@ -0,0 +1,90 @@
+package com.redstoner.misc;
+
+import org.bukkit.plugin.java.JavaPlugin;
+
+import com.redstoner.annotations.Version;
+import com.redstoner.coremods.debugger.Debugger;
+import com.redstoner.coremods.moduleLoader.ModuleLoader;
+import com.redstoner.misc.mysql.MysqlHandler;
+import com.redstoner.modules.abot.Abot;
+import com.redstoner.modules.adminchat.Adminchat;
+import com.redstoner.modules.adminnotes.AdminNotes;
+import com.redstoner.modules.chatalias.Chatalias;
+import com.redstoner.modules.chatgroups.Chatgroups;
+import com.redstoner.modules.check.Check;
+import com.redstoner.modules.cycle.Cycle;
+import com.redstoner.modules.damnspam.DamnSpam;
+import com.redstoner.modules.illumination.Illumination;
+import com.redstoner.modules.imout.Imout;
+import com.redstoner.modules.lagchunks.LagChunks;
+import com.redstoner.modules.loginsecurity.LoginSecurity;
+import com.redstoner.modules.mentio.Mentio;
+import com.redstoner.modules.misc.Misc;
+import com.redstoner.modules.motd.Motd;
+import com.redstoner.modules.nametags.Nametags;
+import com.redstoner.modules.pmtoggle.Pmtoggle;
+import com.redstoner.modules.reports.Reports;
+import com.redstoner.modules.saylol.Saylol;
+import com.redstoner.modules.scriptutils.Scriptutils;
+import com.redstoner.modules.skullclick.SkullClick;
+import com.redstoner.modules.tag.Tag;
+import com.redstoner.modules.vanish.Vanish;
+import com.redstoner.modules.warn.Warn;
+import com.redstoner.modules.webtoken.WebToken;
+
+/** Main class. Duh.
+ *
+ * @author Pepich */
+@Version(major = 1, minor = 4, revision = 1, compatible = -1)
+public class Main extends JavaPlugin
+{
+ public static JavaPlugin plugin;
+
+ @Override
+ public void onEnable()
+ {
+ plugin = this;
+ Debugger.init();
+ ModuleLoader.init();
+ MysqlHandler.init();
+ ModuleLoader.addModule(Abot.class);
+ ModuleLoader.addModule(Adminchat.class);
+ ModuleLoader.addModule(AdminNotes.class);
+ // TODO: ModuleLoader.addModule(BlockplaceMods.class);
+ // TODO: ModuleLoader.addModule(Calc.class);
+ ModuleLoader.addModule(Chatalias.class);
+ ModuleLoader.addModule(Cycle.class);
+ ModuleLoader.addModule(Chatgroups.class);
+ ModuleLoader.addModule(Check.class);
+ ModuleLoader.addModule(DamnSpam.class);
+ // TODO: ModuleLoader.addModule(Friends.class);
+ ModuleLoader.addModule(Illumination.class);
+ // TODO: ModuleLoader.addModule(Imbusy.class);
+ ModuleLoader.addModule(Imout.class);
+ ModuleLoader.addModule(LagChunks.class);
+ ModuleLoader.addModule(LoginSecurity.class);
+ ModuleLoader.addModule(Mentio.class);
+ ModuleLoader.addModule(Misc.class);
+ ModuleLoader.addModule(Motd.class);
+ ModuleLoader.addModule(Nametags.class);
+ ModuleLoader.addModule(Pmtoggle.class);
+ ModuleLoader.addModule(Reports.class);
+ ModuleLoader.addModule(Saylol.class);
+ ModuleLoader.addModule(Scriptutils.class);
+ // TODO: ModuleLoader.addModule(Serversigns.class);
+ // TODO: ModuleLoader.addModule(Signalstrength.class);
+ ModuleLoader.addModule(SkullClick.class);
+ ModuleLoader.addModule(Tag.class);
+ ModuleLoader.addModule(Vanish.class);
+ ModuleLoader.addModule(Warn.class);
+ ModuleLoader.addModule(WebToken.class);
+ // And enable them
+ ModuleLoader.enableModules();
+ }
+
+ @Override
+ public void onDisable()
+ {
+ ModuleLoader.disableModules();
+ }
+}
diff --git a/src/com/redstoner/misc/Utils.java b/src/com/redstoner/misc/Utils.java
new file mode 100644
index 0000000..8973b86
--- /dev/null
+++ b/src/com/redstoner/misc/Utils.java
@@ -0,0 +1,198 @@
+package com.redstoner.misc;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.redstoner.annotations.Debugable;
+import com.redstoner.annotations.Version;
+import com.redstoner.coremods.debugger.Debugger;
+
+import net.md_5.bungee.api.ChatColor;
+
+/** The utils class containing utility functions. Those include but are not limited to sending formatted messages, broadcasts and more.
+ *
+ * @author Pepich */
+@Version(major = 1, minor = 1, revision = 8, compatible = 1)
+public final class Utils
+{
+ /** Hidden constructor. Do not instantiate UTILS classes! :) */
+ private Utils()
+ {}
+
+ /** This will send a message to the specified recipient. It will generate the module prefix if you want it to.
+ *
+ * @param recipient Whom to sent the message to.
+ * @param prefix The prefix for the message. If null, the default prefix will be used: &8[&2MODULE&8]
+ * @param message The message to sent. Will default to &7 (light_grey) if not specified otherwise. */
+ @Debugable
+ public static void sendMessage(CommandSender recipient, String prefix, String message)
+ {
+ Debugger.notifyMethod(recipient, message, prefix);
+ if (prefix == null)
+ prefix = "§8[§2" + getCaller() + "§8]: ";
+ recipient.sendMessage(prefix + "§7" + message);
+ }
+
+ /** This will send a message to the specified recipient. It will generate the module prefix if you want it to. Also, this will be logged to console as a warning.
+ *
+ * @param recipient Whom to sent the message to.
+ * @param prefix The prefix for the message. If null, the default prefix will be used: &8[&cMODULE&8]
+ * @param message The message to sent. Will default to &7 (light_grey) if not specified otherwise. */
+ @Debugable
+ public static void sendErrorMessage(CommandSender recipient, String prefix, String message)
+ {
+ Debugger.notifyMethod(recipient, prefix, message);
+ if (prefix == null)
+ prefix = "§8[§c" + getCaller() + "§8]: ";
+ recipient.sendMessage(prefix + "§7" + message);
+ }
+
+ /** Invokes sendMessage. This method will additionally translate alternate color codes for you.
+ *
+ * @param recipient Whom to sent the message to.
+ * @param prefix The prefix for the message. If null, the default prefix will be used: &8[&cMODULE&8]
+ * @param message The message to sent. Will default to &7 (light_grey) if not specified otherwise.
+ * @param alternateColorCode The alternate color code indicator to use. If set to '&' then "&7" would be translated to "§7". Works with any char. */
+ public static void sendMessage(CommandSender recipient, String prefix, String message, char alternateColorCode)
+ {
+ if (prefix == null)
+ prefix = "§8[§2" + getCaller() + "§8]: ";
+ sendMessage(recipient, ChatColor.translateAlternateColorCodes(alternateColorCode, prefix),
+ ChatColor.translateAlternateColorCodes(alternateColorCode, message));
+ }
+
+ /** Invokes sendErrorMessage. This method will additionally translate alternate color codes for you.
+ *
+ * @param recipient Whom to sent the message to.
+ * @param prefix The prefix for the message. If null, the default prefix will be used: &8[&cMODULE&8]
+ * @param message The message to sent. Will default to &7 (light_grey) if not specified otherwise.
+ * @param alternateColorCode The alternate color code indicator to use. If set to '&' then "&7" would be translated to "§7". Works with any char. */
+ public static void sendErrorMessage(CommandSender recipient, String prefix, String message, char alternateColorCode)
+ {
+ if (prefix == null)
+ prefix = "§8[§c" + getCaller() + "§8]: ";
+ sendErrorMessage(recipient, ChatColor.translateAlternateColorCodes(alternateColorCode, prefix),
+ ChatColor.translateAlternateColorCodes(alternateColorCode, message));
+ }
+
+ /** This method broadcasts a message to all players (and console) that are allowed by the filter. Set the filter to NULL to broadcast to everyone.
+ * This will not be logged to console except when you return true in the filter.
+ *
+ * @param message the message to be sent around
+ * @param filter the BroadcastFilter to be applied.
+ * Write a class implementing the interface and pass it to this method, the "sendTo()" method will be called for each recipient.
+ * @return the amount of people that received the message. */
+ public static int broadcast(String prefix, String message, BroadcastFilter filter)
+ {
+ return broadcast(prefix, message, filter, null);
+ }
+
+ /** This method broadcasts a message to all players (and console) that are allowed by the filter. Set the filter to NULL to broadcast to everyone.
+ * This will not be logged to console except when you return true in the filter.
+ *
+ * @param message the message to be sent around
+ * @param filter the BroadcastFilter to be applied.
+ * Write a class implementing the interface and pass it to this method, the "sendTo()" method will be called for each recipient.
+ * @param alternateColorCode The alternate color code indicator to use. If set to '&' then "&7" would be translated to "§7". Works with any char.
+ * @return the amount of people that received the message. */
+ public static int broadcast(String prefix, String message, BroadcastFilter filter, char alternateColorCode)
+ {
+ if (prefix == null)
+ prefix = "§8[§2" + getCaller() + "§8]: ";
+ return broadcast(ChatColor.translateAlternateColorCodes(alternateColorCode, prefix),
+ ChatColor.translateAlternateColorCodes(alternateColorCode, message), filter, null);
+ }
+
+ /** This method broadcasts a message to all players and console that are allowed by the filter. Set the filter to NULL to broadcast to everyone.
+ * If you want to, you can set a message that will be logged to console. Set to null to not log anything.
+ * You can still allow console in the filter to log the original message.
+ *
+ * @param prefix The prefix for the message. Set to NULL to let it auto generate.
+ * @param message the message to be sent around
+ * @param filter the BroadcastFilter to be applied.
+ * Write a class implementing the interface and pass it to this method, the "sendTo()" method will be called for each recipient.
+ * @param logmessage the log message to appear in console. Set to null to not log this (you can still log the original message by returning true in the filter).
+ * @return the amount of people that received the message. */
+ @Debugable
+ public static int broadcast(String prefix, String message, BroadcastFilter filter, String logmessage)
+ {
+ if (prefix == null)
+ prefix = "§8[§2" + getCaller() + "§8]: ";
+ Debugger.notifyMethod(message, filter, logmessage);
+ if (logmessage != null)
+ sendMessage(Bukkit.getConsoleSender(), prefix, logmessage);
+ if (filter == null)
+ {
+ for (Player p : Bukkit.getOnlinePlayers())
+ p.sendMessage(prefix + message);
+ if (logmessage == null)
+ Bukkit.getConsoleSender().sendMessage(prefix + message);
+ return Bukkit.getOnlinePlayers().size();
+ }
+ else
+ {
+ int count = 0;
+ for (Player p : Bukkit.getOnlinePlayers())
+ if (filter.sendTo(p))
+ {
+ p.sendMessage(prefix + message);
+ count++;
+ }
+ if (logmessage == null)
+ if (filter.sendTo(Bukkit.getConsoleSender()))
+ {
+ Bukkit.getConsoleSender().sendMessage(prefix + message);
+ count++;
+ }
+ return count;
+ }
+ }
+
+ /** Used to make an info output to console. Supports &x color codes.
+ *
+ * @param message The message to be put into console. Prefixes are automatically generated. */
+ @Debugable
+ public static void log(String message)
+ {
+ Debugger.notifyMethod(message);
+ String classname = getCaller();
+ String prefix = "§8[§2" + classname + "§8]: ";
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "§7" + message));
+ }
+
+ /** Used to make an error output to console. Supports &x color codes.
+ *
+ * @param message The message to be put into console. Prefixes are automatically generated. Color defaults to red if not specified otherwise. */
+ @Debugable
+ public static void error(String message)
+ {
+ Debugger.notifyMethod(message);
+ String classname = getCaller();
+ String prefix = "§c[ERROR]: §8[§c" + classname + "§8]: ";
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', prefix + "§7" + message));
+ }
+
+ /** This method will find the next parent caller and return their class name, omitting package names.
+ *
+ * @return */
+ private static final String getCaller()
+ {
+ StackTraceElement[] stackTrace = (new Exception()).getStackTrace();
+ String classname = "Utils";
+ for (int i = 0; classname.equals("Utils"); i++)
+ {
+ classname = stackTrace[i].getClassName().replaceAll(".*\\.", "");
+ }
+ return classname;
+ }
+
+ /** Displays the module header to the recipient.
+ * Format: &2--=[ %MODULE% ]=--
+ *
+ * @param recipient Whom to display the header to. */
+ public static void sendModuleHeader(CommandSender recipient)
+ {
+ recipient.sendMessage("§2--=[ " + getCaller() + " ]=--");
+ }
+}
diff --git a/src/com/redstoner/misc/VersionHelper.java b/src/com/redstoner/misc/VersionHelper.java
new file mode 100644
index 0000000..86a5381
--- /dev/null
+++ b/src/com/redstoner/misc/VersionHelper.java
@@ -0,0 +1,46 @@
+package com.redstoner.misc;
+
+import com.redstoner.annotations.Version;
+import com.redstoner.exceptions.MissingVersionException;
+
+/** This class can be used to compare modules against the loader version or against each other to prevent dependency issues.
+ *
+ * @author Pepich */
+@Version(major = 1, minor = 0, revision = 0, compatible = -1)
+public final class VersionHelper
+{
+ private VersionHelper()
+ {}
+
+ /** Checks two modules versions for compatibility.
+ *
+ * @param base The base to compare to.
+ * @param module The module to compare.
+ * @return true, when the Major version of the base is bigger than the compatible version of the module, and the Version number of the base is smaller or equal to the Version number of the module.
+ * @throws MissingVersionException When one of the parameters is not annotated with a @Version annotation. */
+ public static boolean isCompatible(Class> base, Class> module) throws MissingVersionException
+ {
+ if (!base.isAnnotationPresent(Version.class))
+ throw new MissingVersionException("The base object is not annotated with a version.");
+ if (!module.isAnnotationPresent(Version.class))
+ throw new MissingVersionException("The module is not annotated with a version.");
+ Version baseVersion = base.getClass().getAnnotation(Version.class);
+ Version moduleVersion = module.getClass().getAnnotation(Version.class);
+ if (baseVersion.major() > moduleVersion.major())
+ return false;
+ return baseVersion.major() >= moduleVersion.compatible();
+ }
+
+ /** Returns the version of a given class as a String.
+ *
+ * @param clazz The class to grab the version number from.
+ * @return The version number of the class in format major.minor.revision.compatible.
+ * @throws MissingVersionException If the class is not annotated with @Version. */
+ public static String getVersion(Class> clazz) throws MissingVersionException
+ {
+ if (!clazz.isAnnotationPresent(Version.class))
+ throw new MissingVersionException("The given class is not associated with a version.");
+ Version ver = clazz.getAnnotation(Version.class);
+ return ver.major() + "." + ver.minor() + "." + ver.revision() + "." + ver.compatible();
+ }
+}
diff --git a/src/main/java/com/redstoner/misc/mysql/Config.java b/src/com/redstoner/misc/mysql/Config.java
similarity index 56%
rename from src/main/java/com/redstoner/misc/mysql/Config.java
rename to src/com/redstoner/misc/mysql/Config.java
index b88b0c2..d403c7b 100644
--- a/src/main/java/com/redstoner/misc/mysql/Config.java
+++ b/src/com/redstoner/misc/mysql/Config.java
@@ -1,170 +1,213 @@
package com.redstoner.misc.mysql;
-import com.redstoner.exceptions.NonSaveableConfigException;
-import com.redstoner.misc.Main;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
-public class Config {
- private File file;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import com.redstoner.exceptions.NonSaveableConfigException;
+import com.redstoner.misc.Main;
+
+public class Config
+{
+ private File file;
private JSONObject config;
private JSONParser parser;
-
- public Config() {
+
+ public Config()
+ {
file = null;
parser = new JSONParser();
config = new JSONObject();
}
-
- public Config(JSONObject config) {
+
+ public Config(JSONObject config)
+ {
this.file = null;
this.parser = new JSONParser();
this.config = config;
}
-
- private Config(File file) throws IOException, ParseException {
+
+ private Config(File file) throws IOException, ParseException
+ {
this.file = file;
parser = new JSONParser();
- if (file.exists()) {
+ if (file.exists())
+ {
config = loadConfig(file);
- } else {
+ }
+ else
+ {
config = new JSONObject();
}
}
-
- private JSONObject loadConfig(File file) throws IOException, ParseException {
- FileReader reader = new FileReader(file);
- JSONObject object = (JSONObject) parser.parse(reader);
- reader.close();
- return object;
- }
-
- public static final Config getConfig(String fileName) throws IOException, ParseException {
+
+ public static final Config getConfig(String fileName) throws IOException, ParseException
+ {
return new Config(new File(Main.plugin.getDataFolder(), fileName));
}
-
- public static final Config getConfig(File file) throws IOException, ParseException {
+
+ public static final Config getConfig(File file) throws IOException, ParseException
+ {
return new Config(file);
}
-
+
+ private JSONObject loadConfig(File file) throws IOException, ParseException
+ {
+ FileReader reader = new FileReader(file);
+ return (JSONObject) parser.parse(reader);
+ }
+
@Override
- public String toString() {
+ public String toString()
+ {
return config.toJSONString();
}
-
- public JSONObject asObject() {
+
+ public JSONObject asObject()
+ {
return config;
}
-
- public void save() throws IOException, NonSaveableConfigException {
- if (file == null) {
+
+ public void save() throws IOException, NonSaveableConfigException
+ {
+ if (file == null)
+ {
throw new NonSaveableConfigException();
}
PrintWriter writer = new PrintWriter(file);
writer.write(config.toJSONString());
writer.close();
}
-
- public void refresh() throws IOException, ParseException, NonSaveableConfigException {
- if (file == null) {
+
+ public void refresh() throws IOException, ParseException, NonSaveableConfigException
+ {
+ if (file == null)
+ {
throw new NonSaveableConfigException();
}
loadConfig(file);
}
-
- public void setFile(String fileName) {
+
+ public void setFile(String fileName)
+ {
file = new File(Main.plugin.getDataFolder(), fileName);
}
-
- public void setFile(File file) {
+
+ public void setFile(File file)
+ {
this.file = file;
}
-
- @SuppressWarnings ("unchecked")
- public void put(String key, String value) {
+
+ @SuppressWarnings("unchecked")
+ public void put(String key, String value)
+ {
config.put(key, value);
}
-
- @SuppressWarnings ("unchecked")
- public void put(String key, List value) {
+
+ @SuppressWarnings("unchecked")
+ public void put(String key, List value)
+ {
JSONArray array = new JSONArray();
- for (String entry : value) {
+ for (String entry : value)
+ {
array.add(entry);
}
config.put(key, array);
}
-
- @SuppressWarnings ("unchecked")
- public void putArray(String key, JSONArray value) {
+
+ @SuppressWarnings("unchecked")
+ public void putArray(String key, JSONArray value)
+ {
config.put(key, value);
}
-
- @SuppressWarnings ("unchecked")
- public void put(String key, Map value) {
+
+ @SuppressWarnings("unchecked")
+ public void put(String key, Map value)
+ {
JSONObject object = new JSONObject();
- for (String valKey : value.keySet()) {
+ for (String valKey : value.keySet())
+ {
String valVal = value.get(valKey);
object.put(valKey, valVal);
}
config.put(key, object);
}
-
- @SuppressWarnings ("unchecked")
- public void put(String key, JSONObject value) {
+
+ @SuppressWarnings("unchecked")
+ public void put(String key, JSONObject value)
+ {
config.put(key, value);
}
-
- @SuppressWarnings ("unchecked")
- public void putAll(Map entry) {
- for (String key : entry.keySet()) {
+
+ @SuppressWarnings("unchecked")
+ public void putAll(Map entry)
+ {
+ for (String key : entry.keySet())
+ {
String value = entry.get(key);
config.put(key, value);
}
}
-
- public String get(String key) {
- if (containsKey(key)) {
+
+ public boolean containsKey(String key)
+ {
+ return config.containsKey(key);
+ }
+
+ public String get(String key)
+ {
+ if (containsKey(key))
+ {
Object value = config.get(key);
- if (value instanceof String) {
+ if (value instanceof String)
+ {
return (String) value;
}
}
return null;
}
-
- public boolean containsKey(String key) {
- return config.containsKey(key);
- }
-
- public String getOrDefault(String key, String defaultValue) {
- if (containsKey(key)) {
+
+ public String getOrDefault(String key, String defaultValue)
+ {
+ if (containsKey(key))
+ {
Object value = config.get(key);
- if (value instanceof String) {
+ if (value instanceof String)
+ {
return (String) value;
}
return null;
- } else {
+ }
+ else
+ {
return defaultValue;
}
}
-
- @SuppressWarnings ("unchecked")
- public List getList(String key) {
- if (containsKey(key)) {
+
+ @SuppressWarnings("unchecked")
+ public List getList(String key)
+ {
+ if (containsKey(key))
+ {
Object value = config.get(key);
- if (value instanceof JSONArray) {
- JSONArray array = (JSONArray) value;
+ if (value instanceof JSONArray)
+ {
+ JSONArray array = (JSONArray) value;
List output = new ArrayList();
- for (String entry : (String[]) array.toArray(new String[0])) {
+ for (String entry : (String[]) array.toArray(new String[0]))
+ {
output.add(entry);
}
return output;
@@ -172,27 +215,34 @@ public class Config {
}
return null;
}
-
- public JSONArray getArray(String key) {
- if (containsKey(key)) {
+
+ public JSONArray getArray(String key)
+ {
+ if (containsKey(key))
+ {
Object value = config.get(key);
- if (value instanceof JSONArray) {
+ if (value instanceof JSONArray)
+ {
JSONArray array = (JSONArray) value;
return array;
}
}
return null;
}
-
- public Map getMap(String key) {
- if (containsKey(key)) {
+
+ public Map getMap(String key)
+ {
+ if (containsKey(key))
+ {
Object value = config.get(key);
- if (value instanceof JSONObject) {
+ if (value instanceof JSONObject)
+ {
JSONObject object = (JSONObject) value;
- @SuppressWarnings ("unchecked")
+ @SuppressWarnings("unchecked")
Set> entrySet = object.entrySet();
Map output = new HashMap();
- for (Map.Entry entry : entrySet) {
+ for (Map.Entry entry : entrySet)
+ {
output.put(entry.getKey(), entry.getValue());
}
return output;
@@ -200,24 +250,29 @@ public class Config {
}
return null;
}
-
- public JSONObject getObject(String key) {
- if (containsKey(key)) {
+
+ public JSONObject getObject(String key)
+ {
+ if (containsKey(key))
+ {
Object value = config.get(key);
- if (value instanceof JSONObject) {
+ if (value instanceof JSONObject)
+ {
JSONObject object = (JSONObject) value;
return object;
}
}
return null;
}
-
- public void remove(String key) {
+
+ public void remove(String key)
+ {
config.remove(key);
}
-
- @SuppressWarnings ("unchecked")
- public Set> getAll() {
+
+ @SuppressWarnings("unchecked")
+ public Set> getAll()
+ {
return config.entrySet();
}
}
diff --git a/src/main/java/com/redstoner/misc/mysql/JSONManager.java b/src/com/redstoner/misc/mysql/JSONManager.java
similarity index 62%
rename from src/main/java/com/redstoner/misc/mysql/JSONManager.java
rename to src/com/redstoner/misc/mysql/JSONManager.java
index 6084e8d..ae248d5 100644
--- a/src/main/java/com/redstoner/misc/mysql/JSONManager.java
+++ b/src/com/redstoner/misc/mysql/JSONManager.java
@@ -1,80 +1,107 @@
package com.redstoner.misc.mysql;
-import com.redstoner.misc.Main;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-
-import java.io.*;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class JSONManager {
- public static Map getConfiguration(String fileName) {
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+
+import com.redstoner.misc.Main;
+
+public class JSONManager
+{
+ public static Map getConfiguration(String fileName)
+ {
File file = new File(Main.plugin.getDataFolder(), fileName);
- if (!file.exists()) {
- try {
+ if (!file.exists())
+ {
+ try
+ {
PrintWriter writer = new PrintWriter(file.getAbsolutePath(), "UTF-8");
writer.println("{}");
writer.close();
- } catch (FileNotFoundException | UnsupportedEncodingException e) {
+ }
+ catch (FileNotFoundException | UnsupportedEncodingException e)
+ {
e.printStackTrace();
}
}
- try {
+ try
+ {
return loadMap(file);
- } catch (IOException | ParseException e) {
+ }
+ catch (IOException | ParseException e)
+ {
e.printStackTrace();
return null;
}
}
-
- public static Map loadMap(File file) throws IOException, ParseException {
- FileReader reader = new FileReader(file);
- JSONObject map = (JSONObject) new JSONParser().parse(reader);
- Map entries = new HashMap<>();
- for (Object o : map.keySet()) {
- entries.put((Serializable) o, (Serializable) map.get(o));
- }
- return entries;
- }
-
- public static void saveConfiguration(Map config, String fileName) {
- try {
+
+ public static void saveConfiguration(Map config, String fileName)
+ {
+ try
+ {
saveMap(new File(Main.plugin.getDataFolder(), fileName), config);
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
e.printStackTrace();
}
}
-
- @SuppressWarnings ("unchecked")
- public static void saveMap(File file, Map entries) throws IOException {
- JSONObject map = new JSONObject();
- map.putAll(entries);
- FileWriter writer = new FileWriter(file);
- writer.write(map.toJSONString());
- writer.close();
- }
-
- @SuppressWarnings ("unchecked")
- public static void saveList(File file, List entries) throws IOException {
+
+ @SuppressWarnings("unchecked")
+ public static void saveList(File file, List entries) throws IOException
+ {
JSONArray array = new JSONArray();
array.addAll(entries);
FileWriter writer = new FileWriter(file);
writer.write(array.toJSONString());
writer.close();
}
-
- public static List loadList(File file) throws IOException, ParseException {
- FileReader read = new FileReader(file);
+
+ public static List loadList(File file) throws IOException, ParseException
+ {
+ FileReader read = new FileReader(file);
List entries = new ArrayList<>();
- JSONArray array = (JSONArray) new JSONParser().parse(read);
- for (Object o : array) {
+ JSONArray array = (JSONArray) new JSONParser().parse(read);
+ for (Object o : array)
+ {
entries.add((Serializable) o);
}
return entries;
}
+
+ @SuppressWarnings("unchecked")
+ public static void saveMap(File file, Map entries) throws IOException
+ {
+ JSONObject map = new JSONObject();
+ map.putAll(entries);
+ FileWriter writer = new FileWriter(file);
+ writer.write(map.toJSONString());
+ writer.close();
+ }
+
+ public static Map loadMap(File file) throws IOException, ParseException
+ {
+ FileReader reader = new FileReader(file);
+ JSONObject map = (JSONObject) new JSONParser().parse(reader);
+ Map entries = new HashMap<>();
+ for (Object o : map.keySet())
+ {
+ entries.put((Serializable) o, (Serializable) map.get(o));
+ }
+ return entries;
+ }
}
diff --git a/src/main/java/com/redstoner/misc/mysql/MysqlHandler.java b/src/com/redstoner/misc/mysql/MysqlHandler.java
similarity index 62%
rename from src/main/java/com/redstoner/misc/mysql/MysqlHandler.java
rename to src/com/redstoner/misc/mysql/MysqlHandler.java
index d76227a..909d276 100644
--- a/src/main/java/com/redstoner/misc/mysql/MysqlHandler.java
+++ b/src/com/redstoner/misc/mysql/MysqlHandler.java
@@ -1,86 +1,113 @@
package com.redstoner.misc.mysql;
-import com.redstoner.misc.Main;
-import com.redstoner.misc.mysql.elements.MysqlDatabase;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.json.simple.parser.ParseException;
-
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
-import java.sql.*;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class MysqlHandler {
- public static MysqlHandler INSTANCE;
- private String url, username, password;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.json.simple.parser.ParseException;
- public MysqlHandler(String hostname, int port, String username, String password) {
+import com.redstoner.misc.Main;
+import com.redstoner.misc.mysql.elements.MysqlDatabase;
+
+public class MysqlHandler
+{
+ public static MysqlHandler INSTANCE;
+ private String url, username, password;
+
+ public MysqlHandler(String hostname, int port, String username, String password)
+ {
this.url = "jdbc:mysql://" + hostname + ":" + port + "/";
this.username = username;
this.password = password;
}
-
- public static void init() {
- Map mysqlCredentials = new HashMap<>();
- File mysqlCredentialsFile = new File(Main.plugin.getDataFolder(), "mysqlCredentials.json");
- if (mysqlCredentialsFile.exists()) {
- try {
+
+ public static void init()
+ {
+ Map mysqlCredentials = new HashMap<>();
+ File mysqlCredentialsFile = new File(Main.plugin.getDataFolder(), "mysqlCredentials.json");
+ if (mysqlCredentialsFile.exists())
+ {
+ try
+ {
mysqlCredentials = JSONManager.loadMap(mysqlCredentialsFile);
- } catch (IOException | ParseException e) {
+ }
+ catch (IOException | ParseException e)
+ {
e.printStackTrace();
}
- } else {
+ }
+ else
+ {
Bukkit.getConsoleSender().sendMessage(
ChatColor.RED + "MySQL config does not exist, creating an example one, things might (will) break!");
mysqlCredentials.put("hostname", "localhost");
mysqlCredentials.put("port", "3306");
mysqlCredentials.put("username", "your username here");
mysqlCredentials.put("password", "your password here");
- try {
+ try
+ {
JSONManager.saveMap(mysqlCredentialsFile, mysqlCredentials);
- } catch (IOException e) {
+ }
+ catch (IOException e)
+ {
e.printStackTrace();
}
}
String hostname = (String) mysqlCredentials.get("hostname");
- int port = Integer.valueOf((String) mysqlCredentials.get("port"));
+ int port = Integer.valueOf((String) mysqlCredentials.get("port"));
String username = (String) mysqlCredentials.get("username");
String password = (String) mysqlCredentials.get("password");
INSTANCE = new MysqlHandler(hostname, port, username, password);
}
-
- public MysqlDatabase getDatabase(String databaseName) {
- return new MysqlDatabase(getConnection(databaseName));
- }
-
- private Connection getConnection(String databaseName) throws IllegalStateException {
+
+ private Connection getConnection(String databaseName) throws IllegalStateException
+ {
Connection connection = null;
- try {
+ try
+ {
connection = DriverManager.getConnection(url + databaseName, username, password);
- } catch (SQLException e) {
+ }
+ catch (SQLException e)
+ {
throw new IllegalStateException("Cannot connect to the database!", e);
}
return connection;
}
-
- public List getDatabases() {
- try {
- List databases = new ArrayList<>();
- Connection connection = DriverManager.getConnection(url.substring(0, url.length()), username, password);
- DatabaseMetaData metadata = connection.getMetaData();
- ResultSet queryResults = metadata.getCatalogs();
- while (queryResults.next()) {
+
+ public MysqlDatabase getDatabase(String databaseName)
+ {
+ return new MysqlDatabase(getConnection(databaseName));
+ }
+
+ public List getDatabases()
+ {
+ try
+ {
+ List databases = new ArrayList<>();
+ Connection connection = DriverManager.getConnection(url.substring(0, url.length()), username, password);
+ DatabaseMetaData metadata = connection.getMetaData();
+ ResultSet queryResults = metadata.getCatalogs();
+ while (queryResults.next())
+ {
String databaseName = queryResults.getString("TABLE_CAT");
databases.add(new MysqlDatabase(getConnection(databaseName)));
}
connection.close();
return databases;
- } catch (SQLException e) {
+ }
+ catch (SQLException e)
+ {
e.printStackTrace();
return null;
}
diff --git a/src/main/java/com/redstoner/misc/mysql/MysqlQueryHandler.java b/src/com/redstoner/misc/mysql/MysqlQueryHandler.java
similarity index 72%
rename from src/main/java/com/redstoner/misc/mysql/MysqlQueryHandler.java
rename to src/com/redstoner/misc/mysql/MysqlQueryHandler.java
index df46cab..f89a08a 100644
--- a/src/main/java/com/redstoner/misc/mysql/MysqlQueryHandler.java
+++ b/src/com/redstoner/misc/mysql/MysqlQueryHandler.java
@@ -1,25 +1,29 @@
package com.redstoner.misc.mysql;
-import java.sql.*;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
public class MysqlQueryHandler {
public static ResultSet queryResult(Connection connection, String query) {
try {
Statement statement = connection.createStatement();
- ResultSet results = statement.executeQuery(query);
-
+ ResultSet results = statement.executeQuery(query);
+
return results;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
-
+
public static boolean queryNoResult(Connection connection, String query) {
try {
CallableStatement statement = connection.prepareCall(query);
statement.execute();
-
+
return true;
} catch (SQLException e) {
e.printStackTrace();
diff --git a/src/main/java/com/redstoner/misc/mysql/elements/ConstraintOperator.java b/src/com/redstoner/misc/mysql/elements/ConstraintOperator.java
similarity index 99%
rename from src/main/java/com/redstoner/misc/mysql/elements/ConstraintOperator.java
rename to src/com/redstoner/misc/mysql/elements/ConstraintOperator.java
index 1e8d523..45cb33c 100644
--- a/src/main/java/com/redstoner/misc/mysql/elements/ConstraintOperator.java
+++ b/src/com/redstoner/misc/mysql/elements/ConstraintOperator.java
@@ -2,7 +2,7 @@ package com.redstoner.misc.mysql.elements;
public enum ConstraintOperator {
LESS_THAN, GREATER_THAN, EQUAL, NOT_EQUAL, LESS_THAN_OR_EQUAL, GREATER_THAN_OR_EQUAL;
-
+
public String toString() {
switch (this) {
case LESS_THAN:
diff --git a/src/main/java/com/redstoner/misc/mysql/elements/MysqlConstraint.java b/src/com/redstoner/misc/mysql/elements/MysqlConstraint.java
similarity index 99%
rename from src/main/java/com/redstoner/misc/mysql/elements/MysqlConstraint.java
rename to src/com/redstoner/misc/mysql/elements/MysqlConstraint.java
index 8b99d12..d651344 100644
--- a/src/main/java/com/redstoner/misc/mysql/elements/MysqlConstraint.java
+++ b/src/com/redstoner/misc/mysql/elements/MysqlConstraint.java
@@ -3,7 +3,7 @@ package com.redstoner.misc.mysql.elements;
public class MysqlConstraint {
private String fieldName, value;
private ConstraintOperator operator;
-
+
public MysqlConstraint(String fieldName, ConstraintOperator operator, String value) {
this.fieldName = fieldName;
this.operator = operator;
diff --git a/src/main/java/com/redstoner/misc/mysql/elements/MysqlDatabase.java b/src/com/redstoner/misc/mysql/elements/MysqlDatabase.java
similarity index 89%
rename from src/main/java/com/redstoner/misc/mysql/elements/MysqlDatabase.java
rename to src/com/redstoner/misc/mysql/elements/MysqlDatabase.java
index 3f1c288..91c0fe4 100644
--- a/src/main/java/com/redstoner/misc/mysql/elements/MysqlDatabase.java
+++ b/src/com/redstoner/misc/mysql/elements/MysqlDatabase.java
@@ -1,7 +1,5 @@
package com.redstoner.misc.mysql.elements;
-import com.redstoner.misc.mysql.MysqlQueryHandler;
-
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
@@ -9,55 +7,15 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import com.redstoner.misc.mysql.MysqlQueryHandler;
+
public class MysqlDatabase {
private Connection connection;
-
+
public MysqlDatabase(Connection connection) {
this.connection = connection;
}
-
- public MysqlTable getTable(String name) {
- return new MysqlTable(this, name);
- }
-
- public boolean createTable(String name, MysqlField... description) {
- return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE `" + name + "` " + getDescription(description) + ";");
- }
-
- private String getDescription(MysqlField... description) {
- String desc = "(";
-
- for (int i = 0; i < description.length; i++) {
- String nil = "";
-
- if (description[i].canBeNull()) {
- nil = " NOT NULL";
- }
-
- desc += "`" + description[i].getName() + "` " + description[i].getType().getName() + nil;
-
- if (i < description.length - 1) {
- desc += ",";
- }
- }
-
- desc += ")";
-
- return desc;
- }
-
- public boolean createTableIfNotExists(String name, MysqlField... description) {
- return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE IF NOT EXISTS `" + name + "` " + getDescription(description) + ";");
- }
-
- public boolean dropTable(String name) {
- return MysqlQueryHandler.queryNoResult(connection, "DROP TABLE `" + name + "`;");
- }
-
- public boolean drop() {
- return MysqlQueryHandler.queryNoResult(connection, "DROP DATABASE `" + getName() + "`;");
- }
-
+
public String getName() {
try {
return connection.getCatalog();
@@ -66,25 +24,67 @@ public class MysqlDatabase {
return null;
}
}
-
+
+ public MysqlTable getTable(String name) {
+ return new MysqlTable(this, name);
+ }
+
+ public boolean createTable(String name, MysqlField... description) {
+ return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE `" + name + "` " + getDescription(description) + ";");
+ }
+
+ public boolean createTableIfNotExists(String name, MysqlField... description) {
+ return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE IF NOT EXISTS `" + name + "` " + getDescription(description) + ";");
+ }
+
+ public boolean dropTable(String name) {
+ return MysqlQueryHandler.queryNoResult(connection, "DROP TABLE `" + name + "`;");
+ }
+
+ public boolean drop() {
+ return MysqlQueryHandler.queryNoResult(connection, "DROP DATABASE `" + getName() + "`;");
+ }
+
public List getTables() {
try {
- List tables = new ArrayList<>();
- DatabaseMetaData metadata = connection.getMetaData();
- ResultSet queryResults = metadata.getTables(null, null, "%", null);
-
+ List tables = new ArrayList<>();
+ DatabaseMetaData metadata = connection.getMetaData();
+ ResultSet queryResults = metadata.getTables(null, null, "%", null);
+
while (queryResults.next()) {
tables.add(new MysqlTable(this, queryResults.getString(3)));
}
-
+
return tables;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
-
+
protected Connection getConnection() {
return connection;
}
+
+ private String getDescription(MysqlField... description) {
+ String desc = "(";
+
+ for (int i = 0; i < description.length; i++) {
+ String nil = "";
+
+ if (description[i].canBeNull()) {
+ nil = " NOT NULL";
+ }
+
+ desc += "`" + description[i].getName() + "` " + description[i].getType().getName() + nil;
+
+ if (i < description.length - 1) {
+ desc += ",";
+ }
+ }
+
+ desc += ")";
+
+ return desc;
+ }
}
diff --git a/src/main/java/com/redstoner/misc/mysql/elements/MysqlField.java b/src/com/redstoner/misc/mysql/elements/MysqlField.java
similarity index 90%
rename from src/main/java/com/redstoner/misc/mysql/elements/MysqlField.java
rename to src/com/redstoner/misc/mysql/elements/MysqlField.java
index 68b6fcc..61cba2e 100644
--- a/src/main/java/com/redstoner/misc/mysql/elements/MysqlField.java
+++ b/src/com/redstoner/misc/mysql/elements/MysqlField.java
@@ -3,30 +3,30 @@ package com.redstoner.misc.mysql.elements;
import com.redstoner.misc.mysql.types.MysqlType;
public class MysqlField {
- private String name;
+ private String name;
private MysqlType type;
- private boolean canBeNull;
-
+ private boolean canBeNull;
+
public MysqlField(String name, MysqlType type, boolean canBeNull) {
this.name = name;
this.type = type;
this.canBeNull = canBeNull;
}
-
+
public MysqlField(String name, String type, boolean canBeNull) {
this.name = name;
this.type = MysqlType.getTypeFromString(type);
this.canBeNull = canBeNull;
}
-
+
public String getName() {
return name;
}
-
+
public MysqlType getType() {
return type;
}
-
+
public boolean canBeNull() {
return canBeNull;
}
diff --git a/src/main/java/com/redstoner/misc/mysql/elements/MysqlResult.java b/src/com/redstoner/misc/mysql/elements/MysqlResult.java
similarity index 98%
rename from src/main/java/com/redstoner/misc/mysql/elements/MysqlResult.java
rename to src/com/redstoner/misc/mysql/elements/MysqlResult.java
index 1b4f246..6db0769 100644
--- a/src/main/java/com/redstoner/misc/mysql/elements/MysqlResult.java
+++ b/src/com/redstoner/misc/mysql/elements/MysqlResult.java
@@ -5,11 +5,11 @@ import java.sql.SQLException;
public class MysqlResult {
private ResultSet results;
-
+
public MysqlResult(ResultSet results) {
this.results = results;
}
-
+
public Object getObject(int columnIndex, Class> type) throws SQLException {
return results.getObject(columnIndex, type);
}
diff --git a/src/main/java/com/redstoner/misc/mysql/elements/MysqlTable.java b/src/com/redstoner/misc/mysql/elements/MysqlTable.java
similarity index 57%
rename from src/main/java/com/redstoner/misc/mysql/elements/MysqlTable.java
rename to src/com/redstoner/misc/mysql/elements/MysqlTable.java
index e6a7617..fa0008e 100644
--- a/src/main/java/com/redstoner/misc/mysql/elements/MysqlTable.java
+++ b/src/com/redstoner/misc/mysql/elements/MysqlTable.java
@@ -1,63 +1,58 @@
package com.redstoner.misc.mysql.elements;
-import com.redstoner.misc.mysql.MysqlQueryHandler;
-
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import com.redstoner.misc.mysql.MysqlQueryHandler;
+
public class MysqlTable {
private MysqlDatabase database;
- private String name;
-
+ private String name;
+
public MysqlTable(MysqlDatabase database, String name) {
this.database = database;
this.name = name;
}
-
+
public String getName() {
return this.name;
}
-
- public boolean insert(String... values) {
- MysqlField[] description = describe();
- if (values.length > 0 && values.length == description.length) {
- String val = "(\"" + String.join("\",\"", values) + "\")";
- return MysqlQueryHandler.queryNoResult(
- database.getConnection(),
- "INSERT INTO `" + name + "` VALUES " + val + ";"
- );
- } else {
- return false;
- }
- }
-
+
public MysqlField[] describe() {
try {
- List description = new ArrayList<>();
- DatabaseMetaData metadata = database.getConnection().getMetaData();
- ResultSet queryResults = metadata.getColumns(null, null, name, null);
+ List description = new ArrayList<>();
+ DatabaseMetaData metadata = database.getConnection().getMetaData();
+ ResultSet queryResults = metadata.getColumns(null, null, name, null);
+
while (queryResults.next()) {
- description.add(new MysqlField(
- queryResults.getString(4),
- queryResults.getString(6).split(" ")[0] + "(" + queryResults.getString(7) + ")",
- queryResults.getBoolean(11)
- ));
+ description.add(new MysqlField(queryResults.getString(4), queryResults.getString(6).split(" ")[0] + "(" + queryResults.getString(7) + ")", queryResults.getBoolean(11)));
}
+
return description.toArray(new MysqlField[0]);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
-
+
+ public boolean insert(String... values) {
+ MysqlField[] description = describe();
+
+ if (values.length > 0 && values.length == description.length) {
+ String val = "(\"" + String.join("\",\"", values) + "\")";
+
+ return MysqlQueryHandler.queryNoResult(database.getConnection(), "INSERT INTO `" + name + "` VALUES " + val + ";");
+ } else {
+ return false;
+ }
+ }
+
public Object[] get(String fieldName, MysqlConstraint... constraints) {
- ResultSet results = MysqlQueryHandler.queryResult(
- database.getConnection(),
- "SELECT " + fieldName + " FROM `" + name + "`" + getConstraints(constraints) + ";"
- );
+ ResultSet results = MysqlQueryHandler.queryResult(database.getConnection(), "SELECT " + fieldName + " FROM `" + name + "`" + getConstraints(constraints) + ";");
+
List