From eb26de4d433ae3489e4164e24856c52929db58ab Mon Sep 17 00:00:00 2001 From: Billy Robinson Date: Mon, 25 Nov 2024 18:12:47 +0000 Subject: [PATCH] add world and game state management --- .gitignore | 5 +- README.md | 40 ++- build.gradle | 51 ++++ docs/effects.md | 12 +- docs/events.md | 18 +- docs/examples.md | 49 ++++ docs/expressions.md | 46 +++- gradle/wrapper/gradle-wrapper.properties | 7 + gradlew | 249 ++++++++++++++++++ gradlew.bat | 92 +++++++ pom.xml | 127 --------- settings.gradle.kts | 7 + settings.xml | 25 -- src/main/java/ws/billy/MineplexSK.java | 17 -- .../java/ws/billy/skmineplex/SKMineplex.java | 50 ++++ .../skmineplex/classinfos/MineplexGame.java | 40 +++ .../skmineplex/classinfos/MineplexWorld.java | 58 ++++ .../{ => skmineplex}/conditions/.gitkeep | 0 .../billy/{ => skmineplex}/effects/.gitkeep | 0 .../ws/billy/{ => skmineplex}/events/.gitkeep | 0 .../skmineplex/events/StateChangeEvent.java | 55 ++++ .../{ => skmineplex}/expressions/.gitkeep | 0 .../expressions/CurrentGameExpr.java | 79 ++++++ .../billy/{ => skmineplex}/functions/.gitkeep | 0 .../ws/billy/{ => skmineplex}/utils/.gitkeep | 0 .../skmineplex/utils/MineplexGameImpl.java | 69 +++++ src/main/resources/plugin.yml | 11 + 27 files changed, 921 insertions(+), 186 deletions(-) create mode 100644 build.gradle create mode 100644 docs/examples.md create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat delete mode 100644 pom.xml create mode 100644 settings.gradle.kts delete mode 100644 settings.xml delete mode 100644 src/main/java/ws/billy/MineplexSK.java create mode 100644 src/main/java/ws/billy/skmineplex/SKMineplex.java create mode 100644 src/main/java/ws/billy/skmineplex/classinfos/MineplexGame.java create mode 100644 src/main/java/ws/billy/skmineplex/classinfos/MineplexWorld.java rename src/main/java/ws/billy/{ => skmineplex}/conditions/.gitkeep (100%) rename src/main/java/ws/billy/{ => skmineplex}/effects/.gitkeep (100%) rename src/main/java/ws/billy/{ => skmineplex}/events/.gitkeep (100%) create mode 100644 src/main/java/ws/billy/skmineplex/events/StateChangeEvent.java rename src/main/java/ws/billy/{ => skmineplex}/expressions/.gitkeep (100%) create mode 100644 src/main/java/ws/billy/skmineplex/expressions/CurrentGameExpr.java rename src/main/java/ws/billy/{ => skmineplex}/functions/.gitkeep (100%) rename src/main/java/ws/billy/{ => skmineplex}/utils/.gitkeep (100%) create mode 100644 src/main/java/ws/billy/skmineplex/utils/MineplexGameImpl.java create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore index 2ac5897..06215a1 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,6 @@ hs_err_pid* replay_pid* -# maven files -settings.xml +# gradle +.gradle/ +build/ \ No newline at end of file diff --git a/README.md b/README.md index 0a369b4..4184129 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,60 @@ -![MineplexSK Banner](https://i.imgur.com/zO4o6Rb.png) +![SKMineplex Banner](https://i.imgur.com/RO7AAD4.png) -An unofficially supported Skript addon that allows you to use Skript within the Mineplex ecosystem, and interact with the special provided [Mineplex SDK](https://studio.mineplex.com/docs/sdk). +An unofficially supported Skript addon that allows you to use Skript within the Mineplex ecosystem, and interact with +the special provided [Mineplex SDK](https://studio.mineplex.com/docs/sdk). > [!IMPORTANT] -> This isn't an official addon provided by Mineplex itself. This is a community developed and supported addon. We rely on contributions for this! +> This isn't an official addon provided by Mineplex itself. This is a community developed and supported addon. We rely +> on contributions for this! ## Addon Documentation -[Expressions](/docs/expressions.md) ✦ [Conditions](/docs/conditions.md) ✦ [Effects](/docs/effects.md) ✦ [Events](/docs/events.md) ✦ [Functions](/docs/functions.md) +[Expressions](/docs/expressions.md) ✦ [Conditions](/docs/conditions.md) ✦ [Effects](/docs/effects.md) +✦ [Events](/docs/events.md) ✦ [Functions](/docs/functions.md) ✦ [Examples](/docs/examples.md) ## Purpose -This exists to make it easier for people without Java knowledge to setup and use the Mineplex ecosystem, with the goal being to make it far easier for people to manage and create their projects quickly. + +This exists to make it easier for people without Java knowledge to setup and use the Mineplex ecosystem, with the goal +being to make it far easier for people to manage and create their projects quickly. Our goal with this addon is to have this addon have full feature parity with the actual Mineplex Java SDK. ### Pre-requisites -- You must have [Skript plugin](https://github.com/SkriptLang/Skript/releases) downloaded already, this addon requires it! + +- You must have [Skript plugin](https://github.com/SkriptLang/Skript/releases) downloaded already, this addon requires + it! - You must have a [Mineplex Studio project](https://studio.mineplex.com/docs/getting-started) created and ready to use ## How to install + - Add your **Skript** plugin into a directory within your Mineplex project named `external-plugins` -- Download the [latest version](https://github.com/BillyDotWS/MineplexSK/releases) of the addon from the Releases. +- Download the [latest version](https://github.com/BillyDotWS/MineplexSK/releases) of the addon from the Releases. - Add this addon jar into the same `external-plugins` directory ## How to use -This Skript addon allows you to use the Skript 'way of coding' with the Mineplex SDK. In order to do this, it adds some custom language to Skript to allow for usage. + +This Skript addon allows you to use the Skript 'way of coding' with the Mineplex SDK. In order to do this, it adds some +custom language to Skript to allow for usage. ### Using skript within Mineplex projects + *Note: requires you to have followed the Installation steps first* -In order to use Skript scripts within a project, drop your skript's into a folder (within your project). Within `external-plugins`, create a directory called `Skript`, within this directory, create another called `scripts`. +In order to use Skript scripts within a project, drop your skript's into a folder (within your project). Within +`external-plugins`, create a directory called `Skript`, within this directory, create another called `scripts`. Then create your Skript file (the same way as everywhere else): `scriptName.sk` After that, use Skript the same way as normal, dropping extra scripts into the folder(s) and building your project! ## Contributing + > [!CAUTION] -> This library enforces a licence, which states that you cannot create a private version of this work. Please contribute any improvements you make back to the base repository to assist in making it easier to use Skript on Mineplex for everyone! See [the license](/LICENSE) for more information. +> This library enforces a licence, which states that you cannot create a private version of this work. Please contribute +> any improvements you make back to the base repository to assist in making it easier to use Skript on Mineplex for +> everyone! See [the license](/LICENSE) for more information. -We welcome contributions to improve this project! Please follow these guidelines to ensure a smooth contribution process: +We welcome contributions to improve this project! Please follow these guidelines to ensure a smooth contribution +process: ### How to Contribute @@ -60,7 +76,7 @@ We welcome contributions to improve this project! Please follow these guidelines 5. **Run Tests** Run all tests to confirm that your changes do not break existing functionality: ```bash - mvn test + ./gradlew test ``` 6. **Commit Your Changes** Write clear and concise commit messages: diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..8687ba7 --- /dev/null +++ b/build.gradle @@ -0,0 +1,51 @@ +plugins { + id 'java' + id 'com.mineplex.sdk.plugin' version "1.6.0" +} + +group = 'ws.billy.skmineplex' +version = '1.0-SNAPSHOT' +sourceCompatibility = '21' +targetCompatibility = '21' + +ext { + spigotApiVersion = '1.21.1-R0.1-SNAPSHOT' + lombokVersion = '1.18.30' + jacksonCoreVersion = '2.15.2' + jacksonDatabindVersion = '2.15.2' + skriptVersion = '2.9.4' +} + +repositories { + mavenCentral() + maven { url 'https://repo.papermc.io/repository/maven-public/' } + maven { url 'https://repo.skriptlang.org/releases' } +} + +dependencies { + compileOnly "org.spigotmc:spigot-api:${spigotApiVersion}" + compileOnly "org.projectlombok:lombok:${lombokVersion}" + implementation "com.fasterxml.jackson.core:jackson-core:${jacksonCoreVersion}" + implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonDatabindVersion}" + implementation "com.github.SkriptLang:Skript:${skriptVersion}" +} + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' +} + +tasks.register('shade', Jar) { + archiveClassifier = 'all' + from sourceSets.main.output + dependsOn configurations.runtimeClasspath + from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } + duplicatesStrategy = DuplicatesStrategy.INCLUDE // or DuplicatesStrategy.IGNORE + manifest { + attributes( + 'Implementation-Title': project.name, + 'Implementation-Version': project.version + ) + } +} + +build.dependsOn shade diff --git a/docs/effects.md b/docs/effects.md index c8bf432..e2fa92f 100644 --- a/docs/effects.md +++ b/docs/effects.md @@ -1 +1,11 @@ -## Effects \ No newline at end of file +# Effects + +## Game + +## World + +### Create a world + +``` +[create] mineplex world with template %string% +``` \ No newline at end of file diff --git a/docs/events.md b/docs/events.md index 4ae110c..b9d30c4 100644 --- a/docs/events.md +++ b/docs/events.md @@ -1 +1,17 @@ -## Events \ No newline at end of file +# Events + +## Game + +### Game state change + +``` +on game state change +``` + +This also then exposes the previous and new state. + +``` +on game state change: + broadcast "%past event-gamestate%" # the previous state + broadcast "%event-gamestate%" # the new state +``` \ No newline at end of file diff --git a/docs/examples.md b/docs/examples.md new file mode 100644 index 0000000..6d62253 --- /dev/null +++ b/docs/examples.md @@ -0,0 +1,49 @@ +# Examples + +## World + +### Loading a world + +Load the world from a template name and save it to a variable for further usage + +``` +set {_world} to "world-name" parsed as a mineplex world +``` + +## Game + +### Creating a game + +Create a game and register it as the current game running on this server + +``` +set {_game} to "Micro Battles" parsed as a mineplex game +set {_game}'s game world to {_world} +set {_game}'s maximum players to 20 +set {_game}'s minimum players to 4 +set the current game to {_game} +``` + +### Starting a game + +``` +on join: + add player to {_players::*} + +on player quit: + remove player from {_players::*} + +every 1 second: + if size of {_players::*} is greater than or equal to {_game}'s minimum players: + wait 10 seconds + set game state of {_game} to "STARTED" + clear {_players::*} +``` + +### Game state changed + +``` +on game state change: + if event-gamestate = "STARTED": + broadcast "The game has started!" +``` \ No newline at end of file diff --git a/docs/expressions.md b/docs/expressions.md index 6602488..fc758f8 100644 --- a/docs/expressions.md +++ b/docs/expressions.md @@ -1 +1,45 @@ -## Expressions \ No newline at end of file +# Expressions + +## Game + +### Set game state + +``` +set %game%'s game state to %state% +``` + +State options: `PREPARING`, `PRE_START`, `STARTED`, `ENDED` + +### Get current game state + +``` +%game%'s game state +``` + +### Set game world + +``` +set %game%'s game world to %mineplex world% +``` + +See effects -> Create a world for information + +### Get game world + +``` +%game%'s game world +``` + +## Game Manager + +### Set the current game of the server + +``` +set [the] current game to {_game} +``` + +### Get the current game + +``` +[the] current game +``` diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a441313 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..b740cf1 --- /dev/null +++ b/gradlew @@ -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" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..25da30d --- /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. 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 diff --git a/pom.xml b/pom.xml deleted file mode 100644 index dd6477e..0000000 --- a/pom.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - 4.0.0 - - - MineplexSK - ws.billy - MineplexSK - 1.0-SNAPSHOT - - - - - 21 - 21 - UTF-8 - - - 1.21-R0.1-SNAPSHOT - 1.21.1-R0.1-SNAPSHOT - 1.18.30 - 2.15.2 - 2.9.4 - - - 1.3.7 - 3.5.1 - - - - - - mineplex-mineplex-studio-partners - mineplex-mineplex-studio-partners - https://mineplex-003539567218.d.codeartifact.us-east-1.amazonaws.com/maven/mineplex-studio-partners/ - - - paper - PaperSpigot - https://repo.papermc.io/repository/maven-public/ - - - skript - SkriptLang - https://repo.skriptlang.org/releases - - - - - - - - - io.papermc.paper - paper-api - ${paper.api.version} - provided - - - - - org.spigotmc - spigot - ${spigot.version} - provided - - - - - org.projectlombok - lombok - ${lombok.version} - compile - - - - com.fasterxml.jackson.core - jackson-core - ${jackson.version} - compile - - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - compile - - - - - com.github.SkriptLang - Skript - ${skript.version} - - - - - - - - - - com.mineplex.sdk - plugin - ${mineplex.plugin.version} - - - - - org.apache.maven.plugins - maven-shade-plugin - ${shade.plugin.version} - - - package - - shade - - - - - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..2eb9cae --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,7 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + maven("https://repo.papermc.io/repository/maven-public/") + } +} \ No newline at end of file diff --git a/settings.xml b/settings.xml deleted file mode 100644 index 573d60c..0000000 --- a/settings.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - mineplex-mineplex-studio-partners - - true - - - - mineplex-mineplex-studio-partners - - https://mineplex-003539567218.d.codeartifact.us-east-1.amazonaws.com/maven/mineplex-studio-partners/ - - - - - - - - mineplex-mineplex-studio-partners - aws - ${MINEPLEX_TOKEN} - - - \ No newline at end of file diff --git a/src/main/java/ws/billy/MineplexSK.java b/src/main/java/ws/billy/MineplexSK.java deleted file mode 100644 index 793285e..0000000 --- a/src/main/java/ws/billy/MineplexSK.java +++ /dev/null @@ -1,17 +0,0 @@ -package ws.billy; - -import ch.njol.skript.SkriptAddon; -import lombok.Getter; -import org.bukkit.plugin.java.JavaPlugin; - - -public class MineplexSK extends JavaPlugin { - - @Getter - private static SkriptAddon skriptAddon; - - public void onEnable() { - - } - -} diff --git a/src/main/java/ws/billy/skmineplex/SKMineplex.java b/src/main/java/ws/billy/skmineplex/SKMineplex.java new file mode 100644 index 0000000..639252a --- /dev/null +++ b/src/main/java/ws/billy/skmineplex/SKMineplex.java @@ -0,0 +1,50 @@ +package ws.billy.skmineplex; + +import ch.njol.skript.Skript; +import ch.njol.skript.SkriptAddon; +import com.mineplex.studio.sdk.modules.MineplexModule; +import com.mineplex.studio.sdk.modules.MineplexModuleManager; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.IOException; + +public class SKMineplex extends JavaPlugin { + + private static final String PACKAGE = "ws.billy.skmineplex"; + + @Getter + private static SkriptAddon skriptAddon; + @Getter + private static SKMineplex instance; + + public static T getModule(final Class clazz) { + return MineplexModuleManager.getRegisteredModule(clazz); + } + + @Override + public void onEnable() { + + final Plugin mineplexEngine = Bukkit.getPluginManager().getPlugin("MineplexEngine"); + if (mineplexEngine == null || !mineplexEngine.isEnabled()) { + throw new RuntimeException("MineplexEngine plugin isn't enabled, this addon cannot run without it!"); + } + + // static fields + instance = this; + skriptAddon = Skript.registerAddon(this); + + try { + skriptAddon.loadClasses(PACKAGE, "classinfos", "conditions", "effects", "events", "expressions", "functions", "utils"); + } catch (IOException e) { + throw new RuntimeException(e); + } + + this.getLogger().info("[SKMineplex] Mineplex Studio Skript addon fully loaded!"); + this.getLogger().info("[SKMineplex] This is an unofficial addon, please direct questions to our Github repository, not the Mineplex studio discord!"); + + } + +} diff --git a/src/main/java/ws/billy/skmineplex/classinfos/MineplexGame.java b/src/main/java/ws/billy/skmineplex/classinfos/MineplexGame.java new file mode 100644 index 0000000..bcdf3bd --- /dev/null +++ b/src/main/java/ws/billy/skmineplex/classinfos/MineplexGame.java @@ -0,0 +1,40 @@ +package ws.billy.skmineplex.classinfos; + +import ch.njol.skript.classes.ClassInfo; +import ch.njol.skript.classes.Parser; +import ch.njol.skript.lang.ParseContext; +import ch.njol.skript.registrations.Classes; +import lombok.extern.slf4j.Slf4j; +import ws.billy.skmineplex.utils.MineplexGameImpl; + +@Slf4j +public class MineplexGame { + + static { + + Classes.registerClass(new ClassInfo<>(MineplexGameImpl.class, "mineplexgame") + .user("mineplex ?games?") + .name("Mineplex Game") + .description("Represents a Mineplex Game.") + .examples("set {_game} to \"Micro Battles\" parsed as a mineplex game") + .parser(new Parser<>() { + @Override + public String toString(MineplexGameImpl o, int flags) { + return toVariableNameString(o); + } + + @Override + public MineplexGameImpl parse(String input, ParseContext context) { + return new MineplexGameImpl(input); + } + + @Override + public String toVariableNameString(MineplexGameImpl game) { + return game.getName(); + } + + })); + + } + +} diff --git a/src/main/java/ws/billy/skmineplex/classinfos/MineplexWorld.java b/src/main/java/ws/billy/skmineplex/classinfos/MineplexWorld.java new file mode 100644 index 0000000..57fdbe1 --- /dev/null +++ b/src/main/java/ws/billy/skmineplex/classinfos/MineplexWorld.java @@ -0,0 +1,58 @@ +package ws.billy.skmineplex.classinfos; + +import ch.njol.skript.classes.ClassInfo; +import ch.njol.skript.classes.Parser; +import ch.njol.skript.lang.ParseContext; +import ch.njol.skript.registrations.Classes; +import com.mineplex.studio.sdk.modules.world.MineplexWorldModule; +import com.mineplex.studio.sdk.modules.world.config.MineplexWorldConfig; +import com.mineplex.studio.sdk.modules.world.config.WorldCreationConfig; +import lombok.extern.slf4j.Slf4j; +import ws.billy.skmineplex.SKMineplex; + +import java.util.UUID; + +@Slf4j +public class MineplexWorld { + + static { + + Classes.registerClass(new ClassInfo<>(com.mineplex.studio.sdk.modules.world.MineplexWorld.class, "mineplexworld") + .user("mineplex ?worlds?") + .name("Mineplex World") + .description("Represents a Mineplex world.") + .examples("set {_world} to \"world-name\" parsed as a mineplex world # loads the world with the given template") + .parser(new Parser<>() { + @Override + public String toString(com.mineplex.studio.sdk.modules.world.MineplexWorld o, int flags) { + return toVariableNameString(o); + } + + @Override + public com.mineplex.studio.sdk.modules.world.MineplexWorld parse(String input, ParseContext context) { + final WorldCreationConfig config = WorldCreationConfig.builder() + .worldTemplate(input) + .build(); + + final MineplexWorldConfig worldConfig = MineplexWorldConfig.builder() + .worldRegionType(MineplexWorldConfig.WorldRegionFormatType.ANVIL) + .worldCreationConfig(config) + .build(); + + // load world with UUID as name. + log.info("Loading world {} with config: {}", UUID.randomUUID(), worldConfig); + return SKMineplex.getModule(MineplexWorldModule.class) + .createMineplexWorld(worldConfig, UUID.randomUUID().toString()); + + } + + @Override + public String toVariableNameString(com.mineplex.studio.sdk.modules.world.MineplexWorld world) { + return world.getId(); + } + + })); + + } + +} diff --git a/src/main/java/ws/billy/conditions/.gitkeep b/src/main/java/ws/billy/skmineplex/conditions/.gitkeep similarity index 100% rename from src/main/java/ws/billy/conditions/.gitkeep rename to src/main/java/ws/billy/skmineplex/conditions/.gitkeep diff --git a/src/main/java/ws/billy/effects/.gitkeep b/src/main/java/ws/billy/skmineplex/effects/.gitkeep similarity index 100% rename from src/main/java/ws/billy/effects/.gitkeep rename to src/main/java/ws/billy/skmineplex/effects/.gitkeep diff --git a/src/main/java/ws/billy/events/.gitkeep b/src/main/java/ws/billy/skmineplex/events/.gitkeep similarity index 100% rename from src/main/java/ws/billy/events/.gitkeep rename to src/main/java/ws/billy/skmineplex/events/.gitkeep diff --git a/src/main/java/ws/billy/skmineplex/events/StateChangeEvent.java b/src/main/java/ws/billy/skmineplex/events/StateChangeEvent.java new file mode 100644 index 0000000..718db23 --- /dev/null +++ b/src/main/java/ws/billy/skmineplex/events/StateChangeEvent.java @@ -0,0 +1,55 @@ +package ws.billy.skmineplex.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; +import com.mineplex.studio.sdk.modules.game.GameState; +import com.mineplex.studio.sdk.modules.game.MineplexGame; +import com.mineplex.studio.sdk.modules.game.event.PostMineplexGameStateChangeEvent; +import org.bukkit.event.Event; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class StateChangeEvent extends SkriptEvent { + + static { + Skript.registerEvent("Game state change", StateChangeEvent.class, PostMineplexGameStateChangeEvent.class, "game state chang(e|ing)"); + + EventValues.registerEventValue(PostMineplexGameStateChangeEvent.class, GameState.class, new Getter<>() { + @Override + public @NotNull GameState get(PostMineplexGameStateChangeEvent arg) { + return arg.getFromState(); + } + }, -1); + + EventValues.registerEventValue(PostMineplexGameStateChangeEvent.class, GameState.class, new Getter<>() { + @Override + public @NotNull GameState get(PostMineplexGameStateChangeEvent arg) { + return arg.getToState(); + } + }, 0); + + } + + Literal gameLiteral; + + @Override + public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { + gameLiteral = (Literal) args[0]; + return true; + } + + @Override + public boolean check(Event e) { + return true; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + if (event == null) return null; + return "Game state change event " + event; + } +} diff --git a/src/main/java/ws/billy/expressions/.gitkeep b/src/main/java/ws/billy/skmineplex/expressions/.gitkeep similarity index 100% rename from src/main/java/ws/billy/expressions/.gitkeep rename to src/main/java/ws/billy/skmineplex/expressions/.gitkeep diff --git a/src/main/java/ws/billy/skmineplex/expressions/CurrentGameExpr.java b/src/main/java/ws/billy/skmineplex/expressions/CurrentGameExpr.java new file mode 100644 index 0000000..5708f73 --- /dev/null +++ b/src/main/java/ws/billy/skmineplex/expressions/CurrentGameExpr.java @@ -0,0 +1,79 @@ +package ws.billy.skmineplex.expressions; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import ch.njol.util.coll.CollectionUtils; +import com.mineplex.studio.sdk.modules.game.MineplexGame; +import com.mineplex.studio.sdk.modules.game.MineplexGameModule; +import lombok.NonNull; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; +import ws.billy.skmineplex.SKMineplex; + +import java.util.Optional; + +public class CurrentGameExpr extends SimpleExpression { + + static { + Skript.registerExpression(CurrentGameExpr.class, MineplexGame.class, ExpressionType.COMBINED, "[the] current game"); + } + + @Override + protected @Nullable MineplexGame[] get(Event event) { + final @NonNull Optional currentGame = SKMineplex.getModule(MineplexGameModule.class).getCurrentGame(); + return currentGame.map(mineplexGame -> new MineplexGame[]{mineplexGame}).orElseGet(() -> new MineplexGame[0]); + } + + @Override + public boolean canBeSingle() { + return true; + } + + @Override + public boolean isSingle() { + return true; + } + + @Override + public Class getReturnType() { + return MineplexGame.class; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return SKMineplex.getModule(MineplexGameModule.class).getCurrentGame().toString(); + } + + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + return true; + } + + @Override + public Class[] acceptChange(final Changer.ChangeMode mode) { + if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.RESET) { + return CollectionUtils.array(String.class); + } + return null; + } + + @Override + public void change(Event event, Object[] delta, Changer.ChangeMode mode) { + final MineplexGameModule gameModule = SKMineplex.getModule(MineplexGameModule.class); + if (mode == Changer.ChangeMode.SET) { + if (delta.length == 0 || delta[0] == null) { + Skript.error("Target game cannot be null for this"); + return; + } + gameModule.setCurrentGame((MineplexGame) delta[0]); + } else if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.RESET) { + gameModule.setCurrentGame(null); + } + } + +} diff --git a/src/main/java/ws/billy/functions/.gitkeep b/src/main/java/ws/billy/skmineplex/functions/.gitkeep similarity index 100% rename from src/main/java/ws/billy/functions/.gitkeep rename to src/main/java/ws/billy/skmineplex/functions/.gitkeep diff --git a/src/main/java/ws/billy/utils/.gitkeep b/src/main/java/ws/billy/skmineplex/utils/.gitkeep similarity index 100% rename from src/main/java/ws/billy/utils/.gitkeep rename to src/main/java/ws/billy/skmineplex/utils/.gitkeep diff --git a/src/main/java/ws/billy/skmineplex/utils/MineplexGameImpl.java b/src/main/java/ws/billy/skmineplex/utils/MineplexGameImpl.java new file mode 100644 index 0000000..4d6779e --- /dev/null +++ b/src/main/java/ws/billy/skmineplex/utils/MineplexGameImpl.java @@ -0,0 +1,69 @@ +package ws.billy.skmineplex.utils; + +import com.mineplex.studio.sdk.modules.game.BuiltInGameState; +import com.mineplex.studio.sdk.modules.game.BuiltInPlayerState; +import com.mineplex.studio.sdk.modules.game.MineplexGameMechanicFactory; +import com.mineplex.studio.sdk.modules.game.SingleWorldMineplexGame; +import com.mineplex.studio.sdk.modules.game.helper.GameStateTracker; +import com.mineplex.studio.sdk.modules.game.helper.PlayerStateTracker; +import com.mineplex.studio.sdk.modules.world.MineplexWorld; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.experimental.Delegate; +import ws.billy.skmineplex.SKMineplex; + +@RequiredArgsConstructor +public class MineplexGameImpl implements SingleWorldMineplexGame { + + private final String name; + + @Delegate + private PlayerStateTracker playerStateTracker; + @Delegate + private GameStateTracker gameStateTracker; + private MineplexGameMechanicFactory gameMechanicFactory; + + @Setter + private MineplexWorld gameWorld; + + @Setter + @Getter + private int minimumPlayers, maximumPlayers; + + @Override + public @NonNull MineplexWorld getGameWorld() { + return gameWorld; + } + + @Override + public @NonNull String getName() { + return name; + } + + @Override + public @NonNull MineplexGameMechanicFactory getGameMechanicFactory() { + return gameMechanicFactory; + } + + @Override + public void setup() { + this.gameStateTracker = new GameStateTracker(this, BuiltInGameState.PREPARING); + this.playerStateTracker = new PlayerStateTracker(this, BuiltInPlayerState.SPECTATOR); + this.gameMechanicFactory = SKMineplex.getModule(MineplexGameMechanicFactory.class); + } + + @Override + public void teardown() { + this.gameStateTracker = null; + this.playerStateTracker = null; + this.gameMechanicFactory.teardown(); + this.gameMechanicFactory = null; + } + + @Override + public String toString() { + return name; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..36f39a4 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +# basic details +name: SKMineplex +version: 1.0 +main: ws.billy.skmineplex.SKMineplex + +# dependencies +depend: [ Skript, MineplexEngine ] + +# author details +author: BillyDotWS +website: https://billy.ws \ No newline at end of file