innit commit
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
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 netchimken
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
2
README.md
Normal file
2
README.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# graylist
|
||||||
|
A whitelist management plugin, for handling multiple authentication services on Minecraft servers.
|
||||||
55
build.gradle
Normal file
55
build.gradle
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'dev.chimken'
|
||||||
|
version = '0.0.3-mc1.21'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
name = "papermc-repo"
|
||||||
|
url = "https://repo.papermc.io/repository/maven-public/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||||
|
}
|
||||||
|
|
||||||
|
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
Executable file
249
gradlew
vendored
Executable 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 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=.
|
||||||
|
@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 = 'Graylist'
|
||||||
58
src/main/java/dev/chimken/graylist/Graylist.java
Normal file
58
src/main/java/dev/chimken/graylist/Graylist.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package dev.chimken.graylist;
|
||||||
|
|
||||||
|
import dev.chimken.graylist.commands.*;
|
||||||
|
import dev.chimken.graylist.managers.CommandManager;
|
||||||
|
import dev.chimken.graylist.managers.ServiceManager;
|
||||||
|
import dev.chimken.graylist.managers.WhitelistManager;
|
||||||
|
import dev.chimken.graylist.services.Elyby;
|
||||||
|
import dev.chimken.graylist.services.Floodgate;
|
||||||
|
import dev.chimken.graylist.services.Mojang;
|
||||||
|
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public final class Graylist extends JavaPlugin {
|
||||||
|
private final FileConfiguration config = getConfig();
|
||||||
|
private final Logger logger = getLogger();
|
||||||
|
|
||||||
|
public final ServiceManager serviceManager = new ServiceManager(config, logger);
|
||||||
|
public final WhitelistManager whitelistManager = new WhitelistManager(logger);
|
||||||
|
private final CommandManager commandManager = new CommandManager("graylist");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
saveDefaultConfig();
|
||||||
|
|
||||||
|
try {
|
||||||
|
serviceManager.register(new Mojang());
|
||||||
|
serviceManager.register(new Floodgate());
|
||||||
|
serviceManager.register(new Elyby());
|
||||||
|
} catch (ServiceManager.ServiceAlreadyExists e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Add modify command for editing whitelist entries directly
|
||||||
|
// commandManager.register(new Modify());
|
||||||
|
|
||||||
|
commandManager.register(new AddRemove_CMD());
|
||||||
|
commandManager.register(new List_CMD());
|
||||||
|
commandManager.register(new Off_CMD());
|
||||||
|
commandManager.register(new On_CMD());
|
||||||
|
commandManager.register(new Reload_CMD());
|
||||||
|
commandManager.register(new Services_CMD());
|
||||||
|
commandManager.register(new Status_CMD());
|
||||||
|
|
||||||
|
this.getLifecycleManager().registerEventHandler(
|
||||||
|
LifecycleEvents.COMMANDS,
|
||||||
|
commands ->
|
||||||
|
commands.registrar().register(commandManager.build())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
serviceManager.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/main/java/dev/chimken/graylist/TextStyles.java
Normal file
22
src/main/java/dev/chimken/graylist/TextStyles.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package dev.chimken.graylist;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
|
import net.kyori.adventure.text.format.Style;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class TextStyles {
|
||||||
|
public static Style buildUsernameStyle(UUID uuid) {
|
||||||
|
return Style.style()
|
||||||
|
.color(TextColor.fromHexString("#7FFFFD"))
|
||||||
|
.hoverEvent(HoverEvent.showText(
|
||||||
|
text(uuid.toString())
|
||||||
|
))
|
||||||
|
.clickEvent(ClickEvent.copyToClipboard(uuid.toString()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
88
src/main/java/dev/chimken/graylist/Util.java
Normal file
88
src/main/java/dev/chimken/graylist/Util.java
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package dev.chimken.graylist;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
public static final File WHITELIST_FILE = new File(Bukkit.getServer().getWorldContainer(), "whitelist.json");
|
||||||
|
|
||||||
|
public static String expandUUIDString(String uuid) {
|
||||||
|
StringBuilder builder = new StringBuilder(uuid);
|
||||||
|
builder.insert(8, "-");
|
||||||
|
builder.insert(13, "-");
|
||||||
|
builder.insert(18, "-");
|
||||||
|
builder.insert(23, "-");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonObject fetchJSON(String url) throws RuntimeException {
|
||||||
|
try (HttpClient client = HttpClient.newHttpClient()) {
|
||||||
|
HttpRequest req = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(url))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse<String> res = client.send(req, HttpResponse.BodyHandlers.ofString());
|
||||||
|
return JsonParser.parseString(res.body()).getAsJsonObject();
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String removePrefix(String text, String prefix) {
|
||||||
|
return StringUtils.replaceOnce(text, prefix, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UUID findKnownUUIDByName(String name) {
|
||||||
|
Set<OfflinePlayer> playerlist = new HashSet<>(Bukkit.getOnlinePlayers());
|
||||||
|
OfflinePlayer onlinePlayer = playerlist.stream()
|
||||||
|
.filter(p -> Objects.equals(p.getName(), name))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (onlinePlayer != null) return onlinePlayer.getUniqueId();
|
||||||
|
|
||||||
|
Set<OfflinePlayer> whitelist = Bukkit.getWhitelistedPlayers();
|
||||||
|
OfflinePlayer trustedPlayer = whitelist.stream()
|
||||||
|
.filter(p -> Objects.equals(p.getName(), name))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (trustedPlayer != null) return trustedPlayer.getUniqueId();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String findKnownNameByUUID(UUID uuid) {
|
||||||
|
Set<OfflinePlayer> playerlist = new HashSet<>(Bukkit.getOnlinePlayers());
|
||||||
|
OfflinePlayer onlinePlayer = playerlist.stream()
|
||||||
|
.filter(p -> Objects.equals(p.getUniqueId(), uuid))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (onlinePlayer != null) return onlinePlayer.getName();
|
||||||
|
|
||||||
|
Set<OfflinePlayer> whitelist = Bukkit.getWhitelistedPlayers();
|
||||||
|
OfflinePlayer trustedPlayer = whitelist.stream()
|
||||||
|
.filter(p -> Objects.equals(p.getUniqueId(), uuid))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (trustedPlayer != null) return trustedPlayer.getName();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package dev.chimken.graylist.abstracts;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||||
|
import dev.chimken.graylist.Graylist;
|
||||||
|
import dev.chimken.graylist.managers.ServiceManager;
|
||||||
|
import dev.chimken.graylist.managers.WhitelistManager;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public abstract class GraylistCommandBundle<S> {
|
||||||
|
private static final Graylist graylist = Graylist.getPlugin(Graylist.class);
|
||||||
|
|
||||||
|
protected final FileConfiguration config = graylist.getConfig();
|
||||||
|
protected final Logger logger = graylist.getLogger();
|
||||||
|
protected final ServiceManager serviceManager = graylist.serviceManager;
|
||||||
|
protected final WhitelistManager whitelistManager = graylist.whitelistManager;
|
||||||
|
|
||||||
|
private final List<ArgumentBuilder<S, ?>> commands = new ArrayList<>();
|
||||||
|
|
||||||
|
public final List<ArgumentBuilder<S, ?>> getCommands() {
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void register(ArgumentBuilder<S, ?> command) {
|
||||||
|
commands.add(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package dev.chimken.graylist.abstracts;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class GraylistService {
|
||||||
|
private final String SERVICE_ID;
|
||||||
|
private final String SERVICE_NAMESPACE;
|
||||||
|
private final boolean DEFAULT_STATUS;
|
||||||
|
|
||||||
|
public final String getID() {
|
||||||
|
return SERVICE_ID;
|
||||||
|
}
|
||||||
|
public final @Nullable String getNamespace() {
|
||||||
|
return SERVICE_NAMESPACE;
|
||||||
|
}
|
||||||
|
public final String getConfigPath() {
|
||||||
|
return "services.configs." + (
|
||||||
|
SERVICE_NAMESPACE != null
|
||||||
|
? SERVICE_NAMESPACE + "." + SERVICE_ID
|
||||||
|
: SERVICE_ID
|
||||||
|
);
|
||||||
|
}
|
||||||
|
public final boolean getDefaultStatus() {
|
||||||
|
return DEFAULT_STATUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConfigurationSection config;
|
||||||
|
|
||||||
|
public final void setConfig(ConfigurationSection config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GraylistService(String id, boolean enabled) {
|
||||||
|
this(id, null, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GraylistService(String id, @Nullable String namespace, boolean enabled) {
|
||||||
|
SERVICE_ID = id;
|
||||||
|
SERVICE_NAMESPACE = namespace;
|
||||||
|
DEFAULT_STATUS = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract UUID findUUIDByName(String name) throws UserNotFound;
|
||||||
|
|
||||||
|
public abstract String findNameByUUID(UUID uuid) throws UserNotFound;
|
||||||
|
|
||||||
|
public class UserNotFound extends Exception {
|
||||||
|
public UserNotFound (String search) {
|
||||||
|
super(MessageFormat.format("Couldn't find '{0}' on service '{1}'", search, SERVICE_ID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum PlayerWhitelistStatus {
|
||||||
|
ABSENT,
|
||||||
|
PRESENT,
|
||||||
|
ADDED,
|
||||||
|
REMOVED,
|
||||||
|
}
|
||||||
|
}
|
||||||
221
src/main/java/dev/chimken/graylist/commands/AddRemove_CMD.java
Normal file
221
src/main/java/dev/chimken/graylist/commands/AddRemove_CMD.java
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
package dev.chimken.graylist.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import dev.chimken.graylist.TextStyles;
|
||||||
|
import dev.chimken.graylist.Util;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistCommandBundle;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistService;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.*;
|
||||||
|
import static net.kyori.adventure.text.Component.*;
|
||||||
|
import static net.kyori.adventure.text.minimessage.tag.resolver.Placeholder.component;
|
||||||
|
|
||||||
|
public class AddRemove_CMD extends GraylistCommandBundle<CommandSourceStack> {
|
||||||
|
public AddRemove_CMD() {
|
||||||
|
register(literal("add")
|
||||||
|
.requires(ctx -> ctx.getSender().hasPermission("graylist.command.add"))
|
||||||
|
.then(build(true))
|
||||||
|
);
|
||||||
|
|
||||||
|
register(literal("remove")
|
||||||
|
.requires(ctx -> ctx.getSender().hasPermission("graylist.command.remove"))
|
||||||
|
.then(build(false))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArgumentBuilder<CommandSourceStack, ?> build(boolean value) {
|
||||||
|
return argument("user", StringArgumentType.string())
|
||||||
|
.suggests((ctx, builder) -> {
|
||||||
|
final String operation = ctx.getInput();
|
||||||
|
|
||||||
|
if (operation.startsWith("/graylist add")) {
|
||||||
|
Bukkit.getOnlinePlayers().stream()
|
||||||
|
.map(Player::getName)
|
||||||
|
.forEach(builder::suggest);
|
||||||
|
} else {
|
||||||
|
Bukkit.getWhitelistedPlayers().stream()
|
||||||
|
.map(player -> {
|
||||||
|
final String name = player.getName();
|
||||||
|
|
||||||
|
if (Objects.equals(name, "<unknown>")) {
|
||||||
|
return player.getUniqueId().toString();
|
||||||
|
} else {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.forEach(builder::suggest);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.buildFuture();
|
||||||
|
})
|
||||||
|
.executes(ctx -> executor(ctx, value))
|
||||||
|
.then(argument("service", StringArgumentType.word())
|
||||||
|
.suggests((ctx, builder) -> {
|
||||||
|
serviceManager.getServices().forEach(
|
||||||
|
(s, service) -> builder.suggest(s)
|
||||||
|
);
|
||||||
|
|
||||||
|
return builder.buildFuture();
|
||||||
|
})
|
||||||
|
.executes(ctx -> executor(ctx, value))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int executor(CommandContext<CommandSourceStack> ctx, boolean value) {
|
||||||
|
final String ref = ctx.getArgument("user", String.class);
|
||||||
|
final CommandSender sender = ctx.getSource().getSender();
|
||||||
|
|
||||||
|
GraylistService service = serviceManager.getServices().get(
|
||||||
|
getServiceID(ctx)
|
||||||
|
);
|
||||||
|
|
||||||
|
UUID uuid = null;
|
||||||
|
String name = null;
|
||||||
|
String unprefixed_name = null;
|
||||||
|
|
||||||
|
// Determine whether UUID or name was provided
|
||||||
|
try {
|
||||||
|
uuid = UUID.fromString(ref);
|
||||||
|
} catch (IllegalArgumentException __) {
|
||||||
|
name = ref;
|
||||||
|
|
||||||
|
// reassigned to keep Java happy for use inside lambda
|
||||||
|
String checkName = name;
|
||||||
|
|
||||||
|
String service_id = serviceManager.getPrefixes().entrySet().stream()
|
||||||
|
.filter(entry -> checkName.startsWith(entry.getValue()))
|
||||||
|
.findFirst()
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (service_id != null)
|
||||||
|
service = serviceManager.getServices().get(service_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If service undetermined
|
||||||
|
if (service == null) {
|
||||||
|
sender.sendRichMessage("Couldn't determine service for <user>",
|
||||||
|
component("user", text(ref))
|
||||||
|
);
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search for prefix if name was provided
|
||||||
|
if (name != null) {
|
||||||
|
String service_prefix = config.getString(service.getConfigPath() + ".prefix");
|
||||||
|
|
||||||
|
// If prefix exists but name doesn't start with it, add it
|
||||||
|
if (service_prefix != null) {
|
||||||
|
if (!name.startsWith(service_prefix)) {
|
||||||
|
name = service_prefix + name;
|
||||||
|
unprefixed_name = name;
|
||||||
|
} else {
|
||||||
|
unprefixed_name = Util.removePrefix(name, service_prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Isolate logging
|
||||||
|
{
|
||||||
|
String user = name != null ? name : uuid.toString();
|
||||||
|
|
||||||
|
// Verbose (console)
|
||||||
|
logger.log(Level.INFO, "Searching " + service.getID() + " for " + user);
|
||||||
|
|
||||||
|
// Simple (in-game)
|
||||||
|
sender.sendRichMessage("Finding <user>...",
|
||||||
|
component("user", text(user))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Depending on input ID, find opposite
|
||||||
|
if (uuid != null) {
|
||||||
|
try {
|
||||||
|
name = Util.findKnownNameByUUID(uuid);
|
||||||
|
|
||||||
|
// If unknown name, query service with UUID
|
||||||
|
if (name == null) name = service.findNameByUUID(uuid);
|
||||||
|
} catch (GraylistService.UserNotFound e) { /* ignore */ }
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
uuid = Util.findKnownUUIDByName(name);
|
||||||
|
|
||||||
|
// If unknown UUID, query service with name (minus prefix)
|
||||||
|
if (uuid == null) uuid = service.findUUIDByName(unprefixed_name);
|
||||||
|
} catch (GraylistService.UserNotFound e) {
|
||||||
|
sender.sendRichMessage("Couldn't find <name>",
|
||||||
|
component("name", text(name))
|
||||||
|
);
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name == null) name = "<unknown>";
|
||||||
|
|
||||||
|
GraylistService.PlayerWhitelistStatus status = setWhitelisted(uuid, name, value);
|
||||||
|
|
||||||
|
switch (status) {
|
||||||
|
case ABSENT -> sender.sendRichMessage("<name> is not whitelisted",
|
||||||
|
component("name",
|
||||||
|
text(name).style(TextStyles.buildUsernameStyle(uuid))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
case PRESENT -> sender.sendRichMessage("<name> is already whitelisted",
|
||||||
|
component("name",
|
||||||
|
text(name).style(TextStyles.buildUsernameStyle(uuid))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
case ADDED -> sender.sendRichMessage("Added <name> to the whitelist",
|
||||||
|
component("name",
|
||||||
|
text(name).style(TextStyles.buildUsernameStyle(uuid))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
case REMOVED -> sender.sendRichMessage("Removed <name> from the whitelist",
|
||||||
|
component("name",
|
||||||
|
text(name).style(TextStyles.buildUsernameStyle(uuid))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServiceID (CommandContext<CommandSourceStack> ctx) {
|
||||||
|
String service_id;
|
||||||
|
|
||||||
|
try {
|
||||||
|
service_id = ctx.getArgument("service", String.class).toLowerCase(Locale.ROOT);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
service_id = serviceManager.getDefaultServiceID();
|
||||||
|
}
|
||||||
|
|
||||||
|
return service_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GraylistService.PlayerWhitelistStatus setWhitelisted (UUID uuid, String name, boolean value) {
|
||||||
|
return whitelistManager.setWhitelisted(
|
||||||
|
uuid,
|
||||||
|
name,
|
||||||
|
value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
48
src/main/java/dev/chimken/graylist/commands/List_CMD.java
Normal file
48
src/main/java/dev/chimken/graylist/commands/List_CMD.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package dev.chimken.graylist.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import dev.chimken.graylist.TextStyles;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistCommandBundle;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
public class List_CMD extends GraylistCommandBundle<CommandSourceStack> {
|
||||||
|
public List_CMD() {
|
||||||
|
register(literal("list")
|
||||||
|
|
||||||
|
.requires(ctx -> ctx.getSender().hasPermission("graylist.command.list"))
|
||||||
|
.executes(ctx -> {
|
||||||
|
List<TextComponent> playerlist = Bukkit.getWhitelistedPlayers().stream()
|
||||||
|
.map(player -> {
|
||||||
|
final String name = player.getName();
|
||||||
|
final UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
|
return text(name != null ? name : "<unknown>")
|
||||||
|
.style(TextStyles.buildUsernameStyle(uuid));
|
||||||
|
})
|
||||||
|
.toList();
|
||||||
|
int count = playerlist.size();
|
||||||
|
|
||||||
|
TextComponent msg = text("There are " + count + " whitelisted player(s): \n");
|
||||||
|
|
||||||
|
for (int i = 0; i <= (count - 1); i++) {
|
||||||
|
if (i > 0 || i == (count - 1))
|
||||||
|
msg = msg.append(text(", "));
|
||||||
|
|
||||||
|
msg = msg.append(playerlist.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.getSource().getSender().sendMessage(msg);
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/java/dev/chimken/graylist/commands/Modify_CMD.java
Normal file
29
src/main/java/dev/chimken/graylist/commands/Modify_CMD.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package dev.chimken.graylist.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistCommandBundle;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
public class Modify_CMD extends GraylistCommandBundle<CommandSourceStack> {
|
||||||
|
public Modify_CMD() {
|
||||||
|
register(literal("modify")
|
||||||
|
.requires(ctx -> ctx.getSender().hasPermission("graylist.command.edit"))
|
||||||
|
.executes(ctx -> {
|
||||||
|
CommandSender sender = ctx.getSource().getSender();
|
||||||
|
|
||||||
|
if (Bukkit.getServer().hasWhitelist())
|
||||||
|
sender.sendMessage("Whitelist is already turned on");
|
||||||
|
else {
|
||||||
|
Bukkit.getServer().setWhitelist(true);
|
||||||
|
sender.sendMessage("Whitelist is now turned on");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/java/dev/chimken/graylist/commands/Off_CMD.java
Normal file
29
src/main/java/dev/chimken/graylist/commands/Off_CMD.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package dev.chimken.graylist.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistCommandBundle;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
public class Off_CMD extends GraylistCommandBundle<CommandSourceStack> {
|
||||||
|
public Off_CMD() {
|
||||||
|
register(literal("off")
|
||||||
|
.requires(ctx -> ctx.getSender().hasPermission("graylist.command.off"))
|
||||||
|
.executes(ctx -> {
|
||||||
|
CommandSender sender = ctx.getSource().getSender();
|
||||||
|
|
||||||
|
if (!Bukkit.getServer().hasWhitelist())
|
||||||
|
sender.sendMessage("Whitelist is already turned off");
|
||||||
|
else {
|
||||||
|
Bukkit.getServer().setWhitelist(false);
|
||||||
|
sender.sendMessage("Whitelist is now turned off");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/java/dev/chimken/graylist/commands/On_CMD.java
Normal file
29
src/main/java/dev/chimken/graylist/commands/On_CMD.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package dev.chimken.graylist.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistCommandBundle;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
public class On_CMD extends GraylistCommandBundle<CommandSourceStack> {
|
||||||
|
public On_CMD() {
|
||||||
|
register(literal("on")
|
||||||
|
.requires(ctx -> ctx.getSender().hasPermission("graylist.command.on"))
|
||||||
|
.executes(ctx -> {
|
||||||
|
CommandSender sender = ctx.getSource().getSender();
|
||||||
|
|
||||||
|
if (Bukkit.getServer().hasWhitelist())
|
||||||
|
sender.sendMessage("Whitelist is already turned on");
|
||||||
|
else {
|
||||||
|
Bukkit.getServer().setWhitelist(true);
|
||||||
|
sender.sendMessage("Whitelist is now turned on");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/main/java/dev/chimken/graylist/commands/Reload_CMD.java
Normal file
22
src/main/java/dev/chimken/graylist/commands/Reload_CMD.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package dev.chimken.graylist.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistCommandBundle;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.*;
|
||||||
|
|
||||||
|
public class Reload_CMD extends GraylistCommandBundle<CommandSourceStack> {
|
||||||
|
public Reload_CMD() {
|
||||||
|
register(literal("reload")
|
||||||
|
.requires(ctx -> ctx.getSender().hasPermission("graylist.command.reload"))
|
||||||
|
.executes(ctx -> {
|
||||||
|
Bukkit.getServer().reloadWhitelist();
|
||||||
|
ctx.getSource().getSender().sendMessage("Reloaded the whitelist");
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package dev.chimken.graylist.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistCommandBundle;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistService;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||||
|
|
||||||
|
public class Services_CMD extends GraylistCommandBundle<CommandSourceStack> {
|
||||||
|
public Services_CMD() {
|
||||||
|
register(literal("services")
|
||||||
|
.requires(ctx -> ctx.getSender().hasPermission("graylist.command.services"))
|
||||||
|
.executes(ctx -> {
|
||||||
|
String flatList = String.join(
|
||||||
|
", ",
|
||||||
|
serviceManager.getServices().values().stream().map(GraylistService::getID).toList()
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.getSource().getSender().sendRichMessage("There are <count> service(s) available: <list>",
|
||||||
|
Placeholder.component("count", Component.text(serviceManager.getServices().keySet().toArray().length)),
|
||||||
|
Placeholder.component("list", Component.text(flatList))
|
||||||
|
);
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/main/java/dev/chimken/graylist/commands/Status_CMD.java
Normal file
23
src/main/java/dev/chimken/graylist/commands/Status_CMD.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package dev.chimken.graylist.commands;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistCommandBundle;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import static io.papermc.paper.command.brigadier.Commands.*;
|
||||||
|
|
||||||
|
public class Status_CMD extends GraylistCommandBundle<CommandSourceStack> {
|
||||||
|
public Status_CMD() {
|
||||||
|
register(literal("status")
|
||||||
|
.requires(ctx -> ctx.getSender().hasPermission("graylist.command.status"))
|
||||||
|
.executes(ctx -> {
|
||||||
|
ctx.getSource().getSender().sendMessage(
|
||||||
|
"Whitelist is currently " + (Bukkit.hasWhitelist() ? "on" : "off")
|
||||||
|
);
|
||||||
|
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package dev.chimken.graylist.managers;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistCommandBundle;
|
||||||
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
|
|
||||||
|
public class CommandManager extends LiteralArgumentBuilder<CommandSourceStack> {
|
||||||
|
public CommandManager (String label) {
|
||||||
|
super(label);
|
||||||
|
|
||||||
|
this.requires(ctx -> ctx.getSender().hasPermission("graylist"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(GraylistCommandBundle<CommandSourceStack> bundle) {
|
||||||
|
bundle.getCommands().forEach(this::then);
|
||||||
|
}
|
||||||
|
}
|
||||||
104
src/main/java/dev/chimken/graylist/managers/ServiceManager.java
Normal file
104
src/main/java/dev/chimken/graylist/managers/ServiceManager.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
package dev.chimken.graylist.managers;
|
||||||
|
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistService;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class ServiceManager {
|
||||||
|
private final FileConfiguration config;
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
private final HashMap<String, GraylistService> services = new HashMap<>();
|
||||||
|
private final HashMap<String, String> prefixes = new HashMap<>();
|
||||||
|
private String default_service_id;
|
||||||
|
|
||||||
|
public static final String INTERNAL_NAMESPACE = "internal";
|
||||||
|
|
||||||
|
public String getDefaultServiceID() { return default_service_id; }
|
||||||
|
public GraylistService getDefaultService() {
|
||||||
|
return services.get(default_service_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, GraylistService> getServices() {
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, String> getPrefixes() {
|
||||||
|
return prefixes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
services.clear();
|
||||||
|
prefixes.clear();
|
||||||
|
default_service_id = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServiceManager (FileConfiguration config, Logger logger) {
|
||||||
|
this.config = config;
|
||||||
|
this.logger = logger;
|
||||||
|
|
||||||
|
default_service_id = config.getString("services.default");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(GraylistService service) throws ServiceAlreadyExists {
|
||||||
|
final String id = service.getID();
|
||||||
|
|
||||||
|
if (services.containsKey(id))
|
||||||
|
throw new ServiceAlreadyExists(id);
|
||||||
|
|
||||||
|
final String namespace = service.getNamespace();
|
||||||
|
final String service_config_path = service.getConfigPath();
|
||||||
|
|
||||||
|
ConfigurationSection service_config = config.getConfigurationSection(service_config_path);
|
||||||
|
if (service_config == null) {
|
||||||
|
service_config = config.createSection(service_config_path);
|
||||||
|
service_config.set("enabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
final int isEnabled = service_config.isBoolean("enabled")
|
||||||
|
? service_config.getBoolean("enabled")
|
||||||
|
? 1 // Is enabled
|
||||||
|
: 0 // Isn't enabled
|
||||||
|
: 2; // Not set (use default)
|
||||||
|
|
||||||
|
// If disabled (in config or by default)
|
||||||
|
if (isEnabled == 0 || (isEnabled == 2 && !service.getDefaultStatus())) {
|
||||||
|
if (!Objects.equals(namespace, INTERNAL_NAMESPACE)) logger.log(
|
||||||
|
Level.INFO,
|
||||||
|
MessageFormat.format(
|
||||||
|
"Disabled service: {0} (external)",
|
||||||
|
service.getID()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
service.setConfig(service_config);
|
||||||
|
services.put(id, service);
|
||||||
|
|
||||||
|
String prefix = service_config.getString("prefix");
|
||||||
|
if (prefix != null) prefixes.put(id, prefix);
|
||||||
|
|
||||||
|
logger.log(
|
||||||
|
Level.INFO,
|
||||||
|
MessageFormat.format(
|
||||||
|
"Registered service: {0} ({1})",
|
||||||
|
service.getID(),
|
||||||
|
Objects.equals(namespace, INTERNAL_NAMESPACE) ? "internal" : "external"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ServiceAlreadyExists extends Exception {
|
||||||
|
ServiceAlreadyExists (String name) {
|
||||||
|
super("Failed to register '" + name + "' because it already exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package dev.chimken.graylist.managers;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import dev.chimken.graylist.Util;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistService;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class WhitelistManager {
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
public WhitelistManager (Logger logger) {
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GraylistService.PlayerWhitelistStatus setWhitelisted(UUID uuid, String name, boolean value) {
|
||||||
|
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||||
|
|
||||||
|
try {
|
||||||
|
JsonArray whitelist = JsonParser.parseReader(new FileReader(Util.WHITELIST_FILE)).getAsJsonArray();
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
if (player.isWhitelisted())
|
||||||
|
return GraylistService.PlayerWhitelistStatus.PRESENT;
|
||||||
|
else {
|
||||||
|
JsonObject entry = new JsonObject();
|
||||||
|
entry.addProperty("uuid", uuid.toString());
|
||||||
|
entry.addProperty("name", name);
|
||||||
|
|
||||||
|
whitelist.add(entry);
|
||||||
|
|
||||||
|
try (FileWriter writer = new FileWriter(Util.WHITELIST_FILE)) {
|
||||||
|
new Gson().toJson(whitelist, writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.reloadWhitelist();
|
||||||
|
|
||||||
|
return GraylistService.PlayerWhitelistStatus.ADDED;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!player.isWhitelisted())
|
||||||
|
return GraylistService.PlayerWhitelistStatus.ABSENT;
|
||||||
|
else {
|
||||||
|
player.setWhitelisted(false);
|
||||||
|
return GraylistService.PlayerWhitelistStatus.REMOVED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/main/java/dev/chimken/graylist/services/Elyby.java
Normal file
34
src/main/java/dev/chimken/graylist/services/Elyby.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package dev.chimken.graylist.services;
|
||||||
|
|
||||||
|
import dev.chimken.graylist.Util;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistService;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static dev.chimken.graylist.Util.fetchJSON;
|
||||||
|
import static dev.chimken.graylist.managers.ServiceManager.INTERNAL_NAMESPACE;
|
||||||
|
|
||||||
|
public class Elyby extends GraylistService {
|
||||||
|
public Elyby() {
|
||||||
|
super("elyby", INTERNAL_NAMESPACE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID findUUIDByName(String name) throws UserNotFound {
|
||||||
|
try {
|
||||||
|
final String id = fetchJSON("http://skinsystem.ely.by/profile/" + name)
|
||||||
|
.get("id")
|
||||||
|
.getAsString();
|
||||||
|
|
||||||
|
// Use expandUUIDString because UUID is collapsed initially
|
||||||
|
return UUID.fromString(Util.expandUUIDString(id));
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new UserNotFound(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String findNameByUUID(UUID uuid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
40
src/main/java/dev/chimken/graylist/services/Floodgate.java
Normal file
40
src/main/java/dev/chimken/graylist/services/Floodgate.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package dev.chimken.graylist.services;
|
||||||
|
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistService;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static dev.chimken.graylist.Util.fetchJSON;
|
||||||
|
import static dev.chimken.graylist.managers.ServiceManager.INTERNAL_NAMESPACE;
|
||||||
|
|
||||||
|
// TODO: Don't rely on mcprofile.io; implement Xbox API instead
|
||||||
|
|
||||||
|
public class Floodgate extends GraylistService {
|
||||||
|
public Floodgate() {
|
||||||
|
super("floodgate", INTERNAL_NAMESPACE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID findUUIDByName(String name) throws UserNotFound {
|
||||||
|
try {
|
||||||
|
final String id = fetchJSON("https://mcprofile.io/api/v1/bedrock/gamertag/" + name)
|
||||||
|
.get("floodgateuid")
|
||||||
|
.getAsString();
|
||||||
|
|
||||||
|
return UUID.fromString(id);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new UserNotFound(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String findNameByUUID(UUID uuid) throws UserNotFound {
|
||||||
|
try {
|
||||||
|
return fetchJSON("https://mcprofile.io/api/v1/bedrock/fuid/" + uuid.toString())
|
||||||
|
.get("gamertag")
|
||||||
|
.getAsString();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new UserNotFound(uuid.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
src/main/java/dev/chimken/graylist/services/Mojang.java
Normal file
40
src/main/java/dev/chimken/graylist/services/Mojang.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package dev.chimken.graylist.services;
|
||||||
|
|
||||||
|
import dev.chimken.graylist.Util;
|
||||||
|
import dev.chimken.graylist.abstracts.GraylistService;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static dev.chimken.graylist.Util.fetchJSON;
|
||||||
|
import static dev.chimken.graylist.managers.ServiceManager.INTERNAL_NAMESPACE;
|
||||||
|
|
||||||
|
public class Mojang extends GraylistService {
|
||||||
|
public Mojang () {
|
||||||
|
super("mojang", INTERNAL_NAMESPACE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID findUUIDByName(String name) throws UserNotFound {
|
||||||
|
try {
|
||||||
|
final String id = fetchJSON("https://api.mojang.com/users/profiles/minecraft/" + name)
|
||||||
|
.get("id")
|
||||||
|
.getAsString();
|
||||||
|
|
||||||
|
// Use expandUUIDString because UUID is collapsed initially
|
||||||
|
return UUID.fromString(Util.expandUUIDString(id));
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new UserNotFound(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String findNameByUUID(UUID uuid) throws UserNotFound {
|
||||||
|
try {
|
||||||
|
return fetchJSON("https://api.minecraftservices.com/minecraft/profile/lookup/" + uuid.toString())
|
||||||
|
.get("name")
|
||||||
|
.getAsString();
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw new UserNotFound(uuid.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/resources/config.yml
Normal file
29
src/main/resources/config.yml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# ------------------
|
||||||
|
# Graylist Config
|
||||||
|
# ------------------
|
||||||
|
|
||||||
|
## Plugin Language
|
||||||
|
# Default is "en-US"
|
||||||
|
lang: en-US
|
||||||
|
|
||||||
|
## Service Configuration
|
||||||
|
services:
|
||||||
|
|
||||||
|
## Default service to use when a service isn't specified.
|
||||||
|
default: mojang
|
||||||
|
|
||||||
|
## List of service configs
|
||||||
|
# By default, built-in services (except Mojang) are disabled
|
||||||
|
configs:
|
||||||
|
|
||||||
|
internal.mojang:
|
||||||
|
# enabled: false
|
||||||
|
# prefix:
|
||||||
|
|
||||||
|
internal.floodgate:
|
||||||
|
#enabled: true
|
||||||
|
prefix: "."
|
||||||
|
|
||||||
|
internal.elyby:
|
||||||
|
#enabled: true
|
||||||
|
#prefix:
|
||||||
7
src/main/resources/lang/en-US.yml
Normal file
7
src/main/resources/lang/en-US.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
graylist.add:
|
||||||
|
added: "Added <name> to the whitelist"
|
||||||
|
present: "<name> is already whitelisted"
|
||||||
|
|
||||||
|
graylist.remove:
|
||||||
|
removed: "Removed <name> from the whitelist"
|
||||||
|
absent: "<name> is not whitelisted"
|
||||||
70
src/main/resources/plugin.yml
Normal file
70
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
name: Graylist
|
||||||
|
version: ${version}
|
||||||
|
main: dev.chimken.graylist.Graylist
|
||||||
|
api-version: '1.21'
|
||||||
|
permissions:
|
||||||
|
graylist:
|
||||||
|
default: op
|
||||||
|
|
||||||
|
graylist.*:
|
||||||
|
description: Gives access to all Graylist commands
|
||||||
|
default: op
|
||||||
|
children:
|
||||||
|
graylist.manage: true
|
||||||
|
graylist.view: true
|
||||||
|
|
||||||
|
graylist.manage:
|
||||||
|
description: Gives access to all Graylist management commands
|
||||||
|
children:
|
||||||
|
graylist: true
|
||||||
|
graylist.command.add: true
|
||||||
|
graylist.command.remove: true
|
||||||
|
graylist.command.on: true
|
||||||
|
graylist.command.off: true
|
||||||
|
graylist.command.reload: true
|
||||||
|
|
||||||
|
graylist.view:
|
||||||
|
description: Gives access to all Graylist state viewing commands
|
||||||
|
children:
|
||||||
|
graylist: true
|
||||||
|
graylist.command.list: true
|
||||||
|
graylist.command.status: true
|
||||||
|
graylist.command.services: true
|
||||||
|
|
||||||
|
commands:
|
||||||
|
graylist:
|
||||||
|
usage: /graylist [subcommand]
|
||||||
|
permission: graylist
|
||||||
|
children:
|
||||||
|
add:
|
||||||
|
description: Add a user to the whitelist
|
||||||
|
usage: /graylist add <username|uuid> [service]
|
||||||
|
permission: graylist.command.add
|
||||||
|
remove:
|
||||||
|
description: Remove a user from the whitelist
|
||||||
|
usage: /graylist remove <username|uuid> [service]
|
||||||
|
permission: graylist.command.remove
|
||||||
|
on:
|
||||||
|
description: Enable the whitelist
|
||||||
|
usage: /graylist on
|
||||||
|
permission: graylist.command.on
|
||||||
|
off:
|
||||||
|
description: Disable the whitelist
|
||||||
|
usage: /graylist off
|
||||||
|
permission: graylist.command.off
|
||||||
|
list:
|
||||||
|
description: List all whitelisted users
|
||||||
|
usage: /graylist list
|
||||||
|
permission: graylist.command.list
|
||||||
|
status:
|
||||||
|
description: Get the current whitelist state
|
||||||
|
usage: /graylist status
|
||||||
|
permission: graylist.command.status
|
||||||
|
services:
|
||||||
|
description: Get all available services
|
||||||
|
usage: /graylist services
|
||||||
|
permission: graylist.command.services
|
||||||
|
reload:
|
||||||
|
description: Reload the whitelist
|
||||||
|
usage: /graylist reload
|
||||||
|
permission: graylist.command.reload
|
||||||
Reference in New Issue
Block a user