mirror of
https://github.com/SimplexDevelopment/Traverse.git
synced 2024-12-21 21:57:36 +00:00
Code push
This commit is contained in:
parent
cc6eef4a3e
commit
b730f329fe
3
.gitignore
vendored
3
.gitignore
vendored
@ -22,3 +22,6 @@
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
.gradle/
|
||||
.idea/
|
||||
|
9
Traverse.iml
Normal file
9
Traverse.iml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
49
build.gradle
Normal file
49
build.gradle
Normal file
@ -0,0 +1,49 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'mc.unraveled.reforged'
|
||||
version = '1.0.0'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = 'papermc-repo'
|
||||
url = 'https://repo.papermc.io/repository/maven-public/'
|
||||
}
|
||||
maven {
|
||||
name = 'sonatype'
|
||||
url = 'https://oss.sonatype.org/content/groups/public/'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.projectlombok:lombok:1.18.20'
|
||||
implementation 'org.postgresql:postgresql:42.2.20'
|
||||
compileOnly 'io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
def targetJavaVersion = 17
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
sourceCompatibility = javaVersion
|
||||
targetCompatibility = javaVersion
|
||||
if (JavaVersion.current() < javaVersion) {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||
options.release = 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
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
234
gradlew
vendored
Normal file
234
gradlew
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
#!/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/master/subprojects/plugins/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
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&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
|
||||
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" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
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
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# 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" "$@"
|
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem 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%" == "0" goto execute
|
||||
|
||||
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 execute
|
||||
|
||||
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
|
||||
|
||||
: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%"=="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
|
1
settings.gradle
Normal file
1
settings.gradle
Normal file
@ -0,0 +1 @@
|
||||
rootProject.name = 'Traverse'
|
7
src/main/java/mc/unraveled/reforged/api/Baker.java
Normal file
7
src/main/java/mc/unraveled/reforged/api/Baker.java
Normal file
@ -0,0 +1,7 @@
|
||||
package mc.unraveled.reforged.api;
|
||||
|
||||
public interface Baker {
|
||||
void bake();
|
||||
|
||||
void unbake();
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package mc.unraveled.reforged.api;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
public interface ICommandBase extends TabExecutor {
|
||||
Component run(CommandSender sender, String[] args);
|
||||
}
|
9
src/main/java/mc/unraveled/reforged/api/Locker.java
Normal file
9
src/main/java/mc/unraveled/reforged/api/Locker.java
Normal file
@ -0,0 +1,9 @@
|
||||
package mc.unraveled.reforged.api;
|
||||
|
||||
public interface Locker {
|
||||
Object lock = new Object();
|
||||
|
||||
default Object lock() {
|
||||
return lock;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package mc.unraveled.reforged.api;
|
||||
|
||||
public interface Serializable<T> {
|
||||
String serialize();
|
||||
|
||||
T deserialize(String formatted);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package mc.unraveled.reforged.api.annotations;
|
||||
|
||||
public @interface CommandInfo {
|
||||
String name();
|
||||
|
||||
String permission() default "traverse.op";
|
||||
|
||||
String usage() default "/<command>";
|
||||
|
||||
String description() default "No description provided.";
|
||||
|
||||
String[] aliases() default {};
|
||||
}
|
78
src/main/java/mc/unraveled/reforged/banning/AbstractBan.java
Normal file
78
src/main/java/mc/unraveled/reforged/banning/AbstractBan.java
Normal file
@ -0,0 +1,78 @@
|
||||
package mc.unraveled.reforged.banning;
|
||||
|
||||
import lombok.Getter;
|
||||
import mc.unraveled.reforged.api.Serializable;
|
||||
import mc.unraveled.reforged.util.Pair;
|
||||
import mc.unraveled.reforged.util.Utilities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public abstract class AbstractBan implements Serializable<AbstractBan> {
|
||||
private final String uuid;
|
||||
private final String ip;
|
||||
private final String source;
|
||||
private final String reason;
|
||||
private final long propogated;
|
||||
private final long expiry;
|
||||
private final List<Pair<String, String>> contentPairs;
|
||||
private boolean active;
|
||||
|
||||
public AbstractBan(String uuid, String ip, String source, String reason, long propogated, long expiry, boolean active) {
|
||||
this.uuid = uuid;
|
||||
this.ip = ip;
|
||||
this.source = source;
|
||||
this.reason = reason;
|
||||
this.propogated = propogated;
|
||||
this.expiry = expiry;
|
||||
this.active = active;
|
||||
|
||||
this.contentPairs = List.of(
|
||||
new Pair<>("uuid", uuid),
|
||||
new Pair<>("ip", ip),
|
||||
new Pair<>("source", source),
|
||||
new Pair<>("reason", reason),
|
||||
new Pair<>("propogated", String.valueOf(propogated)),
|
||||
new Pair<>("expiry", String.valueOf(expiry)),
|
||||
new Pair<>("active", String.valueOf(active))
|
||||
);
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return Utilities.serialize(contentPairs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBan deserialize(String formatted) {
|
||||
char delimiter = ':';
|
||||
char end = ';';
|
||||
char uuid = 'u';
|
||||
char ip = 'i';
|
||||
char reason = 'r';
|
||||
char source = 's';
|
||||
char propogated = 'p';
|
||||
char expiry = 'e';
|
||||
char active = 'a';
|
||||
|
||||
String uuidString = formatted.substring(formatted.indexOf(uuid) + 1, formatted.indexOf(end));
|
||||
String ipString = formatted.substring(formatted.indexOf(ip) + 1, formatted.indexOf(end));
|
||||
String reasonString = formatted.substring(formatted.indexOf(reason) + 1, formatted.indexOf(end));
|
||||
String sourceString = formatted.substring(formatted.indexOf(source) + 1, formatted.indexOf(end));
|
||||
String propogatedString = formatted.substring(formatted.indexOf(propogated) + 1, formatted.indexOf(end));
|
||||
String expiryString = formatted.substring(formatted.indexOf(expiry) + 1, formatted.indexOf(end));
|
||||
String activeString = formatted.substring(formatted.indexOf(active) + 1, formatted.indexOf(end));
|
||||
|
||||
return new SimpleBan(uuidString,
|
||||
ipString,
|
||||
reasonString,
|
||||
sourceString,
|
||||
Long.parseLong(propogatedString),
|
||||
Long.parseLong(expiryString),
|
||||
Boolean.parseBoolean(activeString));
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package mc.unraveled.reforged.banning;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import mc.unraveled.reforged.api.Baker;
|
||||
import mc.unraveled.reforged.api.Locker;
|
||||
import mc.unraveled.reforged.plugin.Traverse;
|
||||
import mc.unraveled.reforged.storage.DBBan;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LocalizedBanList implements Locker, Baker {
|
||||
private final Traverse plugin;
|
||||
|
||||
private Set<AbstractBan> storedBans; // This should only be reassigned by the baker.
|
||||
private boolean baked = false; // This should only be reassigned by the baker.
|
||||
|
||||
@SneakyThrows
|
||||
public LocalizedBanList(Traverse plugin) {
|
||||
this.storedBans = new HashSet<>();
|
||||
this.plugin = plugin;
|
||||
|
||||
synchronized (lock()) {
|
||||
DBBan banHandler = new DBBan(plugin.getSQLManager().establish());
|
||||
storedBans.addAll(banHandler.all());
|
||||
banHandler.close();
|
||||
|
||||
lock().wait(1000);
|
||||
}
|
||||
|
||||
bake();
|
||||
}
|
||||
|
||||
public void insert(AbstractBan ban) {
|
||||
if (baked) throw new IllegalStateException("Cannot insert into a baked list.");
|
||||
|
||||
storedBans.add(ban);
|
||||
|
||||
lock().notify();
|
||||
}
|
||||
|
||||
public void eject(AbstractBan ban) {
|
||||
if (baked) throw new IllegalStateException("Cannot eject from a baked list.");
|
||||
|
||||
storedBans.remove(ban);
|
||||
|
||||
lock().notify();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bake() {
|
||||
if (baked) return;
|
||||
|
||||
storedBans = storedBans.stream().collect(Collectors.toUnmodifiableSet());
|
||||
|
||||
baked = true;
|
||||
lock().notify();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbake() {
|
||||
if (!baked) return;
|
||||
|
||||
storedBans = new HashSet<>(storedBans);
|
||||
|
||||
baked = false;
|
||||
lock().notify();
|
||||
}
|
||||
}
|
22
src/main/java/mc/unraveled/reforged/banning/SimpleBan.java
Normal file
22
src/main/java/mc/unraveled/reforged/banning/SimpleBan.java
Normal file
@ -0,0 +1,22 @@
|
||||
package mc.unraveled.reforged.banning;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SimpleBan extends AbstractBan {
|
||||
public SimpleBan(Player player, CommandSender source, String reason, Date propogated, Date expiry, boolean active) {
|
||||
super(player.getUniqueId().toString(),
|
||||
player.getAddress().getAddress().getHostAddress(),
|
||||
source.getName(),
|
||||
reason,
|
||||
propogated.getTime(),
|
||||
expiry.getTime(),
|
||||
active);
|
||||
}
|
||||
|
||||
public SimpleBan(String uuid, String ip, String source, String reason, long propogated, long expiry, boolean active) {
|
||||
super(uuid, ip, source, reason, propogated, expiry, active);
|
||||
}
|
||||
}
|
16
src/main/java/mc/unraveled/reforged/command/TraverseCMD.java
Normal file
16
src/main/java/mc/unraveled/reforged/command/TraverseCMD.java
Normal file
@ -0,0 +1,16 @@
|
||||
package mc.unraveled.reforged.command;
|
||||
|
||||
import mc.unraveled.reforged.command.base.AbstractCommandBase;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class TraverseCMD extends AbstractCommandBase {
|
||||
public TraverseCMD() {
|
||||
super("traverse.cmd", "You do not have permission to use this command!", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component run(CommandSender sender, String[] args) {
|
||||
return Component.text("Hello!");
|
||||
}
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
package mc.unraveled.reforged.command.base;
|
||||
|
||||
import mc.unraveled.reforged.api.ICommandBase;
|
||||
import mc.unraveled.reforged.util.BasicColors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class AbstractCommandBase extends TPermission implements ICommandBase {
|
||||
/**
|
||||
* @param permission The permission the user should have to run the command
|
||||
* @param permissionMessage The message to send when the user does not have the permission to run the command.
|
||||
* @param allowConsole Whether to allow the command to be run anywhere, or only in game.
|
||||
*/
|
||||
public AbstractCommandBase(@NotNull String permission, String permissionMessage, boolean allowConsole) {
|
||||
super(permission, permissionMessage, allowConsole);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permission The permission the user should have to run the command
|
||||
* @param permissionMessage The message to send when the user does not have the permission to run the command.
|
||||
*/
|
||||
public AbstractCommandBase(@NotNull String permission, String permissionMessage) {
|
||||
this(permission, permissionMessage, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permission The permission the user should have to run the command
|
||||
* @param allowConsole Whether to allow the command to be run anywhere, or only in game.
|
||||
*/
|
||||
public AbstractCommandBase(@NotNull String permission, boolean allowConsole) {
|
||||
this(permission, "You do not have permission to use this command!", allowConsole);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permission The permission the user should have to run the command
|
||||
*/
|
||||
public AbstractCommandBase(@NotNull String permission) {
|
||||
this(permission, "You do not have permission to use this command!", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String lbl, String[] args) {
|
||||
if (!hasPermission(sender)) {
|
||||
sender.sendMessage(msg(getPermissionMessage(), BasicColors.RED));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player) && !allowConsole()) {
|
||||
sender.sendMessage(msg("This command can only be run in game."));
|
||||
}
|
||||
|
||||
sender.sendMessage(run(sender, args));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable
|
||||
List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a text component for Kyori friendly messaging.
|
||||
*
|
||||
* @param text The text to convert to a component
|
||||
* @return A {@link TextComponent} containing the message provided in {@param text}
|
||||
*/
|
||||
@NotNull
|
||||
public TextComponent msg(@NotNull String text) {
|
||||
return Component.empty().content(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a text component for Kyori friendly messaging.
|
||||
*
|
||||
* @param text The text to convert to a Component
|
||||
* @param color The color you'd like the text. These colors are basic and the majority of which are provided by Minecraft's native color system.
|
||||
* @return A {@link TextComponent} containing the message provided in {@param text} with the provided {@param color}
|
||||
*/
|
||||
@NotNull
|
||||
public TextComponent msg(@NotNull String text, @NotNull BasicColors color) {
|
||||
return Component.empty().content(text).color(color.getColor());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Player getPlayer(@NotNull String name) {
|
||||
return Bukkit.getServer().getPlayer(name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Player getPlayer(@NotNull UUID uuid) {
|
||||
return Bukkit.getServer().getPlayer(uuid);
|
||||
}
|
||||
|
||||
public List<? extends Player> getOnlinePlayers() {
|
||||
return Bukkit.getOnlinePlayers().stream().toList();
|
||||
}
|
||||
|
||||
public void broadcast(String text) {
|
||||
Bukkit.getServer().broadcast(msg(text));
|
||||
}
|
||||
|
||||
public void broadcast(String text, BasicColors color) {
|
||||
Bukkit.getServer().broadcast(msg(text, color));
|
||||
}
|
||||
|
||||
public void enablePlugin(Plugin plugin) {
|
||||
Bukkit.getServer().getPluginManager().enablePlugin(plugin);
|
||||
}
|
||||
|
||||
public void disablePlugin(Plugin plugin) {
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package mc.unraveled.reforged.command.base;
|
||||
|
||||
import mc.unraveled.reforged.api.annotations.CommandInfo;
|
||||
import mc.unraveled.reforged.plugin.Traverse;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandLoader {
|
||||
private final Traverse plugin;
|
||||
private final List<DummyCommand> commandList = new ArrayList<>();
|
||||
private final String FALLBACK_PREFIX;
|
||||
|
||||
/**
|
||||
* @param plugin Your plugin instance
|
||||
* @param fallbackPrefix The fallback prefix to use in case your plugin fails to provide a namespace.
|
||||
*/
|
||||
public CommandLoader(Traverse plugin, String fallbackPrefix) {
|
||||
this.FALLBACK_PREFIX = fallbackPrefix;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will register your command internally within the CommandLoader.
|
||||
* Instances of commands will be cached and readied for loading into Paper.
|
||||
* You should always run this before using {@link CommandLoader#load()}, otherwise your commands will not be loaded.
|
||||
*
|
||||
* @param command A new instance of your command which should extend CommandBase.
|
||||
*/
|
||||
public void register(AbstractCommandBase command) {
|
||||
Class<? extends AbstractCommandBase> cmd = command.getClass();
|
||||
if (cmd.getDeclaredAnnotation(CommandInfo.class) != null) {
|
||||
CommandInfo info = cmd.getDeclaredAnnotation(CommandInfo.class);
|
||||
DummyCommand dummy = new DummyCommand(plugin,
|
||||
command,
|
||||
info.name(),
|
||||
info.description(),
|
||||
info.usage(),
|
||||
Arrays.asList(info.aliases()));
|
||||
commandList.add(dummy);
|
||||
} else {
|
||||
throw new RuntimeException("Missing a required annotation! Unable to load the command.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This will run a loop for each command instance you input and register them all within one method.
|
||||
* This simply runs the array through a stream and uses a lambda reference to {@link CommandLoader#register(CommandBase)} in order to register the commands.
|
||||
* Each command will be loaded in the order it is provided.
|
||||
*
|
||||
* @param commands An indefinite amount of command instances to be registered.
|
||||
*/
|
||||
public void register(AbstractCommandBase... commands) {
|
||||
Arrays.stream(commands).forEachOrdered(this::register);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will load your commands and initialize them within Paper's CommandMap.
|
||||
*/
|
||||
public void load() {
|
||||
commandList.forEach(cmd -> Bukkit.getCommandMap().register(cmd.getName(), FALLBACK_PREFIX, cmd));
|
||||
}
|
||||
|
||||
/**
|
||||
* This will effectively register all your commands and then load them into the Paper CommandMap.
|
||||
*
|
||||
* @param commands An indefinite amount of command instances to be registered and loaded.
|
||||
*/
|
||||
public void registerAndLoad(AbstractCommandBase... commands) {
|
||||
register(commands);
|
||||
load();
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package mc.unraveled.reforged.command.base;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
final class DummyCommand extends Command implements PluginIdentifiableCommand {
|
||||
private final AbstractCommandBase base;
|
||||
private final Plugin plugin;
|
||||
|
||||
/**
|
||||
* @param plugin Your plugin instance.
|
||||
* @param base Your command instance.
|
||||
* @param name The name of your command
|
||||
* @param description The description of your command
|
||||
* @param usageMessage The usage for your command
|
||||
* @param aliases The aliases for your command.
|
||||
*/
|
||||
DummyCommand(@NotNull Plugin plugin, @NotNull AbstractCommandBase base, @NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases) {
|
||||
super(name, description, usageMessage, aliases);
|
||||
this.setName(name);
|
||||
this.setDescription(description);
|
||||
this.setUsage(usageMessage);
|
||||
this.setAliases(aliases);
|
||||
this.setPermission(base.getPermission());
|
||||
this.permissionMessage(Component.empty().content(base.getPermissionMessage()));
|
||||
this.base = base;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual executor method.
|
||||
*
|
||||
* @param sender The user who sent the command
|
||||
* @param commandLabel The name of the command
|
||||
* @param args Any additional arguments the user may input
|
||||
* @return Successfully executed the command or not
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
base.onCommand(sender, this, commandLabel, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Gets your plugin (Generic)
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Plugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package mc.unraveled.reforged.command.base;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public abstract class TPermission {
|
||||
private final String permission;
|
||||
private final String permissionMessage;
|
||||
private final boolean allowConsole;
|
||||
|
||||
/**
|
||||
* @param permission The permission the user should have to run the command
|
||||
* @param permissionMessage The message to send when the user does not have the permission to run the command.
|
||||
* @param allowConsole Whether to allow the command to be run anywhere, or only in game.
|
||||
*/
|
||||
public TPermission(String permission, String permissionMessage, boolean allowConsole) {
|
||||
this.permission = permission;
|
||||
this.permissionMessage = permissionMessage;
|
||||
this.allowConsole = allowConsole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the permission for the command it represents.
|
||||
*
|
||||
* @return The permission required to run the command.
|
||||
*/
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message to display when a user doesn't have permission to run the command.
|
||||
*
|
||||
* @return The message to send the user when they do not have the required permission.
|
||||
*/
|
||||
public String getPermissionMessage() {
|
||||
return permissionMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the source of the command has the permission required to run it.
|
||||
*
|
||||
* @param sender The command source
|
||||
* @return Whether the sender has the permission or not.
|
||||
*/
|
||||
public boolean hasPermission(CommandSender sender) {
|
||||
return sender.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether to allow the command to be run from anywhere, or only players.
|
||||
*/
|
||||
public boolean allowConsole() {
|
||||
return allowConsole;
|
||||
}
|
||||
}
|
24
src/main/java/mc/unraveled/reforged/permission/Rank.java
Normal file
24
src/main/java/mc/unraveled/reforged/permission/Rank.java
Normal file
@ -0,0 +1,24 @@
|
||||
package mc.unraveled.reforged.permission;
|
||||
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public enum Rank {
|
||||
EXECUTIVE("executive", "Exec", TextColor.color(254, 0, 0), 7),
|
||||
DEV("developer", "Dev", TextColor.color(165, 0, 218), 6),
|
||||
ADMIN("admin", "Admin", TextColor.color(214, 108, 32), 5),
|
||||
MOD("mod", "Mod", TextColor.color(0, 198, 98), 4),
|
||||
BUILDER("builder", "Bldr", TextColor.color(0, 168, 238), 3),
|
||||
VIP("vip", "VIP", TextColor.color(238, 98, 150), 2),
|
||||
OP("op", "OP", TextColor.color(198, 64, 64), 1),
|
||||
NON_OP("guest", "", TextColor.color(178, 178, 178), 0);
|
||||
|
||||
final RankAttachment attachment;
|
||||
|
||||
Rank(String name, String tag, TextColor color, int weight) {
|
||||
this.attachment = new RankAttachment(name, tag, color, weight);
|
||||
}
|
||||
|
||||
public RankAttachment getAttachment() {
|
||||
return attachment;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package mc.unraveled.reforged.permission;
|
||||
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public class RankAttachment {
|
||||
private final String name;
|
||||
private final String tag;
|
||||
private final TextColor color;
|
||||
private final int weight;
|
||||
|
||||
protected RankAttachment(String name, String tag, TextColor color, int weight) {
|
||||
this.name = name;
|
||||
this.tag = tag;
|
||||
this.color = color;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public TextColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return weight;
|
||||
}
|
||||
}
|
37
src/main/java/mc/unraveled/reforged/plugin/Traverse.java
Normal file
37
src/main/java/mc/unraveled/reforged/plugin/Traverse.java
Normal file
@ -0,0 +1,37 @@
|
||||
package mc.unraveled.reforged.plugin;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import mc.unraveled.reforged.permission.Rank;
|
||||
import mc.unraveled.reforged.storage.DBConnectionHandler;
|
||||
import mc.unraveled.reforged.storage.DBGroup;
|
||||
import mc.unraveled.reforged.storage.DBProperties;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class Traverse extends JavaPlugin {
|
||||
|
||||
private DBConnectionHandler handler;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
initDatabaseGroups();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void initDatabaseGroups() {
|
||||
handler = new DBConnectionHandler(new DBProperties("groups.properties"));
|
||||
DBGroup groupHandler = new DBGroup(handler.establish());
|
||||
Arrays.stream(Rank.values()).forEach(groupHandler::createTable);
|
||||
groupHandler.close();
|
||||
}
|
||||
|
||||
public DBConnectionHandler getSQLManager() {
|
||||
return handler;
|
||||
}
|
||||
}
|
87
src/main/java/mc/unraveled/reforged/storage/DBBan.java
Normal file
87
src/main/java/mc/unraveled/reforged/storage/DBBan.java
Normal file
@ -0,0 +1,87 @@
|
||||
package mc.unraveled.reforged.storage;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import mc.unraveled.reforged.banning.AbstractBan;
|
||||
import mc.unraveled.reforged.banning.SimpleBan;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class DBBan {
|
||||
@Getter
|
||||
private Connection connection;
|
||||
|
||||
public DBBan(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void createTable() {
|
||||
PreparedStatement statement = getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS bans (uuid VARCHAR(36), ip VARCHAR(16), reason VARCHAR(64), banned_by VARCHAR(16), banned_at BIGINT, expires_at BIGINT, active BOOLEAN, PRIMARY KEY (uuid));");
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void addBan(AbstractBan ban) {
|
||||
PreparedStatement statement = getConnection().prepareStatement("INSERT INTO bans (uuid, ip, reason, banned_by, banned_at, expires_at, active) VALUES (?, ?, ?, ?, ?, ?, ?);");
|
||||
statement.setString(1, ban.getUuid());
|
||||
statement.setString(2, ban.getIp());
|
||||
statement.setString(3, ban.getReason());
|
||||
statement.setString(4, ban.getSource());
|
||||
statement.setLong(5, ban.getPropogated());
|
||||
statement.setLong(6, ban.getExpiry());
|
||||
statement.setBoolean(7, ban.isActive());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Nullable
|
||||
public AbstractBan getBan(@NotNull UUID uuid) {
|
||||
PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM bans WHERE uuid = ?;");
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet rs = statement.executeQuery();
|
||||
if (rs.next()) {
|
||||
return new SimpleBan(rs.getString("uuid"),
|
||||
rs.getString("ip"),
|
||||
rs.getString("reason"),
|
||||
rs.getString("banned_by"),
|
||||
rs.getLong("banned_at"),
|
||||
rs.getLong("expires_at"),
|
||||
rs.getBoolean("active"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public List<AbstractBan> all() {
|
||||
PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM bans;");
|
||||
ResultSet rs = statement.executeQuery();
|
||||
List<AbstractBan> bans = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
bans.add(new SimpleBan(rs.getString("uuid"),
|
||||
rs.getString("ip"),
|
||||
rs.getString("reason"),
|
||||
rs.getString("banned_by"),
|
||||
rs.getLong("banned_at"),
|
||||
rs.getLong("expires_at"),
|
||||
rs.getBoolean("active")));
|
||||
}
|
||||
return bans;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void close() {
|
||||
getConnection().close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package mc.unraveled.reforged.storage;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class DBConnectionHandler {
|
||||
private final DBProperties properties;
|
||||
|
||||
public DBConnectionHandler(DBProperties properties) throws SQLException {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public Connection establish() {
|
||||
return DriverManager.getConnection(properties.getUrl(), properties.getUsername(), properties.getPassword());
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ContextConnection establishContext() {
|
||||
return new ContextConnection(DriverManager.getConnection(properties.getUrl(), properties.getUsername(), properties.getPassword()));
|
||||
}
|
||||
|
||||
public record ContextConnection(Connection connection) implements AutoCloseable {
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void close() {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
92
src/main/java/mc/unraveled/reforged/storage/DBGroup.java
Normal file
92
src/main/java/mc/unraveled/reforged/storage/DBGroup.java
Normal file
@ -0,0 +1,92 @@
|
||||
package mc.unraveled.reforged.storage;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.SneakyThrows;
|
||||
import mc.unraveled.reforged.permission.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DBGroup {
|
||||
@Getter
|
||||
private Connection connection;
|
||||
|
||||
public DBGroup(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void createTable(Rank rank) {
|
||||
PreparedStatement statement = getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS " + rank.getAttachment().getName() + " (uuid VARCHAR(36), permissions VARCHAR(64));");
|
||||
statement.execute();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void addPermission(Rank rank, String permission) {
|
||||
PreparedStatement statement = getConnection().prepareStatement("INSERT INTO " + rank.getAttachment().getName() + " (permissions) VALUES (?);");
|
||||
statement.setString(1, permission);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void removePermission(Rank rank, String permission) {
|
||||
PreparedStatement statement = getConnection().prepareStatement("DELETE FROM " + rank.getAttachment().getName() + " WHERE permissions = ?;");
|
||||
statement.setString(1, permission);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public List<String> getPermissions(Rank rank) {
|
||||
List<String> permissions = new ArrayList<>();
|
||||
PreparedStatement statement = getConnection().prepareStatement("SELECT permissions FROM " + rank.getAttachment().getName() + ";");
|
||||
ResultSet rs = statement.executeQuery();
|
||||
while (rs.next()) {
|
||||
permissions.add(rs.getString("permissions"));
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void addPlayer(Rank rank, Player player) {
|
||||
PreparedStatement statement = getConnection().prepareStatement("INSERT INTO " + rank.getAttachment().getName() + " (uuid) VALUES (?);");
|
||||
statement.setString(1, player.getUniqueId().toString());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void removePlayer(Rank rank, Player player) {
|
||||
PreparedStatement statement = getConnection().prepareStatement("DELETE FROM " + rank.getAttachment().getName() + " WHERE uuid = ?;");
|
||||
statement.setString(1, player.getUniqueId().toString());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public List<OfflinePlayer> getPlayers(Rank rank) {
|
||||
List<OfflinePlayer> players = new ArrayList<>();
|
||||
PreparedStatement statement = getConnection().prepareStatement("SELECT uuid FROM " + rank.getAttachment().getName() + ";");
|
||||
ResultSet rs = statement.executeQuery();
|
||||
while (rs.next()) {
|
||||
UUID uuid = UUID.fromString(rs.getString("uuid"));
|
||||
players.add(Bukkit.getOfflinePlayer(uuid));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void close() {
|
||||
getConnection().close();
|
||||
}
|
||||
|
||||
public void open(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package mc.unraveled.reforged.storage;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
@Getter
|
||||
public class DBProperties {
|
||||
private final Properties properties;
|
||||
private final String url;
|
||||
private final String driver;
|
||||
private final String databaseType;
|
||||
private final String databaseFile;
|
||||
private final String host;
|
||||
private final String port;
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
public DBProperties(String fileName) {
|
||||
properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileInputStream(fileName));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
driver = properties.getProperty("driver");
|
||||
databaseType = properties.getProperty("databaseType");
|
||||
databaseFile = properties.getProperty("databaseFile");
|
||||
host = properties.getProperty("host");
|
||||
port = properties.getProperty("port");
|
||||
username = properties.getProperty("username");
|
||||
password = properties.getProperty("password");
|
||||
url = driver + ":" + databaseType + "://" + host + ":" + port + "/" + databaseFile;
|
||||
}
|
||||
}
|
36
src/main/java/mc/unraveled/reforged/util/BasicColors.java
Normal file
36
src/main/java/mc/unraveled/reforged/util/BasicColors.java
Normal file
@ -0,0 +1,36 @@
|
||||
package mc.unraveled.reforged.util;
|
||||
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
public enum BasicColors {
|
||||
RED(TextColor.color(255, 0, 0)),
|
||||
DARK_RED(TextColor.color(127, 0, 0)),
|
||||
ORANGE(TextColor.color(255, 165, 0)),
|
||||
DARK_ORANGE(TextColor.color(255, 140, 0)),
|
||||
YELLOW(TextColor.color(255, 255, 0)),
|
||||
GOLD(TextColor.color(255, 215, 0)),
|
||||
GREEN(TextColor.color(0, 255, 0)),
|
||||
DARK_GREEN(TextColor.color(0, 127, 0)),
|
||||
BLUE(TextColor.color(0, 0, 255)),
|
||||
DARK_BLUE(TextColor.color(0, 0, 127)),
|
||||
AQUA(TextColor.color(0, 255, 255)),
|
||||
DARK_AQUA(TextColor.color(0, 127, 127)),
|
||||
PURPLE(TextColor.color(255, 0, 255)),
|
||||
DARK_PURPLE(TextColor.color(127, 0, 127)),
|
||||
PINK(TextColor.color(255, 105, 180)),
|
||||
DARK_PINK(TextColor.color(231, 84, 128)),
|
||||
WHITE(TextColor.color(255, 255, 255)),
|
||||
BLACK(TextColor.color(0, 0, 0)),
|
||||
LIGHT_GRAY(TextColor.color(127, 127, 127)),
|
||||
DARK_GRAY(TextColor.color(65, 65, 65));
|
||||
|
||||
final TextColor color;
|
||||
|
||||
BasicColors(TextColor color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public TextColor getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
27
src/main/java/mc/unraveled/reforged/util/Pair.java
Normal file
27
src/main/java/mc/unraveled/reforged/util/Pair.java
Normal file
@ -0,0 +1,27 @@
|
||||
package mc.unraveled.reforged.util;
|
||||
|
||||
public final class Pair<S, T> {
|
||||
private S first;
|
||||
private T second;
|
||||
|
||||
public Pair(S first, T second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public S getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public T getSecond() {
|
||||
return second;
|
||||
}
|
||||
|
||||
public void setFirst(S first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public void setSecond(T second) {
|
||||
this.second = second;
|
||||
}
|
||||
}
|
37
src/main/java/mc/unraveled/reforged/util/Tuple.java
Normal file
37
src/main/java/mc/unraveled/reforged/util/Tuple.java
Normal file
@ -0,0 +1,37 @@
|
||||
package mc.unraveled.reforged.util;
|
||||
|
||||
public final class Tuple<S, T, U> {
|
||||
private S first;
|
||||
private T second;
|
||||
private U third;
|
||||
|
||||
public Tuple(S first, T second, U third) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
}
|
||||
|
||||
public S getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public T getSecond() {
|
||||
return second;
|
||||
}
|
||||
|
||||
public U getThird() {
|
||||
return third;
|
||||
}
|
||||
|
||||
public void setFirst(S first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public void setSecond(T second) {
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public void setThird(U third) {
|
||||
this.third = third;
|
||||
}
|
||||
}
|
17
src/main/java/mc/unraveled/reforged/util/Unary.java
Normal file
17
src/main/java/mc/unraveled/reforged/util/Unary.java
Normal file
@ -0,0 +1,17 @@
|
||||
package mc.unraveled.reforged.util;
|
||||
|
||||
public final class Unary<T> {
|
||||
private T value;
|
||||
|
||||
public Unary(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
22
src/main/java/mc/unraveled/reforged/util/Utilities.java
Normal file
22
src/main/java/mc/unraveled/reforged/util/Utilities.java
Normal file
@ -0,0 +1,22 @@
|
||||
package mc.unraveled.reforged.util;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.List;
|
||||
|
||||
public final class Utilities {
|
||||
public static <T> @NotNull String serialize(@NotNull List<Pair<String, T>> objectPairs) {
|
||||
char delimiter = ':';
|
||||
char end = ';';
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Pair<String, ?> pair : objectPairs) {
|
||||
builder.append(pair.getFirst().charAt(0));
|
||||
builder.append(delimiter);
|
||||
builder.append(pair.getSecond());
|
||||
builder.append(end);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
14
src/main/resources/groups.properties
Normal file
14
src/main/resources/groups.properties
Normal file
@ -0,0 +1,14 @@
|
||||
# The SQL driver to use.
|
||||
driver=jdbc
|
||||
# The type of database to use.
|
||||
databaseType=postgresql
|
||||
# The database host.
|
||||
host=localhost
|
||||
# The database port.
|
||||
port=5432
|
||||
# The database file name.
|
||||
databaseFile=groups.db
|
||||
# The database username.
|
||||
username=admin
|
||||
# The database password.
|
||||
password=default
|
8
src/main/resources/plugin.yml
Normal file
8
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,8 @@
|
||||
name: Traverse
|
||||
version: '${version}'
|
||||
main: mc.unraveled.reforged.plugin.Traverse
|
||||
api-version: 1.19
|
||||
authors: [ SimplexDevelopment ]
|
||||
description:
|
||||
A plugin designed for the Unraveled: Reforged server.
|
||||
website: https://github.com/SimplexDevelopment
|
Loading…
Reference in New Issue
Block a user