Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
535008a31e |
No files matched your search
+2
-146
@@ -1,120 +1,3 @@
|
|||||||
# Created by https://www.toptal.com/developers/gitignore/api/gradle,intellij,java
|
|
||||||
# Edit at https://www.toptal.com/developers/gitignore?templates=gradle,intellij,java
|
|
||||||
|
|
||||||
### Intellij ###
|
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
||||||
|
|
||||||
# User-specific stuff
|
|
||||||
.idea/**/workspace.xml
|
|
||||||
.idea/**/tasks.xml
|
|
||||||
.idea/**/usage.statistics.xml
|
|
||||||
.idea/**/dictionaries
|
|
||||||
.idea/**/shelf
|
|
||||||
|
|
||||||
# AWS User-specific
|
|
||||||
.idea/**/aws.xml
|
|
||||||
|
|
||||||
# Generated files
|
|
||||||
.idea/**/contentModel.xml
|
|
||||||
|
|
||||||
# Sensitive or high-churn files
|
|
||||||
.idea/**/dataSources/
|
|
||||||
.idea/**/dataSources.ids
|
|
||||||
.idea/**/dataSources.local.xml
|
|
||||||
.idea/**/sqlDataSources.xml
|
|
||||||
.idea/**/dynamic.xml
|
|
||||||
.idea/**/uiDesigner.xml
|
|
||||||
.idea/**/dbnavigator.xml
|
|
||||||
|
|
||||||
# Gradle
|
|
||||||
.idea/**/gradle.xml
|
|
||||||
.idea/**/libraries
|
|
||||||
|
|
||||||
# Gradle and Maven with auto-import
|
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
||||||
# since they will be recreated, and may cause churn. Uncomment if using
|
|
||||||
# auto-import.
|
|
||||||
# .idea/artifacts
|
|
||||||
# .idea/compiler.xml
|
|
||||||
# .idea/jarRepositories.xml
|
|
||||||
# .idea/modules.xml
|
|
||||||
# .idea/*.iml
|
|
||||||
# .idea/modules
|
|
||||||
# *.iml
|
|
||||||
# *.ipr
|
|
||||||
|
|
||||||
# CMake
|
|
||||||
cmake-build-*/
|
|
||||||
|
|
||||||
# Mongo Explorer plugin
|
|
||||||
.idea/**/mongoSettings.xml
|
|
||||||
|
|
||||||
# File-based project format
|
|
||||||
*.iws
|
|
||||||
|
|
||||||
# IntelliJ
|
|
||||||
out/
|
|
||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
|
||||||
.idea_modules/
|
|
||||||
|
|
||||||
# JIRA plugin
|
|
||||||
atlassian-ide-plugin.xml
|
|
||||||
|
|
||||||
# Cursive Clojure plugin
|
|
||||||
.idea/replstate.xml
|
|
||||||
|
|
||||||
# SonarLint plugin
|
|
||||||
.idea/sonarlint/
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
||||||
com_crashlytics_export_strings.xml
|
|
||||||
crashlytics.properties
|
|
||||||
crashlytics-build.properties
|
|
||||||
fabric.properties
|
|
||||||
|
|
||||||
# Editor-based Rest Client
|
|
||||||
.idea/httpRequests
|
|
||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
|
||||||
.idea/caches/build_file_checksums.ser
|
|
||||||
|
|
||||||
### Intellij Patch ###
|
|
||||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
|
||||||
|
|
||||||
# *.iml
|
|
||||||
# modules.xml
|
|
||||||
# .idea/misc.xml
|
|
||||||
# *.ipr
|
|
||||||
|
|
||||||
# Sonarlint plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
|
||||||
.idea/**/sonarlint/
|
|
||||||
|
|
||||||
# SonarQube Plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
|
||||||
.idea/**/sonarIssues.xml
|
|
||||||
|
|
||||||
# Markdown Navigator plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
|
||||||
.idea/**/markdown-navigator.xml
|
|
||||||
.idea/**/markdown-navigator-enh.xml
|
|
||||||
.idea/**/markdown-navigator/
|
|
||||||
|
|
||||||
# Cache file creation bug
|
|
||||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
|
||||||
.idea/$CACHE_FILE$
|
|
||||||
|
|
||||||
# CodeStream plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
|
||||||
.idea/codestream.xml
|
|
||||||
|
|
||||||
# Azure Toolkit for IntelliJ plugin
|
|
||||||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
|
||||||
.idea/**/azureSettings.xml
|
|
||||||
|
|
||||||
### Java ###
|
|
||||||
# Compiled class file
|
# Compiled class file
|
||||||
*.class
|
*.class
|
||||||
|
|
||||||
@@ -140,35 +23,8 @@ fabric.properties
|
|||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
replay_pid*
|
replay_pid*
|
||||||
|
|
||||||
### Gradle ###
|
.idea
|
||||||
.gradle
|
.gradle
|
||||||
**/build/
|
build/*
|
||||||
!src/**/build/
|
|
||||||
|
|
||||||
# Ignore Gradle GUI config
|
|
||||||
gradle-app.setting
|
|
||||||
|
|
||||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
|
||||||
!gradle-wrapper.jar
|
|
||||||
|
|
||||||
# Avoid ignore Gradle wrappper properties
|
|
||||||
!gradle-wrapper.properties
|
|
||||||
|
|
||||||
# Cache of project
|
|
||||||
.gradletasknamecache
|
|
||||||
|
|
||||||
# Eclipse Gradle plugin generated files
|
|
||||||
# Eclipse Core
|
|
||||||
.project
|
|
||||||
# JDT-specific (Eclipse Java Development Tools)
|
|
||||||
.classpath
|
|
||||||
|
|
||||||
### Gradle Patch ###
|
|
||||||
# Java heap dump
|
|
||||||
*.hprof
|
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/gradle,intellij,java
|
|
||||||
|
|
||||||
/resources/
|
/resources/
|
||||||
/build/
|
|
||||||
/bin/
|
|
||||||
Generated
-3
@@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
Generated
-16
@@ -1,16 +0,0 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<code_scheme name="Project" version="173">
|
|
||||||
<codeStyleSettings language="JAVA">
|
|
||||||
<option name="SPACE_BEFORE_IF_PARENTHESES" value="false" />
|
|
||||||
<option name="SPACE_BEFORE_WHILE_PARENTHESES" value="false" />
|
|
||||||
<option name="SPACE_BEFORE_FOR_PARENTHESES" value="false" />
|
|
||||||
<option name="SPACE_BEFORE_TRY_PARENTHESES" value="false" />
|
|
||||||
<option name="SPACE_BEFORE_CATCH_PARENTHESES" value="false" />
|
|
||||||
<option name="SPACE_BEFORE_SWITCH_PARENTHESES" value="false" />
|
|
||||||
<option name="SPACE_BEFORE_SYNCHRONIZED_PARENTHESES" value="false" />
|
|
||||||
<indentOptions>
|
|
||||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
|
||||||
</indentOptions>
|
|
||||||
</codeStyleSettings>
|
|
||||||
</code_scheme>
|
|
||||||
</component>
|
|
||||||
Generated
-5
@@ -1,5 +0,0 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<state>
|
|
||||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
|
||||||
</state>
|
|
||||||
</component>
|
|
||||||
Generated
-13
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<bytecodeTargetLevel target="21" />
|
|
||||||
</component>
|
|
||||||
<component name="JavacSettings">
|
|
||||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
|
||||||
<module name="Minigames" options="-Xlint:deprecation" />
|
|
||||||
<module name="Minigames.test" options="-Xlint:deprecation" />
|
|
||||||
<module name="eu.mhsl.minenet.Minigames.main" options="-Xlint:deprecation" />
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
-7
@@ -1,7 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="UnqualifiedFieldAccess" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="UnqualifiedMethodAccess" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
||||||
Generated
-40
@@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Maven Central repository" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="jboss.community" />
|
|
||||||
<option name="name" value="JBoss Community repository" />
|
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="maven3" />
|
|
||||||
<option name="name" value="maven3" />
|
|
||||||
<option name="url" value="https://oss.sonatype.org/content/repositories/snapshots" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="MavenRepo" />
|
|
||||||
<option name="name" value="MavenRepo" />
|
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="maven2" />
|
|
||||||
<option name="name" value="maven2" />
|
|
||||||
<option name="url" value="https://repo.unnamed.team/repository/unnamed-public/" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="maven4" />
|
|
||||||
<option name="name" value="maven4" />
|
|
||||||
<option name="url" value="https://jitpack.io" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="Google" />
|
|
||||||
<option name="name" value="Google" />
|
|
||||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
|
||||||
</remote-repository>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-5
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK" />
|
|
||||||
</project>
|
|
||||||
Generated
-10
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/Minigames.main.iml" filepath="$PROJECT_DIR$/.idea/modules/Minigames.main.iml" />
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/Minigames.test.iml" filepath="$PROJECT_DIR$/.idea/modules/Minigames.test.iml" />
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/eu.mhsl.minenet.Minigames.main.iml" filepath="$PROJECT_DIR$/.idea/modules/eu.mhsl.minenet.Minigames.main.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
Generated
-17
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="minecraft" name="Minecraft">
|
|
||||||
<configuration>
|
|
||||||
<autoDetectTypes>
|
|
||||||
<platformType>ADVENTURE</platformType>
|
|
||||||
</autoDetectTypes>
|
|
||||||
<projectReimportVersion>1</projectReimportVersion>
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
Generated
-13
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="minecraft" name="Minecraft">
|
|
||||||
<configuration>
|
|
||||||
<autoDetectTypes>
|
|
||||||
<platformType>ADVENTURE</platformType>
|
|
||||||
</autoDetectTypes>
|
|
||||||
<projectReimportVersion>1</projectReimportVersion>
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="minecraft" name="Minecraft">
|
|
||||||
<configuration>
|
|
||||||
<autoDetectTypes>
|
|
||||||
<platformType>ADVENTURE</platformType>
|
|
||||||
</autoDetectTypes>
|
|
||||||
<projectReimportVersion>1</projectReimportVersion>
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="minecraft" name="Minecraft">
|
|
||||||
<configuration>
|
|
||||||
<autoDetectTypes>
|
|
||||||
<platformType>ADVENTURE</platformType>
|
|
||||||
</autoDetectTypes>
|
|
||||||
<projectReimportVersion>1</projectReimportVersion>
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
Generated
-6
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
+40
-21
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id "com.gradleup.shadow" version "9.6.0"
|
id "com.github.johnrengelman.shadow" version "7.1.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'eu.mhsl.minenet'
|
group 'eu.mhsl.minenet'
|
||||||
@@ -11,37 +11,58 @@ version '1.0-SNAPSHOT'
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url = 'https://mvn.everbuild.org/public' }
|
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 {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion = JavaLanguageVersion.of(25)
|
languageVersion = JavaLanguageVersion.of(21)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter:6.1.2'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
|
||||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
|
||||||
|
|
||||||
//https://mvnrepository.com/artifact/net.minestom/minestom
|
//https://jitpack.io/#Minestom/Minestom
|
||||||
implementation 'net.minestom:minestom:2026.07.12-26.2'
|
implementation 'net.minestom:minestom-snapshots:fd51c8d17a'
|
||||||
|
|
||||||
//Tools
|
//Tools
|
||||||
implementation 'de.articdive:jnoise-pipeline:4.1.0'
|
implementation 'de.articdive:jnoise:3.0.2'
|
||||||
compileOnly 'it.unimi.dsi:fastutil:8.5.18' // von Minestom nur zur Laufzeit bereitgestellt, fuer BatchUtil-Reflection benoetigt
|
implementation 'net.md-5:bungeecord-config:1.19-R0.1-SNAPSHOT'
|
||||||
implementation 'net.md-5:bungeecord-config:1.21-R0.3'
|
implementation 'org.apache.commons:commons-text:1.10.0'
|
||||||
implementation 'org.apache.commons:commons-text:1.15.0'
|
implementation 'org.spongepowered:configurate-yaml:4.1.2'
|
||||||
implementation 'org.spongepowered:configurate-yaml:4.2.0'
|
|
||||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||||
implementation 'com.google.code.gson:gson:2.14.0'
|
implementation 'com.google.code.gson:gson:2.10.1'
|
||||||
implementation 'com.google.guava:guava:33.4.8-jre'
|
implementation 'com.google.guava:guava:32.0.1-android'
|
||||||
|
|
||||||
|
|
||||||
//PvP
|
//PvP
|
||||||
implementation 'io.github.togar2:MinestomPvP:2026.05.30-26.1.1'
|
implementation 'io.github.TogAr2:MinestomPvP:PR62-SNAPSHOT'
|
||||||
|
|
||||||
//Block placement
|
// Hephaestus engine
|
||||||
implementation 'org.everbuild.blocksandstuff:blocksandstuff-blocks:1.10.2-SNAPSHOT'
|
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 {
|
tasks {
|
||||||
@@ -50,6 +71,8 @@ tasks {
|
|||||||
attributes 'Main-Class': 'eu.mhsl.minenet.minigames.Main'
|
attributes 'Main-Class': 'eu.mhsl.minenet.minigames.Main'
|
||||||
attributes 'Multi-Release': true
|
attributes 'Multi-Release': true
|
||||||
}
|
}
|
||||||
|
duplicatesStrategy = 'exclude'
|
||||||
|
from configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
|
||||||
}
|
}
|
||||||
build {
|
build {
|
||||||
dependsOn(shadowJar)
|
dependsOn(shadowJar)
|
||||||
@@ -66,7 +89,3 @@ tasks.register('copyJarToServer', Exec) {
|
|||||||
|
|
||||||
commandLine 'scp', 'build/libs/Minigames-1.0-SNAPSHOT.jar', 'root@10.20.6.5:/root/minigames'
|
commandLine 'scp', 'build/libs/Minigames-1.0-SNAPSHOT.jar', 'root@10.20.6.5:/root/minigames'
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
|
||||||
options.compilerArgs << "-Xlint:deprecation"
|
|
||||||
}
|
|
||||||
Vendored
BIN
Binary file not shown.
+1
-3
@@ -1,9 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
retries=0
|
|
||||||
retryBackOffMs=500
|
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright © 2015 the original authors.
|
# Copyright © 2015-2021 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# gradlew start up script for POSIX generated by Gradle.
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
#
|
#
|
||||||
# Important for running:
|
# Important for running:
|
||||||
#
|
#
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
# bash, then to run this script, type that shell name before the whole
|
# bash, then to run this script, type that shell name before the whole
|
||||||
# command line, like:
|
# command line, like:
|
||||||
#
|
#
|
||||||
# ksh gradlew
|
# ksh Gradle
|
||||||
#
|
#
|
||||||
# Busybox and similar reduced shells will NOT work, because this script
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
# requires all of these POSIX shell features:
|
# requires all of these POSIX shell features:
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# 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.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -86,7 +86,8 @@ done
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# 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\n' "$PWD" ) || exit
|
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.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -114,6 +115,7 @@ case "$( uname )" in #(
|
|||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@@ -171,6 +173,7 @@ fi
|
|||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
if "$cygwin" || "$msys" ; then
|
if "$cygwin" || "$msys" ; then
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
@@ -203,14 +206,15 @@ fi
|
|||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
# Collect all arguments for the java command:
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
# and any embedded shellness will be escaped.
|
# 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
|
# * 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.
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
# Stop when "xargs" is not available.
|
||||||
|
|||||||
Vendored
+24
-12
@@ -19,12 +19,12 @@
|
|||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem gradlew startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@rem
|
@rem
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|
||||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
@rem Set local scope for the variables with windows NT shell
|
||||||
setlocal EnableExtensions
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
@@ -51,7 +51,7 @@ echo. 1>&2
|
|||||||
echo Please set the JAVA_HOME variable in your environment to match the 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
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
"%COMSPEC%" /c exit 1
|
goto fail
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
:findJavaFromJavaHome
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
@@ -65,18 +65,30 @@ echo. 1>&2
|
|||||||
echo Please set the JAVA_HOME variable in your environment to match the 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
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
"%COMSPEC%" /c exit 1
|
goto fail
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
@rem Execute gradlew
|
@rem Execute Gradle
|
||||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
@rem which allows us to clear the local environment before executing the java command
|
|
||||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
|
||||||
|
|
||||||
:exitWithErrorLevel
|
:end
|
||||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
@rem End local scope for the variables with windows NT shell
|
||||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
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
|
||||||
@@ -3,12 +3,12 @@ package eu.mhsl.minenet.minigames;
|
|||||||
import eu.mhsl.minenet.minigames.api.HttpServer;
|
import eu.mhsl.minenet.minigames.api.HttpServer;
|
||||||
import eu.mhsl.minenet.minigames.command.Commands;
|
import eu.mhsl.minenet.minigames.command.Commands;
|
||||||
import eu.mhsl.minenet.minigames.handler.Listeners;
|
import eu.mhsl.minenet.minigames.handler.Listeners;
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
|
||||||
import eu.mhsl.minenet.minigames.lang.Languages;
|
import eu.mhsl.minenet.minigames.lang.Languages;
|
||||||
import eu.mhsl.minenet.minigames.server.tasks.TablistUpdateTask;
|
import eu.mhsl.minenet.minigames.server.tasks.TablistUpdateTask;
|
||||||
import net.minestom.server.Auth;
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.extras.bungee.BungeeCordProxy;
|
||||||
import net.minestom.server.extras.lan.OpenToLAN;
|
import net.minestom.server.extras.lan.OpenToLAN;
|
||||||
|
import net.minestom.server.extras.velocity.VelocityProxy;
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
import org.spongepowered.configurate.ConfigurateException;
|
import org.spongepowered.configurate.ConfigurateException;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
@@ -24,8 +24,7 @@ public class Main {
|
|||||||
private final static Logger logger = Logger.getGlobal();
|
private final static Logger logger = Logger.getGlobal();
|
||||||
public static ConfigurationNode globalConfig;
|
public static ConfigurationNode globalConfig;
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
public static void main(String[] args) throws ConfigurateException {
|
||||||
static void main(String[] args) throws ConfigurateException {
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
//noinspection ResultOfMethodCallIgnored
|
||||||
Resource.values(); // This initializes and preloads the enum and extracts the resources
|
Resource.values(); // This initializes and preloads the enum and extracts the resources
|
||||||
Languages.getInstance(); //Preload languages into the jvm
|
Languages.getInstance(); //Preload languages into the jvm
|
||||||
@@ -38,31 +37,14 @@ public class Main {
|
|||||||
|
|
||||||
ConfigurationNode serverConfig = globalConfig.node("server");
|
ConfigurationNode serverConfig = globalConfig.node("server");
|
||||||
|
|
||||||
// muss vor MinecraftServer.init() gesetzt werden: ServerFlag liest die Properties statisch beim Klassenladen;
|
|
||||||
// bei fehlendem/ungueltigem Config-Wert den Minestom-Default behalten (0 wuerde keine Chunks senden)
|
|
||||||
int viewDistance = serverConfig.node("view-distance").getInt(0);
|
|
||||||
if(viewDistance > 0) {
|
|
||||||
System.setProperty("minestom.chunk-view-distance", String.valueOf(viewDistance));
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Initialize Minecraft server...");
|
logger.info("Initialize Minecraft server...");
|
||||||
|
|
||||||
Auth auth = new Auth.Offline();
|
MinecraftServer server = MinecraftServer.init();
|
||||||
if(globalConfig.node("bungeecord", "enabled").getBoolean()) {
|
|
||||||
auth = new Auth.Bungee();
|
|
||||||
} else if(globalConfig.node("velocity", "enabled").getBoolean()) {
|
|
||||||
auth = new Auth.Velocity(Objects.requireNonNull(globalConfig.node("velocity", "secret").getString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
MinecraftServer server = MinecraftServer.init(auth);
|
|
||||||
// MinestomPvP.init();
|
// MinestomPvP.init();
|
||||||
|
|
||||||
// Dimensionen muessen vor server.start() registriert werden:
|
|
||||||
// seit Minestom 26.x sind die dynamischen Registries nach dem Start eingefroren
|
|
||||||
Dimension.values();
|
|
||||||
|
|
||||||
MinecraftServer.setBrandName("mhsl.eu - minenet - credits to minestom");
|
MinecraftServer.setBrandName("mhsl.eu - minenet - credits to minestom");
|
||||||
MinecraftServer.setCompressionThreshold(serverConfig.node("compression-threshold").getInt(0));
|
MinecraftServer.setCompressionThreshold(serverConfig.node("compression-threshold").getInt(0));
|
||||||
|
System.setProperty("minestom.chunk-view-distance", String.valueOf(serverConfig.node("view-distance").getInt()));
|
||||||
|
|
||||||
Commands.values();
|
Commands.values();
|
||||||
Listeners.values();
|
Listeners.values();
|
||||||
@@ -74,6 +56,12 @@ public class Main {
|
|||||||
|
|
||||||
if(serverConfig.node("open-to-lan").getBoolean()) OpenToLAN.open();
|
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));
|
server.start("0.0.0.0", serverConfig.node("port").getInt(25565));
|
||||||
System.gc();
|
System.gc();
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ public enum Resource {
|
|||||||
|
|
||||||
private final Path path;
|
private final Path path;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
Resource(String name, boolean keepOutdated) {
|
Resource(String name, boolean keepOutdated) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.path = Path.of("resources/" + name);
|
this.path = Path.of("resources/" + name);
|
||||||
@@ -39,10 +38,10 @@ public enum Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Path getPath() {
|
public Path getPath() {
|
||||||
return this.path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,11 +12,11 @@ public abstract class Controller<Q, R> implements Route {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Controller() {
|
public Controller() {
|
||||||
this.requestType = ((Class<Q>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
|
this.requestType = ((Class<Q>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object handle(Request request, Response response) {
|
public Object handle(Request request, Response response) throws Exception {
|
||||||
response.header("Access-Control-Allow-Origin", "*");
|
response.header("Access-Control-Allow-Origin", "*");
|
||||||
response.header("Access-Control-Allow-Methods", "*");
|
response.header("Access-Control-Allow-Methods", "*");
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ public abstract class Controller<Q, R> implements Route {
|
|||||||
req = new Gson().fromJson(request.body(), this.requestType);
|
req = new Gson().fromJson(request.body(), this.requestType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Gson().toJson(this.handle(req, response));
|
return new Gson().toJson(handle(req, response));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract R handle(Q request, Response response);
|
public abstract R handle(Q request, Response response);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import static spark.Spark.*;
|
|||||||
|
|
||||||
public class HttpServer {
|
public class HttpServer {
|
||||||
private static final ConfigurationNode apiConfig = Main.globalConfig.node("api");
|
private static final ConfigurationNode apiConfig = Main.globalConfig.node("api");
|
||||||
|
|
||||||
public HttpServer() {
|
public HttpServer() {
|
||||||
if(!apiConfig.node("enabled").getBoolean()) return;
|
if(!apiConfig.node("enabled").getBoolean()) return;
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,8 @@ import spark.Response;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
record Req(UUID room) {
|
record Req(UUID room) {}
|
||||||
}
|
record Resp() {}
|
||||||
|
|
||||||
record Resp() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CloseRoom extends Controller<Req, Resp> {
|
public class CloseRoom extends Controller<Req, Resp> {
|
||||||
@Override
|
@Override
|
||||||
public Resp handle(Req request, Response response) {
|
public Resp handle(Req request, Response response) {
|
||||||
|
|||||||
@@ -6,12 +6,8 @@ import spark.Response;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
record Req() {
|
record Req() {}
|
||||||
}
|
record Resp(UUID uuid) {}
|
||||||
|
|
||||||
record Resp(UUID uuid) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CreateRoom extends Controller<Req, Resp> {
|
public class CreateRoom extends Controller<Req, Resp> {
|
||||||
@Override
|
@Override
|
||||||
public Resp handle(Req request, Response response) {
|
public Resp handle(Req request, Response response) {
|
||||||
|
|||||||
@@ -8,12 +8,8 @@ import spark.Response;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
record Req(UUID player, UUID room) {
|
record Req(UUID player, UUID room) {}
|
||||||
}
|
record Resp(String error) {}
|
||||||
|
|
||||||
record Resp(String error) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public class QueueRoom extends Controller<Req, Resp> {
|
public class QueueRoom extends Controller<Req, Resp> {
|
||||||
@Override
|
@Override
|
||||||
public Resp handle(Req request, Response response) {
|
public Resp handle(Req request, Response response) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package eu.mhsl.minenet.minigames.command;
|
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.HubCommand;
|
||||||
import eu.mhsl.minenet.minigames.command.anonymous.LeaveCommand;
|
import eu.mhsl.minenet.minigames.command.anonymous.LeaveCommand;
|
||||||
import eu.mhsl.minenet.minigames.command.privileged.*;
|
|
||||||
import eu.mhsl.minenet.minigames.message.Icon;
|
import eu.mhsl.minenet.minigames.message.Icon;
|
||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
@@ -20,6 +21,7 @@ public enum Commands {
|
|||||||
ROOM(new RoomCommand()),
|
ROOM(new RoomCommand()),
|
||||||
UPDATE(new RefreshCommandsCommand()),
|
UPDATE(new RefreshCommandsCommand()),
|
||||||
OP(new OpCommand()),
|
OP(new OpCommand()),
|
||||||
|
FAKEPLAYER(new FakeplayerCommand()),
|
||||||
KICK(new KickCommand()),
|
KICK(new KickCommand()),
|
||||||
SKIN(new SkinCommand()),
|
SKIN(new SkinCommand()),
|
||||||
SETOWNER(new SetRoomOwnerCommand()),
|
SETOWNER(new SetRoomOwnerCommand()),
|
||||||
@@ -32,18 +34,14 @@ public enum Commands {
|
|||||||
PLAYERLIMIT(new PlayerLimitCommand()),
|
PLAYERLIMIT(new PlayerLimitCommand()),
|
||||||
SETMEMORIAL(new SetMemorialCommand());
|
SETMEMORIAL(new SetMemorialCommand());
|
||||||
|
|
||||||
static {
|
|
||||||
MinecraftServer.getCommandManager().setUnknownCommandCallback((sender, command) -> {
|
|
||||||
if(command.isBlank()) return;
|
|
||||||
new ChatMessage(Icon.ERROR)
|
|
||||||
.appendTranslated("common#unknownCommand")
|
|
||||||
.appendSpace()
|
|
||||||
.quote(command)
|
|
||||||
.send(sender);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Commands(Command handler) {
|
Commands(Command handler) {
|
||||||
MinecraftServer.getCommandManager().register(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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,21 +11,20 @@ import java.util.List;
|
|||||||
|
|
||||||
public class PrivilegedCommand extends Command {
|
public class PrivilegedCommand extends Command {
|
||||||
private final List<CommandCondition> conditions = new ArrayList<>();
|
private final List<CommandCondition> conditions = new ArrayList<>();
|
||||||
|
|
||||||
public PrivilegedCommand(@NotNull String name, @Nullable String... aliases) {
|
public PrivilegedCommand(@NotNull String name, @Nullable String... aliases) {
|
||||||
super(name, aliases);
|
super(name, aliases);
|
||||||
this.construct();
|
construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrivilegedCommand(@NotNull String name) {
|
public PrivilegedCommand(@NotNull String name) {
|
||||||
super(name);
|
super(name);
|
||||||
this.construct();
|
construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void construct() {
|
private void construct() {
|
||||||
this.addCondition(this.isPrivileged());
|
addCondition(isPrivileged());
|
||||||
|
|
||||||
this.setCondition((sender, commandString) -> this.conditions.parallelStream().allMatch(condition -> condition.canUse(sender, commandString)));
|
setCondition((sender, commandString) -> conditions.parallelStream().allMatch(condition -> condition.canUse(sender, commandString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CommandCondition isPrivileged() {
|
protected CommandCondition isPrivileged() {
|
||||||
@@ -33,6 +32,6 @@ public class PrivilegedCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void addCondition(CommandCondition condition) {
|
protected void addCondition(CommandCondition condition) {
|
||||||
this.conditions.add(condition);
|
conditions.add(condition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package eu.mhsl.minenet.minigames.command.anonymous;
|
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.hub.Hub;
|
||||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||||
import eu.mhsl.minenet.minigames.util.MoveInstance;
|
|
||||||
import net.minestom.server.command.builder.Command;
|
import net.minestom.server.command.builder.Command;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
@@ -10,12 +10,12 @@ public class HubCommand extends Command {
|
|||||||
public HubCommand() {
|
public HubCommand() {
|
||||||
super("hub");
|
super("hub");
|
||||||
|
|
||||||
this.setCondition(
|
setCondition(
|
||||||
(sender, commandString) ->
|
(sender, commandString) ->
|
||||||
((Player) sender).getInstance() instanceof Room room && !room.apiDriven
|
((Player) sender).getInstance() instanceof Room room && !room.apiDriven
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
if(Room.getRoom((Player) sender).orElseThrow().apiDriven) return;
|
if(Room.getRoom((Player) sender).orElseThrow().apiDriven) return;
|
||||||
Room.unsetRoom((Player) sender);
|
Room.unsetRoom((Player) sender);
|
||||||
MoveInstance.move((Player) sender, Hub.INSTANCE);
|
MoveInstance.move((Player) sender, Hub.INSTANCE);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ public class LeaveCommand extends Command {
|
|||||||
public LeaveCommand() {
|
public LeaveCommand() {
|
||||||
super("leave");
|
super("leave");
|
||||||
|
|
||||||
this.setCondition((sender, commandString) -> ((Player) sender).getInstance() instanceof Game);
|
setCondition((sender, commandString) -> ((Player) sender).getInstance() instanceof Game);
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, context) -> Room.setOwnRoom((Player) sender));
|
setDefaultExecutor((sender, context) -> Room.setOwnRoom((Player) sender));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,15 +14,15 @@ public class DebugCommand extends PrivilegedCommand {
|
|||||||
public DebugCommand() {
|
public DebugCommand() {
|
||||||
super("debug");
|
super("debug");
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, args) -> {
|
setDefaultExecutor((sender, args) -> {
|
||||||
new ChatMessage(Icon.CHAT).appendTranslated("sample").send(sender);
|
new ChatMessage(Icon.CHAT).appendTranslated("sample").send(sender);
|
||||||
new ActionBarMessage().appendTranslated("sample").send(sender);
|
new ActionBarMessage().appendTranslated("sample").send(sender);
|
||||||
new TitleMessage().subtitle(subtitleMessage -> subtitleMessage.appendTranslated("sample")).appendTranslated("sample").send(sender);
|
new TitleMessage().subtitle(subtitleMessage -> subtitleMessage.appendTranslated("sample")).appendTranslated("sample").send(sender);
|
||||||
List<String> testplayers = new ArrayList<>() {
|
List<String> testplayers = new ArrayList<>() {
|
||||||
{
|
{
|
||||||
this.add("MineTec");
|
add("MineTec");
|
||||||
this.add("Goldi187");
|
add("Goldi187");
|
||||||
this.add("Test");
|
add("Test");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
new ChatMessage(Icon.STAR, true)
|
new ChatMessage(Icon.STAR, true)
|
||||||
|
|||||||
@@ -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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ public class FlyCommand extends PrivilegedCommand {
|
|||||||
public FlyCommand() {
|
public FlyCommand() {
|
||||||
super("fly");
|
super("fly");
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
p.setVelocity(new Vec(0, 5, 0));
|
p.setVelocity(new Vec(0, 5, 0));
|
||||||
p.setFlying(!p.isFlying());
|
p.setFlying(!p.isFlying());
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.minestom.server.entity.Player;
|
|||||||
public class GameStartCommand extends PrivilegedCommand {
|
public class GameStartCommand extends PrivilegedCommand {
|
||||||
public GameStartCommand() {
|
public GameStartCommand() {
|
||||||
super("gameStart");
|
super("gameStart");
|
||||||
this.setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if(player.getInstance() instanceof StatelessGame game) {
|
if(player.getInstance() instanceof StatelessGame game) {
|
||||||
game.startAccessor();
|
game.startAccessor();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.minestom.server.entity.Player;
|
|||||||
public class GameStopCommand extends PrivilegedCommand {
|
public class GameStopCommand extends PrivilegedCommand {
|
||||||
public GameStopCommand() {
|
public GameStopCommand() {
|
||||||
super("gameStop");
|
super("gameStop");
|
||||||
this.setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if(player.getInstance() instanceof StatelessGame game) {
|
if(player.getInstance() instanceof StatelessGame game) {
|
||||||
game.stop();
|
game.stop();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class GameTimeoutCommand extends PrivilegedCommand {
|
|||||||
|
|
||||||
ArgumentInteger timeout = ArgumentType.Integer("timeout");
|
ArgumentInteger timeout = ArgumentType.Integer("timeout");
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> {
|
addSyntax((sender, context) -> {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if(player.getInstance() instanceof StatelessGame game) {
|
if(player.getInstance() instanceof StatelessGame game) {
|
||||||
game.setTimeLimit(context.get(timeout));
|
game.setTimeLimit(context.get(timeout));
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class GamemodeCommand extends PrivilegedCommand {
|
|||||||
super("gamemode", "gm");
|
super("gamemode", "gm");
|
||||||
|
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> ((Player) sender).setGameMode(
|
addSyntax((sender, context) -> ((Player) sender).setGameMode(
|
||||||
context.get("target")),
|
context.get("target")),
|
||||||
ArgumentType.Enum("target", GameMode.class).setFormat(ArgumentEnum.Format.LOWER_CASED)
|
ArgumentType.Enum("target", GameMode.class).setFormat(ArgumentEnum.Format.LOWER_CASED)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
package eu.mhsl.minenet.minigames.command.privileged;
|
package eu.mhsl.minenet.minigames.command.privileged;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||||
import eu.mhsl.minenet.minigames.message.Icon;
|
|
||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||||
|
import eu.mhsl.minenet.minigames.message.Icon;
|
||||||
import eu.mhsl.minenet.minigames.util.Monitoring;
|
import eu.mhsl.minenet.minigames.util.Monitoring;
|
||||||
|
|
||||||
public class GcCommand extends PrivilegedCommand {
|
public class GcCommand extends PrivilegedCommand {
|
||||||
private static long lastRun = System.currentTimeMillis();
|
private static long lastRun = System.currentTimeMillis();
|
||||||
|
|
||||||
public GcCommand() {
|
public GcCommand() {
|
||||||
super("gc");
|
super("gc");
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
long nextRun = (lastRun - (System.currentTimeMillis() - 30*1000)) / 1000;
|
long nextRun = (lastRun - (System.currentTimeMillis() - 30*1000)) / 1000;
|
||||||
if(nextRun > 0) {
|
if(nextRun > 0) {
|
||||||
new ChatMessage(Icon.ERROR).appendStatic("Please wait ").appendStatic(String.valueOf(nextRun)).appendStatic(" seconds before running GC again!").send(sender);
|
new ChatMessage(Icon.ERROR).appendStatic("Please wait ").appendStatic(String.valueOf(nextRun)).appendStatic(" seconds before running GC again!").send(sender);
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ public class InstanceProxyMoveCommand extends PrivilegedCommand {
|
|||||||
|
|
||||||
ArgumentWord serverArgument = new ArgumentWord("server");
|
ArgumentWord serverArgument = new ArgumentWord("server");
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> {
|
addSyntax((sender, context) -> {
|
||||||
Instance room = ((Player) sender).getInstance();
|
Instance room = ((Player) sender).getInstance();
|
||||||
room.getPlayers().forEach(player -> {
|
room.getPlayers().forEach(player -> {
|
||||||
Room.unsetRoom(player);
|
Room.unsetRoom(player);
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ public class KickCommand extends PrivilegedCommand {
|
|||||||
public KickCommand() {
|
public KickCommand() {
|
||||||
super("kick");
|
super("kick");
|
||||||
|
|
||||||
this.addSyntax(
|
addSyntax(
|
||||||
(sender, context) ->
|
(sender, context) ->
|
||||||
this.kick(context.getRaw("player"), ""),
|
kick(context.getRaw("player"), ""),
|
||||||
ArgumentType.Entity("player").onlyPlayers(true)
|
ArgumentType.Entity("player").onlyPlayers(true)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.addSyntax(
|
addSyntax(
|
||||||
(sender, context) ->
|
(sender, context) ->
|
||||||
this.kick(context.getRaw("player"), context.getRaw("reason")),
|
kick(context.getRaw("player"), context.getRaw("reason")),
|
||||||
ArgumentType.Entity("player").onlyPlayers(true),
|
ArgumentType.Entity("player").onlyPlayers(true),
|
||||||
ArgumentType.String("reason")
|
ArgumentType.String("reason")
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package eu.mhsl.minenet.minigames.command.privileged;
|
package eu.mhsl.minenet.minigames.command.privileged;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||||
import eu.mhsl.minenet.minigames.lang.Lang;
|
|
||||||
import eu.mhsl.minenet.minigames.lang.Languages;
|
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.Icon;
|
||||||
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
|
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
|
||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||||
@@ -13,11 +13,11 @@ public class LangTestCommand extends PrivilegedCommand {
|
|||||||
public LangTestCommand() {
|
public LangTestCommand() {
|
||||||
super("langtest");
|
super("langtest");
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, context) -> this.sendMessage(Languages.getInstance().getLanguage((Player) sender), "sample").send(sender));
|
setDefaultExecutor((sender, context) -> sendMessage(Languages.getInstance().getLanguage((Player) sender), "sample").send(sender));
|
||||||
|
|
||||||
var targetString = ArgumentType.String("mapId");
|
var targetString = ArgumentType.String("mapId");
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> this.sendMessage(Languages.getInstance().getLanguage((Player) sender), context.get("mapId")).send(sender), targetString);
|
addSyntax((sender, context) -> sendMessage(Languages.getInstance().getLanguage((Player) sender), context.get("mapId")).send(sender), targetString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TranslatableMessage sendMessage(Lang lang, String mapId) {
|
private TranslatableMessage sendMessage(Lang lang, String mapId) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class OpCommand extends PrivilegedCommand {
|
|||||||
public OpCommand() {
|
public OpCommand() {
|
||||||
super("op");
|
super("op");
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> {
|
addSyntax((sender, context) -> {
|
||||||
Player target = MinecraftServer.getConnectionManager().getOnlinePlayerByUsername(context.getRaw("target"));
|
Player target = MinecraftServer.getConnectionManager().getOnlinePlayerByUsername(context.getRaw("target"));
|
||||||
if(target != null) {
|
if(target != null) {
|
||||||
target.setPermissionLevel(4);
|
target.setPermissionLevel(4);
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ public class PlayerLimitCommand extends PrivilegedCommand {
|
|||||||
|
|
||||||
ArgumentInteger count = ArgumentType.Integer("count");
|
ArgumentInteger count = ArgumentType.Integer("count");
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> System.setProperty(
|
addSyntax((sender, context) -> {
|
||||||
"minenet.playerlimit",
|
System.setProperty("minenet.playerlimit", String.valueOf(context.get(count)));
|
||||||
String.valueOf(context.get(count))
|
}, count);
|
||||||
), count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-4
@@ -13,11 +13,10 @@ import java.net.http.HttpResponse;
|
|||||||
|
|
||||||
public class PublishRewardCommand extends PrivilegedCommand {
|
public class PublishRewardCommand extends PrivilegedCommand {
|
||||||
private final HttpClient rewardPublishClient = HttpClient.newHttpClient();
|
private final HttpClient rewardPublishClient = HttpClient.newHttpClient();
|
||||||
|
|
||||||
public PublishRewardCommand() {
|
public PublishRewardCommand() {
|
||||||
super("publishReward");
|
super("publishReward");
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
try {
|
try {
|
||||||
Room room = Room.getRoom((Player) sender).orElseThrow();
|
Room room = Room.getRoom((Player) sender).orElseThrow();
|
||||||
TournamentDisplay world = new TournamentDisplay(room.getTournament());
|
TournamentDisplay world = new TournamentDisplay(room.getTournament());
|
||||||
@@ -25,12 +24,12 @@ public class PublishRewardCommand extends PrivilegedCommand {
|
|||||||
|
|
||||||
String rewardRequestJson = new Gson().toJson(room.getTournament().getRewards());
|
String rewardRequestJson = new Gson().toJson(room.getTournament().getRewards());
|
||||||
HttpRequest giveRewardsRequest = HttpRequest.newBuilder()
|
HttpRequest giveRewardsRequest = HttpRequest.newBuilder()
|
||||||
.uri(new URI("http://10.20.9.3:8080/api/event/reward"))
|
.uri(new URI("http://10.20.7.1:8080/api/event/reward"))
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(rewardRequestJson))
|
.POST(HttpRequest.BodyPublishers.ofString(rewardRequestJson))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
room.getTournament().getRewards();
|
room.getTournament().getRewards();
|
||||||
HttpResponse<Void> rawResponse = this.rewardPublishClient.send(giveRewardsRequest, HttpResponse.BodyHandlers.discarding());
|
HttpResponse<Void> rawResponse = rewardPublishClient.send(giveRewardsRequest, HttpResponse.BodyHandlers.discarding());
|
||||||
sender.sendMessage(String.format("Rewards published: HTTP %s", rawResponse.statusCode()));
|
sender.sendMessage(String.format("Rewards published: HTTP %s", rawResponse.statusCode()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sender.sendMessage(e.getMessage());
|
sender.sendMessage(e.getMessage());
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
package eu.mhsl.minenet.minigames.command.privileged;
|
package eu.mhsl.minenet.minigames.command.privileged;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
||||||
import eu.mhsl.minenet.minigames.message.Icon;
|
|
||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||||
|
import eu.mhsl.minenet.minigames.message.Icon;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ public class RefreshCommandsCommand extends PrivilegedCommand {
|
|||||||
public RefreshCommandsCommand() {
|
public RefreshCommandsCommand() {
|
||||||
super("refreshCommands");
|
super("refreshCommands");
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(Player::refreshCommands);
|
MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(Player::refreshCommands);
|
||||||
new ChatMessage(Icon.SUCCESS).appendStatic("Updated command syntax!").send(sender);
|
new ChatMessage(Icon.SUCCESS).appendStatic("Updated command syntax!").send(sender);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package eu.mhsl.minenet.minigames.command.privileged;
|
package eu.mhsl.minenet.minigames.command.privileged;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
|
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.Icon;
|
||||||
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
|
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
|
||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -13,7 +13,7 @@ public class RoomCommand extends PrivilegedCommand {
|
|||||||
public RoomCommand() {
|
public RoomCommand() {
|
||||||
super("room");
|
super("room");
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
TranslatableMessage out = new ChatMessage(Icon.SCIENCE).appendStatic("Rooms:").newLine();
|
TranslatableMessage out = new ChatMessage(Icon.SCIENCE).appendStatic("Rooms:").newLine();
|
||||||
|
|
||||||
Room.getAllRooms().forEach((roomInstance) -> out
|
Room.getAllRooms().forEach((roomInstance) -> out
|
||||||
|
|||||||
@@ -20,22 +20,22 @@ public class SetMemorialCommand extends PrivilegedCommand {
|
|||||||
ArgumentString titleArgument = ArgumentType.String("title");
|
ArgumentString titleArgument = ArgumentType.String("title");
|
||||||
ArgumentString loreArgument = ArgumentType.String("lore");
|
ArgumentString loreArgument = ArgumentType.String("lore");
|
||||||
|
|
||||||
materialArgument.setSuggestionCallback(
|
materialArgument.setSuggestionCallback((sender, context, suggestion) -> {
|
||||||
(sender, context, suggestion) -> Material
|
Material
|
||||||
.values()
|
.values()
|
||||||
.stream()
|
.stream()
|
||||||
.map(material -> new SuggestionEntry(material.name(), Component.text(material.name())))
|
.map(material -> new SuggestionEntry(material.name(), Component.text(material.name())))
|
||||||
.forEach(suggestion::addEntry)
|
.forEach(suggestion::addEntry);
|
||||||
);
|
});
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> {
|
addSyntax((sender, context) -> {
|
||||||
Room
|
Room
|
||||||
.getRoom((Player) sender)
|
.getRoom((Player) sender)
|
||||||
.orElseThrow()
|
.orElseThrow()
|
||||||
.getTournament()
|
.getTournament()
|
||||||
.setMemorialConfiguration(
|
.setMemorialConfiguration(
|
||||||
new MemorialConfiguration(
|
new MemorialConfiguration(
|
||||||
Material.fromKey(context.get(materialArgument)),
|
Material.fromNamespaceId(context.get(materialArgument)),
|
||||||
context.get(titleArgument),
|
context.get(titleArgument),
|
||||||
context.get(loreArgument)
|
context.get(loreArgument)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,22 +22,22 @@ public class SetRewardCommand extends PrivilegedCommand {
|
|||||||
ArgumentWord materialArgument = ArgumentType.Word("material");
|
ArgumentWord materialArgument = ArgumentType.Word("material");
|
||||||
ArgumentStringArray amountsArgument = ArgumentType.StringArray("amount");
|
ArgumentStringArray amountsArgument = ArgumentType.StringArray("amount");
|
||||||
|
|
||||||
materialArgument.setSuggestionCallback(
|
materialArgument.setSuggestionCallback((sender, context, suggestion) -> {
|
||||||
(sender, context, suggestion) -> Material
|
Material
|
||||||
.values()
|
.values()
|
||||||
.stream()
|
.stream()
|
||||||
.map(material -> new SuggestionEntry(material.name(), Component.text(material.name())))
|
.map(material -> new SuggestionEntry(material.name(), Component.text(material.name())))
|
||||||
.forEach(suggestion::addEntry)
|
.forEach(suggestion::addEntry);
|
||||||
);
|
});
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> {
|
addSyntax((sender, context) -> {
|
||||||
Room
|
Room
|
||||||
.getRoom((Player) sender)
|
.getRoom((Player) sender)
|
||||||
.orElseThrow()
|
.orElseThrow()
|
||||||
.getTournament()
|
.getTournament()
|
||||||
.setRewardConfiguration(
|
.setRewardConfiguration(
|
||||||
new RewardConfiguration(
|
new RewardConfiguration(
|
||||||
Material.fromKey(context.get(materialArgument)),
|
Material.fromNamespaceId(context.get(materialArgument)),
|
||||||
Arrays.stream(context.get(amountsArgument)).map(Integer::valueOf).collect(Collectors.toList())
|
Arrays.stream(context.get(amountsArgument)).map(Integer::valueOf).collect(Collectors.toList())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,21 +15,21 @@ public class SetRoomOwnerCommand extends PrivilegedCommand {
|
|||||||
public SetRoomOwnerCommand() {
|
public SetRoomOwnerCommand() {
|
||||||
super("setRoomOwner");
|
super("setRoomOwner");
|
||||||
|
|
||||||
this.addCondition((sender, commandString) -> ((Player) sender).getInstance() instanceof Room);
|
addCondition((sender, commandString) -> ((Player) sender).getInstance() instanceof Room);
|
||||||
|
|
||||||
this.setDefaultExecutor((sender, context) -> {
|
setDefaultExecutor((sender, context) -> {
|
||||||
if(sender instanceof Player p) {
|
if(sender instanceof Player p) {
|
||||||
Room.getRoom(p).orElseThrow().setOwner(p);
|
Room.getRoom(p).orElseThrow().setOwner(p);
|
||||||
new ChatMessage(Icon.SUCCESS).appendTranslated("room#ownerSelf").send(sender);
|
new ChatMessage(Icon.SUCCESS).appendStatic("You are now the owner of this room!").send(sender);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> {
|
addSyntax((sender, context) -> {
|
||||||
System.out.println("Test");
|
System.out.println("Test");
|
||||||
if(sender instanceof Player p) {
|
if(sender instanceof Player p) {
|
||||||
Player newOwner = MinecraftServer.getConnectionManager().getOnlinePlayerByUsername(context.getRaw("player"));
|
Player newOwner = MinecraftServer.getConnectionManager().getOnlinePlayerByUsername(context.getRaw("player"));
|
||||||
Room.getRoom(p).orElseThrow().setOwner(Objects.requireNonNull(newOwner));
|
Room.getRoom(p).orElseThrow().setOwner(Objects.requireNonNull(newOwner));
|
||||||
new ChatMessage(Icon.SUCCESS).appendTranslated("room#ownerSet").send(sender);
|
new ChatMessage(Icon.SUCCESS).appendStatic("The new owner has been set!").send(sender);
|
||||||
}
|
}
|
||||||
}, ArgumentType.Entity("player").onlyPlayers(true));
|
}, ArgumentType.Entity("player").onlyPlayers(true));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class SkinCommand extends PrivilegedCommand {
|
|||||||
public SkinCommand() {
|
public SkinCommand() {
|
||||||
super("skin");
|
super("skin");
|
||||||
|
|
||||||
this.addSyntax((sender, context) -> {
|
addSyntax((sender, context) -> {
|
||||||
if(sender instanceof Player p) {
|
if(sender instanceof Player p) {
|
||||||
p.setSkin(PlayerSkin.fromUsername(context.getRaw("target")));
|
p.setSkin(PlayerSkin.fromUsername(context.getRaw("target")));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
package eu.mhsl.minenet.minigames.handler;
|
package eu.mhsl.minenet.minigames.handler;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.handler.global.AddEntityToInstanceEventListener;
|
import eu.mhsl.minenet.minigames.handler.global.*;
|
||||||
import eu.mhsl.minenet.minigames.handler.global.ChatFormatHandler;
|
|
||||||
import eu.mhsl.minenet.minigames.handler.global.PlayerFreezeHandler;
|
|
||||||
import eu.mhsl.minenet.minigames.handler.global.PlayerLeaveHandler;
|
|
||||||
import eu.mhsl.minenet.minigames.handler.global.PlayerLoginHandler;
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.event.EventListener;
|
import net.minestom.server.event.EventListener;
|
||||||
|
|
||||||
public enum Listeners {
|
public enum Listeners {
|
||||||
SPAWN(new AddEntityToInstanceEventListener()),
|
SPAWN(new AddEntityToInstanceEventListener()),
|
||||||
LOGIN(new PlayerLoginHandler()),
|
LOGIN(new PlayerLoginHandler()),
|
||||||
LEAVE(new PlayerLeaveHandler()),
|
LEAVE(new PlayerLeaveHandler());
|
||||||
FREEZE(new PlayerFreezeHandler()),
|
|
||||||
CHAT(new ChatFormatHandler());
|
|
||||||
|
|
||||||
Listeners(EventListener<?> event) {
|
Listeners(EventListener<?> event) {
|
||||||
MinecraftServer.getGlobalEventHandler().addListener(event);
|
MinecraftServer.getGlobalEventHandler().addListener(event);
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.handler.global;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.Main;
|
|
||||||
import eu.mhsl.minenet.minigames.message.Icon;
|
|
||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.minestom.server.event.EventListener;
|
|
||||||
import net.minestom.server.event.player.PlayerChatEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class ChatFormatHandler implements EventListener<PlayerChatEvent> {
|
|
||||||
// Verteilt der Proxy den Chat (chat-bridge bei CraftAttack), darf er hier nicht noch einmal erscheinen
|
|
||||||
private final boolean chatViaProxy = Main.globalConfig.node("velocity", "chat-via-proxy").getBoolean(false);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Class<PlayerChatEvent> eventType() {
|
|
||||||
return PlayerChatEvent.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Result run(@NotNull PlayerChatEvent event) {
|
|
||||||
if(this.chatViaProxy) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return Result.SUCCESS;
|
|
||||||
}
|
|
||||||
NamedTextColor color = event.getPlayer().getPermissionLevel() > 0 ? NamedTextColor.AQUA : NamedTextColor.GRAY;
|
|
||||||
event.setFormattedMessage(
|
|
||||||
new ChatMessage(Icon.CHAT)
|
|
||||||
.appendStatic(Component.text(event.getPlayer().getUsername(), color))
|
|
||||||
.appendStatic(Component.text(" > ", NamedTextColor.DARK_GRAY))
|
|
||||||
.appendStatic(event.getRawMessage())
|
|
||||||
.build(event.getPlayer())
|
|
||||||
);
|
|
||||||
return Result.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.handler.global;
|
|
||||||
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
import net.minestom.server.event.EventListener;
|
|
||||||
import net.minestom.server.event.player.PlayerTickEvent;
|
|
||||||
import net.minestom.server.instance.Instance;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Weder Minestom noch MinestomPvP verwalten die TICKS_FROZEN-Metadata. Der 26.x-Client baut das
|
|
||||||
* Freeze-Overlay bei Powder-Snow-Kontakt zwar selbst auf, der Abbau ist aber server-authoritative —
|
|
||||||
* ohne diese Vanilla-Logik bleibt das Overlay dauerhaft haengen (auch ueber Instanzwechsel hinweg).
|
|
||||||
*/
|
|
||||||
public class PlayerFreezeHandler implements EventListener<PlayerTickEvent> {
|
|
||||||
private static final int TICKS_REQUIRED_TO_FREEZE = 140;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Class<PlayerTickEvent> eventType() {
|
|
||||||
return PlayerTickEvent.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Result run(@NotNull PlayerTickEvent event) {
|
|
||||||
Player p = event.getPlayer();
|
|
||||||
Instance instance = p.getInstance();
|
|
||||||
if(instance == null) return Result.SUCCESS;
|
|
||||||
|
|
||||||
Pos pos = p.getPosition();
|
|
||||||
boolean inPowderSnow = instance.getBlock(pos).compare(Block.POWDER_SNOW)
|
|
||||||
|| instance.getBlock(pos.add(0, 1, 0)).compare(Block.POWDER_SNOW);
|
|
||||||
|
|
||||||
int ticksFrozen = p.getEntityMeta().getTickFrozen();
|
|
||||||
if(inPowderSnow) {
|
|
||||||
p.getEntityMeta().setTickFrozen(Math.min(TICKS_REQUIRED_TO_FREEZE, ticksFrozen + 1));
|
|
||||||
} else if(ticksFrozen > 0) {
|
|
||||||
p.getEntityMeta().setTickFrozen(Math.max(0, ticksFrozen - 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
package eu.mhsl.minenet.minigames.handler.global;
|
package eu.mhsl.minenet.minigames.handler.global;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.message.Icon;
|
|
||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.minestom.server.MinecraftServer;
|
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.EventListener;
|
import net.minestom.server.event.EventListener;
|
||||||
import net.minestom.server.event.player.PlayerDisconnectEvent;
|
import net.minestom.server.event.player.PlayerDisconnectEvent;
|
||||||
@@ -18,11 +14,7 @@ public class PlayerLeaveHandler implements EventListener<PlayerDisconnectEvent>
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull Result run(@NotNull PlayerDisconnectEvent event) {
|
public @NotNull Result run(@NotNull PlayerDisconnectEvent event) {
|
||||||
Player p = event.getPlayer();
|
Player p = event.getPlayer();
|
||||||
new ChatMessage(Icon.LEAVE)
|
// new ChatMessage(Icon.SCIENCE).appendStatic("unübersetzter Leavetext: ").appendStatic(p.getDisplayName()).send(MinecraftServer.getConnectionManager().getOnlinePlayers());
|
||||||
.appendStatic(p.getName().color(NamedTextColor.GRAY))
|
|
||||||
.appendSpace()
|
|
||||||
.appendTranslated("common#leave", NamedTextColor.DARK_GRAY)
|
|
||||||
.send(MinecraftServer.getConnectionManager().getOnlinePlayers());
|
|
||||||
return Result.SUCCESS;
|
return Result.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,13 @@ package eu.mhsl.minenet.minigames.handler.global;
|
|||||||
|
|
||||||
import eu.mhsl.minenet.minigames.Main;
|
import eu.mhsl.minenet.minigames.Main;
|
||||||
import eu.mhsl.minenet.minigames.api.QueuedPlayerRooms;
|
import eu.mhsl.minenet.minigames.api.QueuedPlayerRooms;
|
||||||
import eu.mhsl.minenet.minigames.instance.hub.Hub;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||||
import eu.mhsl.minenet.minigames.instance.transfer.Transfer;
|
import eu.mhsl.minenet.minigames.instance.transfer.Transfer;
|
||||||
import eu.mhsl.minenet.minigames.skin.SkinCache;
|
import eu.mhsl.minenet.minigames.skin.SkinCache;
|
||||||
import eu.mhsl.minenet.minigames.util.MoveInstance;
|
import eu.mhsl.minenet.minigames.util.MoveInstance;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.Player;
|
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.EventListener;
|
||||||
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
|
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
|
||||||
import net.minestom.server.network.packet.server.play.TeamsPacket;
|
import net.minestom.server.network.packet.server.play.TeamsPacket;
|
||||||
@@ -61,11 +61,12 @@ public class PlayerLoginHandler implements EventListener<AsyncPlayerConfiguratio
|
|||||||
if(Objects.requireNonNull(Main.globalConfig.node("admins").getList(String.class)).stream().anyMatch(s -> s.equalsIgnoreCase(p.getUsername()))) {
|
if(Objects.requireNonNull(Main.globalConfig.node("admins").getList(String.class)).stream().anyMatch(s -> s.equalsIgnoreCase(p.getUsername()))) {
|
||||||
p.setPermissionLevel(4);
|
p.setPermissionLevel(4);
|
||||||
}
|
}
|
||||||
} catch(SerializationException | NullPointerException ignored) {
|
} catch (SerializationException | NullPointerException ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
Logger.getLogger("user").info(p.getUsername() + " joined");
|
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;
|
return Result.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,70 +1,48 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance;
|
package eu.mhsl.minenet.minigames.instance;
|
||||||
|
|
||||||
import net.kyori.adventure.key.Key;
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.registry.RegistryKey;
|
import net.minestom.server.registry.DynamicRegistry;
|
||||||
import net.minestom.server.registry.RegistryTag;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.minestom.server.world.DimensionType;
|
import net.minestom.server.world.DimensionType;
|
||||||
import net.minestom.server.world.attribute.EnvironmentAttribute;
|
|
||||||
import net.minestom.server.world.clock.WorldClock;
|
|
||||||
import net.minestom.server.world.timeline.Timeline;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prebuilt dimensions
|
* Prebuilt dimensions
|
||||||
*/
|
*/
|
||||||
public enum Dimension {
|
public enum Dimension {
|
||||||
OVERWORLD(
|
OVERWORLD(
|
||||||
Key.key("minenet:fullbright_overworld"),
|
NamespaceID.from("minenet:fullbright_overworld"),
|
||||||
DimensionType
|
DimensionType
|
||||||
.builder()
|
.builder()
|
||||||
// Fullbright: seit MC 26.1 laeuft die Grundhelligkeit ueber das Environment-Attribut
|
.ambientLight(2.0f)
|
||||||
// AMBIENT_LIGHT_COLOR (Vanilla-Overworld: #0A0A0A); der alte ambientLight-2.0-Hack
|
|
||||||
// liegt ausserhalb der validen Range und bricht das Client-Rendering
|
|
||||||
.setAttribute(EnvironmentAttribute.AMBIENT_LIGHT_COLOR, NamedTextColor.WHITE)
|
|
||||||
// defaultClock noetig, damit Instance#setTime/#defaultClock funktionieren (sonst null); Timelines wie Vanilla-Overworld
|
|
||||||
.defaultClock(WorldClock.OVERWORLD)
|
|
||||||
.timelines(RegistryTag.direct(Timeline.DAY, Timeline.MOON, Timeline.EARLY_GAME, Timeline.VILLAGER_SCHEDULE))
|
|
||||||
.build()
|
.build()
|
||||||
),
|
),
|
||||||
|
|
||||||
NETHER(
|
NETHER(
|
||||||
Key.key("minenet:fullbright_nether"),
|
NamespaceID.from("minenet:fullbright_nether"),
|
||||||
DimensionType
|
DimensionType
|
||||||
.builder()
|
.builder()
|
||||||
// Fullbright: seit MC 26.1 laeuft die Grundhelligkeit ueber das Environment-Attribut
|
.ambientLight(2.0f)
|
||||||
// AMBIENT_LIGHT_COLOR (Vanilla-Overworld: #0A0A0A); der alte ambientLight-2.0-Hack
|
.effects("minecraft:the_nether")
|
||||||
// liegt ausserhalb der validen Range und bricht das Client-Rendering
|
|
||||||
.setAttribute(EnvironmentAttribute.AMBIENT_LIGHT_COLOR, NamedTextColor.WHITE)
|
|
||||||
.skybox(DimensionType.Skybox.NONE)
|
|
||||||
.defaultClock(WorldClock.OVERWORLD)
|
|
||||||
.timelines(RegistryTag.direct(Timeline.VILLAGER_SCHEDULE))
|
|
||||||
.build()
|
.build()
|
||||||
),
|
),
|
||||||
|
|
||||||
THE_END(
|
THE_END(
|
||||||
Key.key("minenet:fullbright_end"),
|
NamespaceID.from("minenet:fullbright_end"),
|
||||||
DimensionType
|
DimensionType
|
||||||
.builder()
|
.builder()
|
||||||
// Fullbright: seit MC 26.1 laeuft die Grundhelligkeit ueber das Environment-Attribut
|
.ambientLight(2.0f)
|
||||||
// AMBIENT_LIGHT_COLOR (Vanilla-Overworld: #0A0A0A); der alte ambientLight-2.0-Hack
|
.effects("minecraft:the_end")
|
||||||
// liegt ausserhalb der validen Range und bricht das Client-Rendering
|
|
||||||
.setAttribute(EnvironmentAttribute.AMBIENT_LIGHT_COLOR, NamedTextColor.WHITE)
|
|
||||||
.skybox(DimensionType.Skybox.END)
|
|
||||||
.defaultClock(WorldClock.THE_END)
|
|
||||||
.timelines(RegistryTag.direct(Timeline.VILLAGER_SCHEDULE))
|
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
public final DimensionType DIMENSION;
|
public final DimensionType DIMENSION;
|
||||||
public final Key namespaceID;
|
public final NamespaceID namespaceID;
|
||||||
public final RegistryKey<DimensionType> key;
|
public final DynamicRegistry.Key<DimensionType> key;
|
||||||
|
Dimension(NamespaceID namespaceID, DimensionType dimType) {
|
||||||
Dimension(Key namespaceID, DimensionType dimType) {
|
|
||||||
this.DIMENSION = dimType;
|
this.DIMENSION = dimType;
|
||||||
this.namespaceID = namespaceID;
|
this.namespaceID = namespaceID;
|
||||||
|
|
||||||
this.key = MinecraftServer.getDimensionTypeRegistry().register(namespaceID, this.DIMENSION);
|
this.key = MinecraftServer.getDimensionTypeRegistry().register(namespaceID, DIMENSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,25 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance;
|
package eu.mhsl.minenet.minigames.instance;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||||
import net.kyori.adventure.key.Key;
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
|
import net.minestom.server.event.instance.AddEntityToInstanceEvent;
|
||||||
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
|
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.instance.InstanceContainer;
|
import net.minestom.server.instance.InstanceContainer;
|
||||||
import net.minestom.server.registry.RegistryKey;
|
import net.minestom.server.instance.InstanceManager;
|
||||||
|
import net.minestom.server.registry.DynamicRegistry;
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
import net.minestom.server.world.DimensionType;
|
import net.minestom.server.world.DimensionType;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MineNetInstance extends InstanceContainer {
|
public class MineNetInstance extends InstanceContainer {
|
||||||
public MineNetInstance(RegistryKey<DimensionType> type) {
|
public MineNetInstance(DynamicRegistry.Key<DimensionType> type) {
|
||||||
this(UUID.randomUUID(), type);
|
super(UUID.randomUUID(), type);
|
||||||
}
|
|
||||||
|
|
||||||
// Eindeutiger Dimension-Name pro Instanz: Minestom entscheidet anhand dieses Namens (nicht des
|
|
||||||
// DimensionTypes), ob beim setInstance das volle Respawn-Protokoll gefahren wird. Ohne den Reset
|
|
||||||
// rendert der 26.x-Client nach einem Wechsel zwischen Instanzen gleicher Dimension keine Chunks.
|
|
||||||
private MineNetInstance(UUID uuid, RegistryKey<DimensionType> type) {
|
|
||||||
super(uuid, type, Key.key("minenet", "instance-" + uuid));
|
|
||||||
MinecraftServer.getInstanceManager().registerInstance(this);
|
MinecraftServer.getInstanceManager().registerInstance(this);
|
||||||
|
|
||||||
this.eventNode()
|
eventNode()
|
||||||
.addListener(AddEntityToInstanceEvent.class, this::onEntityAdd)
|
.addListener(AddEntityToInstanceEvent.class, this::onEntityAdd)
|
||||||
.addListener(RemoveEntityFromInstanceEvent.class, this::onEntityRemove);
|
.addListener(RemoveEntityFromInstanceEvent.class, this::onEntityRemove);
|
||||||
}
|
}
|
||||||
@@ -45,7 +38,6 @@ public class MineNetInstance extends InstanceContainer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when Player joins this instance
|
* Called when Player joins this instance
|
||||||
*
|
|
||||||
* @param p player who is joining
|
* @param p player who is joining
|
||||||
* @return setCanceled
|
* @return setCanceled
|
||||||
*/
|
*/
|
||||||
@@ -55,15 +47,18 @@ public class MineNetInstance extends InstanceContainer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when Player leaves this instance
|
* Called when Player leaves this instance
|
||||||
*
|
|
||||||
* @param p player who is leaving
|
* @param p player who is leaving
|
||||||
*/
|
*/
|
||||||
protected void onPlayerLeave(Player p) {
|
protected void onPlayerLeave(Player p) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param target
|
||||||
|
*/
|
||||||
public void destroy(Instance target) {
|
public void destroy(Instance target) {
|
||||||
this.getPlayers().forEach(player -> {
|
getPlayers().forEach(player -> {
|
||||||
if(target != null)
|
if(target != null)
|
||||||
player.setInstance(target);
|
player.setInstance(target);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game;
|
package eu.mhsl.minenet.minigames.instance.game;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.MineNetInstance;
|
import eu.mhsl.minenet.minigames.instance.MineNetInstance;
|
||||||
import eu.mhsl.minenet.minigames.instance.Spawnable;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
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.Option;
|
||||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
|
||||||
import eu.mhsl.minenet.minigames.message.Icon;
|
import eu.mhsl.minenet.minigames.message.Icon;
|
||||||
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
|
||||||
import eu.mhsl.minenet.minigames.score.Score;
|
import eu.mhsl.minenet.minigames.score.Score;
|
||||||
import eu.mhsl.minenet.minigames.util.CommonEventHandles;
|
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.MinecraftServer;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
@@ -16,7 +16,7 @@ import net.minestom.server.event.item.ItemDropEvent;
|
|||||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||||
import net.minestom.server.registry.RegistryKey;
|
import net.minestom.server.registry.DynamicRegistry;
|
||||||
import net.minestom.server.timer.ExecutionType;
|
import net.minestom.server.timer.ExecutionType;
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
import net.minestom.server.world.DimensionType;
|
import net.minestom.server.world.DimensionType;
|
||||||
@@ -28,38 +28,51 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public abstract class Game extends MineNetInstance implements Spawnable {
|
public abstract class Game extends MineNetInstance implements Spawnable {
|
||||||
protected final Random rnd = new Random();
|
|
||||||
protected final Logger logger;
|
|
||||||
protected Room parentRoom;
|
protected Room parentRoom;
|
||||||
protected boolean isRunning = false;
|
protected boolean isRunning = false;
|
||||||
protected boolean isBeforeBeginning = true;
|
protected boolean isBeforeBeginning = true;
|
||||||
|
|
||||||
public Game(RegistryKey<DimensionType> dimensionType) {
|
protected final Random rnd = new Random(); //TODO better way than ths?
|
||||||
|
|
||||||
|
protected final Logger logger;
|
||||||
|
|
||||||
|
public Game(DynamicRegistry.Key<DimensionType> dimensionType) {
|
||||||
super(dimensionType);
|
super(dimensionType);
|
||||||
|
|
||||||
MinecraftServer.getInstanceManager().registerInstance(this);
|
MinecraftServer.getInstanceManager().registerInstance(this);
|
||||||
|
|
||||||
this.logger = Logger.getLogger("Game:" + this.getUuid());
|
logger = Logger.getLogger("Game:" + getUuid());
|
||||||
|
|
||||||
this.eventNode()
|
eventNode()
|
||||||
.addListener(PlayerMoveEvent.class, this::onPlayerMove)
|
.addListener(PlayerMoveEvent.class, this::onPlayerMove)
|
||||||
.addListener(PlayerBlockBreakEvent.class, this::onBlockBreak)
|
.addListener(PlayerBlockBreakEvent.class, this::onBlockBreak)
|
||||||
.addListener(PlayerBlockPlaceEvent.class, this::onBlockPlace)
|
.addListener(PlayerBlockPlaceEvent.class, this::onBlockPlace)
|
||||||
.addListener(ItemDropEvent.class, this::onItemDrop);
|
.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) {
|
public static void initialize(GameFactory factory, List<Option<?>> options, Player owner) {
|
||||||
try {
|
try {
|
||||||
Room originRoom = Room.getRoom(owner).orElseThrow();
|
|
||||||
Game game = factory.manufacture(originRoom, options);
|
|
||||||
game.load();
|
|
||||||
originRoom.moveMembersToInstance(game);
|
|
||||||
|
|
||||||
new ChatMessage(Icon.INFO)
|
Game game = factory.manufacture(Room.getRoom(owner).orElseThrow(), options);
|
||||||
.appendTranslated(factory.name())
|
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()
|
.newLine()
|
||||||
.appendTranslated(factory.description())
|
.appendStatic(factory.description().getAssembled(player).asComponent())
|
||||||
.send(originRoom.getAllMembers());
|
.send(player));
|
||||||
|
|
||||||
|
return TaskSchedule.stop();
|
||||||
|
}, TaskSchedule.seconds(3));
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
new ChatMessage(Icon.ERROR).appendStatic("Instance crashed: " + e.getMessage()).send(owner);
|
new ChatMessage(Icon.ERROR).appendStatic("Instance crashed: " + e.getMessage()).send(owner);
|
||||||
@@ -68,16 +81,11 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Game setParent(Room parentRoom) {
|
|
||||||
this.parentRoom = parentRoom;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load and start countdown
|
* Load and start countdown
|
||||||
*/
|
*/
|
||||||
public void load() {
|
public void load() {
|
||||||
this.scheduler().submitTask(() -> {
|
scheduler().submitTask(() -> {
|
||||||
CompletableFuture<Void> callback = new CompletableFuture<>();
|
CompletableFuture<Void> callback = new CompletableFuture<>();
|
||||||
this.onLoad(callback);
|
this.onLoad(callback);
|
||||||
// callback.whenComplete((unused, throwable) -> this.start());
|
// callback.whenComplete((unused, throwable) -> this.start());
|
||||||
@@ -87,13 +95,13 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void start() {
|
protected void start() {
|
||||||
this.isRunning = true;
|
isRunning = true;
|
||||||
this.isBeforeBeginning = false;
|
isBeforeBeginning = false;
|
||||||
this.onStart();
|
this.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
this.isRunning = false;
|
isRunning = false;
|
||||||
this.onStop();
|
this.onStop();
|
||||||
this.unload();
|
this.unload();
|
||||||
}
|
}
|
||||||
@@ -101,12 +109,12 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
|||||||
public void unload() {
|
public void unload() {
|
||||||
this.onUnload();
|
this.onUnload();
|
||||||
|
|
||||||
this.getPlayers().forEach(Room::setOwnRoom);
|
getPlayers().forEach(Room::setOwnRoom);
|
||||||
|
|
||||||
this.scheduler().scheduleTask(() -> {
|
scheduler().scheduleTask(() -> {
|
||||||
|
|
||||||
this.logger.info("stopping game instance " + this.uuid);
|
logger.info("stopping game instance " + this.uuid);
|
||||||
this.getPlayers().forEach(player -> player.kick("timeout"));
|
getPlayers().forEach(player -> player.kick("timeout"));
|
||||||
|
|
||||||
MinecraftServer.getInstanceManager().unregisterInstance(this);
|
MinecraftServer.getInstanceManager().unregisterInstance(this);
|
||||||
|
|
||||||
@@ -117,14 +125,9 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
|||||||
callback.complete(null);
|
callback.complete(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onStart() {
|
protected void onStart() {}
|
||||||
}
|
protected void onStop() {}
|
||||||
|
protected void onUnload() {}
|
||||||
protected void onStop() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onUnload() {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
|
|
||||||
@@ -148,7 +151,7 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void checkAbandoned() {
|
protected void checkAbandoned() {
|
||||||
this.scheduleNextTick((instance) -> {
|
scheduleNextTick((instance) -> {
|
||||||
if(instance.getPlayers().isEmpty()) this.unload();
|
if(instance.getPlayers().isEmpty()) this.unload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -158,7 +161,7 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
return this.isRunning;
|
return isRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
|
|||||||
@@ -1,33 +1,22 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game;
|
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.config.GameFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.acidRain.AcidRainFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun.AnvilRunFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun.AnvilRunFactory;
|
||||||
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.blockBattle.BlockBattleFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace.BlockBreakRaceFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.boatRace.BoatRaceFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bowSpleef.BowSpleefFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle.BuildBattleFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle.BuildBattleFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.colorJump.ColorJumpFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube.DeathcubeFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace.ElytraRaceFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.elytraRace.ElytraRaceFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge.FastbridgeFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms.BackroomsFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.highGround.HighGroundFactory;
|
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.jumpDive.JumpDiveFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun.MinerunFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun.MinerunFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.pillars.PillarsFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.playerRace.PlayerRaceFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.spaceSnake.SpaceSnakeFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef.SpleefFactory;
|
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.stickfight.StickFightFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.sumo.SumoFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.TetrisFactory;
|
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.tntrun.TntRunFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.TowerdefenseFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.TowerdefenseFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace.TrafficLightRaceFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace.TrafficLightRaceFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.turtleGame.TurtleGameFactory;
|
|
||||||
|
|
||||||
public enum GameList {
|
public enum GameList {
|
||||||
DEATHCUBE(new DeathcubeFactory(), GameType.JUMPNRUN),
|
DEATHCUBE(new DeathcubeFactory(), GameType.JUMPNRUN),
|
||||||
@@ -42,35 +31,22 @@ public enum GameList {
|
|||||||
TNTRUN(new TntRunFactory(), GameType.OTHER),
|
TNTRUN(new TntRunFactory(), GameType.OTHER),
|
||||||
ANVILRUN(new AnvilRunFactory(), GameType.PVE),
|
ANVILRUN(new AnvilRunFactory(), GameType.PVE),
|
||||||
ACIDRAIN(new AcidRainFactory(), GameType.PVE),
|
ACIDRAIN(new AcidRainFactory(), GameType.PVE),
|
||||||
TURTLEGAME(new TurtleGameFactory(), GameType.PVE),
|
|
||||||
ELYTRARACE(new ElytraRaceFactory(), GameType.PVP),
|
ELYTRARACE(new ElytraRaceFactory(), GameType.PVP),
|
||||||
SPLEEF(new SpleefFactory(), GameType.PVP),
|
SPLEEF(new SpleefFactory(), GameType.PVP),
|
||||||
JUMPDIVE(new JumpDiveFactory(), GameType.JUMPNRUN),
|
JUMPDIVE(new JumpDiveFactory(), GameType.JUMPNRUN),
|
||||||
SUMO(new SumoFactory(), GameType.PVP),
|
BUILDBATTLE(new BuildBattleFactory(), GameType.OTHER);
|
||||||
HIGHGROUND(new HighGroundFactory(), GameType.PVP),
|
|
||||||
FASTBRIDGE(new FastbridgeFactory(), GameType.OTHER),
|
|
||||||
BLOCKBREAKRACE(new BlockBreakRaceFactory(), GameType.OTHER),
|
|
||||||
SPACESNAKE(new SpaceSnakeFactory(), GameType.PVP),
|
|
||||||
BOATRACE(new BoatRaceFactory(), GameType.OTHER),
|
|
||||||
PILLARS(new PillarsFactory(), GameType.PROTOTYPE),
|
|
||||||
BLOCKBATTLE(new BlockBattleFactory(), GameType.PVP),
|
|
||||||
COLORJUMP(new ColorJumpFactory(), GameType.JUMPNRUN),
|
|
||||||
PLAYERRACE(new PlayerRaceFactory(), GameType.JUMPNRUN),
|
|
||||||
BUILDBATTLE(new BuildBattleFactory(), GameType.PROTOTYPE);
|
|
||||||
|
|
||||||
private final GameFactory factory;
|
private final GameFactory factory;
|
||||||
private final GameType type;
|
private final GameType type;
|
||||||
|
|
||||||
GameList(GameFactory factory, GameType type) {
|
GameList(GameFactory factory, GameType type) {
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameFactory getFactory() {
|
public GameFactory getFactory() {
|
||||||
return this.factory;
|
return this.factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameType getType() {
|
public GameType getType() {
|
||||||
return this.type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,15 +22,15 @@ public enum GameType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Material getIcon() {
|
public Material getIcon() {
|
||||||
return this.icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TranslatedComponent getTitle() {
|
public TranslatedComponent getTitle() {
|
||||||
return this.title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TranslatedComponent getDescription() {
|
public TranslatedComponent getDescription() {
|
||||||
return this.description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+26
-40
@@ -9,7 +9,7 @@ import eu.mhsl.minenet.minigames.score.Score;
|
|||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.minestom.server.registry.RegistryKey;
|
import net.minestom.server.registry.DynamicRegistry;
|
||||||
import net.minestom.server.timer.ExecutionType;
|
import net.minestom.server.timer.ExecutionType;
|
||||||
import net.minestom.server.timer.Task;
|
import net.minestom.server.timer.Task;
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
@@ -26,7 +26,7 @@ public class StatelessGame extends Game {
|
|||||||
private int timeLimit = 0;
|
private int timeLimit = 0;
|
||||||
private int timePlayed = 0;
|
private int timePlayed = 0;
|
||||||
|
|
||||||
public StatelessGame(RegistryKey<DimensionType> dimensionType, String gameName, Score score) {
|
public StatelessGame(DynamicRegistry.Key<DimensionType> dimensionType, String gameName, Score score) {
|
||||||
super(dimensionType);
|
super(dimensionType);
|
||||||
this.score = score;
|
this.score = score;
|
||||||
this.name = gameName;
|
this.name = gameName;
|
||||||
@@ -37,7 +37,7 @@ public class StatelessGame extends Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeLimit(int limit) {
|
public void setTimeLimit(int limit) {
|
||||||
@@ -47,23 +47,20 @@ public class StatelessGame extends Game {
|
|||||||
this.timePlayed = 0;
|
this.timePlayed = 0;
|
||||||
}
|
}
|
||||||
if(this.timeLimit > 0) {
|
if(this.timeLimit > 0) {
|
||||||
this.timeLimitTask = this.scheduler().submitTask(() -> {
|
this.timeLimitTask = scheduler().submitTask(() -> {
|
||||||
if(!this.isRunning || this.timeLimit == 0) return TaskSchedule.stop();
|
if(!isRunning || timeLimit == 0) return TaskSchedule.stop();
|
||||||
if(this.timeLimit <= this.timePlayed) {
|
if(timeLimit <= timePlayed) {
|
||||||
this.stop();
|
stop();
|
||||||
return TaskSchedule.stop();
|
return TaskSchedule.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
int timeLeft = this.timeLimit - this.timePlayed;
|
int timeLeft = timeLimit - timePlayed;
|
||||||
switch (timeLeft) {
|
switch (timeLeft) {
|
||||||
case 90, 60, 30, 10, 5, 4, 3, 2, 1 -> new ChatMessage(Icon.TIME)
|
case 90, 60, 30, 10, 5, 4, 3, 2, 1 ->
|
||||||
.appendStatic(String.valueOf(timeLeft))
|
new ChatMessage(Icon.SCIENCE).appendStatic("Noch " + timeLeft + " Sekunden!").send(getPlayers());
|
||||||
.appendSpace()
|
|
||||||
.appendTranslated(timeLeft == 1 ? "common#secondsLeft_singular" : "common#secondsLeft_plural")
|
|
||||||
.send(this.getPlayers());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.timePlayed++;
|
timePlayed++;
|
||||||
|
|
||||||
return TaskSchedule.seconds(1);
|
return TaskSchedule.seconds(1);
|
||||||
}, ExecutionType.TICK_START);
|
}, ExecutionType.TICK_START);
|
||||||
@@ -80,48 +77,37 @@ public class StatelessGame extends Game {
|
|||||||
* When overriding make sure to call this::start after countdown!
|
* When overriding make sure to call this::start after countdown!
|
||||||
*/
|
*/
|
||||||
protected CompletableFuture<Void> countdownStart() {
|
protected CompletableFuture<Void> countdownStart() {
|
||||||
Duration fadeIn = Duration.ofMillis(300);
|
return new Countdown(TitleMessage.class)
|
||||||
Duration stay = Duration.ofMillis(700);
|
.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))
|
||||||
return new Countdown()
|
.appendStatic(Component.text(countdownModifier.timeLeft, NamedTextColor.GREEN))
|
||||||
.countdown(
|
.appendStatic(Component.text(" seconds", NamedTextColor.DARK_GREEN))));
|
||||||
Audience.audience(this.getPlayers()),
|
|
||||||
5,
|
|
||||||
modifier -> modifier.message = new TitleMessage(fadeIn, stay)
|
|
||||||
.subtitle(subtitleMessage -> subtitleMessage
|
|
||||||
.appendTranslated("common#startIn", NamedTextColor.DARK_GREEN)
|
|
||||||
.appendSpace()
|
|
||||||
.appendStatic(Component.text(modifier.timeLeft, NamedTextColor.GREEN))
|
|
||||||
.appendSpace()
|
|
||||||
.appendTranslated(modifier.timeLeft == 1 ? "common#second" : "common#seconds", NamedTextColor.DARK_GREEN)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void startAccessor() {
|
public void startAccessor() {
|
||||||
this.start();
|
this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void start() {
|
protected void start() {
|
||||||
this.score.setInstance(this);
|
score.setInstance(this);
|
||||||
this.score.attachListeners();
|
score.attachListeners();
|
||||||
|
|
||||||
this.countdownStart().thenRun(super::start);
|
countdownStart().thenRun(super::start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
this.isRunning = false;
|
isRunning = false;
|
||||||
this.onStop();
|
this.onStop();
|
||||||
this.getScore().insertRemainingPlayers(this.getPlayers());
|
getScore().insertRemainingPlayers(getPlayers());
|
||||||
this.publishScore(this.getScore());
|
this.publishScore(getScore());
|
||||||
|
|
||||||
this.countdownUnload();
|
countdownUnload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void countdownUnload() {
|
private void countdownUnload() {
|
||||||
new TitleMessage(Duration.ofSeconds(1)).appendTranslated("score#done").send(this.getPlayers());
|
new TitleMessage(Duration.ofSeconds(1)).appendTranslated("score#done").send(getPlayers());
|
||||||
this.scheduler().scheduleTask(this::unload, TaskSchedule.seconds(5), TaskSchedule.stop());
|
scheduler().scheduleTask(this::unload, TaskSchedule.seconds(5), TaskSchedule.stop());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -5,12 +5,12 @@ import java.util.ArrayList;
|
|||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private final ArrayList<Option<?>> items = new ArrayList<>();
|
private final ArrayList<Option<?>> items = new ArrayList<>();
|
||||||
|
|
||||||
public ConfigManager addOption(Option<?> option) {
|
public ConfigManager addOption(Option option) {
|
||||||
this.items.add(option);
|
items.add(option);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Option<?>> getAll() {
|
public ArrayList<Option<?>> getAll() {
|
||||||
return this.items;
|
return items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+32
-31
@@ -4,19 +4,20 @@ 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.Restriction;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction.RestrictionData;
|
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.instance.game.stateless.config.restriction.RestrictionHandler;
|
||||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
|
||||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||||
import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory;
|
import eu.mhsl.minenet.minigames.shared.inventory.InteractableInventory;
|
||||||
import eu.mhsl.minenet.minigames.util.InventoryItemAlignment;
|
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.sound.Sound;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.Player;
|
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.AddEntityToInstanceEvent;
|
||||||
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
|
import net.minestom.server.event.instance.RemoveEntityFromInstanceEvent;
|
||||||
import net.minestom.server.event.inventory.InventoryPreClickEvent;
|
|
||||||
import net.minestom.server.inventory.InventoryType;
|
import net.minestom.server.inventory.InventoryType;
|
||||||
import net.minestom.server.inventory.click.Click;
|
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.ItemStack;
|
||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
import net.minestom.server.sound.SoundEvent;
|
import net.minestom.server.sound.SoundEvent;
|
||||||
@@ -44,7 +45,7 @@ public class GameConfigurationInventory extends InteractableInventory {
|
|||||||
|
|
||||||
ConfigManager config = factory.configuration();
|
ConfigManager config = factory.configuration();
|
||||||
|
|
||||||
this.setClickableItem(
|
setClickableItem(
|
||||||
ItemStack.builder(Material.RED_WOOL)
|
ItemStack.builder(Material.RED_WOOL)
|
||||||
.customName(
|
.customName(
|
||||||
TranslatedComponent.byId("common#back")
|
TranslatedComponent.byId("common#back")
|
||||||
@@ -57,9 +58,9 @@ public class GameConfigurationInventory extends InteractableInventory {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setDummyItem(Material.BLACK_STAINED_GLASS_PANE, 1);
|
setDummyItem(Material.BLACK_STAINED_GLASS_PANE,1);
|
||||||
|
|
||||||
this.setDummyItem(
|
setDummyItem(
|
||||||
ItemStack.builder(Material.NAME_TAG)
|
ItemStack.builder(Material.NAME_TAG)
|
||||||
.customName(
|
.customName(
|
||||||
factory.name().setColor(NamedTextColor.GOLD).getAssembled(p)
|
factory.name().setColor(NamedTextColor.GOLD).getAssembled(p)
|
||||||
@@ -68,16 +69,16 @@ public class GameConfigurationInventory extends InteractableInventory {
|
|||||||
4
|
4
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setDummyItem(Material.BLACK_STAINED_GLASS_PANE, 7);
|
setDummyItem(Material.BLACK_STAINED_GLASS_PANE,7);
|
||||||
|
|
||||||
this.updatePlayButton();
|
updatePlayButton();
|
||||||
|
|
||||||
for(int i = 9; i <= 17; i++) {
|
for(int i = 9; i <= 17; i++) {
|
||||||
this.setDummyItem(Material.BLACK_STAINED_GLASS_PANE, i);
|
setDummyItem(Material.BLACK_STAINED_GLASS_PANE, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config == null) {
|
if(config == null) {
|
||||||
this.setDummyItem(
|
setDummyItem(
|
||||||
ItemStack.builder(Material.BARRIER)
|
ItemStack.builder(Material.BARRIER)
|
||||||
.customName(
|
.customName(
|
||||||
TranslatedComponent.byId("room#noOption").setColor(NamedTextColor.RED).getAssembled(p)
|
TranslatedComponent.byId("room#noOption").setColor(NamedTextColor.RED).getAssembled(p)
|
||||||
@@ -94,9 +95,9 @@ public class GameConfigurationInventory extends InteractableInventory {
|
|||||||
InventoryItemAlignment itemAlignment = new InventoryItemAlignment(config.getAll().size(), 3);
|
InventoryItemAlignment itemAlignment = new InventoryItemAlignment(config.getAll().size(), 3);
|
||||||
for(Option<?> item : config.getAll()) {
|
for(Option<?> item : config.getAll()) {
|
||||||
InventoryItemAlignment.ItemOffset current = itemAlignment.next();
|
InventoryItemAlignment.ItemOffset current = itemAlignment.next();
|
||||||
this.map.put(offset + current.get(), item);
|
map.put(offset + current.get(), item);
|
||||||
|
|
||||||
this.setDummyItem(
|
setDummyItem(
|
||||||
item.getCurrent(p),
|
item.getCurrent(p),
|
||||||
offset + current.get()
|
offset + current.get()
|
||||||
);
|
);
|
||||||
@@ -106,53 +107,53 @@ public class GameConfigurationInventory extends InteractableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onClick(Player player, int slot, Click click, InventoryPreClickEvent event) {
|
protected void onClick(Player player, int slot, ClickType clickType, InventoryConditionResult inventoryConditionResult) {
|
||||||
event.setCancelled(true);
|
inventoryConditionResult.setCancel(true);
|
||||||
|
|
||||||
if(!this.map.containsKey(slot)) return;
|
if(!map.containsKey(slot)) return;
|
||||||
|
|
||||||
Option<?> item = this.map.get(slot);
|
Option<?> item = map.get(slot);
|
||||||
this.setDummyItem(
|
setDummyItem(
|
||||||
item.getNext(this.p),
|
item.getNext(p),
|
||||||
slot
|
slot
|
||||||
);
|
);
|
||||||
|
|
||||||
this.update();
|
update();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePlayButton() {
|
private void updatePlayButton() {
|
||||||
RestrictionHandler restrictionHandler = this.factory.globalRestrictions();
|
RestrictionHandler restrictionHandler = factory.globalRestrictions();
|
||||||
RestrictionData restrictionData = new RestrictionData(this.room);
|
RestrictionData restrictionData = new RestrictionData(room);
|
||||||
|
|
||||||
if(restrictionHandler.canPlay(restrictionData)) {
|
if(restrictionHandler.canPlay(restrictionData)) {
|
||||||
|
|
||||||
this.setClickableItem(
|
setClickableItem(
|
||||||
ItemStack.builder(!restrictionHandler.getWarnings(restrictionData).isEmpty() ? Material.YELLOW_WOOL : Material.GREEN_WOOL)
|
ItemStack.builder(restrictionHandler.getWarnings(restrictionData).size() > 0 ? Material.YELLOW_WOOL : Material.GREEN_WOOL)
|
||||||
.customName(TranslatedComponent.byId("restriction#success").setColor(NamedTextColor.GREEN).getAssembled(this.p))
|
.customName(TranslatedComponent.byId("restriction#success").setColor(NamedTextColor.GREEN).getAssembled(p))
|
||||||
.lore(restrictionHandler.getWarnings(restrictionData).stream().map(translatedComponent -> translatedComponent.getAssembled(this.p)).collect(Collectors.toList()))
|
.lore(restrictionHandler.getWarnings(restrictionData).stream().map(translatedComponent -> translatedComponent.getAssembled(p)).collect(Collectors.toList()))
|
||||||
.build(),
|
.build(),
|
||||||
8,
|
8,
|
||||||
itemClick -> Game.initialize(this.factory, this.map.values().stream().toList(), itemClick.getPlayer()),
|
itemClick -> Game.initialize(factory, map.values().stream().toList(), itemClick.getPlayer()),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
this.setClickableItem(
|
setClickableItem(
|
||||||
ItemStack.builder(Material.RED_WOOL)
|
ItemStack.builder(Material.RED_WOOL)
|
||||||
.customName(TranslatedComponent.byId("restriction#fail").setColor(NamedTextColor.RED).getAssembled(this.p))
|
.customName(TranslatedComponent.byId("restriction#fail").setColor(NamedTextColor.RED).getAssembled(p))
|
||||||
.lore(
|
.lore(
|
||||||
restrictionHandler.getRestrictions()
|
restrictionHandler.getRestrictions()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(iRestriction -> iRestriction.calculate(restrictionData).type().equals(Restriction.Type.FAIL))
|
.filter(iRestriction -> iRestriction.calculate(restrictionData).type().equals(Restriction.Type.FAIL))
|
||||||
.map(iRestriction -> iRestriction.calculate(restrictionData).description().getAssembled(this.p))
|
.map(iRestriction -> iRestriction.calculate(restrictionData).description().getAssembled(p))
|
||||||
.collect(Collectors.toList()))
|
.collect(Collectors.toList()))
|
||||||
.build(),
|
.build(),
|
||||||
8,
|
8,
|
||||||
itemClick -> {
|
itemClick -> {
|
||||||
if(restrictionHandler.canPlay(restrictionData)) {
|
if(restrictionHandler.canPlay(restrictionData)) {
|
||||||
this.updatePlayButton();
|
updatePlayButton();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
itemClick.getPlayer().playSound(Sound.sound(SoundEvent.ENTITY_SILVERFISH_DEATH, Sound.Source.AMBIENT, 1f, 1f));
|
itemClick.getPlayer().playSound(Sound.sound(SoundEvent.ENTITY_SILVERFISH_DEATH, Sound.Source.AMBIENT, 1f, 1f));
|
||||||
@@ -162,6 +163,6 @@ public class GameConfigurationInventory extends InteractableInventory {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+4
-7
@@ -12,11 +12,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
public interface GameFactory {
|
public interface GameFactory {
|
||||||
TranslatedComponent name();
|
TranslatedComponent name();
|
||||||
|
|
||||||
default ConfigManager configuration() {
|
default ConfigManager configuration() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
default RestrictionHandler globalRestrictions() {
|
default RestrictionHandler globalRestrictions() {
|
||||||
return new RestrictionHandler();
|
return new RestrictionHandler();
|
||||||
}
|
}
|
||||||
@@ -24,7 +22,6 @@ public interface GameFactory {
|
|||||||
default Material symbol() {
|
default Material symbol() {
|
||||||
return Material.GRASS_BLOCK;
|
return Material.GRASS_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
default TranslatedComponent description() {
|
default TranslatedComponent description() {
|
||||||
return TranslatedComponent.byId("GameFactory#missingDescription");
|
return TranslatedComponent.byId("GameFactory#missingDescription");
|
||||||
}
|
}
|
||||||
@@ -32,17 +29,17 @@ public interface GameFactory {
|
|||||||
Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception;
|
Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception;
|
||||||
|
|
||||||
default Game manufacture(Room parent, List<Option<?>> configuration) throws Exception {
|
default Game manufacture(Room parent, List<Option<?>> configuration) throws Exception {
|
||||||
if(configuration == null) return this.manufacture(parent);
|
if(configuration == null) return manufacture(parent);
|
||||||
|
|
||||||
Map<String, Option<?>> cnf = new HashMap<>();
|
Map<String, Option<?>> cnf = new HashMap<>();
|
||||||
configuration.forEach(option -> cnf.put(option.getId(), option));
|
configuration.forEach(option -> cnf.put(option.getId(), option));
|
||||||
|
|
||||||
return this.manufacture(parent, cnf);
|
return manufacture(parent, cnf);
|
||||||
}
|
}
|
||||||
|
|
||||||
default Game manufacture(Room parent) throws Exception {
|
default Game manufacture(Room parent) throws Exception {
|
||||||
if(this.configuration() == null) return this.manufacture(parent, List.of());
|
if(this.configuration() == null) return manufacture(parent, List.of());
|
||||||
|
|
||||||
return this.manufacture(parent, this.configuration().getAll());
|
return manufacture(parent, this.configuration().getAll());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+18
-17
@@ -12,12 +12,12 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class Option<T> {
|
public abstract class Option<T> {
|
||||||
|
private RestrictionHandler restrictionHandler;
|
||||||
private final Material item;
|
private final Material item;
|
||||||
private final TranslatedComponent name;
|
private final TranslatedComponent name;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final List<T> options;
|
|
||||||
protected T currentValue;
|
protected T currentValue;
|
||||||
private RestrictionHandler restrictionHandler;
|
private final List<T> options;
|
||||||
private int pointer = 0;
|
private int pointer = 0;
|
||||||
|
|
||||||
public Option(String id, Material item, TranslatedComponent name, List<T> options) {
|
public Option(String id, Material item, TranslatedComponent name, List<T> options) {
|
||||||
@@ -26,45 +26,46 @@ public abstract class Option<T> {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
this.currentValue = options.getFirst();
|
currentValue = options.getFirst();
|
||||||
}
|
|
||||||
|
|
||||||
public RestrictionHandler getRestrictionHandler() {
|
|
||||||
return this.restrictionHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRestrictionHandler(RestrictionHandler restrictionHandler) {
|
public void setRestrictionHandler(RestrictionHandler restrictionHandler) {
|
||||||
this.restrictionHandler = restrictionHandler;
|
this.restrictionHandler = restrictionHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RestrictionHandler getRestrictionHandler() {
|
||||||
|
return restrictionHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ItemStack getNext(Player p) {
|
public ItemStack getNext(Player p) {
|
||||||
if(++this.pointer >= this.options.size()) this.pointer = 0;
|
if(++pointer >= options.size()) pointer = 0;
|
||||||
this.currentValue = this.options.get(this.pointer);
|
currentValue = options.get(pointer);
|
||||||
return this.getCurrent(p);
|
return getCurrent(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getCurrent(Player p) {
|
public ItemStack getCurrent(Player p) {
|
||||||
String value = this.options.get(this.pointer).toString();
|
String value = options.get(pointer).toString();
|
||||||
return ItemStack.builder(this.item)
|
return ItemStack.builder(item)
|
||||||
.customName(this.name.getAssembled(p))
|
.customName(name.getAssembled(p))
|
||||||
.lore(TranslatedComponent.byId("optionCommon#value").setColor(NamedTextColor.GOLD).getAssembled(p)
|
.lore(TranslatedComponent.byId("optionCommon#value").setColor(NamedTextColor.GOLD).getAssembled(p)
|
||||||
.append(Component.text(": ")).append(Component.text(value)))
|
.append(Component.text(": ")).append(Component.text(value)))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAsInt() {
|
public int getAsInt() {
|
||||||
return Integer.parseInt(this.getAsString());
|
return Integer.parseInt(getAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAsBoolean() {
|
public boolean getAsBoolean() {
|
||||||
return Objects.equals(this.getAsString(), "true") || Objects.equals(this.getAsString(), "1");
|
return Objects.equals(getAsString(), "true") || Objects.equals(getAsString(), "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAsString() {
|
public String getAsString() {
|
||||||
return this.currentValue.toString();
|
return currentValue.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return this.id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -22,11 +22,11 @@ public class RestrictionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<IRestriction> getRestrictions() {
|
public List<IRestriction> getRestrictions() {
|
||||||
return this.restrictions;
|
return restrictions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canPlay(RestrictionData data) {
|
public boolean canPlay(RestrictionData data) {
|
||||||
if(this.restrictions.isEmpty()) return true;
|
if(restrictions.size() < 1) return true;
|
||||||
return this.restrictions.stream()
|
return this.restrictions.stream()
|
||||||
.noneMatch(iRestriction -> iRestriction.calculate(data).type().equals(Restriction.Type.FAIL));
|
.noneMatch(iRestriction -> iRestriction.calculate(data).type().equals(Restriction.Type.FAIL));
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-31
@@ -1,7 +1,6 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.acidRain;
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.acidRain;
|
||||||
|
|
||||||
import de.articdive.jnoise.generators.noisegen.opensimplex.FastSimplexNoiseGenerator;
|
import de.articdive.jnoise.JNoise;
|
||||||
import de.articdive.jnoise.pipeline.JNoise;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||||
@@ -28,25 +27,26 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
|
|
||||||
|
|
||||||
public class AcidRain extends StatelessGame {
|
public class AcidRain extends StatelessGame {
|
||||||
final JNoise noise = JNoise.newBuilder()
|
|
||||||
.fastSimplex(FastSimplexNoiseGenerator.newBuilder().setSeed(this.rnd.nextLong()).build())
|
|
||||||
.scale(0.09)
|
|
||||||
.build();
|
|
||||||
final private int radius = 20;
|
final private int radius = 20;
|
||||||
final private int roofHeight = 55;
|
|
||||||
private int generationOffset = 0;
|
private int generationOffset = 0;
|
||||||
private int difficulty = 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() {
|
public AcidRain() {
|
||||||
super(Dimension.OVERWORLD.key, "acidRain", new LastWinsScore());
|
super(Dimension.OVERWORLD.key, "acidRain", new LastWinsScore());
|
||||||
this.setGenerator(
|
setGenerator(
|
||||||
new CircularPlateTerrainGenerator(this.radius)
|
new CircularPlateTerrainGenerator(radius)
|
||||||
.setPlateHeight(50)
|
.setPlateHeight(50)
|
||||||
.setPlatePallet(BlockPallet.STONE)
|
.setPlatePallet(BlockPallet.STONE)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this.eventNode().addListener(PlayerTickEvent.class, this::onPlayerTick);
|
eventNode().addListener(PlayerTickEvent.class, this::onPlayerTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,40 +61,39 @@ public class AcidRain extends StatelessGame {
|
|||||||
|
|
||||||
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
||||||
|
|
||||||
this.getPlayers().forEach(player -> {
|
getPlayers().forEach(player -> {
|
||||||
player.sendPacket(new ParticlePacket(Particle.SNEEZE, 0, 60, 0, this.radius, this.radius, this.radius, 1f, 500));
|
player.sendPacket(new ParticlePacket(Particle.SNEEZE, 0, 60, 0, radius, radius, radius, 1f, 500));
|
||||||
player.sendPacket(new ParticlePacket(Particle.ITEM_SLIME, 0, 60, 0, this.radius, this.radius, this.radius, 1f, 500));
|
player.sendPacket(new ParticlePacket(Particle.ITEM_SLIME, 0, 60, 0, radius, radius, radius, 1f, 500));
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!this.isRunning) return TaskSchedule.stop();
|
if(!isRunning) return TaskSchedule.stop();
|
||||||
return TaskSchedule.millis(100);
|
return TaskSchedule.millis(100);
|
||||||
}, ExecutionType.TICK_END);
|
}, ExecutionType.TICK_END);
|
||||||
|
|
||||||
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
||||||
this.generationOffset++;
|
generationOffset++;
|
||||||
this.generatePlatform(this.generationOffset);
|
generatePlatform(generationOffset);
|
||||||
|
|
||||||
if(!this.isRunning) return TaskSchedule.stop();
|
if(!isRunning) return TaskSchedule.stop();
|
||||||
return TaskSchedule.millis((long) NumberUtil.map(50 - this.difficulty, 0, 50, 100, 1000));
|
return TaskSchedule.millis((long) NumberUtil.map(50 - difficulty, 0, 50, 100, 1000));
|
||||||
}, ExecutionType.TICK_END);
|
}, ExecutionType.TICK_END);
|
||||||
|
|
||||||
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
MinecraftServer.getSchedulerManager().submitTask(() -> {
|
||||||
this.difficulty++;
|
difficulty++;
|
||||||
|
|
||||||
if(this.difficulty >= 50) return TaskSchedule.stop();
|
if(difficulty >= 50) return TaskSchedule.stop();
|
||||||
return TaskSchedule.seconds(3);
|
return TaskSchedule.seconds(3);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
if(playerMoveEvent.getNewPosition().y() < 50) this.playerDeath(playerMoveEvent.getPlayer());
|
if(playerMoveEvent.getNewPosition().y() < 50) playerDeath(playerMoveEvent.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPlayerTick(PlayerTickEvent playerTickEvent) {
|
private void onPlayerTick(PlayerTickEvent playerTickEvent) {
|
||||||
if(this.isBeforeBeginning) return;
|
if(isBeforeBeginning) return;
|
||||||
if(this.getBlock(playerTickEvent.getPlayer().getPosition().withY(this.roofHeight)).isAir())
|
if(getBlock(playerTickEvent.getPlayer().getPosition().withY(roofHeight)).isAir()) playerDeath(playerTickEvent.getPlayer());
|
||||||
this.playerDeath(playerTickEvent.getPlayer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generatePlatform(long offset) {
|
private void generatePlatform(long offset) {
|
||||||
@@ -103,20 +102,19 @@ public class AcidRain extends StatelessGame {
|
|||||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
for(int x = -radius; x <= radius; x++) {
|
for(int x = -radius; x <= radius; x++) {
|
||||||
for(int z = -radius; z <= radius; z++) {
|
for(int z = -radius; z <= radius; z++) {
|
||||||
batch.setBlock(x, this.roofHeight, z, Block.AIR);
|
batch.setBlock(x, roofHeight, z, Block.AIR);
|
||||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||||
if(this.noise.evaluateNoise(x + offset, z + offset) > 0.4) continue;
|
if(noise.getNoise(x + offset, z + offset) > 0.4) continue;
|
||||||
|
|
||||||
batch.setBlock(x, this.roofHeight, z, Block.OAK_PLANKS);
|
batch.setBlock(x, roofHeight, z, Block.OAK_PLANKS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BatchUtil.loadAndApplyBatch(batch, this, () -> {
|
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playerDeath(Player p) {
|
private void playerDeath(Player p) {
|
||||||
p.setGameMode(GameMode.SPECTATOR);
|
p.setGameMode(GameMode.SPECTATOR);
|
||||||
this.getScore().insertResult(p);
|
getScore().insertResult(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+19
-20
@@ -1,8 +1,8 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun;
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
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.util.BatchUtil;
|
||||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
@@ -27,10 +27,10 @@ class AnvilRun extends StatelessGame {
|
|||||||
|
|
||||||
final int spawnHeight = 30;
|
final int spawnHeight = 30;
|
||||||
final int radius;
|
final int radius;
|
||||||
|
int anvilsPerSecond;
|
||||||
final int seconds;
|
final int seconds;
|
||||||
final int anvilHeight = 200;
|
final int anvilHeight = 200;
|
||||||
final List<Pos> anvilSpawnPositions = new ArrayList<>();
|
final List<Pos> anvilSpawnPositions = new ArrayList<>();
|
||||||
int anvilsPerSecond;
|
|
||||||
|
|
||||||
public AnvilRun(int radius, int seconds) {
|
public AnvilRun(int radius, int seconds) {
|
||||||
super(Dimension.OVERWORLD.key, "Anvil Run", new LastWinsScore());
|
super(Dimension.OVERWORLD.key, "Anvil Run", new LastWinsScore());
|
||||||
@@ -38,25 +38,25 @@ class AnvilRun extends StatelessGame {
|
|||||||
this.seconds = seconds;
|
this.seconds = seconds;
|
||||||
this.setGenerator(new CircularPlateTerrainGenerator(radius));
|
this.setGenerator(new CircularPlateTerrainGenerator(radius));
|
||||||
|
|
||||||
this.eventNode().addListener(EntityTickEvent.class, this::onEntityTick);
|
eventNode().addListener(EntityTickEvent.class, this::onEntityTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
|
|
||||||
for(int x = -this.radius; x <= this.radius; x++) {
|
for(int x = -radius; x <= radius; x++) {
|
||||||
for(int z = -this.radius; z <= this.radius; z++) {
|
for (int z = -radius; z <= radius; z++) {
|
||||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > this.radius) continue;
|
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||||
|
|
||||||
this.anvilSpawnPositions.add(new Pos(x + 0.5, this.anvilHeight, z + 0.5));
|
anvilSpawnPositions.add(new Pos(x+0.5, anvilHeight, z+0.5));
|
||||||
|
|
||||||
batch.setBlock(x, this.spawnHeight - 1, z, Block.SNOW_BLOCK);
|
batch.setBlock(x, spawnHeight-1, z, Block.SNOW_BLOCK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.anvilsPerSecond = this.anvilSpawnPositions.size() / this.seconds;
|
this.anvilsPerSecond = anvilSpawnPositions.size() / this.seconds;
|
||||||
Collections.shuffle(this.anvilSpawnPositions);
|
Collections.shuffle(anvilSpawnPositions);
|
||||||
|
|
||||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ class AnvilRun extends StatelessGame {
|
|||||||
for(int i=0; i<this.anvilSpawnPositions.size(); i++) {
|
for(int i=0; i<this.anvilSpawnPositions.size(); i++) {
|
||||||
final int j = i;
|
final int j = i;
|
||||||
scheduler.scheduleTask(
|
scheduler.scheduleTask(
|
||||||
() -> this.spawnAnvil(this.anvilSpawnPositions.get(j)),
|
() -> spawnAnvil(this.anvilSpawnPositions.get(j)),
|
||||||
TaskSchedule.millis(
|
TaskSchedule.millis(
|
||||||
(long) Math.floor((double) i/this.anvilsPerSecond * 1000)
|
(long) Math.floor((double) i/this.anvilsPerSecond * 1000)
|
||||||
),
|
),
|
||||||
@@ -87,26 +87,25 @@ class AnvilRun extends StatelessGame {
|
|||||||
@Override
|
@Override
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
super.onPlayerMove(playerMoveEvent);
|
super.onPlayerMove(playerMoveEvent);
|
||||||
if(this.isBeforeBeginning && playerMoveEvent.getNewPosition().y() < this.spawnHeight - 2) {
|
if(isBeforeBeginning && playerMoveEvent.getNewPosition().y() < spawnHeight - 2) {
|
||||||
playerMoveEvent.setCancelled(true);
|
playerMoveEvent.setCancelled(true);
|
||||||
playerMoveEvent.getPlayer().teleport(this.getSpawn());
|
playerMoveEvent.getPlayer().teleport(getSpawn());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(playerMoveEvent.getNewPosition().y() < this.spawnHeight - 2)
|
if(playerMoveEvent.getNewPosition().y() < spawnHeight - 2) getScore().insertResult(playerMoveEvent.getPlayer());
|
||||||
this.getScore().insertResult(playerMoveEvent.getPlayer());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
||||||
if(!entityTickEvent.getEntity().getEntityType().equals(EntityType.FALLING_BLOCK)) return;
|
if(!entityTickEvent.getEntity().getEntityType().equals(EntityType.FALLING_BLOCK)) return;
|
||||||
Pos anvilPosition = entityTickEvent.getEntity().getPosition();
|
Pos anvilPosition = entityTickEvent.getEntity().getPosition();
|
||||||
if(anvilPosition.y() > this.spawnHeight + 0.5) return;
|
if(anvilPosition.y() > spawnHeight + 0.5) return;
|
||||||
if(anvilPosition.y() < this.spawnHeight - 3) entityTickEvent.getEntity().remove();
|
if(anvilPosition.y() < spawnHeight - 3) entityTickEvent.getEntity().remove();
|
||||||
if(this.getBlock(anvilPosition.withY(this.spawnHeight - 1)).isAir()) return;
|
if(this.getBlock(anvilPosition.withY(spawnHeight-1)).isAir()) return;
|
||||||
this.setBlock(anvilPosition.withY(this.spawnHeight - 1), Block.AIR);
|
this.setBlock(anvilPosition.withY(spawnHeight-1), Block.AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
return new Pos(0, this.spawnHeight, 0);
|
return new Pos(0, spawnHeight, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.anvilRun;
|
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.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.GameFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
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.game.stateless.config.common.NumericOption;
|
||||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||||
@@ -26,7 +26,7 @@ public class AnvilRunFactory implements GameFactory {
|
|||||||
public ConfigManager configuration() {
|
public ConfigManager configuration() {
|
||||||
return new ConfigManager()
|
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("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 5, 10, 15, 20, 25, 30))
|
||||||
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("optionCommon#seconds"), 10, 30, 60, 90, 120));
|
.addOption(new NumericOption("seconds", Material.STICK, TranslatedComponent.byId("optionCommon#seconds"), 10, 30, 60, 90, 120));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ public class Backrooms extends StatelessGame {
|
|||||||
public Backrooms() {
|
public Backrooms() {
|
||||||
super(Dimension.NETHER.key, "Backrooms", new NoScore());
|
super(Dimension.NETHER.key, "Backrooms", new NoScore());
|
||||||
BackroomsGenerator generator = new BackroomsGenerator();
|
BackroomsGenerator generator = new BackroomsGenerator();
|
||||||
this.setGenerator(unit -> generator.generateRoom(unit, 50));
|
setGenerator(unit -> generator.generateRoom(unit, 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+11
-12
@@ -3,7 +3,6 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms;
|
|||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.instance.generator.GenerationUnit;
|
import net.minestom.server.instance.generator.GenerationUnit;
|
||||||
import net.minestom.server.instance.generator.UnitModifier;
|
import net.minestom.server.instance.generator.UnitModifier;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class BackroomsGenerator {
|
public class BackroomsGenerator {
|
||||||
@@ -37,14 +36,14 @@ public class BackroomsGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.generateWalls(modifier, start.blockX(), yPos + 1, start.blockZ());
|
generateWalls(modifier, start.blockX() + 0, yPos + 1, start.blockZ() + 0);
|
||||||
this.generateWalls(modifier, start.blockX() + 8, yPos + 1, start.blockZ());
|
generateWalls(modifier, start.blockX() + 8, yPos + 1, start.blockZ() + 0);
|
||||||
this.generateWalls(modifier, start.blockX(), yPos + 1, start.blockZ() + 8);
|
generateWalls(modifier, start.blockX() + 0, yPos + 1, start.blockZ() + 8);
|
||||||
this.generateWalls(modifier, start.blockX() + 8, 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) {
|
private void generateWalls(UnitModifier modifier, int xPos, int yPos, int zPos) {
|
||||||
this.generatePillar(modifier, xPos, yPos, zPos, Block.CHISELED_SANDSTONE);
|
generatePillar(modifier, xPos, yPos, zPos, Block.CHISELED_SANDSTONE);
|
||||||
|
|
||||||
var random = ThreadLocalRandom.current();
|
var random = ThreadLocalRandom.current();
|
||||||
|
|
||||||
@@ -58,24 +57,24 @@ public class BackroomsGenerator {
|
|||||||
|
|
||||||
if (wall1) {
|
if (wall1) {
|
||||||
for (int x = xPos; x < xPos + 8; x++) {
|
for (int x = xPos; x < xPos + 8; x++) {
|
||||||
this.generatePillar(modifier, x, yPos, zPos, Block.SMOOTH_SANDSTONE);
|
generatePillar(modifier, x, yPos, zPos, Block.SMOOTH_SANDSTONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wall2) {
|
if (wall2) {
|
||||||
for (int z = zPos; z < zPos + 8; z++) {
|
for (int z = zPos; z < zPos + 8; z++) {
|
||||||
this.generatePillar(modifier, xPos, yPos, z, Block.SMOOTH_SANDSTONE);
|
generatePillar(modifier, xPos, yPos, z, Block.SMOOTH_SANDSTONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (door1 && wall1) {
|
if (door1 && wall1) {
|
||||||
this.generatePillar(modifier, xPos + door1pos, yPos, zPos, Block.AIR);
|
generatePillar(modifier, xPos + door1pos, yPos, zPos, Block.AIR);
|
||||||
this.generatePillar(modifier, xPos + door1pos + 1, yPos, zPos, Block.AIR);
|
generatePillar(modifier, xPos + door1pos + 1, yPos, zPos, Block.AIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (door2 && wall2) {
|
if (door2 && wall2) {
|
||||||
this.generatePillar(modifier, xPos, yPos, zPos + door2pos, Block.AIR);
|
generatePillar(modifier, xPos, yPos, zPos + door2pos, Block.AIR);
|
||||||
this.generatePillar(modifier, xPos, yPos, zPos + door2pos + 1, Block.AIR);
|
generatePillar(modifier, xPos, yPos, zPos + door2pos + 1, Block.AIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-17
@@ -26,13 +26,10 @@ import net.minestom.server.item.ItemStack;
|
|||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
import net.minestom.server.timer.ExecutionType;
|
import net.minestom.server.timer.ExecutionType;
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
import net.minestom.server.world.DimensionType;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Bedwars extends StatelessGame {
|
public class Bedwars extends StatelessGame {
|
||||||
|
|
||||||
@@ -42,13 +39,13 @@ public class Bedwars extends StatelessGame {
|
|||||||
|
|
||||||
public Bedwars() throws IOException {
|
public Bedwars() throws IOException {
|
||||||
super(Dimension.OVERWORLD.key, "Bedwars", new LastWinsScore());
|
super(Dimension.OVERWORLD.key, "Bedwars", new LastWinsScore());
|
||||||
this.setChunkLoader(new AnvilLoader(Resource.GAME_MAP.getPath().resolve("bedwars/test"), DimensionType.OVERWORLD.key()));
|
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());
|
Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(Resource.GAME_MAP.getPath().resolve("bedwars/test/config.yml").toFile());
|
||||||
List<String> teamNames = config.getStringList("setup.teams");
|
List<String> teamNames = config.getStringList("setup.teams");
|
||||||
teamNames.forEach(teamName -> {
|
teamNames.forEach(teamName -> {
|
||||||
String path = "teams." + teamName;
|
String path = "teams." + teamName;
|
||||||
this.teams.add(new BedwarsTeam(
|
teams.add(new BedwarsTeam(
|
||||||
config.getString(path + ".name"),
|
config.getString(path + ".name"),
|
||||||
Position.getPosFromCommaSeparated(config.getString(path + ".pos.spawn")),
|
Position.getPosFromCommaSeparated(config.getString(path + ".pos.spawn")),
|
||||||
Position.getPosFromCommaSeparated(config.getString(path + ".pos.spawner")),
|
Position.getPosFromCommaSeparated(config.getString(path + ".pos.spawner")),
|
||||||
@@ -57,7 +54,7 @@ public class Bedwars extends StatelessGame {
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.eventNode().addListener(PickupItemEvent.class, pickupItemEvent -> {
|
eventNode().addListener(PickupItemEvent.class, pickupItemEvent -> {
|
||||||
if(pickupItemEvent.getEntity() instanceof Player p) {
|
if(pickupItemEvent.getEntity() instanceof Player p) {
|
||||||
p.getInventory().addItemStack(pickupItemEvent.getItemStack());
|
p.getInventory().addItemStack(pickupItemEvent.getItemStack());
|
||||||
}
|
}
|
||||||
@@ -71,10 +68,10 @@ public class Bedwars extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
this.scheduler().submitTask(() -> {
|
scheduler().submitTask(() -> {
|
||||||
if(!this.isRunning) return TaskSchedule.stop();
|
if(!isRunning) return TaskSchedule.stop();
|
||||||
|
|
||||||
this.teams.forEach(bedwarsTeam -> {
|
teams.forEach(bedwarsTeam -> {
|
||||||
ItemEntity item = new ItemEntity(ItemStack.of(bedwarsTeam.getBlock()));
|
ItemEntity item = new ItemEntity(ItemStack.of(bedwarsTeam.getBlock()));
|
||||||
item.setNoGravity(true);
|
item.setNoGravity(true);
|
||||||
item.setInstance(this, bedwarsTeam.getSpawner());
|
item.setInstance(this, bedwarsTeam.getSpawner());
|
||||||
@@ -87,17 +84,16 @@ public class Bedwars extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) {
|
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) {
|
||||||
this.placedBlocks.add(playerBlockPlaceEvent.getBlockPosition());
|
placedBlocks.add(playerBlockPlaceEvent.getBlockPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
|
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
|
||||||
if(!this.placedBlocks.contains(playerBlockBreakEvent.getBlockPosition()))
|
if(!placedBlocks.contains(playerBlockBreakEvent.getBlockPosition())) playerBlockBreakEvent.setCancelled(true);
|
||||||
playerBlockBreakEvent.setCancelled(true);
|
|
||||||
|
|
||||||
this.teams.forEach(bedwarsTeam -> {
|
teams.forEach(bedwarsTeam -> {
|
||||||
if(Arrays.stream(bedwarsTeam.getBed()).anyMatch(pos -> pos.sameBlock(playerBlockBreakEvent.getBlockPosition())))
|
if(Arrays.stream(bedwarsTeam.getBed()).anyMatch(pos -> pos.sameBlock(playerBlockBreakEvent.getBlockPosition())))
|
||||||
this.breakBed(bedwarsTeam);
|
breakBed(bedwarsTeam);
|
||||||
});
|
});
|
||||||
|
|
||||||
if(playerBlockBreakEvent.isCancelled())
|
if(playerBlockBreakEvent.isCancelled())
|
||||||
@@ -106,13 +102,13 @@ public class Bedwars extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
if(playerMoveEvent.getNewPosition().y() < 0) this.death(playerMoveEvent.getPlayer());
|
if(playerMoveEvent.getNewPosition().y() < 0) death(playerMoveEvent.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void breakBed(BedwarsTeam team) {
|
private void breakBed(BedwarsTeam team) {
|
||||||
team.removeBed();
|
team.removeBed();
|
||||||
for (Pos blockPos : team.getBed()) {
|
for (Pos blockPos : team.getBed()) {
|
||||||
this.setBlock(blockPos, Material.AIR.block());
|
setBlock(blockPos, Material.AIR.block());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-8
@@ -8,12 +8,16 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class BedwarsTeam {
|
public class BedwarsTeam {
|
||||||
|
private List<Player> members = new ArrayList<>();
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Pos spawn;
|
private final Pos spawn;
|
||||||
private final Pos spawner;
|
private final Pos spawner;
|
||||||
|
|
||||||
private final Pos[] bed;
|
private final Pos[] bed;
|
||||||
|
|
||||||
private final Material block;
|
private final Material block;
|
||||||
private List<Player> members = new ArrayList<>();
|
|
||||||
private boolean hasBed = true;
|
private boolean hasBed = true;
|
||||||
|
|
||||||
public BedwarsTeam(String name, Pos spawn, Pos spawner, Pos[] bed, Material block) {
|
public BedwarsTeam(String name, Pos spawn, Pos spawner, Pos[] bed, Material block) {
|
||||||
@@ -29,11 +33,11 @@ public class BedwarsTeam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHasBed() {
|
public boolean isHasBed() {
|
||||||
return this.hasBed;
|
return hasBed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Player> getMembers() {
|
public List<Player> getMembers() {
|
||||||
return this.members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMembers(List<Player> members) {
|
public void setMembers(List<Player> members) {
|
||||||
@@ -41,22 +45,22 @@ public class BedwarsTeam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
return this.spawn;
|
return spawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pos getSpawner() {
|
public Pos getSpawner() {
|
||||||
return this.spawner;
|
return spawner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pos[] getBed() {
|
public Pos[] getBed() {
|
||||||
return this.bed;
|
return bed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getBlock() {
|
public Material getBlock() {
|
||||||
return this.block;
|
return block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-207
@@ -1,207 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
|
||||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
|
||||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
|
||||||
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.GameMode;
|
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
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.batch.AbsoluteBlockBatch;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import net.minestom.server.item.ItemStack;
|
|
||||||
import net.minestom.server.item.Material;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class BlockBattle extends StatelessGame {
|
|
||||||
private final Team teamBlue = new Team(new Pos(0,101,20).add(0.5).withView(180, 0), Team.Color.BLUE);
|
|
||||||
private final Team teamRed = new Team(new Pos(0, 101, -20).add(0.5), Team.Color.RED);
|
|
||||||
private final int itemCount;
|
|
||||||
|
|
||||||
private final Map<Player, Team> teams = new WeakHashMap<>();
|
|
||||||
|
|
||||||
public BlockBattle(int itemCount) {
|
|
||||||
super(Dimension.THE_END.key, "Block Battle", new FirstWinsScore());
|
|
||||||
|
|
||||||
this.itemCount = itemCount;
|
|
||||||
|
|
||||||
this.eventNode().addChild(
|
|
||||||
CombatFeatures.empty()
|
|
||||||
.add(CombatFeatures.VANILLA_ATTACK)
|
|
||||||
.add(CombatFeatures.VANILLA_DAMAGE)
|
|
||||||
.add(CombatFeatures.VANILLA_KNOCKBACK)
|
|
||||||
.build().createNode()
|
|
||||||
);
|
|
||||||
|
|
||||||
this.eventNode().addListener(FinalAttackEvent.class, finalAttackEvent -> {
|
|
||||||
if(!this.isRunning) finalAttackEvent.setCancelled(true);
|
|
||||||
finalAttackEvent.setBaseDamage(0);
|
|
||||||
((Player) finalAttackEvent.getTarget()).setHealth(20);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
|
||||||
this.generatePlatform(new Pos(0, 100, 0), Block.GOLD_BLOCK, Block.YELLOW_CONCRETE_POWDER);
|
|
||||||
this.generatePlatform(new Pos(0, 101, 0), Block.AIR, Block.SANDSTONE_SLAB);
|
|
||||||
this.generatePlatform(new Pos(0, 100, 20), Block.BLUE_CONCRETE, Block.BLUE_CONCRETE_POWDER);
|
|
||||||
this.generatePlatform(new Pos(0, 100, -20), Block.RED_CONCRETE, Block.RED_CONCRETE_POWDER);
|
|
||||||
this.generatePlatform(new Pos(-5, 101, -14), Block.RED_STAINED_GLASS, Block.AIR);
|
|
||||||
this.generatePlatform(new Pos(5, 101, 14), Block.BLUE_STAINED_GLASS, Block.AIR);
|
|
||||||
|
|
||||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
|
||||||
|
|
||||||
Pos[] positionsRedGlass = {
|
|
||||||
new Pos(2, 102, -9),
|
|
||||||
new Pos(-1, 103, -9),
|
|
||||||
new Pos(-2, 104, -6),
|
|
||||||
new Pos(-5, 103, -7),
|
|
||||||
new Pos(-7, 102, -10),
|
|
||||||
new Pos(3, 102, -12),
|
|
||||||
new Pos(5, 101, -15)
|
|
||||||
};
|
|
||||||
|
|
||||||
Pos[] positionsBlueGlass = {
|
|
||||||
new Pos(-5, 101, 15),
|
|
||||||
new Pos(-3, 102, 12),
|
|
||||||
new Pos(-2, 102, 9),
|
|
||||||
new Pos(1, 103, 9),
|
|
||||||
new Pos(2, 104, 6),
|
|
||||||
new Pos(5, 103, 7),
|
|
||||||
new Pos(7, 102, 10)
|
|
||||||
};
|
|
||||||
|
|
||||||
for(Pos pos : positionsRedGlass)
|
|
||||||
batch.setBlock(pos, Block.RED_STAINED_GLASS);
|
|
||||||
|
|
||||||
for(Pos pos : positionsBlueGlass)
|
|
||||||
batch.setBlock(pos, Block.BLUE_STAINED_GLASS);
|
|
||||||
|
|
||||||
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) {
|
|
||||||
Pos posGoldBlock = new Pos(playerBlockPlaceEvent.getBlockPosition()).sub(0, 1, 0);
|
|
||||||
Block goldBlock = playerBlockPlaceEvent.getInstance().getBlock(posGoldBlock);
|
|
||||||
|
|
||||||
playerBlockPlaceEvent.setCancelled(goldBlock != Block.GOLD_BLOCK);
|
|
||||||
|
|
||||||
playerBlockPlaceEvent.getInstance().scheduler().scheduleNextTick(() -> {
|
|
||||||
Pos middle = new Pos(0, 101, 0);
|
|
||||||
boolean validBlue = true;
|
|
||||||
boolean validRed = true;
|
|
||||||
|
|
||||||
for(int x = middle.blockX()-1; x < middle.blockX()+2; x++) {
|
|
||||||
for(int z = middle.blockZ()-1; z < middle.blockZ()+2; z++) {
|
|
||||||
if(playerBlockPlaceEvent.getInstance().getBlock(x, 101, z) != Block.BLUE_WOOL) {
|
|
||||||
validBlue = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!validBlue)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int x = middle.blockX()-1; x < middle.blockX()+2; x++) {
|
|
||||||
for(int z = middle.blockZ()-1; z < middle.blockZ()+2; z++) {
|
|
||||||
if(playerBlockPlaceEvent.getInstance().getBlock(x, 101, z) != Block.RED_WOOL) {
|
|
||||||
validRed = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!validRed)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!validBlue && !validRed) return;
|
|
||||||
var winningTeam = validBlue ? Team.Color.BLUE : Team.Color.RED;
|
|
||||||
var winningPlayers = this.teams.entrySet().stream()
|
|
||||||
.filter(entry -> entry.getValue().color().equals(winningTeam))
|
|
||||||
.map(Map.Entry::getKey)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
this.getScore().insertMultiple(winningPlayers);
|
|
||||||
super.stop();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
|
|
||||||
boolean isAllowed = Arrays.stream(Team.Color.values())
|
|
||||||
.map(Team.Color::getMaterial)
|
|
||||||
.map(Material::block)
|
|
||||||
.toList()
|
|
||||||
.contains(playerBlockBreakEvent.getBlock());
|
|
||||||
if(!isAllowed) playerBlockBreakEvent.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
|
||||||
if(playerMoveEvent.getNewPosition().y() < 95) {
|
|
||||||
var player = playerMoveEvent.getPlayer();
|
|
||||||
|
|
||||||
player.teleport(
|
|
||||||
this.isBeforeBeginning
|
|
||||||
? this.getSpawn()
|
|
||||||
: this.teams.get(player).spawnPosition()
|
|
||||||
);
|
|
||||||
|
|
||||||
this.giveItems(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
this.setTeams();
|
|
||||||
this.getPlayers().forEach(player -> player.teleport(this.teams.get(player).spawnPosition()).thenRun(() -> {
|
|
||||||
this.giveItems(player);
|
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generatePlatform(Pos center, Block inner, Block outer) {
|
|
||||||
for(int x = center.blockX()-2; x < center.blockX()+3; x++) {
|
|
||||||
for(int z = center.blockZ()-2; z < center.blockZ()+3; z++) {
|
|
||||||
this.setBlock(x, center.blockY(), z, outer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int x = center.blockX()-1; x < center.blockX()+2; x++) {
|
|
||||||
for(int z = center.blockZ()-1; z < center.blockZ()+2; z++) {
|
|
||||||
this.setBlock(x, center.blockY(), z, inner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setTeams() {
|
|
||||||
List<Player> players = new ArrayList<>(this.getPlayers());
|
|
||||||
Collections.shuffle(players);
|
|
||||||
int halfPlayers = players.size()/2;
|
|
||||||
players.subList(0, halfPlayers).forEach(player -> this.teams.put(player, this.teamBlue));
|
|
||||||
players.subList(halfPlayers, players.size()).forEach(player -> this.teams.put(player, this.teamRed));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Pos getSpawn() {
|
|
||||||
return new Pos(0, 101, 0).add(0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void giveItems(Player player) {
|
|
||||||
player.getInventory().clear();
|
|
||||||
ItemStack item = ItemStack.of(
|
|
||||||
this.teams.get(player).color().getMaterial(),
|
|
||||||
this.itemCount
|
|
||||||
);
|
|
||||||
player.getInventory().addItemStack(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
|
||||||
|
|
||||||
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 BlockBattleFactory implements GameFactory {
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent name() {
|
|
||||||
return TranslatedComponent.byId("game_BlockBattle#name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent description() {
|
|
||||||
return TranslatedComponent.byId("game_BlockBattle#description");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConfigManager configuration() {
|
|
||||||
return new ConfigManager()
|
|
||||||
.addOption(new NumericOption("itemCount", Material.WHITE_WOOL, TranslatedComponent.byId("game_BlockBattle#itemCount"), 1, 2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Material symbol() {
|
|
||||||
return Material.GREEN_CONCRETE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
|
||||||
return new BlockBattle(configuration.get("itemCount").getAsInt()).setParent(parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-21
@@ -1,21 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBattle;
|
|
||||||
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
|
||||||
import net.minestom.server.item.Material;
|
|
||||||
|
|
||||||
public record Team(Pos spawnPosition, Color color) {
|
|
||||||
public enum Color {
|
|
||||||
RED(Material.RED_WOOL),
|
|
||||||
BLUE(Material.BLUE_WOOL);
|
|
||||||
|
|
||||||
private final Material block;
|
|
||||||
|
|
||||||
Color(Material block) {
|
|
||||||
this.block = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getMaterial() {
|
|
||||||
return this.block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-79
@@ -1,79 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
|
||||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
|
||||||
import net.minestom.server.entity.GameMode;
|
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
|
||||||
import net.minestom.server.inventory.PlayerInventory;
|
|
||||||
import net.minestom.server.item.ItemStack;
|
|
||||||
import net.minestom.server.item.Material;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BlockBreakRace extends StatelessGame {
|
|
||||||
private final int height;
|
|
||||||
private int spawnCount = 0;
|
|
||||||
|
|
||||||
public BlockBreakRace(int height) {
|
|
||||||
super(Dimension.OVERWORLD.key, "blockBreakRace", new FirstWinsScore());
|
|
||||||
this.height = height;
|
|
||||||
this.setGenerator(new BlockBreakRaceGenerator(height));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean onPlayerJoin(Player p) {
|
|
||||||
PlayerInventory inv = p.getInventory();
|
|
||||||
inv.addItemStack(ItemStack.of(Material.DIAMOND_PICKAXE));
|
|
||||||
inv.addItemStack(ItemStack.of(Material.DIAMOND_AXE));
|
|
||||||
inv.addItemStack(ItemStack.of(Material.DIAMOND_SHOVEL));
|
|
||||||
return super.onPlayerJoin(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
this.getPlayers().forEach(player -> player.setGameMode(GameMode.SURVIVAL));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent event) {
|
|
||||||
List<Material> allowedMaterials = List.of(Material.STONE, Material.OAK_PLANKS, Material.DIRT);
|
|
||||||
if(!allowedMaterials.contains(event.getBlock().registry().material())) event.setCancelled(true);
|
|
||||||
if(this.isBeforeBeginning) event.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
|
||||||
if(this.isBeforeBeginning) return;
|
|
||||||
if(playerMoveEvent.getNewPosition().y() < BlockBreakRaceGenerator.BOTTOM_Y) {
|
|
||||||
Player player = playerMoveEvent.getPlayer();
|
|
||||||
this.getScore().insertResult(player);
|
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
|
||||||
player.getInventory().clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Pos getSpawn() {
|
|
||||||
int idx = this.spawnCount++;
|
|
||||||
|
|
||||||
int cols = BlockBreakRaceGenerator.ROW_OFFSETS_X.length;
|
|
||||||
int rows = BlockBreakRaceGenerator.ROW_OFFSETS_Z.length;
|
|
||||||
int perChunk = cols * rows;
|
|
||||||
int zChunk = idx / perChunk;
|
|
||||||
|
|
||||||
int gridIndex = idx % perChunk;
|
|
||||||
int xIndex = gridIndex % cols;
|
|
||||||
int zIndex = gridIndex / cols;
|
|
||||||
|
|
||||||
int localX = BlockBreakRaceGenerator.ROW_OFFSETS_X[xIndex];
|
|
||||||
int localZ = BlockBreakRaceGenerator.ROW_OFFSETS_Z[zIndex];
|
|
||||||
|
|
||||||
int absZ = (zChunk * 16) + localZ;
|
|
||||||
return new Pos(localX, BlockBreakRaceGenerator.BOTTOM_Y + this.height + 1, absZ).add(0.5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-40
@@ -1,40 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace;
|
|
||||||
|
|
||||||
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 BlockBreakRaceFactory implements GameFactory {
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent name() {
|
|
||||||
return TranslatedComponent.byId("game_BlockBreakRace#name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Material symbol() {
|
|
||||||
return Material.DIAMOND_PICKAXE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent description() {
|
|
||||||
return TranslatedComponent.byId("game_BlockBreakRace#description");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConfigManager configuration() {
|
|
||||||
return new ConfigManager()
|
|
||||||
.addOption(new NumericOption("height", Material.SCAFFOLDING, TranslatedComponent.byId("optionCommon#height"), 20, 30, 40, 50));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
|
||||||
return new BlockBreakRace(configuration.get("height").getAsInt()).setParent(parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-65
@@ -1,65 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.blockBreakRace;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.world.generator.featureEnriched.ValeGenerator;
|
|
||||||
import eu.mhsl.minenet.minigames.world.generator.terrain.BaseGenerator;
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import net.minestom.server.instance.generator.GenerationUnit;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
public class BlockBreakRaceGenerator extends BaseGenerator {
|
|
||||||
public static final int BOTTOM_Y = 50;
|
|
||||||
public static final int[] ROW_OFFSETS_X = {4, 8, 12};
|
|
||||||
public static final int[] ROW_OFFSETS_Z = {4, 8, 12};
|
|
||||||
private static final Block[] FILL_BLOCKS = {
|
|
||||||
Block.STONE,
|
|
||||||
Block.DIRT,
|
|
||||||
Block.OAK_PLANKS
|
|
||||||
};
|
|
||||||
public final int TOP_Y;
|
|
||||||
private final Random random = ThreadLocalRandom.current();
|
|
||||||
|
|
||||||
public BlockBreakRaceGenerator(int height) {
|
|
||||||
this.TOP_Y = BOTTOM_Y + height;
|
|
||||||
ValeGenerator vale = new ValeGenerator();
|
|
||||||
vale.setXShiftMultiplier(i -> 0.5d);
|
|
||||||
vale.setHeightNoiseMultiplier(i -> 2);
|
|
||||||
vale.setXShiftOffset(i -> 40d);
|
|
||||||
this.addMixIn(vale);
|
|
||||||
|
|
||||||
this.addMixIn(unit -> {
|
|
||||||
if(unit.absoluteStart().chunkX() != 0) return;
|
|
||||||
|
|
||||||
for(int localX : ROW_OFFSETS_X) {
|
|
||||||
for(int localZ : ROW_OFFSETS_Z) {
|
|
||||||
final int absZ = unit.absoluteStart().blockZ() + localZ;
|
|
||||||
this.placeTube(unit, localX, absZ);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void placeTube(GenerationUnit unit, int x, int z) {
|
|
||||||
for(int y = BOTTOM_Y; y < this.TOP_Y; y++) {
|
|
||||||
Block fill = FILL_BLOCKS[this.random.nextInt(FILL_BLOCKS.length)];
|
|
||||||
unit.modifier().fill(
|
|
||||||
new Pos(x, y, z),
|
|
||||||
new Pos(x, y, z).add(1),
|
|
||||||
fill
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int dx = -1; dx <= 1; dx++) {
|
|
||||||
for(int dz = -1; dz <= 1; dz++) {
|
|
||||||
if(dx == 0 && dz == 0) continue; // Zentrum überspringen
|
|
||||||
unit.modifier().fill(
|
|
||||||
new Pos(x + dx, BOTTOM_Y, z + dz),
|
|
||||||
new Pos(x + dx, this.TOP_Y + 3, z + dz).add(1),
|
|
||||||
Block.BARRIER
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-76
@@ -1,76 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.boatRace;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.Resource;
|
|
||||||
import eu.mhsl.minenet.minigames.handler.global.PlayerLoginHandler;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
|
||||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
|
||||||
import eu.mhsl.minenet.minigames.util.CommonProperties;
|
|
||||||
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.GameMode;
|
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
|
||||||
import net.minestom.server.instance.anvil.AnvilLoader;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import net.minestom.server.world.DimensionType;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
|
|
||||||
public class BoatRace extends StatelessGame {
|
|
||||||
public BoatRace() {
|
|
||||||
super(Dimension.OVERWORLD.key, "boatRace", new FirstWinsScore());
|
|
||||||
this.setChunkLoader(new AnvilLoader(Resource.GAME_MAP.getPath().resolve("boatRace/woodlandMansion"), DimensionType.OVERWORLD.key()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean onPlayerJoin(Player p) {
|
|
||||||
Entity boat = new Entity(EntityType.OAK_BOAT);
|
|
||||||
boat.setInstance(this, this.getSpawn());
|
|
||||||
boat.setSynchronizationTicks(100000);
|
|
||||||
PlayerLoginHandler.globalTeam.addMember(boat.getUuid().toString());
|
|
||||||
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> boat.addPassenger(p));
|
|
||||||
return super.onPlayerJoin(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
|
||||||
for(int z = 9; z <= 32; z++) {
|
|
||||||
this.setBlock(31, 235, z, Block.CHERRY_FENCE.withProperties(CommonProperties.fenceNorthSouth));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
for(int z = 9; z <= 32; z++) {
|
|
||||||
this.setBlock(31, 235, z, Block.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
|
||||||
if (this.isBeforeBeginning) return;
|
|
||||||
|
|
||||||
if(event.getNewPosition().z() > 469) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
this.getScore().insertResult(player);
|
|
||||||
|
|
||||||
Entity vehicle = player.getVehicle();
|
|
||||||
if(vehicle != null) {
|
|
||||||
vehicle.removePassenger(player);
|
|
||||||
player.teleport(player.getPosition().withY(y -> y + 3));
|
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
|
||||||
vehicle.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Pos getSpawn() {
|
|
||||||
return new Pos(20, 236, 20, -90, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-27
@@ -1,27 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.boatRace;
|
|
||||||
|
|
||||||
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 BoatRaceFactory implements GameFactory {
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent name() {
|
|
||||||
return TranslatedComponent.byId("game_BoatRace#name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Material symbol() {
|
|
||||||
return Material.OAK_BOAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
|
||||||
return new BoatRace().setParent(parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+14
-17
@@ -9,9 +9,7 @@ import eu.mhsl.minenet.minigames.util.GeneratorUtils;
|
|||||||
import net.minestom.server.coordinate.Point;
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.coordinate.Vec;
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.*;
|
||||||
import net.minestom.server.entity.EntityType;
|
|
||||||
import net.minestom.server.entity.GameMode;
|
|
||||||
import net.minestom.server.entity.metadata.other.PrimedTntMeta;
|
import net.minestom.server.entity.metadata.other.PrimedTntMeta;
|
||||||
import net.minestom.server.event.EventListener;
|
import net.minestom.server.event.EventListener;
|
||||||
import net.minestom.server.event.entity.projectile.ProjectileCollideWithBlockEvent;
|
import net.minestom.server.event.entity.projectile.ProjectileCollideWithBlockEvent;
|
||||||
@@ -31,7 +29,6 @@ public class BowSpleef extends StatelessGame {
|
|||||||
private static final Tag<Boolean> ARROW_FIRST_HIT = Tag.Boolean("ARROW_ALREADY_LIT");
|
private static final Tag<Boolean> ARROW_FIRST_HIT = Tag.Boolean("ARROW_ALREADY_LIT");
|
||||||
private final int radius = 30;
|
private final int radius = 30;
|
||||||
private final int totalElevation = 50;
|
private final int totalElevation = 50;
|
||||||
|
|
||||||
public BowSpleef() {
|
public BowSpleef() {
|
||||||
super(Dimension.OVERWORLD.key, "bowSpleef", new LastWinsScore());
|
super(Dimension.OVERWORLD.key, "bowSpleef", new LastWinsScore());
|
||||||
|
|
||||||
@@ -70,7 +67,7 @@ public class BowSpleef extends StatelessGame {
|
|||||||
// .build()
|
// .build()
|
||||||
// );
|
// );
|
||||||
|
|
||||||
this.eventNode().addListener(
|
eventNode().addListener(
|
||||||
EventListener
|
EventListener
|
||||||
.builder(ProjectileCollideWithBlockEvent.class)
|
.builder(ProjectileCollideWithBlockEvent.class)
|
||||||
.handler(projectileBlockHitEvent -> {
|
.handler(projectileBlockHitEvent -> {
|
||||||
@@ -83,9 +80,9 @@ public class BowSpleef extends StatelessGame {
|
|||||||
float radius = 0.5F;
|
float radius = 0.5F;
|
||||||
Point arrowPos = projectile.getPosition();
|
Point arrowPos = projectile.getPosition();
|
||||||
GeneratorUtils.foreachXZ(arrowPos.add(radius), arrowPos.sub(radius), point -> {
|
GeneratorUtils.foreachXZ(arrowPos.add(radius), arrowPos.sub(radius), point -> {
|
||||||
Point location = point.add(projectile.getVelocity().mul(0.04)).withY(this.totalElevation);
|
Point location = point.add(projectile.getVelocity().mul(0.04)).withY(totalElevation);
|
||||||
if(!this.getBlock(location).isAir()) {
|
if(!getBlock(location).isAir()) {
|
||||||
this.setBlock(location, Block.AIR);
|
setBlock(location, Block.AIR);
|
||||||
|
|
||||||
Entity fallingTnt = new Entity(EntityType.TNT);
|
Entity fallingTnt = new Entity(EntityType.TNT);
|
||||||
PrimedTntMeta fallingTntMeta = (PrimedTntMeta) fallingTnt.getEntityMeta();
|
PrimedTntMeta fallingTntMeta = (PrimedTntMeta) fallingTnt.getEntityMeta();
|
||||||
@@ -100,7 +97,7 @@ public class BowSpleef extends StatelessGame {
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
this.eventNode().addListener(
|
eventNode().addListener(
|
||||||
EventListener
|
EventListener
|
||||||
.builder(ProjectileCollideWithEntityEvent.class)
|
.builder(ProjectileCollideWithEntityEvent.class)
|
||||||
.handler(projectileEntityHitEvent -> projectileEntityHitEvent.setCancelled(true))
|
.handler(projectileEntityHitEvent -> projectileEntityHitEvent.setCancelled(true))
|
||||||
@@ -112,11 +109,11 @@ public class BowSpleef extends StatelessGame {
|
|||||||
@Override
|
@Override
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
for(int x = -this.radius; x <= this.radius; x++) {
|
for(int x = -radius; x <= radius; x++) {
|
||||||
for(int z = -this.radius; z <= this.radius; z++) {
|
for(int z = -radius; z <= radius; z++) {
|
||||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > this.radius) continue;
|
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||||
|
|
||||||
batch.setBlock(x, this.totalElevation, z, Block.TNT);
|
batch.setBlock(x, totalElevation, z, Block.TNT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||||
@@ -124,7 +121,7 @@ public class BowSpleef extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
this.getPlayers().forEach(player -> {
|
getPlayers().forEach(player -> {
|
||||||
player.getInventory().setItemStack(
|
player.getInventory().setItemStack(
|
||||||
0,
|
0,
|
||||||
ItemStack
|
ItemStack
|
||||||
@@ -138,14 +135,14 @@ public class BowSpleef extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
if(playerMoveEvent.getNewPosition().y() < this.totalElevation) {
|
if(playerMoveEvent.getNewPosition().y() < totalElevation) {
|
||||||
this.getScore().insertResult(playerMoveEvent.getPlayer());
|
getScore().insertResult(playerMoveEvent.getPlayer());
|
||||||
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
return new Pos(0, this.totalElevation + 1, 0);
|
return new Pos(0, totalElevation + 1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-8
@@ -3,8 +3,6 @@ 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.Game;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
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.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.instance.room.Room;
|
||||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||||
import net.minestom.server.item.Material;
|
import net.minestom.server.item.Material;
|
||||||
@@ -31,10 +29,4 @@ public class BowSpleefFactory implements GameFactory {
|
|||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||||
return new BowSpleef().setParent(parent);
|
return new BowSpleef().setParent(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestrictionHandler globalRestrictions() {
|
|
||||||
return new RestrictionHandler()
|
|
||||||
.addRestriction(new MinimalPlayeramountGameRestriction(2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+3
-216
@@ -2,225 +2,12 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
|
|||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
import eu.mhsl.minenet.minigames.score.PointsWinScore;
|
import eu.mhsl.minenet.minigames.score.NoScore;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.kyori.adventure.title.Title;
|
|
||||||
import net.minestom.server.coordinate.Point;
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
|
||||||
import net.minestom.server.entity.GameMode;
|
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockInteractEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerUseItemEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
|
|
||||||
import net.minestom.server.item.ItemStack;
|
|
||||||
import net.minestom.server.item.Material;
|
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
|
|
||||||
public class BuildBattle extends StatelessGame {
|
public class BuildBattle extends StatelessGame {
|
||||||
private static final int height = 100;
|
public BuildBattle() {
|
||||||
private static final int plotHalf = BuildBattleChunkgenerator.inner / 2;
|
super(Dimension.OVERWORLD.key, "buildBattle", new NoScore());
|
||||||
private static final int rowCount = 5;
|
|
||||||
private static final int ratingSeconds = 15;
|
|
||||||
private static final List<Material> ratingMaterials = List.of(
|
|
||||||
Material.RED_CONCRETE, Material.ORANGE_CONCRETE, Material.YELLOW_CONCRETE,
|
|
||||||
Material.LIME_CONCRETE, Material.GREEN_CONCRETE
|
|
||||||
);
|
|
||||||
private static final List<ItemStack> ratingItems = IntStream.range(0, ratingMaterials.size())
|
|
||||||
.mapToObj(i -> ItemStack.builder(ratingMaterials.get(i))
|
|
||||||
.customName(Component.text((i + 1) + " Punkte"))
|
|
||||||
.build())
|
|
||||||
.toList();
|
|
||||||
private static final List<String> themes = List.of(
|
|
||||||
"Burg", "Raumschiff", "Unterwasserwelt", "Pizzeria", "Spukhaus",
|
|
||||||
"Bauernhof", "Dschungel", "Zukunftsstadt", "Piratenschiff", "Vulkan",
|
|
||||||
"Freizeitpark", "Leuchtturm", "Wikingerdorf", "Weihnachtsmarkt",
|
|
||||||
"Schloss", "Strand", "Berghütte", "Bahnhof", "Zoo", "Schule",
|
|
||||||
"Zeitreise", "Ein Haus, das auf dem Kopf steht", "Eine Stadt auf dem Rücken eines Riesen",
|
|
||||||
"Wohnen in einer Schneekugel", "Alles ist aus Süßigkeiten", "Ein Schiff in der Luft",
|
|
||||||
"Das Museum der Zukunft", "Das letzte Haus vor dem Weltuntergang",
|
|
||||||
"Wenn Schweine fliegen könnten", "Das Gefängnis für Creeper", "Die Wohnung von Herobrine",
|
|
||||||
"Ein Dönerladen im Weltall", "Ein Spa für Enderman", "Der Käse-Palast",
|
|
||||||
"Mein Zimmer nach 3 Wochen ohne Aufräumen", "Die Hüpfburg des Todes"
|
|
||||||
);
|
|
||||||
|
|
||||||
private int spawnPosx = 0;
|
|
||||||
private int spawnPosz = 0;
|
|
||||||
private final Map<Player, Pos> spawnPositions = new WeakHashMap<>();
|
|
||||||
private final int seconds;
|
|
||||||
private final Map<Player, Integer> currentVotes = new HashMap<>();
|
|
||||||
private Player currentOwner = null;
|
|
||||||
|
|
||||||
public BuildBattle(int seconds) {
|
|
||||||
super(Dimension.THE_END.key, "BuildBattle", new PointsWinScore());
|
|
||||||
this.seconds = seconds;
|
|
||||||
this.setGenerator(new BuildBattleChunkgenerator(height));
|
|
||||||
BuildBattleBlockRules.register();
|
|
||||||
this.eventNode().addListener(PlayerUseItemEvent.class, this::onRatingItemUse);
|
|
||||||
this.eventNode().addListener(PlayerUseItemOnBlockEvent.class, e -> FluidFlowHelper.onBucketUse(e, p -> this.isInArea(p, e.getPlayer())));
|
|
||||||
this.eventNode().addListener(PlayerBlockInteractEvent.class, e -> {
|
|
||||||
if (this.isInArea(e.getBlockPosition(), e.getPlayer())) BuildBattleBlockRules.onInteract(e);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
String theme = themes.get(this.rnd.nextInt(themes.size()));
|
|
||||||
|
|
||||||
this.showTitle(Title.title(
|
|
||||||
Component.text("Thema", NamedTextColor.GOLD),
|
|
||||||
Component.text(theme, NamedTextColor.YELLOW)
|
|
||||||
));
|
|
||||||
this.sendMessage(Component.text("Euer Thema: ", NamedTextColor.GRAY)
|
|
||||||
.append(Component.text(theme, NamedTextColor.YELLOW)));
|
|
||||||
this.getPlayers().forEach(player -> player.setGameMode(GameMode.CREATIVE));
|
|
||||||
|
|
||||||
this.scheduler().scheduleTask(this::endBuildPhase, TaskSchedule.seconds(this.seconds), TaskSchedule.stop());
|
|
||||||
this.scheduleCountdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scheduleCountdown() {
|
|
||||||
int[] marks = {30, 10, 5, 4, 3, 2, 1};
|
|
||||||
for (int m : marks) {
|
|
||||||
if (this.seconds <= m) continue;
|
|
||||||
int remaining = m;
|
|
||||||
this.scheduler().scheduleTask(() -> {
|
|
||||||
NamedTextColor color = remaining <= 5 ? NamedTextColor.RED : (remaining <= 10 ? NamedTextColor.GOLD : NamedTextColor.YELLOW);
|
|
||||||
this.sendMessage(Component.text("Noch ", NamedTextColor.GRAY)
|
|
||||||
.append(Component.text(remaining, color))
|
|
||||||
.append(Component.text(" Sekunde" + (remaining == 1 ? "" : "n") + " Bauzeit!", NamedTextColor.GRAY)));
|
|
||||||
}, TaskSchedule.seconds(this.seconds - m), TaskSchedule.stop());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void endBuildPhase() {
|
|
||||||
this.sendMessage(Component.text("Die Bauzeit ist beendet!"));
|
|
||||||
this.getPlayers().forEach(p -> {
|
|
||||||
p.setGameMode(GameMode.ADVENTURE);
|
|
||||||
p.setAllowFlying(true);
|
|
||||||
p.setFlying(true);
|
|
||||||
});
|
|
||||||
this.scheduler().scheduleTask(this::rating, TaskSchedule.seconds(3), TaskSchedule.stop());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean onPlayerJoin(Player player) {
|
|
||||||
Pos plotCenter = new Pos(
|
|
||||||
this.spawnPosx * BuildBattleChunkgenerator.period + plotHalf,
|
|
||||||
height,
|
|
||||||
this.spawnPosz * BuildBattleChunkgenerator.period + plotHalf
|
|
||||||
);
|
|
||||||
this.spawnPositions.put(player, plotCenter);
|
|
||||||
|
|
||||||
if(this.spawnPosx >= rowCount - 1) {
|
|
||||||
this.spawnPosx = 0;
|
|
||||||
this.spawnPosz++;
|
|
||||||
} else this.spawnPosx ++;
|
|
||||||
|
|
||||||
player.setGameMode(GameMode.ADVENTURE);
|
|
||||||
this.scheduler().scheduleNextTick(() -> player.teleport(plotCenter.add(0, 1.5, 0)));
|
|
||||||
return super.onPlayerJoin(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent event) {
|
|
||||||
if (!this.isInArea(event.getBlockPosition(), event.getPlayer())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FluidFlowHelper.onBreak(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent event) {
|
|
||||||
if (!this.isInArea(event.getBlockPosition(), event.getPlayer())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FluidFlowHelper.onPlace(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Pos safeSpawn(Player owner) {
|
|
||||||
Pos center = this.spawnPositions.get(owner);
|
|
||||||
int topY = center.blockY();
|
|
||||||
for (int y = 300; y >= center.blockY(); y--) {
|
|
||||||
if (!this.getBlock(center.blockX(), y, center.blockZ()).isAir()) {
|
|
||||||
topY = y;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Pos(center.x(), topY + 3, center.z()).withView(center.yaw(), center.pitch());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rating() {
|
|
||||||
Queue<Player> owners = new ArrayDeque<>(this.getPlayers());
|
|
||||||
|
|
||||||
this.scheduler().submitTask(() -> {
|
|
||||||
if (this.currentOwner != null) this.finishRound();
|
|
||||||
|
|
||||||
Player next = owners.poll();
|
|
||||||
while (next != null && !(next.isOnline() && this.spawnPositions.containsKey(next))) next = owners.poll();
|
|
||||||
if (next == null) return TaskSchedule.stop();
|
|
||||||
|
|
||||||
this.startRound(next);
|
|
||||||
return TaskSchedule.seconds(ratingSeconds);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startRound(Player owner) {
|
|
||||||
this.currentOwner = owner;
|
|
||||||
this.currentVotes.clear();
|
|
||||||
|
|
||||||
Pos plot = this.safeSpawn(owner);
|
|
||||||
this.sendMessage(Component.text("Bewerte das Grundstück von " + owner.getUsername() + "!"));
|
|
||||||
this.getPlayers().forEach(p -> {
|
|
||||||
p.teleport(plot);
|
|
||||||
p.getInventory().clear();
|
|
||||||
if (p != owner) this.giveRatingItems(p);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void giveRatingItems(Player player) {
|
|
||||||
for (int i = 0; i < ratingItems.size(); i++) {
|
|
||||||
player.getInventory().setItemStack(i, ratingItems.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onRatingItemUse(PlayerUseItemEvent event) {
|
|
||||||
Player voter = event.getPlayer();
|
|
||||||
if (this.currentOwner == null || voter == this.currentOwner) return;
|
|
||||||
|
|
||||||
int slot = voter.getHeldSlot();
|
|
||||||
if (slot >= ratingItems.size()) return;
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
this.currentVotes.put(voter, slot + 1);
|
|
||||||
voter.sendMessage(Component.text("Du hast " + (slot + 1) + " Punkte vergeben."));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void finishRound() {
|
|
||||||
int voteSum = this.currentVotes.values().stream()
|
|
||||||
.mapToInt(Integer::intValue)
|
|
||||||
.sum();
|
|
||||||
int score = (int) Math.round((double) voteSum / this.getPlayers().size());
|
|
||||||
|
|
||||||
this.getPlayers().forEach(p -> p.getInventory().clear());
|
|
||||||
this.getScore().insertResult(this.currentOwner, score);
|
|
||||||
this.currentOwner = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInArea(Point block, Player player) {
|
|
||||||
Pos center = this.spawnPositions.get(player);
|
|
||||||
if (center == null) return false;
|
|
||||||
Pos min = new Pos(center.x() - plotHalf, center.y() + 1, center.z() - plotHalf);
|
|
||||||
Pos max = new Pos(center.x() + plotHalf - 1, 300, center.z() + plotHalf - 1);
|
|
||||||
return eu.mhsl.minenet.minigames.util.Position.isInArea(block, min, max);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
-85
@@ -1,85 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
|
|
||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockInteractEvent;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import net.minestom.server.instance.block.BlockHandler;
|
|
||||||
import net.minestom.server.instance.block.rule.BlockPlacementRule;
|
|
||||||
import org.everbuild.blocksandstuff.blocks.group.VanillaBlockBehaviour;
|
|
||||||
import org.everbuild.blocksandstuff.blocks.group.VanillaPlacementRules;
|
|
||||||
import org.everbuild.blocksandstuff.blocks.group.behaviour.BehaviourGroup;
|
|
||||||
import org.everbuild.blocksandstuff.blocks.group.placement.PlacementGroup;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public final class BuildBattleBlockRules {
|
|
||||||
private BuildBattleBlockRules() {}
|
|
||||||
|
|
||||||
private static final ThreadLocal<Boolean> interactingInBuildBattle = ThreadLocal.withInitial(() -> false);
|
|
||||||
private static final Map<Integer, BlockHandler> behaviours = new HashMap<>();
|
|
||||||
private static boolean registered = false;
|
|
||||||
|
|
||||||
public static synchronized void register() {
|
|
||||||
if (registered) return;
|
|
||||||
registered = true;
|
|
||||||
|
|
||||||
var blockManager = MinecraftServer.getBlockManager();
|
|
||||||
for (PlacementGroup group : VanillaPlacementRules.INSTANCE.getALL()) {
|
|
||||||
for (Block block : group.getBlockGroup().allMatching()) {
|
|
||||||
blockManager.registerBlockPlacementRule(new BuildBattleOnlyRule(group.createRule(block)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (BehaviourGroup group : VanillaBlockBehaviour.INSTANCE.getALL()) {
|
|
||||||
for (Block block : group.getBlockGroup().allMatching()) {
|
|
||||||
behaviours.put(block.id(), group.createHandler(block));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MinecraftServer.getGlobalEventHandler().addListener(PlayerBlockInteractEvent.class,
|
|
||||||
e -> interactingInBuildBattle.set(e.getInstance() instanceof BuildBattle));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onInteract(PlayerBlockInteractEvent event) {
|
|
||||||
BlockHandler handler = behaviours.get(event.getBlock().id());
|
|
||||||
if (handler == null) return;
|
|
||||||
boolean continueItemUse = handler.onInteract(new BlockHandler.Interaction(
|
|
||||||
event.getBlock(), event.getInstance(), event.getBlockFace(), event.getBlockPosition(),
|
|
||||||
event.getCursorPosition(), event.getPlayer(), event.getHand()
|
|
||||||
));
|
|
||||||
if (!continueItemUse) event.setBlockingItemUse(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class BuildBattleOnlyRule extends BlockPlacementRule {
|
|
||||||
private final BlockPlacementRule delegate;
|
|
||||||
|
|
||||||
private BuildBattleOnlyRule(BlockPlacementRule delegate) {
|
|
||||||
super(delegate.getBlock());
|
|
||||||
this.delegate = delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Block blockPlace(PlacementState placementState) {
|
|
||||||
if (!(placementState.instance() instanceof BuildBattle)) return placementState.block();
|
|
||||||
return this.delegate.blockPlace(placementState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Block blockUpdate(UpdateState updateState) {
|
|
||||||
if (!(updateState.instance() instanceof BuildBattle)) return updateState.currentBlock();
|
|
||||||
return this.delegate.blockUpdate(updateState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSelfReplaceable(Replacement replacement) {
|
|
||||||
return interactingInBuildBattle.get() && this.delegate.isSelfReplaceable(replacement);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int maxUpdateDistance() {
|
|
||||||
return this.delegate.maxUpdateDistance();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-41
@@ -1,41 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.util.GeneratorUtils;
|
|
||||||
import eu.mhsl.minenet.minigames.world.generator.terrain.BaseGenerator;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
|
|
||||||
public class BuildBattleChunkgenerator extends BaseGenerator {
|
|
||||||
static final int inner = 32;
|
|
||||||
private static final int ring = 3;
|
|
||||||
private static final int wall = 1;
|
|
||||||
private static final int wallHeight = 200;
|
|
||||||
|
|
||||||
static final int period = wall + ring + inner + ring;
|
|
||||||
|
|
||||||
private static final int innerStart = wall + ring;
|
|
||||||
private static final int innerEnd = innerStart + inner;
|
|
||||||
|
|
||||||
private static final Block middleBlocks = Block.QUARTZ_BLOCK;
|
|
||||||
private static final Block outerBlocks = Block.STONE_BRICKS;
|
|
||||||
private static final Block wallBlocks = Block.POLISHED_DEEPSLATE;
|
|
||||||
|
|
||||||
public BuildBattleChunkgenerator(int height) {
|
|
||||||
this.addMixIn(unit -> GeneratorUtils.foreachXZ(unit, point -> {
|
|
||||||
int lx = Math.floorMod(point.blockX() + innerStart, period);
|
|
||||||
int lz = Math.floorMod(point.blockZ() + innerStart, period);
|
|
||||||
|
|
||||||
if (lx < wall || lz < wall) {
|
|
||||||
unit.modifier().fill(point.withY(height), point.add(1, 0, 1).withY(height + wallHeight + 1), wallBlocks);
|
|
||||||
} else {
|
|
||||||
unit.modifier().setBlock(point.withY(height), floorBlock(lx, lz));
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Block floorBlock(int lx, int lz) {
|
|
||||||
boolean inInner = lx >= innerStart && lx < innerEnd
|
|
||||||
&& lz >= innerStart && lz < innerEnd;
|
|
||||||
|
|
||||||
return inInner ? middleBlocks : outerBlocks;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-20
@@ -1,13 +1,10 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
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.GameFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
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.instance.room.Room;
|
||||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||||
import net.minestom.server.item.Material;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -17,24 +14,8 @@ public class BuildBattleFactory implements GameFactory {
|
|||||||
return TranslatedComponent.byId("game_BuildBattle#name");
|
return TranslatedComponent.byId("game_BuildBattle#name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConfigManager configuration() {
|
|
||||||
return new ConfigManager()
|
|
||||||
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("game_BuildBattle#seconds"), 60, 120, 300, 600));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||||
return new BuildBattle(configuration.get("seconds").getAsInt()).setParent(parent);
|
return new BuildBattle();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Material symbol() {
|
|
||||||
return Material.SANDSTONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent description() {
|
|
||||||
return TranslatedComponent.byId("game_BuildBattle#description");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
|
||||||
|
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
|
import eu.mhsl.minenet.minigames.score.Score;
|
||||||
|
import net.minestom.server.registry.DynamicRegistry;
|
||||||
|
import net.minestom.server.world.DimensionType;
|
||||||
|
|
||||||
|
class BuilderWorld extends StatelessGame {
|
||||||
|
public BuilderWorld(DynamicRegistry.Key<DimensionType> dimensionType, String gameName, Score score) {
|
||||||
|
super(dimensionType, gameName, score);
|
||||||
|
}
|
||||||
|
}
|
||||||
-267
@@ -1,267 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.buildBattle;
|
|
||||||
|
|
||||||
import net.minestom.server.coordinate.BlockVec;
|
|
||||||
import net.minestom.server.coordinate.Point;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerUseItemOnBlockEvent;
|
|
||||||
import net.minestom.server.instance.Instance;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import net.minestom.server.item.Material;
|
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
|
||||||
import net.minestom.server.utils.Direction;
|
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public final class FluidFlowHelper {
|
|
||||||
private FluidFlowHelper() {}
|
|
||||||
|
|
||||||
private static final int WATER_TICK = 5;
|
|
||||||
private static final int LAVA_TICK = 30;
|
|
||||||
private static final int WATER_RANGE = 7;
|
|
||||||
private static final int LAVA_RANGE = 3;
|
|
||||||
private static final int FALLING = 8;
|
|
||||||
|
|
||||||
public static void onBucketUse(PlayerUseItemOnBlockEvent event, Predicate<Point> inArea) {
|
|
||||||
Material m = event.getItemStack().material();
|
|
||||||
Instance inst = event.getPlayer().getInstance();
|
|
||||||
if (inst == null) return;
|
|
||||||
Point hit = event.getPosition();
|
|
||||||
var face = event.getBlockFace();
|
|
||||||
BlockVec placePos = new BlockVec(
|
|
||||||
hit.blockX() + face.toDirection().normalX(),
|
|
||||||
hit.blockY() + face.toDirection().normalY(),
|
|
||||||
hit.blockZ() + face.toDirection().normalZ()
|
|
||||||
);
|
|
||||||
if (!inArea.test(placePos)) return;
|
|
||||||
|
|
||||||
if (m == Material.WATER_BUCKET) {
|
|
||||||
inst.setBlock(placePos, Block.WATER.withProperty("level", "0"));
|
|
||||||
scheduleFlow(inst, placePos, true);
|
|
||||||
} else if (m == Material.LAVA_BUCKET) {
|
|
||||||
inst.setBlock(placePos, Block.LAVA.withProperty("level", "0"));
|
|
||||||
scheduleFlow(inst, placePos, false);
|
|
||||||
} else if (m == Material.BUCKET) {
|
|
||||||
Block existing = inst.getBlock(placePos);
|
|
||||||
if (isWater(existing) || isLava(existing)) inst.setBlock(placePos, Block.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onPlace(PlayerBlockPlaceEvent event) {
|
|
||||||
Block b = event.getBlock();
|
|
||||||
if (isWater(b) || isLava(b)) {
|
|
||||||
Instance inst = event.getInstance();
|
|
||||||
BlockVec pos = event.getBlockPosition();
|
|
||||||
scheduleFlow(inst, pos, isWater(b));
|
|
||||||
}
|
|
||||||
triggerNeighbors(event.getInstance(), event.getBlockPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onBreak(PlayerBlockBreakEvent event) {
|
|
||||||
triggerNeighbors(event.getInstance(), event.getBlockPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void triggerNeighbors(Instance inst, BlockVec pos) {
|
|
||||||
for (Direction d : Direction.values()) {
|
|
||||||
BlockVec np = new BlockVec(pos.blockX() + d.normalX(), pos.blockY() + d.normalY(), pos.blockZ() + d.normalZ());
|
|
||||||
Block nb = inst.getBlock(np);
|
|
||||||
if (isWater(nb) || isLava(nb)) scheduleFlow(inst, np, isWater(nb));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void scheduleFlow(Instance inst, BlockVec pos, boolean water) {
|
|
||||||
int delay = water ? WATER_TICK : LAVA_TICK;
|
|
||||||
inst.scheduler().buildTask(() -> step(inst, pos, water)).delay(TaskSchedule.tick(delay)).schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void step(Instance inst, BlockVec pos, boolean water) {
|
|
||||||
Block self = inst.getBlock(pos);
|
|
||||||
if (water ? !isWater(self) : !isLava(self)) return;
|
|
||||||
|
|
||||||
int level = parseLevel(self);
|
|
||||||
boolean source = level == 0;
|
|
||||||
boolean falling = level >= FALLING;
|
|
||||||
int flowLevel = source ? 1 : (falling ? 1 : level + 1);
|
|
||||||
int maxRange = water ? WATER_RANGE : LAVA_RANGE;
|
|
||||||
|
|
||||||
if (!source && !falling) {
|
|
||||||
int newLevel = computeIncomingLevel(inst, pos, water, maxRange);
|
|
||||||
if (newLevel == -1) {
|
|
||||||
inst.setBlock(pos, Block.AIR);
|
|
||||||
triggerNeighbors(inst, pos);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (newLevel != level) {
|
|
||||||
inst.setBlock(pos, (water ? Block.WATER : Block.LAVA).withProperty("level", String.valueOf(newLevel)));
|
|
||||||
level = newLevel;
|
|
||||||
flowLevel = level + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (water && !source && countAdjacentSources(inst, pos, true) >= 2
|
|
||||||
&& hasSolidBelow(inst, pos)) {
|
|
||||||
inst.setBlock(pos, Block.WATER.withProperty("level", "0"));
|
|
||||||
scheduleFlow(inst, pos, true);
|
|
||||||
triggerNeighbors(inst, pos);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockVec below = new BlockVec(pos.blockX(), pos.blockY() - 1, pos.blockZ());
|
|
||||||
Block belowBlock = inst.getBlock(below);
|
|
||||||
if (isReplaceable(belowBlock) || (water ? isWater(belowBlock) : isLava(belowBlock))) {
|
|
||||||
if (handleFluidCollision(inst, below, water)) {
|
|
||||||
triggerNeighbors(inst, below);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Block target = (water ? Block.WATER : Block.LAVA).withProperty("level", String.valueOf(FALLING));
|
|
||||||
if (!belowBlock.compare(target) || !target.getProperty("level").equals(belowBlock.getProperty("level"))) {
|
|
||||||
if (!(isWater(belowBlock) && parseLevel(belowBlock) == 0)
|
|
||||||
&& !(isLava(belowBlock) && parseLevel(belowBlock) == 0)) {
|
|
||||||
inst.setBlock(below, target);
|
|
||||||
scheduleFlow(inst, below, water);
|
|
||||||
triggerNeighbors(inst, below);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hasSolidBelow(inst, pos) && !source) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flowLevel > maxRange) return;
|
|
||||||
|
|
||||||
Set<Direction> targets = findFlowTargets(inst, pos, water, maxRange - (source ? 0 : level));
|
|
||||||
for (Direction d : Direction.HORIZONTAL) {
|
|
||||||
if (!targets.contains(d)) continue;
|
|
||||||
BlockVec np = new BlockVec(pos.blockX() + d.normalX(), pos.blockY(), pos.blockZ() + d.normalZ());
|
|
||||||
Block nb = inst.getBlock(np);
|
|
||||||
if (handleFluidCollision(inst, np, water)) continue;
|
|
||||||
if (!isReplaceable(nb) && !(water ? isWater(nb) : isLava(nb))) continue;
|
|
||||||
int existingLevel = (water ? isWater(nb) : isLava(nb)) ? parseLevel(nb) : Integer.MAX_VALUE;
|
|
||||||
if (existingLevel == 0) continue;
|
|
||||||
if (flowLevel < existingLevel) {
|
|
||||||
inst.setBlock(np, (water ? Block.WATER : Block.LAVA).withProperty("level", String.valueOf(flowLevel)));
|
|
||||||
scheduleFlow(inst, np, water);
|
|
||||||
triggerNeighbors(inst, np);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int computeIncomingLevel(Instance inst, BlockVec pos, boolean water, int maxRange) {
|
|
||||||
int min = Integer.MAX_VALUE;
|
|
||||||
BlockVec above = new BlockVec(pos.blockX(), pos.blockY() + 1, pos.blockZ());
|
|
||||||
Block ab = inst.getBlock(above);
|
|
||||||
if ((water ? isWater(ab) : isLava(ab))) return FALLING;
|
|
||||||
for (Direction d : Direction.HORIZONTAL) {
|
|
||||||
BlockVec np = new BlockVec(pos.blockX() + d.normalX(), pos.blockY(), pos.blockZ() + d.normalZ());
|
|
||||||
Block nb = inst.getBlock(np);
|
|
||||||
if (water ? isWater(nb) : isLava(nb)) {
|
|
||||||
int nl = parseLevel(nb);
|
|
||||||
if (nl >= FALLING) nl = 0;
|
|
||||||
if (nl < min) min = nl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (min == Integer.MAX_VALUE) return -1;
|
|
||||||
int result = min + 1;
|
|
||||||
if (result > maxRange) return -1;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Set<Direction> findFlowTargets(Instance inst, BlockVec pos, boolean water, int remaining) {
|
|
||||||
Set<Direction> result = new HashSet<>();
|
|
||||||
if (remaining <= 0) return result;
|
|
||||||
int bestDist = Integer.MAX_VALUE;
|
|
||||||
int[] dist = new int[4];
|
|
||||||
Direction[] dirs = {Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
BlockVec np = new BlockVec(pos.blockX() + dirs[i].normalX(), pos.blockY(), pos.blockZ() + dirs[i].normalZ());
|
|
||||||
Block nb = inst.getBlock(np);
|
|
||||||
if (!isReplaceable(nb) && !(water ? isWater(nb) : isLava(nb))) { dist[i] = Integer.MAX_VALUE; continue; }
|
|
||||||
dist[i] = bfsDownhill(inst, np, water, remaining);
|
|
||||||
if (dist[i] < bestDist) bestDist = dist[i];
|
|
||||||
}
|
|
||||||
if (bestDist == Integer.MAX_VALUE) {
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
if (dist[i] < Integer.MAX_VALUE) result.add(dirs[i]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
if (dist[i] == bestDist) result.add(dirs[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int bfsDownhill(Instance inst, BlockVec start, boolean water, int remaining) {
|
|
||||||
ArrayDeque<int[]> queue = new ArrayDeque<>();
|
|
||||||
Set<Long> visited = new HashSet<>();
|
|
||||||
queue.add(new int[]{start.blockX(), start.blockY(), start.blockZ(), 0});
|
|
||||||
visited.add(key(start.blockX(), start.blockY(), start.blockZ()));
|
|
||||||
while (!queue.isEmpty()) {
|
|
||||||
int[] c = queue.poll();
|
|
||||||
BlockVec cp = new BlockVec(c[0], c[1], c[2]);
|
|
||||||
Block below = inst.getBlock(new BlockVec(c[0], c[1] - 1, c[2]));
|
|
||||||
if (isReplaceable(below) && !(water ? isWater(below) : isLava(below))) return c[3];
|
|
||||||
if (c[3] >= remaining) continue;
|
|
||||||
for (Direction d : Direction.HORIZONTAL) {
|
|
||||||
int nx = c[0] + d.normalX(), nz = c[2] + d.normalZ();
|
|
||||||
long k = key(nx, c[1], nz);
|
|
||||||
if (visited.contains(k)) continue;
|
|
||||||
Block nb = inst.getBlock(new BlockVec(nx, c[1], nz));
|
|
||||||
if (!isReplaceable(nb) && !(water ? isWater(nb) : isLava(nb))) continue;
|
|
||||||
visited.add(k);
|
|
||||||
queue.add(new int[]{nx, c[1], nz, c[3] + 1});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long key(int x, int y, int z) {
|
|
||||||
return ((long) x & 0x3FFFFFFL) | (((long) z & 0x3FFFFFFL) << 26) | (((long) y & 0xFFFL) << 52);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int countAdjacentSources(Instance inst, BlockVec pos, boolean water) {
|
|
||||||
int c = 0;
|
|
||||||
for (Direction d : Direction.HORIZONTAL) {
|
|
||||||
Block nb = inst.getBlock(new BlockVec(pos.blockX() + d.normalX(), pos.blockY(), pos.blockZ() + d.normalZ()));
|
|
||||||
if ((water ? isWater(nb) : isLava(nb)) && parseLevel(nb) == 0) c++;
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean hasSolidBelow(Instance inst, BlockVec pos) {
|
|
||||||
Block below = inst.getBlock(new BlockVec(pos.blockX(), pos.blockY() - 1, pos.blockZ()));
|
|
||||||
return below.isSolid();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean handleFluidCollision(Instance inst, BlockVec pos, boolean incomingIsWater) {
|
|
||||||
Block target = inst.getBlock(pos);
|
|
||||||
if (incomingIsWater && isLava(target)) {
|
|
||||||
boolean lavaSource = parseLevel(target) == 0;
|
|
||||||
inst.setBlock(pos, lavaSource ? Block.OBSIDIAN : Block.COBBLESTONE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!incomingIsWater && isWater(target)) {
|
|
||||||
inst.setBlock(pos, Block.STONE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isReplaceable(Block b) {
|
|
||||||
if (b.isAir()) return true;
|
|
||||||
String p = b.key().value();
|
|
||||||
return p.equals("short_grass") || p.equals("tall_grass") || p.equals("fern") || p.equals("large_fern")
|
|
||||||
|| p.equals("dead_bush") || p.equals("seagrass") || p.equals("tall_seagrass") || p.equals("vine")
|
|
||||||
|| p.equals("snow") || p.equals("fire") || p.equals("soul_fire");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isWater(Block b) { return b.compare(Block.WATER); }
|
|
||||||
private static boolean isLava(Block b) { return b.compare(Block.LAVA); }
|
|
||||||
|
|
||||||
private static int parseLevel(Block b) {
|
|
||||||
String s = b.getProperty("level");
|
|
||||||
if (s == null) return 0;
|
|
||||||
try { return Integer.parseInt(s); } catch (NumberFormatException e) { return 0; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-180
@@ -1,180 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.colorJump;
|
|
||||||
|
|
||||||
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.inventory.InventoryPreClickEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerSwapItemEvent;
|
|
||||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import net.minestom.server.item.ItemStack;
|
|
||||||
import net.minestom.server.timer.Scheduler;
|
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
public class ColorJump extends StatelessGame {
|
|
||||||
private final List<Block> blocks = List.of(
|
|
||||||
Block.RED_CONCRETE,
|
|
||||||
Block.ORANGE_CONCRETE,
|
|
||||||
Block.YELLOW_CONCRETE,
|
|
||||||
Block.LIME_CONCRETE,
|
|
||||||
Block.LIGHT_BLUE_CONCRETE,
|
|
||||||
Block.BLUE_CONCRETE,
|
|
||||||
Block.PURPLE_CONCRETE,
|
|
||||||
Block.PINK_CONCRETE
|
|
||||||
);
|
|
||||||
private Block currentBlock;
|
|
||||||
private Block blockLastRound;
|
|
||||||
private double roundTime = 5;
|
|
||||||
private final double multiplierNextRoundTime = 0.9;
|
|
||||||
|
|
||||||
public ColorJump() {
|
|
||||||
super(Dimension.THE_END.key, "ColorJump", new LastWinsScore());
|
|
||||||
this.getScore().setIgnoreLastPlayers(1);
|
|
||||||
|
|
||||||
this.setGenerator(new CircularPlateTerrainGenerator(100));
|
|
||||||
|
|
||||||
this.eventNode().addListener(
|
|
||||||
InventoryPreClickEvent.class,
|
|
||||||
inventoryPreClickEvent -> inventoryPreClickEvent.setCancelled(true)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.eventNode().addListener(
|
|
||||||
PlayerSwapItemEvent.class,
|
|
||||||
playerSwapItemEvent -> playerSwapItemEvent.setCancelled(true)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
|
||||||
this.generate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
this.nextRound();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void nextRound() {
|
|
||||||
this.generate();
|
|
||||||
do {
|
|
||||||
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
|
||||||
} while(this.currentBlock == this.blockLastRound);
|
|
||||||
this.blockLastRound = this.currentBlock;
|
|
||||||
|
|
||||||
ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material()));
|
|
||||||
this.getPlayers().forEach(player -> {
|
|
||||||
player.getInventory().clear();
|
|
||||||
for(int i = 0; i < 9; i++) {
|
|
||||||
player.getInventory().setItemStack(i, item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var scheduler = MinecraftServer.getSchedulerManager();
|
|
||||||
TaskSchedule stop = TaskSchedule.stop();
|
|
||||||
|
|
||||||
scheduler.scheduleTask(() -> {
|
|
||||||
if(!this.isRunning) return stop;
|
|
||||||
this.destroyAllExcept(this.currentBlock);
|
|
||||||
|
|
||||||
scheduler.scheduleTask(() -> {
|
|
||||||
if(this.isRunning) this.nextRound();
|
|
||||||
return stop;
|
|
||||||
}, TaskSchedule.seconds(3));
|
|
||||||
return stop;
|
|
||||||
}, TaskSchedule.seconds((long) this.roundTime));
|
|
||||||
this.roundTime = this.roundTime * this.multiplierNextRoundTime;
|
|
||||||
if(this.roundTime <= 1) this.roundTime = 1;
|
|
||||||
|
|
||||||
long totalTicks = (long) (this.roundTime * 20);
|
|
||||||
this.scheduleExpUpdate(scheduler, totalTicks, totalTicks);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scheduleExpUpdate(Scheduler scheduler, long remainingTicks, long totalTicks) {
|
|
||||||
if (!this.isRunning) return;
|
|
||||||
|
|
||||||
if (remainingTicks <= 0) {
|
|
||||||
this.getPlayers().forEach(player -> {
|
|
||||||
player.setExp(0f);
|
|
||||||
player.setLevel(0);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
float progress = (float) remainingTicks / totalTicks;
|
|
||||||
|
|
||||||
this.getPlayers().forEach(player -> {
|
|
||||||
player.setExp(progress);
|
|
||||||
player.setLevel((int) Math.ceil(remainingTicks / 20.0));
|
|
||||||
});
|
|
||||||
scheduler.scheduleTask(() -> {
|
|
||||||
this.scheduleExpUpdate(scheduler, remainingTicks -1, totalTicks);
|
|
||||||
return TaskSchedule.stop();
|
|
||||||
}, TaskSchedule.tick(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generate() {
|
|
||||||
int y = 30;
|
|
||||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
|
||||||
|
|
||||||
for (int x = -20; x <= 21; x += 2) {
|
|
||||||
for (int z = -11; z <= 10; z += 2) {
|
|
||||||
Block randomBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
|
||||||
|
|
||||||
for (int dx = 0; dx < 2; dx++) {
|
|
||||||
for (int dz = 0; dz < 2; dz++) {
|
|
||||||
batch.setBlock(x + dx, y, z + dz, randomBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void destroyAllExcept(Block block) {
|
|
||||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
|
||||||
int y = 30;
|
|
||||||
|
|
||||||
for (int x = -20; x <= 21; x++) {
|
|
||||||
for(int z = -11; z <= 10; z++) {
|
|
||||||
Pos blockPos = new Pos(x, y, z);
|
|
||||||
if(this.getBlock(blockPos) != block)
|
|
||||||
batch.setBlock(blockPos, Block.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Pos getSpawn() {
|
|
||||||
return new Pos(0, 31, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
|
||||||
var player = playerMoveEvent.getPlayer();
|
|
||||||
|
|
||||||
if(playerMoveEvent.getNewPosition().y() >= 29)
|
|
||||||
return;
|
|
||||||
player.teleport(this.getSpawn());
|
|
||||||
if(this.isRunning) {
|
|
||||||
this.getScore().insertResult(player);
|
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
|
||||||
}
|
|
||||||
if(!this.isBeforeBeginning && !this.isRunning) {
|
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
|
||||||
player.teleport(this.getSpawn());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.colorJump;
|
|
||||||
|
|
||||||
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 ColorJumpFactory implements GameFactory {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent name() {
|
|
||||||
return TranslatedComponent.byId("game_ColorJump#name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Material symbol() {
|
|
||||||
return Material.PINK_CONCRETE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent description() {
|
|
||||||
return TranslatedComponent.byId("game_ColorJump#description");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
|
||||||
return new ColorJump().setParent(parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+11
-14
@@ -1,14 +1,13 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube;
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
||||||
import eu.mhsl.minenet.minigames.util.BatchUtil;
|
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.BlockPallet;
|
||||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||||
import io.github.togar2.pvp.feature.CombatFeatures;
|
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||||
import net.minestom.server.coordinate.Pos;
|
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.PlayerMoveEvent;
|
||||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -28,7 +27,7 @@ class Deathcube extends StatelessGame {
|
|||||||
this.percentage = percentage;
|
this.percentage = percentage;
|
||||||
this.setGenerator(new CircularPlateTerrainGenerator(radius+10).setPlateHeight(50));
|
this.setGenerator(new CircularPlateTerrainGenerator(radius+10).setPlateHeight(50));
|
||||||
|
|
||||||
if(pvpEnabled == 1) this.eventNode().addChild(
|
if(pvpEnabled == 1) eventNode().addChild(
|
||||||
CombatFeatures.empty()
|
CombatFeatures.empty()
|
||||||
.add(CombatFeatures.VANILLA_ATTACK)
|
.add(CombatFeatures.VANILLA_ATTACK)
|
||||||
.add(CombatFeatures.VANILLA_DAMAGE)
|
.add(CombatFeatures.VANILLA_DAMAGE)
|
||||||
@@ -42,12 +41,12 @@ class Deathcube extends StatelessGame {
|
|||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
|
|
||||||
for(int x = -this.radius; x <= this.radius; x++) {
|
for(int x = -radius; x <= radius; x++) {
|
||||||
for(int z = -this.radius; z <= this.radius; z++) {
|
for (int z = -radius; z <= radius; z++) {
|
||||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > this.radius) continue;
|
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||||
|
|
||||||
for(int y = 49; y < this.height; y++) {
|
for (int y = 49; y < height; y++) {
|
||||||
if(super.rnd.nextInt(1, 100) <= this.percentage) {
|
if(super.rnd.nextInt(1, 100) <= percentage) {
|
||||||
batch.setBlock(x, y, z, BlockPallet.WOOD.rnd());
|
batch.setBlock(x, y, z, BlockPallet.WOOD.rnd());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,20 +61,18 @@ class Deathcube extends StatelessGame {
|
|||||||
super.onPlayerMove(playerMoveEvent);
|
super.onPlayerMove(playerMoveEvent);
|
||||||
if(playerMoveEvent.getNewPosition().y() < 48) {
|
if(playerMoveEvent.getNewPosition().y() < 48) {
|
||||||
playerMoveEvent.setCancelled(true);
|
playerMoveEvent.setCancelled(true);
|
||||||
playerMoveEvent.getPlayer().teleport(this.getSpawn());
|
playerMoveEvent.getPlayer().teleport(getSpawn());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(this.isBeforeBeginning && playerMoveEvent.getNewPosition().y() > 51.5) {
|
if(isBeforeBeginning && playerMoveEvent.getNewPosition().y() > 51.5) {
|
||||||
playerMoveEvent.setCancelled(true);
|
playerMoveEvent.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(playerMoveEvent.getNewPosition().y() <= this.height) return;
|
if(playerMoveEvent.getNewPosition().y() > height) getScore().insertResult(playerMoveEvent.getPlayer());
|
||||||
this.getScore().insertResult(playerMoveEvent.getPlayer());
|
|
||||||
playerMoveEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
return new Pos(0, 50, -(this.radius + 5));
|
return new Pos(0, 50, -(radius+5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,9 +1,9 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube;
|
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.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.GameFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
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.game.stateless.config.common.NumericOption;
|
||||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||||
|
|||||||
+69
-88
@@ -20,11 +20,7 @@ import net.minestom.server.coordinate.Vec;
|
|||||||
import net.minestom.server.entity.EquipmentSlot;
|
import net.minestom.server.entity.EquipmentSlot;
|
||||||
import net.minestom.server.entity.GameMode;
|
import net.minestom.server.entity.GameMode;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
import net.minestom.server.event.player.*;
|
||||||
import net.minestom.server.event.player.PlayerStartFlyingWithElytraEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerStopFlyingWithElytraEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerUseItemEvent;
|
|
||||||
import net.minestom.server.instance.Chunk;
|
|
||||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
@@ -37,7 +33,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
@@ -53,74 +48,80 @@ public class ElytraRace extends StatelessGame {
|
|||||||
private final Material resetMaterial = Material.RED_DYE;
|
private final Material resetMaterial = Material.RED_DYE;
|
||||||
private final int boostMultiplier = 50;
|
private final int boostMultiplier = 50;
|
||||||
private final Material ringMaterial = Material.GOLD_BLOCK;
|
private final Material ringMaterial = Material.GOLD_BLOCK;
|
||||||
private final Map<Player, CheckPointData> playerCheckpoints = new HashMap<>();
|
|
||||||
private int generatedUntil = 0;
|
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) {
|
public ElytraRace(int ringCount) {
|
||||||
super(Dimension.OVERWORLD.key, "ElytraRace", new FirstWinsScore());
|
super(Dimension.OVERWORLD.key, "ElytraRace", new FirstWinsScore());
|
||||||
|
|
||||||
this.ringCount = ringCount;
|
this.ringCount = ringCount;
|
||||||
|
|
||||||
this.setGenerator(this.vale);
|
setGenerator(vale);
|
||||||
this.vale.setCalculateSeaLevel(point -> this.seaLevel);
|
vale.setCalculateSeaLevel(point -> seaLevel);
|
||||||
this.vale.setXShiftMultiplier(integer -> NumberUtil.map(integer, 50, 500, 0, 1));
|
vale.setXShiftMultiplier(integer -> NumberUtil.map(integer, 50, 500, 0, 1));
|
||||||
this.vale.addMixIn(new PlaneTerrainGenerator(this.gameHeight, Block.BARRIER));
|
vale.addMixIn(new PlaneTerrainGenerator(gameHeight, Block.BARRIER));
|
||||||
|
|
||||||
this.eventNode().addListener(PlayerUseItemEvent.class, playerUseItemEvent -> {
|
eventNode().addListener(PlayerUseItemEvent.class, playerUseItemEvent -> {
|
||||||
Player player = playerUseItemEvent.getPlayer();
|
Player player = playerUseItemEvent.getPlayer();
|
||||||
Material usedMaterial = playerUseItemEvent.getItemStack().material();
|
Material usedMaterial = playerUseItemEvent.getItemStack().material();
|
||||||
|
|
||||||
if(usedMaterial.equals(this.boostMaterial)) {
|
if(usedMaterial.equals(boostMaterial)) {
|
||||||
if(!player.isFlyingWithElytra()) return;
|
if(!player.isFlyingWithElytra()) return;
|
||||||
|
|
||||||
this.boost(player);
|
boost(player);
|
||||||
InventoryUtil.removeItemFromPlayer(player, this.boostMaterial, 1);
|
InventoryUtil.removeItemFromPlayer(player, boostMaterial, 1);
|
||||||
} else if(usedMaterial.equals(this.resetMaterial)) {
|
} else if(usedMaterial.equals(resetMaterial)) {
|
||||||
this.toCheckpoint(player);
|
toCheckpoint(player);
|
||||||
InventoryUtil.removeItemFromPlayer(player, this.resetMaterial, 1);
|
InventoryUtil.removeItemFromPlayer(player, resetMaterial, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.eventNode().addListener(PlayerStopFlyingWithElytraEvent.class, playerStopFlyingWithElytraEvent -> {
|
eventNode().addListener(PlayerStopFlyingWithElytraEvent.class, playerStopFlyingWithElytraEvent -> {
|
||||||
Player player = playerStopFlyingWithElytraEvent.getPlayer();
|
Player player = playerStopFlyingWithElytraEvent.getPlayer();
|
||||||
if(Position.blocksBelowPlayer(this, player).contains(this.ringMaterial.block())) {
|
if(Position.blocksBelowPlayer(this, player).contains(ringMaterial.block())) {
|
||||||
player.setFlyingWithElytra(true);
|
player.setFlyingWithElytra(true);
|
||||||
this.boost(player);
|
boost(player);
|
||||||
} else {
|
} else {
|
||||||
this.toCheckpoint(player);
|
toCheckpoint(player);
|
||||||
// getScore().insertResult(playerStopFlyingWithElytraEvent.getPlayer());
|
// getScore().insertResult(playerStopFlyingWithElytraEvent.getPlayer());
|
||||||
// playerStopFlyingWithElytraEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
// playerStopFlyingWithElytraEvent.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.eventNode().addListener(PlayerStartFlyingWithElytraEvent.class, playerStartFlyingWithElytraEvent -> {
|
eventNode().addListener(PlayerStartFlyingWithElytraEvent.class, playerStartFlyingWithElytraEvent -> {
|
||||||
if(!this.isRunning) {
|
if(!isRunning) {
|
||||||
playerStartFlyingWithElytraEvent.getPlayer().setFlyingWithElytra(false);
|
playerStartFlyingWithElytraEvent.getPlayer().setFlyingWithElytra(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.boost(playerStartFlyingWithElytraEvent.getPlayer());
|
boost(playerStartFlyingWithElytraEvent.getPlayer());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
Point spawnpoint = new Pos(this.vale.getXShiftAtZ(0), -46, 0);
|
Point spawnpoint = new Pos(vale.getXShiftAtZ(0), -46, 0);
|
||||||
GeneratorUtils.iterateArea(spawnpoint.sub(5, 0, 5), spawnpoint.add(5, 0, 5), point -> this.setBlock(point, BlockPallet.STREET.rnd()));
|
GeneratorUtils.iterateArea(spawnpoint.sub(5, 0, 5), spawnpoint.add(5, 0, 5), point -> setBlock(point, BlockPallet.STREET.rnd()));
|
||||||
|
|
||||||
this.generateRing(this.ringSpacing);
|
generateRing(ringSpacing);
|
||||||
this.generateRing(this.ringSpacing * 2);
|
generateRing(ringSpacing * 2);
|
||||||
callback.complete(null);
|
callback.complete(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
this.getPlayers().forEach(player -> {
|
getPlayers().forEach(player -> {
|
||||||
player.getInventory().setEquipment(EquipmentSlot.CHESTPLATE, (byte) 0, ItemStack.of(Material.ELYTRA));
|
player.getInventory().setEquipment(EquipmentSlot.CHESTPLATE, (byte) 0, ItemStack.of(Material.ELYTRA));
|
||||||
for(int i = 0; i < 3; i++) {
|
for(int i = 0; i < 3; i++) {
|
||||||
player.getInventory().setItemStack(i, ItemStack.builder(this.boostMaterial).customName(TranslatedComponent.byId("boost").getAssembled(player)).build());
|
player.getInventory().setItemStack(i, ItemStack.builder(boostMaterial).customName(TranslatedComponent.byId("boost").getAssembled(player)).build());
|
||||||
}
|
}
|
||||||
this.addResetItemToPlayer(player);
|
addResetItemToPlayer(player);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,24 +130,24 @@ public class ElytraRace extends StatelessGame {
|
|||||||
Player player = playerMoveEvent.getPlayer();
|
Player player = playerMoveEvent.getPlayer();
|
||||||
Point newPos = playerMoveEvent.getNewPosition();
|
Point newPos = playerMoveEvent.getNewPosition();
|
||||||
|
|
||||||
if(this.isBeforeBeginning && playerMoveEvent.getNewPosition().y() < this.getSpawn().y()) {
|
if(isBeforeBeginning && playerMoveEvent.getNewPosition().y() < getSpawn().y()) {
|
||||||
player.teleport(this.getSpawn());
|
player.teleport(getSpawn());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.playerCheckpoints.putIfAbsent(player, new CheckPointData(0, this.ringSpacing));
|
playerCheckpoints.putIfAbsent(player, new CheckPointData(ringSpacing, ringSpacing * 2));
|
||||||
|
|
||||||
if(newPos.z() > this.generatedUntil - this.ringSpacing) {
|
if(newPos.z() > generatedUntil - ringSpacing) {
|
||||||
this.generateRing(this.generatedUntil + this.ringSpacing);
|
generateRing(generatedUntil + ringSpacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newPos.z() > this.playerCheckpoints.get(player).nextCheckpoint) {
|
if(newPos.z() > playerCheckpoints.get(player).nextCheckpoint) {
|
||||||
this.playerCheckpoints.put(player, this.playerCheckpoints.get(player).next(this.ringSpacing));
|
playerCheckpoints.put(player, playerCheckpoints.get(player).next(ringSpacing));
|
||||||
this.boost(player);
|
boost(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newPos.y() > this.gameHeight - 5) {
|
if(newPos.y() > gameHeight - 5) {
|
||||||
Point particlePoint = newPos.withY(this.gameHeight);
|
Point particlePoint = newPos.withY(gameHeight);
|
||||||
ParticlePacket particle = new ParticlePacket(
|
ParticlePacket particle = new ParticlePacket(
|
||||||
Particle.WAX_ON,
|
Particle.WAX_ON,
|
||||||
particlePoint.blockX(),
|
particlePoint.blockX(),
|
||||||
@@ -156,17 +157,17 @@ public class ElytraRace extends StatelessGame {
|
|||||||
0,
|
0,
|
||||||
30,
|
30,
|
||||||
1f,
|
1f,
|
||||||
Math.toIntExact((long) NumberUtil.map(newPos.y(), this.gameHeight - 5, this.gameHeight, 50, 500))
|
Math.toIntExact((long) NumberUtil.map(newPos.y(), gameHeight - 5, gameHeight, 50, 500))
|
||||||
);
|
);
|
||||||
player.sendPacket(particle);
|
player.sendPacket(particle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.getBlock(player.getPosition()).equals(Block.WATER)) {
|
if(getBlock(player.getPosition()).equals(Block.WATER)) {
|
||||||
this.toCheckpoint(player);
|
toCheckpoint(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newPos.z() > this.ringCount * this.ringSpacing) {
|
if(newPos.z() > ringCount * ringSpacing) {
|
||||||
this.getScore().insertResult(player);
|
getScore().insertResult(player);
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
player.setFlyingWithElytra(false);
|
player.setFlyingWithElytra(false);
|
||||||
}
|
}
|
||||||
@@ -174,35 +175,34 @@ public class ElytraRace extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
return new Pos(this.vale.getXShiftAtZ(0), -45, 0);
|
return new Pos(vale.getXShiftAtZ(0), -45, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addResetItemToPlayer(Player p) {
|
private void addResetItemToPlayer(Player p) {
|
||||||
p.getInventory().setItemStack(8, ItemStack.builder(this.resetMaterial).customName(TranslatedComponent.byId("reset").getAssembled(p)).build());
|
p.getInventory().setItemStack(8, ItemStack.builder(resetMaterial).customName(TranslatedComponent.byId("reset").getAssembled(p)).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point getRingPositionAtZ(int z) {
|
private Point getRingPositionAtZ(int z) {
|
||||||
Random random = new Random(this.hashCode() + z);
|
return new Pos(vale.getXShiftAtZ(z), -45, z);
|
||||||
return new Pos(this.vale.getXShiftAtZ(z), -45 + random.nextInt(-5, 15), z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateRing(int zPos) {
|
private CompletableFuture<Void> generateRing(int zPos) {
|
||||||
if(zPos > this.ringCount * this.ringSpacing) return;
|
if(zPos > ringCount * ringSpacing) return null;
|
||||||
boolean isLast = (zPos == this.ringCount * this.ringSpacing);
|
boolean isLast = (zPos == ringCount * ringSpacing);
|
||||||
|
|
||||||
this.generatedUntil = zPos;
|
generatedUntil = zPos;
|
||||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
|
|
||||||
Point ringPos = this.getRingPositionAtZ(zPos);
|
Point ringPos = getRingPositionAtZ(zPos);
|
||||||
GeneratorUtils.iterateArea(
|
GeneratorUtils.iterateArea(
|
||||||
ringPos.sub(100, 0, 0).withY(0),
|
ringPos.sub(100, 0, 0).withY(0),
|
||||||
ringPos.add(100, 0, 0).withY(this.seaLevel),
|
ringPos.add(100, 0, 0).withY(seaLevel),
|
||||||
point -> batch.setBlock(point, Block.BARRIER)
|
point -> batch.setBlock(point, Block.BARRIER)
|
||||||
);
|
);
|
||||||
GeneratorUtils.iterateArea(
|
GeneratorUtils.iterateArea(
|
||||||
ringPos.sub(3, 3, 0),
|
ringPos.sub(3, 3, 0),
|
||||||
ringPos.add(3, 3, 0),
|
ringPos.add(3, 3, 0),
|
||||||
point -> batch.setBlock(point, isLast ? Block.DIAMOND_BLOCK : this.ringMaterial.block())
|
point -> batch.setBlock(point, isLast ? Block.DIAMOND_BLOCK : ringMaterial.block())
|
||||||
);
|
);
|
||||||
GeneratorUtils.iterateArea(
|
GeneratorUtils.iterateArea(
|
||||||
ringPos.sub(2, 2, 0),
|
ringPos.sub(2, 2, 0),
|
||||||
@@ -210,17 +210,8 @@ public class ElytraRace extends StatelessGame {
|
|||||||
point -> batch.setBlock(point, Block.AIR)
|
point -> batch.setBlock(point, Block.AIR)
|
||||||
);
|
);
|
||||||
|
|
||||||
int minChunkX = (ringPos.blockX() - 100) >> 4;
|
BatchUtil.loadAndApplyBatch(batch, this, () -> {});
|
||||||
int maxChunkX = (ringPos.blockX() + 100) >> 4;
|
return null;
|
||||||
int chunkZ = ringPos.blockZ() >> 4;
|
|
||||||
|
|
||||||
BatchUtil.loadAndApplyBatch(batch, this, () -> {
|
|
||||||
for(int cx = minChunkX; cx <= maxChunkX; cx++) {
|
|
||||||
Chunk chunk = this.getChunk(cx, chunkZ);
|
|
||||||
if(chunk == null) continue;
|
|
||||||
this.getPlayers().forEach(chunk::sendChunk);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void boost(Player player) {
|
private void boost(Player player) {
|
||||||
@@ -228,23 +219,21 @@ public class ElytraRace extends StatelessGame {
|
|||||||
|
|
||||||
Vec playerVelocity = player.getPosition().direction();
|
Vec playerVelocity = player.getPosition().direction();
|
||||||
player.setVelocity(
|
player.setVelocity(
|
||||||
player.getVelocity().add(playerVelocity.mul(this.boostMultiplier))
|
player.getVelocity().add(playerVelocity.mul(boostMultiplier))
|
||||||
.withY(playerVelocity.withY(v -> v * this.boostMultiplier).y())
|
.withY(playerVelocity.withY(v -> v * boostMultiplier).y())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toCheckpoint(Player p) {
|
private void toCheckpoint(Player p) {
|
||||||
CheckPointData data = this.playerCheckpoints.get(p);
|
Point checkpointPos = getRingPositionAtZ(playerCheckpoints.get(p).currentCheckpoint);
|
||||||
Point checkpointPos = this.getRingPositionAtZ(this.playerCheckpoints.get(p).currentCheckpoint);
|
|
||||||
if(data.currentCheckpoint == 0) checkpointPos = this.getSpawn().add(0, 3, 0);
|
|
||||||
p.setVelocity(Vec.ZERO);
|
p.setVelocity(Vec.ZERO);
|
||||||
p.setFlyingWithElytra(false);
|
p.setFlyingWithElytra(false);
|
||||||
p.teleport(new Pos(checkpointPos).add(0.5, 0, 0.5));
|
p.teleport(Pos.fromPoint(checkpointPos).add(0.5, 0, 0.5));
|
||||||
|
|
||||||
p.setFlying(true);
|
p.setFlying(true);
|
||||||
p.setFlyingSpeed(0);
|
p.setFlyingSpeed(0);
|
||||||
|
|
||||||
new Countdown()
|
new Countdown(TitleMessage.class)
|
||||||
.countdown(
|
.countdown(
|
||||||
Audience.audience(p),
|
Audience.audience(p),
|
||||||
3,
|
3,
|
||||||
@@ -256,24 +245,16 @@ public class ElytraRace extends StatelessGame {
|
|||||||
.subtitle(
|
.subtitle(
|
||||||
subtitleMessage ->
|
subtitleMessage ->
|
||||||
subtitleMessage
|
subtitleMessage
|
||||||
.appendTranslated("game_ElytraRace#launchIn")
|
.appendStatic(Component.text("Launch in ", NamedTextColor.DARK_GREEN))
|
||||||
.appendSpace()
|
|
||||||
.appendStatic(Component.text(countdownModifier.timeLeft, NamedTextColor.GREEN))
|
.appendStatic(Component.text(countdownModifier.timeLeft, NamedTextColor.GREEN))
|
||||||
.appendSpace()
|
.appendStatic(Component.text(" seconds", NamedTextColor.DARK_GREEN))
|
||||||
.appendTranslated(countdownModifier.timeLeft == 1 ? "common#second" : "common#seconds")
|
|
||||||
)
|
)
|
||||||
).thenRun(() -> {
|
).thenRun(() -> {
|
||||||
p.setFlying(false);
|
p.setFlying(false);
|
||||||
p.setFlyingSpeed(1);
|
p.setFlyingSpeed(1);
|
||||||
p.setFlyingWithElytra(true);
|
p.setFlyingWithElytra(true);
|
||||||
this.boost(p);
|
boost(p);
|
||||||
this.addResetItemToPlayer(p);
|
addResetItemToPlayer(p);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private record CheckPointData(int currentCheckpoint, int nextCheckpoint) {
|
|
||||||
public CheckPointData next(int spacing) {
|
|
||||||
return new CheckPointData(this.nextCheckpoint, this.nextCheckpoint + spacing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
-64
@@ -1,64 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
|
||||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
|
||||||
import net.minestom.server.entity.GameMode;
|
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
|
||||||
import net.minestom.server.instance.Chunk;
|
|
||||||
import net.minestom.server.inventory.PlayerInventory;
|
|
||||||
import net.minestom.server.item.ItemStack;
|
|
||||||
import net.minestom.server.item.Material;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class Fastbridge extends StatelessGame {
|
|
||||||
private int currentSpawn = 0;
|
|
||||||
|
|
||||||
public Fastbridge() {
|
|
||||||
super(Dimension.OVERWORLD.key, "Fastbridge", new FirstWinsScore());
|
|
||||||
this.setGenerator(new FastbridgeChunkgenerator());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
|
||||||
Player player = playerMoveEvent.getPlayer();
|
|
||||||
Pos newPos = playerMoveEvent.getNewPosition();
|
|
||||||
if(this.getScore().hasResult(player)) return;
|
|
||||||
if(newPos.y() < 0) {
|
|
||||||
player.teleport(this.getSpawn());
|
|
||||||
if(!this.isBeforeBeginning) this.resetPlayer(player);
|
|
||||||
}
|
|
||||||
if(newPos.x() > 53) {
|
|
||||||
this.getScore().insertResult(player);
|
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
this.getPlayers().forEach(player -> {
|
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
|
||||||
this.resetPlayer(player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onBlockPlace(@NotNull PlayerBlockPlaceEvent playerBlockPlaceEvent) {
|
|
||||||
if(this.isBeforeBeginning) playerBlockPlaceEvent.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetPlayer(Player player) {
|
|
||||||
if(this.isBeforeBeginning) return;
|
|
||||||
PlayerInventory inventory = player.getInventory();
|
|
||||||
inventory.clear();
|
|
||||||
inventory.addItemStack(ItemStack.of(Material.WHITE_WOOL, 64));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized Pos getSpawn() {
|
|
||||||
return new Pos(24, 1, this.currentSpawn++ * Chunk.CHUNK_SIZE_Z * 2 - 8, -90, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.world.generator.featureEnriched.ValeGenerator;
|
|
||||||
import eu.mhsl.minenet.minigames.world.generator.terrain.BaseGenerator;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
|
|
||||||
public class FastbridgeChunkgenerator extends BaseGenerator {
|
|
||||||
public FastbridgeChunkgenerator() {
|
|
||||||
this.addMixIn(unit -> {
|
|
||||||
if(unit.absoluteStart().chunkZ() % 2 == 0) {
|
|
||||||
unit.modifier().fill(Block.BARRIER);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(unit.absoluteStart().chunkX() != 1 && unit.absoluteStart().chunkX() != 3) return;
|
|
||||||
for(int x = 5; x <= 10; x++) {
|
|
||||||
for(int z = 5; z <= 10; z++) {
|
|
||||||
unit.modifier().setRelative(x, 64, z, unit.absoluteStart().chunkX() == 3 ? Block.GOLD_BLOCK : Block.GRASS_BLOCK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ValeGenerator vale = new ValeGenerator();
|
|
||||||
vale.setXShiftMultiplier(integer -> 0.5d);
|
|
||||||
vale.setHeightNoiseMultiplier(integer -> 2);
|
|
||||||
vale.setXShiftOffset(integer -> 40d);
|
|
||||||
this.addMixIn(vale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.fastbridge;
|
|
||||||
|
|
||||||
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 FastbridgeFactory implements GameFactory {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent name() {
|
|
||||||
return TranslatedComponent.byId("game_Fastbridge#name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent description() {
|
|
||||||
return TranslatedComponent.byId("game_Fastbridge#description");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Material symbol() {
|
|
||||||
return Material.WHITE_WOOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
|
||||||
return new Fastbridge().setParent(parent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-135
@@ -1,135 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.highGround;
|
|
||||||
|
|
||||||
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.world.BlockPallet;
|
|
||||||
import io.github.togar2.pvp.events.EntityKnockbackEvent;
|
|
||||||
import io.github.togar2.pvp.events.FinalAttackEvent;
|
|
||||||
import io.github.togar2.pvp.events.PrepareAttackEvent;
|
|
||||||
import io.github.togar2.pvp.feature.CombatFeatures;
|
|
||||||
import io.github.togar2.pvp.feature.knockback.KnockbackSettings;
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
import net.minestom.server.event.instance.InstanceTickEvent;
|
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.WeakHashMap;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
class HighGround extends StatelessGame {
|
|
||||||
private final int radius;
|
|
||||||
private final int seconds;
|
|
||||||
private final WeakHashMap<Player, Integer> scoreMap = new WeakHashMap<>();
|
|
||||||
|
|
||||||
HighGround(int radius, int seconds) {
|
|
||||||
super(Dimension.THE_END.key, "highground", new PointsWinScore());
|
|
||||||
this.radius = radius;
|
|
||||||
this.seconds = seconds;
|
|
||||||
|
|
||||||
this.eventNode().addChild(
|
|
||||||
CombatFeatures.empty()
|
|
||||||
.add(CombatFeatures.VANILLA_ATTACK)
|
|
||||||
.add(CombatFeatures.VANILLA_DAMAGE)
|
|
||||||
.add(CombatFeatures.VANILLA_KNOCKBACK)
|
|
||||||
.build()
|
|
||||||
.createNode()
|
|
||||||
);
|
|
||||||
|
|
||||||
this.eventNode().addListener(
|
|
||||||
FinalAttackEvent.class,
|
|
||||||
finalAttackEvent -> finalAttackEvent.setBaseDamage(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.eventNode().addListener(PrepareAttackEvent.class, prepareAttackEvent -> {
|
|
||||||
if(this.isBeforeBeginning) {
|
|
||||||
prepareAttackEvent.setCancelled(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.eventNode().addListener(
|
|
||||||
EntityKnockbackEvent.class,
|
|
||||||
entityKnockbackEvent -> entityKnockbackEvent.setSettings(
|
|
||||||
KnockbackSettings.builder()
|
|
||||||
.horizontal(1.1)
|
|
||||||
.vertical(KnockbackSettings.DEFAULT.vertical())
|
|
||||||
.verticalLimit(KnockbackSettings.DEFAULT.verticalLimit())
|
|
||||||
.extraHorizontal(KnockbackSettings.DEFAULT.extraHorizontal())
|
|
||||||
.extraVertical(KnockbackSettings.DEFAULT.extraVertical())
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.eventNode().addListener(InstanceTickEvent.class, instanceTickEvent -> {
|
|
||||||
if(this.isBeforeBeginning || !this.isRunning) return;
|
|
||||||
this.getPlayers().forEach(player -> {
|
|
||||||
if((player.isOnGround() && player.getPosition().y() >= 1) || (!player.isOnGround() && player.getPosition().y() >= 1.5)) {
|
|
||||||
this.scoreMap.put(player, this.scoreMap.get(player) + 1);
|
|
||||||
player.setLevel(this.scoreMap.get(player) / 20);
|
|
||||||
player.setExp((this.scoreMap.get(player) % 20) / 20.0f);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
|
||||||
for(int y = 0; y >= -3; y--) {
|
|
||||||
int radius = (Math.abs(y) * 5) + this.radius;
|
|
||||||
for(int x = -radius; x <= radius; x++) {
|
|
||||||
for(int z = -radius; z <= radius; z++) {
|
|
||||||
double distance = new Pos(x, 0, z).distance(0, 0, 0);
|
|
||||||
if(distance <= radius) {
|
|
||||||
this.setBlock(x, y, z, y == 0 ? Block.DIAMOND_BLOCK : Block.GRASS_BLOCK);
|
|
||||||
Pos featurePosition = new Pos(x, y + 1, z);
|
|
||||||
|
|
||||||
if(y >= 0 || this.getBlock(featurePosition).isSolid()) continue;
|
|
||||||
if(this.rnd.nextDouble() < 0.1) {
|
|
||||||
this.setBlock(featurePosition, Block.SHORT_GRASS);
|
|
||||||
}
|
|
||||||
if(this.rnd.nextDouble() < 0.01) {
|
|
||||||
this.setBlock(featurePosition, BlockPallet.FLOWER.rnd());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
|
||||||
Player player = playerMoveEvent.getPlayer();
|
|
||||||
if(playerMoveEvent.getNewPosition().y() < -10) {
|
|
||||||
player.teleport(this.getSpawn());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void start() {
|
|
||||||
this.getPlayers().forEach(player -> this.scoreMap.put(player, 0));
|
|
||||||
super.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
this.setTimeLimit(this.seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
this.getPlayers().forEach(player -> this.getScore().insertResult(player, this.scoreMap.get(player)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Pos getSpawn() {
|
|
||||||
double theta = this.rnd.nextDouble() * 2 * Math.PI;
|
|
||||||
|
|
||||||
double spawnRadius = this.radius + 5;
|
|
||||||
double x = spawnRadius * Math.cos(theta);
|
|
||||||
double z = spawnRadius * Math.sin(theta);
|
|
||||||
|
|
||||||
return new Pos(x, 0, z).withLookAt(new Pos(0, 0, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.highGround;
|
|
||||||
|
|
||||||
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 HighGroundFactory implements GameFactory {
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent name() {
|
|
||||||
return TranslatedComponent.byId("game_Highground#name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent description() {
|
|
||||||
return TranslatedComponent.byId("game_Highground#description");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Material symbol() {
|
|
||||||
return Material.GOLDEN_HELMET;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConfigManager configuration() {
|
|
||||||
return new ConfigManager()
|
|
||||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 3, 5, 7, 10))
|
|
||||||
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("optionCommon#seconds"), 30, 60, 90, 120));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
|
||||||
return new HighGround(configuration.get("radius").getAsInt(), configuration.get("seconds").getAsInt()).setParent(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestrictionHandler globalRestrictions() {
|
|
||||||
return new RestrictionHandler()
|
|
||||||
.addRestriction(new MinimalPlayeramountGameRestriction(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+17
-17
@@ -35,10 +35,10 @@ public class JumpDive extends StatelessGame {
|
|||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
|
||||||
|
|
||||||
for(int x = -this.radius * 2; x <= this.radius * 2; x++) {
|
for(int x = -radius*2; x <= radius*2; x++) {
|
||||||
for(int z = -this.radius * 2; z <= this.radius * 2; z++) {
|
for(int z = -radius*2; z <= radius*2; z++) {
|
||||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > this.radius) {
|
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) {
|
||||||
batch.setBlock(x, this.height, z, BlockPallet.STONE.rnd());
|
batch.setBlock(x, height, z, BlockPallet.STONE.rnd());
|
||||||
} else {
|
} else {
|
||||||
batch.setBlock(x, 0, z, BlockPallet.GROUND.rnd());
|
batch.setBlock(x, 0, z, BlockPallet.GROUND.rnd());
|
||||||
batch.setBlock(x, 1, z, Block.WATER);
|
batch.setBlock(x, 1, z, Block.WATER);
|
||||||
@@ -51,7 +51,7 @@ public class JumpDive extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
this.setTimeLimit(this.timeLimit);
|
setTimeLimit(timeLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -59,22 +59,22 @@ public class JumpDive extends StatelessGame {
|
|||||||
Player p = playerMoveEvent.getPlayer();
|
Player p = playerMoveEvent.getPlayer();
|
||||||
|
|
||||||
if(
|
if(
|
||||||
p.isOnGround() && playerMoveEvent.getNewPosition().y() < this.height
|
p.isOnGround() && playerMoveEvent.getNewPosition().y() < height
|
||||||
|| playerMoveEvent.getNewPosition().y() < 0
|
|| playerMoveEvent.getNewPosition().y() < 0
|
||||||
|| this.isBeforeBeginning && playerMoveEvent.getNewPosition().y() < this.height
|
|| isBeforeBeginning && playerMoveEvent.getNewPosition().y() < height
|
||||||
) {
|
) {
|
||||||
p.teleport(this.getSpawn());
|
p.teleport(getSpawn());
|
||||||
playerMoveEvent.setCancelled(true);
|
playerMoveEvent.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(
|
if(
|
||||||
playerMoveEvent.getNewPosition().y() <= 1
|
playerMoveEvent.getNewPosition().y() <= 1
|
||||||
&& playerMoveEvent.getNewPosition().distance(0, 1, 0) < this.radius + 0.5
|
&& playerMoveEvent.getNewPosition().distance(0, 1, 0) < radius + 0.5
|
||||||
&& !(!this.isBeforeBeginning && !this.isRunning)
|
&& !(!isBeforeBeginning && !isRunning)
|
||||||
) {
|
) {
|
||||||
this.setBlock(playerMoveEvent.getNewPosition().withY(1), Block.REDSTONE_BLOCK);
|
setBlock(playerMoveEvent.getNewPosition().withY(1), Block.REDSTONE_BLOCK);
|
||||||
this.scores.merge(p, 1, Integer::sum);
|
scores.merge(p, 1, Integer::sum);
|
||||||
p.teleport(this.getSpawn());
|
p.teleport(getSpawn());
|
||||||
playerMoveEvent.setCancelled(true);
|
playerMoveEvent.setCancelled(true);
|
||||||
p.playSound(Sound.sound(SoundEvent.ENTITY_EXPERIENCE_ORB_PICKUP, Sound.Source.PLAYER, 2f, 2f));
|
p.playSound(Sound.sound(SoundEvent.ENTITY_EXPERIENCE_ORB_PICKUP, Sound.Source.PLAYER, 2f, 2f));
|
||||||
}
|
}
|
||||||
@@ -82,18 +82,18 @@ public class JumpDive extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
this.getPlayers().forEach(player -> this.getScore().insertResult(player, this.scores.getOrDefault(player, 0)));
|
getPlayers().forEach(player -> getScore().insertResult(player, scores.getOrDefault(player, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
double theta = this.rnd.nextDouble() * 2 * Math.PI;
|
double theta = rnd.nextDouble() * 2 * Math.PI;
|
||||||
|
|
||||||
double spawnRadius = this.radius + 2;
|
double spawnRadius = radius + 2;
|
||||||
double x = spawnRadius * Math.cos(theta);
|
double x = spawnRadius * Math.cos(theta);
|
||||||
double z = spawnRadius * Math.sin(theta);
|
double z = spawnRadius * Math.sin(theta);
|
||||||
|
|
||||||
return new Pos(x, this.height + 2, z).withLookAt(new Pos(0, this.height, 0));
|
return new Pos(x, height + 2, z).withLookAt(new Pos(0, height, 0));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loaded 100 of 283 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user