Compare commits
120 Commits
Author | SHA1 | Date | |
---|---|---|---|
edf26785a3 | |||
4d90f5fc28 | |||
343decb05a | |||
36c6c93edb | |||
24af27f2e3 | |||
13132eace6 | |||
8d479b69e3 | |||
5ca8ad8bd7 | |||
3f2ba1e428 | |||
5bab1a1ac7 | |||
8fdd0487bf | |||
e0ee1e66c9 | |||
5acb44b0e1 | |||
7cd849946b | |||
a71aca5d6c | |||
ea08ac7a81 | |||
ee192c1035 | |||
81dbf16d3f | |||
f03011e4f1 | |||
9069ead9e9 | |||
7ced598bfd | |||
f04f1b33e3 | |||
0715771bfc | |||
c18ac59442 | |||
0a1ae69f53 | |||
8451463b73 | |||
7e27a05596 | |||
ba260519e0 | |||
378d872283 | |||
bc27c35f1a | |||
18689ac0df | |||
3fe57d5fe9 | |||
0699206c21 | |||
e663f3f105 | |||
55be88b7da | |||
dc24f28b8f | |||
f85ebbbb5d | |||
720d3c8d65 | |||
e397d69d7a | |||
bef697e5fc | |||
6638a48677 | |||
73a374e529 | |||
f838317af0 | |||
3c25f5f079 | |||
179fa2e4d7 | |||
075db7a91b | |||
c9d00f4f77 | |||
4de66d65a2 | |||
8594f8029c | |||
e192ae4433 | |||
bdb7c85ceb | |||
1b448e749e | |||
2799a40c58 | |||
710838645f | |||
f56023004a | |||
55a98b6464 | |||
236d372746 | |||
1332a42bf6 | |||
5acfe8f6af | |||
9d287f7c2f | |||
7ea39f9aad | |||
21ab8c4bd3 | |||
3f247bfc90 | |||
843fa26c08 | |||
cfbb2688d2 | |||
350cf108dd | |||
c9ef7197cc | |||
40f02449d9 | |||
e71dccb98d | |||
a3f2a06f6a | |||
a321d243ba | |||
5c4ddf892c | |||
7ea619c596 | |||
c63e4badf4 | |||
894b5464dd | |||
8b47eb1139 | |||
440d4f1b48 | |||
76192b1f97 | |||
5f6473b0fb | |||
5d29c387a3 | |||
2306308071 | |||
541eb1e733 | |||
c6ecbe7548 | |||
5191d5ece3 | |||
6dc4269367 | |||
d9bbaf9865 | |||
8ef61e0880 | |||
b3b6644d24 | |||
b9b683dcde | |||
16cf29a590 | |||
4b82b81d63 | |||
91069b76c6 | |||
61448e77f2 | |||
8fddabe00f | |||
de79433c32 | |||
8304b6a105 | |||
95750701f2 | |||
ee9115b774 | |||
cbe16a669c | |||
3489800f28 | |||
57c4993a30 | |||
b836874b46 | |||
61919b71b1 | |||
eecdeff77c | |||
4fc8503d63 | |||
671857b9e4 | |||
7c5d610803 | |||
d1432347c1 | |||
bf4d8b97ed | |||
89aca9bd98 | |||
631463d845 | |||
189da92542 | |||
2284912b16 | |||
c9bc9dd2da | |||
6907a767c6 | |||
18db3514e3 | |||
4bdb3f94d5 | |||
b5468b1fe9 | |||
8409d1cc7d | |||
59a6e1c423 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
@ -24,3 +23,8 @@
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
.idea
|
||||
.gradle
|
||||
build/*
|
||||
|
||||
/resources/
|
||||
|
2
LICENSE
2
LICENSE
@ -2,7 +2,7 @@ MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without IRestriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
|
91
build.gradle
Normal file
91
build.gradle
Normal file
@ -0,0 +1,91 @@
|
||||
|
||||
//for jar packaging see https://github.com/Protonull/BasicMinestomServer/blob/master/build.gradle.kts
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
id "com.github.johnrengelman.shadow" version "7.1.0"
|
||||
}
|
||||
|
||||
group 'eu.mhsl.minenet'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
|
||||
maven {
|
||||
url 'https://jitpack.io'
|
||||
}
|
||||
|
||||
maven {
|
||||
url "https://repo.unnamed.team/repository/unnamed-public/"
|
||||
}
|
||||
|
||||
maven {
|
||||
url 'https://oss.sonatype.org/content/repositories/snapshots'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
|
||||
|
||||
//https://jitpack.io/#Minestom/Minestom
|
||||
implementation 'net.minestom:minestom-snapshots:fd51c8d17a'
|
||||
|
||||
//Tools
|
||||
implementation 'de.articdive:jnoise:3.0.2'
|
||||
implementation 'net.md-5:bungeecord-config:1.19-R0.1-SNAPSHOT'
|
||||
implementation 'org.apache.commons:commons-text:1.10.0'
|
||||
implementation 'org.spongepowered:configurate-yaml:4.1.2'
|
||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||
implementation 'com.google.code.gson:gson:2.10.1'
|
||||
implementation 'com.google.guava:guava:32.0.1-android'
|
||||
|
||||
|
||||
//PvP
|
||||
implementation 'io.github.TogAr2:MinestomPvP:PR62-SNAPSHOT'
|
||||
|
||||
// Hephaestus engine
|
||||
implementation("team.unnamed:hephaestus-api:0.2.1-SNAPSHOT")
|
||||
implementation("team.unnamed:hephaestus-reader-blockbench:0.2.1-SNAPSHOT")
|
||||
implementation("team.unnamed:hephaestus-runtime-minestom:0.2.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks {
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'eu.mhsl.minenet.minigames.Main'
|
||||
attributes 'Multi-Release': true
|
||||
}
|
||||
duplicatesStrategy = 'exclude'
|
||||
from configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
shadowJar {
|
||||
mergeServiceFiles()
|
||||
archiveClassifier.set("")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('copyJarToServer', Exec) {
|
||||
dependsOn shadowJar
|
||||
mustRunAfter shadowJar
|
||||
|
||||
commandLine 'scp', 'build/libs/Minigames-1.0-SNAPSHOT.jar', 'root@10.20.6.5:/root/minigames'
|
||||
}
|
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
252
gradlew
vendored
Executable file
252
gradlew
vendored
Executable file
@ -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='"-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" "$@"
|
94
gradlew.bat
vendored
Normal file
94
gradlew.bat
vendored
Normal file
@ -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="-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
|
2
settings.gradle
Normal file
2
settings.gradle
Normal file
@ -0,0 +1,2 @@
|
||||
rootProject.name = 'Minigames'
|
||||
|
70
src/main/java/eu/mhsl/minenet/minigames/Main.java
Normal file
70
src/main/java/eu/mhsl/minenet/minigames/Main.java
Normal file
@ -0,0 +1,70 @@
|
||||
package eu.mhsl.minenet.minigames;
|
||||
|
||||
import eu.mhsl.minenet.minigames.api.HttpServer;
|
||||
import eu.mhsl.minenet.minigames.command.Commands;
|
||||
import eu.mhsl.minenet.minigames.handler.Listeners;
|
||||
import eu.mhsl.minenet.minigames.lang.Languages;
|
||||
import eu.mhsl.minenet.minigames.server.tasks.TablistUpdateTask;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.extras.bungee.BungeeCordProxy;
|
||||
import net.minestom.server.extras.lan.OpenToLAN;
|
||||
import net.minestom.server.extras.velocity.VelocityProxy;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Main {
|
||||
/**
|
||||
* Starts minenet minigames services
|
||||
*/
|
||||
private final static Logger logger = Logger.getGlobal();
|
||||
public static ConfigurationNode globalConfig;
|
||||
|
||||
public static void main(String[] args) throws ConfigurateException {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
Resource.values(); // This initializes and preloads the enum and extracts the resources
|
||||
Languages.getInstance(); //Preload languages into the jvm
|
||||
|
||||
globalConfig = YamlConfigurationLoader
|
||||
.builder()
|
||||
.path(Resource.CONFIG.getPath())
|
||||
.build()
|
||||
.load();
|
||||
|
||||
ConfigurationNode serverConfig = globalConfig.node("server");
|
||||
|
||||
logger.info("Initialize Minecraft server...");
|
||||
|
||||
MinecraftServer server = MinecraftServer.init();
|
||||
// MinestomPvP.init();
|
||||
|
||||
MinecraftServer.setBrandName("mhsl.eu - minenet - credits to minestom");
|
||||
MinecraftServer.setCompressionThreshold(serverConfig.node("compression-threshold").getInt(0));
|
||||
System.setProperty("minestom.chunk-view-distance", String.valueOf(serverConfig.node("view-distance").getInt()));
|
||||
|
||||
Commands.values();
|
||||
Listeners.values();
|
||||
new HttpServer();
|
||||
|
||||
MinecraftServer.getSchedulerManager().scheduleTask(new TablistUpdateTask(), TaskSchedule.tick(20), TaskSchedule.tick(20));
|
||||
|
||||
logger.info("Starting Minecraft server ... ");
|
||||
|
||||
if(serverConfig.node("open-to-lan").getBoolean()) OpenToLAN.open();
|
||||
|
||||
if(globalConfig.node("bungeecord", "enabled").getBoolean()) BungeeCordProxy.enable();
|
||||
|
||||
if(globalConfig.node("velocity", "enabled").getBoolean()) {
|
||||
VelocityProxy.enable(Objects.requireNonNull(globalConfig.node("velocity", "secret").getString()));
|
||||
}
|
||||
|
||||
server.start("0.0.0.0", serverConfig.node("port").getInt(25565));
|
||||
System.gc();
|
||||
|
||||
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> logger.info("Minecraft server is now running!"));
|
||||
}
|
||||
}
|
47
src/main/java/eu/mhsl/minenet/minigames/Resource.java
Normal file
47
src/main/java/eu/mhsl/minenet/minigames/Resource.java
Normal file
@ -0,0 +1,47 @@
|
||||
package eu.mhsl.minenet.minigames;
|
||||
|
||||
import eu.mhsl.minenet.minigames.util.ResourceUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Predefined resources which are extracted on Runtime
|
||||
*/
|
||||
public enum Resource {
|
||||
CONFIG("config.yml", true),
|
||||
HUB_MAP("maps/hub"),
|
||||
LOBBY_MAP("maps/lobby"),
|
||||
RESULT_DISPLAY("maps/resultdisplay"),
|
||||
|
||||
GAME_MAP("maps/game"),
|
||||
LOCALES("lang");
|
||||
|
||||
private final Path path;
|
||||
private final String name;
|
||||
Resource(String name, boolean keepOutdated) {
|
||||
this.name = name;
|
||||
this.path = Path.of("resources/" + name);
|
||||
|
||||
try {
|
||||
Logger.getLogger("ressource").info("extracting resource " + name + " ... ");
|
||||
ResourceUtils.extractResource(name, keepOutdated);
|
||||
} catch (URISyntaxException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Resource(String name) {
|
||||
this(name, false);
|
||||
}
|
||||
|
||||
public Path getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
35
src/main/java/eu/mhsl/minenet/minigames/api/Controller.java
Normal file
35
src/main/java/eu/mhsl/minenet/minigames/api/Controller.java
Normal file
@ -0,0 +1,35 @@
|
||||
package eu.mhsl.minenet.minigames.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
import spark.Route;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
|
||||
public abstract class Controller<Q, R> implements Route {
|
||||
private final Class<Q> requestType;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Controller() {
|
||||
this.requestType = ((Class<Q>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object handle(Request request, Response response) throws Exception {
|
||||
response.header("Access-Control-Allow-Origin", "*");
|
||||
response.header("Access-Control-Allow-Methods", "*");
|
||||
|
||||
Q req;
|
||||
|
||||
if(request.body().isEmpty()) {
|
||||
req = null;
|
||||
} else {
|
||||
req = new Gson().fromJson(request.body(), this.requestType);
|
||||
}
|
||||
|
||||
return new Gson().toJson(handle(req, response));
|
||||
}
|
||||
|
||||
public abstract R handle(Q request, Response response);
|
||||
}
|
35
src/main/java/eu/mhsl/minenet/minigames/api/HttpServer.java
Normal file
35
src/main/java/eu/mhsl/minenet/minigames/api/HttpServer.java
Normal file
@ -0,0 +1,35 @@
|
||||
package eu.mhsl.minenet.minigames.api;
|
||||
|
||||
import eu.mhsl.minenet.minigames.Main;
|
||||
import eu.mhsl.minenet.minigames.api.routes.closeRoom.CloseRoom;
|
||||
import eu.mhsl.minenet.minigames.api.routes.createRoom.CreateRoom;
|
||||
import eu.mhsl.minenet.minigames.api.routes.queueRoom.QueueRoom;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import static spark.Spark.*;
|
||||
|
||||
public class HttpServer {
|
||||
private static final ConfigurationNode apiConfig = Main.globalConfig.node("api");
|
||||
public HttpServer() {
|
||||
if(!apiConfig.node("enabled").getBoolean()) return;
|
||||
|
||||
port(apiConfig.node("port").getInt());
|
||||
initExceptionHandler(e -> e.printStackTrace(System.err));
|
||||
exception(Exception.class, (exception, request, response) -> {
|
||||
exception.printStackTrace(System.err);
|
||||
response.status(500);
|
||||
});
|
||||
|
||||
before((request, response) -> {
|
||||
String userKey = request.headers("Authorization");
|
||||
String serverKey = apiConfig.node("secret").getString();
|
||||
if(userKey != null && !userKey.equals(serverKey)) {
|
||||
halt(401, "Authorization header missing or wrong");
|
||||
}
|
||||
});
|
||||
|
||||
post("/room", new CreateRoom());
|
||||
delete("/room", new CloseRoom());
|
||||
post("/queueRoom", new QueueRoom());
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.mhsl.minenet.minigames.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class QueuedPlayerRooms {
|
||||
private static final Map<UUID, UUID> playersToRoom = new HashMap<>();
|
||||
|
||||
public static void queuePlayer(UUID playerUUID, UUID roomUUID) {
|
||||
playersToRoom.put(playerUUID, roomUUID);
|
||||
}
|
||||
|
||||
public static UUID pullQueue(UUID playerUUID) {
|
||||
return playersToRoom.remove(playerUUID);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.mhsl.minenet.minigames.api.routes.closeRoom;
|
||||
|
||||
import eu.mhsl.minenet.minigames.api.Controller;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import spark.Response;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
record Req(UUID room) {}
|
||||
record Resp() {}
|
||||
public class CloseRoom extends Controller<Req, Resp> {
|
||||
@Override
|
||||
public Resp handle(Req request, Response response) {
|
||||
Room.deleteRoom(Room.getRoom(request.room()).orElseThrow());
|
||||
return new Resp();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.mhsl.minenet.minigames.api.routes.createRoom;
|
||||
|
||||
import eu.mhsl.minenet.minigames.api.Controller;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import spark.Response;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
record Req() {}
|
||||
record Resp(UUID uuid) {}
|
||||
public class CreateRoom extends Controller<Req, Resp> {
|
||||
@Override
|
||||
public Resp handle(Req request, Response response) {
|
||||
Room createdRoom = Room.createOwnerlessRoom();
|
||||
return new Resp(createdRoom.uuid);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package eu.mhsl.minenet.minigames.api.routes.queueRoom;
|
||||
|
||||
import eu.mhsl.minenet.minigames.api.Controller;
|
||||
import eu.mhsl.minenet.minigames.api.QueuedPlayerRooms;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import spark.Response;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
record Req(UUID player, UUID room) {}
|
||||
record Resp(String error) {}
|
||||
public class QueueRoom extends Controller<Req, Resp> {
|
||||
@Override
|
||||
public Resp handle(Req request, Response response) {
|
||||
if(Room.getRoom(request.room()).isEmpty()) return new Resp("Raum nicht gefunden");
|
||||
if(MinecraftServer.getConnectionManager().getOnlinePlayers().size() >= Integer.parseInt(System.getProperty("minenet.playerlimit", "999"))) {
|
||||
return new Resp("Der Server hat eine Spielerzahllimitierung und ist bereits voll!");
|
||||
}
|
||||
|
||||
QueuedPlayerRooms.queuePlayer(request.player(), request.room());
|
||||
return new Resp(null);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package eu.mhsl.minenet.minigames.command;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.privileged.SkinCommand;
|
||||
import eu.mhsl.minenet.minigames.command.privileged.*;
|
||||
import eu.mhsl.minenet.minigames.command.anonymous.HubCommand;
|
||||
import eu.mhsl.minenet.minigames.command.anonymous.LeaveCommand;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
|
||||
public enum Commands {
|
||||
HUB(new HubCommand()),
|
||||
LEAVE(new LeaveCommand()),
|
||||
|
||||
DEBUG(new DebugCommand()),
|
||||
FLY(new FlyCommand()),
|
||||
GAMEMODE(new GamemodeCommand()),
|
||||
GC(new GcCommand()),
|
||||
LANGTEST(new LangTestCommand()),
|
||||
ROOM(new RoomCommand()),
|
||||
UPDATE(new RefreshCommandsCommand()),
|
||||
OP(new OpCommand()),
|
||||
FAKEPLAYER(new FakeplayerCommand()),
|
||||
KICK(new KickCommand()),
|
||||
SKIN(new SkinCommand()),
|
||||
SETOWNER(new SetRoomOwnerCommand()),
|
||||
SETREWARD(new SetRewardCommand()),
|
||||
PUBLISHREWARD(new PublishRewardCommand()),
|
||||
ROOMPROXYMOVE(new InstanceProxyMoveCommand()),
|
||||
GAMESTART(new GameStartCommand()),
|
||||
GAMESTOP(new GameStopCommand()),
|
||||
GAMETIMEOUT(new GameTimeoutCommand()),
|
||||
PLAYERLIMIT(new PlayerLimitCommand()),
|
||||
SETMEMORIAL(new SetMemorialCommand());
|
||||
|
||||
Commands(Command handler) {
|
||||
MinecraftServer.getCommandManager().register(handler);
|
||||
}
|
||||
|
||||
static {
|
||||
MinecraftServer.getCommandManager().setUnknownCommandCallback((sender, command) -> {
|
||||
if(command.isBlank()) return;
|
||||
new ChatMessage(Icon.ERROR).appendStatic("Unknown command: ").quote(command).send(sender);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package eu.mhsl.minenet.minigames.command;
|
||||
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.condition.CommandCondition;
|
||||
import net.minestom.server.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PrivilegedCommand extends Command {
|
||||
private final List<CommandCondition> conditions = new ArrayList<>();
|
||||
public PrivilegedCommand(@NotNull String name, @Nullable String... aliases) {
|
||||
super(name, aliases);
|
||||
construct();
|
||||
}
|
||||
|
||||
public PrivilegedCommand(@NotNull String name) {
|
||||
super(name);
|
||||
construct();
|
||||
}
|
||||
|
||||
private void construct() {
|
||||
addCondition(isPrivileged());
|
||||
|
||||
setCondition((sender, commandString) -> conditions.parallelStream().allMatch(condition -> condition.canUse(sender, commandString)));
|
||||
}
|
||||
|
||||
protected CommandCondition isPrivileged() {
|
||||
return (sender, commandString) -> ((Player) sender).getPermissionLevel() == 4;
|
||||
}
|
||||
|
||||
protected void addCondition(CommandCondition condition) {
|
||||
conditions.add(condition);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package eu.mhsl.minenet.minigames.command.anonymous;
|
||||
|
||||
import eu.mhsl.minenet.minigames.util.MoveInstance;
|
||||
import eu.mhsl.minenet.minigames.instance.hub.Hub;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class HubCommand extends Command {
|
||||
public HubCommand() {
|
||||
super("hub");
|
||||
|
||||
setCondition(
|
||||
(sender, commandString) ->
|
||||
((Player) sender).getInstance() instanceof Room room && !room.apiDriven
|
||||
);
|
||||
|
||||
setDefaultExecutor((sender, context) -> {
|
||||
if(Room.getRoom((Player) sender).orElseThrow().apiDriven) return;
|
||||
Room.unsetRoom((Player) sender);
|
||||
MoveInstance.move((Player) sender, Hub.INSTANCE);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package eu.mhsl.minenet.minigames.command.anonymous;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class LeaveCommand extends Command {
|
||||
public LeaveCommand() {
|
||||
super("leave");
|
||||
|
||||
setCondition((sender, commandString) -> ((Player) sender).getInstance() instanceof Game);
|
||||
|
||||
setDefaultExecutor((sender, context) -> Room.setOwnRoom((Player) sender));
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.type.ActionBarMessage;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import eu.mhsl.minenet.minigames.message.type.TitleMessage;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DebugCommand extends PrivilegedCommand {
|
||||
public DebugCommand() {
|
||||
super("debug");
|
||||
|
||||
setDefaultExecutor((sender, args) -> {
|
||||
new ChatMessage(Icon.CHAT).appendTranslated("sample").send(sender);
|
||||
new ActionBarMessage().appendTranslated("sample").send(sender);
|
||||
new TitleMessage().subtitle(subtitleMessage -> subtitleMessage.appendTranslated("sample")).appendTranslated("sample").send(sender);
|
||||
List<String> testplayers = new ArrayList<>() {
|
||||
{
|
||||
add("MineTec");
|
||||
add("Goldi187");
|
||||
add("Test");
|
||||
}
|
||||
};
|
||||
new ChatMessage(Icon.STAR, true)
|
||||
.appendTranslated("score#result")
|
||||
.newLine()
|
||||
.indent()
|
||||
.numberedList(testplayers)
|
||||
.undent()
|
||||
.newLine()
|
||||
.appendTranslated("score#thanks")
|
||||
.send(sender);
|
||||
|
||||
new ChatMessage(Icon.SCIENCE).appendStatic(((Player) sender).getUuid().toString()).send(sender);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class FakeplayerCommand extends PrivilegedCommand {
|
||||
public FakeplayerCommand() {
|
||||
super("fakeplayer");
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
if(sender instanceof Player p) {
|
||||
if(p.getInstance() instanceof Room room) {
|
||||
// FakePlayer.initPlayer( // TODO FakePlayer does no longer exists
|
||||
// UUID.randomUUID(),
|
||||
// context.getRaw("name"),
|
||||
// new FakePlayerOption().setInTabList(true).setRegistered(true),
|
||||
// fakePlayer -> Room.setRoom(fakePlayer, room)
|
||||
// );
|
||||
} else {
|
||||
new ChatMessage(Icon.ERROR).appendStatic("Du musst dich in einer Raumlobby befinden!").send(sender);
|
||||
}
|
||||
}
|
||||
}, ArgumentType.String("name"));
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class FlyCommand extends PrivilegedCommand {
|
||||
public FlyCommand() {
|
||||
super("fly");
|
||||
|
||||
setDefaultExecutor((sender, context) -> {
|
||||
Player p = (Player) sender;
|
||||
p.setVelocity(new Vec(0, 5, 0));
|
||||
p.setFlying(!p.isFlying());
|
||||
p.setAllowFlying(!p.isAllowFlying());
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class GameStartCommand extends PrivilegedCommand {
|
||||
public GameStartCommand() {
|
||||
super("gameStart");
|
||||
setDefaultExecutor((sender, context) -> {
|
||||
Player player = (Player) sender;
|
||||
if(player.getInstance() instanceof StatelessGame game) {
|
||||
game.startAccessor();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class GameStopCommand extends PrivilegedCommand {
|
||||
public GameStopCommand() {
|
||||
super("gameStop");
|
||||
setDefaultExecutor((sender, context) -> {
|
||||
Player player = (Player) sender;
|
||||
if(player.getInstance() instanceof StatelessGame game) {
|
||||
game.stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.arguments.number.ArgumentInteger;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class GameTimeoutCommand extends PrivilegedCommand {
|
||||
public GameTimeoutCommand() {
|
||||
super("gameTimeout");
|
||||
|
||||
ArgumentInteger timeout = ArgumentType.Integer("timeout");
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
Player player = (Player) sender;
|
||||
if(player.getInstance() instanceof StatelessGame game) {
|
||||
game.setTimeLimit(context.get(timeout));
|
||||
}
|
||||
}, timeout);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentEnum;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class GamemodeCommand extends PrivilegedCommand {
|
||||
public GamemodeCommand() {
|
||||
super("gamemode", "gm");
|
||||
|
||||
|
||||
addSyntax((sender, context) -> ((Player) sender).setGameMode(
|
||||
context.get("target")),
|
||||
ArgumentType.Enum("target", GameMode.class).setFormat(ArgumentEnum.Format.LOWER_CASED)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.util.Monitoring;
|
||||
|
||||
public class GcCommand extends PrivilegedCommand {
|
||||
private static long lastRun = System.currentTimeMillis();
|
||||
public GcCommand() {
|
||||
super("gc");
|
||||
|
||||
setDefaultExecutor((sender, context) -> {
|
||||
long nextRun = (lastRun - (System.currentTimeMillis() - 30*1000)) / 1000;
|
||||
if(nextRun > 0) {
|
||||
new ChatMessage(Icon.ERROR).appendStatic("Please wait ").appendStatic(String.valueOf(nextRun)).appendStatic(" seconds before running GC again!").send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
lastRun = System.currentTimeMillis();
|
||||
|
||||
long before = Monitoring.getRamUsage();
|
||||
System.gc();
|
||||
long after = Monitoring.getRamUsage();
|
||||
|
||||
new ChatMessage(Icon.SUCCESS).appendStatic("Garbage collector ran successfully!").newLine()
|
||||
.appendStatic("before: ").appendStatic(String.valueOf(before)).appendStatic("MB").newLine()
|
||||
.appendStatic("now: ").appendStatic(String.valueOf(after)).appendStatic("MB").newLine()
|
||||
.appendStatic("difference: ").appendStatic(String.valueOf(before-after)).appendStatic("MB")
|
||||
.send(sender);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.util.PluginMessageUtil;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentWord;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.Instance;
|
||||
|
||||
public class InstanceProxyMoveCommand extends PrivilegedCommand {
|
||||
public InstanceProxyMoveCommand() {
|
||||
super("instanceProxyMove");
|
||||
|
||||
ArgumentWord serverArgument = new ArgumentWord("server");
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
Instance room = ((Player) sender).getInstance();
|
||||
room.getPlayers().forEach(player -> {
|
||||
Room.unsetRoom(player);
|
||||
PluginMessageUtil.connect(player, context.get(serverArgument));
|
||||
});
|
||||
}, serverArgument);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class KickCommand extends PrivilegedCommand {
|
||||
public KickCommand() {
|
||||
super("kick");
|
||||
|
||||
addSyntax(
|
||||
(sender, context) ->
|
||||
kick(context.getRaw("player"), ""),
|
||||
ArgumentType.Entity("player").onlyPlayers(true)
|
||||
);
|
||||
|
||||
addSyntax(
|
||||
(sender, context) ->
|
||||
kick(context.getRaw("player"), context.getRaw("reason")),
|
||||
ArgumentType.Entity("player").onlyPlayers(true),
|
||||
ArgumentType.String("reason")
|
||||
);
|
||||
}
|
||||
|
||||
private void kick(String playername, String reason) {
|
||||
Player playerToKick = MinecraftServer.getConnectionManager().findOnlinePlayer(playername);
|
||||
Objects.requireNonNull(playerToKick).kick(reason);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.lang.Languages;
|
||||
import eu.mhsl.minenet.minigames.lang.Lang;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class LangTestCommand extends PrivilegedCommand {
|
||||
public LangTestCommand() {
|
||||
super("langtest");
|
||||
|
||||
setDefaultExecutor((sender, context) -> sendMessage(Languages.getInstance().getLanguage((Player) sender), "sample").send(sender));
|
||||
|
||||
var targetString = ArgumentType.String("mapId");
|
||||
|
||||
addSyntax((sender, context) -> sendMessage(Languages.getInstance().getLanguage((Player) sender), context.get("mapId")).send(sender), targetString);
|
||||
}
|
||||
|
||||
private TranslatableMessage sendMessage(Lang lang, String mapId) {
|
||||
return new ChatMessage(Icon.SCIENCE).appendStatic(lang.getLangId()).newLine().appendTranslated(lang.getEntry(mapId));
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class OpCommand extends PrivilegedCommand {
|
||||
public OpCommand() {
|
||||
super("op");
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
Player target = MinecraftServer.getConnectionManager().getOnlinePlayerByUsername(context.getRaw("target"));
|
||||
if(target != null) {
|
||||
target.setPermissionLevel(4);
|
||||
target.refreshCommands();
|
||||
} else new ChatMessage(Icon.ERROR).appendStatic("Spieler nicht gefunden").send(sender);
|
||||
}, ArgumentType.Entity("target").onlyPlayers(true));
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.arguments.number.ArgumentInteger;
|
||||
|
||||
public class PlayerLimitCommand extends PrivilegedCommand {
|
||||
public PlayerLimitCommand() {
|
||||
super("playerLimit");
|
||||
|
||||
ArgumentInteger count = ArgumentType.Integer("count");
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
System.setProperty("minenet.playerlimit", String.valueOf(context.get(count)));
|
||||
}, count);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.score.tournament.TournamentDisplay;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
public class PublishRewardCommand extends PrivilegedCommand {
|
||||
private final HttpClient rewardPublishClient = HttpClient.newHttpClient();
|
||||
public PublishRewardCommand() {
|
||||
super("publishReward");
|
||||
|
||||
setDefaultExecutor((sender, context) -> {
|
||||
try {
|
||||
Room room = Room.getRoom((Player) sender).orElseThrow();
|
||||
TournamentDisplay world = new TournamentDisplay(room.getTournament());
|
||||
room.moveMembersToInstance(world);
|
||||
|
||||
String rewardRequestJson = new Gson().toJson(room.getTournament().getRewards());
|
||||
HttpRequest giveRewardsRequest = HttpRequest.newBuilder()
|
||||
.uri(new URI("http://10.20.7.1:8080/api/event/reward"))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(rewardRequestJson))
|
||||
.build();
|
||||
|
||||
room.getTournament().getRewards();
|
||||
HttpResponse<Void> rawResponse = rewardPublishClient.send(giveRewardsRequest, HttpResponse.BodyHandlers.discarding());
|
||||
sender.sendMessage(String.format("Rewards published: HTTP %s", rawResponse.statusCode()));
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
public class RefreshCommandsCommand extends PrivilegedCommand {
|
||||
public RefreshCommandsCommand() {
|
||||
super("refreshCommands");
|
||||
|
||||
setDefaultExecutor((sender, context) -> {
|
||||
MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(Player::refreshCommands);
|
||||
new ChatMessage(Icon.SUCCESS).appendStatic("Updated command syntax!").send(sender);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RoomCommand extends PrivilegedCommand {
|
||||
public RoomCommand() {
|
||||
super("room");
|
||||
|
||||
setDefaultExecutor((sender, context) -> {
|
||||
TranslatableMessage out = new ChatMessage(Icon.SCIENCE).appendStatic("Rooms:").newLine();
|
||||
|
||||
Room.getAllRooms().forEach((roomInstance) -> out
|
||||
.newLine()
|
||||
.appendStatic("Owner: ").appendStatic(roomInstance.getOwner() != null ? roomInstance.getOwner().getUsername() : "none").newLine()
|
||||
.appendStatic("Players: ").appendStatic(String.valueOf(roomInstance.getAllMembers().size())).newLine()
|
||||
.list(roomInstance.getAllMembers().stream().map(Player::getUsername).collect(Collectors.toList())).newLine());
|
||||
|
||||
out.send(sender);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.score.tournament.MemorialConfiguration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentString;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
|
||||
public class SetMemorialCommand extends PrivilegedCommand {
|
||||
public SetMemorialCommand() {
|
||||
super("setMemorial");
|
||||
|
||||
ArgumentString materialArgument = ArgumentType.String("material");
|
||||
ArgumentString titleArgument = ArgumentType.String("title");
|
||||
ArgumentString loreArgument = ArgumentType.String("lore");
|
||||
|
||||
materialArgument.setSuggestionCallback((sender, context, suggestion) -> {
|
||||
Material
|
||||
.values()
|
||||
.stream()
|
||||
.map(material -> new SuggestionEntry(material.name(), Component.text(material.name())))
|
||||
.forEach(suggestion::addEntry);
|
||||
});
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
Room
|
||||
.getRoom((Player) sender)
|
||||
.orElseThrow()
|
||||
.getTournament()
|
||||
.setMemorialConfiguration(
|
||||
new MemorialConfiguration(
|
||||
Material.fromNamespaceId(context.get(materialArgument)),
|
||||
context.get(titleArgument),
|
||||
context.get(loreArgument)
|
||||
)
|
||||
);
|
||||
|
||||
sender.sendMessage(
|
||||
Component.text()
|
||||
.append(Component.text("Memorial gesetzt:", NamedTextColor.GOLD))
|
||||
.appendNewline()
|
||||
.append(Component.text(context.get(materialArgument), NamedTextColor.AQUA))
|
||||
.appendNewline()
|
||||
.append(Component.text(context.get(titleArgument), NamedTextColor.RED))
|
||||
.appendNewline()
|
||||
.append(Component.text(context.get(loreArgument), NamedTextColor.DARK_RED))
|
||||
.build()
|
||||
);
|
||||
}, materialArgument, titleArgument, loreArgument);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.score.tournament.RewardConfiguration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentStringArray;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentWord;
|
||||
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SetRewardCommand extends PrivilegedCommand {
|
||||
public SetRewardCommand() {
|
||||
super("setRewards");
|
||||
|
||||
ArgumentWord materialArgument = ArgumentType.Word("material");
|
||||
ArgumentStringArray amountsArgument = ArgumentType.StringArray("amount");
|
||||
|
||||
materialArgument.setSuggestionCallback((sender, context, suggestion) -> {
|
||||
Material
|
||||
.values()
|
||||
.stream()
|
||||
.map(material -> new SuggestionEntry(material.name(), Component.text(material.name())))
|
||||
.forEach(suggestion::addEntry);
|
||||
});
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
Room
|
||||
.getRoom((Player) sender)
|
||||
.orElseThrow()
|
||||
.getTournament()
|
||||
.setRewardConfiguration(
|
||||
new RewardConfiguration(
|
||||
Material.fromNamespaceId(context.get(materialArgument)),
|
||||
Arrays.stream(context.get(amountsArgument)).map(Integer::valueOf).collect(Collectors.toList())
|
||||
)
|
||||
);
|
||||
|
||||
sender.sendMessage(
|
||||
Component.text()
|
||||
.append(Component.text("Belohnung gesetzt:", NamedTextColor.GOLD))
|
||||
.appendNewline()
|
||||
.append(Component.text(context.get(materialArgument), NamedTextColor.AQUA))
|
||||
.appendNewline()
|
||||
.append(Component.text(String.join(", ", context.get(amountsArgument)), NamedTextColor.RED))
|
||||
.build()
|
||||
);
|
||||
}, materialArgument, amountsArgument);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.condition.CommandCondition;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SetRoomOwnerCommand extends PrivilegedCommand {
|
||||
public SetRoomOwnerCommand() {
|
||||
super("setRoomOwner");
|
||||
|
||||
addCondition((sender, commandString) -> ((Player) sender).getInstance() instanceof Room);
|
||||
|
||||
setDefaultExecutor((sender, context) -> {
|
||||
if(sender instanceof Player p) {
|
||||
Room.getRoom(p).orElseThrow().setOwner(p);
|
||||
new ChatMessage(Icon.SUCCESS).appendStatic("You are now the owner of this room!").send(sender);
|
||||
}
|
||||
});
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
System.out.println("Test");
|
||||
if(sender instanceof Player p) {
|
||||
Player newOwner = MinecraftServer.getConnectionManager().getOnlinePlayerByUsername(context.getRaw("player"));
|
||||
Room.getRoom(p).orElseThrow().setOwner(Objects.requireNonNull(newOwner));
|
||||
new ChatMessage(Icon.SUCCESS).appendStatic("The new owner has been set!").send(sender);
|
||||
}
|
||||
}, ArgumentType.Entity("player").onlyPlayers(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandCondition isPrivileged() {
|
||||
return (sender, commandString) -> {
|
||||
Room playerRoom = Room.getRoom(((Player) sender)).orElse(null);
|
||||
return super.isPrivileged().canUse(sender, commandString) || (playerRoom != null && playerRoom.getOwner() == sender);
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package eu.mhsl.minenet.minigames.command.privileged;
|
||||
|
||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.PlayerSkin;
|
||||
|
||||
public class SkinCommand extends PrivilegedCommand {
|
||||
public SkinCommand() {
|
||||
super("skin");
|
||||
|
||||
addSyntax((sender, context) -> {
|
||||
if(sender instanceof Player p) {
|
||||
p.setSkin(PlayerSkin.fromUsername(context.getRaw("target")));
|
||||
}
|
||||
}, ArgumentType.Entity("target").onlyPlayers(true).onlyPlayers(true));
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package eu.mhsl.minenet.minigames.handler;
|
||||
|
||||
import eu.mhsl.minenet.minigames.handler.global.*;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.event.EventListener;
|
||||
|
||||
public enum Listeners {
|
||||
SPAWN(new AddEntityToInstanceEventListener()),
|
||||
LOGIN(new PlayerLoginHandler()),
|
||||
LEAVE(new PlayerLeaveHandler());
|
||||
|
||||
Listeners(EventListener<?> event) {
|
||||
MinecraftServer.getGlobalEventHandler().addListener(event);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package eu.mhsl.minenet.minigames.handler.global;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Spawnable;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.EventListener;
|
||||
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
|
||||
import net.minestom.server.potion.Potion;
|
||||
import net.minestom.server.potion.PotionEffect;
|
||||
import net.minestom.server.timer.ExecutionType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AddEntityToInstanceEventListener implements EventListener<AddEntityToInstanceEvent> {
|
||||
@Override
|
||||
public @NotNull Class eventType() {
|
||||
return AddEntityToInstanceEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Result run(@NotNull AddEntityToInstanceEvent event) {
|
||||
if(event.getEntity() instanceof Player p) {
|
||||
MinecraftServer.getSchedulerManager().scheduleNextTick(p::refreshCommands, ExecutionType.TICK_END);
|
||||
|
||||
if(event.getInstance() instanceof Spawnable instance) {
|
||||
p.setRespawnPoint(instance.getSpawn());
|
||||
}
|
||||
|
||||
p.addEffect(new Potion(PotionEffect.BLINDNESS, (byte) 1, 20));
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package eu.mhsl.minenet.minigames.handler.global;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.EventListener;
|
||||
import net.minestom.server.event.player.PlayerDisconnectEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerLeaveHandler implements EventListener<PlayerDisconnectEvent> {
|
||||
@Override
|
||||
public @NotNull Class<PlayerDisconnectEvent> eventType() {
|
||||
return PlayerDisconnectEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Result run(@NotNull PlayerDisconnectEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
// new ChatMessage(Icon.SCIENCE).appendStatic("unübersetzter Leavetext: ").appendStatic(p.getDisplayName()).send(MinecraftServer.getConnectionManager().getOnlinePlayers());
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package eu.mhsl.minenet.minigames.handler.global;
|
||||
|
||||
import eu.mhsl.minenet.minigames.Main;
|
||||
import eu.mhsl.minenet.minigames.api.QueuedPlayerRooms;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.instance.transfer.Transfer;
|
||||
import eu.mhsl.minenet.minigames.skin.SkinCache;
|
||||
import eu.mhsl.minenet.minigames.util.MoveInstance;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.entity.Player;
|
||||
import eu.mhsl.minenet.minigames.instance.hub.Hub;
|
||||
import net.minestom.server.event.EventListener;
|
||||
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket;
|
||||
import net.minestom.server.scoreboard.Team;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PlayerLoginHandler implements EventListener<AsyncPlayerConfigurationEvent> {
|
||||
public static final Team globalTeam = MinecraftServer.getTeamManager()
|
||||
.createBuilder("global")
|
||||
.collisionRule(TeamsPacket.CollisionRule.NEVER)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public @NotNull Class<AsyncPlayerConfigurationEvent> eventType() {
|
||||
return AsyncPlayerConfigurationEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Result run(@NotNull AsyncPlayerConfigurationEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
|
||||
Transfer transferInstance = new Transfer();
|
||||
p.setRespawnPoint(transferInstance.getSpawn());
|
||||
event.setSpawningInstance(transferInstance);
|
||||
|
||||
UUID pushQueue = QueuedPlayerRooms.pullQueue(event.getPlayer().getUuid());
|
||||
|
||||
MinecraftServer.getSchedulerManager().scheduleTask(
|
||||
() -> {
|
||||
p.setTeam(globalTeam);
|
||||
if(pushQueue != null) {
|
||||
Room.setRoom(p, Room.getRoom(pushQueue).orElseThrow());
|
||||
} else {
|
||||
MoveInstance.move(p, Hub.INSTANCE);
|
||||
}
|
||||
},
|
||||
TaskSchedule.seconds(1),
|
||||
TaskSchedule.stop()
|
||||
);
|
||||
|
||||
SkinCache.applySkin(p);
|
||||
|
||||
try {
|
||||
if(Objects.requireNonNull(Main.globalConfig.node("admins").getList(String.class)).stream().anyMatch(s -> s.equalsIgnoreCase(p.getUsername()))) {
|
||||
p.setPermissionLevel(4);
|
||||
}
|
||||
} catch (SerializationException | NullPointerException ignored) {}
|
||||
|
||||
Logger.getLogger("user").info(p.getUsername() + " joined");
|
||||
|
||||
// new ChatMessage(Icon.SCIENCE).appendStatic("unübersetzter Jointext: ").appendStatic(p.getUsername()).send(MinecraftServer.getConnectionManager().getOnlinePlayers());
|
||||
|
||||
return Result.SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package eu.mhsl.minenet.minigames.instance;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.registry.DynamicRegistry;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
|
||||
/**
|
||||
* Prebuilt dimensions
|
||||
*/
|
||||
public enum Dimension {
|
||||
OVERWORLD(
|
||||
NamespaceID.from("minenet:fullbright_overworld"),
|
||||
DimensionType
|
||||
.builder()
|
||||
.ambientLight(2.0f)
|
||||
.build()
|
||||
),
|
||||
|
||||
NETHER(
|
||||
NamespaceID.from("minenet:fullbright_nether"),
|
||||
DimensionType
|
||||
.builder()
|
||||
.ambientLight(2.0f)
|
||||
.effects("minecraft:the_nether")
|
||||
.build()
|
||||
),
|
||||
|
||||
THE_END(
|
||||
NamespaceID.from("minenet:fullbright_end"),
|
||||
DimensionType
|
||||
.builder()
|
||||
.ambientLight(2.0f)
|
||||
.effects("minecraft:the_end")
|
||||
.build()
|
||||
);
|
||||
|
||||
public final DimensionType DIMENSION;
|
||||
public final NamespaceID namespaceID;
|
||||
public final DynamicRegistry.Key<DimensionType> key;
|
||||
Dimension(NamespaceID namespaceID, DimensionType dimType) {
|
||||
this.DIMENSION = dimType;
|
||||
this.namespaceID = namespaceID;
|
||||
|
||||
this.key = MinecraftServer.getDimensionTypeRegistry().register(namespaceID, DIMENSION);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package eu.mhsl.minenet.minigames.instance;
|
||||
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
|
||||
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.instance.InstanceContainer;
|
||||
import net.minestom.server.instance.InstanceManager;
|
||||
import net.minestom.server.registry.DynamicRegistry;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class MineNetInstance extends InstanceContainer {
|
||||
public MineNetInstance(DynamicRegistry.Key<DimensionType> type) {
|
||||
super(UUID.randomUUID(), type);
|
||||
MinecraftServer.getInstanceManager().registerInstance(this);
|
||||
|
||||
eventNode()
|
||||
.addListener(AddEntityToInstanceEvent.class, this::onEntityAdd)
|
||||
.addListener(RemoveEntityFromInstanceEvent.class, this::onEntityRemove);
|
||||
}
|
||||
|
||||
private void onEntityRemove(RemoveEntityFromInstanceEvent removeEntityFromInstanceEvent) {
|
||||
if(removeEntityFromInstanceEvent.getEntity() instanceof Player p) {
|
||||
this.onPlayerLeave(p);
|
||||
}
|
||||
}
|
||||
|
||||
private void onEntityAdd(AddEntityToInstanceEvent addEntityToInstanceEvent) {
|
||||
if(addEntityToInstanceEvent.getEntity() instanceof Player p) {
|
||||
addEntityToInstanceEvent.setCancelled(this.onPlayerJoin(p));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Player joins this instance
|
||||
* @param p player who is joining
|
||||
* @return setCanceled
|
||||
*/
|
||||
protected boolean onPlayerJoin(Player p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Player leaves this instance
|
||||
* @param p player who is leaving
|
||||
*/
|
||||
protected void onPlayerLeave(Player p) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
*/
|
||||
public void destroy(Instance target) {
|
||||
getPlayers().forEach(player -> {
|
||||
if(target != null)
|
||||
player.setInstance(target);
|
||||
else
|
||||
player.kick(TranslatedComponent.byId("sample").getAssembled(player));
|
||||
});
|
||||
|
||||
MinecraftServer.getSchedulerManager().scheduleTask(
|
||||
() -> MinecraftServer.getInstanceManager().unregisterInstance(this),
|
||||
TaskSchedule.seconds(10),
|
||||
TaskSchedule.stop()
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package eu.mhsl.minenet.minigames.instance;
|
||||
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
|
||||
public interface Spawnable {
|
||||
Pos getSpawn();
|
||||
}
|
170
src/main/java/eu/mhsl/minenet/minigames/instance/game/Game.java
Normal file
170
src/main/java/eu/mhsl/minenet/minigames/instance/game/Game.java
Normal file
@ -0,0 +1,170 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.MineNetInstance;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import eu.mhsl.minenet.minigames.score.Score;
|
||||
import eu.mhsl.minenet.minigames.util.CommonEventHandles;
|
||||
import eu.mhsl.minenet.minigames.instance.Spawnable;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.item.ItemDropEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.registry.DynamicRegistry;
|
||||
import net.minestom.server.timer.ExecutionType;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class Game extends MineNetInstance implements Spawnable {
|
||||
|
||||
protected Room parentRoom;
|
||||
protected boolean isRunning = false;
|
||||
protected boolean isBeforeBeginning = true;
|
||||
|
||||
protected final Random rnd = new Random(); //TODO better way than ths?
|
||||
|
||||
protected final Logger logger;
|
||||
|
||||
public Game(DynamicRegistry.Key<DimensionType> dimensionType) {
|
||||
super(dimensionType);
|
||||
|
||||
MinecraftServer.getInstanceManager().registerInstance(this);
|
||||
|
||||
logger = Logger.getLogger("Game:" + getUuid());
|
||||
|
||||
eventNode()
|
||||
.addListener(PlayerMoveEvent.class, this::onPlayerMove)
|
||||
.addListener(PlayerBlockBreakEvent.class, this::onBlockBreak)
|
||||
.addListener(PlayerBlockPlaceEvent.class, this::onBlockPlace)
|
||||
.addListener(ItemDropEvent.class, this::onItemDrop);
|
||||
}
|
||||
|
||||
public Game setParent(Room parentRoom) {
|
||||
this.parentRoom = parentRoom;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static void initialize(GameFactory factory, List<Option<?>> options, Player owner) {
|
||||
try {
|
||||
|
||||
Game game = factory.manufacture(Room.getRoom(owner).orElseThrow(), options);
|
||||
game.load();
|
||||
Room.getRoom(owner).orElseThrow().moveMembersToInstance(game);
|
||||
|
||||
MinecraftServer.getSchedulerManager().scheduleTask(() -> {
|
||||
game.getPlayers().forEach(player -> new ChatMessage(Icon.SCIENCE)
|
||||
.appendStatic(factory.name().getAssembled(player).asComponent())
|
||||
.newLine()
|
||||
.appendStatic(factory.description().getAssembled(player).asComponent())
|
||||
.send(player));
|
||||
|
||||
return TaskSchedule.stop();
|
||||
}, TaskSchedule.seconds(3));
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
new ChatMessage(Icon.ERROR).appendStatic("Instance crashed: " + e.getMessage()).send(owner);
|
||||
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> Room.getRoom(owner).orElseThrow().moveMembersToRoomLobby());
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and start countdown
|
||||
*/
|
||||
public void load() {
|
||||
scheduler().submitTask(() -> {
|
||||
CompletableFuture<Void> callback = new CompletableFuture<>();
|
||||
this.onLoad(callback);
|
||||
// callback.whenComplete((unused, throwable) -> this.start());
|
||||
return TaskSchedule.stop();
|
||||
}, ExecutionType.TICK_END);
|
||||
|
||||
}
|
||||
|
||||
protected void start() {
|
||||
isRunning = true;
|
||||
isBeforeBeginning = false;
|
||||
this.onStart();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
isRunning = false;
|
||||
this.onStop();
|
||||
this.unload();
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
this.onUnload();
|
||||
|
||||
getPlayers().forEach(Room::setOwnRoom);
|
||||
|
||||
scheduler().scheduleTask(() -> {
|
||||
|
||||
logger.info("stopping game instance " + this.uuid);
|
||||
getPlayers().forEach(player -> player.kick("timeout"));
|
||||
|
||||
MinecraftServer.getInstanceManager().unregisterInstance(this);
|
||||
|
||||
}, TaskSchedule.seconds(10), TaskSchedule.stop());
|
||||
}
|
||||
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
callback.complete(null);
|
||||
}
|
||||
|
||||
protected void onStart() {}
|
||||
protected void onStop() {}
|
||||
protected void onUnload() {}
|
||||
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
|
||||
}
|
||||
|
||||
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
|
||||
playerBlockBreakEvent.setCancelled(true);
|
||||
}
|
||||
|
||||
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) {
|
||||
playerBlockPlaceEvent.setCancelled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerLeave(Player p) {
|
||||
this.checkAbandoned();
|
||||
}
|
||||
|
||||
protected void onItemDrop(@NotNull ItemDropEvent itemDropEvent) {
|
||||
CommonEventHandles.cancel(itemDropEvent);
|
||||
}
|
||||
|
||||
protected void checkAbandoned() {
|
||||
scheduleNextTick((instance) -> {
|
||||
if(instance.getPlayers().isEmpty()) this.unload();
|
||||
});
|
||||
}
|
||||
|
||||
protected void publishScore(Score score) {
|
||||
this.parentRoom.getTournament().addScore(score);
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0,50,0);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun.AnvilRunFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace.ElytraRaceFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms.BackroomsFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bedwars.BedwarsFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.acidRain.AcidRainFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube.DeathcubeFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.jumpDive.JumpDiveFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun.MinerunFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef.SpleefFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight.StickFightFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.TetrisFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tntrun.TntRunFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.TowerdefenseFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace.TrafficLightRaceFactory;
|
||||
|
||||
public enum GameList {
|
||||
DEATHCUBE(new DeathcubeFactory(), GameType.JUMPNRUN),
|
||||
MINERUN(new MinerunFactory(), GameType.JUMPNRUN),
|
||||
TRAFFICLIGHTRACE(new TrafficLightRaceFactory(), GameType.OTHER),
|
||||
STICKFIGHT(new StickFightFactory(), GameType.PROTOTYPE),
|
||||
TOWERDEFENSE(new TowerdefenseFactory(), GameType.PROTOTYPE),
|
||||
BEDWARS(new BedwarsFactory(), GameType.PROTOTYPE),
|
||||
BACKROOMS(new BackroomsFactory(), GameType.PROTOTYPE),
|
||||
BOWSPLEEF(new BowSpleefFactory(), GameType.PROTOTYPE),
|
||||
TETRIS(new TetrisFactory(), GameType.OTHER),
|
||||
TNTRUN(new TntRunFactory(), GameType.OTHER),
|
||||
ANVILRUN(new AnvilRunFactory(), GameType.PVE),
|
||||
ACIDRAIN(new AcidRainFactory(), GameType.PVE),
|
||||
ELYTRARACE(new ElytraRaceFactory(), GameType.PVP),
|
||||
SPLEEF(new SpleefFactory(), GameType.PVP),
|
||||
JUMPDIVE(new JumpDiveFactory(), GameType.JUMPNRUN);
|
||||
|
||||
private final GameFactory factory;
|
||||
private final GameType type;
|
||||
GameList(GameFactory factory, GameType type) {
|
||||
this.factory = factory;
|
||||
this.type = type;
|
||||
}
|
||||
public GameFactory getFactory() {
|
||||
return this.factory;
|
||||
}
|
||||
|
||||
public GameType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
public enum GameType {
|
||||
OTHER(Material.GRASS_BLOCK, TranslatedComponent.byId("GameType#other"), TranslatedComponent.byId("GameType#other_description")),
|
||||
PVP(Material.DIAMOND_SWORD, TranslatedComponent.byId("GameType#pvp"), TranslatedComponent.byId("GameType#pvp_description")),
|
||||
PVE(Material.DIAMOND_PICKAXE, TranslatedComponent.byId("GameType#pve"), TranslatedComponent.byId("GameType#pve_description")),
|
||||
JUMPNRUN(Material.DIAMOND_BOOTS, TranslatedComponent.byId("GameType#jumpnrun"), TranslatedComponent.byId("GameType#jumpnrun_description")),
|
||||
PROTOTYPE(Material.COMMAND_BLOCK, TranslatedComponent.byId("GameType#prototype"), TranslatedComponent.byId("GameType#prototype_description"));
|
||||
|
||||
|
||||
final Material icon;
|
||||
final TranslatedComponent title;
|
||||
final TranslatedComponent description;
|
||||
|
||||
GameType(Material icon, TranslatedComponent title, TranslatedComponent description) {
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public Material getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public TranslatedComponent getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public TranslatedComponent getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.message.Countdown;
|
||||
import eu.mhsl.minenet.minigames.message.Icon;
|
||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||
import eu.mhsl.minenet.minigames.message.type.TitleMessage;
|
||||
import eu.mhsl.minenet.minigames.score.Score;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.registry.DynamicRegistry;
|
||||
import net.minestom.server.timer.ExecutionType;
|
||||
import net.minestom.server.timer.Task;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class StatelessGame extends Game {
|
||||
private final String name;
|
||||
private final Score score;
|
||||
private Task timeLimitTask;
|
||||
|
||||
private int timeLimit = 0;
|
||||
private int timePlayed = 0;
|
||||
|
||||
public StatelessGame(DynamicRegistry.Key<DimensionType> dimensionType, String gameName, Score score) {
|
||||
super(dimensionType);
|
||||
this.score = score;
|
||||
this.name = gameName;
|
||||
}
|
||||
|
||||
public Score getScore() {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setTimeLimit(int limit) {
|
||||
this.timeLimit = limit;
|
||||
if(this.timeLimitTask != null) {
|
||||
this.timeLimitTask.cancel();
|
||||
this.timePlayed = 0;
|
||||
}
|
||||
if(this.timeLimit > 0) {
|
||||
this.timeLimitTask = scheduler().submitTask(() -> {
|
||||
if(!isRunning || timeLimit == 0) return TaskSchedule.stop();
|
||||
if(timeLimit <= timePlayed) {
|
||||
stop();
|
||||
return TaskSchedule.stop();
|
||||
}
|
||||
|
||||
int timeLeft = timeLimit - timePlayed;
|
||||
switch (timeLeft) {
|
||||
case 90, 60, 30, 10, 5, 4, 3, 2, 1 ->
|
||||
new ChatMessage(Icon.SCIENCE).appendStatic("Noch " + timeLeft + " Sekunden!").send(getPlayers());
|
||||
}
|
||||
|
||||
timePlayed++;
|
||||
|
||||
return TaskSchedule.seconds(1);
|
||||
}, ExecutionType.TICK_START);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
super.load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays countdown and starts the game
|
||||
* When overriding make sure to call this::start after countdown!
|
||||
*/
|
||||
protected CompletableFuture<Void> countdownStart() {
|
||||
return new Countdown(TitleMessage.class)
|
||||
.countdown(Audience.audience(getPlayers()), 5, countdownModifier -> countdownModifier.message = new TitleMessage(Duration.ofMillis(300), Duration.ofMillis(700))
|
||||
.subtitle(subtitleMessage -> subtitleMessage.appendStatic(Component.text("in ", NamedTextColor.DARK_GREEN))
|
||||
.appendStatic(Component.text(countdownModifier.timeLeft, NamedTextColor.GREEN))
|
||||
.appendStatic(Component.text(" seconds", NamedTextColor.DARK_GREEN))));
|
||||
}
|
||||
|
||||
|
||||
public void startAccessor() {
|
||||
this.start();
|
||||
}
|
||||
@Override
|
||||
protected void start() {
|
||||
score.setInstance(this);
|
||||
score.attachListeners();
|
||||
|
||||
countdownStart().thenRun(super::start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
isRunning = false;
|
||||
this.onStop();
|
||||
getScore().insertRemainingPlayers(getPlayers());
|
||||
this.publishScore(getScore());
|
||||
|
||||
countdownUnload();
|
||||
}
|
||||
|
||||
private void countdownUnload() {
|
||||
new TitleMessage(Duration.ofSeconds(1)).appendTranslated("score#done").send(getPlayers());
|
||||
scheduler().scheduleTask(this::unload, TaskSchedule.seconds(5), TaskSchedule.stop());
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ConfigManager {
|
||||
private final ArrayList<Option<?>> items = new ArrayList<>();
|
||||
|
||||
public ConfigManager addOption(Option option) {
|
||||
items.add(option);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayList<Option<?>> getAll() {
|
||||
return items;
|
||||
}
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.Restriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionData;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory;
|
||||
import eu.mhsl.minenet.minigames.util.InventoryItemAlignment;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.EventListener;
|
||||
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
|
||||
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
|
||||
import net.minestom.server.inventory.InventoryType;
|
||||
import net.minestom.server.inventory.click.ClickType;
|
||||
import net.minestom.server.inventory.condition.InventoryConditionResult;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GameConfigurationInventory extends InteractableInventory {
|
||||
private final Map<Integer, Option<?>> map = new HashMap<>();
|
||||
|
||||
final private Room room;
|
||||
final private GameFactory factory;
|
||||
final private Player p;
|
||||
|
||||
public GameConfigurationInventory(Room room, Player p, GameFactory factory) {
|
||||
super(InventoryType.CHEST_5_ROW, factory.name().getAssembled(p));
|
||||
this.room = room;
|
||||
this.p = p;
|
||||
this.factory = factory;
|
||||
|
||||
room.eventNode()
|
||||
.addListener(AddEntityToInstanceEvent.class, addEntityToInstanceEvent -> MinecraftServer.getSchedulerManager().scheduleNextTick(this::updatePlayButton))
|
||||
.addListener(RemoveEntityFromInstanceEvent.class, removeEntityFromInstanceEvent -> MinecraftServer.getSchedulerManager().scheduleNextTick(this::updatePlayButton));
|
||||
|
||||
ConfigManager config = factory.configuration();
|
||||
|
||||
setClickableItem(
|
||||
ItemStack.builder(Material.RED_WOOL)
|
||||
.customName(
|
||||
TranslatedComponent.byId("common#back")
|
||||
.setColor(NamedTextColor.RED)
|
||||
.getAssembled(p)
|
||||
)
|
||||
.build(),
|
||||
0,
|
||||
itemClick -> itemClick.getPlayer().closeInventory(),
|
||||
true
|
||||
);
|
||||
|
||||
setDummyItem(Material.BLACK_STAINED_GLASS_PANE,1);
|
||||
|
||||
setDummyItem(
|
||||
ItemStack.builder(Material.NAME_TAG)
|
||||
.customName(
|
||||
factory.name().setColor(NamedTextColor.GOLD).getAssembled(p)
|
||||
)
|
||||
.build(),
|
||||
4
|
||||
);
|
||||
|
||||
setDummyItem(Material.BLACK_STAINED_GLASS_PANE,7);
|
||||
|
||||
updatePlayButton();
|
||||
|
||||
for(int i = 9; i <= 17; i++) {
|
||||
setDummyItem(Material.BLACK_STAINED_GLASS_PANE, i);
|
||||
}
|
||||
|
||||
if(config == null) {
|
||||
setDummyItem(
|
||||
ItemStack.builder(Material.BARRIER)
|
||||
.customName(
|
||||
TranslatedComponent.byId("room#noOption").setColor(NamedTextColor.RED).getAssembled(p)
|
||||
)
|
||||
.lore(
|
||||
TranslatedComponent.assemble("room#noOptionDescription", p)
|
||||
)
|
||||
.build(),
|
||||
31
|
||||
);
|
||||
|
||||
} else {
|
||||
int offset = 18;
|
||||
InventoryItemAlignment itemAlignment = new InventoryItemAlignment(config.getAll().size(), 3);
|
||||
for(Option<?> item : config.getAll()) {
|
||||
InventoryItemAlignment.ItemOffset current = itemAlignment.next();
|
||||
map.put(offset + current.get(), item);
|
||||
|
||||
setDummyItem(
|
||||
item.getCurrent(p),
|
||||
offset + current.get()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick(Player player, int slot, ClickType clickType, InventoryConditionResult inventoryConditionResult) {
|
||||
inventoryConditionResult.setCancel(true);
|
||||
|
||||
if(!map.containsKey(slot)) return;
|
||||
|
||||
Option<?> item = map.get(slot);
|
||||
setDummyItem(
|
||||
item.getNext(p),
|
||||
slot
|
||||
);
|
||||
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
private void updatePlayButton() {
|
||||
RestrictionHandler restrictionHandler = factory.globalRestrictions();
|
||||
RestrictionData restrictionData = new RestrictionData(room);
|
||||
|
||||
if(restrictionHandler.canPlay(restrictionData)) {
|
||||
|
||||
setClickableItem(
|
||||
ItemStack.builder(restrictionHandler.getWarnings(restrictionData).size() > 0 ? Material.YELLOW_WOOL : Material.GREEN_WOOL)
|
||||
.customName(TranslatedComponent.byId("restriction#success").setColor(NamedTextColor.GREEN).getAssembled(p))
|
||||
.lore(restrictionHandler.getWarnings(restrictionData).stream().map(translatedComponent -> translatedComponent.getAssembled(p)).collect(Collectors.toList()))
|
||||
.build(),
|
||||
8,
|
||||
itemClick -> Game.initialize(factory, map.values().stream().toList(), itemClick.getPlayer()),
|
||||
true
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
setClickableItem(
|
||||
ItemStack.builder(Material.RED_WOOL)
|
||||
.customName(TranslatedComponent.byId("restriction#fail").setColor(NamedTextColor.RED).getAssembled(p))
|
||||
.lore(
|
||||
restrictionHandler.getRestrictions()
|
||||
.stream()
|
||||
.filter(iRestriction -> iRestriction.calculate(restrictionData).type().equals(Restriction.Type.FAIL))
|
||||
.map(iRestriction -> iRestriction.calculate(restrictionData).description().getAssembled(p))
|
||||
.collect(Collectors.toList()))
|
||||
.build(),
|
||||
8,
|
||||
itemClick -> {
|
||||
if(restrictionHandler.canPlay(restrictionData)) {
|
||||
updatePlayButton();
|
||||
return;
|
||||
}
|
||||
itemClick.getPlayer().playSound(Sound.sound(SoundEvent.ENTITY_SILVERFISH_DEATH, Sound.Source.AMBIENT, 1f, 1f));
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface GameFactory {
|
||||
TranslatedComponent name();
|
||||
default ConfigManager configuration() {
|
||||
return null;
|
||||
}
|
||||
default RestrictionHandler globalRestrictions() {
|
||||
return new RestrictionHandler();
|
||||
}
|
||||
|
||||
default Material symbol() {
|
||||
return Material.GRASS_BLOCK;
|
||||
}
|
||||
default TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("GameFactory#missingDescription");
|
||||
}
|
||||
|
||||
Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception;
|
||||
|
||||
default Game manufacture(Room parent, List<Option<?>> configuration) throws Exception {
|
||||
if(configuration == null) return manufacture(parent);
|
||||
|
||||
Map<String, Option<?>> cnf = new HashMap<>();
|
||||
configuration.forEach(option -> cnf.put(option.getId(), option));
|
||||
|
||||
return manufacture(parent, cnf);
|
||||
}
|
||||
|
||||
default Game manufacture(Room parent) throws Exception {
|
||||
if(this.configuration() == null) return manufacture(parent, List.of());
|
||||
|
||||
return manufacture(parent, this.configuration().getAll());
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Option<T> {
|
||||
private RestrictionHandler restrictionHandler;
|
||||
private final Material item;
|
||||
private final TranslatedComponent name;
|
||||
private final String id;
|
||||
protected T currentValue;
|
||||
private final List<T> options;
|
||||
private int pointer = 0;
|
||||
|
||||
public Option(String id, Material item, TranslatedComponent name, List<T> options) {
|
||||
this.id = id;
|
||||
this.item = item;
|
||||
this.name = name;
|
||||
this.options = options;
|
||||
|
||||
currentValue = options.getFirst();
|
||||
}
|
||||
|
||||
public void setRestrictionHandler(RestrictionHandler restrictionHandler) {
|
||||
this.restrictionHandler = restrictionHandler;
|
||||
}
|
||||
|
||||
public RestrictionHandler getRestrictionHandler() {
|
||||
return restrictionHandler;
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getNext(Player p) {
|
||||
if(++pointer >= options.size()) pointer = 0;
|
||||
currentValue = options.get(pointer);
|
||||
return getCurrent(p);
|
||||
}
|
||||
|
||||
public ItemStack getCurrent(Player p) {
|
||||
String value = options.get(pointer).toString();
|
||||
return ItemStack.builder(item)
|
||||
.customName(name.getAssembled(p))
|
||||
.lore(TranslatedComponent.byId("optionCommon#value").setColor(NamedTextColor.GOLD).getAssembled(p)
|
||||
.append(Component.text(": ")).append(Component.text(value)))
|
||||
.build();
|
||||
}
|
||||
|
||||
public int getAsInt() {
|
||||
return Integer.parseInt(getAsString());
|
||||
}
|
||||
|
||||
public boolean getAsBoolean() {
|
||||
return Objects.equals(getAsString(), "true") || Objects.equals(getAsString(), "1");
|
||||
}
|
||||
|
||||
public String getAsString() {
|
||||
return currentValue.toString();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config.common;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BoolOption extends Option<String> {
|
||||
public BoolOption(String id, Material item, TranslatedComponent name) {
|
||||
super(id, item, name, List.of("true", "false"));
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config.common;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NumericOption extends Option<Integer> {
|
||||
|
||||
public NumericOption(String id, Material item, TranslatedComponent name, Integer... options) {
|
||||
super(id, item, name, List.of(options));
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction;
|
||||
|
||||
|
||||
public interface IRestriction {
|
||||
Restriction calculate(RestrictionData data);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction;
|
||||
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
|
||||
public record Restriction(TranslatedComponent name, TranslatedComponent description, TranslatedComponent warnMessage,
|
||||
eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.Restriction.Type type) {
|
||||
public Restriction(TranslatedComponent name, TranslatedComponent description, TranslatedComponent warnMessage, Type type) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.warnMessage = warnMessage;
|
||||
this.type = type;
|
||||
|
||||
if (this.warnMessage == null && this.type.equals(Type.WARN)) {
|
||||
throw new IllegalStateException("warnMessage cannot be null when RestrictionType is WARN");
|
||||
}
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
OK,
|
||||
WARN,
|
||||
FAIL,
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
|
||||
public record RestrictionData(Room room) {
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction;
|
||||
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RestrictionHandler {
|
||||
private List<IRestriction> restrictions = new ArrayList<>();
|
||||
|
||||
public RestrictionHandler(IRestriction... restrictions) {
|
||||
this.restrictions = List.of(restrictions);
|
||||
}
|
||||
|
||||
public RestrictionHandler() {
|
||||
|
||||
}
|
||||
|
||||
public RestrictionHandler addRestriction(IRestriction IRestriction) {
|
||||
this.restrictions.add(IRestriction);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<IRestriction> getRestrictions() {
|
||||
return restrictions;
|
||||
}
|
||||
|
||||
public boolean canPlay(RestrictionData data) {
|
||||
if(restrictions.size() < 1) return true;
|
||||
return this.restrictions.stream()
|
||||
.noneMatch(iRestriction -> iRestriction.calculate(data).type().equals(Restriction.Type.FAIL));
|
||||
}
|
||||
|
||||
public List<TranslatedComponent> getWarnings(RestrictionData data) {
|
||||
List<TranslatedComponent> warnings = new ArrayList<>();
|
||||
for (IRestriction r : this.restrictions) {
|
||||
Restriction calculated = r.calculate(data);
|
||||
if(!calculated.type().equals(Restriction.Type.WARN)) continue;
|
||||
|
||||
warnings.add(calculated.warnMessage());
|
||||
}
|
||||
return warnings;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.common;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.IRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.Restriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionData;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
|
||||
public class MaximalPlayeramountGameRestriction implements IRestriction {
|
||||
private final int max;
|
||||
|
||||
public MaximalPlayeramountGameRestriction(int max) {
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Restriction calculate(RestrictionData data) {
|
||||
return new Restriction(
|
||||
TranslatedComponent.byId("restriction#maxPlayersInRoom"),
|
||||
TranslatedComponent.byId("restriction#maxPlayersInRoomDescription"),
|
||||
null,
|
||||
data.room().getAllMembers().size() > this.max ? Restriction.Type.FAIL : Restriction.Type.OK
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.common;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.IRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.Restriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionData;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
|
||||
public class MinimalPlayeramountGameRestriction implements IRestriction {
|
||||
private final int min;
|
||||
|
||||
public MinimalPlayeramountGameRestriction(int min) {
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Restriction calculate(RestrictionData data) {
|
||||
return new Restriction(
|
||||
TranslatedComponent.byId("restriction#minPlayersInRoom"),
|
||||
TranslatedComponent.byId("restriction#minPlayersInRoomDescription"),
|
||||
null,
|
||||
data.room().getAllMembers().size() < this.min ? Restriction.Type.FAIL : Restriction.Type.OK
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.acidRain;
|
||||
|
||||
import de.articdive.jnoise.JNoise;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.util.NumberUtil;
|
||||
import eu.mhsl.minenet.minigames.util.WeatherUtils;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.event.player.PlayerTickEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.network.packet.server.play.ParticlePacket;
|
||||
import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.timer.ExecutionType;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
public class AcidRain extends StatelessGame {
|
||||
final private int radius = 20;
|
||||
private int generationOffset = 0;
|
||||
|
||||
final private int roofHeight = 55;
|
||||
private int difficulty = 0;
|
||||
final JNoise noise = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.09)
|
||||
.build();
|
||||
public AcidRain() {
|
||||
super(Dimension.OVERWORLD.key, "acidRain", new LastWinsScore());
|
||||
setGenerator(
|
||||
new CircularPlateTerrainGenerator(radius)
|
||||
.setPlateHeight(50)
|
||||
.setPlatePallet(BlockPallet.STONE)
|
||||
);
|
||||
|
||||
|
||||
eventNode().addListener(PlayerTickEvent.class, this::onPlayerTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
this.generatePlatform(0);
|
||||
callback.complete(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
new WeatherUtils().startRain(this.getPlayers());
|
||||
|
||||
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
||||
|
||||
getPlayers().forEach(player -> {
|
||||
player.sendPacket(new ParticlePacket(Particle.SNEEZE, 0, 60, 0, radius, radius, radius, 1f, 500));
|
||||
player.sendPacket(new ParticlePacket(Particle.ITEM_SLIME, 0, 60, 0, radius, radius, radius, 1f, 500));
|
||||
});
|
||||
|
||||
if(!isRunning) return TaskSchedule.stop();
|
||||
return TaskSchedule.millis(100);
|
||||
}, ExecutionType.TICK_END);
|
||||
|
||||
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
||||
generationOffset++;
|
||||
generatePlatform(generationOffset);
|
||||
|
||||
if(!isRunning) return TaskSchedule.stop();
|
||||
return TaskSchedule.millis((long) NumberUtil.map(50 - difficulty, 0, 50, 100, 1000));
|
||||
}, ExecutionType.TICK_END);
|
||||
|
||||
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
||||
difficulty++;
|
||||
|
||||
if(difficulty >= 50) return TaskSchedule.stop();
|
||||
return TaskSchedule.seconds(3);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
if(playerMoveEvent.getNewPosition().y() < 50) playerDeath(playerMoveEvent.getPlayer());
|
||||
}
|
||||
|
||||
private void onPlayerTick(PlayerTickEvent playerTickEvent) {
|
||||
if(isBeforeBeginning) return;
|
||||
if(getBlock(playerTickEvent.getPlayer().getPosition().withY(roofHeight)).isAir()) playerDeath(playerTickEvent.getPlayer());
|
||||
}
|
||||
|
||||
private void generatePlatform(long offset) {
|
||||
int radius = this.radius + 20;
|
||||
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
for(int x = -radius; x <= radius; x++) {
|
||||
for(int z = -radius; z <= radius; z++) {
|
||||
batch.setBlock(x, roofHeight, z, Block.AIR);
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||
if(noise.getNoise(x + offset, z + offset) > 0.4) continue;
|
||||
|
||||
batch.setBlock(x, roofHeight, z, Block.OAK_PLANKS);
|
||||
}
|
||||
}
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
||||
}
|
||||
|
||||
private void playerDeath(Player p) {
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
getScore().insertResult(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, 51, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.acidRain;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AcidRainFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_AcidRain#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_AcidRain#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.SLIME_BALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||
return new AcidRain().setParent(parent);
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.metadata.other.FallingBlockMeta;
|
||||
import net.minestom.server.event.entity.EntityTickEvent;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.timer.Scheduler;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
class AnvilRun extends StatelessGame {
|
||||
|
||||
final int spawnHeight = 30;
|
||||
final int radius;
|
||||
int anvilsPerSecond;
|
||||
final int seconds;
|
||||
final int anvilHeight = 200;
|
||||
final List<Pos> anvilSpawnPositions = new ArrayList<>();
|
||||
|
||||
public AnvilRun(int radius, int seconds) {
|
||||
super(Dimension.OVERWORLD.key, "Anvil Run", new LastWinsScore());
|
||||
this.radius = radius;
|
||||
this.seconds = seconds;
|
||||
this.setGenerator(new CircularPlateTerrainGenerator(radius));
|
||||
|
||||
eventNode().addListener(EntityTickEvent.class, this::onEntityTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
|
||||
for(int x = -radius; x <= radius; x++) {
|
||||
for (int z = -radius; z <= radius; z++) {
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||
|
||||
anvilSpawnPositions.add(new Pos(x+0.5, anvilHeight, z+0.5));
|
||||
|
||||
batch.setBlock(x, spawnHeight-1, z, Block.SNOW_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
this.anvilsPerSecond = anvilSpawnPositions.size() / this.seconds;
|
||||
Collections.shuffle(anvilSpawnPositions);
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
protected void spawnAnvil(Pos spawnPosition) {
|
||||
Entity anvil = new Entity(EntityType.FALLING_BLOCK);
|
||||
((FallingBlockMeta) anvil.getEntityMeta()).setBlock(Block.ANVIL);
|
||||
anvil.setInstance(this, spawnPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
Scheduler scheduler = MinecraftServer.getSchedulerManager();
|
||||
for(int i=0; i<this.anvilSpawnPositions.size(); i++) {
|
||||
final int j = i;
|
||||
scheduler.scheduleTask(
|
||||
() -> spawnAnvil(this.anvilSpawnPositions.get(j)),
|
||||
TaskSchedule.millis(
|
||||
(long) Math.floor((double) i/this.anvilsPerSecond * 1000)
|
||||
),
|
||||
TaskSchedule.stop()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
super.onPlayerMove(playerMoveEvent);
|
||||
if(isBeforeBeginning && playerMoveEvent.getNewPosition().y() < spawnHeight - 2) {
|
||||
playerMoveEvent.setCancelled(true);
|
||||
playerMoveEvent.getPlayer().teleport(getSpawn());
|
||||
return;
|
||||
}
|
||||
if(playerMoveEvent.getNewPosition().y() < spawnHeight - 2) getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
}
|
||||
|
||||
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
||||
if(!entityTickEvent.getEntity().getEntityType().equals(EntityType.FALLING_BLOCK)) return;
|
||||
Pos anvilPosition = entityTickEvent.getEntity().getPosition();
|
||||
if(anvilPosition.y() > spawnHeight + 0.5) return;
|
||||
if(anvilPosition.y() < spawnHeight - 3) entityTickEvent.getEntity().remove();
|
||||
if(this.getBlock(anvilPosition.withY(spawnHeight-1)).isAir()) return;
|
||||
this.setBlock(anvilPosition.withY(spawnHeight-1), Block.AIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, spawnHeight, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AnvilRunFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_AnvilRun#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_AnvilRun#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 5, 10, 15, 20, 25, 30))
|
||||
.addOption(new NumericOption("seconds", Material.STICK, TranslatedComponent.byId("optionCommon#seconds"), 10, 30, 60, 90, 120));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new AnvilRun(configuration.get("radius").getAsInt(), configuration.get("seconds").getAsInt()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.ANVIL;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.NoScore;
|
||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Backrooms extends StatelessGame {
|
||||
public Backrooms() {
|
||||
super(Dimension.NETHER.key, "Backrooms", new NoScore());
|
||||
BackroomsGenerator generator = new BackroomsGenerator();
|
||||
setGenerator(unit -> generator.generateRoom(unit, 50));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
|
||||
playerBlockBreakEvent.setCancelled(false);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BackroomsFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("gameBackrooms");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||
return new Backrooms().setParent(parent);
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms;
|
||||
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.generator.GenerationUnit;
|
||||
import net.minestom.server.instance.generator.UnitModifier;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class BackroomsGenerator {
|
||||
public void generateRoom(GenerationUnit unit, int y) {
|
||||
var modifier = unit.modifier();
|
||||
var start = unit.absoluteStart();
|
||||
var yPos = start.blockY() + y;
|
||||
|
||||
for (int x = 0; x < unit.size().blockX(); x++) {
|
||||
for (int z = 0; z < unit.size().blockZ(); z++) {
|
||||
var xPos = start.blockX() + x;
|
||||
var zPos = start.blockZ() + z;
|
||||
|
||||
modifier.setBlock(xPos, yPos - 1, zPos, Block.BEDROCK);
|
||||
modifier.setBlock(xPos, yPos + 5, zPos, Block.BEDROCK);
|
||||
|
||||
modifier.setBlock(xPos, yPos, zPos, Block.LIGHT_GRAY_WOOL);
|
||||
modifier.setBlock(xPos, yPos + 4, zPos, Block.SMOOTH_STONE_SLAB);
|
||||
|
||||
// idk man... dont ask about this
|
||||
if (
|
||||
(x - 2) % 4 == 0 && (
|
||||
((z - 2) % 8 == 0) ||
|
||||
((z - 2) % 8 == 1) ||
|
||||
((z - 2) % 8 == 3) ||
|
||||
((z - 2) % 8 == 4)
|
||||
)
|
||||
) {
|
||||
modifier.setBlock(xPos, yPos + 4, zPos, Block.SEA_LANTERN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generateWalls(modifier, start.blockX() + 0, yPos + 1, start.blockZ() + 0);
|
||||
generateWalls(modifier, start.blockX() + 8, yPos + 1, start.blockZ() + 0);
|
||||
generateWalls(modifier, start.blockX() + 0, yPos + 1, start.blockZ() + 8);
|
||||
generateWalls(modifier, start.blockX() + 8, yPos + 1, start.blockZ() + 8);
|
||||
}
|
||||
|
||||
private void generateWalls(UnitModifier modifier, int xPos, int yPos, int zPos) {
|
||||
generatePillar(modifier, xPos, yPos, zPos, Block.CHISELED_SANDSTONE);
|
||||
|
||||
var random = ThreadLocalRandom.current();
|
||||
|
||||
var wall1 = random.nextInt(4) != 0;
|
||||
var wall2 = random.nextInt(4) != 0;
|
||||
var door1 = random.nextInt(2) != 0;
|
||||
var door2 = random.nextInt(2) != 0;
|
||||
|
||||
var door1pos = random.nextInt(2, 6);
|
||||
var door2pos = random.nextInt(2, 6);
|
||||
|
||||
if (wall1) {
|
||||
for (int x = xPos; x < xPos + 8; x++) {
|
||||
generatePillar(modifier, x, yPos, zPos, Block.SMOOTH_SANDSTONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (wall2) {
|
||||
for (int z = zPos; z < zPos + 8; z++) {
|
||||
generatePillar(modifier, xPos, yPos, z, Block.SMOOTH_SANDSTONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (door1 && wall1) {
|
||||
generatePillar(modifier, xPos + door1pos, yPos, zPos, Block.AIR);
|
||||
generatePillar(modifier, xPos + door1pos + 1, yPos, zPos, Block.AIR);
|
||||
}
|
||||
|
||||
if (door2 && wall2) {
|
||||
generatePillar(modifier, xPos, yPos, zPos + door2pos, Block.AIR);
|
||||
generatePillar(modifier, xPos, yPos, zPos + door2pos + 1, Block.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
private void generatePillar(UnitModifier modifier, int xPos, int yPos, int zPos, Block material) {
|
||||
for (int y = yPos; y < yPos + 3; y++) {
|
||||
modifier.setBlock(xPos, y, zPos, material);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.bedwars;
|
||||
|
||||
import eu.mhsl.minenet.minigames.Resource;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bedwars.data.BedwarsTeam;
|
||||
import eu.mhsl.minenet.minigames.message.type.ActionBarMessage;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.MaterialUtil;
|
||||
import eu.mhsl.minenet.minigames.util.Position;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.ItemEntity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.item.ItemDropEvent;
|
||||
import net.minestom.server.event.item.PickupItemEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.anvil.AnvilLoader;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.timer.ExecutionType;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class Bedwars extends StatelessGame {
|
||||
|
||||
List<Point> placedBlocks = new ArrayList<>();
|
||||
List<BedwarsTeam> teams = new ArrayList<>();
|
||||
|
||||
|
||||
public Bedwars() throws IOException {
|
||||
super(Dimension.OVERWORLD.key, "Bedwars", new LastWinsScore());
|
||||
setChunkLoader(new AnvilLoader(Resource.GAME_MAP.getPath().resolve("bedwars/test")));
|
||||
|
||||
Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(Resource.GAME_MAP.getPath().resolve("bedwars/test/config.yml").toFile());
|
||||
List<String> teamNames = config.getStringList("setup.teams");
|
||||
teamNames.forEach(teamName -> {
|
||||
String path = "teams." + teamName;
|
||||
teams.add(new BedwarsTeam(
|
||||
config.getString(path + ".name"),
|
||||
Position.getPosFromCommaSeparated(config.getString(path + ".pos.spawn")),
|
||||
Position.getPosFromCommaSeparated(config.getString(path + ".pos.spawner")),
|
||||
config.getStringList(path + ".pos.bed").stream().map(Position::getPosFromCommaSeparated).toList().toArray(new Pos[0]),
|
||||
MaterialUtil.fromString(config.getString(path + ".material.block"), Material.BLACK_WOOL)
|
||||
));
|
||||
});
|
||||
|
||||
eventNode().addListener(PickupItemEvent.class, pickupItemEvent -> {
|
||||
if(pickupItemEvent.getEntity() instanceof Player p) {
|
||||
p.getInventory().addItemStack(pickupItemEvent.getItemStack());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onItemDrop(@NotNull ItemDropEvent itemDropEvent) {
|
||||
itemDropEvent.setCancelled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
scheduler().submitTask(() -> {
|
||||
if(!isRunning) return TaskSchedule.stop();
|
||||
|
||||
teams.forEach(bedwarsTeam -> {
|
||||
ItemEntity item = new ItemEntity(ItemStack.of(bedwarsTeam.getBlock()));
|
||||
item.setNoGravity(true);
|
||||
item.setInstance(this, bedwarsTeam.getSpawner());
|
||||
});
|
||||
|
||||
return TaskSchedule.stop();
|
||||
}, ExecutionType.TICK_END);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) {
|
||||
placedBlocks.add(playerBlockPlaceEvent.getBlockPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
|
||||
if(!placedBlocks.contains(playerBlockBreakEvent.getBlockPosition())) playerBlockBreakEvent.setCancelled(true);
|
||||
|
||||
teams.forEach(bedwarsTeam -> {
|
||||
if(Arrays.stream(bedwarsTeam.getBed()).anyMatch(pos -> pos.sameBlock(playerBlockBreakEvent.getBlockPosition())))
|
||||
breakBed(bedwarsTeam);
|
||||
});
|
||||
|
||||
if(playerBlockBreakEvent.isCancelled())
|
||||
new ActionBarMessage().appendStatic(Component.text("BLAH")).send(playerBlockBreakEvent.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
if(playerMoveEvent.getNewPosition().y() < 0) death(playerMoveEvent.getPlayer());
|
||||
}
|
||||
|
||||
private void breakBed(BedwarsTeam team) {
|
||||
team.removeBed();
|
||||
for (Pos blockPos : team.getBed()) {
|
||||
setBlock(blockPos, Material.AIR.block());
|
||||
}
|
||||
}
|
||||
|
||||
private void death(Player p) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, 13, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.bedwars;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.common.MinimalPlayeramountGameRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BedwarsFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Bedwars#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestrictionHandler globalRestrictions() {
|
||||
return new RestrictionHandler()
|
||||
.addRestriction(new MinimalPlayeramountGameRestriction(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.RED_BED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Bedwars#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||
return new Bedwars().setParent(parent);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.bedwars.data;
|
||||
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BedwarsTeam {
|
||||
private List<Player> members = new ArrayList<>();
|
||||
|
||||
private final String name;
|
||||
private final Pos spawn;
|
||||
private final Pos spawner;
|
||||
|
||||
private final Pos[] bed;
|
||||
|
||||
private final Material block;
|
||||
|
||||
private boolean hasBed = true;
|
||||
|
||||
public BedwarsTeam(String name, Pos spawn, Pos spawner, Pos[] bed, Material block) {
|
||||
this.name = name;
|
||||
this.spawn = spawn;
|
||||
this.spawner = spawner;
|
||||
this.bed = bed;
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public void removeBed() {
|
||||
this.hasBed = false;
|
||||
}
|
||||
|
||||
public boolean isHasBed() {
|
||||
return hasBed;
|
||||
}
|
||||
|
||||
public List<Player> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
public void setMembers(List<Player> members) {
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Pos getSpawn() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
public Pos getSpawner() {
|
||||
return spawner;
|
||||
}
|
||||
|
||||
public Pos[] getBed() {
|
||||
return bed;
|
||||
}
|
||||
|
||||
public Material getBlock() {
|
||||
return block;
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.util.GeneratorUtils;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.*;
|
||||
import net.minestom.server.entity.metadata.other.PrimedTntMeta;
|
||||
import net.minestom.server.event.EventListener;
|
||||
import net.minestom.server.event.entity.projectile.ProjectileCollideWithBlockEvent;
|
||||
import net.minestom.server.event.entity.projectile.ProjectileCollideWithEntityEvent;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.tag.Tag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class BowSpleef extends StatelessGame {
|
||||
private static final Tag<Long> CHARGE_BOW_SINCE = Tag.Long("CHARGE_BOW_SINCE");
|
||||
private static final Tag<Boolean> ARROW_FIRST_HIT = Tag.Boolean("ARROW_ALREADY_LIT");
|
||||
private final int radius = 30;
|
||||
private final int totalElevation = 50;
|
||||
public BowSpleef() {
|
||||
super(Dimension.OVERWORLD.key, "bowSpleef", new LastWinsScore());
|
||||
|
||||
// eventNode().addListener( TODO implement bow mechanism
|
||||
// EventListener
|
||||
// .builder(PlayerItemAnimationEvent.class)
|
||||
// .handler(playerItemAnimationEvent -> playerItemAnimationEvent.getPlayer().setTag(CHARGE_BOW_SINCE, System.currentTimeMillis()))
|
||||
// .filter(playerItemAnimationEvent -> playerItemAnimationEvent.getItemAnimationType() == PlayerItemAnimationEvent.ItemAnimationType.BOW)
|
||||
// .build()
|
||||
// );
|
||||
//
|
||||
// eventNode().addListener(
|
||||
// EventListener
|
||||
// .builder(ItemUpdateStateEvent.class)
|
||||
// .handler(event -> {
|
||||
// final Player player = event.getPlayer();
|
||||
// final double chargedFor = (System.currentTimeMillis() - player.getTag(CHARGE_BOW_SINCE)) / 1000D;
|
||||
// final double power = MathUtils.clamp((chargedFor * chargedFor + 2 * chargedFor) / 2D, 0, 1);
|
||||
//
|
||||
// if (power > 0.2) {
|
||||
// final CustomEntityProjectile projectile = new CustomEntityProjectile(player, EntityType.ARROW);
|
||||
// final ArrowMeta meta = (ArrowMeta) projectile.getEntityMeta();
|
||||
// meta.setCritical(power >= 0.9);
|
||||
// projectile.scheduleRemove(Duration.of(100, TimeUnit.SERVER_TICK));
|
||||
// meta.setOnFire(true);
|
||||
//
|
||||
// final Pos position = player.getPosition().add(0, player.getEyeHeight(), 0);
|
||||
// projectile.setInstance(Objects.requireNonNull(player.getInstance()), position);
|
||||
//
|
||||
// final Vec direction = projectile.getPosition().direction();
|
||||
// projectile.shootFrom(position.add(direction).sub(0, 0.2, 0), power * 3, 1.0);
|
||||
// projectile.setTag(ARROW_FIRST_HIT, true);
|
||||
// }
|
||||
// })
|
||||
// .filter(itemUpdateStateEvent -> itemUpdateStateEvent.getItemStack().material() == Material.BOW)
|
||||
// .build()
|
||||
// );
|
||||
|
||||
eventNode().addListener(
|
||||
EventListener
|
||||
.builder(ProjectileCollideWithBlockEvent.class)
|
||||
.handler(projectileBlockHitEvent -> {
|
||||
Entity projectile = projectileBlockHitEvent.getEntity();
|
||||
if(!projectile.getTag(ARROW_FIRST_HIT)) {
|
||||
projectile.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
float radius = 0.5F;
|
||||
Point arrowPos = projectile.getPosition();
|
||||
GeneratorUtils.foreachXZ(arrowPos.add(radius), arrowPos.sub(radius), point -> {
|
||||
Point location = point.add(projectile.getVelocity().mul(0.04)).withY(totalElevation);
|
||||
if(!getBlock(location).isAir()) {
|
||||
setBlock(location, Block.AIR);
|
||||
|
||||
Entity fallingTnt = new Entity(EntityType.TNT);
|
||||
PrimedTntMeta fallingTntMeta = (PrimedTntMeta) fallingTnt.getEntityMeta();
|
||||
fallingTntMeta.setFuseTime(20);
|
||||
fallingTnt.setInstance(this, location);
|
||||
fallingTnt.setVelocity(new Vec(0, 3, 0));
|
||||
}
|
||||
});
|
||||
|
||||
projectile.setTag(ARROW_FIRST_HIT, false);
|
||||
})
|
||||
.build()
|
||||
);
|
||||
|
||||
eventNode().addListener(
|
||||
EventListener
|
||||
.builder(ProjectileCollideWithEntityEvent.class)
|
||||
.handler(projectileEntityHitEvent -> projectileEntityHitEvent.setCancelled(true))
|
||||
.build()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
for(int x = -radius; x <= radius; x++) {
|
||||
for(int z = -radius; z <= radius; z++) {
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||
|
||||
batch.setBlock(x, totalElevation, z, Block.TNT);
|
||||
}
|
||||
}
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
getPlayers().forEach(player -> {
|
||||
player.getInventory().setItemStack(
|
||||
0,
|
||||
ItemStack
|
||||
.builder(Material.BOW)
|
||||
.customName(TranslatedComponent.byId("bow").getAssembled(player))
|
||||
.glowing(true)
|
||||
.build()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
if(playerMoveEvent.getNewPosition().y() < totalElevation) {
|
||||
getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, totalElevation + 1, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BowSpleefFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_BowSpleef#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_BowSpleef#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.BOW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||
return new BowSpleef().setParent(parent);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
class Deathcube extends StatelessGame {
|
||||
|
||||
final int radius;
|
||||
final int height;
|
||||
final int percentage;
|
||||
|
||||
public Deathcube(int radius, int height, int percentage, int pvpEnabled) {
|
||||
super(Dimension.THE_END.key, "Deathcube", new FirstWinsScore());
|
||||
this.radius = radius;
|
||||
this.height = height + 49;
|
||||
this.percentage = percentage;
|
||||
this.setGenerator(new CircularPlateTerrainGenerator(radius+10).setPlateHeight(50));
|
||||
|
||||
if(pvpEnabled == 1) eventNode().addChild(
|
||||
CombatFeatures.empty()
|
||||
.add(CombatFeatures.VANILLA_ATTACK)
|
||||
.add(CombatFeatures.VANILLA_DAMAGE)
|
||||
.add(CombatFeatures.VANILLA_KNOCKBACK)
|
||||
.build().createNode()
|
||||
);
|
||||
System.out.println(radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
|
||||
for(int x = -radius; x <= radius; x++) {
|
||||
for (int z = -radius; z <= radius; z++) {
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||
|
||||
for (int y = 49; y < height; y++) {
|
||||
if(super.rnd.nextInt(1, 100) <= percentage) {
|
||||
batch.setBlock(x, y, z, BlockPallet.WOOD.rnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
super.onPlayerMove(playerMoveEvent);
|
||||
if(playerMoveEvent.getNewPosition().y() < 48) {
|
||||
playerMoveEvent.setCancelled(true);
|
||||
playerMoveEvent.getPlayer().teleport(getSpawn());
|
||||
return;
|
||||
}
|
||||
if(isBeforeBeginning && playerMoveEvent.getNewPosition().y() > 51.5) {
|
||||
playerMoveEvent.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if(playerMoveEvent.getNewPosition().y() > height) getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, 50, -(radius+5));
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class DeathcubeFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Deathcube#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Deathcube#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 10, 20, 30))
|
||||
.addOption(new NumericOption("height", Material.SCAFFOLDING, TranslatedComponent.byId("optionCommon#height"), 10, 30, 50))
|
||||
.addOption(new NumericOption("percentage", Material.COBWEB, TranslatedComponent.byId("game_Deathcube#optionPercentageBlocks"), 5, 7, 9, 11, 13))
|
||||
.addOption(new NumericOption("pvpEnabled", Material.STICK, TranslatedComponent.byId("game_Deathcube#optionPvpEnabled"), 0, 1));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new Deathcube(configuration.get("radius").getAsInt(), configuration.get("height").getAsInt(), configuration.get("percentage").getAsInt(), configuration.get("pvpEnabled").getAsInt()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.OAK_FENCE;
|
||||
}
|
||||
}
|
@ -0,0 +1,260 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.message.Countdown;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.message.type.TitleMessage;
|
||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.*;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.featureEnriched.ValeGenerator;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.PlaneTerrainGenerator;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.EquipmentSlot;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.*;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.network.packet.server.play.ParticlePacket;
|
||||
import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
public class ElytraRace extends StatelessGame {
|
||||
private final ValeGenerator vale = new ValeGenerator();
|
||||
|
||||
private final int gameHeight = 0;
|
||||
private final int seaLevel = -55;
|
||||
private final int ringSpacing = 100;
|
||||
private final int ringCount;
|
||||
|
||||
private final Material boostMaterial = Material.FIREWORK_ROCKET;
|
||||
private final Material resetMaterial = Material.RED_DYE;
|
||||
private final int boostMultiplier = 50;
|
||||
private final Material ringMaterial = Material.GOLD_BLOCK;
|
||||
private int generatedUntil = 0;
|
||||
|
||||
private record CheckPointData(int currentCheckpoint, int nextCheckpoint) {
|
||||
public CheckPointData next(int spacing) {
|
||||
return new CheckPointData(nextCheckpoint, nextCheckpoint + spacing);
|
||||
}
|
||||
}
|
||||
private final Map<Player, CheckPointData> playerCheckpoints = new HashMap<>();
|
||||
|
||||
public ElytraRace(int ringCount) {
|
||||
super(Dimension.OVERWORLD.key, "ElytraRace", new FirstWinsScore());
|
||||
|
||||
this.ringCount = ringCount;
|
||||
|
||||
setGenerator(vale);
|
||||
vale.setCalculateSeaLevel(point -> seaLevel);
|
||||
vale.setXShiftMultiplier(integer -> NumberUtil.map(integer, 50, 500, 0, 1));
|
||||
vale.addMixIn(new PlaneTerrainGenerator(gameHeight, Block.BARRIER));
|
||||
|
||||
eventNode().addListener(PlayerUseItemEvent.class, playerUseItemEvent -> {
|
||||
Player player = playerUseItemEvent.getPlayer();
|
||||
Material usedMaterial = playerUseItemEvent.getItemStack().material();
|
||||
|
||||
if(usedMaterial.equals(boostMaterial)) {
|
||||
if(!player.isFlyingWithElytra()) return;
|
||||
|
||||
boost(player);
|
||||
InventoryUtil.removeItemFromPlayer(player, boostMaterial, 1);
|
||||
} else if(usedMaterial.equals(resetMaterial)) {
|
||||
toCheckpoint(player);
|
||||
InventoryUtil.removeItemFromPlayer(player, resetMaterial, 1);
|
||||
}
|
||||
});
|
||||
|
||||
eventNode().addListener(PlayerStopFlyingWithElytraEvent.class, playerStopFlyingWithElytraEvent -> {
|
||||
Player player = playerStopFlyingWithElytraEvent.getPlayer();
|
||||
if(Position.blocksBelowPlayer(this, player).contains(ringMaterial.block())) {
|
||||
player.setFlyingWithElytra(true);
|
||||
boost(player);
|
||||
} else {
|
||||
toCheckpoint(player);
|
||||
// getScore().insertResult(playerStopFlyingWithElytraEvent.getPlayer());
|
||||
// playerStopFlyingWithElytraEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
});
|
||||
|
||||
eventNode().addListener(PlayerStartFlyingWithElytraEvent.class, playerStartFlyingWithElytraEvent -> {
|
||||
if(!isRunning) {
|
||||
playerStartFlyingWithElytraEvent.getPlayer().setFlyingWithElytra(false);
|
||||
return;
|
||||
}
|
||||
|
||||
boost(playerStartFlyingWithElytraEvent.getPlayer());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
Point spawnpoint = new Pos(vale.getXShiftAtZ(0), -46, 0);
|
||||
GeneratorUtils.iterateArea(spawnpoint.sub(5, 0, 5), spawnpoint.add(5, 0, 5), point -> setBlock(point, BlockPallet.STREET.rnd()));
|
||||
|
||||
generateRing(ringSpacing);
|
||||
generateRing(ringSpacing * 2);
|
||||
callback.complete(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
getPlayers().forEach(player -> {
|
||||
player.getInventory().setEquipment(EquipmentSlot.CHESTPLATE, (byte) 0, ItemStack.of(Material.ELYTRA));
|
||||
for(int i = 0; i < 3; i++) {
|
||||
player.getInventory().setItemStack(i, ItemStack.builder(boostMaterial).customName(TranslatedComponent.byId("boost").getAssembled(player)).build());
|
||||
}
|
||||
addResetItemToPlayer(player);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
Player player = playerMoveEvent.getPlayer();
|
||||
Point newPos = playerMoveEvent.getNewPosition();
|
||||
|
||||
if(isBeforeBeginning && playerMoveEvent.getNewPosition().y() < getSpawn().y()) {
|
||||
player.teleport(getSpawn());
|
||||
return;
|
||||
}
|
||||
|
||||
playerCheckpoints.putIfAbsent(player, new CheckPointData(ringSpacing, ringSpacing * 2));
|
||||
|
||||
if(newPos.z() > generatedUntil - ringSpacing) {
|
||||
generateRing(generatedUntil + ringSpacing);
|
||||
}
|
||||
|
||||
if(newPos.z() > playerCheckpoints.get(player).nextCheckpoint) {
|
||||
playerCheckpoints.put(player, playerCheckpoints.get(player).next(ringSpacing));
|
||||
boost(player);
|
||||
}
|
||||
|
||||
if(newPos.y() > gameHeight - 5) {
|
||||
Point particlePoint = newPos.withY(gameHeight);
|
||||
ParticlePacket particle = new ParticlePacket(
|
||||
Particle.WAX_ON,
|
||||
particlePoint.blockX(),
|
||||
particlePoint.blockY(),
|
||||
particlePoint.withZ(z -> z+10).blockZ(),
|
||||
20,
|
||||
0,
|
||||
30,
|
||||
1f,
|
||||
Math.toIntExact((long) NumberUtil.map(newPos.y(), gameHeight - 5, gameHeight, 50, 500))
|
||||
);
|
||||
player.sendPacket(particle);
|
||||
}
|
||||
|
||||
if(getBlock(player.getPosition()).equals(Block.WATER)) {
|
||||
toCheckpoint(player);
|
||||
}
|
||||
|
||||
if(newPos.z() > ringCount * ringSpacing) {
|
||||
getScore().insertResult(player);
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.setFlyingWithElytra(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(vale.getXShiftAtZ(0), -45, 0);
|
||||
}
|
||||
|
||||
private void addResetItemToPlayer(Player p) {
|
||||
p.getInventory().setItemStack(8, ItemStack.builder(resetMaterial).customName(TranslatedComponent.byId("reset").getAssembled(p)).build());
|
||||
}
|
||||
|
||||
private Point getRingPositionAtZ(int z) {
|
||||
return new Pos(vale.getXShiftAtZ(z), -45, z);
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> generateRing(int zPos) {
|
||||
if(zPos > ringCount * ringSpacing) return null;
|
||||
boolean isLast = (zPos == ringCount * ringSpacing);
|
||||
|
||||
generatedUntil = zPos;
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
|
||||
Point ringPos = getRingPositionAtZ(zPos);
|
||||
GeneratorUtils.iterateArea(
|
||||
ringPos.sub(100, 0, 0).withY(0),
|
||||
ringPos.add(100, 0, 0).withY(seaLevel),
|
||||
point -> batch.setBlock(point, Block.BARRIER)
|
||||
);
|
||||
GeneratorUtils.iterateArea(
|
||||
ringPos.sub(3, 3, 0),
|
||||
ringPos.add(3, 3, 0),
|
||||
point -> batch.setBlock(point, isLast ? Block.DIAMOND_BLOCK : ringMaterial.block())
|
||||
);
|
||||
GeneratorUtils.iterateArea(
|
||||
ringPos.sub(2, 2, 0),
|
||||
ringPos.add(2, 2, 0),
|
||||
point -> batch.setBlock(point, Block.AIR)
|
||||
);
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
||||
return null;
|
||||
}
|
||||
|
||||
private void boost(Player player) {
|
||||
player.playSound(Sound.sound(SoundEvent.ENTITY_FIREWORK_ROCKET_LAUNCH, Sound.Source.VOICE, 1f, 1f));
|
||||
|
||||
Vec playerVelocity = player.getPosition().direction();
|
||||
player.setVelocity(
|
||||
player.getVelocity().add(playerVelocity.mul(boostMultiplier))
|
||||
.withY(playerVelocity.withY(v -> v * boostMultiplier).y())
|
||||
);
|
||||
}
|
||||
|
||||
private void toCheckpoint(Player p) {
|
||||
Point checkpointPos = getRingPositionAtZ(playerCheckpoints.get(p).currentCheckpoint);
|
||||
p.setVelocity(Vec.ZERO);
|
||||
p.setFlyingWithElytra(false);
|
||||
p.teleport(Pos.fromPoint(checkpointPos).add(0.5, 0, 0.5));
|
||||
|
||||
p.setFlying(true);
|
||||
p.setFlyingSpeed(0);
|
||||
|
||||
new Countdown(TitleMessage.class)
|
||||
.countdown(
|
||||
Audience.audience(p),
|
||||
3,
|
||||
countdownModifier ->
|
||||
countdownModifier.message = new TitleMessage(
|
||||
Duration.ofMillis(300),
|
||||
Duration.ofMillis(700)
|
||||
)
|
||||
.subtitle(
|
||||
subtitleMessage ->
|
||||
subtitleMessage
|
||||
.appendStatic(Component.text("Launch in ", NamedTextColor.DARK_GREEN))
|
||||
.appendStatic(Component.text(countdownModifier.timeLeft, NamedTextColor.GREEN))
|
||||
.appendStatic(Component.text(" seconds", NamedTextColor.DARK_GREEN))
|
||||
)
|
||||
).thenRun(() -> {
|
||||
p.setFlying(false);
|
||||
p.setFlyingSpeed(1);
|
||||
p.setFlyingWithElytra(true);
|
||||
boost(p);
|
||||
addResetItemToPlayer(p);
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ElytraRaceFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_ElytraRace#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_ElytraRace#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.ELYTRA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("ringCount", Material.DIAMOND_BLOCK, TranslatedComponent.byId("game_ElytraRace#ringCount"), 5, 10, 20, 30, 40, 50));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||
return new ElytraRace(configuration.get("ringCount").getAsInt()).setParent(parent);
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.jumpDive;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class JumpDive extends StatelessGame {
|
||||
private final int radius;
|
||||
private final int height;
|
||||
private final int timeLimit;
|
||||
|
||||
private final WeakHashMap<Player, Integer> scores = new WeakHashMap<>();
|
||||
|
||||
public JumpDive(int radius, int height, int timeLimit) {
|
||||
super(Dimension.OVERWORLD.key, "jumpDive", new PointsWinScore());
|
||||
this.radius = radius;
|
||||
this.height = height;
|
||||
this.timeLimit = timeLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
|
||||
for(int x = -radius*2; x <= radius*2; x++) {
|
||||
for(int z = -radius*2; z <= radius*2; z++) {
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) {
|
||||
batch.setBlock(x, height, z, BlockPallet.STONE.rnd());
|
||||
} else {
|
||||
batch.setBlock(x, 0, z, BlockPallet.GROUND.rnd());
|
||||
batch.setBlock(x, 1, z, Block.WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
setTimeLimit(timeLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
Player p = playerMoveEvent.getPlayer();
|
||||
|
||||
if(
|
||||
p.isOnGround() && playerMoveEvent.getNewPosition().y() < height
|
||||
|| playerMoveEvent.getNewPosition().y() < 0
|
||||
|| isBeforeBeginning && playerMoveEvent.getNewPosition().y() < height
|
||||
) {
|
||||
p.teleport(getSpawn());
|
||||
playerMoveEvent.setCancelled(true);
|
||||
}
|
||||
|
||||
if(
|
||||
playerMoveEvent.getNewPosition().y() <= 1
|
||||
&& playerMoveEvent.getNewPosition().distance(0, 1, 0) < radius + 0.5
|
||||
&& !(!isBeforeBeginning && !isRunning)
|
||||
) {
|
||||
setBlock(playerMoveEvent.getNewPosition().withY(1), Block.REDSTONE_BLOCK);
|
||||
scores.merge(p, 1, Integer::sum);
|
||||
p.teleport(getSpawn());
|
||||
playerMoveEvent.setCancelled(true);
|
||||
p.playSound(Sound.sound(SoundEvent.ENTITY_EXPERIENCE_ORB_PICKUP, Sound.Source.PLAYER, 2f, 2f));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
getPlayers().forEach(player -> getScore().insertResult(player, scores.getOrDefault(player, 0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
double theta = rnd.nextDouble() * 2 * Math.PI;
|
||||
|
||||
double spawnRadius = radius + 2;
|
||||
double x = spawnRadius * Math.cos(theta);
|
||||
double z = spawnRadius * Math.sin(theta);
|
||||
|
||||
return new Pos(x, height + 2, z).withLookAt(new Pos(0, height, 0));
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.jumpDive;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class JumpDiveFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_jumpDive#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_jumpDive#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 5, 8, 10, 12, 14, 16))
|
||||
.addOption(new NumericOption("height", Material.SCAFFOLDING, TranslatedComponent.byId("optionCommon#height"), 30, 60, 90))
|
||||
.addOption(new NumericOption("timeLimit", Material.CLOCK, TranslatedComponent.byId("optionCommon#seconds"), 60, 120, 180, 240, 300));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||
return new JumpDive(configuration.get("radius").getAsInt(), configuration.get("height").getAsInt(), configuration.get("timeLimit").getAsInt()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.WATER_BUCKET;
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.util.CommonProperties;
|
||||
import eu.mhsl.minenet.minigames.util.Intersect;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.SquarePlateTerrainGenerator;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
class Minerun extends StatelessGame {
|
||||
|
||||
private final int minePercentage;
|
||||
private final int width;
|
||||
private final int length;
|
||||
|
||||
private final int preRun = 5;
|
||||
private final int afterMines = 2;
|
||||
private final int afterFinishLine = 10;
|
||||
|
||||
public Minerun(int width, int length, int minePercentage) {
|
||||
super(Dimension.THE_END.key, "Minerun", new FirstWinsScore());
|
||||
setGenerator(new SquarePlateTerrainGenerator(width, length + preRun + afterFinishLine).setPlateHeight(50).setGenerateBorders(true));
|
||||
|
||||
this.width = width;
|
||||
this.length = length;
|
||||
this.minePercentage = minePercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
int spawnToFinishLine = preRun + length + afterMines;
|
||||
|
||||
Random random = new Random();
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
|
||||
for(int x = 0; x <= width; x++) {
|
||||
for(int z = preRun; z <= length + preRun; z++) {
|
||||
|
||||
if (random.nextInt(0, 100) < minePercentage) {
|
||||
batch.setBlock(x, 50, z, BlockPallet.PRESSURE_PLATES.rnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int x = 0; x <= width; x++) {
|
||||
batch.setBlock(x, 49, spawnToFinishLine, Block.GOLD_BLOCK);
|
||||
batch.setBlock(x, 49, preRun, Block.GOLD_BLOCK);
|
||||
batch.setBlock(x, 50, preRun, Block.OAK_FENCE.withProperties(CommonProperties.fenceEastWest));
|
||||
}
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
for(int x = 0; x <= width; x++) {
|
||||
batch.setBlock(x, 50, preRun, Block.AIR);
|
||||
}
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> playSound(Sound.sound(SoundEvent.BLOCK_WOOD_BREAK, Sound.Source.BLOCK, 1f, 1f)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
|
||||
Player p = playerMoveEvent.getPlayer();
|
||||
Pos middle = playerMoveEvent.getNewPosition();
|
||||
|
||||
if(isBeforeBeginning && middle.z() > preRun+0.5) { //player cannot go forward before the game start
|
||||
playerMoveEvent.setCancelled(true);
|
||||
}
|
||||
|
||||
if(Intersect.withPressurePlate(this, BlockPallet.PRESSURE_PLATES, middle)) { //Player died
|
||||
p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.PLAYER, 1f, 1f));
|
||||
p.teleport(new Pos(p.getPosition().x(), getSpawn().y(), getSpawn().z()));
|
||||
}
|
||||
|
||||
if(middle.z() > preRun + length + afterMines) { // Player finished
|
||||
getScore().insertResult(p);
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos((double) width /2, 50, 3);
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MinerunFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Minerun#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("width", Material.OAK_FENCE, TranslatedComponent.byId("optionCommon#width"), 10, 30, 50, 100))
|
||||
.addOption(new NumericOption("length", Material.ZOMBIE_HEAD, TranslatedComponent.byId("optionCommon#length"), 50, 100, 150, 200))
|
||||
.addOption(new NumericOption("percentage", Material.LIGHT_WEIGHTED_PRESSURE_PLATE, TranslatedComponent.byId("game_Minerun#optionPercentageMines"), 30, 40, 50, 60, 70));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new Minerun(configuration.get("width").getAsInt(), configuration.get("length").getAsInt(), configuration.get("percentage").getAsInt()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.LIGHT_WEIGHTED_PRESSURE_PLATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Minerun#description");
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.event.player.PlayerStartDiggingEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class Spleef extends StatelessGame {
|
||||
int radius;
|
||||
int stackCount;
|
||||
|
||||
final int heightPerLevel = 20;
|
||||
final int totalElevation = 50;
|
||||
|
||||
public Spleef(int radius, int stackCount) {
|
||||
super(Dimension.OVERWORLD.key, "Spleef", new LastWinsScore());
|
||||
getScore().setIgnoreLastPlayers(1);
|
||||
|
||||
this.radius = radius;
|
||||
this.stackCount = stackCount;
|
||||
|
||||
setGenerator(new CircularPlateTerrainGenerator(50));
|
||||
|
||||
eventNode().addListener(PlayerStartDiggingEvent.class, this::destroyBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
AbsoluteBlockBatch circle = new AbsoluteBlockBatch();
|
||||
|
||||
for (int level = 0; level < stackCount; level++) {
|
||||
for(int x = -radius; x <= radius; x++) {
|
||||
for(int z = -radius; z <= radius; z++) {
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||
|
||||
circle.setBlock(x, totalElevation + (level * heightPerLevel), z, BlockPallet.WINTER.rnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BatchUtil.loadAndApplyBatch(circle, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
getPlayers().forEach(player -> {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.getInventory().addItemStack(
|
||||
ItemStack
|
||||
.builder(Material.DIAMOND_SHOVEL)
|
||||
.customName(TranslatedComponent.byId("game_Spleef#shovelName").getAssembled(player))
|
||||
.build()
|
||||
);
|
||||
player.setHeldItemSlot((byte) 0);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
if(playerMoveEvent.getNewPosition().y() < totalElevation) {
|
||||
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
playerMoveEvent.getPlayer().getInventory().clear();
|
||||
getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private void destroyBlock(PlayerStartDiggingEvent event) {
|
||||
if(!isRunning) return;
|
||||
setBlock(event.getBlockPosition(), Block.AIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, totalElevation + heightPerLevel * (stackCount-1) + 1, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.common.MinimalPlayeramountGameRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SpleefFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Spleef#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestrictionHandler globalRestrictions() {
|
||||
return new RestrictionHandler()
|
||||
.addRestriction(new MinimalPlayeramountGameRestriction(2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.DIAMOND_SHOVEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 10, 20, 30))
|
||||
.addOption(new NumericOption("stackCount", Material.SCAFFOLDING, TranslatedComponent.byId("game_Spleef#stackCount"), 1, 2, 3, 4, 5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Spleef#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||
return new Spleef(configuration.get("radius").getAsInt(), configuration.get("stackCount").getAsInt()).setParent(parent);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionHandler;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.common.MaximalPlayeramountGameRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.common.MinimalPlayeramountGameRestriction;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class StickFightFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Stickfight#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Stickfight#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 5, 7, 9, 11));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestrictionHandler globalRestrictions() {
|
||||
return new RestrictionHandler()
|
||||
.addRestriction(new MinimalPlayeramountGameRestriction(2))
|
||||
.addRestriction(new MaximalPlayeramountGameRestriction(4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new Stickfight().setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.STICK;
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||
import io.github.togar2.pvp.events.FinalAttackEvent;
|
||||
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class Stickfight extends StatelessGame {
|
||||
private final double radius = 20;
|
||||
private final WeakHashMap<Player, Pos> spawnPoints = new WeakHashMap<>();
|
||||
|
||||
public Stickfight() {
|
||||
super(Dimension.OVERWORLD.key, "Stickfight", new LastWinsScore());
|
||||
|
||||
eventNode().addChild(
|
||||
CombatFeatures.empty()
|
||||
.add(CombatFeatures.VANILLA_ATTACK)
|
||||
.add(CombatFeatures.VANILLA_DAMAGE)
|
||||
.add(CombatFeatures.VANILLA_KNOCKBACK)
|
||||
.build().createNode()
|
||||
);
|
||||
|
||||
eventNode().addListener(FinalAttackEvent.class, finalAttackEvent -> {
|
||||
finalAttackEvent.setBaseDamage(0);
|
||||
((Player) finalAttackEvent.getTarget()).setHealth(20);
|
||||
});
|
||||
|
||||
setGenerator(new CircularPlateTerrainGenerator(20));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
setBlock(0, 50, 0, Block.DIAMOND_BLOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void start() {
|
||||
List<Player> players = getPlayers().stream().toList();
|
||||
int numPlayers = players.size();
|
||||
|
||||
for (int i = 0; i < numPlayers; i++) {
|
||||
double angle = (2 * Math.PI / numPlayers) * i;
|
||||
int spawnX = (int) (radius * Math.cos(angle));
|
||||
int spawnZ = (int) (radius * Math.sin(angle));
|
||||
int spawnY = 50;
|
||||
|
||||
Pos spawnpoint = new Pos(spawnX, spawnY + 1, spawnZ).add(0.5);
|
||||
spawnPoints.put(players.get(i), spawnpoint.withLookAt(getSpawn()));
|
||||
players.get(i).teleport(spawnpoint);
|
||||
|
||||
generateBridge(spawnX, spawnY, spawnZ);
|
||||
}
|
||||
|
||||
setBlock(0, 50, 0, Block.GOLD_BLOCK);
|
||||
super.start();
|
||||
}
|
||||
|
||||
private void generateBridge(int startX, int startY, int startZ) {
|
||||
int steps = (int) (radius * 1.5);
|
||||
for (int i = 0; i < steps; i++) {
|
||||
double t = (double) i / steps;
|
||||
int x = (int) (startX * (1 - t));
|
||||
int z = (int) (startZ * (1 - t));
|
||||
setBlock(x, startY, z, Block.SANDSTONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
if(!spawnPoints.containsKey(playerMoveEvent.getPlayer())) {
|
||||
playerMoveEvent.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(isBeforeBeginning) {
|
||||
if(spawnPoints.get(playerMoveEvent.getPlayer()).distance(playerMoveEvent.getNewPosition()) < 1) return;
|
||||
playerMoveEvent.setCancelled(true);
|
||||
playerMoveEvent.getPlayer().teleport(spawnPoints.get(playerMoveEvent.getPlayer()));
|
||||
}
|
||||
|
||||
if(playerMoveEvent.getNewPosition().y() < 40) {
|
||||
playerMoveEvent.getPlayer().teleport(spawnPoints.get(playerMoveEvent.getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0.5, 51, 0.5);
|
||||
}
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.TetrisGame;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetromino;
|
||||
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.player.*;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class Tetris extends StatelessGame {
|
||||
private final Map<Player, TetrisGame> tetrisGames = new WeakHashMap<>();
|
||||
private final int nextTetrominoesCount;
|
||||
private final boolean isFast;
|
||||
private final boolean hasCombat;
|
||||
private boolean setTimeLimit = false;
|
||||
private final long randomSeed;
|
||||
|
||||
public Tetris(int nextTetrominoesCount, boolean isFast, boolean hasCombat) {
|
||||
super(Dimension.THE_END.key, "Tetris", new PointsWinScore());
|
||||
|
||||
this.eventNode()
|
||||
.addListener(PlayerUseItemEvent.class, this::onPlayerInteract)
|
||||
.addListener(PlayerHandAnimationEvent.class, this::onPlayerAttack)
|
||||
.addListener(PlayerTickEvent.class, this::onPlayerTick);
|
||||
|
||||
this.nextTetrominoesCount = nextTetrominoesCount;
|
||||
this.isFast = isFast;
|
||||
this.hasCombat = hasCombat;
|
||||
|
||||
Random random = new Random();
|
||||
this.randomSeed = random.nextLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
this.getEntities().stream()
|
||||
.filter(entity -> entity.getEntityType().equals(Tetromino.getGhostEntityType()))
|
||||
.forEach(Entity::remove);
|
||||
|
||||
if(this.hasCombat) {
|
||||
this.tetrisGames.values().forEach(tetrisGame -> tetrisGame.updateOtherTetrisGames(this.tetrisGames.values()));
|
||||
}
|
||||
|
||||
this.tetrisGames.forEach((player, tetrisGame) -> tetrisGame.start());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
this.tetrisGames.forEach((player, tetrisGame) -> {
|
||||
tetrisGame.loose();
|
||||
this.getScore().insertResult(player, tetrisGame.getScore());
|
||||
tetrisGame.sidebar.removeViewer(player);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerLeave(Player p) {
|
||||
this.tetrisGames.get(p).sidebar.removeViewer(p);
|
||||
this.letPlayerLoose(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Pos currentPosition = event.getNewPosition();
|
||||
|
||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
||||
|
||||
if(tetrisGame == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if(tetrisGame.lost) return;
|
||||
if(player.getGameMode() == GameMode.SPECTATOR) return;
|
||||
|
||||
if(player.inputs().forward()) tetrisGame.pressedButton(TetrisGame.Button.W);
|
||||
if(player.inputs().backward()) tetrisGame.pressedButton(TetrisGame.Button.S);
|
||||
if(player.inputs().right()) tetrisGame.pressedButton(TetrisGame.Button.D);
|
||||
if(player.inputs().left()) tetrisGame.pressedButton(TetrisGame.Button.A);
|
||||
if(player.inputs().jump()) tetrisGame.pressedButton(TetrisGame.Button.space);
|
||||
|
||||
event.setNewPosition(tetrisGame.getPlayerSpawnPosition().withView(currentPosition));
|
||||
player.setSprinting(false);
|
||||
}
|
||||
|
||||
protected void onPlayerInteract(@NotNull PlayerUseItemEvent event) {
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseRight);
|
||||
}
|
||||
|
||||
protected void onPlayerAttack(@NotNull PlayerHandAnimationEvent event) {
|
||||
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseLeft);
|
||||
}
|
||||
|
||||
protected void onPlayerTick(PlayerTickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
||||
if(tetrisGame == null) return;
|
||||
if(tetrisGame.lost && player.getGameMode() != GameMode.SPECTATOR) {
|
||||
this.letPlayerLoose(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void letPlayerLoose(Player player) {
|
||||
TetrisGame tetrisGame = this.tetrisGames.get(player);
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.setInvisible(true);
|
||||
this.getScore().insertResult(player, tetrisGame.getScore());
|
||||
|
||||
boolean allGamesLost = this.tetrisGames.values().stream()
|
||||
.filter(game -> !game.lost)
|
||||
.toList()
|
||||
.isEmpty();
|
||||
if(!this.setTimeLimit && !allGamesLost) {
|
||||
this.setTimeLimit(90);
|
||||
this.setTimeLimit = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onPlayerJoin(Player p) {
|
||||
p.getInventory().setItemStack(0, ItemStack.builder(Material.BIRCH_BUTTON).customName(Component.text("Controller")).build());
|
||||
p.setSprinting(false);
|
||||
|
||||
if(this.tetrisGames.get(p) == null) {
|
||||
this.tetrisGames.put(p, new TetrisGame(
|
||||
this,
|
||||
this.getSpawn().sub(6, 8, 15).add(this.tetrisGames.size()*30, 0, 0),
|
||||
Tetromino.Shape.J,
|
||||
this.nextTetrominoesCount,
|
||||
this.isFast,
|
||||
this.hasCombat,
|
||||
this.randomSeed
|
||||
));
|
||||
this.tetrisGames.get(p).generate();
|
||||
this.tetrisGames.values().forEach(tetrisGame -> tetrisGame.updateOtherTetrisGames(this.tetrisGames.values()));
|
||||
}
|
||||
|
||||
TetrisGame tetrisGame = this.tetrisGames.get(p);
|
||||
|
||||
p.teleport(tetrisGame.getPlayerSpawnPosition());
|
||||
tetrisGame.sidebar.addViewer(p);
|
||||
|
||||
return super.onPlayerJoin(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, 30, 15).withView(180, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.BoolOption;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TetrisFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Tetris#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Tetris#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("nextTetrominoesCount", Material.LADDER, TranslatedComponent.byId("game_Tetris#nextTetrominoesCount"), 3, 4, 5, 1, 2))
|
||||
.addOption(new BoolOption("isFast", Material.MINECART, TranslatedComponent.byId("game_Tetris#isFast")))
|
||||
.addOption(new BoolOption("hasCombat", Material.DIAMOND_SWORD, TranslatedComponent.byId("game_Tetris#hasCombat")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new Tetris(configuration.get("nextTetrominoesCount").getAsInt(), configuration.get("isFast").getAsBoolean(), configuration.get("hasCombat").getAsBoolean()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.PURPLE_WOOL;
|
||||
}
|
||||
}
|
@ -0,0 +1,191 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Playfield {
|
||||
private final Pos lowerLeftCorner;
|
||||
private final StatelessGame instance;
|
||||
private final static int height = 22;
|
||||
private final static Block scoreBlock = Block.STONE;
|
||||
private final int nextTetrominoesCount;
|
||||
private final Random random;
|
||||
|
||||
public Playfield(Pos lowerLeftCorner, StatelessGame instance, int nextTetrominoesCount) {
|
||||
this.nextTetrominoesCount = nextTetrominoesCount;
|
||||
this.lowerLeftCorner = lowerLeftCorner;
|
||||
this.instance = instance;
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public Pos getPlayerSpawnPosition() {
|
||||
return this.lowerLeftCorner.add(6, 9, 20).withView(180, 0);
|
||||
}
|
||||
|
||||
public Pos getTetrominoSpawnPosition() {
|
||||
return this.lowerLeftCorner.add(5, 21, 1);
|
||||
}
|
||||
|
||||
public Pos getHoldPosition() {
|
||||
return this.lowerLeftCorner.add(-4, 18, 1);
|
||||
}
|
||||
|
||||
public Pos getNextPosition() {
|
||||
return this.lowerLeftCorner.add(15, 18, 1);
|
||||
}
|
||||
|
||||
public Pos getScorePosition() {
|
||||
return this.lowerLeftCorner.add(-5, height+3, 0);
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
|
||||
// actual playfield:
|
||||
for(int x=0; x<12; x++) {
|
||||
for(int y = 0; y< height; y++) {
|
||||
batch.setBlock(this.lowerLeftCorner.add(x, y, 0), Block.GLASS);
|
||||
batch.setBlock(this.lowerLeftCorner.add(x, y, -1), Block.BLACK_CONCRETE);
|
||||
|
||||
if(x==0 || x==11 || y==0) {
|
||||
batch.setBlock(this.lowerLeftCorner.add(x, y, 1), Block.GRAY_CONCRETE);
|
||||
batch.setBlock(this.lowerLeftCorner.add(x, y, 0), Block.GRAY_CONCRETE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hold position:
|
||||
for(int x = 0; x < 4; x++) {
|
||||
for(int y = 0; y < 4; y++) {
|
||||
batch.setBlock(this.getHoldPosition().add(x-1, y-1, -1), Block.QUARTZ_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
// next positions:
|
||||
for(int x = 0; x < 4; x++) {
|
||||
for(int y = -4*this.nextTetrominoesCount+4; y < 4; y++) {
|
||||
batch.setBlock(this.getNextPosition().add(x-1, y-1, -1), Block.QUARTZ_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
batch.setBlock(this.getPlayerSpawnPosition().sub(0, 1, 0), Block.STONE);
|
||||
batch.setBlock(this.getPlayerSpawnPosition().sub(1, 1, 0), Block.STONE);
|
||||
batch.setBlock(this.getPlayerSpawnPosition().sub(1, 1, 1), Block.STONE);
|
||||
batch.setBlock(this.getPlayerSpawnPosition().sub(0, 1, 1), Block.STONE);
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this.instance, () -> {});
|
||||
}
|
||||
|
||||
public int removeFullLines() {
|
||||
int removedLinesCounter = 0;
|
||||
for(int y = 1; y< height; y++) {
|
||||
boolean isFullLine = true;
|
||||
for(int x=1; x<11; x++) {
|
||||
if(this.instance.getBlock(this.lowerLeftCorner.add(x, y, 1)) == Block.AIR) isFullLine = false;
|
||||
}
|
||||
if(isFullLine) {
|
||||
this.removeFullLine(y);
|
||||
removedLinesCounter += 1;
|
||||
y -= 1;
|
||||
}
|
||||
}
|
||||
return removedLinesCounter;
|
||||
}
|
||||
|
||||
public void addLines(int lines) {
|
||||
int xPosMissing = this.random.nextInt(1, 10);
|
||||
|
||||
for (int i = 0; i < lines; i++) {
|
||||
this.moveAllLinesUp();
|
||||
for (int x = 1; x < 11; x++) {
|
||||
if(x != xPosMissing) {
|
||||
this.instance.setBlock(this.lowerLeftCorner.add(x, 1, 1), Block.LIGHT_GRAY_CONCRETE);
|
||||
} else {
|
||||
this.instance.setBlock(this.lowerLeftCorner.add(x, 1, 1), Block.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAttackingLines(int attackingLines) {
|
||||
for (int y = 0; y < height + 5; y++) {
|
||||
if(attackingLines > 0) {
|
||||
this.instance.setBlock(this.lowerLeftCorner.add(12, y, 1), Block.REDSTONE_BLOCK);
|
||||
attackingLines -= 1;
|
||||
} else {
|
||||
this.instance.setBlock(this.lowerLeftCorner.add(12, y, 1), Block.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateScore(int score) {
|
||||
this.removeDigits();
|
||||
String scoreString = String.valueOf(score);
|
||||
char[] characters = scoreString.toCharArray();
|
||||
ArrayUtils.reverse(characters);
|
||||
for(int i = 6; i > 0; i--) {
|
||||
char digit;
|
||||
if(i <= characters.length) {
|
||||
digit = characters[i-1];
|
||||
} else {
|
||||
digit = '0';
|
||||
}
|
||||
this.displayDigit(digit, 6-i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void displayDigit(char digit, int positionFromLeft) {
|
||||
int[][] digitArray;
|
||||
switch (digit) {
|
||||
case '1' -> digitArray = new int[][]{{0,0,1},{0,1,1},{0,0,1},{0,0,1},{0,0,1}};
|
||||
case '2' -> digitArray = new int[][]{{1,1,1},{0,0,1},{1,1,1},{1,0,0},{1,1,1}};
|
||||
case '3' -> digitArray = new int[][]{{1,1,1},{0,0,1},{0,1,1},{0,0,1},{1,1,1}};
|
||||
case '4' -> digitArray = new int[][]{{1,0,1},{1,0,1},{1,1,1},{0,0,1},{0,0,1}};
|
||||
case '5' -> digitArray = new int[][]{{1,1,1},{1,0,0},{1,1,1},{0,0,1},{1,1,1}};
|
||||
case '6' -> digitArray = new int[][]{{1,1,1},{1,0,0},{1,1,1},{1,0,1},{1,1,1}};
|
||||
case '7' -> digitArray = new int[][]{{1,1,1},{0,0,1},{0,1,0},{0,1,0},{0,1,0}};
|
||||
case '8' -> digitArray = new int[][]{{1,1,1},{1,0,1},{1,1,1},{1,0,1},{1,1,1}};
|
||||
case '9' -> digitArray = new int[][]{{1,1,1},{1,0,1},{1,1,1},{0,0,1},{1,1,1}};
|
||||
default -> digitArray = new int[][]{{1,1,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1}};
|
||||
}
|
||||
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
if(digitArray[4-y][x] == 1) this.instance.setBlock(this.getScorePosition().add(positionFromLeft*4+x, y, 0), scoreBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeDigits() {
|
||||
for (int x = 0; x < 4 * 6; x++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
this.instance.setBlock(this.getScorePosition().add(x, y, 0), Block.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void moveAllLinesUp() {
|
||||
for (int y = height + 3; y > 1; y--) {
|
||||
for (int x = 1; x < 11; x++) {
|
||||
Block blockBeneath = this.instance.getBlock(this.lowerLeftCorner.add(x, y - 1, 1));
|
||||
this.instance.setBlock(this.lowerLeftCorner.add(x, y, 1), blockBeneath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFullLine(int positionY) {
|
||||
for(int y = positionY; y< height; y++) {
|
||||
for(int x=1; x<11; x++) {
|
||||
Block blockAbove = this.instance.getBlock(this.lowerLeftCorner.add(x, y+1, 1));
|
||||
this.instance.setBlock(this.lowerLeftCorner.add(x, y, 1), blockAbove);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,318 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.scoreboard.Sidebar;
|
||||
import net.minestom.server.timer.Scheduler;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TetrisGame {
|
||||
private final StatelessGame instance;
|
||||
private final Playfield playfield;
|
||||
private final boolean isFast;
|
||||
private int level = 1;
|
||||
private int lines = 0;
|
||||
private int score = 0;
|
||||
private int combo = 0;
|
||||
private int attackingLines = 0;
|
||||
public boolean lost = false;
|
||||
public boolean paused = true;
|
||||
private final boolean hasCombat;
|
||||
public Tetromino currentTetromino;
|
||||
private final List<Tetromino> nextTetrominoes = new ArrayList<>();
|
||||
private Tetromino holdTetromino;
|
||||
private final List<Tetromino> tetrominoBag = new ArrayList<>();
|
||||
private boolean holdPossible = true;
|
||||
private final Pos nextPosition;
|
||||
private final Pos holdPosition;
|
||||
private final Pos tetrominoSpawnPosition;
|
||||
public Sidebar sidebar = new Sidebar(Component.text("Info:"));
|
||||
private final Map<Button, Long> lastPresses = new HashMap<>();
|
||||
private final List<TetrisGame> otherTetrisGames = new ArrayList<>();
|
||||
private final Random random;
|
||||
|
||||
public enum Button {
|
||||
W,
|
||||
A,
|
||||
S,
|
||||
D,
|
||||
mouseLeft,
|
||||
mouseRight,
|
||||
space
|
||||
}
|
||||
|
||||
public TetrisGame(StatelessGame instance, Pos lowerLeftCorner, Tetromino.Shape startTetrominoShape, int nextTetrominoesCount, boolean isfast, boolean hasCombat, long randomSeed) {
|
||||
this.isFast = isfast;
|
||||
this.hasCombat = hasCombat;
|
||||
this.instance = instance;
|
||||
this.playfield = new Playfield(lowerLeftCorner, this.instance, nextTetrominoesCount);
|
||||
this.random = new Random(randomSeed);
|
||||
|
||||
this.holdPosition = this.playfield.getHoldPosition();
|
||||
this.nextPosition = this.playfield.getNextPosition();
|
||||
this.tetrominoSpawnPosition = this.playfield.getTetrominoSpawnPosition();
|
||||
this.buildSidebar();
|
||||
|
||||
this.currentTetromino = new Tetromino(this.instance, startTetrominoShape);
|
||||
for (int i = 0; i < nextTetrominoesCount; i++) {
|
||||
this.updateNextTetrominoes();
|
||||
}
|
||||
}
|
||||
|
||||
public void pressedButton(Button button) {
|
||||
final int standardButtonDelay = 100;
|
||||
final int buttonDebounce = 70;
|
||||
|
||||
if(this.lastPresses.getOrDefault(button, 0L) >= System.currentTimeMillis()-standardButtonDelay) return;
|
||||
|
||||
this.lastPresses.put(button, System.currentTimeMillis());
|
||||
if(button == Button.W) this.lastPresses.put(button, System.currentTimeMillis()+buttonDebounce);
|
||||
if(button == Button.S) this.lastPresses.put(button, System.currentTimeMillis()-buttonDebounce);
|
||||
|
||||
if(this.lost || this.paused) return;
|
||||
|
||||
switch (button) {
|
||||
case A -> this.currentTetromino.moveLeft();
|
||||
case S -> this.moveDown();
|
||||
case D -> this.currentTetromino.moveRight();
|
||||
case W -> this.hardDrop();
|
||||
case mouseLeft -> this.currentTetromino.rotate(false);
|
||||
case mouseRight -> this.currentTetromino.rotate(true);
|
||||
case space -> this.switchHold();
|
||||
}
|
||||
}
|
||||
|
||||
public Pos getPlayerSpawnPosition() {
|
||||
return this.playfield.getPlayerSpawnPosition();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.paused = false;
|
||||
Scheduler scheduler = MinecraftServer.getSchedulerManager();
|
||||
scheduler.submitTask(() -> {
|
||||
if(this.lost) return TaskSchedule.stop();
|
||||
int standardTickDelay = 40;
|
||||
if(this.isFast) standardTickDelay = 20;
|
||||
|
||||
TaskSchedule nextTick = TaskSchedule.tick(Math.round((float) standardTickDelay /this.level));
|
||||
if(this.paused) return nextTick;
|
||||
this.tick();
|
||||
return nextTick;
|
||||
});
|
||||
|
||||
this.updateInfo();
|
||||
this.nextTetrominoes.forEach(tetromino -> {
|
||||
double xChange = -tetromino.getXChange();
|
||||
tetromino.setPosition(this.nextPosition.sub(xChange, 4*this.nextTetrominoes.indexOf(tetromino), 0));
|
||||
tetromino.drawAsEntities();
|
||||
});
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
this.playfield.generate();
|
||||
|
||||
this.currentTetromino.setPosition(this.tetrominoSpawnPosition);
|
||||
this.currentTetromino.draw(false);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
if(this.lost || this.paused) return;
|
||||
if(!this.currentTetromino.moveDown()) {
|
||||
this.setActiveTetrominoDown();
|
||||
}
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return this.score;
|
||||
}
|
||||
|
||||
public void updateOtherTetrisGames(Collection<TetrisGame> tetrisGames) {
|
||||
List<TetrisGame> games = new ArrayList<>(tetrisGames);
|
||||
games.remove(this);
|
||||
games.removeIf(tetrisGame -> tetrisGame.lost);
|
||||
this.otherTetrisGames.clear();
|
||||
this.otherTetrisGames.addAll(games);
|
||||
}
|
||||
|
||||
public void getAttacked(int lines) {
|
||||
if(this.hasCombat && !this.lost) {
|
||||
this.attackingLines += lines;
|
||||
this.playfield.updateAttackingLines(this.attackingLines);
|
||||
}
|
||||
}
|
||||
|
||||
public void loose() {
|
||||
this.lost = true;
|
||||
}
|
||||
|
||||
|
||||
private boolean moveDown() {
|
||||
if(!this.currentTetromino.moveDown()) {
|
||||
this.setActiveTetrominoDown();
|
||||
return false;
|
||||
}
|
||||
this.score += 1;
|
||||
this.updateInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hardDrop() {
|
||||
if(!this.currentTetromino.moveDown()) {
|
||||
this.setActiveTetrominoDown();
|
||||
return false;
|
||||
}
|
||||
this.score += 2;
|
||||
this.updateInfo();
|
||||
while(this.currentTetromino.moveDown()) {
|
||||
this.score += 2;
|
||||
this.updateInfo();
|
||||
}
|
||||
this.setActiveTetrominoDown();
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean switchHold() {
|
||||
if(!this.holdPossible) return false;
|
||||
|
||||
Tetromino newCurrentTetromino;
|
||||
if(this.holdTetromino == null) {
|
||||
newCurrentTetromino = this.nextTetrominoes.removeFirst();
|
||||
newCurrentTetromino.remove();
|
||||
this.updateNextTetrominoes();
|
||||
} else {
|
||||
newCurrentTetromino = this.holdTetromino;
|
||||
this.holdTetromino.remove();
|
||||
}
|
||||
|
||||
this.currentTetromino.remove();
|
||||
this.holdTetromino = new Tetromino(this.instance, this.currentTetromino.getShape());
|
||||
this.currentTetromino = newCurrentTetromino;
|
||||
|
||||
this.currentTetromino.setPosition(this.tetrominoSpawnPosition);
|
||||
this.currentTetromino.draw();
|
||||
if(!this.currentTetromino.moveDown()) this.loose();
|
||||
|
||||
double xChange = this.holdTetromino.getXChange();
|
||||
this.holdTetromino.setPosition(this.holdPosition.add(xChange, 0, 0));
|
||||
this.holdTetromino.drawAsEntities();
|
||||
this.holdPossible = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void updateNextTetrominoes() {
|
||||
if(this.tetrominoBag.isEmpty()) {
|
||||
for(Tetromino.Shape shape : Tetromino.Shape.values()) {
|
||||
this.tetrominoBag.add(new Tetromino(this.instance, shape));
|
||||
}
|
||||
Collections.shuffle(this.tetrominoBag, this.random);
|
||||
}
|
||||
|
||||
if(!this.nextTetrominoes.isEmpty()) this.nextTetrominoes.forEach(Tetromino::remove);
|
||||
Tetromino newTetromino = this.tetrominoBag.removeFirst();
|
||||
this.nextTetrominoes.add(newTetromino);
|
||||
this.nextTetrominoes.forEach(tetromino -> {
|
||||
double xChange = -tetromino.getXChange();
|
||||
tetromino.setPosition(this.nextPosition.sub(xChange, 4*this.nextTetrominoes.indexOf(tetromino), 0));
|
||||
tetromino.drawAsEntities();
|
||||
});
|
||||
}
|
||||
|
||||
private void buildSidebar() {
|
||||
this.sidebar.createLine(new Sidebar.ScoreboardLine(
|
||||
"0",
|
||||
Component.text("Score: "),
|
||||
0
|
||||
));
|
||||
this.sidebar.createLine(new Sidebar.ScoreboardLine(
|
||||
"1",
|
||||
Component.text("Lines: "),
|
||||
0
|
||||
));
|
||||
this.sidebar.createLine(new Sidebar.ScoreboardLine(
|
||||
"2",
|
||||
Component.text("Level: "),
|
||||
1
|
||||
));
|
||||
}
|
||||
|
||||
private void updateInfo() {
|
||||
this.playfield.updateScore(this.score);
|
||||
this.sidebar.updateLineScore("0", this.score);
|
||||
this.sidebar.updateLineScore("1", this.lines);
|
||||
this.sidebar.updateLineScore("2", this.level);
|
||||
}
|
||||
|
||||
private void setActiveTetrominoDown() {
|
||||
this.currentTetromino.removeOwnEntities();
|
||||
this.currentTetromino = this.nextTetrominoes.removeFirst();
|
||||
this.currentTetromino.remove();
|
||||
this.updateNextTetrominoes();
|
||||
|
||||
int removedLines = this.playfield.removeFullLines();
|
||||
int combatLines = 0;
|
||||
this.combo += 1;
|
||||
switch (removedLines) {
|
||||
case 0 -> this.combo = 0;
|
||||
case 1 -> {
|
||||
this.lines += 1;
|
||||
this.score += 40 * this.level;
|
||||
}
|
||||
case 2 -> {
|
||||
combatLines = 1;
|
||||
this.lines += 2;
|
||||
this.score += 100 * this.level;
|
||||
}
|
||||
case 3 -> {
|
||||
combatLines = 2;
|
||||
this.lines += 3;
|
||||
this.score += 300 * this.level;
|
||||
}
|
||||
case 4 -> {
|
||||
combatLines = 4;
|
||||
this.lines += 4;
|
||||
this.score += 1200 * this.level;
|
||||
}
|
||||
}
|
||||
|
||||
this.score += 50 * this.combo * this.level;
|
||||
if(this.combo >= 2) {
|
||||
combatLines += (int) Math.floor((double) this.combo /2);
|
||||
}
|
||||
|
||||
if(this.hasCombat && this.attackingLines > 0) {
|
||||
if(combatLines > 0 && this.attackingLines >= combatLines) {
|
||||
this.attackingLines -= combatLines;
|
||||
combatLines = 0;
|
||||
} else if(combatLines > 0) {
|
||||
combatLines -= this.attackingLines;
|
||||
this.attackingLines = 0;
|
||||
} else {
|
||||
this.playfield.addLines(this.attackingLines);
|
||||
this.attackingLines = 0;
|
||||
}
|
||||
|
||||
this.playfield.updateAttackingLines(this.attackingLines);
|
||||
}
|
||||
|
||||
if(this.hasCombat && !this.otherTetrisGames.isEmpty()) {
|
||||
Collections.shuffle(this.otherTetrisGames);
|
||||
this.otherTetrisGames.getFirst().getAttacked(combatLines);
|
||||
}
|
||||
|
||||
this.level = (int) Math.floor((double) this.lines / 10) + 1;
|
||||
this.holdPossible = true;
|
||||
|
||||
this.updateInfo();
|
||||
|
||||
this.currentTetromino.setPosition(this.tetrominoSpawnPosition);
|
||||
this.currentTetromino.draw();
|
||||
if(!this.currentTetromino.moveDown()) {
|
||||
this.loose();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,246 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.metadata.other.FallingBlockMeta;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.tag.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Tetromino {
|
||||
private final Shape shape;
|
||||
private final StatelessGame instance;
|
||||
private Pos position;
|
||||
private int[][] shapeArray;
|
||||
private final static EntityType ghostEntityType = EntityType.FALLING_BLOCK;
|
||||
private final UUID uuid;
|
||||
private final static Tag<String> uuidTag = Tag.String("uuid");
|
||||
|
||||
public enum Shape {
|
||||
I,
|
||||
J,
|
||||
L,
|
||||
O,
|
||||
S,
|
||||
T,
|
||||
Z
|
||||
}
|
||||
|
||||
public Tetromino(StatelessGame instance, Shape shape) {
|
||||
this.instance = instance;
|
||||
this.shape = shape;
|
||||
this.uuid = UUID.randomUUID();
|
||||
|
||||
switch (this.shape) {
|
||||
case I -> this.shapeArray = new int[][]{{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}};
|
||||
case J -> this.shapeArray = new int[][]{{1,0,0}, {1,1,1}, {0,0,0}};
|
||||
case L -> this.shapeArray = new int[][]{{0,0,1}, {1,1,1}, {0,0,0}};
|
||||
case O -> this.shapeArray = new int[][]{{1,1}, {1,1}};
|
||||
case S -> this.shapeArray = new int[][]{{0,1,1}, {1,1,0}, {0,0,0}};
|
||||
case T -> this.shapeArray = new int[][]{{0,1,0}, {1,1,1}, {0,0,0}};
|
||||
case Z -> this.shapeArray = new int[][]{{1,1,0}, {0,1,1}, {0,0,0}};
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityType getGhostEntityType() {
|
||||
return ghostEntityType;
|
||||
}
|
||||
|
||||
public void setPosition(Pos newPosition) {
|
||||
this.position = newPosition;
|
||||
}
|
||||
|
||||
public boolean rotate(boolean clockwise) {
|
||||
int[][] newShapeArray = this.getTurnedShapeArray(clockwise);
|
||||
return this.checkCollisionAndMove(this.position, newShapeArray);
|
||||
}
|
||||
|
||||
public boolean moveDown() {
|
||||
Pos newPosition = this.position.sub(0, 1, 0);
|
||||
return this.checkCollisionAndMove(newPosition, this.shapeArray);
|
||||
}
|
||||
|
||||
public boolean moveLeft() {
|
||||
Pos newPosition = this.position.sub(1, 0, 0);
|
||||
return this.checkCollisionAndMove(newPosition, this.shapeArray);
|
||||
}
|
||||
|
||||
public boolean moveRight() {
|
||||
Pos newPosition = this.position.add(1, 0, 0);
|
||||
return this.checkCollisionAndMove(newPosition, this.shapeArray);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
this.draw(true);
|
||||
}
|
||||
|
||||
public void draw(boolean withGhost) {
|
||||
if(withGhost) {
|
||||
Pos ghostPos = this.position;
|
||||
while (!this.checkCollision(ghostPos.sub(0, 1, 0), this.shapeArray)) {
|
||||
ghostPos = ghostPos.sub(0, 1, 0);
|
||||
}
|
||||
Pos positionChange = this.position.sub(ghostPos);
|
||||
this.getBlockPositions().forEach(pos -> {
|
||||
Entity ghostBlock = new Entity(ghostEntityType);
|
||||
((FallingBlockMeta) ghostBlock.getEntityMeta()).setBlock(this.getGhostBlock());
|
||||
ghostBlock.setNoGravity(true);
|
||||
ghostBlock.setGlowing(true);
|
||||
ghostBlock.setTag(uuidTag, this.uuid.toString());
|
||||
ghostBlock.setInstance(this.instance, pos.sub(positionChange).add(0.5, 0, 0.5));
|
||||
});
|
||||
}
|
||||
|
||||
this.getBlockPositions().forEach(pos -> this.instance.setBlock(pos, this.getColoredBlock()));
|
||||
}
|
||||
|
||||
public void drawAsEntities() {
|
||||
this.getBlockPositions().forEach(pos -> {
|
||||
Entity ghostBlock = new Entity(ghostEntityType);
|
||||
((FallingBlockMeta) ghostBlock.getEntityMeta()).setBlock(this.getColoredBlock());
|
||||
ghostBlock.setNoGravity(true);
|
||||
ghostBlock.setTag(uuidTag, this.uuid.toString());
|
||||
ghostBlock.setInstance(this.instance, pos.add(0.5, 0, 0.5));
|
||||
});
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
this.removeOwnEntities();
|
||||
this.getBlockPositions().forEach(pos -> this.instance.setBlock(pos, Block.AIR));
|
||||
}
|
||||
|
||||
public Block getColoredBlock() {
|
||||
Block returnBlock;
|
||||
switch (this.shape) {
|
||||
case I -> returnBlock = Block.LIGHT_BLUE_CONCRETE;
|
||||
case J -> returnBlock = Block.BLUE_CONCRETE;
|
||||
case L -> returnBlock = Block.ORANGE_CONCRETE;
|
||||
case O -> returnBlock = Block.YELLOW_CONCRETE;
|
||||
case S -> returnBlock = Block.GREEN_CONCRETE;
|
||||
case T -> returnBlock = Block.PURPLE_CONCRETE;
|
||||
case Z -> returnBlock = Block.RED_CONCRETE;
|
||||
default -> returnBlock = Block.WHITE_CONCRETE;
|
||||
}
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
public void removeOwnEntities() {
|
||||
this.instance.getEntities().stream()
|
||||
.filter(entity -> {
|
||||
String tagValue = entity.getTag(uuidTag);
|
||||
if(tagValue == null) return false;
|
||||
return entity.getTag(uuidTag).equals(this.uuid.toString());
|
||||
})
|
||||
.forEach(Entity::remove);
|
||||
}
|
||||
|
||||
public double getXChange() {
|
||||
switch (this.shape) {
|
||||
case O, I -> {
|
||||
return 0;
|
||||
}
|
||||
case null, default -> {
|
||||
return 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Shape getShape() {
|
||||
return this.shape;
|
||||
}
|
||||
|
||||
private Block getGhostBlock() {
|
||||
Block returnBlock;
|
||||
switch (this.shape) {
|
||||
case I -> returnBlock = Block.LIGHT_BLUE_STAINED_GLASS;
|
||||
case J -> returnBlock = Block.BLUE_STAINED_GLASS;
|
||||
case L -> returnBlock = Block.ORANGE_STAINED_GLASS;
|
||||
case O -> returnBlock = Block.YELLOW_STAINED_GLASS;
|
||||
case S -> returnBlock = Block.GREEN_STAINED_GLASS;
|
||||
case T -> returnBlock = Block.PURPLE_STAINED_GLASS;
|
||||
case Z -> returnBlock = Block.RED_STAINED_GLASS;
|
||||
default -> returnBlock = Block.WHITE_STAINED_GLASS;
|
||||
}
|
||||
return returnBlock;
|
||||
}
|
||||
|
||||
private int[][] getTurnedShapeArray(boolean clockwise) {
|
||||
int iterations = 1;
|
||||
if(!clockwise) iterations = 3;
|
||||
|
||||
int arrayLength = this.shapeArray.length;
|
||||
int[][] startArray = Arrays.stream(this.shapeArray).map(int[]::clone).toArray(int[][]::new);
|
||||
int[][] returnArray = new int[arrayLength][arrayLength];
|
||||
|
||||
for(int k=0; k<iterations; k++) {
|
||||
for(int i=0; i<arrayLength; i++) {
|
||||
for(int j=0; j<arrayLength; j++) {
|
||||
returnArray[i][arrayLength-1-j] = startArray[j][i];
|
||||
}
|
||||
}
|
||||
startArray = Arrays.stream(returnArray).map(int[]::clone).toArray(int[][]::new);
|
||||
}
|
||||
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
private boolean isPartOfTetromino(Pos position) {
|
||||
return this.getBlockPositions().stream()
|
||||
.anyMatch(pos -> pos.equals(position));
|
||||
}
|
||||
|
||||
private List<Pos> getBlockPositions() {
|
||||
return this.getBlockPositions(this.position, this.shapeArray);
|
||||
}
|
||||
|
||||
private List<Pos> getBlockPositions(Pos position, int[][] shapeArray) {
|
||||
List<Pos> returnList = new ArrayList<>();
|
||||
if(position == null) return returnList;
|
||||
|
||||
int arrayLength = shapeArray.length;
|
||||
|
||||
for(int x=0; x<arrayLength; x++) {
|
||||
for(int y=0; y<arrayLength; y++) {
|
||||
if(shapeArray[arrayLength-1-y][x] == 1) {
|
||||
switch (this.shape) {
|
||||
case I -> returnList.add(position.add(x-1, y-2, 0));
|
||||
case O -> returnList.add(position.add(x, y, 0));
|
||||
default -> returnList.add(position.add(x-1, y-1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnList;
|
||||
}
|
||||
|
||||
private boolean checkCollision(Pos newPosition, int[][] newShapeArray) {
|
||||
List<Pos> newBlockPositions = this.getBlockPositions(newPosition, newShapeArray);
|
||||
|
||||
for(Pos pos : newBlockPositions) {
|
||||
if(this.isPartOfTetromino(pos)) continue;
|
||||
if(this.instance.getBlock(pos) == this.getGhostBlock()) continue;
|
||||
if(this.instance.getBlock(pos) != Block.AIR) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkCollisionAndMove(Pos newPosition, int[][] newShapeArray) {
|
||||
if(!this.checkCollision(newPosition, newShapeArray)) {
|
||||
this.remove();
|
||||
this.shapeArray = Arrays.stream(newShapeArray).map(int[]::clone).toArray(int[][]::new);
|
||||
this.setPosition(newPosition);
|
||||
this.draw();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.tntrun;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.timer.ExecutionType;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TntRun extends StatelessGame {
|
||||
final int totalElevation = 50;
|
||||
final int heightPerLevel = 20;
|
||||
|
||||
final int radius;
|
||||
final int stackCount;
|
||||
public TntRun(int radius, int stackCount) {
|
||||
super(Dimension.OVERWORLD.key, "tntRun", new LastWinsScore());
|
||||
this.radius = radius;
|
||||
this.stackCount = stackCount;
|
||||
setGenerator(new CircularPlateTerrainGenerator(radius));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
for (int level = 0; level < stackCount; level++) {
|
||||
for(int x = -radius; x <= radius; x++) {
|
||||
for(int z = -radius; z <= radius; z++) {
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||
|
||||
batch.setBlock(x, totalElevation + (level * heightPerLevel), z, Block.TNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
|
||||
|
||||
if(playerMoveEvent.getNewPosition().y() < totalElevation) {
|
||||
if(isBeforeBeginning) {
|
||||
playerMoveEvent.getPlayer().teleport(getSpawn());
|
||||
return;
|
||||
}
|
||||
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
}
|
||||
|
||||
if(isRunning && !getScore().hasResult(playerMoveEvent.getPlayer())) {
|
||||
MinecraftServer.getSchedulerManager().scheduleTask(() -> {
|
||||
float radius = 0.5F;
|
||||
for (float x = -radius; x <= radius; x++) {
|
||||
for (float z = -radius; z <= radius; z++) {
|
||||
Pos firstLocation = playerMoveEvent.getNewPosition().add(x, -1, z);
|
||||
Pos secondLocation = firstLocation.withY(y -> y-1);
|
||||
if(!getBlock(firstLocation).isAir() || !getBlock(secondLocation).isAir()) {
|
||||
setBlock(firstLocation, Block.AIR);
|
||||
setBlock(secondLocation, Block.AIR);
|
||||
|
||||
// Entity fallingTnt = new Entity(EntityType.TNT);
|
||||
// PrimedTntMeta fallingTntMeta = (PrimedTntMeta) fallingTnt.getEntityMeta();
|
||||
// fallingTntMeta.setFuseTime(20);
|
||||
// fallingTnt.setInstance(this, secondLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, TaskSchedule.millis(500), TaskSchedule.stop(), ExecutionType.TICK_END);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos(0, totalElevation + heightPerLevel * (stackCount-1) + 1, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.tntrun;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TntRunFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_TntRun#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_TntRun#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.TNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("radius", Material.STICK, TranslatedComponent.byId("optionCommon#radius"), 20, 30, 50, 60))
|
||||
.addOption(new NumericOption("levels", Material.SCAFFOLDING, TranslatedComponent.byId("game_TntRun#levels"), 1, 2, 3, 4, 5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||
return new TntRun(configuration.get("radius").getAsInt(), configuration.get("levels").getAsInt()).setParent(parent);
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.generator.MazeGenerator;
|
||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Towerdefense extends StatelessGame {
|
||||
private final Random random = new Random();
|
||||
private final AbsoluteBlockBatch mazeBatch = new AbsoluteBlockBatch();
|
||||
private final List<Pos> mazePath = new ArrayList<>();
|
||||
private List<TowerdefenseRoom> instances = new ArrayList<>();
|
||||
|
||||
public Towerdefense() {
|
||||
super(Dimension.NETHER.key, "Towerdefense", new LastWinsScore());
|
||||
|
||||
setGenerator(new MazeGenerator());
|
||||
this.generateMaze();
|
||||
}
|
||||
|
||||
private void generateMaze() {
|
||||
Pos position = new Pos(0, 0, 0);
|
||||
this.addMazePosition(position, Block.GREEN_WOOL);
|
||||
|
||||
List<Integer> previousDirections = new ArrayList<>();
|
||||
int direction = 1; // 0 -> right; 1 -> straight; 2 -> left
|
||||
for (int i = 0; i < 9; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
position = position.add(direction-1,0,direction%2);
|
||||
this.addMazePosition(position, Block.WHITE_WOOL);
|
||||
}
|
||||
|
||||
int origin = 0;
|
||||
int bound = 3;
|
||||
long rightLeftDifference = previousDirections.stream().filter(integer -> integer == 0).count() - previousDirections.stream().filter(integer -> integer == 2).count();
|
||||
if(rightLeftDifference >= 2 || direction == 2) origin = 1;
|
||||
if(rightLeftDifference <= -2 || direction == 0) bound = 2;
|
||||
direction = this.random.nextInt(origin, bound);
|
||||
previousDirections.add(direction);
|
||||
}
|
||||
this.addMazePosition(position, Block.WHITE_WOOL);
|
||||
this.addMazePosition(position.add(0,0,1), Block.WHITE_WOOL);
|
||||
this.addMazePosition(position.add(0,0,2), Block.RED_WOOL);
|
||||
}
|
||||
|
||||
private void addMazePosition(Pos position, Block pathBlock) {
|
||||
this.mazeBatch.setBlock(position, pathBlock);
|
||||
this.mazePath.add(position.add(0.5,1,0.5));
|
||||
}
|
||||
|
||||
public AbsoluteBlockBatch getMazeBatch() {
|
||||
return this.mazeBatch;
|
||||
}
|
||||
|
||||
public List<Pos> getMazePath() {
|
||||
return this.mazePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onPlayerJoin(Player p) {
|
||||
TowerdefenseRoom newRoom = new TowerdefenseRoom(p, this);
|
||||
this.instances.add(newRoom);
|
||||
p.setInstance(newRoom);
|
||||
newRoom.startWave(List.of(EntityType.ENDERMAN, EntityType.BLAZE, EntityType.PLAYER, EntityType.HORSE, EntityType.ARMOR_STAND, EntityType.SKELETON));
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TowerdefenseFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_Towerdefense#name");
|
||||
}
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.ARMOR_STAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_Towerdefense#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new Towerdefense().setParent(parent);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.generator.MazeGenerator;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.entity.*;
|
||||
import net.minestom.server.entity.attribute.Attribute;
|
||||
import net.minestom.server.instance.InstanceContainer;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TowerdefenseRoom extends InstanceContainer {
|
||||
private final Player player;
|
||||
private final Towerdefense game;
|
||||
|
||||
public TowerdefenseRoom(Player player, Towerdefense game) {
|
||||
super(UUID.randomUUID(), Dimension.OVERWORLD.key);
|
||||
MinecraftServer.getInstanceManager().registerInstance(this);
|
||||
this.player = player;
|
||||
this.game = game;
|
||||
this.player.setGameMode(GameMode.ADVENTURE);
|
||||
this.player.setAllowFlying(true);
|
||||
this.player.getInventory().setItemStack(0, ItemStack.of(Material.ARMOR_STAND));
|
||||
|
||||
setGenerator(new MazeGenerator());
|
||||
BatchUtil.loadAndApplyBatch(this.game.getMazeBatch(), this, () -> {});
|
||||
}
|
||||
|
||||
public void startWave(List<EntityType> entities) {
|
||||
int counter = 0;
|
||||
for(EntityType entityType : entities) {
|
||||
MinecraftServer.getSchedulerManager().scheduleTask(() -> {
|
||||
this.addEntity(new EntityCreature(entityType));
|
||||
return TaskSchedule.stop();
|
||||
}, TaskSchedule.millis(800L*counter));
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
private void addEntity(EntityCreature entity) {
|
||||
entity.setInstance(this, this.game.getMazePath().getFirst());
|
||||
entity.getAttribute(Attribute.MOVEMENT_SPEED).setBaseValue(0.15);
|
||||
entity.getNavigator().setPathTo(this.game.getMazePath().get(1), 0.7, () -> changeEntityGoal(entity, 1));
|
||||
}
|
||||
|
||||
private void changeEntityGoal(EntityCreature entity, int positionIndex) {
|
||||
if(positionIndex == this.game.getMazePath().size()-1) {
|
||||
return;
|
||||
}
|
||||
entity.getNavigator().setPathTo(this.game.getMazePath().get(positionIndex+1), 0.7, () -> changeEntityGoal(entity, positionIndex+1));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.generator;
|
||||
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.generator.GenerationUnit;
|
||||
import net.minestom.server.instance.generator.Generator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MazeGenerator implements Generator {
|
||||
@Override
|
||||
public void generate(@NotNull GenerationUnit unit) {
|
||||
unit.modifier().fillHeight(0, 1, Block.BLACK_WOOL);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
enum LightPhase {
|
||||
RED(Material.RED_WOOL, 1000, 5000),
|
||||
YELLOW(Material.YELLOW_WOOL, 500, 1500),
|
||||
GREEN(Material.GREEN_WOOL, 2000, 5000);
|
||||
|
||||
public final ItemStack item;
|
||||
private final int minDuration;
|
||||
private final int maxDuration;
|
||||
private static final Random rnd = new Random();
|
||||
|
||||
LightPhase(Material material, int minDuration, int maxDuration) {
|
||||
this.item = ItemStack.of(material);
|
||||
this.minDuration = minDuration;
|
||||
this.maxDuration = maxDuration;
|
||||
}
|
||||
|
||||
public TaskSchedule taskScheduleRandomDuration() {
|
||||
return TaskSchedule.millis(rnd.nextLong(minDuration, maxDuration));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace;
|
||||
|
||||
import de.articdive.jnoise.JNoise;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||
import eu.mhsl.minenet.minigames.util.CommonProperties;
|
||||
import eu.mhsl.minenet.minigames.world.BlockPallet;
|
||||
import eu.mhsl.minenet.minigames.world.generator.terrain.SquarePlateTerrainGenerator;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import net.minestom.server.timer.ExecutionType;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class TrafficLightRace extends StatelessGame {
|
||||
private LightPhase phase = LightPhase.RED;
|
||||
private int phaseCounter = 0;
|
||||
|
||||
private final int width;
|
||||
private final int length;
|
||||
private final int preRun = 10;
|
||||
private final int afterRun = 10;
|
||||
|
||||
private final List<Pos> trafficLights = new ArrayList<>();
|
||||
|
||||
public TrafficLightRace(int width, int length) {
|
||||
super(Dimension.THE_END.key, "Ampelrennen", new FirstWinsScore());
|
||||
this.width = width;
|
||||
this.length = length;
|
||||
|
||||
setGenerator(
|
||||
new SquarePlateTerrainGenerator(width, length + preRun + afterRun)
|
||||
.setPlateHeight(50)
|
||||
.setGenerateBorders(true)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
final JNoise slowBatches = JNoise.newBuilder()
|
||||
.fastSimplex()
|
||||
.setSeed(rnd.nextLong())
|
||||
.setFrequency(0.1)
|
||||
.build();
|
||||
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
|
||||
for (int x = 0; x <= width; x++) {
|
||||
for (int z = 0; z <= preRun; z++) {
|
||||
batch.setBlock(x, 50, z, BlockPallet.GROUND.rnd());
|
||||
}
|
||||
|
||||
for (int z = preRun; z <= length + preRun; z++) {
|
||||
batch.setBlock(x, 50, z, slowBatches.getNoise(x, z) > 0.6 ? Block.SOUL_SAND : BlockPallet.STREET.rnd());
|
||||
}
|
||||
|
||||
for (int z = preRun + length; z <= preRun + length + afterRun; z++) {
|
||||
batch.setBlock(x, 50, z, BlockPallet.GROUND.rnd());
|
||||
}
|
||||
|
||||
batch.setBlock(x, 51, preRun-1, Block.OAK_FENCE.withProperties(CommonProperties.fenceEastWest));
|
||||
batch.setBlock(x, 50, preRun + length, Block.GOLD_BLOCK);
|
||||
}
|
||||
|
||||
record TrafficLightsInput(int x, int z) {}
|
||||
|
||||
Consumer<TrafficLightsInput> generateTrafficLight = (input) -> {
|
||||
batch.setBlock(input.x, 51, input.z, Block.ANVIL);
|
||||
|
||||
for(int y = 52; y <= 59; y++) {
|
||||
batch.setBlock(input.x, y, input.z, Block.ANDESITE_WALL);
|
||||
}
|
||||
|
||||
for (int x = input.x-3; x <= input.x+3; x++) {
|
||||
batch.setBlock(x, 60, input.z, Block.SMOOTH_STONE_SLAB);
|
||||
}
|
||||
|
||||
batch.setBlock(input.x-2, 59, input.z, Block.STONE_BRICK_WALL);
|
||||
trafficLights.add(new Pos(input.x-2, 58, input.z));
|
||||
trafficLights.add(new Pos(input.x-2, 57, input.z));
|
||||
|
||||
batch.setBlock(input.x+2, 59, input.z, Block.STONE_BRICK_WALL);
|
||||
trafficLights.add(new Pos(input.x+2, 58, input.z));
|
||||
trafficLights.add(new Pos(input.x+2, 57, input.z));
|
||||
|
||||
for (Pos trafficLight : trafficLights) {
|
||||
batch.setBlock(trafficLight, Block.WHITE_WOOL);
|
||||
}
|
||||
};
|
||||
|
||||
for (int count = 0; count <= this.rnd.nextInt(1, 2); count++) {
|
||||
generateTrafficLight.accept(new TrafficLightsInput(0, this.rnd.nextInt(preRun + 10, length + preRun - 10)));
|
||||
generateTrafficLight.accept(new TrafficLightsInput(width, this.rnd.nextInt(preRun + 10, length + preRun - 10)));
|
||||
}
|
||||
|
||||
if(width > 30) {
|
||||
for (int count = 0; count <= this.rnd.nextInt(1, 2); count++) {
|
||||
generateTrafficLight.accept(new TrafficLightsInput(width/2, this.rnd.nextInt(preRun, length + preRun)));
|
||||
}
|
||||
}
|
||||
|
||||
generateTrafficLight.accept(new TrafficLightsInput(0, length + preRun));
|
||||
generateTrafficLight.accept(new TrafficLightsInput(width, length + preRun));
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||
for(int x = 0; x <= width; x++) {
|
||||
batch.setBlock(x, 51, preRun-1, Block.AIR);
|
||||
}
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> playSound(Sound.sound(SoundEvent.BLOCK_WOOD_BREAK, Sound.Source.BLOCK, 1f, 1f)));
|
||||
|
||||
scheduler().submitTask(() -> {
|
||||
if(!super.isRunning) return TaskSchedule.stop();
|
||||
|
||||
phaseCounter++;
|
||||
if(phaseCounter >= 3) phaseCounter = 0;
|
||||
|
||||
if(phaseCounter == 0) phase = LightPhase.RED;
|
||||
if(phaseCounter == 1) phase = LightPhase.GREEN;
|
||||
if(phaseCounter == 2) phase = LightPhase.YELLOW;
|
||||
|
||||
getPlayers().forEach(player -> {
|
||||
for(int i = 0; i < 9; i++) {
|
||||
player.getInventory().setItemStack(i, phase.item);
|
||||
}
|
||||
});
|
||||
|
||||
AbsoluteBlockBatch changeLightsBatch = new AbsoluteBlockBatch();
|
||||
for (Pos trafficLight : trafficLights) {
|
||||
changeLightsBatch.setBlock(trafficLight, phase.item.material().block());
|
||||
}
|
||||
BatchUtil.loadAndApplyBatch(changeLightsBatch, this, () -> {});
|
||||
|
||||
return phase.taskScheduleRandomDuration();
|
||||
}, ExecutionType.TICK_END);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
if(isBeforeBeginning) return;
|
||||
|
||||
if(phase.equals(LightPhase.RED) && playerMoveEvent.getNewPosition().z()-0.01 > playerMoveEvent.getPlayer().getPosition().z()) {
|
||||
playerMoveEvent.getPlayer().setVelocity(new Vec(0, 8, -15));
|
||||
playerMoveEvent.getPlayer().playSound(Sound.sound(SoundEvent.ENTITY_BLAZE_SHOOT, Sound.Source.PLAYER, 1f, 1f));
|
||||
}
|
||||
|
||||
if(playerMoveEvent.getNewPosition().z() > preRun+length) {
|
||||
getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
playerMoveEvent.getPlayer().getInventory().clear();
|
||||
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos getSpawn() {
|
||||
return new Pos((double) width/2, 51, 3);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace;
|
||||
|
||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||
import net.minestom.server.item.Material;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TrafficLightRaceFactory implements GameFactory {
|
||||
@Override
|
||||
public TranslatedComponent name() {
|
||||
return TranslatedComponent.byId("game_TrafficlightRace#name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TranslatedComponent description() {
|
||||
return TranslatedComponent.byId("game_TrafficlightRace#description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("width", Material.OAK_FENCE, TranslatedComponent.byId("game_TrafficlightRace#width"), 20, 30, 40))
|
||||
.addOption(new NumericOption("length", Material.BLACK_CONCRETE_POWDER, TranslatedComponent.byId("game_TrafficlightRace#length"), 50, 80, 100, 120, 150));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new TrafficLightRace(configuration.get("width").getAsInt(), configuration.get("length").getAsInt()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material symbol() {
|
||||
return Material.YELLOW_WOOL;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user