diff --git a/.gitignore b/.gitignore index d3ee570..6a7860b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .idea/ .settings/ bin/ -target/ +build/ +.gradle/ .checkstyle .classpath .project diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..4f9a2fc --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,44 @@ +plugins { + id("java") + id("checkstyle") + id("com.github.johnrengelman.shadow") version "8.1.1" +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT") + + implementation(project(":common")) + implementation(project(":paper-platform")) + implementation(project(":folia-platform")) +} + +allprojects { + apply(plugin = "java") + apply(plugin = "checkstyle") + + repositories { + mavenCentral() + maven("https://repo.papermc.io/repository/maven-public/") + } + + group = "pw.kaboom" + version = "master" + description = "Extras" + java.sourceCompatibility = JavaVersion.VERSION_17 + + tasks { + assemble { + dependsOn(checkstyleMain) + } + + compileJava { + options.encoding = "UTF-8" + } + } +} + +tasks { + assemble { + dependsOn(shadowJar) + } +} \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts new file mode 100644 index 0000000..732e3c1 --- /dev/null +++ b/common/build.gradle.kts @@ -0,0 +1,3 @@ +dependencies { + compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT") +} \ No newline at end of file diff --git a/common/src/main/java/pw/kaboom/extras/platform/IScheduler.java b/common/src/main/java/pw/kaboom/extras/platform/IScheduler.java new file mode 100644 index 0000000..03aa94d --- /dev/null +++ b/common/src/main/java/pw/kaboom/extras/platform/IScheduler.java @@ -0,0 +1,14 @@ +package pw.kaboom.extras.platform; + +import org.bukkit.plugin.Plugin; + +import java.util.concurrent.TimeUnit; + +public interface IScheduler { + void runRepeating(final Plugin plugin, final Runnable runnable, final long delay, + final long period, final TimeUnit unit); + void runLater(final Plugin plugin, final Runnable runnable, + final long delay, final TimeUnit unit); + void runSync(final Plugin plugin, final Runnable runnable); + void runAsync(final Plugin plugin, final Runnable runnable); +} diff --git a/common/src/main/java/pw/kaboom/extras/platform/PlatformScheduler.java b/common/src/main/java/pw/kaboom/extras/platform/PlatformScheduler.java new file mode 100644 index 0000000..417357e --- /dev/null +++ b/common/src/main/java/pw/kaboom/extras/platform/PlatformScheduler.java @@ -0,0 +1,36 @@ +package pw.kaboom.extras.platform; + +import org.bukkit.plugin.Plugin; + +import java.util.concurrent.TimeUnit; + +public final class PlatformScheduler { + private static IScheduler currentScheduler = null; + + public static void setCurrentScheduler(final IScheduler implementation) { + if (currentScheduler != null) { + throw new IllegalStateException("Tried to set current scheduler, even though " + + " it was already set!"); + } + + currentScheduler = implementation; + } + + public static void runRepeating(final Plugin plugin, final Runnable runnable, + final long delay, final long period, final TimeUnit unit) { + currentScheduler.runRepeating(plugin, runnable, delay, period, unit); + } + + public static void runLater(final Plugin plugin, final Runnable runnable, + final long delay, final TimeUnit unit) { + currentScheduler.runLater(plugin, runnable, delay, unit); + } + + public static void runSync(final Plugin plugin, final Runnable runnable) { + currentScheduler.runSync(plugin, runnable); + } + + public static void runAsync(final Plugin plugin, final Runnable runnable) { + currentScheduler.runAsync(plugin, runnable); + } +} diff --git a/checkstyle.xml b/config/checkstyle/checkstyle.xml similarity index 100% rename from checkstyle.xml rename to config/checkstyle/checkstyle.xml diff --git a/folia-platform/build.gradle.kts b/folia-platform/build.gradle.kts new file mode 100644 index 0000000..0d6c302 --- /dev/null +++ b/folia-platform/build.gradle.kts @@ -0,0 +1,5 @@ +dependencies { + compileOnly("dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT") + + implementation(project(":common")) +} \ No newline at end of file diff --git a/folia-platform/src/main/java/pw/kaboom/extras/platform/folia/FoliaScheduler.java b/folia-platform/src/main/java/pw/kaboom/extras/platform/folia/FoliaScheduler.java new file mode 100644 index 0000000..b825e15 --- /dev/null +++ b/folia-platform/src/main/java/pw/kaboom/extras/platform/folia/FoliaScheduler.java @@ -0,0 +1,54 @@ +package pw.kaboom.extras.platform.folia; + +import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; +import io.papermc.paper.threadedregions.scheduler.ScheduledTask; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import pw.kaboom.extras.platform.IScheduler; + +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; + +public final class FoliaScheduler implements IScheduler { + private static final AsyncScheduler ASYNC_SCHEDULER = Bukkit.getAsyncScheduler(); + + @Override + public void runRepeating(final Plugin plugin, final Runnable runnable, + final long delay, final long period, + final TimeUnit unit) { + ASYNC_SCHEDULER.runAtFixedRate(plugin, FoliaTask.from(runnable), delay, period, unit); + } + + @Override + public void runLater(final Plugin plugin, final Runnable runnable, final long delay, + final TimeUnit unit) { + ASYNC_SCHEDULER.runDelayed(plugin, FoliaTask.from(runnable), delay, unit); + } + + @Override + public void runSync(final Plugin plugin, final Runnable runnable) { + ASYNC_SCHEDULER.runNow(plugin, FoliaTask.from(runnable)); + } + + @Override + public void runAsync(final Plugin plugin, final Runnable runnable) { + ASYNC_SCHEDULER.runNow(plugin, FoliaTask.from(runnable)); + } + + private static final class FoliaTask implements Consumer { + private final Runnable runnable; + + FoliaTask(final Runnable runnable) { + this.runnable = runnable; + } + + @Override + public void accept(final ScheduledTask scheduledTask) { + this.runnable.run(); + } + + public static FoliaTask from(final Runnable runnable) { + return new FoliaTask(runnable); + } + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..943f0cb Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..bdc9a83 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..65dcd68 --- /dev/null +++ b/gradlew @@ -0,0 +1,244 @@ +#!/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/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 + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# 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*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=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=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 + +# 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 \ + "$@" + +# 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" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/gradlew.bat @@ -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. +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% 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 diff --git a/paper-platform/build.gradle.kts b/paper-platform/build.gradle.kts new file mode 100644 index 0000000..0a5d5d5 --- /dev/null +++ b/paper-platform/build.gradle.kts @@ -0,0 +1,5 @@ +dependencies { + compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT") + + implementation(project(":common")) +} \ No newline at end of file diff --git a/paper-platform/src/main/java/pw/kaboom/extras/platform/paper/PaperScheduler.java b/paper-platform/src/main/java/pw/kaboom/extras/platform/paper/PaperScheduler.java new file mode 100644 index 0000000..d31e372 --- /dev/null +++ b/paper-platform/src/main/java/pw/kaboom/extras/platform/paper/PaperScheduler.java @@ -0,0 +1,42 @@ +package pw.kaboom.extras.platform.paper; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitScheduler; +import pw.kaboom.extras.platform.IScheduler; + +import java.util.concurrent.TimeUnit; + +public final class PaperScheduler implements IScheduler { + private static final BukkitScheduler BUKKIT_SCHEDULER = Bukkit.getScheduler(); + + private static long convertIntoTicks(final long time, final TimeUnit unit) { + final long millis = unit.toMillis(time); + + return millis / 20L; + } + + @Override + public void runRepeating(final Plugin plugin, final Runnable runnable, final long delay, + final long period, final TimeUnit unit) { + BUKKIT_SCHEDULER.runTaskTimerAsynchronously(plugin, runnable, convertIntoTicks(delay, unit), + convertIntoTicks(period, unit)); + } + + @Override + public void runLater(final Plugin plugin, final Runnable runnable, + final long delay, TimeUnit unit) { + BUKKIT_SCHEDULER.runTaskLaterAsynchronously(plugin, runnable, + convertIntoTicks(delay, unit)); + } + + @Override + public void runSync(final Plugin plugin, final Runnable runnable) { + BUKKIT_SCHEDULER.runTask(plugin, runnable); + } + + @Override + public void runAsync(final Plugin plugin, final Runnable runnable) { + BUKKIT_SCHEDULER.runTaskAsynchronously(plugin, runnable); + } +} diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 64db095..0000000 --- a/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ - - 4.0.0 - pw.kaboom - Extras - master - - - 17 - 17 - true - UTF-8 - - - - - io.papermc.paper - paper-api - 1.19.4-R0.1-SNAPSHOT - provided - - - dev.folia - folia-api - 1.19.4-R0.1-SNAPSHOT - provided - - - - - - papermc - https://repo.papermc.io/repository/maven-public/ - - - - - ${project.artifactId} - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.2.0 - - - checkstyle - validate - - check - - - checkstyle.xml - suppressions.xml - true - - - - - - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..727c336 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,4 @@ +rootProject.name = "Extras" +include("paper-platform") +include("folia-platform") +include("common") diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index 2aafc53..608479c 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -1,56 +1,54 @@ package pw.kaboom.extras; -import java.io.File; -import java.util.Collections; import org.bukkit.WorldCreator; import org.bukkit.WorldType; import org.bukkit.block.BlockFace; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; -import pw.kaboom.extras.commands.CommandBroadcastMM; -import pw.kaboom.extras.commands.CommandBroadcastVanilla; -import pw.kaboom.extras.commands.CommandClearChat; -import pw.kaboom.extras.commands.CommandConsole; -import pw.kaboom.extras.commands.CommandDestroyEntities; -import pw.kaboom.extras.commands.CommandEnchantAll; -import pw.kaboom.extras.commands.CommandGetJSON; -import pw.kaboom.extras.commands.CommandJumpscare; -import pw.kaboom.extras.commands.CommandKaboom; -import pw.kaboom.extras.commands.CommandPing; -import pw.kaboom.extras.commands.CommandPrefix; -import pw.kaboom.extras.commands.CommandPumpkin; -import pw.kaboom.extras.commands.CommandServerInfo; -import pw.kaboom.extras.commands.CommandSkin; -import pw.kaboom.extras.commands.CommandSpawn; -import pw.kaboom.extras.commands.CommandSpidey; -import pw.kaboom.extras.commands.CommandTellraw; -import pw.kaboom.extras.commands.CommandUsername; +import pw.kaboom.extras.commands.*; import pw.kaboom.extras.modules.block.BlockCheck; import pw.kaboom.extras.modules.block.BlockPhysics; import pw.kaboom.extras.modules.entity.EntityExplosion; import pw.kaboom.extras.modules.entity.EntityKnockback; import pw.kaboom.extras.modules.entity.EntitySpawn; import pw.kaboom.extras.modules.entity.EntityTeleport; -import pw.kaboom.extras.modules.player.PlayerChat; -import pw.kaboom.extras.modules.player.PlayerCommand; -import pw.kaboom.extras.modules.player.PlayerConnection; -import pw.kaboom.extras.modules.player.PlayerDamage; -import pw.kaboom.extras.modules.player.PlayerInteract; -import pw.kaboom.extras.modules.player.PlayerPrefix; -import pw.kaboom.extras.modules.player.PlayerRecipe; -import pw.kaboom.extras.modules.player.PlayerTeleport; +import pw.kaboom.extras.modules.player.*; import pw.kaboom.extras.modules.server.ServerCommand; import pw.kaboom.extras.modules.server.ServerGameRule; import pw.kaboom.extras.modules.server.ServerTabComplete; import pw.kaboom.extras.modules.server.ServerTick; +import pw.kaboom.extras.platform.PlatformScheduler; +import pw.kaboom.extras.platform.folia.FoliaScheduler; +import pw.kaboom.extras.platform.paper.PaperScheduler; + +import java.io.File; +import java.util.Collections; public final class Main extends JavaPlugin { + private boolean isFolia; private File prefixConfigFile; private FileConfiguration prefixConfig; + public boolean isFolia() { + return this.isFolia; + } + @Override public void onLoad() { + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); + isFolia = true; + } catch (ClassNotFoundException ignored) { + isFolia = false; + } + + if (isFolia) { + PlatformScheduler.setCurrentScheduler(new FoliaScheduler()); + } else { + PlatformScheduler.setCurrentScheduler(new PaperScheduler()); + } + /* Fill lists */ Collections.addAll( BlockPhysics.getBlockFaces(), @@ -86,11 +84,11 @@ public final class Main extends JavaPlugin { this.getCommand("prefix").setExecutor(new CommandPrefix()); this.getCommand("pumpkin").setExecutor(new CommandPumpkin()); this.getCommand("serverinfo").setExecutor(new CommandServerInfo()); - this.getCommand("skin").setExecutor(new CommandSkin()); + this.getCommand("username").setExecutor(new CommandUsername()); this.getCommand("spawn").setExecutor(new CommandSpawn()); this.getCommand("spidey").setExecutor(new CommandSpidey()); this.getCommand("tellraw").setExecutor(new CommandTellraw()); - this.getCommand("username").setExecutor(new CommandUsername()); + this.getCommand("skin").setExecutor(new CommandSkin()); /* Block-related modules */ BlockPhysics.init(this); @@ -121,9 +119,15 @@ public final class Main extends JavaPlugin { this.getServer().getPluginManager().registerEvents(new ServerTick(), this); /* Custom worlds */ - this.getServer().createWorld( - new WorldCreator("world_flatlands").generateStructures(false).type(WorldType.FLAT) - ); + // Custom worlds are not implemented on Folia! + if(!isFolia) { + this.getServer().createWorld( + new WorldCreator("world_flatlands") + .generateStructures(false) + .type(WorldType.FLAT) + ); + } + } public File getPrefixConfigFile() { diff --git a/src/main/java/pw/kaboom/extras/commands/CommandSkin.java b/src/main/java/pw/kaboom/extras/commands/CommandSkin.java index 204f7a2..690bb74 100644 --- a/src/main/java/pw/kaboom/extras/commands/CommandSkin.java +++ b/src/main/java/pw/kaboom/extras/commands/CommandSkin.java @@ -1,7 +1,5 @@ package pw.kaboom.extras.commands; -import java.util.HashMap; -import java.util.Map; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.Command; @@ -9,9 +7,13 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import pw.kaboom.extras.Main; import pw.kaboom.extras.skin.SkinManager; import javax.annotation.Nonnull; +import java.util.HashMap; +import java.util.Map; public final class CommandSkin implements CommandExecutor { private final Map lastUsedMillis = new HashMap<>(); @@ -21,6 +23,14 @@ public final class CommandSkin implements CommandExecutor { final @Nonnull Command command, final @Nonnull String label, final String[] args) { + final Main plugin = JavaPlugin.getPlugin(Main.class); + + if (plugin.isFolia()) { + sender.sendMessage(Component + .text("Command cannot be ran on Folia servers!")); + return true; + } + if (sender instanceof ConsoleCommandSender) { sender.sendMessage(Component .text("Command has to be run by a player")); diff --git a/src/main/java/pw/kaboom/extras/commands/CommandUsername.java b/src/main/java/pw/kaboom/extras/commands/CommandUsername.java index 4c9de77..a42fefc 100644 --- a/src/main/java/pw/kaboom/extras/commands/CommandUsername.java +++ b/src/main/java/pw/kaboom/extras/commands/CommandUsername.java @@ -1,8 +1,6 @@ package pw.kaboom.extras.commands; import com.destroystokyo.paper.profile.PlayerProfile; -import java.util.HashMap; -import java.util.Map; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; @@ -12,8 +10,12 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import pw.kaboom.extras.Main; import javax.annotation.Nonnull; +import java.util.HashMap; +import java.util.Map; public final class CommandUsername implements CommandExecutor { private final Map lastUsedMillis = new HashMap<>(); @@ -23,6 +25,14 @@ public final class CommandUsername implements CommandExecutor { final @Nonnull Command command, final @Nonnull String label, final String[] args) { + final Main plugin = JavaPlugin.getPlugin(Main.class); + + if (plugin.isFolia()) { + sender.sendMessage(Component + .text("Command cannot be ran on Folia servers!")); + return true; + } + if (sender instanceof ConsoleCommandSender) { sender.sendMessage(Component .text("Command has to be run by a player")); diff --git a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java index bb9adb9..da5da6e 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java @@ -1,23 +1,19 @@ package pw.kaboom.extras.modules.block; -import java.util.HashSet; - +import com.destroystokyo.paper.event.block.BlockDestroyEvent; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockFadeEvent; -import org.bukkit.event.block.BlockFormEvent; -import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.block.BlockPhysicsEvent; -import org.bukkit.event.block.BlockRedstoneEvent; +import org.bukkit.event.block.*; import org.bukkit.event.entity.EntityChangeBlockEvent; - -import com.destroystokyo.paper.event.block.BlockDestroyEvent; -import org.bukkit.scheduler.BukkitScheduler; import pw.kaboom.extras.Main; +import pw.kaboom.extras.platform.PlatformScheduler; + +import java.util.HashSet; +import java.util.concurrent.TimeUnit; public final class BlockPhysics implements Listener { @@ -178,8 +174,7 @@ public final class BlockPhysics implements Listener { } public static void init(final Main main) { - final BukkitScheduler scheduler = Bukkit.getScheduler(); - - scheduler.runTaskTimer(main, BlockPhysics::updateTPS, 0L, 1200L); // 1 minute + PlatformScheduler.runRepeating(main, BlockPhysics::updateTPS, 0L, + 1L, TimeUnit.MINUTES); } } diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java index a15df64..dd08965 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java @@ -1,9 +1,8 @@ package pw.kaboom.extras.modules.player; -import java.util.HashSet; -import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; - +import com.destroystokyo.paper.event.profile.PreLookupProfileEvent; +import com.destroystokyo.paper.profile.ProfileProperty; +import com.google.common.base.Charsets; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -11,27 +10,19 @@ import org.bukkit.World; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerPreLoginEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.*; import org.bukkit.event.player.PlayerLoginEvent.Result; -import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; - import org.spigotmc.event.player.PlayerSpawnLocationEvent; - -import com.destroystokyo.paper.event.profile.PreLookupProfileEvent; -import com.destroystokyo.paper.profile.ProfileProperty; - -import com.google.common.base.Charsets; - import pw.kaboom.extras.Main; import pw.kaboom.extras.modules.server.ServerTabComplete; import pw.kaboom.extras.skin.SkinManager; +import java.util.HashSet; +import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; + public final class PlayerConnection implements Listener { private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig(); private static final String TITLE = CONFIG.getString("playerJoinTitle"); @@ -119,9 +110,10 @@ public final class PlayerConnection implements Listener { } final Server server = Bukkit.getServer(); + final Main plugin = JavaPlugin.getPlugin(Main.class); - if (!server.getOnlineMode()) { + if (!server.getOnlineMode() && !plugin.isFolia()) { SkinManager.applySkin(player, player.getName(), false); } } diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerPrefix.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerPrefix.java index ce35ed3..05b2c18 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerPrefix.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerPrefix.java @@ -1,11 +1,5 @@ package pw.kaboom.extras.modules.player; -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; @@ -18,8 +12,16 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitScheduler; import pw.kaboom.extras.Main; +import pw.kaboom.extras.platform.PlatformScheduler; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; public class PlayerPrefix implements Listener { private static final Main plugin = JavaPlugin.getPlugin(Main.class); @@ -42,12 +44,10 @@ public class PlayerPrefix implements Listener { opTag = LegacyComponentSerializer.legacySection().deserialize(legacyOpTag); deOpTag = LegacyComponentSerializer.legacySection().deserialize(legacyDeOpTag); - final BukkitScheduler scheduler = Bukkit.getScheduler(); - - scheduler.runTaskTimerAsynchronously(plugin, PlayerPrefix::checkOpStatus, - 0L, 1L); - scheduler.runTaskTimerAsynchronously(plugin, PlayerPrefix::checkDisplayNames, - 0L, 1L); + PlatformScheduler.runRepeating(plugin, PlayerPrefix::checkOpStatus, + 0L, 20L, TimeUnit.MILLISECONDS); + PlatformScheduler.runRepeating(plugin, PlayerPrefix::checkDisplayNames, + 0L, 20L, TimeUnit.MILLISECONDS); } public static void removePrefix(Player player) throws IOException { diff --git a/src/main/java/pw/kaboom/extras/skin/SkinManager.java b/src/main/java/pw/kaboom/extras/skin/SkinManager.java index be76dea..4beaff1 100644 --- a/src/main/java/pw/kaboom/extras/skin/SkinManager.java +++ b/src/main/java/pw/kaboom/extras/skin/SkinManager.java @@ -1,6 +1,16 @@ package pw.kaboom.extras.skin; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.destroystokyo.paper.profile.ProfileProperty; import com.google.gson.Gson; +import net.kyori.adventure.text.Component; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import pw.kaboom.extras.Main; +import pw.kaboom.extras.platform.PlatformScheduler; +import pw.kaboom.extras.skin.response.ProfileResponse; +import pw.kaboom.extras.skin.response.SkinResponse; + import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -8,25 +18,10 @@ import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.util.List; import java.util.UUID; - import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import com.destroystokyo.paper.profile.PlayerProfile; -import com.destroystokyo.paper.profile.ProfileProperty; - -import net.kyori.adventure.text.Component; - -import org.bukkit.scheduler.BukkitScheduler; -import pw.kaboom.extras.Main; -import pw.kaboom.extras.skin.response.ProfileResponse; -import pw.kaboom.extras.skin.response.SkinResponse; - public final class SkinManager { private static final HttpClient httpClient = HttpClient.newHttpClient(); private static final Gson GSON = new Gson(); @@ -34,14 +29,17 @@ public final class SkinManager { .newCachedThreadPool(); public static void resetSkin(final Player player, final boolean shouldSendMessage) { + final Main plugin = JavaPlugin.getPlugin(Main.class); + + if (plugin.isFolia()) { + return; + } + executorService.submit(() -> { final PlayerProfile playerProfile = player.getPlayerProfile(); playerProfile.removeProperty("textures"); - final BukkitScheduler bukkitScheduler = Bukkit.getScheduler(); - final Main plugin = JavaPlugin.getPlugin(Main.class); - - bukkitScheduler.runTask(plugin, () -> player.setPlayerProfile(playerProfile)); + PlatformScheduler.runSync(plugin, () -> player.setPlayerProfile(playerProfile)); if(!shouldSendMessage) { return; @@ -53,6 +51,12 @@ public final class SkinManager { public static void applySkin(final Player player, final String name, final boolean shouldSendMessage) { + final Main plugin = JavaPlugin.getPlugin(Main.class); + + if (plugin.isFolia()) { + return; + } + executorService.submit(() -> { final PlayerProfile profile = player.getPlayerProfile(); final SkinData skinData; @@ -72,10 +76,7 @@ public final class SkinManager { final String signature = skinData.signature(); profile.setProperty(new ProfileProperty("textures", texture, signature)); - final BukkitScheduler bukkitScheduler = Bukkit.getScheduler(); - final Main plugin = JavaPlugin.getPlugin(Main.class); - - bukkitScheduler.runTask(plugin, + PlatformScheduler.runSync(plugin, () -> player.setPlayerProfile(profile));