First commit (1.0.0)
This commit is contained in:
119
.gitignore
vendored
Normal file
119
.gitignore
vendored
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# 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*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# 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*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
.gradle
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Ignore Gradle GUI config
|
||||||
|
gradle-app.setting
|
||||||
|
|
||||||
|
# Cache of project
|
||||||
|
.gradletasknamecache
|
||||||
|
|
||||||
|
**/build/
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
|
runs/
|
||||||
|
|
||||||
|
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||||
|
!gradle-wrapper.jar
|
||||||
59
build.gradle
Normal file
59
build.gradle
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'me.monster'
|
||||||
|
version = '1.0'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
name = "papermc-repo"
|
||||||
|
url = "https://repo.papermc.io/repository/maven-public/"
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
url = 'https://jitpack.io'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||||
|
implementation("com.mysql:mysql-connector-j:9.4.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
runServer {
|
||||||
|
// Configure the Minecraft version for our task.
|
||||||
|
// This is the only required configuration besides applying the plugin.
|
||||||
|
// Your plugin's jar (or shadowJar if present) will be used automatically.
|
||||||
|
minecraftVersion("1.21")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def targetJavaVersion = 21
|
||||||
|
java {
|
||||||
|
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||||
|
sourceCompatibility = javaVersion
|
||||||
|
targetCompatibility = javaVersion
|
||||||
|
if (JavaVersion.current() < javaVersion) {
|
||||||
|
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
|
||||||
|
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||||
|
options.release.set(targetJavaVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
def props = [version: version]
|
||||||
|
inputs.properties props
|
||||||
|
filteringCharset 'UTF-8'
|
||||||
|
filesMatching('plugin.yml') {
|
||||||
|
expand props
|
||||||
|
}
|
||||||
|
}
|
||||||
0
gradle.properties
Normal file
0
gradle.properties
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
249
gradlew
vendored
Normal file
249
gradlew
vendored
Normal file
@@ -0,0 +1,249 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original 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 POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# 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 ;; #(
|
||||||
|
MSYS* | 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
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# 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"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
92
gradlew.bat
vendored
Normal file
92
gradlew.bat
vendored
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
@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 userInfo 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=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@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% equ 0 goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
: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 %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 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!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
1
settings.gradle
Normal file
1
settings.gradle
Normal file
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'permission-manager'
|
||||||
62
src/main/java/me/monster/ranks/Main.java
Normal file
62
src/main/java/me/monster/ranks/Main.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package me.monster.ranks;
|
||||||
|
|
||||||
|
import me.monster.ranks.database.dbManager;
|
||||||
|
import me.monster.ranks.config.configManager;
|
||||||
|
import me.monster.ranks.utils.defaultGroups;
|
||||||
|
import me.monster.ranks.utils.loaders.loadCommands;
|
||||||
|
import me.monster.ranks.utils.loaders.loadListeners;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public final class Main extends JavaPlugin {
|
||||||
|
|
||||||
|
public static Main plugin;
|
||||||
|
public static Plugin getPlugin() { return plugin; }
|
||||||
|
private static dbManager database;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
plugin = this;
|
||||||
|
// Plugin startup logic
|
||||||
|
|
||||||
|
// Config file creation and loading
|
||||||
|
new configManager().createConfigFiles();
|
||||||
|
|
||||||
|
|
||||||
|
// Database connection etc
|
||||||
|
database = new dbManager();
|
||||||
|
try {
|
||||||
|
database.initializeDatabase();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Main.getLogger("Could not initialize database. (" + e.getMessage() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
new defaultGroups().createDefaultGroups();
|
||||||
|
|
||||||
|
// Load event listeners and commands
|
||||||
|
|
||||||
|
loadListeners.load();
|
||||||
|
loadCommands.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
|
Main.getLogger("Shutting down plugin");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getLogger(String string) {
|
||||||
|
plugin.getLogger().info(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static dbManager getDatabase() {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
32
src/main/java/me/monster/ranks/commands/test.java
Normal file
32
src/main/java/me/monster/ranks/commands/test.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package me.monster.ranks.commands;
|
||||||
|
|
||||||
|
import me.monster.ranks.utils.updatePlayer;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class test implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
|
||||||
|
if (sender.hasPermission("ranks.test")) {
|
||||||
|
if (sender instanceof Player p) {
|
||||||
|
try {
|
||||||
|
new updatePlayer(p);
|
||||||
|
return true;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("You must be a player to use this command");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("You don't have permission to use this command");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
41
src/main/java/me/monster/ranks/config/configManager.java
Normal file
41
src/main/java/me/monster/ranks/config/configManager.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package me.monster.ranks.config;
|
||||||
|
|
||||||
|
import me.monster.ranks.Main;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class configManager {
|
||||||
|
static Plugin plugin = Main.getPlugin();
|
||||||
|
|
||||||
|
|
||||||
|
public void createConfigFiles() {
|
||||||
|
|
||||||
|
Main.getLogger("Creating config files...");
|
||||||
|
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||||
|
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
plugin.saveResource("config.yml", false);
|
||||||
|
}
|
||||||
|
Main.getLogger("Created config files");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||||
|
public static @NotNull YamlConfiguration configFile() { return YamlConfiguration.loadConfiguration(configFile); }
|
||||||
|
|
||||||
|
public static void saveConfigFiles() {
|
||||||
|
Main.getLogger("Saving config");
|
||||||
|
plugin.saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadConfigFiles() {
|
||||||
|
Main.getLogger("Reloading config");
|
||||||
|
plugin.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
117
src/main/java/me/monster/ranks/database/dbManager.java
Normal file
117
src/main/java/me/monster/ranks/database/dbManager.java
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
package me.monster.ranks.database;
|
||||||
|
|
||||||
|
import me.monster.ranks.Main;
|
||||||
|
import me.monster.ranks.database.managers.groups;
|
||||||
|
import me.monster.ranks.database.managers.permissions;
|
||||||
|
import me.monster.ranks.database.managers.players;
|
||||||
|
import me.monster.ranks.database.models.groupPermissions;
|
||||||
|
import me.monster.ranks.config.configManager;
|
||||||
|
import me.monster.ranks.database.models.ranks;
|
||||||
|
import me.monster.ranks.database.models.userInfo;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class dbManager {
|
||||||
|
|
||||||
|
private static Connection connection;
|
||||||
|
|
||||||
|
public static Connection getConnection() throws SQLException {
|
||||||
|
|
||||||
|
if(connection != null){
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
String port = configManager.configFile().getString("mysql.port");
|
||||||
|
String host = configManager.configFile().getString("mysql.host");
|
||||||
|
String user = configManager.configFile().getString("mysql.user");
|
||||||
|
String password = configManager.configFile().getString("mysql.password");
|
||||||
|
String database = configManager.configFile().getString("mysql.database");
|
||||||
|
String url = "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true";
|
||||||
|
|
||||||
|
Connection connection = DriverManager.getConnection(url, user, password);
|
||||||
|
|
||||||
|
dbManager.connection = connection;
|
||||||
|
|
||||||
|
Main.getLogger("Connected to database.");
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeDatabase() throws SQLException {
|
||||||
|
|
||||||
|
Statement statement = getConnection().createStatement();
|
||||||
|
|
||||||
|
String player_infoSQL = "CREATE TABLE IF NOT EXISTS player_info (uuid varchar(36), playerRank TEXT, temp INT, date DATETIME)";
|
||||||
|
String groupsSQL = "CREATE TABLE IF NOT EXISTS groups (groupName TEXT, groupPrefix TEXT, groupSuffix TEXT, groupWeight INT, groupParent TEXT)";
|
||||||
|
String groupsPermissionsSQL = "CREATE TABLE IF NOT EXISTS group_permissions (groupName TEXT, permission TEXT, value INT, context TEXT)";
|
||||||
|
|
||||||
|
|
||||||
|
statement.execute(player_infoSQL);
|
||||||
|
statement.execute(groupsSQL);
|
||||||
|
statement.execute(groupsPermissionsSQL);
|
||||||
|
|
||||||
|
statement.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//################################################
|
||||||
|
//########### Player Info Section ################
|
||||||
|
//################################################
|
||||||
|
|
||||||
|
public static userInfo findPlayerGroupByUUID(String string) throws SQLException {
|
||||||
|
return players.findPlayerGroupByUUID(string);
|
||||||
|
}
|
||||||
|
public static List<userInfo> findPlayerGroups(String uuid) throws SQLException {
|
||||||
|
return players.findPlayerGroups(uuid);
|
||||||
|
}
|
||||||
|
public static void deletePlayerGroups(userInfo databaseModel) throws SQLException {
|
||||||
|
players.deletePlayerGroups(databaseModel);
|
||||||
|
}
|
||||||
|
public static void updatePlayerGroups(userInfo databaseModel) throws SQLException {
|
||||||
|
players.updatePlayerGroups(databaseModel);
|
||||||
|
}
|
||||||
|
public static void createPlayer(userInfo databaseModel) throws SQLException {
|
||||||
|
players.createPlayer(databaseModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
//################################################
|
||||||
|
//############# Groups Section ##################
|
||||||
|
//################################################
|
||||||
|
|
||||||
|
public static void createGroup(ranks databaseModel) throws SQLException {
|
||||||
|
groups.createGroup(databaseModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateGroup(ranks databaseModel) throws SQLException {
|
||||||
|
groups.updateGroup(databaseModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteGroup(ranks databaseModel) throws SQLException {
|
||||||
|
groups.deleteGroup(databaseModel);
|
||||||
|
}
|
||||||
|
public static ranks findGroupByName(String groupName) throws SQLException {
|
||||||
|
return groups.findGroupByName(groupName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//################################################
|
||||||
|
//########### Permission Section ################
|
||||||
|
//################################################
|
||||||
|
|
||||||
|
public static List<groupPermissions> fetchGroupPermissions(String groupName) throws SQLException {
|
||||||
|
return permissions.fetchGroupPermissions(groupName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateGroupPermission(groupPermissions permission) throws SQLException {
|
||||||
|
permissions.updateGroupPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addGroupPermission(groupPermissions permission) throws SQLException {
|
||||||
|
permissions.addGroupPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteGroupPermission(String groupName, String permission, String context) throws SQLException {
|
||||||
|
permissions.deleteGroupPermission(groupName, permission, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
71
src/main/java/me/monster/ranks/database/managers/groups.java
Normal file
71
src/main/java/me/monster/ranks/database/managers/groups.java
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package me.monster.ranks.database.managers;
|
||||||
|
|
||||||
|
import me.monster.ranks.Main;
|
||||||
|
import me.monster.ranks.database.dbManager;
|
||||||
|
import me.monster.ranks.database.models.ranks;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class groups extends dbManager {
|
||||||
|
|
||||||
|
public static void createGroup(ranks databaseModel) throws SQLException {
|
||||||
|
|
||||||
|
PreparedStatement statement = getConnection()
|
||||||
|
.prepareStatement("INSERT INTO groups (groupName, groupPrefix, groupSuffix, groupWeight, groupParent) VALUES (?, ?, ?, ?, ?)");
|
||||||
|
statement.setString(1, databaseModel.getGroupName());
|
||||||
|
statement.setString(2, databaseModel.getGroupPrefix());
|
||||||
|
statement.setString(3, databaseModel.getGroupSuffix());
|
||||||
|
statement.setInt(4, databaseModel.getGroupWeight());
|
||||||
|
statement.setString(5, databaseModel.getGroupParent());
|
||||||
|
statement.executeUpdate();
|
||||||
|
Main.getLogger("[Permissions Manager] Created group: " + databaseModel.getGroupName());
|
||||||
|
statement.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateGroup(ranks databaseModel) throws SQLException {
|
||||||
|
|
||||||
|
PreparedStatement statement = getConnection()
|
||||||
|
.prepareStatement("UPDATE groups SET groupName = ?, groupPrefix = ?, groupSuffix = ?, groupWeight = ?, groupParent = ? WHERE groupName = ?");
|
||||||
|
statement.setString(1, databaseModel.getGroupName());
|
||||||
|
statement.setString(2, databaseModel.getGroupPrefix());
|
||||||
|
statement.setString(3, databaseModel.getGroupSuffix());
|
||||||
|
statement.setInt(4, databaseModel.getGroupWeight());
|
||||||
|
statement.setString(5, databaseModel.getGroupParent());
|
||||||
|
statement.setString(6, databaseModel.getGroupName());
|
||||||
|
statement.executeUpdate();
|
||||||
|
Main.getLogger("[Permissions Manager] Updated group: " + databaseModel.getGroupName());
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteGroup(ranks databaseModel) throws SQLException {
|
||||||
|
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement("DELETE FROM groups WHERE groupName = ?");
|
||||||
|
statement.setString(1, databaseModel.getGroupName());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
Main.getLogger("[Permissions Manager] Deleted group: " + databaseModel.getGroupName());
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ranks findGroupByName(String groupName) throws SQLException {
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM groups WHERE groupName = ?");
|
||||||
|
statement.setString(1, groupName);
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
ranks databaseModel;
|
||||||
|
if(resultSet.next()){
|
||||||
|
databaseModel = new ranks(resultSet.getString("groupName"), resultSet.getString("groupPrefix"), resultSet.getString("groupSuffix"), resultSet.getInt("groupWeight"), resultSet.getString("groupParent"));
|
||||||
|
statement.close();
|
||||||
|
return databaseModel;
|
||||||
|
}
|
||||||
|
statement.close();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package me.monster.ranks.database.managers;
|
||||||
|
|
||||||
|
import me.monster.ranks.database.dbManager;
|
||||||
|
import me.monster.ranks.database.models.groupPermissions;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class permissions extends dbManager {
|
||||||
|
|
||||||
|
public static List<groupPermissions> fetchGroupPermissions(String groupName) throws SQLException {
|
||||||
|
String query = "SELECT * FROM group_permissions WHERE groupName = ?";
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement(query);
|
||||||
|
statement.setString(1, groupName);
|
||||||
|
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
List<groupPermissions> permissions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
groupPermissions permission = new groupPermissions(
|
||||||
|
resultSet.getString("groupName"),
|
||||||
|
resultSet.getString("permission"),
|
||||||
|
resultSet.getInt("value"),
|
||||||
|
resultSet.getString("context")
|
||||||
|
);
|
||||||
|
permissions.add(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
statement.close();
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateGroupPermission(groupPermissions permission) throws SQLException {
|
||||||
|
String query = "UPDATE group_permissions SET permission = ?, value = ?, context = ? WHERE groupName = ? AND permission = ? AND context = ?";
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement(query);
|
||||||
|
|
||||||
|
statement.setString(1, permission.getPermission());
|
||||||
|
statement.setInt(2, permission.getValue());
|
||||||
|
statement.setString(3, permission.getContext());
|
||||||
|
statement.setString(4, permission.getGroupName());
|
||||||
|
statement.setString(5, permission.getPermission());
|
||||||
|
statement.setString(6, permission.getContext());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addGroupPermission(groupPermissions permission) throws SQLException {
|
||||||
|
String query = "INSERT INTO group_permissions (groupName, permission, value, context) VALUES (?, ?, ?, ?)";
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement(query);
|
||||||
|
|
||||||
|
statement.setString(1, permission.getGroupName());
|
||||||
|
statement.setString(2, permission.getPermission());
|
||||||
|
statement.setInt(3, permission.getValue());
|
||||||
|
statement.setString(4, permission.getContext());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteGroupPermission(String groupName, String permission, String context) throws SQLException {
|
||||||
|
String query = "DELETE FROM group_permissions WHERE groupName = ? AND permission = ? AND context = ?";
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement(query);
|
||||||
|
|
||||||
|
statement.setString(1, groupName);
|
||||||
|
statement.setString(2, permission);
|
||||||
|
statement.setString(3, context);
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package me.monster.ranks.database.managers;
|
||||||
|
|
||||||
|
import me.monster.ranks.database.dbManager;
|
||||||
|
import me.monster.ranks.database.models.userInfo;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class players extends dbManager {
|
||||||
|
|
||||||
|
public static userInfo findPlayerGroupByUUID(String uuid) throws SQLException {
|
||||||
|
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM player_info WHERE uuid = ?");
|
||||||
|
statement.setString(1, uuid);
|
||||||
|
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
userInfo databaseModel;
|
||||||
|
|
||||||
|
if(resultSet.next()){
|
||||||
|
|
||||||
|
databaseModel = new userInfo(resultSet.getString("uuid"), resultSet.getString("playerRank"), resultSet.getInt("temp"), resultSet.getDate("date"));
|
||||||
|
statement.close();
|
||||||
|
return databaseModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
statement.close();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<userInfo> findPlayerGroups(String uuid) throws SQLException {
|
||||||
|
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM player_info WHERE uuid = ?");
|
||||||
|
statement.setString(1, uuid);
|
||||||
|
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
List<userInfo> databaseModel = new ArrayList<>(); // Use ArrayList to hold all results
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
userInfo user = new userInfo(resultSet.getString("uuid"), resultSet.getString("playerRank"), resultSet.getInt("temp"), resultSet.getTimestamp("date"));
|
||||||
|
databaseModel.add(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
statement.close();
|
||||||
|
|
||||||
|
return databaseModel.isEmpty() ? null : databaseModel; // Return null if the list is empty
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void createPlayer(userInfo databaseModel) throws SQLException {
|
||||||
|
PreparedStatement statement = getConnection()
|
||||||
|
.prepareStatement("INSERT INTO player_info (uuid, playerRank, temp, date) VALUES (?, ?, ?, ?)");
|
||||||
|
statement.setString(1, databaseModel.getPlayerUUID());
|
||||||
|
statement.setString(2, "default");
|
||||||
|
statement.setInt(3, 0);
|
||||||
|
statement.setDate(4, null);
|
||||||
|
statement.executeUpdate();
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updatePlayerGroups(userInfo databaseModel) throws SQLException {
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement("UPDATE player_info SET playerRank = ?, temp = ?, date = ? WHERE uuid = ?");
|
||||||
|
statement.setString(1, databaseModel.getPlayerRank());
|
||||||
|
statement.setInt(2, databaseModel.getPlayerRankTemp());
|
||||||
|
statement.setDate(3, (Date) databaseModel.getDate());
|
||||||
|
statement.setString(4, databaseModel.getPlayerUUID());
|
||||||
|
statement.executeUpdate();
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deletePlayerGroups(userInfo databaseModel) throws SQLException {
|
||||||
|
|
||||||
|
PreparedStatement statement = getConnection().prepareStatement("DELETE FROM player_info WHERE uuid = ? AND playerRank = ?");
|
||||||
|
statement.setString(1, databaseModel.getPlayerUUID());
|
||||||
|
statement.setString(2, databaseModel.getPlayerRank());
|
||||||
|
|
||||||
|
statement.executeUpdate();
|
||||||
|
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package me.monster.ranks.database.models;
|
||||||
|
|
||||||
|
public class groupPermissions {
|
||||||
|
|
||||||
|
private String groupName;
|
||||||
|
private String permission;
|
||||||
|
private Integer value;
|
||||||
|
private String context;
|
||||||
|
|
||||||
|
public groupPermissions(String groupName, String permission, Integer value, String context) {
|
||||||
|
this.groupName = groupName;
|
||||||
|
this.permission = permission;
|
||||||
|
this.value = value;
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupName() {
|
||||||
|
return groupName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupName(String groupName) {
|
||||||
|
this.groupName = groupName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPermission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermission(String permission) {
|
||||||
|
this.permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContext(String context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
}
|
||||||
58
src/main/java/me/monster/ranks/database/models/ranks.java
Normal file
58
src/main/java/me/monster/ranks/database/models/ranks.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package me.monster.ranks.database.models;
|
||||||
|
|
||||||
|
public class ranks {
|
||||||
|
private String groupName;
|
||||||
|
private String groupPrefix;
|
||||||
|
private String groupSuffix;
|
||||||
|
private Integer groupWeight;
|
||||||
|
private String groupParent;
|
||||||
|
|
||||||
|
public ranks(String groupName, String groupPrefix, String groupSuffix, Integer groupWeight, String groupParent) {
|
||||||
|
this.groupName = groupName;
|
||||||
|
this.groupPrefix = groupPrefix;
|
||||||
|
this.groupSuffix = groupSuffix;
|
||||||
|
this.groupWeight = groupWeight;
|
||||||
|
this.groupParent = groupParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupName() {
|
||||||
|
return groupName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupName(String groupName) {
|
||||||
|
this.groupName = groupName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupPrefix() {
|
||||||
|
return groupPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupPrefix(String groupPrefix) {
|
||||||
|
this.groupPrefix = groupPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupSuffix() {
|
||||||
|
return groupSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupSuffix(String groupSuffix) {
|
||||||
|
this.groupSuffix = groupSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getGroupWeight() {
|
||||||
|
return groupWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupWeight(Integer groupWeight) {
|
||||||
|
this.groupWeight = groupWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupParent() {
|
||||||
|
return groupParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupParent(String groupParent) {
|
||||||
|
this.groupParent = groupParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
49
src/main/java/me/monster/ranks/database/models/userInfo.java
Normal file
49
src/main/java/me/monster/ranks/database/models/userInfo.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package me.monster.ranks.database.models;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class userInfo {
|
||||||
|
private String playerUUID;
|
||||||
|
private String playerRank;
|
||||||
|
private Integer temp;
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
public userInfo(String playerUUID, String playerRank, Integer temp, Date date) {
|
||||||
|
this.playerUUID = playerUUID;
|
||||||
|
this.playerRank = playerRank;
|
||||||
|
this.temp = temp;
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlayerUUID() {
|
||||||
|
return playerUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayerUUID(String playerUUID) {
|
||||||
|
this.playerUUID = playerUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlayerRank() {
|
||||||
|
return playerRank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayerRank(String playerRank) {
|
||||||
|
this.playerRank = playerRank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPlayerRankTemp() {
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayerRankTemp(Integer temp) {
|
||||||
|
this.temp = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/main/java/me/monster/ranks/listeners/chatListener.java
Normal file
19
src/main/java/me/monster/ranks/listeners/chatListener.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package me.monster.ranks.listeners;
|
||||||
|
|
||||||
|
import me.monster.ranks.utils.groupsPriority;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class chatListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onChat(org.bukkit.event.player.AsyncPlayerChatEvent event) {
|
||||||
|
Player p = event.getPlayer();
|
||||||
|
|
||||||
|
event.setFormat(groupsPriority.getHighestPrefix(p) + " " + event.getPlayer().getDisplayName() + groupsPriority.getHighestSuffix(p) + ": " + event.getMessage());
|
||||||
|
event.setCancelled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
37
src/main/java/me/monster/ranks/listeners/joinListener.java
Normal file
37
src/main/java/me/monster/ranks/listeners/joinListener.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package me.monster.ranks.listeners;
|
||||||
|
|
||||||
|
import me.monster.ranks.Main;
|
||||||
|
import me.monster.ranks.database.dbManager;
|
||||||
|
import me.monster.ranks.database.models.userInfo;
|
||||||
|
import me.monster.ranks.utils.updatePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class joinListener implements Listener {
|
||||||
|
|
||||||
|
public void createPlayer(Player player) throws SQLException {
|
||||||
|
userInfo userInfo2 = dbManager.findPlayerGroupByUUID(player.getUniqueId().toString());
|
||||||
|
|
||||||
|
if(userInfo2 == null) {
|
||||||
|
dbManager.createPlayer(new userInfo(player.getUniqueId().toString(), "default", 0, null));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent event) throws SQLException {
|
||||||
|
Player p = event.getPlayer();
|
||||||
|
try {
|
||||||
|
createPlayer(p);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Main.getLogger("Could not update player stats after join.");
|
||||||
|
}
|
||||||
|
new updatePlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package me.monster.ranks.permission;
|
||||||
|
|
||||||
|
import me.monster.ranks.Main;
|
||||||
|
import me.monster.ranks.database.dbManager;
|
||||||
|
import me.monster.ranks.database.models.groupPermissions;
|
||||||
|
import me.monster.ranks.database.models.ranks;
|
||||||
|
import me.monster.ranks.utils.groupsPriority;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static me.monster.ranks.config.configManager.configFile;
|
||||||
|
|
||||||
|
public class permissionManager {
|
||||||
|
|
||||||
|
static HashMap<UUID, PermissionAttachment> perms = new HashMap<>();
|
||||||
|
|
||||||
|
private static final YamlConfiguration config = configFile();
|
||||||
|
|
||||||
|
|
||||||
|
public static void loadAndApplyPermissions(Player player) {
|
||||||
|
try {
|
||||||
|
// Step 1: Get the player's group and server context
|
||||||
|
ranks groupName = groupsPriority.getHighestGroup(player);
|
||||||
|
|
||||||
|
// Step 2: Fetch the permissions for the group and context
|
||||||
|
List<groupPermissions> permissions = dbManager.fetchGroupPermissions(groupName.getGroupName());
|
||||||
|
|
||||||
|
// Step 3: Apply the permissions to the player
|
||||||
|
applyPermissionsToPlayer(player, permissions);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace(); // Log or handle the exception as needed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getServerName() {
|
||||||
|
return config.getString("server.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyPermissionsToPlayer(Player player, List<groupPermissions> permissions) {
|
||||||
|
PermissionAttachment attachment = player.addAttachment(Main.getPlugin());
|
||||||
|
removePermissions(player, attachment);
|
||||||
|
|
||||||
|
// Clear existing permissions (optional: only if you need to refresh)
|
||||||
|
attachment.getPermissions().clear();
|
||||||
|
|
||||||
|
// Loop through all the permissions for the player's group
|
||||||
|
for (groupPermissions permission : permissions) {
|
||||||
|
String perm = permission.getPermission();
|
||||||
|
boolean allow = permission.getValue() == 1; // 1 = allow, 0 = deny
|
||||||
|
if (permission.getContext().equals("server=" + getServerName()) || permission.getContext().isEmpty()) {
|
||||||
|
perms.put(player.getUniqueId(), attachment);
|
||||||
|
PermissionAttachment pperms = perms.get(player.getUniqueId());
|
||||||
|
pperms.setPermission(perm, allow);
|
||||||
|
}
|
||||||
|
if (permission.getPermission().equals("*")) {
|
||||||
|
getAllPermissions(player, attachment, allow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getAllPermissions(Player player, PermissionAttachment attachment, boolean allow) {
|
||||||
|
Set<Permission> permissions = Main.getPlugin().getServer().getPluginManager().getPermissions();
|
||||||
|
for (Permission permission : permissions) {
|
||||||
|
perms.put(player.getUniqueId(), attachment);
|
||||||
|
PermissionAttachment pperms = perms.get(player.getUniqueId());
|
||||||
|
pperms.setPermission(permission, allow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removePermissions(Player player, PermissionAttachment attachment) {
|
||||||
|
for (PermissionAttachmentInfo perm : player.getEffectivePermissions()) {
|
||||||
|
perms.put(player.getUniqueId(), attachment);
|
||||||
|
PermissionAttachment pperms = perms.get(player.getUniqueId());
|
||||||
|
pperms.unsetPermission(String.valueOf(perm));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
src/main/java/me/monster/ranks/utils/defaultGroups.java
Normal file
22
src/main/java/me/monster/ranks/utils/defaultGroups.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package me.monster.ranks.utils;
|
||||||
|
|
||||||
|
import me.monster.ranks.database.dbManager;
|
||||||
|
import me.monster.ranks.database.models.ranks;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class defaultGroups {
|
||||||
|
public void createDefaultGroups() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (dbManager.findGroupByName("default") == null) {
|
||||||
|
dbManager.createGroup(new ranks("default", "Player", "", 1, "default"));
|
||||||
|
}
|
||||||
|
if (dbManager.findGroupByName("owner") == null ){
|
||||||
|
dbManager.createGroup(new ranks("owner", "Owner ", "", 90, "default"));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
57
src/main/java/me/monster/ranks/utils/groupsPriority.java
Normal file
57
src/main/java/me/monster/ranks/utils/groupsPriority.java
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package me.monster.ranks.utils;
|
||||||
|
|
||||||
|
import me.monster.ranks.database.dbManager;
|
||||||
|
import me.monster.ranks.database.models.ranks;
|
||||||
|
import me.monster.ranks.database.models.userInfo;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class groupsPriority {
|
||||||
|
|
||||||
|
public static ranks getHighestGroup(Player p) throws SQLException {
|
||||||
|
// Get the list of groups associated with the player (userInfo objects)
|
||||||
|
List<userInfo> test = dbManager.findPlayerGroups(p.getUniqueId().toString());
|
||||||
|
|
||||||
|
String highestGroupName = null;
|
||||||
|
int highestWeight = Integer.MIN_VALUE; // Start with the lowest possible weight
|
||||||
|
|
||||||
|
// Loop through the list of groups associated with the player
|
||||||
|
for (userInfo userInfo : test) {
|
||||||
|
// Assuming test.get(i) contains some identifier that can be used to fetch the group
|
||||||
|
String groupName = userInfo.getPlayerRank(); // Replace with the correct method or field
|
||||||
|
ranks group = dbManager.findGroupByName(groupName); // Retrieve the group from the database
|
||||||
|
|
||||||
|
if (group != null) {
|
||||||
|
// Get the weight of the group
|
||||||
|
int weight = group.getGroupWeight();
|
||||||
|
|
||||||
|
// If the current group weight is higher than the previous highest, update the highest group
|
||||||
|
if (weight > highestWeight) {
|
||||||
|
highestWeight = weight;
|
||||||
|
highestGroupName = group.getGroupName(); // Return the group name with the highest weight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the name of the group with the highest weight
|
||||||
|
return dbManager.findGroupByName(highestGroupName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHighestPrefix(Player p) {
|
||||||
|
try {
|
||||||
|
return getHighestGroup(p).getGroupPrefix();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static String getHighestSuffix(Player p) {
|
||||||
|
try {
|
||||||
|
return getHighestGroup(p).getGroupSuffix();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package me.monster.ranks.utils.loaders;
|
||||||
|
|
||||||
|
import me.monster.ranks.Main;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.JarURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
public class loadCommands {
|
||||||
|
|
||||||
|
public static void load() {
|
||||||
|
Plugin plugin = Main.getPlugin();
|
||||||
|
if (!(plugin instanceof JavaPlugin javaPlugin)) {
|
||||||
|
Bukkit.getLogger().severe("[Commands] Plugin is not an instance of JavaPlugin!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String packageName = javaPlugin.getClass().getPackage().getName() + ".commands";
|
||||||
|
Bukkit.getLogger().info("[Commands] Loading commands from package: " + packageName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (Class<?> clazz : getClassesInJar(packageName, plugin)) {
|
||||||
|
if (!CommandExecutor.class.isAssignableFrom(clazz)) continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object instance;
|
||||||
|
try {
|
||||||
|
instance = clazz.getDeclaredConstructor(Plugin.class).newInstance(plugin);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
String commandName = clazz.getSimpleName().toLowerCase(); // assuming command name is class name
|
||||||
|
PluginCommand command = javaPlugin.getCommand(commandName);
|
||||||
|
if (command != null) {
|
||||||
|
command.setExecutor((CommandExecutor) instance);
|
||||||
|
Bukkit.getLogger().info("[Commands] Registered: " + clazz.getSimpleName());
|
||||||
|
} else {
|
||||||
|
Bukkit.getLogger().warning("[Commands] Command not found for class: " + clazz.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
Bukkit.getLogger().warning("[Commands] No valid constructor found for " + clazz.getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Bukkit.getLogger().severe("[Commands] Failed to load commands:");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?>[] getClassesInJar(String packageName, Plugin plugin) throws IOException {
|
||||||
|
String path = packageName.replace('.', '/');
|
||||||
|
URL url = plugin.getClass().getClassLoader().getResource(path);
|
||||||
|
if (url == null) return new Class<?>[0];
|
||||||
|
|
||||||
|
JarURLConnection connection = (JarURLConnection) url.openConnection();
|
||||||
|
JarFile jarFile = connection.getJarFile();
|
||||||
|
|
||||||
|
return jarFile.stream()
|
||||||
|
.filter(e -> e.getName().startsWith(path) && e.getName().endsWith(".class"))
|
||||||
|
.map(JarEntry::getName)
|
||||||
|
.map(name -> name.replace('/', '.').substring(0, name.length() - 6))
|
||||||
|
.map(className -> {
|
||||||
|
try {
|
||||||
|
return Class.forName(className);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
Bukkit.getLogger().warning("[Commands] Could not load class: " + className);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toArray(Class<?>[]::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package me.monster.ranks.utils.loaders;
|
||||||
|
|
||||||
|
import me.monster.ranks.Main;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.JarURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
public class loadListeners {
|
||||||
|
|
||||||
|
public static void load() {
|
||||||
|
Plugin plugin = Main.getPlugin();
|
||||||
|
String packageName = plugin.getClass().getPackage().getName() + ".listeners";
|
||||||
|
Bukkit.getLogger().info("[Listeners] Loading listeners from package: " + packageName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (Class<?> clazz : getClassesInJar(packageName, plugin)) {
|
||||||
|
if (!Listener.class.isAssignableFrom(clazz)) continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object instance;
|
||||||
|
try {
|
||||||
|
instance = clazz.getDeclaredConstructor(Plugin.class).newInstance(plugin);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().registerEvents((Listener) instance, plugin);
|
||||||
|
Bukkit.getLogger().info("[Listeners] Registered: " + clazz.getSimpleName());
|
||||||
|
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
Bukkit.getLogger().warning("[Listeners] No valid constructor found for " + clazz.getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Bukkit.getLogger().severe("[Listeners] Failed to load listeners:");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?>[] getClassesInJar(String packageName, Plugin plugin) throws IOException {
|
||||||
|
String path = packageName.replace('.', '/');
|
||||||
|
URL url = plugin.getClass().getClassLoader().getResource(path);
|
||||||
|
if (url == null) return new Class<?>[0];
|
||||||
|
|
||||||
|
JarURLConnection connection = (JarURLConnection) url.openConnection();
|
||||||
|
JarFile jarFile = connection.getJarFile();
|
||||||
|
|
||||||
|
return jarFile.stream()
|
||||||
|
.filter(e -> e.getName().startsWith(path) && e.getName().endsWith(".class"))
|
||||||
|
.map(JarEntry::getName)
|
||||||
|
.map(name -> name.replace('/', '.').substring(0, name.length() - 6))
|
||||||
|
.map(className -> {
|
||||||
|
try {
|
||||||
|
return Class.forName(className);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
Bukkit.getLogger().warning("[Listeners] Could not load class: " + className);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toArray(Class<?>[]::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/main/java/me/monster/ranks/utils/updatePlayer.java
Normal file
20
src/main/java/me/monster/ranks/utils/updatePlayer.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package me.monster.ranks.utils;
|
||||||
|
|
||||||
|
import me.monster.ranks.database.models.ranks;
|
||||||
|
import me.monster.ranks.permission.permissionManager;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class updatePlayer {
|
||||||
|
public updatePlayer(Player player) throws SQLException {
|
||||||
|
|
||||||
|
ranks highestGroup = groupsPriority.getHighestGroup(player);
|
||||||
|
|
||||||
|
player.setPlayerListName(highestGroup.getGroupPrefix() + " " + player.getName());
|
||||||
|
permissionManager.loadAndApplyPermissions(player);
|
||||||
|
player.recalculatePermissions();
|
||||||
|
player.updateCommands();
|
||||||
|
player.sendMessage("Your group has been updated to " + highestGroup.getGroupName());
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/main/resources/config.yml
Normal file
9
src/main/resources/config.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
mysql:
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 3306
|
||||||
|
user: root
|
||||||
|
password: password
|
||||||
|
database: permission
|
||||||
|
|
||||||
|
server:
|
||||||
|
name: "server_name"
|
||||||
12
src/main/resources/plugin.yml
Normal file
12
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
name: Ranks
|
||||||
|
version: '1.0'
|
||||||
|
main: me.monster.ranks.Main
|
||||||
|
api-version: '1.21'
|
||||||
|
prefix: Ranks
|
||||||
|
load: STARTUP
|
||||||
|
authors: [ 41ms_ ]
|
||||||
|
website: 41ms.fr
|
||||||
|
|
||||||
|
commands:
|
||||||
|
test:
|
||||||
|
description: test command
|
||||||
Reference in New Issue
Block a user