0.1.0 base plugin working
This commit is contained in:
commit
11b8ea887a
19 changed files with 1704 additions and 0 deletions
118
.gitignore
vendored
Normal file
118
.gitignore
vendored
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
.gradle
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Ignore Gradle GUI config
|
||||||
|
gradle-app.setting
|
||||||
|
|
||||||
|
# Cache of project
|
||||||
|
.gradletasknamecache
|
||||||
|
|
||||||
|
**/build/
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
|
|
||||||
|
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||||
|
!gradle-wrapper.jar
|
141
build.gradle
Normal file
141
build.gradle
Normal file
|
@ -0,0 +1,141 @@
|
||||||
|
import groovy.json.JsonSlurper
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'io.papermc.paperweight.userdev' version '1.5.5'
|
||||||
|
id 'maven-publish'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'me.unurled.sacredrealms'
|
||||||
|
version = '0.1.0'
|
||||||
|
def minecraft_version = '1.20.1'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
name = "papermc-repo"
|
||||||
|
url = "https://repo.papermc.io/repository/maven-public/"
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name = "sonatype"
|
||||||
|
url = "https://oss.sonatype.org/content/groups/public/"
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name = "citizens"
|
||||||
|
url = "https://maven.citizensnpcs.co/repo"
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name = "SacredRealms"
|
||||||
|
url = "https://git.unurled.me/api/packages/SacredRealms/maven"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// PaperMc
|
||||||
|
compileOnly "io.papermc.paper:paper-api:${minecraft_version}-R0.1-SNAPSHOT"
|
||||||
|
|
||||||
|
// NMS
|
||||||
|
paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:${minecraft_version}-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
|
// Citizens
|
||||||
|
compileOnly ("net.citizensnpcs:citizens-main:2.0.32-SNAPSHOT") {
|
||||||
|
exclude group: '*', module: '*'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def targetJavaVersion = 17
|
||||||
|
java {
|
||||||
|
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||||
|
sourceCompatibility = javaVersion
|
||||||
|
targetCompatibility = javaVersion
|
||||||
|
if (JavaVersion.current() < javaVersion) {
|
||||||
|
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
|
||||||
|
options.release = targetJavaVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
def props = [version: version]
|
||||||
|
inputs.properties props
|
||||||
|
filteringCharset 'UTF-8'
|
||||||
|
filesMatching('plugin.yml') {
|
||||||
|
expand props
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
maven(MavenPublication) {
|
||||||
|
artifactId = project.name
|
||||||
|
from components.java
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = 'SacredRealms'
|
||||||
|
url = uri('https://git.unurled.me/api/packages/SacredRealms/maven')
|
||||||
|
|
||||||
|
credentials(HttpHeaderCredentials) {
|
||||||
|
name = "Authorization"
|
||||||
|
value = "token ${System.getenv('TOKEN')}"
|
||||||
|
}
|
||||||
|
|
||||||
|
authentication {
|
||||||
|
header(HttpHeaderAuthentication)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def serverDir = file("${project.buildDir}/server")
|
||||||
|
def serverJar = file("${serverDir}/paper-${minecraft_version}.jar")
|
||||||
|
def pluginsDir = file("${serverDir}/plugins")
|
||||||
|
def pluginJar = file("${pluginsDir}/${archivesBaseName}.jar")
|
||||||
|
def buildJar = file("${project.buildDir}/libs/${archivesBaseName}-${version}-dev.jar")
|
||||||
|
def semver = minecraft_version.tokenize('.')
|
||||||
|
|
||||||
|
tasks.register('prepare') {
|
||||||
|
group 'server'
|
||||||
|
onlyIf {
|
||||||
|
!serverJar.exists()
|
||||||
|
}
|
||||||
|
doFirst {
|
||||||
|
serverDir.mkdirs()
|
||||||
|
def baseUrl = 'https://papermc.io/api/v2/projects/paper'
|
||||||
|
def builds = new URL("${baseUrl}/version_group/${semver[0]}.${semver[1]}/builds")
|
||||||
|
def latest = new JsonSlurper()
|
||||||
|
.parseText(builds.text)
|
||||||
|
.builds
|
||||||
|
.reverse()
|
||||||
|
.find { it.version == minecraft_version }
|
||||||
|
|
||||||
|
def fileName = latest.downloads.application.name
|
||||||
|
def jarUrl = new URL("${baseUrl}/versions/${latest.version}/builds/${latest.build}/downloads/${fileName}")
|
||||||
|
serverJar << jarUrl.openStream()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register('start', JavaExec) {
|
||||||
|
group 'server'
|
||||||
|
dependsOn 'prepare', 'build'
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
pluginsDir.mkdirs()
|
||||||
|
pluginJar.delete()
|
||||||
|
Files.createSymbolicLink(pluginJar.toPath(), buildJar.toPath())
|
||||||
|
}
|
||||||
|
|
||||||
|
classpath = files(serverJar)
|
||||||
|
workingDir = serverDir
|
||||||
|
main = 'io.papermc.paperclip.Main'
|
||||||
|
jvmArgs = [ '-Ddisable.watchdog=true', '-Dcom.mojang.eula.agree=true' ]
|
||||||
|
args = [ '--nogui' ]
|
||||||
|
standardInput = System.in
|
||||||
|
}
|
||||||
|
|
0
gradle.properties
Normal file
0
gradle.properties
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
245
gradlew
vendored
Executable file
245
gradlew
vendored
Executable file
|
@ -0,0 +1,245 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# 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, and $GRADLE_OPTS can contain fragments of
|
||||||
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
# double quotes to make sure that they get re-expanded; and
|
||||||
|
# * put everything else in single quotes, so that it's not re-expanded.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
92
gradlew.bat
vendored
Normal file
92
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
1
settings.gradle
Normal file
1
settings.gradle
Normal file
|
@ -0,0 +1 @@
|
||||||
|
rootProject.name = 'Cutscenes'
|
226
src/main/java/me/unurled/sacredrealms/cutscenes/Cutscene.java
Normal file
226
src/main/java/me/unurled/sacredrealms/cutscenes/Cutscene.java
Normal file
|
@ -0,0 +1,226 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cutscene class
|
||||||
|
* Start by creating an instance of it.
|
||||||
|
* You can play it then using {@link Cutscene#play(org.bukkit.entity.Player)}
|
||||||
|
*/
|
||||||
|
public class Cutscene {
|
||||||
|
|
||||||
|
private static final NamespacedKey PLAYING = new NamespacedKey(Cutscenes.getInstance(), "cutscene_playing");
|
||||||
|
|
||||||
|
private final String ID;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private final ArrayList<Marker> markers;
|
||||||
|
private ArrayList<Integer> markerIds;
|
||||||
|
private Location start;
|
||||||
|
private Location end;
|
||||||
|
private HashMap<Player, BukkitTask> tasks;
|
||||||
|
|
||||||
|
public Cutscene(String ID, String name) {
|
||||||
|
this.ID = ID.toUpperCase();
|
||||||
|
this.name = name;
|
||||||
|
this.markers = new ArrayList<>();
|
||||||
|
this.markerIds = new ArrayList<>();
|
||||||
|
this.tasks = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cutscene(String ID, String name, ArrayList<Marker> markers) {
|
||||||
|
this.ID = ID.toUpperCase();
|
||||||
|
this.name = name;
|
||||||
|
this.markers = markers;
|
||||||
|
markerIds = new ArrayList<>();
|
||||||
|
for (Marker marker : markers) {
|
||||||
|
markerIds.add(marker.getID());
|
||||||
|
}
|
||||||
|
if (markers.size() == 0)
|
||||||
|
return;
|
||||||
|
if (markers.get(0).getFrames().size() == 0)
|
||||||
|
return;
|
||||||
|
start = markers.get(0).getFrames().get(0).getLocation();
|
||||||
|
end = markers.get(markers.size() - 1).getFrames().get(markers.get(markers.size() - 1).getFrames().size() - 1).getLocation();
|
||||||
|
this.tasks = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMarkers() {
|
||||||
|
for (Integer i : markerIds) {
|
||||||
|
markers.add(Marker.getMarker(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMarker(Marker marker) {
|
||||||
|
this.markers.add(marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStart(Location start) {
|
||||||
|
this.start = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnd(Location end) {
|
||||||
|
this.end = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getID() {
|
||||||
|
return this.ID.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Marker> getMarkers() {
|
||||||
|
return this.markers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getStart() {
|
||||||
|
return this.start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getEnd() {
|
||||||
|
return this.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMarkerId(Integer id) {
|
||||||
|
this.markerIds.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long time() {
|
||||||
|
long time = 0;
|
||||||
|
for (Marker marker : this.markers) {
|
||||||
|
if (marker.getOverAllTime() != null)
|
||||||
|
time += marker.getOverAllTime();
|
||||||
|
}
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void play(Player p) {
|
||||||
|
PersistentDataContainer pdc = p.getPersistentDataContainer();
|
||||||
|
if (pdc.has(PLAYING)) {
|
||||||
|
if (pdc.get(PLAYING, PersistentDataType.STRING) == null) {
|
||||||
|
pdc.remove(PLAYING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Cutscenes.getInstance().getCutscenesId().contains(pdc.get(PLAYING, PersistentDataType.STRING))) {
|
||||||
|
pdc.remove(PLAYING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Objects.equals(pdc.get(PLAYING, PersistentDataType.STRING), this.ID.toUpperCase())) {
|
||||||
|
p.sendMessage(
|
||||||
|
Component.text("You are already playing this cutscene!")
|
||||||
|
.appendNewline()
|
||||||
|
.append(Component.text("Type /cutscene stop to stop playing it."))
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
p.sendMessage(
|
||||||
|
Component.text("You are already playing a cutscene!")
|
||||||
|
.appendNewline()
|
||||||
|
.append(Component.text("Type /cutscene stop to stop playing it."))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pdc.set(PLAYING, PersistentDataType.STRING, this.ID.toUpperCase());
|
||||||
|
Cutscenes.getInstance().setOriginalLocation(p, p.getLocation());
|
||||||
|
Cutscenes.getInstance().addCurrentPlayingCutscene(this, p);
|
||||||
|
BukkitTask task = RScheduler.scheduleAsync(Cutscenes.getInstance(), () -> {
|
||||||
|
int finalI = 0;
|
||||||
|
for (int j = 0 ; j < markers.size() ; j++) {
|
||||||
|
Marker marker = markers.get(j);
|
||||||
|
for (int i = 0 ; i < marker.getFrames().size() ; i++) {
|
||||||
|
int finalI1 = i;
|
||||||
|
RScheduler.schedule(Cutscenes.getInstance(), () -> {
|
||||||
|
p.teleport(marker.getFrames().get(finalI1).getLocation());
|
||||||
|
marker.getFrames().get(finalI1).play();
|
||||||
|
}, Util.miliToTicks(marker.getTimeBetweenFrames()) * finalI);
|
||||||
|
finalI++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
RScheduler.scheduleAsync(Cutscenes.getInstance(), () -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(time());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
RScheduler.schedule(Cutscenes.getInstance(), () -> stop(p));
|
||||||
|
});
|
||||||
|
tasks.put(p, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop(Player p) {
|
||||||
|
PersistentDataContainer pdc = p.getPersistentDataContainer();
|
||||||
|
if (pdc.has(PLAYING)) {
|
||||||
|
if (pdc.get(PLAYING, PersistentDataType.STRING) == null) {
|
||||||
|
pdc.remove(PLAYING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Objects.equals(pdc.get(PLAYING, PersistentDataType.STRING), this.ID.toUpperCase())) {
|
||||||
|
Cutscenes.getInstance().removeCurrentPlayingCutscene(Cutscenes.getInstance()
|
||||||
|
.getCutscene(pdc.get(PLAYING, PersistentDataType.STRING)), p);
|
||||||
|
pdc.remove(PLAYING);
|
||||||
|
if (tasks.get(p) != null)
|
||||||
|
tasks.get(p).cancel();
|
||||||
|
// TODO: replace player to it's original location
|
||||||
|
Location loc = Cutscenes.getInstance().getOriginalLocation(p);
|
||||||
|
if (loc != null) {
|
||||||
|
p.teleport(loc);
|
||||||
|
}
|
||||||
|
p.sendMessage(
|
||||||
|
Component.text("You stopped playing the cutscene!")
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
p.sendMessage(
|
||||||
|
Component.text("You are not playing this cutscene!")
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Cutscenes.getInstance().getCurrentPlayingCutscenes().containsValue(p)) {
|
||||||
|
p.sendMessage(
|
||||||
|
Component.text("You are not playing a cutscene!")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculateMarkers() {
|
||||||
|
if (markers.size() == 0)
|
||||||
|
return;
|
||||||
|
for (int i = 0 ; i < markers.size() ; i++) {
|
||||||
|
if (i < markers.size() - 1) {
|
||||||
|
markers.get(i).calculateFrames(markers.get(i+1));
|
||||||
|
} else {
|
||||||
|
ArrayList<Frame> frames = new ArrayList<>();
|
||||||
|
frames.add(new Frame(markers.get(i).getStart()));
|
||||||
|
markers.get(i).setFrames(frames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Cutscene{" +
|
||||||
|
"ID='" + ID + '\'' +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
", markers=" + markers +
|
||||||
|
", markerIds=" + markerIds +
|
||||||
|
", start=" + start +
|
||||||
|
", end=" + end +
|
||||||
|
", tasks=" + tasks +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,141 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class CutsceneCommand implements TabExecutor {
|
||||||
|
|
||||||
|
List<String> complete = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||||
|
@NotNull String label, @NotNull String[] args) {
|
||||||
|
if (args.length == 1) {
|
||||||
|
// stop, list
|
||||||
|
if (args[0].equalsIgnoreCase("stop")) {
|
||||||
|
// stop cutscene
|
||||||
|
if (sender.hasPermission("cutscenes.use")) {
|
||||||
|
// stop current cutscene current player
|
||||||
|
if (sender instanceof Player p) {
|
||||||
|
if (Cutscenes.getInstance().getCutscene(p) != null) {
|
||||||
|
Cutscenes.getInstance().stopCutscene(p);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (sender.hasPermission("cutscenes.admin")) {
|
||||||
|
if (args[0].equalsIgnoreCase("list")) {
|
||||||
|
// list all cutscenes
|
||||||
|
sender.sendMessage(Component.text("Cutscenes: ").append(Component.text(Cutscenes.getInstance().getCutscenesId().toString())));
|
||||||
|
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||||
|
Cutscenes.getInstance().stopCutscenesForAllPlayers();
|
||||||
|
Cutscenes.getInstance().load();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (args.length == 2) {
|
||||||
|
// play, stop, create, remove
|
||||||
|
if (sender.hasPermission("cutscenes.admin")) {
|
||||||
|
if (args[0].equalsIgnoreCase("play")) {
|
||||||
|
if (sender instanceof Player p) {
|
||||||
|
Cutscenes.getInstance().playCutscene(
|
||||||
|
Cutscenes.getInstance()
|
||||||
|
.getCutscene(args[1].toUpperCase()),
|
||||||
|
p
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||||
|
if (Bukkit.getOnlinePlayers().contains(Bukkit.getPlayer(args[1]))) {
|
||||||
|
Cutscenes.getInstance().stopCutscene(Bukkit.getPlayer(args[1]));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (args.length == 3) {
|
||||||
|
if (sender.hasPermission("cutscenes.admin")) {
|
||||||
|
if (args[0].equalsIgnoreCase("play")) {
|
||||||
|
if (Bukkit.getOnlinePlayers().contains(Bukkit.getPlayer(args[2]))) {
|
||||||
|
Cutscenes.getInstance().playCutscene(
|
||||||
|
Cutscenes.getInstance()
|
||||||
|
.getCutscene(args[1].toUpperCase()),
|
||||||
|
Bukkit.getPlayer(args[2])
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// usage/help message
|
||||||
|
if (sender.hasPermission("cutscenes.admin")) {
|
||||||
|
sender.sendMessage(Component
|
||||||
|
.text("Usage: /cutscenes <play|stop|reload|list> <cutscene_id|player (only play and stop)> <player (only possible if play with an id before)>")
|
||||||
|
.color(TextColor.color(255, 251, 0)));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(Component
|
||||||
|
.text("Usage: /cutscenes stop")
|
||||||
|
.color(TextColor.color(255, 251, 0)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender,
|
||||||
|
@NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
complete.clear();
|
||||||
|
complete.add("stop");
|
||||||
|
if (sender.hasPermission("cutscenes.admin")) {
|
||||||
|
complete.add("play");
|
||||||
|
complete.add("list");
|
||||||
|
complete.add("reload");
|
||||||
|
}
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
if (args.length == 1) {
|
||||||
|
for (String s : complete) {
|
||||||
|
if (s.toLowerCase().startsWith(args[0].toLowerCase())) {
|
||||||
|
result.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else if (args.length == 2) {
|
||||||
|
if (sender.hasPermission("cutscenes.admin")) {
|
||||||
|
if (args[0].equalsIgnoreCase("stop")) {
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (p.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
|
||||||
|
result.add(p.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (args[0].equalsIgnoreCase("play")) {
|
||||||
|
for (String s : Cutscenes.getInstance().getCutscenesId()) {
|
||||||
|
if (s.toLowerCase().startsWith(args[1].toLowerCase())) {
|
||||||
|
result.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else if (args.length == 3) {
|
||||||
|
if (sender.hasPermission("cutscenes.admin")) {
|
||||||
|
if (args[0].equalsIgnoreCase("play")) {
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (p.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
|
||||||
|
result.add(p.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
220
src/main/java/me/unurled/sacredrealms/cutscenes/Cutscenes.java
Normal file
220
src/main/java/me/unurled/sacredrealms/cutscenes/Cutscenes.java
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Objects;
|
||||||
|
import me.unurled.sacredrealms.cutscenes.parse.CutsceneParser;
|
||||||
|
import me.unurled.sacredrealms.cutscenes.parse.MarkerParser;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public final class Cutscenes extends JavaPlugin {
|
||||||
|
|
||||||
|
private static Cutscenes instance;
|
||||||
|
|
||||||
|
private ArrayList<Cutscene> cutscenes;
|
||||||
|
private HashMap<Cutscene, Player> currentPlayingCutscenes;
|
||||||
|
private HashMap<Player, Location> originalLocation;
|
||||||
|
private ArrayList<String> cutscenesId;
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger("Cutscenes");
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
// Plugin startup logic
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
CutsceneCommand command = new CutsceneCommand();
|
||||||
|
getCommand("cutscenes").setExecutor(command);
|
||||||
|
getCommand("cutscenes").setTabCompleter(command);
|
||||||
|
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
cutscenes = new ArrayList<>();
|
||||||
|
currentPlayingCutscenes = new HashMap<>();
|
||||||
|
originalLocation = new HashMap<>();
|
||||||
|
cutscenesId = new ArrayList<>();
|
||||||
|
|
||||||
|
// TODO: detect all cutscenes in the cutscenes folder and load them.
|
||||||
|
detectAndParseAllCutscenes();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
|
}
|
||||||
|
|
||||||
|
void detectAndParseAllCutscenes() {
|
||||||
|
new File("plugins/SacredRealms").mkdir();
|
||||||
|
File folder = new File("plugins/SacredRealms", "cutscenes");
|
||||||
|
if (!folder.exists()) {
|
||||||
|
folder.mkdir();
|
||||||
|
} else {
|
||||||
|
if (folder.isDirectory()) {
|
||||||
|
Marker.setMarkers(new ArrayList<>());
|
||||||
|
File[] files = folder.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.isDirectory()) { // cutscene id folder
|
||||||
|
File[] files1 = file.listFiles();
|
||||||
|
if (files1 != null) {
|
||||||
|
for (File file1 : files1) {
|
||||||
|
if (file1.getName().equals("cutscene.yml")) {
|
||||||
|
try {
|
||||||
|
FileConfiguration config = YamlConfiguration.loadConfiguration(file1);
|
||||||
|
Cutscene cutscene = CutsceneParser.parse(config);
|
||||||
|
if (cutscene == null)
|
||||||
|
continue;
|
||||||
|
addCutscene(cutscene);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("Failed to parse cutscene " + file.getName() + "!");
|
||||||
|
}
|
||||||
|
} else if (file1.isDirectory()) {
|
||||||
|
File[] files2 = file1.listFiles();
|
||||||
|
if (files2 != null) {
|
||||||
|
for (File file2 : files2) {
|
||||||
|
if (file2.getName().equals("marker.yml")) {
|
||||||
|
try {
|
||||||
|
FileConfiguration config = YamlConfiguration.loadConfiguration(file2);
|
||||||
|
Marker marker = MarkerParser.parse(config);
|
||||||
|
if (marker == null)
|
||||||
|
continue;
|
||||||
|
Marker.getMarkers().add(marker);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("Failed to parse marker " + file.getName() + "!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.error("The cutscenes folder is not a directory!");
|
||||||
|
try {
|
||||||
|
folder.delete();
|
||||||
|
folder.mkdir();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("Failed to delete the cutscenes folder!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Cutscene cutscene : cutscenes) {
|
||||||
|
cutscene.setMarkers();
|
||||||
|
cutscene.calculateMarkers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Cutscenes getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Cutscene> getCutscenes() {
|
||||||
|
return cutscenes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<Cutscene, Player> getCurrentPlayingCutscenes() {
|
||||||
|
return currentPlayingCutscenes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCutscene(Cutscene cutscene) {
|
||||||
|
LOGGER.info("Adding cutscene " + cutscene.getID().toUpperCase() + " to the list of cutscenes!");
|
||||||
|
cutscenes.add(cutscene);
|
||||||
|
cutscenesId.add(cutscene.getID().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCutscene(Cutscene cutscene) {
|
||||||
|
cutscenes.remove(cutscene);
|
||||||
|
cutscenesId.remove(cutscene.getID().toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCurrentPlayingCutscene(Cutscene cutscene, Player p) {
|
||||||
|
currentPlayingCutscenes.put(cutscene, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCurrentPlayingCutscene(Cutscene cutscene, Player p) {
|
||||||
|
currentPlayingCutscenes.remove(cutscene, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getCutscenesId() {
|
||||||
|
return cutscenesId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopCutscene(Player p) {
|
||||||
|
for (Cutscene cutscene : currentPlayingCutscenes.keySet()) {
|
||||||
|
if (currentPlayingCutscenes.get(cutscene).equals(p)) {
|
||||||
|
currentPlayingCutscenes.remove(cutscene, p);
|
||||||
|
cutscene.stop(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopCutscenesForAllPlayers() {
|
||||||
|
for (Cutscene cutscene : currentPlayingCutscenes.keySet()) {
|
||||||
|
cutscene.stop(currentPlayingCutscenes.get(cutscene));
|
||||||
|
currentPlayingCutscenes.remove(cutscene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playCutscene(Cutscene cutscene, Player p) {
|
||||||
|
if (cutscene == null) {
|
||||||
|
p.sendMessage(
|
||||||
|
Component.text("There was an error with the cutscene!", NamedTextColor.RED));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cutscenes.contains(cutscene)) {
|
||||||
|
if (!currentPlayingCutscenes.containsValue(p)) {
|
||||||
|
currentPlayingCutscenes.put(cutscene, p);
|
||||||
|
cutscene.play(p);
|
||||||
|
LOGGER.info("Playing cutscene " + cutscene.getID() + " to player " + p.getName() + "!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cutscene getCutscene(Player p){
|
||||||
|
for (Entry<Cutscene, Player> entry : currentPlayingCutscenes.entrySet()) {
|
||||||
|
if (entry.getValue().equals(p))
|
||||||
|
return entry.getKey();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Cutscene getCutscene(String id){
|
||||||
|
if (!cutscenesId.contains(id.toUpperCase())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (Cutscene cutscene : cutscenes) {
|
||||||
|
if (cutscene.getID().equalsIgnoreCase(id.toUpperCase()))
|
||||||
|
return cutscene;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalLocation(Player p, Location loc){
|
||||||
|
originalLocation.put(p, loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getOriginalLocation(Player p){
|
||||||
|
return originalLocation.get(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Logger getLOGGER() {
|
||||||
|
return LOGGER;
|
||||||
|
}
|
||||||
|
}
|
41
src/main/java/me/unurled/sacredrealms/cutscenes/Frame.java
Normal file
41
src/main/java/me/unurled/sacredrealms/cutscenes/Frame.java
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class Frame {
|
||||||
|
private final Location location;
|
||||||
|
private static int idCounter = 0;
|
||||||
|
private final int ID;
|
||||||
|
|
||||||
|
public Frame(Location location) {
|
||||||
|
this.location = location;
|
||||||
|
ID = idCounter;
|
||||||
|
idCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Frame(Location location, int ID) {
|
||||||
|
this.location = location;
|
||||||
|
this.ID = ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play the frame
|
||||||
|
* aka move stuff around :shrug:
|
||||||
|
*/
|
||||||
|
public void play() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Frame{" +
|
||||||
|
"location=" + location +
|
||||||
|
", ID=" + ID +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
111
src/main/java/me/unurled/sacredrealms/cutscenes/Marker.java
Normal file
111
src/main/java/me/unurled/sacredrealms/cutscenes/Marker.java
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class Marker {
|
||||||
|
|
||||||
|
private static int idCounter = 0;
|
||||||
|
private static ArrayList<Marker> markers = new ArrayList<>();
|
||||||
|
private final int ID;
|
||||||
|
private ArrayList<Frame> frames;
|
||||||
|
private Long timeBetweenFrames;
|
||||||
|
private Long overAllTime;
|
||||||
|
private Location start;
|
||||||
|
|
||||||
|
|
||||||
|
public Marker(Integer id) {
|
||||||
|
frames = new ArrayList<>();
|
||||||
|
timeBetweenFrames = 0L;
|
||||||
|
overAllTime = 0L;
|
||||||
|
if (id == null) {
|
||||||
|
ID = idCounter;
|
||||||
|
idCounter++;
|
||||||
|
} else {
|
||||||
|
ID = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Marker(ArrayList<Frame> frames, long timeBetweenFrames, Location start) {
|
||||||
|
this.frames = frames;
|
||||||
|
this.timeBetweenFrames = timeBetweenFrames;
|
||||||
|
this.overAllTime = timeBetweenFrames * frames.size();
|
||||||
|
this.start = start;
|
||||||
|
ID = idCounter;
|
||||||
|
idCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Frame> getFrames() {
|
||||||
|
return frames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTimeBetweenFrames() {
|
||||||
|
return timeBetweenFrames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getOverAllTime() {
|
||||||
|
return overAllTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFrames(ArrayList<Frame> frames) {
|
||||||
|
this.frames = frames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeBetweenFrames(Long timeBetweenFrames) {
|
||||||
|
this.timeBetweenFrames = timeBetweenFrames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOverAllTime(Long overAllTime) {
|
||||||
|
this.overAllTime = overAllTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void calculateFrames(Marker endMarker) {
|
||||||
|
frames = MarkerInterpolator.interpolateFrames(this, endMarker, timeBetweenFrames);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStart(Location start) {
|
||||||
|
this.start = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getID() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFrame(Frame frame) {
|
||||||
|
frames.add(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeFrame(Frame frame) {
|
||||||
|
frames.remove(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeFrame(int index) {
|
||||||
|
frames.remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Marker> getMarkers() {
|
||||||
|
return markers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Marker getMarker(int ID) {
|
||||||
|
for (Marker marker : markers) {
|
||||||
|
if (marker.getID() == ID) {
|
||||||
|
return marker;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Marker{" + "ID=" + ID + ", frames=" + frames + ", timeBetweenFrames=" + timeBetweenFrames + ", overAllTime=" + overAllTime + ", start=" + start + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMarkers(ArrayList<Marker> markers) {
|
||||||
|
Marker.markers = markers;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
public class MarkerInterpolator {
|
||||||
|
public static ArrayList<Frame> interpolateFrames(Marker startMarker, Marker endMarker, long stepMillis) {
|
||||||
|
long duration = startMarker.getOverAllTime();
|
||||||
|
|
||||||
|
int numFrames = (int) (duration / stepMillis);
|
||||||
|
|
||||||
|
double xDiff = (endMarker.getStart().getX() - startMarker.getStart().getX()) / numFrames;
|
||||||
|
double yDiff = (endMarker.getStart().getY() - startMarker.getStart().getY()) / numFrames;
|
||||||
|
double zDiff = (endMarker.getStart().getZ() - startMarker.getStart().getZ()) / numFrames;
|
||||||
|
double yawDiff = (endMarker.getStart().getYaw() - startMarker.getStart().getYaw()) / numFrames;
|
||||||
|
double pitchDiff = (endMarker.getStart().getPitch() - startMarker.getStart().getPitch()) / numFrames;
|
||||||
|
|
||||||
|
ArrayList<Frame> frames = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < numFrames; i++) {
|
||||||
|
|
||||||
|
double x = startMarker.getStart().getX() + xDiff * i;
|
||||||
|
double y = startMarker.getStart().getY() + yDiff * i;
|
||||||
|
double z = startMarker.getStart().getZ() + zDiff * i;
|
||||||
|
double yaw = startMarker.getStart().getYaw() + yawDiff * i;
|
||||||
|
double pitch = startMarker.getStart().getPitch() + pitchDiff * i;
|
||||||
|
|
||||||
|
Frame frame = new Frame(
|
||||||
|
new Location(startMarker.getStart().getWorld(), x, y, z, (float) yaw, (float) pitch)
|
||||||
|
);
|
||||||
|
|
||||||
|
frames.add(frame);
|
||||||
|
}
|
||||||
|
System.out.println(numFrames + " " +frames.size());
|
||||||
|
return frames;
|
||||||
|
}
|
||||||
|
}
|
108
src/main/java/me/unurled/sacredrealms/cutscenes/RScheduler.java
Normal file
108
src/main/java/me/unurled/sacredrealms/cutscenes/RScheduler.java
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author edasaki
|
||||||
|
*/
|
||||||
|
public class RScheduler {
|
||||||
|
/**
|
||||||
|
* Schedule a repeating task. Halts on plugin disable.
|
||||||
|
* @param plugin - plugin to schedule for
|
||||||
|
* @param r - task to run
|
||||||
|
* @param repeatEveryTicks - ticks between each run
|
||||||
|
*/
|
||||||
|
public static void scheduleRepeating(final JavaPlugin plugin, final Runnable r, final int repeatEveryTicks) {
|
||||||
|
Runnable r2 = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (plugin == null || !plugin.isEnabled())
|
||||||
|
return;
|
||||||
|
r.run();
|
||||||
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, this, repeatEveryTicks);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a repeating task. Halts when halter is stopped.
|
||||||
|
* @param plugin - plugin to schedule for
|
||||||
|
* @param r - task to run
|
||||||
|
* @param repeatEvery - ticks between each run
|
||||||
|
* @param halter - halter to stop the task
|
||||||
|
*/
|
||||||
|
public static void scheduleRepeating(final JavaPlugin plugin, final Runnable r, final int repeatEvery, final Halter halter) {
|
||||||
|
Runnable r2 = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (plugin == null || !plugin.isEnabled() || halter.halt)
|
||||||
|
return;
|
||||||
|
r.run();
|
||||||
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, this, repeatEvery);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to stop repeating tasks.
|
||||||
|
*/
|
||||||
|
public static class Halter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this to true to stop the task.
|
||||||
|
*/
|
||||||
|
public boolean halt = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a single task.
|
||||||
|
* @param plugin - plugin to schedule for
|
||||||
|
* @param r - task to run
|
||||||
|
* @param runInTicks - ticks to wait before running
|
||||||
|
*/
|
||||||
|
public static BukkitTask schedule(JavaPlugin plugin, Runnable r, long runInTicks) {
|
||||||
|
return Bukkit.getScheduler().runTaskLater(plugin, r, runInTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule a single task to run immediately.
|
||||||
|
* @param plugin - plugin to schedule for
|
||||||
|
* @param r - task to run
|
||||||
|
*/
|
||||||
|
public static void schedule(JavaPlugin plugin, Runnable r) {
|
||||||
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule an async task to run immediately.
|
||||||
|
* @param plugin - plugin to schedule for
|
||||||
|
* @param r - task to run
|
||||||
|
*/
|
||||||
|
public static BukkitTask scheduleAsync(JavaPlugin plugin, Runnable r) {
|
||||||
|
return plugin.getServer().getScheduler().runTaskAsynchronously(plugin, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule an async task.
|
||||||
|
*
|
||||||
|
* @param plugin - plugin to schedule for
|
||||||
|
* @param r - task to run
|
||||||
|
* @param runInTicks - ticks to wait before running
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static BukkitTask scheduleAsync(JavaPlugin plugin, Runnable r, int runInTicks) {
|
||||||
|
return plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, r, runInTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule an async task.
|
||||||
|
* @param plugin - plugin to schedule for
|
||||||
|
* @param r - task to run
|
||||||
|
* @param runInTicks - ticks to wait before running
|
||||||
|
*/
|
||||||
|
public static void scheduleAsync(JavaPlugin plugin, Runnable r, long runInTicks) {
|
||||||
|
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, r, runInTicks);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
public static long miliToTicks(long mili) {
|
||||||
|
return mili / 50;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,92 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes.parse;
|
||||||
|
|
||||||
|
import me.unurled.sacredrealms.cutscenes.Cutscene;
|
||||||
|
import me.unurled.sacredrealms.cutscenes.Cutscenes;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File structure organisation :
|
||||||
|
* ```plugins/SacredRealms/cutscenes/<cutscene_id>/cutscene.yml```
|
||||||
|
* ```plugins/SacredRealms/cutscenes/<cutscene_id>/<marker_id>/marker.yml```
|
||||||
|
|
||||||
|
* ```plugins/SacredRealms/cutscenes/<cutscene_id>/cutscene.yml``` contains the cutscene's name, ID, start and end location, and the list of markers IDs;
|
||||||
|
* ```
|
||||||
|
* name: "Cutscene name"
|
||||||
|
* id: "CUTSCENE_ID" // must be unique and uppercase
|
||||||
|
* start: "world,x,y,z,yaw,pitch"
|
||||||
|
* end: "world,x,y,z,yaw,pitch"
|
||||||
|
* markers:
|
||||||
|
* - "marker_id"
|
||||||
|
* - "marker_id"
|
||||||
|
* ...
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
public class CutsceneParser {
|
||||||
|
|
||||||
|
public static Cutscene parse(FileConfiguration file) {
|
||||||
|
String name = null;
|
||||||
|
String id = null;
|
||||||
|
Cutscene cutscene = null;
|
||||||
|
if (file.contains("name")) { // name: "Cutscene name"
|
||||||
|
name = file.getString("name");
|
||||||
|
}
|
||||||
|
if (file.contains("id")) { // id: "CUTSCENE_ID"
|
||||||
|
id = file.getString("id").toUpperCase();
|
||||||
|
}
|
||||||
|
if (name != null && id != null && name.length() != 0 && id.length() != 0) {
|
||||||
|
cutscene = new Cutscene(id.toUpperCase(), name);
|
||||||
|
} else {
|
||||||
|
Cutscenes.getLOGGER().error(
|
||||||
|
"Error while parsing cutscene name or ID " + (name == null ? "(name)" : name + " ")
|
||||||
|
+ (id == null ? "(id)" : id));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
double x = 0, y = 0, z = 0;
|
||||||
|
float yaw = 0, pitch = 0;
|
||||||
|
if (file.contains("start")) { // start: "world,x,y,z,yaw,pitch"
|
||||||
|
try {
|
||||||
|
String[] start = file.getString("start").split(",");
|
||||||
|
x = Double.parseDouble(start[1]);
|
||||||
|
y = Double.parseDouble(start[2]);
|
||||||
|
z = Double.parseDouble(start[3]);
|
||||||
|
yaw = Float.parseFloat(start[4]);
|
||||||
|
pitch = Float.parseFloat(start[5]);
|
||||||
|
Location location = new Location(Bukkit.getWorld(start[0]), x, y, z, yaw, pitch);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Cutscenes.getLOGGER()
|
||||||
|
.error("Error while parsing cutscene start location: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file.contains("end")) { // end: "world,x,y,z,yaw,pitch"
|
||||||
|
try {
|
||||||
|
String[] end = file.getString("end").split(",");
|
||||||
|
x = Double.parseDouble(end[1]);
|
||||||
|
y = Double.parseDouble(end[2]);
|
||||||
|
z = Double.parseDouble(end[3]);
|
||||||
|
yaw = Float.parseFloat(end[4]);
|
||||||
|
pitch = Float.parseFloat(end[5]);
|
||||||
|
Location location = new Location(Bukkit.getWorld(end[0]), x, y, z, yaw, pitch);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Cutscenes.getLOGGER()
|
||||||
|
.error("Error while parsing cutscene end location: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file.contains("markers")) { // markers: ["marker_id", "marker_id", ...]
|
||||||
|
for (String marker : file.getStringList("markers")) {
|
||||||
|
try {
|
||||||
|
cutscene.addMarkerId(Integer.parseInt(marker));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Cutscenes.getLOGGER().error(
|
||||||
|
"Error while parsing cutscene " + name + "/" + id + " marker ID: "
|
||||||
|
+ e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cutscene;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package me.unurled.sacredrealms.cutscenes.parse;
|
||||||
|
|
||||||
|
import me.unurled.sacredrealms.cutscenes.Cutscenes;
|
||||||
|
import me.unurled.sacredrealms.cutscenes.Frame;
|
||||||
|
import me.unurled.sacredrealms.cutscenes.Marker;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ```
|
||||||
|
* id: "marker_id"
|
||||||
|
* cutscene_id: "cutscene_id"
|
||||||
|
* start: "world,x,y,z,yaw,pitch"
|
||||||
|
* timeBetweenFrames: "long time"
|
||||||
|
* overAllTime: "long time"
|
||||||
|
* frames: # in order of play
|
||||||
|
* - "0,world,x,y,z,yaw,pitch"
|
||||||
|
* - "1,world,x,y,z,yaw,pitch"
|
||||||
|
* ...
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class MarkerParser {
|
||||||
|
|
||||||
|
public static Marker parse(FileConfiguration file) {
|
||||||
|
String id = null;
|
||||||
|
Marker marker = null;
|
||||||
|
if (file.contains("id")) { // id: "marker_id"
|
||||||
|
id = file.getString("id");
|
||||||
|
}
|
||||||
|
if (id != null && id.length() != 0) {
|
||||||
|
try {
|
||||||
|
marker = new Marker(Integer.parseInt(id));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Cutscenes.getLOGGER().error("Error while parsing marker ID: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Cutscenes.getLOGGER().error("Error while parsing marker ID " + (id == null ? "(id)" : id));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
double x = 0, y = 0, z = 0;
|
||||||
|
float yaw = 0, pitch = 0;
|
||||||
|
if (file.contains("start")) { // start: "world,x,y,z,yaw,pitch"
|
||||||
|
try {
|
||||||
|
String[] start = file.getString("start").split(",");
|
||||||
|
x = Double.parseDouble(start[1]);
|
||||||
|
y = Double.parseDouble(start[2]);
|
||||||
|
z = Double.parseDouble(start[3]);
|
||||||
|
yaw = Float.parseFloat(start[4]);
|
||||||
|
pitch = Float.parseFloat(start[5]);
|
||||||
|
Location location = new Location(Bukkit.getWorld(start[0]), x, y, z, yaw, pitch);
|
||||||
|
marker.setStart(location);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Cutscenes.getLOGGER().error("Error while parsing cutscene start location: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file.contains("timeBetweenFrames")) { // timeBetweenFrames: "long time"
|
||||||
|
try {
|
||||||
|
marker.setTimeBetweenFrames(Long.parseLong(file.getString("timeBetweenFrames", "50")));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Cutscenes.getLOGGER().error("Error while parsing cutscene timeBetweenFrames: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file.contains("overAllTime")) { // overAllTime: "long time"
|
||||||
|
try {
|
||||||
|
marker.setOverAllTime(Long.parseLong(file.getString("overAllTime", "250")));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Cutscenes.getLOGGER().error("Error while parsing cutscene overAllTime: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file.contains("frames")) { // frames: [ "0,world,x,y,z,yaw,pitch", "1,world,x,y,z,yaw,pitch", ... ]
|
||||||
|
for (String frames : file.getStringList("markers")) {
|
||||||
|
try {
|
||||||
|
String[] frame = frames.split(",");
|
||||||
|
x = Double.parseDouble(frame[2]);
|
||||||
|
y = Double.parseDouble(frame[3]);
|
||||||
|
z = Double.parseDouble(frame[4]);
|
||||||
|
yaw = Float.parseFloat(frame[5]);
|
||||||
|
pitch = Float.parseFloat(frame[6]);
|
||||||
|
Location location = new Location(Bukkit.getWorld(frame[1]), x, y, z, yaw, pitch);
|
||||||
|
marker.addFrame(new Frame(location, Integer.parseInt(frame[0])));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Cutscenes.getLOGGER().error("Error while parsing cutscene " + id + " frame ID: " + frames + " " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return marker;
|
||||||
|
}
|
||||||
|
}
|
21
src/main/resources/plugin.yml
Normal file
21
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
name: Cutscenes
|
||||||
|
version: '${version}'
|
||||||
|
main: me.unurled.sacredrealms.cutscenes.Cutscenes
|
||||||
|
api-version: '1.20'
|
||||||
|
authors: [unurled]
|
||||||
|
description: a cutscene make plugin for the sacred realms server
|
||||||
|
depend:
|
||||||
|
- Citizens
|
||||||
|
|
||||||
|
commands:
|
||||||
|
cutscenes:
|
||||||
|
aliases: cs
|
||||||
|
description: cutscenes command
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
cutscenes.admin:
|
||||||
|
description: admin permission for cutscenes command
|
||||||
|
default: op
|
||||||
|
|
||||||
|
cutscenes.use:
|
||||||
|
description: use permission for cutscenes command
|
Loading…
Reference in a new issue