Gradle-based plugin targeting the latest Paper API (26.2), with configurable races (laps, checkpoints, lobby/start, min players, countdown), a /boatparty command suite, and lap/checkpoint tracking via player movement. Includes Gitea Actions CI to build with JDK 25. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["**"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["**"]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up JDK 25
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: "25"
|
||||||
|
|
||||||
|
- name: Grant execute permission for gradlew
|
||||||
|
run: chmod +x gradlew
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: ./gradlew build --no-daemon
|
||||||
|
|
||||||
|
- name: Upload plugin jar
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: BoatParty
|
||||||
|
path: build/libs/BoatParty-*.jar
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
.gradle/
|
||||||
|
build/
|
||||||
|
out/
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
.vscode/
|
||||||
|
.DS_Store
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# BoatParty
|
||||||
|
|
||||||
|
An ice-and-boat lap racing minigame for [PaperMC](https://papermc.io/), targeting the latest
|
||||||
|
Minecraft server API (Paper 26.2).
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
|
||||||
|
Build an ice track, place checkpoints along it, and race other players in boats for the
|
||||||
|
fastest lap times over a configurable number of laps.
|
||||||
|
|
||||||
|
## Commands (`/boatparty`, alias `/bp`)
|
||||||
|
|
||||||
|
| Command | Description |
|
||||||
|
|---|---|
|
||||||
|
| `/bp create <name>` | Create a new race |
|
||||||
|
| `/bp delete <name>` | Delete a race |
|
||||||
|
| `/bp setlobby <name>` | Set the waiting-area location (your current position) |
|
||||||
|
| `/bp setstart <name>` | Set the race start/grid location |
|
||||||
|
| `/bp addcheckpoint <name>` | Append a checkpoint at your current position |
|
||||||
|
| `/bp removecheckpoint <name>` | Remove the last checkpoint |
|
||||||
|
| `/bp setlaps <name> <n>` | Set number of laps |
|
||||||
|
| `/bp setminplayers <name> <n>` | Minimum players required to auto-start the countdown |
|
||||||
|
| `/bp setcountdown <name> <seconds>` | Countdown length before a race begins |
|
||||||
|
| `/bp setradius <name> <blocks>` | Checkpoint trigger radius |
|
||||||
|
| `/bp join <name>` / `/bp leave` | Join or leave a race |
|
||||||
|
| `/bp start <name>` / `/bp stop <name>` | Force-start or stop a race (admin) |
|
||||||
|
| `/bp list` / `/bp info <name>` | List races / show race details |
|
||||||
|
|
||||||
|
The last checkpoint added also serves as the finish line — crossing it completes a lap.
|
||||||
|
|
||||||
|
## Permissions
|
||||||
|
|
||||||
|
- `boatparty.admin` (default: op) — configure and control races
|
||||||
|
- `boatparty.play` (default: true) — join and play races
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
```
|
||||||
|
./gradlew build
|
||||||
|
```
|
||||||
|
|
||||||
|
The compiled plugin jar is produced at `build/libs/BoatParty-<version>.jar`.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Java 21+
|
||||||
|
- PaperMC (latest, built against Paper API 26.2)
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
plugins {
|
||||||
|
java
|
||||||
|
id("com.gradleup.shadow") version "8.3.5"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "us.tss3.boatparty"
|
||||||
|
version = "1.0.0"
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion.set(JavaLanguageVersion.of(25))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven("https://repo.papermc.io/repository/maven-public/")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly("io.papermc.paper:paper-api:26.2.build.111-stable")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
compileJava {
|
||||||
|
options.encoding = "UTF-8"
|
||||||
|
options.release.set(25)
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
filesMatching("plugin.yml") {
|
||||||
|
expand("version" to project.version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveClassifier.set("")
|
||||||
|
archiveBaseName.set("BoatParty")
|
||||||
|
}
|
||||||
|
|
||||||
|
build {
|
||||||
|
dependsOn(shadowJar)
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
BIN
Binary file not shown.
+7
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
#!/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.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# 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 -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||||
|
' "$PWD" ) || 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='-Dfile.encoding=UTF-8 "-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" "$@"
|
||||||
Vendored
+94
@@ -0,0 +1,94 @@
|
|||||||
|
@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
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@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=-Dfile.encoding=UTF-8 "-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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = "BoatParty"
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package us.tss3.boatparty;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import us.tss3.boatparty.command.BoatPartyCommand;
|
||||||
|
import us.tss3.boatparty.game.RaceManager;
|
||||||
|
import us.tss3.boatparty.listener.RaceListener;
|
||||||
|
|
||||||
|
public final class BoatPartyPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
private RaceManager raceManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
saveDefaultConfig();
|
||||||
|
|
||||||
|
this.raceManager = new RaceManager(this);
|
||||||
|
this.raceManager.load();
|
||||||
|
|
||||||
|
BoatPartyCommand commandExecutor = new BoatPartyCommand(this, raceManager);
|
||||||
|
var command = getCommand("boatparty");
|
||||||
|
if (command != null) {
|
||||||
|
command.setExecutor(commandExecutor);
|
||||||
|
command.setTabCompleter(commandExecutor);
|
||||||
|
}
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(new RaceListener(this, raceManager), this);
|
||||||
|
|
||||||
|
getLogger().info("BoatParty enabled - " + raceManager.getRaces().size() + " race(s) loaded.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
if (raceManager != null) {
|
||||||
|
raceManager.stopAllRaces();
|
||||||
|
raceManager.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RaceManager getRaceManager() {
|
||||||
|
return raceManager;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,381 @@
|
|||||||
|
package us.tss3.boatparty.command;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import us.tss3.boatparty.BoatPartyPlugin;
|
||||||
|
import us.tss3.boatparty.game.Race;
|
||||||
|
import us.tss3.boatparty.game.RaceManager;
|
||||||
|
import us.tss3.boatparty.game.RaceState;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public final class BoatPartyCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
private static final List<String> SUBCOMMANDS = List.of(
|
||||||
|
"create", "delete", "setlobby", "setstart", "addcheckpoint", "removecheckpoint",
|
||||||
|
"setlaps", "setminplayers", "setcountdown", "setradius", "join", "leave",
|
||||||
|
"start", "stop", "list", "info");
|
||||||
|
|
||||||
|
private final BoatPartyPlugin plugin;
|
||||||
|
private final RaceManager raceManager;
|
||||||
|
|
||||||
|
public BoatPartyCommand(BoatPartyPlugin plugin, RaceManager raceManager) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.raceManager = raceManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
sendHelp(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String sub = args[0].toLowerCase(Locale.ROOT);
|
||||||
|
switch (sub) {
|
||||||
|
case "create" -> handleCreate(sender, args);
|
||||||
|
case "delete" -> handleDelete(sender, args);
|
||||||
|
case "setlobby" -> handleSetLobby(sender, args);
|
||||||
|
case "setstart" -> handleSetStart(sender, args);
|
||||||
|
case "addcheckpoint" -> handleAddCheckpoint(sender, args);
|
||||||
|
case "removecheckpoint" -> handleRemoveCheckpoint(sender, args);
|
||||||
|
case "setlaps" -> handleSetLaps(sender, args);
|
||||||
|
case "setminplayers" -> handleSetMinPlayers(sender, args);
|
||||||
|
case "setcountdown" -> handleSetCountdown(sender, args);
|
||||||
|
case "setradius" -> handleSetRadius(sender, args);
|
||||||
|
case "join" -> handleJoin(sender, args);
|
||||||
|
case "leave" -> handleLeave(sender);
|
||||||
|
case "start" -> handleStart(sender, args);
|
||||||
|
case "stop" -> handleStop(sender, args);
|
||||||
|
case "list" -> handleList(sender);
|
||||||
|
case "info" -> handleInfo(sender, args);
|
||||||
|
default -> sendHelp(sender);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleCreate(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
if (args.length < 2) {
|
||||||
|
msg(sender, "Usage: /boatparty create <name>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String name = args[1];
|
||||||
|
if (raceManager.getRace(name) != null) {
|
||||||
|
msg(sender, "A race named '" + name + "' already exists.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
raceManager.createRace(name);
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Created race '" + name + "'. Now set lobby, start, and checkpoints.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleDelete(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
if (args.length < 2) {
|
||||||
|
msg(sender, "Usage: /boatparty delete <name>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (raceManager.deleteRace(args[1])) {
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Deleted race '" + args[1] + "'.");
|
||||||
|
} else {
|
||||||
|
msg(sender, "No such race.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSetLobby(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Player player = requirePlayer(sender);
|
||||||
|
if (player == null) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
race.setLobby(player.getLocation());
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Lobby set for race '" + race.getName() + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSetStart(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Player player = requirePlayer(sender);
|
||||||
|
if (player == null) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
race.setStartLocation(player.getLocation());
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Start location set for race '" + race.getName() + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleAddCheckpoint(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Player player = requirePlayer(sender);
|
||||||
|
if (player == null) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
race.addCheckpoint(player.getLocation());
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Checkpoint #" + race.getCheckpoints().size() + " added to '" + race.getName() + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleRemoveCheckpoint(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
if (race.removeLastCheckpoint()) {
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Removed last checkpoint from '" + race.getName() + "'.");
|
||||||
|
} else {
|
||||||
|
msg(sender, "Race '" + race.getName() + "' has no checkpoints.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSetLaps(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
if (args.length < 3) {
|
||||||
|
msg(sender, "Usage: /boatparty setlaps <name> <laps>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
int laps = Integer.parseInt(args[2]);
|
||||||
|
if (laps < 1) throw new NumberFormatException();
|
||||||
|
race.setLaps(laps);
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Laps for '" + race.getName() + "' set to " + laps + ".");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
msg(sender, "Laps must be a positive integer.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSetMinPlayers(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
if (args.length < 3) {
|
||||||
|
msg(sender, "Usage: /boatparty setminplayers <name> <count>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
int count = Integer.parseInt(args[2]);
|
||||||
|
if (count < 1) throw new NumberFormatException();
|
||||||
|
race.setMinPlayers(count);
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Minimum players for '" + race.getName() + "' set to " + count + ".");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
msg(sender, "Value must be a positive integer.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSetCountdown(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
if (args.length < 3) {
|
||||||
|
msg(sender, "Usage: /boatparty setcountdown <name> <seconds>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
int seconds = Integer.parseInt(args[2]);
|
||||||
|
if (seconds < 0) throw new NumberFormatException();
|
||||||
|
race.setCountdownSeconds(seconds);
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Countdown for '" + race.getName() + "' set to " + seconds + "s.");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
msg(sender, "Value must be a non-negative integer.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleSetRadius(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
if (args.length < 3) {
|
||||||
|
msg(sender, "Usage: /boatparty setradius <name> <blocks>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
double radius = Double.parseDouble(args[2]);
|
||||||
|
if (radius <= 0) throw new NumberFormatException();
|
||||||
|
race.setCheckpointRadius(radius);
|
||||||
|
raceManager.save();
|
||||||
|
msg(sender, "Checkpoint radius for '" + race.getName() + "' set to " + radius + ".");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
msg(sender, "Value must be a positive number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleJoin(CommandSender sender, String[] args) {
|
||||||
|
Player player = requirePlayer(sender);
|
||||||
|
if (player == null) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
|
||||||
|
if (!race.isReady()) {
|
||||||
|
msg(sender, "Race '" + race.getName() + "' is not fully configured yet.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (race.getState() != RaceState.WAITING) {
|
||||||
|
msg(sender, "Race '" + race.getName() + "' is not accepting new players right now.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Race existing = raceManager.getRaceOf(player);
|
||||||
|
if (existing != null) {
|
||||||
|
msg(sender, "You are already in race '" + existing.getName() + "'. Leave it first.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
race.addParticipant(player.getUniqueId());
|
||||||
|
player.teleport(race.getLobby());
|
||||||
|
broadcast(race, player.getName() + " joined the race! (" + race.getParticipants().size() + " players)");
|
||||||
|
|
||||||
|
if (race.getParticipants().size() >= race.getMinPlayers()) {
|
||||||
|
race.startCountdown(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleLeave(CommandSender sender) {
|
||||||
|
Player player = requirePlayer(sender);
|
||||||
|
if (player == null) return;
|
||||||
|
Race race = raceManager.getRaceOf(player);
|
||||||
|
if (race == null) {
|
||||||
|
msg(sender, "You are not in a race.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
race.removeParticipant(player.getUniqueId());
|
||||||
|
msg(sender, "You left race '" + race.getName() + "'.");
|
||||||
|
if (race.getState() == RaceState.COUNTDOWN && race.getParticipants().size() < race.getMinPlayers()) {
|
||||||
|
race.cancelCountdown();
|
||||||
|
race.setState(RaceState.WAITING);
|
||||||
|
broadcast(race, "Not enough players, countdown cancelled.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleStart(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
if (!race.isReady()) {
|
||||||
|
msg(sender, "Race is not fully configured (need lobby, start, and at least one checkpoint).");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (race.getState() != RaceState.WAITING) {
|
||||||
|
msg(sender, "Race is already starting or running.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (race.getParticipants().isEmpty()) {
|
||||||
|
msg(sender, "No players have joined this race yet.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
race.startCountdown(plugin);
|
||||||
|
msg(sender, "Countdown started for '" + race.getName() + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleStop(CommandSender sender, String[] args) {
|
||||||
|
if (!requirePermission(sender, "boatparty.admin")) return;
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
broadcast(race, "The race has been stopped by an admin.");
|
||||||
|
race.reset();
|
||||||
|
msg(sender, "Race '" + race.getName() + "' stopped and reset.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleList(CommandSender sender) {
|
||||||
|
if (raceManager.getRaces().isEmpty()) {
|
||||||
|
msg(sender, "There are no races configured.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
msg(sender, "Races: " + raceManager.getRaces().keySet().stream().collect(Collectors.joining(", ")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleInfo(CommandSender sender, String[] args) {
|
||||||
|
Race race = requireRace(sender, args, 1);
|
||||||
|
if (race == null) return;
|
||||||
|
msg(sender, "--- " + race.getName() + " ---");
|
||||||
|
msg(sender, "State: " + race.getState());
|
||||||
|
msg(sender, "Players: " + race.getParticipants().size() + " (min " + race.getMinPlayers() + ")");
|
||||||
|
msg(sender, "Laps: " + race.getLaps() + " | Checkpoints: " + race.getCheckpoints().size());
|
||||||
|
msg(sender, "Ready: " + race.isReady());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendHelp(CommandSender sender) {
|
||||||
|
List<String> lines = List.of(
|
||||||
|
"&b&lBoatParty &7- ice boat racing",
|
||||||
|
"&7/boatparty create <name>",
|
||||||
|
"&7/boatparty delete <name>",
|
||||||
|
"&7/boatparty setlobby|setstart <name>",
|
||||||
|
"&7/boatparty addcheckpoint|removecheckpoint <name>",
|
||||||
|
"&7/boatparty setlaps|setminplayers|setcountdown|setradius <name> <value>",
|
||||||
|
"&7/boatparty join|leave <name>",
|
||||||
|
"&7/boatparty start|stop <name>",
|
||||||
|
"&7/boatparty list",
|
||||||
|
"&7/boatparty info <name>");
|
||||||
|
for (String line : lines) {
|
||||||
|
sender.sendMessage(Component.text(line.replace("&", "§")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Race requireRace(CommandSender sender, String[] args, int index) {
|
||||||
|
if (args.length <= index) {
|
||||||
|
msg(sender, "You must specify a race name.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Race race = raceManager.getRace(args[index]);
|
||||||
|
if (race == null) {
|
||||||
|
msg(sender, "No race named '" + args[index] + "' exists.");
|
||||||
|
}
|
||||||
|
return race;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Player requirePlayer(CommandSender sender) {
|
||||||
|
if (sender instanceof Player player) {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
msg(sender, "This command can only be used by a player.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean requirePermission(CommandSender sender, String permission) {
|
||||||
|
if (sender.hasPermission(permission)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
msg(sender, "You do not have permission to do that.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void broadcast(Race race, String message) {
|
||||||
|
for (var uuid : race.getParticipants()) {
|
||||||
|
Player player = plugin.getServer().getPlayer(uuid);
|
||||||
|
if (player != null) {
|
||||||
|
msg(player, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void msg(CommandSender sender, String text) {
|
||||||
|
sender.sendMessage(Component.text("[BoatParty] ", NamedTextColor.AQUA)
|
||||||
|
.append(Component.text(text, NamedTextColor.WHITE)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
String prefix = args[0].toLowerCase(Locale.ROOT);
|
||||||
|
return SUBCOMMANDS.stream().filter(s -> s.startsWith(prefix)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
if (args.length == 2 && !args[0].equalsIgnoreCase("create")) {
|
||||||
|
String prefix = args[1].toLowerCase(Locale.ROOT);
|
||||||
|
return raceManager.getRaces().keySet().stream()
|
||||||
|
.filter(s -> s.startsWith(prefix))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package us.tss3.boatparty.game;
|
||||||
|
|
||||||
|
public final class PlayerProgress {
|
||||||
|
|
||||||
|
private int lap = 0;
|
||||||
|
private int nextCheckpointIndex = 0;
|
||||||
|
private long startTimeMillis;
|
||||||
|
private long finishTimeMillis = -1;
|
||||||
|
private boolean finished = false;
|
||||||
|
|
||||||
|
public PlayerProgress(long startTimeMillis) {
|
||||||
|
this.startTimeMillis = startTimeMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLap() {
|
||||||
|
return lap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrementLap() {
|
||||||
|
this.lap++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNextCheckpointIndex() {
|
||||||
|
return nextCheckpointIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextCheckpointIndex(int nextCheckpointIndex) {
|
||||||
|
this.nextCheckpointIndex = nextCheckpointIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getStartTimeMillis() {
|
||||||
|
return startTimeMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTimeMillis(long startTimeMillis) {
|
||||||
|
this.startTimeMillis = startTimeMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFinishTimeMillis() {
|
||||||
|
return finishTimeMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFinishTimeMillis(long finishTimeMillis) {
|
||||||
|
this.finishTimeMillis = finishTimeMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFinished() {
|
||||||
|
return finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFinished(boolean finished) {
|
||||||
|
this.finished = finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long elapsedMillis() {
|
||||||
|
long end = finished ? finishTimeMillis : System.currentTimeMillis();
|
||||||
|
return Math.max(0, end - startTimeMillis);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,250 @@
|
|||||||
|
package us.tss3.boatparty.game;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.boss.BarColor;
|
||||||
|
import org.bukkit.boss.BarStyle;
|
||||||
|
import org.bukkit.boss.BossBar;
|
||||||
|
import org.bukkit.entity.Boat;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.title.Title;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public final class Race {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private Location lobby;
|
||||||
|
private Location startLocation;
|
||||||
|
private final List<Location> checkpoints = new ArrayList<>();
|
||||||
|
private double checkpointRadius = 3.0;
|
||||||
|
private int laps = 3;
|
||||||
|
private int minPlayers = 2;
|
||||||
|
private int countdownSeconds = 10;
|
||||||
|
|
||||||
|
private RaceState state = RaceState.WAITING;
|
||||||
|
private final List<UUID> participants = new ArrayList<>();
|
||||||
|
private final Map<UUID, PlayerProgress> progress = new LinkedHashMap<>();
|
||||||
|
private final List<UUID> finishOrder = new ArrayList<>();
|
||||||
|
|
||||||
|
private BukkitTask countdownTask;
|
||||||
|
private BossBar countdownBar;
|
||||||
|
|
||||||
|
public Race(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLobby() {
|
||||||
|
return lobby;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLobby(Location lobby) {
|
||||||
|
this.lobby = lobby;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getStartLocation() {
|
||||||
|
return startLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartLocation(Location startLocation) {
|
||||||
|
this.startLocation = startLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Location> getCheckpoints() {
|
||||||
|
return checkpoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCheckpoint(Location location) {
|
||||||
|
checkpoints.add(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeLastCheckpoint() {
|
||||||
|
if (checkpoints.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
checkpoints.remove(checkpoints.size() - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getCheckpointRadius() {
|
||||||
|
return checkpointRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckpointRadius(double checkpointRadius) {
|
||||||
|
this.checkpointRadius = checkpointRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLaps() {
|
||||||
|
return laps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLaps(int laps) {
|
||||||
|
this.laps = laps;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinPlayers() {
|
||||||
|
return minPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinPlayers(int minPlayers) {
|
||||||
|
this.minPlayers = minPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCountdownSeconds() {
|
||||||
|
return countdownSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCountdownSeconds(int countdownSeconds) {
|
||||||
|
this.countdownSeconds = countdownSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RaceState getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(RaceState state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getParticipants() {
|
||||||
|
return participants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<UUID, PlayerProgress> getProgress() {
|
||||||
|
return progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getFinishOrder() {
|
||||||
|
return finishOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReady() {
|
||||||
|
return lobby != null && startLocation != null && checkpoints.size() >= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addParticipant(UUID uuid) {
|
||||||
|
if (state != RaceState.WAITING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (participants.contains(uuid)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
participants.add(uuid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeParticipant(UUID uuid) {
|
||||||
|
progress.remove(uuid);
|
||||||
|
finishOrder.remove(uuid);
|
||||||
|
return participants.remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasParticipant(UUID uuid) {
|
||||||
|
return participants.contains(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startCountdown(us.tss3.boatparty.BoatPartyPlugin plugin) {
|
||||||
|
if (state != RaceState.WAITING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state = RaceState.COUNTDOWN;
|
||||||
|
countdownBar = Bukkit.createBossBar("BoatParty starting...", BarColor.YELLOW, BarStyle.SOLID);
|
||||||
|
for (UUID uuid : participants) {
|
||||||
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player != null) {
|
||||||
|
countdownBar.addPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
countdownTask = new BukkitRunnable() {
|
||||||
|
int remaining = countdownSeconds;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (remaining <= 0) {
|
||||||
|
cancel();
|
||||||
|
countdownBar.removeAll();
|
||||||
|
begin(plugin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
countdownBar.setProgress(Math.max(0.0, Math.min(1.0, (double) remaining / countdownSeconds)));
|
||||||
|
countdownBar.setTitle("BoatParty starting in " + remaining + "...");
|
||||||
|
for (UUID uuid : participants) {
|
||||||
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player != null) {
|
||||||
|
player.showTitle(Title.title(
|
||||||
|
Component.text(String.valueOf(remaining), NamedTextColor.AQUA),
|
||||||
|
Component.text("Get ready to race!", NamedTextColor.GRAY),
|
||||||
|
Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ZERO)));
|
||||||
|
player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_BLOCK_HAT, 1f, 1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
remaining--;
|
||||||
|
}
|
||||||
|
}.runTaskTimer(plugin, 0L, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelCountdown() {
|
||||||
|
if (countdownTask != null) {
|
||||||
|
countdownTask.cancel();
|
||||||
|
countdownTask = null;
|
||||||
|
}
|
||||||
|
if (countdownBar != null) {
|
||||||
|
countdownBar.removeAll();
|
||||||
|
countdownBar = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void begin(us.tss3.boatparty.BoatPartyPlugin plugin) {
|
||||||
|
state = RaceState.RUNNING;
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
int index = 0;
|
||||||
|
for (UUID uuid : participants) {
|
||||||
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
progress.put(uuid, new PlayerProgress(now));
|
||||||
|
|
||||||
|
Location spawn = startLocation.clone().add((index % 5) * 1.5 - 3, 0, (index / 5) * 2.0);
|
||||||
|
spawn.setYaw(startLocation.getYaw());
|
||||||
|
spawn.setPitch(startLocation.getPitch());
|
||||||
|
player.teleport(spawn);
|
||||||
|
|
||||||
|
Boat boat = spawn.getWorld().spawn(spawn, Boat.class);
|
||||||
|
boat.addPassenger(player);
|
||||||
|
|
||||||
|
player.showTitle(Title.title(
|
||||||
|
Component.text("GO!", NamedTextColor.GREEN),
|
||||||
|
Component.text("Lap 1 / " + laps, NamedTextColor.GRAY)));
|
||||||
|
player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_FIREWORK_ROCKET_LAUNCH, 1f, 1f);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
cancelCountdown();
|
||||||
|
state = RaceState.WAITING;
|
||||||
|
participants.clear();
|
||||||
|
progress.clear();
|
||||||
|
finishOrder.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getStandings() {
|
||||||
|
return finishOrder.stream().collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package us.tss3.boatparty.game;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import us.tss3.boatparty.BoatPartyPlugin;
|
||||||
|
import us.tss3.boatparty.util.LocationUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class RaceManager {
|
||||||
|
|
||||||
|
private final BoatPartyPlugin plugin;
|
||||||
|
private final File dataFile;
|
||||||
|
private final Map<String, Race> races = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
public RaceManager(BoatPartyPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.dataFile = new File(plugin.getDataFolder(), "races.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Race> getRaces() {
|
||||||
|
return races;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Race getRace(String name) {
|
||||||
|
return races.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Race createRace(String name) {
|
||||||
|
Race race = new Race(name);
|
||||||
|
races.put(name.toLowerCase(), race);
|
||||||
|
return race;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteRace(String name) {
|
||||||
|
Race race = races.remove(name.toLowerCase());
|
||||||
|
if (race != null) {
|
||||||
|
race.reset();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Race getRaceOf(Player player) {
|
||||||
|
for (Race race : races.values()) {
|
||||||
|
if (race.hasParticipant(player.getUniqueId())) {
|
||||||
|
return race;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopAllRaces() {
|
||||||
|
for (Race race : races.values()) {
|
||||||
|
race.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
if (!dataFile.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
YamlConfiguration yaml = YamlConfiguration.loadConfiguration(dataFile);
|
||||||
|
ConfigurationSection racesSection = yaml.getConfigurationSection("races");
|
||||||
|
if (racesSection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String key : racesSection.getKeys(false)) {
|
||||||
|
ConfigurationSection rs = racesSection.getConfigurationSection(key);
|
||||||
|
if (rs == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Race race = new Race(key);
|
||||||
|
race.setLobby(LocationUtil.read(rs, "lobby"));
|
||||||
|
race.setStartLocation(LocationUtil.read(rs, "start"));
|
||||||
|
race.setLaps(rs.getInt("laps", 3));
|
||||||
|
race.setMinPlayers(rs.getInt("min-players", 2));
|
||||||
|
race.setCountdownSeconds(rs.getInt("countdown-seconds", 10));
|
||||||
|
race.setCheckpointRadius(rs.getDouble("checkpoint-radius", 3.0));
|
||||||
|
|
||||||
|
ConfigurationSection cpSection = rs.getConfigurationSection("checkpoints");
|
||||||
|
if (cpSection != null) {
|
||||||
|
int i = 0;
|
||||||
|
while (cpSection.contains(String.valueOf(i))) {
|
||||||
|
Location loc = LocationUtil.read(cpSection, String.valueOf(i));
|
||||||
|
if (loc != null) {
|
||||||
|
race.addCheckpoint(loc);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
races.put(key, race);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
YamlConfiguration yaml = new YamlConfiguration();
|
||||||
|
ConfigurationSection racesSection = yaml.createSection("races");
|
||||||
|
for (Race race : races.values()) {
|
||||||
|
ConfigurationSection rs = racesSection.createSection(race.getName());
|
||||||
|
if (race.getLobby() != null) {
|
||||||
|
LocationUtil.write(rs, "lobby", race.getLobby());
|
||||||
|
}
|
||||||
|
if (race.getStartLocation() != null) {
|
||||||
|
LocationUtil.write(rs, "start", race.getStartLocation());
|
||||||
|
}
|
||||||
|
rs.set("laps", race.getLaps());
|
||||||
|
rs.set("min-players", race.getMinPlayers());
|
||||||
|
rs.set("countdown-seconds", race.getCountdownSeconds());
|
||||||
|
rs.set("checkpoint-radius", race.getCheckpointRadius());
|
||||||
|
|
||||||
|
ConfigurationSection cpSection = rs.createSection("checkpoints");
|
||||||
|
for (int i = 0; i < race.getCheckpoints().size(); i++) {
|
||||||
|
LocationUtil.write(cpSection, String.valueOf(i), race.getCheckpoints().get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (!plugin.getDataFolder().exists()) {
|
||||||
|
plugin.getDataFolder().mkdirs();
|
||||||
|
}
|
||||||
|
yaml.save(dataFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
plugin.getLogger().warning("Failed to save races.yml: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package us.tss3.boatparty.game;
|
||||||
|
|
||||||
|
public enum RaceState {
|
||||||
|
WAITING,
|
||||||
|
COUNTDOWN,
|
||||||
|
RUNNING,
|
||||||
|
FINISHED
|
||||||
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
package us.tss3.boatparty.listener;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.entity.Boat;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||||
|
import us.tss3.boatparty.BoatPartyPlugin;
|
||||||
|
import us.tss3.boatparty.game.PlayerProgress;
|
||||||
|
import us.tss3.boatparty.game.Race;
|
||||||
|
import us.tss3.boatparty.game.RaceManager;
|
||||||
|
import us.tss3.boatparty.game.RaceState;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public final class RaceListener implements Listener {
|
||||||
|
|
||||||
|
private final BoatPartyPlugin plugin;
|
||||||
|
private final RaceManager raceManager;
|
||||||
|
|
||||||
|
public RaceListener(BoatPartyPlugin plugin, RaceManager raceManager) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.raceManager = raceManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMove(PlayerMoveEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Race race = raceManager.getRaceOf(player);
|
||||||
|
if (race == null || race.getState() != RaceState.RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlayerProgress progress = race.getProgress().get(player.getUniqueId());
|
||||||
|
if (progress == null || progress.isFinished()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<org.bukkit.Location> checkpoints = race.getCheckpoints();
|
||||||
|
int nextIndex = progress.getNextCheckpointIndex();
|
||||||
|
if (nextIndex >= checkpoints.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
org.bukkit.Location checkpoint = checkpoints.get(nextIndex);
|
||||||
|
if (checkpoint.getWorld() == null || !checkpoint.getWorld().equals(player.getWorld())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
double radiusSq = race.getCheckpointRadius() * race.getCheckpointRadius();
|
||||||
|
if (player.getLocation().distanceSquared(checkpoint) > radiusSq) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int newIndex = nextIndex + 1;
|
||||||
|
if (newIndex >= checkpoints.size()) {
|
||||||
|
progress.incrementLap();
|
||||||
|
progress.setNextCheckpointIndex(0);
|
||||||
|
if (progress.getLap() >= race.getLaps()) {
|
||||||
|
finishPlayer(race, player, progress);
|
||||||
|
} else {
|
||||||
|
player.sendActionBar(Component.text(
|
||||||
|
"Lap " + (progress.getLap() + 1) + " / " + race.getLaps(),
|
||||||
|
NamedTextColor.AQUA));
|
||||||
|
player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 0.6f, 1.6f);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
progress.setNextCheckpointIndex(newIndex);
|
||||||
|
player.sendActionBar(Component.text(
|
||||||
|
"Checkpoint " + newIndex + " / " + checkpoints.size() + " | Lap "
|
||||||
|
+ (progress.getLap() + 1) + " / " + race.getLaps(),
|
||||||
|
NamedTextColor.GREEN));
|
||||||
|
player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_BLOCK_CHIME, 0.6f, 1.4f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finishPlayer(Race race, Player player, PlayerProgress progress) {
|
||||||
|
progress.setFinished(true);
|
||||||
|
progress.setFinishTimeMillis(System.currentTimeMillis());
|
||||||
|
race.getFinishOrder().add(player.getUniqueId());
|
||||||
|
|
||||||
|
int place = race.getFinishOrder().size();
|
||||||
|
double seconds = progress.elapsedMillis() / 1000.0;
|
||||||
|
|
||||||
|
for (UUID uuid : race.getParticipants()) {
|
||||||
|
Player p = plugin.getServer().getPlayer(uuid);
|
||||||
|
if (p != null) {
|
||||||
|
p.sendMessage(Component.text("[BoatParty] ", NamedTextColor.AQUA)
|
||||||
|
.append(Component.text(player.getName() + " finished in place #" + place
|
||||||
|
+ " (" + String.format("%.2f", seconds) + "s)", NamedTextColor.GOLD)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.showTitle(net.kyori.adventure.title.Title.title(
|
||||||
|
Component.text("Finished! #" + place, NamedTextColor.GOLD),
|
||||||
|
Component.text(String.format("%.2fs", seconds), NamedTextColor.GRAY)));
|
||||||
|
|
||||||
|
for (Boat boat : player.getWorld().getEntitiesByClass(Boat.class)) {
|
||||||
|
if (boat.getPassengers().contains(player)) {
|
||||||
|
boat.eject();
|
||||||
|
boat.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (race.getLobby() != null) {
|
||||||
|
player.teleport(race.getLobby());
|
||||||
|
}
|
||||||
|
|
||||||
|
long finishedCount = race.getParticipants().stream()
|
||||||
|
.map(u -> race.getProgress().get(u))
|
||||||
|
.filter(p -> p != null && p.isFinished())
|
||||||
|
.count();
|
||||||
|
if (finishedCount >= race.getParticipants().size()) {
|
||||||
|
endRace(race);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void endRace(Race race) {
|
||||||
|
List<UUID> standings = new ArrayList<>(race.getFinishOrder());
|
||||||
|
StringBuilder sb = new StringBuilder("Final standings: ");
|
||||||
|
for (int i = 0; i < standings.size(); i++) {
|
||||||
|
Player p = plugin.getServer().getPlayer(standings.get(i));
|
||||||
|
sb.append(i + 1).append(". ").append(p != null ? p.getName() : "?").append(" ");
|
||||||
|
}
|
||||||
|
for (UUID uuid : race.getParticipants()) {
|
||||||
|
Player p = plugin.getServer().getPlayer(uuid);
|
||||||
|
if (p != null) {
|
||||||
|
p.sendMessage(Component.text("[BoatParty] ", NamedTextColor.AQUA)
|
||||||
|
.append(Component.text(sb.toString(), NamedTextColor.GREEN)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plugin.getServer().getScheduler().runTaskLater(plugin, race::reset, 100L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onVehicleExit(VehicleExitEvent event) {
|
||||||
|
if (!(event.getExited() instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Race race = raceManager.getRaceOf(player);
|
||||||
|
if (race != null && race.getState() == RaceState.RUNNING) {
|
||||||
|
PlayerProgress progress = race.getProgress().get(player.getUniqueId());
|
||||||
|
if (progress != null && !progress.isFinished()) {
|
||||||
|
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
|
||||||
|
if (player.isOnline() && !player.isInsideVehicle()
|
||||||
|
&& race.getState() == RaceState.RUNNING && !progress.isFinished()) {
|
||||||
|
var boat = player.getWorld().spawn(player.getLocation(), Boat.class);
|
||||||
|
boat.addPassenger(player);
|
||||||
|
}
|
||||||
|
}, 40L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDamage(EntityDamageEvent event) {
|
||||||
|
if (!(event.getEntity() instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Race race = raceManager.getRaceOf(player);
|
||||||
|
if (race != null && (race.getState() == RaceState.RUNNING || race.getState() == RaceState.COUNTDOWN)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onQuit(PlayerQuitEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Race race = raceManager.getRaceOf(player);
|
||||||
|
if (race != null) {
|
||||||
|
race.removeParticipant(player.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package us.tss3.boatparty.util;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public final class LocationUtil {
|
||||||
|
|
||||||
|
private LocationUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void write(ConfigurationSection section, String path, Location location) {
|
||||||
|
if (location == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ConfigurationSection s = section.createSection(path);
|
||||||
|
s.set("world", location.getWorld().getName());
|
||||||
|
s.set("x", location.getX());
|
||||||
|
s.set("y", location.getY());
|
||||||
|
s.set("z", location.getZ());
|
||||||
|
s.set("yaw", location.getYaw());
|
||||||
|
s.set("pitch", location.getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location read(ConfigurationSection section, String path) {
|
||||||
|
ConfigurationSection s = section.getConfigurationSection(path);
|
||||||
|
if (s == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String worldName = s.getString("world");
|
||||||
|
if (worldName == null || Bukkit.getWorld(worldName) == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Location(
|
||||||
|
Bukkit.getWorld(worldName),
|
||||||
|
s.getDouble("x"),
|
||||||
|
s.getDouble("y"),
|
||||||
|
s.getDouble("z"),
|
||||||
|
(float) s.getDouble("yaw"),
|
||||||
|
(float) s.getDouble("pitch"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# BoatParty configuration
|
||||||
|
# Per-race settings (laps, min players, countdown, checkpoint radius) are stored
|
||||||
|
# in races.yml and set via /boatparty commands. This file is reserved for
|
||||||
|
# future global settings.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
name: BoatParty
|
||||||
|
version: '${version}'
|
||||||
|
main: us.tss3.boatparty.BoatPartyPlugin
|
||||||
|
api-version: '1.21'
|
||||||
|
author: skywalker3200
|
||||||
|
description: Ice-and-boat lap racing minigame for PaperMC.
|
||||||
|
website: https://git.tss3.us/skywalker3200/BoatParty
|
||||||
|
|
||||||
|
commands:
|
||||||
|
boatparty:
|
||||||
|
description: Manage and play BoatParty races.
|
||||||
|
usage: /boatparty <create|delete|setlobby|setstart|addcheckpoint|join|leave|start|stop|list|info>
|
||||||
|
aliases: [bp]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
boatparty.admin:
|
||||||
|
description: Allows creating and managing BoatParty races.
|
||||||
|
default: op
|
||||||
|
boatparty.play:
|
||||||
|
description: Allows joining BoatParty races.
|
||||||
|
default: true
|
||||||
Reference in New Issue
Block a user