mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-06 23:11:30 +00:00
Compare commits
1 Commits
main
...
bifrost-se
Author | SHA1 | Date | |
---|---|---|---|
e05d6355e6 |
25
.github/workflows-disabled/build.yml
vendored
25
.github/workflows-disabled/build.yml
vendored
@ -1,25 +0,0 @@
|
|||||||
name: Build
|
|
||||||
on: [push]
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout Repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Set up JDK 17
|
|
||||||
uses: actions/setup-java@v3
|
|
||||||
with:
|
|
||||||
java-version: '17'
|
|
||||||
distribution: 'temurin'
|
|
||||||
- name: Build with Gradle
|
|
||||||
uses: gradle/gradle-build-action@v2
|
|
||||||
with:
|
|
||||||
arguments: build check
|
|
||||||
- name: Organize Artifacts
|
|
||||||
run: ./tools/organize-artifacts.sh
|
|
||||||
- name: Upload Artifacts
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: foundation-build
|
|
||||||
path: |
|
|
||||||
artifacts/*
|
|
36
.github/workflows-disabled/release.yml
vendored
36
.github/workflows-disabled/release.yml
vendored
@ -1,36 +0,0 @@
|
|||||||
name: Release
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
jobs:
|
|
||||||
upload:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout Repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Set up JDK 17
|
|
||||||
uses: actions/setup-java@v3
|
|
||||||
with:
|
|
||||||
java-version: '17'
|
|
||||||
distribution: 'temurin'
|
|
||||||
- name: Build with Gradle
|
|
||||||
uses: gradle/gradle-build-action@v2
|
|
||||||
with:
|
|
||||||
arguments: build
|
|
||||||
env:
|
|
||||||
CONCRETE_BUILD_NUMBER: "${{ github.run_number }}"
|
|
||||||
- name: Organize Artifacts
|
|
||||||
run: ./tools/organize-artifacts.sh
|
|
||||||
- name: Upload to Backblaze
|
|
||||||
run: ./tools/gh-upload-backblaze.sh
|
|
||||||
env:
|
|
||||||
ARTIFACTS_KEY_ID: "${{ secrets.ARTIFACTS_KEY_ID }}"
|
|
||||||
ARTIFACTS_APP_KEY: "${{ secrets.ARTIFACTS_APP_KEY }}"
|
|
||||||
ARTIFACTS_BUCKET: "${{ secrets.ARTIFACTS_BUCKET }}"
|
|
||||||
- name: Upload Artifacts
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: foundation-build
|
|
||||||
path: |
|
|
||||||
artifacts/*
|
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -119,7 +119,3 @@ run/
|
|||||||
|
|
||||||
# Foundation Server
|
# Foundation Server
|
||||||
/server
|
/server
|
||||||
|
|
||||||
# Foundation build
|
|
||||||
/.concrete-local-path
|
|
||||||
/artifacts
|
|
||||||
|
18
.gitlab-ci.yml
Normal file
18
.gitlab-ci.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
image: gradle:7.3-jdk17
|
||||||
|
|
||||||
|
variables:
|
||||||
|
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
|
||||||
|
|
||||||
|
build:
|
||||||
|
stage: build
|
||||||
|
script: gradle --build-cache assemble
|
||||||
|
cache:
|
||||||
|
key: "$CI_COMMIT_REF_NAME"
|
||||||
|
policy: push
|
||||||
|
paths:
|
||||||
|
- build
|
||||||
|
- .gradle
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- "build/manifests/update.json"
|
||||||
|
- "**/build/libs/*-plugin.jar"
|
215
LICENSE
215
LICENSE
@ -1,21 +1,202 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2023 Gay Pizza Specifications
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
1. Definitions.
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
the copyright owner that is granting the License.
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
11
README.md
11
README.md
@ -7,21 +7,12 @@ server.
|
|||||||
|
|
||||||
* foundation-core: Core functionality
|
* foundation-core: Core functionality
|
||||||
* foundation-bifrost: Discord chat bridge
|
* foundation-bifrost: Discord chat bridge
|
||||||
* foundation-chaos: Simulate chaos inside a minecraft world
|
|
||||||
* foundation-heimdall: Event tracking
|
* foundation-heimdall: Event tracking
|
||||||
* foundation-tailscale: Connect the Minecraft Server to Tailscale
|
|
||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
* tool-gjallarhorn - Heimdall swiss army knife
|
* tool-gjallarhorn - Heimdall swiss army knife
|
||||||
|
|
||||||
## Libraries
|
|
||||||
|
|
||||||
* common-all: Common code for every Foundation module.
|
|
||||||
* common-plugin: Common code for every Foundation plugin. Included directly in the plugin jar.
|
|
||||||
* common-heimdall: Common code for Heimdall modules.
|
|
||||||
* foundation-shared: Common code for every Foundation plugin. Linked dynamically from Foundation Core.
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
The following command downloads and runs a script that will fetch the latest update manifest, and
|
The following command downloads and runs a script that will fetch the latest update manifest, and
|
||||||
@ -30,5 +21,5 @@ available.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Always validate the contents of a script from the internet!
|
# Always validate the contents of a script from the internet!
|
||||||
bash -c "$(curl -sL https://github.com/GayPizzaSpecifications/foundation/raw/main/install.sh)"
|
bash -c "$(curl -sL https://git.mystic.run/minecraft/foundation/-/raw/main/install.sh)"
|
||||||
```
|
```
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
|
import cloud.kubelet.foundation.gradle.FoundationProjectPlugin
|
||||||
|
import cloud.kubelet.foundation.gradle.isFoundationPlugin
|
||||||
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
@Suppress("DSL_SCOPE_VIOLATION")
|
|
||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
|
id("cloud.kubelet.foundation.gradle")
|
||||||
alias(libs.plugins.concrete.root)
|
|
||||||
alias(libs.plugins.concrete.base) apply false
|
|
||||||
alias(libs.plugins.concrete.library) apply false
|
|
||||||
alias(libs.plugins.concrete.plugin) apply false
|
|
||||||
|
|
||||||
alias(libs.plugins.versions)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
name = "papermc"
|
||||||
|
url = uri("https://papermc.io/repo/repository/maven-public/")
|
||||||
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
name = "sonatype"
|
name = "sonatype"
|
||||||
@ -23,23 +23,75 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.assemble {
|
||||||
|
dependsOn("updateManifests")
|
||||||
|
}
|
||||||
|
|
||||||
version = "0.2"
|
version = "0.2"
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
group = "gay.pizza.foundation"
|
plugins.apply("org.jetbrains.kotlin.jvm")
|
||||||
|
plugins.apply("org.jetbrains.kotlin.plugin.serialization")
|
||||||
|
plugins.apply("com.github.johnrengelman.shadow")
|
||||||
|
plugins.apply(FoundationProjectPlugin::class)
|
||||||
|
|
||||||
|
group = "lgbt.mystic"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// Kotlin dependencies
|
||||||
|
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||||
|
|
||||||
|
// Core libraries.
|
||||||
|
implementation("io.insert-koin:koin-core:3.1.4")
|
||||||
|
testImplementation("io.insert-koin:koin-test:3.1.4")
|
||||||
|
|
||||||
|
// Serialization
|
||||||
|
implementation("com.charleskorn.kaml:kaml:0.38.0")
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")
|
||||||
|
|
||||||
|
// Persistence
|
||||||
|
implementation("org.jetbrains.xodus:xodus-openAPI:1.3.232")
|
||||||
|
implementation("org.jetbrains.xodus:xodus-entity-store:1.3.232")
|
||||||
|
|
||||||
|
// Paper API
|
||||||
|
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
val javaVersion = JavaVersion.toVersion(17)
|
||||||
|
sourceCompatibility = javaVersion
|
||||||
|
targetCompatibility = javaVersion
|
||||||
|
}
|
||||||
|
|
||||||
tasks.withType<KotlinCompile> {
|
tasks.withType<KotlinCompile> {
|
||||||
compilerOptions {
|
kotlinOptions {
|
||||||
freeCompilerArgs.add("-opt-in=kotlinx.serialization.ExperimentalSerializationApi")
|
freeCompilerArgs =
|
||||||
|
freeCompilerArgs + "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.processResources {
|
||||||
|
val props = mapOf("version" to version)
|
||||||
|
inputs.properties(props)
|
||||||
|
filteringCharset = "UTF-8"
|
||||||
|
filesMatching("plugin.yml") {
|
||||||
|
expand(props)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (project.isFoundationPlugin()) {
|
||||||
|
tasks.withType<ShadowJar> {
|
||||||
|
archiveClassifier.set("plugin")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.assemble {
|
||||||
|
dependsOn("shadowJar")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val paperServerVersion: String = project.properties["paperServerVersion"]?.toString() ?: "1.21"
|
foundation {
|
||||||
|
|
||||||
concreteRoot {
|
|
||||||
minecraftServerPath.set("server")
|
minecraftServerPath.set("server")
|
||||||
paperServerVersionGroup.set(paperServerVersion)
|
paperVersionGroup.set("1.18")
|
||||||
paperApiVersion.set("1.21.4-R0.1-SNAPSHOT")
|
|
||||||
acceptServerEula.set(true)
|
|
||||||
}
|
}
|
||||||
|
28
buildSrc/build.gradle.kts
Normal file
28
buildSrc/build.gradle.kts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
plugins {
|
||||||
|
`kotlin-dsl`
|
||||||
|
kotlin("plugin.serialization") version "1.6.21"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-serialization:1.6.21")
|
||||||
|
implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
|
||||||
|
implementation("com.google.code.gson:gson:2.9.0")
|
||||||
|
implementation("org.bouncycastle:bcprov-jdk15on:1.70")
|
||||||
|
}
|
||||||
|
|
||||||
|
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
java.targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
|
gradlePlugin {
|
||||||
|
plugins {
|
||||||
|
create("foundation") {
|
||||||
|
id = "cloud.kubelet.foundation.gradle"
|
||||||
|
implementationClass = "cloud.kubelet.foundation.gradle.FoundationGradlePlugin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.provider.Property
|
||||||
|
|
||||||
|
interface FoundationExtension {
|
||||||
|
val paperVersionGroup: Property<String>
|
||||||
|
val minecraftServerPath: Property<String>
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
|
||||||
|
object FoundationGlobals {
|
||||||
|
val gson = Gson()
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.kotlin.dsl.create
|
||||||
|
|
||||||
|
class FoundationGradlePlugin : Plugin<Project> {
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
project.extensions.create<FoundationExtension>("foundation")
|
||||||
|
val setupPaperServer = project.tasks.create<SetupPaperServer>("setupPaperServer")
|
||||||
|
project.afterEvaluate { ->
|
||||||
|
setupPaperServer.dependsOn(*project.subprojects
|
||||||
|
.filter { it.name.startsWith("foundation-") }
|
||||||
|
.map { it.tasks.getByName("shadowJar") }
|
||||||
|
.toTypedArray()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val runPaperServer = project.tasks.create<RunPaperServer>("runPaperServer")
|
||||||
|
runPaperServer.dependsOn(setupPaperServer)
|
||||||
|
|
||||||
|
val updateManifests = project.tasks.create<UpdateManifestTask>("updateManifests")
|
||||||
|
project.tasks.getByName("assemble").dependsOn(updateManifests)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
|
||||||
|
class FoundationProjectPlugin : Plugin<Project> {
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
val versionWithBuild = if (System.getenv("CI_PIPELINE_IID") != null) {
|
||||||
|
project.rootProject.version.toString() + ".${System.getenv("CI_PIPELINE_IID")}"
|
||||||
|
} else {
|
||||||
|
"DEV"
|
||||||
|
}
|
||||||
|
|
||||||
|
project.version = versionWithBuild
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import java.net.URI
|
||||||
|
import java.net.http.HttpClient
|
||||||
|
import java.net.http.HttpRequest
|
||||||
|
import java.net.http.HttpResponse
|
||||||
|
|
||||||
|
class PaperVersionClient(
|
||||||
|
val client: HttpClient = HttpClient.newHttpClient(),
|
||||||
|
private val gson: Gson = FoundationGlobals.gson
|
||||||
|
) {
|
||||||
|
private val apiBaseUrl = URI.create("https://papermc.io/api/v2/")
|
||||||
|
|
||||||
|
fun getVersionBuilds(group: String): List<PaperBuild> {
|
||||||
|
val response = client.send(
|
||||||
|
HttpRequest.newBuilder()
|
||||||
|
.GET()
|
||||||
|
.uri(apiBaseUrl.resolve("projects/paper/version_group/${group}/builds"))
|
||||||
|
.build(),
|
||||||
|
HttpResponse.BodyHandlers.ofString()
|
||||||
|
)
|
||||||
|
|
||||||
|
val body = response.body()
|
||||||
|
val root = gson.fromJson(body, PaperVersionRoot::class.java)
|
||||||
|
return root.builds
|
||||||
|
}
|
||||||
|
|
||||||
|
fun resolveDownloadUrl(build: PaperBuild, download: PaperVersionDownload): URI =
|
||||||
|
apiBaseUrl.resolve("projects/paper/versions/${build.version}/builds/${build.build}/downloads/${download.name}")
|
||||||
|
|
||||||
|
data class PaperVersionRoot(
|
||||||
|
val builds: List<PaperBuild>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PaperBuild(
|
||||||
|
val version: String,
|
||||||
|
val build: Int,
|
||||||
|
val downloads: Map<String, PaperVersionDownload>
|
||||||
|
)
|
||||||
|
|
||||||
|
data class PaperVersionDownload(
|
||||||
|
val name: String,
|
||||||
|
val sha256: String
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import org.gradle.kotlin.dsl.getByType
|
||||||
|
import java.io.File
|
||||||
|
import java.util.jar.JarFile
|
||||||
|
|
||||||
|
open class RunPaperServer : DefaultTask() {
|
||||||
|
init {
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
|
}
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
fun runPaperServer() {
|
||||||
|
val foundation = project.extensions.getByType<FoundationExtension>()
|
||||||
|
|
||||||
|
val minecraftServerDirectory = project.file(foundation.minecraftServerPath.get())
|
||||||
|
val paperJarFile = minecraftServerDirectory.resolve("paper.jar")
|
||||||
|
val mainClassName = readMainClass(paperJarFile)
|
||||||
|
|
||||||
|
project.javaexec {
|
||||||
|
classpath(paperJarFile.absolutePath)
|
||||||
|
workingDir(minecraftServerDirectory)
|
||||||
|
args("nogui")
|
||||||
|
mainClass.set(mainClassName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readMainClass(file: File): String = JarFile(file).use { jar ->
|
||||||
|
jar.manifest.mainAttributes.getValue("Main-Class")!!
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.tasks.Input
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import org.gradle.api.tasks.options.Option
|
||||||
|
import org.gradle.kotlin.dsl.getByType
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
open class SetupPaperServer : DefaultTask() {
|
||||||
|
init {
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
|
}
|
||||||
|
|
||||||
|
@get:Input
|
||||||
|
@set:Option(option = "update", description = "Update Paper Server")
|
||||||
|
var shouldUpdatePaperServer = false
|
||||||
|
|
||||||
|
private val paperVersionClient = PaperVersionClient()
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
fun downloadPaperTask() {
|
||||||
|
val foundation = project.extensions.getByType<FoundationExtension>()
|
||||||
|
val minecraftServerDirectory = project.file(foundation.minecraftServerPath.get())
|
||||||
|
|
||||||
|
if (!minecraftServerDirectory.exists()) {
|
||||||
|
minecraftServerDirectory.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
val paperJarFile = project.file("${foundation.minecraftServerPath.get()}/paper.jar")
|
||||||
|
if (!paperJarFile.exists() || shouldUpdatePaperServer) {
|
||||||
|
downloadLatestBuild(foundation.paperVersionGroup.get(), paperJarFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
val paperPluginsDirectory = minecraftServerDirectory.resolve("plugins")
|
||||||
|
|
||||||
|
if (!paperPluginsDirectory.exists()) {
|
||||||
|
paperPluginsDirectory.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
for (project in project.subprojects) {
|
||||||
|
if (!project.name.startsWith("foundation-")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
val pluginJarFile = project.buildDir.resolve("libs/${project.name}-DEV-plugin.jar")
|
||||||
|
val pluginLinkFile = paperPluginsDirectory.resolve("${project.name}.jar")
|
||||||
|
if (pluginLinkFile.exists()) {
|
||||||
|
pluginLinkFile.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
Files.createSymbolicLink(pluginLinkFile.toPath(), pluginJarFile.toPath())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun downloadLatestBuild(paperVersionGroup: String, paperJarFile: File) {
|
||||||
|
val builds = paperVersionClient.getVersionBuilds(paperVersionGroup)
|
||||||
|
val build = builds.last()
|
||||||
|
val download = build.downloads["application"]!!
|
||||||
|
val url = paperVersionClient.resolveDownloadUrl(build, download)
|
||||||
|
val downloader = SmartDownloader(paperJarFile.toPath(), url, download.sha256)
|
||||||
|
if (downloader.download()) {
|
||||||
|
logger.lifecycle("Installed Paper Server ${build.version} build ${build.build}")
|
||||||
|
} else {
|
||||||
|
logger.lifecycle("Paper Server ${build.version} build ${build.build} is up-to-date")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import java.net.URI
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.security.MessageDigest
|
||||||
|
|
||||||
|
class SmartDownloader(
|
||||||
|
private val localFilePath: Path,
|
||||||
|
private val remoteDownloadUrl: URI,
|
||||||
|
private val sha256: String
|
||||||
|
) {
|
||||||
|
fun download(): Boolean {
|
||||||
|
val hashResult = checkLocalFileHash()
|
||||||
|
if (hashResult != HashResult.ValidHash) {
|
||||||
|
downloadRemoteFile()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun downloadRemoteFile() {
|
||||||
|
val url = remoteDownloadUrl.toURL()
|
||||||
|
val remoteFileStream = url.openStream()
|
||||||
|
val localFileStream = Files.newOutputStream(localFilePath)
|
||||||
|
remoteFileStream.transferTo(localFileStream)
|
||||||
|
val hashResult = checkLocalFileHash()
|
||||||
|
if (hashResult != HashResult.ValidHash) {
|
||||||
|
throw RuntimeException("Download of $remoteDownloadUrl did not result in valid hash.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkLocalFileHash(): HashResult {
|
||||||
|
if (!Files.exists(localFilePath)) {
|
||||||
|
return HashResult.DoesNotExist
|
||||||
|
}
|
||||||
|
|
||||||
|
val digest = MessageDigest.getInstance("SHA-256")
|
||||||
|
val localFileStream = Files.newInputStream(localFilePath)
|
||||||
|
val buffer = ByteArray(16 * 1024)
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
val size = localFileStream.read(buffer)
|
||||||
|
if (size <= 0) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
val bytes = buffer.take(size).toByteArray()
|
||||||
|
digest.update(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
val sha256Bytes = digest.digest()
|
||||||
|
val localSha256Hash = bytesToHex(sha256Bytes)
|
||||||
|
return if (localSha256Hash.equals(sha256, ignoreCase = true)) {
|
||||||
|
HashResult.ValidHash
|
||||||
|
} else {
|
||||||
|
HashResult.InvalidHash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bytesToHex(hash: ByteArray): String {
|
||||||
|
val hexString = StringBuilder(2 * hash.size)
|
||||||
|
for (i in hash.indices) {
|
||||||
|
val hex = Integer.toHexString(0xff and hash[i].toInt())
|
||||||
|
if (hex.length == 1) {
|
||||||
|
hexString.append('0')
|
||||||
|
}
|
||||||
|
hexString.append(hex)
|
||||||
|
}
|
||||||
|
return hexString.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class HashResult {
|
||||||
|
DoesNotExist,
|
||||||
|
InvalidHash,
|
||||||
|
ValidHash
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
open class UpdateManifestTask : DefaultTask() {
|
||||||
|
@TaskAction
|
||||||
|
fun update() {
|
||||||
|
val manifestsDir = ensureManifestsDir()
|
||||||
|
val updateFile = manifestsDir.resolve("update.json")
|
||||||
|
val rootPath = project.rootProject.rootDir.toPath()
|
||||||
|
val updateManifest = project.findPluginProjects().mapNotNull { project ->
|
||||||
|
val paths = project.shadowJarOutputs.allFilesRelativeToPath(rootPath)
|
||||||
|
if (paths.isNotEmpty()) {
|
||||||
|
project.name to mapOf(
|
||||||
|
"version" to project.version,
|
||||||
|
"artifacts" to paths.map { it.toUnixString() }
|
||||||
|
)
|
||||||
|
} else null
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
|
Files.writeString(updateFile, FoundationGlobals.gson.toJson(updateManifest))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ensureManifestsDir(): Path {
|
||||||
|
val manifestsDir = project.buildDir.resolve("manifests")
|
||||||
|
manifestsDir.mkdirs()
|
||||||
|
return manifestsDir.toPath()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package cloud.kubelet.foundation.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.tasks.TaskOutputs
|
||||||
|
import java.nio.file.FileSystems
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
fun Project.isFoundationPlugin() = name.startsWith("foundation-")
|
||||||
|
|
||||||
|
fun Project.findPluginProjects() = rootProject.subprojects.filter { project -> project.isFoundationPlugin() }
|
||||||
|
|
||||||
|
val Project.shadowJarOutputs: TaskOutputs
|
||||||
|
get() = project.tasks.getByName("shadowJar").outputs
|
||||||
|
|
||||||
|
fun TaskOutputs.allFilesRelativeToPath(root: Path): List<Path> = files.map { root.relativize(it.toPath()) }
|
||||||
|
|
||||||
|
fun Path.toUnixString() = toString().replace(FileSystems.getDefault().separator, "/")
|
@ -1,9 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("gay.pizza.foundation.concrete-base")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
// Serialization
|
|
||||||
api(libs.kotlin.serialization.json)
|
|
||||||
api(libs.kotlin.serialization.yaml)
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
package gay.pizza.foundation.common
|
|
||||||
|
|
||||||
fun <T> Array<T>.without(value: T): List<T> = filter { it != value }
|
|
@ -1,11 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("gay.pizza.foundation.concrete-base")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
api(project(":common-all"))
|
|
||||||
api(libs.postgresql)
|
|
||||||
api(libs.exposed.jdbc)
|
|
||||||
api(libs.exposed.java.time)
|
|
||||||
api(libs.hikaricp)
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.export
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class ExportedBlock(
|
|
||||||
val type: String,
|
|
||||||
val data: String? = null
|
|
||||||
)
|
|
@ -1,19 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.load
|
|
||||||
|
|
||||||
import gay.pizza.foundation.heimdall.export.ExportedBlock
|
|
||||||
|
|
||||||
class ExportedBlockTable {
|
|
||||||
private val internalBlocks = mutableListOf<ExportedBlock>()
|
|
||||||
|
|
||||||
val blocks: List<ExportedBlock>
|
|
||||||
get() = internalBlocks
|
|
||||||
|
|
||||||
fun index(block: ExportedBlock): Int {
|
|
||||||
val existing = internalBlocks.indexOf(block)
|
|
||||||
if (existing >= 0) {
|
|
||||||
return existing
|
|
||||||
}
|
|
||||||
internalBlocks.add(block)
|
|
||||||
return internalBlocks.size - 1
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.load
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlin.math.absoluteValue
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class OffsetList<L: List<T>, T>(
|
|
||||||
val offset: Int,
|
|
||||||
val data: L
|
|
||||||
) {
|
|
||||||
fun <K> toMap(toKey: (Int) -> K): Map<K, T> {
|
|
||||||
val map = mutableMapOf<K, T>()
|
|
||||||
for ((index, value) in data.withIndex()) {
|
|
||||||
val real = index + offset
|
|
||||||
val key = toKey(real)
|
|
||||||
map[key] = value
|
|
||||||
}
|
|
||||||
return map
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <R> map(value: (T) -> R): ImmutableOffsetList<R> =
|
|
||||||
ImmutableOffsetList(offset, MutableList(data.size) { index -> value(data[index]) })
|
|
||||||
|
|
||||||
fun eachRealIndex(block: (Int, T) -> Unit) {
|
|
||||||
for ((fakeIndex, value) in data.withIndex()) {
|
|
||||||
val realIndex = fakeIndex + offset
|
|
||||||
block(realIndex, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun <K, T, V> transform(
|
|
||||||
map: Map<K, T>,
|
|
||||||
minAndTotal: (Map<K, T>) -> Pair<Int, Int>,
|
|
||||||
keyToInt: (K) -> Int,
|
|
||||||
valueTransform: (T) -> V
|
|
||||||
): ImmutableOffsetList<V?> {
|
|
||||||
val (min, total) = minAndTotal(map)
|
|
||||||
val offset = if (min < 0) min.absoluteValue else 0
|
|
||||||
val list = MutableList<V?>(total) { null }
|
|
||||||
for ((key, value) in map) {
|
|
||||||
val pkey = keyToInt(key)
|
|
||||||
val rkey = pkey + offset
|
|
||||||
list[rkey] = valueTransform(value)
|
|
||||||
}
|
|
||||||
return OffsetList(if (min < 0) min else 0, list)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typealias ImmutableOffsetList<T> = OffsetList<List<T>, T>
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
class WorldLoadCompactWorld(
|
|
||||||
override val name: String,
|
|
||||||
val data: ImmutableOffsetList<ImmutableOffsetList<ImmutableOffsetList<Int?>?>?>
|
|
||||||
) : WorldLoadWorld() {
|
|
||||||
override fun crawl(block: (Long, Long, Long, Int) -> Unit) {
|
|
||||||
data.eachRealIndex { x, zList ->
|
|
||||||
zList?.eachRealIndex { z, yList ->
|
|
||||||
yList?.eachRealIndex { y, index ->
|
|
||||||
if (index != null) {
|
|
||||||
block(x.toLong(), z.toLong(), y.toLong(), index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.load
|
|
||||||
|
|
||||||
import gay.pizza.foundation.heimdall.export.ExportedBlock
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
class WorldLoadFormat(
|
|
||||||
val blockLookupTable: List<ExportedBlock>,
|
|
||||||
val worlds: Map<String, WorldLoadWorld>
|
|
||||||
)
|
|
@ -1,64 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.load
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlin.math.absoluteValue
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
class WorldLoadSimpleWorld(
|
|
||||||
override val name: String,
|
|
||||||
val blocks: Map<Long, Map<Long, Map<Long, Int>>>
|
|
||||||
) : WorldLoadWorld() {
|
|
||||||
fun compact(): WorldLoadCompactWorld {
|
|
||||||
val list = OffsetList.transform(
|
|
||||||
blocks,
|
|
||||||
minAndTotal = ::minAndTotal,
|
|
||||||
keyToInt = Long::toInt,
|
|
||||||
valueTransform = { zValue ->
|
|
||||||
OffsetList.transform(
|
|
||||||
zValue,
|
|
||||||
minAndTotal = ::minAndTotal,
|
|
||||||
keyToInt = Long::toInt,
|
|
||||||
valueTransform = { yValue ->
|
|
||||||
OffsetList.transform(
|
|
||||||
yValue,
|
|
||||||
minAndTotal = ::minAndTotal,
|
|
||||||
keyToInt = Long::toInt,
|
|
||||||
valueTransform = { it }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
return WorldLoadCompactWorld(name, list)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun <T> minAndTotal(map: Map<Long, T>): Pair<Int, Int> {
|
|
||||||
val keys = map.keys
|
|
||||||
|
|
||||||
if (keys.isEmpty()) {
|
|
||||||
return 0 to 0
|
|
||||||
}
|
|
||||||
|
|
||||||
val min = keys.min()
|
|
||||||
val max = keys.max()
|
|
||||||
var total = 1L
|
|
||||||
|
|
||||||
if (max > 0) {
|
|
||||||
total += max
|
|
||||||
}
|
|
||||||
|
|
||||||
if (min < 0) {
|
|
||||||
total += min.absoluteValue
|
|
||||||
}
|
|
||||||
return min.toInt() to total.toInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun crawl(block: (Long, Long, Long, Int) -> Unit) {
|
|
||||||
for ((x, zBlocks) in blocks) {
|
|
||||||
for ((z, yBlocks) in zBlocks) {
|
|
||||||
for ((y, index) in yBlocks) {
|
|
||||||
block(x, z, y, index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.load
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
sealed class WorldLoadWorld {
|
|
||||||
abstract val name: String
|
|
||||||
|
|
||||||
abstract fun crawl(block: (Long, Long, Long, Int) -> Unit)
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.table
|
|
||||||
|
|
||||||
object BlockChangeTable : PlayerTimedLocalEventTable("block_changes") {
|
|
||||||
val block = text("block")
|
|
||||||
val data = text("data")
|
|
||||||
val cause = text("cause")
|
|
||||||
val inc = integer("inc")
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.table
|
|
||||||
|
|
||||||
object EntityKillTable : PlayerTimedLocalEventTable("entity_kills") {
|
|
||||||
val entity = uuid("entity")
|
|
||||||
val entityType = text("entity_type")
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.table
|
|
||||||
|
|
||||||
object PlayerAdvancementTable : PlayerTimedLocalEventTable("player_advancements") {
|
|
||||||
val advancement = text("advancement")
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.table
|
|
||||||
|
|
||||||
object PlayerDeathTable : PlayerTimedLocalEventTable("player_deaths") {
|
|
||||||
val experience = double("experience")
|
|
||||||
val message = text("message").nullable()
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.table
|
|
||||||
|
|
||||||
object PlayerPositionTable : PlayerTimedLocalEventTable("player_positions")
|
|
@ -1,7 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.table
|
|
||||||
|
|
||||||
abstract class PlayerTimedLocalEventTable(name: String) : TimedLocalEventTable(name) {
|
|
||||||
val player = uuid("player").nullable()
|
|
||||||
val pitch = double("pitch")
|
|
||||||
val yaw = double("yaw")
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.table
|
|
||||||
|
|
||||||
import org.jetbrains.exposed.sql.Table
|
|
||||||
import org.jetbrains.exposed.sql.javatime.timestamp
|
|
||||||
|
|
||||||
abstract class TimedEventTable(name: String) : Table(name) {
|
|
||||||
val time = timestamp("time")
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.table
|
|
||||||
|
|
||||||
abstract class TimedLocalEventTable(name: String) : TimedEventTable(name) {
|
|
||||||
val world = uuid("world")
|
|
||||||
val x = double("x")
|
|
||||||
val y = double("y")
|
|
||||||
val z = double("z")
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package gay.pizza.foundation.heimdall.table
|
|
||||||
|
|
||||||
object WorldChangeTable : TimedEventTable("world_changes") {
|
|
||||||
val player = uuid("player")
|
|
||||||
val fromWorld = uuid("from_world")
|
|
||||||
val toWorld = uuid("to_world")
|
|
||||||
val fromWorldName = text("from_world_name")
|
|
||||||
val toWorldName = text("to_world_name")
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("gay.pizza.foundation.concrete-library")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
api(project(":common-all"))
|
|
||||||
compileOnly(project(":foundation-shared"))
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package gay.pizza.foundation.common
|
|
||||||
|
|
||||||
import gay.pizza.foundation.shared.IFoundationCore
|
|
||||||
import gay.pizza.foundation.shared.loadConfigurationWithDefault
|
|
||||||
import kotlinx.serialization.DeserializationStrategy
|
|
||||||
import org.bukkit.command.CommandExecutor
|
|
||||||
import org.bukkit.command.TabCompleter
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
|
||||||
|
|
||||||
abstract class BaseFoundationPlugin : JavaPlugin() {
|
|
||||||
fun registerCommandExecutor(name: String, executor: CommandExecutor) {
|
|
||||||
registerCommandExecutor(listOf(name), executor)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun registerCommandExecutor(names: List<String>, executor: CommandExecutor) {
|
|
||||||
for (name in names) {
|
|
||||||
val command = getCommand(name) ?: throw Exception("Failed to get $name command")
|
|
||||||
command.setExecutor(executor)
|
|
||||||
if (executor is TabCompleter) {
|
|
||||||
command.tabCompleter = executor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <reified T> loadConfigurationWithDefault(
|
|
||||||
core: IFoundationCore,
|
|
||||||
deserializer: DeserializationStrategy<T>,
|
|
||||||
name: String
|
|
||||||
): T {
|
|
||||||
return loadConfigurationWithDefault(
|
|
||||||
slF4JLogger, deserializer,
|
|
||||||
core.pluginDataPath, name)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package gay.pizza.foundation.common
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
|
|
||||||
fun Player.chat(vararg messages: String): Unit = messages.forEach { message ->
|
|
||||||
chat(message)
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package gay.pizza.foundation.common
|
|
||||||
|
|
||||||
import gay.pizza.foundation.shared.IFoundationCore
|
|
||||||
import org.bukkit.Server
|
|
||||||
|
|
||||||
object FoundationCoreLoader {
|
|
||||||
fun get(server: Server): IFoundationCore {
|
|
||||||
return server.pluginManager.getPlugin("Foundation") as IFoundationCore?
|
|
||||||
?: throw RuntimeException("Foundation Core is not loaded!")
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package gay.pizza.foundation.common
|
|
||||||
|
|
||||||
import org.bukkit.Location
|
|
||||||
import org.bukkit.World
|
|
||||||
import org.bukkit.entity.Entity
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
fun <T: Entity> World.spawn(location: Location, clazz: KClass<T>): T = spawn(location, clazz.java)
|
|
||||||
|
|
||||||
fun <T: Entity> Player.spawn(clazz: KClass<T>): T = spawn(clazz.java)
|
|
||||||
fun <T: Entity> Player.spawn(clazz: Class<T>): T = world.spawn(location, clazz)
|
|
@ -1,16 +1,8 @@
|
|||||||
plugins {
|
|
||||||
id("gay.pizza.foundation.concrete-plugin")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.discord.jda) {
|
implementation("net.dv8tion:JDA:5.0.0-alpha.2") {
|
||||||
exclude(module = "opus-java")
|
exclude(module = "opus-java")
|
||||||
}
|
}
|
||||||
|
implementation("com.rabbitmq:amqp-client:5.14.2")
|
||||||
|
|
||||||
implementation(project(":common-plugin"))
|
compileOnly(project(":foundation-core"))
|
||||||
compileOnly(project(":foundation-shared"))
|
|
||||||
}
|
|
||||||
|
|
||||||
concreteItem {
|
|
||||||
dependency(project(":foundation-core"))
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package cloud.kubelet.foundation.bifrost
|
||||||
|
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent
|
||||||
|
|
||||||
|
interface EventHandler {
|
||||||
|
fun onPlayerJoin(e: PlayerJoinEvent)
|
||||||
|
fun onPlayerQuit(e: PlayerQuitEvent)
|
||||||
|
fun onChat(e: AsyncChatEvent)
|
||||||
|
}
|
@ -1,20 +1,20 @@
|
|||||||
package gay.pizza.foundation.bifrost
|
package cloud.kubelet.foundation.bifrost
|
||||||
|
|
||||||
import gay.pizza.foundation.bifrost.model.BifrostConfig
|
import cloud.kubelet.foundation.bifrost.model.BifrostConfig
|
||||||
import gay.pizza.foundation.common.BaseFoundationPlugin
|
import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||||
import gay.pizza.foundation.common.FoundationCoreLoader
|
import cloud.kubelet.foundation.core.Util
|
||||||
import gay.pizza.foundation.shared.AdvancementTitleCache
|
import cloud.kubelet.foundation.core.util.AdvancementTitleCache
|
||||||
import gay.pizza.foundation.shared.PluginMainClass
|
import com.charleskorn.kaml.Yaml
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent
|
import io.papermc.paper.event.player.AsyncChatEvent
|
||||||
import net.dv8tion.jda.api.EmbedBuilder
|
import net.dv8tion.jda.api.EmbedBuilder
|
||||||
import net.dv8tion.jda.api.JDA
|
import net.dv8tion.jda.api.JDA
|
||||||
import net.dv8tion.jda.api.JDABuilder
|
import net.dv8tion.jda.api.JDABuilder
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel
|
import net.dv8tion.jda.api.MessageBuilder
|
||||||
|
import net.dv8tion.jda.api.entities.Message
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel
|
||||||
import net.dv8tion.jda.api.events.GenericEvent
|
import net.dv8tion.jda.api.events.GenericEvent
|
||||||
|
import net.dv8tion.jda.api.events.ReadyEvent
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
|
||||||
import net.dv8tion.jda.api.events.session.ReadyEvent
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder
|
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateData
|
|
||||||
import net.kyori.adventure.text.Component
|
import net.kyori.adventure.text.Component
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
@ -23,24 +23,30 @@ import org.bukkit.event.entity.PlayerDeathEvent
|
|||||||
import org.bukkit.event.player.PlayerAdvancementDoneEvent
|
import org.bukkit.event.player.PlayerAdvancementDoneEvent
|
||||||
import org.bukkit.event.player.PlayerJoinEvent
|
import org.bukkit.event.player.PlayerJoinEvent
|
||||||
import org.bukkit.event.player.PlayerQuitEvent
|
import org.bukkit.event.player.PlayerQuitEvent
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
|
import kotlin.io.path.inputStream
|
||||||
import net.dv8tion.jda.api.hooks.EventListener as DiscordEventListener
|
import net.dv8tion.jda.api.hooks.EventListener as DiscordEventListener
|
||||||
import org.bukkit.event.Listener as BukkitEventListener
|
import org.bukkit.event.Listener as BukkitEventListener
|
||||||
|
|
||||||
@PluginMainClass
|
class FoundationBifrostPlugin : JavaPlugin(), DiscordEventListener, BukkitEventListener {
|
||||||
class FoundationBifrostPlugin : BaseFoundationPlugin(), DiscordEventListener, BukkitEventListener {
|
|
||||||
private lateinit var config: BifrostConfig
|
private lateinit var config: BifrostConfig
|
||||||
private var jda: JDA? = null
|
private var jda: JDA? = null
|
||||||
private var isDev = false
|
private var isDev = false
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
isDev = description.version == "DEV"
|
isDev = description.version == "DEV"
|
||||||
val foundation = FoundationCoreLoader.get(server)
|
|
||||||
config = loadConfigurationWithDefault(
|
val foundation = server.pluginManager.getPlugin("Foundation") as FoundationCorePlugin
|
||||||
foundation,
|
slF4JLogger.info("Plugin data path: ${foundation.pluginDataPath}")
|
||||||
BifrostConfig.serializer(),
|
|
||||||
|
val configPath = Util.copyDefaultConfig<FoundationBifrostPlugin>(
|
||||||
|
slF4JLogger,
|
||||||
|
foundation.pluginDataPath,
|
||||||
"bifrost.yaml"
|
"bifrost.yaml"
|
||||||
)
|
)
|
||||||
|
config = Yaml.default.decodeFromStream(BifrostConfig.serializer(), configPath.inputStream())
|
||||||
|
|
||||||
server.pluginManager.registerEvents(this, this)
|
server.pluginManager.registerEvents(this, this)
|
||||||
if (config.authentication.token.isEmpty()) {
|
if (config.authentication.token.isEmpty()) {
|
||||||
slF4JLogger.warn("Token empty, Bifrost will not connect to Discord.")
|
slF4JLogger.warn("Token empty, Bifrost will not connect to Discord.")
|
||||||
@ -99,12 +105,12 @@ class FoundationBifrostPlugin : BaseFoundationPlugin(), DiscordEventListener, Bu
|
|||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun message(f: MessageCreateBuilder.() -> Unit) = MessageCreateBuilder().apply(f).build()
|
private fun message(f: MessageBuilder.() -> Unit) = MessageBuilder().apply(f).build()
|
||||||
private fun MessageCreateBuilder.embed(f: EmbedBuilder.() -> Unit) {
|
private fun MessageBuilder.embed(f: EmbedBuilder.() -> Unit) {
|
||||||
setEmbeds(EmbedBuilder().apply(f).build())
|
setEmbeds(EmbedBuilder().apply(f).build())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendChannelMessage(message: MessageCreateData, debug: () -> String) {
|
private fun sendChannelMessage(message: Message, debug: () -> String) {
|
||||||
val channel = getTextChannel()
|
val channel = getTextChannel()
|
||||||
channel?.sendMessage(message)?.queue()
|
channel?.sendMessage(message)?.queue()
|
||||||
|
|
||||||
@ -152,7 +158,7 @@ class FoundationBifrostPlugin : BaseFoundationPlugin(), DiscordEventListener, Bu
|
|||||||
if (!config.channel.sendPlayerDeath) return
|
if (!config.channel.sendPlayerDeath) return
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
var deathMessage = e.deathMessage
|
var deathMessage = e.deathMessage
|
||||||
if (deathMessage.isNullOrBlank()) {
|
if (deathMessage == null || deathMessage.isBlank()) {
|
||||||
deathMessage = "${e.player.name} died"
|
deathMessage = "${e.player.name} died"
|
||||||
}
|
}
|
||||||
sendEmbedMessage(Color.YELLOW, deathMessage)
|
sendEmbedMessage(Color.YELLOW, deathMessage)
|
@ -0,0 +1,26 @@
|
|||||||
|
package cloud.kubelet.foundation.bifrost
|
||||||
|
|
||||||
|
import cloud.kubelet.foundation.bifrost.model.BifrostMessageQueueConfig
|
||||||
|
import cloud.kubelet.foundation.bifrost.model.BifrostMultiConfig
|
||||||
|
import com.rabbitmq.client.Connection
|
||||||
|
import com.rabbitmq.client.ConnectionFactory
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent
|
||||||
|
|
||||||
|
class MultiServerEventHandler(config: BifrostMultiConfig) : EventHandler {
|
||||||
|
private val bus = buildConnection(config.messageQueue)
|
||||||
|
private val channel = bus.createChannel()
|
||||||
|
|
||||||
|
init {
|
||||||
|
channel.queueDeclare(config.messageQueue.queueName, false, false, false, emptyMap())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onChat(e: AsyncChatEvent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
fun buildConnection(config: BifrostMessageQueueConfig): Connection = ConnectionFactory().apply {
|
||||||
|
host = config.host
|
||||||
|
port = config.port
|
||||||
|
}.newConnection()
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.bifrost.model
|
package cloud.kubelet.foundation.bifrost.model
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
package cloud.kubelet.foundation.bifrost.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class BifrostMultiConfig(
|
||||||
|
val messageQueue: BifrostMessageQueueConfig,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class BifrostMessageQueueConfig(
|
||||||
|
val host: String = "localhost",
|
||||||
|
val port: Int = 5672,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the RabbitMQ queue
|
||||||
|
*/
|
||||||
|
val queueName: String = "bifrost",
|
||||||
|
)
|
5
foundation-bifrost/src/main/resources/bifrost-multi.yaml
Normal file
5
foundation-bifrost/src/main/resources/bifrost-multi.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Configuration for the Bifrost multi-server chat bridge.
|
||||||
|
|
||||||
|
messageQueue:
|
||||||
|
host: localhost
|
||||||
|
|
@ -1,11 +1,10 @@
|
|||||||
name: Foundation-Bifrost
|
name: Foundation-Bifrost
|
||||||
version: '${version}'
|
version: '${version}'
|
||||||
main: gay.pizza.foundation.bifrost.FoundationBifrostPlugin
|
main: cloud.kubelet.foundation.bifrost.FoundationBifrostPlugin
|
||||||
api-version: 1.18
|
api-version: 1.18
|
||||||
prefix: Foundation-Bifrost
|
prefix: Foundation-Bifrost
|
||||||
load: STARTUP
|
load: STARTUP
|
||||||
depend:
|
depend:
|
||||||
- Foundation
|
- Foundation
|
||||||
authors:
|
authors:
|
||||||
- kubeliv
|
- kubelet
|
||||||
- azenla
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("gay.pizza.foundation.concrete-plugin")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(project(":common-all"))
|
|
||||||
implementation(project(":common-plugin"))
|
|
||||||
compileOnly(project(":foundation-shared"))
|
|
||||||
}
|
|
||||||
|
|
||||||
concreteItem {
|
|
||||||
dependency(project(":foundation-core"))
|
|
||||||
}
|
|
@ -1,94 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos
|
|
||||||
|
|
||||||
import gay.pizza.foundation.chaos.model.ChaosConfig
|
|
||||||
import gay.pizza.foundation.chaos.modules.ChaosModule
|
|
||||||
import gay.pizza.foundation.chaos.modules.ChaosModules
|
|
||||||
import org.bukkit.boss.BarColor
|
|
||||||
import org.bukkit.boss.BarStyle
|
|
||||||
import org.bukkit.boss.BossBar
|
|
||||||
import org.bukkit.event.EventHandler
|
|
||||||
import org.bukkit.event.HandlerList
|
|
||||||
import org.bukkit.event.Listener
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
|
||||||
|
|
||||||
class ChaosController(val plugin: Plugin, val config: ChaosConfig) : Listener {
|
|
||||||
val state: AtomicBoolean = AtomicBoolean(false)
|
|
||||||
val selectorController = ChaosSelectorController(this, plugin)
|
|
||||||
|
|
||||||
val allModules = ChaosModules.all(plugin)
|
|
||||||
var allowedModules: List<ChaosModule> = emptyList()
|
|
||||||
|
|
||||||
private var activeModules = mutableSetOf<ChaosModule>()
|
|
||||||
|
|
||||||
var bossBar: BossBar? = null
|
|
||||||
|
|
||||||
fun load() {
|
|
||||||
if (state.get()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
allowedModules = filterEnabledModules()
|
|
||||||
state.set(true)
|
|
||||||
selectorController.schedule()
|
|
||||||
bossBar = plugin.server.createBossBar("Chaos Mode", BarColor.RED, BarStyle.SOLID)
|
|
||||||
for (player in plugin.server.onlinePlayers) {
|
|
||||||
bossBar?.addPlayer(player)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun filterEnabledModules(): List<ChaosModule> = allModules.filter { module ->
|
|
||||||
val moduleConfig = config.modules[module.id()] ?: config.defaultModuleConfiguration
|
|
||||||
moduleConfig.enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
fun activateAll() {
|
|
||||||
for (module in allowedModules) {
|
|
||||||
if (activeModules.contains(module)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
activate(module)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun activate(module: ChaosModule) {
|
|
||||||
plugin.server.pluginManager.registerEvents(module, plugin)
|
|
||||||
module.activate()
|
|
||||||
activeModules.add(module)
|
|
||||||
updateBossBar()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deactivate(module: ChaosModule) {
|
|
||||||
HandlerList.unregisterAll(module)
|
|
||||||
module.deactivate()
|
|
||||||
activeModules.remove(module)
|
|
||||||
updateBossBar()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateBossBar() {
|
|
||||||
val activeModuleText = activeModules.joinToString(", ") { it.name() }
|
|
||||||
bossBar?.setTitle("Chaos Mode: $activeModuleText")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deactivateAll() {
|
|
||||||
for (module in activeModules.toList()) {
|
|
||||||
deactivate(module)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
fun onPlayerJoin(event: PlayerJoinEvent) {
|
|
||||||
bossBar?.addPlayer(event.player)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun unload() {
|
|
||||||
if (!state.get()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
deactivateAll()
|
|
||||||
bossBar?.removeAll()
|
|
||||||
bossBar = null
|
|
||||||
state.set(false)
|
|
||||||
selectorController.cancel()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos
|
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
import org.bukkit.scheduler.BukkitTask
|
|
||||||
|
|
||||||
class ChaosSelectorController(val controller: ChaosController, val plugin: Plugin) {
|
|
||||||
var task: BukkitTask? = null
|
|
||||||
|
|
||||||
fun schedule() {
|
|
||||||
cancel()
|
|
||||||
task = plugin.server.scheduler.runTaskTimer(controller.plugin, { ->
|
|
||||||
select()
|
|
||||||
}, 20, controller.config.selection.timerTicks)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun select() {
|
|
||||||
controller.deactivateAll()
|
|
||||||
val module = controller.allowedModules.randomOrNull()
|
|
||||||
if (module != null) {
|
|
||||||
controller.activate(module)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun cancel() {
|
|
||||||
task?.cancel()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos
|
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component
|
|
||||||
import org.bukkit.command.Command
|
|
||||||
import org.bukkit.command.CommandExecutor
|
|
||||||
import org.bukkit.command.CommandSender
|
|
||||||
|
|
||||||
class ChaosToggleCommand : CommandExecutor {
|
|
||||||
override fun onCommand(
|
|
||||||
sender: CommandSender,
|
|
||||||
command: Command,
|
|
||||||
label: String,
|
|
||||||
args: Array<out String>
|
|
||||||
): Boolean {
|
|
||||||
val plugin = sender.server.pluginManager.getPlugin("Foundation-Chaos") as FoundationChaosPlugin
|
|
||||||
if (!plugin.config.allowed) {
|
|
||||||
sender.sendMessage("Chaos is not allowed.")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
val controller = plugin.controller
|
|
||||||
if (controller.state.get()) {
|
|
||||||
controller.unload()
|
|
||||||
sender.server.broadcast(Component.text("Chaos Mode Disabled"))
|
|
||||||
} else {
|
|
||||||
controller.load()
|
|
||||||
sender.server.broadcast(Component.text("Chaos Mode Enabled"))
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos
|
|
||||||
|
|
||||||
import org.bukkit.Location
|
|
||||||
import org.bukkit.Server
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
|
|
||||||
fun Location.nearestPlayer(): Player? =
|
|
||||||
world?.players?.minByOrNull { it.location.distance(this) }
|
|
||||||
|
|
||||||
fun Server.randomPlayer(): Player? =
|
|
||||||
onlinePlayers.randomOrNull()
|
|
@ -1,25 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos
|
|
||||||
|
|
||||||
import gay.pizza.foundation.chaos.model.ChaosConfig
|
|
||||||
import gay.pizza.foundation.common.BaseFoundationPlugin
|
|
||||||
import gay.pizza.foundation.common.FoundationCoreLoader
|
|
||||||
import gay.pizza.foundation.shared.PluginMainClass
|
|
||||||
|
|
||||||
@PluginMainClass
|
|
||||||
class FoundationChaosPlugin : BaseFoundationPlugin() {
|
|
||||||
lateinit var config: ChaosConfig
|
|
||||||
|
|
||||||
val controller by lazy {
|
|
||||||
ChaosController(this, config)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onEnable() {
|
|
||||||
val foundation = FoundationCoreLoader.get(server)
|
|
||||||
config = loadConfigurationWithDefault(
|
|
||||||
foundation,
|
|
||||||
ChaosConfig.serializer(),
|
|
||||||
"chaos.yaml"
|
|
||||||
)
|
|
||||||
registerCommandExecutor("chaos", ChaosToggleCommand())
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
class ChaosConfig(
|
|
||||||
val allowed: Boolean = true,
|
|
||||||
val defaultModuleConfiguration: ChaosModuleConfig,
|
|
||||||
val modules: Map<String, ChaosModuleConfig> = emptyMap(),
|
|
||||||
val selection: ChaosSelectionConfig
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
class ChaosModuleConfig(
|
|
||||||
val enabled: Boolean
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
class ChaosSelectionConfig(
|
|
||||||
val timerTicks: Long
|
|
||||||
)
|
|
@ -1,71 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import org.bukkit.Chunk
|
|
||||||
import org.bukkit.ChunkSnapshot
|
|
||||||
import org.bukkit.World
|
|
||||||
import org.bukkit.block.Block
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler
|
|
||||||
|
|
||||||
val World.heightRange
|
|
||||||
get() = minHeight until maxHeight
|
|
||||||
|
|
||||||
inline fun forEachChunkPosition(crossinline each: (Int, Int) -> Unit) {
|
|
||||||
for (x in 0..15) {
|
|
||||||
for (z in 0..15) {
|
|
||||||
each(x, z)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun Chunk.forEachPosition(crossinline each: (Int, Int, Int) -> Unit) {
|
|
||||||
for (x in 0..15) {
|
|
||||||
for (z in 0..15) {
|
|
||||||
for (y in world.heightRange) {
|
|
||||||
each(x, y, z)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun Chunk.forEachBlock(crossinline each: (Int, Int, Int, Block) -> Unit) {
|
|
||||||
forEachPosition { x, y, z ->
|
|
||||||
each(x, y, z, getBlock(x, y, z))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Chunk.applyChunkSnapshot(snapshot: ChunkSnapshot) {
|
|
||||||
forEachPosition { x, y, z ->
|
|
||||||
val blockData = snapshot.getBlockData(x, y, z)
|
|
||||||
val block = getBlock(x, y, z)
|
|
||||||
block.blockData = blockData
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Player.teleportHighestLocation() {
|
|
||||||
teleport(location.toHighestLocation().add(0.0, 1.0, 0.0))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> BukkitScheduler.scheduleUntilEmpty(
|
|
||||||
plugin: Plugin,
|
|
||||||
items: MutableList<T>,
|
|
||||||
ticksBetween: Long,
|
|
||||||
callback: (T) -> Unit
|
|
||||||
) {
|
|
||||||
fun performOne() {
|
|
||||||
if (items.isEmpty()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val item = items.removeAt(0)
|
|
||||||
callback(item)
|
|
||||||
|
|
||||||
if (items.isNotEmpty()) {
|
|
||||||
runTaskLater(plugin, { ->
|
|
||||||
performOne()
|
|
||||||
}, ticksBetween)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
performOne()
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import org.bukkit.event.Listener
|
|
||||||
|
|
||||||
interface ChaosModule : Listener {
|
|
||||||
fun id(): String
|
|
||||||
fun name(): String
|
|
||||||
fun what(): String
|
|
||||||
fun activate() {}
|
|
||||||
fun deactivate() {}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
|
|
||||||
object ChaosModules {
|
|
||||||
fun all(plugin: Plugin) = listOf(
|
|
||||||
NearestPlayerEntitySpawn(plugin),
|
|
||||||
TeleportAllEntitiesNearestPlayer(plugin),
|
|
||||||
KillRandomPlayer(plugin),
|
|
||||||
TntAllPlayers(plugin),
|
|
||||||
MegaTnt(plugin),
|
|
||||||
PlayerSwap(plugin),
|
|
||||||
WorldSwapper(plugin),
|
|
||||||
ChunkEnterRotate()
|
|
||||||
).shuffled()
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import org.bukkit.Chunk
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
import org.bukkit.event.EventHandler
|
|
||||||
import org.bukkit.event.player.PlayerMoveEvent
|
|
||||||
import java.util.WeakHashMap
|
|
||||||
|
|
||||||
class ChunkEnterRotate : ChaosModule {
|
|
||||||
override fun id(): String = "chunk-enter-rotate"
|
|
||||||
override fun name(): String = "Chunk Enter Rotate"
|
|
||||||
override fun what(): String = "Rotates the chunk when the player enters a chunk."
|
|
||||||
|
|
||||||
private val playerChunkMap = WeakHashMap<Player, Chunk>()
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
fun onPotentialChunkMove(event: PlayerMoveEvent) {
|
|
||||||
val player = event.player
|
|
||||||
val currentChunk = event.player.chunk
|
|
||||||
val previousChunk = playerChunkMap.put(player, currentChunk)
|
|
||||||
if (previousChunk == null || previousChunk == currentChunk) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rotateChunk(currentChunk)
|
|
||||||
if (!player.isFlying) {
|
|
||||||
player.teleportHighestLocation()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun rotateChunk(chunk: Chunk) {
|
|
||||||
val snapshot = chunk.chunkSnapshot
|
|
||||||
chunk.forEachBlock { x, y, z, rotatedBlock ->
|
|
||||||
val originalBlockData = snapshot.getBlockData(z, y, x)
|
|
||||||
rotatedBlock.blockData = originalBlockData
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
|
|
||||||
class KillRandomPlayer(val plugin: Plugin) : ChaosModule {
|
|
||||||
override fun id(): String = "kill-random-player"
|
|
||||||
override fun name(): String = "Random Kill"
|
|
||||||
override fun what(): String = "Kill a random player."
|
|
||||||
|
|
||||||
override fun activate() {
|
|
||||||
val player = plugin.server.onlinePlayers.randomOrNull() ?: return
|
|
||||||
player.damage(1000000.0)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import gay.pizza.foundation.common.spawn
|
|
||||||
import org.bukkit.entity.TNTPrimed
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
|
|
||||||
class MegaTnt(val plugin: Plugin) : ChaosModule {
|
|
||||||
override fun id(): String = "mega-tnt"
|
|
||||||
override fun name(): String = "Mega TNT"
|
|
||||||
override fun what(): String = "Spawn a massive TNT explosion"
|
|
||||||
|
|
||||||
override fun activate() {
|
|
||||||
for (player in plugin.server.onlinePlayers) {
|
|
||||||
val tnt = player.spawn(TNTPrimed::class)
|
|
||||||
tnt.fuseTicks = 1
|
|
||||||
tnt.yield = 10.0f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import gay.pizza.foundation.chaos.nearestPlayer
|
|
||||||
import org.bukkit.event.EventHandler
|
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
|
|
||||||
class NearestPlayerEntitySpawn(val plugin: Plugin) : ChaosModule {
|
|
||||||
override fun id(): String = "nearest-player-entity-spawn"
|
|
||||||
override fun name(): String = "Monster Me"
|
|
||||||
override fun what(): String = "Teleport all spawned entities to the nearest player"
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
fun onMobSpawn(e: EntitySpawnEvent) {
|
|
||||||
val player = e.location.nearestPlayer()
|
|
||||||
if (player != null) {
|
|
||||||
e.entity.server.scheduler.runTask(plugin) { ->
|
|
||||||
e.entity.teleport(player)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import org.bukkit.Location
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
|
|
||||||
class PlayerSwap(val plugin: Plugin) : ChaosModule {
|
|
||||||
override fun id(): String = "player-swap"
|
|
||||||
override fun name(): String = "Player Swap"
|
|
||||||
override fun what(): String = "Randomly swaps player positions."
|
|
||||||
|
|
||||||
override fun activate() {
|
|
||||||
for (world in plugin.server.worlds) {
|
|
||||||
if (world.playerCount <= 0) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
val players = world.players
|
|
||||||
val map = mutableMapOf<Player, Location>()
|
|
||||||
for (player in players) {
|
|
||||||
val next = players.filter { it != player }.randomOrNull() ?: continue
|
|
||||||
map[player] = next.location.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
for ((player, next) in map) {
|
|
||||||
player.teleport(next)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import gay.pizza.foundation.chaos.nearestPlayer
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
|
|
||||||
class TeleportAllEntitiesNearestPlayer(val plugin: Plugin) : ChaosModule {
|
|
||||||
override fun id(): String = "teleport-all-entities-nearest-player"
|
|
||||||
override fun name(): String = "Monster Me Once"
|
|
||||||
override fun what(): String = "Teleport all entities to the nearest player"
|
|
||||||
|
|
||||||
override fun activate() {
|
|
||||||
for (world in plugin.server.worlds) {
|
|
||||||
for (entity in world.entities) {
|
|
||||||
val player = entity.location.nearestPlayer()
|
|
||||||
if (player != null) {
|
|
||||||
entity.teleport(player)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import gay.pizza.foundation.common.spawn
|
|
||||||
import org.bukkit.entity.TNTPrimed
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
|
|
||||||
class TntAllPlayers(val plugin: Plugin) : ChaosModule {
|
|
||||||
override fun id(): String = "tnt-all-players"
|
|
||||||
override fun name(): String = "TNT Us All"
|
|
||||||
override fun what(): String = "TNT All Players"
|
|
||||||
|
|
||||||
override fun activate() {
|
|
||||||
for (player in plugin.server.onlinePlayers) {
|
|
||||||
player.spawn(TNTPrimed::class)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
package gay.pizza.foundation.chaos.modules
|
|
||||||
|
|
||||||
import gay.pizza.foundation.chaos.randomPlayer
|
|
||||||
import gay.pizza.foundation.common.without
|
|
||||||
import org.bukkit.Chunk
|
|
||||||
import org.bukkit.ChunkSnapshot
|
|
||||||
import org.bukkit.block.Block
|
|
||||||
import org.bukkit.block.data.BlockData
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
|
|
||||||
class WorldSwapper(val plugin: Plugin) : ChaosModule {
|
|
||||||
override fun id(): String = "world-swapper"
|
|
||||||
override fun name(): String = "World Swapper"
|
|
||||||
override fun what(): String = "Swaps the world vertically on activation, and un-swaps it on deactivation."
|
|
||||||
|
|
||||||
var chunkInversions = mutableListOf<ChunkInversion>()
|
|
||||||
|
|
||||||
override fun activate() {
|
|
||||||
val player = plugin.server.randomPlayer() ?: return
|
|
||||||
val baseChunk = player.chunk
|
|
||||||
recordInvert(baseChunk)
|
|
||||||
player.teleport(player.location.toHighestLocation())
|
|
||||||
val chunksToInvert = player.world.loadedChunks.without(baseChunk).toMutableList()
|
|
||||||
|
|
||||||
println("Inverting ${chunksToInvert.size} chunks...")
|
|
||||||
plugin.server.scheduler.scheduleUntilEmpty(plugin, chunksToInvert, 5) { chunk ->
|
|
||||||
recordInvert(chunk)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun recordInvert(chunk: Chunk) {
|
|
||||||
chunkInversions.add(invertChunk(chunk))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun deactivate() {
|
|
||||||
fun scheduleOne() {
|
|
||||||
if (chunkInversions.isEmpty()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val inversion = chunkInversions.removeAt(0)
|
|
||||||
plugin.server.scheduler.runTaskLater(plugin, { ->
|
|
||||||
inversion.revert()
|
|
||||||
scheduleOne()
|
|
||||||
}, 5)
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduleOne()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun invertChunk(chunk: Chunk): ChunkInversion {
|
|
||||||
val snapshot = chunk.chunkSnapshot
|
|
||||||
forEachChunkPosition { x, z ->
|
|
||||||
var sy = chunk.world.minHeight
|
|
||||||
var ey = chunk.world.maxHeight
|
|
||||||
while (sy != ey) {
|
|
||||||
sy++
|
|
||||||
ey--
|
|
||||||
val targetBlock = chunk.getBlock(x, sy, z)
|
|
||||||
val targetBlockData = targetBlock.blockData.clone()
|
|
||||||
val nextBlock = chunk.getBlock(x, ey, z)
|
|
||||||
val nextBlockData = nextBlock.blockData.clone()
|
|
||||||
invertSetBlockData(targetBlock, nextBlockData)
|
|
||||||
invertSetBlockData(nextBlock, targetBlockData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ChunkInversion(plugin, snapshot)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun invertSetBlockData(block: Block, data: BlockData) {
|
|
||||||
block.setBlockData(data, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
class ChunkInversion(val plugin: Plugin, val snapshot: ChunkSnapshot) {
|
|
||||||
fun revert() {
|
|
||||||
val world = plugin.server.getWorld(snapshot.worldName) ?: return
|
|
||||||
val chunk = world.getChunkAt(snapshot.x, snapshot.z)
|
|
||||||
chunk.applyChunkSnapshot(snapshot)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
# Whether enabling the chaos mode is allowed.
|
|
||||||
allowed: false
|
|
||||||
# The default module configuration for modules with
|
|
||||||
# no explicit configuration.
|
|
||||||
defaultModuleConfiguration:
|
|
||||||
enabled: true
|
|
||||||
# Module configuration.
|
|
||||||
modules:
|
|
||||||
nearest-player-entity-spawn:
|
|
||||||
enabled: true
|
|
||||||
teleport-all-entities-nearest-player:
|
|
||||||
enabled: true
|
|
||||||
# Chaos selection configuration.
|
|
||||||
selection:
|
|
||||||
# The number of ticks before a new selection is made.
|
|
||||||
timerTicks: 6000
|
|
@ -1,16 +0,0 @@
|
|||||||
name: Foundation-Chaos
|
|
||||||
version: '${version}'
|
|
||||||
main: gay.pizza.foundation.chaos.FoundationChaosPlugin
|
|
||||||
api-version: 1.18
|
|
||||||
prefix: Foundation-Chaos
|
|
||||||
load: STARTUP
|
|
||||||
depend:
|
|
||||||
- Foundation
|
|
||||||
authors:
|
|
||||||
- kubeliv
|
|
||||||
- azenla
|
|
||||||
commands:
|
|
||||||
chaos:
|
|
||||||
description: Chaos Toggle
|
|
||||||
usage: /chaos
|
|
||||||
permission: foundation.command.chaos
|
|
@ -1,16 +1,7 @@
|
|||||||
plugins {
|
|
||||||
id("gay.pizza.foundation.concrete-plugin")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api(project(":common-all"))
|
// TODO: might be able to ship all dependencies in core? are we duplicating classes in JARs?
|
||||||
api(project(":common-plugin"))
|
|
||||||
implementation(project(":foundation-shared"))
|
|
||||||
|
|
||||||
implementation(libs.aws.sdk.s3)
|
implementation("software.amazon.awssdk:s3:2.17.102")
|
||||||
implementation(libs.quartz.core)
|
implementation("org.quartz-scheduler:quartz:2.3.2")
|
||||||
implementation(libs.guava)
|
implementation("com.google.guava:guava:31.0.1-jre")
|
||||||
|
|
||||||
implementation(libs.koin.core)
|
|
||||||
testImplementation(libs.koin.test)
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.common
|
package cloud.kubelet.foundation.core
|
||||||
|
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.OfflinePlayer
|
import org.bukkit.OfflinePlayer
|
||||||
@ -9,7 +9,7 @@ import org.bukkit.entity.EntityType
|
|||||||
val Server.allPlayers: List<OfflinePlayer>
|
val Server.allPlayers: List<OfflinePlayer>
|
||||||
get() = listOf(onlinePlayers, offlinePlayers.filter { !isPlayerOnline(it) }.toList()).flatten()
|
get() = listOf(onlinePlayers, offlinePlayers.filter { !isPlayerOnline(it) }.toList()).flatten()
|
||||||
|
|
||||||
fun Server.isPlayerOnline(player: OfflinePlayer): Boolean =
|
fun Server.isPlayerOnline(player: OfflinePlayer) =
|
||||||
onlinePlayers.any { onlinePlayer -> onlinePlayer.name == player.name }
|
onlinePlayers.any { onlinePlayer -> onlinePlayer.name == player.name }
|
||||||
|
|
||||||
fun Server.allPlayerStatisticsOf(
|
fun Server.allPlayerStatisticsOf(
|
||||||
@ -17,7 +17,7 @@ fun Server.allPlayerStatisticsOf(
|
|||||||
material: Material? = null,
|
material: Material? = null,
|
||||||
entityType: EntityType? = null,
|
entityType: EntityType? = null,
|
||||||
order: SortOrder = SortOrder.Ascending
|
order: SortOrder = SortOrder.Ascending
|
||||||
): List<Pair<OfflinePlayer, Int>> = allPlayers.map { player ->
|
) = allPlayers.map { player ->
|
||||||
player to if (material != null) {
|
player to if (material != null) {
|
||||||
player.getStatistic(statistic, material)
|
player.getStatistic(statistic, material)
|
||||||
} else if (entityType != null) {
|
} else if (entityType != null) {
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.common
|
package cloud.kubelet.foundation.core
|
||||||
|
|
||||||
fun <T, R : Comparable<R>> Collection<T>.sortedBy(order: SortOrder, selector: (T) -> R?): List<T> =
|
fun <T, R : Comparable<R>> Collection<T>.sortedBy(order: SortOrder, selector: (T) -> R?): List<T> =
|
||||||
if (order == SortOrder.Ascending) {
|
if (order == SortOrder.Ascending) {
|
@ -0,0 +1,57 @@
|
|||||||
|
package cloud.kubelet.foundation.core
|
||||||
|
|
||||||
|
import cloud.kubelet.foundation.core.abstraction.FoundationPlugin
|
||||||
|
import cloud.kubelet.foundation.core.features.backup.BackupFeature
|
||||||
|
import cloud.kubelet.foundation.core.features.dev.DevFeature
|
||||||
|
import cloud.kubelet.foundation.core.features.gameplay.GameplayFeature
|
||||||
|
import cloud.kubelet.foundation.core.features.persist.PersistenceFeature
|
||||||
|
import cloud.kubelet.foundation.core.features.player.PlayerFeature
|
||||||
|
import cloud.kubelet.foundation.core.features.scheduler.SchedulerFeature
|
||||||
|
import cloud.kubelet.foundation.core.features.stats.StatsFeature
|
||||||
|
import cloud.kubelet.foundation.core.features.update.UpdateFeature
|
||||||
|
import cloud.kubelet.foundation.core.features.world.WorldFeature
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
class FoundationCorePlugin : FoundationPlugin() {
|
||||||
|
private lateinit var _pluginDataPath: Path
|
||||||
|
|
||||||
|
var pluginDataPath: Path
|
||||||
|
/**
|
||||||
|
* Data path of the core plugin.
|
||||||
|
* Can be used as a sanity check of sorts for dependencies to be sure the plugin is loaded.
|
||||||
|
*/
|
||||||
|
get() {
|
||||||
|
if (!::_pluginDataPath.isInitialized) {
|
||||||
|
throw Exception("FoundationCore is not loaded!")
|
||||||
|
}
|
||||||
|
return _pluginDataPath
|
||||||
|
}
|
||||||
|
private set(value) {
|
||||||
|
_pluginDataPath = value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onEnable() {
|
||||||
|
// Create core plugin directory.
|
||||||
|
pluginDataPath = dataFolder.toPath()
|
||||||
|
pluginDataPath.toFile().mkdir()
|
||||||
|
|
||||||
|
super.onEnable()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createFeatures() = listOf(
|
||||||
|
SchedulerFeature(),
|
||||||
|
PersistenceFeature(),
|
||||||
|
BackupFeature(),
|
||||||
|
DevFeature(),
|
||||||
|
GameplayFeature(),
|
||||||
|
PlayerFeature(),
|
||||||
|
StatsFeature(),
|
||||||
|
UpdateFeature(),
|
||||||
|
WorldFeature(),
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun createModule() = module {
|
||||||
|
single { this@FoundationCorePlugin }
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.common
|
package cloud.kubelet.foundation.core
|
||||||
|
|
||||||
enum class SortOrder {
|
enum class SortOrder {
|
||||||
Ascending,
|
Ascending,
|
@ -0,0 +1,7 @@
|
|||||||
|
package cloud.kubelet.foundation.core
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.format.TextColor
|
||||||
|
|
||||||
|
object TextColors {
|
||||||
|
val AMARANTH_PINK = TextColor.fromHexString("#F7A8B8")!!
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package cloud.kubelet.foundation.core
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component
|
||||||
|
import net.kyori.adventure.text.format.TextColor
|
||||||
|
import org.slf4j.Logger
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
object Util {
|
||||||
|
private val leftBracket: Component = Component.text('[')
|
||||||
|
private val rightBracket: Component = Component.text(']')
|
||||||
|
private val whitespace: Component = Component.text(' ')
|
||||||
|
private val foundationName: Component = Component.text("Foundation")
|
||||||
|
|
||||||
|
fun formatSystemMessage(message: String): Component {
|
||||||
|
return formatSystemMessage(TextColors.AMARANTH_PINK, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun formatSystemMessage(prefixColor: TextColor, message: String): Component {
|
||||||
|
return leftBracket
|
||||||
|
.append(foundationName.color(prefixColor))
|
||||||
|
.append(rightBracket)
|
||||||
|
.append(whitespace)
|
||||||
|
.append(Component.text(message))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the default configuration from the resource [resourceName] into the directory [targetPath].
|
||||||
|
* @param targetPath The output directory as a path, it must exist before calling this.
|
||||||
|
* @param resourceName Path to resource, it should be in the root of the `resources` directory,
|
||||||
|
* without the leading slash.
|
||||||
|
*/
|
||||||
|
inline fun <reified T> copyDefaultConfig(log: Logger, targetPath: Path, resourceName: String): Path {
|
||||||
|
if (resourceName.startsWith("/")) {
|
||||||
|
throw IllegalArgumentException("resourceName starts with slash")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetPath.toFile().exists()) {
|
||||||
|
throw Exception("Configuration output path does not exist!")
|
||||||
|
}
|
||||||
|
val outPath = targetPath.resolve(resourceName)
|
||||||
|
val outFile = outPath.toFile()
|
||||||
|
if (outFile.exists()) {
|
||||||
|
log.debug("Configuration file already exists.")
|
||||||
|
return outPath
|
||||||
|
}
|
||||||
|
|
||||||
|
val resourceStream = T::class.java.getResourceAsStream("/$resourceName")
|
||||||
|
?: throw Exception("Configuration resource does not exist!")
|
||||||
|
val outputStream = outFile.outputStream()
|
||||||
|
|
||||||
|
resourceStream.use {
|
||||||
|
outputStream.use {
|
||||||
|
log.info("Copied default configuration to $outPath")
|
||||||
|
resourceStream.copyTo(outputStream)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return outPath
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isPlatformWindows(): Boolean {
|
||||||
|
val os = System.getProperty("os.name")
|
||||||
|
return os != null && os.lowercase().startsWith("windows")
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.core.abstraction
|
package cloud.kubelet.foundation.core.abstraction
|
||||||
|
|
||||||
interface CoreFeature {
|
interface CoreFeature {
|
||||||
fun enable()
|
fun enable()
|
@ -0,0 +1,33 @@
|
|||||||
|
package cloud.kubelet.foundation.core.abstraction
|
||||||
|
|
||||||
|
import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||||
|
import org.bukkit.command.CommandExecutor
|
||||||
|
import org.bukkit.command.TabCompleter
|
||||||
|
import org.bukkit.event.Listener
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import org.quartz.Scheduler
|
||||||
|
|
||||||
|
abstract class Feature : CoreFeature, KoinComponent, Listener {
|
||||||
|
protected val plugin by inject<FoundationCorePlugin>()
|
||||||
|
protected val scheduler by inject<Scheduler>()
|
||||||
|
|
||||||
|
override fun enable() {}
|
||||||
|
override fun disable() {}
|
||||||
|
override fun module() = module {}
|
||||||
|
|
||||||
|
protected fun registerCommandExecutor(name: String, executor: CommandExecutor) {
|
||||||
|
registerCommandExecutor(listOf(name), executor)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun registerCommandExecutor(names: List<String>, executor: CommandExecutor) {
|
||||||
|
for (name in names) {
|
||||||
|
val command = plugin.getCommand(name) ?: throw Exception("Failed to get $name command")
|
||||||
|
command.setExecutor(executor)
|
||||||
|
if (executor is TabCompleter) {
|
||||||
|
command.tabCompleter = executor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
package gay.pizza.foundation.core.abstraction
|
package cloud.kubelet.foundation.core.abstraction
|
||||||
|
|
||||||
import gay.pizza.foundation.common.BaseFoundationPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
import org.koin.core.KoinApplication
|
import org.koin.core.KoinApplication
|
||||||
import org.koin.core.context.startKoin
|
import org.koin.core.context.startKoin
|
||||||
import org.koin.core.context.stopKoin
|
import org.koin.core.context.stopKoin
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
abstract class FoundationPlugin : BaseFoundationPlugin() {
|
abstract class FoundationPlugin : JavaPlugin() {
|
||||||
private lateinit var pluginModule: Module
|
private lateinit var pluginModule: Module
|
||||||
private lateinit var pluginApplication: KoinApplication
|
private lateinit var pluginApplication: KoinApplication
|
||||||
private lateinit var features: List<CoreFeature>
|
private lateinit var features: List<CoreFeature>
|
@ -1,8 +1,7 @@
|
|||||||
package gay.pizza.foundation.core.features.backup
|
package cloud.kubelet.foundation.core.features.backup
|
||||||
|
|
||||||
import gay.pizza.foundation.shared.Platform
|
import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||||
import gay.pizza.foundation.core.FoundationCorePlugin
|
import cloud.kubelet.foundation.core.Util
|
||||||
import gay.pizza.foundation.shared.MessageUtil
|
|
||||||
import net.kyori.adventure.text.Component
|
import net.kyori.adventure.text.Component
|
||||||
import net.kyori.adventure.text.format.TextColor
|
import net.kyori.adventure.text.format.TextColor
|
||||||
import org.bukkit.Server
|
import org.bukkit.Server
|
||||||
@ -27,14 +26,14 @@ import java.util.zip.ZipOutputStream
|
|||||||
// TODO: Clean up dependency injection.
|
// TODO: Clean up dependency injection.
|
||||||
class BackupCommand(
|
class BackupCommand(
|
||||||
private val plugin: FoundationCorePlugin,
|
private val plugin: FoundationCorePlugin,
|
||||||
private val backupFilePath: Path,
|
private val backupsPath: Path,
|
||||||
private val config: BackupConfig,
|
private val config: BackupConfig,
|
||||||
private val s3Client: S3Client,
|
private val s3Client: S3Client,
|
||||||
) : CommandExecutor {
|
) : CommandExecutor {
|
||||||
override fun onCommand(
|
override fun onCommand(
|
||||||
sender: CommandSender, command: Command, label: String, args: Array<String>
|
sender: CommandSender, command: Command, label: String, args: Array<String>
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (running.get()) {
|
if (RUNNING.get()) {
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
Component
|
Component
|
||||||
.text("Backup is already running.")
|
.text("Backup is already running.")
|
||||||
@ -52,20 +51,20 @@ class BackupCommand(
|
|||||||
|
|
||||||
// TODO: Pull backup creation code into a separate service.
|
// TODO: Pull backup creation code into a separate service.
|
||||||
private fun runBackup(server: Server, sender: CommandSender? = null) = try {
|
private fun runBackup(server: Server, sender: CommandSender? = null) = try {
|
||||||
running.set(true)
|
RUNNING.set(true)
|
||||||
|
|
||||||
server.scheduler.runTask(plugin) { ->
|
server.scheduler.runTask(plugin) { ->
|
||||||
server.sendMessage(MessageUtil.formatSystemMessage("Backup started."))
|
server.sendMessage(Util.formatSystemMessage("Backup started."))
|
||||||
}
|
}
|
||||||
|
|
||||||
val backupTime = Instant.now()
|
val backupTime = Instant.now()
|
||||||
val backupIdentifier = if (Platform.isWindows()) {
|
val backupIdentifier = if (Util.isPlatformWindows()) {
|
||||||
backupTime.toEpochMilli().toString()
|
backupTime.toEpochMilli().toString()
|
||||||
} else {
|
} else {
|
||||||
backupTime.toString()
|
backupTime.toString()
|
||||||
}
|
}
|
||||||
val backupFileName = String.format("backup-%s.zip", backupIdentifier)
|
val backupFileName = String.format("backup-%s.zip", backupIdentifier)
|
||||||
val backupPath = backupFilePath.resolve(backupFileName)
|
val backupPath = backupsPath.resolve(backupFileName)
|
||||||
val backupFile = backupPath.toFile()
|
val backupFile = backupPath.toFile()
|
||||||
|
|
||||||
FileOutputStream(backupFile).use { zipFileStream ->
|
FileOutputStream(backupFile).use { zipFileStream ->
|
||||||
@ -94,9 +93,9 @@ class BackupCommand(
|
|||||||
}
|
}
|
||||||
plugin.slF4JLogger.warn("Failed to backup.", e)
|
plugin.slF4JLogger.warn("Failed to backup.", e)
|
||||||
} finally {
|
} finally {
|
||||||
running.set(false)
|
RUNNING.set(false)
|
||||||
server.scheduler.runTask(plugin) { ->
|
server.scheduler.runTask(plugin) { ->
|
||||||
server.sendMessage(MessageUtil.formatSystemMessage("Backup finished."))
|
server.sendMessage(Util.formatSystemMessage("Backup finished."))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +139,7 @@ class BackupCommand(
|
|||||||
.filter { path -> !matchers.any { it.matches(Paths.get(path.normalize().toString())) } }
|
.filter { path -> !matchers.any { it.matches(Paths.get(path.normalize().toString())) } }
|
||||||
.toList()
|
.toList()
|
||||||
val buffer = ByteArray(16 * 1024)
|
val buffer = ByteArray(16 * 1024)
|
||||||
val backupsPath = backupFilePath.toRealPath()
|
val backupsPath = backupsPath.toRealPath()
|
||||||
|
|
||||||
for (path in paths) {
|
for (path in paths) {
|
||||||
val realPath = path.toRealPath()
|
val realPath = path.toRealPath()
|
||||||
@ -163,6 +162,6 @@ class BackupCommand(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val running = AtomicBoolean()
|
private val RUNNING = AtomicBoolean()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.core.features.backup
|
package cloud.kubelet.foundation.core.features.backup
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
@ -1,8 +1,11 @@
|
|||||||
package gay.pizza.foundation.core.features.backup
|
package cloud.kubelet.foundation.core.features.backup
|
||||||
|
|
||||||
import gay.pizza.foundation.core.abstraction.Feature
|
import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||||
import gay.pizza.foundation.core.features.scheduler.cancel
|
import cloud.kubelet.foundation.core.Util
|
||||||
import gay.pizza.foundation.core.features.scheduler.cron
|
import cloud.kubelet.foundation.core.abstraction.Feature
|
||||||
|
import cloud.kubelet.foundation.core.features.scheduler.cancel
|
||||||
|
import cloud.kubelet.foundation.core.features.scheduler.cron
|
||||||
|
import com.charleskorn.kaml.Yaml
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials
|
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials
|
||||||
@ -10,6 +13,7 @@ import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
|
|||||||
import software.amazon.awssdk.regions.Region
|
import software.amazon.awssdk.regions.Region
|
||||||
import software.amazon.awssdk.services.s3.S3Client
|
import software.amazon.awssdk.services.s3.S3Client
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
import kotlin.io.path.inputStream
|
||||||
|
|
||||||
class BackupFeature : Feature() {
|
class BackupFeature : Feature() {
|
||||||
private val s3Client by inject<S3Client>()
|
private val s3Client by inject<S3Client>()
|
||||||
@ -21,10 +25,10 @@ class BackupFeature : Feature() {
|
|||||||
val backupPath = plugin.pluginDataPath.resolve(BACKUPS_DIRECTORY)
|
val backupPath = plugin.pluginDataPath.resolve(BACKUPS_DIRECTORY)
|
||||||
backupPath.toFile().mkdir()
|
backupPath.toFile().mkdir()
|
||||||
|
|
||||||
plugin.registerCommandExecutor("fbackup", BackupCommand(plugin, backupPath, config, s3Client))
|
registerCommandExecutor("fbackup", BackupCommand(plugin, backupPath, config, s3Client))
|
||||||
|
|
||||||
if (config.schedule.cron.isNotEmpty()) {
|
if (config.schedule.cron.isNotEmpty()) {
|
||||||
// Assume the user never wants to modify the second. I'm not sure why this is enforced in Quartz.
|
// Assume user never wants to modify second. I'm not sure why this is enforced in Quartz.
|
||||||
val expr = "0 ${config.schedule.cron}"
|
val expr = "0 ${config.schedule.cron}"
|
||||||
scheduleId = scheduler.cron(expr) {
|
scheduleId = scheduler.cron(expr) {
|
||||||
plugin.server.scheduler.runTask(plugin) { ->
|
plugin.server.scheduler.runTask(plugin) { ->
|
||||||
@ -42,10 +46,14 @@ class BackupFeature : Feature() {
|
|||||||
|
|
||||||
override fun module() = module {
|
override fun module() = module {
|
||||||
single {
|
single {
|
||||||
plugin.loadConfigurationWithDefault(
|
val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
|
||||||
plugin,
|
plugin.slF4JLogger,
|
||||||
|
plugin.pluginDataPath,
|
||||||
|
"backup.yaml",
|
||||||
|
)
|
||||||
|
return@single Yaml.default.decodeFromStream(
|
||||||
BackupConfig.serializer(),
|
BackupConfig.serializer(),
|
||||||
"backup.yaml"
|
configPath.inputStream()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
single {
|
single {
|
@ -0,0 +1,16 @@
|
|||||||
|
package cloud.kubelet.foundation.core.features.dev
|
||||||
|
|
||||||
|
import cloud.kubelet.foundation.core.abstraction.Feature
|
||||||
|
|
||||||
|
class DevFeature : Feature() {
|
||||||
|
private lateinit var devUpdateServer: DevUpdateServer
|
||||||
|
|
||||||
|
override fun enable() {
|
||||||
|
devUpdateServer = DevUpdateServer(plugin)
|
||||||
|
devUpdateServer.enable()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun disable() {
|
||||||
|
devUpdateServer.disable()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package cloud.kubelet.foundation.core.features.dev
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class DevUpdateConfig(
|
||||||
|
val port: Int = 8484,
|
||||||
|
val token: String,
|
||||||
|
val ipAllowList: List<String> = listOf("*")
|
||||||
|
)
|
@ -0,0 +1,13 @@
|
|||||||
|
package cloud.kubelet.foundation.core.features.dev
|
||||||
|
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class DevUpdatePayload(
|
||||||
|
@SerialName("object_kind")
|
||||||
|
val objectKind: String,
|
||||||
|
@SerialName("object_attributes")
|
||||||
|
val objectAttributes: Map<String, JsonElement>
|
||||||
|
)
|
@ -0,0 +1,117 @@
|
|||||||
|
package cloud.kubelet.foundation.core.features.dev
|
||||||
|
|
||||||
|
import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||||
|
import cloud.kubelet.foundation.core.Util
|
||||||
|
import cloud.kubelet.foundation.core.features.update.UpdateService
|
||||||
|
import com.charleskorn.kaml.Yaml
|
||||||
|
import com.sun.net.httpserver.HttpExchange
|
||||||
|
import com.sun.net.httpserver.HttpServer
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import kotlinx.serialization.json.decodeFromStream
|
||||||
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
|
import java.net.InetSocketAddress
|
||||||
|
import kotlin.io.path.inputStream
|
||||||
|
|
||||||
|
class DevUpdateServer(val plugin: FoundationCorePlugin) {
|
||||||
|
private lateinit var config: DevUpdateConfig
|
||||||
|
private var server: HttpServer? = null
|
||||||
|
|
||||||
|
private val json = Json {
|
||||||
|
prettyPrint = true
|
||||||
|
prettyPrintIndent = " "
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun enable() {
|
||||||
|
val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
|
||||||
|
plugin.slF4JLogger,
|
||||||
|
plugin.pluginDataPath,
|
||||||
|
"devupdate.yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
config = Yaml.default.decodeFromStream(DevUpdateConfig.serializer(), configPath.inputStream())
|
||||||
|
start()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun start() {
|
||||||
|
if (config.token.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.token.length < 8) {
|
||||||
|
plugin.slF4JLogger.warn("DevUpdateServer Token was too short (must be 8 or more characters)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val server = HttpServer.create()
|
||||||
|
server.createContext("/").setHandler { exchange ->
|
||||||
|
handle(exchange)
|
||||||
|
}
|
||||||
|
server.bind(InetSocketAddress("0.0.0.0", config.port), 0)
|
||||||
|
server.start()
|
||||||
|
this.server = server
|
||||||
|
plugin.slF4JLogger.info("DevUpdateServer listening on port ${config.port}")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handle(exchange: HttpExchange) {
|
||||||
|
val ip = exchange.remoteAddress.address.hostAddress
|
||||||
|
if (!config.ipAllowList.contains("*") && !config.ipAllowList.contains(ip)) {
|
||||||
|
plugin.slF4JLogger.warn("DevUpdateServer received request from IP $ip which is not allowed.")
|
||||||
|
exchange.close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.slF4JLogger.info("DevUpdateServer Request $ip ${exchange.requestMethod} ${exchange.requestURI.path}")
|
||||||
|
if (exchange.requestMethod != "POST") {
|
||||||
|
exchange.respond(405, "Method not allowed.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exchange.requestURI.path != "/webhook/update") {
|
||||||
|
exchange.respond(404, "Not Found.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exchange.requestURI.query != config.token) {
|
||||||
|
exchange.respond(401, "Unauthorized.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val payload: DevUpdatePayload
|
||||||
|
try {
|
||||||
|
payload = json.decodeFromStream(exchange.requestBody)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
plugin.slF4JLogger.error("Failed to decode request body.", e)
|
||||||
|
exchange.respond(400, "Bad Request")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.objectKind != "pipeline" ||
|
||||||
|
payload.objectAttributes["ref"]?.jsonPrimitive?.content != "main" ||
|
||||||
|
payload.objectAttributes["status"]?.jsonPrimitive?.content != "success"
|
||||||
|
) {
|
||||||
|
exchange.respond(200, "Event was not relevant for update.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
exchange.respond(200, "Success.")
|
||||||
|
plugin.slF4JLogger.info("DevUpdate Started")
|
||||||
|
UpdateService.updatePlugins(plugin.server.consoleSender) {
|
||||||
|
plugin.server.scheduler.runTask(plugin) { ->
|
||||||
|
plugin.server.shutdown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun disable() {
|
||||||
|
server?.stop(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun HttpExchange.respond(code: Int, content: String) {
|
||||||
|
val encoded = content.encodeToByteArray()
|
||||||
|
sendResponseHeaders(code, encoded.size.toLong())
|
||||||
|
responseBody.write(encoded)
|
||||||
|
responseBody.close()
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.core.features.gameplay
|
package cloud.kubelet.foundation.core.features.gameplay
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
@ -1,6 +1,9 @@
|
|||||||
package gay.pizza.foundation.core.features.gameplay
|
package cloud.kubelet.foundation.core.features.gameplay
|
||||||
|
|
||||||
import gay.pizza.foundation.core.abstraction.Feature
|
import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||||
|
import cloud.kubelet.foundation.core.Util
|
||||||
|
import cloud.kubelet.foundation.core.abstraction.Feature
|
||||||
|
import com.charleskorn.kaml.Yaml
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.entity.EntityType
|
import org.bukkit.entity.EntityType
|
||||||
@ -14,16 +17,21 @@ import org.bukkit.event.player.PlayerInteractEntityEvent
|
|||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
import kotlin.io.path.inputStream
|
||||||
|
|
||||||
class GameplayFeature : Feature() {
|
class GameplayFeature : Feature() {
|
||||||
private val config by inject<GameplayConfig>()
|
private val config by inject<GameplayConfig>()
|
||||||
|
|
||||||
override fun module() = module {
|
override fun module() = module {
|
||||||
single {
|
single {
|
||||||
plugin.loadConfigurationWithDefault(
|
val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
|
||||||
plugin,
|
plugin.slF4JLogger,
|
||||||
|
plugin.pluginDataPath,
|
||||||
|
"gameplay.yaml",
|
||||||
|
)
|
||||||
|
return@single Yaml.default.decodeFromStream(
|
||||||
GameplayConfig.serializer(),
|
GameplayConfig.serializer(),
|
||||||
"gameplay.yaml"
|
configPath.inputStream()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,10 +60,12 @@ class GameplayFeature : Feature() {
|
|||||||
private fun onPlayerInteractEntity(event: PlayerInteractEntityEvent) {
|
private fun onPlayerInteractEntity(event: PlayerInteractEntityEvent) {
|
||||||
val mainHandItem = event.player.inventory.itemInMainHand
|
val mainHandItem = event.player.inventory.itemInMainHand
|
||||||
val hasLead = mainHandItem.type == Material.LEAD
|
val hasLead = mainHandItem.type == Material.LEAD
|
||||||
val livingEntity = event.rightClicked as? LivingEntity
|
val isLivingEntity = event.rightClicked is LivingEntity
|
||||||
|
|
||||||
// If leads are allowed on all mobs, then start leading the mob.
|
// If leads are allowed on all mobs, then start leading the mob.
|
||||||
if (config.mobs.allowLeads && hasLead && livingEntity != null) {
|
if (config.mobs.allowLeads && hasLead && isLivingEntity) {
|
||||||
|
val livingEntity = event.rightClicked as LivingEntity
|
||||||
|
|
||||||
// Something to do with Bukkit, leashes must happen after the event.
|
// Something to do with Bukkit, leashes must happen after the event.
|
||||||
Bukkit.getScheduler().runTask(plugin) { ->
|
Bukkit.getScheduler().runTask(plugin) { ->
|
||||||
// If the entity is already leashed, don't do anything.
|
// If the entity is already leashed, don't do anything.
|
@ -0,0 +1,18 @@
|
|||||||
|
package cloud.kubelet.foundation.core.features.persist
|
||||||
|
|
||||||
|
import cloud.kubelet.foundation.core.abstraction.Feature
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import org.koin.core.module.Module
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
class PersistenceFeature : Feature() {
|
||||||
|
private val persistence = inject<PluginPersistence>()
|
||||||
|
|
||||||
|
override fun disable() {
|
||||||
|
persistence.value.unload()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun module(): Module = module {
|
||||||
|
single { PluginPersistence() }
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,13 @@
|
|||||||
package gay.pizza.foundation.shared
|
package cloud.kubelet.foundation.core.features.persist
|
||||||
|
|
||||||
|
import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||||
import jetbrains.exodus.entitystore.Entity
|
import jetbrains.exodus.entitystore.Entity
|
||||||
import jetbrains.exodus.entitystore.EntityIterable
|
import jetbrains.exodus.entitystore.EntityIterable
|
||||||
import jetbrains.exodus.entitystore.PersistentEntityStores
|
import jetbrains.exodus.entitystore.PersistentEntityStores
|
||||||
import jetbrains.exodus.entitystore.StoreTransaction
|
import jetbrains.exodus.entitystore.StoreTransaction
|
||||||
|
|
||||||
class PersistentStore(core: IFoundationCore, fileStoreName: String) : AutoCloseable {
|
class PersistentStore(corePlugin: FoundationCorePlugin, fileStoreName: String) : AutoCloseable {
|
||||||
private val fileStorePath = core.pluginDataPath.resolve("persistence/${fileStoreName}")
|
private val fileStorePath = corePlugin.pluginDataPath.resolve("persistence/${fileStoreName}")
|
||||||
private val entityStore = PersistentEntityStores.newInstance(fileStorePath.toFile())
|
private val entityStore = PersistentEntityStores.newInstance(fileStorePath.toFile())
|
||||||
|
|
||||||
fun <R> transact(block: StoreTransaction.() -> R): R {
|
fun <R> transact(block: StoreTransaction.() -> R): R {
|
@ -1,6 +1,6 @@
|
|||||||
package gay.pizza.foundation.core.features.persist
|
package cloud.kubelet.foundation.core.features.persist
|
||||||
|
|
||||||
import gay.pizza.foundation.core.features.stats.StatsFeature
|
import cloud.kubelet.foundation.core.features.stats.StatsFeature
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandExecutor
|
import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
@ -24,7 +24,7 @@ class PersistentStoreCommand(
|
|||||||
|
|
||||||
when (args[0]) {
|
when (args[0]) {
|
||||||
"stats" -> {
|
"stats" -> {
|
||||||
statsFeature.persistence.stores.forEach { (name, store) ->
|
statsFeature.persistence.value.stores.forEach { (name, store) ->
|
||||||
val counts = store.transact {
|
val counts = store.transact {
|
||||||
entityTypes.associateWith { type -> getAll(type).size() }.toSortedMap()
|
entityTypes.associateWith { type -> getAll(type).size() }.toSortedMap()
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ class PersistentStoreCommand(
|
|||||||
|
|
||||||
val storeName = args[1]
|
val storeName = args[1]
|
||||||
val entityTypeName = args[2]
|
val entityTypeName = args[2]
|
||||||
val store = statsFeature.persistence.store(storeName)
|
val store = statsFeature.persistence.value.store(storeName)
|
||||||
store.transact {
|
store.transact {
|
||||||
val entities = getAll(entityTypeName).take(3)
|
val entities = getAll(entityTypeName).take(3)
|
||||||
for (entity in entities) {
|
for (entity in entities) {
|
||||||
@ -62,7 +62,7 @@ class PersistentStoreCommand(
|
|||||||
|
|
||||||
val storeName = args[1]
|
val storeName = args[1]
|
||||||
val entityTypeName = args[2]
|
val entityTypeName = args[2]
|
||||||
val store = statsFeature.persistence.store(storeName)
|
val store = statsFeature.persistence.value.store(storeName)
|
||||||
store.transact {
|
store.transact {
|
||||||
store.deleteAllEntities(entityTypeName)
|
store.deleteAllEntities(entityTypeName)
|
||||||
}
|
}
|
@ -1,15 +1,20 @@
|
|||||||
package gay.pizza.foundation.shared
|
package cloud.kubelet.foundation.core.features.persist
|
||||||
|
|
||||||
|
import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
class PluginPersistence(val core: IFoundationCore) {
|
class PluginPersistence : KoinComponent {
|
||||||
|
private val plugin = inject<FoundationCorePlugin>()
|
||||||
|
|
||||||
val stores = ConcurrentHashMap<String, PersistentStore>()
|
val stores = ConcurrentHashMap<String, PersistentStore>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a persistent store by name. Make sure the name is path-safe, descriptive and consistent across server runs.
|
* Fetch a persistent store by name. Make sure the name is path-safe, descriptive and consistent across server runs.
|
||||||
*/
|
*/
|
||||||
fun store(name: String): PersistentStore =
|
fun store(name: String): PersistentStore =
|
||||||
stores.getOrPut(name) { PersistentStore(core, name) }
|
stores.getOrPut(name) { PersistentStore(plugin.value, name) }
|
||||||
|
|
||||||
fun unload() {
|
fun unload() {
|
||||||
stores.values.forEach { store -> store.close() }
|
stores.values.forEach { store -> store.close() }
|
@ -1,7 +1,7 @@
|
|||||||
package gay.pizza.foundation.core.features.persist
|
package cloud.kubelet.foundation.core.features.persist
|
||||||
|
|
||||||
import jetbrains.exodus.entitystore.Entity
|
import jetbrains.exodus.entitystore.Entity
|
||||||
|
|
||||||
fun <T : Comparable<*>> Entity.setAllProperties(vararg entries: Pair<String, T>): Unit = entries.forEach { entry ->
|
fun <T : Comparable<*>> Entity.setAllProperties(vararg entries: Pair<String, T>) = entries.forEach { entry ->
|
||||||
setProperty(entry.first, entry.second)
|
setProperty(entry.first, entry.second)
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.core.features.player
|
package cloud.kubelet.foundation.core.features.player
|
||||||
|
|
||||||
import org.bukkit.GameMode
|
import org.bukkit.GameMode
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.core.features.player
|
package cloud.kubelet.foundation.core.features.player
|
||||||
|
|
||||||
import org.bukkit.WeatherType
|
import org.bukkit.WeatherType
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.core.features.player
|
package cloud.kubelet.foundation.core.features.player
|
||||||
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
@ -1,9 +1,12 @@
|
|||||||
package gay.pizza.foundation.core.features.player
|
package cloud.kubelet.foundation.core.features.player
|
||||||
|
|
||||||
|
import cloud.kubelet.foundation.core.FoundationCorePlugin
|
||||||
|
import cloud.kubelet.foundation.core.Util
|
||||||
|
import cloud.kubelet.foundation.core.abstraction.Feature
|
||||||
|
import com.charleskorn.kaml.Yaml
|
||||||
import com.google.common.cache.Cache
|
import com.google.common.cache.Cache
|
||||||
import com.google.common.cache.CacheBuilder
|
import com.google.common.cache.CacheBuilder
|
||||||
import com.google.common.cache.RemovalCause
|
import com.google.common.cache.RemovalCause
|
||||||
import gay.pizza.foundation.core.abstraction.Feature
|
|
||||||
import net.kyori.adventure.text.Component
|
import net.kyori.adventure.text.Component
|
||||||
import org.bukkit.GameMode
|
import org.bukkit.GameMode
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
@ -13,6 +16,7 @@ import org.bukkit.event.player.PlayerMoveEvent
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent
|
import org.bukkit.event.player.PlayerQuitEvent
|
||||||
import org.koin.core.component.inject
|
import org.koin.core.component.inject
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
|
import kotlin.io.path.inputStream
|
||||||
|
|
||||||
class PlayerFeature : Feature() {
|
class PlayerFeature : Feature() {
|
||||||
private val config by inject<PlayerConfig>()
|
private val config by inject<PlayerConfig>()
|
||||||
@ -38,21 +42,23 @@ class PlayerFeature : Feature() {
|
|||||||
playerActivity.cleanUp()
|
playerActivity.cleanUp()
|
||||||
}, 20, 100)
|
}, 20, 100)
|
||||||
|
|
||||||
plugin.registerCommandExecutor(listOf("survival", "s"), GamemodeCommand(GameMode.SURVIVAL))
|
registerCommandExecutor(listOf("survival", "s"), GamemodeCommand(GameMode.SURVIVAL))
|
||||||
plugin.registerCommandExecutor(listOf("creative", "c"), GamemodeCommand(GameMode.CREATIVE))
|
registerCommandExecutor(listOf("creative", "c"), GamemodeCommand(GameMode.CREATIVE))
|
||||||
plugin.registerCommandExecutor(listOf("adventure", "a"), GamemodeCommand(GameMode.ADVENTURE))
|
registerCommandExecutor(listOf("adventure", "a"), GamemodeCommand(GameMode.ADVENTURE))
|
||||||
plugin.registerCommandExecutor(listOf("spectator", "sp"), GamemodeCommand(GameMode.SPECTATOR))
|
registerCommandExecutor(listOf("spectator", "sp"), GamemodeCommand(GameMode.SPECTATOR))
|
||||||
plugin.registerCommandExecutor(listOf("localweather", "lw"), LocalWeatherCommand())
|
registerCommandExecutor(listOf("localweather", "lw"), LocalWeatherCommand())
|
||||||
plugin.registerCommandExecutor(listOf("goose", "the_most_wonderful_kitty_ever"), GooseCommand())
|
|
||||||
plugin.registerCommandExecutor(listOf("megatnt"), MegaTntCommand())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun module() = org.koin.dsl.module {
|
override fun module() = org.koin.dsl.module {
|
||||||
single {
|
single {
|
||||||
plugin.loadConfigurationWithDefault(
|
val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
|
||||||
plugin,
|
plugin.slF4JLogger,
|
||||||
|
plugin.pluginDataPath,
|
||||||
|
"player.yaml",
|
||||||
|
)
|
||||||
|
return@single Yaml.default.decodeFromStream(
|
||||||
PlayerConfig.serializer(),
|
PlayerConfig.serializer(),
|
||||||
"player.yaml"
|
configPath.inputStream()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.core.features.scheduler
|
package cloud.kubelet.foundation.core.features.scheduler
|
||||||
|
|
||||||
import org.quartz.CronScheduleBuilder.cronSchedule
|
import org.quartz.CronScheduleBuilder.cronSchedule
|
||||||
import org.quartz.JobBuilder.newJob
|
import org.quartz.JobBuilder.newJob
|
@ -1,6 +1,6 @@
|
|||||||
package gay.pizza.foundation.core.features.scheduler
|
package cloud.kubelet.foundation.core.features.scheduler
|
||||||
|
|
||||||
import gay.pizza.foundation.core.abstraction.CoreFeature
|
import cloud.kubelet.foundation.core.abstraction.CoreFeature
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.quartz.Scheduler
|
import org.quartz.Scheduler
|
||||||
import org.quartz.impl.StdSchedulerFactory
|
import org.quartz.impl.StdSchedulerFactory
|
@ -1,4 +1,4 @@
|
|||||||
package gay.pizza.foundation.core.features.scheduler
|
package cloud.kubelet.foundation.core.features.scheduler
|
||||||
|
|
||||||
import org.quartz.Job
|
import org.quartz.Job
|
||||||
import org.quartz.JobExecutionContext
|
import org.quartz.JobExecutionContext
|
||||||
@ -9,4 +9,4 @@ class SchedulerRunner : Job {
|
|||||||
val function = context.jobDetail.jobDataMap["function"] as () -> Unit
|
val function = context.jobDetail.jobDataMap["function"] as () -> Unit
|
||||||
function()
|
function()
|
||||||
}
|
}
|
||||||
}
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user