diff --git a/.editorconfig b/.editorconfig index 15c5c6d2..ca62e0a6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,12 +2,14 @@ root = true [*] charset = utf-8 +end_of_line = lf +tab_width = 4 indent_size = 4 indent_style = space -tab_width = 4 insert_final_newline = true +trim_trailing_whitespace = true max_line_length = 120 -ij_visual_guides = 80 +ij_visual_guides = 80, 120 ij_continuation_indent_size = 8 [*.java] @@ -264,5 +266,5 @@ ij_json_space_before_colon = false ij_json_space_before_comma = false ij_json_wrap_long_lines = false -[{*.yml,*.md}] +[*.{yml,md}] indent_size = 2 diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 7576e1da..df230924 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,3 +1,5 @@ +#file: noinspection YAMLSchemaValidation + blank_issues_enabled: false contact_links: - name: Issue with site (whomine.net) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f6f7d32..1e501291 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,5 @@ +#file: noinspection Annotator + name: Java CI with Gradle on: @@ -13,7 +15,7 @@ jobs: strategy: fail-fast: true matrix: - java: [ '17' ] + java: [ '21' ] steps: - if: ${{ github.event_name == 'push' }} uses: actions/checkout@v4 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a1dcd6dd..9f2ad41e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,3 +1,5 @@ +#file: noinspection Annotator + name: "CodeQL" on: @@ -27,7 +29,7 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} - + - name: Initialize CodeQL uses: github/codeql-action/init@v3 with: diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 00000000..2f3311a4 --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() + gradlePluginPortal() + + maven("https://repo.papermc.io/repository/maven-public/") +} + +dependencies { + compileOnly(gradleApi()) + implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) + implementation(libs.shadow) + implementation(libs.paper.userdev) +} diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts new file mode 100644 index 00000000..4d3e1830 --- /dev/null +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,11 @@ +@file:Suppress("UnstableApiUsage") + +dependencyResolutionManagement { + versionCatalogs { + register("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +rootProject.name = "build-logic" diff --git a/build-logic/src/main/kotlin/Dependencies.kt b/build-logic/src/main/kotlin/Dependencies.kt new file mode 100644 index 00000000..bc665d2c --- /dev/null +++ b/build-logic/src/main/kotlin/Dependencies.kt @@ -0,0 +1,18 @@ +@file:Suppress("unused") + +import com.github.jengelman.gradle.plugins.shadow.internal.DependencyFilter +import org.gradle.api.artifacts.ExternalModuleDependency +import org.gradle.api.provider.Provider + +fun DependencyFilter.exclude(provider: Provider): DependencyFilter? = + exclude(provider.get()) + +fun DependencyFilter.exclude(dependency: ExternalModuleDependency): DependencyFilter? = + exclude(dependency("${dependency.group}:${dependency.name}:.*")) + +fun DependencyFilter.include(provider: Provider): DependencyFilter? = + include(provider.get()) + +fun DependencyFilter.include(dependency: ExternalModuleDependency): DependencyFilter? = + include(dependency("${dependency.group}:${dependency.name}:.*")) + diff --git a/build-logic/src/main/kotlin/LibsAccessor.kt b/build-logic/src/main/kotlin/LibsAccessor.kt new file mode 100644 index 00000000..1214d491 --- /dev/null +++ b/build-logic/src/main/kotlin/LibsAccessor.kt @@ -0,0 +1,6 @@ +import org.gradle.accessors.dm.LibrariesForLibs +import org.gradle.api.Project +import org.gradle.kotlin.dsl.getByType + +val Project.libs: LibrariesForLibs + get() = rootProject.extensions.getByType() diff --git a/build-logic/src/main/kotlin/Projects.kt b/build-logic/src/main/kotlin/Projects.kt new file mode 100644 index 00000000..ccb97b4e --- /dev/null +++ b/build-logic/src/main/kotlin/Projects.kt @@ -0,0 +1,52 @@ +@file:Suppress("MemberVisibilityCanBePrivate", "unused") + +import org.gradle.api.Project + +const val WHOMINE_PREFIX = "WhoMine" +const val WHOLIB_PREFIX = "WhoLib" + +interface Projects { + val projectName: String + val projectPath: String + val projectDir: String + get() = projectName + val buildDir: String + get() = "build/$projectDir" + + fun asProject(root: Project): Project = + root.project(projectPath) + + fun exists(root: Project): Boolean = + root.findProject(projectPath) != null + + companion object { + fun fromName(name: String): Projects? = + Libs.fromName(name) ?: Platforms.fromName(name) + } +} + +enum class Libs(prefix: String = WHOLIB_PREFIX) : Projects { + Common, Paper, Velocity; + + override val projectName: String = "$prefix-${name.lowercase()}" + override val projectPath: String = ":$projectName" + override val projectDir: String = "lib/$projectName" + + companion object { + fun fromName(name: String): Projects? = + values().find { it.projectName == name } + } +} + +enum class Platforms(prefix: String = WHOMINE_PREFIX) : Projects { + Paper, Velocity; + + override val projectName: String = "$prefix-${name.lowercase()}" + override val projectPath: String = ":$projectName" + override val projectDir: String = "platform/$projectName" + + companion object { + fun fromName(name: String): Projects? = + values().find { it.projectName == name } + } +} diff --git a/build-logic/src/main/kotlin/Properties.kt b/build-logic/src/main/kotlin/Properties.kt new file mode 100644 index 00000000..ca1765ab --- /dev/null +++ b/build-logic/src/main/kotlin/Properties.kt @@ -0,0 +1,86 @@ +import org.gradle.api.JavaVersion +import org.gradle.api.Project +import org.gradle.jvm.toolchain.JavaLanguageVersion + +val utf8: String = Charsets.UTF_8.name() + +val Project.javaVersionInt: Int + get() = ( + getProperty("java.version") + ?: throw IllegalStateException("Java version not set") + ).toString().toInt() + +val Project.javaVersion: JavaVersion + get() = JavaVersion.toVersion(javaVersionInt) + +val Project.javaLanguageVersion: JavaLanguageVersion + get() = JavaLanguageVersion.of(javaVersionInt) + +val Project.javaCompilerArgs: String + get() = ( + getProperty("java.compilerArgs") + ?: throw IllegalStateException("Java compiler args not set") + ).toString() + +val Project.projectGroup: String + get() = ( + getProperty("project.group") + ?: throw IllegalStateException("Project group not set") + ).toString() + +val Project.projectVersion: Any + get() = ( + getProperty("project.version") + ?: throw IllegalStateException("Project version not set") + ) + +val Project.projectDescription: String + get() = ( + getProperty("project.description") + ?: throw IllegalStateException("Project description not set") + ).toString() + +val Project.paperVersion: String + get() = ( + getProperty("paper.version") + ?: throw IllegalStateException("Paper version not set") + ).toString() + +val Project.projectAuthor: String + get() = ( + getProperty("project.author") + ?: throw IllegalStateException("Author not set") + ).toString() + +val Project.projectContributors: String + get() = ( + getProperty("project.contributors") + ?: throw IllegalStateException("Contributors not set") + ).toString() + +val Project.projectWebsite: String + get() = ( + getProperty("project.website") + ?: throw IllegalStateException("Website not set") + ).toString() + +fun apiVersion(minecraftVersion: String): String { + val parts = minecraftVersion.split('.') + + return if (parts.size < 2) { + throw IllegalStateException("Invalid Minecraft version: '$minecraftVersion'") + } else { + "'${parts[0]}.${parts[1]}'" + } +} + +fun Project.getProperty(name: String): Any? { + return rootProject.property(name) +} + +fun Project.getProperty( + name: String, + default: Any +): Any { + return rootProject.property(name) ?: default +} diff --git a/build-logic/src/main/kotlin/whomine.base.gradle.kts b/build-logic/src/main/kotlin/whomine.base.gradle.kts new file mode 100644 index 00000000..24661fc1 --- /dev/null +++ b/build-logic/src/main/kotlin/whomine.base.gradle.kts @@ -0,0 +1,71 @@ +plugins { + `java-library` +} + +group = projectGroup +version = projectVersion +description = projectDescription + +java { + toolchain { + languageVersion.set(javaLanguageVersion) + } + + sourceCompatibility = javaVersion + targetCompatibility = javaVersion +} + +repositories { + mavenCentral() + + maven("https://repo.papermc.io/repository/maven-public/") + maven("https://repo.codemc.org/repository/maven-public/") + maven("https://maven.playpro.com") +} + +dependencies { + if (project.name != Libs.Common.projectName) { + compileOnlyApi(Libs.Common.asProject(rootProject)) + } + + compileOnlyApi(libs.adventure.api) + compileOnlyApi(libs.adventure.ansi) + compileOnlyApi(libs.adventure.gson) + compileOnlyApi(libs.adventure.legacy) + compileOnlyApi(libs.adventure.plain) + compileOnlyApi(libs.adventure.minimessage) + compileOnlyApi(libs.asm.api) + compileOnlyApi(libs.asm.commons) + compileOnlyApi(libs.fastutil) + compileOnlyApi(libs.google.guava) + compileOnlyApi(libs.google.gson) + compileOnlyApi(libs.google.jsr305) + compileOnlyApi(libs.jackson.annotations) + compileOnlyApi(libs.jda) + compileOnlyApi(libs.jetbrains.annotations) + compileOnlyApi(libs.netty.buffer) +} + +sourceSets { + main { + java.srcDir(Libs.Common.asProject(rootProject).sourceSets.main.get().java.srcDirs) + } +} + +tasks { + compileJava { + options.encoding = utf8 + + options.release.set(javaVersionInt) + options.compilerArgs.add(javaCompilerArgs) + } + + javadoc { + options.encoding = utf8 + setDestinationDir(file("$rootDir/build/javadoc")) + } + + processResources { + filteringCharset = utf8 + } +} diff --git a/build-logic/src/main/kotlin/whomine.library.gradle.kts b/build-logic/src/main/kotlin/whomine.library.gradle.kts new file mode 100644 index 00000000..a361395e --- /dev/null +++ b/build-logic/src/main/kotlin/whomine.library.gradle.kts @@ -0,0 +1,34 @@ +import org.gradle.kotlin.dsl.invoke + +plugins { + id("whomine.shadow") +} + +dependencies { + runtimeClasspath(libs.adventure.api) + runtimeClasspath(libs.adventure.ansi) + runtimeClasspath(libs.adventure.gson) + runtimeClasspath(libs.adventure.legacy) + runtimeClasspath(libs.adventure.plain) + runtimeClasspath(libs.adventure.minimessage) + runtimeClasspath(libs.asm.api) + runtimeClasspath(libs.asm.commons) + runtimeClasspath(libs.fastutil) + runtimeClasspath(libs.google.guava) + runtimeClasspath(libs.google.gson) + runtimeClasspath(libs.google.jsr305) + runtimeClasspath(libs.jackson.annotations) + runtimeClasspath(libs.jda) + runtimeClasspath(libs.jetbrains.annotations) + runtimeClasspath(libs.netty.buffer) +} + +tasks { + jar { + destinationDirectory.set(file("$rootDir/build/lib")) + } + + shadowJar { + destinationDirectory.set(file("$rootDir/build/lib")) + } +} diff --git a/build-logic/src/main/kotlin/whomine.paperweight.gradle.kts b/build-logic/src/main/kotlin/whomine.paperweight.gradle.kts new file mode 100644 index 00000000..8fd7824e --- /dev/null +++ b/build-logic/src/main/kotlin/whomine.paperweight.gradle.kts @@ -0,0 +1,8 @@ +plugins { + id("whomine.base") + id("io.papermc.paperweight.userdev") +} + +dependencies { + paperweight.paperDevBundle(paperVersion) +} diff --git a/build-logic/src/main/kotlin/whomine.platform.gradle.kts b/build-logic/src/main/kotlin/whomine.platform.gradle.kts new file mode 100644 index 00000000..264a4473 --- /dev/null +++ b/build-logic/src/main/kotlin/whomine.platform.gradle.kts @@ -0,0 +1,17 @@ +import org.gradle.kotlin.dsl.invoke + +plugins { + id("whomine.shadow") +} + +tasks { + jar { + enabled = false + } + + shadowJar { + destinationDirectory.set(file("$rootDir/build/platform")) + + archiveClassifier.set("") + } +} diff --git a/build-logic/src/main/kotlin/whomine.shadow.gradle.kts b/build-logic/src/main/kotlin/whomine.shadow.gradle.kts new file mode 100644 index 00000000..e1492c58 --- /dev/null +++ b/build-logic/src/main/kotlin/whomine.shadow.gradle.kts @@ -0,0 +1,12 @@ +import org.gradle.kotlin.dsl.invoke + +plugins { + id("whomine.base") + id("com.gradleup.shadow") +} + +tasks { + build { + dependsOn(shadowJar) + } +} diff --git a/build-logic/src/main/kotlin/whomine.velocitypowered.gradle.kts b/build-logic/src/main/kotlin/whomine.velocitypowered.gradle.kts new file mode 100644 index 00000000..c72da8db --- /dev/null +++ b/build-logic/src/main/kotlin/whomine.velocitypowered.gradle.kts @@ -0,0 +1,8 @@ +plugins { + id("whomine.base") +} + +dependencies { + compileOnly(libs.velocity.api) + annotationProcessor(libs.velocity.api) +} diff --git a/build.gradle.kts b/build.gradle.kts index bc9955f4..39d11792 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,74 +1,15 @@ -val utf8: String = Charsets.UTF_8.name() -val javaVersion: Int = property("java.version").toString().toInt() -val javaCompilerArgs: String = property("java.compilerArgs").toString() -val projectGroup: String = property("project.group").toString() -val projectVersion: Any = property("project.version")!! -val projectDescription: String = property("project.description").toString() - plugins { - java - alias(libs.plugins.shadow) apply false - alias(libs.plugins.paper.userdev) apply false - alias(libs.plugins.paper.run) apply false -} - -subprojects { - apply(plugin = "java") - - group = project.group - version = projectVersion - description = projectDescription - - java { - toolchain.languageVersion.set(JavaLanguageVersion.of(javaVersion)) - } - - repositories { - mavenCentral() - maven("https://repo.papermc.io/repository/maven-public/") - maven("https://repo.codemc.org/repository/maven-public/") - maven("https://maven.playpro.com") - } - - dependencies { - compileOnly(rootProject.libs.fastutil) - compileOnly(rootProject.libs.google.guava) - compileOnly(rootProject.libs.google.gson) - compileOnly(rootProject.libs.google.jsr305) - compileOnly(rootProject.libs.jetbrains.annotations) - compileOnly(rootProject.libs.jackson.annotations) - compileOnly(rootProject.libs.jda) - } - - tasks { - compileJava { - options.encoding = utf8 - - options.release.set(javaVersion) - options.compilerArgs.add(javaCompilerArgs) - } - - jar { - archiveBaseName.set("${rootProject.name}-${project.name}") - destinationDirectory.set(file("$rootDir/build")) - } - - javadoc { - enabled = false - options.encoding = utf8 - setDestinationDir(file("$rootDir/builds/javadoc")) - } - - processResources { - filteringCharset = utf8 - } - } + `java-library` } tasks { jar { doLast { - file("build").deleteRecursively() + file("build").listFiles()?.forEach { + if (it.name != "javadoc") { + it.deleteRecursively() + } + } } } compileJava { enabled = false } diff --git a/common/build.gradle.kts b/common/build.gradle.kts deleted file mode 100644 index e69de29b..00000000 diff --git a/common/src/main/java/com/minersstudios/whomine/api/annotation/Key.java b/common/src/main/java/com/minersstudios/whomine/api/annotation/Key.java deleted file mode 100644 index 127dcdf8..00000000 --- a/common/src/main/java/com/minersstudios/whomine/api/annotation/Key.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.minersstudios.whomine.api.annotation; - -import com.minersstudios.whomine.api.throwable.InvalidRegexException; -import org.intellij.lang.annotations.RegExp; -import org.intellij.lang.annotations.Subst; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.Nullable; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; - -/** - * Annotation used to mark the key. - *
- * The key must match the {@link #REGEX regex} pattern. - * - * @see Key.Validator - */ -@Documented -@Retention(RetentionPolicy.CLASS) -@Target({ - FIELD, - LOCAL_VARIABLE, - METHOD, - PARAMETER -}) -@org.intellij.lang.annotations.Pattern(Key.REGEX) -public @interface Key { - /** The regex pattern that a valid key must match */ - @RegExp String REGEX = "[a-z0-9/._-]*"; - - /** - * Validator class for the {@link Key} annotation to check whether the - * key matches the {@link #REGEX regex} - * - * @see #matches(String) - * @see #validate(String) - */ - final class Validator { - - @Contract(" -> fail") - private Validator() throws AssertionError { - throw new AssertionError("Utility class"); - } - - /** - * Checks whether the key matches the {@link #REGEX regex} - * - * @param key The key - * @return Whether the key matches the {@link #REGEX regex} - */ - public static boolean matches(final @Subst("key") @Key @Nullable String key) { - if (key == null) { - return true; - } - - for(int i = 0; i < key.length(); ++i) { - final char character = key.charAt(i); - - switch (character) { - case '_', '-', '.', '/' -> {} - default -> { - if (character < 'a' || character > 'z') { - if (character < '0' || character > '9') { - return false; - } - } - } - } - } - - return true; - } - - /** - * Validates the key - * - * @param key The key - * @throws InvalidRegexException If the key does not match the - * {@link #REGEX regex} - * @see #matches(String) - */ - public static void validate(final @Subst("key") @Key @Nullable String key) throws InvalidRegexException { - if (!matches(key)) { - throw new InvalidRegexException("Key must match regex: " + REGEX); - } - } - } -} diff --git a/common/src/main/java/com/minersstudios/whomine/api/annotation/Namespace.java b/common/src/main/java/com/minersstudios/whomine/api/annotation/Namespace.java deleted file mode 100644 index 0c9fea79..00000000 --- a/common/src/main/java/com/minersstudios/whomine/api/annotation/Namespace.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.minersstudios.whomine.api.annotation; - -import com.minersstudios.whomine.api.throwable.InvalidRegexException; -import org.intellij.lang.annotations.RegExp; -import org.intellij.lang.annotations.Subst; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.Nullable; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; - -/** - * Annotation used to mark the namespace. - *
- * The namespace must match the {@link #REGEX regex} pattern. - * - * @see Namespace.Validator - */ -@Documented -@Retention(RetentionPolicy.CLASS) -@Target({ - FIELD, - LOCAL_VARIABLE, - METHOD, - PARAMETER -}) -@org.intellij.lang.annotations.Pattern(Namespace.REGEX) -public @interface Namespace { - /** The regex pattern that a valid namespace must match */ - @RegExp String REGEX = "[a-z0-9._-]*"; - - /** - * Validator class for the {@link Namespace} annotation to check whether the - * namespace matches the {@link #REGEX regex} - * - * @see #matches(String) - * @see #validate(String) - */ - final class Validator { - - @Contract(" -> fail") - private Validator() throws AssertionError { - throw new AssertionError("Utility class"); - } - - /** - * Checks whether the namespace matches the {@link #REGEX regex} - * - * @param namespace The namespace - * @return Whether the namespace matches the {@link #REGEX regex} - */ - public static boolean matches(final @Subst("namespace") @Namespace @Nullable String namespace) { - if (namespace == null) { - return false; - } - - for(int i = 0; i < namespace.length(); ++i) { - final char character = namespace.charAt(i); - - switch (character) { - case '_', '-', '.' -> {} - default -> { - if (character < 'a' || character > 'z') { - if (character < '0' || character > '9') { - return false; - } - } - } - } - } - - return true; - } - - /** - * Validates the namespace - * - * @param namespace The namespace - * @throws InvalidRegexException If the namespace does not match the - * {@link #REGEX regex} - * @see #matches(String) - */ - public static void validate(final @Subst("namespace") @Namespace @Nullable String namespace) throws InvalidRegexException { - if (!matches(namespace)) { - throw new InvalidRegexException("Namespace must match regex: " + REGEX); - } - } - } -} diff --git a/common/src/main/java/com/minersstudios/whomine/api/annotation/ResourceKey.java b/common/src/main/java/com/minersstudios/whomine/api/annotation/ResourceKey.java deleted file mode 100644 index 079826a0..00000000 --- a/common/src/main/java/com/minersstudios/whomine/api/annotation/ResourceKey.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.minersstudios.whomine.api.annotation; - -import com.minersstudios.whomine.api.throwable.InvalidRegexException; -import org.intellij.lang.annotations.RegExp; -import org.intellij.lang.annotations.Subst; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.Nullable; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; - -/** - * Annotation used to mark the {@code namespaced-key}. - *
- * The namespaced-key must match the {@link #REGEX regex} pattern. - * - * @see ResourceKey.Validator - */ -@Documented -@Retention(RetentionPolicy.CLASS) -@Target({ - FIELD, - LOCAL_VARIABLE, - METHOD, - PARAMETER -}) -@org.intellij.lang.annotations.Pattern(ResourceKey.REGEX) -public @interface ResourceKey { - /** The regex pattern that a valid namespaced-key must match */ - @RegExp String REGEX = "(" + Namespace.REGEX + ")(:(" + Key.REGEX + "))?"; - - /** - * Validator class for the {@link ResourceKey} annotation to check whether - * the namespaced-key matches the {@link #REGEX regex} - * - * @see #matches(String) - * @see #validate(String) - */ - final class Validator { - - @Contract(" -> fail") - private Validator() throws AssertionError { - throw new AssertionError("Utility class"); - } - - /** - * Checks whether the namespaced-key matches the {@link #REGEX regex} - * - * @param namespacedKey The namespaced-key - * @return Whether the namespaced-key matches the {@link #REGEX regex} - */ - public static boolean matches(final @Subst("namespace:key") @ResourceKey @Nullable String namespacedKey) { - if (namespacedKey == null) { - return true; - } - - final int colonIndex = namespacedKey.indexOf(':'); - - @Subst("namespace") String namespace = ""; - @Subst("key") String key = namespacedKey; - - if (colonIndex >= 0) { - key = namespacedKey.substring(colonIndex + 1); - - if (colonIndex >= 1) { - namespace = namespacedKey.substring(0, colonIndex); - } - } - - return Namespace.Validator.matches(namespace) - && Key.Validator.matches(key); - } - - /** - * Validates the namespaced-key - * - * @param namespacedKey The namespaced-key - * @throws InvalidRegexException If the namespaced-key does not match - * the {@link #REGEX regex} - * @see #matches(String) - */ - public static void validate(final @Subst("namespace:key") @ResourceKey @Nullable String namespacedKey) throws InvalidRegexException { - if (!matches(namespacedKey)) { - throw new InvalidRegexException("NamespacedKey must match regex: " + REGEX); - } - } - } -} diff --git a/common/src/main/java/com/minersstudios/whomine/api/status/package-info.java b/common/src/main/java/com/minersstudios/whomine/api/status/package-info.java deleted file mode 100644 index 21ddabe0..00000000 --- a/common/src/main/java/com/minersstudios/whomine/api/status/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This package contains classes and interfaces related to statuses and their - * management. They are thread-safe and can be safely used to manage plugin - * statuses in a multithreading environment. - * - * @see com.minersstudios.whomine.api.status.Status - * @see com.minersstudios.whomine.api.status.StatusWatcher - * @see com.minersstudios.whomine.api.status.StatusHandler - */ -package com.minersstudios.whomine.api.status; diff --git a/gradle.properties b/gradle.properties index a186dbac..9d667d5a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,12 @@ -java.version=17 +java.version=21 java.compilerArgs=-Xlint:deprecation -paper.version=1.20.4-R0.1-SNAPSHOT +paper.version=1.21.1-R0.1-SNAPSHOT project.group=com.minersstudios project.name=WhoMine project.version=1.0.0 project.description=A Minecraft plugin for WhoMine project.author=MinersStudios -project.contributors=p0loskun, PackmanDude +project.contributors=Nykon, PackmanDude project.website=https://whomine.net diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ca322077..0aa7d138 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,32 +1,44 @@ [versions] # libraries -authme = "5.6.0-SNAPSHOT" -coreprotect = "22.2" -fastutil = "8.5.13" -google-guava = "33.2.1-jre" +adventure-api = "4.17.0" +authme = "5.6.0" +asm = "9.7.1" +coreprotect = "22.4" +fastutil = "8.5.14" +google-guava = "33.3.1-jre" google-gson = "2.11.0" google-jsr305 = "3.0.2" -jetbrains-annotations = "24.0.1" -jackson-annotations = "2.16.0" -jda = "5.0.0-beta.23" +jackson-annotations = "2.18.0" +jda = "5.1.1" +jetbrains-annotations = "25.0.0" +netty-buffer = "4.1.113.Final" +velocity = "3.4.0-SNAPSHOT" # plugins -paper-userdev = "1.5.11" -shadow = "8.1.1" -paper-run = "2.2.3" +paper-userdev = "1.7.2" +shadow = "8.3.3" [libraries] -authme = { group = "fr.xephi", name = "authme", version.ref = "authme" } -coreprotect = { group = "net.coreprotect", name = "coreprotect", version.ref = "coreprotect" } -fastutil = { group = "it.unimi.dsi", name = "fastutil", version.ref = "fastutil" } -google-guava = { group = "com.google.guava", name = "guava", version.ref = "google-guava" } -google-gson = { group = "com.google.code.gson", name = "gson", version.ref = "google-gson" } -google-jsr305 = { group = "com.google.code.findbugs", name = "jsr305", version.ref = "google-jsr305" } -jetbrains-annotations = { group = "org.jetbrains", name = "annotations", version.ref = "jetbrains-annotations" } -jackson-annotations = { group = "com.fasterxml.jackson.core", name = "jackson-annotations", version.ref = "jackson-annotations" } -jda = { group = "net.dv8tion", name = "JDA", version.ref = "jda" } +adventure-api = { group = "net.kyori", name = "adventure-api", version.ref = "adventure-api" } +adventure-ansi = { group = "net.kyori", name = "adventure-text-serializer-ansi", version.ref = "adventure-api" } +adventure-gson = { group = "net.kyori", name = "adventure-text-serializer-gson", version.ref = "adventure-api" } +adventure-legacy = { group = "net.kyori", name = "adventure-text-serializer-legacy", version.ref = "adventure-api" } +adventure-plain = { group = "net.kyori", name = "adventure-text-serializer-plain", version.ref = "adventure-api" } +adventure-minimessage = { group = "net.kyori", name = "adventure-text-minimessage", version.ref = "adventure-api" } +authme = { group = "fr.xephi", name = "authme", version.ref = "authme" } +asm-api = { group = "org.ow2.asm", name = "asm", version.ref = "asm" } +asm-commons = { group = "org.ow2.asm", name = "asm-commons", version.ref = "asm" } +coreprotect = { group = "net.coreprotect", name = "coreprotect", version.ref = "coreprotect" } +fastutil = { group = "it.unimi.dsi", name = "fastutil", version.ref = "fastutil" } +google-guava = { group = "com.google.guava", name = "guava", version.ref = "google-guava" } +google-gson = { group = "com.google.code.gson", name = "gson", version.ref = "google-gson" } +google-jsr305 = { group = "com.google.code.findbugs", name = "jsr305", version.ref = "google-jsr305" } +jackson-annotations = { group = "com.fasterxml.jackson.core", name = "jackson-annotations", version.ref = "jackson-annotations" } +jda = { group = "net.dv8tion", name = "JDA", version.ref = "jda" } +jetbrains-annotations = { group = "org.jetbrains", name = "annotations", version.ref = "jetbrains-annotations" } +netty-buffer = { group = "io.netty", name = "netty-buffer", version.ref = "netty-buffer" } +velocity-api = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" } -[plugins] -paper-userdev = { id = "io.papermc.paperweight.userdev", version.ref = "paper-userdev" } -paper-run = { id = "xyz.jpenilla.run-paper", version.ref = "paper-run" } -shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" } +# plugins +shadow = { group = "com.gradleup.shadow", name = "shadow-gradle-plugin", version.ref = "shadow" } +paper-userdev = { group = "io.papermc.paperweight.userdev", name = "io.papermc.paperweight.userdev.gradle.plugin", version.ref = "paper-userdev" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9355b415..df97d72b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/lib/common/build.gradle.kts b/lib/common/build.gradle.kts new file mode 100644 index 00000000..5b34d6ae --- /dev/null +++ b/lib/common/build.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("whomine.library") +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/annotation/Path.java b/lib/common/src/main/java/com/minersstudios/wholib/annotation/Path.java new file mode 100644 index 00000000..9a6c42f8 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/annotation/Path.java @@ -0,0 +1,103 @@ +package com.minersstudios.wholib.annotation; + +import com.minersstudios.wholib.throwable.InvalidResourceException; +import org.intellij.lang.annotations.Pattern; +import org.intellij.lang.annotations.RegExp; +import org.intellij.lang.annotations.Subst; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.Nullable; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +/** + * Annotation used to mark the path. + *

+ * The path must match the {@link #REGEX regex} pattern. + *

+ * Example of usage: + *

+ *     {@code @Path String path = "path";}
+ * 
+ * + * @see Path.Validator + * @see ResourcePath + * @see Resource + */ +@SuppressWarnings("unused") +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ + FIELD, + LOCAL_VARIABLE, + METHOD, + PARAMETER +}) +@Pattern(Path.REGEX) +public @interface Path { + /** The regex pattern that a valid path must match */ + @RegExp String REGEX = "[a-z0-9/._-]*"; + + /** + * Validator class for the {@link Path} annotation to check whether the + * path matches the {@link #REGEX regex} + * + * @see #matches(String) + * @see #validate(String) + */ + final class Validator { + + @Contract(" -> fail") + private Validator() throws AssertionError { + throw new AssertionError("Utility class"); + } + + /** + * Checks whether the path matches the {@link #REGEX regex} + * + * @param path The path + * @return Whether the path matches the {@link #REGEX regex} + */ + @Contract("null -> true") + public static boolean matches(final @Subst("path") @Path @Nullable String path) { + if (path == null) { + return true; + } + + for(int i = 0; i < path.length(); ++i) { + final char character = path.charAt(i); + + switch (character) { + case '_', '-', '.', '/' -> {} + default -> { + if (character < 'a' || character > 'z') { + if (character < '0' || character > '9') { + return false; + } + } + } + } + } + + return true; + } + + /** + * Validates the path + * + * @param path The path + * @throws InvalidResourceException If the path does not match the + * {@link #REGEX regex} + * @see #matches(String) + */ + public static void validate(final @Subst("path") @Path @Nullable String path) throws InvalidResourceException { + if (!matches(path)) { + throw new InvalidResourceException("Path must match regex: " + REGEX); + } + } + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/annotation/Resource.java b/lib/common/src/main/java/com/minersstudios/wholib/annotation/Resource.java new file mode 100644 index 00000000..df8c2c73 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/annotation/Resource.java @@ -0,0 +1,168 @@ +package com.minersstudios.wholib.annotation; + +import com.minersstudios.wholib.throwable.InvalidResourceException; +import org.intellij.lang.annotations.Pattern; +import org.intellij.lang.annotations.RegExp; +import org.intellij.lang.annotations.Subst; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.Nullable; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +/** + * Annotation used to mark the resource. + *

+ * The resource must match the {@link #REGEX regex} pattern. + *

+ * Example of usage: + *

+ *     {@code @Resource String resource = "resource";}
+ * 
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available Constants
ResourceValue
{@link #EMPTY}{@value #EMPTY}
{@link #MINECRAFT}{@value #MINECRAFT}
{@link #REALMS}{@value #REALMS}
{@link #PAPER}{@value #PAPER}
{@link #WHOMINE}{@value #WHOMINE}
{@link #WMBLOCK}{@value #WMBLOCK}
{@link #WMITEM}{@value #WMITEM}
{@link #WMDECOR}{@value #WMDECOR}
{@link #WMENTITY}{@value #WMENTITY}
+ * + * @see Resource.Validator + * @see ResourcePath + * @see Path + */ +@SuppressWarnings("unused") +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ + FIELD, + LOCAL_VARIABLE, + METHOD, + PARAMETER +}) +@Pattern(Resource.REGEX) +public @interface Resource { + /** The regex pattern that a valid resource must match */ + @RegExp String REGEX = "[a-z0-9._-]*"; + + /** The empty resource */ + @Resource String EMPTY = ""; + /** The Minecraft resource */ + @Resource String MINECRAFT = "minecraft"; + /** The Realms resource */ + @Resource String REALMS = "realms"; + /** The Paper resource */ + @Resource String PAPER = "paper"; + /** The Velocity resource */ + @Resource String VELOCITY = "velocity"; + /** The WhoMine resource */ + @Resource String WHOMINE = "whomine"; + /** The WhoMine's block resource */ + @Resource String WMBLOCK = "wmblock"; + /** The WhoMine's item resource */ + @Resource String WMITEM = "wmitem"; + /** The WhoMine's decor resource */ + @Resource String WMDECOR = "wmdecor"; + /** The WhoMine's entity resource */ + @Resource String WMENTITY = "wmentity"; + + /** + * Validator class for the {@link Resource} annotation to check whether the + * resource matches the {@link #REGEX regex} + * + * @see #matches(String) + * @see #validate(String) + */ + final class Validator { + + @Contract(" -> fail") + private Validator() throws AssertionError { + throw new AssertionError("Utility class"); + } + + /** + * Checks whether the resource matches the {@link #REGEX regex} + * + * @param resource The resource + * @return Whether the resource matches the {@link #REGEX regex} + */ + @Contract("null -> false") + public static boolean matches(final @Subst("resource") @Resource @Nullable String resource) { + if (resource == null) { + return false; + } + + for(int i = 0; i < resource.length(); ++i) { + final char character = resource.charAt(i); + + switch (character) { + case '_', '-', '.' -> {} + default -> { + if (character < 'a' || character > 'z') { + if (character < '0' || character > '9') { + return false; + } + } + } + } + } + + return true; + } + + /** + * Validates the resource + * + * @param resource The resource + * @throws InvalidResourceException If the resource does not match the + * {@link #REGEX regex} + * @see #matches(String) + */ + @Contract("null -> fail") + public static void validate(final @Subst("resource") @Resource @Nullable String resource) throws InvalidResourceException { + if (!matches(resource)) { + throw new InvalidResourceException("Resource must match regex: " + REGEX); + } + } + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/annotation/ResourcePath.java b/lib/common/src/main/java/com/minersstudios/wholib/annotation/ResourcePath.java new file mode 100644 index 00000000..08073544 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/annotation/ResourcePath.java @@ -0,0 +1,142 @@ +package com.minersstudios.wholib.annotation; + +import com.minersstudios.wholib.throwable.InvalidResourceException; +import com.minersstudios.wholib.utility.ResourcedPath; +import io.netty.buffer.ByteBufUtil; +import org.intellij.lang.annotations.Pattern; +import org.intellij.lang.annotations.RegExp; +import org.intellij.lang.annotations.Subst; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.Nullable; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +/** + * Annotation used to mark the string as {@link ResourcedPath resourced-path}. + *

+ * The resourced-path must match the {@link #REGEX regex} pattern. + *

+ * Example of usage: + *

+ *     {@code @ResourcePath String resourcedPath = "resource:path";}
+ *     {@code @ResourcePath String resourcedPath = "path";}
+ * 
+ * + * @see ResourcePath.Validator + * @see Resource + * @see Path + */ +@SuppressWarnings("unused") +@Documented +@Retention(RetentionPolicy.CLASS) +@Target({ + FIELD, + LOCAL_VARIABLE, + METHOD, + PARAMETER +}) +@Pattern(ResourcePath.REGEX) +public @interface ResourcePath { + /** The regex pattern that a valid resourced-path must match */ + @RegExp String REGEX = "(" + Resource.REGEX + ")(:(" + Path.REGEX + "))?"; + + /** + * Validator class for the {@link ResourcePath} annotation to check whether + * the resourced-path matches the {@link #REGEX regex} + * + * @see #matches(String) + * @see #matchesLength(String) + * @see #validate(String) + * @see #validateLength(String) + */ + final class Validator { + + @Contract(" -> fail") + private Validator() throws AssertionError { + throw new AssertionError("Utility class"); + } + + /** + * Checks whether the resourced-path matches the {@link #REGEX regex} + * + * @param resourcedPath The resourced-path + * @return Whether the resourced-path matches the {@link #REGEX regex} + */ + @Contract("null -> true") + public static boolean matches(final @Subst("resource:path") @ResourcePath @Nullable String resourcedPath) { + if (resourcedPath == null) { + return true; + } + + if (!matchesLength(resourcedPath)) { + return false; + } + + final int colonIndex = resourcedPath.indexOf(':'); + + @Subst("resource") String resource = ""; + @Subst("path") String path = resourcedPath; + + if (colonIndex >= 0) { + path = resourcedPath.substring(colonIndex + 1); + + if (colonIndex >= 1) { + resource = resourcedPath.substring(0, colonIndex); + } + } + + return Resource.Validator.matches(resource) + && Path.Validator.matches(path); + } + + /** + * Checks whether the resourced-path matches the length requirements + * + * @param resourcedPath The resourced-path + * @return Whether the resourced-path matches the length requirements + */ + @Contract("null -> true") + public static boolean matchesLength(final @Subst("resource:path") @ResourcePath @Nullable String resourcedPath) { + return resourcedPath == null + || ( + resourcedPath.length() <= Short.MAX_VALUE + && ByteBufUtil.utf8MaxBytes(resourcedPath) <= 2 * Short.MAX_VALUE + 1 + ); + } + + /** + * Validates the resourced-path. + *

+ * If the resourced-path is {@code null}, then it is considered valid. + * + * @param resourcedPath The resourced-path + * @throws InvalidResourceException If the resourced-path does not match + * the {@link #REGEX regex} + * @see #matches(String) + */ + public static void validate(final @Subst("resource:path") @ResourcePath @Nullable String resourcedPath) throws InvalidResourceException { + if (!matches(resourcedPath)) { + throw new InvalidResourceException("Resourced-path must match regex: " + REGEX); + } + } + + /** + * Validates the length of the resourced-path. + *

+ * If the resourced-path is {@code null}, then it is considered valid. + * + * @param resourcedPath The resourced-path + * @throws InvalidResourceException If the resourced-path is too long + */ + public static void validateLength(final @Subst("resource:path") @ResourcePath @Nullable String resourcedPath) throws InvalidResourceException { + if (!matchesLength(resourcedPath)) { + throw new InvalidResourceException("Resourced-path is too long: " + resourcedPath); + } + } + } +} diff --git a/common/src/main/java/com/minersstudios/whomine/api/annotation/StatusKey.java b/lib/common/src/main/java/com/minersstudios/wholib/annotation/StatusKey.java similarity index 87% rename from common/src/main/java/com/minersstudios/whomine/api/annotation/StatusKey.java rename to lib/common/src/main/java/com/minersstudios/wholib/annotation/StatusKey.java index 77c48601..ad5bbf7d 100644 --- a/common/src/main/java/com/minersstudios/whomine/api/annotation/StatusKey.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/annotation/StatusKey.java @@ -1,6 +1,7 @@ -package com.minersstudios.whomine.api.annotation; +package com.minersstudios.wholib.annotation; -import com.minersstudios.whomine.api.throwable.InvalidRegexException; +import com.minersstudios.wholib.throwable.InvalidRegexException; +import org.intellij.lang.annotations.Pattern; import org.intellij.lang.annotations.RegExp; import org.intellij.lang.annotations.Subst; import org.jetbrains.annotations.Contract; @@ -15,11 +16,17 @@ /** * Annotation used to mark the key of the status. - *
+ *

* The status key must match the {@link #REGEX regex} pattern. + *

+ * Example of usage: + *

+ *     {@code @StatusKey String statusKey = "STATUS_KEY";}
+ * 
* * @see StatusKey.Validator */ +@SuppressWarnings("unused") @Documented @Retention(RetentionPolicy.CLASS) @Target({ @@ -28,7 +35,7 @@ METHOD, PARAMETER }) -@org.intellij.lang.annotations.Pattern(StatusKey.REGEX) +@Pattern(StatusKey.REGEX) public @interface StatusKey { /** The regex pattern that a valid status key must match */ @RegExp String REGEX = "^[A-Z][A-Z0-9_]*$"; @@ -53,6 +60,7 @@ private Validator() throws AssertionError { * @param key Key of the status * @return Whether the key matches the {@link #REGEX regex} */ + @Contract("null -> false") public static boolean matches(final @Subst("STATUS_KEY") @StatusKey @Nullable String key) { if (key == null) { return false; @@ -93,6 +101,7 @@ public static boolean matches(final @Subst("STATUS_KEY") @StatusKey @Nullable St * {@link #REGEX regex} * @see #matches(String) */ + @Contract("null -> fail") public static void validate(final @Subst("STATUS_KEY") @StatusKey @Nullable String key) throws InvalidRegexException { if (!matches(key)) { throw new InvalidRegexException("Status key must match regex: " + REGEX); diff --git a/lib/common/src/main/java/com/minersstudios/wholib/annotation/package-info.java b/lib/common/src/main/java/com/minersstudios/wholib/annotation/package-info.java new file mode 100644 index 00000000..7b063346 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/annotation/package-info.java @@ -0,0 +1,47 @@ +/** + * This package contains all the annotations used in the API. + *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available Annotations
AnnotationDescriptionExample
{@link com.minersstudios.wholib.annotation.Resource}Indicates that the annotated element is a resource string. + *
{@code @Resource String resource = "resource";}
+ *
{@link com.minersstudios.wholib.annotation.Path}Indicates that the annotated element is a path string. + *
{@code @Path String path = "path";}
+ *
{@link com.minersstudios.wholib.annotation.ResourcePath}Indicates that the annotated element is a resource path. + *
+ *                 {@code @ResourcePath String resourcedPath = "resource:path";}
+ *                 {@code @ResourcePath String resourcedPath = "path";}
+ *             
+ *
{@link com.minersstudios.wholib.annotation.StatusKey} + * Indicates that the annotated element is a status key string.

+ * Used in the {@link com.minersstudios.wholib.status StatusAPI}. + *

+ *
{@code @StatusKey String statusKey = "STATUS_KEY";}
+ *
+ */ +package com.minersstudios.wholib.annotation; diff --git a/lib/common/src/main/java/com/minersstudios/wholib/discord/DiscordListener.java b/lib/common/src/main/java/com/minersstudios/wholib/discord/DiscordListener.java new file mode 100644 index 00000000..6c323fb1 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/discord/DiscordListener.java @@ -0,0 +1,16 @@ +package com.minersstudios.wholib.discord; + +import com.minersstudios.wholib.listener.Listener; +import net.dv8tion.jda.api.events.GenericEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; + +public abstract class DiscordListener + extends ListenerAdapter + implements Listener> { + + @Override + public @NotNull Class getKey() { + return null; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/discord/DiscordModule.java b/lib/common/src/main/java/com/minersstudios/wholib/discord/DiscordModule.java new file mode 100644 index 00000000..22e88d68 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/discord/DiscordModule.java @@ -0,0 +1,7 @@ +package com.minersstudios.wholib.discord; + +import com.minersstudios.wholib.module.Module; + +public interface DiscordModule> extends Module { + +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/CancellableEventContainer.java b/lib/common/src/main/java/com/minersstudios/wholib/event/CancellableEventContainer.java new file mode 100644 index 00000000..7a4507c4 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/CancellableEventContainer.java @@ -0,0 +1,46 @@ +package com.minersstudios.wholib.event; + +import com.minersstudios.wholib.event.handle.HandlerExecutor; +import com.minersstudios.wholib.module.Module; +import com.minersstudios.wholib.packet.PacketContainer; +import org.jetbrains.annotations.NotNull; + +/** + * Represents a cancellable event container that can be executed by + * {@link HandlerExecutor handler executors} + *

+ * It contains : + *

+ * + * @param The module type, that registers and handles the event + * @param The event type + * + * @see EventListener + * @see PacketContainer + */ +public abstract class CancellableEventContainer + extends EventContainer { + + /** + * Cancellable event container constructor + * + * @param module The module that registers and handles the event + * @param event The event associated with this event container + */ + protected CancellableEventContainer( + final @NotNull M module, + final @NotNull E event + ) { + super(module, event); + } + + /** + * Returns whether the event has been cancelled + * + * @return Whether the event has been cancelled + */ + public abstract boolean isCancelled(); +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/EventContainer.java b/lib/common/src/main/java/com/minersstudios/wholib/event/EventContainer.java new file mode 100644 index 00000000..f41f6694 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/EventContainer.java @@ -0,0 +1,56 @@ +package com.minersstudios.wholib.event; + +import com.minersstudios.wholib.event.handle.HandlerExecutor; +import com.minersstudios.wholib.executor.Executable; +import com.minersstudios.wholib.module.AbstractModuleComponent; +import com.minersstudios.wholib.module.Module; +import com.minersstudios.wholib.module.ModuleComponent; +import com.minersstudios.wholib.packet.PacketContainer; +import org.jetbrains.annotations.NotNull; + +/** + * Represents an event container that can be executed by + * {@link HandlerExecutor handler executors} + *

+ * It contains : + *

    + *
  • The module that registers and handles the event
  • + *
  • The event itself
  • + *
+ * + * @param The module type, that registers and handles the event + * @param The event type + * + * @see EventListener + * @see PacketContainer + */ +public abstract class EventContainer + extends AbstractModuleComponent + implements ModuleComponent, Executable { + + private final E event; + + /** + * Event container constructor + * + * @param module The module that registers and handles the event + * @param event The event associated with this event container + */ + protected EventContainer( + final @NotNull M module, + final @NotNull E event + ) { + super(module); + + this.event = event; + } + + /** + * Returns the event + * + * @return The event + */ + public @NotNull E getEvent() { + return this.event; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/EventListener.java b/lib/common/src/main/java/com/minersstudios/wholib/event/EventListener.java new file mode 100644 index 00000000..f83097e4 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/EventListener.java @@ -0,0 +1,287 @@ +package com.minersstudios.wholib.event; + +import com.google.common.base.Joiner; +import com.minersstudios.wholib.event.handle.HandlerExecutor; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.listener.Listener; +import com.minersstudios.wholib.listener.ListenerManager; +import com.minersstudios.wholib.event.handle.CancellableHandlerParams; +import com.minersstudios.wholib.listener.handler.HandlerParams; +import com.minersstudios.wholib.registrable.Registrable; +import com.minersstudios.wholib.throwable.ListenerException; +import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.lang.annotation.Annotation; +import java.util.*; +import java.util.function.Function; + +/** + * An abstract class that represents an event listener. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available optional overridable methods
MethodDescription
{@link #onRegister()} + * Called when the listener is registered by a manager in the + * {@link ListenerManager#register(Registrable)} method + *
{@link #onUnregister()} + * Called when the listener is unregistered by a manager in the + * {@link ListenerManager#unregister(Registrable)} method + *
+ * + * @param The key type of the event listener + * @param The event container type of the event listener + * + * @see EventContainer + * @see HandlerExecutor + */ +@SuppressWarnings("unused") +public abstract class EventListener> + implements Listener { + + private final K key; + private final Map> executorMap; + + /** + * Constructs a new event listener. + *

+ * This constructor will automatically retrieve all event handlers from the + * listener class and key from the {@link ListenFor} annotation. + * + * @param annotationClass The annotation class of the event handler + * @param executorFunction The function to retrieve the handler parameters + * from the annotation + * @throws ClassCastException If the event class is not a subclass of + * annotated event class + * @throws ListenerException If the listener has duplicate event handlers + * for the same order, or if the listener does + * not have a {@link ListenFor} annotation + */ + @SuppressWarnings("unchecked") + protected EventListener( + final @NotNull Class annotationClass, + final @NotNull Function> executorFunction + ) throws ClassCastException, ListenerException { + this.key = (K) this.getListenFor().value(); + this.executorMap = this.retrieveExecutors(annotationClass, executorFunction); + } + + /** + * Constructs a new event listener with the specified key. + *

+ * This constructor will automatically retrieve all event handlers from the + * listener class. + * + * @param key The key of the event listener + * @param annotationClass The annotation class of the event handler + * @param executorFunction The function to retrieve the handler parameters + * from the annotation + * @throws ListenerException If the listener has duplicate event handlers + * for the same order + */ + protected EventListener( + final @NotNull K key, + final @NotNull Class annotationClass, + final @NotNull Function> executorFunction + ) throws ListenerException { + this.key = key; + this.executorMap = this.retrieveExecutors(annotationClass, executorFunction); + } + + @Override + public final @NotNull K getKey() { + return this.key; + } + + /** + * Returns an unmodifiable set of event orders + * + * @return An unmodifiable set of event orders + */ + public final @NotNull @Unmodifiable Set orders() { + return Collections.unmodifiableSet(this.executorMap.keySet()); + } + + /** + * Returns an unmodifiable list of event executors + * + * @return An unmodifiable list of event executors + */ + public final @NotNull @Unmodifiable Collection> executors() { + return Collections.unmodifiableCollection(this.executorMap.values()); + } + + /** + * Returns a hash code value for this event listener + * + * @return A hash code value for this event listener + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + this.key.hashCode(); + result = prime * result + this.executorMap.hashCode(); + + return result; + } + + /** + * Returns whether the event listener contains the specified order + * + * @param order The event order + * @return True if the event listener contains the specified order + */ + public final boolean containsOrder(final @NotNull EventOrder order) { + return this.executorMap.containsKey(order); + } + + /** + * Returns whether the event listener contains the specified executor + * + * @param executor The event executor + * @return True if the event listener contains the specified executor + */ + public final boolean containsExecutor(final @NotNull HandlerExecutor executor) { + return this.executorMap.containsValue(executor); + } + + /** + * Indicates whether some other object is "equal to" this event listener + * + * @param obj The reference object with which to compare + * @return True if this event listener is the same as the obj argument + */ + @Contract("null -> false") + @Override + public boolean equals(final @Nullable Object obj) { + return this == obj + || ( + obj instanceof final EventListener listener + && this.key.equals(listener.key) + && this.executorMap.equals(listener.executorMap) + ); + } + + /** + * Returns a string representation of this event listener + * + * @return A string representation of this event listener + */ + @Override + public @NotNull String toString() { + return this.getClass().getSimpleName() + '{' + + "key=" + this.key + + ( + this.executorMap == null + ? '}' + : ", executors=[" + Joiner.on(", ").join(this.executorMap.values()) + "]}" + ); + } + + /** + * Calls all event executors with the specified event container + * + * @param container The event container + */ + public void call(final @NotNull C container) { + for (final var executor : this.executorMap.values()) { + if (this.isIgnoringCancelled(executor.getParams(), container)) { + continue; + } + + executor.execute(this, container); + } + } + + /** + * Calls the event executor with the specified event container and order + * + * @param order The event order + * @param container The event container + */ + public void call( + final @NotNull EventOrder order, + final @NotNull C container + ) { + final var executor = this.executorMap.get(order); + + if ( + executor != null + && !this.isIgnoringCancelled(executor.getParams(), container) + ) { + executor.execute(this, container); + } + } + + private @NotNull ListenFor getListenFor() throws ListenerException { + final ListenFor annotation = this.getClass().getAnnotation(ListenFor.class); + + if (annotation == null) { + throw new ListenerException("Listener must have " + ListenFor.class.getSimpleName() + " annotation"); + } + + return annotation; + } + + private @NotNull Map> retrieveExecutors( + final @NotNull Class annotationClass, + final @NotNull Function> executorFunction + ) throws ListenerException { + final var map = new Object2ObjectAVLTreeMap>(EventOrder::compareTo); + + for (final var method : this.getClass().getMethods()) { + final var parameterTypes = method.getParameterTypes(); + + if ( + parameterTypes.length != 1 + || !EventContainer.class.isAssignableFrom(parameterTypes[0]) + ) { + continue; + } + + final var annotation = method.getAnnotation(annotationClass); + + if (annotation != null) { + final var handlerParams = executorFunction.apply(annotation); + final var order = handlerParams.getOrder(); + + if (map.containsKey(order)) { + throw new ListenerException("Duplicate event handler for " + order + " order in " + this); + } + + map.put( + order, + HandlerExecutor.of(method, handlerParams) + ); + } + } + + return map; + } + + private boolean isIgnoringCancelled( + final @NotNull HandlerParams params, + final @NotNull C container + ) { + return params instanceof final CancellableHandlerParams cancellableParams + && container instanceof final CancellableEventContainer cancellableContainer + && cancellableParams.isIgnoringCancelled() + && cancellableContainer.isCancelled(); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/EventOrder.java b/lib/common/src/main/java/com/minersstudios/wholib/event/EventOrder.java new file mode 100644 index 00000000..9117e3c6 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/EventOrder.java @@ -0,0 +1,28 @@ +package com.minersstudios.wholib.event; + +import com.minersstudios.wholib.order.Order; +import com.minersstudios.wholib.order.Ordered; + +/** + * This enum represents the order. + *

+ * Handling occurs in the following order : + *

    + *
  1. {@link #LOWEST}
  2. + *
  3. {@link #LOW}
  4. + *
  5. {@link #NORMAL}
  6. + *
  7. {@link #HIGH}
  8. + *
  9. {@link #HIGHEST}
  10. + *
  11. {@link #CUSTOM}
  12. + *
+ * + * @see Ordered + */ +public enum EventOrder implements Order { + LOWEST, LOW, NORMAL, HIGH, HIGHEST, CUSTOM; + + @Override + public int asNumber() { + return this.ordinal(); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/AsyncHandler.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/AsyncHandler.java new file mode 100644 index 00000000..bbb6635c --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/AsyncHandler.java @@ -0,0 +1,52 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.event.EventOrder; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.*; + +/** + * An annotation that marks a method as an async event handler. + *

+ * It contains : + *

    + *
  • The order of the event
  • + *
  • + * Whether the handler must be called asynchronously + *
  • + *
+ * + * @see EventOrder + * @see AsyncHandlerParams + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface AsyncHandler { + + /** + * Returns the order of the event. + *

+ * Handling occurs in the following order : + *

    + *
  1. {@link EventOrder#LOWEST}
  2. + *
  3. {@link EventOrder#LOW}
  4. + *
  5. {@link EventOrder#NORMAL}
  6. + *
  7. {@link EventOrder#HIGH}
  8. + *
  9. {@link EventOrder#HIGHEST}
  10. + *
  11. {@link EventOrder#CUSTOM}
  12. + *
+ * + * @return The order of the event + */ + @NotNull EventOrder order() default EventOrder.NORMAL; + + /** + * Returns whether the handler must be called asynchronously. + *

+ * The default value is {@value AsyncHandlerParams#DEFAULT_ASYNC}. + * + * @return Whether the handler must be called asynchronously + */ + boolean async() default AsyncHandlerParams.DEFAULT_ASYNC; +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/AsyncHandlerParams.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/AsyncHandlerParams.java new file mode 100644 index 00000000..83845a2b --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/AsyncHandlerParams.java @@ -0,0 +1,217 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.handler.HandlerParams; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.concurrent.Immutable; + +/** + * An immutable class that represents the parameters of an async event handler. + *

+ * It contains : + *

    + *
  • The order of the event handler
  • + *
  • Whether the event handler must be called asynchronously
  • + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Factory Methods
MethodDescription
{@link #defaultParams()}Returns the default event handler params
{@link #of(AsyncHandler)}Creates a new event handler params with the given handler's + * order and async state
{@link #of(EventOrder)}Creates a new event handler params with the given order and + * default async state
{@link #of(boolean)}Creates a new event handler params with the default order and + * async state
{@link #of(EventOrder, boolean)}Creates a new event handler params with the given order and async + * state
+ * + * @see AsyncHandler + */ +@SuppressWarnings("unused") +@Immutable +public class AsyncHandlerParams extends EventHandlerParams { + /** + * Default async state of the + * {@link AsyncHandlerParams async handler params} + */ + public static final boolean DEFAULT_ASYNC = true; + private static final AsyncHandlerParams DEFAULT = + new AsyncHandlerParams( + DEFAULT_ORDER, + DEFAULT_ASYNC + ); + + private final boolean async; + + protected AsyncHandlerParams( + final @NotNull EventOrder order, + final boolean async + ) { + super(order); + + this.async = async; + } + + /** + * Returns whether the event handler must be called asynchronously + * + * @return Whether the event handler must be called asynchronously + */ + public final boolean isAsync() { + return this.async; + } + + @Override + public int compareTo(final @NotNull HandlerParams other) { + int result = super.compareTo(other); + + if ( + result == 0 + && other instanceof AsyncHandlerParams that + ) { + result = Boolean.compare(this.async, that.async); + } + + return result; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + this.getOrder().hashCode(); + result = prime * result + Boolean.hashCode(this.async); + + return result; + } + + @Contract("null -> false") + @Override + public boolean equals(final @Nullable Object obj) { + return this == obj + || ( + obj instanceof AsyncHandlerParams that + && this.getOrder().isEqualTo(that.getOrder()) + && this.async == that.async + ); + } + + @Override + public @NotNull String toString() { + return this.getClass().getSimpleName() + '{' + + "order=" + this.getOrder() + + ", async=" + this.async + + '}'; + } + + /** + * Returns the default event handler params. + *

+ *

    + *
  • Order: {@link #DEFAULT_ORDER}
  • + *
  • Async: {@value #DEFAULT_ASYNC}
  • + *
+ * + * @return The default event handler params + */ + public static @NotNull AsyncHandlerParams defaultParams() { + return DEFAULT; + } + + /** + * Creates a new event handler params with the given handler's order and + * default async state + * + * @param handler The event handler + * @return A new event handler params with the given handler's order and + * default async state + * @see #of(EventOrder, boolean) + */ + @Contract("_ -> new") + public static @NotNull AsyncHandlerParams of(final @NotNull EventHandler handler) { + return of(handler.value()); + } + + /** + * Creates a new event handler params with the given handler's order and + * async state + * + * @param handler The event handler + * @return A new event handler params with the given handler's order and + * async state + * @see #of(EventOrder, boolean) + */ + @Contract("_ -> new") + public static @NotNull AsyncHandlerParams of(final @NotNull AsyncHandler handler) { + return of(handler.order(), handler.async()); + } + + /** + * Creates a new event handler params with the given order and default + * async state. + *

+ * The default async state is {@value #DEFAULT_ASYNC}. + * + * @param order The order of the event handler + * @return A new event handler params with the given order and default + * async state + * @see #of(EventOrder, boolean) + */ + @Contract("_ -> new") + public static @NotNull AsyncHandlerParams of(final @NotNull EventOrder order) { + return of(order, DEFAULT_ASYNC); + } + + /** + * Creates a new event handler params with the default order and async state. + *

+ * The default order is {@link EventHandlerParams#DEFAULT_ORDER}. + * + * @param async Whether the event handler must be called asynchronously + * @return A new event handler params with the default order and async state + * @see #of(EventOrder, boolean) + */ + @Contract("_ -> new") + public static @NotNull AsyncHandlerParams of(final boolean async) { + return of(DEFAULT_ORDER, async); + } + + /** + * Creates a new event handler params with the given order and async state + * + * @param order The order of the event handler + * @param async Whether the event handler must be called asynchronously + * @return A new event handler params with the given order and async state + */ + @Contract("_, _ -> new") + public static @NotNull AsyncHandlerParams of( + final @NotNull EventOrder order, + final boolean async + ) { + return new AsyncHandlerParams(order, async); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/CancellableHandler.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/CancellableHandler.java new file mode 100644 index 00000000..80d230d2 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/CancellableHandler.java @@ -0,0 +1,57 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.event.EventOrder; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.*; + +/** + * An annotation that marks a method as a cancellable event handler. + *

+ * It contains : + *

    + *
  • The order of the event
  • + *
  • + * Whether to ignore an event call if it is canceled by a lower order + * event in this or another event listener + *
  • + *
+ * + * @see EventOrder + * @see CancellableHandlerParams + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface CancellableHandler { + + /** + * Returns the order of the event. + *

+ * Handling occurs in the following order : + *

    + *
  1. {@link EventOrder#LOWEST}
  2. + *
  3. {@link EventOrder#LOW}
  4. + *
  5. {@link EventOrder#NORMAL}
  6. + *
  7. {@link EventOrder#HIGH}
  8. + *
  9. {@link EventOrder#HIGHEST}
  10. + *
  11. {@link EventOrder#CUSTOM}
  12. + *
+ * + * @return The order of the event + */ + @NotNull EventOrder order() default EventOrder.NORMAL; + + /** + * Returns whether to ignore an event call if it is canceled. + *

+ * If set to {@code true}, the event call will be ignored if it is canceled + * by a lower order event in this or another event listener. + *

+ * The default value is + * {@value CancellableHandlerParams#DEFAULT_IGNORE_CANCELLED}. + * + * @return Whether to ignore an event call if it is canceled + */ + boolean ignoreCancelled() default CancellableHandlerParams.DEFAULT_IGNORE_CANCELLED; +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/CancellableHandlerParams.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/CancellableHandlerParams.java new file mode 100644 index 00000000..1cf967b3 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/CancellableHandlerParams.java @@ -0,0 +1,224 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.handler.HandlerParams; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.concurrent.Immutable; + +/** + * An immutable class that represents the parameters of a cancellable handler. + *

+ * It contains : + *

    + *
  • The order of the handler
  • + *
  • Whether the handler should ignore cancelled events
  • + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Factory Methods
MethodDescription
{@link #defaultParams()}Returns the default cancellable handler params
{@link #of(CancellableHandler)}Creates a new cancellable handler params with the given handler's + * order and ignore cancelled state
{@link #of(EventOrder)}Creates a new cancellable handler params with the given order and + * default ignore cancelled state
{@link #of(boolean)}Creates a new cancellable handler params with the default order + * and ignore cancelled state
{@link #of(EventOrder, boolean)}Creates a new cancellable handler params with the given order and + * ignore cancelled state
+ * + * @see CancellableHandler + */ +@SuppressWarnings("unused") +@Immutable +public class CancellableHandlerParams extends EventHandlerParams { + /** + * Default ignore cancelled state of the + * {@link CancellableHandlerParams cancellable handler params} + */ + public static final boolean DEFAULT_IGNORE_CANCELLED = false; + private static final CancellableHandlerParams DEFAULT = + new CancellableHandlerParams( + DEFAULT_ORDER, + DEFAULT_IGNORE_CANCELLED + ); + + private final boolean ignoreCancelled; + + protected CancellableHandlerParams( + final @NotNull EventOrder order, + final boolean ignoreCancelled + ) { + super(order); + + this.ignoreCancelled = ignoreCancelled; + } + + /** + * Returns whether the handler should ignore cancelled events + * + * @return Whether the handler should ignore cancelled events + */ + public final boolean isIgnoringCancelled() { + return this.ignoreCancelled; + } + + @Override + public int compareTo(final @NotNull HandlerParams other) { + int result = super.compareTo(other); + + if ( + result == 0 + && other instanceof CancellableHandlerParams that + ) { + result = Boolean.compare(this.ignoreCancelled, that.ignoreCancelled); + } + + return result; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + this.getOrder().hashCode(); + result = prime * result + Boolean.hashCode(this.ignoreCancelled); + + return result; + } + + @Contract("null -> false") + @Override + public boolean equals(final @Nullable Object obj) { + return this == obj + || ( + obj instanceof CancellableHandlerParams that + && this.getOrder().isEqualTo(that.getOrder()) + && this.ignoreCancelled == that.ignoreCancelled + ); + } + + @Override + public @NotNull String toString() { + return this.getClass().getSimpleName() + '{' + + "order=" + this.getOrder() + + ", ignoreCancelled=" + this.ignoreCancelled + + '}'; + } + + /** + * Returns the default cancellable handler params. + *

+ *

    + *
  • Order: {@link EventOrder#NORMAL}
  • + *
  • Ignore Cancelled: {@code false}
  • + *
+ * + * @return The default cancellable handler params + */ + public static @NotNull CancellableHandlerParams defaultParams() { + return DEFAULT; + } + + /** + * Creates a new cancellable handler params with the given handler's order + * and default ignore cancelled state + * + * @param handler The cancellable event handler + * @return A new cancellable handler params with the given handler's order + * and default ignore cancelled state + * @see #of(EventOrder, boolean) + */ + @Contract("_ -> new") + public static @NotNull CancellableHandlerParams of(final @NotNull EventHandler handler) { + return of(handler.value()); + } + + /** + * Creates a new cancellable handler params with the given handler's order + * and ignore cancelled state + * + * @param handler The cancellable event handler + * @return A new cancellable handler params with the given handler's order + * and ignore cancelled state + * @see #of(EventOrder, boolean) + */ + @Contract("_ -> new") + public static @NotNull CancellableHandlerParams of(final @NotNull CancellableHandler handler) { + return of(handler.order(), handler.ignoreCancelled()); + } + + /** + * Creates a new cancellable handler params with the given order and default + * ignore cancelled state. + *

+ * The default ignore cancelled state retrieved from the + * {@link #defaultParams() default params}. + * + * @param order The order of the handler + * @return A new cancellable handler params with the given order and default + * ignore cancelled state + * @see #of(EventOrder, boolean) + */ + @Contract("_ -> new") + public static @NotNull CancellableHandlerParams of(final @NotNull EventOrder order) { + return of(order, DEFAULT_IGNORE_CANCELLED); + } + + /** + * Creates a new cancellable handler params with the default order and + * ignore cancelled state. + *

+ * The default order is {@link EventHandlerParams#DEFAULT_ORDER}. + * + * @param ignoreCancelled Whether the cancellable event handler should + * ignore cancelled events + * @return A new cancellable handler params with the default order and + * ignore cancelled state + * @see #of(EventOrder, boolean) + */ + @Contract("_ -> new") + public static @NotNull CancellableHandlerParams of(final boolean ignoreCancelled) { + return of(DEFAULT_ORDER, ignoreCancelled); + } + + /** + * Creates a new cancellable handler params with the given order and ignore + * cancelled state + * + * @param order The order of the handler + * @param ignoreCancelled Whether the cancellable handler should ignore + * cancelled events + * @return A new cancellable handler params with the given order and ignore + * cancelled state + */ + @Contract("_, _ -> new") + public static @NotNull CancellableHandlerParams of( + final @NotNull EventOrder order, + final boolean ignoreCancelled + ) { + return new CancellableHandlerParams(order, ignoreCancelled); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/EventExecutor.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/EventExecutor.java new file mode 100644 index 00000000..f395aa30 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/EventExecutor.java @@ -0,0 +1,45 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.event.EventContainer; +import com.minersstudios.wholib.event.EventListener; +import com.minersstudios.wholib.executor.Executor; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.concurrent.Immutable; + +/** + * Represents an executor that can execute + * {@link EventContainer event container}. + *

+ * Default {@link #execute(EventContainer) method} is unsupported, use + * {@link #execute(EventListener, EventContainer)} instead. + * + * @see EventContainer + */ +@Immutable +public interface EventExecutor extends Executor> { + + /** + * @deprecated Use {@link #execute(EventListener, EventContainer)} instead + */ + @Contract("_ -> fail") + @Deprecated + @Override + default void execute(final @NotNull EventContainer ignored) throws UnsupportedOperationException { + throw new UnsupportedOperationException( + "Use " + this.getClass().getSimpleName() + "#execute(EventListener, EventContainer)" + ); + } + + /** + * Executes the event + * + * @param listener The event listener + * @param container The event container + */ + void execute( + final @NotNull EventListener listener, + final @NotNull EventContainer container + ); +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/EventHandler.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/EventHandler.java new file mode 100644 index 00000000..c553834d --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/EventHandler.java @@ -0,0 +1,41 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.handler.HandlerParams; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.*; + +/** + * An annotation that marks a method as an event handler. + *

+ * It contains : + *

    + *
  • The order of the event
  • + *
+ * + * @see EventOrder + * @see HandlerParams + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface EventHandler { + + /** + * Returns the order of the event. + *

+ * Handling occurs in the following order : + *

    + *
  1. {@link EventOrder#LOWEST}
  2. + *
  3. {@link EventOrder#LOW}
  4. + *
  5. {@link EventOrder#NORMAL}
  6. + *
  7. {@link EventOrder#HIGH}
  8. + *
  9. {@link EventOrder#HIGHEST}
  10. + *
  11. {@link EventOrder#CUSTOM}
  12. + *
+ * + * @return The order of the event + */ + @NotNull EventOrder value() default EventOrder.NORMAL; +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/EventHandlerParams.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/EventHandlerParams.java new file mode 100644 index 00000000..fadafeb4 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/EventHandlerParams.java @@ -0,0 +1,86 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.handler.AbstractHandlerParams; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.concurrent.Immutable; + +/** + * An immutable class that represents the parameters of an event handler. + *

+ * It contains : + *

    + *
  • The order of the handler
  • + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Factory Methods
MethodDescription
{@link #defaultParams()}Returns the default event handler params
{@link #of(EventHandler)}Creates a new event handler params with the given handler's + * order
{@link #of(EventOrder)}Creates a new event handler params with the given order
+ * + * @see EventHandler + */ +@SuppressWarnings("unused") +@Immutable +public class EventHandlerParams extends AbstractHandlerParams { + /** Default order of the handler */ + public static EventOrder DEFAULT_ORDER = EventOrder.NORMAL; + private static final EventHandlerParams DEFAULT = new EventHandlerParams(DEFAULT_ORDER); + + protected EventHandlerParams(final @NotNull EventOrder order) { + super(order); + } + + /** + * Returns the default event handler params. + *

+ *

    + *
  • Order: {@link EventOrder#NORMAL}
  • + *
+ * + * @return The default event handler params + */ + public static @NotNull EventHandlerParams defaultParams() { + return DEFAULT; + } + + /** + * Creates a new event handler params with the given handler's order + * + * @param handler The event handler + * @return A new event handler params with the given handler's order + * @see #of(EventOrder) + */ + @Contract("_ -> new") + public static @NotNull EventHandlerParams of(final @NotNull EventHandler handler) { + return of(handler.value()); + } + + /** + * Creates a new event handler params with the given order + * + * @param order The order of the event handler + * @return A new event handler params with the given order + */ + @Contract("_ -> new") + public static @NotNull EventHandlerParams of(final @NotNull EventOrder order) { + return new EventHandlerParams(order); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/HandlerExecutor.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/HandlerExecutor.java new file mode 100644 index 00000000..cf4878de --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/HandlerExecutor.java @@ -0,0 +1,57 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.event.EventContainer; +import com.minersstudios.wholib.listener.handler.HandlerParams; +import com.minersstudios.wholib.order.Order; +import com.minersstudios.wholib.order.Ordered; +import com.minersstudios.wholib.throwable.ListenerException; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.concurrent.Immutable; +import java.lang.reflect.Method; + +/** + * Represents an executor that can execute + * {@link EventContainer event container} + *

+ * It also contains : + *

    + *
  • The parameters of the event handler
  • + *
+ * + * @see EventContainer + */ +@Immutable +public interface HandlerExecutor> extends EventExecutor, Ordered { + + /** + * Returns the parameters of the event handler + * + * @return The parameters of the event handler + */ + @NotNull HandlerParams getParams(); + + /** + * Returns a string representation of this handler executor + * + * @return A string representation of this handler executor + */ + @Override + @NotNull String toString(); + + /** + * Creates a handler executor + * + * @param method The method to execute + * @param params The parameters of the event handler + * @return A handler executor + */ + @Contract("_, _ -> new") + static > @NotNull HandlerExecutor of( + final @NotNull Method method, + final @NotNull HandlerParams params + ) throws IllegalStateException, ListenerException { + return HandlerExecutorFabric.create(method, params); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/HandlerExecutorFabric.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/HandlerExecutorFabric.java new file mode 100644 index 00000000..8d078515 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/HandlerExecutorFabric.java @@ -0,0 +1,198 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.event.EventContainer; +import com.minersstudios.wholib.event.EventListener; +import com.minersstudios.wholib.listener.handler.HandlerParams; +import com.minersstudios.wholib.order.Order; +import com.minersstudios.wholib.throwable.ListenerException; +import org.jetbrains.annotations.NotNull; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Type; +import org.objectweb.asm.commons.GeneratorAdapter; + +import java.lang.reflect.Method; + +import static org.objectweb.asm.Opcodes.*; + +final class HandlerExecutorFabric { + // + private static final String HANDLER_NAME_TEMPLATE = HandlerExecutor.class.getName() + "$Generated$"; + private static final String HANDLER_INTERNAL_NAME = Type.getInternalName(HandlerExecutor.class); + private static final String HANDLER_IMPL_INTERNAL_NAME = Type.getInternalName(HandlerExecutorImpl.class); + private static final String CONSTRUCTOR_NAME = ""; + private static final String CONSTRUCTOR_DESCRIPTOR = '(' + HandlerParams.class.descriptorString() + ")V"; + private static final String METHOD_NAME = "execute"; + private static final String METHOD_DESCRIPTOR = + '(' + + EventListener.class.descriptorString() + + EventContainer.class.descriptorString() + + ")V"; + // + + private String className; + private ExecutorClassLoader classLoader; + private Class> clazz; + + public @NotNull HandlerExecutorFabric defineClassName(final @NotNull String className) { + this.className = className; + + return this; + } + + public @NotNull HandlerExecutorFabric defineLoader(final @NotNull ClassLoader loader) { + this.classLoader = new ExecutorClassLoader(loader); + + return this; + } + + @SuppressWarnings("unchecked") + public @NotNull HandlerExecutorFabric generateClass(final @NotNull Method method) throws IllegalStateException, ListenerException { + if (this.className == null) { + throw new IllegalStateException("Class name is not defined"); + } + + if (this.classLoader == null) { + throw new IllegalStateException("Class loader is not defined"); + } + + try { + this.clazz = (Class>) + this.classLoader + .loadClass(this.className) + .asSubclass(HandlerExecutorImpl.class); + } catch (final ClassNotFoundException e) { + this.clazz = null; + } catch (final ClassCastException e) { + throw new ListenerException("Class is already generated, but not an instance of " + HandlerExecutorImpl.class, e); + } + + if (this.clazz == null) { + this.clazz = + this.classLoader.defineClass( + this.className, + this.generateClassData(method) + ); + } + + return this; + } + + public @NotNull HandlerExecutor createInstance(final HandlerParams params) throws IllegalStateException, ListenerException { + if (this.clazz == null) { + throw new IllegalStateException("Class is not generated"); + } + + try { + return this.clazz.getConstructor(HandlerParams.class) + .newInstance(params); + } catch (final Throwable e) { + throw new ListenerException("Failed to create instance of " + this.clazz, e); + } + } + + private void generateConstructor(final @NotNull ClassWriter writer) { + final GeneratorAdapter generator = + new GeneratorAdapter( + writer.visitMethod(ACC_PUBLIC, CONSTRUCTOR_NAME, CONSTRUCTOR_DESCRIPTOR, null, null), + ACC_PUBLIC, + CONSTRUCTOR_NAME, + CONSTRUCTOR_DESCRIPTOR + ); + + generator.loadThis(); + generator.loadArg(0); + generator.visitMethodInsn( + INVOKESPECIAL, HANDLER_IMPL_INTERNAL_NAME, + CONSTRUCTOR_NAME, + CONSTRUCTOR_DESCRIPTOR, + false + ); + generator.returnValue(); + generator.endMethod(); + } + + private void generateMethod( + final @NotNull ClassWriter writer, + final @NotNull Method method + ) { + final var declaringClass = method.getDeclaringClass(); + final boolean isInterface = declaringClass.isInterface(); + final GeneratorAdapter generator = + new GeneratorAdapter( + writer.visitMethod(ACC_PUBLIC, METHOD_NAME, METHOD_DESCRIPTOR, null, null), + ACC_PUBLIC, + METHOD_NAME, + METHOD_DESCRIPTOR + ); + + generator.loadArg(0); + generator.checkCast(Type.getType(declaringClass)); + + generator.loadArg(1); + generator.checkCast(Type.getType(method.getParameterTypes()[0])); + + generator.visitMethodInsn( + isInterface + ? INVOKEINTERFACE + : INVOKEVIRTUAL, + Type.getInternalName(declaringClass), + method.getName(), + Type.getMethodDescriptor(method), + isInterface + ); + generator.returnValue(); + generator.endMethod(); + } + + private byte @NotNull [] generateClassData(final @NotNull Method method) { + final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); + + writer.visit( + V21, + ACC_PUBLIC, + this.className.replace('.', '/'), + null, HANDLER_IMPL_INTERNAL_NAME, + new String[] { HANDLER_INTERNAL_NAME } + ); + this.generateConstructor(writer); + this.generateMethod(writer, method); + writer.visitEnd(); + + return writer.toByteArray(); + } + + @SuppressWarnings("unchecked") + public static > @NotNull HandlerExecutor create( + final @NotNull Method method, + final @NotNull HandlerParams handlerParams + ) throws IllegalStateException, ListenerException { + return (HandlerExecutor) new HandlerExecutorFabric() + .defineClassName(HANDLER_NAME_TEMPLATE + method.hashCode()) + .defineLoader(method.getDeclaringClass().getClassLoader()) + .generateClass(method) + .createInstance(handlerParams); + } + + private static final class ExecutorClassLoader extends ClassLoader { + + static { + registerAsParallelCapable(); + } + + ExecutorClassLoader(final @NotNull ClassLoader parent) { + super(parent); + } + + @SuppressWarnings("unchecked") + public @NotNull Class> defineClass( + final @NotNull String name, + final byte @NotNull [] bytes + ) { + final var clazz = this.defineClass(name, bytes, 0, bytes.length); + + this.resolveClass(clazz); + + return (Class>) clazz.asSubclass(HandlerExecutorImpl.class); + } + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/event/handle/HandlerExecutorImpl.java b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/HandlerExecutorImpl.java new file mode 100644 index 00000000..8ecb568e --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/event/handle/HandlerExecutorImpl.java @@ -0,0 +1,34 @@ +package com.minersstudios.wholib.event.handle; + +import com.minersstudios.wholib.listener.handler.HandlerParams; +import com.minersstudios.wholib.order.Order; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.concurrent.Immutable; + +@ApiStatus.Internal +@Immutable +public abstract class HandlerExecutorImpl> implements HandlerExecutor { + + private final HandlerParams params; + + protected HandlerExecutorImpl(final @NotNull HandlerParams params) { + this.params = params; + } + + @Override + public @NotNull HandlerParams getParams() { + return this.params; + } + + @Override + public @NotNull O getOrder() { + return this.getParams().getOrder(); + } + + @Override + public @NotNull String toString() { + return this.getClass().getSimpleName() + "{params=" + this.params + '}'; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/executor/Executable.java b/lib/common/src/main/java/com/minersstudios/wholib/executor/Executable.java new file mode 100644 index 00000000..327e162c --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/executor/Executable.java @@ -0,0 +1,6 @@ +package com.minersstudios.wholib.executor; + +/** + * Represents an executable that can be executed by an {@link Executor} + */ +public interface Executable {} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/executor/Executor.java b/lib/common/src/main/java/com/minersstudios/wholib/executor/Executor.java new file mode 100644 index 00000000..9e0086ed --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/executor/Executor.java @@ -0,0 +1,23 @@ +package com.minersstudios.wholib.executor; + +import org.jetbrains.annotations.NotNull; + +/** + * Represents an executor that can execute an {@link Executable} + * + * @param The executable type + */ +@SuppressWarnings("unused") +public interface Executor { + + /** + * Executes the provided executable + * + * @param executable The executable to execute + * @throws UnsupportedOperationException If the implementation does not + * support this method + */ + default void execute(final @NotNull E executable) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Use another method provided by the implementation"); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/executor/package-info.java b/lib/common/src/main/java/com/minersstudios/wholib/executor/package-info.java new file mode 100644 index 00000000..7531a7e1 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/executor/package-info.java @@ -0,0 +1,8 @@ +/** + * This package contains the basic interfaces for executable objects and their + * executors + * + * @see com.minersstudios.wholib.executor.Executable + * @see com.minersstudios.wholib.executor.Executor + */ +package com.minersstudios.wholib.executor; diff --git a/lib/common/src/main/java/com/minersstudios/wholib/gui/GuiManager.java b/lib/common/src/main/java/com/minersstudios/wholib/gui/GuiManager.java new file mode 100644 index 00000000..06bf63c8 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/gui/GuiManager.java @@ -0,0 +1,13 @@ +package com.minersstudios.wholib.gui; + +import com.minersstudios.wholib.module.AbstractModuleComponent; +import com.minersstudios.wholib.module.Module; +import com.minersstudios.wholib.module.ModuleComponent; +import org.jetbrains.annotations.NotNull; + +public class GuiManager extends AbstractModuleComponent implements ModuleComponent { + + public GuiManager(final @NotNull M module) { + super(module); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/listener/ListenFor.java b/lib/common/src/main/java/com/minersstudios/wholib/listener/ListenFor.java new file mode 100644 index 00000000..a31bb156 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/listener/ListenFor.java @@ -0,0 +1,25 @@ +package com.minersstudios.wholib.listener; + +import com.minersstudios.wholib.event.EventListener; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.*; + +/** + * An annotation that marks a class as a listener for an event + * + * @see EventListener + */ +@Documented +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface ListenFor { + + /** + * Returns the class of the event that the listener listens for + * + * @return The class of the event that the listener listens for + */ + @NotNull Class value(); +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/listener/Listener.java b/lib/common/src/main/java/com/minersstudios/wholib/listener/Listener.java new file mode 100644 index 00000000..d2580301 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/listener/Listener.java @@ -0,0 +1,37 @@ +package com.minersstudios.wholib.listener; + +import com.minersstudios.wholib.registrable.Registrable; + +/** + * Represents a listener that can be registered with + * {@link ListenerManager listener managers}. + *

+ * The key of the listener is used to its identification in the listener manager + * and must be unique. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available optional overridable methods
MethodDescription
{@link #onRegister()} + * Called when the listener is registered by a manager in the + * {@link ListenerManager#register(Registrable)} method + *
{@link #onUnregister()} + * Called when the listener is unregistered by a manager in the + * {@link ListenerManager#unregister(Registrable)} method + *
+ * + * @param The key type of the listener + * + * @see ListenerManager + */ +public interface Listener extends Registrable {} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/listener/ListenerManager.java b/lib/common/src/main/java/com/minersstudios/wholib/listener/ListenerManager.java new file mode 100644 index 00000000..49808e46 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/listener/ListenerManager.java @@ -0,0 +1,28 @@ +package com.minersstudios.wholib.listener; + +import com.minersstudios.wholib.module.AbstractModuleComponent; +import com.minersstudios.wholib.module.Module; +import com.minersstudios.wholib.module.ModuleComponent; +import com.minersstudios.wholib.registrable.Registrar; +import org.jetbrains.annotations.NotNull; + +/** + * The listener manager that can store and manage {@link Listener listeners} + * + * @param The module, that the listener manager belongs to + * + * @see Listener + */ +public abstract class ListenerManager + extends AbstractModuleComponent + implements ModuleComponent, Registrar> { + + /** + * Constructs a new listener manager + * + * @param module The module, that the listener manager belongs to + */ + public ListenerManager(final @NotNull M module) { + super(module); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/listener/ListenerMap.java b/lib/common/src/main/java/com/minersstudios/wholib/listener/ListenerMap.java new file mode 100644 index 00000000..423b1d29 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/listener/ListenerMap.java @@ -0,0 +1,525 @@ +package com.minersstudios.wholib.listener; + +import it.unimi.dsi.fastutil.Hash; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import it.unimi.dsi.fastutil.objects.ObjectLists; +import org.jetbrains.annotations.*; + +import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; + +/** + * Represents a listener map that can store {@link Listener listeners} + * + * @param The key type + * @param The listener type + * + * @see Listener + * @see ListenerManager + */ +@SuppressWarnings("unused") +public class ListenerMap> { + + private final Object2ObjectMap> delegate; + + /** + * Constructs a new listener map with the default initial capacity and load + * factor + */ + public ListenerMap() { + this(Hash.DEFAULT_INITIAL_SIZE); + } + + /** + * Constructs a new listener map with the given initial capacity and the + * default load factor. + *

+ * Also copies the entries from the given map. + * + * @param map The map to copy + */ + public ListenerMap(final @NotNull ListenerMap map) { + this(map, Hash.DEFAULT_LOAD_FACTOR); + } + + /** + * Constructs a new listener map with the given load factor and the initial + * capacity of the given map. + *

+ * Also copies the entries from the given map. + * + * @param map The map to copy + * @param loadFactor The load factor + */ + public ListenerMap( + final @NotNull ListenerMap map, + final float loadFactor + ) { + this(map.keyCount(), loadFactor); + + this.putAll(map); + } + + /** + * Constructs a new listener map with the given initial capacity and the + * default load factor + * + * @param initialCapacity The initial capacity + */ + public ListenerMap(final int initialCapacity) { + this(initialCapacity, Hash.DEFAULT_LOAD_FACTOR); + } + + /** + * Constructs a new listener map with the given initial capacity and load + * factor + * + * @param initialCapacity The initial capacity + * @param loadFactor The load factor + */ + public ListenerMap( + final int initialCapacity, + final float loadFactor + ) { + this.delegate = new Object2ObjectOpenHashMap<>(initialCapacity, loadFactor); + } + + /** + * Returns an unmodifiable view of the key set + * + * @return An unmodifiable view of the key set + */ + public @NotNull @UnmodifiableView Set keySet() { + return this.delegate.keySet(); + } + + /** + * Returns an unmodifiable collection of all listeners in the map + * + * @return An unmodifiable collection of all listeners in the map + */ + public @NotNull @Unmodifiable Collection listeners() { + final var listeners = new ObjectArrayList(); + + for (final var list : this.delegate.values()) { + listeners.addAll(list); + } + + return ObjectLists.unmodifiable(listeners); + } + + /** + * Returns an unmodifiable view of the entry set + * + * @return An unmodifiable view of the entry set + */ + public @NotNull @UnmodifiableView Set>> entrySet() { + return this.delegate.entrySet(); + } + + /** + * Returns an unmodifiable list of listeners for the given key + * + * @param key The key + * @return An unmodifiable list of listeners for the given key + */ + @Contract("null -> null") + public @Nullable @Unmodifiable List get(final @Nullable K key) { + final var listeners = this.delegate.get(key); + + return listeners == null + ? null + : Collections.unmodifiableList(listeners); + } + + /** + * Returns an unmodifiable list of listeners for the given key or the + * default list if the key is not present + * + * @param key The key + * @param defaultList The default list + * @return An unmodifiable list of listeners for the given key or the + * default list if the key is not present + */ + @Contract("_, null -> null; null, !null -> param2") + public @UnknownNullability @UnmodifiableView List getOrDefault( + final @Nullable K key, + final @Nullable List defaultList + ) { + final var result = this.delegate.getOrDefault(key, defaultList); + + return result == null + ? null + : Collections.unmodifiableList(result); + } + + /** + * Puts the given listener in the map + * + * @param listener The listener to put + * @return An unmodifiable list of listeners for the key of the given + * listener or {@code null} if the listener is already present in + * the map + */ + public @Nullable @UnmodifiableView List put(final @NotNull L listener) { + final var key = listener.getKey(); + var listeners = this.delegate.get(key); + + if (listeners == null) { + listeners = new ObjectArrayList<>(); + + this.delegate.put(key, listeners); + } else if (listeners.contains(listener)) { + return null; + } + + listeners.add(listener); + + return Collections.unmodifiableList(listeners); + } + + /** + * Puts all listeners in the given list in the map + * + * @param listeners The listeners to put + * @see #put(Listener) + */ + public void putAll(final @NotNull List listeners) { + for (final var listener : listeners) { + this.put(listener); + } + } + + /** + * Puts all listeners in the given map in the map + * + * @param map The map to put + * @see #put(Listener) + */ + public void putAll(final @NotNull ListenerMap map) { + for (final var entry : map.entrySet()) { + this.delegate.put(entry.getKey(), entry.getValue()); + } + } + + /** + * Removes all listeners for the given key + * + * @param key The key + * @return An unmodifiable list of removed listeners or {@code null} if the + * key is not present in the map + */ + @Contract("null -> null") + public @Nullable @Unmodifiable List remove(final @Nullable K key) { + final var listeners = this.delegate.remove(key); + + return listeners == null + ? null + : Collections.unmodifiableList(listeners); + } + + /** + * Removes the given listener from the map + * + * @param listener The listener to remove + * @return An unmodifiable list of listeners for the key of the given + * listener or {@code null} if the listener is not present in the + * map + */ + public @Nullable @UnmodifiableView List remove(final @NotNull L listener) { + final var listeners = this.delegate.get(listener.getKey()); + + if (listeners == null) { + return null; + } + + final int size = listeners.size(); + + if (size <= 1) { + this.delegate.remove(listener.getKey()); + + return Collections.emptyList(); + } + + listeners.remove(listener); + + return Collections.unmodifiableList(listeners); + } + + /** + * Returns the total count of keys in the map + * + * @return The total count of keys in the map + */ + public int keyCount() { + return this.delegate.size(); + } + + /** + * Returns the total count of listeners in the map + * + * @return The total count of listeners in the map + */ + public int listenerCount() { + int count = 0; + + for (final var listeners : this.delegate.values()) { + count += listeners.size(); + } + + return count; + } + + /** + * Returns whether the map is empty + * + * @return Whether the map is empty + */ + public boolean isEmpty() { + return this.delegate.isEmpty(); + } + + /** + * Returns whether the map contains the given key + * + * @param key The key + * @return Whether the map contains the given key + */ + @Contract("null -> false") + public boolean containsKey(final @Nullable K key) { + return this.delegate.containsKey(key); + } + + /** + * Returns whether the map contains the given listener + * + * @param listener The listener + * @return Whether the map contains the given listener + */ + @Contract("null -> false") + public boolean containsListener(final @Nullable L listener) { + if ( + listener == null + || this.keyCount() == 0 + ) { + return false; + } + + final var listeners = this.delegate.get(listener.getKey()); + + return listeners != null + && listeners.contains(listener); + } + + /** + * Returns an unmodifiable view of the map + * + * @return An unmodifiable view of the map + */ + @Contract(" -> new") + public @NotNull ListenerMap toUnmodifiableView() { + return new View<>(this); + } + + /** + * Removes all keys and listeners from the map + */ + public void clear() { + this.delegate.clear(); + } + + /** + * Iterates over all keys and listeners in the map + * + * @param action The action to perform + */ + public void forEach(final @NotNull BiConsumer action) { + this.delegate.forEach( + (key, listeners) -> + listeners.forEach( + listener -> action.accept(key, listener) + ) + ); + } + + /** + * Replaces the given old listener with the new listener + * + * @param oldListener The old listener + * @param newListener The new listener + * @return Whether the replacement was successful + * @throws IllegalArgumentException If the keys of the listeners do not + * match + */ + public boolean replace( + final @NotNull L oldListener, + final @NotNull L newListener + ) throws IllegalArgumentException { + this.validateKey(oldListener.getKey(), newListener.getKey()); + + final var listeners = this.delegate.get(oldListener.getKey()); + + if (listeners == null) { + return false; + } + + final int index = listeners.indexOf(oldListener); + + if (index == -1) { + return false; + } + + listeners.set(index, newListener); + + return true; + } + + /** + * Replaces all listeners in the map with the result of the given function + * + * @param function The function to apply + */ + public void replaceAll(final @NotNull BiFunction function) { + this.delegate.replaceAll( + (key, listeners) -> { + final var result = new ObjectArrayList(); + + for (final var listener : listeners) { + result.add(function.apply(key, listener)); + } + + return result; + } + ); + } + + private void validateKey( + final @NotNull K first, + final @NotNull K second + ) throws IllegalArgumentException { + if (!first.equals(second)) { + throw new IllegalArgumentException("Listener keys must match, got " + first + " and " + second); + } + } + + private static class View> extends ListenerMap { + + private final ListenerMap delegate; + + private View(final @NotNull ListenerMap delegate) { + this.delegate = delegate; + } + + @Override + public @NotNull @UnmodifiableView Set keySet() { + return this.delegate.keySet(); + } + + @Override + public @NotNull @Unmodifiable Collection listeners() { + return this.delegate.listeners(); + } + + @Override + public @NotNull @UnmodifiableView Set>> entrySet() { + return this.delegate.entrySet(); + } + + @Override + public @Nullable @UnmodifiableView List get(final @Nullable K key) { + return this.delegate.get(key); + } + + @Override + public @UnknownNullability @UnmodifiableView List getOrDefault( + final @Nullable K key, + final @Nullable List defaultList + ) { + return this.delegate.getOrDefault(key, defaultList); + } + + @Contract("_ -> fail") + @Override + public @Nullable @UnmodifiableView List put(final @NotNull L listener) throws UnsupportedOperationException { + throw new UnsupportedOperationException("View does not support modification"); + } + + @Contract("_ -> fail") + @Override + public void putAll(final @NotNull List listeners) throws UnsupportedOperationException { + throw new UnsupportedOperationException("View does not support modification"); + } + + @Contract("_ -> fail") + @Override + public void putAll(final @NotNull ListenerMap map) throws UnsupportedOperationException { + throw new UnsupportedOperationException("View does not support modification"); + } + + @Contract("_ -> fail") + @Override + public @Nullable @Unmodifiable List remove(final @Nullable K key) throws UnsupportedOperationException { + throw new UnsupportedOperationException("View does not support modification"); + } + + @Contract("_ -> fail") + @Override + public @Nullable @UnmodifiableView List remove(final @NotNull L listener) throws UnsupportedOperationException { + throw new UnsupportedOperationException("View does not support modification"); + } + + @Override + public int keyCount() { + return this.delegate.keyCount(); + } + + @Override + public int listenerCount() { + return this.delegate.listenerCount(); + } + + @Override + public boolean isEmpty() { + return this.delegate.isEmpty(); + } + + @Override + public boolean containsKey(final @Nullable K key) { + return this.delegate.containsKey(key); + } + + @Override + public boolean containsListener(final @Nullable L listener) { + return this.delegate.containsListener(listener); + } + + @Contract(" -> fail") + @Override + public void clear() throws UnsupportedOperationException { + throw new UnsupportedOperationException("View does not support modification"); + } + + @Override + public void forEach(final @NotNull BiConsumer action) { + this.delegate.forEach(action); + } + + @Contract("_, _ -> fail") + @Override + public boolean replace( + final @NotNull L oldListener, + final @NotNull L newListener + ) throws UnsupportedOperationException { + throw new UnsupportedOperationException("View does not support modification"); + } + + @Contract("_ -> fail") + @Override + public void replaceAll(final @NotNull BiFunction function) throws UnsupportedOperationException { + throw new UnsupportedOperationException("View does not support modification"); + } + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/listener/handler/AbstractHandlerParams.java b/lib/common/src/main/java/com/minersstudios/wholib/listener/handler/AbstractHandlerParams.java new file mode 100644 index 00000000..7bed3b34 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/listener/handler/AbstractHandlerParams.java @@ -0,0 +1,65 @@ +package com.minersstudios.wholib.listener.handler; + +import com.minersstudios.wholib.order.Order; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.concurrent.Immutable; + +/** + * An immutable abstract class that represents the parameters of a handler + * + * @param The order type + */ +@Immutable +public abstract class AbstractHandlerParams> + implements HandlerParams { + + private final O order; + + protected AbstractHandlerParams(final @NotNull O order) { + this.order = order; + } + + @Override + public final @NotNull O getOrder() { + return this.order; + } + + @Override + public int compareTo(final @NotNull HandlerParams other) { + return this.compareByOrder(other); + } + + @Override + public int hashCode() { + return 31 + this.getOrder().hashCode(); + } + + @SuppressWarnings("unchecked") + @Contract("null -> false") + @Override + public boolean equals(final @Nullable Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof HandlerParams that) { + final O thisOrder = this.getOrder(); + final var thatOrder = that.getOrder(); + + return thisOrder.getClass().isInstance(thatOrder) + && thisOrder.isEqualTo((O) thatOrder); + } + + return false; + } + + @Override + public @NotNull String toString() { + return this.getClass().getSimpleName() + '{' + + "order=" + this.order + + '}'; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/listener/handler/HandlerParams.java b/lib/common/src/main/java/com/minersstudios/wholib/listener/handler/HandlerParams.java new file mode 100644 index 00000000..b29564ff --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/listener/handler/HandlerParams.java @@ -0,0 +1,45 @@ +package com.minersstudios.wholib.listener.handler; + +import com.minersstudios.wholib.order.Order; +import com.minersstudios.wholib.order.Ordered; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.concurrent.Immutable; + +/** + * Represents the parameters of a handler + * + * @param The order type + */ +@Immutable +public interface HandlerParams> extends Ordered, Comparable> { + + /** + * Returns a hash code value for this handler params + * + * @return A hash code value for this handler params + */ + @Override + int hashCode(); + + /** + * Indicates whether some other object is {@code equal to} this + * handler params + * + * @param obj The reference object with which to compare + * @return True if this object is the same as the obj argument + */ + @Contract("null -> false") + @Override + boolean equals(final @Nullable Object obj); + + /** + * Returns a string representation of this handler params + * + * @return A string representation of this handler params + */ + @Override + @NotNull String toString(); +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/locale/LanguageFile.java b/lib/common/src/main/java/com/minersstudios/wholib/locale/LanguageFile.java new file mode 100644 index 00000000..4909f214 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/locale/LanguageFile.java @@ -0,0 +1,167 @@ +package com.minersstudios.wholib.locale; + +import com.google.common.base.Joiner; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.jetbrains.annotations.*; + +import javax.annotation.concurrent.Immutable; +import java.util.Collections; +import java.util.Locale; +import java.util.Map; + +/** + * Represents a language file containing translations for a specific locale + */ +@SuppressWarnings("unused") +@Immutable +public class LanguageFile { + + private final Locale locale; + private final Map translationMap; + + /** + * Constructs a new language file with the given locale + * + * @param locale The locale of the language file + */ + public LanguageFile( + final @NotNull Locale locale, + final @NotNull Map translationMap + ) { + this.locale = locale; + this.translationMap = new Object2ObjectOpenHashMap<>(translationMap); + } + + /** + * Returns the locale of this language file + * + * @return The locale of this language file + */ + public @NotNull Locale getLocale() { + return this.locale; + } + + /** + * Returns the unmodifiable map of translations in this language file + * + * @return The unmodifiable map of translations in this language file + */ + public @NotNull @Unmodifiable Map getTranslationMap() { + return Collections.unmodifiableMap(this.translationMap); + } + + /** + * Gets the translation for the given path + * + * @param path The path to get the translation for + * @return The translation for the given path, or null if it doesn't exist + */ + public @Nullable String get(final @NotNull String path) { + return this.getOrDefault(path, null); + } + + /** + * Gets the translation for the given path, or the fallback if it doesn't + * exist + * + * @param path The path to get the translation for + * @param fallback The fallback to return if the translation doesn't exist + * @return The translation for the given path, or the fallback if it doesn't + * exist + */ + public @UnknownNullability String getOrDefault( + final @NotNull String path, + final @Nullable String fallback + ) { + return this.translationMap.getOrDefault(path, fallback); + } + + /** + * Returns the number of translations in this language file + * + * @return The number of translations in this language file + */ + public int size() { + return this.translationMap.size(); + } + + /** + * Returns a hash code based on the locale and translations + * + * @return A hash code based on the locale and translations + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + this.locale.hashCode(); + result = prime * result + this.translationMap.hashCode(); + + return result; + } + + /** + * Compares the specified object with this language file for equality + * + * @param obj The object to compare + * @return True if the object is a language file and has the same locale and + * translations + */ + @Contract("null -> false") + @Override + public boolean equals(final @Nullable Object obj) { + return this == obj + || ( + obj instanceof LanguageFile that + && this.getLocale().equals(that.getLocale()) + && this.getTranslationMap().equals(that.getTranslationMap()) + ); + } + + /** + * Checks whether the given path exists in this language file + * + * @param path The path to check for + * @return Whether the given path exists in this language file + */ + public boolean containsPath(final @NotNull String path) { + return this.translationMap.containsKey(path); + } + + /** + * Returns whether this language file contains the given translation + * + * @param translation The translation to check for + * @return True if this language file contains the given translation + */ + public boolean containsTranslation(final @NotNull String translation) { + return this.translationMap.containsValue(translation); + } + + /** + * Returns whether this language file contains no translations + * + * @return True if this language file contains no translations + */ + public boolean isEmpty() { + return this.translationMap.isEmpty(); + } + + /** + * Returns a string representation of this language file + * + * @return A string representation of this language file containing the + * translations + */ + @Override + public @NotNull String toString() { + return this.getClass().getSimpleName() + + "{locale=" + this.locale + + ", translations=[" + + Joiner.on(", ") + .withKeyValueSeparator("=") + .join(this.translationMap) + + "]}"; + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/locale/Translation.java b/lib/common/src/main/java/com/minersstudios/wholib/locale/Translation.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/locale/Translation.java rename to lib/common/src/main/java/com/minersstudios/wholib/locale/Translation.java index 8517565b..b2b45acd 100644 --- a/paper/src/main/java/com/minersstudios/whomine/locale/Translation.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/locale/Translation.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.locale; +package com.minersstudios.wholib.locale; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; @@ -12,12 +12,14 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import static com.minersstudios.whomine.locale.TranslationRegistry.registry; +import static com.minersstudios.wholib.locale.TranslationRegistry.registry; /** * Represents a translation */ +@SuppressWarnings("unused") public final class Translation { + private final String path; private final MessageFormat fallback; private final Map map; @@ -251,7 +253,7 @@ public boolean equals(final @Nullable Object obj) { builder.setLength(builder.length() - 2); } - return "Translation{" + + return this.getClass().getSimpleName() + '{' + "path=" + this.path + ", fallback=" + this.fallback + ", translations=[" + builder + ']' + diff --git a/paper/src/main/java/com/minersstudios/whomine/locale/TranslationRegistry.java b/lib/common/src/main/java/com/minersstudios/wholib/locale/TranslationRegistry.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/locale/TranslationRegistry.java rename to lib/common/src/main/java/com/minersstudios/wholib/locale/TranslationRegistry.java index 4aa5b828..d4775849 100644 --- a/paper/src/main/java/com/minersstudios/whomine/locale/TranslationRegistry.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/locale/TranslationRegistry.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.locale; +package com.minersstudios.wholib.locale; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.annotation.Resource; import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TranslatableComponent; @@ -15,6 +15,7 @@ import java.util.Locale; import java.util.Map; +@SuppressWarnings("unused") public interface TranslationRegistry extends Translator { /** @@ -301,7 +302,7 @@ static void bootstrap(final @NotNull Locale defaultLocale) throws IllegalStateEx TranslationRegistryImpl.registry = new TranslationRegistryImpl( - Key.key(SharedConstants.WHOMINE_NAMESPACE, "translations"), + Key.key(Resource.WHOMINE, "translations"), defaultLocale ); } diff --git a/paper/src/main/java/com/minersstudios/whomine/locale/TranslationRegistryImpl.java b/lib/common/src/main/java/com/minersstudios/wholib/locale/TranslationRegistryImpl.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/locale/TranslationRegistryImpl.java rename to lib/common/src/main/java/com/minersstudios/wholib/locale/TranslationRegistryImpl.java index af4d6244..039eb0f6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/locale/TranslationRegistryImpl.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/locale/TranslationRegistryImpl.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.locale; +package com.minersstudios.wholib.locale; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.utility.ChatUtils; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; @@ -16,13 +16,13 @@ import java.util.concurrent.ConcurrentHashMap; final class TranslationRegistryImpl implements TranslationRegistry { + static volatile TranslationRegistryImpl registry; + private final Key name; private final Locale defaultLocale; private final Map translationMap; private final TranslatableComponentRenderer renderer; - static volatile TranslationRegistryImpl registry; - TranslationRegistryImpl( final @NotNull Key name, final @NotNull Locale defaultLocale @@ -32,6 +32,7 @@ final class TranslationRegistryImpl implements TranslationRegistry { this.translationMap = new ConcurrentHashMap<>(); this.renderer = new TranslatableComponentRenderer<>() { + @Override protected @Nullable MessageFormat translate( final @NotNull String path, final @NotNull Locale locale @@ -39,6 +40,7 @@ final class TranslationRegistryImpl implements TranslationRegistry { return this.translate(path, null, locale); } + @Override protected @Nullable MessageFormat translate( final @NotNull String path, final @Nullable String fallback, @@ -51,6 +53,7 @@ final class TranslationRegistryImpl implements TranslationRegistry { : translation.translateNullable(locale); } + @Override protected @NotNull Component renderTranslatable( final @NotNull TranslatableComponent component, final @NotNull Locale locale @@ -82,10 +85,12 @@ final class TranslationRegistryImpl implements TranslationRegistry { return this.renderer; } + @Override public @Nullable Translation getTranslation(final @NotNull String path) { return this.translationMap.get(path); } + @Override public @NotNull Translation getTranslation( final @NotNull String path, final @Nullable String fallback diff --git a/paper/src/main/java/com/minersstudios/whomine/locale/Translations.java b/lib/common/src/main/java/com/minersstudios/wholib/locale/Translations.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/locale/Translations.java rename to lib/common/src/main/java/com/minersstudios/wholib/locale/Translations.java index f657cbdb..760f2d01 100644 --- a/paper/src/main/java/com/minersstudios/whomine/locale/Translations.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/locale/Translations.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.locale; +package com.minersstudios.wholib.locale; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.utility.SharedConstants; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static com.minersstudios.whomine.locale.TranslationRegistry.registry; -import static com.minersstudios.whomine.utility.Font.Chars.*; +import static com.minersstudios.wholib.locale.TranslationRegistry.registry; +import static com.minersstudios.wholib.utility.Font.Chars.*; /** - * This class stores all translations used in the WhoMine plugins + * This class stores all translations used in the API * * @see Translation * @see Default translation repository @@ -372,13 +372,13 @@ private Translations() throws AssertionError { } private static @NotNull Translation register( - final @NotNull String key, + final @NotNull String path, final @Nullable String translation ) { return translation == null - ? registry().registerPath(key) + ? registry().registerPath(path) : registry().register( - key, + path, SharedConstants.DEFAULT_LOCALE, translation ); diff --git a/paper/src/main/java/com/minersstudios/whomine/locale/resource/FileTranslationResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/locale/resource/FileTranslationResourceManager.java similarity index 69% rename from paper/src/main/java/com/minersstudios/whomine/locale/resource/FileTranslationResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/locale/resource/FileTranslationResourceManager.java index f5cd782f..e9fb6df6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/locale/resource/FileTranslationResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/locale/resource/FileTranslationResourceManager.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.locale.resource; +package com.minersstudios.wholib.locale.resource; -import com.minersstudios.whomine.resource.file.AbstractFileResourceManager; +import com.minersstudios.wholib.resource.file.AbstractFileResourceManager; import org.jetbrains.annotations.NotNull; import java.io.File; diff --git a/paper/src/main/java/com/minersstudios/whomine/locale/resource/GitHubTranslationResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/locale/resource/GitHubTranslationResourceManager.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/locale/resource/GitHubTranslationResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/locale/resource/GitHubTranslationResourceManager.java index 8020de58..8c5a7daf 100644 --- a/paper/src/main/java/com/minersstudios/whomine/locale/resource/GitHubTranslationResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/locale/resource/GitHubTranslationResourceManager.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.locale.resource; +package com.minersstudios.wholib.locale.resource; -import com.minersstudios.whomine.resource.github.AbstractGithubResourceManager; +import com.minersstudios.wholib.resource.github.AbstractGithubResourceManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -8,10 +8,10 @@ import java.net.URI; public final class GitHubTranslationResourceManager extends AbstractGithubResourceManager implements TranslationResourceManager { - private final String folderPath; - private static final String DOWNLOAD_TRANSLATION_URL = "https://raw.githubusercontent.com/%s/%s/%s/%s"; + private final String folderPath; + GitHubTranslationResourceManager( final @NotNull File file, final @NotNull String user, diff --git a/paper/src/main/java/com/minersstudios/whomine/locale/resource/TranslationResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/locale/resource/TranslationResourceManager.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/locale/resource/TranslationResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/locale/resource/TranslationResourceManager.java index d72bc47b..d957c82f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/locale/resource/TranslationResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/locale/resource/TranslationResourceManager.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.locale.resource; +package com.minersstudios.wholib.locale.resource; -import com.minersstudios.whomine.resource.ResourceManager; +import com.minersstudios.wholib.resource.ResourceManager; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/paper/src/main/java/com/minersstudios/whomine/locale/resource/URITranslationResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/locale/resource/URITranslationResourceManager.java similarity index 69% rename from paper/src/main/java/com/minersstudios/whomine/locale/resource/URITranslationResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/locale/resource/URITranslationResourceManager.java index e7af73d8..27232d06 100644 --- a/paper/src/main/java/com/minersstudios/whomine/locale/resource/URITranslationResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/locale/resource/URITranslationResourceManager.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.locale.resource; +package com.minersstudios.wholib.locale.resource; -import com.minersstudios.whomine.resource.uri.AbstractURIResourceManager; +import com.minersstudios.wholib.resource.uri.AbstractURIResourceManager; import org.jetbrains.annotations.NotNull; import java.net.URI; diff --git a/lib/common/src/main/java/com/minersstudios/wholib/module/AbstractModuleComponent.java b/lib/common/src/main/java/com/minersstudios/wholib/module/AbstractModuleComponent.java new file mode 100644 index 00000000..db14da2f --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/module/AbstractModuleComponent.java @@ -0,0 +1,27 @@ +package com.minersstudios.wholib.module; + +import org.jetbrains.annotations.NotNull; + +public abstract class AbstractModuleComponent implements ModuleComponent { + + private final M module; + + /** + * Module component constructor + * + * @param module The module instance + */ + protected AbstractModuleComponent(final @NotNull M module) { + this.module = module; + } + + @Override + public final @NotNull M getModule() { + return this.module; + } + + @Override + public @NotNull String toString() { + return this.getClass().getSimpleName() + "{module=" + this.module + "}"; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/module/MainModule.java b/lib/common/src/main/java/com/minersstudios/wholib/module/MainModule.java new file mode 100644 index 00000000..2308c6a8 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/module/MainModule.java @@ -0,0 +1,116 @@ +package com.minersstudios.wholib.module; + +import com.minersstudios.wholib.module.components.Cache; +import com.minersstudios.wholib.module.components.Configuration; +import com.minersstudios.wholib.status.FailureStatus; +import com.minersstudios.wholib.status.SuccessStatus; +import org.jetbrains.annotations.NotNull; + +import static com.minersstudios.wholib.status.Status.*; + +/** + * Represents a WhoMine module + */ +public interface MainModule> extends Module { + // + /** High-priority module loading status */ + SuccessStatus LOADING = successHigh("LOADING"); + /** Low-priority module loaded status */ + SuccessStatus LOADED = successLow("LOADED"); + + /** High-priority module enabling status */ + SuccessStatus ENABLING = successHigh("ENABLING"); + /** High-priority module enabled status */ + SuccessStatus ENABLED = successHigh("ENABLED"); + + /** High-priority module disabling status */ + SuccessStatus DISABLING = successHigh("DISABLING"); + /** High-priority module disabled status */ + SuccessStatus DISABLED = successHigh("DISABLED"); + + /** Failed low-priority status for loading cache */ + FailureStatus FAILED_LOAD_CACHE = failureLow("FAILED_LOAD_CACHE"); + /** Low-priority module loading cache status */ + SuccessStatus LOADING_CACHE = successLow("LOADING_CACHE"); + /** Low-priority module loaded cache status */ + SuccessStatus LOADED_CACHE = successLow("LOADED_CACHE", FAILED_LOAD_CACHE); + + /** Failed low-priority status for loading config */ + FailureStatus FAILED_LOAD_CONFIG = failureLow("FAILED_LOAD_CONFIG"); + /** Low-priority module loading config status */ + SuccessStatus LOADING_CONFIG = successLow("LOADING_CONFIG"); + /** Low-priority module loaded config status */ + SuccessStatus LOADED_CONFIG = successLow("LOADED_CONFIG", FAILED_LOAD_CONFIG); + + /** Low-priority module loading languages.yml status */ + SuccessStatus LOADING_LANGUAGES = successLow("LOADING_LANGUAGES"); + /** Low-priority module loaded languages.yml status */ + SuccessStatus LOADED_LANGUAGES = successLow("LOADED_LANGUAGES"); + + /** Low-priority module decorations loading status */ + SuccessStatus LOADING_DECORATIONS = successLow("LOADING_DECORATIONS"); + /** Low-priority module decorations loaded status */ + SuccessStatus LOADED_DECORATIONS = successLow("LOADED_DECORATIONS"); + + /** Failed low-priority status for loading blocks */ + FailureStatus FAILED_LOAD_BLOCKS = failureLow("FAILED_LOAD_BLOCKS"); + /** Low-priority module loading blocks status */ + SuccessStatus LOADING_BLOCKS = successLow("LOADING_BLOCKS"); + /** Low-priority module loaded blocks status */ + SuccessStatus LOADED_BLOCKS = successLow("LOADED_BLOCKS", FAILED_LOAD_BLOCKS); + + /** Failed low-priority status for loading items */ + SuccessStatus LOADING_ITEMS = successLow("LOADING_ITEMS"); + /** Low-priority module loaded items status */ + SuccessStatus LOADED_ITEMS = successLow("LOADED_ITEMS"); + + /** Failed low-priority status for loading decor */ + FailureStatus FAILED_LOAD_RENAMEABLES = failureLow("FAILED_LOAD_RENAMEABLES"); + /** Low-priority module loading decor status */ + SuccessStatus LOADING_RENAMEABLES = successLow("LOADING_RENAMEABLES"); + /** Low-priority module loaded decor status */ + SuccessStatus LOADED_RENAMEABLES = successLow("LOADED_RENAMEABLES", FAILED_LOAD_RENAMEABLES); + + /** Failed low-priority status for loading resource packs */ + FailureStatus FAILED_LOAD_RESOURCE_PACKS = failureLow("FAILED_LOAD_RESOURCE_PACKS"); + /** Low-priority module loading resource packs status */ + SuccessStatus LOADING_RESOURCE_PACKS = successLow("LOADING_RESOURCE_PACKS"); + /** Low-priority module loaded resource packs status */ + SuccessStatus LOADED_RESOURCE_PACKS = successLow("LOADED_RESOURCE_PACKS", FAILED_LOAD_RESOURCE_PACKS); + + /** Failed low-priority status for loading anomalies */ + FailureStatus FAILED_LOAD_ANOMALIES = failureLow("FAILED_LOAD_ANOMALIES"); + /** Low-priority module loading anomalies status */ + SuccessStatus LOADING_ANOMALIES = successLow("LOADING_ANOMALIES"); + /** Low-priority module loaded anomalies status */ + SuccessStatus LOADED_ANOMALIES = successLow("LOADED_ANOMALIES", FAILED_LOAD_ANOMALIES); + + /** Failed low-priority status for loading discord */ + FailureStatus FAILED_LOAD_DISCORD = failureLow("FAILED_LOAD_DISCORD"); + /** Low-priority module loading discord status */ + SuccessStatus LOADING_DISCORD = successLow("LOADING_DISCORD"); + /** Low-priority module loaded discord status */ + SuccessStatus LOADED_DISCORD = successLow("LOADED_DISCORD", FAILED_LOAD_DISCORD); + // + + /** + * Returns the cache of the module + * + * @return The cache of the module + */ + @NotNull Cache getCache(); + + /** + * Returns the configuration of the module + * + * @return The configuration of the module + */ + @NotNull Configuration getConfiguration(); + + /** + * Returns whether the module is fully loaded + * + * @return True if the module is fully loaded + */ + boolean isFullyLoaded(); +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/module/Module.java b/lib/common/src/main/java/com/minersstudios/wholib/module/Module.java new file mode 100644 index 00000000..c2743045 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/module/Module.java @@ -0,0 +1,14 @@ +package com.minersstudios.wholib.module; + +import com.minersstudios.wholib.status.StatusHandler; +import org.jetbrains.annotations.NotNull; + +public interface Module { + + /** + * Returns the status handler of the module + * + * @return The status handler of the module + */ + @NotNull StatusHandler getStatusHandler(); +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/module/ModuleComponent.java b/lib/common/src/main/java/com/minersstudios/wholib/module/ModuleComponent.java new file mode 100644 index 00000000..3fad2987 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/module/ModuleComponent.java @@ -0,0 +1,18 @@ +package com.minersstudios.wholib.module; + +import org.jetbrains.annotations.NotNull; + +/** + * Module component interface + * + * @param The module type + */ +public interface ModuleComponent { + + /** + * Returns the module that this component is associated with + * + * @return The module that this component is associated with + */ + @NotNull M getModule(); +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/module/RegistrableComponent.java b/lib/common/src/main/java/com/minersstudios/wholib/module/RegistrableComponent.java new file mode 100644 index 00000000..0b75afb3 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/module/RegistrableComponent.java @@ -0,0 +1,6 @@ +package com.minersstudios.wholib.module; + +import com.minersstudios.wholib.registrable.Registrable; + +public interface RegistrableComponent + extends ModuleComponent, Registrable {} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/module/components/Cache.java b/lib/common/src/main/java/com/minersstudios/wholib/module/components/Cache.java new file mode 100644 index 00000000..51c941b7 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/module/components/Cache.java @@ -0,0 +1,6 @@ +package com.minersstudios.wholib.module.components; + +import com.minersstudios.wholib.module.Module; +import com.minersstudios.wholib.module.ModuleComponent; + +public interface Cache extends ModuleComponent {} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/module/components/Configuration.java b/lib/common/src/main/java/com/minersstudios/wholib/module/components/Configuration.java new file mode 100644 index 00000000..ec68a1be --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/module/components/Configuration.java @@ -0,0 +1,12 @@ +package com.minersstudios.wholib.module.components; + +import com.minersstudios.wholib.module.Module; +import com.minersstudios.wholib.module.ModuleComponent; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public interface Configuration extends ModuleComponent { + + @NotNull File getFile(); +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/order/Order.java b/lib/common/src/main/java/com/minersstudios/wholib/order/Order.java new file mode 100644 index 00000000..206b68b9 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/order/Order.java @@ -0,0 +1,61 @@ +package com.minersstudios.wholib.order; + +import org.jetbrains.annotations.NotNull; + +/** + * An interface that represents an order + */ +@SuppressWarnings("unused") +public interface Order> extends Comparable { + + /** + * Returns the order as a number + * + * @return The order as a number + */ + int asNumber(); + + /** + * Returns whether this order is higher than the provided order + * + * @param other The order to compare + * @return Whether this order is higher than the provided order + */ + default boolean isHigherThan(final @NotNull O other) { + return this.compareTo(other) > 0; + } + + /** + * Returns whether this order is lower than the provided order + * + * @param other The order to compare + * @return Whether this order is lower than the provided order + */ + default boolean isLowerThan(final @NotNull O other) { + return this.compareTo(other) < 0; + } + + /** + * Returns whether this order is equal to the provided order + * + * @param other The order to compare + * @return Whether this order is equal to the provided order + */ + default boolean isEqualTo(final @NotNull O other) { + return this.compareTo(other) == 0; + } + + /** + * Compares this order to the provided order + * + * @param other The order to compare + * @return The value {@code 0} if this order is equal to the provided order; + * a value less than {@code 0} if this order is lower than the + * provided order; and a value greater than {@code 0} if this order + * is higher than the provided order + */ + @Override + default int compareTo(final @NotNull O other) { + return Integer.compare(this.asNumber(), other.asNumber()); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/order/Ordered.java b/lib/common/src/main/java/com/minersstudios/wholib/order/Ordered.java new file mode 100644 index 00000000..ab8d637f --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/order/Ordered.java @@ -0,0 +1,175 @@ +package com.minersstudios.wholib.order; + +import com.minersstudios.wholib.event.EventOrder; +import org.jetbrains.annotations.NotNull; + +/** + * An interface that represents an object that can be ordered + * + * @param The type of the object to compare + * + * @see EventOrder + */ +@SuppressWarnings("unused") +public interface Ordered> { + + /** + * Returns the order of this object + * + * @return The order of this object + */ + @NotNull O getOrder(); + + /** + * Returns whether this object is higher than the provided object using + * the {@link #compareByOrder(Order)} method + * + * @param other The object to compare + * @return Whether this object is higher than the provided object + * @see #compareByOrder(Order) + */ + default boolean isHigherThan(final @NotNull O other) { + return this.compareByOrder(other) > 0; + } + + /** + * Returns whether this object is higher than or equal to the provided + * object using the {@link #compareByOrder(Order)} method + * + * @param other The object to compare + * @return Whether this object is higher or equal than the provided object + * @see #compareByOrder(Order) + */ + default boolean isHigherOrEqualThan(final @NotNull O other) { + return this.compareByOrder(other) >= 0; + } + + /** + * Returns whether this object is higher than or equal to (if {@code orEqual} + * is {@code true}) the provided object using the {@link #compareByOrder(Order)} + * method + * + * @param other The object to compare + * @param orEqual Whether to check if this object is equal to the provided + * object + * @return Whether this object is higher or equal than the provided object + * @see #compareByOrder(Order) + */ + default boolean isHigherThan( + final @NotNull O other, + final boolean orEqual + ) { + return orEqual ? isHigherOrEqualThan(other) : isHigherThan(other); + } + + /** + * Returns whether this object is lower than the provided object using + * the {@link #compareByOrder(Order)} method + * + * @param other The object to compare + * @return Whether this object is lower than the provided object + * @see #compareByOrder(Order) + */ + default boolean isLowerThan(final @NotNull O other) { + return this.compareByOrder(other) < 0; + } + + /** + * Returns whether this object is lower than or equal to the provided + * object using the {@link #compareByOrder(Order)} method + * + * @param other The object to compare + * @return Whether this object is lower or equal than the provided object + * @see #compareByOrder(Order) + */ + default boolean isLowerOrEqualThan(final @NotNull O other) { + return this.compareByOrder(other) <= 0; + } + + /** + * Returns whether this object is lower than or equal to (if {@code orEqual} + * is {@code true}) the provided object using the {@link #compareByOrder(Order)} + * method + * + * @param other The object to compare + * @param orEqual Whether to check if this object is equal to the provided + * object + * @return Whether this object is lower or equal than the provided object + * @see #compareByOrder(Order) + */ + default boolean isLowerThan( + final @NotNull O other, + final boolean orEqual + ) { + return orEqual ? isLowerOrEqualThan(other) : isLowerThan(other); + } + + /** + * Returns whether this object is equal to the provided object using the + * {@link #compareByOrder(Order)} method + * + * @param other The object to compare + * @return Whether this object is equal to the provided object + * @see #compareByOrder(Order) + */ + default boolean isEqualTo(final @NotNull O other) { + return this.compareByOrder(other) == 0; + } + + /** + * Compares this object with the specified order + * + * @param order The order to compare + * @return The value {@code 0} if this order is equal to the provided order; + * a value less than {@code 0} if this order is lower than the + * provided order; and a value greater than {@code 0} if this order + * is higher than the provided order + */ + default int compareByOrder(final @NotNull O order) { + return this.getOrder().compareTo(order); + } + + /** + * Compares this object with the specified ordered object with the same + * order type + * + * @param ordered The ordered object to compare + * @return The value {@code 0} if this order is equal to the provided order; + * a value less than {@code 0} if this order is lower than the + * provided order; and a value greater than {@code 0} if this order + * is higher than the provided order + */ + default int compareByOrder(final @NotNull Ordered ordered) { + return this.compareByOrder(ordered.getOrder()); + } + + /** + * Compares this object with the specified order by its + * {@link Order#asNumber() order number} bypassing overridden + * {@link Order#compareTo(Order)} methods + * + * @param order The order to compare + * @return The value {@code 0} if this order is equal to the provided order; + * a value less than {@code 0} if this order is lower than the + * provided order; and a value greater than {@code 0} if this order + * is higher than the provided order + */ + default int rawCompareByOrder(final @NotNull Order order) { + return Integer.compare(this.getOrder().asNumber(), order.asNumber()); + } + + /** + * Compares this object with the specified ordered object by its + * {@link Order#asNumber() order number} bypassing overridden + * {@link Order#compareTo(Order)} methods + * + * @param ordered The ordered object to compare + * @return The value {@code 0} if this order is equal to the provided order; + * a value less than {@code 0} if this order is lower than the + * provided order; and a value greater than {@code 0} if this order + * is higher than the provided order + */ + default int rawCompareByOrder(final @NotNull Ordered ordered) { + return ordered.rawCompareByOrder(this.getOrder()); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/order/package-info.java b/lib/common/src/main/java/com/minersstudios/wholib/order/package-info.java new file mode 100644 index 00000000..5cfe85fe --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/order/package-info.java @@ -0,0 +1,14 @@ +/** + * This package contains the classes that are used to represent the order of the + * ordered objects in the API. + *

+ * It contains : + *

    + *
  • {@link com.minersstudios.wholib.order.Order} + * - An interface that represents an order
  • + *
  • {@link com.minersstudios.wholib.order.Ordered} + * - An interface that represents an object that can be ordered by the + * order
  • + *
+ */ +package com.minersstudios.wholib.order; diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketBound.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketBound.java new file mode 100644 index 00000000..b508321d --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketBound.java @@ -0,0 +1,131 @@ +package com.minersstudios.wholib.packet; + +import com.minersstudios.wholib.annotation.Path; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; + +import java.util.Locale; + +/** + * This enum represents a packet's bound in the Minecraft server networking. + *

+ * Available bounds are: + *

    + *
  • {@link #SERVERBOUND} - from the client to the server
  • + *
  • {@link #CLIENTBOUND} - from the server to the client
  • + *
+ * + * @see PacketType + * @see PacketProtocol + */ +@SuppressWarnings("unused") +public enum PacketBound { + /** The serverbound packet flow */ + SERVERBOUND("serverbound"), + /** The clientbound packet flow */ + CLIENTBOUND("clientbound"); + + private static final PacketBound[] VALUES = values(); + + private final String id; + + /** + * Packet bound constructor + * + * @param id The state ID of the bound + */ + PacketBound(final @Path @NotNull String id) { + this.id = id; + } + + /** + * Returns the state ID of the bound + * + * @return The state ID of the bound + */ + public @Path @NotNull String getId() { + return this.id; + } + + /** + * Returns the opposite bound + * + * @return The opposite bound + */ + public @NotNull PacketBound getOpposite() { + return this == CLIENTBOUND + ? SERVERBOUND + : CLIENTBOUND; + } + + /** + * Returns all available bounds as an array + * + * @return All available bounds as an array + */ + public static PacketBound @NotNull [] bounds() { + return VALUES; + } + + /** + * Returns the bound from the given ordinal + * + * @param ordinal The ordinal of the bound + * @return The bound from the given ordinal + * @throws ArrayIndexOutOfBoundsException If the ordinal is out of bounds + */ + public static @NotNull PacketBound byOrdinal(final @Range(from = 0, to = 1) int ordinal) throws ArrayIndexOutOfBoundsException { + return VALUES[ordinal]; + } + + /** + * Returns the bound from the given state ID (case-insensitive) + * + * @param id The state ID of the bound + * @return The bound from the given ID + * @throws EnumConstantNotPresentException If the state ID is unknown + */ + public static @NotNull PacketBound fromId(final @Path @NotNull String id) throws EnumConstantNotPresentException { + return dummyId(id.toLowerCase(Locale.ENGLISH)); + } + + /** + * Returns the bound from the given state ID (case-sensitive) + * + * @param id The state ID of the bound + * @return The bound from the given ID + * @throws EnumConstantNotPresentException If the state ID is unknown + */ + public static @NotNull PacketBound dummyId(final @Path @NotNull String id) throws EnumConstantNotPresentException { + return switch (id) { + case "serverbound" -> SERVERBOUND; + case "clientbound" -> CLIENTBOUND; + default -> throw new EnumConstantNotPresentException(PacketBound.class, id); + }; + } + + /** + * Returns the bound from the given state ID (case-insensitive) + * + * @param id The state ID of the bound + * @return The bound from the given ID, or null if the state ID is unknown + */ + public static @Nullable PacketBound fromIdOrNull(final @Path @NotNull String id) { + return dummyIdOrNull(id.toLowerCase(Locale.ENGLISH)); + } + + /** + * Returns the bound from the given state ID (case-sensitive) + * + * @param id The state ID of the bound + * @return The bound from the given ID, or null if the state ID is unknown + */ + public static @Nullable PacketBound dummyIdOrNull(final @Path @NotNull String id) { + return switch (id) { + case "serverbound" -> SERVERBOUND; + case "clientbound" -> CLIENTBOUND; + default -> null; + }; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketContainer.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketContainer.java new file mode 100644 index 00000000..2c6b1757 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketContainer.java @@ -0,0 +1,39 @@ +package com.minersstudios.wholib.packet; + +import com.minersstudios.wholib.event.CancellableEventContainer; +import com.minersstudios.wholib.event.EventContainer; +import com.minersstudios.wholib.module.Module; +import org.jetbrains.annotations.NotNull; + +/** + * Represents a packet container. + *

+ * It contains : + *

    + *
  • The module that registers and handles the packet event
  • + *
  • The packet event itself
  • + *
+ * + * @param The module type, that registers and handles the packet event + * @param The packet event type + * + * @see PacketEvent + * @see PacketListener + * @see EventContainer + */ +@SuppressWarnings("unused") +public abstract class PacketContainer> extends CancellableEventContainer { + + /** + * Packet container constructor + * + * @param module The module that registers and handles the packet event + * @param packetEvent The packet event associated with this packet container + */ + protected PacketContainer( + final @NotNull M module, + final @NotNull E packetEvent + ) { + super(module, packetEvent); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketEvent.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketEvent.java new file mode 100644 index 00000000..24cc189f --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketEvent.java @@ -0,0 +1,87 @@ +package com.minersstudios.wholib.packet; + +import org.jetbrains.annotations.NotNull; + +/** + * Represents a packet event. + *

+ * It contains the packet type, the packet and the connection who sent or + * received the packet. + * + * @param

The packet type + * @param The connection type + * + * @see PacketContainer + * @see PacketListener + */ +@SuppressWarnings("unused") +public abstract class PacketEvent { + + private final PacketType type; + private final P packet; + private final C connection; + private boolean cancelled; + + /** + * Constructs a new packet event + * + * @param type The packet type + * @param packet The packet + * @param connection The connection who sent or received the packet + */ + protected PacketEvent( + final @NotNull PacketType type, + final @NotNull P packet, + final @NotNull C connection + ) { + this.type = type; + this.packet = packet; + this.connection = connection; + } + + /** + * Returns the packet type + * + * @return The packet type + */ + public final @NotNull PacketType getType() { + return this.type; + } + + /** + * Returns the packet + * + * @return The packet + */ + public final @NotNull P getPacket() { + return this.packet; + } + + /** + * Returns the connection who sent or received the packet + * + * @return The connection who sent or received the packet + */ + public final @NotNull C getConnection() { + return this.connection; + } + + /** + * Sets the cancellation state of this event. A cancelled event will not be + * sent or received. + * + * @param cancel True if you wish to cancel this event + */ + public final void setCancelled(final boolean cancel) { + this.cancelled = cancel; + } + + /** + * Returns the cancellation state of this event + * + * @return True if this event is cancelled + */ + public final boolean isCancelled() { + return this.cancelled; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketListener.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketListener.java new file mode 100644 index 00000000..1751b52c --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketListener.java @@ -0,0 +1,68 @@ +package com.minersstudios.wholib.packet; + +import com.minersstudios.wholib.event.handle.HandlerExecutor; +import com.minersstudios.wholib.event.EventListener; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.handler.HandlerParams; +import com.minersstudios.wholib.listener.ListenerManager; +import com.minersstudios.wholib.registrable.Registrable; +import com.minersstudios.wholib.throwable.ListenerException; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.Annotation; +import java.util.function.Function; + +/** + * An abstract class that represents a packet listener. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available optional overridable methods
MethodDescription
{@link #onRegister()} + * Called when the listener is registered by a manager in the + * {@link ListenerManager#register(Registrable)} method + *
{@link #onUnregister()} + * Called when the listener is unregistered by a manager in the + * {@link ListenerManager#unregister(Registrable)} method + *
+ * + * @param The packet container type of the event listener + * + * @see PacketContainer + * @see HandlerExecutor + */ +@SuppressWarnings("unused") +public abstract class PacketListener> + extends EventListener { + + /** + * Constructs a new packet listener with the specified packet type. + *

+ * This constructor will automatically retrieve all handlers from the + * listener class. + * + * @param packetType The packet type of the packet listener + * @param annotationClass The annotation class of the event handler + * @param executorFunction The function to retrieve the handler parameters + * from the annotation + * @throws ListenerException If the listener has duplicate handlers for the + * same order + */ + protected PacketListener( + final @NotNull PacketType packetType, + final @NotNull Class annotationClass, + final @NotNull Function> executorFunction + ) throws ListenerException { + super(packetType, annotationClass, executorFunction); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketProtocol.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketProtocol.java new file mode 100644 index 00000000..175a4a37 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketProtocol.java @@ -0,0 +1,203 @@ +package com.minersstudios.wholib.packet; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.packet.registry.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; + +import java.util.Locale; + +/** + * Represents the different packet protocols used in Minecraft. + *

+ * Each protocol corresponds to a specific phase in the network connection + * process. + *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available Protocols
ProtocolRegistry
{@link #HANDSHAKING}{@link HandshakePackets}
{@link #PLAY}{@link PlayPackets}
{@link #STATUS}{@link StatusPackets}
{@link #LOGIN}{@link LoginPackets}
{@link #CONFIGURATION}{@link ConfigurationPackets}
+ * + * @see PacketRegistry + */ +@SuppressWarnings("unused") +public enum PacketProtocol { + /** + * The handshake protocol + * + * @see HandshakePackets + * @see
Protocol Wiki - Handshake + */ + HANDSHAKING("handshake", HandshakePackets.registry()), + /** + * The play protocol + * + * @see PlayPackets + * @see Protocol Wiki - Play + */ + PLAY("play", PlayPackets.registry()), + /** + * The status protocol + * + * @see StatusPackets + * @see Protocol Wiki - Status + */ + STATUS("status", StatusPackets.registry()), + /** + * The login protocol + * + * @see LoginPackets + * @see Protocol Wiki - Login + */ + LOGIN("login", LoginPackets.registry()), + /** + * The configuration protocol + * + * @see ConfigurationPackets + * @see Protocol Wiki - Configuration + */ + CONFIGURATION("configuration", ConfigurationPackets.registry()); + + private static final PacketProtocol[] VALUES = values(); + + private final String id; + private final PacketRegistry registry; + + /** + * Constructor for the {@link PacketProtocol} enum + * + * @param id The state ID of this protocol + * @param registry The packet registry of this protocol + */ + PacketProtocol( + final @Path @NotNull String id, + final @NotNull PacketRegistry registry + ) { + this.id = id; + this.registry = registry; + } + + /** + * Returns the state ID of this protocol. + *

+ * The ID is the same as the ID of the Minecraft protocol. + * + * @return The state ID of this protocol + */ + public @NotNull String getId() { + return this.id; + } + + /** + * Returns the packet registry of this protocol + * + * @return The packet registry of this protocol + */ + public @NotNull PacketRegistry getRegistry() { + return this.registry; + } + + /** + * Returns all available protocols as an array + * + * @return All available protocols as an array + */ + public static PacketProtocol @NotNull [] protocols() { + return VALUES; + } + + /** + * Returns the protocol from the given ordinal + * + * @param ordinal The ordinal of the protocol + * @return The protocol from the given ordinal + * @throws ArrayIndexOutOfBoundsException If the ordinal is out of bounds + */ + public static @NotNull PacketProtocol byOrdinal(final @Range(from = 0, to = 4) int ordinal) throws ArrayIndexOutOfBoundsException { + return VALUES[ordinal]; + } + + /** + * Returns the protocol from the given state ID (case-insensitive) + * + * @param id The ID of the protocol + * @return The protocol from the given state ID + * @throws EnumConstantNotPresentException If the state ID is unknown + * @see #dummyId(String) + */ + public static @NotNull PacketProtocol fromId(final @Path @NotNull String id) throws EnumConstantNotPresentException { + return dummyId(id.toLowerCase(Locale.ENGLISH)); + } + + /** + * Returns the protocol from the given state ID (case-sensitive) + * + * @param id The ID of the protocol + * @return The protocol from the given state ID + * @throws EnumConstantNotPresentException If the state ID is unknown + * @see #fromId(String) + */ + public static @NotNull PacketProtocol dummyId(final @Path @NotNull String id) throws EnumConstantNotPresentException { + return switch (id) { + case "handshake" -> HANDSHAKING; + case "play" -> PLAY; + case "status" -> STATUS; + case "login" -> LOGIN; + case "configuration" -> CONFIGURATION; + default -> throw new EnumConstantNotPresentException(PacketProtocol.class, id); + }; + } + + /** + * Returns the protocol from the given state ID (case-insensitive) + * + * @param id The ID of the protocol + * @return The protocol from the given state ID or null if the ID is unknown + * @see #dummyIdOrNull(String) + */ + public static @Nullable PacketProtocol fromIdOrNull(final @Path @NotNull String id) { + return dummyIdOrNull(id.toLowerCase(Locale.ENGLISH)); + } + + /** + * Returns the protocol from the given state ID (case-sensitive) + * + * @param id The ID of the protocol + * @return The protocol from the given state ID or null if the ID is unknown + * @see #fromIdOrNull(String) + */ + public static @Nullable PacketProtocol dummyIdOrNull(final @Path @NotNull String id) { + return switch (id) { + case "handshake" -> HANDSHAKING; + case "play" -> PLAY; + case "status" -> STATUS; + case "login" -> LOGIN; + case "configuration" -> CONFIGURATION; + default -> null; + }; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketRegistry.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketRegistry.java new file mode 100644 index 00000000..f713b0d2 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketRegistry.java @@ -0,0 +1,168 @@ +package com.minersstudios.wholib.packet; + +import com.minersstudios.wholib.packet.collection.Class2PacketMap; +import com.minersstudios.wholib.packet.collection.PacketMap; +import com.minersstudios.wholib.packet.collection.Path2PacketMap; +import com.minersstudios.wholib.packet.registry.*; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents a packet registry, which contains the packet maps. + *

+ * The packet registry contains two packet maps: + *

    + *
  • The path packet map, which maps the packet's path to the packet + * type
  • + *
  • The class packet map, which maps the packet's class to the packet + * type
  • + *
+ *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available factory methods
MethodDescription
{@link #create(Path2PacketMap)}Creates a new packet registry with the given path packet map + * and an empty mutable class packet map
{@link #create(Path2PacketMap, Class2PacketMap)}Creates a new packet registry with the given packet maps, the + * class packet map will be a mutable map
+ *

+ * Next packet type registries are available by default: + *

    + *
  • {@link HandshakePackets}
  • + *
  • {@link PlayPackets}
  • + *
  • {@link StatusPackets}
  • + *
  • {@link LoginPackets}
  • + *
  • {@link ConfigurationPackets}
  • + *
+ * + * @see Path2PacketMap + * @see Class2PacketMap + */ +@SuppressWarnings("unused") +public final class PacketRegistry { + + private final Path2PacketMap byPath; + private final Class2PacketMap byClass; + + private PacketRegistry( + final @NotNull Path2PacketMap byPath, + final @NotNull Class2PacketMap byClass + ) { + this.byPath = byPath; + this.byClass = byClass; + } + + /** + * Returns the packet map, which maps the packet's path to the packet type + * + * @return The packet map, which maps the packet's path to the packet type + */ + public @NotNull Path2PacketMap byPath() { + return this.byPath; + } + + /** + * Returns the packet map, which maps the packet's class to the packet type + * + * @return The packet map, which maps the packet's class to the packet type + */ + public @NotNull Class2PacketMap byClass() { + return this.byClass; + } + + /** + * Returns the hash code value for this packet registry + * + * @return The hash code value for this packet registry + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + this.byPath.hashCode(); + result = prime * result + this.byClass.hashCode(); + + return result; + } + + /** + * Returns whether the given object is equal to this packet registry. + *

+ * To be equal, the given object must be an instance of + * {@link PacketRegistry} and have the same packet maps with same packet + * types. + * + * @param obj The object to compare + * @return True if the given object is equal to this packet registry + */ + @Contract("null -> false") + @Override + public boolean equals(final @Nullable Object obj) { + return this == obj + || ( + obj instanceof PacketRegistry that + && this.byPath.equals(that.byPath) + && this.byClass.equals(that.byClass) + ); + } + + /** + * Returns the string representation of this packet registry + * + * @return The string representation of this packet registry + */ + @Override + public @NotNull String toString() { + return this.getClass().getSimpleName() + '{' + + "pathToPacketMap=" + this.byPath + + ", classToPacketMap=" + this.byClass + + '}'; + } + + /** + * Creates a new packet registry with the given path packet map. + *

+ * The class packet map will be created as an empty mutable map. + * + * @param byPath The packet map, which maps the packet's path to the packet + * type + * @return A new packet registry with the given path packet map + * @see #create(Path2PacketMap, Class2PacketMap) + */ + @Contract("_ -> new") + public static @NotNull PacketRegistry create(final @NotNull Path2PacketMap byPath) { + return new PacketRegistry(byPath, PacketMap.class2PacketBuilder().build()); + } + + /** + * Creates a new packet registry with the given packet maps. + *

+ * NOTE: The class packet map will be a mutable map, check its + * documentation for more information. + * + * @param byPath The packet map, which maps the packet's path to the packet + * type + * @param byClass The packet map, which maps the packet's class to the + * packet type + * @return A new packet registry with the given packet maps + */ + @Contract("_, _ -> new") + public static @NotNull PacketRegistry create( + final @NotNull Path2PacketMap byPath, + final @NotNull Class2PacketMap byClass + ) { + return new PacketRegistry(byPath, byClass); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketType.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketType.java new file mode 100644 index 00000000..4131c46d --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/PacketType.java @@ -0,0 +1,182 @@ +package com.minersstudios.wholib.packet; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.packet.registry.*; +import com.minersstudios.wholib.utility.ResourcedPath; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.concurrent.Immutable; + +import static com.minersstudios.wholib.packet.PacketBound.*; + +/** + * Represents a packet type used in the Minecraft server networking. + *

+ * It contains information about the packet's bound, its ID, and its name. + *

+ * Available packet types are defined in the following registries: + *

    + *
  • {@link HandshakePackets}
  • + *
  • {@link PlayPackets}
  • + *
  • {@link StatusPackets}
  • + *
  • {@link LoginPackets}
  • + *
  • {@link ConfigurationPackets}
  • + *
+ * + * To create a new packet type, use one of the following methods: + *
    + *
  • {@link #ofMC(PacketBound, int, String)}
  • + *
  • {@link #of(PacketBound, int, ResourcedPath)}
  • + *
+ * + * @see PacketBound + * @see ResourcedPath + */ +@SuppressWarnings("unused") +@Immutable +public final class PacketType { + + private final PacketBound bound; + private final int id; + private final ResourcedPath resourcedPath; + + private PacketType( + final @NotNull PacketBound bound, + final int id, + final @NotNull ResourcedPath resourcedPath + ) { + this.bound = bound; + this.id = id; + this.resourcedPath = resourcedPath; + } + + /** + * Returns the bound of the packet + * + * @return The bound of the packet + */ + public @NotNull PacketBound getBound() { + return this.bound; + } + + /** + * Returns the ID of the packet + * + * @return The ID of the packet + */ + public int getId() { + return this.id; + } + + /** + * Returns the resourced-path of the packet + * + * @return The resourced-path of the packet + */ + public @NotNull ResourcedPath getResourcedPath() { + return this.resourcedPath; + } + + /** + * Returns whether the packet is {@link PacketBound#SERVERBOUND serverbound} + * + * @return True if the packet is {@link PacketBound#SERVERBOUND serverbound} + */ + public boolean isServerbound() { + return this.bound == SERVERBOUND; + } + + /** + * Returns whether the packet is {@link PacketBound#CLIENTBOUND clientbound} + * + * @return True if the packet is {@link PacketBound#CLIENTBOUND clientbound} + */ + public boolean isClientbound() { + return this.bound == CLIENTBOUND; + } + + /** + * Returns the hash code value for this packet type + * + * @return The hash code value for this packet type + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + this.bound.hashCode(); + result = prime * result + Integer.hashCode(this.id); + result = prime * result + this.resourcedPath.hashCode(); + + return result; + } + + /** + * Indicates whether some other object is "equal to" this packet type + * + * @param obj The reference object with which to compare + * @return True if this object is the same as the object argument + */ + @Contract("null -> false") + @Override + public boolean equals(final @Nullable Object obj) { + return this == obj + || ( + obj instanceof PacketType that + && this.bound == that.getBound() + && this.id == that.getId() + && this.resourcedPath.equals(that.getResourcedPath()) + ); + } + + /** + * Returns the string representation of this packet type + * + * @return The string representation of this packet type + */ + @Override + public @NotNull String toString() { + return this.bound + "/" + this.resourcedPath; + } + + /** + * Creates a new packet type with the given bound, ID, minecraft resource, + * and path + * + * @param bound The bound of the packet + * @param id The ID of the packet + * @param path The path of the packet + * @return A new packet type with the given bound, ID, minecraft resource, + * and path + * @see ResourcedPath#minecraft(String) + * @see #of(PacketBound, int, ResourcedPath) + */ + @Contract("_, _, _ -> new") + public static @NotNull PacketType ofMC( + final @NotNull PacketBound bound, + final int id, + final @Path @NotNull String path + ) { + return of(bound, id, ResourcedPath.minecraft(path)); + } + + /** + * Creates a new packet type with the given bound, ID, and resourced-path + * + * @param bound The bound of the packet + * @param id The ID of the packet + * @param resourcedPath The resourced-path of the packet + * @return A new packet type with the given bound, ID, and resourced-path + */ + @Contract("_, _, _ -> new") + public static @NotNull PacketType of( + final @NotNull PacketBound bound, + final int id, + final @NotNull ResourcedPath resourcedPath + ) { + return new PacketType(bound, id, resourcedPath); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Class2PacketMap.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Class2PacketMap.java new file mode 100644 index 00000000..673563eb --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Class2PacketMap.java @@ -0,0 +1,55 @@ +package com.minersstudios.wholib.packet.collection; + +import com.minersstudios.wholib.packet.PacketType; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +/** + * Represents a map of {@link Class classes} to {@link PacketType packet types}. + *

+ * This map is mutable and can be modified after creation by using the internal + * {@link #put(Class, PacketType)} method. It is only present for internal use, + * such as when registering packet classes for Bukkit servers. + *

+ * To create a new instance of this map, use the following method: + * {@link #builder()} + * + * @see PacketMap + */ +public interface Class2PacketMap extends PacketMap> { + + /** + * Puts a packet into the map + * + * @param key The key of the packet + * @param packet The packet to put + * @return This map for chaining + */ + @ApiStatus.Internal + @Contract("_, _ -> this") + @NotNull Class2PacketMap put( + final @NotNull Class key, + final @NotNull PacketType packet + ); + + /** + * Creates a new class to packet map builder + * + * @return A new class to packet map builder + */ + @Contract(" -> new") + static @NotNull Builder builder() { + return new Class2PacketMapImpl.Class2PacketBuilderImpl(); + } + + /** + * Represents a builder for a {@link Class2PacketMap class to packet map}. + *

+ * To create a new instance of this builder, use the following method: + * {@link Class2PacketMap#builder()} + * + * @see PacketMap.Builder + */ + interface Builder extends PacketMap.Builder> {} +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Class2PacketMapImpl.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Class2PacketMapImpl.java new file mode 100644 index 00000000..c6d0282b --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Class2PacketMapImpl.java @@ -0,0 +1,45 @@ +package com.minersstudios.wholib.packet.collection; + +import com.minersstudios.wholib.packet.PacketType; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +final class Class2PacketMapImpl extends PacketMapImpl> implements Class2PacketMap { + + Class2PacketMapImpl( + final @NotNull Map, PacketType> clientMap, + final @NotNull Map, PacketType> serverMap + ) { + super(clientMap, serverMap); + } + + @ApiStatus.Internal + @Contract("_, _ -> this") + @Override + public synchronized @NotNull Class2PacketMap put( + final @NotNull Class key, + final @NotNull PacketType packet + ) { + this.forBound(packet.getBound()) + .put(key, packet); + + return this; + } + + public static final class Class2PacketBuilderImpl + extends BuilderImpl> + implements Class2PacketMap.Builder { + + @Contract(" -> new") + @Override + public @NotNull Class2PacketMap build() { + return new Class2PacketMapImpl( + this.clientMap, + this.serverMap + ); + } + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/PacketMap.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/PacketMap.java new file mode 100644 index 00000000..25635821 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/PacketMap.java @@ -0,0 +1,152 @@ +package com.minersstudios.wholib.packet.collection; + +import com.minersstudios.wholib.packet.PacketBound; +import com.minersstudios.wholib.packet.PacketType; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.Map; + +/** + * Represents a packet map that maps a key to a packet type. + *

+ * To create a new packet map, use one of the following methods: + *

    + *
  • {@link #path2PacketBuilder()} - Creates a new path to packet map + * builder
  • + *
  • {@link #class2PacketBuilder()} - Creates a new class to packet map + * builder
  • + *
+ * + * @param The key type of the packet map + * + * @see Path2PacketMap + * @see Class2PacketMap + */ +@SuppressWarnings("unused") +public interface PacketMap { + + /** + * Returns the unmodifiable client delegate packet map + * + * @return The unmodifiable client delegate packet map + */ + @NotNull @Unmodifiable Map clientDelegate(); + + /** + * Returns the unmodifiable server delegate packet map + * + * @return The unmodifiable server delegate packet map + */ + @NotNull @Unmodifiable Map serverDelegate(); + + /** + * Returns the packet of the specified bound and key + * + * @param bound The bound of the packet + * @param key The key of the packet + * @return The packet of the specified bound and key + */ + @Nullable PacketType get( + final @NotNull PacketBound bound, + final @NotNull K key + ); + + /** + * Returns true if the packet map contains the specified packet + * + * @param bound The bound of the packet + * @param key The key of the packet + * @return True if the packet map contains the specified packet + */ + boolean contains( + final @NotNull PacketBound bound, + final @NotNull K key + ); + + /** + * Returns true if the packet map contains the specified key + * + * @param key The key of the packet + * @return True if the packet map contains the specified key + */ + boolean contains(final @NotNull K key); + + /** + * Returns true if the packet map contains the specified packet + * + * @param packetType The packet type + * @return True if the packet map contains the specified packet + */ + boolean contains(final @NotNull PacketType packetType); + + /** + * Returns the number of packets in the packet map + * + * @return The number of packets in the packet map + */ + int size(); + + /** + * Returns the number of packets in the packet map of the specified bound + * + * @param bound The bound of the packets + * @return The number of packets in the packet map of the specified bound + */ + int size(final @NotNull PacketBound bound); + + /** + * Creates a new path to packet map builder + * + * @return A new path to packet map builder + * @see Path2PacketMap + */ + @Contract(" -> new") + static @NotNull Path2PacketMap.Builder path2PacketBuilder() { + return Path2PacketMap.builder(); + } + + /** + * Creates a new class to packet map builder + * + * @return A new class to packet map builder + * @see Class2PacketMap + */ + @Contract(" -> new") + static @NotNull Class2PacketMap.Builder class2PacketBuilder() { + return Class2PacketMap.builder(); + } + + /** + * Represents a packet map builder + * + * @param The builder type + * @param The packet map type + * @param The key type of the packet map + */ + interface Builder, M extends PacketMap, K> { + + /** + * Binds the specified key to the packet type + * + * @param key The key of the packet + * @param packetType The packet type + * @return This builder for chaining + */ + @Contract("_, _ -> this") + @NotNull B add( + final @NotNull K key, + final @NotNull PacketType packetType + ); + + /** + * Builds the packet map + * + * @return The built packet map + */ + @Contract(" -> new") + @NotNull M build(); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/PacketMapImpl.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/PacketMapImpl.java new file mode 100644 index 00000000..d613839c --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/PacketMapImpl.java @@ -0,0 +1,110 @@ +package com.minersstudios.wholib.packet.collection; + +import com.minersstudios.wholib.packet.PacketBound; +import com.minersstudios.wholib.packet.PacketType; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import javax.annotation.concurrent.Immutable; +import java.util.Collections; +import java.util.Map; + +import static com.minersstudios.wholib.packet.PacketBound.CLIENTBOUND; + +@Immutable +abstract class PacketMapImpl implements PacketMap { + + private final Map clientMap; + private final Map serverMap; + + protected PacketMapImpl( + final @NotNull Map clientMap, + final @NotNull Map serverMap + ) { + this.clientMap = clientMap; + this.serverMap = serverMap; + } + + @Override + public @NotNull @Unmodifiable Map clientDelegate() { + return Collections.unmodifiableMap(this.clientMap); + } + + @Override + public @NotNull @Unmodifiable Map serverDelegate() { + return Collections.unmodifiableMap(this.serverMap); + } + + @Override + public @Nullable PacketType get( + final @NotNull PacketBound bound, + final @NotNull K key + ) { + return this.forBound(bound) + .get(key); + } + + @Override + public boolean contains( + final @NotNull PacketBound bound, + final @NotNull K key + ) { + return this.forBound(bound) + .containsKey(key); + } + + @Override + public boolean contains(final @NotNull K key) { + return this.clientMap.containsKey(key) + || this.serverMap.containsKey(key); + } + + @Override + public boolean contains(final @NotNull PacketType packetType) { + return this.forBound(packetType.getBound()) + .containsValue(packetType); + } + + @Override + public int size() { + return this.clientMap.size() + this.serverMap.size(); + } + + @Override + public int size(final @NotNull PacketBound bound) { + return this.forBound(bound).size(); + } + + protected @NotNull Map forBound(final @NotNull PacketBound bound) { + return bound == CLIENTBOUND ? this.clientMap : this.serverMap; + } + + @SuppressWarnings("unchecked") + public static abstract class BuilderImpl, M extends PacketMap, K> + implements PacketMap.Builder { + + protected final Map clientMap; + protected final Map serverMap; + + BuilderImpl() { + this.clientMap = new Object2ObjectOpenHashMap<>(); + this.serverMap = new Object2ObjectOpenHashMap<>(); + } + + @Override + public @NotNull B add( + final @NotNull K key, + final @NotNull PacketType packetType + ) { + if (packetType.isClientbound()) { + this.clientMap.put(key, packetType); + } else { + this.serverMap.put(key, packetType); + } + + return (B) this; + } + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Path2PacketMap.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Path2PacketMap.java new file mode 100644 index 00000000..ad3d1e9b --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Path2PacketMap.java @@ -0,0 +1,65 @@ +package com.minersstudios.wholib.packet.collection; + +import com.minersstudios.wholib.packet.PacketType; +import com.minersstudios.wholib.utility.ResourcedPath; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.concurrent.Immutable; + +/** + * Represents a map of {@link ResourcedPath resourced-paths} to + * {@link PacketType packet types}. + *

+ * This map is immutable and cannot be modified after creation. + *

+ * To create a new instance of this map, use the following method: + * {@link #builder()} + * + * @see PacketMap + */ +@Immutable +public interface Path2PacketMap extends PacketMap { + + /** + * Creates a new path to packet map builder + * + * @return A new path to packet map builder + */ + @Contract(" -> new") + static @NotNull Builder builder() { + return new Path2PacketMapImpl.Path2PacketBuilderImpl(); + } + + /** + * Represents a builder for a {@link Path2PacketMap path to packet map}. + *

+ * To create a new instance of this builder, use the following method: + * {@link Path2PacketMap#builder()} + * + * @see PacketMap.Builder + */ + interface Builder extends PacketMap.Builder { + + /** + * Adds a packet to the map + * + * @param packet The packet to add + * @return This builder for chaining + * @see #add(PacketType...) + * @see PacketMap.Builder#add(Object, PacketType) + */ + @Contract("_ -> this") + @NotNull Builder add(final @NotNull PacketType packet); + + /** + * Adds a list of packets to the map + * + * @param packets The packets to add + * @return This builder for chaining + * @see #add(PacketType) + */ + @Contract("_ -> this") + @NotNull Builder add(final PacketType @NotNull ... packets); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Path2PacketMapImpl.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Path2PacketMapImpl.java new file mode 100644 index 00000000..a43a43ff --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/Path2PacketMapImpl.java @@ -0,0 +1,48 @@ +package com.minersstudios.wholib.packet.collection; + +import com.minersstudios.wholib.packet.PacketType; +import com.minersstudios.wholib.utility.ResourcedPath; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +final class Path2PacketMapImpl extends PacketMapImpl implements Path2PacketMap { + + Path2PacketMapImpl( + final @NotNull Map clientMap, + final @NotNull Map serverMap + ) { + super(clientMap, serverMap); + } + + public static final class Path2PacketBuilderImpl + extends BuilderImpl + implements Path2PacketMap.Builder { + + @Contract("_ -> this") + @Override + public @NotNull Path2PacketMap.Builder add(final @NotNull PacketType packetType) { + return this.add(packetType.getResourcedPath(), packetType); + } + + @Contract("_ -> this") + @Override + public @NotNull Path2PacketMap.Builder add(final PacketType @NotNull ... packets) { + for (final var packet : packets) { + this.add(packet); + } + + return this; + } + + @Contract(" -> new") + @Override + public @NotNull Path2PacketMap build() { + return new Path2PacketMapImpl( + this.clientMap, + this.serverMap + ); + } + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/package-info.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/package-info.java new file mode 100644 index 00000000..57eb1270 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/collection/package-info.java @@ -0,0 +1,28 @@ +/** + * This package contains collection classes for packets. + *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available Collections
ClassDescription
{@link com.minersstudios.wholib.packet.collection.PacketMap}Represents a packet map. It maps any key to a packet type.
{@link com.minersstudios.wholib.packet.collection.Path2PacketMap}Represents a path packet map. It maps a packet's path to a packet + * type.
{@link com.minersstudios.wholib.packet.collection.Class2PacketMap}Represents a class packet map. It maps a packet's class to a + * packet type.
+ * + * @see com.minersstudios.wholib.packet Root PacketAPI package + */ +package com.minersstudios.wholib.packet.collection; diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/package-info.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/package-info.java new file mode 100644 index 00000000..34de4be7 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/package-info.java @@ -0,0 +1,81 @@ +/** + * This package contains classes for handling packets. + *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available Classes
ClassDescription
{@link com.minersstudios.wholib.packet.PacketContainer}Represents a packet container. It contains the packet and the + * packet type. The packet can be modified, but the packet type cannot + * be changed.
{@link com.minersstudios.wholib.packet.PacketEvent}Represents a packet event. It contains the packet container and + * the connection who sent or received the packet.
{@link com.minersstudios.wholib.packet.PacketListener}Represents a packet listener. It listens for packet events and + * handles them.
{@link com.minersstudios.wholib.packet.PacketRegistry}Represents a packet registry, which contains the packet maps. + * The packet registry contains two packet maps: + *
    + *
  • The path packet map, which maps the packet's path to the + * packet type
  • + *
  • The class packet map, which maps the packet's class to the + * packet type
  • + *
+ *
{@link com.minersstudios.wholib.packet.PacketType}Represents a packet type used in the Minecraft server networking. + * It contains information about the packet's bound, its ID, and its + * resourced-path.
{@link com.minersstudios.wholib.packet.PacketBound}Represents a packet's bound in the Minecraft server networking. + * Available bounds are: + *
    + *
  • {@link com.minersstudios.wholib.packet.PacketBound#SERVERBOUND} + * - from the client to the server
  • + *
  • {@link com.minersstudios.wholib.packet.PacketBound#CLIENTBOUND} + * - from the server to the client
  • + *
+ *
{@link com.minersstudios.wholib.packet.PacketProtocol}Represents a packet protocol in the Minecraft server networking. + * Available protocols are: + *
    + *
  • {@link com.minersstudios.wholib.packet.PacketProtocol#HANDSHAKING} + * - the handshake protocol
  • + *
  • {@link com.minersstudios.wholib.packet.PacketProtocol#PLAY} + * - the play protocol
  • + *
  • {@link com.minersstudios.wholib.packet.PacketProtocol#STATUS} + * - the status protocol
  • + *
  • {@link com.minersstudios.wholib.packet.PacketProtocol#LOGIN} + * - the login protocol
  • + *
  • {@link com.minersstudios.wholib.packet.PacketProtocol#CONFIGURATION} + * - the configuration protocol
  • + *
+ *
+ * + * + * @see Protocol Wiki + * @see com.minersstudios.wholib.packet.registry Packet type registries + * @see com.minersstudios.wholib.packet.collection Packet collections + */ +package com.minersstudios.wholib.packet; diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/ConfigurationPackets.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/ConfigurationPackets.java new file mode 100644 index 00000000..8a7ac1db --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/ConfigurationPackets.java @@ -0,0 +1,114 @@ +package com.minersstudios.wholib.packet.registry; + +import com.minersstudios.wholib.packet.PacketRegistry; +import com.minersstudios.wholib.packet.collection.PacketMap; +import com.minersstudios.wholib.packet.PacketType; +import com.minersstudios.wholib.utility.SharedConstants; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import static com.minersstudios.wholib.packet.PacketBound.*; +import static com.minersstudios.wholib.packet.PacketType.ofMC; + +/** + * Represents a registry of configuration packet types used in the Minecraft + * server networking. + * + * @see PacketType + * @see PacketRegistry + * @see Protocol Wiki - Configuration + * + * @version Minecraft {@value SharedConstants#MINECRAFT_VERSION}, + * Protocol {@value SharedConstants#PROTOCOL_VERSION} + */ +@SuppressWarnings("unused") +public final class ConfigurationPackets { + // + + public static final PacketType CLIENT_COOKIE_REQUEST = ofMC(CLIENTBOUND, 0x00, "cookie_request"); // "Cookie Request (configuration) + public static final PacketType CLIENT_PLUGIN_MESSAGE = ofMC(CLIENTBOUND, 0x01, "custom_payload"); // Clientbound Plugin Message (configuration) + public static final PacketType CLIENT_DISCONNECT = ofMC(CLIENTBOUND, 0x02, "disconnect"); // Disconnect (configuration) + public static final PacketType CLIENT_FINISH_CONFIGURATION = ofMC(CLIENTBOUND, 0x03, "finish_configuration"); // Finish Configuration + public static final PacketType CLIENT_KEEP_ALIVE = ofMC(CLIENTBOUND, 0x04, "keep_alive"); // Clientbound Keep Alive (configuration) + public static final PacketType CLIENT_PING = ofMC(CLIENTBOUND, 0x05, "ping"); // Ping (configuration) + public static final PacketType CLIENT_RESET_CHAT = ofMC(CLIENTBOUND, 0x06, "reset_chat"); // Reset Chat + public static final PacketType CLIENT_REGISTRY_DATA = ofMC(CLIENTBOUND, 0x07, "registry_data"); // Registry Data + public static final PacketType CLIENT_REMOVE_RESOURCE_PACK = ofMC(CLIENTBOUND, 0x08, "resource_pack_pop"); // Remove Resource Pack (configuration) + public static final PacketType CLIENT_ADD_RESOURCE_PACK = ofMC(CLIENTBOUND, 0x09, "resource_pack_push"); // Add Resource Pack (configuration) + public static final PacketType CLIENT_STORE_COOKIE = ofMC(CLIENTBOUND, 0x0A, "store_cookie"); // Store Cookie + public static final PacketType CLIENT_TRANSFER = ofMC(CLIENTBOUND, 0x0B, "transfer"); // Transfer (configuration) + public static final PacketType CLIENT_FEATURE_FLAGS = ofMC(CLIENTBOUND, 0x0C, "update_enabled_features"); // Feature Flags + public static final PacketType CLIENT_UPDATE_TAGS = ofMC(CLIENTBOUND, 0x0D, "update_tags"); // Update Tags (configuration) + public static final PacketType CLIENT_KNOWN_PACKS = ofMC(CLIENTBOUND, 0x0E, "select_known_packs"); // Clientbound Known Packs + public static final PacketType CLIENT_CUSTOM_REPORT_DETAILS = ofMC(CLIENTBOUND, 0x0F, "custom_report_details"); // Custom Report Details (configuration) + public static final PacketType CLIENT_SERVER_LINKS = ofMC(CLIENTBOUND, 0x10, "server_links"); // Server Links (configuration) + + // + // + + public static final PacketType SERVER_CLIENT_INFORMATION = ofMC(SERVERBOUND, 0x00, "client_information"); // Client Information (configuration) + public static final PacketType SERVER_COOKIE_RESPONSE = ofMC(SERVERBOUND, 0x01, "cookie_response"); // Cookie Response (configuration) + public static final PacketType SERVER_PLUGIN_MESSAGE = ofMC(SERVERBOUND, 0x02, "custom_payload"); // Serverbound Plugin Message (configuration) + public static final PacketType SERVER_ACKNOWLEDGE_FINISH_CONFIGURATION = ofMC(SERVERBOUND, 0x03, "finish_configuration"); // Acknowledge Finish Configuration + public static final PacketType SERVER_KEEP_ALIVE = ofMC(SERVERBOUND, 0x04, "keep_alive"); // Serverbound Keep Alive (configuration) + public static final PacketType SERVER_PONG = ofMC(SERVERBOUND, 0x05, "pong"); // Pong (configuration) + public static final PacketType SERVER_RESOURCE_PACK_RESPONSE = ofMC(SERVERBOUND, 0x06, "resource_pack"); // Resource Pack Response (configuration) + public static final PacketType SERVER_KNOWN_PACKS = ofMC(SERVERBOUND, 0x07, "select_known_packs"); // Serverbound Known Packs + + // + + private static final PacketRegistry REGISTRY = + PacketRegistry.create( + PacketMap.path2PacketBuilder() + .add( + // + + CLIENT_COOKIE_REQUEST, + CLIENT_PLUGIN_MESSAGE, + CLIENT_DISCONNECT, + CLIENT_FINISH_CONFIGURATION, + CLIENT_KEEP_ALIVE, + CLIENT_PING, + CLIENT_RESET_CHAT, + CLIENT_REGISTRY_DATA, + CLIENT_REMOVE_RESOURCE_PACK, + CLIENT_ADD_RESOURCE_PACK, + CLIENT_STORE_COOKIE, + CLIENT_TRANSFER, + CLIENT_FEATURE_FLAGS, + CLIENT_UPDATE_TAGS, + CLIENT_KNOWN_PACKS, + CLIENT_CUSTOM_REPORT_DETAILS, + CLIENT_SERVER_LINKS, + + // + // + + SERVER_CLIENT_INFORMATION, + SERVER_COOKIE_RESPONSE, + SERVER_PLUGIN_MESSAGE, + SERVER_ACKNOWLEDGE_FINISH_CONFIGURATION, + SERVER_KEEP_ALIVE, + SERVER_PONG, + SERVER_RESOURCE_PACK_RESPONSE, + SERVER_KNOWN_PACKS + + // + ).build() + ); + + @Contract(" -> fail") + private ConfigurationPackets() throws AssertionError { + throw new AssertionError("Registry class"); + } + + /** + * Returns the registry of configuration packet types + * + * @return The registry of configuration packet types + */ + public static @Unmodifiable @NotNull PacketRegistry registry() { + return REGISTRY; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/HandshakePackets.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/HandshakePackets.java new file mode 100644 index 00000000..08f3a50c --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/HandshakePackets.java @@ -0,0 +1,67 @@ +package com.minersstudios.wholib.packet.registry; + +import com.minersstudios.wholib.packet.PacketRegistry; +import com.minersstudios.wholib.packet.collection.PacketMap; +import com.minersstudios.wholib.packet.PacketType; +import com.minersstudios.wholib.utility.SharedConstants; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import static com.minersstudios.wholib.packet.PacketBound.*; +import static com.minersstudios.wholib.packet.PacketType.ofMC; + +/** + * Represents a registry of handshake packet types used in the Minecraft + * server networking. + * + * @see PacketType + * @see PacketRegistry + * @see Protocol Wiki - Handshake + * + * @version Minecraft {@value SharedConstants#MINECRAFT_VERSION}, + * Protocol {@value SharedConstants#PROTOCOL_VERSION} + */ +@SuppressWarnings("unused") +public final class HandshakePackets { + // + + // There are no clientbound packets in the Handshaking state, since the + // protocol immediately switches to a different state after the client sends + // the first packet. + + // + // + + public static final PacketType SERVER_HANDSHAKE = ofMC(SERVERBOUND, 0x00, "intention"); // Handshake + public static final PacketType SERVER_LEGACY_SERVER_LIST_PING = ofMC(SERVERBOUND, 0xFE, ""); // Legacy Server List Ping + + // + + private static final PacketRegistry REGISTRY = + PacketRegistry.create( + PacketMap.path2PacketBuilder() + .add( + // + + SERVER_HANDSHAKE, + SERVER_LEGACY_SERVER_LIST_PING + + // + ).build() + ); + + @Contract(" -> fail") + private HandshakePackets() throws AssertionError { + throw new AssertionError("Registry class"); + } + + /** + * Returns the registry of the handshake packet types + * + * @return The registry of the handshake packet types + */ + public static @Unmodifiable @NotNull PacketRegistry registry() { + return REGISTRY; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/LoginPackets.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/LoginPackets.java new file mode 100644 index 00000000..b8317dd4 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/LoginPackets.java @@ -0,0 +1,85 @@ +package com.minersstudios.wholib.packet.registry; + +import com.minersstudios.wholib.packet.PacketRegistry; +import com.minersstudios.wholib.packet.collection.PacketMap; +import com.minersstudios.wholib.packet.PacketType; +import com.minersstudios.wholib.utility.SharedConstants; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import static com.minersstudios.wholib.packet.PacketBound.*; +import static com.minersstudios.wholib.packet.PacketType.ofMC; + +/** + * Represents a registry of login packet types used in the Minecraft + * server networking. + * + * @see PacketType + * @see PacketRegistry + * @see Protocol Wiki - Login + * + * @version Minecraft {@value SharedConstants#MINECRAFT_VERSION}, + * Protocol {@value SharedConstants#PROTOCOL_VERSION} + */ +public final class LoginPackets { + // + + public static final PacketType CLIENT_DISCONNECT = ofMC(CLIENTBOUND, 0x00, "login_disconnect"); // Disconnect (login) + public static final PacketType CLIENT_ENCRYPTION_REQUEST = ofMC(CLIENTBOUND, 0x01, "hello"); // Encryption Request + public static final PacketType CLIENT_LOGIN_SUCCESS = ofMC(CLIENTBOUND, 0x02, "game_profile"); // Login Success + public static final PacketType CLIENT_SET_COMPRESSION = ofMC(CLIENTBOUND, 0x03, "login_compression"); // Set Compression + public static final PacketType CLIENT_LOGIN_PLUGIN_REQUEST = ofMC(CLIENTBOUND, 0x04, "custom_query"); // Login Plugin Request + public static final PacketType CLIENT_COOKIE_REQUEST = ofMC(CLIENTBOUND, 0x05, "cookie_request"); // Cookie Request (login) + + // + // + + private static final PacketRegistry REGISTRY = + PacketRegistry.create( + PacketMap.path2PacketBuilder() + .add( + // + + CLIENT_DISCONNECT, + CLIENT_ENCRYPTION_REQUEST, + CLIENT_LOGIN_SUCCESS, + CLIENT_SET_COMPRESSION, + CLIENT_LOGIN_PLUGIN_REQUEST, + CLIENT_COOKIE_REQUEST, + + // + // + + SERVER_LOGIN_START, + SERVER_ENCRYPTION_RESPONSE, + SERVER_LOGIN_PLUGIN_RESPONSE, + SERVER_LOGIN_ACKNOWLEDGED, + SERVER_COOKIE_RESPONSE + + // + ).build() + ); + + @Contract(" -> fail") + private LoginPackets() throws AssertionError { + throw new AssertionError("Registry class"); + } + + /** + * Returns the registry of login packet types + * + * @return The registry of login packet types + */ + public static @Unmodifiable @NotNull PacketRegistry registry() { + return REGISTRY; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/PlayPackets.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/PlayPackets.java new file mode 100644 index 00000000..b541a991 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/PlayPackets.java @@ -0,0 +1,427 @@ +package com.minersstudios.wholib.packet.registry; + +import com.minersstudios.wholib.packet.PacketRegistry; +import com.minersstudios.wholib.packet.collection.PacketMap; +import com.minersstudios.wholib.packet.PacketType; +import com.minersstudios.wholib.utility.SharedConstants; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import static com.minersstudios.wholib.packet.PacketBound.*; +import static com.minersstudios.wholib.packet.PacketType.ofMC; + +/** + * Represents a registry of play packet types used in the Minecraft + * server networking. + * + * @see PacketType + * @see PacketRegistry + * @see Protocol Wiki - Play + * + * @version Minecraft {@value SharedConstants#MINECRAFT_VERSION}, + * Protocol {@value SharedConstants#PROTOCOL_VERSION} + */ +public final class PlayPackets { + // + + public static final PacketType CLIENT_BUNDLE_DELIMITER = ofMC(CLIENTBOUND, 0x00, "bundle"); // Bundle Delimiter + public static final PacketType CLIENT_SPAWN_ENTITY = ofMC(CLIENTBOUND, 0x01, "add_entity"); // Spawn Entity + public static final PacketType CLIENT_SPAWN_EXPERIENCE_ORB = ofMC(CLIENTBOUND, 0x02, "add_experience_orb"); // Spawn Experience Orb + public static final PacketType CLIENT_ENTITY_ANIMATION = ofMC(CLIENTBOUND, 0x03, "animate"); // Entity Animation + public static final PacketType CLIENT_AWARD_STATISTICS = ofMC(CLIENTBOUND, 0x04, "award_stats"); // Award Statistics + public static final PacketType CLIENT_ACKNOWLEDGE_BLOCK_CHANGE = ofMC(CLIENTBOUND, 0x05, "block_changed_ack"); // Acknowledge Block Change + public static final PacketType CLIENT_SET_BLOCK_DESTROY_STAGE = ofMC(CLIENTBOUND, 0x06, "block_destruction"); // Set Block Destroy Stage + public static final PacketType CLIENT_BLOCK_ENTITY_DATA = ofMC(CLIENTBOUND, 0x07, "block_entity_data"); // Block Entity Data + public static final PacketType CLIENT_BLOCK_ACTION = ofMC(CLIENTBOUND, 0x08, "block_event"); // Block Action + public static final PacketType CLIENT_BLOCK_UPDATE = ofMC(CLIENTBOUND, 0x09, "block_update"); // Block Update + public static final PacketType CLIENT_BOSS_BAR = ofMC(CLIENTBOUND, 0x0A, "boss_event"); // Boss Bar + public static final PacketType CLIENT_CHANGE_DIFFICULTY = ofMC(CLIENTBOUND, 0x0B, "change_difficulty"); // Change Difficulty + public static final PacketType CLIENT_CHUNK_BATCH_FINISHED = ofMC(CLIENTBOUND, 0x0C, "chunk_batch_finished"); // Chunk Batch Finished + public static final PacketType CLIENT_CHUNK_BATCH_START = ofMC(CLIENTBOUND, 0x0D, "chunk_batch_start"); // Chunk Batch Start + public static final PacketType CLIENT_CHUNK_BIOMES = ofMC(CLIENTBOUND, 0x0E, "chunks_biomes"); // Chunk Biomes + public static final PacketType CLIENT_CLEAR_TITLES = ofMC(CLIENTBOUND, 0x0F, "clear_titles"); // Clear Titles + public static final PacketType CLIENT_COMMAND_SUGGESTIONS_RESPONSE = ofMC(CLIENTBOUND, 0x10, "command_suggestions"); // Command Suggestions Response + public static final PacketType CLIENT_COMMANDS = ofMC(CLIENTBOUND, 0x11, "commands"); // Commands + public static final PacketType CLIENT_CLOSE_CONTAINER = ofMC(CLIENTBOUND, 0x12, "container_close"); // Close Container + public static final PacketType CLIENT_SET_CONTAINER_CONTENT = ofMC(CLIENTBOUND, 0x13, "container_set_content"); // Set Container Content + public static final PacketType CLIENT_SET_CONTAINER_PROPERTY = ofMC(CLIENTBOUND, 0x14, "container_set_data"); // Set Container Property + public static final PacketType CLIENT_SET_CONTAINER_SLOT = ofMC(CLIENTBOUND, 0x15, "container_set_slot"); // Set Container Slot + public static final PacketType CLIENT_COOKIE_REQUEST = ofMC(CLIENTBOUND, 0x16, "cookie_request"); // Cookie Request (play) + public static final PacketType CLIENT_SET_COOLDOWN = ofMC(CLIENTBOUND, 0x17, "cooldown"); // Set Cooldown + public static final PacketType CLIENT_CHAT_SUGGESTIONS = ofMC(CLIENTBOUND, 0x18, "custom_chat_completions"); // Chat Suggestions + public static final PacketType CLIENT_PLUGIN_MESSAGE = ofMC(CLIENTBOUND, 0x19, "custom_payload"); // Clientbound Plugin Message (play) + public static final PacketType CLIENT_DAMAGE_EVENT = ofMC(CLIENTBOUND, 0x1A, "damage_event"); // Damage Event + public static final PacketType CLIENT_DEBUG_SAMPLE = ofMC(CLIENTBOUND, 0x1B, "debug_sample"); // Debug Sample + public static final PacketType CLIENT_DELETE_MESSAGE = ofMC(CLIENTBOUND, 0x1C, "delete_chat"); // Delete Message + public static final PacketType CLIENT_DISCONNECT = ofMC(CLIENTBOUND, 0x1D, "disconnect"); // Disconnect (play) + public static final PacketType CLIENT_DISGUISED_CHAT_MESSAGE = ofMC(CLIENTBOUND, 0x1E, "disguised_chat"); // Disguised Chat Message + public static final PacketType CLIENT_ENTITY_EVENT = ofMC(CLIENTBOUND, 0x1F, "entity_event"); // Entity Event + public static final PacketType CLIENT_EXPLOSION = ofMC(CLIENTBOUND, 0x20, "explode"); // Explosion + public static final PacketType CLIENT_UNLOAD_CHUNK = ofMC(CLIENTBOUND, 0x21, "forget_level_chunk"); // Unload Chunk + public static final PacketType CLIENT_GAME_EVENT = ofMC(CLIENTBOUND, 0x22, "game_event"); // Game Event + public static final PacketType CLIENT_OPEN_HORSE_SCREEN = ofMC(CLIENTBOUND, 0x23, "horse_screen_open"); // Open Horse Screen + public static final PacketType CLIENT_HURT_ANIMATION = ofMC(CLIENTBOUND, 0x24, "hurt_animation"); // Hurt Animation + public static final PacketType CLIENT_INITIALIZE_WORLD_BORDER = ofMC(CLIENTBOUND, 0x25, "initialize_border"); // Initialize World Border + public static final PacketType CLIENT_KEEP_ALIVE = ofMC(CLIENTBOUND, 0x26, "keep_alive"); // Clientbound Keep Alive (play) + public static final PacketType CLIENT_CHUNK_DATA_AND_UPDATE_LIGHT = ofMC(CLIENTBOUND, 0x27, "level_chunk_with_light"); // Chunk Data and Update Light + public static final PacketType CLIENT_WORLD_EVENT = ofMC(CLIENTBOUND, 0x28, "level_event"); // World Event + public static final PacketType CLIENT_PARTICLE = ofMC(CLIENTBOUND, 0x29, "level_particles"); // Particle + public static final PacketType CLIENT_UPDATE_LIGHT = ofMC(CLIENTBOUND, 0x2A, "light_update"); // Update Light + public static final PacketType CLIENT_LOGIN = ofMC(CLIENTBOUND, 0x2B, "login"); // Login (play) + public static final PacketType CLIENT_MAP_DATA = ofMC(CLIENTBOUND, 0x2C, "map_item_data"); // Map Data + public static final PacketType CLIENT_MERCHANT_OFFERS = ofMC(CLIENTBOUND, 0x2D, "merchant_offers"); // Merchant Offers + public static final PacketType CLIENT_UPDATE_ENTITY_POSITION = ofMC(CLIENTBOUND, 0x2E, "move_entity_pos"); // Update Entity Position + public static final PacketType CLIENT_UPDATE_ENTITY_POSITION_AND_ROTATION = ofMC(CLIENTBOUND, 0x2F, "move_entity_pos_rot"); // Update Entity Position and Rotation + public static final PacketType CLIENT_UPDATE_ENTITY_ROTATION = ofMC(CLIENTBOUND, 0x30, "move_entity_rot"); // Update Entity Rotation + public static final PacketType CLIENT_MOVE_VEHICLE = ofMC(CLIENTBOUND, 0x31, "move_vehicle"); // Move Vehicle + public static final PacketType CLIENT_OPEN_BOOK = ofMC(CLIENTBOUND, 0x32, "open_book"); // Open Book + public static final PacketType CLIENT_OPEN_SCREEN = ofMC(CLIENTBOUND, 0x33, "open_screen"); // Open Screen + public static final PacketType CLIENT_OPEN_SIGN_EDITOR = ofMC(CLIENTBOUND, 0x34, "open_sign_editor"); // Open Sign Editor + public static final PacketType CLIENT_PING = ofMC(CLIENTBOUND, 0x35, "ping"); // Ping (play) + public static final PacketType CLIENT_PING_RESPONSE = ofMC(CLIENTBOUND, 0x36, "pong_response"); // Ping Response (play) + public static final PacketType CLIENT_PLACE_GHOST_RECIPE = ofMC(CLIENTBOUND, 0x37, "place_ghost_recipe"); // Place Ghost Recipe + public static final PacketType CLIENT_PLAYER_ABILITIES = ofMC(CLIENTBOUND, 0x38, "player_abilities"); // Player Abilities (clientbound) + public static final PacketType CLIENT_PLAYER_CHAT_MESSAGE = ofMC(CLIENTBOUND, 0x39, "player_chat"); // Player Chat Message + public static final PacketType CLIENT_END_COMBAT = ofMC(CLIENTBOUND, 0x3A, "player_combat_end"); // End Combat + public static final PacketType CLIENT_ENTER_COMBAT = ofMC(CLIENTBOUND, 0x3B, "player_combat_enter"); // Enter Combat + public static final PacketType CLIENT_COMBAT_DEATH = ofMC(CLIENTBOUND, 0x3C, "player_combat_kill"); // Combat Death + public static final PacketType CLIENT_PLAYER_INFO_REMOVE = ofMC(CLIENTBOUND, 0x3D, "player_info_remove"); // Player Info Remove + public static final PacketType CLIENT_PLAYER_INFO_UPDATE = ofMC(CLIENTBOUND, 0x3E, "player_info_update"); // Player Info Update + public static final PacketType CLIENT_LOOK_AT = ofMC(CLIENTBOUND, 0x3F, "player_look_at"); // Look At + public static final PacketType CLIENT_SYNCHRONIZE_PLAYER_POSITION = ofMC(CLIENTBOUND, 0x40, "player_position"); // Synchronize Player Position + public static final PacketType CLIENT_UPDATE_RECIPE_BOOK = ofMC(CLIENTBOUND, 0x41, "recipe"); // Update Recipe Book + public static final PacketType CLIENT_REMOVE_ENTITIES = ofMC(CLIENTBOUND, 0x42, "remove_entities"); // Remove Entities + public static final PacketType CLIENT_REMOVE_ENTITY_EFFECT = ofMC(CLIENTBOUND, 0x43, "remove_mob_effect"); // Remove Entity Effect + public static final PacketType CLIENT_RESET_SCORE = ofMC(CLIENTBOUND, 0x44, "reset_score"); // Reset Score + public static final PacketType CLIENT_REMOVE_RESOURCE_PACK = ofMC(CLIENTBOUND, 0x45, "resource_pack_pop"); // Remove Resource Pack (play) + public static final PacketType CLIENT_ADD_RESOURCE_PACK = ofMC(CLIENTBOUND, 0x46, "resource_pack_push"); // Add Resource Pack (play) + public static final PacketType CLIENT_RESPAWN = ofMC(CLIENTBOUND, 0x47, "respawn"); // Respawn + public static final PacketType CLIENT_SET_HEAD_ROTATION = ofMC(CLIENTBOUND, 0x48, "rotate_head"); // Set Head Rotation + public static final PacketType CLIENT_UPDATE_SECTION_BLOCKS = ofMC(CLIENTBOUND, 0x49, "section_blocks_update"); // Update Section Blocks + public static final PacketType CLIENT_SELECT_ADVANCEMENT_TAB = ofMC(CLIENTBOUND, 0x4A, "select_advancements_tab"); // Select Advancement Tab + public static final PacketType CLIENT_SERVER_DATA = ofMC(CLIENTBOUND, 0x4B, "server_data"); // Server Data + public static final PacketType CLIENT_SET_ACTION_BAR_TEXT = ofMC(CLIENTBOUND, 0x4C, "set_action_bar_text"); // Set Action Bar Text + public static final PacketType CLIENT_SET_BORDER_CENTER = ofMC(CLIENTBOUND, 0x4D, "set_border_center"); // Set Border Center + public static final PacketType CLIENT_SET_BORDER_LERP_SIZE = ofMC(CLIENTBOUND, 0x4E, "set_border_lerp_size"); // Set Border Lerp Size + public static final PacketType CLIENT_SET_BORDER_SIZE = ofMC(CLIENTBOUND, 0x4F, "set_border_size"); // Set Border Size + public static final PacketType CLIENT_SET_BORDER_WARNING_DELAY = ofMC(CLIENTBOUND, 0x50, "set_border_warning_delay"); // Set Border Warning Delay + public static final PacketType CLIENT_SET_BORDER_WARNING_DISTANCE = ofMC(CLIENTBOUND, 0x51, "set_border_warning_distance"); // Set Border Warning Distance + public static final PacketType CLIENT_SET_CAMERA = ofMC(CLIENTBOUND, 0x52, "set_camera"); // Set Camera + public static final PacketType CLIENT_SET_HELD_ITEM = ofMC(CLIENTBOUND, 0x53, "set_carried_item"); // Set Held Item (clientbound) + public static final PacketType CLIENT_SET_CENTER_CHUNK = ofMC(CLIENTBOUND, 0x54, "set_chunk_cache_center"); // Set Center Chunk + public static final PacketType CLIENT_SET_RENDER_DISTANCE = ofMC(CLIENTBOUND, 0x55, "set_chunk_cache_radius"); // Set Render Distance + public static final PacketType CLIENT_SET_DEFAULT_SPAWN_POSITION = ofMC(CLIENTBOUND, 0x56, "set_default_spawn_position"); // Set Default Spawn Position + public static final PacketType CLIENT_DISPLAY_OBJECTIVE = ofMC(CLIENTBOUND, 0x57, "set_display_objective"); // Display Objective + public static final PacketType CLIENT_SET_ENTITY_METADATA = ofMC(CLIENTBOUND, 0x58, "set_entity_data"); // Set Entity Metadata + public static final PacketType CLIENT_LINK_ENTITIES = ofMC(CLIENTBOUND, 0x59, "set_entity_link"); // Link Entities + public static final PacketType CLIENT_SET_ENTITY_VELOCITY = ofMC(CLIENTBOUND, 0x5A, "set_entity_motion"); // Set Entity Velocity + public static final PacketType CLIENT_SET_EQUIPMENT = ofMC(CLIENTBOUND, 0x5B, "set_equipment"); // Set Equipment + public static final PacketType CLIENT_SET_EXPERIENCE = ofMC(CLIENTBOUND, 0x5C, "set_experience"); // Set Experience + public static final PacketType CLIENT_SET_HEALTH = ofMC(CLIENTBOUND, 0x5D, "set_health"); // Set Health + public static final PacketType CLIENT_UPDATE_OBJECTIVES = ofMC(CLIENTBOUND, 0x5E, "set_objective"); // Update Objectives + public static final PacketType CLIENT_SET_PASSENGERS = ofMC(CLIENTBOUND, 0x5F, "set_passengers"); // Set Passengers + public static final PacketType CLIENT_UPDATE_TEAMS = ofMC(CLIENTBOUND, 0x60, "set_player_team"); // Update Teams + public static final PacketType CLIENT_UPDATE_SCORE = ofMC(CLIENTBOUND, 0x61, "set_score"); // Update Score + public static final PacketType CLIENT_SET_SIMULATION_DISTANCE = ofMC(CLIENTBOUND, 0x62, "set_simulation_distance"); // Set Simulation Distance + public static final PacketType CLIENT_SET_SUBTITLE_TEXT = ofMC(CLIENTBOUND, 0x63, "set_subtitle_text"); // Set Subtitle Text + public static final PacketType CLIENT_UPDATE_TIME = ofMC(CLIENTBOUND, 0x64, "set_time"); // Update Time + public static final PacketType CLIENT_SET_TITLE_TEXT = ofMC(CLIENTBOUND, 0x65, "set_title_text"); // Set Title Text + public static final PacketType CLIENT_SET_TITLE_ANIMATION_TIMES = ofMC(CLIENTBOUND, 0x66, "set_titles_animation"); // Set Title Animation Times + public static final PacketType CLIENT_ENTITY_SOUND_EFFECT = ofMC(CLIENTBOUND, 0x67, "sound_entity"); // Entity Sound Effect + public static final PacketType CLIENT_SOUND_EFFECT = ofMC(CLIENTBOUND, 0x68, "sound"); // Sound Effect + public static final PacketType CLIENT_START_CONFIGURATION = ofMC(CLIENTBOUND, 0x69, "start_configuration"); // Start Configuration + public static final PacketType CLIENT_STOP_SOUND = ofMC(CLIENTBOUND, 0x6A, "stop_sound"); // Stop Sound + public static final PacketType CLIENT_STORE_COOKIE = ofMC(CLIENTBOUND, 0x6B, "store_cookie"); // Store Cookie (play) + public static final PacketType CLIENT_SYSTEM_CHAT_MESSAGE = ofMC(CLIENTBOUND, 0x6C, "system_chat"); // System Chat Message + public static final PacketType CLIENT_SET_TAB_LIST_HEADER_AND_FOOTER = ofMC(CLIENTBOUND, 0x6D, "tab_list"); // Set Tab List Header And Footer + public static final PacketType CLIENT_TAG_QUERY_RESPONSE = ofMC(CLIENTBOUND, 0x6E, "tag_query"); // Tag Query Response + public static final PacketType CLIENT_PICKUP_ITEM = ofMC(CLIENTBOUND, 0x6F, "take_item_entity"); // Pickup Item + public static final PacketType CLIENT_TELEPORT_ENTITY = ofMC(CLIENTBOUND, 0x70, "teleport_entity"); // Teleport Entity + public static final PacketType CLIENT_SET_TICKING_STATE = ofMC(CLIENTBOUND, 0x71, "ticking_state"); // Set Ticking State + public static final PacketType CLIENT_STEP_TICK = ofMC(CLIENTBOUND, 0x72, "ticking_step"); // Step Tick + public static final PacketType CLIENT_TRANSFER = ofMC(CLIENTBOUND, 0x73, "transfer"); // Transfer (play) + public static final PacketType CLIENT_UPDATE_ADVANCEMENTS = ofMC(CLIENTBOUND, 0x74, "update_advancements"); // Update Advancements + public static final PacketType CLIENT_UPDATE_ATTRIBUTES = ofMC(CLIENTBOUND, 0x75, "update_attributes"); // Update Attributes + public static final PacketType CLIENT_ENTITY_EFFECT = ofMC(CLIENTBOUND, 0x76, "update_mob_effect"); // Entity Effect + public static final PacketType CLIENT_UPDATE_RECIPES = ofMC(CLIENTBOUND, 0x77, "update_recipes"); // Update Recipes + public static final PacketType CLIENT_UPDATE_TAGS = ofMC(CLIENTBOUND, 0x78, "update_tags"); // Update Tags (play) + public static final PacketType CLIENT_PROJECTILE_POWER = ofMC(CLIENTBOUND, 0x79, "projectile_power"); // Projectile Power + public static final PacketType CLIENT_CUSTOM_REPORT_DETAILS = ofMC(CLIENTBOUND, 0x7A, "custom_report_details"); // Custom Report Details + public static final PacketType CLIENT_SERVER_LINKS = ofMC(CLIENTBOUND, 0x7B, "server_links"); // Server Links (play) + + // + // + + public static final PacketType SERVER_CONFIRM_TELEPORTATION = ofMC(SERVERBOUND, 0x00, "accept_teleportation"); // Confirm Teleportation + public static final PacketType SERVER_QUERY_BLOCK_ENTITY_TAG = ofMC(SERVERBOUND, 0x01, "block_entity_tag_query"); // Query Block Entity Tag + public static final PacketType SERVER_CHANGE_DIFFICULTY = ofMC(SERVERBOUND, 0x02, "change_difficulty"); // Change Difficulty + public static final PacketType SERVER_ACKNOWLEDGE_MESSAGE = ofMC(SERVERBOUND, 0x03, "chat_ack"); // Acknowledge Message + public static final PacketType SERVER_CHAT_COMMAND = ofMC(SERVERBOUND, 0x04, "chat_command"); // Chat Command + public static final PacketType SERVER_SIGNED_CHAT_COMMAND = ofMC(SERVERBOUND, 0x05, "chat_command_signed"); // Signed Chat Command + public static final PacketType SERVER_CHAT_MESSAGE = ofMC(SERVERBOUND, 0x06, "chat"); // Chat Message + public static final PacketType SERVER_PLAYER_SESSION = ofMC(SERVERBOUND, 0x07, "chat_session_update"); // Player Session + public static final PacketType SERVER_CHUNK_BATCH_RECEIVED = ofMC(SERVERBOUND, 0x08, "chunk_batch_received"); // Chunk Batch Received + public static final PacketType SERVER_CLIENT_STATUS = ofMC(SERVERBOUND, 0x09, "client_command"); // Client Status + public static final PacketType SERVER_CLIENT_INFORMATION = ofMC(SERVERBOUND, 0x0A, "client_information"); // Client Information (play) + public static final PacketType SERVER_COMMAND_SUGGESTIONS_REQUEST = ofMC(SERVERBOUND, 0x0B, "command_suggestion"); // Command Suggestions Request + public static final PacketType SERVER_ACKNOWLEDGE_CONFIGURATION = ofMC(SERVERBOUND, 0x0C, "configuration_acknowledged"); // Acknowledge Configuration + public static final PacketType SERVER_CLICK_CONTAINER_BUTTON = ofMC(SERVERBOUND, 0x0D, "container_button_click"); // Click Container Button + public static final PacketType SERVER_CLICK_CONTAINER = ofMC(SERVERBOUND, 0x0E, "container_click"); // Click Container + public static final PacketType SERVER_CLOSE_CONTAINER = ofMC(SERVERBOUND, 0x0F, "container_close"); // Close Container + public static final PacketType SERVER_CHANGE_CONTAINER_SLOT_STATE = ofMC(SERVERBOUND, 0x10, "container_slot_state_changed"); // Change Container Slot State + public static final PacketType SERVER_COOKIE_RESPONSE = ofMC(SERVERBOUND, 0x11, "cookie_response"); // Cookie Response (play) + public static final PacketType SERVER_PLUGIN_MESSAGE = ofMC(SERVERBOUND, 0x12, "custom_payload"); // Serverbound Plugin Message (play) + public static final PacketType SERVER_DEBUG_SAMPLE_SUBSCRIPTION = ofMC(SERVERBOUND, 0x13, "debug_sample_subscription"); // Debug Sample Subscription + public static final PacketType SERVER_EDIT_BOOK = ofMC(SERVERBOUND, 0x14, "edit_book"); // Edit Book + public static final PacketType SERVER_QUERY_ENTITY_TAG = ofMC(SERVERBOUND, 0x15, "entity_tag_query"); // Query Entity Tag + public static final PacketType SERVER_INTERACT = ofMC(SERVERBOUND, 0x16, "interact"); // Interact + public static final PacketType SERVER_JIGSAW_GENERATE = ofMC(SERVERBOUND, 0x17, "jigsaw_generate"); // Jigsaw Generate + public static final PacketType SERVER_KEEP_ALIVE = ofMC(SERVERBOUND, 0x18, "keep_alive"); // Serverbound Keep Alive (play) + public static final PacketType SERVER_LOCK_DIFFICULTY = ofMC(SERVERBOUND, 0x19, "lock_difficulty"); // Lock Difficulty + public static final PacketType SERVER_SET_PLAYER_POSITION = ofMC(SERVERBOUND, 0x1A, "move_player_pos"); // Set Player Position + public static final PacketType SERVER_SET_PLAYER_POSITION_AND_ROTATION = ofMC(SERVERBOUND, 0x1B, "move_player_pos_rot"); // Set Player Position and Rotation + public static final PacketType SERVER_SET_PLAYER_ROTATION = ofMC(SERVERBOUND, 0x1C, "move_player_rot"); // Set Player Rotation + public static final PacketType SERVER_SET_PLAYER_ON_GROUND = ofMC(SERVERBOUND, 0x1D, "move_player_status_only"); // Set Player On Ground + public static final PacketType SERVER_MOVE_VEHICLE = ofMC(SERVERBOUND, 0x1E, "move_vehicle"); // Move Vehicle + public static final PacketType SERVER_PADDLE_BOAT = ofMC(SERVERBOUND, 0x1F, "paddle_boat"); // Paddle Boat + public static final PacketType SERVER_PICK_ITEM = ofMC(SERVERBOUND, 0x20, "pick_item"); // Pick Item + public static final PacketType SERVER_PING_REQUEST = ofMC(SERVERBOUND, 0x21, "ping_request"); // Ping Request (play) + public static final PacketType SERVER_PLACE_RECIPE = ofMC(SERVERBOUND, 0x22, "place_recipe"); // Place Recipe + public static final PacketType SERVER_PLAYER_ABILITIES = ofMC(SERVERBOUND, 0x23, "player_abilities"); // Player Abilities (serverbound) + public static final PacketType SERVER_PLAYER_ACTION = ofMC(SERVERBOUND, 0x24, "player_action"); // Player Action + public static final PacketType SERVER_PLAYER_COMMAND = ofMC(SERVERBOUND, 0x25, "player_command"); // Player Command + public static final PacketType SERVER_PLAYER_INPUT = ofMC(SERVERBOUND, 0x26, "player_input"); // Player Input + public static final PacketType SERVER_PONG = ofMC(SERVERBOUND, 0x27, "pong"); // Pong (play) + public static final PacketType SERVER_CHANGE_RECIPE_BOOK_SETTINGS = ofMC(SERVERBOUND, 0x28, "recipe_book_change_settings"); // Change Recipe Book Settings + public static final PacketType SERVER_SET_SEEN_RECIPE = ofMC(SERVERBOUND, 0x29, "recipe_book_seen_recipe"); // Set Seen Recipe + public static final PacketType SERVER_RENAME_ITEM = ofMC(SERVERBOUND, 0x2A, "rename_item"); // Rename Item + public static final PacketType SERVER_RESOURCE_PACK_RESPONSE = ofMC(SERVERBOUND, 0x2B, "resource_pack"); // Resource Pack Response (play) + public static final PacketType SERVER_SEEN_ADVANCEMENTS = ofMC(SERVERBOUND, 0x2C, "seen_advancements"); // Seen Advancements + public static final PacketType SERVER_SELECT_TRADE = ofMC(SERVERBOUND, 0x2D, "select_trade"); // Select Trade + public static final PacketType SERVER_SET_BEACON_EFFECT = ofMC(SERVERBOUND, 0x2E, "set_beacon"); // Set Beacon Effect + public static final PacketType SERVER_SET_HELD_ITEM = ofMC(SERVERBOUND, 0x2F, "set_carried_item"); // Set Held Item (serverbound) + public static final PacketType SERVER_PROGRAM_COMMAND_BLOCK = ofMC(SERVERBOUND, 0x30, "set_command_block"); // Program Command Block + public static final PacketType SERVER_PROGRAM_COMMAND_BLOCK_MINECART = ofMC(SERVERBOUND, 0x31, "set_command_minecart"); // Program Command Block Minecart + public static final PacketType SERVER_SET_CREATIVE_MODE_SLOT = ofMC(SERVERBOUND, 0x32, "set_creative_mode_slot"); // Set Creative Mode Slot + public static final PacketType SERVER_PROGRAM_JIGSAW_BLOCK = ofMC(SERVERBOUND, 0x33, "set_jigsaw_block"); // Program Jigsaw Block + public static final PacketType SERVER_PROGRAM_STRUCTURE_BLOCK = ofMC(SERVERBOUND, 0x34, "set_structure_block"); // Program Structure Block + public static final PacketType SERVER_UPDATE_SIGN = ofMC(SERVERBOUND, 0x35, "sign_update"); // Update Sign + public static final PacketType SERVER_SWING_ARM = ofMC(SERVERBOUND, 0x36, "swing"); // Swing Arm + public static final PacketType SERVER_TELEPORT_TO_ENTITY = ofMC(SERVERBOUND, 0x37, "teleport_to_entity"); // Teleport To Entity + public static final PacketType SERVER_USE_ITEM_ON = ofMC(SERVERBOUND, 0x38, "use_item_on"); // Use Item On + public static final PacketType SERVER_USE_ITEM = ofMC(SERVERBOUND, 0x39, "use_item"); // Use Item + + // + + private static final PacketRegistry REGISTRY = + PacketRegistry.create( + PacketMap.path2PacketBuilder() + .add( + // + + CLIENT_BUNDLE_DELIMITER, + CLIENT_SPAWN_ENTITY, + CLIENT_SPAWN_EXPERIENCE_ORB, + CLIENT_ENTITY_ANIMATION, + CLIENT_AWARD_STATISTICS, + CLIENT_ACKNOWLEDGE_BLOCK_CHANGE, + CLIENT_SET_BLOCK_DESTROY_STAGE, + CLIENT_BLOCK_ENTITY_DATA, + CLIENT_BLOCK_ACTION, + CLIENT_BLOCK_UPDATE, + CLIENT_BOSS_BAR, + CLIENT_CHANGE_DIFFICULTY, + CLIENT_CHUNK_BATCH_FINISHED, + CLIENT_CHUNK_BATCH_START, + CLIENT_CHUNK_BIOMES, + CLIENT_CLEAR_TITLES, + CLIENT_COMMAND_SUGGESTIONS_RESPONSE, + CLIENT_COMMANDS, + CLIENT_CLOSE_CONTAINER, + CLIENT_SET_CONTAINER_CONTENT, + CLIENT_SET_CONTAINER_PROPERTY, + CLIENT_SET_CONTAINER_SLOT, + CLIENT_COOKIE_REQUEST, + CLIENT_SET_COOLDOWN, + CLIENT_CHAT_SUGGESTIONS, + CLIENT_PLUGIN_MESSAGE, + CLIENT_DAMAGE_EVENT, + CLIENT_DEBUG_SAMPLE, + CLIENT_DELETE_MESSAGE, + CLIENT_DISCONNECT, + CLIENT_DISGUISED_CHAT_MESSAGE, + CLIENT_ENTITY_EVENT, + CLIENT_EXPLOSION, + CLIENT_UNLOAD_CHUNK, + CLIENT_GAME_EVENT, + CLIENT_OPEN_HORSE_SCREEN, + CLIENT_HURT_ANIMATION, + CLIENT_INITIALIZE_WORLD_BORDER, + CLIENT_KEEP_ALIVE, + CLIENT_CHUNK_DATA_AND_UPDATE_LIGHT, + CLIENT_WORLD_EVENT, + CLIENT_PARTICLE, + CLIENT_UPDATE_LIGHT, + CLIENT_LOGIN, + CLIENT_MAP_DATA, + CLIENT_MERCHANT_OFFERS, + CLIENT_UPDATE_ENTITY_POSITION, + CLIENT_UPDATE_ENTITY_POSITION_AND_ROTATION, + CLIENT_UPDATE_ENTITY_ROTATION, + CLIENT_MOVE_VEHICLE, + CLIENT_OPEN_BOOK, + CLIENT_OPEN_SCREEN, + CLIENT_OPEN_SIGN_EDITOR, + CLIENT_PING, + CLIENT_PING_RESPONSE, + CLIENT_PLACE_GHOST_RECIPE, + CLIENT_PLAYER_ABILITIES, + CLIENT_PLAYER_CHAT_MESSAGE, + CLIENT_END_COMBAT, + CLIENT_ENTER_COMBAT, + CLIENT_COMBAT_DEATH, + CLIENT_PLAYER_INFO_REMOVE, + CLIENT_PLAYER_INFO_UPDATE, + CLIENT_LOOK_AT, + CLIENT_SYNCHRONIZE_PLAYER_POSITION, + CLIENT_UPDATE_RECIPE_BOOK, + CLIENT_REMOVE_ENTITIES, + CLIENT_REMOVE_ENTITY_EFFECT, + CLIENT_RESET_SCORE, + CLIENT_REMOVE_RESOURCE_PACK, + CLIENT_ADD_RESOURCE_PACK, + CLIENT_RESPAWN, + CLIENT_SET_HEAD_ROTATION, + CLIENT_UPDATE_SECTION_BLOCKS, + CLIENT_SELECT_ADVANCEMENT_TAB, + CLIENT_SERVER_DATA, + CLIENT_SET_ACTION_BAR_TEXT, + CLIENT_SET_BORDER_CENTER, + CLIENT_SET_BORDER_LERP_SIZE, + CLIENT_SET_BORDER_SIZE, + CLIENT_SET_BORDER_WARNING_DELAY, + CLIENT_SET_BORDER_WARNING_DISTANCE, + CLIENT_SET_CAMERA, + CLIENT_SET_HELD_ITEM, + CLIENT_SET_CENTER_CHUNK, + CLIENT_SET_RENDER_DISTANCE, + CLIENT_SET_DEFAULT_SPAWN_POSITION, + CLIENT_DISPLAY_OBJECTIVE, + CLIENT_SET_ENTITY_METADATA, + CLIENT_LINK_ENTITIES, + CLIENT_SET_ENTITY_VELOCITY, + CLIENT_SET_EQUIPMENT, + CLIENT_SET_EXPERIENCE, + CLIENT_SET_HEALTH, + CLIENT_UPDATE_OBJECTIVES, + CLIENT_SET_PASSENGERS, + CLIENT_UPDATE_TEAMS, + CLIENT_UPDATE_SCORE, + CLIENT_SET_SIMULATION_DISTANCE, + CLIENT_SET_SUBTITLE_TEXT, + CLIENT_UPDATE_TIME, + CLIENT_SET_TITLE_TEXT, + CLIENT_SET_TITLE_ANIMATION_TIMES, + CLIENT_ENTITY_SOUND_EFFECT, + CLIENT_SOUND_EFFECT, + CLIENT_START_CONFIGURATION, + CLIENT_STOP_SOUND, + CLIENT_STORE_COOKIE, + CLIENT_SYSTEM_CHAT_MESSAGE, + CLIENT_SET_TAB_LIST_HEADER_AND_FOOTER, + CLIENT_TAG_QUERY_RESPONSE, + CLIENT_PICKUP_ITEM, + CLIENT_TELEPORT_ENTITY, + CLIENT_SET_TICKING_STATE, + CLIENT_STEP_TICK, + CLIENT_TRANSFER, + CLIENT_UPDATE_ADVANCEMENTS, + CLIENT_UPDATE_ATTRIBUTES, + CLIENT_ENTITY_EFFECT, + CLIENT_UPDATE_RECIPES, + CLIENT_UPDATE_TAGS, + CLIENT_PROJECTILE_POWER, + CLIENT_CUSTOM_REPORT_DETAILS, + CLIENT_SERVER_LINKS, + + // + // + + SERVER_CONFIRM_TELEPORTATION, + SERVER_QUERY_BLOCK_ENTITY_TAG, + SERVER_CHANGE_DIFFICULTY, + SERVER_ACKNOWLEDGE_MESSAGE, + SERVER_CHAT_COMMAND, + SERVER_SIGNED_CHAT_COMMAND, + SERVER_CHAT_MESSAGE, + SERVER_PLAYER_SESSION, + SERVER_CHUNK_BATCH_RECEIVED, + SERVER_CLIENT_STATUS, + SERVER_CLIENT_INFORMATION, + SERVER_COMMAND_SUGGESTIONS_REQUEST, + SERVER_ACKNOWLEDGE_CONFIGURATION, + SERVER_CLICK_CONTAINER_BUTTON, + SERVER_CLICK_CONTAINER, + SERVER_CLOSE_CONTAINER, + SERVER_CHANGE_CONTAINER_SLOT_STATE, + SERVER_COOKIE_RESPONSE, + SERVER_PLUGIN_MESSAGE, + SERVER_DEBUG_SAMPLE_SUBSCRIPTION, + SERVER_EDIT_BOOK, + SERVER_QUERY_ENTITY_TAG, + SERVER_INTERACT, + SERVER_JIGSAW_GENERATE, + SERVER_KEEP_ALIVE, + SERVER_LOCK_DIFFICULTY, + SERVER_SET_PLAYER_POSITION, + SERVER_SET_PLAYER_POSITION_AND_ROTATION, + SERVER_SET_PLAYER_ROTATION, + SERVER_SET_PLAYER_ON_GROUND, + SERVER_MOVE_VEHICLE, + SERVER_PADDLE_BOAT, + SERVER_PICK_ITEM, + SERVER_PING_REQUEST, + SERVER_PLACE_RECIPE, + SERVER_PLAYER_ABILITIES, + SERVER_PLAYER_ACTION, + SERVER_PLAYER_COMMAND, + SERVER_PLAYER_INPUT, + SERVER_PONG, + SERVER_CHANGE_RECIPE_BOOK_SETTINGS, + SERVER_SET_SEEN_RECIPE, + SERVER_RENAME_ITEM, + SERVER_RESOURCE_PACK_RESPONSE, + SERVER_SEEN_ADVANCEMENTS, + SERVER_SELECT_TRADE, + SERVER_SET_BEACON_EFFECT, + SERVER_SET_HELD_ITEM, + SERVER_PROGRAM_COMMAND_BLOCK, + SERVER_PROGRAM_COMMAND_BLOCK_MINECART, + SERVER_SET_CREATIVE_MODE_SLOT, + SERVER_PROGRAM_JIGSAW_BLOCK, + SERVER_PROGRAM_STRUCTURE_BLOCK, + SERVER_UPDATE_SIGN, + SERVER_SWING_ARM, + SERVER_TELEPORT_TO_ENTITY, + SERVER_USE_ITEM_ON, + SERVER_USE_ITEM + + // + ).build() + ); + + @Contract(" -> fail") + private PlayPackets() throws AssertionError { + throw new AssertionError("Registry class"); + } + + /** + * Returns the registry of play packet types + * + * @return The registry of play packet types + */ + public static @Unmodifiable @NotNull PacketRegistry registry() { + return REGISTRY; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/StatusPackets.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/StatusPackets.java new file mode 100644 index 00000000..7d300051 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/StatusPackets.java @@ -0,0 +1,71 @@ +package com.minersstudios.wholib.packet.registry; + +import com.minersstudios.wholib.packet.PacketRegistry; +import com.minersstudios.wholib.packet.collection.PacketMap; +import com.minersstudios.wholib.packet.PacketType; +import com.minersstudios.wholib.utility.SharedConstants; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import static com.minersstudios.wholib.packet.PacketBound.*; +import static com.minersstudios.wholib.packet.PacketType.ofMC; + +/** + * Represents a registry of status packet types used in the Minecraft + * server networking. + * + * @see PacketType + * @see PacketRegistry + * @see Protocol Wiki - Status + * + * @version Minecraft {@value SharedConstants#MINECRAFT_VERSION}, + * Protocol {@value SharedConstants#PROTOCOL_VERSION} + */ +public final class StatusPackets { + // + + public static final PacketType CLIENT_STATUS_RESPONSE = ofMC(CLIENTBOUND, 0x00, "status_response"); // Status Response + public static final PacketType CLIENT_PONG_RESPONSE = ofMC(CLIENTBOUND, 0x01, "pong_response"); // Pong Response (status) + + // + // + + public static final PacketType SERVER_STATUS_REQUEST = ofMC(SERVERBOUND, 0x00, "status_request"); // Status Request + public static final PacketType SERVER_PING_REQUEST = ofMC(SERVERBOUND, 0x01, "ping_request"); // Ping Request (status) + + // + + private static final PacketRegistry REGISTRY = + PacketRegistry.create( + PacketMap.path2PacketBuilder() + .add( + // + + CLIENT_STATUS_RESPONSE, + CLIENT_PONG_RESPONSE, + + // + // + + SERVER_STATUS_REQUEST, + SERVER_PING_REQUEST + + // + ).build() + ); + + @Contract(" -> fail") + private StatusPackets() throws AssertionError { + throw new AssertionError("Registry class"); + } + + /** + * Returns the registry of status packet types + * + * @return The registry of status packet types + */ + public static @Unmodifiable @NotNull PacketRegistry registry() { + return REGISTRY; + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/package-info.java b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/package-info.java new file mode 100644 index 00000000..fd61ef26 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/packet/registry/package-info.java @@ -0,0 +1,17 @@ +/** + * This package contains all the registries for the packet types. + *

+ * Available registries : + *

    + *
  • {@link com.minersstudios.wholib.packet.registry.HandshakePackets}
  • + *
  • {@link com.minersstudios.wholib.packet.registry.PlayPackets}
  • + *
  • {@link com.minersstudios.wholib.packet.registry.StatusPackets}
  • + *
  • {@link com.minersstudios.wholib.packet.registry.LoginPackets}
  • + *
  • {@link com.minersstudios.wholib.packet.registry.ConfigurationPackets}
  • + *
+ * + * @see Protocol Wiki + * @see com.minersstudios.wholib.packet.PacketRegistry PacketRegistry + * @see com.minersstudios.wholib.packet Root PacketAPI package + */ +package com.minersstudios.wholib.packet.registry; diff --git a/lib/common/src/main/java/com/minersstudios/wholib/registrable/Registrable.java b/lib/common/src/main/java/com/minersstudios/wholib/registrable/Registrable.java new file mode 100644 index 00000000..fb70c47e --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/registrable/Registrable.java @@ -0,0 +1,58 @@ +package com.minersstudios.wholib.registrable; + +import org.jetbrains.annotations.NotNull; + +/** + * Represents an object that can be registered with {@link Registrar registrars}. + *

+ * The key of the registrable object is used to identify the object in the + * registrar and must be unique. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Available optional overridable methods
MethodDescription
{@link #onRegister()} + * Called when the object is registered by a registrar in the + * {@link Registrar#register(Registrable)} method + *
{@link #onUnregister()} + * Called when the object is unregistered by a registrar in the + * {@link Registrar#unregister(Registrable)} method + *
+ * + * @param The key type of the registrable object + * + * @see Registrar + */ +public interface Registrable { + + /** + * Returns the key of the registrable object + * + * @return The key of the registrable object + */ + @NotNull K getKey(); + + /** + * Called when the object is registered + */ + default void onRegister() { + // Do nothing by default + } + + /** + * Called when the object is unregistered + */ + default void onUnregister() { + // Do nothing by default + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/registrable/Registrar.java b/lib/common/src/main/java/com/minersstudios/wholib/registrable/Registrar.java new file mode 100644 index 00000000..f785729b --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/registrable/Registrar.java @@ -0,0 +1,54 @@ +package com.minersstudios.wholib.registrable; + +import org.jetbrains.annotations.NotNull; + +/** + * Represents a registrar that can store and manage + * {@link Registrable registrable} objects + * + * @param The registrable object type + * + * @see Registrable + */ +public interface Registrar> { + + /** + * Registers the registrable object. + *

+ * IMPORTANT: This method MUST handle the + * {@link Registrable#onRegister()} method call of the registrable object. + * + * @param registrable The registrable object + * @return True if the object has not yet been registered and its + * registration was successful + */ + boolean register(final @NotNull R registrable); + + /** + * Unregisters the registrable object. + *

+ * IMPORTANT: This method MUST handle the + * {@link Registrable#onUnregister()} method call of the registrable object. + * + * @param registrable The registrable object + * @return True if the object has been registered and its deregistration + * was successful + */ + boolean unregister(final @NotNull R registrable); + + /** + * Unregisters all registrable objects. + *

+ * IMPORTANT: This method MUST handle the + * {@link Registrable#onUnregister()} method call of the registrable objects. + */ + void unregisterAll(); + + /** + * Checks if the registrable object is registered + * + * @param registrable The registrable object + * @return True if the object is registered + */ + boolean isRegistered(final @NotNull R registrable); +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/registrable/package-info.java b/lib/common/src/main/java/com/minersstudios/wholib/registrable/package-info.java new file mode 100644 index 00000000..b27e5089 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/registrable/package-info.java @@ -0,0 +1,8 @@ +/** + * This package contains the basic interfaces for registered objects and their + * registrars + * + * @see com.minersstudios.wholib.registrable.Registrable + * @see com.minersstudios.wholib.registrable.Registrar + */ +package com.minersstudios.wholib.registrable; diff --git a/paper/src/main/java/com/minersstudios/whomine/resource/ResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/resource/ResourceManager.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/resource/ResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/resource/ResourceManager.java index 283154c5..d0fe102e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resource/ResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/resource/ResourceManager.java @@ -1,10 +1,11 @@ -package com.minersstudios.whomine.resource; +package com.minersstudios.wholib.resource; import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.io.InputStream; +@SuppressWarnings("unused") public interface ResourceManager { /** diff --git a/paper/src/main/java/com/minersstudios/whomine/resource/file/AbstractFileResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/resource/file/AbstractFileResourceManager.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/resource/file/AbstractFileResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/resource/file/AbstractFileResourceManager.java index 702de276..87f6acd6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resource/file/AbstractFileResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/resource/file/AbstractFileResourceManager.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.resource.file; +package com.minersstudios.wholib.resource.file; import org.jetbrains.annotations.NotNull; @@ -7,6 +7,7 @@ import java.io.IOException; public abstract class AbstractFileResourceManager implements FileResourceManager { + private final File file; protected AbstractFileResourceManager(final @NotNull File file) { diff --git a/paper/src/main/java/com/minersstudios/whomine/resource/file/FileResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/resource/file/FileResourceManager.java similarity index 66% rename from paper/src/main/java/com/minersstudios/whomine/resource/file/FileResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/resource/file/FileResourceManager.java index 198c4b5e..253c6a07 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resource/file/FileResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/resource/file/FileResourceManager.java @@ -1,10 +1,11 @@ -package com.minersstudios.whomine.resource.file; +package com.minersstudios.wholib.resource.file; -import com.minersstudios.whomine.resource.ResourceManager; +import com.minersstudios.wholib.resource.ResourceManager; import org.jetbrains.annotations.NotNull; import java.io.File; +@SuppressWarnings("unused") public interface FileResourceManager extends ResourceManager { /** diff --git a/paper/src/main/java/com/minersstudios/whomine/resource/github/AbstractGithubResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/resource/github/AbstractGithubResourceManager.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/resource/github/AbstractGithubResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/resource/github/AbstractGithubResourceManager.java index b4370948..80e42d1a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resource/github/AbstractGithubResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/resource/github/AbstractGithubResourceManager.java @@ -1,9 +1,8 @@ -package com.minersstudios.whomine.resource.github; +package com.minersstudios.wholib.resource.github; import com.google.gson.Gson; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.resource.file.AbstractFileResourceManager; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.resource.file.AbstractFileResourceManager; +import com.minersstudios.wholib.utility.ChatUtils; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,24 +14,25 @@ import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; -import java.nio.file.Path; import java.util.Arrays; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicReference; +import java.util.logging.Logger; import static java.net.HttpURLConnection.*; public abstract class AbstractGithubResourceManager extends AbstractFileResourceManager implements GithubResourceManager { + private static final Logger LOGGER = Logger.getLogger("ResourceManager"); + private static final Gson GSON = new Gson(); + private static final String AUTHORIZATION_HEADER = "Authorization"; + private static final String AUTHORIZATION_VALUE = "Bearer %s"; + private final String user; private final String repo; private final AtomicReference tags; private final String currentTag; private transient final String token; - private static final Gson GSON = new Gson(); - private static final String AUTHORIZATION_HEADER = "Authorization"; - private static final String AUTHORIZATION_VALUE = "Bearer %s"; - protected AbstractGithubResourceManager( final @NotNull File file, final @NotNull String user, @@ -139,20 +139,18 @@ protected AbstractGithubResourceManager( !directory.exists() && !directory.mkdirs() ) { - MSLogger.warning("Failed to create a new directory: " + directory.getAbsolutePath()); + LOGGER.warning("Failed to create a new directory: " + directory.getAbsolutePath()); } - final Path path = file.toPath(); - final HttpClient client = - HttpClient.newBuilder() - .followRedirects(HttpClient.Redirect.ALWAYS) - .build(); - - try { + try ( + final var client = HttpClient.newBuilder() + .followRedirects(HttpClient.Redirect.ALWAYS) + .build() + ) { final int statusCode = client.send( HttpRequest.newBuilder(uri).build(), - HttpResponse.BodyHandlers.ofFile(path) + HttpResponse.BodyHandlers.ofFile(file.toPath()) ).statusCode(); if (statusCode != HTTP_OK) { @@ -187,8 +185,8 @@ protected AbstractGithubResourceManager( ); } - try { - response = HttpClient.newHttpClient().send( + try (final var client = HttpClient.newHttpClient()) { + response = client.send( builder.build(), HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8) ); diff --git a/paper/src/main/java/com/minersstudios/whomine/resource/github/GithubResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/resource/github/GithubResourceManager.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/resource/github/GithubResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/resource/github/GithubResourceManager.java index ddc15967..fdd01371 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resource/github/GithubResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/resource/github/GithubResourceManager.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.resource.github; +package com.minersstudios.wholib.resource.github; -import com.minersstudios.whomine.resource.file.FileResourceManager; -import com.minersstudios.whomine.resource.uri.URIResourceManager; +import com.minersstudios.wholib.resource.file.FileResourceManager; +import com.minersstudios.wholib.resource.uri.URIResourceManager; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,6 +10,7 @@ import java.net.URI; import java.util.concurrent.CompletableFuture; +@SuppressWarnings("unused") public interface GithubResourceManager extends FileResourceManager, URIResourceManager { /** * The URL to get the tags of a GitHub repository. diff --git a/paper/src/main/java/com/minersstudios/whomine/resource/github/Tag.java b/lib/common/src/main/java/com/minersstudios/wholib/resource/github/Tag.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/resource/github/Tag.java rename to lib/common/src/main/java/com/minersstudios/wholib/resource/github/Tag.java index 87f83e77..f28ac6bb 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resource/github/Tag.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/resource/github/Tag.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.resource.github; +package com.minersstudios.wholib.resource.github; import com.google.gson.annotations.SerializedName; import org.jetbrains.annotations.Contract; @@ -10,8 +10,10 @@ /** * Represents a tag in a GitHub repository */ +@SuppressWarnings("unused") @Immutable public final class Tag { + private final String name; @SerializedName("zipball_url") private final String zipballUrl; diff --git a/paper/src/main/java/com/minersstudios/whomine/resource/uri/AbstractURIResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/resource/uri/AbstractURIResourceManager.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/resource/uri/AbstractURIResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/resource/uri/AbstractURIResourceManager.java index 9142ffa7..def0bd67 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resource/uri/AbstractURIResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/resource/uri/AbstractURIResourceManager.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.resource.uri; +package com.minersstudios.wholib.resource.uri; import org.jetbrains.annotations.NotNull; @@ -8,6 +8,7 @@ import java.util.concurrent.CompletableFuture; public abstract class AbstractURIResourceManager implements URIResourceManager { + private final URI uri; protected AbstractURIResourceManager(final @NotNull URI uri) { diff --git a/paper/src/main/java/com/minersstudios/whomine/resource/uri/URIResourceManager.java b/lib/common/src/main/java/com/minersstudios/wholib/resource/uri/URIResourceManager.java similarity index 72% rename from paper/src/main/java/com/minersstudios/whomine/resource/uri/URIResourceManager.java rename to lib/common/src/main/java/com/minersstudios/wholib/resource/uri/URIResourceManager.java index c9173845..017209f4 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resource/uri/URIResourceManager.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/resource/uri/URIResourceManager.java @@ -1,11 +1,12 @@ -package com.minersstudios.whomine.resource.uri; +package com.minersstudios.wholib.resource.uri; -import com.minersstudios.whomine.resource.ResourceManager; +import com.minersstudios.wholib.resource.ResourceManager; import org.jetbrains.annotations.NotNull; import java.net.URI; import java.util.concurrent.CompletableFuture; +@SuppressWarnings("unused") public interface URIResourceManager extends ResourceManager { /** diff --git a/common/src/main/java/com/minersstudios/whomine/api/status/FailureStatus.java b/lib/common/src/main/java/com/minersstudios/wholib/status/FailureStatus.java similarity index 83% rename from common/src/main/java/com/minersstudios/whomine/api/status/FailureStatus.java rename to lib/common/src/main/java/com/minersstudios/wholib/status/FailureStatus.java index 2801281d..d068e934 100644 --- a/common/src/main/java/com/minersstudios/whomine/api/status/FailureStatus.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/status/FailureStatus.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.api.status; +package com.minersstudios.wholib.status; -import com.minersstudios.whomine.api.annotation.StatusKey; +import com.minersstudios.wholib.annotation.StatusKey; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,19 +14,20 @@ *
* Factory methods for creating a failure status: *

    - *
  • {@link #failure(String, Priority)}
  • + *
  • {@link #failure(String, StatusPriority)}
  • *
  • {@link #failureLow(String)}
  • *
  • {@link #failureHigh(String)}
  • *
* * @see Status */ +@SuppressWarnings("unused") @Immutable public class FailureStatus extends ImplStatus { protected FailureStatus( final @StatusKey @NotNull String key, - final @NotNull Priority priority + final @NotNull StatusPriority priority ) { super(key, priority); } diff --git a/common/src/main/java/com/minersstudios/whomine/api/status/ImplStatus.java b/lib/common/src/main/java/com/minersstudios/wholib/status/ImplStatus.java similarity index 72% rename from common/src/main/java/com/minersstudios/whomine/api/status/ImplStatus.java rename to lib/common/src/main/java/com/minersstudios/wholib/status/ImplStatus.java index e85f6dcd..c6ef92d0 100644 --- a/common/src/main/java/com/minersstudios/whomine/api/status/ImplStatus.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/status/ImplStatus.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.api.status; +package com.minersstudios.wholib.status; -import com.minersstudios.whomine.api.annotation.StatusKey; +import com.minersstudios.wholib.annotation.StatusKey; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,12 +11,13 @@ @Immutable abstract class ImplStatus implements Status { + private final String key; - private final Status.Priority priority; + private final StatusPriority priority; protected ImplStatus( final @StatusKey @NotNull String key, - final @NotNull Priority priority + final @NotNull StatusPriority priority ) { this.key = key; this.priority = priority; @@ -29,18 +30,18 @@ protected ImplStatus( } @Override - public final @NotNull Priority getPriority() { + public final @NotNull StatusPriority getPriority() { return this.priority; } @Override public final boolean isHighPriority() { - return this.priority == Priority.HIGH; + return this.priority == StatusPriority.HIGH; } @Override public final boolean isLowPriority() { - return this.priority == Priority.LOW; + return this.priority == StatusPriority.LOW; } @Override @@ -57,21 +58,12 @@ public int hashCode() { @Contract("null -> false") @Override public boolean equals(final @Nullable Object obj) { - if (this == obj) { - return true; - } - - if ( - obj == null - || this.getClass() != obj.getClass() - ) { - return false; - } - - final ImplStatus that = (ImplStatus) obj; - - return this.key.equals(that.key) - && this.priority == that.priority; + return this == obj + || ( + obj instanceof Status that + && this.key.equals(that.getKey()) + && this.priority == that.getPriority() + ); } @Override diff --git a/common/src/main/java/com/minersstudios/whomine/api/status/Status.java b/lib/common/src/main/java/com/minersstudios/wholib/status/Status.java similarity index 86% rename from common/src/main/java/com/minersstudios/whomine/api/status/Status.java rename to lib/common/src/main/java/com/minersstudios/wholib/status/Status.java index b3c6335b..19e97eba 100644 --- a/common/src/main/java/com/minersstudios/whomine/api/status/Status.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/status/Status.java @@ -1,7 +1,8 @@ -package com.minersstudios.whomine.api.status; +package com.minersstudios.wholib.status; -import com.minersstudios.whomine.api.annotation.StatusKey; -import com.minersstudios.whomine.api.throwable.InvalidRegexException; +import com.minersstudios.wholib.annotation.StatusKey; +import com.minersstudios.wholib.order.Ordered; +import com.minersstudios.wholib.throwable.InvalidRegexException; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,7 +10,7 @@ import java.util.function.Consumer; import java.util.function.Function; -import static com.minersstudios.whomine.api.annotation.StatusKey.Validator.validate; +import static com.minersstudios.wholib.annotation.StatusKey.Validator.validate; /** * Represents a status. @@ -20,7 +21,8 @@ *
  • {@link FailureStatus Failure Status}
  • * */ -public interface Status { +@SuppressWarnings("unused") +public interface Status extends Ordered { /** * Returns the key of the status @@ -30,12 +32,21 @@ public interface Status { @StatusKey @NotNull String getKey(); + /** + * @deprecated Use {@link #getPriority()} instead + */ + @Deprecated + @Override + default @NotNull StatusPriority getOrder() { + return this.getPriority(); + } + /** * Returns the priority of the status * * @return The priority of the status */ - @NotNull Priority getPriority(); + @NotNull StatusPriority getPriority(); /** * Returns whether the status is a high priority @@ -110,11 +121,11 @@ U apply( * @return A new status with the specified key and low priority * @throws InvalidRegexException If the key does not match the * {@link StatusKey#REGEX regex} - * @see #success(String, Priority) + * @see #success(String, StatusPriority) */ @Contract("_ -> new") static @NotNull SuccessStatus successLow(final @StatusKey @NotNull String key) throws InvalidRegexException { - return success(key, Priority.LOW); + return success(key, StatusPriority.LOW); } /** @@ -129,14 +140,14 @@ U apply( * {@link StatusKey#REGEX regex} * @throws IllegalArgumentException If the failure status has a different * priority than the specified priority - * @see #success(String, Priority, FailureStatus) + * @see #success(String, StatusPriority, FailureStatus) */ @Contract("_, _ -> new") static @NotNull SuccessStatus successLow( final @StatusKey @NotNull String key, final @Nullable FailureStatus failureStatus ) throws InvalidRegexException, IllegalArgumentException { - return success(key, Priority.LOW, failureStatus); + return success(key, StatusPriority.LOW, failureStatus); } /** @@ -146,11 +157,11 @@ U apply( * @return A new status with the specified key and high priority * @throws InvalidRegexException If the key does not match the * {@link StatusKey#REGEX regex} - * @see #success(String, Priority) + * @see #success(String, StatusPriority) */ @Contract("_ -> new") static @NotNull SuccessStatus successHigh(final @StatusKey @NotNull String key) throws InvalidRegexException { - return success(key, Priority.HIGH); + return success(key, StatusPriority.HIGH); } /** @@ -166,14 +177,14 @@ U apply( * {@link StatusKey#REGEX regex} * @throws IllegalArgumentException If the failure status has a different * priority than the specified priority - * @see #success(String, Priority, FailureStatus) + * @see #success(String, StatusPriority, FailureStatus) */ @Contract("_, _ -> new") static @NotNull SuccessStatus successHigh( final @StatusKey @NotNull String key, final @Nullable FailureStatus failureStatus ) throws InvalidRegexException, IllegalArgumentException { - return success(key, Priority.HIGH, failureStatus); + return success(key, StatusPriority.HIGH, failureStatus); } /** @@ -189,7 +200,7 @@ U apply( @Contract("_, _ -> new") static @NotNull SuccessStatus success( final @StatusKey @NotNull String key, - final @NotNull Priority priority + final @NotNull StatusPriority priority ) throws InvalidRegexException { validate(key); @@ -213,14 +224,14 @@ U apply( @Contract("_, _, _ -> new") static @NotNull SuccessStatus success( final @StatusKey @NotNull String key, - final @NotNull Priority priority, + final @NotNull StatusPriority priority, final @Nullable FailureStatus failureStatus ) throws InvalidRegexException, IllegalArgumentException { validate(key); if ( failureStatus != null - && failureStatus.getPriority() != priority + && !failureStatus.isEqualTo(priority) ) { throw new IllegalArgumentException( "Failure status must have the same priority as the main status" @@ -237,11 +248,11 @@ U apply( * @return A new failure status with the specified key and low priority * @throws InvalidRegexException If the key does not match the * {@link StatusKey#REGEX regex} - * @see #failure(String, Priority) + * @see #failure(String, StatusPriority) */ @Contract("_ -> new") static @NotNull FailureStatus failureLow(final @StatusKey @NotNull String key) throws InvalidRegexException { - return failure(key, Priority.LOW); + return failure(key, StatusPriority.LOW); } /** @@ -251,11 +262,11 @@ U apply( * @return A new failure status with the specified key and medium priority * @throws InvalidRegexException If the key does not match the * {@link StatusKey#REGEX regex} - * @see #failure(String, Priority) + * @see #failure(String, StatusPriority) */ @Contract("_ -> new") static @NotNull FailureStatus failureHigh(final @StatusKey @NotNull String key) throws InvalidRegexException { - return failure(key, Priority.HIGH); + return failure(key, StatusPriority.HIGH); } /** @@ -271,23 +282,10 @@ U apply( @Contract("_, _ -> new") static @NotNull FailureStatus failure( final @StatusKey @NotNull String key, - final @NotNull Priority priority + final @NotNull StatusPriority priority ) throws InvalidRegexException { validate(key); return new FailureStatus(key, priority); } - - /** - * Priority of the status. - *
    - * There are two types of priorities: - *
      - *
    • {@link Priority#LOW Low-priority}
    • - *
    • {@link Priority#HIGH High-priority}
    • - *
    - */ - enum Priority { - LOW, HIGH - } } diff --git a/common/src/main/java/com/minersstudios/whomine/api/status/StatusHandler.java b/lib/common/src/main/java/com/minersstudios/wholib/status/StatusHandler.java similarity index 98% rename from common/src/main/java/com/minersstudios/whomine/api/status/StatusHandler.java rename to lib/common/src/main/java/com/minersstudios/wholib/status/StatusHandler.java index 886d5cab..9bc64168 100644 --- a/common/src/main/java/com/minersstudios/whomine/api/status/StatusHandler.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/status/StatusHandler.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.api.status; +package com.minersstudios.wholib.status; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.Contract; @@ -20,8 +20,10 @@ * @see Status * @see StatusWatcher */ +@SuppressWarnings("unused") @ThreadSafe public final class StatusHandler { + private final AtomicReference highStatus; private final Set lowStatusSet; private final List watcherList; @@ -115,7 +117,7 @@ public void removeWatcher(final @NotNull StatusWatcher watcher) { * @param status Status to be assigned */ public void assignStatus(final @NotNull Status status) { - if (status.getPriority() == Status.Priority.HIGH) { + if (status.isHighPriority()) { this.highStatus.set(status); } else { this.lowStatusSet.add(status); diff --git a/lib/common/src/main/java/com/minersstudios/wholib/status/StatusPriority.java b/lib/common/src/main/java/com/minersstudios/wholib/status/StatusPriority.java new file mode 100644 index 00000000..a54ae9ee --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/status/StatusPriority.java @@ -0,0 +1,21 @@ +package com.minersstudios.wholib.status; + +import com.minersstudios.wholib.order.Order; + +/** + * Priority of the status. + *
    + * There are two types of priorities: + *
      + *
    • {@link #LOW Low-priority}
    • + *
    • {@link #HIGH High-priority}
    • + *
    + */ +public enum StatusPriority implements Order { + LOW, HIGH; + + @Override + public int asNumber() { + return this.ordinal(); + } +} diff --git a/common/src/main/java/com/minersstudios/whomine/api/status/StatusWatcher.java b/lib/common/src/main/java/com/minersstudios/wholib/status/StatusWatcher.java similarity index 99% rename from common/src/main/java/com/minersstudios/whomine/api/status/StatusWatcher.java rename to lib/common/src/main/java/com/minersstudios/wholib/status/StatusWatcher.java index dbfa3230..a77baa49 100644 --- a/common/src/main/java/com/minersstudios/whomine/api/status/StatusWatcher.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/status/StatusWatcher.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.api.status; +package com.minersstudios.wholib.status; import com.google.common.base.Joiner; import com.google.common.collect.Sets; @@ -22,15 +22,9 @@ * * @see StatusHandler */ +@SuppressWarnings("unused") @ThreadSafe public final class StatusWatcher { - private final Set successStatusSet; - private final Set failureStatusSet; - private final Runnable successRunnable; - private final Runnable failureRunnable; - private final boolean isAnySuccess; - private final boolean isAnyFailure; - private static final String FORMAT = "%s{" + "successStatusSet=[%s], " + "failureStatusSet=[%s], " + @@ -40,6 +34,13 @@ public final class StatusWatcher { "isAnyFailure=%s" + '}'; + private final Set successStatusSet; + private final Set failureStatusSet; + private final Runnable successRunnable; + private final Runnable failureRunnable; + private final boolean isAnySuccess; + private final boolean isAnyFailure; + private StatusWatcher(final @NotNull Builder builder) { this.successStatusSet = builder.successStatusSet; this.failureStatusSet = builder.failureStatusSet; diff --git a/common/src/main/java/com/minersstudios/whomine/api/status/SuccessStatus.java b/lib/common/src/main/java/com/minersstudios/wholib/status/SuccessStatus.java similarity index 72% rename from common/src/main/java/com/minersstudios/whomine/api/status/SuccessStatus.java rename to lib/common/src/main/java/com/minersstudios/wholib/status/SuccessStatus.java index 077426bf..3add5c05 100644 --- a/common/src/main/java/com/minersstudios/whomine/api/status/SuccessStatus.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/status/SuccessStatus.java @@ -1,11 +1,13 @@ -package com.minersstudios.whomine.api.status; +package com.minersstudios.wholib.status; -import com.minersstudios.whomine.api.annotation.StatusKey; +import com.minersstudios.wholib.annotation.StatusKey; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.annotation.concurrent.Immutable; +import java.util.Objects; import java.util.function.Consumer; import java.util.function.Function; @@ -14,8 +16,8 @@ *
    * Factory methods for creating a successful status: *
      - *
    • {@link #success(String, Priority)}
    • - *
    • {@link #success(String, Priority, FailureStatus)}
    • + *
    • {@link #success(String, StatusPriority)}
    • + *
    • {@link #success(String, StatusPriority, FailureStatus)}
    • *
    • {@link #successLow(String)} *
    • {@link #successLow(String, FailureStatus)}
    • *
    • {@link #successHigh(String)}
    • @@ -24,13 +26,15 @@ * * @see Status */ +@SuppressWarnings("unused") @Immutable public class SuccessStatus extends ImplStatus { + private final FailureStatus failureStatus; protected SuccessStatus( final @StatusKey @NotNull String key, - final @NotNull Priority priority, + final @NotNull StatusPriority priority, final @Nullable FailureStatus failureStatus ) { super(key, priority); @@ -54,6 +58,18 @@ public int hashCode() { : 31 * super.hashCode() + this.failureStatus.hashCode(); } + @Contract("null -> false") + @Override + public boolean equals(final @Nullable Object obj) { + return this == obj + || ( + obj instanceof SuccessStatus that + && this.getKey().equals(that.getKey()) + && this.getPriority() == that.getPriority() + && Objects.equals(this.failureStatus, that.failureStatus) + ); + } + @Override public @NotNull String toString() { return this.getKey() + diff --git a/lib/common/src/main/java/com/minersstudios/wholib/status/package-info.java b/lib/common/src/main/java/com/minersstudios/wholib/status/package-info.java new file mode 100644 index 00000000..8d015e4d --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/status/package-info.java @@ -0,0 +1,12 @@ +/** + * This package contains classes and interfaces related to statuses and their + * management. + *

      + * They are thread-safe and can be safely used to manage process statuses in a + * multithreading environment. + * + * @see com.minersstudios.wholib.status.Status + * @see com.minersstudios.wholib.status.StatusWatcher + * @see com.minersstudios.wholib.status.StatusHandler + */ +package com.minersstudios.wholib.status; diff --git a/common/src/main/java/com/minersstudios/whomine/api/throwable/ConfigurationException.java b/lib/common/src/main/java/com/minersstudios/wholib/throwable/ConfigurationException.java similarity index 97% rename from common/src/main/java/com/minersstudios/whomine/api/throwable/ConfigurationException.java rename to lib/common/src/main/java/com/minersstudios/wholib/throwable/ConfigurationException.java index 1c6cfad7..4c0abd9b 100644 --- a/common/src/main/java/com/minersstudios/whomine/api/throwable/ConfigurationException.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/throwable/ConfigurationException.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.api.throwable; +package com.minersstudios.wholib.throwable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/common/src/main/java/com/minersstudios/whomine/api/throwable/InvalidRegexException.java b/lib/common/src/main/java/com/minersstudios/wholib/throwable/InvalidRegexException.java similarity index 97% rename from common/src/main/java/com/minersstudios/whomine/api/throwable/InvalidRegexException.java rename to lib/common/src/main/java/com/minersstudios/wholib/throwable/InvalidRegexException.java index ea790f58..7561231a 100644 --- a/common/src/main/java/com/minersstudios/whomine/api/throwable/InvalidRegexException.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/throwable/InvalidRegexException.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.api.throwable; +package com.minersstudios.wholib.throwable; import org.jetbrains.annotations.Nullable; diff --git a/lib/common/src/main/java/com/minersstudios/wholib/throwable/InvalidResourceException.java b/lib/common/src/main/java/com/minersstudios/wholib/throwable/InvalidResourceException.java new file mode 100644 index 00000000..c6ffff55 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/throwable/InvalidResourceException.java @@ -0,0 +1,62 @@ +package com.minersstudios.wholib.throwable; + +import org.jetbrains.annotations.Nullable; + +/** + * Unchecked invalid resource exception. + *
      + * Signals that when checking a string against a resource or path pattern, the + * string was invalid. + */ +public class InvalidResourceException extends RuntimeException { + + /** + * Constructs a new exception with no detail message + */ + public InvalidResourceException() { + super(); + } + + /** + * Constructs a new exception with the specified detail message + * + * @param message The detail message (which is saved for later retrieval + * by the {@link #getMessage()} method) + */ + public InvalidResourceException(final @Nullable String message) { + super(message); + } + + /** + * Constructs a new exception with the specified detail message and cause + * + * @param message The detail message + * (which is saved for later retrieval by + * {@link #getMessage()} method) + * @param cause The cause + * (which is saved for later retrieval by {@link #getCause()} + * method) + * (A null value is permitted, and indicates that the cause + * is nonexistent or unknown) + */ + public InvalidResourceException( + final @Nullable String message, + final @Nullable Throwable cause + ) { + super(message, cause); + } + + /** + * Constructs a new exception with the specified cause and a detail message + * of {@code (cause == null ? null : cause.toString())} + * + * @param cause The cause + * (which is saved for later retrieval by {@link #getCause()} + * method) + * (A null value is permitted, and indicates that the cause is + * nonexistent or unknown) + */ + public InvalidResourceException(final @Nullable Throwable cause) { + super(cause); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/throwable/ListenerException.java b/lib/common/src/main/java/com/minersstudios/wholib/throwable/ListenerException.java new file mode 100644 index 00000000..218af731 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/throwable/ListenerException.java @@ -0,0 +1,62 @@ +package com.minersstudios.wholib.throwable; + +import com.minersstudios.wholib.listener.Listener; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents an exception thrown when an error occurs while working with + * {@link Listener listeners} + */ +public class ListenerException extends RuntimeException { + + /** + * Constructs a new exception with no detail message + */ + public ListenerException() { + super(); + } + + /** + * Constructs a new exception with the specified detail message + * + * @param message The detail message (which is saved for later retrieval + * by the {@link #getMessage()} method) + */ + public ListenerException(final @NotNull String message) { + super(message); + } + + /** + * Constructs a new exception with the specified detail message and cause + * + * @param message The detail message + * (which is saved for later retrieval by + * {@link #getMessage()} method) + * @param cause The cause + * (which is saved for later retrieval by {@link #getCause()} + * method) + * (A null value is permitted, and indicates that the cause + * is nonexistent or unknown) + */ + public ListenerException( + final @NotNull String message, + final @Nullable Throwable cause + ) { + super(message, cause); + } + + /** + * Constructs a new exception with the specified cause and a detail message + * of {@code (cause == null ? null : cause.toString())} + * + * @param cause The cause + * (which is saved for later retrieval by {@link #getCause()} + * method) + * (A null value is permitted, and indicates that the cause is + * nonexistent or unknown) + */ + public ListenerException(final @Nullable Throwable cause) { + super(cause); + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/ChatUtils.java b/lib/common/src/main/java/com/minersstudios/wholib/utility/ChatUtils.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/utility/ChatUtils.java rename to lib/common/src/main/java/com/minersstudios/wholib/utility/ChatUtils.java index 189df7bd..3615969b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/ChatUtils.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/utility/ChatUtils.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.utility; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; @@ -22,6 +22,7 @@ /** * Utility class for text-related operations */ +@SuppressWarnings("unused") public final class ChatUtils { /** * Default style for components. diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/Font.java b/lib/common/src/main/java/com/minersstudios/wholib/utility/Font.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/utility/Font.java rename to lib/common/src/main/java/com/minersstudios/wholib/utility/Font.java index 3becd8e8..9ec5891f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/Font.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/utility/Font.java @@ -1,9 +1,9 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.utility; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.Contract; -import static com.minersstudios.whomine.utility.ChatUtils.createDefaultStyledText; +import static com.minersstudios.wholib.utility.ChatUtils.createDefaultStyledText; /** * This class provides utility methods and constants for handling fonts. It @@ -14,6 +14,7 @@ * NOTE: PUA characters - "Private Use Area" characters, in range * from 0xE000 to 0xF8FF. */ +@SuppressWarnings("unused") public final class Font { @Contract(" -> fail") diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/IDUtils.java b/lib/common/src/main/java/com/minersstudios/wholib/utility/IDUtils.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/utility/IDUtils.java rename to lib/common/src/main/java/com/minersstudios/wholib/utility/IDUtils.java index 94946d30..dec79db1 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/IDUtils.java +++ b/lib/common/src/main/java/com/minersstudios/wholib/utility/IDUtils.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.utility; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -9,6 +9,7 @@ /** * Utility class for IDs */ +@SuppressWarnings("unused") public final class IDUtils { public static final String ID_REGEX = "-?\\d+"; public static final Pattern ID_PATTERN = Pattern.compile(ID_REGEX); diff --git a/lib/common/src/main/java/com/minersstudios/wholib/utility/ProjectInfo.java b/lib/common/src/main/java/com/minersstudios/wholib/utility/ProjectInfo.java new file mode 100644 index 00000000..94791f68 --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/utility/ProjectInfo.java @@ -0,0 +1,21 @@ +package com.minersstudios.wholib.utility; + +import org.jetbrains.annotations.Contract; + +@SuppressWarnings("unused") +public final class ProjectInfo { + // + + public static final String NAME = "WhoMine"; + public static final String VERSION = "1.0.0"; + public static final String DESCRIPTION = "A Minecraft plugin for WhoMine"; + public static final String AUTHOR = "MinersStudios"; + public static final String WEBSITE = "https://whomine.net"; + + // + + @Contract(" -> fail") + private ProjectInfo() throws AssertionError { + throw new AssertionError("Utility class"); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/utility/ResourcedPath.java b/lib/common/src/main/java/com/minersstudios/wholib/utility/ResourcedPath.java new file mode 100644 index 00000000..d376b84f --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/utility/ResourcedPath.java @@ -0,0 +1,286 @@ +package com.minersstudios.wholib.utility; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.annotation.ResourcePath; +import com.minersstudios.wholib.throwable.InvalidResourceException; +import net.kyori.adventure.key.Key; +import org.intellij.lang.annotations.Subst; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.concurrent.Immutable; + +/** + * Represents a resourced-path used in the API. + *

      + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
      Available factory methods
      MethodDescriptionExample
      {@link #empty(String)}Creates a new resourced-path with the given path and empty + * resource{@code ResourcedPath.empty("path")}
      {@link #minecraft(String)}Creates a new resourced-path with the given path and the + * {@link Resource#MINECRAFT minecraft} resource{@code ResourcedPath.minecraft("path")}
      {@link #realms(String)}Creates a new resourced-path with the given path and the + * {@link Resource#REALMS realms} resource{@code ResourcedPath.realms("path")}
      {@link #paper(String)}Creates a new resourced-path with the given path and the + * {@link Resource#PAPER paper} resource{@code ResourcedPath.paper("path")}
      {@link #whomine(String)}Creates a new resourced-path with the given path and the + * {@link Resource#WHOMINE whomine} resource{@code ResourcedPath.whomine("path")}
      {@link #of(String, String)}Creates a new resourced-path with the given resource and path{@code ResourcedPath.of("resource", "path")}
      {@link #of(String)}Creates a new resourced-path with the given resourced-path string{@code ResourcedPath.of("resource:path")}
      + * + * @see Resource + * @see Path + * @see ResourcePath + */ +@SuppressWarnings("unused") +@Immutable +public final class ResourcedPath { + + private final String resource; + private final String path; + + private ResourcedPath( + final @Resource @Nullable String resource, + final @Path @NotNull String path + ) throws InvalidResourceException { + this.resource = resource == null ? "" : resource; + this.path = path; + } + + /** + * Returns the resource of the resourced-path + * + * @return The resource of the resourced-path + */ + public @NotNull String getResource() { + return this.resource; + } + + /** + * Returns the path of the resourced-path + * + * @return The path of the resourced-path + */ + public @NotNull String getPath() { + return this.path; + } + + /** + * Returns a hash code value for the resourced-path + * + * @return A hash code value for the resourced-path + */ + @Override + public int hashCode() { + return 31 * this.resource.hashCode() + this.path.hashCode(); + } + + /** + * Indicates whether some other object is "equal to" this one + * + * @param obj The reference object with which to compare + * @return True if this object is the same as the obj argument + */ + @Contract("null -> false") + @Override + public boolean equals(final @Nullable Object obj) { + return this == obj + || ( + obj instanceof ResourcedPath that + && this.resource.equals(that.resource) + && this.path.equals(that.path) + ); + } + + /** + * Returns the string representation of the resourced-path + * + * @return The string representation of the resourced-path + */ + @Override + public @NotNull String toString() { + return ChatUtils.isBlank(this.resource) + ? this.path + : this.resource + ':' + this.path; + } + + public @NotNull Key toAdventure() { + return Key.key(this.resource, this.path); + } + + /** + * Creates a new resourced-path with the given path and no resource + * + * @param path The path of the resourced-path + * @return A new resourced-path with the given path and no resource + * @throws InvalidResourceException If the path is invalid + */ + @Contract("_ -> new") + public static @NotNull ResourcedPath empty(final @Path @NotNull String path) throws InvalidResourceException { + return dummyResource(null, path); + } + + /** + * Creates a new resourced-path with the given path and the resource + * {@link Resource#MINECRAFT minecraft} + * + * @param path The path of the resourced-path + * @return A new resourced-path with the given path and the {@code minecraft} + * resource + * @throws InvalidResourceException If the path is invalid + */ + @Contract("_ -> new") + public static @NotNull ResourcedPath minecraft(final @Path @NotNull String path) throws InvalidResourceException { + return dummyResource(Resource.MINECRAFT, path); + } + + /** + * Creates a new resourced-path with the given path and the resource + * {@link Resource#REALMS realms} + * + * @param path The path of the resourced-path + * @return A new resourced-path with the given path and the {@code realms} + * resource + * @throws InvalidResourceException If the path is invalid + */ + @Contract("_ -> new") + public static @NotNull ResourcedPath realms(final @Path @NotNull String path) throws InvalidResourceException { + return dummyResource(Resource.REALMS, path); + } + + /** + * Creates a new resourced-path with the given path and the resource + * {@link Resource#PAPER paper} + * + * @param path The path of the resourced-path + * @return A new resourced-path with the given path and the {@code paper} + * resource + * @throws InvalidResourceException If the path is invalid + */ + @Contract("_ -> new") + public static @NotNull ResourcedPath paper(final @Path @NotNull String path) throws InvalidResourceException { + return dummyResource(Resource.PAPER, path); + } + + /** + * Creates a new resourced-path with the given path and the resource + * {@link Resource#WHOMINE whomine} + * + * @param path The path of the resourced-path + * @return A new resourced-path with the given path and the {@code whomine} + * resource + * @throws InvalidResourceException If the path is invalid + */ + @Contract("_ -> new") + public static @NotNull ResourcedPath whomine(final @Path @NotNull String path) throws InvalidResourceException { + return dummyResource(Resource.WHOMINE, path); + } + + /** + * Creates a new resourced-path with the given resource and path + * + * @param resource The resource of the resourced-path + * @param path The path of the resourced-path + * @return A new resourced-path with the given resource and path + * @throws InvalidResourceException If the resource or path is invalid + */ + @Contract("_, _ -> new") + public static @NotNull ResourcedPath of( + final @Resource @Nullable String resource, + final @Path @NotNull String path + ) throws InvalidResourceException { + Resource.Validator.validate(resource); + + return dummyResource(resource, path); + } + + /** + * Creates a new resourced-path with the given resourced-path string + * + * @param resourcedPath The resourced-path string + * @return A new resourced-path with the given resourced-path string + * @throws InvalidResourceException If the resourced-path is invalid + */ + @Contract("_ -> new") + public static @NotNull ResourcedPath of(final @ResourcePath @NotNull String resourcedPath) throws InvalidResourceException { + ResourcePath.Validator.validateLength(resourcedPath); + + final int colonIndex = resourcedPath.indexOf(':'); + + @Subst("resource") String resource = null; + @Subst("path") String path = resourcedPath; + + if (colonIndex >= 0) { + path = resourcedPath.substring(colonIndex + 1); + + if (colonIndex >= 1) { + resource = resourcedPath.substring(0, colonIndex); + } + } + + Resource.Validator.validate(resource); + Path.Validator.validate(path); + + return new ResourcedPath(resource, path); + } + + /** + * Creates a new resourced-path with the given resource and path. + *

      + * The resource is not validated. + * + * @param resource The resource of the resourced-path + * @param path The path of the resourced-path + * @return A new resourced-path with the given resource and path + * @throws InvalidResourceException If the path is invalid + */ + @Contract("_, _ -> new") + private static @NotNull ResourcedPath dummyResource( + final @Resource @Nullable String resource, + final @Path @NotNull String path + ) throws InvalidResourceException { + Path.Validator.validate(path); + + final @Subst("resource:path") String resourcedPath = resource + ':' + path; + + ResourcePath.Validator.validateLength(resourcedPath); + + return new ResourcedPath(resource, path); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/utility/SharedConstants.java b/lib/common/src/main/java/com/minersstudios/wholib/utility/SharedConstants.java new file mode 100644 index 00000000..f29412cb --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/utility/SharedConstants.java @@ -0,0 +1,42 @@ +package com.minersstudios.wholib.utility; + +import net.kyori.adventure.translation.Translator; +import org.jetbrains.annotations.Contract; + +import java.time.format.DateTimeFormatter; +import java.util.Locale; +import java.util.Objects; + +/** + * Shared constants + */ +@SuppressWarnings("unused") +public final class SharedConstants { + // + public static final String MINECRAFT_VERSION = "1.21.1"; + public static final int PROTOCOL_VERSION = 767; + + public static final String GLOBAL_FOLDER_PATH = "config/minersstudios/"; + public static final String LANGUAGE_FOLDER_PATH = GLOBAL_FOLDER_PATH + "language/"; + + public static final String DATE_FORMAT = "EEE, yyyy-MM-dd HH:mm z"; + public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DATE_FORMAT); + + public static final String DEFAULT_LANGUAGE_CODE = "en_us"; + public static final Locale DEFAULT_LOCALE = Objects.requireNonNull(Translator.parseLocale(DEFAULT_LANGUAGE_CODE), "Not found default locale for " + DEFAULT_LANGUAGE_CODE); + + public static final String DISCORD_LINK = "https://discord.whomine.net"; + public static final String CONSOLE_NICKNAME = "$Console"; + public static final String INVISIBLE_ITEM_FRAME_TAG = "invisibleItemFrame"; + public static final String HIDE_TAGS_TEAM_NAME = "hide_tags"; + + public static final int SIT_RANGE = 9; + public static final int FINAL_DESTROY_STAGE = 9; + public static final int DECOR_MAX_STACK_SIZE = 8; + // + + @Contract(" -> fail") + private SharedConstants() throws AssertionError { + throw new AssertionError("Utility class"); + } +} diff --git a/lib/common/src/main/java/com/minersstudios/wholib/utility/package-info.java b/lib/common/src/main/java/com/minersstudios/wholib/utility/package-info.java new file mode 100644 index 00000000..b8db7e5e --- /dev/null +++ b/lib/common/src/main/java/com/minersstudios/wholib/utility/package-info.java @@ -0,0 +1,10 @@ +/** + * This package contains utility classes that are used throughout the project. + * + * @see com.minersstudios.wholib.utility.SharedConstants + * @see com.minersstudios.wholib.utility.Font + * @see com.minersstudios.wholib.utility.ResourcedPath + * @see com.minersstudios.wholib.utility.ChatUtils + * @see com.minersstudios.wholib.utility.IDUtils + */ +package com.minersstudios.wholib.utility; diff --git a/lib/common/src/test/java/com/minersstudios/wholib/Main.java b/lib/common/src/test/java/com/minersstudios/wholib/Main.java new file mode 100644 index 00000000..5b2ab706 --- /dev/null +++ b/lib/common/src/test/java/com/minersstudios/wholib/Main.java @@ -0,0 +1,8 @@ +package com.minersstudios.wholib; + +public final class Main { + + public static void main(final String[] args) { + System.out.println("Hello, Demon!"); + } +} diff --git a/lib/paper/build.gradle.kts b/lib/paper/build.gradle.kts new file mode 100644 index 00000000..1fe7c491 --- /dev/null +++ b/lib/paper/build.gradle.kts @@ -0,0 +1,13 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration.Companion.MOJANG_PRODUCTION + +plugins { + id("whomine.library") + id("whomine.paperweight") +} + +paperweight.reobfArtifactConfiguration = MOJANG_PRODUCTION + +dependencies { + compileOnlyApi(libs.authme) + compileOnlyApi(libs.coreprotect) +} diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/PaperCache.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/PaperCache.java new file mode 100644 index 00000000..b8ee06aa --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/PaperCache.java @@ -0,0 +1,82 @@ +package com.minersstudios.wholib.paper; + +import com.google.gson.JsonElement; +import com.minersstudios.wholib.module.components.Cache; +import com.minersstudios.wholib.paper.chat.ChatBuffer; +import com.minersstudios.wholib.paper.collection.DiggingMap; +import com.minersstudios.wholib.paper.collection.StepMap; +import com.minersstudios.wholib.paper.custom.anomaly.Anomaly; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyAction; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItem; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.discord.DiscordMap; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.collection.IDMap; +import com.minersstudios.wholib.paper.player.collection.MuteMap; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.paper.world.WorldDark; +import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import org.bukkit.NamespacedKey; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.Recipe; +import org.bukkit.scheduler.BukkitTask; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.UnknownNullability; + +import java.util.List; +import java.util.Map; + +public interface PaperCache extends Cache { + + void load() throws IllegalStateException; + + void unload(); + + @UnknownNullability List getCustomDecorRecipes(); + + @UnknownNullability List getCustomItemRecipes(); + + @UnknownNullability List getCustomBlockRecipes(); + + @UnknownNullability StepMap getStepMap(); + + @UnknownNullability DiggingMap getDiggingMap(); + + @UnknownNullability Map getDosimeterPlayers(); + + @UnknownNullability List getRenameableMenuItems(); + + @ApiStatus.Internal + @UnknownNullability List> getBlockDataRecipes(); + + @UnknownNullability PlayerInfoMap getPlayerInfoMap(); + + @UnknownNullability MuteMap getMuteMap(); + + @UnknownNullability DiscordMap getDiscordMap(); + + @UnknownNullability IDMap getIdMap(); + + @UnknownNullability Map getSeats(); + + @UnknownNullability Map getAnomalies(); + + @UnknownNullability Map> getPlayerAnomalyActionMap(); + + @UnknownNullability ChatBuffer getChatBuffer(); + + @UnknownNullability List getBukkitTasks(); + + @UnknownNullability Long2ObjectMap getBotHandlers(); + + @UnknownNullability PlayerInfo getConsolePlayerInfo(); + + void setConsolePlayerInfo(PlayerInfo playerInfo); + + @UnknownNullability WorldDark getWorldDark(); + + boolean isLoaded(); +} diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/PaperConfig.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/PaperConfig.java new file mode 100644 index 00000000..68c1aefb --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/PaperConfig.java @@ -0,0 +1,86 @@ +package com.minersstudios.wholib.paper; + +import com.minersstudios.wholib.module.components.Configuration; +import org.bukkit.Location; +import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnknownNullability; + +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Locale; +import java.util.logging.Logger; + +public interface PaperConfig extends Configuration { + + boolean reload(); + + @NotNull YamlConfiguration getYaml(); + + @NotNull Logger getLogger(); + + @Nullable String getDateFormat(); + + boolean isChristmas(); + + boolean isHalloween(); + + @UnknownNullability String getLanguageDefaultCode(); + + @UnknownNullability DateTimeFormatter getDateFormatter(); + + @UnknownNullability Locale getDefaultLocale(); + + @UnknownNullability List getLocales(); + + long getDosimeterCheckRate(); + + @UnknownNullability String getWoodSoundPlace(); + + @UnknownNullability String getWoodSoundBreak(); + + @UnknownNullability String getWoodSoundStep(); + + @UnknownNullability String getWoodSoundHit(); + + boolean isDeveloperMode(); + + void setDeveloperMode(final boolean developerMode); + + long getAnomalyCheckRate(); + + void setAnomalyCheckRate(final long rate); + + long getAnomalyParticlesCheckRate(); + + void setAnomalyParticlesCheckRate(final long rate); + + long getDiscordServerId(); + + void setDiscordServerId(final long id); + + long getMemberRoleId(); + + void setMemberRoleId(final long id); + + long getDiscordGlobalChannelId(); + + void setDiscordGlobalChannelId(final long id); + + long getDiscordLocalChannelId(); + + void setDiscordLocalChannelId(final long id); + + double getLocalChatRadius(); + + void setLocalChatRadius(final double radius); + + @Nullable String getMineSkinApiKey(); + + void setMineSkinApiKey(final @Nullable String apiKey); + + @NotNull Location getSpawnLocation(); + + void setSpawnLocation(final @NotNull Location location); +} diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/WhoMine.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/WhoMine.java new file mode 100644 index 00000000..311aa323 --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/WhoMine.java @@ -0,0 +1,117 @@ +package com.minersstudios.wholib.paper; + +import com.minersstudios.wholib.module.MainModule; +import com.minersstudios.wholib.paper.discord.DiscordManager; +import com.minersstudios.wholib.paper.gui.PaperGuiManager; +import com.minersstudios.wholib.paper.listener.PaperListenerManager; +import com.minersstudios.wholib.paper.scheduler.TaskExecutor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +/** + * Represents a WhoMine module + */ +public interface WhoMine extends MainModule, Plugin, TaskExecutor { + Instance SINGLETON = new Instance(); + + @Override + @NotNull PaperCache getCache(); + + @Override + @NotNull PaperConfig getConfiguration(); + + /** + * Returns the listener manager of the module + * + * @return The listener manager of the module + */ + @NotNull PaperListenerManager getListenerManager(); + + /** + * Returns the gui manager of the module + * + * @return The gui manager of the module + */ + @NotNull PaperGuiManager getGuiManager(); + + /** + * Returns the discord module + * + * @return The discord module + */ + @NotNull DiscordManager getDiscordModule(); + + /** + * Gets a {@link FileConfiguration} for this plugin, read through + * "config.yml" + *
      + * If there is a default config.yml embedded in this plugin, it will be + * provided as a default for this Configuration. + * + * @return Plugin configuration + */ + @Override + @NotNull FileConfiguration getConfig(); + + /** + * Discards any data in {@link #getConfig()} and reloads from disk. + */ + @Override + void reloadConfig(); + + /** + * Saves the {@link FileConfiguration} retrievable by {@link #getConfig()} + */ + @Override + void saveConfig(); + + /** + * Saves the raw contents of any resource embedded with a plugin's .jar file + * assuming it can be found using {@link #getResource(String)}. + *
      + * The resource is saved into the plugin's data folder using the same + * hierarchy as the .jar file (subdirectories are preserved). + * + * @param resourcePath The embedded resource path to look for within the + * plugin's .jar file. (No preceding slash). + * @param replace If true, the embedded resource will overwrite the contents + * of an existing file. + * @throws IllegalArgumentException if the resource path is null, empty, + * or points to a nonexistent resource. + */ + @Override + void saveResource( + final @NotNull String resourcePath, + final boolean replace + ) throws IllegalArgumentException; + + /** + * Saves the raw contents of the default config.yml file to the location + * retrievable by {@link #getConfig()}. + *
      + * This should fail silently if the config.yml already exists. + */ + @Override + void saveDefaultConfig(); + + static @NotNull Optional singleton() { + return SINGLETON.get(); + } + + final class Instance { + private volatile WhoMine instance; + + private Instance() {} + + public @NotNull Optional get() { + return Optional.ofNullable(this.instance); + } + + public void set(final @NotNull WhoMine instance) { + this.instance = instance; + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/chat/ChatBuffer.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/chat/ChatBuffer.java similarity index 91% rename from paper/src/main/java/com/minersstudios/whomine/chat/ChatBuffer.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/chat/ChatBuffer.java index 0c23f07b..8c51bcd6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/chat/ChatBuffer.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/chat/ChatBuffer.java @@ -1,7 +1,8 @@ -package com.minersstudios.whomine.chat; +package com.minersstudios.wholib.paper.chat; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.module.AbstractModuleComponent; +import com.minersstudios.wholib.utility.Font; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -18,12 +19,13 @@ import static net.kyori.adventure.text.Component.space; import static net.kyori.adventure.text.Component.text; -public final class ChatBuffer { - private final @NotNull WhoMine plugin; +public final class ChatBuffer extends AbstractModuleComponent { + private final @NotNull Map> chatQueue; - public ChatBuffer(final @NotNull WhoMine plugin) { - this.plugin = plugin; + public ChatBuffer(final @NotNull WhoMine module) { + super(module); + this.chatQueue = new Object2ObjectOpenHashMap<>(); } @@ -112,7 +114,7 @@ private void scheduleMessageUpdate( final @NotNull UUID uuid, final int delay ) { - this.plugin.runTaskLater(() -> { + this.getModule().runTaskLater(() -> { if ( !player.isOnline() || this.chatQueue.get(uuid).isEmpty() @@ -153,7 +155,7 @@ private void scheduleMessageUpdate( .append(space()) .color(NamedTextColor.WHITE) ); - entity.setParticle(Particle.TOWN_AURA); + entity.setParticle(Particle.MYCELIUM); entity.setRadius(0); entity.setCustomNameVisible(true); entity.setWaitTime(0); diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/chat/ChatType.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/chat/ChatType.java new file mode 100644 index 00000000..e29839cc --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/chat/ChatType.java @@ -0,0 +1,5 @@ +package com.minersstudios.wholib.paper.chat; + +public enum ChatType { + GLOBAL, LOCAL +} diff --git a/paper/src/main/java/com/minersstudios/whomine/collection/DiggingMap.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/collection/DiggingMap.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/collection/DiggingMap.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/collection/DiggingMap.java index 4ec74f9e..750e2370 100644 --- a/paper/src/main/java/com/minersstudios/whomine/collection/DiggingMap.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/collection/DiggingMap.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.collection; +package com.minersstudios.wholib.paper.collection; import com.google.common.collect.ImmutableSet; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.block.Block; import org.bukkit.entity.Player; diff --git a/paper/src/main/java/com/minersstudios/whomine/collection/StepMap.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/collection/StepMap.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/collection/StepMap.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/collection/StepMap.java index ed4078d5..f094ac4a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/collection/StepMap.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/collection/StepMap.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.collection; +package com.minersstudios.wholib.paper.collection; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/Anomaly.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/Anomaly.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/custom/anomaly/Anomaly.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/Anomaly.java index 7c452f05..a8b98a09 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/Anomaly.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/Anomaly.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.anomaly; +package com.minersstudios.wholib.paper.custom.anomaly; import com.destroystokyo.paper.ParticleBuilder; -import com.minersstudios.whomine.Cache; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.anomaly.action.AddPotionAction; -import com.minersstudios.whomine.custom.anomaly.action.SpawnParticlesAction; -import com.minersstudios.whomine.world.location.MSBoundingBox; -import com.minersstudios.whomine.utility.BlockUtils; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.custom.anomaly.action.AddPotionAction; +import com.minersstudios.wholib.paper.custom.anomaly.action.SpawnParticlesAction; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.world.location.MSBoundingBox; +import com.minersstudios.wholib.paper.utility.BlockUtils; import it.unimi.dsi.fastutil.doubles.Double2ObjectMap; import it.unimi.dsi.fastutil.doubles.Double2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -30,7 +30,7 @@ /** * Anomaly class with all anomaly data and associated namespaced key. - * All anomalies are cached in {@link Cache#getAnomalies()} . + * All anomalies are cached in {@link PaperCache#getAnomalies()} . *
      * Can have : *

        @@ -228,7 +228,7 @@ public Anomaly( ); particleBuilderList.add( - particleBuilder.particle() == Particle.REDSTONE + particleBuilder.particle() == Particle.DUST ? particleBuilder.color( Color.fromRGB(particleSection.getInt("color")), (float) particleSection.getDouble("particle-size") @@ -266,7 +266,7 @@ public Anomaly( return new Anomaly( new NamespacedKey( - SharedConstants.WHOMINE_NAMESPACE, + Resource.WHOMINE, namespacedKeyStr ), anomalyBoundingBox, diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/AnomalyAction.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/AnomalyAction.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/custom/anomaly/AnomalyAction.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/AnomalyAction.java index f31b8264..06b773f9 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/AnomalyAction.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/AnomalyAction.java @@ -1,8 +1,8 @@ -package com.minersstudios.whomine.custom.anomaly; +package com.minersstudios.wholib.paper.custom.anomaly; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.anomaly.action.AddPotionAction; -import com.minersstudios.whomine.custom.anomaly.action.SpawnParticlesAction; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.anomaly.action.AddPotionAction; +import com.minersstudios.wholib.paper.custom.anomaly.action.SpawnParticlesAction; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/AnomalyBoundingBox.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/AnomalyBoundingBox.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/custom/anomaly/AnomalyBoundingBox.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/AnomalyBoundingBox.java index 9ce20a91..b4aeec42 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/AnomalyBoundingBox.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/AnomalyBoundingBox.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.anomaly; +package com.minersstudios.wholib.paper.custom.anomaly; -import com.minersstudios.whomine.world.location.MSBoundingBox; +import com.minersstudios.wholib.paper.world.location.MSBoundingBox; import it.unimi.dsi.fastutil.doubles.Double2ObjectArrayMap; import it.unimi.dsi.fastutil.doubles.Double2ObjectMap; import org.bukkit.World; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/AnomalyIgnorableItems.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/AnomalyIgnorableItems.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/custom/anomaly/AnomalyIgnorableItems.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/AnomalyIgnorableItems.java index e832555a..643a7077 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/AnomalyIgnorableItems.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/AnomalyIgnorableItems.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.anomaly; +package com.minersstudios.wholib.paper.custom.anomaly; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ItemUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.ItemUtils; import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/action/AddPotionAction.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/action/AddPotionAction.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/custom/anomaly/action/AddPotionAction.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/action/AddPotionAction.java index ee218b61..de9e7138 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/action/AddPotionAction.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/action/AddPotionAction.java @@ -1,8 +1,8 @@ -package com.minersstudios.whomine.custom.anomaly.action; +package com.minersstudios.wholib.paper.custom.anomaly.action; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.anomaly.AnomalyAction; -import com.minersstudios.whomine.custom.anomaly.AnomalyIgnorableItems; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyAction; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyIgnorableItems; import org.bukkit.entity.Player; import org.bukkit.inventory.PlayerInventory; import org.bukkit.potion.PotionEffect; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/action/SpawnParticlesAction.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/action/SpawnParticlesAction.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/custom/anomaly/action/SpawnParticlesAction.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/action/SpawnParticlesAction.java index 93d822e8..60263ebe 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/action/SpawnParticlesAction.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/action/SpawnParticlesAction.java @@ -1,9 +1,9 @@ -package com.minersstudios.whomine.custom.anomaly.action; +package com.minersstudios.wholib.paper.custom.anomaly.action; import com.destroystokyo.paper.ParticleBuilder; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.anomaly.AnomalyAction; -import com.minersstudios.whomine.custom.anomaly.AnomalyIgnorableItems; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyAction; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyIgnorableItems; import org.bukkit.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/task/AnomalyParticleTask.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/task/AnomalyParticleTask.java similarity index 79% rename from paper/src/main/java/com/minersstudios/whomine/custom/anomaly/task/AnomalyParticleTask.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/task/AnomalyParticleTask.java index 94814bd6..259e2c90 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/task/AnomalyParticleTask.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/task/AnomalyParticleTask.java @@ -1,11 +1,11 @@ -package com.minersstudios.whomine.custom.anomaly.task; +package com.minersstudios.wholib.paper.custom.anomaly.task; -import com.minersstudios.whomine.Config; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.anomaly.Anomaly; -import com.minersstudios.whomine.custom.anomaly.AnomalyAction; -import com.minersstudios.whomine.custom.anomaly.AnomalyBoundingBox; -import com.minersstudios.whomine.custom.anomaly.action.SpawnParticlesAction; +import com.minersstudios.wholib.paper.PaperConfig; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyBoundingBox; +import com.minersstudios.wholib.paper.custom.anomaly.action.SpawnParticlesAction; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.anomaly.Anomaly; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyAction; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -18,8 +18,8 @@ * performed and particles will be spawned. Otherwise, the action will be * removed. *
        - * The task is registered in {@link Config#reload()} with - * {@link Config#getAnomalyParticlesCheckRate()}. + * The task is registered in {@link PaperConfig#reload()} with + * {@link PaperConfig#getAnomalyParticlesCheckRate()}. * * @see SpawnParticlesAction * @see AnomalyBoundingBox diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/task/MainAnomalyActionTask.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/task/MainAnomalyActionTask.java similarity index 84% rename from paper/src/main/java/com/minersstudios/whomine/custom/anomaly/task/MainAnomalyActionTask.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/task/MainAnomalyActionTask.java index 78afb882..68176f8c 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/anomaly/task/MainAnomalyActionTask.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/anomaly/task/MainAnomalyActionTask.java @@ -1,11 +1,11 @@ -package com.minersstudios.whomine.custom.anomaly.task; - -import com.minersstudios.whomine.Config; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.anomaly.Anomaly; -import com.minersstudios.whomine.custom.anomaly.AnomalyAction; -import com.minersstudios.whomine.custom.anomaly.AnomalyBoundingBox; -import com.minersstudios.whomine.custom.anomaly.action.SpawnParticlesAction; +package com.minersstudios.wholib.paper.custom.anomaly.task; + +import com.minersstudios.wholib.paper.PaperConfig; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyBoundingBox; +import com.minersstudios.wholib.paper.custom.anomaly.action.SpawnParticlesAction; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.anomaly.Anomaly; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyAction; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -17,8 +17,8 @@ * anomaly zone. When a player is in the anomaly zone, the action will be * performed. Otherwise, the action will be removed. *
        - * The task is registered in {@link Config#reload()} with - * {@link Config#getAnomalyCheckRate()}. + * The task is registered in {@link PaperConfig#reload()} with + * {@link PaperConfig#getAnomalyCheckRate()}. * * @see AnomalyAction * @see AnomalyBoundingBox diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/CustomBlock.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/CustomBlock.java similarity index 81% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/CustomBlock.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/CustomBlock.java index 2374a7c3..0cb4d295 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/CustomBlock.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/CustomBlock.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.block; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.event.CustomBlockPlaceEvent; -import com.minersstudios.whomine.custom.block.params.PlacingType; -import com.minersstudios.whomine.custom.block.params.ToolType; -import com.minersstudios.whomine.custom.block.params.settings.Tool; -import com.minersstudios.whomine.custom.block.event.CustomBlockBreakEvent; -import com.minersstudios.whomine.utility.BlockUtils; -import com.minersstudios.whomine.utility.CoreProtectUtils; -import com.minersstudios.whomine.utility.ItemUtils; +package com.minersstudios.wholib.paper.custom.block; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.block.event.CustomBlockBreakEvent; +import com.minersstudios.wholib.paper.custom.block.event.CustomBlockPlaceEvent; +import com.minersstudios.wholib.paper.custom.block.params.PlacingType; +import com.minersstudios.wholib.paper.custom.block.params.ToolType; +import com.minersstudios.wholib.paper.custom.block.params.settings.Tool; +import com.minersstudios.wholib.paper.utility.BlockUtils; +import com.minersstudios.wholib.paper.utility.CoreProtectUtils; +import com.minersstudios.wholib.paper.utility.ItemUtils; import net.coreprotect.CoreProtectAPI; import net.minecraft.core.BlockPos; import net.minecraft.world.level.LevelAccessor; @@ -18,7 +18,7 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.NoteBlock; -import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock; +import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; @@ -34,6 +34,7 @@ * @see #destroy(WhoMine, Player) */ public final class CustomBlock { + private final Block block; private final CustomBlockData customBlockData; @@ -127,22 +128,27 @@ public void place( final NoteBlock noteBlock; final PlacingType placingType = this.customBlockData.getBlockSettings().getPlacing().getType(); - if (placingType instanceof final PlacingType.Default normal) { - noteBlock = normal.getNoteBlockData().craftNoteBlock(blockData); - } else if (placingType instanceof final PlacingType.Directional directional) { - if (blockFace == null) { - throw new IllegalArgumentException("Block face is null, but placing type is directional! " + key); - } + switch (placingType) { + case final PlacingType.Default normal -> noteBlock = normal.getNoteBlockData().craftNoteBlock(blockData); + case final PlacingType.Directional directional -> { + if (blockFace == null) { + throw new IllegalArgumentException( + "Block face is null, but placing type is directional! " + key + ); + } - noteBlock = directional.getNoteBlockData(blockFace).craftNoteBlock(blockData); - } else if (placingType instanceof final PlacingType.Orientable orientable) { - if (axis == null) { - throw new IllegalArgumentException("Axis is null, but placing type is orientable! " + key); + noteBlock = directional.getNoteBlockData(blockFace).craftNoteBlock(blockData); } + case final PlacingType.Orientable orientable -> { + if (axis == null) { + throw new IllegalArgumentException("Axis is null, but placing type is orientable! " + key); + } - noteBlock = orientable.getNoteBlockData(axis).craftNoteBlock(blockData); - } else { - throw new IllegalArgumentException("Unknown placing type: " + placingType.getClass().getName()); + noteBlock = orientable.getNoteBlockData(axis).craftNoteBlock(blockData); + } + default -> throw new IllegalArgumentException( + "Unknown placing type: " + placingType.getClass().getName() + ); } this.block.setBlockData(noteBlock); diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/CustomBlockData.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/CustomBlockData.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/CustomBlockData.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/CustomBlockData.java index d64418df..dae20399 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/CustomBlockData.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/CustomBlockData.java @@ -1,15 +1,14 @@ -package com.minersstudios.whomine.custom.block; +package com.minersstudios.wholib.paper.custom.block; import com.google.gson.JsonElement; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.file.CustomBlockFile; -import com.minersstudios.whomine.custom.block.file.adapter.RecipeAdapter; -import com.minersstudios.whomine.custom.block.params.*; -import com.minersstudios.whomine.custom.block.params.settings.Placing; -import com.minersstudios.whomine.custom.block.params.settings.Tool; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.menu.CraftsMenu; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.block.file.CustomBlockFile; +import com.minersstudios.wholib.paper.custom.block.params.*; +import com.minersstudios.wholib.paper.custom.block.params.settings.Placing; +import com.minersstudios.wholib.paper.custom.block.params.settings.Tool; +import com.minersstudios.wholib.paper.custom.block.file.adapter.RecipeAdapter; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectLists; import org.bukkit.Keyed; @@ -41,6 +40,7 @@ */ @Immutable public final class CustomBlockData { + private final String key; private final BlockSettings blockSettings; private final DropSettings dropSettings; @@ -253,7 +253,7 @@ public boolean isDefault() { * Registers the recipes of the custom block data. If the showInCraftsMenu * parameter of a recipe entry is true, the recipe will be added to the * global cache's custom block recipes list. This list is used to display - * the custom block recipes in the {@link CraftsMenu} + * the custom block recipes in the {@code CraftsMenu} * * @param plugin The plugin that owns this custom block data * @param recipeJson The json element containing the recipes @@ -287,7 +287,7 @@ public void registerRecipes( server.addRecipe(recipe); if (recipeEntry.isRegisteredInMenu()) { - plugin.getCache().customBlockRecipes.add(recipe); + plugin.getCache().getCustomBlockRecipes().add(recipe); } } } @@ -306,7 +306,7 @@ public void unregisterRecipes(final @NotNull WhoMine plugin) { plugin.getServer().removeRecipe(recipe.getKey()); if (entry.isRegisteredInMenu()) { - plugin.getCache().customBlockRecipes.remove(recipe); + plugin.getCache().getCustomBlockRecipes().remove(recipe); } } } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/CustomBlockRegistry.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/CustomBlockRegistry.java similarity index 86% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/CustomBlockRegistry.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/CustomBlockRegistry.java index bee22715..bf7a2017 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/CustomBlockRegistry.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/CustomBlockRegistry.java @@ -1,10 +1,10 @@ -package com.minersstudios.whomine.custom.block; +package com.minersstudios.wholib.paper.custom.block; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.params.PlacingType; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.custom.block.params.NoteBlockData; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.module.MainModule; +import com.minersstudios.wholib.paper.custom.block.params.NoteBlockData; +import com.minersstudios.wholib.paper.custom.block.params.PlacingType; +import com.minersstudios.wholib.utility.ChatUtils; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; @@ -26,7 +26,7 @@ /** * The CustomBlockRegistry class is responsible for managing and storing custom - * block data for {@link WhoMine} plugin. + * block data for {@link MainModule} plugin. *
        * It provides various methods to register, unregister, and retrieve custom * block data based on different criteria, such as the custom block's key, hash @@ -37,12 +37,12 @@ * {@link NoteBlockData} of the custom block. And another concurrent map to * store the registered keys associated with the corresponding hash code of the * {@link NoteBlockData} of the custom block. The {@link #HASH_CODE_MAP} is a - * main map that stores all the registered custom block data. The + * main map that stores all the registered custom block data. The * {@link #KEY_MAP} is used to store the registered keys and associated hash * codes. *
        * All recipes by default are registered after all custom blocks, items, and - * decorations are registered. This is to avoid problems related to dependencies + * decorations are registered. This is to avoid problems related to dependencies * between other plugins and custom items, decorations, and blocks. *
        * Make sure to use the provided methods and their respective Optional return @@ -76,7 +76,7 @@ * } */ public final class CustomBlockRegistry { - public static final NamespacedKey TYPE_NAMESPACED_KEY = new NamespacedKey(SharedConstants.MSBLOCK_NAMESPACE, "type"); + public static final NamespacedKey TYPE_NAMESPACED_KEY = new NamespacedKey(Resource.WMBLOCK, "type"); private static final Int2ObjectMap HASH_CODE_MAP = new Int2ObjectOpenHashMap<>(); private static final Map KEY_MAP = new Object2ObjectOpenHashMap<>(); @@ -91,7 +91,7 @@ private CustomBlockRegistry() throws AssertionError { } /** - * @return An unmodifiable view of the hash codes of all registered custom + * @return An unmodifiable view of the hash codes of all registered custom * block data (NoteBlockData) * @see #HASH_CODE_MAP */ @@ -100,7 +100,7 @@ private CustomBlockRegistry() throws AssertionError { } /** - * @return An unmodifiable view of the keys of all registered custom + * @return An unmodifiable view of the keys of all registered custom * block data * @see #KEY_MAP */ @@ -132,14 +132,14 @@ private CustomBlockRegistry() throws AssertionError { } /** - * Gets the {@link CustomBlockData} from the given custom block data key. It + * Gets the {@link CustomBlockData} from the given custom block data key. It * will get the hash code from the {@link #KEY_MAP}, then get the custom * block data from the {@link #HASH_CODE_MAP}. * - * @param key The custom block data key to get the {@link CustomBlockData} + * @param key The custom block data key to get the {@link CustomBlockData} * from, must not be blank * @return An {@link Optional} containing the {@link CustomBlockData} - * or an {@link Optional#empty()} if the given key is not associated + * or an {@link Optional#empty()} if the given key is not associated * with any custom block data * @see #KEY_MAP * @see #fromHashCode(int) @@ -158,7 +158,7 @@ private CustomBlockRegistry() throws AssertionError { /** * Gets the {@link CustomBlockData} from the given block data. It will check * if the given block data is an instance of {@link NoteBlock} and if it is, - * it will get the custom block data from the {@link NoteBlock} by calling + * it will get the custom block data from the {@link NoteBlock} by calling * {@link #fromNoteBlock(NoteBlock)} method. * * @param blockData The block data to get the {@link CustomBlockData} from, @@ -199,7 +199,7 @@ private CustomBlockRegistry() throws AssertionError { * will get the {@link CustomBlockData} from the hash code by calling * {@link #fromHashCode(int)} method. * - * @param noteBlockData The note block data get the {@link CustomBlockData} + * @param noteBlockData The note block data get the {@link CustomBlockData} * from * @return An {@link Optional} containing the {@link CustomBlockData} * or an {@link Optional#empty()} if the given note block data @@ -213,14 +213,14 @@ private CustomBlockRegistry() throws AssertionError { /** * Gets the {@link CustomBlockData} from the given item stack. It will check - * the item stack's persistent data container for the - * {@link #TYPE_NAMESPACED_KEY} key, and if it has it, it will get the + * the item stack's persistent data container for the + * {@link #TYPE_NAMESPACED_KEY} key, and if it has it, it will get the * custom block data from the key by calling {@link #fromKey(String)} method. * * @param itemStack The item stack to get the {@link CustomBlockData} from * @return An {@link Optional} containing the {@link CustomBlockData}, or an * {@link Optional#empty()} if the key from the item stack's - * persistent data container is not associated with any custom block + * persistent data container is not associated with any custom block * data * @see #TYPE_NAMESPACED_KEY * @see #fromKey(String) @@ -229,7 +229,7 @@ private CustomBlockRegistry() throws AssertionError { if (itemStack == null) { return Optional.empty(); } - + final ItemMeta itemMeta = itemStack.getItemMeta(); return itemMeta == null ? Optional.empty() @@ -259,7 +259,7 @@ public static boolean containsKey(final @Nullable String key) { /** * @param customBlockData The custom block data to check - * @return True if the {@link #HASH_CODE_MAP} contains the hash code of the + * @return True if the {@link #HASH_CODE_MAP} contains the hash code of the * note block data associated with the custom block data */ @Contract("null -> false") @@ -270,29 +270,32 @@ public static boolean containsCustomBlockData(final @Nullable CustomBlockData cu final PlacingType placingType = customBlockData.getBlockSettings().getPlacing().getType(); - if (placingType instanceof final PlacingType.Default normal) { - return containsHashCode(normal.getNoteBlockData().hashCode()); - } else if (placingType instanceof final PlacingType.Directional directional) { - for (final var noteBlockData : directional.getMap().values()) { - if (containsHashCode(noteBlockData.hashCode())) { - return true; + switch (placingType) { + case final PlacingType.Default normal -> { + return containsHashCode(normal.getNoteBlockData().hashCode()); + } + case final PlacingType.Directional directional -> { + for (final var noteBlockData : directional.getMap().values()) { + if (containsHashCode(noteBlockData.hashCode())) { + return true; + } } } - } else if (placingType instanceof final PlacingType.Orientable orientable) { - for (final var noteBlockData : orientable.getMap().values()) { - if (containsHashCode(noteBlockData.hashCode())) { - return true; + case final PlacingType.Orientable orientable -> { + for (final var noteBlockData : orientable.getMap().values()) { + if (containsHashCode(noteBlockData.hashCode())) { + return true; + } } } - } else { - throw new IllegalArgumentException("Unknown placing type: " + placingType.getClass().getName()); + default -> throw new IllegalArgumentException("Unknown placing type: " + placingType.getClass().getName()); } return false; } /** - * Checks if the item stack is a custom block by verifying if it has a valid + * Checks if the item stack is a custom block by verifying if it has a valid * custom block data key associated with it * * @param itemStack The item stack to check @@ -306,8 +309,8 @@ public static boolean isCustomBlock(final @Nullable ItemStack itemStack) { } /** - * Checks if the block is a custom block by verifying if its block data is - * an instance of {@link NoteBlock} and if it has a valid custom block data + * Checks if the block is a custom block by verifying if its block data is + * an instance of {@link NoteBlock} and if it has a valid custom block data * associated with it * * @param block The block to check @@ -321,8 +324,8 @@ public static boolean isCustomBlock(final @Nullable Block block) { } /** - * Checks if the block data is a custom block by verifying if it is an - * instance of {@link NoteBlock} and if it has a valid custom block data + * Checks if the block data is a custom block by verifying if it is an + * instance of {@link NoteBlock} and if it has a valid custom block data * associated with it * * @param blockData The block data to check @@ -354,14 +357,14 @@ public static int size() { /** * Registers the custom block data to the data map. The key and hash code * are all used to register the custom block data. If the custom block data - * have the note block data, the note block data's hash code is used to + * have the note block data, the note block data's hash code is used to * register the custom block data in the data maps, otherwise the block * {@link PlacingType.Directional} or {@link PlacingType.Orientable} is used * to generate the hash code of the note block data. Make sure that one of * the note block data, block face map, or block axis map is not null. * * @param customBlockData The custom block data to register - * @throws IllegalArgumentException If the custom block data is already + * @throws IllegalArgumentException If the custom block data is already * registered, or if the custom block data * has an unknown placing type * @see CustomBlockData @@ -372,30 +375,20 @@ public static synchronized void register(final @NotNull CustomBlockData customBl final String key = customBlockData.getKey(); final PlacingType placingType = customBlockData.getBlockSettings().getPlacing().getType(); - if (placingType instanceof final PlacingType.Default normal) { - register( - customBlockData, - normal.getNoteBlockData().hashCode(), - key - ); - } else if (placingType instanceof final PlacingType.Directional directional) { - directional.getMap().forEach( - (blockFace, data) -> register( - customBlockData, - data.hashCode(), - key - ) - ); - } else if (placingType instanceof final PlacingType.Orientable orientable) { - orientable.getMap().forEach( - (blockAxis, data) -> register( - customBlockData, - data.hashCode(), - key - ) - ); - } else { - throw new IllegalArgumentException("Unknown placing type: " + placingType.getClass().getName()); + switch (placingType) { + case final PlacingType.Default normal -> + register( + customBlockData, normal.getNoteBlockData().hashCode(), key + ); + case final PlacingType.Directional directional -> + directional.getMap().forEach( + (blockFace, data) -> register(customBlockData, data.hashCode(), key) + ); + case final PlacingType.Orientable orientable -> + orientable.getMap().forEach( + (blockAxis, data) -> register(customBlockData, data.hashCode(), key) + ); + default -> throw new IllegalArgumentException("Unknown placing type: " + placingType.getClass().getName()); } } @@ -403,7 +396,7 @@ public static synchronized void register(final @NotNull CustomBlockData customBl * Unregister a custom block data from the data map * * @param customBlockData The custom block data to unregister - * @throws IllegalArgumentException If the key, or hash code is not + * @throws IllegalArgumentException If the key, or hash code is not * registered */ public static synchronized void unregister(final @NotNull CustomBlockData customBlockData) throws IllegalArgumentException { @@ -424,7 +417,7 @@ public static synchronized void unregister(final @NotNull CustomBlockData custom /** * Unregisters all custom block data and recipes by clearing all maps and - * lists used to store them. After this method is called, the custom block + * lists used to store them. After this method is called, the custom block * registry will be empty. */ public static synchronized void unregisterAll() { @@ -442,7 +435,7 @@ public static synchronized void unregisterAll() { * @param customBlockData The custom block data to register * @param hashCode The hash code of the note block data to register * @param key The key of the custom block data to register - * @throws IllegalArgumentException If the hash code, or key is already + * @throws IllegalArgumentException If the hash code, or key is already * registered * @see #HASH_CODE_MAP * @see #KEY_MAP diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockBreakEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockBreakEvent.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockBreakEvent.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockBreakEvent.java index 2233fe7d..d7bde0c1 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockBreakEvent.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockBreakEvent.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.block.event; +package com.minersstudios.wholib.paper.custom.block.event; -import com.minersstudios.whomine.custom.block.CustomBlock; +import com.minersstudios.wholib.paper.custom.block.CustomBlock; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockDamageEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockDamageEvent.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockDamageEvent.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockDamageEvent.java index e0b097d9..5891f6c7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockDamageEvent.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockDamageEvent.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.block.event; +package com.minersstudios.wholib.paper.custom.block.event; -import com.minersstudios.whomine.custom.block.CustomBlock; +import com.minersstudios.wholib.paper.custom.block.CustomBlock; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockEvent.java similarity index 82% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockEvent.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockEvent.java index ca82d0ed..da32915a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockEvent.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockEvent.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.block.event; +package com.minersstudios.wholib.paper.custom.block.event; -import com.minersstudios.whomine.custom.block.CustomBlock; +import com.minersstudios.wholib.paper.custom.block.CustomBlock; import org.bukkit.event.Event; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockPlaceEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockPlaceEvent.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockPlaceEvent.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockPlaceEvent.java index f7304a95..ce735bd5 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockPlaceEvent.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockPlaceEvent.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.block.event; +package com.minersstudios.wholib.paper.custom.block.event; -import com.minersstudios.whomine.custom.block.CustomBlock; +import com.minersstudios.wholib.paper.custom.block.CustomBlock; import org.bukkit.block.BlockState; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockRightClickEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockRightClickEvent.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockRightClickEvent.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockRightClickEvent.java index 169b4351..b15d766d 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/event/CustomBlockRightClickEvent.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/event/CustomBlockRightClickEvent.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.block.event; +package com.minersstudios.wholib.paper.custom.block.event; -import com.minersstudios.whomine.custom.block.CustomBlock; +import com.minersstudios.wholib.paper.custom.block.CustomBlock; import org.bukkit.Location; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/CustomBlockFile.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/CustomBlockFile.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/CustomBlockFile.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/CustomBlockFile.java index d6b9f71f..be5307c1 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/CustomBlockFile.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/CustomBlockFile.java @@ -1,19 +1,19 @@ -package com.minersstudios.whomine.custom.block.file; +package com.minersstudios.wholib.paper.custom.block.file; import com.google.gson.*; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.file.adapter.*; -import com.minersstudios.whomine.custom.block.params.NoteBlockData; -import com.minersstudios.whomine.custom.block.params.PlacingType; -import com.minersstudios.whomine.custom.block.params.ToolType; -import com.minersstudios.whomine.custom.block.params.settings.Placing; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.api.throwable.ConfigurationException; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.world.sound.Sound; -import com.minersstudios.whomine.world.sound.SoundAdapter; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.custom.block.file.adapter.*; +import com.minersstudios.wholib.paper.custom.block.params.NoteBlockData; +import com.minersstudios.wholib.paper.custom.block.params.PlacingType; +import com.minersstudios.wholib.paper.custom.block.params.ToolType; +import com.minersstudios.wholib.paper.custom.block.params.settings.Placing; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.throwable.ConfigurationException; +import com.minersstudios.wholib.paper.world.sound.Sound; +import com.minersstudios.wholib.paper.world.sound.SoundAdapter; import org.bukkit.NamespacedKey; import org.bukkit.SoundCategory; import org.bukkit.inventory.ItemStack; @@ -51,7 +51,7 @@ public final class CustomBlockFile { private static final Gson GSON = new GsonBuilder() - .registerTypeAdapter(NamespacedKey.class, new NamespacedKeyAdapter(SharedConstants.MSBLOCK_NAMESPACE)) + .registerTypeAdapter(NamespacedKey.class, new NamespacedKeyAdapter(Resource.WMBLOCK)) .registerTypeAdapter(ItemStack.class, new ItemStackAdapter()) .registerTypeAdapter(Recipe.class, new RecipeAdapter()) .registerTypeAdapter(RecipeChoice.class, new RecipeChoiceAdapter()) diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/EnumAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/EnumAdapter.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/EnumAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/EnumAdapter.java index caf1c8a3..870ccacb 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/EnumAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/EnumAdapter.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.custom.block.file.adapter; +package com.minersstudios.wholib.paper.custom.block.file.adapter; import com.google.gson.*; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/ItemStackAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/ItemStackAdapter.java similarity index 83% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/ItemStackAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/ItemStackAdapter.java index 8617f5c1..c73bb9cc 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/ItemStackAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/ItemStackAdapter.java @@ -1,11 +1,9 @@ -package com.minersstudios.whomine.custom.block.file.adapter; +package com.minersstudios.wholib.paper.custom.block.file.adapter; import com.google.gson.*; -import com.minersstudios.whomine.utility.BlockUtils; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.nbt.TagParser; +import com.minersstudios.wholib.paper.utility.BlockUtils; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -48,11 +46,12 @@ public class ItemStackAdapter implements JsonSerializer, JsonDeserial final net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); final String nbt = jsonObject.get(NBT_KEY).getAsString(); - try { - nmsItemStack.setTag(TagParser.parseTag(nbt)); - } catch (final CommandSyntaxException e) { - throw new JsonParseException("Invalid NBT: " + nbt); - } + // TODO: fix tag deserialization + //try { + // nmsItemStack.setTag(TagParser.parseTag(nbt)); + //} catch (final CommandSyntaxException e) { + // throw new JsonParseException("Invalid NBT: " + nbt); + //} return nmsItemStack.asBukkitCopy(); } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/NamespacedKeyAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/NamespacedKeyAdapter.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/NamespacedKeyAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/NamespacedKeyAdapter.java index fc93675a..e437054e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/NamespacedKeyAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/NamespacedKeyAdapter.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.block.file.adapter; +package com.minersstudios.wholib.paper.custom.block.file.adapter; import com.google.gson.*; -import com.minersstudios.whomine.api.annotation.ResourceKey; +import com.minersstudios.wholib.annotation.ResourcePath; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; @@ -20,7 +20,7 @@ public class NamespacedKeyAdapter implements JsonSerializer, JsonDeserializer { private final String namespace; - public NamespacedKeyAdapter(final @ResourceKey @NotNull String namespace) { + public NamespacedKeyAdapter(final @ResourcePath @NotNull String namespace) { this.namespace = namespace; } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/NoteBlockDataAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/NoteBlockDataAdapter.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/NoteBlockDataAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/NoteBlockDataAdapter.java index 7acaa8be..cce9d76c 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/NoteBlockDataAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/NoteBlockDataAdapter.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.block.file.adapter; +package com.minersstudios.wholib.paper.custom.block.file.adapter; import com.google.gson.*; -import com.minersstudios.whomine.custom.block.params.NoteBlockData; +import com.minersstudios.wholib.paper.custom.block.params.NoteBlockData; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.bukkit.Instrument; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/PlacingAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/PlacingAdapter.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/PlacingAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/PlacingAdapter.java index e72cfdc5..c7cc1e58 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/PlacingAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/PlacingAdapter.java @@ -1,8 +1,8 @@ -package com.minersstudios.whomine.custom.block.file.adapter; +package com.minersstudios.wholib.paper.custom.block.file.adapter; import com.google.gson.*; -import com.minersstudios.whomine.custom.block.params.PlacingType; -import com.minersstudios.whomine.custom.block.params.settings.Placing; +import com.minersstudios.wholib.paper.custom.block.params.PlacingType; +import com.minersstudios.wholib.paper.custom.block.params.settings.Placing; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/PlacingTypeAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/PlacingTypeAdapter.java similarity index 70% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/PlacingTypeAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/PlacingTypeAdapter.java index b2e6f95e..9ad0f2d3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/PlacingTypeAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/PlacingTypeAdapter.java @@ -1,9 +1,9 @@ -package com.minersstudios.whomine.custom.block.file.adapter; +package com.minersstudios.wholib.paper.custom.block.file.adapter; import com.google.gson.*; import com.google.gson.reflect.TypeToken; -import com.minersstudios.whomine.custom.block.params.PlacingType; -import com.minersstudios.whomine.custom.block.params.NoteBlockData; +import com.minersstudios.wholib.paper.custom.block.params.NoteBlockData; +import com.minersstudios.wholib.paper.custom.block.params.PlacingType; import org.bukkit.Axis; import org.bukkit.block.BlockFace; import org.jetbrains.annotations.NotNull; @@ -83,32 +83,20 @@ public class PlacingTypeAdapter implements JsonSerializer, JsonDese ) throws UnsupportedOperationException { final JsonObject jsonObject = new JsonObject(); - if (placingType instanceof final PlacingType.Default defaultType) { - jsonObject.addProperty(TYPE_KEY, DEFAULT_TYPE); - jsonObject.add( - NOTE_BLOCK_DATA_KEY, - context.serialize(defaultType.getNoteBlockData()) - ); - } else if (placingType instanceof final PlacingType.Directional directionalType) { - jsonObject.addProperty(TYPE_KEY, DIRECTIONAL_TYPE); - jsonObject.add( - NOTE_BLOCK_DATA_KEY, - context.serialize( - directionalType.getMap(), - BLOCK_FACE_MAP_TYPE - ) - ); - } else if (placingType instanceof final PlacingType.Orientable orientableType) { - jsonObject.addProperty(TYPE_KEY, ORIENTABLE_TYPE); - jsonObject.add( - NOTE_BLOCK_DATA_KEY, - context.serialize( - orientableType.getMap(), - AXIS_NOTE_MAP_TYPE - ) - ); - } else { - throw new UnsupportedOperationException("Unknown placing type : " + placingType.getClass()); + switch (placingType) { + case final PlacingType.Default defaultType -> { + jsonObject.addProperty(TYPE_KEY, DEFAULT_TYPE); + jsonObject.add(NOTE_BLOCK_DATA_KEY, context.serialize(defaultType.getNoteBlockData())); + } + case final PlacingType.Directional directionalType -> { + jsonObject.addProperty(TYPE_KEY, DIRECTIONAL_TYPE); + jsonObject.add(NOTE_BLOCK_DATA_KEY, context.serialize(directionalType.getMap(), BLOCK_FACE_MAP_TYPE)); + } + case final PlacingType.Orientable orientableType -> { + jsonObject.addProperty(TYPE_KEY, ORIENTABLE_TYPE); + jsonObject.add(NOTE_BLOCK_DATA_KEY, context.serialize(orientableType.getMap(), AXIS_NOTE_MAP_TYPE)); + } + default -> throw new UnsupportedOperationException("Unknown placing type : " + placingType.getClass()); } return jsonObject; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/RecipeAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/RecipeAdapter.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/RecipeAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/RecipeAdapter.java index dfeeb6a1..060de0fb 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/RecipeAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/RecipeAdapter.java @@ -1,10 +1,10 @@ -package com.minersstudios.whomine.custom.block.file.adapter; +package com.minersstudios.wholib.paper.custom.block.file.adapter; import com.google.gson.*; import com.google.gson.reflect.TypeToken; -import com.minersstudios.whomine.custom.block.file.CustomBlockFile; -import com.minersstudios.whomine.custom.block.params.RecipeType; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.paper.custom.block.file.CustomBlockFile; +import com.minersstudios.wholib.paper.custom.block.params.RecipeType; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/RecipeChoiceAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/RecipeChoiceAdapter.java similarity index 80% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/RecipeChoiceAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/RecipeChoiceAdapter.java index 4316c16e..c8de6fea 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/RecipeChoiceAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/RecipeChoiceAdapter.java @@ -1,8 +1,8 @@ -package com.minersstudios.whomine.custom.block.file.adapter; +package com.minersstudios.wholib.paper.custom.block.file.adapter; import com.google.gson.*; import com.google.gson.reflect.TypeToken; -import com.minersstudios.whomine.inventory.recipe.choice.CustomChoice; +import com.minersstudios.wholib.paper.inventory.recipe.choice.CustomChoice; import org.bukkit.inventory.RecipeChoice; import org.jetbrains.annotations.NotNull; @@ -85,14 +85,14 @@ public class RecipeChoiceAdapter implements JsonSerializer, JsonDe : CUSTOM_CHOICE ); - if (choice instanceof final RecipeChoice.MaterialChoice materialChoice) { - jsonObject.add(CHOICES_KEY, context.serialize(materialChoice.getChoices())); - } else if (choice instanceof final RecipeChoice.ExactChoice exactChoice) { - jsonObject.add(CHOICES_KEY, context.serialize(exactChoice.getChoices())); - } else if (choice instanceof final CustomChoice customChoice) { - jsonObject.add(CHOICES_KEY, context.serialize(customChoice.namespacedKeySet())); - } else { - throw new IllegalArgumentException("Unknown RecipeChoice type: " + choice.getClass().getName()); + switch (choice) { + case final RecipeChoice.MaterialChoice materialChoice -> + jsonObject.add(CHOICES_KEY, context.serialize(materialChoice.getChoices())); + case final RecipeChoice.ExactChoice exactChoice -> + jsonObject.add(CHOICES_KEY, context.serialize(exactChoice.getChoices())); + case final CustomChoice customChoice -> + jsonObject.add(CHOICES_KEY, context.serialize(customChoice.namespacedKeySet())); + default -> throw new IllegalArgumentException("Unknown RecipeChoice type: " + choice.getClass().getName()); } return jsonObject; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/RecipeEntryAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/RecipeEntryAdapter.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/RecipeEntryAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/RecipeEntryAdapter.java index c52f9688..7afe25dd 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/file/adapter/RecipeEntryAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/file/adapter/RecipeEntryAdapter.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.block.file.adapter; +package com.minersstudios.wholib.paper.custom.block.file.adapter; import com.google.gson.*; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; import org.bukkit.inventory.Recipe; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/BlockSettings.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/BlockSettings.java similarity index 81% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/params/BlockSettings.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/BlockSettings.java index c847dd7d..6cdbed13 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/BlockSettings.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/BlockSettings.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.block.params; +package com.minersstudios.wholib.paper.custom.block.params; -import com.minersstudios.whomine.custom.block.params.settings.Placing; -import com.minersstudios.whomine.custom.block.params.settings.Tool; +import com.minersstudios.wholib.paper.custom.block.params.settings.Placing; +import com.minersstudios.wholib.paper.custom.block.params.settings.Tool; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -69,26 +69,22 @@ public float getHardness() { * * @param player The player whose dig speed is being * calculated - * @param slowDiggingAmplifier The amplifier of the slow digging effect, - * or -1 if the player doesn't have the effect * @return The calculated dig speed of the custom block for the player using * magic numbers */ public float calculateDigSpeed( - final @NotNull Player player, - final int slowDiggingAmplifier + final @NotNull Player player ) { float base = 1.0f; final ItemStack itemInMainHand = player.getInventory().getItemInMainHand(); final Material material = itemInMainHand.getType(); - final PotionEffect fastDigging = player.getPotionEffect(PotionEffectType.FAST_DIGGING); final ToolType toolType = this.tool.getToolType(); if (toolType == ToolType.fromMaterial(material)) { base = ToolTier.fromMaterial(material).getDigSpeed(); - if (itemInMainHand.containsEnchantment(Enchantment.DIG_SPEED)) { - base += itemInMainHand.getEnchantmentLevel(Enchantment.DIG_SPEED) * 0.3f; + if (itemInMainHand.containsEnchantment(Enchantment.EFFICIENCY)) { + base += itemInMainHand.getEnchantmentLevel(Enchantment.EFFICIENCY) * 0.3f; } } else if (toolType == ToolType.PICKAXE) { base /= 30.0f; @@ -96,12 +92,16 @@ public float calculateDigSpeed( base /= 5.0f; } + final PotionEffect fastDigging = player.getPotionEffect(PotionEffectType.HASTE); + if (fastDigging != null) { base *= (fastDigging.getAmplifier() + 1) * 1.8f; } - if (slowDiggingAmplifier != -1) { - base /= (slowDiggingAmplifier + 1) * 3.6f; + final PotionEffect slowDigging = player.getPotionEffect(PotionEffectType.MINING_FATIGUE); + + if (slowDigging != null) { + base /= (slowDigging.getAmplifier() + 1) * 3.6f; } return base / this.hardness; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/DropSettings.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/DropSettings.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/params/DropSettings.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/DropSettings.java index 3d4f478d..63f2d167 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/DropSettings.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/DropSettings.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.custom.block.params; +package com.minersstudios.wholib.paper.custom.block.params; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/NoteBlockData.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/NoteBlockData.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/params/NoteBlockData.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/NoteBlockData.java index 8416071c..57427ba3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/NoteBlockData.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/NoteBlockData.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.custom.block.params; +package com.minersstudios.wholib.paper.custom.block.params; import org.bukkit.Instrument; import org.bukkit.Note; @@ -215,6 +215,7 @@ public int hashCode() { * {@link NoteBlock} and has the same instrument, note and powered * state */ + @Contract("null -> false") @Override public boolean equals(final @Nullable Object obj) { return obj == this diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/PlacingType.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/PlacingType.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/params/PlacingType.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/PlacingType.java index 1e2838f1..7dfc80bc 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/PlacingType.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/PlacingType.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.custom.block.params; +package com.minersstudios.wholib.paper.custom.block.params; import org.bukkit.Axis; import org.bukkit.block.BlockFace; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/RecipeType.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/RecipeType.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/params/RecipeType.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/RecipeType.java index a61a181c..e2794113 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/RecipeType.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/RecipeType.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.custom.block.params; +package com.minersstudios.wholib.paper.custom.block.params; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.bukkit.inventory.*; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/ToolTier.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/ToolTier.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/params/ToolTier.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/ToolTier.java index 66ed17c1..8c6f74bf 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/ToolTier.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/ToolTier.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.custom.block.params; +package com.minersstudios.wholib.paper.custom.block.params; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/ToolType.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/ToolType.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/params/ToolType.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/ToolType.java index dc806c45..9d8002f0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/ToolType.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/ToolType.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.custom.block.params; +package com.minersstudios.wholib.paper.custom.block.params; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/settings/Placing.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/settings/Placing.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/params/settings/Placing.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/settings/Placing.java index e16e6c25..38069c0a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/settings/Placing.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/settings/Placing.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.block.params.settings; +package com.minersstudios.wholib.paper.custom.block.params.settings; import com.google.common.base.Joiner; -import com.minersstudios.whomine.custom.block.params.PlacingType; +import com.minersstudios.wholib.paper.custom.block.params.PlacingType; import org.bukkit.Material; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/settings/Tool.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/settings/Tool.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/custom/block/params/settings/Tool.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/settings/Tool.java index 47c1b8d0..4c9beee2 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/block/params/settings/Tool.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/block/params/settings/Tool.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.block.params.settings; +package com.minersstudios.wholib.paper.custom.block.params.settings; -import com.minersstudios.whomine.custom.block.params.ToolType; +import com.minersstudios.wholib.paper.custom.block.params.ToolType; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecor.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecor.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecor.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecor.java index 94eedca8..55f13dee 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecor.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecor.java @@ -1,12 +1,11 @@ -package com.minersstudios.whomine.custom.decor; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.world.location.MSBoundingBox; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.MSDecorUtils; -import com.minersstudios.whomine.custom.decor.event.CustomDecorBreakEvent; +package com.minersstudios.wholib.paper.custom.decor; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.world.location.MSBoundingBox; +import com.minersstudios.wholib.paper.world.location.MSPosition; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.utility.MSDecorUtils; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorBreakEvent; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; import net.minecraft.world.level.block.Blocks; @@ -15,7 +14,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.type.Light; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Interaction; import org.bukkit.entity.ItemDisplay; @@ -152,13 +151,7 @@ public void destroy( final MSPosition center = this.msbb.getCenter(world); if (dropItem) { - ItemStack displayItem = this.display.getItemStack(); - - if (displayItem == null) { - displayItem = this.data.getItem(); - - MSLogger.warning("Trying to drop a null item from a custom decor at " + this.display.getLocation()); - } + final ItemStack displayItem = this.display.getItemStack(); world.dropItemNaturally( center.toLocation(), diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecorData.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecorData.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecorData.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecorData.java index 68269e7f..3f90cf05 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecorData.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecorData.java @@ -1,17 +1,17 @@ -package com.minersstudios.whomine.custom.decor; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.decor.action.DecorBreakAction; -import com.minersstudios.whomine.custom.decor.action.DecorClickAction; -import com.minersstudios.whomine.custom.decor.action.DecorPlaceAction; -import com.minersstudios.whomine.custom.decor.event.CustomDecorBreakEvent; -import com.minersstudios.whomine.custom.decor.event.CustomDecorClickEvent; -import com.minersstudios.whomine.custom.decor.event.CustomDecorPlaceEvent; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.world.sound.SoundGroup; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.MSDecorUtils; +package com.minersstudios.wholib.paper.custom.decor; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.decor.action.DecorBreakAction; +import com.minersstudios.wholib.paper.custom.decor.action.DecorClickAction; +import com.minersstudios.wholib.paper.custom.decor.action.DecorPlaceAction; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorBreakEvent; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorClickEvent; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorPlaceEvent; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.paper.world.location.MSPosition; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.utility.MSDecorUtils; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.kyori.adventure.text.Component; import org.bukkit.Keyed; @@ -793,6 +793,7 @@ interface Type> extends Keyed { /** * @return The unique namespaced key identifying the custom decor type */ + @Override @NotNull NamespacedKey getKey(); /** diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecorDataImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecorDataImpl.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecorDataImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecorDataImpl.java index 547ad789..7759cb2f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecorDataImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecorDataImpl.java @@ -1,26 +1,30 @@ -package com.minersstudios.whomine.custom.decor; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.decor.action.DecorBreakAction; -import com.minersstudios.whomine.custom.decor.action.DecorClickAction; -import com.minersstudios.whomine.custom.decor.action.DecorPlaceAction; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.world.location.MSBoundingBox; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.world.location.MSVector; -import com.minersstudios.whomine.api.throwable.InvalidRegexException; -import com.minersstudios.whomine.custom.decor.event.CustomDecorBreakEvent; -import com.minersstudios.whomine.custom.decor.event.CustomDecorClickEvent; -import com.minersstudios.whomine.custom.decor.event.CustomDecorPlaceEvent; -import com.minersstudios.whomine.world.sound.SoundGroup; -import com.minersstudios.whomine.utility.*; +package com.minersstudios.wholib.paper.custom.decor; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.utility.SharedConstants; +import com.minersstudios.wholib.paper.custom.decor.action.DecorBreakAction; +import com.minersstudios.wholib.paper.custom.decor.action.DecorClickAction; +import com.minersstudios.wholib.paper.custom.decor.action.DecorPlaceAction; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.paper.world.location.MSBoundingBox; +import com.minersstudios.wholib.paper.world.location.MSPosition; +import com.minersstudios.wholib.paper.world.location.MSVector; +import com.minersstudios.wholib.throwable.InvalidRegexException; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorBreakEvent; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorClickEvent; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorPlaceEvent; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.utility.*; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import org.bukkit.*; @@ -29,9 +33,10 @@ import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Levelled; import org.bukkit.block.data.type.Light; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockStates; -import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.craftbukkit.block.CraftBlockStates; +import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.entity.Interaction; import org.bukkit.entity.ItemDisplay; import org.bukkit.entity.Player; @@ -268,13 +273,13 @@ protected CustomDecorDataImpl(final @NotNull WhoMine plugin) throws IllegalState if (!CustomDecorType.matchesTypedKey(key)) { return this.types[0]; } - + for (final var type : this.types) { if (key.equals(type.getKey().getKey())) { return type; } } - + return null; } @@ -725,7 +730,7 @@ public void registerRecipes(final @NotNull WhoMine plugin) { plugin.getServer().addRecipe(recipe); if (registerInMenu) { - plugin.getCache().customDecorRecipes.add(recipe); + plugin.getCache().getCustomDecorRecipes().add(recipe); } } } @@ -743,7 +748,7 @@ public final void unregisterRecipes(final @NotNull WhoMine plugin) { plugin.getServer().removeRecipe(recipe.getKey()); if (isRegisteredInMenu) { - plugin.getCache().customDecorRecipes.remove(recipe); + plugin.getCache().getCustomDecorRecipes().remove(recipe); } } } @@ -810,17 +815,12 @@ public void place( for (final var blockPos : blocksToReplace) { final BlockState blockState = serverLevel.getBlockState(blockPos); - if (!BlockUtils.isReplaceable(blockState.getBlock())) { - return; - } + if (BlockUtils.isReplaceable(blockState.getBlock())) { + final BlockEntity tileEntity = serverLevel.getBlockEntity(blockPos); + final CraftBlockState craftState = CraftBlockStates.getBlockState(null, blockPos, blockState, tileEntity); - blockStates.add( - CraftBlockStates.getUnplacedBlockState( - serverLevel, - blockPos, - blockState - ) - ); + blockStates.add(craftState); + } } if ( @@ -1354,7 +1354,7 @@ public Builder() { if ( this.isSittable() - && this.sitHeight != this.sitHeight + && Double.isNaN(this.sitHeight) ) { throw new IllegalStateException("Sit height is not set, but sittable parameter is set!"); } @@ -1445,10 +1445,10 @@ public Builder() { return this.namespacedKey; } - public @NotNull Builder key(final @Key @NotNull String key) throws InvalidRegexException { - Key.Validator.validate(key); + public @NotNull Builder key(final @Path @NotNull String key) throws InvalidRegexException { + Path.Validator.validate(key); - this.namespacedKey = new NamespacedKey(SharedConstants.MSDECOR_NAMESPACE, key); + this.namespacedKey = new NamespacedKey(Resource.WMDECOR, key); return this; } @@ -1496,6 +1496,10 @@ public Builder() { } this.itemStack = setTypeKey(itemStack, this.namespacedKey.getKey()); + final ItemMeta meta = this.itemStack.getItemMeta(); + + meta.setMaxStackSize(SharedConstants.DECOR_MAX_STACK_SIZE); + this.itemStack.setItemMeta(meta); return this; } @@ -1990,13 +1994,13 @@ protected final class Type implements CustomDecorData.Type { public Type( final @NotNull Builder builder, - final @Key @NotNull String key, + final @Path @NotNull String key, final @NotNull ItemStack itemStack ) throws InvalidRegexException { - Key.Validator.validate(key); + Path.Validator.validate(key); final String typedKey = builder.namespacedKey.getKey() + ".type." + key; - this.namespacedKey = new NamespacedKey(SharedConstants.MSDECOR_NAMESPACE, typedKey); + this.namespacedKey = new NamespacedKey(Resource.WMDECOR, typedKey); this.itemStack = setTypeKey(itemStack, typedKey); } @@ -2021,8 +2025,8 @@ public int hashCode() { return result; } - @Override @Contract("null -> false") + @Override public boolean equals(final @Nullable Object obj) { return obj == this || ( diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecorType.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecorType.java similarity index 87% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecorType.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecorType.java index 1f8ac163..965d1d1e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/CustomDecorType.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/CustomDecorType.java @@ -1,32 +1,32 @@ -package com.minersstudios.whomine.custom.decor; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.decor.registry.christmas.*; -import com.minersstudios.whomine.custom.decor.registry.decoration.home.*; -import com.minersstudios.whomine.custom.decor.registry.furniture.chair.*; -import com.minersstudios.whomine.menu.CraftsMenu; -import com.minersstudios.whomine.custom.decor.registry.decoration.home.head.DeerHead; -import com.minersstudios.whomine.custom.decor.registry.decoration.home.head.HoglinHead; -import com.minersstudios.whomine.custom.decor.registry.decoration.home.head.ZoglinHead; -import com.minersstudios.whomine.custom.decor.registry.decoration.home.plush.BMOPlush; -import com.minersstudios.whomine.custom.decor.registry.decoration.home.plush.BrownBearPlush; -import com.minersstudios.whomine.custom.decor.registry.decoration.home.plush.RacoonPlush; -import com.minersstudios.whomine.custom.decor.registry.decoration.home.plush.WhocintoshMini; -import com.minersstudios.whomine.custom.decor.registry.decoration.street.Brazier; -import com.minersstudios.whomine.custom.decor.registry.decoration.street.FireHydrant; -import com.minersstudios.whomine.custom.decor.registry.decoration.street.IronTrashcan; -import com.minersstudios.whomine.custom.decor.registry.decoration.street.Wheelbarrow; -import com.minersstudios.whomine.custom.decor.registry.furniture.Nightstand; -import com.minersstudios.whomine.custom.decor.registry.furniture.lamp.BigLamp; -import com.minersstudios.whomine.custom.decor.registry.furniture.lamp.SmallLamp; -import com.minersstudios.whomine.custom.decor.registry.furniture.table.BigTable; -import com.minersstudios.whomine.custom.decor.registry.furniture.table.SmallTable; -import com.minersstudios.whomine.custom.decor.registry.other.Poop; -import com.minersstudios.whomine.api.status.StatusHandler; -import com.minersstudios.whomine.api.status.StatusWatcher; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; +package com.minersstudios.wholib.paper.custom.decor; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.module.MainModule; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.custom.decor.registry.christmas.*; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.*; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.head.DeerHead; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.head.HoglinHead; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.head.ZoglinHead; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.plush.BMOPlush; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.plush.BrownBearPlush; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.plush.RacoonPlush; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.plush.WhocintoshMini; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.street.Brazier; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.street.FireHydrant; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.street.IronTrashcan; +import com.minersstudios.wholib.paper.custom.decor.registry.decoration.street.Wheelbarrow; +import com.minersstudios.wholib.paper.custom.decor.registry.furniture.Nightstand; +import com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair.*; +import com.minersstudios.wholib.paper.custom.decor.registry.furniture.lamp.BigLamp; +import com.minersstudios.wholib.paper.custom.decor.registry.furniture.lamp.SmallLamp; +import com.minersstudios.wholib.paper.custom.decor.registry.furniture.table.BigTable; +import com.minersstudios.wholib.paper.custom.decor.registry.furniture.table.SmallTable; +import com.minersstudios.wholib.paper.custom.decor.registry.other.Poop; +import com.minersstudios.wholib.status.StatusHandler; +import com.minersstudios.wholib.status.StatusWatcher; +import com.minersstudios.wholib.utility.ChatUtils; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; @@ -83,7 +83,7 @@ public enum CustomDecorType { NETHERITE_PIGGYBANK(Piggybank.Netherite.class), SMALL_CLOCK(SmallClock.class), SMALL_GLOBE(SmallGlobe.class), - ATM(com.minersstudios.whomine.custom.decor.registry.decoration.street.ATM.class), + ATM(com.minersstudios.wholib.paper.custom.decor.registry.decoration.street.ATM.class), BRAZIER(Brazier.class), FIRE_HYDRANT(FireHydrant.class), IRON_TRASHCAN(IronTrashcan.class), @@ -189,9 +189,9 @@ public enum CustomDecorType { private final Class> clazz; public static final String TYPE_TAG_NAME = "type"; - public static final NamespacedKey TYPE_NAMESPACED_KEY = new NamespacedKey(SharedConstants.MSDECOR_NAMESPACE, TYPE_TAG_NAME); + public static final NamespacedKey TYPE_NAMESPACED_KEY = new NamespacedKey(Resource.WMDECOR, TYPE_TAG_NAME); - public static final String TYPED_KEY_REGEX = "(" + Key.REGEX + ")\\.type\\.(" + Key.REGEX + ")"; + public static final String TYPED_KEY_REGEX = "(" + Path.REGEX + ")\\.type\\.(" + Path.REGEX + ")"; public static final Pattern TYPED_KEY_PATTERN = Pattern.compile(TYPED_KEY_REGEX); private static final Map KEY_TO_TYPE_MAP = new Object2ObjectOpenHashMap<>(); @@ -229,9 +229,9 @@ public static void load(final @NotNull WhoMine plugin) throws IllegalStateExcept statusHandler.addWatcher( StatusWatcher.builder() .successStatuses( - WhoMine.LOADED_BLOCKS, - WhoMine.LOADED_ITEMS, - WhoMine.LOADED_DECORATIONS + MainModule.LOADED_BLOCKS, + MainModule.LOADED_ITEMS, + MainModule.LOADED_DECORATIONS ) .successRunnable( () -> plugin.runTask(() -> { @@ -239,16 +239,17 @@ public static void load(final @NotNull WhoMine plugin) throws IllegalStateExcept type.getCustomDecorData().registerRecipes(plugin); } - CraftsMenu.putCrafts( - CraftsMenu.Type.DECORS, - plugin.getCache().customDecorRecipes - ); + // TODO: fix this + //CraftsMenu.putCrafts( + // CraftsMenu.Type.DECORS, + // plugin.getCache().customDecorRecipes + //); }) ) .build() ); - statusHandler.assignStatus(WhoMine.LOADING_DECORATIONS); + statusHandler.assignStatus(MainModule.LOADING_DECORATIONS); Stream.of(values()).parallel() .forEach(type -> { final CustomDecorData data; @@ -295,7 +296,7 @@ public static void load(final @NotNull WhoMine plugin) throws IllegalStateExcept }); typesWithRecipes.sort(Comparator.comparingInt(CustomDecorType::ordinal)); - statusHandler.assignStatus(WhoMine.LOADED_DECORATIONS); + statusHandler.assignStatus(MainModule.LOADED_DECORATIONS); plugin.getComponentLogger().info( Component.text( "Loaded " + loaded.get() + " custom decors in " + (System.currentTimeMillis() - startTime) + "ms", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/DecorHitBox.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/DecorHitBox.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/DecorHitBox.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/DecorHitBox.java index a1b4647e..19a41f56 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/DecorHitBox.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/DecorHitBox.java @@ -1,9 +1,9 @@ -package com.minersstudios.whomine.custom.decor; +package com.minersstudios.wholib.paper.custom.decor; -import com.minersstudios.whomine.world.location.MSBoundingBox; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.world.location.MSVector; -import com.minersstudios.whomine.utility.LocationUtils; +import com.minersstudios.wholib.paper.world.location.MSBoundingBox; +import com.minersstudios.wholib.paper.world.location.MSPosition; +import com.minersstudios.wholib.paper.world.location.MSVector; +import com.minersstudios.wholib.paper.utility.LocationUtils; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import org.bukkit.Material; @@ -19,7 +19,7 @@ import java.util.EnumSet; import java.util.Set; -import static com.minersstudios.whomine.utility.SharedConstants.MSDECOR_NAMESPACE; +import static com.minersstudios.wholib.annotation.Resource.WMDECOR; /** * Represents a DecorHitBox, defining the hitbox properties for custom decor @@ -41,10 +41,10 @@ public final class DecorHitBox { public static final String HITBOX_INTERACTIONS_KEY = "hitbox_interactions"; public static final String HITBOX_BOUNDING_BOX_KEY = "hitbox_bounding_box"; - public static final NamespacedKey HITBOX_CHILD_NAMESPACED_KEY = new NamespacedKey(MSDECOR_NAMESPACE, HITBOX_CHILD_KEY); - public static final NamespacedKey HITBOX_DISPLAY_NAMESPACED_KEY = new NamespacedKey(MSDECOR_NAMESPACE, HITBOX_DISPLAY_KEY); - public static final NamespacedKey HITBOX_INTERACTIONS_NAMESPACED_KEY = new NamespacedKey(MSDECOR_NAMESPACE, HITBOX_INTERACTIONS_KEY); - public static final NamespacedKey HITBOX_BOUNDING_BOX_NAMESPACED_KEY = new NamespacedKey(MSDECOR_NAMESPACE, HITBOX_BOUNDING_BOX_KEY); + public static final NamespacedKey HITBOX_CHILD_NAMESPACED_KEY = new NamespacedKey(WMDECOR, HITBOX_CHILD_KEY); + public static final NamespacedKey HITBOX_DISPLAY_NAMESPACED_KEY = new NamespacedKey(WMDECOR, HITBOX_DISPLAY_KEY); + public static final NamespacedKey HITBOX_INTERACTIONS_NAMESPACED_KEY = new NamespacedKey(WMDECOR, HITBOX_INTERACTIONS_KEY); + public static final NamespacedKey HITBOX_BOUNDING_BOX_NAMESPACED_KEY = new NamespacedKey(WMDECOR, HITBOX_BOUNDING_BOX_KEY); /** * Constructs a DecorHitBox based on the provided Builder diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/DecorParameter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/DecorParameter.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/DecorParameter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/DecorParameter.java index 2a09e4d3..ebb17bae 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/DecorParameter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/DecorParameter.java @@ -1,12 +1,12 @@ -package com.minersstudios.whomine.custom.decor; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.decor.action.DecorClickAction; -import com.minersstudios.whomine.world.location.MSBoundingBox; -import com.minersstudios.whomine.utility.ItemUtils; -import com.minersstudios.whomine.utility.PlayerUtils; -import com.minersstudios.whomine.custom.decor.event.CustomDecorClickEvent; -import com.minersstudios.whomine.custom.item.CustomItemType; +package com.minersstudios.wholib.paper.custom.decor; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.decor.action.DecorClickAction; +import com.minersstudios.wholib.paper.world.location.MSBoundingBox; +import com.minersstudios.wholib.paper.utility.ItemUtils; +import com.minersstudios.wholib.paper.utility.PlayerUtils; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorClickEvent; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; import org.bukkit.*; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Light; @@ -93,7 +93,6 @@ public enum DecorParameter { final ItemDisplay itemDisplay = customDecor.getDisplay(); final ItemStack displayItem = itemDisplay.getItemStack(); - assert displayItem != null; itemMeta.displayName(displayItem.getItemMeta().displayName()); typeItem.setItemMeta(itemMeta); diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/Facing.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/Facing.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/Facing.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/Facing.java index b6377c38..e4837f1c 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/Facing.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/Facing.java @@ -1,8 +1,8 @@ -package com.minersstudios.whomine.custom.decor; +package com.minersstudios.wholib.paper.custom.decor; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.utility.BlockUtils; -import com.minersstudios.whomine.utility.LocationUtils; +import com.minersstudios.wholib.paper.world.location.MSPosition; +import com.minersstudios.wholib.paper.utility.BlockUtils; +import com.minersstudios.wholib.paper.utility.LocationUtils; import org.bukkit.block.BlockFace; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/action/DecorBreakAction.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/action/DecorBreakAction.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/action/DecorBreakAction.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/action/DecorBreakAction.java index d287294e..dc0d053a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/action/DecorBreakAction.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/action/DecorBreakAction.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.decor.action; +package com.minersstudios.wholib.paper.custom.decor.action; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.decor.event.CustomDecorBreakEvent; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorBreakEvent; import org.jetbrains.annotations.NotNull; /** diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/action/DecorClickAction.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/action/DecorClickAction.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/action/DecorClickAction.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/action/DecorClickAction.java index 8b8321b2..5d68e720 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/action/DecorClickAction.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/action/DecorClickAction.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.decor.action; +package com.minersstudios.wholib.paper.custom.decor.action; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.decor.event.CustomDecorClickEvent; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorClickEvent; import org.jetbrains.annotations.NotNull; /** diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/action/DecorPlaceAction.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/action/DecorPlaceAction.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/action/DecorPlaceAction.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/action/DecorPlaceAction.java index 9d1d470a..48f888b3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/action/DecorPlaceAction.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/action/DecorPlaceAction.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.decor.action; +package com.minersstudios.wholib.paper.custom.decor.action; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.decor.event.CustomDecorPlaceEvent; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorPlaceEvent; import org.jetbrains.annotations.NotNull; /** diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorBreakEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorBreakEvent.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorBreakEvent.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorBreakEvent.java index 4b1d664f..dc0f46f3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorBreakEvent.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorBreakEvent.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.decor.event; +package com.minersstudios.wholib.paper.custom.decor.event; -import com.minersstudios.whomine.custom.decor.CustomDecor; +import com.minersstudios.wholib.paper.custom.decor.CustomDecor; import org.bukkit.entity.Entity; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorClickEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorClickEvent.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorClickEvent.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorClickEvent.java index ae4c3c58..5441c845 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorClickEvent.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorClickEvent.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.decor.event; +package com.minersstudios.wholib.paper.custom.decor.event; -import com.minersstudios.whomine.custom.decor.CustomDecor; +import com.minersstudios.wholib.paper.custom.decor.CustomDecor; import org.bukkit.entity.Interaction; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorEvent.java similarity index 83% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorEvent.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorEvent.java index 5c3e5a12..a8155200 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorEvent.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorEvent.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.decor.event; +package com.minersstudios.wholib.paper.custom.decor.event; -import com.minersstudios.whomine.custom.decor.CustomDecor; +import com.minersstudios.wholib.paper.custom.decor.CustomDecor; import org.bukkit.event.Event; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorPlaceEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorPlaceEvent.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorPlaceEvent.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorPlaceEvent.java index f93d093a..84ba89b7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/event/CustomDecorPlaceEvent.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/event/CustomDecorPlaceEvent.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.decor.event; +package com.minersstudios.wholib.paper.custom.decor.event; -import com.minersstudios.whomine.custom.decor.CustomDecor; +import com.minersstudios.wholib.paper.custom.decor.CustomDecor; import org.bukkit.block.BlockState; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/ChristmasBall.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/ChristmasBall.java similarity index 79% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/ChristmasBall.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/ChristmasBall.java index 728bb9d9..1efaad06 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/ChristmasBall.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/ChristmasBall.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.custom.decor.registry.christmas; +package com.minersstudios.wholib.paper.custom.decor.registry.christmas; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/ChristmasTallBall.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/ChristmasTallBall.java similarity index 79% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/ChristmasTallBall.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/ChristmasTallBall.java index 6ed96ba5..4e49bf07 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/ChristmasTallBall.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/ChristmasTallBall.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.custom.decor.registry.christmas; +package com.minersstudios.wholib.paper.custom.decor.registry.christmas; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/SantaSock.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/SantaSock.java similarity index 75% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/SantaSock.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/SantaSock.java index 5796b757..c6eda902 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/SantaSock.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/SantaSock.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.custom.decor.registry.christmas; +package com.minersstudios.wholib.paper.custom.decor.registry.christmas; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/SnowflakeOnString.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/SnowflakeOnString.java similarity index 80% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/SnowflakeOnString.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/SnowflakeOnString.java index bae49a0f..6ab47e58 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/SnowflakeOnString.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/SnowflakeOnString.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.custom.decor.registry.christmas; +package com.minersstudios.wholib.paper.custom.decor.registry.christmas; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.world.sound.SoundGroup; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/Snowman.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/Snowman.java similarity index 79% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/Snowman.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/Snowman.java index a04d3a32..8a485f01 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/Snowman.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/Snowman.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.custom.decor.registry.christmas; +package com.minersstudios.wholib.paper.custom.decor.registry.christmas; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/SnowmanBall.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/SnowmanBall.java similarity index 80% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/SnowmanBall.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/SnowmanBall.java index f08a1abf..bec6d1e0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/SnowmanBall.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/SnowmanBall.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.custom.decor.registry.christmas; +package com.minersstudios.wholib.paper.custom.decor.registry.christmas; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.world.sound.SoundGroup; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/StarOnString.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/StarOnString.java similarity index 80% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/StarOnString.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/StarOnString.java index cd680832..3eb3a04c 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/StarOnString.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/StarOnString.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.custom.decor.registry.christmas; +package com.minersstudios.wholib.paper.custom.decor.registry.christmas; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.world.sound.SoundGroup; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/TreeStar.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/TreeStar.java similarity index 76% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/TreeStar.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/TreeStar.java index f70c44d4..6afbf168 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/christmas/TreeStar.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/christmas/TreeStar.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.christmas; +package com.minersstudios.wholib.paper.custom.decor.registry.christmas; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Cell.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Cell.java similarity index 83% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Cell.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Cell.java index 7e413d1d..4e410435 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Cell.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Cell.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/CookingPot.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/CookingPot.java similarity index 81% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/CookingPot.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/CookingPot.java index 937f669a..fb7d995a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/CookingPot.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/CookingPot.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/OldCamera.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/OldCamera.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/OldCamera.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/OldCamera.java index a9ed593a..8e90aad2 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/OldCamera.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/OldCamera.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Patefon.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Patefon.java similarity index 72% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Patefon.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Patefon.java index f2a89b3e..c541eba0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Patefon.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Patefon.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Piggybank.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Piggybank.java similarity index 81% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Piggybank.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Piggybank.java index 34c8123b..ce12f03f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Piggybank.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Piggybank.java @@ -1,16 +1,16 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.custom.decor.CustomDecorData; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorData; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -20,7 +20,7 @@ public abstract class Piggybank> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final int customModelData, final @NotNull String displayName, final @NotNull Material material @@ -46,7 +46,7 @@ public abstract class Piggybank> extends CustomDeco .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":piggybank") + .group(Resource.WMDECOR + ":piggybank") .category(CraftingBookCategory.BUILDING) .shape( " P", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/SmallClock.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/SmallClock.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/SmallClock.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/SmallClock.java index 1a1fd5e8..cac0e246 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/SmallClock.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/SmallClock.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/SmallGlobe.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/SmallGlobe.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/SmallGlobe.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/SmallGlobe.java index bee0a292..292fe4d0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/SmallGlobe.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/SmallGlobe.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Whocintosh.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Whocintosh.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Whocintosh.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Whocintosh.java index f72343bb..e413a365 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/Whocintosh.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/Whocintosh.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/head/DeerHead.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/head/DeerHead.java similarity index 76% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/head/DeerHead.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/head/DeerHead.java index 225e3789..29f9989b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/head/DeerHead.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/head/DeerHead.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home.head; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.head; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/head/HoglinHead.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/head/HoglinHead.java similarity index 76% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/head/HoglinHead.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/head/HoglinHead.java index 8c979bef..181347ba 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/head/HoglinHead.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/head/HoglinHead.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home.head; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.head; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/head/ZoglinHead.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/head/ZoglinHead.java similarity index 76% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/head/ZoglinHead.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/head/ZoglinHead.java index e7adb852..27273dd1 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/head/ZoglinHead.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/head/ZoglinHead.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home.head; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.head; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/BMOPlush.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/BMOPlush.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/BMOPlush.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/BMOPlush.java index 8d62737f..65f274df 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/BMOPlush.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/BMOPlush.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home.plush; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.plush; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/BrownBearPlush.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/BrownBearPlush.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/BrownBearPlush.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/BrownBearPlush.java index 8a876ade..61abaf0f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/BrownBearPlush.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/BrownBearPlush.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home.plush; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.plush; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/RacoonPlush.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/RacoonPlush.java similarity index 72% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/RacoonPlush.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/RacoonPlush.java index ecb7e6e8..35ef2c1a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/RacoonPlush.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/RacoonPlush.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home.plush; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.plush; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/WhocintoshMini.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/WhocintoshMini.java similarity index 76% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/WhocintoshMini.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/WhocintoshMini.java index dbc69a4f..4c7373c4 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/home/plush/WhocintoshMini.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/home/plush/WhocintoshMini.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.home.plush; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.home.plush; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/ATM.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/ATM.java similarity index 71% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/ATM.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/ATM.java index 109f64e5..2b08ba48 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/ATM.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/ATM.java @@ -1,10 +1,10 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.street; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.street; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.world.sound.SoundGroup; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/Brazier.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/Brazier.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/Brazier.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/Brazier.java index 4809565e..180bce7e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/Brazier.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/Brazier.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.street; - -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.ItemUtils; -import com.minersstudios.whomine.world.sound.SoundGroup; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.street; + +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.utility.ItemUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; import org.bukkit.*; import org.bukkit.entity.ItemDisplay; import org.bukkit.entity.Player; @@ -143,7 +143,6 @@ public final class Brazier extends CustomDecorDataImpl { final ItemDisplay itemDisplay = customDecor.getDisplay(); final ItemStack displayItem = itemDisplay.getItemStack(); - assert displayItem != null; final ItemStack typeItem = nextType.getItem(); final ItemMeta typeMeta = typeItem.getItemMeta(); diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/FireHydrant.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/FireHydrant.java similarity index 73% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/FireHydrant.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/FireHydrant.java index 273c41d2..29eda886 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/FireHydrant.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/FireHydrant.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.street; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.street; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/IronTrashcan.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/IronTrashcan.java similarity index 82% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/IronTrashcan.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/IronTrashcan.java index d82c9dfd..b60b2c8a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/IronTrashcan.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/IronTrashcan.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.street; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.street; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Material; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/Wheelbarrow.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/Wheelbarrow.java similarity index 75% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/Wheelbarrow.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/Wheelbarrow.java index e805db3a..fe98ecf7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/decoration/street/Wheelbarrow.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/decoration/street/Wheelbarrow.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.decoration.street; +package com.minersstudios.wholib.paper.custom.decor.registry.decoration.street; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/Nightstand.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/Nightstand.java similarity index 91% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/Nightstand.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/Nightstand.java index a0ba445c..979b07b0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/Nightstand.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/Nightstand.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.decor.*; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.custom.decor.*; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -17,7 +17,7 @@ public abstract class Nightstand> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final @NotNull String displayName, final @NotNull Material planksMaterial, final int @NotNull ... cmd @@ -43,7 +43,7 @@ public abstract class Nightstand> extends CustomDec .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":nightstand") + .group(Resource.WMDECOR + ":nightstand") .category(CraftingBookCategory.BUILDING) .shape( "PPP", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/Armchair.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/Armchair.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/Armchair.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/Armchair.java index fbacb711..5b074793 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/Armchair.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/Armchair.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.chair; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.decor.*; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.custom.decor.*; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -17,7 +17,7 @@ public abstract class Armchair> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final int customModelData, final @NotNull String displayName, final @NotNull Material planksMaterial @@ -43,7 +43,7 @@ public abstract class Armchair> extends CustomDecor .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":armchair") + .group(Resource.WMDECOR + ":armchair") .category(CraftingBookCategory.BUILDING) .shape( "PP ", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/BarStool.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/BarStool.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/BarStool.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/BarStool.java index 0f0b82fc..d8a8e30b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/BarStool.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/BarStool.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.chair; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/Chair.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/Chair.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/Chair.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/Chair.java index 179f6b9e..0ad18ed8 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/Chair.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/Chair.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.chair; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.decor.*; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.custom.decor.*; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -17,7 +17,7 @@ public abstract class Chair> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final int customModelData, final @NotNull String displayName, final @NotNull Material planksMaterial @@ -43,7 +43,7 @@ public abstract class Chair> extends CustomDecorDat .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":chair") + .group(Resource.WMDECOR + ":chair") .category(CraftingBookCategory.BUILDING) .shape( "P ", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/CoolArmchair.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/CoolArmchair.java similarity index 80% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/CoolArmchair.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/CoolArmchair.java index 38dcf76e..778a1798 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/CoolArmchair.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/CoolArmchair.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.chair; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/CoolChair.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/CoolChair.java similarity index 75% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/CoolChair.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/CoolChair.java index 8be35b5d..c5e3ce97 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/CoolChair.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/CoolChair.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.chair; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/PaintableRockingChair.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/PaintableRockingChair.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/PaintableRockingChair.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/PaintableRockingChair.java index ff1063ef..45688ddd 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/PaintableRockingChair.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/PaintableRockingChair.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.chair; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.decor.*; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.custom.decor.*; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -17,7 +17,7 @@ public abstract class PaintableRockingChair> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final int customModelData, final @NotNull String displayName, final @NotNull Material planksMaterial @@ -43,7 +43,7 @@ public abstract class PaintableRockingChair> extend .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":paintable_rocking_chair") + .group(Resource.WMDECOR + ":paintable_rocking_chair") .category(CraftingBookCategory.BUILDING) .shape( "P ", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/RockingChair.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/RockingChair.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/RockingChair.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/RockingChair.java index 6cb14e8f..f6d2957a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/RockingChair.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/RockingChair.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.chair; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.decor.*; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.custom.decor.*; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -17,7 +17,7 @@ public abstract class RockingChair> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final int customModelData, final @NotNull String displayName, final @NotNull Material planksMaterial @@ -43,7 +43,7 @@ public abstract class RockingChair> extends CustomD .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":rocking_chair") + .group(Resource.WMDECOR + ":rocking_chair") .category(CraftingBookCategory.BUILDING) .shape( "P ", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/SmallArmchair.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/SmallArmchair.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/SmallArmchair.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/SmallArmchair.java index 732b0d83..373574e1 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/SmallArmchair.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/SmallArmchair.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.chair; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.decor.*; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.custom.decor.*; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -17,7 +17,7 @@ public abstract class SmallArmchair> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final int customModelData, final @NotNull String displayName, final @NotNull Material planksMaterial @@ -43,7 +43,7 @@ public abstract class SmallArmchair> extends Custom .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":small_armchair") + .group(Resource.WMDECOR + ":small_armchair") .category(CraftingBookCategory.BUILDING) .shape( "LP ", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/SmallChair.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/SmallChair.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/SmallChair.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/SmallChair.java index 44427cac..0d37e831 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/chair/SmallChair.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/chair/SmallChair.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.chair; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.decor.*; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.chair; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.custom.decor.*; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -17,7 +17,7 @@ public abstract class SmallChair> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final int customModelData, final @NotNull String displayName, final @NotNull Material planksMaterial @@ -43,7 +43,7 @@ public abstract class SmallChair> extends CustomDec .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":small_chair") + .group(Resource.WMDECOR + ":small_chair") .category(CraftingBookCategory.BUILDING) .shape( "PLP", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/lamp/BigLamp.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/lamp/BigLamp.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/lamp/BigLamp.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/lamp/BigLamp.java index 7b3021fb..516eb6a6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/lamp/BigLamp.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/lamp/BigLamp.java @@ -1,12 +1,12 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.lamp; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.lamp; -import com.minersstudios.whomine.custom.decor.*; -import com.minersstudios.whomine.custom.decor.event.CustomDecorClickEvent; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.custom.decor.*; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorClickEvent; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.SoundCategory; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/lamp/SmallLamp.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/lamp/SmallLamp.java similarity index 75% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/lamp/SmallLamp.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/lamp/SmallLamp.java index a4a5984f..60eaed71 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/lamp/SmallLamp.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/lamp/SmallLamp.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.lamp; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.lamp; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.DecorParameter; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.DecorParameter; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/table/BigTable.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/table/BigTable.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/table/BigTable.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/table/BigTable.java index c4c8c9f1..7b07ac32 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/table/BigTable.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/table/BigTable.java @@ -1,16 +1,16 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.table; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.custom.decor.CustomDecorData; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.table; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorData; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -20,7 +20,7 @@ public abstract class BigTable> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final int customModelData, final @NotNull String displayName, final @NotNull Material planksMaterial @@ -46,7 +46,7 @@ public abstract class BigTable> extends CustomDecor .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":big_table") + .group(Resource.WMDECOR + ":big_table") .category(CraftingBookCategory.BUILDING) .shape( "PPP", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/table/SmallTable.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/table/SmallTable.java similarity index 86% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/table/SmallTable.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/table/SmallTable.java index 0eaa10d6..32139bdf 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/furniture/table/SmallTable.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/furniture/table/SmallTable.java @@ -1,16 +1,16 @@ -package com.minersstudios.whomine.custom.decor.registry.furniture.table; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.custom.decor.CustomDecorData; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.wholib.paper.custom.decor.registry.furniture.table; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorData; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -20,7 +20,7 @@ public abstract class SmallTable> extends CustomDecorDataImpl { protected final @NotNull Builder createBuilder( - final @Key @NotNull String key, + final @Path @NotNull String key, final int customModelData, final @NotNull String displayName, final @NotNull Material planksMaterial @@ -46,7 +46,7 @@ public abstract class SmallTable> extends CustomDec .recipes( unused -> RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .group(SharedConstants.MSDECOR_NAMESPACE + ":small_table") + .group(Resource.WMDECOR + ":small_table") .category(CraftingBookCategory.BUILDING) .shape( "PPP", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/other/Poop.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/other/Poop.java similarity index 72% rename from paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/other/Poop.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/other/Poop.java index 867f346a..e746f930 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/decor/registry/other/Poop.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/decor/registry/other/Poop.java @@ -1,10 +1,10 @@ -package com.minersstudios.whomine.custom.decor.registry.other; +package com.minersstudios.wholib.paper.custom.decor.registry.other; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.world.sound.SoundGroup; -import com.minersstudios.whomine.custom.decor.CustomDecorDataImpl; -import com.minersstudios.whomine.custom.decor.DecorHitBox; -import com.minersstudios.whomine.custom.decor.Facing; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorDataImpl; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; +import com.minersstudios.wholib.paper.custom.decor.Facing; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/CustomItem.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/CustomItem.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/CustomItem.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/CustomItem.java index eacc83a1..d110cbe6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/CustomItem.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/CustomItem.java @@ -1,8 +1,7 @@ -package com.minersstudios.whomine.custom.item; +package com.minersstudios.wholib.paper.custom.item; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.menu.CraftsMenu; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -92,7 +91,7 @@ void setRecipeEntries( /** * Initialize and retrieve a list of associated recipes for this custom item. * Boolean value in the entry represents whether the recipe should be - * registered in {@link CraftsMenu}. + * registered in {@code CraftsMenu}. * * @return A list of recipe entries representing the associated * recipes, or null if there are no recipes diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/CustomItemImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/CustomItemImpl.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/CustomItemImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/CustomItemImpl.java index 9859ae13..ebee1d5f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/CustomItemImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/CustomItemImpl.java @@ -1,10 +1,10 @@ -package com.minersstudios.whomine.custom.item; +package com.minersstudios.wholib.paper.custom.item; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.api.throwable.InvalidRegexException; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.throwable.InvalidRegexException; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; @@ -40,19 +40,19 @@ public abstract class CustomItemImpl implements CustomItem, Cloneable { * @param itemStack The {@link ItemStack} representing the custom item * @throws IllegalArgumentException If the key format is invalid or the item * stack type is air - * @see Key.Validator#matches(String) + * @see Path.Validator#matches(String) */ protected CustomItemImpl( - final @Key @NotNull String key, + final @Path @NotNull String key, final @NotNull ItemStack itemStack ) throws InvalidRegexException, IllegalArgumentException { - Key.Validator.validate(key); + Path.Validator.validate(key); if (itemStack.isEmpty()) { throw new IllegalArgumentException("Item type cannot be empty! Check " + key); } - this.namespacedKey = new NamespacedKey(SharedConstants.MSITEMS_NAMESPACE, key); + this.namespacedKey = new NamespacedKey(Resource.WMITEM, key); this.itemStack = itemStack; this.recipeEntries = new ObjectArrayList<>(); @@ -148,7 +148,7 @@ public final void registerRecipes(final @NotNull WhoMine plugin) { plugin.getServer().addRecipe(recipe); if (entry.isRegisteredInMenu()) { - plugin.getCache().customItemRecipes.add(recipe); + plugin.getCache().getCustomItemRecipes().add(recipe); } } } @@ -165,7 +165,7 @@ public final void unregisterRecipes(final @NotNull WhoMine plugin) { plugin.getServer().removeRecipe(recipe.getKey()); if (entry.isRegisteredInMenu()) { - plugin.getCache().customItemRecipes.remove(recipe); + plugin.getCache().getCustomItemRecipes().remove(recipe); } } } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/CustomItemType.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/CustomItemType.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/CustomItemType.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/CustomItemType.java index 907878fe..347b0ccd 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/CustomItemType.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/CustomItemType.java @@ -1,19 +1,20 @@ -package com.minersstudios.whomine.custom.item; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.item.damageable.Damageable; -import com.minersstudios.whomine.custom.item.registry.*; -import com.minersstudios.whomine.menu.CraftsMenu; -import com.minersstudios.whomine.custom.item.registry.hazmat.HazmatBoots; -import com.minersstudios.whomine.custom.item.registry.hazmat.HazmatChestplate; -import com.minersstudios.whomine.custom.item.registry.hazmat.HazmatHelmet; -import com.minersstudios.whomine.custom.item.registry.hazmat.HazmatLeggings; -import com.minersstudios.whomine.custom.item.registry.cards.CardsBicycle; -import com.minersstudios.whomine.custom.item.registry.cosmetics.LeatherHat; -import com.minersstudios.whomine.api.status.StatusHandler; -import com.minersstudios.whomine.api.status.StatusWatcher; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; +package com.minersstudios.wholib.paper.custom.item; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.module.MainModule; +import com.minersstudios.wholib.paper.custom.item.damageable.Damageable; +import com.minersstudios.wholib.paper.custom.item.registry.*; +import com.minersstudios.wholib.paper.custom.item.registry.cards.CardsBicycle; +import com.minersstudios.wholib.paper.custom.item.registry.cosmetics.LeatherHat; +import com.minersstudios.wholib.paper.custom.item.registry.hazmat.HazmatBoots; +import com.minersstudios.wholib.paper.custom.item.registry.hazmat.HazmatChestplate; +import com.minersstudios.wholib.paper.custom.item.registry.hazmat.HazmatHelmet; +import com.minersstudios.wholib.paper.custom.item.registry.hazmat.HazmatLeggings; +import com.minersstudios.wholib.paper.custom.item.registry.*; +import com.minersstudios.wholib.status.StatusHandler; +import com.minersstudios.wholib.status.StatusWatcher; +import com.minersstudios.wholib.utility.ChatUtils; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; @@ -57,7 +58,7 @@ public enum CustomItemType { private final Class clazz; public static final String TYPE_TAG_NAME = "type"; - public static final NamespacedKey TYPE_NAMESPACED_KEY = new NamespacedKey(SharedConstants.MSITEMS_NAMESPACE, TYPE_TAG_NAME); + public static final NamespacedKey TYPE_NAMESPACED_KEY = new NamespacedKey(Resource.WMITEM, TYPE_TAG_NAME); private static final Map KEY_TO_TYPE_MAP = new Object2ObjectOpenHashMap<>(); private static final Map, CustomItemType> CLASS_TO_TYPE_MAP = new Object2ObjectOpenHashMap<>(); @@ -94,9 +95,9 @@ public static void load(final @NotNull WhoMine plugin) throws IllegalStateExcept statusHandler.addWatcher( StatusWatcher.builder() .successStatuses( - WhoMine.LOADED_BLOCKS, - WhoMine.LOADED_DECORATIONS, - WhoMine.LOADED_ITEMS + MainModule.LOADED_BLOCKS, + MainModule.LOADED_DECORATIONS, + MainModule.LOADED_ITEMS ) .successRunnable( () -> plugin.runTask(() -> { @@ -104,16 +105,17 @@ public static void load(final @NotNull WhoMine plugin) throws IllegalStateExcept item.getCustomItem().registerRecipes(plugin); } - CraftsMenu.putCrafts( - CraftsMenu.Type.ITEMS, - plugin.getCache().customItemRecipes - ); + //TODO: fix this + //CraftsMenu.putCrafts( + // CraftsMenu.Type.ITEMS, + // plugin.getCache().customItemRecipes + //); }) ) .build() ); - statusHandler.assignStatus(WhoMine.LOADING_ITEMS); + statusHandler.assignStatus(MainModule.LOADING_ITEMS); Stream.of(types).parallel() .forEach(type -> { final CustomItem customItem; @@ -143,7 +145,7 @@ public static void load(final @NotNull WhoMine plugin) throws IllegalStateExcept }); typesWithRecipes.sort(Comparator.comparingInt(CustomItemType::ordinal)); - statusHandler.assignStatus(WhoMine.LOADED_ITEMS); + statusHandler.assignStatus(MainModule.LOADED_ITEMS); plugin.getComponentLogger().info( Component.text( "Loaded " + types.length + " custom items in " + (System.currentTimeMillis() - startTime) + "ms", diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/Wearable.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/Wearable.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/Wearable.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/Wearable.java index 659b402b..a9478a5e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/Wearable.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/Wearable.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.custom.item; +package com.minersstudios.wholib.paper.custom.item; /** * Interface for custom items that players can wear on their head. When a player diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/damageable/Damageable.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/damageable/Damageable.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/damageable/Damageable.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/damageable/Damageable.java index 412fe08e..20b9e30f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/damageable/Damageable.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/damageable/Damageable.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.custom.item.damageable; +package com.minersstudios.wholib.paper.custom.item.damageable; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/damageable/DamageableItem.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/damageable/DamageableItem.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/damageable/DamageableItem.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/damageable/DamageableItem.java index 557a23e3..64e5a92c 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/damageable/DamageableItem.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/damageable/DamageableItem.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.item.damageable; +package com.minersstudios.wholib.paper.custom.item.damageable; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.utility.ChatUtils; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TranslatableComponent; @@ -29,8 +29,8 @@ public class DamageableItem { public static final String MAX_DAMAGE_KEY = "max_damage"; public static final String REAL_DAMAGE_KEY = "real_damage"; - public static final NamespacedKey MAX_DAMAGE_NAMESPACED_KEY = new NamespacedKey(SharedConstants.MSITEMS_NAMESPACE, MAX_DAMAGE_KEY); - public static final NamespacedKey REAL_DAMAGE_NAMESPACED_KEY = new NamespacedKey(SharedConstants.MSITEMS_NAMESPACE, REAL_DAMAGE_KEY); + public static final NamespacedKey MAX_DAMAGE_NAMESPACED_KEY = new NamespacedKey(Resource.WMITEM, MAX_DAMAGE_KEY); + public static final NamespacedKey REAL_DAMAGE_NAMESPACED_KEY = new NamespacedKey(Resource.WMITEM, REAL_DAMAGE_KEY); private static final TranslatableComponent DURABILITY = translatable("item.durability"); @@ -162,9 +162,9 @@ public boolean saveForItemStack(final @NotNull ItemStack itemStack) { if (lore != null) { newLore.addAll(lore); - if (newLore.get(newLore.size() - 1) instanceof TranslatableComponent) { - newLore.remove(newLore.size() - 1); - newLore.remove(newLore.size() - 1); + if (newLore.getLast() instanceof TranslatableComponent) { + newLore.removeLast(); + newLore.removeLast(); } } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/AntiRadiationTextile.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/AntiRadiationTextile.java similarity index 75% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/AntiRadiationTextile.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/AntiRadiationTextile.java index a15cb978..e461e33d 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/AntiRadiationTextile.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/AntiRadiationTextile.java @@ -1,12 +1,12 @@ -package com.minersstudios.whomine.custom.item.registry; +package com.minersstudios.wholib.paper.custom.item.registry; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.CustomItemType; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -18,7 +18,7 @@ import java.util.List; public final class AntiRadiationTextile extends CustomItemImpl { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/BanSword.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/BanSword.java similarity index 58% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/BanSword.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/BanSword.java index 6eaeb25f..cafa94b6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/BanSword.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/BanSword.java @@ -1,22 +1,22 @@ -package com.minersstudios.whomine.custom.item.registry; +package com.minersstudios.wholib.paper.custom.item.registry; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.CustomItemImpl; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.UUID; - +@SuppressWarnings("UnstableApiUsage") public final class BanSword extends CustomItemImpl { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { @@ -34,14 +34,24 @@ public final class BanSword extends CustomItemImpl { meta.setCustomModelData(20); meta.setUnbreakable(true); meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - meta.addEnchant(Enchantment.DAMAGE_ALL, 1, true); + meta.addEnchant(Enchantment.SHARPNESS, 1, true); meta.addAttributeModifier( Attribute.GENERIC_ATTACK_DAMAGE, - new AttributeModifier(UUID.randomUUID(), "attack_damage", Double.POSITIVE_INFINITY, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND) + new AttributeModifier( + NamespacedKey.minecraft("attack_damage"), + Double.POSITIVE_INFINITY, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.HAND + ) ); meta.addAttributeModifier( Attribute.GENERIC_LUCK, - new AttributeModifier(UUID.randomUUID(), "luck", Double.POSITIVE_INFINITY, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND) + new AttributeModifier( + NamespacedKey.minecraft("luck"), + Double.POSITIVE_INFINITY, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.HAND + ) ); ITEM_STACK.setItemMeta(meta); } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/Cocaine.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/Cocaine.java similarity index 76% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/Cocaine.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/Cocaine.java index 4fea8243..adf4c6b2 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/Cocaine.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/Cocaine.java @@ -1,11 +1,11 @@ -package com.minersstudios.whomine.custom.item.registry; +package com.minersstudios.wholib.paper.custom.item.registry; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.CustomItemImpl; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -20,7 +20,7 @@ import java.util.List; public final class Cocaine extends CustomItemImpl { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { @@ -28,10 +28,10 @@ public final class Cocaine extends CustomItemImpl { ITEM_STACK = new ItemStack(Material.POTION); final PotionMeta meta = (PotionMeta) ITEM_STACK.getItemMeta(); - meta.addCustomEffect(new PotionEffect(PotionEffectType.CONFUSION, 3600, 1), true); - meta.addCustomEffect(new PotionEffect(PotionEffectType.HUNGER, 3600, 1), true); - meta.addCustomEffect(new PotionEffect(PotionEffectType.SPEED, 1200, 1), true); - meta.addCustomEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 800, 1), true); + meta.addCustomEffect(new PotionEffect(PotionEffectType.NAUSEA, 3600, 1), true); + meta.addCustomEffect(new PotionEffect(PotionEffectType.HUNGER, 3600, 1), true); + meta.addCustomEffect(new PotionEffect(PotionEffectType.SPEED, 1200, 1), true); + meta.addCustomEffect(new PotionEffect(PotionEffectType.RESISTANCE, 800, 1), true); meta.addCustomEffect(new PotionEffect(PotionEffectType.ABSORPTION, 1200, 1), true); meta.displayName(ChatUtils.createDefaultStyledText("Кокаин")); meta.setCustomModelData(10); diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/Dosimeter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/Dosimeter.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/Dosimeter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/Dosimeter.java index 6d795934..e8a1b37c 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/Dosimeter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/Dosimeter.java @@ -1,12 +1,12 @@ -package com.minersstudios.whomine.custom.item.registry; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.CustomItemType; +package com.minersstudios.wholib.paper.custom.item.registry; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -21,7 +21,7 @@ import java.util.Set; public final class Dosimeter extends CustomItemImpl { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/PlumbumIngot.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/PlumbumIngot.java similarity index 71% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/PlumbumIngot.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/PlumbumIngot.java index ee7dedf0..bcaa342a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/PlumbumIngot.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/PlumbumIngot.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.custom.item.registry; +package com.minersstudios.wholib.paper.custom.item.registry; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.utility.MSBlockUtils; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.utility.MSBlockUtils; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -23,7 +23,7 @@ import java.util.List; public final class PlumbumIngot extends CustomItemImpl { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { @@ -46,14 +46,14 @@ public PlumbumIngot() { final ItemStack input = CustomItemType.RAW_PLUMBUM.getCustomItem().getItem(); final var furnaceBuilder = RecipeBuilder.furnace() - .namespacedKey(new NamespacedKey(SharedConstants.MSITEMS_NAMESPACE, "plumbum_ingot_furnace")) + .namespacedKey(new NamespacedKey(Resource.WMITEM, "plumbum_ingot_furnace")) .result(this.itemStack) .ingredient(new RecipeChoice.ExactChoice(input)) .experience(0.7f) .cookingTime(200); final var blastingBuilder = RecipeBuilder.blasting() - .namespacedKey(new NamespacedKey(SharedConstants.MSITEMS_NAMESPACE, "plumbum_ingot_blast")) + .namespacedKey(new NamespacedKey(Resource.WMITEM, "plumbum_ingot_blast")) .result(this.itemStack) .ingredient(new RecipeChoice.ExactChoice(input)) .experience(0.7f) @@ -77,7 +77,7 @@ public PlumbumIngot() { RecipeEntry.fromBuilder(blastingBuilder), RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .namespacedKey(new NamespacedKey(SharedConstants.MSITEMS_NAMESPACE, "plumbum_ingot_from_block")) + .namespacedKey(new NamespacedKey(Resource.WMITEM, "plumbum_ingot_from_block")) .result(this.itemStack.clone().add(8)) .shape("I") .ingredients( diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/RawPlumbum.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/RawPlumbum.java similarity index 75% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/RawPlumbum.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/RawPlumbum.java index 653c3fae..b958ca06 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/RawPlumbum.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/RawPlumbum.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.item.registry; +package com.minersstudios.wholib.paper.custom.item.registry; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.utility.MSBlockUtils; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.utility.MSBlockUtils; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -22,7 +22,7 @@ import java.util.List; public final class RawPlumbum extends CustomItemImpl { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { @@ -70,7 +70,7 @@ public RawPlumbum() { RecipeEntry.fromBuilder(shapedBuilder, true), RecipeEntry.fromBuilder( RecipeBuilder.shaped() - .namespacedKey(new NamespacedKey(SharedConstants.MSITEMS_NAMESPACE, "raw_plumbum_from_block")) + .namespacedKey(new NamespacedKey(Resource.WMITEM, "raw_plumbum_from_block")) .result(this.itemStack.clone().add(8)) .shape("I") .ingredients( diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/Wrench.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/Wrench.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/Wrench.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/Wrench.java index d73fc213..7b1df79f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/Wrench.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/Wrench.java @@ -1,14 +1,14 @@ -package com.minersstudios.whomine.custom.item.registry; +package com.minersstudios.wholib.paper.custom.item.registry; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.damageable.Damageable; -import com.minersstudios.whomine.custom.item.damageable.DamageableItem; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.damageable.Damageable; +import com.minersstudios.wholib.paper.custom.item.damageable.DamageableItem; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -21,7 +21,7 @@ import java.util.List; public final class Wrench extends CustomItemImpl implements Damageable { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/cards/CardsBicycle.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/cards/CardsBicycle.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/cards/CardsBicycle.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/cards/CardsBicycle.java index ae9f5fea..02278335 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/cards/CardsBicycle.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/cards/CardsBicycle.java @@ -1,12 +1,12 @@ -package com.minersstudios.whomine.custom.item.registry.cards; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.CustomItemType; +package com.minersstudios.wholib.paper.custom.item.registry.cards; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.Material; @@ -22,7 +22,7 @@ import java.util.Collections; import java.util.List; -import static com.minersstudios.whomine.utility.ChatUtils.createDefaultStyledText; +import static com.minersstudios.wholib.utility.ChatUtils.createDefaultStyledText; import static net.kyori.adventure.text.Component.text; public interface CardsBicycle { @@ -112,20 +112,20 @@ final class Blue { public static @NotNull @Unmodifiable List cardItems() { return Collections.unmodifiableList(CARD_ITEMS); } - + private static @NotNull ItemStack createCardItem( final int customModelData, final @NotNull String name ) { return CardsBicycle.createCardItem( - customModelData, - name, + customModelData, + name, "Синяя колода карт \"Bicycle\"" ); } public static final class First extends CustomItemImpl implements CardsBicycle { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { @@ -175,7 +175,7 @@ public First() { } public static final class Second extends CustomItemImpl implements CardsBicycle { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { @@ -301,9 +301,9 @@ final class Red { "Красная колода карт \"Bicycle\"" ); } - + public static final class First extends CustomItemImpl implements CardsBicycle { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { @@ -353,7 +353,7 @@ public First() { } public static final class Second extends CustomItemImpl implements CardsBicycle { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/cosmetics/LeatherHat.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/cosmetics/LeatherHat.java similarity index 63% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/cosmetics/LeatherHat.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/cosmetics/LeatherHat.java index 467fc4e8..b51e934a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/cosmetics/LeatherHat.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/cosmetics/LeatherHat.java @@ -1,17 +1,18 @@ -package com.minersstudios.whomine.custom.item.registry.cosmetics; +package com.minersstudios.wholib.paper.custom.item.registry.cosmetics; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.Wearable; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.Wearable; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.Contract; @@ -20,10 +21,10 @@ import java.util.Collections; import java.util.List; -import java.util.UUID; +@SuppressWarnings("UnstableApiUsage") public final class LeatherHat extends CustomItemImpl implements Wearable { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; static { @@ -36,7 +37,12 @@ public final class LeatherHat extends CustomItemImpl implements Wearable { meta.lore(Collections.singletonList(Font.Components.PAINTABLE)); meta.addAttributeModifier( Attribute.GENERIC_ARMOR, - new AttributeModifier(UUID.randomUUID(), "armor", 1.0f, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HEAD) + new AttributeModifier( + NamespacedKey.minecraft("armor"), + 1.0d, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.HEAD + ) ); ITEM_STACK.setItemMeta(meta); } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatBoots.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatBoots.java similarity index 64% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatBoots.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatBoots.java index e29bd295..0e84a855 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatBoots.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatBoots.java @@ -1,19 +1,20 @@ -package com.minersstudios.whomine.custom.item.registry.hazmat; +package com.minersstudios.wholib.paper.custom.item.registry.hazmat; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.custom.item.damageable.Damageable; -import com.minersstudios.whomine.custom.item.damageable.DamageableItem; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.custom.item.damageable.Damageable; +import com.minersstudios.wholib.paper.custom.item.damageable.DamageableItem; import org.bukkit.Color; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; @@ -23,10 +24,10 @@ import java.util.Collections; import java.util.List; -import java.util.UUID; +@SuppressWarnings("UnstableApiUsage") public final class HazmatBoots extends CustomItemImpl implements Damageable { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; /** Max durability of this item */ @@ -43,11 +44,21 @@ public final class HazmatBoots extends CustomItemImpl implements Damageable { meta.addItemFlags(ItemFlag.HIDE_DYE); meta.addAttributeModifier( Attribute.GENERIC_ARMOR, - new AttributeModifier(UUID.randomUUID(), "armor", 2, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.FEET) + new AttributeModifier( + NamespacedKey.minecraft("armor"), + 2.0d, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.FEET + ) ); meta.addAttributeModifier( Attribute.GENERIC_ARMOR_TOUGHNESS, - new AttributeModifier(UUID.randomUUID(), "armor_toughness", 1, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.FEET) + new AttributeModifier( + NamespacedKey.minecraft("armor_toughness"), + 1.0d, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.FEET + ) ); ITEM_STACK.setItemMeta(meta); } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatChestplate.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatChestplate.java similarity index 67% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatChestplate.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatChestplate.java index 8e6e26f3..0491b6c5 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatChestplate.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatChestplate.java @@ -1,18 +1,19 @@ -package com.minersstudios.whomine.custom.item.registry.hazmat; +package com.minersstudios.wholib.paper.custom.item.registry.hazmat; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.custom.item.damageable.Damageable; -import com.minersstudios.whomine.custom.item.damageable.DamageableItem; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.custom.item.damageable.Damageable; +import com.minersstudios.wholib.paper.custom.item.damageable.DamageableItem; import org.bukkit.Color; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; @@ -23,8 +24,8 @@ import java.util.Collections; import java.util.List; -import java.util.UUID; +@SuppressWarnings("UnstableApiUsage") public final class HazmatChestplate extends CustomItemImpl implements Damageable { private static final @Subst("key") String KEY; private static final ItemStack ITEM_STACK; @@ -43,11 +44,21 @@ public final class HazmatChestplate extends CustomItemImpl implements Damageable meta.addItemFlags(ItemFlag.HIDE_DYE); meta.addAttributeModifier( Attribute.GENERIC_ARMOR, - new AttributeModifier(UUID.randomUUID(), "armor", 4, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.CHEST) + new AttributeModifier( + NamespacedKey.minecraft("armor"), + 4.0d, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.CHEST + ) ); meta.addAttributeModifier( Attribute.GENERIC_ARMOR_TOUGHNESS, - new AttributeModifier(UUID.randomUUID(), "armor_toughness", 1, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.CHEST) + new AttributeModifier( + NamespacedKey.minecraft("armor_toughness"), + 1.0d, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.CHEST + ) ); ITEM_STACK.setItemMeta(meta); } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatHelmet.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatHelmet.java similarity index 64% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatHelmet.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatHelmet.java index 253f561a..61d8f565 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatHelmet.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatHelmet.java @@ -1,19 +1,20 @@ -package com.minersstudios.whomine.custom.item.registry.hazmat; +package com.minersstudios.wholib.paper.custom.item.registry.hazmat; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.custom.item.damageable.Damageable; -import com.minersstudios.whomine.custom.item.damageable.DamageableItem; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.custom.item.damageable.Damageable; +import com.minersstudios.wholib.paper.custom.item.damageable.DamageableItem; import org.bukkit.Color; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; @@ -23,10 +24,10 @@ import java.util.Collections; import java.util.List; -import java.util.UUID; +@SuppressWarnings("UnstableApiUsage") public final class HazmatHelmet extends CustomItemImpl implements Damageable { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; /** Max durability of this item */ @@ -43,11 +44,21 @@ public final class HazmatHelmet extends CustomItemImpl implements Damageable { meta.addItemFlags(ItemFlag.HIDE_DYE); meta.addAttributeModifier( Attribute.GENERIC_ARMOR, - new AttributeModifier(UUID.randomUUID(), "armor", 2, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HEAD) + new AttributeModifier( + NamespacedKey.minecraft("armor"), + 2.0d, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.HEAD + ) ); meta.addAttributeModifier( Attribute.GENERIC_ARMOR_TOUGHNESS, - new AttributeModifier(UUID.randomUUID(), "armor_toughness", 1, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HEAD) + new AttributeModifier( + NamespacedKey.minecraft("armor_toughness"), + 1.0d, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.HEAD + ) ); ITEM_STACK.setItemMeta(meta); } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatLeggings.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatLeggings.java similarity index 63% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatLeggings.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatLeggings.java index 6b53ba57..3a365cca 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/registry/hazmat/HazmatLeggings.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/registry/hazmat/HazmatLeggings.java @@ -1,19 +1,20 @@ -package com.minersstudios.whomine.custom.item.registry.hazmat; +package com.minersstudios.wholib.paper.custom.item.registry.hazmat; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; -import com.minersstudios.whomine.inventory.recipe.entry.RecipeEntry; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.CustomItemImpl; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.custom.item.damageable.Damageable; -import com.minersstudios.whomine.custom.item.damageable.DamageableItem; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.entry.RecipeEntry; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemImpl; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.custom.item.damageable.Damageable; +import com.minersstudios.wholib.paper.custom.item.damageable.DamageableItem; import org.bukkit.Color; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.EquipmentSlotGroup; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; @@ -23,10 +24,10 @@ import java.util.Collections; import java.util.List; -import java.util.UUID; +@SuppressWarnings("UnstableApiUsage") public final class HazmatLeggings extends CustomItemImpl implements Damageable { - private static final @Key String KEY; + private static final @Path String KEY; private static final ItemStack ITEM_STACK; /** Max durability of this item */ @@ -43,11 +44,21 @@ public final class HazmatLeggings extends CustomItemImpl implements Damageable { meta.addItemFlags(ItemFlag.HIDE_DYE); meta.addAttributeModifier( Attribute.GENERIC_ARMOR, - new AttributeModifier(UUID.randomUUID(), "armor", 3, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.LEGS) + new AttributeModifier( + NamespacedKey.minecraft("armor"), + 3, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.LEGS + ) ); meta.addAttributeModifier( Attribute.GENERIC_ARMOR_TOUGHNESS, - new AttributeModifier(UUID.randomUUID(), "armor_toughness", 1, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.LEGS) + new AttributeModifier( + NamespacedKey.minecraft("armor_toughness"), + 1, + AttributeModifier.Operation.ADD_NUMBER, + EquipmentSlotGroup.LEGS + ) ); ITEM_STACK.setItemMeta(meta); } diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameCollection.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameCollection.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameCollection.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameCollection.java index 7fb0273f..17e6cfdc 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameCollection.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameCollection.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.item.renameable; +package com.minersstudios.wholib.paper.custom.item.renameable; import com.google.common.collect.ImmutableSet; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.utility.ChatUtils; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.bukkit.inventory.ItemStack; @@ -255,8 +255,9 @@ public boolean removeItem(final @Nullable ItemStack item) { * @see #addAllItems(Collection) */ public boolean addAll(final @NotNull RenameCollection that) { - return this.addAllRenames(that.renames) - | this.addAllItems(that.items); + final boolean addedRenames = this.addAllRenames(that.renames); + + return this.addAllItems(that.items) || addedRenames; } /** diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameEntry.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameEntry.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameEntry.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameEntry.java index 63501999..5a96823a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameEntry.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameEntry.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.custom.item.renameable; +package com.minersstudios.wholib.paper.custom.item.renameable; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.utility.ChatUtils; import org.apache.commons.lang3.StringUtils; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameableItem.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameableItem.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameableItem.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameableItem.java index 6db1d365..2e504882 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameableItem.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameableItem.java @@ -1,8 +1,8 @@ -package com.minersstudios.whomine.custom.item.renameable; +package com.minersstudios.wholib.paper.custom.item.renameable; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.api.annotation.ResourceKey; -import com.minersstudios.whomine.utility.MSCustomUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.annotation.ResourcePath; +import com.minersstudios.wholib.paper.utility.MSCustomUtils; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import net.kyori.adventure.text.Component; @@ -198,7 +198,7 @@ public RenameableItem( return null; } - for (final @ResourceKey var namespacedKey : itemString) { + for (final @ResourcePath var namespacedKey : itemString) { final ItemStack itemStack; if (namespacedKey.contains(":")) { diff --git a/paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameableItemRegistry.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameableItemRegistry.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameableItemRegistry.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameableItemRegistry.java index f10d93e3..4ba51139 100644 --- a/paper/src/main/java/com/minersstudios/whomine/custom/item/renameable/RenameableItemRegistry.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/custom/item/renameable/RenameableItemRegistry.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.custom.item.renameable; +package com.minersstudios.wholib.paper.custom.item.renameable; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.utility.ChatUtils; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -51,7 +51,7 @@ */ public final class RenameableItemRegistry { public static final String RENAMEABLE_KEY = "renameable"; - public static final NamespacedKey RENAMEABLE_NAMESPACED_KEY = new NamespacedKey(SharedConstants.MSITEMS_NAMESPACE, RENAMEABLE_KEY); + public static final NamespacedKey RENAMEABLE_NAMESPACED_KEY = new NamespacedKey(Resource.WMITEM, RENAMEABLE_KEY); private static final Map KEY_MAP = new Object2ObjectOpenHashMap<>(); private static final Map RENAME_ENTRY_MAP = new Object2ObjectOpenHashMap<>(); diff --git a/paper/src/main/java/com/minersstudios/whomine/discord/Attempt.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/Attempt.java similarity index 84% rename from paper/src/main/java/com/minersstudios/whomine/discord/Attempt.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/Attempt.java index 5cfd5bfa..37089632 100644 --- a/paper/src/main/java/com/minersstudios/whomine/discord/Attempt.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/Attempt.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.discord; +package com.minersstudios.wholib.paper.discord; import org.jetbrains.annotations.Range; diff --git a/paper/src/main/java/com/minersstudios/whomine/discord/BotHandler.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/BotHandler.java similarity index 83% rename from paper/src/main/java/com/minersstudios/whomine/discord/BotHandler.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/BotHandler.java index 7aabc4dd..94db5d11 100644 --- a/paper/src/main/java/com/minersstudios/whomine/discord/BotHandler.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/BotHandler.java @@ -1,13 +1,12 @@ -package com.minersstudios.whomine.discord; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.command.impl.discord.EditSkinCommand; -import com.minersstudios.whomine.command.impl.discord.RemoveSkinCommand; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.skin.Skin; +package com.minersstudios.wholib.paper.discord; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.skin.Skin; +import com.minersstudios.wholib.utility.ChatUtils; import net.dv8tion.jda.api.entities.EmbedType; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -16,12 +15,13 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; import java.util.Locale; import java.util.regex.Pattern; -import static com.minersstudios.whomine.locale.Translations.*; -import static com.minersstudios.whomine.utility.ChatUtils.serializePlainComponent; +import static com.minersstudios.wholib.locale.Translations.*; +import static com.minersstudios.wholib.utility.ChatUtils.serializePlainComponent; import static net.kyori.adventure.text.Component.text; public final class BotHandler { @@ -93,7 +93,7 @@ public void handleMessage(final @NotNull Message message) { final int attachmentSize = attachments.size(); short code = 0; - if (!this.plugin.getDiscordManager().isVerified(this.user)) { + if (!this.plugin.getDiscordModule().isVerified(this.user)) { this.reply(DISCORD_NOT_A_USER.asString()); return; @@ -157,7 +157,7 @@ public void handleMessage(final @NotNull Message message) { return; } else if (attachmentSize == 1) { - final Message.Attachment attachment = attachments.get(0); + final Message.Attachment attachment = attachments.getFirst(); final String link = attachment.getUrl(); try { @@ -471,7 +471,7 @@ private void handleSkinTask(final @NotNull Skin skin) { switch (actionIndex) { case 1 -> this.plugin.runTask(() -> this.handleEditImageTask(skin)); case 2 -> this.plugin.runTask(() -> this.handleEditNameTask(skin)); - case 3 -> this.plugin.runTask(() -> RemoveSkinCommand.remove(playerInfo, skin, message, null)); + case 3 -> this.plugin.runTask(() -> removeSkin(this.playerInfo, skin, message)); default -> { this.reply(DISCORD_SKIN_INVALID_INDEX.asString()); @@ -503,16 +503,15 @@ private void handleEditImageTask(final @NotNull Skin editableSkin) { final Skin skin = Skin.create( this.plugin, skinName, - attachments.get(0).getUrl() + attachments.getFirst().getUrl() ); return skin != null - && EditSkinCommand.edit( + && editSkin( this.playerInfo, playerFile.getSkinIndex(editableSkin), skin, - this.message, - null + this.message ); } catch (final Throwable ignored) { this.reply(DISCORD_SKIN_INVALID_IMG.asString()); @@ -642,4 +641,86 @@ private boolean editSkin( null ); } + + private static void removeSkin( + final @NotNull PlayerInfo playerInfo, + final @NotNull Skin skin, + final @Nullable Message messageForReply + ) { + final boolean isDeleted = playerInfo.getPlayerFile().removeSkin(skin); + + if (!isDeleted) { + return; + } + + final String skinName = skin.getName(); + final Player player = playerInfo.getOnlinePlayer(); + final MessageEmbed embed = + BotHandler.craftEmbed( + ChatUtils.serializePlainComponent( + DISCORD_SKIN_SUCCESSFULLY_REMOVED + .asComponent( + text(skinName), + playerInfo.getDefaultName(), + text(playerInfo.getNickname()) + ) + ) + ); + + if (player != null) { + MSLogger.fine( + player, + DISCORD_SKIN_SUCCESSFULLY_REMOVED_MINECRAFT.asTranslatable() + .arguments(text(skinName)) + ); + } + + if (messageForReply != null) { + messageForReply.replyEmbeds(embed).queue(); + } else { + playerInfo.sendPrivateDiscordMessage(embed); + } + } + + public static boolean editSkin( + final @NotNull PlayerInfo playerInfo, + final @Range(from = 0, to = Integer.MAX_VALUE) int currentSkinIndex, + final @NotNull Skin newSkin, + final @Nullable Message messageForReply + ) { + final boolean isEdited = playerInfo.getPlayerFile().setSkin(currentSkinIndex, newSkin); + + if (!isEdited) { + return false; + } + + final String skinName = newSkin.getName(); + final Player player = playerInfo.getOnlinePlayer(); + final MessageEmbed embed = + BotHandler.craftEmbed( + ChatUtils.serializePlainComponent( + DISCORD_SKIN_SUCCESSFULLY_EDITED + .asComponent( + text(skinName), + playerInfo.getDefaultName(), + text(playerInfo.getNickname()) + ) + ) + ); + + if (player != null) { + MSLogger.fine( + player, + DISCORD_SKIN_SUCCESSFULLY_EDITED_MINECRAFT.asTranslatable().arguments(text(skinName)) + ); + } + + if (messageForReply != null) { + messageForReply.replyEmbeds(embed).queue(); + } else { + playerInfo.sendPrivateDiscordMessage(embed); + } + + return true; + } } diff --git a/paper/src/main/java/com/minersstudios/whomine/discord/DiscordManager.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/DiscordManager.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/discord/DiscordManager.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/DiscordManager.java index 5348b671..df03d5b3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/discord/DiscordManager.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/DiscordManager.java @@ -1,10 +1,12 @@ -package com.minersstudios.whomine.discord; - -import com.minersstudios.whomine.Config; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.chat.ChatType; -import com.minersstudios.whomine.api.status.StatusHandler; -import com.minersstudios.whomine.utility.ChatUtils; +package com.minersstudios.wholib.paper.discord; + +import com.minersstudios.wholib.paper.PaperConfig; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.discord.DiscordModule; +import com.minersstudios.wholib.module.MainModule; +import com.minersstudios.wholib.paper.chat.ChatType; +import com.minersstudios.wholib.status.StatusHandler; +import com.minersstudios.wholib.utility.ChatUtils; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.OnlineStatus; @@ -22,8 +24,8 @@ import java.util.logging.Level; import java.util.logging.Logger; -import static com.minersstudios.whomine.locale.Translations.DISCORD_BOT_STATUS; -import static com.minersstudios.whomine.locale.Translations.DISCORD_SERVER_ENABLED; +import static com.minersstudios.wholib.locale.Translations.DISCORD_BOT_STATUS; +import static com.minersstudios.wholib.locale.Translations.DISCORD_SERVER_ENABLED; /** * This class handles the Discord integration for the MSEssentials plugin. It @@ -32,7 +34,7 @@ * * @see JDA Wiki */ -public final class DiscordManager { +public final class DiscordManager implements DiscordModule { private final WhoMine plugin; private JDA jda; private Guild mainGuild; @@ -250,12 +252,12 @@ public void sendMessage( } switch (chatType) { - case GLOBAL -> { + case ChatType.GLOBAL -> { if (this.globalChannel != null) { this.globalChannel.sendMessage(message).queue(); } } - case LOCAL -> { + case ChatType.LOCAL -> { if (this.localChannel != null) { this.localChannel.sendMessage(message).queue(); } @@ -317,12 +319,12 @@ public void sendEmbeds( } switch (chatType) { - case GLOBAL -> { + case ChatType.GLOBAL -> { if (this.globalChannel != null) { this.globalChannel.sendMessageEmbeds(first, rest).queue(); } } - case LOCAL -> { + case ChatType.LOCAL -> { if (this.localChannel != null) { this.localChannel.sendMessageEmbeds(first, rest).queue(); } @@ -423,13 +425,13 @@ public void load() throws IllegalStateException { } final Logger logger = this.plugin.getLogger(); - final Config config = this.plugin.getConfiguration(); + final PaperConfig config = this.plugin.getConfiguration(); final StatusHandler statusHandler = this.plugin.getStatusHandler(); final String botToken = config.getYaml().getString("discord.bot-token"); this.plugin.runTaskAsync(() -> { try { - statusHandler.assignStatus(WhoMine.LOADING_DISCORD); + statusHandler.assignStatus(MainModule.LOADING_DISCORD); this.jda = this.buildJda(botToken); } catch (final Throwable e) { @@ -442,7 +444,7 @@ public void load() throws IllegalStateException { if (this.jda == null) { logger.warning("Discord bot not found!"); - statusHandler.assignStatus(WhoMine.FAILED_LOAD_DISCORD); + statusHandler.assignStatus(MainModule.FAILED_LOAD_DISCORD); return; } @@ -451,7 +453,7 @@ public void load() throws IllegalStateException { if (this.mainGuild == null) { logger.warning("Discord server not found!"); - statusHandler.assignStatus(WhoMine.FAILED_LOAD_DISCORD); + statusHandler.assignStatus(MainModule.FAILED_LOAD_DISCORD); this.unload(); return; @@ -497,7 +499,7 @@ public void load() throws IllegalStateException { ) ); - statusHandler.assignStatus(WhoMine.LOADED_DISCORD); + statusHandler.assignStatus(MainModule.LOADED_DISCORD); this.sendMessage(ChatType.GLOBAL, DISCORD_SERVER_ENABLED.asString()); this.sendMessage(ChatType.LOCAL, DISCORD_SERVER_ENABLED.asString()); @@ -537,4 +539,9 @@ public void onShutdown(final @NotNull ShutdownEvent event) { .build() .awaitReady(); } + + @Override + public @NotNull StatusHandler getStatusHandler() { + return null; + } } diff --git a/paper/src/main/java/com/minersstudios/whomine/discord/DiscordMap.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/DiscordMap.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/discord/DiscordMap.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/DiscordMap.java index 3dc87b83..3f570df0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/discord/DiscordMap.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/DiscordMap.java @@ -1,10 +1,10 @@ -package com.minersstudios.whomine.discord; +package com.minersstudios.wholib.paper.discord; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.player.PlayerInfo; import org.bukkit.entity.Player; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -396,6 +396,7 @@ public int hashCode() { * @param obj {@link Params} to compare * @return True if uuid and nickname are equals */ + @Contract("null -> false") @Override public boolean equals(final @Nullable Object obj) { return this == obj diff --git a/paper/src/main/java/com/minersstudios/whomine/discord/WaitingReplyTask.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/WaitingReplyTask.java similarity index 84% rename from paper/src/main/java/com/minersstudios/whomine/discord/WaitingReplyTask.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/WaitingReplyTask.java index 257ca0de..6afb7c5c 100644 --- a/paper/src/main/java/com/minersstudios/whomine/discord/WaitingReplyTask.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/discord/WaitingReplyTask.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.discord; +package com.minersstudios.wholib.paper.discord; @FunctionalInterface public interface WaitingReplyTask { diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/event/PaperEventContainer.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/event/PaperEventContainer.java new file mode 100644 index 00000000..fccee517 --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/event/PaperEventContainer.java @@ -0,0 +1,51 @@ +package com.minersstudios.wholib.paper.event; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.CancellableEventContainer; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.jetbrains.annotations.NotNull; + +/** + * Represents a paper event container. + *

        + * It contains : + *

          + *
        • The main module that registers and handles the event
        • + *
        • The event itself
        • + *
        + * + * @param The event type + * + * @see PaperEventListener + */ +@SuppressWarnings("unused") +public class PaperEventContainer extends CancellableEventContainer { + + private PaperEventContainer( + final @NotNull WhoMine module, + final @NotNull E event + ) { + super(module, event); + } + + @Override + public boolean isCancelled() { + return this.getEvent() instanceof final Cancellable cancellable + && cancellable.isCancelled(); + } + + /** + * Creates a new paper event container with the given module and event + * + * @param module The main module that registers and handles the event + * @param event The event associated with this container + * @return A new container instance + */ + public static @NotNull PaperEventContainer of( + final @NotNull WhoMine module, + final @NotNull E event + ) { + return new PaperEventContainer<>(module, event); + } +} diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/event/PaperEventListener.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/event/PaperEventListener.java new file mode 100644 index 00000000..b32b82e6 --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/event/PaperEventListener.java @@ -0,0 +1,75 @@ +package com.minersstudios.wholib.paper.event; + +import com.minersstudios.wholib.event.handle.HandlerExecutor; +import com.minersstudios.wholib.event.EventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.event.handle.CancellableHandlerParams; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.throwable.ListenerException; +import com.minersstudios.wholib.paper.listener.PaperListenerManager; +import org.bukkit.event.Event; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.NotNull; + +/** + * An abstract class that represents a paper event listener. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
        Available optional overridable methods
        MethodDescription
        {@link #onRegister()} + * Called when the listener is registered by a manager in the + * {@link PaperListenerManager#register(com.minersstudios.wholib.listener.Listener)} method + *
        {@link #onUnregister()} + * Called when the listener is unregistered by a manager in the + * {@link PaperListenerManager#unregister(com.minersstudios.wholib.listener.Listener)} method + *
        + * + * @see PaperEventContainer + * @see HandlerExecutor + */ +@SuppressWarnings("unused") +public abstract class PaperEventListener + extends EventListener, PaperEventContainer> + implements Listener { + + /** + * Constructs a new event listener. + *

        + * This constructor will automatically retrieve all event handlers from the + * listener class and event class from the {@link ListenFor} annotation. + * + * @throws ClassCastException If the event class is not a subclass of + * annotated event class + * @throws ListenerException If the listener has duplicate event handlers + * for the same order, or if the listener does + * not have a {@link ListenFor} annotation + */ + protected PaperEventListener() throws ClassCastException, ListenerException { + super(CancellableHandler.class, CancellableHandlerParams::of); + } + + /** + * Constructs a new event listener with the specified event class. + *

        + * This constructor will automatically retrieve all event handlers from the + * listener class. + * + * @param key The key of the event listener + * @throws ListenerException If the listener has duplicate event handlers + * for the same order + */ + protected PaperEventListener(final @NotNull Class key) throws ListenerException { + super(key, CancellableHandler.class, CancellableHandlerParams::of); + } +} diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/gui/PaperGuiManager.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/gui/PaperGuiManager.java new file mode 100644 index 00000000..6e178756 --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/gui/PaperGuiManager.java @@ -0,0 +1,46 @@ +package com.minersstudios.wholib.paper.gui; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.gui.GuiManager; +import com.minersstudios.wholib.paper.inventory.holder.AbstractInventoryHolder; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.UnmodifiableView; + +import java.util.Collections; +import java.util.Map; +import java.util.Optional; + +public class PaperGuiManager extends GuiManager { + + private final Map inventoryHolderMap; + + public PaperGuiManager(final @NotNull WhoMine module) { + super(module); + + this.inventoryHolderMap = new Object2ObjectOpenHashMap<>(); + } + + public @NotNull @UnmodifiableView Map getInventoryHolderMap() { + return Collections.unmodifiableMap(this.inventoryHolderMap); + } + + public @NotNull Optional getInventoryHolder(final @NotNull String id) { + return Optional.ofNullable(this.inventoryHolderMap.get(id)); + } + + public void open( + final @NotNull String id, + final @NotNull Player player + ) { + this.getInventoryHolder(id) + .ifPresent( + holder -> holder.open(player) + ); + } + + public void register(final @NotNull AbstractInventoryHolder holder) { + this.inventoryHolderMap.put(holder.getId(), holder); + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/CustomInventory.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/CustomInventory.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/inventory/CustomInventory.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/CustomInventory.java index 46561b30..b046358d 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/CustomInventory.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/CustomInventory.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; -import com.minersstudios.whomine.inventory.action.InventoryAction; +import com.minersstudios.wholib.paper.inventory.action.InventoryAction; import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/CustomInventoryImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/CustomInventoryImpl.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/inventory/CustomInventoryImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/CustomInventoryImpl.java index 0545edbe..4abbe3bf 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/CustomInventoryImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/CustomInventoryImpl.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; -import com.minersstudios.whomine.inventory.action.InventoryAction; +import com.minersstudios.wholib.paper.inventory.action.InventoryAction; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; import net.minecraft.world.Container; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryCustom; +import org.bukkit.craftbukkit.inventory.CraftInventory; +import org.bukkit.craftbukkit.inventory.CraftInventoryCustom; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/ElementPagedInventory.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/ElementPagedInventory.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/inventory/ElementPagedInventory.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/ElementPagedInventory.java index 57367dbd..b44b73dc 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/ElementPagedInventory.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/ElementPagedInventory.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/ElementSingleInventory.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/ElementSingleInventory.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/inventory/ElementSingleInventory.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/ElementSingleInventory.java index d6cb9cd5..ebcf4375 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/ElementSingleInventory.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/ElementSingleInventory.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/InventoryButton.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/InventoryButton.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/inventory/InventoryButton.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/InventoryButton.java index c821be41..40af4ab4 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/InventoryButton.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/InventoryButton.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; -import com.minersstudios.whomine.inventory.action.ButtonClickAction; +import com.minersstudios.wholib.paper.inventory.action.ButtonClickAction; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.SoundCategory; @@ -129,7 +129,7 @@ public void doClickAction( clone.item = this.item.clone(); return clone; } catch (final CloneNotSupportedException e) { - throw new AssertionError("An error occurred while cloning '" + this + "'", e); + throw new AssertionError("An error occurred while cloning button", e); } } } diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/PagedCustomInventory.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/PagedCustomInventory.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/inventory/PagedCustomInventory.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/PagedCustomInventory.java index 1014cf84..39374f22 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/PagedCustomInventory.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/PagedCustomInventory.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/PagedCustomInventoryImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/PagedCustomInventoryImpl.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/inventory/PagedCustomInventoryImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/PagedCustomInventoryImpl.java index 80f99ae0..6257e155 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/PagedCustomInventoryImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/PagedCustomInventoryImpl.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/PagedInventory.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/PagedInventory.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/inventory/PagedInventory.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/PagedInventory.java index 62cfce30..676a76ea 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/PagedInventory.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/PagedInventory.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/ShulkerBoxMenu.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/ShulkerBoxMenu.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/inventory/ShulkerBoxMenu.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/ShulkerBoxMenu.java index f97dd0cc..6dafe074 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/ShulkerBoxMenu.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/ShulkerBoxMenu.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; import net.minecraft.world.Container; import net.minecraft.world.entity.player.Inventory; @@ -8,13 +8,14 @@ import net.minecraft.world.inventory.ShulkerBoxSlot; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventory; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryView; +import org.bukkit.craftbukkit.inventory.CraftInventory; +import org.bukkit.craftbukkit.inventory.CraftInventoryView; +import org.bukkit.inventory.InventoryView; import org.jetbrains.annotations.NotNull; public final class ShulkerBoxMenu extends AbstractContainerMenu { private final Container container; - private CraftInventoryView bukkitEntity; + private InventoryView bukkitEntity; private final Inventory playerInventory; private static final int CONTAINER_SIZE = 27; @@ -51,9 +52,9 @@ public ShulkerBoxMenu( } @Override - public @NotNull CraftInventoryView getBukkitView() { + public @NotNull InventoryView getBukkitView() { return this.bukkitEntity == null - ? this.bukkitEntity = new CraftInventoryView( + ? this.bukkitEntity = new CraftInventoryView<>( this.playerInventory.player.getBukkitEntity(), new CraftInventory(this.container), this diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/SignMenu.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/SignMenu.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/inventory/SignMenu.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/SignMenu.java index f39aaf20..7a57ff98 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/SignMenu.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/SignMenu.java @@ -1,7 +1,6 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; -import com.minersstudios.whomine.listener.impl.packet.player.PlayerUpdateSignListener; -import com.minersstudios.whomine.utility.LocationUtils; +import com.minersstudios.wholib.paper.utility.LocationUtils; import io.papermc.paper.adventure.AdventureComponent; import net.kyori.adventure.text.Component; import net.minecraft.core.BlockPos; @@ -13,7 +12,7 @@ import net.minecraft.world.level.block.entity.SignBlockEntity; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -77,7 +76,6 @@ public SignMenu( * Uses the packet listener to get the sign text * * @return The response of the sign - * @see PlayerUpdateSignListener */ public @NotNull BiPredicate getResponse() { return this.response; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/SingleInventory.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/SingleInventory.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/inventory/SingleInventory.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/SingleInventory.java index cc0b30c2..57392687 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/SingleInventory.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/SingleInventory.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/StaticInventoryButton.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/StaticInventoryButton.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/inventory/StaticInventoryButton.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/StaticInventoryButton.java index 591fe020..2d098fd3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/StaticInventoryButton.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/StaticInventoryButton.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory; +package com.minersstudios.wholib.paper.inventory; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/action/ButtonClickAction.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/action/ButtonClickAction.java similarity index 82% rename from paper/src/main/java/com/minersstudios/whomine/inventory/action/ButtonClickAction.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/action/ButtonClickAction.java index ade2e224..9fdfd20d 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/action/ButtonClickAction.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/action/ButtonClickAction.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.inventory.action; +package com.minersstudios.wholib.paper.inventory.action; -import com.minersstudios.whomine.inventory.CustomInventory; +import com.minersstudios.wholib.paper.inventory.CustomInventory; import org.bukkit.event.inventory.InventoryClickEvent; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/action/InventoryAction.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/action/InventoryAction.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/inventory/action/InventoryAction.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/action/InventoryAction.java index e07bbd5a..fdd4fab5 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/action/InventoryAction.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/action/InventoryAction.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.inventory.action; +package com.minersstudios.wholib.paper.inventory.action; -import com.minersstudios.whomine.inventory.CustomInventory; +import com.minersstudios.wholib.paper.inventory.CustomInventory; import org.bukkit.event.Event; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/holder/AbstractInventoryHolder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/holder/AbstractInventoryHolder.java similarity index 79% rename from paper/src/main/java/com/minersstudios/whomine/inventory/holder/AbstractInventoryHolder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/holder/AbstractInventoryHolder.java index e0d7db7a..1c756492 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/holder/AbstractInventoryHolder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/holder/AbstractInventoryHolder.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.inventory.holder; +package com.minersstudios.wholib.paper.inventory.holder; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.CustomInventory; import org.bukkit.entity.Player; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -15,9 +15,27 @@ * @see InventoryHolder */ public abstract class AbstractInventoryHolder { + + private final String id; private CustomInventory customInventory; private WhoMine plugin; + /** + * Creates a new abstract inventory holder with the given id + * + * @param id The id of this inventory holder + */ + public AbstractInventoryHolder(final @NotNull String id) { + this.id = id; + } + + /** + * @return The id of this inventory holder + */ + public final @NotNull String getId() { + return this.id; + } + /** * @return The custom inventory, that this custom inventory is registered to */ @@ -58,6 +76,8 @@ public final void register(final @NotNull WhoMine plugin) throws IllegalStateExc this.plugin = plugin; this.customInventory = this.createCustomInventory(); + + plugin.getGuiManager().register(this); } /** diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/holder/InventoryHolder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/holder/InventoryHolder.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/inventory/holder/InventoryHolder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/holder/InventoryHolder.java index 2f2ce746..bc13c22f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/holder/InventoryHolder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/holder/InventoryHolder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.holder; +package com.minersstudios.wholib.paper.inventory.holder; import java.lang.annotation.*; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/BlastingRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/BlastingRecipeBuilder.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/BlastingRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/BlastingRecipeBuilder.java index 969cd1e8..20d2bcba 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/BlastingRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/BlastingRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.inventory.BlastingRecipe; import org.jetbrains.annotations.ApiStatus; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CampfireRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CampfireRecipeBuilder.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CampfireRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CampfireRecipeBuilder.java index 89481c08..fb465b73 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CampfireRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CampfireRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.inventory.CampfireRecipe; import org.jetbrains.annotations.ApiStatus; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CategorizedRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CategorizedRecipeBuilder.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CategorizedRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CategorizedRecipeBuilder.java index 067d6709..7a3181f7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CategorizedRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CategorizedRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.inventory.Recipe; import org.jetbrains.annotations.Contract; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CookingRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CookingRecipeBuilder.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CookingRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CookingRecipeBuilder.java index 6abcd014..714f25c3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CookingRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CookingRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.Material; import org.bukkit.inventory.*; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CookingRecipeBuilderImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CookingRecipeBuilderImpl.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CookingRecipeBuilderImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CookingRecipeBuilderImpl.java index 6f35072d..30ccd4d6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CookingRecipeBuilderImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CookingRecipeBuilderImpl.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.Material; import org.bukkit.NamespacedKey; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CraftingRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CraftingRecipeBuilder.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CraftingRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CraftingRecipeBuilder.java index 117ea671..a99d0c57 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CraftingRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CraftingRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.inventory.CraftingRecipe; import org.bukkit.inventory.ShapedRecipe; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CraftingRecipeBuilderImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CraftingRecipeBuilderImpl.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CraftingRecipeBuilderImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CraftingRecipeBuilderImpl.java index b9f47f18..c2b59195 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/CraftingRecipeBuilderImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/CraftingRecipeBuilderImpl.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.NamespacedKey; import org.bukkit.inventory.CraftingRecipe; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/FurnaceRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/FurnaceRecipeBuilder.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/FurnaceRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/FurnaceRecipeBuilder.java index 49fc1b0d..be75ebf4 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/FurnaceRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/FurnaceRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.inventory.FurnaceRecipe; import org.jetbrains.annotations.ApiStatus; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/GroupedRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/GroupedRecipeBuilder.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/GroupedRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/GroupedRecipeBuilder.java index cf8a35f0..12ccb940 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/GroupedRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/GroupedRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.inventory.Recipe; import org.jetbrains.annotations.Contract; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/RecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/RecipeBuilder.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/RecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/RecipeBuilder.java index e13dc6a6..9cce7b5b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/RecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/RecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.NamespacedKey; import org.bukkit.inventory.*; @@ -279,26 +279,17 @@ public interface RecipeBuilder { */ @Contract("_-> new") static @NotNull RecipeBuilder unknown(final @NotNull Recipe recipe) throws UnsupportedOperationException { - if (recipe instanceof final ShapedRecipe shaped) { - return shaped(shaped); - } else if (recipe instanceof final ShapelessRecipe shapeless) { - return shapeless(shapeless); - } else if (recipe instanceof final FurnaceRecipe furnace) { - return furnace(furnace); - } else if (recipe instanceof final SmokingRecipe smoking) { - return smoking(smoking); - } else if (recipe instanceof final BlastingRecipe blasting) { - return blasting(blasting); - } else if (recipe instanceof final CampfireRecipe campfire) { - return campfire(campfire); - } else if (recipe instanceof final StonecuttingRecipe stonecutting) { - return stonecutting(stonecutting); - } else if (recipe instanceof final SmithingTransformRecipe smithingTransform) { - return smithingTransform(smithingTransform); - } else if (recipe instanceof final SmithingTrimRecipe smithingTrim) { - return smithingTrim(smithingTrim); - } else { - throw new UnsupportedOperationException("Unknown recipe type: " + recipe.getClass().getName()); - } + return switch (recipe) { + case final ShapedRecipe shaped -> shaped(shaped); + case final ShapelessRecipe shapeless -> shapeless(shapeless); + case final FurnaceRecipe furnace -> furnace(furnace); + case final SmokingRecipe smoking -> smoking(smoking); + case final BlastingRecipe blasting -> blasting(blasting); + case final CampfireRecipe campfire -> campfire(campfire); + case final StonecuttingRecipe stonecutting -> stonecutting(stonecutting); + case final SmithingTransformRecipe smithingTransform -> smithingTransform(smithingTransform); + case final SmithingTrimRecipe smithingTrim -> smithingTrim(smithingTrim); + default -> throw new UnsupportedOperationException("Unknown recipe type: " + recipe.getClass().getName()); + }; } } diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/ShapedRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/ShapedRecipeBuilder.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/ShapedRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/ShapedRecipeBuilder.java index 239b9447..024b264e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/ShapedRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/ShapedRecipeBuilder.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; -import com.minersstudios.whomine.inventory.recipe.choice.RecipeChoiceEntry; +import com.minersstudios.wholib.paper.inventory.recipe.choice.RecipeChoiceEntry; import it.unimi.dsi.fastutil.chars.Char2ObjectMap; import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap; import org.bukkit.inventory.RecipeChoice; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/ShapelessRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/ShapelessRecipeBuilder.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/ShapelessRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/ShapelessRecipeBuilder.java index c4adf310..2a8095c0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/ShapelessRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/ShapelessRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingRecipeBuilder.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingRecipeBuilder.java index caf88cf1..d9327e3b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.Material; import org.bukkit.inventory.*; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingRecipeBuilderImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingRecipeBuilderImpl.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingRecipeBuilderImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingRecipeBuilderImpl.java index f4ce9d2c..4be0cb13 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingRecipeBuilderImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingRecipeBuilderImpl.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.Material; import org.bukkit.NamespacedKey; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingTransformRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingTransformRecipeBuilder.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingTransformRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingTransformRecipeBuilder.java index d6430cdc..6072aa3b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingTransformRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingTransformRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.inventory.SmithingTransformRecipe; import org.jetbrains.annotations.ApiStatus; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingTrimRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingTrimRecipeBuilder.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingTrimRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingTrimRecipeBuilder.java index e069c00d..7117abde 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmithingTrimRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmithingTrimRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.inventory.SmithingTrimRecipe; import org.jetbrains.annotations.ApiStatus; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmokingRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmokingRecipeBuilder.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmokingRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmokingRecipeBuilder.java index cfcfcd68..45f01096 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/SmokingRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/SmokingRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.inventory.SmokingRecipe; import org.jetbrains.annotations.ApiStatus; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/StonecuttingRecipeBuilder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/StonecuttingRecipeBuilder.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/StonecuttingRecipeBuilder.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/StonecuttingRecipeBuilder.java index 2e0e1cc2..12a49933 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/builder/StonecuttingRecipeBuilder.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/builder/StonecuttingRecipeBuilder.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.builder; +package com.minersstudios.wholib.paper.inventory.recipe.builder; import org.bukkit.Material; import org.bukkit.NamespacedKey; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/choice/CustomChoice.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/choice/CustomChoice.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/choice/CustomChoice.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/choice/CustomChoice.java index bf036fc8..766e046a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/choice/CustomChoice.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/choice/CustomChoice.java @@ -1,10 +1,10 @@ -package com.minersstudios.whomine.inventory.recipe.choice; +package com.minersstudios.wholib.paper.inventory.recipe.choice; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.minersstudios.whomine.api.annotation.ResourceKey; -import com.minersstudios.whomine.api.throwable.InvalidRegexException; -import com.minersstudios.whomine.utility.MSCustomUtils; +import com.minersstudios.wholib.annotation.ResourcePath; +import com.minersstudios.wholib.throwable.InvalidRegexException; +import com.minersstudios.wholib.paper.utility.MSCustomUtils; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -39,7 +39,7 @@ public final class CustomChoice implements RecipeChoice { * @param namespacedKey The namespaced key to use for the choice * @throws InvalidRegexException If the namespaced key is invalid */ - public CustomChoice(final @ResourceKey @NotNull String namespacedKey) throws InvalidRegexException { + public CustomChoice(final @ResourcePath @NotNull String namespacedKey) throws InvalidRegexException { this(Collections.singletonList(namespacedKey)); } @@ -51,7 +51,7 @@ public CustomChoice(final @ResourceKey @NotNull String namespacedKey) throws Inv * @throws InvalidRegexException If any of the namespaced keys are invalid */ public CustomChoice( - final @ResourceKey @NotNull String first, + final @ResourcePath @NotNull String first, final String @NotNull ... rest ) throws InvalidRegexException { this(Lists.asList(first, rest)); @@ -72,8 +72,8 @@ public CustomChoice(final @NotNull Collection namespacedKeys) throws Ill this.choiceMap = new Object2ObjectOpenHashMap<>(namespacedKeys.size()); - for (final @ResourceKey var namespacedKey : namespacedKeys) { - ResourceKey.Validator.validate(namespacedKey); + for (final @ResourcePath var namespacedKey : namespacedKeys) { + ResourcePath.Validator.validate(namespacedKey); MSCustomUtils.getItemStack(namespacedKey) .ifPresent(itemStack -> this.choiceMap.put(namespacedKey, itemStack)); } @@ -98,7 +98,7 @@ public CustomChoice(final @NotNull Collection namespacedKeys) throws Ill * @param namespacedKey The namespaced key to get the item stack for * @return A clone of the item stack for the specified namespaced key */ - public @NotNull ItemStack getItemStack(final @ResourceKey @NotNull String namespacedKey) { + public @NotNull ItemStack getItemStack(final @ResourcePath @NotNull String namespacedKey) { return this.choiceMap.get(namespacedKey).clone(); } @@ -166,7 +166,7 @@ public boolean equals(final @Nullable Object obj) { * @param namespacedKey The namespaced key to test * @return True if the namespaced key is present in the choices */ - public boolean test(final @ResourceKey @NotNull String namespacedKey) { + public boolean test(final @ResourcePath @NotNull String namespacedKey) { return this.choiceMap.containsKey(namespacedKey); } diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/choice/RecipeChoiceEntry.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/choice/RecipeChoiceEntry.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/choice/RecipeChoiceEntry.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/choice/RecipeChoiceEntry.java index 94828dcb..0bd95694 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/choice/RecipeChoiceEntry.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/choice/RecipeChoiceEntry.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.choice; +package com.minersstudios.wholib.paper.inventory.recipe.choice; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/BuilderRecipeEntry.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/BuilderRecipeEntry.java similarity index 86% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/BuilderRecipeEntry.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/BuilderRecipeEntry.java index cf3c714a..424f71b0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/BuilderRecipeEntry.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/BuilderRecipeEntry.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.inventory.recipe.entry; +package com.minersstudios.wholib.paper.inventory.recipe.entry; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; import org.bukkit.inventory.Recipe; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/RecipeEntry.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/RecipeEntry.java similarity index 87% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/RecipeEntry.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/RecipeEntry.java index 14042a41..b579a771 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/RecipeEntry.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/RecipeEntry.java @@ -1,8 +1,7 @@ -package com.minersstudios.whomine.inventory.recipe.entry; +package com.minersstudios.wholib.paper.inventory.recipe.entry; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; -import com.minersstudios.whomine.inventory.recipe.builder.ShapedRecipeBuilder; -import com.minersstudios.whomine.menu.CraftsMenu; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.builder.ShapedRecipeBuilder; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapedRecipe; import org.jetbrains.annotations.Contract; @@ -11,7 +10,7 @@ /** * Represents a custom recipe entry that encapsulates a Bukkit Recipe and a flag - * indicating whether the recipe should be shown in the {@link CraftsMenu}. + * indicating whether the recipe should be shown in the {@code CraftsMenu}. *
        * Factory methods : *

          @@ -68,9 +67,9 @@ public interface RecipeEntry { boolean equals(final @Nullable Object obj); /** - * Returns whether the recipe should be shown in the {@link CraftsMenu} + * Returns whether the recipe should be shown in the {@code CraftsMenu} * - * @return True if the recipe should be shown in the {@link CraftsMenu} + * @return True if the recipe should be shown in the {@code CraftsMenu} */ boolean isRegisteredInMenu(); @@ -106,7 +105,7 @@ public interface RecipeEntry { * Constructs a RecipeEntry with the specified recipe builder and * isRegisteredInMenu flag. *
          - * If the recipe type is not supported in the {@link CraftsMenu}, the + * If the recipe type is not supported in the {@code CraftsMenu}, the * isRegisteredInMenu flag will be ignored. * * @param builder The recipe builder @@ -144,7 +143,7 @@ && isSupportedInCraftsMenu(builder) * Constructs a RecipeEntry with the specified recipe and isRegisteredInMenu * flag. *
          - * If the recipe type is not supported in the {@link CraftsMenu}, the + * If the recipe type is not supported in the {@code CraftsMenu}, the * isRegisteredInMenu flag will be ignored. * * @param recipe The Bukkit Recipe object @@ -166,10 +165,10 @@ && isSupportedInCraftsMenu(recipe) } /** - * Returns whether the recipe type is supported in the {@link CraftsMenu} + * Returns whether the recipe type is supported in the {@code CraftsMenu} * * @param recipe The Bukkit Recipe object - * @return True if the recipe type is supported in the {@link CraftsMenu} + * @return True if the recipe type is supported in the {@code CraftsMenu} */ static boolean isSupportedInCraftsMenu(final @NotNull Recipe recipe) { return recipe instanceof ShapedRecipe; @@ -177,11 +176,11 @@ static boolean isSupportedInCraftsMenu(final @NotNull Recipe recipe) { /** * Returns whether the recipe builder type is supported in the - * {@link CraftsMenu} + * {@code CraftsMenu} * * @param builder The recipe builder * @return True if the recipe builder type is supported in the - * {@link CraftsMenu} + * {@code CraftsMenu} */ static boolean isSupportedInCraftsMenu(final @NotNull RecipeBuilder builder) { return builder instanceof ShapedRecipeBuilder; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/RecipeEntryImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/RecipeEntryImpl.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/RecipeEntryImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/RecipeEntryImpl.java index b8dd6aa7..ede185c3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/RecipeEntryImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/RecipeEntryImpl.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.inventory.recipe.entry; +package com.minersstudios.wholib.paper.inventory.recipe.entry; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/SimpleRecipeEntry.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/SimpleRecipeEntry.java similarity index 87% rename from paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/SimpleRecipeEntry.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/SimpleRecipeEntry.java index ade38fbe..389c5246 100644 --- a/paper/src/main/java/com/minersstudios/whomine/inventory/recipe/entry/SimpleRecipeEntry.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/inventory/recipe/entry/SimpleRecipeEntry.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.inventory.recipe.entry; +package com.minersstudios.wholib.paper.inventory.recipe.entry; -import com.minersstudios.whomine.inventory.recipe.builder.RecipeBuilder; +import com.minersstudios.wholib.paper.inventory.recipe.builder.RecipeBuilder; import org.bukkit.inventory.Recipe; import org.jetbrains.annotations.NotNull; diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/listener/PaperListenerManager.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/listener/PaperListenerManager.java new file mode 100644 index 00000000..2d28bd42 --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/listener/PaperListenerManager.java @@ -0,0 +1,320 @@ +package com.minersstudios.wholib.paper.listener; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.EventContainer; +import com.minersstudios.wholib.event.handle.CancellableHandlerParams; +import com.minersstudios.wholib.event.EventListener; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.Listener; +import com.minersstudios.wholib.listener.ListenerManager; +import com.minersstudios.wholib.listener.ListenerMap; +import com.minersstudios.wholib.packet.PacketBound; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.packet.PacketType; +import com.minersstudios.wholib.paper.packet.PaperPacketContainer; +import com.minersstudios.wholib.paper.packet.PaperPacketListener; +import com.minersstudios.wholib.paper.utility.ApiConverter; +import com.minersstudios.wholib.paper.utility.MSLogger; +import org.bukkit.event.Event; +import org.jetbrains.annotations.*; + +import java.util.*; +import java.util.function.Supplier; + +/** + * Listener manager class. + *
          + * This class is responsible for managing event and packet listeners. + * + * @see PaperEventListener + * @see PaperPacketListener + */ +@SuppressWarnings("unused") +public final class PaperListenerManager extends ListenerManager { + + private final ListenerMap, PaperEventListener> eventMap; + private final ListenerMap receivePacketMap; + private final ListenerMap sendPacketMap; + + public PaperListenerManager(final @NotNull WhoMine module) { + super(module); + + this.eventMap = new ListenerMap<>(); + this.receivePacketMap = new ListenerMap<>(); + this.sendPacketMap = new ListenerMap<>(); + } + + /** + * Returns the unmodifiable listener map containing all event listeners + * + * @return The unmodifiable listener map containing all event listeners + */ + public @NotNull @UnmodifiableView ListenerMap, PaperEventListener> eventMap() { + return this.eventMap.toUnmodifiableView(); + } + + /** + * Returns the unmodifiable listener map containing all packet listeners + * + * @return The unmodifiable listener map containing all packet listeners + */ + public @NotNull @Unmodifiable ListenerMap packetMap() { + final var map = new ListenerMap(); + + map.putAll(this.receivePacketMap); + map.putAll(this.sendPacketMap); + + return map.toUnmodifiableView(); + } + + /** + * Returns the unmodifiable view of the + * {@link PacketBound#CLIENTBOUND clientbound} packet map + * + * @return The unmodifiable view of the + * {@link PacketBound#CLIENTBOUND clientbound} packet map + */ + public @NotNull @UnmodifiableView ListenerMap receivePacketMap() { + return this.receivePacketMap.toUnmodifiableView(); + } + + /** + * Returns the unmodifiable view of the + * {@link PacketBound#SERVERBOUND serverbound} packet map + * + * @return The unmodifiable view of the + * {@link PacketBound#SERVERBOUND serverbound} packet map + */ + public @NotNull @UnmodifiableView ListenerMap sendPacketMap() { + return this.sendPacketMap.toUnmodifiableView(); + } + + /** + * Returns the event listeners for the given event + * + * @param event The event + * @return The event listeners for the given event + * @see #getEventListeners(Class) + */ + public @Nullable @UnmodifiableView List getEventListeners(final @NotNull Event event) { + return this.getEventListeners(event.getClass()); + } + + /** + * Returns the event listeners for the given event class + * + * @param eventClass The event class + * @return The event listeners for the given event class + * @see #getEventListeners(Event) + */ + public @Nullable @UnmodifiableView List getEventListeners(final @NotNull Class eventClass) { + return this.eventMap.get(eventClass); + } + + /** + * Returns the packet listeners for the given packet type + * + * @param type The packet type + * @return The packet listeners for the given packet type + */ + public @Nullable @UnmodifiableView List getPacketListeners(final @NotNull PacketType type) { + return type.isServerbound() + ? this.receivePacketMap.get(type) + : this.sendPacketMap.get(type); + } + + @Override + public boolean register(final @NotNull Listener listener) { + final boolean result = switch (listener) { + case PaperEventListener eventListener -> { + final var eventClass = eventListener.getKey(); + + if (this.eventMap.put(eventListener) == null) { + MSLogger.warning("Tried to register an event listener that is already registered: " + eventListener); + + yield false; + } + + for (final var executor : eventListener.executors()) { + final var params = executor.getParams(); + final EventOrder order = params.getOrder(); + + this.getModule().getServer().getPluginManager().registerEvent( + eventClass, + eventListener, + ApiConverter.apiToBukkit(order), + (__, event) -> { + if (!eventClass.isAssignableFrom(event.getClass())) { + return; + } + + eventListener.call( + order, + PaperEventContainer.of( + this.getModule(), + event + ) + ); + }, + this.getModule(), + params instanceof final CancellableHandlerParams cancellable + && cancellable.isIgnoringCancelled() + ); + } + + yield true; + } + case PaperPacketListener packetListener -> { + final PacketType type = packetListener.getKey(); + + yield type.isServerbound() + ? this.receivePacketMap.put(packetListener) != null + : this.sendPacketMap.put(packetListener) != null; + } + default -> throw new UnsupportedOperationException("Unknown listener type: " + listener.getClass()); + }; + + if (result) { + listener.onRegister(); + } + + return result; + } + + @Override + public boolean unregister(final @NotNull Listener registrable) { + final boolean result = switch (registrable) { + case PaperEventListener eventListener -> this.eventMap.remove(eventListener) != null; + case PaperPacketListener packetListener -> { + final PacketType type = packetListener.getKey(); + + yield (type.isServerbound() + ? this.receivePacketMap.remove(packetListener) + : this.sendPacketMap.remove(packetListener)) != null; + } + default -> false; + }; + + if (result) { + registrable.onUnregister(); + } + + return result; + } + + @Override + public void unregisterAll() { + this.unregisterAll(this.eventMap); + this.unregisterAll(this.receivePacketMap); + this.unregisterAll(this.sendPacketMap); + } + + @Override + public boolean isRegistered(final @NotNull Listener registrable) { + return switch (registrable) { + case PaperEventListener eventListener -> this.eventMap.containsListener(eventListener); + case PaperPacketListener packetListener -> { + final PacketType type = packetListener.getKey(); + + yield type.isServerbound() + ? this.receivePacketMap.containsListener(packetListener) + : this.sendPacketMap.containsListener(packetListener); + } + default -> false; + }; + } + + /** + * Calls the registered listeners for the given event + * + * @param container The event container + */ + public void call(final @NotNull PaperEventContainer container) { + this.rawCall( + container, + () -> this.getEventListeners(container.getEvent()) + ); + } + + /** + * Calls the registered listeners for the given event with the given + * parameters + * + * @param order The event order + * @param container The event container + */ + public void call( + final @NotNull EventOrder order, + final @NotNull PaperEventContainer container + ) { + this.rawCall( + order, container, + () -> this.getEventListeners(container.getEvent()) + ); + } + + /** + * Calls the registered listeners for the given packet + * + * @param container The packet container + */ + public void call(final @NotNull PaperPacketContainer container) { + this.rawCall( + container, + () -> this.getPacketListeners(container.getEvent().getType()) + ); + } + + /** + * Calls the registered listeners for the given packet with the given + * order + * + * @param order The event order + * @param container The packet container + */ + public void call( + final @NotNull EventOrder order, + final @NotNull PaperPacketContainer container + ) { + this.rawCall( + order, container, + () -> this.getPacketListeners(container.getEvent().getType()) + ); + } + + private void unregisterAll(final @NotNull ListenerMap map) { + for (final var listener : map.listeners()) { + listener.onUnregister(); + } + + map.clear(); + } + + private > void rawCall( + final @NotNull C container, + final @NotNull Supplier>> supplier + ) { + final var listeners = supplier.get(); + + if (listeners != null) { + for (final var listener : listeners) { + listener.call(container); + } + } + } + + private > void rawCall( + final @NotNull EventOrder order, + final @NotNull C container, + final @NotNull Supplier>> supplier + ) { + final var listeners = supplier.get(); + + if (listeners != null) { + for (final var listener : listeners) { + listener.call(order, container); + } + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/locale/LanguageFile.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/locale/LangFileFabric.java similarity index 71% rename from paper/src/main/java/com/minersstudios/whomine/locale/LanguageFile.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/locale/LangFileFabric.java index 721d3b3e..a15c6ab5 100644 --- a/paper/src/main/java/com/minersstudios/whomine/locale/LanguageFile.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/locale/LangFileFabric.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.locale; +package com.minersstudios.wholib.paper.locale; -import com.google.common.base.Joiner; import com.google.gson.JsonIOException; import com.google.gson.JsonSyntaxException; -import com.minersstudios.whomine.locale.resource.GitHubTranslationResourceManager; -import com.minersstudios.whomine.locale.resource.TranslationResourceManager; -import com.minersstudios.whomine.locale.resource.URITranslationResourceManager; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.resource.github.Tag; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.locale.LanguageFile; +import com.minersstudios.wholib.locale.resource.GitHubTranslationResourceManager; +import com.minersstudios.wholib.locale.resource.TranslationResourceManager; +import com.minersstudios.wholib.locale.resource.URITranslationResourceManager; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.resource.github.Tag; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.SharedConstants; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.kyori.adventure.translation.Translator; import net.minecraft.locale.Language; @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.Collections; import java.util.Locale; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -40,10 +39,7 @@ *
        */ @Immutable -public final class LanguageFile { - private final Locale locale; - private final Map translationMap; - +public final class LangFileFabric { // private static final String KEY_URL = "url"; private static final String KEY_TOKEN = "token"; @@ -53,141 +49,6 @@ public final class LanguageFile { private static final String KEY_FOLDER_PATH = "folder-path"; // - private LanguageFile(final @NotNull Locale locale) { - this.locale = locale; - this.translationMap = new Object2ObjectOpenHashMap<>(); - } - - /** - * Returns the locale of this language file - * - * @return The locale of this language file - */ - public @NotNull Locale getLocale() { - return this.locale; - } - - /** - * Returns the unmodifiable map of translations in this language file - * - * @return The unmodifiable map of translations in this language file - */ - public @NotNull @Unmodifiable Map getTranslationMap() { - return Collections.unmodifiableMap(this.translationMap); - } - - /** - * Gets the translation for the given path - * - * @param path The path to get the translation for - * @return The translation for the given path, or null if it doesn't exist - */ - public @Nullable String get(final @NotNull String path) { - return this.getOrDefault(path, null); - } - - /** - * Gets the translation for the given path, or the fallback if it doesn't - * exist - * - * @param path The path to get the translation for - * @param fallback The fallback to return if the translation doesn't exist - * @return The translation for the given path, or the fallback if it doesn't - * exist - */ - public @UnknownNullability String getOrDefault( - final @NotNull String path, - final @Nullable String fallback - ) { - return this.translationMap.getOrDefault(path, fallback); - } - - /** - * Returns the number of translations in this language file - * - * @return The number of translations in this language file - */ - public int size() { - return this.translationMap.size(); - } - - /** - * Returns a hash code based on the locale and translations - * - * @return A hash code based on the locale and translations - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - - result = prime * result + this.locale.hashCode(); - result = prime * result + this.translationMap.hashCode(); - - return result; - } - - /** - * Compares the specified object with this language file for equality - * - * @param obj The object to compare - * @return True if the object is a language file and has the same locale and - * translations - */ - @Contract("null -> false") - @Override - public boolean equals(final @Nullable Object obj) { - return this == obj - || ( - obj instanceof LanguageFile that - && this.locale.equals(that.locale) - && this.translationMap.equals(that.translationMap) - ); - } - - /** - * Checks whether the given path exists in this language file - * - * @param path The path to check for - * @return Whether the given path exists in this language file - */ - public boolean containsPath(final @NotNull String path) { - return this.translationMap.containsKey(path); - } - - /** - * Returns whether this language file contains the given translation - * - * @param translation The translation to check for - * @return True if this language file contains the given translation - */ - public boolean containsTranslation(final @NotNull String translation) { - return this.translationMap.containsValue(translation); - } - - /** - * Returns whether this language file contains no translations - * - * @return True if this language file contains no translations - */ - public boolean isEmpty() { - return this.translationMap.isEmpty(); - } - - /** - * Returns a string representation of this language file - * - * @return A string representation of this language file containing the - * translations - */ - @Override - public @NotNull String toString() { - return "LanguageFile{" + - "locale=" + this.locale + - ", translations=[" + Joiner.on(", ").withKeyValueSeparator("=").join(this.translationMap) + ']' + - '}'; - } - /** * Creates and loads all languages.yml from the given configuration section. *
        @@ -372,7 +233,7 @@ public boolean isEmpty() { if (latestTag != null) { section.set(KEY_TAG, latestTag.getName()); - synchronized (LanguageFile.class) { + synchronized (LangFileFabric.class) { try { config.save(file); } catch (final Throwable e) { @@ -475,18 +336,18 @@ public boolean isEmpty() { final @NotNull Locale locale, final @NotNull InputStream inputStream ) throws JsonIOException, JsonSyntaxException { - final LanguageFile file = new LanguageFile(locale); + final var translationMap = new Object2ObjectOpenHashMap(); try (inputStream) { Language.loadFromJson( inputStream, - file.translationMap::put + translationMap::put ); } catch (final IOException e) { throw new JsonIOException(e); } - return file; + return new LanguageFile(locale, translationMap); } private static @NotNull File getFile(final @NotNull String path) { diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/ChannelHandler.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/ChannelHandler.java new file mode 100644 index 00000000..85a63794 --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/ChannelHandler.java @@ -0,0 +1,180 @@ +package com.minersstudios.wholib.paper.packet; + +import com.minersstudios.wholib.module.ModuleComponent; +import com.minersstudios.wholib.packet.*; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import io.netty.channel.*; +import net.kyori.adventure.text.Component; +import net.minecraft.network.Connection; +import net.minecraft.network.PacketListener; +import net.minecraft.network.protocol.Packet; +import net.minecraft.server.level.ServerPlayer; +import org.bukkit.event.player.PlayerKickEvent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.concurrent.Immutable; + +/** + * The ChannelHandler class is responsible for handling incoming and outgoing + * packets in the Minecraft server networking pipeline. + *
        + * It extends {@link ChannelDuplexHandler}, which allows handling of both + * inbound and outbound data. + * + * @see PacketType + * @see PacketContainer + * @see PacketEvent + */ +@SuppressWarnings("unused") +@Immutable +public final class ChannelHandler extends ChannelDuplexHandler implements ModuleComponent { + + private final WhoMine module; + private final Connection connection; + + /** + * Channel handler constructor + * + * @param module The module associated with this channel handler + * @param connection The connection associated with this channel handler + */ + public ChannelHandler( + final @NotNull WhoMine module, + final @NotNull Connection connection + ) { + this.module = module; + this.connection = connection; + } + + /** + * Returns the module associated with this channel handler + * + * @return The module associated with this channel handler + */ + @Override + public @NotNull WhoMine getModule() { + return this.module; + } + + /** + * @return The connection associated with this channel handler + */ + public @NotNull Connection getConnection() { + return this.connection; + } + + /** + * This method is called when a packet is received from the client. It + * processes the packet, creates a {@link PacketContainer}, and fires a + * {@link PacketEvent}. If the event is not cancelled, the packet is passed + * to the next channel handler in the pipeline. + * + * @param ctx The ChannelHandlerContext + * @param msg The received packet + * @throws Exception If an error occurs while processing the packet + */ + @Override + public void channelRead( + final @NotNull ChannelHandlerContext ctx, + final @NotNull Object msg + ) throws Exception { + final PaperPacketContainer container = this.handle(msg); + + if (container != null) { + final PaperPacketEvent event = container.getEvent(); + + this.module.getListenerManager().call(container); + + if (!event.isCancelled()) { + super.channelRead(ctx, event.getPacket()); + } + } + } + + /** + * This method is called when a packet is about to be sent to the client. + * It processes the packet, creates a {@link PacketContainer}, and fires a + * {@link PacketEvent}. If the event is not cancelled, the packet is passed + * to the next channel handler in the pipeline. + * + * @param ctx The ChannelHandlerContext + * @param msg The packet to be sent + * @param promise The ChannelPromise + * @throws Exception If an error occurs while processing the packet + */ + @Override + public void write( + final @NotNull ChannelHandlerContext ctx, + final @NotNull Object msg, + final @NotNull ChannelPromise promise + ) throws Exception { + final PaperPacketContainer container = this.handle(msg); + + if (container != null) { + final PaperPacketEvent event = container.getEvent(); + + this.module.getListenerManager().call(container); + + if (!event.isCancelled()) { + super.write(ctx, event.getPacket(), promise); + } + } + } + + @SuppressWarnings("PatternValidation") + private @Nullable PaperPacketContainer handle(final @NotNull Object msg) { + if (!(msg instanceof final Packet packet)) { + return null; + } + + final var nmsType = packet.type(); + final PacketListener packetListener = this.connection.getPacketListener(); + + if (packetListener == null) { + this.kick( + Component.text("No packet listener found"), + Component.text("No packet listener found for " + this.connection.getPlayer().getName() + " with packet type: " + nmsType) + ); + + return null; + } + + final PacketType packetType = + PacketProtocol.byOrdinal(packetListener.protocol().ordinal()) + .getRegistry() + .byClass() + .get( + PacketBound.fromId(nmsType.flow().id()), + packet.getClass() + ); + + if (packetType == null) { + this.kick( + Component.text("Unknown packet type: " + nmsType), + Component.text("Unknown packet type: " + nmsType + " sent by " + this.connection.getPlayer().getName()) + ); + + return null; + } + + return PaperPacketContainer.of( + this.module, + new PaperPacketEvent(packetType, packet, this.connection) + ); + } + + private void kick( + final @NotNull Component playerKickMessage, + final @NotNull Component consoleKickMessage + ) { + final ServerPlayer serverPlayer = this.connection.getPlayer(); + + this.module.runTask(() -> serverPlayer.connection.disconnect( + playerKickMessage, + PlayerKickEvent.Cause.PLUGIN + )); + MSLogger.severe(consoleKickMessage); + } +} diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/ChannelInjector.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/ChannelInjector.java new file mode 100644 index 00000000..d04b88ae --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/ChannelInjector.java @@ -0,0 +1,46 @@ +package com.minersstudios.wholib.paper.packet; + +import com.minersstudios.wholib.module.AbstractModuleComponent; +import com.minersstudios.wholib.paper.WhoMine; +import io.netty.channel.Channel; +import io.netty.channel.ChannelPipeline; +import net.minecraft.network.Connection; +import net.minecraft.network.HandlerNames; + +public class ChannelInjector extends AbstractModuleComponent { + public static final String CHANNEL_HANDLER_NAME = "ms_channel_handler"; + + private final Connection connection; + + public ChannelInjector( + final WhoMine module, + final Connection connection + ) { + super(module); + + this.connection = connection; + } + + public void inject() { + final ChannelPipeline pipeline = this.connection.channel.pipeline(); + + if (!pipeline.names().contains(CHANNEL_HANDLER_NAME)) { + pipeline.addBefore( + HandlerNames.PACKET_HANDLER, + CHANNEL_HANDLER_NAME, + new ChannelHandler(this.getModule(), this.connection) + ); + } + } + + public void uninject() { + final Channel channel = this.connection.channel; + final ChannelPipeline pipeline = channel.pipeline(); + + if (pipeline.names().contains(CHANNEL_HANDLER_NAME)) { + try (final var eventLoop = channel.eventLoop()) { + eventLoop.execute(() -> pipeline.remove(CHANNEL_HANDLER_NAME)); + } + } + } +} diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/PaperPacketContainer.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/PaperPacketContainer.java new file mode 100644 index 00000000..3d86dc1d --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/PaperPacketContainer.java @@ -0,0 +1,50 @@ +package com.minersstudios.wholib.paper.packet; + +import com.minersstudios.wholib.packet.PacketContainer; +import com.minersstudios.wholib.paper.WhoMine; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +/** + * Represents a paper packet container. + *

        + * It contains : + *

          + *
        • The main module that registers and handles the packet event
        • + *
        • The packet event itself
        • + *
        + * + * @see PaperPacketEvent + * @see PaperPacketListener + */ +@SuppressWarnings("unused") +public final class PaperPacketContainer + extends PacketContainer { + + private PaperPacketContainer( + final @NotNull WhoMine module, + final @NotNull PaperPacketEvent packet + ) { + super(module, packet); + } + + @Override + public boolean isCancelled() { + return this.getEvent().isCancelled(); + } + + /** + * Creates a new paper packet container with the given module and event + * + * @param module The main module that registers and handles the event + * @param packet The packet event associated with this container + * @return A new container instance + */ + @Contract("_, _ -> new") + public static @NotNull PaperPacketContainer of( + final @NotNull WhoMine module, + final @NotNull PaperPacketEvent packet + ) { + return new PaperPacketContainer(module, packet); + } +} diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/PaperPacketEvent.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/PaperPacketEvent.java new file mode 100644 index 00000000..2f86125d --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/PaperPacketEvent.java @@ -0,0 +1,33 @@ +package com.minersstudios.wholib.paper.packet; + +import com.minersstudios.wholib.packet.PacketContainer; +import com.minersstudios.wholib.packet.PacketEvent; +import com.minersstudios.wholib.packet.PacketType; +import net.minecraft.network.Connection; +import net.minecraft.network.protocol.Packet; +import org.jetbrains.annotations.NotNull; + +/** + * Represents a packet event. It contains the packet container and the player + * who sent or received. The packet container contains the packet and the + * packet type and can be modified, but the packet type cannot be changed. + * + * @see PacketContainer + */ +public final class PaperPacketEvent extends PacketEvent, Connection> { + + /** + * Creates a new packet event with the given type, packet and connection + * + * @param type The packet type + * @param packet The packet + * @param connection The connection + */ + public PaperPacketEvent( + final @NotNull PacketType type, + final @NotNull Packet packet, + final @NotNull Connection connection + ) { + super(type, packet, connection); + } +} diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/PaperPacketListener.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/PaperPacketListener.java new file mode 100644 index 00000000..47feb881 --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/packet/PaperPacketListener.java @@ -0,0 +1,56 @@ +package com.minersstudios.wholib.paper.packet; + +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.event.handle.CancellableHandlerParams; +import com.minersstudios.wholib.event.handle.HandlerExecutor; +import com.minersstudios.wholib.listener.Listener; +import com.minersstudios.wholib.packet.PacketListener; +import com.minersstudios.wholib.packet.PacketType; +import com.minersstudios.wholib.throwable.ListenerException; +import com.minersstudios.wholib.paper.listener.PaperListenerManager; +import org.jetbrains.annotations.NotNull; + +/** + * An abstract class that represents a paper packet listener. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
        Available optional overridable methods
        MethodDescription
        {@link #onRegister()} + * Called when the listener is registered by a manager in the + * {@link PaperListenerManager#register(Listener)} method + *
        {@link #onUnregister()} + * Called when the listener is unregistered by a manager in the + * {@link PaperListenerManager#unregister(Listener)} method + *
        + * + * @see PaperPacketContainer + * @see HandlerExecutor + */ +@SuppressWarnings("unused") +public abstract class PaperPacketListener extends PacketListener { + + /** + * Constructs a new packet listener with the specified packet type. + *

        + * This constructor will automatically retrieve all handlers from the + * listener class. + * + * @param packetType The packet type of the packet listener + * @throws ListenerException If the listener has duplicate handlers for the + * same order + */ + protected PaperPacketListener(final @NotNull PacketType packetType) throws ListenerException { + super(packetType, CancellableHandler.class, CancellableHandlerParams::of); + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/player/PlayerFile.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerFile.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/player/PlayerFile.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerFile.java index 270cb2e3..dee43811 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/PlayerFile.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerFile.java @@ -1,8 +1,8 @@ -package com.minersstudios.whomine.player; +package com.minersstudios.wholib.paper.player; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.player.skin.Skin; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.player.skin.Skin; +import com.minersstudios.wholib.utility.ChatUtils; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -18,7 +18,7 @@ import java.util.*; import java.util.logging.Level; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; /** * Player file with player data, settings, etc. diff --git a/paper/src/main/java/com/minersstudios/whomine/player/PlayerInfo.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerInfo.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/player/PlayerInfo.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerInfo.java index 16198e97..0301c9b3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/PlayerInfo.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerInfo.java @@ -1,27 +1,23 @@ -package com.minersstudios.whomine.player; +package com.minersstudios.wholib.paper.player; import com.destroystokyo.paper.profile.PlayerProfile; -import com.minersstudios.whomine.Cache; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.collection.MuteMap; -import com.minersstudios.whomine.player.collection.PlayerInfoMap; -import com.minersstudios.whomine.player.skin.Skin; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.BlockUtils; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.DateUtils; -import com.minersstudios.whomine.utility.PlayerUtils; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.discord.DiscordMap; -import com.minersstudios.whomine.menu.PronounMenu; -import com.minersstudios.whomine.menu.ResourcePackMenu; -import com.minersstudios.whomine.utility.IDUtils; -import com.minersstudios.whomine.utility.MSPlayerUtils; -import com.minersstudios.whomine.world.WorldDark; +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.IDUtils; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.discord.DiscordMap; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.player.collection.MuteMap; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.paper.player.skin.Skin; +import com.minersstudios.wholib.paper.utility.*; +import com.minersstudios.wholib.paper.world.WorldDark; import com.mojang.authlib.GameProfile; import fr.xephi.authme.api.v3.AuthMeApi; +import io.papermc.paper.ban.BanListType; import net.dv8tion.jda.api.entities.MessageEmbed; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -31,7 +27,7 @@ import net.minecraft.server.players.UserWhiteListEntry; import org.bukkit.*; import org.bukkit.command.CommandSender; -import org.bukkit.craftbukkit.v1_20_R3.CraftServer; +import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -52,10 +48,10 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeoutException; -import static com.minersstudios.whomine.locale.Translations.*; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.ME; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.TODO; -import static com.minersstudios.whomine.utility.MessageUtils.*; +import static com.minersstudios.wholib.locale.Translations.*; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.ME; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.TODO; +import static com.minersstudios.wholib.paper.utility.MessageUtils.*; import static net.kyori.adventure.text.Component.text; /** @@ -106,7 +102,7 @@ public PlayerInfo( } /** - * Gets player info from {@link Cache#getPlayerInfoMap()} by nickname and + * Gets player info from {@link PaperCache#getPlayerInfoMap()} by nickname and * {@link UUID}. *
        * If the player info is not cached, new player info is created with the @@ -116,7 +112,7 @@ public PlayerInfo( * * @param uuid The player UUID * @param nickname The player nickname - * @return Player info from {@link Cache#getPlayerInfoMap()} + * @return Player info from {@link PaperCache#getPlayerInfoMap()} */ public static @NotNull PlayerInfo fromProfile( final @NotNull WhoMine plugin, @@ -127,7 +123,7 @@ public PlayerInfo( } /** - * Gets player info from {@link Cache#getPlayerInfoMap()} by {@link Player} + * Gets player info from {@link PaperCache#getPlayerInfoMap()} by {@link Player} * object. *
        * If the player info is not cached, new player info is created with the @@ -136,7 +132,7 @@ public PlayerInfo( * to the map. * * @param player The player - * @return Player info from {@link Cache#getPlayerInfoMap()} + * @return Player info from {@link PaperCache#getPlayerInfoMap()} */ public static @NotNull PlayerInfo fromOnlinePlayer( final @NotNull WhoMine plugin, @@ -146,7 +142,7 @@ public PlayerInfo( } /** - * Gets player info from {@link Cache#getPlayerInfoMap()} by + * Gets player info from {@link PaperCache#getPlayerInfoMap()} by * {@link OfflinePlayer} object. *
        * If the player info is not cached, new player info is created with the @@ -155,7 +151,7 @@ public PlayerInfo( * to the map. * * @param offlinePlayer The offline player - * @return Player info from {@link Cache#getPlayerInfoMap()}, or null if + * @return Player info from {@link PaperCache#getPlayerInfoMap()}, or null if * player nickname is blank */ @Contract("_, null -> null") @@ -167,9 +163,9 @@ public PlayerInfo( } /** - * Gets player info from {@link Cache#getPlayerInfoMap()} by + * Gets player info from {@link PaperCache#getPlayerInfoMap()} by * {@link OfflinePlayer} object, which was retrieved by the specified player - * ID from {@link Cache#getIdMap()}. + * ID from {@link PaperCache#getIdMap()}. *
        * If the player info is not cached, new player info is created with the * player file and settings if the file exists, or new player information is @@ -189,7 +185,7 @@ public PlayerInfo( } /** - * Gets player info from {@link Cache#getPlayerInfoMap()} by + * Gets player info from {@link PaperCache#getPlayerInfoMap()} by * {@link OfflinePlayer} object, which was retrieved by the specified player * nickname with {@link Server#getOfflinePlayer(String)}. *
        @@ -215,7 +211,7 @@ public PlayerInfo( } /** - * Gets player info from {@link Cache#getPlayerInfoMap()} by + * Gets player info from {@link PaperCache#getPlayerInfoMap()} by * {@link OfflinePlayer} object, which was retrieved by the specified player * {@link UUID} with {@link Server#getOfflinePlayer(UUID)}. *
        @@ -240,7 +236,7 @@ public PlayerInfo( } /** - * Gets player info from {@link Cache#getPlayerInfoMap()} by + * Gets player info from {@link PaperCache#getPlayerInfoMap()} by * {@link OfflinePlayer} object, which was retrieved by the specified player * ID or nickname. *
        @@ -273,8 +269,8 @@ public PlayerInfo( } /** - * Gets player info from {@link Cache#getPlayerInfoMap()} by discord ID with - * {@link Cache#getDiscordMap()}, then gets the player info from its uuid + * Gets player info from {@link PaperCache#getPlayerInfoMap()} by discord ID with + * {@link PaperCache#getDiscordMap()}, then gets the player info from its uuid * and nickname with {@link #fromProfile(WhoMine, UUID, String)}. *
        * If the player info is not cached, new player info is created with the @@ -395,7 +391,7 @@ public PlayerInfo( } /** - * @return Player's id from {@link Cache#getIdMap()} + * @return Player's id from {@link PaperCache#getIdMap()} * @see #getID(boolean, boolean) */ public int getID() { @@ -405,13 +401,13 @@ public int getID() { /** * @param addPlayer If true, the next available ID is added * @param zeroIfNull If true, returns 0 if the id is null - * @return Player's id from {@link Cache#getIdMap()} + * @return Player's id from {@link PaperCache#getIdMap()} */ public int getID( final boolean addPlayer, final boolean zeroIfNull ) { - final Cache cache = this.plugin.getCache(); + final PaperCache cache = this.plugin.getCache(); return this == cache.getConsolePlayerInfo() ? -1 : cache.getIdMap().getID( @@ -499,9 +495,9 @@ public void setSitting( ); if (message == null) { - sendRPEventMessage(player, this.playerFile.getPronouns().getSitMessage(), ME); + MessageUtils.sendRPEventMessage(player, this.playerFile.getPronouns().getSitMessage(), RolePlayActionType.ME); } else { - sendRPEventMessage(player, message, text("приседая"), TODO); + MessageUtils.sendRPEventMessage(player, message, text("приседая"), RolePlayActionType.TODO); } } @@ -546,9 +542,9 @@ public void unsetSitting(final @Nullable Component message) { player.teleportAsync(getUpLocation, PlayerTeleportEvent.TeleportCause.PLUGIN).thenAccept(bool -> { if (message == null) { - sendRPEventMessage(player, this.playerFile.getPronouns().getUnSitMessage(), ME); + MessageUtils.sendRPEventMessage(player, this.playerFile.getPronouns().getUnSitMessage(), RolePlayActionType.ME); } else { - sendRPEventMessage(player, message, text("вставая"), TODO); + MessageUtils.sendRPEventMessage(player, message, text("вставая"), RolePlayActionType.TODO); } }); } @@ -643,7 +639,7 @@ public void linkDiscord(final long id) { * @see DiscordMap#remove(long) */ public long unlinkDiscord() { - final Cache cache = this.plugin.getCache(); + final PaperCache cache = this.plugin.getCache(); final DiscordMap discordMap = cache.getDiscordMap(); final long id = discordMap.getId(DiscordMap.Params.create(this.uuid, this.nickname)); final BotHandler botHandler = cache.getBotHandlers().get(id); @@ -721,7 +717,7 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv } /** - * @return Player's mute params from {@link Cache#getMuteMap()} + * @return Player's mute params from {@link PaperCache#getMuteMap()} * @see MuteMap#getMuteEntry(OfflinePlayer) */ public @Nullable MuteMap.Entry getMuteEntry() { @@ -729,7 +725,7 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv } /** - * @return Player's mute reason from {@link Cache#getMuteMap()} params + * @return Player's mute reason from {@link PaperCache#getMuteMap()} params * @throws IllegalStateException If the player is not muted, check * {@link #isMuted()} first * @see MuteMap.Entry#getReason() @@ -745,7 +741,7 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv } /** - * @return Player's mute source from {@link Cache#getMuteMap()} params + * @return Player's mute source from {@link PaperCache#getMuteMap()} params * @throws IllegalStateException If the player is not muted, check * {@link #isMuted()} first * @see MuteMap.Entry#getSource() @@ -762,7 +758,7 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv /** * @param sender The command sender, used to get the time zone - * @return Date when the player was muted from {@link Cache#getMuteMap()} + * @return Date when the player was muted from {@link PaperCache#getMuteMap()} * with the sender's time zone or default time zone if the sender's * time zone cannot be obtained * @throws IllegalStateException If the player is not muted, check @@ -770,12 +766,12 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv * @see MuteMap.Entry#getCreated() */ public @NotNull Component getMutedFrom(final @NotNull CommandSender sender) throws IllegalStateException { - return text(DateUtils.getSenderDate(this.getMutedFrom(), sender, this.plugin.getConfiguration().getDateFormatter())); + return Component.text(DateUtils.getSenderDate(this.getMutedFrom(), sender, this.plugin.getConfiguration().getDateFormatter())); } /** * @param address The IP address, used to get the time zone - * @return Date when the player was muted from {@link Cache#getMuteMap()} + * @return Date when the player was muted from {@link PaperCache#getMuteMap()} * with the time zone of the IP address or default time zone if the * time zone cannot be obtained * @throws IllegalStateException If the player is not muted, check @@ -783,11 +779,11 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv * @see MuteMap.Entry#getCreated() */ public @NotNull Component getMutedFrom(final @NotNull InetAddress address) throws IllegalStateException { - return text(DateUtils.getDate(this.getMutedFrom(), address, this.plugin.getConfiguration().getDateFormatter())); + return Component.text(DateUtils.getDate(this.getMutedFrom(), address, this.plugin.getConfiguration().getDateFormatter())); } /** - * @return Date when the player was muted from {@link Cache#getMuteMap()} + * @return Date when the player was muted from {@link PaperCache#getMuteMap()} * @throws IllegalStateException If the player is not muted, check * {@link #isMuted()} first * @see MuteMap.Entry#getCreated() @@ -804,7 +800,7 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv /** * @param sender The command sender, used to get the time zone - * @return Date when the player will be unmuted from {@link Cache#getMuteMap()} + * @return Date when the player will be unmuted from {@link PaperCache#getMuteMap()} * with the sender's time zone or default time zone if the sender's * time zone cannot be obtained * @throws IllegalStateException If the player is not muted, check @@ -812,12 +808,12 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv * @see MuteMap.Entry#getExpiration() */ public @NotNull Component getMutedTo(final @NotNull CommandSender sender) throws IllegalStateException { - return text(DateUtils.getSenderDate(this.getMutedTo(), sender, this.plugin.getConfiguration().getDateFormatter())); + return Component.text(DateUtils.getSenderDate(this.getMutedTo(), sender, this.plugin.getConfiguration().getDateFormatter())); } /** * @param address The IP address, used to get the time zone - * @return Date when the player will be unmuted from {@link Cache#getMuteMap()} + * @return Date when the player will be unmuted from {@link PaperCache#getMuteMap()} * with the time zone of the IP address or default time zone if the * time zone cannot be obtained * @throws IllegalStateException If the player is not muted, check @@ -825,11 +821,11 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv * @see MuteMap.Entry#getExpiration() */ public @NotNull Component getMutedTo(final @NotNull InetAddress address) throws IllegalStateException { - return text(DateUtils.getDate(this.getMutedTo(), address, this.plugin.getConfiguration().getDateFormatter())); + return Component.text(DateUtils.getDate(this.getMutedTo(), address, this.plugin.getConfiguration().getDateFormatter())); } /** - * @return Date when the player will be unmuted from {@link Cache#getMuteMap()} + * @return Date when the player will be unmuted from {@link PaperCache#getMuteMap()} * @throws IllegalStateException If the player is not muted, check * {@link #isMuted()} first * @see MuteMap.Entry#getExpiration() @@ -845,7 +841,7 @@ public void completeResourcePackFuture(final @NotNull PlayerResourcePackStatusEv } /** - * Mutes or unmutes the player in {@link Cache#getMuteMap()}.Also sends a + * Mutes or unmutes the player in {@link PaperCache#getMuteMap()}.Also sends a * message to the muted player if they are online, and to the sender, who * muted the player. * @@ -888,7 +884,7 @@ public void setMuted( this.getGrayIDGreenName(), text(this.nickname), text(reason), - text(DateUtils.getSenderDate(date, sender, this.plugin.getConfiguration().getDateFormatter())) + Component.text(DateUtils.getSenderDate(date, sender, this.plugin.getConfiguration().getDateFormatter())) ) ); @@ -898,7 +894,7 @@ public void setMuted( COMMAND_MUTE_MESSAGE_RECEIVER.asTranslatable() .arguments( text(reason), - text(DateUtils.getSenderDate(date, sender, this.plugin.getConfiguration().getDateFormatter())) + Component.text(DateUtils.getSenderDate(date, sender, this.plugin.getConfiguration().getDateFormatter())) ) ); } @@ -941,7 +937,7 @@ public void setMuted( this.defaultName, text(this.nickname), text(reason), - text(DateUtils.getSenderDate(date, player, this.plugin.getConfiguration().getDateFormatter())) + Component.text(DateUtils.getSenderDate(date, player, this.plugin.getConfiguration().getDateFormatter())) ) : DISCORD_UNMUTED.asComponent( this.defaultName, @@ -953,7 +949,7 @@ public void setMuted( } /** - * Unmutes the player in {@link Cache#getMuteMap()}. Also sends a message to + * Unmutes the player in {@link PaperCache#getMuteMap()}. Also sends a message to * the muted player if they are online, and to the sender, who unmuted the * player. * @@ -965,16 +961,16 @@ public void unmute(final @NotNull CommandSender commandSender) { } /** - * @return The ban entry of the player from {@link BanList.Type#PROFILE} + * @return The ban entry of the player from {@link BanListType#PROFILE} */ public @Nullable BanEntry getBanEntry() { - final BanList banList = this.server.getBanList(BanList.Type.PROFILE); + final BanList banList = this.server.getBanList(BanListType.PROFILE); return banList.getBanEntry(this.profile); } /** - * @return The ban reason of the player from {@link BanList.Type#PROFILE} + * @return The ban reason of the player from {@link BanListType#PROFILE} * or {@link Translations#COMMAND_BAN_DEFAULT_REASON} * if the reason is null * @throws IllegalStateException If the player is not banned, check @@ -1006,13 +1002,13 @@ public void setBanReason(final @NotNull String reason) throws IllegalStateExcept if (banEntry == null) { throw new IllegalStateException("Player is not banned"); } - + banEntry.setReason(reason); banEntry.save(); } /** - * @return The ban source of the player from {@link BanList.Type#PROFILE} + * @return The ban source of the player from {@link BanListType#PROFILE} * @throws IllegalStateException If the player is not banned, check * {@link #isBanned()} first * @see BanEntry#getSource() @@ -1039,14 +1035,14 @@ public void setBannedBy(final @NotNull String source) throws IllegalStateExcepti if (banEntry == null) { throw new IllegalStateException("Player is not banned"); } - + banEntry.setSource(source); banEntry.save(); } /** * @param sender The command sender, used to get the time zone - * @return Date when the player was banned from {@link BanList.Type#PROFILE} + * @return Date when the player was banned from {@link BanListType#PROFILE} * with the sender's time zone or default time zone if the sender's * time zone cannot be obtained * @throws IllegalStateException If the player is not banned, check @@ -1054,12 +1050,12 @@ public void setBannedBy(final @NotNull String source) throws IllegalStateExcepti * @see BanEntry#getCreated() */ public @NotNull Component getBannedFrom(final @NotNull CommandSender sender) throws IllegalStateException { - return text(DateUtils.getSenderDate(this.getBannedFrom(), sender, this.plugin.getConfiguration().getDateFormatter())); + return Component.text(DateUtils.getSenderDate(this.getBannedFrom(), sender, this.plugin.getConfiguration().getDateFormatter())); } /** * @param address The IP address, used to get the time zone - * @return Date when the player was banned from {@link BanList.Type#PROFILE} + * @return Date when the player was banned from {@link BanListType#PROFILE} * with the time zone of the IP address or default time zone if the * time zone cannot be obtained * @throws IllegalStateException If the player is not banned, check @@ -1067,11 +1063,11 @@ public void setBannedBy(final @NotNull String source) throws IllegalStateExcepti * @see BanEntry#getCreated() */ public @NotNull Component getBannedFrom(final @NotNull InetAddress address) throws IllegalStateException { - return text(DateUtils.getDate(this.getBannedFrom(), address, this.plugin.getConfiguration().getDateFormatter())); + return Component.text(DateUtils.getDate(this.getBannedFrom(), address, this.plugin.getConfiguration().getDateFormatter())); } /** - * @return Date when the player was banned from {@link BanList.Type#PROFILE} + * @return Date when the player was banned from {@link BanListType#PROFILE} * @throws IllegalStateException If the player is not banned, check * {@link #isBanned()} first * @see BanEntry#getCreated() @@ -1088,7 +1084,7 @@ public void setBannedBy(final @NotNull String source) throws IllegalStateExcepti /** * @param sender The command sender, used to get the time zone - * @return Date when the player will be unbanned from {@link BanList.Type#PROFILE} + * @return Date when the player will be unbanned from {@link BanListType#PROFILE} * with the sender's time zone or default time zone if the sender's * time zone cannot be obtained * @throws IllegalStateException If the player is not banned, check @@ -1105,12 +1101,12 @@ public void setBannedBy(final @NotNull String source) throws IllegalStateExcepti final Date expiration = banEntry.getExpiration(); return expiration == null ? COMMAND_BAN_TIME_FOREVER.asTranslatable() - : text(DateUtils.getSenderDate(expiration.toInstant(), sender, this.plugin.getConfiguration().getDateFormatter())); + : Component.text(DateUtils.getSenderDate(expiration.toInstant(), sender, this.plugin.getConfiguration().getDateFormatter())); } /** * @param address The IP address, used to get the time zone - * @return Date when the player will be unbanned from {@link BanList.Type#PROFILE} + * @return Date when the player will be unbanned from {@link BanListType#PROFILE} * with the time zone of the IP address or default time zone if the * time zone cannot be obtained * @throws IllegalStateException If the player is not banned, check @@ -1127,11 +1123,11 @@ public void setBannedBy(final @NotNull String source) throws IllegalStateExcepti final Date expiration = banEntry.getExpiration(); return expiration == null ? COMMAND_BAN_TIME_FOREVER.asTranslatable() - : text(DateUtils.getDate(expiration.toInstant(), address, this.plugin.getConfiguration().getDateFormatter())); + : Component.text(DateUtils.getDate(expiration.toInstant(), address, this.plugin.getConfiguration().getDateFormatter())); } /** - * @return Date when the player will be unbanned from {@link BanList.Type#PROFILE}, + * @return Date when the player will be unbanned from {@link BanListType#PROFILE}, * or null if the player is banned forever * @throws IllegalStateException If the player is not banned, check * {@link #isBanned()} first @@ -1150,7 +1146,7 @@ public void setBannedBy(final @NotNull String source) throws IllegalStateExcepti /** * @param expiration Date when the player will be unbanned from - * {@link BanList.Type#PROFILE}, or null if the player is + * {@link BanListType#PROFILE}, or null if the player is * banned forever * @throws IllegalStateException If the player is not banned, check * {@link #isBanned()} first @@ -1162,13 +1158,13 @@ public void setBannedTo(final @Nullable Date expiration) throws IllegalStateExce if (banEntry == null) { throw new IllegalStateException("Player is not banned"); } - + banEntry.setExpiration(expiration); banEntry.save(); } /** - * Bans or unbans the player in {@link BanList.Type#PROFILE}. Also kick the + * Bans or unbans the player in {@link BanListType#PROFILE}. Also kick the * player with the specified reason and expiration date if they are online, * and to the player's private discord channel, if it is linked. Also sends * a message to the sender. @@ -1185,7 +1181,7 @@ public void setBanned( final @NotNull String reason, final @Nullable CommandSender sender ) { - final BanList banList = this.server.getBanList(BanList.Type.PROFILE); + final BanList banList = this.server.getBanList(BanListType.PROFILE); final Player player = this.getOnlinePlayer(); final CommandSender commandSender = sender == null ? this.server.getConsoleSender() : sender; @@ -1208,7 +1204,7 @@ public void setBanned( COMMAND_BAN_MESSAGE_RECEIVER_SUBTITLE.asTranslatable() .arguments( text(reason), - text(DateUtils.getSenderDate(date, player, this.plugin.getConfiguration().getDateFormatter())) + Component.text(DateUtils.getSenderDate(date, player, this.plugin.getConfiguration().getDateFormatter())) ), PlayerKickEvent.Cause.BANNED ); @@ -1219,7 +1215,7 @@ public void setBanned( this.getGrayIDGreenName(), text(this.nickname), text(reason), - text(DateUtils.getSenderDate(date, sender, this.plugin.getConfiguration().getDateFormatter())) + Component.text(DateUtils.getSenderDate(date, sender, this.plugin.getConfiguration().getDateFormatter())) ) ); } else { @@ -1254,7 +1250,7 @@ public void setBanned( this.defaultName, text(this.nickname), text(reason), - text(DateUtils.getSenderDate(date, player, this.plugin.getConfiguration().getDateFormatter())) + Component.text(DateUtils.getSenderDate(date, player, this.plugin.getConfiguration().getDateFormatter())) ) : DISCORD_UNBANNED.asComponent( this.defaultName, @@ -1266,7 +1262,7 @@ public void setBanned( } /** - * Unbans the player in {@link BanList.Type#PROFILE} + * Unbans the player in {@link BanListType#PROFILE} * * @param commandSender The command sender, who unbanned the player, or null * if the player was unbanned by the console @@ -1354,7 +1350,7 @@ public boolean isWhiteListed() { } /** - * @return True, if the player is muted in {@link Cache#getMuteMap()} + * @return True, if the player is muted in {@link PaperCache#getMuteMap()} * @see MuteMap#isMuted(OfflinePlayer) */ public boolean isMuted() { @@ -1362,7 +1358,7 @@ public boolean isMuted() { } /** - * @return True, if the player is banned in {@link BanList.Type#PROFILE} + * @return True, if the player is banned in {@link BanListType#PROFILE} */ public boolean isBanned() { return this.getBanEntry() != null; @@ -1473,7 +1469,7 @@ public void handleQuit(final @Nullable Player player) { this.savePlayerDataParams(); if (!this.isInWorldDark()) { - sendQuitMessage(this, player); + MessageUtils.sendQuitMessage(this, player); } } @@ -1503,7 +1499,7 @@ public void handleQuit(final @Nullable Player player) { return; } - this.plugin.openCustomInventory(ResourcePackMenu.class, player); + this.plugin.getGuiManager().open("resource_pack_choice", player); }, 0L, 5L); return CompletableFuture.completedFuture(false); } @@ -1550,8 +1546,8 @@ public void handleQuit(final @Nullable Player player) { .exceptionally( throwable -> { componentLogger.error( - "An error occurred while sending the resource pack to " + this.nickname, - throwable + "An error occurred while sending the resource pack to {}", + this.nickname, throwable ); this.kick( SOMETHING_WENT_WRONG_TITLE.asTranslatable(), @@ -1826,7 +1822,7 @@ public boolean sendPrivateDiscordMessage( return false; } - this.plugin.getDiscordManager().sendEmbeds(id, messageEmbed, other); + //this.plugin.getDiscordModule().sendEmbeds(id, messageEmbed, other); return true; } @@ -1844,7 +1840,7 @@ public boolean sendPrivateDiscordMessage(final @NotNull CharSequence message) { return false; } - this.plugin.getDiscordManager().sendMessage(id, message); + //this.plugin.getDiscordModule().sendMessage(id, message); return true; } @@ -1889,7 +1885,6 @@ public void hideNameTag() { /** * Updates the player's file and initializes the player's names - * @see PlayerFile#loadConfig(WhoMine, UUID, String) * @see PlayerInfo#initNames() */ public void update() { @@ -1926,7 +1921,7 @@ private void handleJoinTask() { new RegistrationProcess(this.plugin).registerPlayer(this); } else { if (this.playerFile.getConfig().getString("pronouns") == null) { - this.plugin.openCustomInventory(PronounMenu.class, player); + this.plugin.getGuiManager().open("pronouns_choice", player); } else { final Skin currentSkin = this.getCurrentSkin(); @@ -1940,7 +1935,7 @@ private void handleJoinTask() { this.teleportToLastLeaveLocation().thenAccept(result -> { if (result) { - sendJoinMessage(this); + MessageUtils.sendJoinMessage(this); } else { player.kick(); this.plugin.getLogger().warning( diff --git a/paper/src/main/java/com/minersstudios/whomine/player/PlayerName.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerName.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/player/PlayerName.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerName.java index e4e9a013..87bb8ba1 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/PlayerName.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerName.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.player; +package com.minersstudios.wholib.paper.player; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -7,8 +7,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static com.minersstudios.whomine.utility.ChatUtils.normalize; -import static com.minersstudios.whomine.utility.MessageUtils.Colors.*; +import static com.minersstudios.wholib.utility.ChatUtils.normalize; +import static com.minersstudios.wholib.paper.utility.MessageUtils.Colors.*; import static net.kyori.adventure.text.Component.text; /** @@ -18,6 +18,7 @@ * @see PlayerFile */ public final class PlayerName { + private @NotNull String nickname; private @NotNull String firstName; private @NotNull String lastName; diff --git a/paper/src/main/java/com/minersstudios/whomine/player/PlayerSettings.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerSettings.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/player/PlayerSettings.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerSettings.java index a61afa7f..1843d350 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/PlayerSettings.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/PlayerSettings.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.player; +package com.minersstudios.wholib.paper.player; -import com.minersstudios.whomine.player.skin.Skin; +import com.minersstudios.wholib.paper.player.skin.Skin; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/paper/src/main/java/com/minersstudios/whomine/player/Pronouns.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/Pronouns.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/player/Pronouns.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/Pronouns.java index 2e62ccf8..12103ccb 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/Pronouns.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/Pronouns.java @@ -1,15 +1,15 @@ -package com.minersstudios.whomine.player; +package com.minersstudios.wholib.paper.player; -import com.minersstudios.whomine.locale.LanguageFile; +import com.minersstudios.wholib.paper.locale.LangFileFabric; import net.kyori.adventure.text.TranslatableComponent; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; /** * Pronouns enum with custom messages. All messages stored in the - * {@link LanguageFile}. + * {@link LangFileFabric}. * * @see PlayerFile */ diff --git a/paper/src/main/java/com/minersstudios/whomine/player/RegistrationProcess.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/RegistrationProcess.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/player/RegistrationProcess.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/RegistrationProcess.java index eca5591c..f6b44e86 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/RegistrationProcess.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/RegistrationProcess.java @@ -1,11 +1,10 @@ -package com.minersstudios.whomine.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.SignMenu; -import com.minersstudios.whomine.locale.LanguageFile; -import com.minersstudios.whomine.menu.PronounMenu; -import com.minersstudios.whomine.utility.MSPlayerUtils; -import com.minersstudios.whomine.utility.MessageUtils; +package com.minersstudios.wholib.paper.player; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.SignMenu; +import com.minersstudios.wholib.paper.locale.LangFileFabric; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; +import com.minersstudios.wholib.paper.utility.MessageUtils; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Location; @@ -16,12 +15,12 @@ import java.util.Locale; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; /** * Registration process class. It is used to register a player on the server on - * the first join. All messages stored in the {@link LanguageFile}. + * the first join. All messages stored in the {@link LangFileFabric}. */ public final class RegistrationProcess { private final WhoMine plugin; @@ -147,7 +146,7 @@ private void setPatronymic() { this.sendDialogueMessage(REGISTRATION_MESSAGE_13.asTranslatable(), 150L); this.plugin.runTaskLater( - () -> this.plugin.openCustomInventory(PronounMenu.class, this.player), + () -> this.plugin.getGuiManager().open("pronouns_choice", this.player), 225L ); diff --git a/paper/src/main/java/com/minersstudios/whomine/player/ResourcePack.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/ResourcePack.java similarity index 84% rename from paper/src/main/java/com/minersstudios/whomine/player/ResourcePack.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/ResourcePack.java index 25099fff..e1cee8da 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/ResourcePack.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/ResourcePack.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.player; +package com.minersstudios.wholib.paper.player; //@Deprecated(forRemoval = true) public final class ResourcePack { diff --git a/paper/src/main/java/com/minersstudios/whomine/player/collection/IDMap.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/collection/IDMap.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/player/collection/IDMap.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/collection/IDMap.java index ca745e69..84873895 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/collection/IDMap.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/collection/IDMap.java @@ -1,10 +1,10 @@ -package com.minersstudios.whomine.player.collection; +package com.minersstudios.wholib.paper.player.collection; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.IDUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.utility.IDUtils; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; diff --git a/paper/src/main/java/com/minersstudios/whomine/player/collection/MuteMap.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/collection/MuteMap.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/player/collection/MuteMap.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/collection/MuteMap.java index eb248ff0..cceebad7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/collection/MuteMap.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/collection/MuteMap.java @@ -1,9 +1,9 @@ -package com.minersstudios.whomine.player.collection; +package com.minersstudios.wholib.paper.player.collection; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.mojang.util.InstantTypeAdapter; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.Contract; diff --git a/paper/src/main/java/com/minersstudios/whomine/player/collection/PlayerInfoMap.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/collection/PlayerInfoMap.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/player/collection/PlayerInfoMap.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/collection/PlayerInfoMap.java index e773263c..f41729b5 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/collection/PlayerInfoMap.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/collection/PlayerInfoMap.java @@ -1,9 +1,9 @@ -package com.minersstudios.whomine.player.collection; +package com.minersstudios.wholib.paper.player.collection; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.Contract; diff --git a/paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinDelayErrorJson.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinDelayErrorJson.java similarity index 83% rename from paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinDelayErrorJson.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinDelayErrorJson.java index 36656b41..410abe02 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinDelayErrorJson.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinDelayErrorJson.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.player.skin; +package com.minersstudios.wholib.paper.player.skin; /** * This class is a record class for the MineSkin API error response. It is used diff --git a/paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinErrorJson.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinErrorJson.java similarity index 82% rename from paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinErrorJson.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinErrorJson.java index e4c510f3..b113bc0b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinErrorJson.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinErrorJson.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.player.skin; +package com.minersstudios.wholib.paper.player.skin; /** * This class is a record class for the MineSkin API error response. It is used diff --git a/paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinJson.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinJson.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinJson.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinJson.java index a59ecd6e..56f79a1f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinJson.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinJson.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.player.skin; +package com.minersstudios.wholib.paper.player.skin; import com.google.gson.annotations.SerializedName; diff --git a/paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinResponse.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinResponse.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinResponse.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinResponse.java index 614ebf03..d1f9ca31 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/skin/MineSkinResponse.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/MineSkinResponse.java @@ -17,11 +17,11 @@ * License along with this program. If not, see * . */ -package com.minersstudios.whomine.player.skin; +package com.minersstudios.wholib.paper.player.skin; import com.google.gson.Gson; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.utility.ChatUtils; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -29,12 +29,10 @@ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; -import java.net.URL; +import java.net.URI; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import static com.minersstudios.whomine.player.skin.Skin.isValidSkinImg; - /** * Represents a response from the MineSkin API. */ @@ -71,13 +69,13 @@ private MineSkinResponse( final @NotNull WhoMine plugin, final @NotNull String link ) throws IOException, IllegalArgumentException { - if (!isValidSkinImg(link)) { + if (!Skin.isValidSkinImg(link)) { throw new IllegalArgumentException("The link must be a valid skin image"); } final String requestBody = "url=" + URLEncoder.encode(link, StandardCharsets.UTF_8); final String apiKey = plugin.getConfiguration().getMineSkinApiKey(); - final HttpURLConnection connection = (HttpURLConnection) new URL(MINE_SKIN_API_URL).openConnection(); + final HttpURLConnection connection = (HttpURLConnection) URI.create(MINE_SKIN_API_URL).toURL().openConnection(); connection.setRequestMethod("POST"); connection.setConnectTimeout(90000); diff --git a/paper/src/main/java/com/minersstudios/whomine/player/skin/Skin.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/Skin.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/player/skin/Skin.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/Skin.java index 710b6a5b..6f760550 100644 --- a/paper/src/main/java/com/minersstudios/whomine/player/skin/Skin.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/player/skin/Skin.java @@ -1,9 +1,9 @@ -package com.minersstudios.whomine.player.skin; +package com.minersstudios.wholib.paper.player.skin; import com.destroystokyo.paper.profile.CraftPlayerProfile; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.player.PlayerFile; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.utility.ChatUtils; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -18,7 +18,7 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; -import java.net.URL; +import java.net.URI; import java.time.Duration; import java.time.Instant; import java.util.Base64; @@ -217,6 +217,7 @@ public int hashCode() { * @return True if the skin's name, value, and signature are equal */ @Contract("null -> false") + @Override public boolean equals(final @Nullable Object obj) { return obj == this || ( @@ -309,7 +310,7 @@ public boolean equals(final @Nullable Object obj) { */ public static boolean isValidSkinImg(final @NotNull String link) { try { - final BufferedImage image = ImageIO.read(new URL(link)); + final BufferedImage image = ImageIO.read(URI.create(link).toURL()); return image != null && image.getWidth() == 64 && image.getHeight() == 64; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePack.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePack.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePack.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePack.java index e535f3d8..d18f9bec 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePack.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePack.java @@ -1,8 +1,8 @@ -package com.minersstudios.whomine.resourcepack; +package com.minersstudios.wholib.paper.resourcepack; -import com.minersstudios.whomine.resourcepack.data.ResourcePackData; -import com.minersstudios.whomine.resourcepack.throwable.FatalPackLoadException; -import com.minersstudios.whomine.resourcepack.throwable.PackLoadException; +import com.minersstudios.wholib.paper.resourcepack.data.ResourcePackData; +import com.minersstudios.wholib.paper.resourcepack.throwable.FatalPackLoadException; +import com.minersstudios.wholib.paper.resourcepack.throwable.PackLoadException; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.kyori.adventure.text.Component; import org.bukkit.configuration.ConfigurationSection; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePackApplier.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePackApplier.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePackApplier.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePackApplier.java index addcac02..c503b77a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePackApplier.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePackApplier.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.resourcepack; +package com.minersstudios.wholib.paper.resourcepack; -import com.minersstudios.whomine.resourcepack.data.ResourcePackData; +import com.minersstudios.wholib.paper.resourcepack.data.ResourcePackData; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.resource.ResourcePackRequest; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePackLoader.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePackLoader.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePackLoader.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePackLoader.java index 29644d74..1d81aa23 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePackLoader.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePackLoader.java @@ -1,13 +1,13 @@ -package com.minersstudios.whomine.resourcepack; - -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.resourcepack.resource.PackResourceManager; -import com.minersstudios.whomine.resourcepack.throwable.PackLoadException; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.resourcepack.data.ResourcePackData; -import com.minersstudios.whomine.resourcepack.resource.GitHubPackResourceManager; -import com.minersstudios.whomine.resource.github.Tag; -import com.minersstudios.whomine.resourcepack.throwable.FatalPackLoadException; +package com.minersstudios.wholib.paper.resourcepack; + +import com.minersstudios.wholib.paper.resourcepack.data.ResourcePackData; +import com.minersstudios.wholib.paper.resourcepack.resource.GitHubPackResourceManager; +import com.minersstudios.wholib.paper.resourcepack.resource.PackResourceManager; +import com.minersstudios.wholib.paper.resourcepack.throwable.FatalPackLoadException; +import com.minersstudios.wholib.paper.resourcepack.throwable.PackLoadException; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.resource.github.Tag; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -24,8 +24,8 @@ import java.util.function.Consumer; import java.util.function.Function; -import static com.minersstudios.whomine.resourcepack.ResourcePack.create; -import static com.minersstudios.whomine.resourcepack.ResourcePack.entry; +import static com.minersstudios.wholib.paper.resourcepack.ResourcePack.create; +import static com.minersstudios.wholib.paper.resourcepack.ResourcePack.entry; import static java.util.concurrent.CompletableFuture.completedFuture; public final class ResourcePackLoader { diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePackRegistry.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePackRegistry.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePackRegistry.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePackRegistry.java index ef59237f..45005e87 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/ResourcePackRegistry.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/ResourcePackRegistry.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.resourcepack; +package com.minersstudios.wholib.paper.resourcepack; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.Contract; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/data/EmptyResourcePackData.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/data/EmptyResourcePackData.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/data/EmptyResourcePackData.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/data/EmptyResourcePackData.java index 30cbfb20..75d8df49 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/data/EmptyResourcePackData.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/data/EmptyResourcePackData.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.resourcepack.data; +package com.minersstudios.wholib.paper.resourcepack.data; import net.kyori.adventure.resource.ResourcePackInfo; import net.kyori.adventure.text.Component; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/data/ResourcePackData.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/data/ResourcePackData.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/data/ResourcePackData.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/data/ResourcePackData.java index 288b0b23..d1e3205c 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/data/ResourcePackData.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/data/ResourcePackData.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.resourcepack.data; +package com.minersstudios.wholib.paper.resourcepack.data; -import com.minersstudios.whomine.resourcepack.resource.PackResourceManager; +import com.minersstudios.wholib.paper.resourcepack.resource.PackResourceManager; import net.kyori.adventure.resource.ResourcePackInfo; import net.kyori.adventure.resource.ResourcePackInfoLike; import net.kyori.adventure.text.Component; @@ -137,6 +137,7 @@ public interface ResourcePackData extends ResourcePackInfoLike { * @throws UnsupportedOperationException If the data {@link #isEmpty()} */ @Contract(" -> new") + @Override @NotNull ResourcePackInfo asResourcePackInfo() throws UnsupportedOperationException; /** diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/data/ResourcePackDataImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/data/ResourcePackDataImpl.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/data/ResourcePackDataImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/data/ResourcePackDataImpl.java index ba4c9425..c6c14d5b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/data/ResourcePackDataImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/data/ResourcePackDataImpl.java @@ -1,9 +1,9 @@ -package com.minersstudios.whomine.resourcepack.data; +package com.minersstudios.wholib.paper.resourcepack.data; -import com.minersstudios.whomine.resourcepack.resource.PackResourceManager; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.resourcepack.resource.GitHubPackResourceManager; -import com.minersstudios.whomine.resource.github.Tag; +import com.minersstudios.wholib.paper.resourcepack.resource.PackResourceManager; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.resourcepack.resource.GitHubPackResourceManager; +import com.minersstudios.wholib.resource.github.Tag; import net.kyori.adventure.resource.ResourcePackInfo; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.Contract; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/resource/GitHubPackResourceManager.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/resource/GitHubPackResourceManager.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/resource/GitHubPackResourceManager.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/resource/GitHubPackResourceManager.java index 7384fd9b..74292fee 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/resource/GitHubPackResourceManager.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/resource/GitHubPackResourceManager.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.resourcepack.resource; +package com.minersstudios.wholib.paper.resourcepack.resource; -import com.minersstudios.whomine.resource.github.AbstractGithubResourceManager; +import com.minersstudios.wholib.resource.github.AbstractGithubResourceManager; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/resource/PackResourceManager.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/resource/PackResourceManager.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/resource/PackResourceManager.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/resource/PackResourceManager.java index b0564778..ce402aed 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/resource/PackResourceManager.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/resource/PackResourceManager.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.resourcepack.resource; +package com.minersstudios.wholib.paper.resourcepack.resource; -import com.minersstudios.whomine.resource.ResourceManager; +import com.minersstudios.wholib.resource.ResourceManager; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/resource/URIPackResourceManager.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/resource/URIPackResourceManager.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/resource/URIPackResourceManager.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/resource/URIPackResourceManager.java index d0b5801d..2040947f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/resource/URIPackResourceManager.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/resource/URIPackResourceManager.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.resourcepack.resource; +package com.minersstudios.wholib.paper.resourcepack.resource; -import com.minersstudios.whomine.resource.uri.AbstractURIResourceManager; +import com.minersstudios.wholib.resource.uri.AbstractURIResourceManager; import org.jetbrains.annotations.NotNull; import javax.annotation.concurrent.Immutable; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/throwable/FatalPackLoadException.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/throwable/FatalPackLoadException.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/throwable/FatalPackLoadException.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/throwable/FatalPackLoadException.java index 53947c77..5c79761b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/throwable/FatalPackLoadException.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/throwable/FatalPackLoadException.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.resourcepack.throwable; +package com.minersstudios.wholib.paper.resourcepack.throwable; import org.jetbrains.annotations.Nullable; diff --git a/paper/src/main/java/com/minersstudios/whomine/resourcepack/throwable/PackLoadException.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/throwable/PackLoadException.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/resourcepack/throwable/PackLoadException.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/throwable/PackLoadException.java index e651acc5..57770d9d 100644 --- a/paper/src/main/java/com/minersstudios/whomine/resourcepack/throwable/PackLoadException.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/resourcepack/throwable/PackLoadException.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.resourcepack.throwable; +package com.minersstudios.wholib.paper.resourcepack.throwable; import org.jetbrains.annotations.Nullable; diff --git a/paper/src/main/java/com/minersstudios/whomine/scheduler/TaskExecutor.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/scheduler/TaskExecutor.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/scheduler/TaskExecutor.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/scheduler/TaskExecutor.java index 9707e9ec..c81d322e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/scheduler/TaskExecutor.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/scheduler/TaskExecutor.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.scheduler; +package com.minersstudios.wholib.paper.scheduler; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/ApiConverter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/ApiConverter.java new file mode 100644 index 00000000..4c57d8ed --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/ApiConverter.java @@ -0,0 +1,50 @@ +package com.minersstudios.wholib.paper.utility; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.utility.ResourcedPath; +import org.bukkit.NamespacedKey; +import org.bukkit.event.EventPriority; +import org.intellij.lang.annotations.Subst; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +public final class ApiConverter { + + @Contract(" -> fail") + private ApiConverter() throws AssertionError { + throw new AssertionError("Utility class"); + } + + public static @NotNull NamespacedKey apiToBukkit(final @NotNull ResourcedPath resourcedPath) { + return new NamespacedKey(resourcedPath.getResource(), resourcedPath.getPath()); + } + + public static @NotNull ResourcedPath bukkitToApi(final @NotNull NamespacedKey key) { + final @Subst("resource") String resource = key.getNamespace(); + final @Subst("path") String path = key.getKey(); + + return ResourcedPath.of(resource, path); + } + + public static @NotNull EventPriority apiToBukkit(final @NotNull EventOrder order) { + return switch (order) { + case LOWEST -> EventPriority.LOWEST; + case LOW -> EventPriority.LOW; + case NORMAL -> EventPriority.NORMAL; + case HIGH -> EventPriority.HIGH; + case HIGHEST -> EventPriority.HIGHEST; + case CUSTOM -> EventPriority.MONITOR; + }; + } + + public static @NotNull EventOrder bukkitToApi(final @NotNull EventPriority priority) { + return switch (priority) { + case LOWEST -> EventOrder.LOWEST; + case LOW -> EventOrder.LOW; + case NORMAL -> EventOrder.NORMAL; + case HIGH -> EventOrder.HIGH; + case HIGHEST -> EventOrder.HIGHEST; + case MONITOR -> EventOrder.CUSTOM; + }; + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/BlockUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/BlockUtils.java similarity index 86% rename from paper/src/main/java/com/minersstudios/whomine/utility/BlockUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/BlockUtils.java index 138cfec0..772854b0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/BlockUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/BlockUtils.java @@ -1,19 +1,24 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Material; import org.bukkit.SoundGroup; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.v1_20_R3.CraftSoundGroup; -import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntityType; +import org.bukkit.craftbukkit.CraftSoundGroup; +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.entity.EntityType; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.EnumSet; import java.util.Locale; import java.util.Map; @@ -401,29 +406,29 @@ public static boolean isReplaceable(final @NotNull Material material) { public static boolean isIgnorableEntity(final @NotNull EntityType entityType) { return switch (entityType) { // - case DROPPED_ITEM, - ITEM_FRAME, - GLOW_ITEM_FRAME, - LIGHTNING, - LLAMA_SPIT, - EXPERIENCE_ORB, - THROWN_EXP_BOTTLE, - EGG, - SPLASH_POTION, - FIREWORK, - FIREBALL, - FISHING_HOOK, - SMALL_FIREBALL, - SNOWBALL, - TRIDENT, - WITHER_SKULL, - DRAGON_FIREBALL, - AREA_EFFECT_CLOUD, - ARROW, - SPECTRAL_ARROW, - ENDER_PEARL, - EVOKER_FANGS, - LEASH_HITCH -> true; + case ITEM, + ITEM_FRAME, + GLOW_ITEM_FRAME, + LIGHTNING_BOLT, + LLAMA_SPIT, + EXPERIENCE_ORB, + EXPERIENCE_BOTTLE, + EGG, + POTION, + FIREWORK_ROCKET, + FIREBALL, + FISHING_BOBBER, + SMALL_FIREBALL, + SNOWBALL, + TRIDENT, + WITHER_SKULL, + DRAGON_FIREBALL, + AREA_EFFECT_CLOUD, + ARROW, + SPECTRAL_ARROW, + ENDER_PEARL, + EVOKER_FANGS, + LEASH_KNOT -> true; // default -> false; }; @@ -442,4 +447,34 @@ private static boolean isBreaksOnBlockPlace(final Material material) { || material == Material.LARGE_FERN || material == Material.TALL_SEAGRASS; } + + public static void editBlockStrength( + final @NotNull net.minecraft.world.level.block.Block block, + final float hardness, + final float resistance + ) { + block.properties().strength(hardness, resistance); + + final BlockState newNoteBlockState = block.defaultBlockState(); + + try { + final Field destroySpeedField = BlockBehaviour.BlockStateBase.class.getDeclaredField("destroySpeed"); + + destroySpeedField.setAccessible(true); + destroySpeedField.set(newNoteBlockState, -1.0f); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + + try { + final Method registerDefaultState = net.minecraft.world.level.block.Block.class.getDeclaredMethod("registerDefaultState", BlockState.class); + + registerDefaultState.setAccessible(true); + registerDefaultState.invoke(block, newNoteBlockState); + } catch (final NoSuchMethodException e) { + MSLogger.severe("Could not find Block#registerDefaultState method", e); + } catch (final InvocationTargetException | IllegalAccessException e) { + MSLogger.severe("Could not invoke Block#registerDefaultState method", e); + } + } } diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/CoreProtectUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/CoreProtectUtils.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/utility/CoreProtectUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/CoreProtectUtils.java index fdbd3880..c4ba256a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/CoreProtectUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/CoreProtectUtils.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; import net.coreprotect.CoreProtectAPI; import org.bukkit.Location; diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/DateUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/DateUtils.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/utility/DateUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/DateUtils.java index 24c67dbb..6ffddf82 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/DateUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/DateUtils.java @@ -1,5 +1,7 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.SharedConstants; import org.apache.commons.lang3.StringUtils; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -13,7 +15,7 @@ import java.io.InputStreamReader; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.URL; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.DateTimeException; import java.time.Instant; @@ -58,7 +60,7 @@ private DateUtils() throws AssertionError { } try ( - final var input = new URL("http://ip-api.com/json/" + ip.getHostAddress()).openStream(); + final var input = URI.create("http://ip-api.com/json/" + ip.getHostAddress()).toURL().openStream(); final var reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)) ) { final StringBuilder entirePage = new StringBuilder(); diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/ItemUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/ItemUtils.java similarity index 78% rename from paper/src/main/java/com/minersstudios/whomine/utility/ItemUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/ItemUtils.java index c7831d7c..49aa6730 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/ItemUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/ItemUtils.java @@ -1,9 +1,7 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; -import com.minersstudios.whomine.custom.item.damageable.DamageableItem; -import net.minecraft.world.item.Item; +import com.minersstudios.wholib.paper.custom.item.damageable.DamageableItem; import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerItemDamageEvent; import org.bukkit.inventory.EquipmentSlot; @@ -14,12 +12,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Field; import java.util.Collection; -import java.util.logging.Level; import static org.bukkit.EntityEffect.*; -import static org.bukkit.enchantments.Enchantment.DURABILITY; +import static org.bukkit.enchantments.Enchantment.UNBREAKING; /** * Utility class for {@link ItemStack} and {@link ItemMeta} @@ -150,16 +146,16 @@ public static boolean damageItem( damageableItem.setRealDamage(damageableItem.getRealDamage() + originalDamage); if ( - !damageable.hasEnchant(DURABILITY) - || Math.random() < 1.0d / (damageable.getEnchantLevel(DURABILITY) + 1.0d) + !damageable.hasEnchant(UNBREAKING) + || Math.random() < 1.0d / (damageable.getEnchantLevel(UNBREAKING) + 1.0d) ) { damage = originalDamage; damageableItem.saveForItemStack(item); } } else if ( - !damageable.hasEnchant(DURABILITY) - || Math.random() < 1.0d / (damageable.getEnchantLevel(DURABILITY) + 1.0d) + !damageable.hasEnchant(UNBREAKING) + || Math.random() < 1.0d / (damageable.getEnchantLevel(UNBREAKING) + 1.0d) ) { damage = originalDamage; @@ -201,41 +197,4 @@ public static boolean damageItem( return true; } - - /** - * Sets the max stack size of the specified material to the specified value - * - * @param material The material, whose max stack size will be changed - * @param maxStackSize The new max stack size - * @see NMS Item - */ - public static void setMaxStackSize( - final @NotNull Material material, - final int maxStackSize - ) { - try { - @SuppressWarnings("JavaReflectionMemberAccess") - final Field nmsSize = Item.class.getDeclaredField("d"); // Obfuscated "maxStackSize" field name - - nmsSize.setAccessible(true); - nmsSize.setInt( - CraftItemStack.asNMSCopy(new ItemStack(material)).getItem(), - maxStackSize - ); - - final Field bukkitSize = Material.class.getDeclaredField("maxStack"); - - bukkitSize.setAccessible(true); - bukkitSize.setInt( - material, - maxStackSize - ); - } catch (final Throwable e) { - MSLogger.log( - Level.SEVERE, - "Failed to set max stack size for : " + material, - e - ); - } - } } diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/LocationUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/LocationUtils.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/utility/LocationUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/LocationUtils.java index 71c68bd7..4ac637e9 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/LocationUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/LocationUtils.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; -import com.minersstudios.whomine.world.location.MSBoundingBox; +import com.minersstudios.wholib.paper.world.location.MSBoundingBox; import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/MSBlockUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSBlockUtils.java similarity index 77% rename from paper/src/main/java/com/minersstudios/whomine/utility/MSBlockUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSBlockUtils.java index 59e56427..20c08c72 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/MSBlockUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSBlockUtils.java @@ -1,8 +1,10 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -15,7 +17,7 @@ * Utility class for {@link CustomBlockData} */ public final class MSBlockUtils { - public static final String NAMESPACED_KEY_REGEX = '(' + SharedConstants.MSBLOCK_NAMESPACE + "):(" + Key.REGEX + ")"; + public static final String NAMESPACED_KEY_REGEX = '(' + Resource.WMBLOCK + "):(" + Path.REGEX + ")"; public static final Pattern NAMESPACED_KEY_PATTERN = Pattern.compile(NAMESPACED_KEY_REGEX); @Contract(" -> fail") diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/MSCustomUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSCustomUtils.java similarity index 81% rename from paper/src/main/java/com/minersstudios/whomine/utility/MSCustomUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSCustomUtils.java index 5eca470b..b3897b31 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/MSCustomUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSCustomUtils.java @@ -1,15 +1,16 @@ -package com.minersstudios.whomine.utility; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.api.annotation.Namespace; -import com.minersstudios.whomine.api.annotation.ResourceKey; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.custom.decor.CustomDecorData; -import com.minersstudios.whomine.custom.decor.CustomDecorType; -import com.minersstudios.whomine.custom.item.CustomItem; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.custom.item.renameable.RenameableItemRegistry; +package com.minersstudios.wholib.paper.utility; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.annotation.ResourcePath; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorData; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorType; +import com.minersstudios.wholib.paper.custom.item.CustomItem; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItemRegistry; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -22,7 +23,7 @@ import java.util.Optional; -import static com.minersstudios.whomine.utility.SharedConstants.*; +import static com.minersstudios.wholib.annotation.Resource.*; /** * Utility class for custom items / blocks / decor. @@ -49,7 +50,7 @@ private MSCustomUtils() throws AssertionError { * or empty optional if not found * @see #getItemStack(String, String) */ - public static @NotNull Optional getItemStack(final @Subst("namespace:key") @ResourceKey @Nullable String namespacedKeyStr) { + public static @NotNull Optional getItemStack(final @Subst("namespace:key") @ResourcePath @Nullable String namespacedKeyStr) { if (ChatUtils.isBlank(namespacedKeyStr)) { return Optional.empty(); } @@ -102,15 +103,15 @@ private MSCustomUtils() throws AssertionError { * @see MSItemUtils#getItemStack(String) */ public static @NotNull Optional getItemStack( - final @Namespace @Nullable String namespace, - final @Key @Nullable String key + final @Resource @Nullable String namespace, + final @Path @Nullable String key ) { return namespace == null || key == null ? Optional.empty() : switch (namespace) { - case MSBLOCK_NAMESPACE -> MSBlockUtils.getItemStack(key); - case MSDECOR_NAMESPACE -> MSDecorUtils.getItemStack(key); - case MSITEMS_NAMESPACE -> MSItemUtils.getItemStack(key); + case WMBLOCK -> MSBlockUtils.getItemStack(key); + case WMDECOR -> MSDecorUtils.getItemStack(key); + case WMITEM -> MSItemUtils.getItemStack(key); default -> Optional.empty(); }; } @@ -159,7 +160,7 @@ private MSCustomUtils() throws AssertionError { * or {@link CustomItem} or empty optional if not found * @see #getCustom(String, String) */ - public static @NotNull Optional getCustom(final @Subst("namespace:key") @ResourceKey @Nullable String namespacedKeyStr) { + public static @NotNull Optional getCustom(final @Subst("namespace:key") @ResourcePath @Nullable String namespacedKeyStr) { if ( ChatUtils.isBlank(namespacedKeyStr) || !namespacedKeyStr.contains(":") @@ -218,18 +219,18 @@ private MSCustomUtils() throws AssertionError { * @see CustomItemType#fromKey(String) */ public static @NotNull Optional getCustom( - final @Namespace @Nullable String namespace, - final @Key @Nullable String key + final @Resource @Nullable String namespace, + final @Path @Nullable String key ) { return ChatUtils.isBlank(namespace) || ChatUtils.isBlank(key) ? Optional.empty() : switch (namespace) { - case MSBLOCK_NAMESPACE, - MSBLOCK_NAMESPACE + ":type" -> CustomBlockRegistry.fromKey(key); - case MSDECOR_NAMESPACE, - MSDECOR_NAMESPACE + ":type" -> CustomDecorData.fromKey(key); - case MSITEMS_NAMESPACE, - MSITEMS_NAMESPACE + ":type" -> CustomItem.fromKey(key); + case WMBLOCK, + WMBLOCK + ":type" -> CustomBlockRegistry.fromKey(key); + case WMDECOR, + WMDECOR + ":type" -> CustomDecorData.fromKey(key); + case WMITEM, + WMITEM + ":type" -> CustomItem.fromKey(key); default -> Optional.empty(); }; } diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/MSDecorUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSDecorUtils.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/utility/MSDecorUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSDecorUtils.java index d01cf903..d319efa7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/MSDecorUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSDecorUtils.java @@ -1,14 +1,16 @@ -package com.minersstudios.whomine.utility; - -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.world.location.MSBoundingBox; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.custom.decor.CustomDecorData; -import com.minersstudios.whomine.custom.decor.DecorHitBox; +package com.minersstudios.wholib.paper.utility; + +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.world.location.MSBoundingBox; +import com.minersstudios.wholib.paper.world.location.MSPosition; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorData; +import com.minersstudios.wholib.paper.custom.decor.DecorHitBox; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Interaction; import org.bukkit.inventory.ItemStack; @@ -23,7 +25,7 @@ * Utility class for {@link CustomDecorData} */ public final class MSDecorUtils { - public static final String NAMESPACED_KEY_REGEX = '(' + SharedConstants.MSDECOR_NAMESPACE + "):(" + Key.REGEX + ")"; + public static final String NAMESPACED_KEY_REGEX = '(' + Resource.WMDECOR + "):(" + Path.REGEX + ")"; public static final Pattern NAMESPACED_KEY_PATTERN = Pattern.compile(NAMESPACED_KEY_REGEX); @Contract(" -> fail") @@ -103,7 +105,7 @@ private MSDecorUtils() throws AssertionError { ); return entities.isEmpty() ? null - : (Interaction) entities.get(0).getBukkitEntity(); + : (Interaction) entities.getFirst().getBukkitEntity(); } /** diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/MSItemUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSItemUtils.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/utility/MSItemUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSItemUtils.java index 4972df94..e773bc42 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/MSItemUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSItemUtils.java @@ -1,8 +1,10 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; -import com.minersstudios.whomine.api.annotation.Key; -import com.minersstudios.whomine.custom.item.CustomItem; -import com.minersstudios.whomine.custom.item.CustomItemType; +import com.minersstudios.wholib.annotation.Path; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItem; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -15,7 +17,7 @@ * Utility class for {@link CustomItem} */ public final class MSItemUtils { - public static final String NAMESPACED_KEY_REGEX = '(' + SharedConstants.MSITEMS_NAMESPACE + "):(" + Key.REGEX + ")"; + public static final String NAMESPACED_KEY_REGEX = '(' + Resource.WMITEM + "):(" + Path.REGEX + ")"; public static final Pattern NAMESPACED_KEY_PATTERN = Pattern.compile(NAMESPACED_KEY_REGEX); @Contract(" -> fail") diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/MSLogger.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSLogger.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/utility/MSLogger.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSLogger.java index f4a33433..e84105d8 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/MSLogger.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSLogger.java @@ -1,7 +1,8 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.locale.TranslationRegistry; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.locale.TranslationRegistry; import io.papermc.paper.adventure.PaperAdventure; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TranslatableComponent; @@ -35,6 +36,7 @@ *

      • {@link Level#FINE} - Green
      • *
      */ +@SuppressWarnings("unused") public final class MSLogger { private static final Logger LOGGER = Logger.getLogger(WhoMine.class.getSimpleName()); @@ -51,7 +53,7 @@ private MSLogger() throws AssertionError { } /** - * Logs a message with the specified severity level. If the level is + * Logs a message with the specified severity level. If the level is * {@link Level#FINE}, the message will be logged with the {@link Level#INFO} * level and colored lime green. * @@ -67,7 +69,7 @@ public static void log( } /** - * Logs a message with the specified severity level. If the level is + * Logs a message with the specified severity level. If the level is * {@link Level#FINE}, the message will be logged with the {@link Level#INFO} * level and colored lime green. * @@ -87,8 +89,8 @@ public static void log( } /** - * Log a message with the specified severity level and associated array of - * parameters. If the level is {@link Level#FINE}, the message will be + * Log a message with the specified severity level and associated array of + * parameters. If the level is {@link Level#FINE}, the message will be * logged with the {@link Level#INFO} level and colored lime green. * * @param level One of the message level identifiers @@ -105,8 +107,8 @@ public static void log( } /** - * Log a message with the specified severity level and associated array of - * parameters. If the level is {@link Level#FINE}, the message will be + * Log a message with the specified severity level and associated array of + * parameters. If the level is {@link Level#FINE}, the message will be * logged with the {@link Level#INFO} level and colored lime green. * * @param level One of the message level identifiers @@ -146,7 +148,7 @@ public static void log( /** * Logs a message with the specified severity level and associated throwable. - * If the level is {@link Level#FINE}, the message will be logged with the + * If the level is {@link Level#FINE}, the message will be logged with the * {@link Level#INFO} level and colored lime green. * * @param level One of the message level identifiers @@ -228,7 +230,7 @@ public static void logChat( target.sendMessage( switch (level.intValue()) { case SEVERE -> space().append(Font.Components.RED_EXCLAMATION_MARK).append(space()) - .append(coloredMessage); + .append(coloredMessage); case WARNING -> space().append(Font.Components.YELLOW_EXCLAMATION_MARK).append(space()) .append(coloredMessage); case FINE -> space().append(Font.Components.GREEN_EXCLAMATION_MARK).append(space()) @@ -260,7 +262,7 @@ public static void severe(final @NotNull Component message) { } /** - * Logs a message with the {@link Level#SEVERE} severity level and + * Logs a message with the {@link Level#SEVERE} severity level and * associated array of parameters * * @param message The string message @@ -275,7 +277,7 @@ public static void severe( } /** - * Logs a message with the {@link Level#SEVERE} severity level and + * Logs a message with the {@link Level#SEVERE} severity level and * associated array of parameters * * @param message The component message @@ -305,7 +307,7 @@ public static void severe( } /** - * Logs a message with the {@link Level#SEVERE} severity level and + * Logs a message with the {@link Level#SEVERE} severity level and * associated throwable * * @param message The component message @@ -320,7 +322,7 @@ public static void severe( } /** - * Logs a message with the {@link Level#SEVERE} severity level to the + * Logs a message with the {@link Level#SEVERE} severity level to the * specified target * * @param sender The target to send the message to @@ -336,7 +338,7 @@ public static void severe( } /** - * Logs a message with the {@link Level#SEVERE} severity level to the + * Logs a message with the {@link Level#SEVERE} severity level to the * specified target * * @param sender The target to send the message to @@ -372,7 +374,7 @@ public static void warning(final @NotNull Component message) { } /** - * Logs a message with the {@link Level#WARNING} severity level and + * Logs a message with the {@link Level#WARNING} severity level and * associated array of parameters * * @param message The string message @@ -402,7 +404,7 @@ public static void warning( } /** - * Logs a message with the {@link Level#WARNING} severity level and + * Logs a message with the {@link Level#WARNING} severity level and * associated throwable * * @param message The string message @@ -417,7 +419,7 @@ public static void warning( } /** - * Logs a message with the {@link Level#WARNING} severity level and + * Logs a message with the {@link Level#WARNING} severity level and * associated throwable * * @param message The component message @@ -484,7 +486,7 @@ public static void info(final @NotNull Component message) { } /** - * Logs a message with the {@link Level#INFO} severity level and associated + * Logs a message with the {@link Level#INFO} severity level and associated * array of parameters * * @param message The string message @@ -499,7 +501,7 @@ public static void info( } /** - * Logs a message with the {@link Level#INFO} severity level and associated + * Logs a message with the {@link Level#INFO} severity level and associated * array of parameters * * @param message The component message @@ -514,7 +516,7 @@ public static void info( } /** - * Logs a message with the {@link Level#INFO} severity level and associated + * Logs a message with the {@link Level#INFO} severity level and associated * throwable * * @param message The string message @@ -529,7 +531,7 @@ public static void info( } /** - * Logs a message with the {@link Level#INFO} severity level and associated + * Logs a message with the {@link Level#INFO} severity level and associated * throwable * * @param message The component message @@ -544,7 +546,7 @@ public static void info( } /** - * Logs a message with the {@link Level#INFO} severity level to the + * Logs a message with the {@link Level#INFO} severity level to the * specified target * * @param sender The target to send the message to @@ -596,7 +598,7 @@ public static void fine(final @NotNull Component message) { } /** - * Logs a message with the {@link Level#FINE} severity level and associated + * Logs a message with the {@link Level#FINE} severity level and associated * array of parameters * * @param message The string message @@ -611,7 +613,7 @@ public static void fine( } /** - * Logs a message with the {@link Level#FINE} severity level and associated + * Logs a message with the {@link Level#FINE} severity level and associated * array of parameters * * @param message The component message @@ -626,7 +628,7 @@ public static void fine( } /** - * Logs a message with the {@link Level#FINE} severity level and associated + * Logs a message with the {@link Level#FINE} severity level and associated * throwable * * @param message The string message @@ -641,7 +643,7 @@ public static void fine( } /** - * Logs a message with the {@link Level#FINE} severity level and associated + * Logs a message with the {@link Level#FINE} severity level and associated * throwable * * @param message The component message @@ -656,7 +658,7 @@ public static void fine( } /** - * Logs a message with the {@link Level#FINE} severity level to the + * Logs a message with the {@link Level#FINE} severity level to the * specified target * * @param sender The target to send the message to diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/MSPlayerUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSPlayerUtils.java similarity index 82% rename from paper/src/main/java/com/minersstudios/whomine/utility/MSPlayerUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSPlayerUtils.java index afdeb2a4..5d3728e0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/MSPlayerUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MSPlayerUtils.java @@ -1,8 +1,9 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Scoreboard; @@ -38,10 +39,10 @@ public static void hideNameTag( final @NotNull WhoMine plugin, final @Nullable Player player ) { - if (player != null) { - plugin.getScoreboardHideTagsTeam().addEntry(player.getName()); - player.setScoreboard(plugin.getScoreboardHideTags()); - } + //if (player != null) { + // plugin.getScoreboardHideTagsTeam().addEntry(player.getName()); + // player.setScoreboard(plugin.getScoreboardHideTags()); + //} } /** diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/MessageUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MessageUtils.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/utility/MessageUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MessageUtils.java index eb546628..1a04e0f8 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/MessageUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/MessageUtils.java @@ -1,19 +1,20 @@ -package com.minersstudios.whomine.utility; - -import com.minersstudios.whomine.Config; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.locale.TranslationRegistry; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.chat.ChatType; -import com.minersstudios.whomine.discord.DiscordManager; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.world.WorldDark; +package com.minersstudios.wholib.paper.utility; + +import com.minersstudios.wholib.paper.PaperConfig; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.locale.TranslationRegistry; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.chat.ChatType; +import com.minersstudios.wholib.paper.discord.DiscordManager; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.world.WorldDark; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -21,7 +22,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static com.minersstudios.whomine.utility.MessageUtils.Colors.*; +import static com.minersstudios.wholib.paper.utility.MessageUtils.Colors.*; import static net.kyori.adventure.text.Component.*; public final class MessageUtils { @@ -37,13 +38,16 @@ private MessageUtils() throws AssertionError { * @param message message */ public static void sendGlobalMessage(final @NotNull Component message) { - final WorldDark worldDark = WhoMine.singleton().getCache().getWorldDark(); + WhoMine.singleton() + .ifPresent(module -> { + final WorldDark worldDark = module.getCache().getWorldDark(); - for (final var player : Bukkit.getOnlinePlayers()) { - if (!worldDark.isInWorldDark(player)) { - player.sendMessage(message); - } - } + for (final var player : module.getServer().getOnlinePlayers()) { + if (!worldDark.isInWorldDark(player)) { + player.sendMessage(message); + } + } + }); } /** @@ -58,10 +62,14 @@ public static void sendLocalMessage( final @NotNull Location location, final double radius ) { - WhoMine.singleton().runTask( - () -> location.getWorld().getNearbyPlayers(location, radius) - .forEach(player -> player.sendMessage(message)) - ); + WhoMine.singleton() + .ifPresent(module -> + module.runTask(() -> + location.getWorld() + .getNearbyPlayers(location, radius) + .forEach(player -> player.sendMessage(message)) + ) + ); } /** @@ -78,9 +86,14 @@ public static void sendMessageToChat( final @NotNull ChatType chatType, final @NotNull Component message ) { - final WhoMine plugin = WhoMine.singleton(); - final Config config = plugin.getConfiguration(); - final DiscordManager discordManager = plugin.getDiscordManager(); + final WhoMine module = WhoMine.singleton().orElse(null); + + if (module == null) { + return; + } + + final PaperConfig config = module.getConfiguration(); + final DiscordManager discordManager = module.getDiscordModule(); if (chatType == ChatType.LOCAL && location != null) { final Component localMessage = space() @@ -97,7 +110,7 @@ public static void sendMessageToChat( ); sendLocalMessage(localMessage, location, config.getLocalChatRadius()); - plugin.runTaskAsync( + module.runTaskAsync( () -> discordManager.sendMessage(ChatType.LOCAL, stringLocalMessage) ); MSLogger.info(null, localMessage); @@ -119,7 +132,7 @@ public static void sendMessageToChat( ); sendGlobalMessage(globalMessage); - plugin.runTaskAsync(() -> { + module.runTaskAsync(() -> { discordManager.sendMessage(ChatType.GLOBAL, stringGlobalMessage.replaceFirst("\\[WM]", "")); discordManager.sendMessage(ChatType.LOCAL, stringGlobalMessage); }); @@ -139,8 +152,13 @@ public static boolean sendPrivateMessage( final @NotNull PlayerInfo receiver, final @NotNull Component message ) { - final WhoMine plugin = WhoMine.singleton(); - final DiscordManager discordManager = plugin.getDiscordManager(); + final WhoMine plugin = WhoMine.singleton().orElse(null); + + if (plugin == null) { + return true; + } + + final DiscordManager discordManager = plugin.getDiscordModule(); final CommandSender commandSender = sender == plugin.getCache().getConsolePlayerInfo() ? plugin.getServer().getConsoleSender() : sender.getOnlinePlayer(); @@ -167,7 +185,7 @@ public static boolean sendPrivateMessage( .hoverEvent(HoverEvent.showText(text("Нажмите, чтобы написать приватное сообщение данному игроку", NamedTextColor.GRAY))) .clickEvent(ClickEvent.suggestCommand("/pm " + receiver.getID() + " "))) .color(CHAT_COLOR_PRIMARY)) - .append(message.color(CHAT_COLOR_SECONDARY)) + .append(message.color(CHAT_COLOR_SECONDARY)) ); receiverPlayer.sendMessage( Font.Components.SPEECH.append(sender.getDefaultName().append(text(" -> Вам : ")) @@ -199,9 +217,14 @@ public static void sendRPEventMessage( final @NotNull Component action, final @NotNull RolePlayActionType rolePlayActionType ) { - final WhoMine plugin = WhoMine.singleton(); - final Config config = plugin.getConfiguration(); - final DiscordManager discordManager = plugin.getDiscordManager(); + final WhoMine plugin = WhoMine.singleton().orElse(null); + + if (plugin == null) { + return; + } + + final PaperConfig config = plugin.getConfiguration(); + final DiscordManager discordManager = plugin.getDiscordModule(); final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(plugin, sender); final Component fullMessage = switch (rolePlayActionType) { case DO -> @@ -267,8 +290,13 @@ public static void sendDeathMessage( final @NotNull Player killed, final @Nullable Player killer ) { - final WhoMine plugin = WhoMine.singleton(); - final DiscordManager discordManager = plugin.getDiscordManager(); + final WhoMine plugin = WhoMine.singleton().orElse(null); + + if (plugin == null) { + return; + } + + final DiscordManager discordManager = plugin.getDiscordModule(); final Location deathLocation = killed.getLocation(); final PlayerInfo killedInfo = PlayerInfo.fromOnlinePlayer(plugin, killed); final PlayerInfo killerInfo = killer != null @@ -331,8 +359,13 @@ public static void sendJoinMessage(final @NotNull PlayerInfo playerInfo) { return; } - final WhoMine plugin = WhoMine.singleton(); - final DiscordManager discordManager = plugin.getDiscordManager(); + final WhoMine plugin = WhoMine.singleton().orElse(null); + + if (plugin == null) { + return; + } + + final DiscordManager discordManager = plugin.getDiscordModule(); final Component joinMessage = space() .append(playerInfo.getGoldenName() .append(space())) @@ -365,8 +398,13 @@ public static void sendQuitMessage( return; } - final WhoMine plugin = WhoMine.singleton(); - final DiscordManager discordManager = plugin.getDiscordManager(); + final WhoMine plugin = WhoMine.singleton().orElse(null); + + if (plugin == null) { + return; + } + + final DiscordManager discordManager = plugin.getDiscordModule(); final Component quitMessage = space() .append(playerInfo.getGoldenName() .append(space())) diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/PacketClassBinder.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/PacketClassBinder.java new file mode 100644 index 00000000..928c2157 --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/PacketClassBinder.java @@ -0,0 +1,260 @@ +package com.minersstudios.wholib.paper.utility; + +import com.minersstudios.wholib.packet.registry.*; +import net.minecraft.network.protocol.common.*; +import net.minecraft.network.protocol.configuration.*; +import net.minecraft.network.protocol.cookie.ClientboundCookieRequestPacket; +import net.minecraft.network.protocol.cookie.ServerboundCookieResponsePacket; +import net.minecraft.network.protocol.game.*; +import net.minecraft.network.protocol.handshake.ClientIntentionPacket; +import net.minecraft.network.protocol.login.*; +import net.minecraft.network.protocol.ping.ClientboundPongResponsePacket; +import net.minecraft.network.protocol.ping.ServerboundPingRequestPacket; +import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket; +import net.minecraft.network.protocol.status.ServerboundStatusRequestPacket; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; + +@ApiStatus.Internal +public final class PacketClassBinder { + + @Contract(" -> fail") + private PacketClassBinder() throws AssertionError { + throw new AssertionError("Utility class"); + } + + public static void bindAll() { + HandshakePackets.registry().byClass() + .put(ClientIntentionPacket.class, HandshakePackets.SERVER_HANDSHAKE); + + PlayPackets.registry().byClass() + .put(ClientboundBundlePacket.class, PlayPackets.CLIENT_BUNDLE_DELIMITER) + .put(ClientboundAddEntityPacket.class, PlayPackets.CLIENT_SPAWN_ENTITY) + .put(ClientboundAddExperienceOrbPacket.class, PlayPackets.CLIENT_SPAWN_EXPERIENCE_ORB) + .put(ClientboundAnimatePacket.class, PlayPackets.CLIENT_ENTITY_ANIMATION) + .put(ClientboundAwardStatsPacket.class, PlayPackets.CLIENT_AWARD_STATISTICS) + .put(ClientboundBlockChangedAckPacket.class, PlayPackets.CLIENT_ACKNOWLEDGE_BLOCK_CHANGE) + .put(ClientboundBlockDestructionPacket.class, PlayPackets.CLIENT_SET_BLOCK_DESTROY_STAGE) + .put(ClientboundBlockEntityDataPacket.class, PlayPackets.CLIENT_BLOCK_ENTITY_DATA) + .put(ClientboundBlockEventPacket.class, PlayPackets.CLIENT_BLOCK_ACTION) + .put(ClientboundBlockUpdatePacket.class, PlayPackets.CLIENT_BLOCK_UPDATE) + .put(ClientboundBossEventPacket.class, PlayPackets.CLIENT_BOSS_BAR) + .put(ClientboundChangeDifficultyPacket.class, PlayPackets.CLIENT_CHANGE_DIFFICULTY) + .put(ClientboundChunkBatchFinishedPacket.class, PlayPackets.CLIENT_CHUNK_BATCH_FINISHED) + .put(ClientboundChunkBatchStartPacket.class, PlayPackets.CLIENT_CHUNK_BATCH_START) + .put(ClientboundChunksBiomesPacket.class, PlayPackets.CLIENT_CHUNK_BIOMES) + .put(ClientboundClearTitlesPacket.class, PlayPackets.CLIENT_CLEAR_TITLES) + .put(ClientboundCommandSuggestionsPacket.class, PlayPackets.CLIENT_COMMAND_SUGGESTIONS_RESPONSE) + .put(ClientboundCommandsPacket.class, PlayPackets.CLIENT_COMMANDS) + .put(ClientboundContainerClosePacket.class, PlayPackets.CLIENT_CLOSE_CONTAINER) + .put(ClientboundContainerSetContentPacket.class, PlayPackets.CLIENT_SET_CONTAINER_CONTENT) + .put(ClientboundContainerSetDataPacket.class, PlayPackets.CLIENT_SET_CONTAINER_PROPERTY) + .put(ClientboundContainerSetSlotPacket.class, PlayPackets.CLIENT_SET_CONTAINER_SLOT) + .put(ClientboundCookieRequestPacket.class, PlayPackets.CLIENT_COOKIE_REQUEST) + .put(ClientboundCooldownPacket.class, PlayPackets.CLIENT_SET_COOLDOWN) + .put(ClientboundCustomChatCompletionsPacket.class, PlayPackets.CLIENT_CHAT_SUGGESTIONS) + .put(ClientboundCustomPayloadPacket.class, PlayPackets.CLIENT_PLUGIN_MESSAGE) + .put(ClientboundDamageEventPacket.class, PlayPackets.CLIENT_DAMAGE_EVENT) + .put(ClientboundDebugSamplePacket.class, PlayPackets.CLIENT_DEBUG_SAMPLE) + .put(ClientboundDeleteChatPacket.class, PlayPackets.CLIENT_DELETE_MESSAGE) + .put(ClientboundDisconnectPacket.class, PlayPackets.CLIENT_DISCONNECT) + .put(ClientboundDisguisedChatPacket.class, PlayPackets.CLIENT_DISGUISED_CHAT_MESSAGE) + .put(ClientboundEntityEventPacket.class, PlayPackets.CLIENT_ENTITY_EVENT) + .put(ClientboundExplodePacket.class, PlayPackets.CLIENT_EXPLOSION) + .put(ClientboundForgetLevelChunkPacket.class, PlayPackets.CLIENT_UNLOAD_CHUNK) + .put(ClientboundGameEventPacket.class, PlayPackets.CLIENT_GAME_EVENT) + .put(ClientboundHorseScreenOpenPacket.class, PlayPackets.CLIENT_OPEN_HORSE_SCREEN) + .put(ClientboundHurtAnimationPacket.class, PlayPackets.CLIENT_HURT_ANIMATION) + .put(ClientboundInitializeBorderPacket.class, PlayPackets.CLIENT_INITIALIZE_WORLD_BORDER) + .put(ClientboundKeepAlivePacket.class, PlayPackets.CLIENT_KEEP_ALIVE) + .put(ClientboundLevelChunkWithLightPacket.class, PlayPackets.CLIENT_CHUNK_DATA_AND_UPDATE_LIGHT) + .put(ClientboundLevelEventPacket.class, PlayPackets.CLIENT_WORLD_EVENT) + .put(ClientboundLevelParticlesPacket.class, PlayPackets.CLIENT_PARTICLE) + .put(ClientboundLightUpdatePacket.class, PlayPackets.CLIENT_UPDATE_LIGHT) + .put(ClientboundLoginPacket.class, PlayPackets.CLIENT_LOGIN) + .put(ClientboundMapItemDataPacket.class, PlayPackets.CLIENT_MAP_DATA) + .put(ClientboundMerchantOffersPacket.class, PlayPackets.CLIENT_MERCHANT_OFFERS) + .put(ClientboundMoveEntityPacket.Pos.class, PlayPackets.CLIENT_UPDATE_ENTITY_POSITION) + .put(ClientboundMoveEntityPacket.PosRot.class, PlayPackets.CLIENT_UPDATE_ENTITY_POSITION_AND_ROTATION) + .put(ClientboundMoveEntityPacket.Rot.class, PlayPackets.CLIENT_UPDATE_ENTITY_ROTATION) + .put(ClientboundMoveVehiclePacket.class, PlayPackets.CLIENT_MOVE_VEHICLE) + .put(ClientboundOpenBookPacket.class, PlayPackets.CLIENT_OPEN_BOOK) + .put(ClientboundOpenScreenPacket.class, PlayPackets.CLIENT_OPEN_SCREEN) + .put(ClientboundOpenSignEditorPacket.class, PlayPackets.CLIENT_OPEN_SIGN_EDITOR) + .put(ClientboundPingPacket.class, PlayPackets.CLIENT_PING) + .put(ClientboundPongResponsePacket.class, PlayPackets.CLIENT_PING_RESPONSE) + .put(ClientboundPlaceGhostRecipePacket.class, PlayPackets.CLIENT_PLACE_GHOST_RECIPE) + .put(ClientboundPlayerAbilitiesPacket.class, PlayPackets.CLIENT_PLAYER_ABILITIES) + .put(ClientboundPlayerChatPacket.class, PlayPackets.CLIENT_PLAYER_CHAT_MESSAGE) + .put(ClientboundPlayerCombatEndPacket.class, PlayPackets.CLIENT_END_COMBAT) + .put(ClientboundPlayerCombatEnterPacket.class, PlayPackets.CLIENT_ENTER_COMBAT) + .put(ClientboundPlayerCombatKillPacket.class, PlayPackets.CLIENT_COMBAT_DEATH) + .put(ClientboundPlayerInfoRemovePacket.class, PlayPackets.CLIENT_PLAYER_INFO_REMOVE) + .put(ClientboundPlayerInfoUpdatePacket.class, PlayPackets.CLIENT_PLAYER_INFO_UPDATE) + .put(ClientboundPlayerLookAtPacket.class, PlayPackets.CLIENT_LOOK_AT) + .put(ClientboundPlayerPositionPacket.class, PlayPackets.CLIENT_SYNCHRONIZE_PLAYER_POSITION) + .put(ClientboundRecipePacket.class, PlayPackets.CLIENT_UPDATE_RECIPE_BOOK) + .put(ClientboundRemoveEntitiesPacket.class, PlayPackets.CLIENT_REMOVE_ENTITIES) + .put(ClientboundRemoveMobEffectPacket.class, PlayPackets.CLIENT_REMOVE_ENTITY_EFFECT) + .put(ClientboundResetScorePacket.class, PlayPackets.CLIENT_RESET_SCORE) + .put(ClientboundResourcePackPopPacket.class, PlayPackets.CLIENT_REMOVE_RESOURCE_PACK) + .put(ClientboundResourcePackPushPacket.class, PlayPackets.CLIENT_ADD_RESOURCE_PACK) + .put(ClientboundRespawnPacket.class, PlayPackets.CLIENT_RESPAWN) + .put(ClientboundRotateHeadPacket.class, PlayPackets.CLIENT_SET_HEAD_ROTATION) + .put(ClientboundSectionBlocksUpdatePacket.class, PlayPackets.CLIENT_UPDATE_SECTION_BLOCKS) + .put(ClientboundSelectAdvancementsTabPacket.class, PlayPackets.CLIENT_SELECT_ADVANCEMENT_TAB) + .put(ClientboundServerDataPacket.class, PlayPackets.CLIENT_SERVER_DATA) + .put(ClientboundSetActionBarTextPacket.class, PlayPackets.CLIENT_SET_ACTION_BAR_TEXT) + .put(ClientboundSetBorderCenterPacket.class, PlayPackets.CLIENT_SET_BORDER_CENTER) + .put(ClientboundSetBorderLerpSizePacket.class, PlayPackets.CLIENT_SET_BORDER_LERP_SIZE) + .put(ClientboundSetBorderSizePacket.class, PlayPackets.CLIENT_SET_BORDER_SIZE) + .put(ClientboundSetBorderWarningDelayPacket.class, PlayPackets.CLIENT_SET_BORDER_WARNING_DELAY) + .put(ClientboundSetBorderWarningDistancePacket.class, PlayPackets.CLIENT_SET_BORDER_WARNING_DISTANCE) + .put(ClientboundSetCameraPacket.class, PlayPackets.CLIENT_SET_CAMERA) + .put(ClientboundSetCarriedItemPacket.class, PlayPackets.CLIENT_SET_HELD_ITEM) + .put(ClientboundSetChunkCacheCenterPacket.class, PlayPackets.CLIENT_SET_CENTER_CHUNK) + .put(ClientboundSetChunkCacheRadiusPacket.class, PlayPackets.CLIENT_SET_RENDER_DISTANCE) + .put(ClientboundSetDefaultSpawnPositionPacket.class, PlayPackets.CLIENT_SET_DEFAULT_SPAWN_POSITION) + .put(ClientboundSetDisplayObjectivePacket.class, PlayPackets.CLIENT_DISPLAY_OBJECTIVE) + .put(ClientboundSetEntityDataPacket.class, PlayPackets.CLIENT_SET_ENTITY_METADATA) + .put(ClientboundSetEntityLinkPacket.class, PlayPackets.CLIENT_LINK_ENTITIES) + .put(ClientboundSetEntityMotionPacket.class, PlayPackets.CLIENT_SET_ENTITY_VELOCITY) + .put(ClientboundSetEquipmentPacket.class, PlayPackets.CLIENT_SET_EQUIPMENT) + .put(ClientboundSetExperiencePacket.class, PlayPackets.CLIENT_SET_EXPERIENCE) + .put(ClientboundSetHealthPacket.class, PlayPackets.CLIENT_SET_HEALTH) + .put(ClientboundSetObjectivePacket.class, PlayPackets.CLIENT_UPDATE_OBJECTIVES) + .put(ClientboundSetPassengersPacket.class, PlayPackets.CLIENT_SET_PASSENGERS) + .put(ClientboundSetPlayerTeamPacket.class, PlayPackets.CLIENT_UPDATE_TEAMS) + .put(ClientboundSetScorePacket.class, PlayPackets.CLIENT_UPDATE_SCORE) + .put(ClientboundSetSimulationDistancePacket.class, PlayPackets.CLIENT_SET_SIMULATION_DISTANCE) + .put(ClientboundSetSubtitleTextPacket.class, PlayPackets.CLIENT_SET_SUBTITLE_TEXT) + .put(ClientboundSetTimePacket.class, PlayPackets.CLIENT_UPDATE_TIME) + .put(ClientboundSetTitleTextPacket.class, PlayPackets.CLIENT_SET_TITLE_TEXT) + .put(ClientboundSetTitlesAnimationPacket.class, PlayPackets.CLIENT_SET_TITLE_ANIMATION_TIMES) + .put(ClientboundSoundEntityPacket.class, PlayPackets.CLIENT_ENTITY_SOUND_EFFECT) + .put(ClientboundSoundPacket.class, PlayPackets.CLIENT_SOUND_EFFECT) + .put(ClientboundStartConfigurationPacket.class, PlayPackets.CLIENT_START_CONFIGURATION) + .put(ClientboundStopSoundPacket.class, PlayPackets.CLIENT_STOP_SOUND) + .put(ClientboundStoreCookiePacket.class, PlayPackets.CLIENT_STORE_COOKIE) + .put(ClientboundSystemChatPacket.class, PlayPackets.CLIENT_SYSTEM_CHAT_MESSAGE) + .put(ClientboundTabListPacket.class, PlayPackets.CLIENT_SET_TAB_LIST_HEADER_AND_FOOTER) + .put(ClientboundTagQueryPacket.class, PlayPackets.CLIENT_TAG_QUERY_RESPONSE) + .put(ClientboundTakeItemEntityPacket.class, PlayPackets.CLIENT_PICKUP_ITEM) + .put(ClientboundTeleportEntityPacket.class, PlayPackets.CLIENT_TELEPORT_ENTITY) + .put(ClientboundTickingStatePacket.class, PlayPackets.CLIENT_SET_TICKING_STATE) + .put(ClientboundTickingStepPacket.class, PlayPackets.CLIENT_STEP_TICK) + .put(ClientboundTransferPacket.class, PlayPackets.CLIENT_TRANSFER) + .put(ClientboundUpdateAdvancementsPacket.class, PlayPackets.CLIENT_UPDATE_ADVANCEMENTS) + .put(ClientboundUpdateAttributesPacket.class, PlayPackets.CLIENT_UPDATE_ATTRIBUTES) + .put(ClientboundUpdateMobEffectPacket.class, PlayPackets.CLIENT_ENTITY_EFFECT) + .put(ClientboundUpdateRecipesPacket.class, PlayPackets.CLIENT_UPDATE_RECIPES) + .put(ClientboundUpdateTagsPacket.class, PlayPackets.CLIENT_UPDATE_TAGS) + .put(ClientboundProjectilePowerPacket.class, PlayPackets.CLIENT_PROJECTILE_POWER) + .put(ClientboundCustomReportDetailsPacket.class, PlayPackets.CLIENT_CUSTOM_REPORT_DETAILS) + .put(ClientboundServerLinksPacket.class, PlayPackets.CLIENT_SERVER_LINKS) + .put(ServerboundAcceptTeleportationPacket.class, PlayPackets.SERVER_CONFIRM_TELEPORTATION) + .put(ServerboundBlockEntityTagQueryPacket.class, PlayPackets.SERVER_QUERY_BLOCK_ENTITY_TAG) + .put(ServerboundChangeDifficultyPacket.class, PlayPackets.SERVER_CHANGE_DIFFICULTY) + .put(ServerboundChatAckPacket.class, PlayPackets.SERVER_ACKNOWLEDGE_MESSAGE) + .put(ServerboundChatCommandPacket.class, PlayPackets.SERVER_CHAT_COMMAND) + .put(ServerboundChatCommandSignedPacket.class, PlayPackets.SERVER_SIGNED_CHAT_COMMAND) + .put(ServerboundChatPacket.class, PlayPackets.SERVER_CHAT_MESSAGE) + .put(ServerboundChatSessionUpdatePacket.class, PlayPackets.SERVER_PLAYER_SESSION) + .put(ServerboundChunkBatchReceivedPacket.class, PlayPackets.SERVER_CHUNK_BATCH_RECEIVED) + .put(ServerboundClientCommandPacket.class, PlayPackets.SERVER_CLIENT_STATUS) + .put(ServerboundClientInformationPacket.class, PlayPackets.SERVER_CLIENT_INFORMATION) + .put(ServerboundCommandSuggestionPacket.class, PlayPackets.SERVER_COMMAND_SUGGESTIONS_REQUEST) + .put(ServerboundConfigurationAcknowledgedPacket.class, PlayPackets.SERVER_ACKNOWLEDGE_CONFIGURATION) + .put(ServerboundContainerButtonClickPacket.class, PlayPackets.SERVER_CLICK_CONTAINER_BUTTON) + .put(ServerboundContainerClickPacket.class, PlayPackets.SERVER_CLICK_CONTAINER) + .put(ServerboundContainerClosePacket.class, PlayPackets.SERVER_CLOSE_CONTAINER) + .put(ServerboundContainerSlotStateChangedPacket.class, PlayPackets.SERVER_CHANGE_CONTAINER_SLOT_STATE) + .put(ServerboundCookieResponsePacket.class, PlayPackets.SERVER_COOKIE_RESPONSE) + .put(ServerboundCustomPayloadPacket.class, PlayPackets.SERVER_PLUGIN_MESSAGE) + .put(ServerboundDebugSampleSubscriptionPacket.class, PlayPackets.SERVER_DEBUG_SAMPLE_SUBSCRIPTION) + .put(ServerboundEditBookPacket.class, PlayPackets.SERVER_EDIT_BOOK) + .put(ServerboundEntityTagQueryPacket.class, PlayPackets.SERVER_QUERY_ENTITY_TAG) + .put(ServerboundInteractPacket.class, PlayPackets.SERVER_INTERACT) + .put(ServerboundJigsawGeneratePacket.class, PlayPackets.SERVER_JIGSAW_GENERATE) + .put(ServerboundKeepAlivePacket.class, PlayPackets.SERVER_KEEP_ALIVE) + .put(ServerboundLockDifficultyPacket.class, PlayPackets.SERVER_LOCK_DIFFICULTY) + .put(ServerboundMovePlayerPacket.Pos.class, PlayPackets.SERVER_SET_PLAYER_POSITION) + .put(ServerboundMovePlayerPacket.PosRot.class, PlayPackets.SERVER_SET_PLAYER_POSITION_AND_ROTATION) + .put(ServerboundMovePlayerPacket.Rot.class, PlayPackets.SERVER_SET_PLAYER_ROTATION) + .put(ServerboundMovePlayerPacket.StatusOnly.class, PlayPackets.SERVER_SET_PLAYER_ON_GROUND) + .put(ServerboundMoveVehiclePacket.class, PlayPackets.SERVER_MOVE_VEHICLE) + .put(ServerboundPaddleBoatPacket.class, PlayPackets.SERVER_PADDLE_BOAT) + .put(ServerboundPickItemPacket.class, PlayPackets.SERVER_PICK_ITEM) + .put(ServerboundPingRequestPacket.class, PlayPackets.SERVER_PING_REQUEST) + .put(ServerboundPlaceRecipePacket.class, PlayPackets.SERVER_PLACE_RECIPE) + .put(ServerboundPlayerAbilitiesPacket.class, PlayPackets.SERVER_PLAYER_ABILITIES) + .put(ServerboundPlayerActionPacket.class, PlayPackets.SERVER_PLAYER_ACTION) + .put(ServerboundPlayerCommandPacket.class, PlayPackets.SERVER_PLAYER_COMMAND) + .put(ServerboundPlayerInputPacket.class, PlayPackets.SERVER_PLAYER_INPUT) + .put(ServerboundPongPacket.class, PlayPackets.SERVER_PONG) + .put(ServerboundRecipeBookChangeSettingsPacket.class, PlayPackets.SERVER_CHANGE_RECIPE_BOOK_SETTINGS) + .put(ServerboundRecipeBookSeenRecipePacket.class, PlayPackets.SERVER_SET_SEEN_RECIPE) + .put(ServerboundRenameItemPacket.class, PlayPackets.SERVER_RENAME_ITEM) + .put(ServerboundResourcePackPacket.class, PlayPackets.SERVER_RESOURCE_PACK_RESPONSE) + .put(ServerboundSeenAdvancementsPacket.class, PlayPackets.SERVER_SEEN_ADVANCEMENTS) + .put(ServerboundSelectTradePacket.class, PlayPackets.SERVER_SELECT_TRADE) + .put(ServerboundSetBeaconPacket.class, PlayPackets.SERVER_SET_BEACON_EFFECT) + .put(ServerboundSetCarriedItemPacket.class, PlayPackets.SERVER_SET_HELD_ITEM) + .put(ServerboundSetCommandBlockPacket.class, PlayPackets.SERVER_PROGRAM_COMMAND_BLOCK) + .put(ServerboundSetCommandMinecartPacket.class, PlayPackets.SERVER_PROGRAM_COMMAND_BLOCK_MINECART) + .put(ServerboundSetCreativeModeSlotPacket.class, PlayPackets.SERVER_SET_CREATIVE_MODE_SLOT) + .put(ServerboundSetJigsawBlockPacket.class, PlayPackets.SERVER_PROGRAM_JIGSAW_BLOCK) + .put(ServerboundSetStructureBlockPacket.class, PlayPackets.SERVER_PROGRAM_STRUCTURE_BLOCK) + .put(ServerboundSignUpdatePacket.class, PlayPackets.SERVER_UPDATE_SIGN) + .put(ServerboundSwingPacket.class, PlayPackets.SERVER_SWING_ARM) + .put(ServerboundTeleportToEntityPacket.class, PlayPackets.SERVER_TELEPORT_TO_ENTITY) + .put(ServerboundUseItemOnPacket.class, PlayPackets.SERVER_USE_ITEM_ON) + .put(ServerboundUseItemPacket.class, PlayPackets.SERVER_USE_ITEM); + + StatusPackets.registry().byClass() + .put(ClientboundStatusResponsePacket.class, StatusPackets.CLIENT_STATUS_RESPONSE) + .put(ClientboundPongResponsePacket.class, StatusPackets.CLIENT_PONG_RESPONSE) + .put(ServerboundStatusRequestPacket.class, StatusPackets.SERVER_STATUS_REQUEST) + .put(ServerboundPingRequestPacket.class, StatusPackets.SERVER_PING_REQUEST); + + LoginPackets.registry().byClass() + .put(ClientboundLoginDisconnectPacket.class, LoginPackets.CLIENT_DISCONNECT) + .put(ClientboundHelloPacket.class, LoginPackets.CLIENT_ENCRYPTION_REQUEST) + .put(ClientboundGameProfilePacket.class, LoginPackets.CLIENT_LOGIN_SUCCESS) + .put(ClientboundLoginCompressionPacket.class, LoginPackets.CLIENT_SET_COMPRESSION) + .put(ClientboundCustomQueryPacket.class, LoginPackets.CLIENT_LOGIN_PLUGIN_REQUEST) + .put(ClientboundCookieRequestPacket.class, LoginPackets.CLIENT_COOKIE_REQUEST) + .put(ServerboundHelloPacket.class, LoginPackets.SERVER_LOGIN_START) + .put(ServerboundKeyPacket.class, LoginPackets.SERVER_ENCRYPTION_RESPONSE) + .put(ServerboundCustomQueryAnswerPacket.class, LoginPackets.SERVER_LOGIN_PLUGIN_RESPONSE) + .put(ServerboundLoginAcknowledgedPacket.class, LoginPackets.SERVER_LOGIN_ACKNOWLEDGED) + .put(ServerboundCookieResponsePacket.class, LoginPackets.SERVER_COOKIE_RESPONSE); + + ConfigurationPackets.registry().byClass() + .put(ClientboundCookieRequestPacket.class, ConfigurationPackets.CLIENT_COOKIE_REQUEST) + .put(ClientboundCustomPayloadPacket.class, ConfigurationPackets.CLIENT_PLUGIN_MESSAGE) + .put(ClientboundDisconnectPacket.class, ConfigurationPackets.CLIENT_DISCONNECT) + .put(ClientboundFinishConfigurationPacket.class, ConfigurationPackets.CLIENT_FINISH_CONFIGURATION) + .put(ClientboundKeepAlivePacket.class, ConfigurationPackets.CLIENT_KEEP_ALIVE) + .put(ClientboundPingPacket.class, ConfigurationPackets.CLIENT_PING) + .put(ClientboundResetChatPacket.class, ConfigurationPackets.CLIENT_RESET_CHAT) + .put(ClientboundRegistryDataPacket.class, ConfigurationPackets.CLIENT_REGISTRY_DATA) + .put(ClientboundResourcePackPopPacket.class, ConfigurationPackets.CLIENT_REMOVE_RESOURCE_PACK) + .put(ClientboundResourcePackPushPacket.class, ConfigurationPackets.CLIENT_ADD_RESOURCE_PACK) + .put(ClientboundStoreCookiePacket.class, ConfigurationPackets.CLIENT_STORE_COOKIE) + .put(ClientboundTransferPacket.class, ConfigurationPackets.CLIENT_TRANSFER) + .put(ClientboundUpdateEnabledFeaturesPacket.class, ConfigurationPackets.CLIENT_FEATURE_FLAGS) + .put(ClientboundUpdateTagsPacket.class, ConfigurationPackets.CLIENT_UPDATE_TAGS) + .put(ClientboundSelectKnownPacks.class, ConfigurationPackets.CLIENT_KNOWN_PACKS) + .put(ClientboundCustomReportDetailsPacket.class, ConfigurationPackets.CLIENT_CUSTOM_REPORT_DETAILS) + .put(ClientboundServerLinksPacket.class, ConfigurationPackets.CLIENT_SERVER_LINKS) + .put(ServerboundClientInformationPacket.class, ConfigurationPackets.SERVER_CLIENT_INFORMATION) + .put(ServerboundCookieResponsePacket.class, ConfigurationPackets.SERVER_COOKIE_RESPONSE) + .put(ServerboundCustomPayloadPacket.class, ConfigurationPackets.SERVER_PLUGIN_MESSAGE) + .put(ServerboundFinishConfigurationPacket.class, ConfigurationPackets.SERVER_ACKNOWLEDGE_FINISH_CONFIGURATION) + .put(ServerboundKeepAlivePacket.class, ConfigurationPackets.SERVER_KEEP_ALIVE) + .put(ServerboundPongPacket.class, ConfigurationPackets.SERVER_PONG) + .put(ServerboundResourcePackPacket.class, ConfigurationPackets.SERVER_RESOURCE_PACK_RESPONSE) + .put(ServerboundSelectKnownPacks.class, ConfigurationPackets.SERVER_KNOWN_PACKS); + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/PaperUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/PaperUtils.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/utility/PaperUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/PaperUtils.java index 9de8650c..c5676056 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/PaperUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/PaperUtils.java @@ -1,12 +1,13 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; import com.google.common.base.Joiner; +import io.papermc.paper.configuration.PaperConfigurations; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.server.MinecraftServer; import org.bukkit.Server; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.craftbukkit.v1_20_R3.CraftServer; +import org.bukkit.craftbukkit.CraftServer; import org.jetbrains.annotations.*; import javax.annotation.concurrent.Immutable; @@ -20,6 +21,11 @@ * Utility class for paper */ public final class PaperUtils { + public static final String PAPER_GLOBAL_CONFIG_FILE_NAME = "paper-global.yml"; + public static final String PAPER_WORLD_DEFAULTS_CONFIG_FILE_NAME = "paper-world-defaults.yml"; + public static final String PAPER_WORLD_CONFIG_FILE_NAME = "paper-world.yml"; + public static final String PAPER_GLOBAL_CONFIG_PATH = PaperConfigurations.CONFIG_DIR + '/' + PAPER_GLOBAL_CONFIG_FILE_NAME; + public static final String PAPER_WORLD_DEFAULTS_PATH = PaperConfigurations.CONFIG_DIR + '/' + PAPER_WORLD_DEFAULTS_CONFIG_FILE_NAME; @Contract(" -> fail") private PaperUtils() throws AssertionError { @@ -276,8 +282,8 @@ public boolean isEmpty() { } public enum ConfigType { - GLOBAL(SharedConstants.PAPER_GLOBAL_CONFIG_PATH), - WORLD_DEFAULTS(SharedConstants.PAPER_WORLD_DEFAULTS_PATH); + GLOBAL(PAPER_GLOBAL_CONFIG_PATH), + WORLD_DEFAULTS(PAPER_WORLD_DEFAULTS_PATH); private final String filePath; diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/PlayerUtils.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/PlayerUtils.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/utility/PlayerUtils.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/PlayerUtils.java index 579b455c..9af97d4a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/PlayerUtils.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/utility/PlayerUtils.java @@ -1,10 +1,11 @@ -package com.minersstudios.whomine.utility; +package com.minersstudios.wholib.paper.utility; import com.destroystokyo.paper.profile.CraftPlayerProfile; import com.destroystokyo.paper.profile.PlayerProfile; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.ShulkerBoxMenu; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.inventory.ShulkerBoxMenu; +import com.minersstudios.wholib.paper.player.PlayerInfo; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; @@ -29,10 +30,10 @@ import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; import org.bukkit.block.ShulkerBox; -import org.bukkit.craftbukkit.v1_20_R3.CraftServer; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventory; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -237,7 +238,7 @@ public static void setSkin( connection.send( new ClientboundRespawnPacket( new CommonPlayerSpawnInfo( - serverLevel.dimensionTypeId(), + serverLevel.dimensionTypeRegistration(), serverLevel.dimension(), BiomeManager.obfuscateSeed(serverLevel.getSeed()), gameMode.getGameModeForPlayer(), @@ -262,7 +263,7 @@ public static void setSkin( ); for (final var mobEffect : serverPlayer.getActiveEffects()) { - connection.send(new ClientboundUpdateMobEffectPacket(serverPlayer.getId(), mobEffect)); + connection.send(new ClientboundUpdateMobEffectPacket(serverPlayer.getId(), mobEffect, true)); } if (player.isOp()) { @@ -410,24 +411,24 @@ public static void openShulkerBoxSilent( private static boolean isIgnorableEntity(final @NotNull EntityType entityType) { return switch (entityType) { // - case DROPPED_ITEM, - ARROW, - SPECTRAL_ARROW, - AREA_EFFECT_CLOUD, - DRAGON_FIREBALL, - EGG, - FISHING_HOOK, - WITHER_SKULL, - TRIDENT, - SNOWBALL, - SMALL_FIREBALL, - FIREBALL, - FIREWORK, - SPLASH_POTION, - THROWN_EXP_BOTTLE, - EXPERIENCE_ORB, - LLAMA_SPIT, - LIGHTNING -> true; + case ITEM, + ARROW, + SPECTRAL_ARROW, + AREA_EFFECT_CLOUD, + DRAGON_FIREBALL, + EGG, + FISHING_BOBBER, + WITHER_SKULL, + TRIDENT, + SNOWBALL, + SMALL_FIREBALL, + FIREBALL, + FIREWORK_ROCKET, + POTION, + EXPERIENCE_BOTTLE, + EXPERIENCE_ORB, + LLAMA_SPIT, + LIGHTNING_BOLT -> true; // default -> false; }; diff --git a/paper/src/main/java/com/minersstudios/whomine/world/WorldDark.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/WorldDark.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/world/WorldDark.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/world/WorldDark.java index 1da49d1a..d2a7d226 100644 --- a/paper/src/main/java/com/minersstudios/whomine/world/WorldDark.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/WorldDark.java @@ -1,10 +1,10 @@ -package com.minersstudios.whomine.world; +package com.minersstudios.wholib.paper.world; import net.kyori.adventure.util.TriState; import net.minecraft.server.level.ServerLevel; import org.bukkit.*; import org.bukkit.block.Biome; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; diff --git a/paper/src/main/java/com/minersstudios/whomine/world/location/MSBoundingBox.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/location/MSBoundingBox.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/world/location/MSBoundingBox.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/world/location/MSBoundingBox.java index 11719a1e..fe110f4f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/world/location/MSBoundingBox.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/location/MSBoundingBox.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.world.location; +package com.minersstudios.wholib.paper.world.location; -import io.papermc.paper.chunk.system.entity.EntityLookup; -import io.papermc.paper.world.ChunkEntitySlices; +import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.ChunkEntitySlices; +import ca.spottedleaf.moonrise.patches.chunk_system.level.entity.EntityLookup; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.core.BlockPos; import net.minecraft.core.Position; @@ -15,7 +15,7 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.util.Vector; import org.jetbrains.annotations.Contract; @@ -31,6 +31,9 @@ @SuppressWarnings("UnstableApiUsage") @Immutable public final class MSBoundingBox { + private static final int REGION_SHIFT = 5; + private static final int REGION_MASK = (1 << REGION_SHIFT) - 1; + private final double minX; private final double minY; private final double minZ; @@ -38,9 +41,6 @@ public final class MSBoundingBox { private final double maxY; private final double maxZ; - private static final int REGION_SHIFT = 5; - private static final int REGION_MASK = (1 << REGION_SHIFT) - 1; - /** * Creates a new bounding box with the given corner coordinates * @@ -1873,24 +1873,23 @@ public boolean isAllFinite() { */ @Override public int hashCode() { - long l = Double.doubleToLongBits(this.minX); - int i = (int)(l ^ l >>> 32); - l = Double.doubleToLongBits(this.minY); - i = 31 * i + (int)(l ^ l >>> 32); - l = Double.doubleToLongBits(this.minZ); - i = 31 * i + (int)(l ^ l >>> 32); - l = Double.doubleToLongBits(this.maxX); - i = 31 * i + (int)(l ^ l >>> 32); - l = Double.doubleToLongBits(this.maxY); - i = 31 * i + (int)(l ^ l >>> 32); - l = Double.doubleToLongBits(this.maxZ); - return 31 * i + (int)(l ^ l >>> 32); + final int prime = 31; + int i = Double.hashCode(this.minX); + + i = prime * i + Double.hashCode(this.minY); + i = prime * i + Double.hashCode(this.minZ); + i = prime * i + Double.hashCode(this.maxX); + i = prime * i + Double.hashCode(this.maxY); + i = prime * i + Double.hashCode(this.maxZ); + + return i; } /** * @param obj The object to compare this bounding box against * @return Whether the given object is equal to this bounding box */ + @Contract("null -> false") @Override public boolean equals(final @Nullable Object obj) { return this == obj @@ -1971,7 +1970,7 @@ public boolean equals(final @Nullable Object obj) { final AABB aabb = this.toAABB(); final var list = new ObjectArrayList(); - final EntityLookup entityLookup = level.getEntityLookup(); + final EntityLookup entityLookup = level.moonrise$getEntityLookup(); final int minChunkX = ((int) Math.floor(this.minX) - 2) >> 4; final int minChunkZ = ((int) Math.floor(this.minZ) - 2) >> 4; diff --git a/paper/src/main/java/com/minersstudios/whomine/world/location/MSPosition.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/location/MSPosition.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/world/location/MSPosition.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/world/location/MSPosition.java index 941b3e7b..03e01fc6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/world/location/MSPosition.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/location/MSPosition.java @@ -1,7 +1,7 @@ -package com.minersstudios.whomine.world.location; +package com.minersstudios.wholib.paper.world.location; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.LocationUtils; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.utility.LocationUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Position; import net.minecraft.core.Vec3i; @@ -11,7 +11,7 @@ import net.minecraft.world.phys.Vec3; import org.bukkit.*; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.util.Vector; import org.jetbrains.annotations.Contract; @@ -30,6 +30,7 @@ @SuppressWarnings("UnstableApiUsage") @Immutable public final class MSPosition implements Cloneable { + private Reference world; private double x; private double y; @@ -1091,9 +1092,9 @@ public int hashCode() { int hash = 3; hash = 19 * hash + Objects.hashCode(this.world()); - hash = 19 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32)); - hash = 19 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32)); - hash = 19 * hash + (int) (Double.doubleToLongBits(this.z) ^ (Double.doubleToLongBits(this.z) >>> 32)); + hash = 19 * hash + Long.hashCode(Double.doubleToLongBits(this.x)); + hash = 19 * hash + Long.hashCode(Double.doubleToLongBits(this.y)); + hash = 19 * hash + Long.hashCode(Double.doubleToLongBits(this.z)); hash = 19 * hash + Float.floatToIntBits(this.pitch); hash = 19 * hash + Float.floatToIntBits(this.yaw); @@ -1134,6 +1135,7 @@ public boolean equalsCoords( && Double.compare(z, this.z) == 0; } + @Contract("null -> false") @Override public boolean equals(final @Nullable Object obj) { return this == obj diff --git a/paper/src/main/java/com/minersstudios/whomine/world/location/MSVector.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/location/MSVector.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/world/location/MSVector.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/world/location/MSVector.java index a24efce8..391200bc 100644 --- a/paper/src/main/java/com/minersstudios/whomine/world/location/MSVector.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/location/MSVector.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.world.location; +package com.minersstudios.wholib.paper.world.location; import com.google.common.primitives.Doubles; import net.minecraft.core.BlockPos; @@ -17,13 +17,13 @@ @SuppressWarnings("UnstableApiUsage") @Immutable public final class MSVector { + private static final double EPSILON = 1E-4; + private static final MSVector ZERO = of(0.0d, 0.0d, 0.0d); + private final double x; private final double y; private final double z; - private static final double EPSILON = 1E-4; - private static final MSVector ZERO = of(0.0d, 0.0d, 0.0d); - private MSVector( double x, double y, @@ -852,6 +852,7 @@ public int hashCode() { return hash; } + @Contract("null -> false") @Override public boolean equals(final @Nullable Object obj) { return this == obj diff --git a/paper/src/main/java/com/minersstudios/whomine/world/sound/EmptySound.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/EmptySound.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/world/sound/EmptySound.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/EmptySound.java index 790e1346..d16490f9 100644 --- a/paper/src/main/java/com/minersstudios/whomine/world/sound/EmptySound.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/EmptySound.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.world.sound; +package com.minersstudios.wholib.paper.world.sound; -import com.minersstudios.whomine.world.location.MSPosition; +import com.minersstudios.wholib.paper.world.location.MSPosition; import org.bukkit.Location; import org.bukkit.SoundCategory; import org.bukkit.entity.Entity; diff --git a/paper/src/main/java/com/minersstudios/whomine/world/sound/Sound.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/Sound.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/world/sound/Sound.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/Sound.java index df30eb80..d87c1c6e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/world/sound/Sound.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/Sound.java @@ -1,7 +1,6 @@ -package com.minersstudios.whomine.world.sound; +package com.minersstudios.wholib.paper.world.sound; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.Config; +import com.minersstudios.wholib.paper.world.location.MSPosition; import net.minecraft.sounds.SoundEvent; import org.bukkit.Location; import org.bukkit.SoundCategory; @@ -118,10 +117,7 @@ public interface Sound { @NotNull Builder toBuilder(); /** - * Plays this Sound to the specified player. - *
      - * If the place sound is {@link SoundGroup#WOOD}, the wood place sound from - * the {@link Config} will be played instead. + * Plays this Sound to the specified player * * @param player The player to play this sound to * @param entity The entity source of this sound @@ -132,10 +128,7 @@ void play( ); /** - * Plays this Sound to the specified player. - *
      - * If the place sound is {@link SoundGroup#WOOD}, the wood place sound from - * the {@link Config} will be played instead. + * Plays this Sound to the specified player * * @param player The player to play this sound to * @param position The position to play this sound at @@ -146,10 +139,7 @@ void play( ); /** - * Plays this Sound to the specified player. - *
      - * If the place sound is {@link SoundGroup#WOOD}, the wood place sound from - * the {@link Config} will be played instead. + * Plays this Sound to the specified player * * @param player The player to play this sound to * @param location The location to play this sound at @@ -160,20 +150,14 @@ void play( ); /** - * Plays this sound at the specified entity in the world. - *
      - * If the place sound is {@link SoundGroup#WOOD}, the wood place sound from - * the {@link Config} will be played instead. + * Plays this sound at the specified entity in the world * * @param entity The entity source of this sound */ void play(final @NotNull Entity entity); /** - * Plays this Sound at the specified position in the world. - *
      - * If the place sound is {@link SoundGroup#WOOD}, the wood place sound from - * the {@link Config} will be played instead. + * Plays this Sound at the specified position in the world * * @param position The position to play this sound at * @throws IllegalStateException If the world of the position is null @@ -181,10 +165,7 @@ void play( void play(final @NotNull MSPosition position) throws IllegalStateException; /** - * Plays this Sound at the specified location in the world. - *
      - * If the place sound is {@link SoundGroup#WOOD}, the wood place sound from - * the {@link Config} will be played instead. + * Plays this Sound at the specified location in the world * * @param location The location to play this sound at * @throws IllegalStateException If the world of the location is null diff --git a/paper/src/main/java/com/minersstudios/whomine/world/sound/SoundAdapter.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/SoundAdapter.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/world/sound/SoundAdapter.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/SoundAdapter.java index 7b5d94f9..f0313c94 100644 --- a/paper/src/main/java/com/minersstudios/whomine/world/sound/SoundAdapter.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/SoundAdapter.java @@ -1,4 +1,4 @@ -package com.minersstudios.whomine.world.sound; +package com.minersstudios.wholib.paper.world.sound; import com.google.gson.*; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; diff --git a/paper/src/main/java/com/minersstudios/whomine/world/sound/SoundGroup.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/SoundGroup.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/world/sound/SoundGroup.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/SoundGroup.java index ff5fa7f5..8b12606d 100644 --- a/paper/src/main/java/com/minersstudios/whomine/world/sound/SoundGroup.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/SoundGroup.java @@ -1,6 +1,6 @@ -package com.minersstudios.whomine.world.sound; +package com.minersstudios.wholib.paper.world.sound; -import com.minersstudios.whomine.world.location.MSPosition; +import com.minersstudios.wholib.paper.world.location.MSPosition; import net.minecraft.world.level.block.SoundType; import org.bukkit.Location; import org.bukkit.SoundCategory; @@ -40,12 +40,8 @@ @SuppressWarnings("unused") @Immutable public final class SoundGroup { - private final Sound placeSound; - private final Sound breakSound; - private final Sound hitSound; - private final Sound stepSound; - // + public static final SoundGroup EMPTY = create(SoundType.EMPTY); public static final SoundGroup WOOD = create(SoundType.WOOD); public static final SoundGroup GRAVEL = create(SoundType.GRAVEL); @@ -156,8 +152,14 @@ public final class SoundGroup { public static final SoundGroup TRIAL_SPAWNER = create(SoundType.TRIAL_SPAWNER); public static final SoundGroup SPONGE = create(SoundType.SPONGE); public static final SoundGroup WET_SPONGE = create(SoundType.WET_SPONGE); + // + private final Sound placeSound; + private final Sound breakSound; + private final Sound hitSound; + private final Sound stepSound; + private SoundGroup( final @NotNull Sound placeSound, final @NotNull Sound breakSound, @@ -610,6 +612,7 @@ public int hashCode() { * @param obj The reference object with which to compare * @return True if this SoundGroup is the same as the obj argument */ + @Contract("null -> false") @Override public boolean equals(final @Nullable Object obj) { return this == obj diff --git a/paper/src/main/java/com/minersstudios/whomine/world/sound/SoundImpl.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/SoundImpl.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/world/sound/SoundImpl.java rename to lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/SoundImpl.java index 064b5018..6e394262 100644 --- a/paper/src/main/java/com/minersstudios/whomine/world/sound/SoundImpl.java +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/SoundImpl.java @@ -1,9 +1,9 @@ -package com.minersstudios.whomine.world.sound; +package com.minersstudios.wholib.paper.world.sound; -import com.minersstudios.whomine.Config; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.paper.PaperConfig; +import com.minersstudios.wholib.paper.world.location.MSPosition; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.utility.ChatUtils; import net.minecraft.sounds.SoundEvent; import org.bukkit.Location; import org.bukkit.SoundCategory; @@ -20,18 +20,20 @@ @Immutable final class SoundImpl implements Sound { - private final String key; - private final SoundCategory category; - private final float volume; - private final float pitch; - // + private static final String WOOD_PLACE_SOUND_KEY = "block.wood.place"; private static final String WOOD_BREAK_SOUND_KEY = "block.wood.break"; private static final String WOOD_HIT_SOUND_KEY = "block.wood.hit"; private static final String WOOD_STEP_SOUND_KEY = "block.wood.step"; + // + private final String key; + private final SoundCategory category; + private final float volume; + private final float pitch; + SoundImpl(final @NotNull Builder builder) { this.key = builder.key(); this.category = builder.category(); @@ -138,6 +140,7 @@ public void play( ); } + @Override public void play(final @NotNull Entity entity) { entity.getWorld().playSound( entity, @@ -170,25 +173,25 @@ public void play(final @NotNull Location location) throws IllegalStateException ); } + // TODO: Add support for custom sound keys private @NotNull String getParsedKey() { - final WhoMine plugin = WhoMine.singleton(); - - if (plugin == null) { - return this.key; - } - - final Config config = plugin.getConfiguration(); - - return switch (this.key) { - case WOOD_PLACE_SOUND_KEY -> config.getWoodSoundPlace(); - case WOOD_BREAK_SOUND_KEY -> config.getWoodSoundBreak(); - case WOOD_HIT_SOUND_KEY -> config.getWoodSoundHit(); - case WOOD_STEP_SOUND_KEY -> config.getWoodSoundStep(); - default -> this.key; - }; + return WhoMine.singleton() + .map( + module -> { + final PaperConfig config = module.getConfiguration(); + + return switch (this.key) { + case WOOD_PLACE_SOUND_KEY -> config.getWoodSoundPlace(); + case WOOD_BREAK_SOUND_KEY -> config.getWoodSoundBreak(); + case WOOD_HIT_SOUND_KEY -> config.getWoodSoundHit(); + case WOOD_STEP_SOUND_KEY -> config.getWoodSoundStep(); + default -> this.key; + }; + } + ).orElseThrow(); } - static final class BuilderImpl implements Sound.Builder { + static final class BuilderImpl implements Builder { private String key; private SoundCategory category; private float volume; diff --git a/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/package-info.java b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/package-info.java new file mode 100644 index 00000000..298c89b4 --- /dev/null +++ b/lib/paper/src/main/java/com/minersstudios/wholib/paper/world/sound/package-info.java @@ -0,0 +1,12 @@ +/** + * Classes and interfaces related to sound functionality in the + * {@code MSCustoms} plugin. + *
      + * The classes in this package are responsible for playing sounds in the world + * or to the player. + * + * @see com.minersstudios.wholib.paper.world.sound.Sound + * @see com.minersstudios.wholib.paper.world.sound.SoundGroup + * @see com.minersstudios.wholib.paper.world.sound.SoundAdapter GSON adapter + */ +package com.minersstudios.wholib.paper.world.sound; diff --git a/lib/paper/src/test/java/com/minersstudios/wholib/paper/Main.java b/lib/paper/src/test/java/com/minersstudios/wholib/paper/Main.java new file mode 100644 index 00000000..2d73ad4f --- /dev/null +++ b/lib/paper/src/test/java/com/minersstudios/wholib/paper/Main.java @@ -0,0 +1,8 @@ +package com.minersstudios.wholib.paper; + +public final class Main { + + public static void main(final String[] args) { + System.out.println("Hello, Demmicat!"); + } +} diff --git a/lib/velocity/build.gradle.kts b/lib/velocity/build.gradle.kts new file mode 100644 index 00000000..30428201 --- /dev/null +++ b/lib/velocity/build.gradle.kts @@ -0,0 +1,4 @@ +plugins { + id("whomine.library") + id("whomine.velocitypowered") +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/VelocityCache.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/VelocityCache.java new file mode 100644 index 00000000..8f9dbd5f --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/VelocityCache.java @@ -0,0 +1,17 @@ +package com.minersstudios.wholib.velocity; + +import com.minersstudios.wholib.module.AbstractModuleComponent; +import com.minersstudios.wholib.module.components.Cache; +import org.jetbrains.annotations.NotNull; + +public final class VelocityCache extends AbstractModuleComponent implements Cache { + + /** + * Module component constructor + * + * @param module The module instance + */ + public VelocityCache(final @NotNull WhoMine module) { + super(module); + } +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/VelocityConfig.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/VelocityConfig.java new file mode 100644 index 00000000..c925d125 --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/VelocityConfig.java @@ -0,0 +1,24 @@ +package com.minersstudios.wholib.velocity; + +import com.minersstudios.wholib.module.AbstractModuleComponent; +import com.minersstudios.wholib.module.components.Configuration; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public final class VelocityConfig extends AbstractModuleComponent implements Configuration { + + /** + * Module component constructor + * + * @param module The module instance + */ + public VelocityConfig(final @NotNull WhoMine module) { + super(module); + } + + @Override + public @NotNull File getFile() { + return null; + } +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/WhoMine.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/WhoMine.java new file mode 100644 index 00000000..beb74791 --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/WhoMine.java @@ -0,0 +1,65 @@ +package com.minersstudios.wholib.velocity; + +import com.minersstudios.wholib.module.MainModule; +import com.minersstudios.wholib.velocity.discord.DiscordModuleImpl; +import com.minersstudios.wholib.velocity.gui.VelocityGuiManager; +import com.minersstudios.wholib.velocity.listener.VelocityListenerManager; +import com.velocitypowered.api.proxy.ProxyServer; +import org.jetbrains.annotations.NotNull; + +import java.nio.file.Path; +import java.util.logging.Logger; + +/** + * Represents a WhoMine module + */ +public interface WhoMine extends MainModule { + + /** + * Returns the server of the module + * + * @return The server of the module + */ + @NotNull ProxyServer getServer(); + + /** + * Returns the logger of the module + * + * @return The logger of the module + */ + @NotNull Logger getLogger(); + + /** + * Returns the data directory of the module + * + * @return The data directory of the module + */ + @NotNull Path getDataDirectory(); + + @Override + @NotNull VelocityCache getCache(); + + @Override + @NotNull VelocityConfig getConfiguration(); + + /** + * Returns the listener manager of the module + * + * @return The listener manager of the module + */ + @NotNull VelocityListenerManager getListenerManager(); + + /** + * Returns the gui manager of the module + * + * @return The gui manager of the module + */ + @NotNull VelocityGuiManager getGuiManager(); + + /** + * Returns the discord module + * + * @return The discord module + */ + @NotNull DiscordModuleImpl getDiscordModule(); +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/discord/DiscordModuleImpl.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/discord/DiscordModuleImpl.java new file mode 100644 index 00000000..2f6e678d --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/discord/DiscordModuleImpl.java @@ -0,0 +1,19 @@ +package com.minersstudios.wholib.velocity.discord; + +import com.minersstudios.wholib.discord.DiscordModule; +import com.minersstudios.wholib.status.StatusHandler; +import org.jetbrains.annotations.NotNull; + +public class DiscordModuleImpl implements DiscordModule { + + private final StatusHandler statusHandler; + + public DiscordModuleImpl() { + this.statusHandler = new StatusHandler(); + } + + @Override + public @NotNull StatusHandler getStatusHandler() { + return this.statusHandler; + } +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/event/VelocityEventContainer.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/event/VelocityEventContainer.java new file mode 100644 index 00000000..54ea9dd6 --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/event/VelocityEventContainer.java @@ -0,0 +1,43 @@ +package com.minersstudios.wholib.velocity.event; + +import com.minersstudios.wholib.velocity.WhoMine; +import com.minersstudios.wholib.event.EventContainer; +import org.jetbrains.annotations.NotNull; + +/** + * Represents a velocity event container. + *

      + * It contains : + *

        + *
      • The main module that registers and handles the event
      • + *
      • The event itself
      • + *
      + * + * @param The event type + * + * @see VelocityEventListener + */ +@SuppressWarnings("unused") +public class VelocityEventContainer extends EventContainer { + + private VelocityEventContainer( + final @NotNull WhoMine module, + final @NotNull E event + ) { + super(module, event); + } + + /** + * Creates a new paper event container with the given module and event + * + * @param module The main module that registers and handles the event + * @param event The event associated with this container + * @return A new container instance + */ + public static @NotNull VelocityEventContainer of( + final @NotNull WhoMine module, + final @NotNull E event + ) { + return new VelocityEventContainer<>(module, event); + } +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/event/VelocityEventListener.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/event/VelocityEventListener.java new file mode 100644 index 00000000..d18bd2c5 --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/event/VelocityEventListener.java @@ -0,0 +1,73 @@ +package com.minersstudios.wholib.velocity.event; + +import com.minersstudios.wholib.event.handle.HandlerExecutor; +import com.minersstudios.wholib.event.EventListener; +import com.minersstudios.wholib.event.handle.AsyncHandler; +import com.minersstudios.wholib.event.handle.AsyncHandlerParams; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.listener.Listener; +import com.minersstudios.wholib.throwable.ListenerException; +import com.minersstudios.wholib.velocity.listener.VelocityListenerManager; +import org.jetbrains.annotations.NotNull; + +/** + * An abstract class that represents a velocity event listener. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
      Available optional overridable methods
      MethodDescription
      {@link #onRegister()} + * Called when the listener is registered by a manager in the + * {@link VelocityListenerManager#register(Listener)} method + *
      {@link #onUnregister()} + * Called when the listener is unregistered by a manager in the + * {@link VelocityListenerManager#unregister(Listener)} method + *
      + * + * @see VelocityEventContainer + * @see HandlerExecutor + */ +@SuppressWarnings("unused") +public abstract class VelocityEventListener + extends EventListener, VelocityEventContainer> { + + /** + * Constructs a new event listener. + *

      + * This constructor will automatically retrieve all event handlers from the + * listener class and event class from the {@link ListenFor} annotation. + * + * @throws ClassCastException If the event class is not a subclass of + * annotated event class + * @throws ListenerException If the listener has duplicate event handlers + * for the same order, or if the listener does + * not have a {@link ListenFor} annotation + */ + protected VelocityEventListener() throws ClassCastException, ListenerException { + super(AsyncHandler.class, AsyncHandlerParams::of); + } + + /** + * Constructs a new event listener with the specified event class. + *

      + * This constructor will automatically retrieve all event handlers from the + * listener class. + * + * @param key The key of the event listener + * @throws ListenerException If the listener has duplicate event handlers + * for the same order + */ + protected VelocityEventListener(final @NotNull Class key) throws ListenerException { + super(key, AsyncHandler.class, AsyncHandlerParams::of); + } +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/gui/VelocityGuiManager.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/gui/VelocityGuiManager.java new file mode 100644 index 00000000..e9818493 --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/gui/VelocityGuiManager.java @@ -0,0 +1,12 @@ +package com.minersstudios.wholib.velocity.gui; + +import com.minersstudios.wholib.velocity.WhoMine; +import com.minersstudios.wholib.gui.GuiManager; +import org.jetbrains.annotations.NotNull; + +public class VelocityGuiManager extends GuiManager { + + public VelocityGuiManager(final @NotNull WhoMine module) { + super(module); + } +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/listener/VelocityListenerManager.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/listener/VelocityListenerManager.java new file mode 100644 index 00000000..272d013c --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/listener/VelocityListenerManager.java @@ -0,0 +1,210 @@ +package com.minersstudios.wholib.velocity.listener; + +import com.minersstudios.wholib.velocity.WhoMine; +import com.minersstudios.wholib.event.EventContainer; +import com.minersstudios.wholib.event.EventListener; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.Listener; +import com.minersstudios.wholib.listener.ListenerManager; +import com.minersstudios.wholib.listener.ListenerMap; +import com.minersstudios.wholib.velocity.event.VelocityEventContainer; +import com.minersstudios.wholib.velocity.event.VelocityEventListener; +import com.velocitypowered.api.event.EventManager; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnmodifiableView; + +import java.util.List; +import java.util.function.Supplier; + +/** + * Listener manager class. + *
      + * This class is responsible for managing event and packet listeners. + * + * @see VelocityEventListener + */ +@SuppressWarnings("unused") +public final class VelocityListenerManager extends ListenerManager { + + private final ListenerMap, VelocityEventListener> eventMap; + + public VelocityListenerManager(final @NotNull WhoMine module) { + super(module); + + this.eventMap = new ListenerMap<>(); + } + + /** + * Returns the unmodifiable listener map containing all event listeners + * + * @return The unmodifiable listener map containing all event listeners + */ + public @NotNull @UnmodifiableView ListenerMap, VelocityEventListener> eventMap() { + return this.eventMap.toUnmodifiableView(); + } + + /** + * Returns the event listeners for the given event + * + * @param event The event + * @return The event listeners for the given event + * @see #getEventListeners(Class) + */ + public @Nullable @UnmodifiableView List getEventListeners(final @NotNull E event) { + return this.getEventListeners(event.getClass()); + } + + /** + * Returns the event listeners for the given event class + * + * @param eventClass The event class + * @return The event listeners for the given event class + * @see #getEventListeners(Object) + */ + public @Nullable @UnmodifiableView List getEventListeners(final @NotNull Class eventClass) { + return this.eventMap.get(eventClass); + } + + @Override + public boolean register(final @NotNull Listener listener) { + final boolean result = switch (listener) { + case VelocityEventListener eventListener -> { + final var eventClass = eventListener.getKey(); + + if (this.eventMap.put(eventListener) == null) { + this.getModule().getLogger().warning("Tried to register an event listener that is already registered: " + eventListener); + + yield false; + } + + final WhoMine module = this.getModule(); + final EventManager eventManager = module.getServer().getEventManager(); + + for (final var executor : eventListener.executors()) { + final var params = executor.getParams(); + final EventOrder order = params.getOrder(); + + eventManager.register( + module, + eventClass, + (short) order.asNumber(), + (event) -> { + if (!eventClass.isAssignableFrom(event.getClass())) { + return; + } + + eventListener.call( + order, + VelocityEventContainer.of( + this.getModule(), + event + ) + ); + } + ); + } + + yield true; + } + default -> throw new UnsupportedOperationException("Unknown listener type: " + listener.getClass()); + }; + + if (result) { + listener.onRegister(); + } + + return result; + } + + @Override + public boolean unregister(final @NotNull Listener registrable) { + final boolean result = switch (registrable) { + case VelocityEventListener eventListener -> this.eventMap.remove(eventListener) != null; + default -> false; + }; + + if (result) { + registrable.onUnregister(); + } + + return result; + } + + @Override + public void unregisterAll() { + this.unregisterAll(this.eventMap); + } + + @Override + public boolean isRegistered(final @NotNull Listener registrable) { + return switch (registrable) { + case VelocityEventListener eventListener -> this.eventMap.containsListener(eventListener); + default -> false; + }; + } + + /** + * Calls the registered listeners for the given event + * + * @param container The event container + */ + public void call(final @NotNull VelocityEventContainer container) { + this.rawCall( + container, + () -> this.getEventListeners(container.getEvent()) + ); + } + + /** + * Calls the registered listeners for the given event with the given + * parameters + * + * @param order The event order + * @param container The event container + */ + public void call( + final @NotNull EventOrder order, + final @NotNull VelocityEventContainer container + ) { + this.rawCall( + order, container, + () -> this.getEventListeners(container.getEvent()) + ); + } + + private void unregisterAll(final @NotNull ListenerMap map) { + for (final var listener : map.listeners()) { + listener.onUnregister(); + } + + map.clear(); + } + + private > void rawCall( + final @NotNull C container, + final @NotNull Supplier>> supplier + ) { + final var listeners = supplier.get(); + + if (listeners != null) { + for (final var listener : listeners) { + listener.call(container); + } + } + } + + private > void rawCall( + final @NotNull EventOrder order, + final @NotNull C container, + final @NotNull Supplier>> supplier + ) { + final var listeners = supplier.get(); + + if (listeners != null) { + for (final var listener : listeners) { + listener.call(order, container); + } + } + } +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/utility/ApiConverter.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/utility/ApiConverter.java new file mode 100644 index 00000000..43b45a93 --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/utility/ApiConverter.java @@ -0,0 +1,36 @@ +package com.minersstudios.wholib.velocity.utility; + +import com.minersstudios.wholib.event.EventOrder; +import com.velocitypowered.api.event.PostOrder; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +public final class ApiConverter { + + @Contract(" -> fail") + private ApiConverter() throws AssertionError { + throw new AssertionError("Utility class"); + } + + public static @NotNull PostOrder apiToVelocity(final @NotNull EventOrder order) { + return switch (order) { + case LOWEST -> PostOrder.FIRST; + case LOW -> PostOrder.EARLY; + case NORMAL -> PostOrder.NORMAL; + case HIGH -> PostOrder.LATE; + case HIGHEST -> PostOrder.LAST; + case CUSTOM -> PostOrder.CUSTOM; + }; + } + + public static @NotNull EventOrder velocityToApi(final @NotNull PostOrder order) { + return switch (order) { + case FIRST -> EventOrder.LOWEST; + case EARLY -> EventOrder.LOW; + case NORMAL -> EventOrder.NORMAL; + case LATE -> EventOrder.HIGH; + case LAST -> EventOrder.HIGHEST; + case CUSTOM -> EventOrder.CUSTOM; + }; + } +} diff --git a/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/utility/MSLogger.java b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/utility/MSLogger.java new file mode 100644 index 00000000..bf98f06f --- /dev/null +++ b/lib/velocity/src/main/java/com/minersstudios/wholib/velocity/utility/MSLogger.java @@ -0,0 +1,495 @@ +package com.minersstudios.wholib.velocity.utility; + +import com.minersstudios.wholib.velocity.WhoMine; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.ansi.ANSIComponentSerializer; +import net.kyori.adventure.translation.GlobalTranslator; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * A custom logging utility designed to send formatted log messages with + * different levels and colors to various targets. Supports logging to the + * console, players, and command senders using AdventureAPI for text formatting. + *
      + * Available levels, and their corresponding colors: + *

        + *
      • {@link Level#SEVERE} - Red
      • + *
      • {@link Level#WARNING} - Yellow
      • + *
      • {@link Level#INFO} - Default
      • + *
      • {@link Level#FINE} - Green
      • + *
      + */ +@SuppressWarnings("unused") +public final class MSLogger { + private static final ANSIComponentSerializer ANSI_SERIALIZER = ANSIComponentSerializer.builder().build(); + private static final Logger LOGGER = Logger.getLogger(WhoMine.class.getSimpleName()); + + private static final String ANSI_LIME = "\u001B[92m"; + private static final String ANSI_RESET = "\u001B[0m"; + + private static final int SEVERE = 1000; + private static final int WARNING = 900; + private static final int FINE = 500; + + @Contract(" -> fail") + private MSLogger() throws AssertionError { + throw new AssertionError("This class cannot be instantiated!"); + } + + /** + * Logs a message with the specified severity level. If the level is + * {@link Level#FINE}, the message will be logged with the {@link Level#INFO} + * level and colored lime green. + * + * @param level One of the message level identifiers + * @param message The component message + * @see #log(Level, String) + */ + public static void log( + final @NotNull Level level, + final @NotNull Component message + ) { + log(level, serialize(message)); + } + + /** + * Logs a message with the specified severity level. If the level is + * {@link Level#FINE}, the message will be logged with the {@link Level#INFO} + * level and colored lime green. + * + * @param level One of the message level identifiers + * @param message The string message + * @see Logger#log(Level, String) + */ + public static void log( + final @NotNull Level level, + final @NotNull String message + ) { + if (level.intValue() == FINE) { + LOGGER.log(Level.INFO, ANSI_LIME + message + ANSI_RESET); + } else { + LOGGER.log(level, message); + } + } + + /** + * Log a message with the specified severity level and associated array of + * parameters. If the level is {@link Level#FINE}, the message will be + * logged with the {@link Level#INFO} level and colored lime green. + * + * @param level One of the message level identifiers + * @param message The component message + * @param params Array of parameters to the message + * @see #log(Level, String, Object...) + */ + public static void log( + final @NotNull Level level, + final @NotNull Component message, + final Object @NotNull ... params + ) { + log(level, serialize(message), params); + } + + /** + * Log a message with the specified severity level and associated array of + * parameters. If the level is {@link Level#FINE}, the message will be + * logged with the {@link Level#INFO} level and colored lime green. + * + * @param level One of the message level identifiers + * @param message The string message + * @param params Array of parameters to the message + * @see Logger#log(Level, String, Object...) + */ + public static void log( + final @NotNull Level level, + final @NotNull String message, + final @Nullable Object @NotNull ... params + ) { + if (level.intValue() == FINE) { + LOGGER.log(Level.INFO, ANSI_LIME + message + ANSI_RESET, params); + } else { + LOGGER.log(level, message, params); + } + } + + /** + * Logs a message with the specified severity level and associated throwable. + * If the level is {@link Level#FINE}, the message will be logged with the + * {@link Level#INFO} level and colored lime green. + * + * @param level One of the message level identifiers + * @param message The component message + * @param throwable Throwable associated with a log message + * @see #log(Level, String, Throwable) + */ + public static void log( + final @NotNull Level level, + final @NotNull Component message, + final @NotNull Throwable throwable + ) { + log(level, serialize(message), throwable); + } + + /** + * Logs a message with the specified severity level and associated throwable. + * If the level is {@link Level#FINE}, the message will be logged with the + * {@link Level#INFO} level and colored lime green. + * + * @param level One of the message level identifiers + * @param message The string message + * @param throwable Throwable associated with a log message + * @see Logger#log(Level, String, Throwable) + */ + public static void log( + final @NotNull Level level, + final @NotNull String message, + final @NotNull Throwable throwable + ) { + if (level.intValue() == FINE) { + LOGGER.log(Level.INFO, ANSI_LIME + message + ANSI_RESET, throwable); + } else { + LOGGER.log(level, message, throwable); + } + } + + /** + * Logs a message with the {@link Level#SEVERE} severity level + * + * @param message The string message + * @see #log(Level, String) + */ + public static void severe(final @NotNull String message) { + log(Level.SEVERE, message); + } + + /** + * Logs a message with the {@link Level#SEVERE} severity level + * + * @param message The component message + * @see #log(Level, Component) + */ + public static void severe(final @NotNull Component message) { + log(Level.SEVERE, message); + } + + /** + * Logs a message with the {@link Level#SEVERE} severity level and + * associated array of parameters + * + * @param message The string message + * @param params Array of parameters to the message + * @see #log(Level, String, Object...) + */ + public static void severe( + final @NotNull String message, + final Object @NotNull ... params + ) { + log(Level.SEVERE, message, params); + } + + /** + * Logs a message with the {@link Level#SEVERE} severity level and + * associated array of parameters + * + * @param message The component message + * @param params Array of parameters to the message + * @see #log(Level, Component, Object...) + */ + public static void severe( + final @NotNull Component message, + final Object @NotNull ... params + ) { + log(Level.SEVERE, message, params); + } + + /** + * Logs a message with the {@link Level#SEVERE} severity level and + * associated throwable + * + * @param message The string message + * @param throwable Throwable associated with a log message + * @see #log(Level, String, Throwable) + */ + public static void severe( + final @NotNull String message, + final @NotNull Throwable throwable + ) { + log(Level.SEVERE, message, throwable); + } + + /** + * Logs a message with the {@link Level#SEVERE} severity level and + * associated throwable + * + * @param message The component message + * @param throwable Throwable associated with a log message + * @see #log(Level, Component, Throwable) + */ + public static void severe( + final @NotNull Component message, + final @NotNull Throwable throwable + ) { + log(Level.SEVERE, message, throwable); + } + + /** + * Logs a message with the {@link Level#WARNING} severity level + * + * @param message The string message + * @see #log(Level, String) + */ + public static void warning(final @NotNull String message) { + log(Level.WARNING, message); + } + + /** + * Logs a message with the {@link Level#WARNING} severity level + * + * @param message The component message + * @see #log(Level, Component) + */ + public static void warning(final @NotNull Component message) { + log(Level.WARNING, message); + } + + /** + * Logs a message with the {@link Level#WARNING} severity level and + * associated array of parameters + * + * @param message The string message + * @param params Array of parameters to the message + * @see #log(Level, String, Object...) + */ + public static void warning( + final @NotNull String message, + final Object @NotNull ... params + ) { + log(Level.WARNING, message, params); + } + + /** + * Logs a message with the {@link Level#WARNING} severity level and + * associated array of parameters + * + * @param message The component message + * @param params Array of parameters to the message + * @see #log(Level, Component, Object...) + */ + public static void warning( + final @NotNull Component message, + final Object @NotNull ... params + ) { + log(Level.WARNING, message, params); + } + + /** + * Logs a message with the {@link Level#WARNING} severity level and + * associated throwable + * + * @param message The string message + * @param throwable Throwable associated with a log message + * @see #log(Level, String, Throwable) + */ + public static void warning( + final @NotNull String message, + final @NotNull Throwable throwable + ) { + log(Level.WARNING, message, throwable); + } + + /** + * Logs a message with the {@link Level#WARNING} severity level and + * associated throwable + * + * @param message The component message + * @param throwable Throwable associated with a log message + * @see #log(Level, Component, Throwable) + */ + public static void warning( + final @NotNull Component message, + final @NotNull Throwable throwable + ) { + log(Level.WARNING, message, throwable); + } + + /** + * Logs a message with the {@link Level#INFO} severity level + * + * @param message The string message + * @see #log(Level, String) + */ + public static void info(final @NotNull String message) { + log(Level.INFO, message); + } + + /** + * Logs a message with the {@link Level#INFO} severity level + * + * @param message The component message + * @see #log(Level, Component) + */ + public static void info(final @NotNull Component message) { + log(Level.INFO, message); + } + + /** + * Logs a message with the {@link Level#INFO} severity level and associated + * array of parameters + * + * @param message The string message + * @param params Array of parameters to the message + * @see #log(Level, String, Object...) + */ + public static void info( + final @NotNull String message, + final Object @NotNull ... params + ) { + log(Level.INFO, message, params); + } + + /** + * Logs a message with the {@link Level#INFO} severity level and associated + * array of parameters + * + * @param message The component message + * @param params Array of parameters to the message + * @see #log(Level, Component, Object...) + */ + public static void info( + final @NotNull Component message, + final Object @NotNull ... params + ) { + log(Level.INFO, message, params); + } + + /** + * Logs a message with the {@link Level#INFO} severity level and associated + * throwable + * + * @param message The string message + * @param throwable Throwable associated with a log message + * @see #log(Level, String, Throwable) + */ + public static void info( + final @NotNull String message, + final @NotNull Throwable throwable + ) { + log(Level.INFO, message, throwable); + } + + /** + * Logs a message with the {@link Level#INFO} severity level and associated + * throwable + * + * @param message The component message + * @param throwable Throwable associated with a log message + * @see #log(Level, Component, Throwable) + */ + public static void info( + final @NotNull Component message, + final @NotNull Throwable throwable + ) { + log(Level.INFO, message, throwable); + } + + /** + * Logs a message with the {@link Level#FINE} severity level + * + * @param message The string message + * @see #log(Level, String) + */ + public static void fine(final @NotNull String message) { + log(Level.FINE, message); + } + + /** + * Logs a message with the {@link Level#FINE} severity level + * + * @param message The component message + * @see #log(Level, Component) + */ + public static void fine(final @NotNull Component message) { + log(Level.FINE, message); + } + + /** + * Logs a message with the {@link Level#FINE} severity level and associated + * array of parameters + * + * @param message The string message + * @param params Array of parameters to the message + * @see #log(Level, String, Object...) + */ + public static void fine( + final @NotNull String message, + final Object @NotNull ... params + ) { + log(Level.FINE, message, params); + } + + /** + * Logs a message with the {@link Level#FINE} severity level and associated + * array of parameters + * + * @param message The component message + * @param params Array of parameters to the message + * @see #log(Level, Component, Object...) + */ + public static void fine( + final @NotNull Component message, + final Object @NotNull ... params + ) { + log(Level.FINE, message, params); + } + + /** + * Logs a message with the {@link Level#FINE} severity level and associated + * throwable + * + * @param message The string message + * @param throwable Throwable associated with a log message + * @see #log(Level, String, Throwable) + */ + public static void fine( + final @NotNull String message, + final @NotNull Throwable throwable + ) { + log(Level.FINE, message, throwable); + } + + /** + * Logs a message with the {@link Level#FINE} severity level and associated + * throwable + * + * @param message The component message + * @param throwable Throwable associated with a log message + * @see #log(Level, Component, Throwable) + */ + public static void fine( + final @NotNull Component message, + final @NotNull Throwable throwable + ) { + log(Level.FINE, message, throwable); + } + + /** + * Serializes a component message to a string + * + * @param message The component message + * @return The serialized string + */ + private static @NotNull String serialize(final @NotNull Component message) { + return ANSI_SERIALIZER.serialize( + GlobalTranslator.render( + message, + Locale.getDefault() + ) + ); + } +} diff --git a/lib/velocity/src/test/java/com/minersstudios/wholib/velocity/Main.java b/lib/velocity/src/test/java/com/minersstudios/wholib/velocity/Main.java new file mode 100644 index 00000000..f0794815 --- /dev/null +++ b/lib/velocity/src/test/java/com/minersstudios/wholib/velocity/Main.java @@ -0,0 +1,8 @@ +package com.minersstudios.wholib.velocity; + +public final class Main { + + public static void main(final String[] args) { + System.out.println("Hello, Sparrow!"); + } +} diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts deleted file mode 100644 index 5b90d6e6..00000000 --- a/paper/build.gradle.kts +++ /dev/null @@ -1,60 +0,0 @@ -val paperVersion: String = rootProject.property("paper.version").toString() -val author: String = rootProject.property("project.author").toString() -val contributors: String = rootProject.property("project.contributors").toString() -val website: String = rootProject.property("project.website").toString() -val coreProtectVersion: String = libs.versions.coreprotect.get() -val authMeVersion: String = libs.versions.authme.get() -val apiVersion: String - get() { - val minecraftVersion = paperweight.minecraftVersion.get() - val parts = minecraftVersion.split('.') - - return if (parts.size < 2) { - throw IllegalStateException("Invalid Minecraft version: '$minecraftVersion'") - } else { - "'${parts[0]}.${parts[1]}'" - } - } - -plugins { - alias(libs.plugins.paper.userdev) - alias(libs.plugins.paper.run) - alias(libs.plugins.shadow) -} - -dependencies { - paperweight.paperDevBundle(paperVersion) - - implementation(project(":common")) - compileOnly(libs.authme) - compileOnly(libs.coreprotect) -} - -tasks { - reobfJar { - outputJar.set(file("$rootDir/build/${jar.get().archiveBaseName.get()}-$version.jar")) - } - - assemble { - dependsOn(reobfJar) - } - - processResources { - val props = mapOf( - "name" to project.name, - "version" to project.version, - "description" to project.description, - "author" to author, - "contributors" to contributors, - "website" to website, - "apiVersion" to apiVersion, - "coreProtectVersion" to coreProtectVersion, - "authMeVersion" to libs.versions.authme.get(), - ) - - inputs.properties(props) - filesMatching("paper-plugin.yml") { - expand(props) - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/WhoMine.java b/paper/src/main/java/com/minersstudios/whomine/WhoMine.java deleted file mode 100644 index 224e0c3e..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/WhoMine.java +++ /dev/null @@ -1,272 +0,0 @@ -package com.minersstudios.whomine; - -import com.minersstudios.whomine.command.api.CommandManager; -import com.minersstudios.whomine.discord.DiscordManager; -import com.minersstudios.whomine.inventory.holder.AbstractInventoryHolder; -import com.minersstudios.whomine.listener.api.ListenerManager; -import com.minersstudios.whomine.scheduler.TaskExecutor; -import com.minersstudios.whomine.api.status.FailureStatus; -import com.minersstudios.whomine.api.status.StatusHandler; -import com.minersstudios.whomine.api.status.SuccessStatus; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.UnknownNullability; -import org.jetbrains.annotations.UnmodifiableView; - -import java.io.File; -import java.util.Map; -import java.util.Optional; - -import static com.minersstudios.whomine.api.status.Status.*; - -/** - * Represents a WhoMine plugin - */ -public interface WhoMine extends Plugin, TaskExecutor { - // - /** High-priority plugin loading status */ - SuccessStatus LOADING = successHigh("LOADING"); - /** Low-priority plugin loaded status */ - SuccessStatus LOADED = successLow("LOADED"); - - /** High-priority plugin enabling status */ - SuccessStatus ENABLING = successHigh("ENABLING"); - /** High-priority plugin enabled status */ - SuccessStatus ENABLED = successHigh("ENABLED"); - - /** High-priority plugin disabling status */ - SuccessStatus DISABLING = successHigh("DISABLING"); - /** High-priority plugin disabled status */ - SuccessStatus DISABLED = successHigh("DISABLED"); - - /** Failed low-priority status for loading cache */ - FailureStatus FAILED_LOAD_CACHE = failureLow("FAILED_LOAD_CACHE"); - /** Low-priority plugin loading cache status */ - SuccessStatus LOADING_CACHE = successLow("LOADING_CACHE"); - /** Low-priority plugin loaded cache status */ - SuccessStatus LOADED_CACHE = successLow("LOADED_CACHE", FAILED_LOAD_CACHE); - - /** Failed low-priority status for loading config */ - FailureStatus FAILED_LOAD_CONFIG = failureLow("FAILED_LOAD_CONFIG"); - /** Low-priority plugin loading config status */ - SuccessStatus LOADING_CONFIG = successLow("LOADING_CONFIG"); - /** Low-priority plugin loaded config status */ - SuccessStatus LOADED_CONFIG = successLow("LOADED_CONFIG", FAILED_LOAD_CONFIG); - - /** Low-priority plugin loading languages.yml status */ - SuccessStatus LOADING_LANGUAGES = successLow("LOADING_LANGUAGES"); - /** Low-priority plugin loaded languages.yml status */ - SuccessStatus LOADED_LANGUAGES = successLow("LOADED_LANGUAGES"); - - /** Low-priority plugin decorations loading status */ - SuccessStatus LOADING_DECORATIONS = successLow("LOADING_DECORATIONS"); - /** Low-priority plugin decorations loaded status */ - SuccessStatus LOADED_DECORATIONS = successLow("LOADED_DECORATIONS"); - - /** Failed low-priority status for loading blocks */ - FailureStatus FAILED_LOAD_BLOCKS = failureLow("FAILED_LOAD_BLOCKS"); - /** Low-priority plugin loading blocks status */ - SuccessStatus LOADING_BLOCKS = successLow("LOADING_BLOCKS"); - /** Low-priority plugin loaded blocks status */ - SuccessStatus LOADED_BLOCKS = successLow("LOADED_BLOCKS", FAILED_LOAD_BLOCKS); - - /** Failed low-priority status for loading items */ - SuccessStatus LOADING_ITEMS = successLow("LOADING_ITEMS"); - /** Low-priority plugin loaded items status */ - SuccessStatus LOADED_ITEMS = successLow("LOADED_ITEMS"); - - /** Failed low-priority status for loading decor */ - FailureStatus FAILED_LOAD_RENAMEABLES = failureLow("FAILED_LOAD_RENAMEABLES"); - /** Low-priority plugin loading decor status */ - SuccessStatus LOADING_RENAMEABLES = successLow("LOADING_RENAMEABLES"); - /** Low-priority plugin loaded decor status */ - SuccessStatus LOADED_RENAMEABLES = successLow("LOADED_RENAMEABLES", FAILED_LOAD_RENAMEABLES); - - /** Failed low-priority status for loading resource packs */ - FailureStatus FAILED_LOAD_RESOURCE_PACKS = failureLow("FAILED_LOAD_RESOURCE_PACKS"); - /** Low-priority plugin loading resource packs status */ - SuccessStatus LOADING_RESOURCE_PACKS = successLow("LOADING_RESOURCE_PACKS"); - /** Low-priority plugin loaded resource packs status */ - SuccessStatus LOADED_RESOURCE_PACKS = successLow("LOADED_RESOURCE_PACKS", FAILED_LOAD_RESOURCE_PACKS); - - /** Failed low-priority status for loading anomalies */ - FailureStatus FAILED_LOAD_ANOMALIES = failureLow("FAILED_LOAD_ANOMALIES"); - /** Low-priority plugin loading anomalies status */ - SuccessStatus LOADING_ANOMALIES = successLow("LOADING_ANOMALIES"); - /** Low-priority plugin loaded anomalies status */ - SuccessStatus LOADED_ANOMALIES = successLow("LOADED_ANOMALIES", FAILED_LOAD_ANOMALIES); - - /** Failed low-priority status for loading discord */ - FailureStatus FAILED_LOAD_DISCORD = failureLow("FAILED_LOAD_DISCORD"); - /** Low-priority plugin loading discord status */ - SuccessStatus LOADING_DISCORD = successLow("LOADING_DISCORD"); - /** Low-priority plugin loaded discord status */ - SuccessStatus LOADED_DISCORD = successLow("LOADED_DISCORD", FAILED_LOAD_DISCORD); - // - - /** - * Returns the singleton instance of the plugin - * - * @return The singleton instance of the plugin - */ - static WhoMine singleton() { - return WhoMineImpl.singleton; - } - - /** - * Returns the plugin's configuration file - * - * @return The plugin's configuration file - */ - @NotNull File getConfigFile(); - - /** - * Returns the cache of the plugin - * - * @return The cache of the plugin - */ - @NotNull Cache getCache(); - - /** - * Returns the configuration of the plugin - * - * @return The configuration of the plugin - */ - @NotNull Config getConfiguration(); - - /** - * Returns the status handler of the plugin - * - * @return The status handler of the plugin - */ - @NotNull StatusHandler getStatusHandler(); - - /** - * Returns the listener manager of the plugin - * - * @return The listener manager of the plugin - */ - @NotNull ListenerManager getListenerManager(); - - /** - * Returns the command manager of the plugin - * - * @return The command manager of the plugin - */ - @NotNull CommandManager getCommandManager(); - - /** - * Returns the discord manager of the plugin - * - * @return The discord manager of the plugin - */ - @NotNull DiscordManager getDiscordManager(); - - /** - * Returns an unmodifiable view of the inventory holder map - * - * @return An unmodifiable view of the inventory holder map - */ - @NotNull @UnmodifiableView Map, AbstractInventoryHolder> getInventoryHolderMap(); - - /** - * Gets the inventory holder of the specified class if present, otherwise an - * empty optional will be returned - * - * @param clazz Class of the inventory holder - * @return An optional containing the inventory holder if present, otherwise - * an empty optional - */ - @NotNull Optional getInventoryHolder(final @NotNull Class clazz); - - /** - * Returns scoreboard for hiding tags - * - * @return Scoreboard for hiding tags - */ - @UnknownNullability Scoreboard getScoreboardHideTags(); - - /** - * Returns team for hiding tags - * - * @return Team for hiding tags - */ - @UnknownNullability Team getScoreboardHideTagsTeam(); - - /** - * Gets a {@link FileConfiguration} for this plugin, read through - * "config.yml" - *
      - * If there is a default config.yml embedded in this plugin, it will be - * provided as a default for this Configuration. - * - * @return Plugin configuration - */ - @Override - @NotNull FileConfiguration getConfig(); - - /** - * Returns whether the plugin is fully loaded - * - * @return True if the plugin is fully loaded - */ - boolean isFullyLoaded(); - - /** - * Discards any data in {@link #getConfig()} and reloads from disk. - */ - @Override - void reloadConfig(); - - /** - * Saves the {@link FileConfiguration} retrievable by {@link #getConfig()} - */ - @Override - void saveConfig(); - - /** - * Saves the raw contents of any resource embedded with a plugin's .jar file - * assuming it can be found using {@link #getResource(String)}. - *
      - * The resource is saved into the plugin's data folder using the same - * hierarchy as the .jar file (subdirectories are preserved). - * - * @param resourcePath The embedded resource path to look for within the - * plugin's .jar file. (No preceding slash). - * @param replace If true, the embedded resource will overwrite the contents - * of an existing file. - * @throws IllegalArgumentException if the resource path is null, empty, - * or points to a nonexistent resource. - */ - @Override - void saveResource( - final @NotNull String resourcePath, - final boolean replace - ) throws IllegalArgumentException; - - /** - * Saves the raw contents of the default config.yml file to the location - * retrievable by {@link #getConfig()}. - *
      - * This should fail silently if the config.yml already exists. - */ - @Override - void saveDefaultConfig(); - - /** - * Opens a custom inventory for the given player if the custom inventory is - * registered to the plugin - * - * @param clazz Class of the custom inventory holder - * @param player Player to open the custom inventory - * @see AbstractInventoryHolder - */ - void openCustomInventory( - final @NotNull Class clazz, - final @NotNull Player player - ); -} diff --git a/paper/src/main/java/com/minersstudios/whomine/chat/ChatType.java b/paper/src/main/java/com/minersstudios/whomine/chat/ChatType.java deleted file mode 100644 index 05b4f046..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/chat/ChatType.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.minersstudios.whomine.chat; - -public enum ChatType { - GLOBAL, LOCAL -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/api/DiscordListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/api/DiscordListener.java deleted file mode 100644 index f3f66188..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/api/DiscordListener.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.minersstudios.whomine.listener.api; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.plugin.PluginComponent; -import net.dv8tion.jda.api.hooks.ListenerAdapter; -import org.jetbrains.annotations.NotNull; - -public abstract class DiscordListener extends ListenerAdapter implements PluginComponent { - private final WhoMine plugin; - - /** - * Discord listener constructor - * - * @param plugin The plugin instance - */ - protected DiscordListener(final @NotNull WhoMine plugin) { - this.plugin = plugin; - } - - @Override - public final @NotNull WhoMine getPlugin() { - return this.plugin; - } - - @Override - public @NotNull String toString() { - return this.getClass().getSimpleName() + "{plugin=" + this.plugin + '}'; - } - - @Override - public void register() throws IllegalStateException { - this.getPlugin().getListenerManager().registerDiscord(this); - this.onRegister(); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/api/EventListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/api/EventListener.java deleted file mode 100644 index ecaed3c6..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/api/EventListener.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.minersstudios.whomine.listener.api; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.plugin.AbstractPluginComponent; -import org.bukkit.event.Listener; -import org.jetbrains.annotations.NotNull; - -public abstract class EventListener extends AbstractPluginComponent implements Listener { - - /** - * Event listener constructor - * - * @param plugin The plugin instance - */ - protected EventListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @Override - public void register() throws IllegalStateException { - this.getPlugin().getListenerManager().registerEvent(this); - this.onRegister(); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/api/ListenerManager.java b/paper/src/main/java/com/minersstudios/whomine/listener/api/ListenerManager.java deleted file mode 100644 index 95f1557e..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/api/ListenerManager.java +++ /dev/null @@ -1,440 +0,0 @@ -package com.minersstudios.whomine.listener.api; - -import com.google.common.collect.Sets; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.impl.discord.CommandAutoCompleteInteractionListener; -import com.minersstudios.whomine.listener.impl.discord.MessageReceivedListener; -import com.minersstudios.whomine.listener.impl.discord.SlashCommandInteractionListener; -import com.minersstudios.whomine.listener.impl.event.block.*; -import com.minersstudios.whomine.listener.impl.event.chat.AsyncChatListener; -import com.minersstudios.whomine.listener.impl.event.command.UnknownCommandListener; -import com.minersstudios.whomine.listener.impl.event.entity.*; -import com.minersstudios.whomine.listener.impl.event.hanging.HangingBreakByEntityListener; -import com.minersstudios.whomine.listener.impl.event.inventory.*; -import com.minersstudios.whomine.listener.impl.event.mechanic.*; -import com.minersstudios.whomine.listener.impl.event.player.*; -import com.minersstudios.whomine.listener.impl.event.server.ServerCommandListener; -import com.minersstudios.whomine.listener.impl.packet.player.PlayerActionListener; -import com.minersstudios.whomine.listener.impl.packet.player.PlayerUpdateSignListener; -import com.minersstudios.whomine.listener.impl.packet.player.SwingArmListener; -import com.minersstudios.whomine.packet.PacketEvent; -import com.minersstudios.whomine.packet.PacketType; -import com.minersstudios.whomine.api.status.StatusWatcher; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * Listener manager class. - *
      - * This class is responsible for managing various types of plugin listeners. - * - * @see DiscordListener - * @see EventListener - * @see PacketListener - */ -public final class ListenerManager { - private final WhoMine plugin; - private final List discordList; - private final List eventList; - private final Map> receivePacketMap; - private final Map> sendPacketMap; - - /** - * Constructs a new listener manager - * - * @param plugin Plugin instance - */ - public ListenerManager(final @NotNull WhoMine plugin) { - this.plugin = plugin; - this.discordList = new ObjectArrayList<>(); - this.eventList = new ObjectArrayList<>(); - this.receivePacketMap = new EnumMap<>(PacketType.class); - this.sendPacketMap = new EnumMap<>(PacketType.class); - } - - /** - * Returns an unmodifiable view of the discord listeners - * - * @return An unmodifiable view of the discord listeners - */ - public @NotNull @UnmodifiableView Collection discordListeners() { - return Collections.unmodifiableCollection(this.discordList); - } - - /** - * Returns an unmodifiable view of the event listeners - * - * @return An unmodifiable view of the event listeners - */ - public @NotNull @UnmodifiableView Collection eventListeners() { - return Collections.unmodifiableCollection(this.eventList); - } - - /** - * Returns an unmodifiable collection of packet listeners - * - * @return An unmodifiable collection of packet listeners - */ - public @NotNull @Unmodifiable Collection packetListeners() { - final var map = new ObjectArrayList(); - - for (final var list : this.receivePacketMap.values()) { - map.addAll(list); - } - - for (final var list : this.sendPacketMap.values()) { - map.addAll(list); - } - - return Collections.unmodifiableCollection(map); - } - - /** - * Gets packet listeners for the specified packet type - * - * @param packetType Packet type - * @return An unmodifiable collection of packet listeners for the specified - * packet type - */ - public @NotNull @Unmodifiable Collection packetListeners(final @NotNull PacketType packetType) { - final var list = - packetType.isReceive() - ? this.receivePacketMap.get(packetType) - : this.sendPacketMap.get(packetType); - - return list != null - ? Collections.unmodifiableCollection(list) - : Collections.emptyList(); - } - - /** - * Returns an unmodifiable collection of packet listeners - * - * @return An unmodifiable collection of packet listeners - */ - public @NotNull @Unmodifiable Collection receivePacketListeners() { - final var collection = new ObjectArrayList(); - - for (final var list : this.receivePacketMap.values()) { - collection.addAll(list); - } - - return Collections.unmodifiableCollection(collection); - } - - /** - * Returns an unmodifiable collection of send packet listeners - * - * @return An unmodifiable collection of send packet listeners - */ - public @NotNull @Unmodifiable Collection sendPacketListeners() { - final var collection = new ObjectArrayList(); - - for (final var list : this.sendPacketMap.values()) { - collection.addAll(list); - } - - return Collections.unmodifiableCollection(collection); - } - - /** - * Returns an unmodifiable view of the packet type set - * - * @return An unmodifiable view of the packet type set - */ - public @NotNull @UnmodifiableView Set packetTypeSet() { - return Sets.union(this.receivePacketMap.keySet(), this.sendPacketMap.keySet()); - } - - /** - * Returns an unmodifiable view of the receive packet type set - * - * @return An unmodifiable view of the receive packet type set - */ - public @NotNull @UnmodifiableView Set receivePacketTypeSet() { - return Collections.unmodifiableSet(this.receivePacketMap.keySet()); - } - - /** - * Returns an unmodifiable view of the send packet type set - * - * @return An unmodifiable view of the send packet type set - */ - public @NotNull @UnmodifiableView Set sendPacketTypeSet() { - return Collections.unmodifiableSet(this.sendPacketMap.keySet()); - } - - /** - * Returns whether the listener manager contains the specified discord - * listener - * - * @param listener Listener to be checked - * @return True if the listener manager contains the specified listener, - * false otherwise - */ - @Contract("null -> false") - public boolean containsDiscord(final @Nullable DiscordListener listener) { - return listener != null - && this.discordList.contains(listener); - } - - /** - * Returns whether the listener manager contains the specified event - * listener - * - * @param listener Listener to be checked - * @return True if the listener manager contains the specified listener, - * false otherwise - */ - @Contract("null -> false") - public boolean containsEvent(final @Nullable EventListener listener) { - return listener != null - && this.eventList.contains(listener); - } - - /** - * Returns whether the listener manager contains the specified packet - * listener - * - * @param listener Listener to be checked - * @return True if the listener manager contains the specified listener, - * false otherwise - */ - @Contract("null -> false") - public boolean containsPacket(final @Nullable PacketListener listener) { - if (listener == null) { - return false; - } - - for (final var list : this.receivePacketMap.values()) { - if (list.contains(listener)) { - return true; - } - } - - for (final var list : this.sendPacketMap.values()) { - if (list.contains(listener)) { - return true; - } - } - - return false; - } - - /** - * Returns whether the listener manager contains the specified packet type - * - * @param packetType Packet type to be checked - * @return True if the listener manager contains the specified packet type, - * false otherwise - */ - public boolean containsPacketType(final @Nullable PacketType packetType) { - return packetType != null - && ( - packetType.isReceive() - ? this.receivePacketMap.containsKey(packetType) - : this.sendPacketMap.containsKey(packetType) - ); - } - - /** - * Calls a packet event to all registered packet listeners with the - * whitelist containing the packet type of the event - * - * @param event Packet event to be called - * @see PacketEvent - */ - public void callPacketReceiveEvent(final @NotNull PacketEvent event) { - final PacketType packetType = event.getPacketContainer().getType(); - - if (this.containsPacketType(packetType)) { - for (final var listener : this.packetListeners(packetType)) { - listener.onPacketReceive(event); - } - } - } - - /** - * Calls a packet event to all registered packet listeners with the - * whitelist containing the packet type of the event - * - * @param event Packet event to be called - * @see PacketEvent - */ - public void callPacketSendEvent(final @NotNull PacketEvent event) { - final PacketType packetType = event.getPacketContainer().getType(); - - if (this.containsPacketType(packetType)) { - for (final var listener : this.packetListeners(packetType)) { - listener.onPacketSend(event); - } - } - } - - /** - * Bootstraps all listeners - */ - public void bootstrap() { - // - this.plugin.getStatusHandler().addWatcher( - StatusWatcher.builder() - .statuses(WhoMine.LOADED_DISCORD) - .successRunnable( - () -> { - new CommandAutoCompleteInteractionListener(this.plugin).register(); - new MessageReceivedListener(this.plugin).register(); - new SlashCommandInteractionListener(this.plugin).register(); - } - ) - .build() - ); - // - - // - - // Block listeners - new BlockBreakListener(this.plugin).register(); - new BlockDamageListener(this.plugin).register(); - new BlockDropItemListener(this.plugin).register(); - new BlockExplodeListener(this.plugin).register(); - new BlockPistonExtendListener(this.plugin).register(); - new BlockPistonRetractListener(this.plugin).register(); - new BlockPlaceListener(this.plugin).register(); - new NotePlayListener(this.plugin).register(); - - // Chat listeners - new AsyncChatListener(this.plugin).register(); - - // Command listeners - new UnknownCommandListener(this.plugin).register(); - - // Entity listeners - new EntityChangeBlockListener(this.plugin).register(); - new EntityDamageByEntityListener(this.plugin).register(); - new EntityDamageListener(this.plugin).register(); - new EntityDismountListener(this.plugin).register(); - new EntityExplodeListener(this.plugin).register(); - - // Hanging listeners - new HangingBreakByEntityListener(this.plugin).register(); - - // Inventory listeners - new InventoryClickListener(this.plugin).register(); - new InventoryCloseListener(this.plugin).register(); - new InventoryCreativeListener(this.plugin).register(); - new InventoryDragListener(this.plugin).register(); - new InventoryOpenListener(this.plugin).register(); - new PrepareAnvilListener(this.plugin).register(); - new PrepareItemCraftListener(this.plugin).register(); - - // Player listeners - new AsyncPlayerPreLoginListener(this.plugin).register(); - new PlayerAdvancementDoneListener(this.plugin).register(); - new PlayerBucketEmptyListener(this.plugin).register(); - new PlayerChangedWorldListener(this.plugin).register(); - new PlayerCommandPreprocessListener(this.plugin).register(); - new PlayerDeathListener(this.plugin).register(); - new PlayerDropItemListener(this.plugin).register(); - new PlayerEditBookListener(this.plugin).register(); - new PlayerGameModeChangeListener(this.plugin).register(); - new PlayerInteractEntityListener(this.plugin).register(); - new PlayerInteractListener(this.plugin).register(); - new PlayerJoinListener(this.plugin).register(); - new PlayerKickListener(this.plugin).register(); - new PlayerMoveListener(this.plugin).register(); - new PlayerQuitListener(this.plugin).register(); - new PlayerResourcePackStatusListener(this.plugin).register(); - new PlayerSpawnLocationListener(this.plugin).register(); - new PlayerSpawnLocationListener(this.plugin).register(); - new PlayerStopSpectatingEntityListener(this.plugin).register(); - new PlayerTeleportListener(this.plugin).register(); - - // Server listeners - new ServerCommandListener(this.plugin).register(); - - // Mechanic listeners - new BanSwordMechanic(this.plugin).register(); - new CardBoxMechanic(this.plugin).register(); - new CocaineMechanic(this.plugin).register(); - new DamageableItemMechanic(this.plugin).register(); - new DosimeterMechanic(this.plugin).register(); - new PoopMechanic(this.plugin).register(); - - // - - // - new PlayerActionListener(this.plugin).register(); - new PlayerUpdateSignListener(this.plugin).register(); - new SwingArmListener(this.plugin).register(); - // - } - - void registerDiscord(final @NotNull DiscordListener listener) throws IllegalStateException { - if (this.discordList.contains(listener)) { - throw new IllegalStateException("Listener is already registered"); - } - - this.plugin.getDiscordManager().getJda() - .ifPresent( - jda -> { - synchronized (this.discordList) { - this.discordList.add(listener); - } - - jda.addEventListener(listener); - } - ); - } - - void registerEvent(final @NotNull EventListener listener) throws IllegalStateException { - if (this.eventList.contains(listener)) { - throw new IllegalStateException("Listener is already registered"); - } - - synchronized (this.eventList) { - this.eventList.add(listener); - } - - this.plugin.getServer().getPluginManager().registerEvents(listener, this.plugin); - } - - void registerPacket(final @NotNull PacketListener listener) throws IllegalStateException, IllegalArgumentException { - if (this.containsPacket(listener)) { - throw new IllegalStateException("Listener is already registered"); - } - - final var receiveWhiteList = listener.getReceiveWhiteList(); - final var sendWhiteList = listener.getSendWhiteList(); - final int receiveSize = receiveWhiteList.size(); - final int sendSize = sendWhiteList.size(); - - if ( - receiveSize == 0 - && sendSize == 0 - ) { - throw new IllegalArgumentException("Packet listener must have at least one packet type in the whitelist"); - } - - if (receiveSize != 0) { - for (final var packetType : receiveWhiteList) { - synchronized (this.receivePacketMap) { - this.receivePacketMap - .computeIfAbsent(packetType, unused -> new ObjectArrayList<>()) - .add(listener); - } - } - } - - if (sendSize != 0) { - for (final var packetType : sendWhiteList) { - synchronized (this.sendPacketMap) { - this.sendPacketMap - .computeIfAbsent(packetType, unused -> new ObjectArrayList<>()) - .add(listener); - } - } - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/api/PacketListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/api/PacketListener.java deleted file mode 100644 index f1cd1080..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/api/PacketListener.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.minersstudios.whomine.listener.api; - -import com.google.common.base.Joiner; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.packet.PacketEvent; -import com.minersstudios.whomine.packet.PacketType; -import com.minersstudios.whomine.plugin.AbstractPluginComponent; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.UnmodifiableView; - -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; - -public abstract class PacketListener extends AbstractPluginComponent { - private final Set sendWhiteList; - private final Set receiveWhiteList; - - /** - * Packet listener constructor - * - * @param plugin The plugin instance - * @param first The first packet type to listen to - * @param rest The other packet types to listen to (optional) - * @see PacketType - */ - protected PacketListener( - final @NotNull WhoMine plugin, - final @NotNull PacketType first, - final PacketType @NotNull ... rest - ) { - super(plugin); - - this.sendWhiteList = EnumSet.noneOf(PacketType.class); - this.receiveWhiteList = EnumSet.noneOf(PacketType.class); - - this.addPacketType(first); - - for (final var packetType : rest) { - this.addPacketType(packetType); - } - } - - /** - * @return Types of received packets listened to by this listener - * @see PacketType - */ - public final @NotNull @UnmodifiableView Set getReceiveWhiteList() { - return Collections.unmodifiableSet(this.receiveWhiteList); - } - - /** - * @return Types of sent packets listened to by this listener - * @see PacketType - */ - public final @NotNull @UnmodifiableView Set getSendWhiteList() { - return Collections.unmodifiableSet(this.sendWhiteList); - } - - @Override - public @NotNull String toString() { - return this.getClass().getSimpleName() + - "plugin=" + this.getPlugin() + - ", sendWhiteList=[" + Joiner.on(", ").join(this.sendWhiteList) + ']' + - ", receiveWhiteList=[" + Joiner.on(", ").join(this.receiveWhiteList) + ']' + - '}'; - } - - @Override - public void register() throws IllegalStateException { - this.getPlugin().getListenerManager().registerPacket(this); - this.onRegister(); - } - - /** - * Packet receive event handler - * - * @param event The packet event - */ - public void onPacketReceive(final @NotNull PacketEvent event) { - throw new UnsupportedOperationException("Packet receive not implemented for " + event.getPacketContainer().getType().getName()); - } - - /** - * Packet send event handler - * - * @param event The packet event - */ - public void onPacketSend(final @NotNull PacketEvent event) { - throw new UnsupportedOperationException("Packet send not implemented for " + event.getPacketContainer().getType().getName()); - } - - private void addPacketType(final @NotNull PacketType packetType) { - if (packetType.isReceive()) { - this.receiveWhiteList.add(packetType); - } else { - this.sendWhiteList.add(packetType); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/discord/CommandAutoCompleteInteractionListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/discord/CommandAutoCompleteInteractionListener.java deleted file mode 100644 index 242b6aa9..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/discord/CommandAutoCompleteInteractionListener.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.minersstudios.whomine.listener.impl.discord; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.command.api.SlashCommandExecutor; -import com.minersstudios.whomine.listener.api.DiscordListener; -import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; -import org.jetbrains.annotations.NotNull; - -public class CommandAutoCompleteInteractionListener extends DiscordListener { - - public CommandAutoCompleteInteractionListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @Override - public void onCommandAutoCompleteInteraction(final @NotNull CommandAutoCompleteInteractionEvent event) { - final SlashCommandExecutor executor = - this.getPlugin().getCommandManager().getDiscordExecutor(event.getCommandIdLong()); - - if (executor != null) { - executor.tabComplete(event); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/discord/MessageReceivedListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/discord/MessageReceivedListener.java deleted file mode 100644 index 12880fa9..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/discord/MessageReceivedListener.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.minersstudios.whomine.listener.impl.discord; - -import com.minersstudios.whomine.listener.api.DiscordListener; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.utility.MessageUtils; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.entities.channel.ChannelType; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextColor; -import org.jetbrains.annotations.NotNull; - -import static net.kyori.adventure.text.Component.text; - -public final class MessageReceivedListener extends DiscordListener { - - public MessageReceivedListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @Override - public void onMessageReceived(final @NotNull MessageReceivedEvent event) { - final User user = event.getAuthor(); - final Message message = event.getMessage(); - - if ( - user.isBot() - || user.isSystem() - ) { - return; - } - - if ( - event.isFromGuild() - && event.getChannel() == this.getPlugin().getDiscordManager().getGlobalChannel().orElse(null) - ) { - final Message referencedMessage = message.getReferencedMessage(); - final String reply = - referencedMessage != null - ? replaceReplyPlaceholders(referencedMessage) - : ""; - final Component messageComponent = craftComponent(message, reply); - - MessageUtils.sendGlobalMessage(messageComponent); - MSLogger.info(null, messageComponent); - } else if (event.isFromType(ChannelType.PRIVATE)) { - final WhoMine plugin = this.getPlugin(); - final long userID = user.getIdLong(); - final var handlerMap = plugin.getCache().getBotHandlers(); - BotHandler handler = handlerMap.get(userID); - - if (handler == null) { - handler = new BotHandler(plugin, event); - - handlerMap.put(userID, handler); - } - - handler.handleMessage(message); - } - } - - private static @NotNull Component craftComponent( - final @NotNull Message message, - final @NotNull String reply - ) { - return Font.Components.DISCORD - .color(NamedTextColor.WHITE) - .append(text(message.getAuthor().getName(), TextColor.color(112, 125, 223))) - .append(text(reply, TextColor.color(152, 162, 249))) - .append(text(" : ", TextColor.color(112, 125, 223))) - .append(text(craftAttachmentString(message), TextColor.color(165, 165, 255))) - .append(text(message.getContentDisplay(), TextColor.color(202, 202, 255))); - } - - private static @NotNull String replaceReplyPlaceholders(final @NotNull Message repliedMessage) { - return " (отвечая на \"" + craftAttachmentString(repliedMessage) + repliedMessage.getContentDisplay() + "\")"; - } - - private static @NotNull String craftAttachmentString(final @NotNull Message message) { - return message.getAttachments().isEmpty() - ? "" - : message.getAttachments().size() > 1 - ? "(вложения) " - : "(вложение) "; - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/discord/SlashCommandInteractionListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/discord/SlashCommandInteractionListener.java deleted file mode 100644 index 0fbbdef4..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/discord/SlashCommandInteractionListener.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.minersstudios.whomine.listener.impl.discord; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.command.api.SlashCommandExecutor; -import com.minersstudios.whomine.listener.api.DiscordListener; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import org.jetbrains.annotations.NotNull; - -public final class SlashCommandInteractionListener extends DiscordListener { - - public SlashCommandInteractionListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @Override - public void onSlashCommandInteraction(final @NotNull SlashCommandInteractionEvent event) { - final SlashCommandExecutor executor = - this.getPlugin().getCommandManager().getDiscordExecutor(event.getCommandIdLong()); - - if (executor != null) { - executor.execute(event); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockPistonExtendListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockPistonExtendListener.java deleted file mode 100644 index eb7fcad9..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockPistonExtendListener.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.block; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.MSDecorUtils; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockPistonExtendEvent; -import org.jetbrains.annotations.NotNull; - -public final class BlockPistonExtendListener extends EventListener { - - public BlockPistonExtendListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onBlockPistonExtend(final @NotNull BlockPistonExtendEvent event) { - for (final var block : event.getBlocks()) { - if (MSDecorUtils.isCustomDecorMaterial(block.getType())) { - event.setCancelled(true); - break; - } - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockPistonRetractListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockPistonRetractListener.java deleted file mode 100644 index 15c912e2..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockPistonRetractListener.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.block; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.MSDecorUtils; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.jetbrains.annotations.NotNull; - -public final class BlockPistonRetractListener extends EventListener { - - public BlockPistonRetractListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onBlockPistonRetract(final @NotNull BlockPistonRetractEvent event) { - for (final var block : event.getBlocks()) { - if (MSDecorUtils.isCustomDecorMaterial(block.getType())) { - event.setCancelled(true); - break; - } - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/NotePlayListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/NotePlayListener.java deleted file mode 100644 index ced12ae4..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/NotePlayListener.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.block; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.params.NoteBlockData; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.Instrument; -import org.bukkit.Note; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.NotePlayEvent; -import org.jetbrains.annotations.NotNull; - -public final class NotePlayListener extends EventListener { - private static final Instrument DEFAULT_INSTRUMENT = NoteBlockData.defaultData().instrument(); - private static final Note DEFAULT_NOTE = NoteBlockData.defaultData().note(); - - public NotePlayListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onNotePlay(final @NotNull NotePlayEvent event) { - if ( - !(event.getInstrument() == DEFAULT_INSTRUMENT - && event.getNote().equals(DEFAULT_NOTE)) - ) { - event.setCancelled(true); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/command/UnknownCommandListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/command/UnknownCommandListener.java deleted file mode 100644 index 83d0710f..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/command/UnknownCommandListener.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.command; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.MSLogger; -import org.bukkit.event.EventHandler; -import org.bukkit.event.command.UnknownCommandEvent; -import org.jetbrains.annotations.NotNull; - -import static com.minersstudios.whomine.locale.Translations.ERROR_UNKNOWN_COMMAND; - -public class UnknownCommandListener extends EventListener { - - public UnknownCommandListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onUnknownCommand(final @NotNull UnknownCommandEvent event) { - event.message(null); - MSLogger.severe( - event.getSender(), - ERROR_UNKNOWN_COMMAND.asTranslatable() - ); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityChangeBlockListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityChangeBlockListener.java deleted file mode 100644 index bdd41175..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityChangeBlockListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.entity; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.MSDecorUtils; -import org.bukkit.block.Block; -import org.bukkit.entity.FallingBlock; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -public final class EntityChangeBlockListener extends EventListener { - - public EntityChangeBlockListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onEntityChangeBlock(final @NotNull EntityChangeBlockEvent event) { - final Block block = event.getBlock(); - - if ( - event.getEntity() instanceof FallingBlock - && MSDecorUtils.isCustomDecor(block) - ) { - event.setCancelled(true); - block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(event.getTo())); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityDamageListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityDamageListener.java deleted file mode 100644 index 5f5a1e72..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityDamageListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.entity; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageEvent; -import org.jetbrains.annotations.NotNull; - -public final class EntityDamageListener extends EventListener { - - public EntityDamageListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(ignoreCancelled = true) - public void onEntityDamage(final @NotNull EntityDamageEvent event) { - if ( - event.getEntity() instanceof Player player - && this.getPlugin().getCache().getWorldDark().isInWorldDark(player) - ) { - event.setCancelled(true); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityDismountListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityDismountListener.java deleted file mode 100644 index 1f442547..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityDismountListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.entity; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.player.PlayerInfo; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDismountEvent; -import org.jetbrains.annotations.NotNull; - -public final class EntityDismountListener extends EventListener { - - public EntityDismountListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onEntityDismount(final @NotNull EntityDismountEvent event) { - if (event.getEntity() instanceof final Player player) { - PlayerInfo - .fromOnlinePlayer(this.getPlugin(), player) - .unsetSitting(); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityExplodeListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityExplodeListener.java deleted file mode 100644 index 8df6d34c..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityExplodeListener.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.entity; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.jetbrains.annotations.NotNull; - -public final class EntityExplodeListener extends EventListener { - - public EntityExplodeListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onEntityExplode(final @NotNull EntityExplodeEvent event) { - final World world = event.getLocation().getWorld(); - - for (final var block : event.blockList()) { - if (block.getType() == Material.NOTE_BLOCK) { - block.setType(Material.AIR); - world.dropItemNaturally( - block.getLocation(), - CustomBlockRegistry - .fromBlockData(block.getBlockData()) - .orElse(CustomBlockData.defaultData()) - .craftItemStack() - ); - } - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/hanging/HangingBreakByEntityListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/hanging/HangingBreakByEntityListener.java deleted file mode 100644 index 0fffeb41..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/hanging/HangingBreakByEntityListener.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.hanging; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.SharedConstants; -import org.bukkit.entity.ItemFrame; -import org.bukkit.event.EventHandler; -import org.bukkit.event.hanging.HangingBreakByEntityEvent; -import org.jetbrains.annotations.NotNull; - -public final class HangingBreakByEntityListener extends EventListener { - - public HangingBreakByEntityListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onHangingBreakByEntity(final @NotNull HangingBreakByEntityEvent event) { - if ( - event.getEntity() instanceof final ItemFrame itemFrame - && itemFrame.getScoreboardTags().contains(SharedConstants.INVISIBLE_ITEM_FRAME_TAG) - && itemFrame.isVisible() - ) { - itemFrame.removeScoreboardTag(SharedConstants.INVISIBLE_ITEM_FRAME_TAG); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryCloseListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryCloseListener.java deleted file mode 100644 index c5eea638..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryCloseListener.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.inventory; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.event.EventHandler; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.jetbrains.annotations.NotNull; - -public final class InventoryCloseListener extends EventListener { - - public InventoryCloseListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onInventoryClose(final @NotNull InventoryCloseEvent event) { - if (event.getInventory() instanceof final CustomInventory customInventory) { - customInventory.doCloseAction(event); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryDragListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryDragListener.java deleted file mode 100644 index ea4ec3c3..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryDragListener.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.inventory; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.jetbrains.annotations.NotNull; - -public final class InventoryDragListener extends EventListener { - - public InventoryDragListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onInventoryDrag(final @NotNull InventoryDragEvent event) { - if (!(event.getInventory() instanceof final CustomInventory customInventory)) { - return; - } - - for (final int slot : event.getRawSlots()) { - if (slot >= 0 && slot < customInventory.getSize()) { - event.setCancelled(true); - break; - } - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryOpenListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryOpenListener.java deleted file mode 100644 index 50e00cca..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryOpenListener.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.inventory; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.event.EventHandler; -import org.bukkit.event.inventory.InventoryOpenEvent; -import org.jetbrains.annotations.NotNull; - -public final class InventoryOpenListener extends EventListener { - - public InventoryOpenListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onInventoryOpen(final @NotNull InventoryOpenEvent event) { - if (event.getInventory() instanceof final CustomInventory customInventory) { - customInventory.doOpenAction(event); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/PrepareAnvilListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/PrepareAnvilListener.java deleted file mode 100644 index 74b8f87c..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/PrepareAnvilListener.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.inventory; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.decor.CustomDecorData; -import com.minersstudios.whomine.custom.item.CustomItem; -import com.minersstudios.whomine.custom.item.renameable.RenameableItem; -import com.minersstudios.whomine.custom.item.renameable.RenameableItemRegistry; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.MSCustomUtils; -import org.bukkit.OfflinePlayer; -import org.bukkit.event.EventHandler; -import org.bukkit.event.inventory.PrepareAnvilEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; -import org.bukkit.persistence.PersistentDataType; -import org.jetbrains.annotations.NotNull; - -public final class PrepareAnvilListener extends EventListener { - - public PrepareAnvilListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPrepareAnvil(final @NotNull PrepareAnvilEvent event) { - final ItemStack resultItem = event.getResult(); - final ItemStack firstItem = event.getInventory().getFirstItem(); - final String renameText = event.getInventory().getRenameText(); - - if ( - resultItem == null - || firstItem == null - ) { - return; - } - - final RenameableItem renameableItem = RenameableItemRegistry.fromRename(renameText, resultItem).orElse(null); - - if ( - renameableItem != null - && renameableItem.isWhiteListed((OfflinePlayer) event.getViewers().get(0)) - ) { - final ItemStack renamedItem = renameableItem.craftRenamed(resultItem, renameText); - - if (renamedItem != null) { - event.setResult(renamedItem); - } - } else { - final ItemMeta meta = resultItem.getItemMeta(); - final var custom = MSCustomUtils.getCustom(firstItem).orElse(null); - ItemStack customStack = null; - - if (custom == null) { - meta.setCustomModelData(null); - resultItem.setItemMeta(meta); - event.setResult(resultItem); - return; - } else if (custom instanceof final CustomBlockData data) { - customStack = data.craftItemStack(); - } else if (custom instanceof final CustomItem item) { - customStack = item.getItem().clone(); - } else if (custom instanceof final CustomDecorData data) { - customStack = data.getItem().clone(); - } - - assert customStack != null; - - final ItemMeta customMeta = customStack.getItemMeta(); - final PersistentDataContainer container = meta.getPersistentDataContainer(); - final PersistentDataContainer dataContainer = customMeta.getPersistentDataContainer(); - - meta.setCustomModelData(customMeta.getCustomModelData()); - meta.lore(customMeta.lore()); - container.getKeys().forEach(container::remove); - - for (final var key : dataContainer.getKeys()) { - final String keyStr = dataContainer.get(key, PersistentDataType.STRING); - - if (keyStr != null) { - container.set(key, PersistentDataType.STRING, keyStr); - } - } - - resultItem.setItemMeta(meta); - event.setResult(resultItem); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/BanSwordMechanic.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/BanSwordMechanic.java deleted file mode 100644 index 6cf9d8f6..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/BanSwordMechanic.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.mechanic; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -public final class BanSwordMechanic extends EventListener { - - public BanSwordMechanic(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onEntityDamageByEntity(final @NotNull EntityDamageByEntityEvent event) { - if ( - !(event.getDamager() instanceof final Player damager) - || CustomItemType.fromItemStack(damager.getInventory().getItemInMainHand()) != CustomItemType.BAN_SWORD - ) { - return; - } - - final Entity damagedEntity = event.getEntity(); - event.setCancelled(!damager.isOp() || damagedEntity instanceof Player); - - if (damager.isOp() && damagedEntity instanceof final Player damaged) { - damager.performCommand("ban " + damaged.getName() + " 1000y Вы были поражены великим Бан-Мечём"); - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onInventoryClick(final @NotNull InventoryClickEvent event) { - final ItemStack currentItem = event.getCurrentItem(); - - if ( - currentItem == null - || CustomItemType.fromItemStack(currentItem) != CustomItemType.BAN_SWORD - ) { - return; - } - - currentItem.setAmount(0); - event.setCancelled(true); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/CardBoxMechanic.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/CardBoxMechanic.java deleted file mode 100644 index 6b876ab3..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/CardBoxMechanic.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.mechanic; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.item.CustomItem; -import com.minersstudios.whomine.custom.item.registry.cards.CardsBicycle; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.ItemUtils; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.inventory.InventoryMoveItemEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BundleMeta; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public final class CardBoxMechanic extends EventListener { - private static final List CARDS = new ObjectArrayList<>(); - - public CardBoxMechanic(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onInventoryMoveItem(final @NotNull InventoryMoveItemEvent event) { - if (event.getDestination().getType() != InventoryType.SHULKER_BOX) { - return; - } - - CustomItem.fromItemStack(event.getItem()) - .filter(customItem -> customItem instanceof CardsBicycle) - .ifPresent( - c -> event.setCancelled(true) - ); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onInventoryDrag(final @NotNull InventoryDragEvent event) { - if (event.getInventory().getType() != InventoryType.SHULKER_BOX) { - return; - } - - CustomItem.fromItemStack(event.getOldCursor()) - .filter(customItem -> customItem instanceof CardsBicycle) - .ifPresent( - c -> event.setCancelled(true) - ); - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onInventoryClick(final @NotNull InventoryClickEvent event) { - final ItemStack cursorItem = event.getCursor(); - final ItemStack currentItem = event.getCurrentItem(); - final Inventory clickedInventory = event.getClickedInventory(); - - if ( - ( - clickedInventory != null - && clickedInventory.getType() == InventoryType.SHULKER_BOX - && CustomItem.fromItemStack(cursorItem).orElse(null) instanceof CardsBicycle - ) - || ( - event.isShiftClick() - && event.getWhoClicked().getOpenInventory().getType() == InventoryType.SHULKER_BOX - && CustomItem.fromItemStack(currentItem).orElse(null) instanceof CardsBicycle - ) - ) { - event.setCancelled(true); - } - - if ( - currentItem == null - || !event.isRightClick() - ) { - return; - } - - if ( - !cursorItem.getType().isAir() - && CustomItem.fromItemStack(currentItem).orElse(null) instanceof CardsBicycle - ) { - addCardToCardBox(event, currentItem, cursorItem); - } else if ( - !currentItem.getType().isAir() - && CustomItem.fromItemStack(cursorItem).orElse(null) instanceof CardsBicycle - ) { - addCardToCardBox(event, cursorItem, currentItem); - } - } - - @SuppressWarnings("UnstableApiUsage") - private static void addCardToCardBox( - final @NotNull InventoryClickEvent event, - final @NotNull ItemStack cardBoxItem, - final @NotNull ItemStack cardItem - ) { - if (CARDS.isEmpty()) { - CARDS.addAll(CardsBicycle.Blue.cardItems()); - CARDS.addAll(CardsBicycle.Red.cardItems()); - } - - if (ItemUtils.isContainsItem(CARDS, cardItem)) { - final BundleMeta bundleMeta = (BundleMeta) cardBoxItem.getItemMeta(); - final var itemStacks = new ObjectArrayList(); - - itemStacks.add(cardItem); - itemStacks.addAll(bundleMeta.getItems()); - - if (itemStacks.size() <= 54) { - bundleMeta.setItems(itemStacks); - cardBoxItem.setItemMeta(bundleMeta); - cardItem.setAmount(0); - } - } - - event.setCancelled(true); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/CocaineMechanic.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/CocaineMechanic.java deleted file mode 100644 index bf5c5b3a..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/CocaineMechanic.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.mechanic; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerItemConsumeEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.PotionMeta; -import org.jetbrains.annotations.NotNull; - -public final class CocaineMechanic extends EventListener { - - public CocaineMechanic(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onInventoryClick(final @NotNull PlayerItemConsumeEvent event) { - final ItemStack itemStack = event.getItem(); - - if ( - !(itemStack.getItemMeta() instanceof PotionMeta) - || CustomItemType.fromItemStack(itemStack) != CustomItemType.COCAINE - ) { - return; - } - - this.getPlugin().runTask( - () -> event.getPlayer().getInventory().getItem(event.getHand()).setAmount(0) - ); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/DamageableItemMechanic.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/DamageableItemMechanic.java deleted file mode 100644 index d2cac6d0..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/DamageableItemMechanic.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.mechanic; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.item.damageable.DamageableItem; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.ItemUtils; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerItemDamageEvent; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -public final class DamageableItemMechanic extends EventListener { - - public DamageableItemMechanic(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerItemDamage(final @NotNull PlayerItemDamageEvent event) { - final ItemStack itemStack = event.getItem(); - - if (DamageableItem.fromItemStack(itemStack) != null) { - event.setCancelled(true); - ItemUtils.damageItem(event.getPlayer(), event.getItem(), event.getDamage()); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/DosimeterMechanic.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/DosimeterMechanic.java deleted file mode 100644 index 1f7cb5eb..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/DosimeterMechanic.java +++ /dev/null @@ -1,296 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.mechanic; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.anomaly.Anomaly; -import com.minersstudios.whomine.custom.item.CustomItem; -import com.minersstudios.whomine.custom.item.registry.Dosimeter; -import com.minersstudios.whomine.listener.api.EventListener; -import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.*; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import static net.kyori.adventure.text.Component.text; - -public final class DosimeterMechanic extends EventListener { - - public DosimeterMechanic(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerSwapHandItems(final @NotNull PlayerSwapHandItemsEvent event) { - final Player player = event.getPlayer(); - final var players = this.getPlugin().getCache().getDosimeterPlayers(); - final EquipmentSlot equipmentSlot = players.get(player); - - if (equipmentSlot != null) { - players.put(player, equipmentSlot == EquipmentSlot.HAND ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND); - } - } - - @EventHandler - public void onPlayerItemHeld(final @NotNull PlayerItemHeldEvent event) { - final Player player = event.getPlayer(); - final var players = this.getPlugin().getCache().getDosimeterPlayers(); - final EquipmentSlot equipmentSlot = players.get(player); - - if (equipmentSlot == EquipmentSlot.HAND) { - final ItemStack dosimeterItem = player.getInventory().getItem(event.getPreviousSlot()); - - CustomItem.fromItemStack(dosimeterItem, Dosimeter.class) - .ifPresent(dosimeter -> { - final Dosimeter copy = dosimeter.copy(); - - assert dosimeterItem != null; - - copy.setItem(dosimeterItem); - copy.setEnabled(false); - players.remove(player); - }); - } - } - - @EventHandler - public void onInventoryClick(final @NotNull InventoryClickEvent event) { - final Player player = (Player) event.getWhoClicked(); - final Inventory inventory = event.getClickedInventory(); - final ClickType clickType = event.getClick(); - - if (!(inventory instanceof final PlayerInventory playerInventory)) { - return; - } - - final var players = this.getPlugin().getCache().getDosimeterPlayers(); - final EquipmentSlot equipmentSlot = players.get(player); - - if (equipmentSlot == null) { - return; - } - - final ItemStack dosimeterItem = playerInventory.getItem(equipmentSlot); - - CustomItem.fromItemStack(dosimeterItem, Dosimeter.class) - .ifPresent(dosimeter -> { - final Dosimeter copy = dosimeter.copy(); - final EquipmentSlot newEquipmentSlot = equipmentSlot == EquipmentSlot.HAND ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND; - - if ( - clickType.isShiftClick() - || (clickType == ClickType.SWAP_OFFHAND - && equipmentSlot == EquipmentSlot.OFF_HAND - && event.getSlot() != playerInventory.getHeldItemSlot()) - ) { - copy.setItem(clickType.isShiftClick() ? Objects.requireNonNull(event.getCurrentItem()) : dosimeterItem); - copy.setEnabled(false); - players.remove(player); - - return; - } - - this.getPlugin().runTask(() -> { - if (dosimeterItem.equals(playerInventory.getItem(newEquipmentSlot))) { - players.put(player, newEquipmentSlot); - } else if (!dosimeterItem.equals(playerInventory.getItem(equipmentSlot))) { - copy.setItem( - clickType.isKeyboardClick() - ? dosimeterItem - : Objects.requireNonNull(event.getCursor()) - ); - copy.setEnabled(false); - players.remove(player); - } - }); - }); - } - - @EventHandler - public void onPlayerDropItem(final @NotNull PlayerDropItemEvent event) { - final Player player = event.getPlayer(); - final var players = this.getPlugin().getCache().getDosimeterPlayers(); - final EquipmentSlot equipmentSlot = players.get(player); - - if (equipmentSlot != null) { - final ItemStack drop = event.getItemDrop().getItemStack(); - final ItemStack itemStack = player.getInventory().getItem(equipmentSlot); - - CustomItem.fromItemStack(itemStack, Dosimeter.class) - .ifPresent(dosimeter -> { - if (CustomItem.fromItemStack(drop, Dosimeter.class).isEmpty()) { - return; - } - - final Dosimeter copy = dosimeter.copy(); - - copy.setItem(drop); - copy.setEnabled(false); - players.remove(player); - }); - } - } - - @EventHandler - public void onPlayerQuit(final @NotNull PlayerQuitEvent event) { - final Player player = event.getPlayer(); - final EquipmentSlot equipmentSlot = this.getPlugin().getCache().getDosimeterPlayers().remove(player); - - if (equipmentSlot != null) { - final ItemStack itemStack = player.getInventory().getItem(equipmentSlot); - - CustomItem.fromItemStack(itemStack, Dosimeter.class) - .ifPresent(dosimeter -> { - final Dosimeter copy = dosimeter.copy(); - - copy.setItem(itemStack); - copy.setEnabled(false); - }); - } - } - - @EventHandler - public void onPlayerInteract(final @NotNull PlayerInteractEvent event) { - if (!event.getAction().isRightClick()) { - return; - } - - final Player player = event.getPlayer(); - final EquipmentSlot hand = event.getHand(); - - if ( - hand == null - || !hand.isHand() - ) { - return; - } - - final ItemStack itemInHand = player.getInventory().getItem(hand); - - CustomItem.fromItemStack(itemInHand, Dosimeter.class) - .ifPresent(dosimeter -> { - final Dosimeter copy = dosimeter.copy(); - - event.setCancelled(true); - copy.setItem(itemInHand); - copy.setEnabled(!copy.isEnabled()); - - if (copy.isEnabled()) { - this.getPlugin().getCache().getDosimeterPlayers().put(player, hand); - } else { - this.getPlugin().getCache().getDosimeterPlayers().remove(player, hand); - } - }); - } - - public static class DosimeterTask { - private final WhoMine plugin; - private final Map players; - - public DosimeterTask(final @NotNull WhoMine plugin) { - this.plugin = plugin; - this.players = plugin.getCache().getDosimeterPlayers(); - } - - public void run() { - if (this.players.isEmpty()) { - return; - } - - this.players - .forEach((player, equipmentSlot) -> { - if (!player.isOnline()) { - return; - } - - final ItemStack itemStack = player.getInventory().getItem(equipmentSlot); - - if (CustomItem.fromItemStack(itemStack).orElse(null) instanceof final Dosimeter dosimeter) { - final Dosimeter copy = dosimeter.copy(); - - copy.setItem(itemStack); - - if (copy.isEnabled()) { - final var radiiPlayerInside = new Object2DoubleOpenHashMap(); - - for (final var anomaly : this.plugin.getCache().getAnomalies().values()) { - final double radiusInside = anomaly.getBoundingBox().getRadiusInside(player); - - if (radiusInside != -1.0d) { - radiiPlayerInside.put(anomaly, radiusInside); - } - } - - final var anomalyEntry = getEntryWithMinValue(radiiPlayerInside); - final List radii = - anomalyEntry == null - ? Collections.emptyList() - : anomalyEntry.getKey().getBoundingBox().getRadii(); - final Double radius = - anomalyEntry == null - ? null - : anomalyEntry.getValue(); - - copy.setItem(itemStack); - copy.setScreenTypeByRadius(radii, radius); - player.sendActionBar( - text("Уровень радиации : ") - .append(text(radiusToLevel(radii, radius, player.getLocation()))) - .append(text(" мк3в/ч")) - ); - - return; - } - } - - this.players.remove(player); - }); - } - - private static @NotNull String radiusToLevel( - final @NotNull List radii, - final @Nullable Double radius, - final @NotNull Location loc - ) { - final var reversedRadii = new ObjectArrayList<>(radii); - - Collections.reverse(reversedRadii); - - final double indexOfRadius = reversedRadii.indexOf(radius); - final double afterComma = Math.round(((Math.abs(loc.getX()) + Math.abs(loc.getY()) + Math.abs(loc.getZ())) % 1.0d) * 10.0d) / 10.0d; - - return (indexOfRadius == -1.0d ? 0.0d : indexOfRadius + 1.0d) - + Math.min(afterComma, 0.9d) - + String.valueOf(Math.min(Math.round(Math.random() * 10.0d), 9)); - } - - private static @Nullable Map.Entry getEntryWithMinValue(final @NotNull Map map) { - Map.Entry minEntry = null; - double minValue = Double.POSITIVE_INFINITY; - - for (final var entry : map.entrySet()) { - final double value = entry.getValue(); - - if (value < minValue) { - minValue = value; - minEntry = entry; - } - } - - return minEntry; - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/PoopMechanic.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/PoopMechanic.java deleted file mode 100644 index 7b076679..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/mechanic/PoopMechanic.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.mechanic; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.decor.CustomDecorType; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.data.Levelled; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -public final class PoopMechanic extends EventListener { - - public PoopMechanic(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerInteract(final @NotNull PlayerInteractEvent event) { - if ( - event.getClickedBlock() == null - || event.getHand() == null - || event.getAction().isLeftClick() - ) { - return; - } - - final Block clickedBlock = event.getClickedBlock(); - - if (clickedBlock.getType() != Material.COMPOSTER) { - return; - } - - final Player player = event.getPlayer(); - final EquipmentSlot hand = event.getHand(); - final ItemStack itemInHand = player.getInventory().getItem(hand); - final GameMode gameMode = player.getGameMode(); - final Material handType = itemInHand.getType(); - - if ( - gameMode != GameMode.SPECTATOR - && !player.isSneaking() - && clickedBlock.getBlockData() instanceof final Levelled levelled - && ( - !handType.isBlock() - || handType == Material.AIR - ) - && levelled.getLevel() < levelled.getMaximumLevel() - && CustomDecorType.fromItemStack(itemInHand) == CustomDecorType.POOP - ) { - levelled.setLevel(levelled.getLevel() + 1); - clickedBlock.setBlockData(levelled); - player.swingHand(hand); - - if (gameMode != GameMode.CREATIVE) { - itemInHand.setAmount(itemInHand.getAmount() - 1); - } - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerBucketEmptyListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerBucketEmptyListener.java deleted file mode 100644 index 7b0fbd3d..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerBucketEmptyListener.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.MSDecorUtils; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerBucketEmptyListener extends EventListener { - - public PlayerBucketEmptyListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerBucketEmpty(final @NotNull PlayerBucketEmptyEvent event) { - final Block block = event.getBlock(); - - if ( - block.getType() == Material.NOTE_BLOCK - || CustomBlockRegistry.isCustomBlock(event.getPlayer().getInventory().getItemInMainHand()) - || ( - event.getBucket() == Material.LAVA_BUCKET - && MSDecorUtils.isCustomDecor(block) - ) - ) { - event.setCancelled(true); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerChangedWorldListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerChangedWorldListener.java deleted file mode 100644 index 75ec1ac1..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerChangedWorldListener.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.MSPlayerUtils; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerChangedWorldListener extends EventListener { - - public PlayerChangedWorldListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerChangedWorld(final @NotNull PlayerChangedWorldEvent event) { - MSPlayerUtils.hideNameTag( - this.getPlugin(), - event.getPlayer() - ); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerCommandPreprocessListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerCommandPreprocessListener.java deleted file mode 100644 index dd4199d8..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerCommandPreprocessListener.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerCommandPreprocessListener extends EventListener { - - public PlayerCommandPreprocessListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerCommandPreprocess(final @NotNull PlayerCommandPreprocessEvent event) { - final Player player = event.getPlayer(); - final String message = event.getMessage(); - - if ( - ( - message.startsWith("/l") - && !message.startsWith("/logout") - ) - || message.startsWith("/reg") - || !this.getPlugin().getCache().getWorldDark().isInWorldDark(player) - ) { - return; - } - - event.setCancelled(true); - MSLogger.warning( - player, - Translations.WARNING_YOU_CANT_DO_THIS_NOW.asTranslatable() - ); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerDeathListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerDeathListener.java deleted file mode 100644 index 000f3150..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerDeathListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.Cache; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.MessageUtils; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerDeathListener extends EventListener { - - public PlayerDeathListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerDeath(final @NotNull PlayerDeathEvent event) { - final Player player = event.getEntity(); - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); - final Cache cache = this.getPlugin().getCache(); - - cache.getDiggingMap().removeAll(player); - cache.getStepMap().put(player, 0.0d); - event.deathMessage(null); - playerInfo.unsetSitting(); - MessageUtils.sendDeathMessage(player, player.getKiller()); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerDropItemListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerDropItemListener.java deleted file mode 100644 index 66b08fe0..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerDropItemListener.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerDropItemListener extends EventListener { - - public PlayerDropItemListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(ignoreCancelled = true) - public void onPlayerDropItem(final @NotNull PlayerDropItemEvent event) { - if (this.getPlugin().getCache().getWorldDark().isInWorldDark(event.getPlayer())) { - event.setCancelled(true); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerGameModeChangeListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerGameModeChangeListener.java deleted file mode 100644 index 2e3d4dec..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerGameModeChangeListener.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerGameModeChangeEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerGameModeChangeListener extends EventListener { - - public PlayerGameModeChangeListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerGameModeChange(final @NotNull PlayerGameModeChangeEvent event) { - this.getPlugin().getCache().getDiggingMap().removeAll(event.getPlayer()); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerJoinListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerJoinListener.java deleted file mode 100644 index e28a166c..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerJoinListener.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.packet.ChannelHandler; -import com.minersstudios.whomine.player.PlayerInfo; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerJoinEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerJoinListener extends EventListener { - - public PlayerJoinListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerJoin(final @NotNull PlayerJoinEvent event) { - final WhoMine plugin = this.getPlugin(); - final Player player = event.getPlayer(); - - plugin.runTask(() -> - ChannelHandler.injectConnection( - ((CraftPlayer) event.getPlayer()).getHandle().connection.connection, - plugin - ) - ); - - event.joinMessage(null); - - if (player.isDead()) { - this.getPlugin().runTaskLater(() -> { - player.spigot().respawn(); - this.handle(player); - }, 8L); - } else { - this.handle(player); - } - } - - private void handle(final @NotNull Player player) { - final WhoMine plugin = this.getPlugin(); - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(plugin, player); - - playerInfo.hideNameTag(); - player.displayName(playerInfo.getDefaultName()); - plugin.getCache().getWorldDark() - .teleportToDarkWorld(player) - .thenRun(() -> plugin.runTaskTimer(task -> { - if (!player.isOnline()) { - task.cancel(); - return; - } - - if (playerInfo.isAuthenticated()) { - task.cancel(); - playerInfo.handleResourcePack().thenAccept(bool -> { - if (bool) { - playerInfo.handleJoin(); - } - }); - } - }, 0L, 10L)); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerQuitListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerQuitListener.java deleted file mode 100644 index 10c6e099..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerQuitListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.Cache; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.player.PlayerInfo; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerQuitEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerQuitListener extends EventListener { - - public PlayerQuitListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerQuit(final @NotNull PlayerQuitEvent event) { - final Player player = event.getPlayer(); - final Cache cache = this.getPlugin().getCache(); - - cache.getDiggingMap().removeAll(player); - cache.getStepMap().remove(player); - - event.quitMessage(null); - PlayerInfo - .fromOnlinePlayer(this.getPlugin(), event.getPlayer()) - .handleQuit(); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerResourcePackStatusListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerResourcePackStatusListener.java deleted file mode 100644 index dab0c6cb..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerResourcePackStatusListener.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.ResourcePack; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerResourcePackStatusEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerResourcePackStatusListener extends EventListener { - - public PlayerResourcePackStatusListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerResourcePackStatus(final @NotNull PlayerResourcePackStatusEvent event) { - final PlayerResourcePackStatusEvent.Status status = event.getStatus(); - final Player player = event.getPlayer(); - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); - final ResourcePack.Type currentType = playerInfo.getPlayerFile().getPlayerSettings().getResourcePackType(); - - if ( - currentType == ResourcePack.Type.NULL - || status == PlayerResourcePackStatusEvent.Status.ACCEPTED - ) { - return; - } - - playerInfo.completeResourcePackFuture(status); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerSpawnLocationListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerSpawnLocationListener.java deleted file mode 100644 index 08b1bce0..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerSpawnLocationListener.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.event.EventHandler; -import org.jetbrains.annotations.NotNull; -import org.spigotmc.event.player.PlayerSpawnLocationEvent; - -public final class PlayerSpawnLocationListener extends EventListener { - - public PlayerSpawnLocationListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerSpawnLocation(final @NotNull PlayerSpawnLocationEvent event) { - if (!event.getPlayer().isDead()) { - event.setSpawnLocation(this.getPlugin().getCache().getWorldDark().getSpawnLocation()); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerStopSpectatingEntityListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerStopSpectatingEntityListener.java deleted file mode 100644 index cdb46f8b..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerStopSpectatingEntityListener.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.destroystokyo.paper.event.player.PlayerStopSpectatingEntityEvent; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import org.bukkit.event.EventHandler; -import org.jetbrains.annotations.NotNull; - -public final class PlayerStopSpectatingEntityListener extends EventListener { - - public PlayerStopSpectatingEntityListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerStopSpectatingEntity(final @NotNull PlayerStopSpectatingEntityEvent event) { - if (this.getPlugin().getCache().getWorldDark().isInWorldDark(event.getPlayer())) { - event.setCancelled(true); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerTeleportListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerTeleportListener.java deleted file mode 100644 index f451e149..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerTeleportListener.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.Cache; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.player.PlayerInfo; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.jetbrains.annotations.NotNull; - -public final class PlayerTeleportListener extends EventListener { - - public PlayerTeleportListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerTeleport(final @NotNull PlayerTeleportEvent event) { - final Player player = event.getPlayer(); - final Cache cache = this.getPlugin().getCache(); - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); - - cache.getDiggingMap().removeAll(player); - cache.getStepMap().put(player, 0.0d); - - if (playerInfo.isSitting()) { - playerInfo.unsetSitting(); - } - - if ( - event.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE - && playerInfo.isInWorldDark() - ) { - event.setCancelled(true); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/server/ServerCommandListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/server/ServerCommandListener.java deleted file mode 100644 index 5114e305..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/server/ServerCommandListener.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.minersstudios.whomine.listener.impl.event.server; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; -import org.bukkit.event.EventHandler; -import org.bukkit.event.server.ServerCommandEvent; -import org.jetbrains.annotations.NotNull; - -public final class ServerCommandListener extends EventListener { - - public ServerCommandListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onServerCommand(final @NotNull ServerCommandEvent event) { - final String command = event.getCommand().split(" ")[0]; - - if (this.getPlugin().getCommandManager().isPlayerOnly(command)) { - MSLogger.severe( - event.getSender(), - Translations.ERROR_ONLY_PLAYER_COMMAND.asTranslatable() - ); - event.setCancelled(true); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/packet/player/PlayerUpdateSignListener.java b/paper/src/main/java/com/minersstudios/whomine/listener/impl/packet/player/PlayerUpdateSignListener.java deleted file mode 100644 index feceb006..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/packet/player/PlayerUpdateSignListener.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.minersstudios.whomine.listener.impl.packet.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.SignMenu; -import com.minersstudios.whomine.listener.api.PacketListener; -import com.minersstudios.whomine.packet.PacketEvent; -import com.minersstudios.whomine.packet.PacketType; -import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public final class PlayerUpdateSignListener extends PacketListener { - - public PlayerUpdateSignListener(final @NotNull WhoMine plugin) { - super(plugin, PacketType.PLAY_SERVER_UPDATE_SIGN); - } - - @Override - public void onPacketReceive(final @NotNull PacketEvent event) { - final Player player = event.getConnection().getPlayer().getBukkitEntity(); - final SignMenu menu = SignMenu.getSignMenu(player); - - if ( - menu != null - && event.getPacketContainer().getPacket() instanceof final ServerboundSignUpdatePacket packet - ) { - if (!menu.getResponse().test(player, packet.getLines())) { - this.getPlugin().runTaskLater(() -> menu.open(player), 2L); - } else { - menu.close(player); - } - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/packet/ChannelHandler.java b/paper/src/main/java/com/minersstudios/whomine/packet/ChannelHandler.java deleted file mode 100644 index ad20bac5..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/packet/ChannelHandler.java +++ /dev/null @@ -1,184 +0,0 @@ -package com.minersstudios.whomine.packet; - -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import io.netty.channel.*; -import net.kyori.adventure.text.Component; -import net.minecraft.network.Connection; -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.level.ServerPlayer; -import org.bukkit.event.player.PlayerKickEvent; -import org.jetbrains.annotations.NotNull; - -import javax.annotation.concurrent.Immutable; - -/** - * The ChannelHandler class is responsible for handling incoming and outgoing - * packets in the Minecraft server networking pipeline. - *
      - * It extends {@link ChannelDuplexHandler}, which allows handling of both - * inbound and outbound data. - * - * @see PacketType - * @see PacketContainer - * @see PacketEvent - */ -@Immutable -public final class ChannelHandler extends ChannelDuplexHandler { - private final WhoMine plugin; - private final Connection connection; - - public static final String CHANNEL_HANDLER_NAME = "ms_channel_handler"; - public static final String PACKET_HANDLER_NAME = "packet_handler"; - - /** - * Channel handler constructor - * - * @param plugin The plugin associated with this channel handler - * @param connection The connection associated with this channel handler - */ - public ChannelHandler( - final @NotNull WhoMine plugin, - final @NotNull Connection connection - ) { - this.plugin = plugin; - this.connection = connection; - } - - /** - * @return The plugin associated with this channel handler - */ - public @NotNull WhoMine getPlugin() { - return this.plugin; - } - - /** - * @return The connection associated with this channel handler - */ - public @NotNull Connection getConnection() { - return this.connection; - } - - /** - * This method is called when a packet is received from the client. It - * processes the packet, creates a {@link PacketContainer}, and fires a - * {@link PacketEvent}. If the event is not cancelled, the packet is passed - * to the next channel handler in the pipeline. - * - * @param ctx The ChannelHandlerContext - * @param msg The received packet - * @throws Exception If an error occurs while processing the packet - */ - @Override - public void channelRead( - final @NotNull ChannelHandlerContext ctx, - final @NotNull Object msg - ) throws Exception { - if (!(msg instanceof final Packet packet)) { - return; - } - - final PacketType packetType = PacketType.fromClass(packet.getClass()); - - if (packetType == null) { - final ServerPlayer serverPlayer = this.connection.getPlayer(); - - this.plugin.runTask(() -> serverPlayer.connection.disconnect( - Component.text("Unknown packet type: " + packet.getClass().getName()), - PlayerKickEvent.Cause.PLUGIN - )); - MSLogger.severe("Unknown packet type: " + packet.getClass().getName() + " sent by " + serverPlayer.getName()); - return; - } - - final PacketContainer packetContainer = new PacketContainer(packet, packetType); - final PacketEvent event = new PacketEvent(packetContainer, this.connection); - - this.plugin.getListenerManager().callPacketReceiveEvent(event); - - if (!event.isCancelled()) { - super.channelRead(ctx, event.getPacketContainer().getPacket()); - } - } - - /** - * This method is called when a packet is about to be sent to the client. - * It processes the packet, creates a {@link PacketContainer}, and fires a - * {@link PacketEvent}. If the event is not cancelled, the packet is passed - * to the next channel handler in the pipeline. - * - * @param ctx The ChannelHandlerContext - * @param msg The packet to be sent - * @param promise The ChannelPromise - * @throws Exception If an error occurs while processing the packet - */ - @Override - public void write( - final @NotNull ChannelHandlerContext ctx, - final @NotNull Object msg, - final @NotNull ChannelPromise promise - ) throws Exception { - if (!(msg instanceof final Packet packet)) { - return; - } - - final PacketType packetType = PacketType.fromClass(packet.getClass()); - - if (packetType == null) { - final ServerPlayer serverPlayer = this.connection.getPlayer(); - - this.plugin.runTask(() -> serverPlayer.connection.disconnect( - Component.text("Unknown packet type: " + packet.getClass().getName()), - PlayerKickEvent.Cause.PLUGIN - )); - MSLogger.severe("Unknown packet type: " + packet.getClass().getName() + " sent to " + serverPlayer.getName()); - return; - } - - final PacketContainer packetContainer = new PacketContainer(packet, packetType); - final PacketEvent event = new PacketEvent(packetContainer, connection); - - this.plugin.getListenerManager().callPacketSendEvent(event); - - if (!event.isCancelled()) { - super.write(ctx, event.getPacketContainer().getPacket(), promise); - } - } - - /** - * Injects the {@link ChannelHandler} for a specific player into the server - * networking pipeline - * - * @param connection The connection to inject the ChannelHandler for - * @param plugin The MSPlugin instance associated with the ChannelHandler - */ - public static void injectConnection( - final @NotNull Connection connection, - final @NotNull WhoMine plugin - ) { - final ChannelPipeline pipeline = connection.channel.pipeline(); - - if (!pipeline.names().contains(ChannelHandler.CHANNEL_HANDLER_NAME)) { - pipeline.addBefore( - ChannelHandler.PACKET_HANDLER_NAME, - ChannelHandler.CHANNEL_HANDLER_NAME, - new ChannelHandler(plugin, connection) - ); - } - } - - /** - * Removes the {@link ChannelHandler} from a specific player in the server - * networking pipeline - * - * @param connection The connection to remove the ChannelHandler for - */ - public static void uninjectConnection(final @NotNull Connection connection) { - final Channel channel = connection.channel; - final ChannelPipeline pipeline = channel.pipeline(); - - if (pipeline.names().contains(CHANNEL_HANDLER_NAME)) { - channel.eventLoop().execute(() -> pipeline.remove(CHANNEL_HANDLER_NAME)); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/packet/PacketContainer.java b/paper/src/main/java/com/minersstudios/whomine/packet/PacketContainer.java deleted file mode 100644 index 6b948ba9..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/packet/PacketContainer.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.minersstudios.whomine.packet; - -import net.minecraft.network.protocol.Packet; -import org.jetbrains.annotations.NotNull; - -/** - * Represents a packet container. It contains the packet and the packet type. - * The packet type contains the id, flow, name and class of the packet. The - * packet can be modified, but the packet type cannot be changed. - * - * @see PacketType - */ -public final class PacketContainer { - private Packet packet; - private final PacketType type; - - /** - * Packet container constructor - * - * @param packet The packet to contain - * @param type The packet type of the packet - */ - public PacketContainer( - final @NotNull Packet packet, - final @NotNull PacketType type - ) { - this.packet = packet; - this.type = type; - } - - /** - * @return The packet contained in this container - */ - public @NotNull Packet getPacket() { - return this.packet; - } - - /** - * @param packet The packet to set - * @throws IllegalArgumentException If the packet type of the packet is not - * the same as the packet type of this - * container - * (Checks by comparing the classes) - */ - public void setPacket(final @NotNull Packet packet) throws IllegalArgumentException { - if (this.packet.getClass() != packet.getClass()) { - throw new IllegalArgumentException("Packet type cannot be changed!"); - } - - this.packet = packet; - } - - /** - * @return The packet type of the packet contained in this container - */ - public @NotNull PacketType getType() { - return this.type; - } - - /** - * @return The string representation of this packet container - */ - @Override - public @NotNull String toString() { - return "PacketContainer{" + - "packet=" + this.packet.getClass() + - ", type=" + this.type + - '}'; - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/packet/PacketEvent.java b/paper/src/main/java/com/minersstudios/whomine/packet/PacketEvent.java deleted file mode 100644 index 25fb2f62..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/packet/PacketEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.minersstudios.whomine.packet; - -import net.minecraft.network.Connection; -import org.bukkit.event.Cancellable; -import org.jetbrains.annotations.NotNull; - -/** - * Represents a packet event. It contains the packet container and the player - * who sent or received the packet. It also implements {@link Cancellable} so - * the packet can be cancelled. The packet container contains the packet and the - * packet type and can be modified, but the packet type cannot be changed. - * - * @see PacketContainer - * @see Cancellable - */ -public class PacketEvent implements Cancellable { - private final PacketContainer packetContainer; - private final Connection connection; - private boolean cancelled; - - /** - * @param packetContainer The packet container - * @param connection The connection - */ - public PacketEvent( - final @NotNull PacketContainer packetContainer, - final @NotNull Connection connection - ) { - this.packetContainer = packetContainer; - this.connection = connection; - } - - /** - * @return The packet container of this event - */ - public final @NotNull PacketContainer getPacketContainer() { - return this.packetContainer; - } - - /** - * @return The player who sent or received the packet - */ - public final @NotNull Connection getConnection() { - return this.connection; - } - - /** - * Sets the cancellation state of this event. A cancelled event will not be - * sent or received. - * - * @param cancel True if you wish to cancel this event - */ - @Override - public final void setCancelled(final boolean cancel) { - this.cancelled = cancel; - } - - /** - * @return True if this event is cancelled - */ - @Override - public final boolean isCancelled() { - return this.cancelled; - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/packet/PacketProtocol.java b/paper/src/main/java/com/minersstudios/whomine/packet/PacketProtocol.java deleted file mode 100644 index 5b57ea4f..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/packet/PacketProtocol.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.minersstudios.whomine.packet; - -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.network.ConnectionProtocol; -import net.minecraft.network.protocol.PacketFlow; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Unmodifiable; - -import java.util.Collections; -import java.util.Map; - -import static com.minersstudios.whomine.packet.PacketType.*; - -/** - * Represents the different packet protocols used in Minecraft. Each protocol - * corresponds to a specific phase in the network connection process. - * - * @see PacketType - * @see PacketFlow - * @see PacketRegistry - * @see Protocol Wiki - */ -public enum PacketProtocol { - HANDSHAKING ("handshake", HANDSHAKING_PACKET_MAP), - PLAY ("play", PLAY_PACKET_MAP), - STATUS ("status", STATUS_PACKET_MAP), - LOGIN ("login", LOGIN_PACKET_MAP), - CONFIGURATION("configuration", CONFIGURATION_PACKET_MAP); - - private final String stateId; - private final Map> packets; - - private static final PacketProtocol[] VALUES = values(); - - /** - * Constructor for the PacketProtocol enum - * - * @param stateId The state id of this protocol - * @param packets The map of packet types associated with this protocol, - * organized by packet flow and packet ID - */ - PacketProtocol( - final @NotNull String stateId, - final @NotNull Map> packets - ) { - this.stateId = stateId; - this.packets = packets; - } - - /** - * Get the state id of this protocol. The id is the same as the id of the - * {@link ConnectionProtocol} associated with this protocol. - * - * @return The state id of this protocol - */ - public @NotNull String getStateId() { - return this.stateId; - } - - /** - * Get the packet map associated with this protocol. The packet map contains - * packet types organized by packet flow and packet ID. - * - * @return The unmodifiable packet map of this protocol. - */ - public @NotNull @Unmodifiable Map> getPackets() { - return Collections.unmodifiableMap(this.packets); - } - - /** - * Gets the PacketProtocol associated with a specific - * {@link ConnectionProtocol} - * - * @param protocol The ConnectionProtocol for which to retrieve the - * corresponding PacketProtocol - * @return The PacketProtocol associated with the given ConnectionProtocol - */ - public static @NotNull PacketProtocol fromMinecraft(final @NotNull ConnectionProtocol protocol) { - return VALUES[protocol.ordinal()]; - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/packet/PacketRegistry.java b/paper/src/main/java/com/minersstudios/whomine/packet/PacketRegistry.java deleted file mode 100644 index baf9bd06..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/packet/PacketRegistry.java +++ /dev/null @@ -1,206 +0,0 @@ -package com.minersstudios.whomine.packet; - -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import net.minecraft.network.ConnectionProtocol; -import net.minecraft.network.protocol.PacketFlow; -import net.minecraft.network.protocol.game.ClientboundBundlePacket; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.UnmodifiableView; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import static net.minecraft.network.protocol.PacketFlow.*; - -/** - * Represents a packet registry for Minecraft packets. This class maps packet - * classes to their corresponding {@link PacketType} and vice versa. - * - * @see PacketType - * @see PacketProtocol - * @see PacketFlow - * @see Protocol Wiki - */ -public final class PacketRegistry { - private static final Map, PacketType> CLASS_TO_TYPE = new ConcurrentHashMap<>(); - private static final Map> TYPE_TO_CLASS = new ConcurrentHashMap<>(); - - static { - final ConnectionProtocol[] protocols = ConnectionProtocol.values(); - final var serverMaps = new LinkedHashMap>(); - final var clientMaps = new LinkedHashMap>(); - Field flowsField = null; - - for (final var field : ConnectionProtocol.class.getDeclaredFields()) { - if ( - field.getType() == Map.class - && Modifier.isFinal(field.getModifiers()) - && !Modifier.isStatic(field.getModifiers()) - ) { - flowsField = field; - flowsField.setAccessible(true); - break; - } - } - - if (flowsField == null) { - throw new IllegalStateException("Could not find 'flows' field in ConnectionProtocol class"); - } - - for (final var protocol : protocols) { - Map flowsMap; - - try { - flowsMap = (Map) flowsField.get(protocol); - } catch (final IllegalAccessException e) { - throw new IllegalStateException("Failed to access flows packet map", e); - } - - for (final var entry : flowsMap.entrySet()) { - final var flow = (PacketFlow) entry.getKey(); - final var codecData = entry.getValue(); - final Object packetSet; - Field packetSetField = null; - - for (final var field : codecData.getClass().getDeclaredFields()) { - if ( - field.getName().equals("c") - && Modifier.isFinal(field.getModifiers()) - ) { - packetSetField = field; - packetSetField.setAccessible(true); - break; - } - } - - if (packetSetField == null) { - throw new IllegalStateException("Could not find 'packetSet' field in codec data class"); - } - - try { - packetSet = packetSetField.get(codecData); - } catch (final ReflectiveOperationException e) { - throw new IllegalStateException("Failed to access packet set", e); - } - - final Object2IntMap packetMap; - Field packetMapField = null; - - for (final var field : packetSet.getClass().getDeclaredFields()) { - if ( - field.getType() == Object2IntMap.class - && Modifier.isFinal(field.getModifiers()) - && !Modifier.isStatic(field.getModifiers()) - ) { - packetMapField = field; - packetMapField.setAccessible(true); - break; - } - } - - if (packetMapField == null) { - throw new IllegalStateException("Could not find 'packetMap' field in packet set class"); - } - - try { - packetMap = (Object2IntMap) packetMapField.get(packetSet); - } catch (final ReflectiveOperationException e) { - throw new IllegalStateException("Failed to access packet map", e); - } - - switch (flow) { - case CLIENTBOUND -> clientMaps.put(protocol, packetMap); - case SERVERBOUND -> serverMaps.put(protocol, packetMap); - } - } - } - - for (final var protocol : protocols) { - final PacketProtocol packetProtocol = PacketProtocol.fromMinecraft(protocol); - - if (serverMaps.containsKey(protocol)) { - putPackets(serverMaps.get(protocol), packetProtocol, SERVERBOUND); - } - - if (clientMaps.containsKey(protocol)) { - putPackets(clientMaps.get(protocol), packetProtocol, CLIENTBOUND); - } - } - } - - /** - * Get an unmodifiable view of the map that maps packet classes to their - * corresponding {@link PacketType} - * - * @return An unmodifiable view of the map containing packet classes as keys - * and their corresponding {@link PacketType} as values - */ - public static @NotNull @UnmodifiableView Map, PacketType> getClassToType() { - return Collections.unmodifiableMap(CLASS_TO_TYPE); - } - - /** - * Get an unmodifiable view of the map that maps {@link PacketType} to their - * corresponding packet classes - * - * @return An unmodifiable view of the map containing {@link PacketType} as - * keys and their corresponding packet classes as values - */ - public static @NotNull @UnmodifiableView Map> getTypeToClass() { - return Collections.unmodifiableMap(TYPE_TO_CLASS); - } - - /** - * Get the {@link PacketType} associated with the given packet class - * - * @param packet The packet class for which to retrieve the corresponding - * {@link PacketType} - * @return The {@link PacketType} associated with the given packet class, or - * null if the packet class is not registered - */ - public static @Nullable PacketType getTypeFromClass(final @NotNull Class packet) { - return packet == ClientboundBundlePacket.class - ? PacketType.PLAY_CLIENT_BUNDLE_DELIMITER - : CLASS_TO_TYPE.get(packet); - } - - /** - * Get the packet class associated with the given - * {@link PacketType} - * - * @param type The {@link PacketType} for which to retrieve the - * corresponding packet class - * @return The packet class associated with the given {@link PacketType} - */ - public static @NotNull Class getClassFromType(final @NotNull PacketType type) { - return TYPE_TO_CLASS.get(type); - } - - /** - * Put the packets from the given map into the registry - * - * @param packetMap The map containing the packet classes - * @param protocol The protocol for which to register the packets - * @param flow The flow for which to register the packets - */ - private static void putPackets( - final @NotNull Object2IntMap packetMap, - final @NotNull PacketProtocol protocol, - final @NotNull PacketFlow flow - ) { - final var map = protocol.getPackets().get(flow); - - for (final var entry : packetMap.object2IntEntrySet()) { - final var packetType = map.get(entry.getIntValue()); - final var packetClass = (Class) entry.getKey(); - - CLASS_TO_TYPE.put(packetClass, packetType); - TYPE_TO_CLASS.put(packetType, packetClass); - } - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/packet/PacketType.java b/paper/src/main/java/com/minersstudios/whomine/packet/PacketType.java deleted file mode 100644 index 3e6a8bde..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/packet/PacketType.java +++ /dev/null @@ -1,446 +0,0 @@ -package com.minersstudios.whomine.packet; - -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import net.minecraft.network.protocol.PacketFlow; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.Unmodifiable; - -import java.util.Collections; -import java.util.EnumMap; -import java.util.Map; - -import static net.minecraft.network.protocol.PacketFlow.CLIENTBOUND; -import static net.minecraft.network.protocol.PacketFlow.SERVERBOUND; - -/** - * This class represents a packet type used in the Minecraft server networking. - * It contains information about the packet's flow (CLIENTBOUND or SERVERBOUND), - * its ID, and its name. - * - * @see PacketProtocol - * @see PacketFlow - * @see PacketRegistry - * @see Protocol Wiki - * @version 1.20.4, protocol 765 - */ -@SuppressWarnings("unused") -public enum PacketType { - // - // There are no clientbound packets in the Handshaking state, since the - // protocol immediately switches to a different state after the client sends - // the first packet. - // - // - HANDSHAKING_SERVER_HANDSHAKE (SERVERBOUND, 0x00, "Handshake"), - HANDSHAKING_SERVER_LEGACY_SERVER_LIST_PING (SERVERBOUND, 0xFE, "Legacy Server List Ping"), - // - // - STATUS_CLIENT_STATUS_RESPONSE (CLIENTBOUND, 0x00, "Status Response"), - STATUS_CLIENT_PING_RESPONSE (CLIENTBOUND, 0x01, "Ping Response"), - // - // - STATUS_SERVER_STATUS_REQUEST (SERVERBOUND, 0x00, "Status Request"), - STATUS_SERVER_PING_REQUEST (SERVERBOUND, 0x01, "Ping Request"), - // - // - LOGIN_CLIENT_DISCONNECT (CLIENTBOUND, 0x00, "Disconnect (login)"), - LOGIN_CLIENT_ENCRYPTION_REQUEST (CLIENTBOUND, 0x01, "Encryption Request"), - LOGIN_CLIENT_LOGIN_SUCCESS (CLIENTBOUND, 0x02, "Login Success"), - LOGIN_CLIENT_SET_COMPRESSION (CLIENTBOUND, 0x03, "Set Compression"), - LOGIN_CLIENT_LOGIN_PLUGIN_REQUEST (CLIENTBOUND, 0x04, "Login Plugin Request"), - // - // - LOGIN_SERVER_LOGIN_START (SERVERBOUND, 0x00, "Login Start"), - LOGIN_SERVER_ENCRYPTION_RESPONSE (SERVERBOUND, 0x01, "Encryption Response"), - LOGIN_SERVER_LOGIN_PLUGIN_RESPONSE (SERVERBOUND, 0x02, "Login Plugin Response"), - LOGIN_SERVER_LOGIN_ACKNOWLEDGED (SERVERBOUND, 0x03, "Login Acknowledged"), - // - // - CONFIGURATION_CLIENT_PLUGIN_MESSAGE (CLIENTBOUND, 0x00, "Clientbound Plugin Message (configuration)"), - CONFIGURATION_CLIENT_DISCONNECT (CLIENTBOUND, 0x01, "Disconnect (configuration)"), - CONFIGURATION_CLIENT_FINISH_CONFIGURATION (CLIENTBOUND, 0x02, "Finish Configuration"), - CONFIGURATION_CLIENT_KEEP_ALIVE (CLIENTBOUND, 0x03, "Clientbound Keep Alive (configuration)"), - CONFIGURATION_CLIENT_PING (CLIENTBOUND, 0x04, "Ping (configuration)"), - CONFIGURATION_CLIENT_REGISTRY_DATA (CLIENTBOUND, 0x05, "Registry Data"), - CONFIGURATION_CLIENT_REMOVE_RESOURCE_PACK (CLIENTBOUND, 0x06, "Remove Resource Pack (configuration)"), - CONFIGURATION_CLIENT_ADD_RESOURCE_PACK (CLIENTBOUND, 0x07, "Add Resource Pack (configuration)"), - CONFIGURATION_CLIENT_FEATURE_FLAGS (CLIENTBOUND, 0x08, "Feature Flags"), - CONFIGURATION_CLIENT_UPDATE_TAGS (CLIENTBOUND, 0x09, "Update Tags"), - // - // - CONFIGURATION_SERVER_CLIENT_INFORMATION (SERVERBOUND, 0x00, "Client Information (configuration)"), - CONFIGURATION_SERVER_PLUGIN_MESSAGE (SERVERBOUND, 0x01, "Serverbound Plugin Message (configuration)"), - CONFIGURATION_SERVER_FINISH_CONFIGURATION (SERVERBOUND, 0x02, "Finish Configuration"), - CONFIGURATION_SERVER_KEEP_ALIVE (SERVERBOUND, 0x03, "Serverbound Keep Alive (configuration)"), - CONFIGURATION_SERVER_PONG (SERVERBOUND, 0x04, "Pong (configuration)"), - CONFIGURATION_SERVER_RESOURCE_PACK_RESPONSE (SERVERBOUND, 0x05, "Resource Pack Response (configuration)"), - // - // - PLAY_CLIENT_BUNDLE_DELIMITER (CLIENTBOUND, 0x00, "Bundle Delimiter"), - PLAY_CLIENT_SPAWN_ENTITY (CLIENTBOUND, 0x01, "Spawn Entity"), - PLAY_CLIENT_SPAWN_EXPERIENCE_ORB (CLIENTBOUND, 0x02, "Spawn Experience Orb"), - PLAY_CLIENT_ENTITY_ANIMATION (CLIENTBOUND, 0x03, "Entity Animation"), - PLAY_CLIENT_AWARD_STATISTICS (CLIENTBOUND, 0x04, "Award Statistics"), - PLAY_CLIENT_ACKNOWLEDGE_BLOCK_CHANGE (CLIENTBOUND, 0x05, "Acknowledge Block Change"), - PLAY_CLIENT_SET_BLOCK_DESTROY_STAGE (CLIENTBOUND, 0x06, "Set Block Destroy Stage"), - PLAY_CLIENT_BLOCK_ENTITY_DATA (CLIENTBOUND, 0x07, "Block Entity Data"), - PLAY_CLIENT_BLOCK_ACTION (CLIENTBOUND, 0x08, "Block Action"), - PLAY_CLIENT_BLOCK_UPDATE (CLIENTBOUND, 0x09, "Block Update"), - PLAY_CLIENT_BOSS_BAR (CLIENTBOUND, 0x0A, "Boss Bar"), - PLAY_CLIENT_CHANGE_DIFFICULTY (CLIENTBOUND, 0x0B, "Change Difficulty"), - PLAY_CLIENT_CHUNK_BATCH_FINISHED (CLIENTBOUND, 0x0C, "Chunk Batch Finished"), - PLAY_CLIENT_CHUNK_BATCH_START (CLIENTBOUND, 0x0D, "Chunk Batch Start"), - PLAY_CLIENT_CHUNK_BIOMES (CLIENTBOUND, 0x0E, "Chunk Biomes"), - PLAY_CLIENT_CLEAR_TITLES (CLIENTBOUND, 0x0F, "Clear Titles"), - PLAY_CLIENT_COMMAND_SUGGESTIONS_RESPONSE (CLIENTBOUND, 0x10, "Command Suggestions Response"), - PLAY_CLIENT_COMMANDS (CLIENTBOUND, 0x11, "Commands"), - PLAY_CLIENT_CLOSE_CONTAINER (CLIENTBOUND, 0x12, "Close Container"), - PLAY_CLIENT_SET_CONTAINER_CONTENT (CLIENTBOUND, 0x13, "Set Container Content"), - PLAY_CLIENT_SET_CONTAINER_PROPERTY (CLIENTBOUND, 0x14, "Set Container Property"), - PLAY_CLIENT_SET_CONTAINER_SLOT (CLIENTBOUND, 0x15, "Set Container Slot"), - PLAY_CLIENT_SET_COOLDOWN (CLIENTBOUND, 0x16, "Set Cooldown"), - PLAY_CLIENT_CHAT_SUGGESTIONS (CLIENTBOUND, 0x17, "Chat Suggestions"), - PLAY_CLIENT_PLUGIN_MESSAGE (CLIENTBOUND, 0x18, "Clientbound Plugin Message (play)"), - PLAY_CLIENT_DAMAGE_EVENT (CLIENTBOUND, 0x19, "Damage Event"), - PLAY_CLIENT_DELETE_MESSAGE (CLIENTBOUND, 0x1A, "Delete Message"), - PLAY_CLIENT_DISCONNECT (CLIENTBOUND, 0x1B, "Disconnect (play)"), - PLAY_CLIENT_DISGUISED_CHAT_MESSAGE (CLIENTBOUND, 0x1C, "Disguised Chat Message"), - PLAY_CLIENT_ENTITY_EVENT (CLIENTBOUND, 0x1D, "Entity Event"), - PLAY_CLIENT_EXPLOSION (CLIENTBOUND, 0x1E, "Explosion"), - PLAY_CLIENT_UNLOAD_CHUNK (CLIENTBOUND, 0x1F, "Unload Chunk"), - PLAY_CLIENT_GAME_EVENT (CLIENTBOUND, 0x20, "Game Event"), - PLAY_CLIENT_OPEN_HORSE_SCREEN (CLIENTBOUND, 0x21, "Open Horse Screen"), - PLAY_CLIENT_HURT_ANIMATION (CLIENTBOUND, 0x22, "Hurt Animation"), - PLAY_CLIENT_INITIALIZE_WORLD_BORDER (CLIENTBOUND, 0x23, "Initialize World Border"), - PLAY_CLIENT_KEEP_ALIVE (CLIENTBOUND, 0x24, "Clientbound Keep Alive (play)"), - PLAY_CLIENT_CHUNK_DATA_AND_UPDATE_LIGHT (CLIENTBOUND, 0x25, "Chunk Data and Update Light"), - PLAY_CLIENT_WORLD_EVENT (CLIENTBOUND, 0x26, "World Event"), - PLAY_CLIENT_PARTICLE (CLIENTBOUND, 0x27, "Particle"), - PLAY_CLIENT_UPDATE_LIGHT (CLIENTBOUND, 0x28, "Update Light"), - PLAY_CLIENT_LOGIN (CLIENTBOUND, 0x29, "Login (play)"), - PLAY_CLIENT_MAP_DATA (CLIENTBOUND, 0x2A, "Map Data"), - PLAY_CLIENT_MERCHANT_OFFERS (CLIENTBOUND, 0x2B, "Merchant Offers"), - PLAY_CLIENT_UPDATE_ENTITY_POSITION (CLIENTBOUND, 0x2C, "Update Entity Position"), - PLAY_CLIENT_UPDATE_ENTITY_POSITION_AND_ROTATION(CLIENTBOUND, 0x2D, "Update Entity Position and Rotation"), - PLAY_CLIENT_UPDATE_ENTITY_ROTATION (CLIENTBOUND, 0x2E, "Update Entity Rotation"), - PLAY_CLIENT_MOVE_VEHICLE (CLIENTBOUND, 0x2F, "Move Vehicle"), - PLAY_CLIENT_OPEN_BOOK (CLIENTBOUND, 0x30, "Open Book"), - PLAY_CLIENT_OPEN_SCREEN (CLIENTBOUND, 0x31, "Open Screen"), - PLAY_CLIENT_OPEN_SIGN_EDITOR (CLIENTBOUND, 0x32, "Open Sign Editor"), - PLAY_CLIENT_PING (CLIENTBOUND, 0x33, "Ping (play)"), - PLAY_CLIENT_PING_RESPONSE (CLIENTBOUND, 0x34, "Ping Response (play)"), - PLAY_CLIENT_PLACE_GHOST_RECIPE (CLIENTBOUND, 0x35, "Place Ghost Recipe"), - PLAY_CLIENT_PLAYER_ABILITIES (CLIENTBOUND, 0x36, "Player Abilities"), - PLAY_CLIENT_PLAYER_CHAT_MESSAGE (CLIENTBOUND, 0x37, "Player Chat Message"), - PLAY_CLIENT_END_COMBAT (CLIENTBOUND, 0x38, "End Combat"), - PLAY_CLIENT_ENTER_COMBAT (CLIENTBOUND, 0x39, "Enter Combat"), - PLAY_CLIENT_COMBAT_DEATH (CLIENTBOUND, 0x3A, "Combat Death"), - PLAY_CLIENT_PLAYER_INFO_REMOVE (CLIENTBOUND, 0x3B, "Player Info Remove"), - PLAY_CLIENT_PLAYER_INFO_UPDATE (CLIENTBOUND, 0x3C, "Player Info Update"), - PLAY_CLIENT_LOOK_AT (CLIENTBOUND, 0x3D, "Look At"), - PLAY_CLIENT_SYNCHRONIZE_PLAYER_POSITION (CLIENTBOUND, 0x3E, "Synchronize Player Position"), - PLAY_CLIENT_UPDATE_RECIPE_BOOK (CLIENTBOUND, 0x3F, "Update Recipe Book"), - PLAY_CLIENT_REMOVE_ENTITIES (CLIENTBOUND, 0x40, "Remove Entities"), - PLAY_CLIENT_REMOVE_ENTITY_EFFECT (CLIENTBOUND, 0x41, "Remove Entity Effect"), - PLAY_CLIENT_RESET_SCORE (CLIENTBOUND, 0x42, "Reset Score"), - PLAY_CLIENT_REMOVE_RESOURCE_PACK (CLIENTBOUND, 0x43, "Remove Resource Pack (play)"), - PLAY_CLIENT_ADD_RESOURCE_PACK (CLIENTBOUND, 0x44, "Add Resource Pack (play)"), - PLAY_CLIENT_RESPAWN (CLIENTBOUND, 0x45, "Respawn"), - PLAY_CLIENT_SET_HEAD_ROTATION (CLIENTBOUND, 0x46, "Set Head Rotation"), - PLAY_CLIENT_UPDATE_SECTION_BLOCKS (CLIENTBOUND, 0x47, "Update Section Blocks"), - PLAY_CLIENT_SELECT_ADVANCEMENT_TAB (CLIENTBOUND, 0x48, "Select Advancement Tab"), - PLAY_CLIENT_SERVER_DATA (CLIENTBOUND, 0x49, "Server Data"), - PLAY_CLIENT_SET_ACTION_BAR_TEXT (CLIENTBOUND, 0x4A, "Set Action Bar Text"), - PLAY_CLIENT_SET_BORDER_CENTER (CLIENTBOUND, 0x4B, "Set Border Center"), - PLAY_CLIENT_SET_BORDER_LERP_SIZE (CLIENTBOUND, 0x4C, "Set Border Lerp Size"), - PLAY_CLIENT_SET_BORDER_SIZE (CLIENTBOUND, 0x4D, "Set Border Size"), - PLAY_CLIENT_SET_BORDER_WARNING_DELAY (CLIENTBOUND, 0x4E, "Set Border Warning Delay"), - PLAY_CLIENT_SET_BORDER_WARNING_DISTANCE (CLIENTBOUND, 0x4F, "Set Border Warning Distance"), - PLAY_CLIENT_SET_CAMERA (CLIENTBOUND, 0x50, "Set Camera"), - PLAY_CLIENT_SET_HELD_ITEM (CLIENTBOUND, 0x51, "Set Held Item"), - PLAY_CLIENT_SET_CENTER_CHUNK (CLIENTBOUND, 0x52, "Set Center Chunk"), - PLAY_CLIENT_SET_RENDER_DISTANCE (CLIENTBOUND, 0x53, "Set Render Distance"), - PLAY_CLIENT_SET_DEFAULT_SPAWN_POSITION (CLIENTBOUND, 0x54, "Set Default Spawn Position"), - PLAY_CLIENT_DISPLAY_OBJECTIVE (CLIENTBOUND, 0x55, "Display Objective"), - PLAY_CLIENT_SET_ENTITY_METADATA (CLIENTBOUND, 0x56, "Set Entity Metadata"), - PLAY_CLIENT_LINK_ENTITIES (CLIENTBOUND, 0x57, "Link Entities"), - PLAY_CLIENT_SET_ENTITY_VELOCITY (CLIENTBOUND, 0x58, "Set Entity Velocity"), - PLAY_CLIENT_SET_EQUIPMENT (CLIENTBOUND, 0x59, "Set Equipment"), - PLAY_CLIENT_SET_EXPERIENCE (CLIENTBOUND, 0x5A, "Set Experience"), - PLAY_CLIENT_SET_HEALTH (CLIENTBOUND, 0x5B, "Set Health"), - PLAY_CLIENT_UPDATE_OBJECTIVES (CLIENTBOUND, 0x5C, "Update Objectives"), - PLAY_CLIENT_SET_PASSENGERS (CLIENTBOUND, 0x5D, "Set Passengers"), - PLAY_CLIENT_UPDATE_TEAMS (CLIENTBOUND, 0x5E, "Update Teams"), - PLAY_CLIENT_UPDATE_SCORE (CLIENTBOUND, 0x5F, "Update Score"), - PLAY_CLIENT_SET_SIMULATION_DISTANCE (CLIENTBOUND, 0x60, "Set Simulation Distance"), - PLAY_CLIENT_SET_SUBTITLE_TEXT (CLIENTBOUND, 0x61, "Set Subtitle Text"), - PLAY_CLIENT_UPDATE_TIME (CLIENTBOUND, 0x62, "Update Time"), - PLAY_CLIENT_SET_TITLE_TEXT (CLIENTBOUND, 0x63, "Set Title Text"), - PLAY_CLIENT_SET_TITLE_ANIMATION_TIMES (CLIENTBOUND, 0x64, "Set Title Animation Times"), - PLAY_CLIENT_ENTITY_SOUND_EFFECT (CLIENTBOUND, 0x65, "Entity Sound Effect"), - PLAY_CLIENT_SOUND_EFFECT (CLIENTBOUND, 0x66, "Sound Effect"), - PLAY_CLIENT_START_CONFIGURATION (CLIENTBOUND, 0x67, "Start Configuration"), - PLAY_CLIENT_STOP_SOUND (CLIENTBOUND, 0x68, "Stop Sound"), - PLAY_CLIENT_SYSTEM_CHAT_MESSAGE (CLIENTBOUND, 0x69, "System Chat Message"), - PLAY_CLIENT_SET_TAB_LIST_HEADER_AND_FOOTER (CLIENTBOUND, 0x6A, "Set Tab List Header And Footer"), - PLAY_CLIENT_TAG_QUERY_RESPONSE (CLIENTBOUND, 0x6B, "Tag Query Response"), - PLAY_CLIENT_PICKUP_ITEM (CLIENTBOUND, 0x6C, "Pickup Item"), - PLAY_CLIENT_TELEPORT_ENTITY (CLIENTBOUND, 0x6D, "Teleport Entity"), - PLAY_CLIENT_SET_TICKING_STATE (CLIENTBOUND, 0x6E, "Set Ticking State"), - PLAY_CLIENT_STEP_TICK (CLIENTBOUND, 0x6F, "Step Tick"), - PLAY_CLIENT_UPDATE_ADVANCEMENTS (CLIENTBOUND, 0x70, "Update Advancements"), - PLAY_CLIENT_UPDATE_ATTRIBUTES (CLIENTBOUND, 0x71, "Update Attributes"), - PLAY_CLIENT_ENTITY_EFFECT (CLIENTBOUND, 0x72, "Entity Effect"), - PLAY_CLIENT_UPDATE_RECIPES (CLIENTBOUND, 0x73, "Update Recipes"), - PLAY_CLIENT_UPDATE_TAGS (CLIENTBOUND, 0x74, "Update Tags"), - // - // - PLAY_SERVER_CONFIRM_TELEPORTATION (SERVERBOUND, 0x00, "Confirm Teleportation"), - PLAY_SERVER_QUERY_BLOCK_ENTITY_TAG (SERVERBOUND, 0x01, "Query Block Entity Tag"), - PLAY_SERVER_CHANGE_DIFFICULTY (SERVERBOUND, 0x02, "Change Difficulty"), - PLAY_SERVER_ACKNOWLEDGE_MESSAGE (SERVERBOUND, 0x03, "Acknowledge Message"), - PLAY_SERVER_CHAT_COMMAND (SERVERBOUND, 0x04, "Chat Command"), - PLAY_SERVER_CHAT_MESSAGE (SERVERBOUND, 0x05, "Chat Message"), - PLAY_SERVER_PLAYER_SESSION (SERVERBOUND, 0x06, "Player Session"), - PLAY_SERVER_CHUNK_BATCH_RECEIVED (SERVERBOUND, 0x07, "Chunk Batch Received"), - PLAY_SERVER_CLIENT_STATUS (SERVERBOUND, 0x08, "Client Status"), - PLAY_SERVER_CLIENT_INFORMATION (SERVERBOUND, 0x09, "Client Information (play)"), - PLAY_SERVER_COMMAND_SUGGESTIONS_REQUEST (SERVERBOUND, 0x0A, "Command Suggestions Request"), - PLAY_SERVER_ACKNOWLEDGE_CONFIGURATION (SERVERBOUND, 0x0B, "Acknowledge Configuration"), - PLAY_SERVER_CLICK_CONTAINER_BUTTON (SERVERBOUND, 0x0C, "Click Container Button"), - PLAY_SERVER_CLICK_CONTAINER (SERVERBOUND, 0x0D, "Click Container"), - PLAY_SERVER_CLOSE_CONTAINER (SERVERBOUND, 0x0E, "Close Container"), - PLAY_SERVER_CHANGE_CONTAINER_SLOT_STATE (SERVERBOUND, 0x0F, "Change Container Slot State"), - PLAY_SERVER_PLUGIN_MESSAGE (SERVERBOUND, 0x10, "Serverbound Plugin Message (play)"), - PLAY_SERVER_EDIT_BOOK (SERVERBOUND, 0x11, "Edit Book"), - PLAY_SERVER_QUERY_ENTITY_TAG (SERVERBOUND, 0x12, "Query Entity Tag"), - PLAY_SERVER_INTERACT (SERVERBOUND, 0x13, "Interact"), - PLAY_SERVER_JIGSAW_GENERATE (SERVERBOUND, 0x14, "Jigsaw Generate"), - PLAY_SERVER_KEEP_ALIVE (SERVERBOUND, 0x15, "Serverbound Keep Alive (play)"), - PLAY_SERVER_LOCK_DIFFICULTY (SERVERBOUND, 0x16, "Lock Difficulty"), - PLAY_SERVER_SET_PLAYER_POSITION (SERVERBOUND, 0x17, "Set Player Position"), - PLAY_SERVER_SET_PLAYER_POSITION_AND_ROTATION (SERVERBOUND, 0x18, "Set Player Position and Rotation"), - PLAY_SERVER_SET_PLAYER_ROTATION (SERVERBOUND, 0x19, "Set Player Rotation"), - PLAY_SERVER_SET_PLAYER_ON_GROUND (SERVERBOUND, 0x1A, "Set Player On Ground"), - PLAY_SERVER_MOVE_VEHICLE (SERVERBOUND, 0x1B, "Move Vehicle"), - PLAY_SERVER_PADDLE_BOAT (SERVERBOUND, 0x1C, "Paddle Boat"), - PLAY_SERVER_PICK_ITEM (SERVERBOUND, 0x1D, "Pick Item"), - PLAY_SERVER_PING_REQUEST (SERVERBOUND, 0x1E, "Ping Request (play)"), - PLAY_SERVER_PLACE_RECIPE (SERVERBOUND, 0x1F, "Place Recipe"), - PLAY_SERVER_PLAYER_ABILITIES (SERVERBOUND, 0x20, "Player Abilities"), - PLAY_SERVER_PLAYER_ACTION (SERVERBOUND, 0x21, "Player Action"), - PLAY_SERVER_PLAYER_COMMAND (SERVERBOUND, 0x22, "Player Command"), - PLAY_SERVER_PLAYER_INPUT (SERVERBOUND, 0x23, "Player Input"), - PLAY_SERVER_PONG (SERVERBOUND, 0x24, "Pong (play)"), - PLAY_SERVER_CHANGE_RECIPE_BOOK_SETTINGS (SERVERBOUND, 0x25, "Change Recipe Book Settings"), - PLAY_SERVER_SET_SEEN_RECIPE (SERVERBOUND, 0x26, "Set Seen Recipe"), - PLAY_SERVER_RENAME_ITEM (SERVERBOUND, 0x27, "Rename Item"), - PLAY_SERVER_RESOURCE_PACK_RESPONSE (SERVERBOUND, 0x28, "Resource Pack Response (play)"), - PLAY_SERVER_SEEN_ADVANCEMENTS (SERVERBOUND, 0x29, "Seen Advancements"), - PLAY_SERVER_SELECT_TRADE (SERVERBOUND, 0x2A, "Select Trade"), - PLAY_SERVER_SET_BEACON_EFFECT (SERVERBOUND, 0x2B, "Set Beacon Effect"), - PLAY_SERVER_SET_HELD_ITEM (SERVERBOUND, 0x2C, "Set Held Item"), - PLAY_SERVER_PROGRAM_COMMAND_BLOCK (SERVERBOUND, 0x2D, "Program Command Block"), - PLAY_SERVER_PROGRAM_COMMAND_BLOCK_MINECART (SERVERBOUND, 0x2E, "Program Command Block Minecart"), - PLAY_SERVER_SET_CREATIVE_MODE_SLOT (SERVERBOUND, 0x2F, "Set Creative Mode Slot"), - PLAY_SERVER_PROGRAM_JIGSAW_BLOCK (SERVERBOUND, 0x30, "Program Jigsaw Block"), - PLAY_SERVER_PROGRAM_STRUCTURE_BLOCK (SERVERBOUND, 0x31, "Program Structure Block"), - PLAY_SERVER_UPDATE_SIGN (SERVERBOUND, 0x32, "Update Sign"), - PLAY_SERVER_SWING_ARM (SERVERBOUND, 0x33, "Swing Arm"), - PLAY_SERVER_TELEPORT_TO_ENTITY (SERVERBOUND, 0x34, "Teleport To Entity"), - PLAY_SERVER_USE_ITEM_ON (SERVERBOUND, 0x35, "Use Item On"), - PLAY_SERVER_USE_ITEM (SERVERBOUND, 0x36, "Use Item"); - // - - private final PacketFlow flow; - private final int id; - private final String name; - - private static final PacketType[] VALUES; - static final Map> HANDSHAKING_PACKET_MAP; - static final Map> STATUS_PACKET_MAP; - static final Map> LOGIN_PACKET_MAP; - static final Map> CONFIGURATION_PACKET_MAP; - static final Map> PLAY_PACKET_MAP; - - static { - VALUES = values(); - HANDSHAKING_PACKET_MAP = createMap("HANDSHAKING_CLIENT_", "HANDSHAKING_SERVER_"); - STATUS_PACKET_MAP = createMap("STATUS_CLIENT_", "STATUS_SERVER_"); - LOGIN_PACKET_MAP = createMap("LOGIN_CLIENT_", "LOGIN_SERVER_"); - CONFIGURATION_PACKET_MAP = createMap("CONFIGURATION_CLIENT_", "CONFIGURATION_SERVER_"); - PLAY_PACKET_MAP = createMap("PLAY_CLIENT_", "PLAY_SERVER_"); - } - - PacketType( - final @NotNull PacketFlow flow, - final int id, - final @NotNull String name - ) { - this.flow = flow; - this.id = id; - this.name = name; - } - - /** - * Returns the flow of the packet (CLIENTBOUND or SERVERBOUND) - * - * @return The flow of the packet (CLIENTBOUND or SERVERBOUND) - */ - public @NotNull PacketFlow getFlow() { - return this.flow; - } - - /** - * Returns the ID of the packet - * - * @return The ID of the packet - */ - public int getId() { - return this.id; - } - - /** - * Returns the name of the packet - * - * @return The name of the packet - */ - public @NotNull String getName() { - return this.name; - } - - /** - * Retrieves the packet class associated with this PacketType - * - * @return The packet class associated with this PacketType - */ - public @NotNull Class getPacketClass() { - return PacketRegistry.getClassFromType(this); - } - - /** - * Returns whether the packet is {@link PacketFlow#SERVERBOUND serverbound} - * - * @return True if the packet is {@link PacketFlow#SERVERBOUND serverbound}, - * false otherwise - */ - public boolean isReceive() { - return this.flow == SERVERBOUND; - } - - /** - * Returns whether the packet is {@link PacketFlow#CLIENTBOUND clientbound} - * - * @return True if the packet is {@link PacketFlow#CLIENTBOUND clientbound}, - * false otherwise - */ - public boolean isSend() { - return this.flow == CLIENTBOUND; - } - - /** - * Returns the string representation of this packet type - * - * @return The string representation of this packet type - */ - @Override - public @NotNull String toString() { - return this.name() + '{' + - "bound=" + this.flow + - ", id=" + this.id + - ", name='" + this.name + '\'' + - '}'; - } - - /** - * Returns an unmodifiable map of a handshaking packet flows to packet IDs - * to PacketType instances - * - * @return An unmodifiable map of a handshaking packet flows to packet IDs - * to PacketType instances - */ - public static @NotNull @Unmodifiable Map> handshaking() { - return Collections.unmodifiableMap(HANDSHAKING_PACKET_MAP); - } - - /** - * Returns an unmodifiable map of a status packet flows to packet IDs to - * PacketType instances - * - * @return An unmodifiable map of a status packet flows to packet IDs to - * PacketType instances - */ - public static @NotNull @Unmodifiable Map> status() { - return Collections.unmodifiableMap(STATUS_PACKET_MAP); - } - - /** - * Returns an unmodifiable map of a login packet flows to packet IDs to - * PacketType instances - * - * @return An unmodifiable map of a login packet flows to packet IDs to - * PacketType instances - */ - public static @NotNull @Unmodifiable Map> login() { - return Collections.unmodifiableMap(LOGIN_PACKET_MAP); - } - - /** - * Returns an unmodifiable map of a configuration packet flows to packet IDs - * to PacketType instances - * - * @return An unmodifiable map of a configuration packet flows to packet IDs - * to PacketType instances - */ - public static @NotNull @Unmodifiable Map> configuration() { - return Collections.unmodifiableMap(CONFIGURATION_PACKET_MAP); - } - - /** - * Returns an unmodifiable map of a play packet flows to packet IDs to - * PacketType instances - * - * @return An unmodifiable map of a play packet flows to packet IDs to - * PacketType instances - */ - public static @NotNull @Unmodifiable Map> play() { - return Collections.unmodifiableMap(PLAY_PACKET_MAP); - } - - /** - * Retrieves the PacketType corresponding to a given packet class - * - * @param clazz The packet class for which to retrieve the PacketType - * @return The PacketType for the given packet class, or null if not found - */ - public static @Nullable PacketType fromClass(final @NotNull Class clazz) { - return PacketRegistry.getTypeFromClass(clazz); - } - - private static @NotNull Map> createMap( - final @NotNull String clientboundPrefix, - final @NotNull String serverboundPrefix - ) { - final var clientboundMap = new Int2ObjectOpenHashMap(); - final var serverboundMap = new Int2ObjectOpenHashMap(); - - for (final var value : VALUES) { - final String name = value.name(); - - if (name.startsWith(clientboundPrefix)) { - clientboundMap.put(value.id, value); - } else if (name.startsWith(serverboundPrefix)) { - serverboundMap.put(value.id, value); - } - } - - final var flowMap = new EnumMap>(PacketFlow.class); - - flowMap.put(CLIENTBOUND, clientboundMap); - flowMap.put(SERVERBOUND, serverboundMap); - - return flowMap; - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/plugin/AbstractPluginComponent.java b/paper/src/main/java/com/minersstudios/whomine/plugin/AbstractPluginComponent.java deleted file mode 100644 index bd276995..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/plugin/AbstractPluginComponent.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.minersstudios.whomine.plugin; - -import com.minersstudios.whomine.WhoMine; -import org.jetbrains.annotations.NotNull; - -public abstract class AbstractPluginComponent implements PluginComponent { - private final WhoMine plugin; - - /** - * Plugin component constructor - * - * @param plugin The plugin instance - */ - protected AbstractPluginComponent(final @NotNull WhoMine plugin) { - this.plugin = plugin; - } - - @Override - public final @NotNull WhoMine getPlugin() { - return this.plugin; - } - - @Override - public @NotNull String toString() { - return this.getClass().getSimpleName() + "{plugin=" + this.plugin + '}'; - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/plugin/PluginComponent.java b/paper/src/main/java/com/minersstudios/whomine/plugin/PluginComponent.java deleted file mode 100644 index 28b4f453..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/plugin/PluginComponent.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.minersstudios.whomine.plugin; - -import com.minersstudios.whomine.WhoMine; -import org.jetbrains.annotations.NotNull; - -/** - * Plugin component interface - */ -public interface PluginComponent { - - /** - * Returns the plugin that this component is associated with - * - * @return The plugin that this component is associated with - */ - @NotNull WhoMine getPlugin(); - - /** - * Returns a string representation of this component - * - * @return A string representation of this component - */ - @Override - @NotNull String toString(); - - /** - * Registers the component with the {@link #getPlugin() plugin} - * - * @throws IllegalStateException If the component is already registered - * @see #onRegister() - */ - void register() throws IllegalStateException; - - /** - * Called when the component is registered - */ - default void onRegister() { - // Some registration magic - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/SharedConstants.java b/paper/src/main/java/com/minersstudios/whomine/utility/SharedConstants.java deleted file mode 100644 index 6efa5cb4..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/utility/SharedConstants.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.minersstudios.whomine.utility; - -import com.minersstudios.whomine.api.annotation.Namespace; -import net.kyori.adventure.translation.Translator; -import org.jetbrains.annotations.Contract; - -import java.time.format.DateTimeFormatter; -import java.util.Locale; -import java.util.Objects; - -import static io.papermc.paper.configuration.PaperConfigurations.CONFIG_DIR; - -/** - * Shared constants - */ -public final class SharedConstants { - public static final String GLOBAL_PACKAGE = "com.minersstudios"; - public static final String GLOBAL_FOLDER_PATH = CONFIG_DIR + "/minersstudios/"; - public static final String LANGUAGE_FOLDER_PATH = GLOBAL_FOLDER_PATH + "language/"; - public static final String PAPER_GLOBAL_CONFIG_FILE_NAME = "paper-global.yml"; - public static final String PAPER_WORLD_DEFAULTS_CONFIG_FILE_NAME = "paper-world-defaults.yml"; - public static final String PAPER_WORLD_CONFIG_FILE_NAME = "paper-world.yml"; - public static final String PAPER_GLOBAL_CONFIG_PATH = CONFIG_DIR + '/' + PAPER_GLOBAL_CONFIG_FILE_NAME; - public static final String PAPER_WORLD_DEFAULTS_PATH = CONFIG_DIR + '/' + PAPER_WORLD_DEFAULTS_CONFIG_FILE_NAME; - public static final String DATE_FORMAT = "EEE, yyyy-MM-dd HH:mm z"; - public static final String DEFAULT_LANGUAGE_CODE = "en_us"; - public static final String DISCORD_LINK = "https://discord.whomine.net"; - public static final String CONSOLE_NICKNAME = "$Console"; - public static final String INVISIBLE_ITEM_FRAME_TAG = "invisibleItemFrame"; - public static final String HIDE_TAGS_TEAM_NAME = "hide_tags"; - public static final @Namespace String WHOMINE_NAMESPACE = "whomine"; - public static final @Namespace String MSBLOCK_NAMESPACE = "msblock"; - public static final @Namespace String MSITEMS_NAMESPACE = "msitems"; - public static final @Namespace String MSDECOR_NAMESPACE = "msdecor"; - public static final Locale DEFAULT_LOCALE = Objects.requireNonNull(Translator.parseLocale(DEFAULT_LANGUAGE_CODE), "Not found default locale for " + DEFAULT_LANGUAGE_CODE); - public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DATE_FORMAT); - public static final int SIT_RANGE = 9; - public static final int FINAL_DESTROY_STAGE = 9; - public static final int LEATHER_HORSE_ARMOR_MAX_STACK_SIZE = 8; - - @Contract(" -> fail") - private SharedConstants() throws AssertionError { - throw new AssertionError("Utility class"); - } -} diff --git a/paper/src/main/java/com/minersstudios/whomine/world/sound/package-info.java b/paper/src/main/java/com/minersstudios/whomine/world/sound/package-info.java deleted file mode 100644 index 60d23b27..00000000 --- a/paper/src/main/java/com/minersstudios/whomine/world/sound/package-info.java +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Classes and interfaces related to sound functionality in the - * {@code MSCustoms} plugin. - *
      - * The classes in this package are responsible for playing sounds in the world - * or to the player. - * - * @see com.minersstudios.whomine.world.sound.Sound - * @see com.minersstudios.whomine.world.sound.SoundGroup - * @see com.minersstudios.whomine.world.sound.SoundAdapter GSON adapter - */ -package com.minersstudios.whomine.world.sound; diff --git a/platform/paper/build.gradle.kts b/platform/paper/build.gradle.kts new file mode 100644 index 00000000..1256d7d9 --- /dev/null +++ b/platform/paper/build.gradle.kts @@ -0,0 +1,35 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration.Companion.MOJANG_PRODUCTION + +val apiVersion: String = apiVersion(paperweight.minecraftVersion.get()) + +plugins { + id("whomine.platform") + id("whomine.paperweight") +} + +paperweight.reobfArtifactConfiguration = MOJANG_PRODUCTION + +dependencies { + api(Libs.Paper.asProject(rootProject)) +} + +tasks { + processResources { + val props = mapOf( + "name" to project.name, + "version" to project.version, + "description" to project.description, + "author" to projectAuthor, + "contributors" to projectContributors, + "website" to projectWebsite, + "apiVersion" to apiVersion, + "coreProtectVersion" to libs.versions.coreprotect.get(), + "authMeVersion" to libs.versions.authme.get() + ) + + inputs.properties(props) + filesMatching("paper-plugin.yml") { + expand(props) + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/Cache.java b/platform/paper/src/main/java/com/minersstudios/whomine/PaperCacheImpl.java similarity index 70% rename from paper/src/main/java/com/minersstudios/whomine/Cache.java rename to platform/paper/src/main/java/com/minersstudios/whomine/PaperCacheImpl.java index f9e8ba77..46ea1617 100644 --- a/paper/src/main/java/com/minersstudios/whomine/Cache.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/PaperCacheImpl.java @@ -1,21 +1,25 @@ package com.minersstudios.whomine; import com.google.gson.JsonElement; -import com.minersstudios.whomine.chat.ChatBuffer; -import com.minersstudios.whomine.collection.DiggingMap; -import com.minersstudios.whomine.collection.StepMap; -import com.minersstudios.whomine.custom.anomaly.Anomaly; -import com.minersstudios.whomine.custom.anomaly.AnomalyAction; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.item.renameable.RenameableItem; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.discord.DiscordMap; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.collection.IDMap; -import com.minersstudios.whomine.player.collection.MuteMap; -import com.minersstudios.whomine.player.collection.PlayerInfoMap; -import com.minersstudios.whomine.api.status.StatusHandler; -import com.minersstudios.whomine.world.WorldDark; +import com.minersstudios.wholib.module.AbstractModuleComponent; +import com.minersstudios.wholib.module.MainModule; +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.chat.ChatBuffer; +import com.minersstudios.wholib.paper.collection.DiggingMap; +import com.minersstudios.wholib.paper.collection.StepMap; +import com.minersstudios.wholib.paper.custom.anomaly.Anomaly; +import com.minersstudios.wholib.paper.custom.anomaly.AnomalyAction; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItem; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.discord.DiscordMap; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.collection.IDMap; +import com.minersstudios.wholib.paper.player.collection.MuteMap; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.status.StatusHandler; +import com.minersstudios.wholib.paper.world.WorldDark; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -33,8 +37,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -public final class Cache { - private final WhoMine plugin; +public final class PaperCacheImpl extends AbstractModuleComponent implements PaperCache { + private boolean isLoaded; public List customDecorRecipes; @@ -58,12 +62,8 @@ public final class Cache { PlayerInfo consolePlayerInfo; WorldDark worldDark; - Cache(final @NotNull WhoMine plugin) { - this.plugin = plugin; - } - - public @NotNull WhoMine getPlugin() { - return this.plugin; + PaperCacheImpl(final @NotNull WhoMine module) { + super(module); } public @UnknownNullability StepMap getStepMap() { @@ -131,6 +131,10 @@ public final class Cache { return this.consolePlayerInfo; } + public void setConsolePlayerInfo(final @NotNull PlayerInfo playerInfo) { + this.consolePlayerInfo = playerInfo; + } + public @UnknownNullability WorldDark getWorldDark() { return this.worldDark; } @@ -150,9 +154,9 @@ public void load() throws IllegalStateException { } this.isLoaded = true; - final StatusHandler statusHandler = this.plugin.getStatusHandler(); + final StatusHandler statusHandler = this.getModule().getStatusHandler(); - statusHandler.assignStatus(WhoMine.LOADING_CACHE); + statusHandler.assignStatus(MainModule.LOADING_CACHE); this.customDecorRecipes = new ObjectArrayList<>(); this.customItemRecipes = new ObjectArrayList<>(); @@ -162,21 +166,21 @@ public void load() throws IllegalStateException { this.dosimeterPlayers = new ConcurrentHashMap<>(); this.renameableMenuItems = new ObjectArrayList<>(); this.blockDataRecipes = new ObjectArrayList<>(); - this.playerInfoMap = new PlayerInfoMap(this.plugin); - this.muteMap = new MuteMap(this.plugin); - this.discordMap = new DiscordMap(this.plugin); - this.idMap = new IDMap(this.plugin); + this.playerInfoMap = new PlayerInfoMap(this.getModule()); + this.muteMap = new MuteMap(this.getModule()); + this.discordMap = new DiscordMap(this.getModule()); + this.idMap = new IDMap(this.getModule()); this.seats = new ConcurrentHashMap<>(); this.anomalies = new ConcurrentHashMap<>(); this.playerAnomalyActionMap = new ConcurrentHashMap<>(); - this.chatBuffer = new ChatBuffer(this.plugin); + this.chatBuffer = new ChatBuffer(this.getModule()); this.bukkitTasks = new ObjectArrayList<>(); this.botHandlers = new Long2ObjectOpenHashMap<>(); statusHandler.assignStatus( this.isLoaded() - ? WhoMine.LOADED_CACHE - : WhoMine.FAILED_LOAD_CACHE + ? MainModule.LOADED_CACHE + : MainModule.FAILED_LOAD_CACHE ); } @@ -210,4 +214,19 @@ public void unload() { this.bukkitTasks = null; this.botHandlers = null; } + + @Override + public @UnknownNullability List getCustomDecorRecipes() { + return this.customDecorRecipes; + } + + @Override + public @UnknownNullability List getCustomItemRecipes() { + return this.customItemRecipes; + } + + @Override + public @UnknownNullability List getCustomBlockRecipes() { + return this.customBlockRecipes; + } } diff --git a/paper/src/main/java/com/minersstudios/whomine/Config.java b/platform/paper/src/main/java/com/minersstudios/whomine/PaperConfigImpl.java similarity index 82% rename from paper/src/main/java/com/minersstudios/whomine/Config.java rename to platform/paper/src/main/java/com/minersstudios/whomine/PaperConfigImpl.java index 9ce5ab08..12535488 100644 --- a/paper/src/main/java/com/minersstudios/whomine/Config.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/PaperConfigImpl.java @@ -1,26 +1,31 @@ package com.minersstudios.whomine; import com.google.common.base.Joiner; -import com.minersstudios.whomine.custom.anomaly.Anomaly; -import com.minersstudios.whomine.custom.anomaly.task.AnomalyParticleTask; -import com.minersstudios.whomine.custom.anomaly.task.MainAnomalyActionTask; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.custom.item.renameable.RenameableItem; -import com.minersstudios.whomine.custom.item.renameable.RenameableItemRegistry; -import com.minersstudios.whomine.locale.LanguageFile; -import com.minersstudios.whomine.locale.TranslationRegistry; +import com.minersstudios.wholib.module.AbstractModuleComponent; +import com.minersstudios.wholib.module.MainModule; +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.PaperConfig; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.anomaly.Anomaly; +import com.minersstudios.wholib.paper.custom.anomaly.task.AnomalyParticleTask; +import com.minersstudios.wholib.paper.custom.anomaly.task.MainAnomalyActionTask; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItem; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItemRegistry; +import com.minersstudios.wholib.paper.locale.LangFileFabric; +import com.minersstudios.wholib.locale.TranslationRegistry; import com.minersstudios.whomine.menu.CraftsMenu; import com.minersstudios.whomine.menu.RenamesMenu; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.resourcepack.ResourcePack; -import com.minersstudios.whomine.resourcepack.throwable.FatalPackLoadException; -import com.minersstudios.whomine.api.status.StatusHandler; -import com.minersstudios.whomine.api.status.StatusWatcher; -import com.minersstudios.whomine.api.throwable.ConfigurationException; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.resourcepack.ResourcePack; +import com.minersstudios.wholib.paper.resourcepack.throwable.FatalPackLoadException; +import com.minersstudios.wholib.status.StatusHandler; +import com.minersstudios.wholib.status.StatusWatcher; +import com.minersstudios.wholib.throwable.ConfigurationException; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.utility.SharedConstants; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -49,8 +54,8 @@ import static net.kyori.adventure.text.Component.text; -public final class Config { - private final WhoMine plugin; +public final class PaperConfigImpl extends AbstractModuleComponent implements PaperConfig { + private final File file; private final YamlConfiguration yaml; private final Logger logger; @@ -165,13 +170,15 @@ public final class Config { public static final char DEFAULT_MINE_SKIN_API_KEY = ' '; // - Config(final @NotNull WhoMine plugin) { - this.plugin = plugin; - this.file = plugin.getConfigFile(); + PaperConfigImpl(final @NotNull WhoMineImpl module) { + super(module); + + this.file = module.getConfigFile(); this.yaml = new YamlConfiguration(); this.logger = Logger.getLogger(this.getClass().getSimpleName()); } + @Override public @NotNull File getFile() { return this.file; } @@ -194,18 +201,18 @@ public void setIfNotExists( } public boolean reload() { - final StatusHandler statusHandler = this.plugin.getStatusHandler(); + final StatusHandler statusHandler = this.getModule().getStatusHandler(); - statusHandler.assignStatus(WhoMine.LOADING_CONFIG); + statusHandler.assignStatus(MainModule.LOADING_CONFIG); try { this.saveDefaultConfig(); this.reloadVariables(); - statusHandler.assignStatus(WhoMine.LOADED_CONFIG); + statusHandler.assignStatus(MainModule.LOADED_CONFIG); return true; } catch (final ConfigurationException e) { - statusHandler.assignStatus(WhoMine.FAILED_LOAD_CONFIG); + statusHandler.assignStatus(MainModule.FAILED_LOAD_CONFIG); MSLogger.severe("An error occurred while loading the config!", e); return false; @@ -220,7 +227,9 @@ public void reloadVariables() { this.parseDiscord(); this.parseSkins(); + final WhoMine module = this.getModule(); final YamlConfiguration yaml = this.getYaml(); + this.isChristmas = yaml.getBoolean(KEY_IS_CHRISTMAS); this.isHalloween = yaml.getBoolean(KEY_IS_HALLOWEEN); this.dateFormat = yaml.getString(KEY_DATE_FORMAT, SharedConstants.DATE_FORMAT); @@ -230,7 +239,7 @@ public void reloadVariables() { this.anomalyCheckRate = yaml.getLong(KEY_ANOMALY_CHECK_RATE); this.anomalyParticlesCheckRate = yaml.getLong(KEY_ANOMALY_PARTICLES_CHECK_RATE); - final Cache cache = this.plugin.getCache(); + final PaperCache cache = module.getCache(); if (cache.isLoaded()) { for (final var task : cache.getBukkitTasks()) { @@ -242,22 +251,22 @@ public void reloadVariables() { cache.getAnomalies().clear(); } - this.plugin.getStatusHandler().addWatcher( + module.getStatusHandler().addWatcher( StatusWatcher.builder() .successStatuses( - WhoMine.LOADED_BLOCKS, - WhoMine.LOADED_ITEMS, - WhoMine.LOADED_DECORATIONS + MainModule.LOADED_BLOCKS, + MainModule.LOADED_ITEMS, + MainModule.LOADED_DECORATIONS ) .successRunnable( () -> { - this.plugin.runTaskAsync(this::loadRenames); - this.plugin.runTask(() -> { - final var list = this.plugin.getCache().getBlockDataRecipes(); + module.runTaskAsync(this::loadRenames); + module.runTask(() -> { + final var list = module.getCache().getBlockDataRecipes(); for (final var entry : list) { entry.getKey().registerRecipes( - this.plugin, + module, entry.getValue() ); } @@ -265,7 +274,7 @@ public void reloadVariables() { list.clear(); CraftsMenu.putCrafts( CraftsMenu.Type.BLOCKS, - this.plugin.getCache().customBlockRecipes + module.getCache().getCustomBlockRecipes() ); }); } @@ -303,8 +312,9 @@ public void reloadDefaultVariables() { } public void onEnable() { - final Cache cache = this.plugin.getCache(); - final Location mainWorldSpawn = this.plugin.getServer().getWorlds().get(0).getSpawnLocation(); + final WhoMine module = this.getModule(); + final PaperCache cache = module.getCache(); + final Location mainWorldSpawn = module.getServer().getWorlds().getFirst().getSpawnLocation(); this.setIfNotExists(KEY_SPAWN_LOCATION_SECTION + '.' + KEY_WORLD, mainWorldSpawn.getWorld().getName()); this.setIfNotExists(KEY_SPAWN_LOCATION_SECTION + '.' + KEY_X, mainWorldSpawn.x()); @@ -315,12 +325,12 @@ public void onEnable() { this.parseSpawnLocation(); - cache.getBukkitTasks().add(this.plugin.runTaskTimer(new MainAnomalyActionTask(this.plugin), 0L, this.anomalyCheckRate)); - cache.getBukkitTasks().add(this.plugin.runTaskTimer(new AnomalyParticleTask(this.plugin), 0L, this.anomalyParticlesCheckRate)); + cache.getBukkitTasks().add(module.runTaskTimer(new MainAnomalyActionTask(module), 0L, this.anomalyCheckRate)); + cache.getBukkitTasks().add(module.runTaskTimer(new AnomalyParticleTask(module), 0L, this.anomalyParticlesCheckRate)); - this.plugin.runTaskAsync(this::loadResourcePacks); - this.plugin.runTaskAsync(this::loadAnomalies); - this.plugin.runTaskAsync(this::loadBlocks); + module.runTaskAsync(this::loadResourcePacks); + module.runTaskAsync(this::loadAnomalies); + module.runTaskAsync(this::loadBlocks); } public void reloadYaml() throws ConfigurationException { @@ -380,10 +390,6 @@ public void saveDefaultConfig() throws ConfigurationException { "]}"; } - public @NotNull WhoMine getPlugin() { - return this.plugin; - } - public @Nullable String getDateFormat() { return this.dateFormat; } @@ -566,13 +572,14 @@ private void createDirectories() { } private void createDirectory(final @NotNull String directoryPath) { - final File directory = new File(this.plugin.getDataFolder(), directoryPath); + final WhoMine module = this.getModule(); + final File directory = new File(module.getDataFolder(), directoryPath); if ( !directory.exists() && !directory.mkdirs() ) { - this.plugin.getLogger().warning("Failed to create directory: " + directoryPath); + module.getLogger().warning("Failed to create directory: " + directoryPath); } } @@ -640,8 +647,9 @@ private void parseSkins() { } private void parseSpawnLocation() { + final WhoMine module = this.getModule(); final YamlConfiguration yaml = this.getYaml(); - final Server server = this.plugin.getServer(); + final Server server = module.getServer(); final String spawnLocationWorldName = yaml.getString(KEY_SPAWN_LOCATION_SECTION + '.' + KEY_WORLD, ""); final World spawnLocationWorld = server.getWorld(spawnLocationWorldName); final double spawnLocationX = yaml.getDouble(KEY_SPAWN_LOCATION_SECTION + '.' + KEY_X); @@ -651,9 +659,9 @@ private void parseSpawnLocation() { final float spawnLocationPitch = (float) yaml.getDouble(KEY_SPAWN_LOCATION_SECTION + '.' + KEY_PITCH); if (spawnLocationWorld == null) { - this.plugin.getLogger().warning("World \"" + spawnLocationWorldName + "\" not found!\nUsing default spawn location!"); + module.getLogger().warning("World \"" + spawnLocationWorldName + "\" not found!\nUsing default spawn location!"); - this.spawnLocation = server.getWorlds().get(0).getSpawnLocation(); + this.spawnLocation = server.getWorlds().getFirst().getSpawnLocation(); } else { this.spawnLocation = new Location( spawnLocationWorld, @@ -667,13 +675,14 @@ private void parseSpawnLocation() { } private void parseConsoleInfo() { - final File consoleDataFile = new File(this.plugin.getDataFolder(), CONSOLE_FILE_PATH); + final WhoMine module = this.getModule(); + final File consoleDataFile = new File(module.getDataFolder(), CONSOLE_FILE_PATH); if (!consoleDataFile.exists()) { - this.plugin.saveResource(CONSOLE_FILE_PATH, false); + module.saveResource(CONSOLE_FILE_PATH, false); } - this.plugin.getCache().consolePlayerInfo = new PlayerInfo(this.plugin, UUID.randomUUID(), SharedConstants.CONSOLE_NICKNAME); + module.getCache().setConsolePlayerInfo(new PlayerInfo(module, UUID.randomUUID(), SharedConstants.CONSOLE_NICKNAME)); } private void parseLanguages() throws IllegalStateException { @@ -690,6 +699,7 @@ private void parseLanguages() throws IllegalStateException { this.defaultLocale = SharedConstants.DEFAULT_LOCALE; } + final WhoMine module = this.getModule(); this.locales = new ObjectArrayList<>(); this.locales.add(this.defaultLocale); @@ -698,7 +708,7 @@ private void parseLanguages() throws IllegalStateException { final Locale locale = Translator.parseLocale(tag); if (locale == null) { - this.plugin.getLogger().warning("Invalid language tag: " + tag); + module.getLogger().warning("Invalid language tag: " + tag); } else { this.locales.add(locale); } @@ -708,15 +718,15 @@ private void parseLanguages() throws IllegalStateException { } private void loadLanguages() { - final StatusHandler statusHandler = this.plugin.getStatusHandler(); + final StatusHandler statusHandler = this.getModule().getStatusHandler(); final YamlConfiguration yaml = this.getYaml(); final ConfigurationSection languageSection = yaml.getConfigurationSection(KEY_LANGUAGE_SECTION + '.' + KEY_CODES); - statusHandler.assignStatus(WhoMine.LOADING_LANGUAGES); + statusHandler.assignStatus(MainModule.LOADING_LANGUAGES); if (languageSection == null) { - statusHandler.assignStatus(WhoMine.LOADED_LANGUAGES); + statusHandler.assignStatus(MainModule.LOADED_LANGUAGES); return; } @@ -725,7 +735,7 @@ private void loadLanguages() { CompletableFuture .allOf( - LanguageFile + LangFileFabric .allFromSection( this.getFile(), yaml, @@ -755,24 +765,25 @@ private void loadLanguages() { ) .thenRun(() -> { TranslationRegistry.registerGlobal(); - statusHandler.assignStatus(WhoMine.LOADED_LANGUAGES); + statusHandler.assignStatus(MainModule.LOADED_LANGUAGES); }); } private void loadResourcePacks() { - final StatusHandler statusHandler = this.plugin.getStatusHandler(); + final WhoMine module = this.getModule(); + final StatusHandler statusHandler = module.getStatusHandler(); final YamlConfiguration yaml = this.getYaml(); final ConfigurationSection resourcePacksSection = yaml.getConfigurationSection(KEY_RESOURCE_PACKS_SECTION); - statusHandler.assignStatus(WhoMine.LOADING_RESOURCE_PACKS); + statusHandler.assignStatus(MainModule.LOADING_RESOURCE_PACKS); if (resourcePacksSection == null) { - statusHandler.assignStatus(WhoMine.LOADED_RESOURCE_PACKS); + statusHandler.assignStatus(MainModule.LOADED_RESOURCE_PACKS); return; } - final ComponentLogger logger = this.plugin.getComponentLogger(); + final ComponentLogger logger = module.getComponentLogger(); final long start = System.currentTimeMillis(); final Map> futureMap; @@ -805,7 +816,7 @@ private void loadResourcePacks() { } ); } catch (final FatalPackLoadException e) { - statusHandler.assignStatus(WhoMine.FAILED_LOAD_RESOURCE_PACKS); + statusHandler.assignStatus(MainModule.FAILED_LOAD_RESOURCE_PACKS); logger.error( "Failed to load resource packs due to a fatal error!", e @@ -820,15 +831,16 @@ private void loadResourcePacks() { .values() .toArray(CompletableFuture[]::new) ) - .thenRun(() -> statusHandler.assignStatus(WhoMine.LOADED_RESOURCE_PACKS)); + .thenRun(() -> statusHandler.assignStatus(MainModule.LOADED_RESOURCE_PACKS)); } private void loadAnomalies() { - final StatusHandler statusHandler = this.plugin.getStatusHandler(); - final Cache cache = this.plugin.getCache(); - final Logger logger = this.plugin.getLogger(); + final WhoMine module = this.getModule(); + final StatusHandler statusHandler = module.getStatusHandler(); + final PaperCache cache = module.getCache(); + final Logger logger = module.getLogger(); - statusHandler.assignStatus(WhoMine.LOADING_ANOMALIES); + statusHandler.assignStatus(MainModule.LOADING_ANOMALIES); try (final var path = Files.walk(Paths.get(this.getFile().getParent() + '/' + ANOMALIES_FOLDER))) { path.parallel() @@ -836,7 +848,7 @@ private void loadAnomalies() { .map(Path::toFile) .forEach(file -> { try { - final Anomaly anomaly = Anomaly.fromConfig(this.plugin, file); + final Anomaly anomaly = Anomaly.fromConfig(module, file); cache.getAnomalies().put(anomaly.getNamespacedKey(), anomaly); } catch (final IllegalArgumentException e) { @@ -848,9 +860,9 @@ private void loadAnomalies() { } }); - statusHandler.assignStatus(WhoMine.LOADED_ANOMALIES); + statusHandler.assignStatus(MainModule.LOADED_ANOMALIES); } catch (final IOException e) { - statusHandler.assignStatus(WhoMine.FAILED_LOAD_ANOMALIES); + statusHandler.assignStatus(MainModule.FAILED_LOAD_ANOMALIES); logger.log( Level.SEVERE, "An error occurred while loading anomalies!", @@ -861,27 +873,29 @@ private void loadAnomalies() { private void loadBlocks() { final long start = System.currentTimeMillis(); - final StatusHandler statusHandler = this.plugin.getStatusHandler(); - statusHandler.assignStatus(WhoMine.LOADING_BLOCKS); + final WhoMine module = this.getModule(); + final StatusHandler statusHandler = module.getStatusHandler(); + + statusHandler.assignStatus(MainModule.LOADING_BLOCKS); try (final var pathStream = Files.walk(Paths.get(this.getFile().getParent() + '/' + BLOCKS_FOLDER))) { pathStream.parallel() .filter(file -> file.getFileName().toString().endsWith(JSON_EXTENSION)) - .map(path -> CustomBlockData.fromFile(this.plugin, path.toFile())) + .map(path -> CustomBlockData.fromFile(module, path.toFile())) .filter(Objects::nonNull) .forEach(CustomBlockRegistry::register); - statusHandler.assignStatus(WhoMine.LOADED_BLOCKS); - this.plugin.getComponentLogger().info( + statusHandler.assignStatus(MainModule.LOADED_BLOCKS); + module.getComponentLogger().info( Component.text( "Loaded " + CustomBlockRegistry.size() + " custom blocks in " + (System.currentTimeMillis() - start) + "ms", NamedTextColor.GREEN ) ); } catch (final IOException e) { - statusHandler.assignStatus(WhoMine.FAILED_LOAD_BLOCKS); - this.plugin.getLogger().log( + statusHandler.assignStatus(MainModule.FAILED_LOAD_BLOCKS); + module.getLogger().log( Level.SEVERE, "An error occurred while loading blocks", e @@ -891,29 +905,31 @@ private void loadBlocks() { private void loadRenames() { final long start = System.currentTimeMillis(); - final StatusHandler statusHandler = this.plugin.getStatusHandler(); - statusHandler.assignStatus(WhoMine.LOADING_RENAMEABLES); + final WhoMine module = this.getModule(); + final StatusHandler statusHandler = module.getStatusHandler(); + + statusHandler.assignStatus(MainModule.LOADING_RENAMEABLES); try (final var pathStream = Files.walk(Paths.get(this.getFile().getParent() + '/' + ITEMS_FOLDER))) { pathStream.parallel() .filter(file -> file.getFileName().toString().endsWith(YAML_EXTENSION)) - .map(path -> RenameableItem.fromFile(this.plugin, path.toFile())) + .map(path -> RenameableItem.fromFile(module, path.toFile())) .filter(Objects::nonNull) .forEach(RenameableItemRegistry::register); - statusHandler.assignStatus(WhoMine.LOADED_RENAMEABLES); - this.plugin.getComponentLogger().info( + statusHandler.assignStatus(MainModule.LOADED_RENAMEABLES); + module.getComponentLogger().info( Component.text( "Loaded " + RenameableItemRegistry.keysSize() + " renameable items in " + (System.currentTimeMillis() - start) + "ms", NamedTextColor.GREEN ) ); - RenamesMenu.update(this.plugin); + RenamesMenu.update(module); } catch (final IOException e) { - statusHandler.assignStatus(WhoMine.FAILED_LOAD_RENAMEABLES); - this.plugin.getLogger().log( + statusHandler.assignStatus(MainModule.FAILED_LOAD_RENAMEABLES); + module.getLogger().log( Level.SEVERE, "An error occurred while loading renameable items", e diff --git a/paper/src/main/java/com/minersstudios/whomine/WhoMineImpl.java b/platform/paper/src/main/java/com/minersstudios/whomine/WhoMineImpl.java similarity index 62% rename from paper/src/main/java/com/minersstudios/whomine/WhoMineImpl.java rename to platform/paper/src/main/java/com/minersstudios/whomine/WhoMineImpl.java index 0292c53f..32e532d2 100644 --- a/paper/src/main/java/com/minersstudios/whomine/WhoMineImpl.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/WhoMineImpl.java @@ -1,86 +1,88 @@ package com.minersstudios.whomine; import com.google.common.base.Charsets; -import com.minersstudios.whomine.chat.ChatType; +import com.minersstudios.wholib.locale.TranslationRegistry; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.PaperConfig; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.*; +import com.minersstudios.wholib.status.StatusHandler; +import com.minersstudios.wholib.status.StatusWatcher; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.utility.SharedConstants; +import com.minersstudios.wholib.paper.chat.ChatType; import com.minersstudios.whomine.command.api.CommandManager; -import com.minersstudios.whomine.custom.decor.CustomDecorType; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.discord.DiscordManager; -import com.minersstudios.whomine.inventory.holder.AbstractInventoryHolder; -import com.minersstudios.whomine.listener.api.ListenerManager; -import com.minersstudios.whomine.listener.impl.event.mechanic.DosimeterMechanic; -import com.minersstudios.whomine.locale.TranslationRegistry; -import com.minersstudios.whomine.locale.Translations; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorType; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.discord.DiscordManager; +import com.minersstudios.wholib.paper.gui.PaperGuiManager; +import com.minersstudios.wholib.paper.listener.PaperListenerManager; +import com.minersstudios.whomine.listener.event.block.*; +import com.minersstudios.whomine.listener.event.entity.*; +import com.minersstudios.whomine.listener.event.inventory.*; +import com.minersstudios.whomine.listener.event.mechanic.*; +import com.minersstudios.whomine.listener.event.player.*; +import com.minersstudios.whomine.listener.event.chat.AsyncChatListener; +import com.minersstudios.whomine.listener.event.command.UnknownCommandListener; +import com.minersstudios.whomine.listener.event.hanging.HangingBreakByEntityListener; +import com.minersstudios.whomine.listener.event.server.ServerCommandListener; +import com.minersstudios.whomine.listener.packet.player.PlayerActionListener; +import com.minersstudios.whomine.listener.packet.player.PlayerUpdateSignListener; +import com.minersstudios.whomine.listener.packet.player.SwingArmListener; import com.minersstudios.whomine.menu.DiscordLinkCodeMenu; import com.minersstudios.whomine.menu.PronounMenu; import com.minersstudios.whomine.menu.ResourcePackMenu; import com.minersstudios.whomine.menu.SkinsMenu; -import com.minersstudios.whomine.packet.PacketRegistry; -import com.minersstudios.whomine.packet.PacketType; -import com.minersstudios.whomine.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; import com.minersstudios.whomine.scheduler.task.BanListTask; import com.minersstudios.whomine.scheduler.task.MuteMapTask; import com.minersstudios.whomine.scheduler.task.PlayerListTask; import com.minersstudios.whomine.scheduler.task.SeatsTask; -import com.minersstudios.whomine.api.status.StatusHandler; -import com.minersstudios.whomine.api.status.StatusWatcher; -import com.minersstudios.whomine.utility.*; -import com.minersstudios.whomine.world.WorldDark; -import com.minersstudios.whomine.world.sound.SoundAdapter; -import com.minersstudios.whomine.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.world.WorldDark; +import com.minersstudios.wholib.paper.world.sound.SoundAdapter; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import fr.xephi.authme.AuthMe; import fr.xephi.authme.api.v3.AuthMeApi; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.coreprotect.CoreProtect; import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.Material; +import net.minecraft.world.level.block.Blocks; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.UnknownNullability; -import org.jetbrains.annotations.UnmodifiableView; import java.io.*; import java.lang.reflect.Field; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; -import static com.minersstudios.whomine.locale.Translations.*; -import static com.minersstudios.whomine.utility.Font.Chars.RED_EXCLAMATION_MARK; +import static com.minersstudios.wholib.locale.Translations.*; +import static com.minersstudios.wholib.utility.Font.Chars.RED_EXCLAMATION_MARK; import static net.kyori.adventure.text.Component.text; @ApiStatus.Internal public final class WhoMineImpl extends JavaPlugin implements WhoMine { - static WhoMine singleton; - private final File configFile; - private final Cache cache; - private final Config config; private final StatusHandler statusHandler; - private final ListenerManager listenerManager; + private final PaperCacheImpl cache; + private final PaperConfigImpl config; + private final PaperListenerManager listenerManager; + private final PaperGuiManager guiManager; private final CommandManager commandManager; private final DiscordManager discordManager; - private final Map, AbstractInventoryHolder> inventoryHolderMap; + + private final File configFile; private FileConfiguration newConfig; - private Scoreboard scoreboardHideTags; - private Team scoreboardHideTagsTeam; static { - initClass(PacketRegistry.class); - initClass(PacketType.class); initClass(Font.class); initClass(BlockUtils.class); initClass(ChatUtils.class); @@ -91,32 +93,27 @@ public final class WhoMineImpl extends JavaPlugin implements WhoMine { } public WhoMineImpl() { - singleton = this; + SINGLETON.set(this); this.setupDataFolder(); this.configFile = new File(this.getDataFolder(), "config.yml"); - this.cache = new Cache(this); - this.config = new Config(this); + this.cache = new PaperCacheImpl(this); + this.config = new PaperConfigImpl(this); this.statusHandler = new StatusHandler(); - this.listenerManager = new ListenerManager(this); + this.listenerManager = new PaperListenerManager(this); + this.guiManager = new PaperGuiManager(this); this.commandManager = new CommandManager(this); this.discordManager = new DiscordManager(this); - this.inventoryHolderMap = new Object2ObjectOpenHashMap<>(); } @Override - public @NotNull File getConfigFile() { - return this.configFile; - } - - @Override - public @NotNull Cache getCache() { + public @NotNull PaperCache getCache() { return this.cache; } @Override - public @NotNull Config getConfiguration() { + public @NotNull PaperConfig getConfiguration() { return this.config; } @@ -126,40 +123,20 @@ public WhoMineImpl() { } @Override - public @NotNull ListenerManager getListenerManager() { + public @NotNull PaperListenerManager getListenerManager() { return this.listenerManager; } @Override - public @NotNull CommandManager getCommandManager() { - return this.commandManager; + public @NotNull PaperGuiManager getGuiManager() { + return this.guiManager; } @Override - public @NotNull DiscordManager getDiscordManager() { + public @NotNull DiscordManager getDiscordModule() { return this.discordManager; } - @Override - public @NotNull @UnmodifiableView Map, AbstractInventoryHolder> getInventoryHolderMap() { - return Collections.unmodifiableMap(this.inventoryHolderMap); - } - - @Override - public @NotNull Optional getInventoryHolder(final @NotNull Class clazz) { - return Optional.ofNullable(this.inventoryHolderMap.get(clazz)); - } - - @Override - public @UnknownNullability Scoreboard getScoreboardHideTags() { - return this.scoreboardHideTags; - } - - @Override - public @UnknownNullability Team getScoreboardHideTagsTeam() { - return this.scoreboardHideTagsTeam; - } - @Override public @NotNull FileConfiguration getConfig() { if (this.newConfig == null) { @@ -190,13 +167,12 @@ public void onLoad() { this.config.reload(); + PacketClassBinder.bindAll(); + TranslationRegistry.bootstrap(this.config.getDefaultLocale()); initClass(Translations.class); - ItemUtils.setMaxStackSize( - Material.LEATHER_HORSE_ARMOR, - SharedConstants.LEATHER_HORSE_ARMOR_MAX_STACK_SIZE - ); + BlockUtils.editBlockStrength(Blocks.NOTE_BLOCK, -1.0f, 3600000.8F); PaperUtils .editConfig(PaperUtils.ConfigType.GLOBAL, this.getServer()) @@ -229,8 +205,8 @@ public void onEnable() { this.cache.load(); this.discordManager.load(); - this.listenerManager.bootstrap(); this.commandManager.bootstrap(); + this.bootstrap(); this.statusHandler.addWatcher( StatusWatcher.builder() @@ -246,7 +222,6 @@ public void onEnable() { this.setupCoreProtect(); this.setupAuthMe(); - this.setupHideTags(); this.runTask(() -> this.cache.worldDark = new WorldDark()); this.runTaskTimer(new SeatsTask(this), 0L, 1L); // 0.05 seconds @@ -260,6 +235,13 @@ public void onEnable() { this.config.onEnable(); + MSLogger.info( + "Note block strength: " + Blocks.NOTE_BLOCK.defaultDestroyTime() + ", " + + "Acacia planks strength: " + Blocks.ACACIA_PLANKS.defaultDestroyTime() + ", " + + "Note block getDestroySpeed: " + Blocks.NOTE_BLOCK.defaultBlockState().destroySpeed + ", " + + "Acacia planks getDestroySpeed: " + Blocks.ACACIA_PLANKS.defaultBlockState().destroySpeed + ); + this.statusHandler.assignStatus(ENABLED); if (this.isEnabled()) { this.getComponentLogger() @@ -298,14 +280,15 @@ public void reloadConfig() { this.newConfig = YamlConfiguration.loadConfiguration(this.configFile); final InputStream defaultInput = this.getResource("config.yml"); - if (defaultInput == null) { - return; - } - - final InputStreamReader inputReader = new InputStreamReader(defaultInput, Charsets.UTF_8); - final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(inputReader); + if (defaultInput != null) { + try(final var inputReader = new InputStreamReader(defaultInput, Charsets.UTF_8)) { + final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(inputReader); - this.newConfig.setDefaults(configuration); + this.newConfig.setDefaults(configuration); + } catch (final Exception e) { + this.getLogger().severe("Could not load default config from jar"); + } + } } @Override @@ -471,15 +454,8 @@ public void runTaskTimer( this.getServer().getScheduler().runTaskTimer(this, task, delay, period); } - @Override - public void openCustomInventory( - final @NotNull Class clazz, - final @NotNull Player player - ) { - this.getInventoryHolder(clazz) - .ifPresent( - holder -> holder.open(player) - ); + @NotNull File getConfigFile() { + return this.configFile; } private void setupCoreProtect() { @@ -501,14 +477,6 @@ private void setupCoreProtect() { } } - private void setupHideTags() { - this.scoreboardHideTags = this.getServer().getScoreboardManager().getNewScoreboard(); - this.scoreboardHideTagsTeam = this.scoreboardHideTags.registerNewTeam(SharedConstants.HIDE_TAGS_TEAM_NAME); - - this.scoreboardHideTagsTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER); - this.scoreboardHideTagsTeam.setCanSeeFriendlyInvisibles(false); - } - private void setupAuthMe() { final Logger logger = this.getLogger(); final PluginManager pluginManager = this.getServer().getPluginManager(); @@ -581,6 +549,113 @@ private void setupDataFolder() { } } + private void bootstrap() { + // + + // TODO: Discord listener manager + //module.getStatusHandler().addWatcher( + // StatusWatcher.builder() + // .statuses(MainModule.LOADED_DISCORD) + // .successRunnable( + // () -> { + // this.listenerManager.register(new CommandAutoCompleteInteractionListener()); + // this.listenerManager.register(new MessageReceivedListener()); + // this.listenerManager.register(new SlashCommandInteractionListener()); + // } + // ) + // .build() + //); + // + + // + + // Block listeners + this.listenerManager.register(new BlockBreakListener()); + + this.listenerManager.register(new BlockDamageListener()); + this.listenerManager.register(new BlockDropItemListener()); + this.listenerManager.register(new BlockExplodeListener()); + this.listenerManager.register(new BlockPistonExtendListener()); + this.listenerManager.register(new BlockPistonRetractListener()); + this.listenerManager.register(new BlockPlaceListener()); + this.listenerManager.register(new NotePlayListener()); + + // Chat listeners + this.listenerManager.register(new AsyncChatListener()); + + // Command listeners + this.listenerManager.register(new UnknownCommandListener()); + + // Entity listeners + this.listenerManager.register(new EntityChangeBlockListener()); + this.listenerManager.register(new EntityDamageByEntityListener()); + this.listenerManager.register(new EntityDamageListener()); + this.listenerManager.register(new EntityDismountListener()); + this.listenerManager.register(new EntityExplodeListener()); + + // Hanging listeners + this.listenerManager.register(new HangingBreakByEntityListener()); + + // Inventory listeners + this.listenerManager.register(new InventoryClickListener()); + this.listenerManager.register(new InventoryCloseListener()); + this.listenerManager.register(new InventoryCreativeListener()); + this.listenerManager.register(new InventoryDragListener()); + this.listenerManager.register(new InventoryOpenListener()); + this.listenerManager.register(new PrepareAnvilListener()); + this.listenerManager.register(new PrepareItemCraftListener()); + + // Player listeners + this.listenerManager.register(new AsyncPlayerPreLoginListener()); + this.listenerManager.register(new PlayerAdvancementDoneListener()); + this.listenerManager.register(new PlayerBucketEmptyListener()); + this.listenerManager.register(new PlayerChangedWorldListener()); + this.listenerManager.register(new PlayerCommandPreprocessListener()); + this.listenerManager.register(new PlayerDeathListener()); + this.listenerManager.register(new PlayerDropItemListener()); + this.listenerManager.register(new PlayerEditBookListener()); + this.listenerManager.register(new PlayerGameModeChangeListener()); + this.listenerManager.register(new PlayerInteractEntityListener()); + this.listenerManager.register(new PlayerInteractListener()); + this.listenerManager.register(new PlayerJoinListener()); + this.listenerManager.register(new PlayerKickListener()); + this.listenerManager.register(new PlayerMoveListener()); + this.listenerManager.register(new PlayerQuitListener()); + this.listenerManager.register(new PlayerResourcePackStatusListener()); + this.listenerManager.register(new PlayerSpawnLocationListener()); + this.listenerManager.register(new PlayerStopSpectatingEntityListener()); + this.listenerManager.register(new PlayerTeleportListener()); + + // Server listeners + this.listenerManager.register(new ServerCommandListener()); + + // Mechanic listeners + this.listenerManager.register(new BanSwordMechanic.EntityDamageByEntity()); + this.listenerManager.register(new BanSwordMechanic.InventoryClick()); + this.listenerManager.register(new CardBoxMechanic.InventoryMoveItem()); + this.listenerManager.register(new CardBoxMechanic.InventoryDrag()); + this.listenerManager.register(new CardBoxMechanic.InventoryClick()); + this.listenerManager.register(new CocaineMechanic.PlayerItemConsume()); + this.listenerManager.register(new DamageableItemMechanic.PlayerItemDamage()); + this.listenerManager.register(new DosimeterMechanic.PlayerSwapHandItems()); + this.listenerManager.register(new DosimeterMechanic.PlayerItemHeld()); + this.listenerManager.register(new DosimeterMechanic.InventoryClick()); + this.listenerManager.register(new DosimeterMechanic.PlayerDropItem()); + this.listenerManager.register(new DosimeterMechanic.PlayerQuit()); + this.listenerManager.register(new DosimeterMechanic.PlayerInteract()); + this.listenerManager.register(new PoopMechanic.PlayerInteract()); + + // + + // + + this.listenerManager.register(new PlayerActionListener()); + this.listenerManager.register(new PlayerUpdateSignListener()); + this.listenerManager.register(new SwingArmListener()); + + // + } + private static void initClass(final @NotNull Class clazz) throws ExceptionInInitializerError { try { Class.forName(clazz.getName()); diff --git a/paper/src/main/java/com/minersstudios/whomine/WhoMineLoader.java b/platform/paper/src/main/java/com/minersstudios/whomine/WhoMineLoader.java similarity index 100% rename from paper/src/main/java/com/minersstudios/whomine/WhoMineLoader.java rename to platform/paper/src/main/java/com/minersstudios/whomine/WhoMineLoader.java diff --git a/paper/src/main/java/com/minersstudios/whomine/command/api/CommandManager.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/CommandManager.java similarity index 98% rename from paper/src/main/java/com/minersstudios/whomine/command/api/CommandManager.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/api/CommandManager.java index 9ae2fded..265406c0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/api/CommandManager.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/CommandManager.java @@ -1,6 +1,6 @@ package com.minersstudios.whomine.command.api; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.module.MainModule; import com.minersstudios.whomine.WhoMineImpl; import com.minersstudios.whomine.command.api.minecraft.CommandData; import com.minersstudios.whomine.command.api.minecraft.Commodore; @@ -28,8 +28,8 @@ import com.minersstudios.whomine.command.impl.minecraft.player.ResourcePackCommand; import com.minersstudios.whomine.command.impl.minecraft.player.SkinsCommand; import com.minersstudios.whomine.command.impl.minecraft.player.roleplay.*; -import com.minersstudios.whomine.api.status.StatusWatcher; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.status.StatusWatcher; +import com.minersstudios.wholib.utility.ChatUtils; import com.mojang.brigadier.tree.LiteralCommandNode; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -201,7 +201,7 @@ public void bootstrap() { // this.plugin.getStatusHandler().addWatcher( StatusWatcher.builder() - .statuses(WhoMine.LOADED_DISCORD) + .statuses(MainModule.LOADED_DISCORD) .successRunnable( () -> { new AddSkinCommand(this.plugin).register(); @@ -255,7 +255,7 @@ void registerDiscord(final @NotNull SlashCommandExecutor executor) throws Illega throw new IllegalStateException("Command already registered : " + executor); } - this.plugin.getDiscordManager().getJda() + this.plugin.getDiscordModule().getJda() .ifPresent( jda -> jda.upsertCommand(executor.getData()) .onSuccess( diff --git a/paper/src/main/java/com/minersstudios/whomine/command/api/PluginCommandExecutor.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/PluginCommandExecutor.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/command/api/PluginCommandExecutor.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/api/PluginCommandExecutor.java index efdb3f9f..8a08cd81 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/api/PluginCommandExecutor.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/PluginCommandExecutor.java @@ -1,8 +1,8 @@ package com.minersstudios.whomine.command.api; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.plugin.AbstractPluginComponent; +import com.minersstudios.wholib.module.AbstractModuleComponent; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -15,7 +15,7 @@ /** * Represents a class which contains a bunch of methods for handling commands */ -public abstract class PluginCommandExecutor extends AbstractPluginComponent implements CommandExecutor, TabCompleter { +public abstract class PluginCommandExecutor extends AbstractModuleComponent implements CommandExecutor, TabCompleter { private final CommandData data; /** @@ -51,15 +51,14 @@ protected PluginCommandExecutor( @Override public @NotNull String toString() { return this.getClass().getSimpleName() + '{' + - "plugin=" + this.getPlugin() + + "plugin=" + this.getModule() + ", commandData=" + this.data + '}'; } - @Override public void register() throws IllegalStateException { - this.getPlugin().getCommandManager().registerMinecraft(this); - this.onRegister(); + //this.getModule().getCommandManager().registerMinecraft(this); + //this.onRegister(); } /** diff --git a/paper/src/main/java/com/minersstudios/whomine/command/api/SlashCommandExecutor.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/SlashCommandExecutor.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/command/api/SlashCommandExecutor.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/api/SlashCommandExecutor.java index 08ee9ced..65850ce7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/api/SlashCommandExecutor.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/SlashCommandExecutor.java @@ -1,9 +1,9 @@ package com.minersstudios.whomine.command.api; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.discord.interaction.CommandHandler; import com.minersstudios.whomine.command.api.discord.interaction.TabCompleterHandler; -import com.minersstudios.whomine.plugin.AbstractPluginComponent; +import com.minersstudios.wholib.module.AbstractModuleComponent; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -21,7 +21,7 @@ /** * Represents an abstract class for handling discord slash commands */ -public abstract class SlashCommandExecutor extends AbstractPluginComponent { +public abstract class SlashCommandExecutor extends AbstractModuleComponent { private final Map> userRemainingTabCompletes; private final SlashCommandData data; @@ -56,15 +56,14 @@ protected SlashCommandExecutor( @Override public @NotNull String toString() { return this.getClass().getSimpleName() + '{' + - "plugin=" + this.getPlugin() + + "plugin=" + this.getModule() + ", commandInfo=" + this.data + '}'; } - @Override public final void register() throws IllegalStateException { - this.getPlugin().getCommandManager().registerDiscord(this); - this.onRegister(); + //this.getModule().getCommandManager().registerDiscord(this); + //this.onRegister(); } /** @@ -95,7 +94,7 @@ public final void register() throws IllegalStateException { public final void execute(final @NotNull SlashCommandInteractionEvent event) { this.onCommand( new CommandHandler( - this.getPlugin(), + this.getModule(), event.getInteraction() ) ); @@ -117,7 +116,7 @@ public final void tabComplete(final @NotNull CommandAutoCompleteInteractionEvent entry == null || entry.getKey() != interaction.getCommandIdLong() ) { - handler = new TabCompleterHandler(this.getPlugin(), interaction); + handler = new TabCompleterHandler(this.getModule(), interaction); this.userRemainingTabCompletes.put( interaction.getUser(), diff --git a/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/AbstractInteractionHandler.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/AbstractInteractionHandler.java similarity index 80% rename from paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/AbstractInteractionHandler.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/AbstractInteractionHandler.java index 152ac322..751169f8 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/AbstractInteractionHandler.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/AbstractInteractionHandler.java @@ -1,7 +1,7 @@ package com.minersstudios.whomine.command.api.discord.interaction; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.player.PlayerInfo; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.interactions.Interaction; import org.jetbrains.annotations.NotNull; @@ -35,9 +35,9 @@ public AbstractInteractionHandler( final User user = this.interaction.getUser(); - if (this.plugin.getDiscordManager().isVerified(user)) { - this.playerInfo = PlayerInfo.fromDiscord(this.plugin, user.getIdLong()); - } + //if (this.plugin.getDiscordModule().isVerified(user)) { + // this.playerInfo = PlayerInfo.fromDiscord(this.plugin, user.getIdLong()); + //} return this.playerInfo; } diff --git a/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/CommandHandler.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/CommandHandler.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/CommandHandler.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/CommandHandler.java index d3ffcf5b..97cdd81a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/CommandHandler.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/CommandHandler.java @@ -1,9 +1,9 @@ package com.minersstudios.whomine.command.api.discord.interaction; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.player.PlayerInfo; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; @@ -33,7 +33,7 @@ public CommandHandler( final User user = this.getInteraction().getUser(); - if (!this.getPlugin().getDiscordManager().isVerified(user)) { + if (!this.getPlugin().getDiscordModule().isVerified(user)) { this.send(Translations.DISCORD_NOT_A_USER.asString()); return null; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/TabCompleterHandler.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/TabCompleterHandler.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/TabCompleterHandler.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/TabCompleterHandler.java index b522e3f9..cd9a343b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/TabCompleterHandler.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/discord/interaction/TabCompleterHandler.java @@ -1,6 +1,6 @@ package com.minersstudios.whomine.command.api.discord.interaction; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import net.dv8tion.jda.api.interactions.AutoCompleteQuery; import net.dv8tion.jda.api.interactions.commands.CommandAutoCompleteInteraction; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/CommandData.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/CommandData.java similarity index 99% rename from paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/CommandData.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/CommandData.java index ecc8b0f9..ab07a5fb 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/CommandData.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/CommandData.java @@ -1,6 +1,6 @@ package com.minersstudios.whomine.command.api.minecraft; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.utility.ChatUtils; import com.mojang.brigadier.tree.CommandNode; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanMaps; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/Commodore.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/Commodore.java similarity index 86% rename from paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/Commodore.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/Commodore.java index 5f4e83f0..c0ea291b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/Commodore.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/api/minecraft/Commodore.java @@ -1,8 +1,12 @@ package com.minersstudios.whomine.command.api.minecraft; import com.destroystokyo.paper.event.brigadier.AsyncPlayerSendCommandsEvent; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.api.status.StatusWatcher; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.module.MainModule; +import com.minersstudios.wholib.status.StatusWatcher; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.tree.ArgumentCommandNode; import com.mojang.brigadier.tree.CommandNode; @@ -11,8 +15,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,6 +29,7 @@ /** * API for registering commands with Mojang's Brigadier command system */ +@SuppressWarnings("UnstableApiUsage") public final class Commodore { public final List commands; private final String pluginName; @@ -74,26 +78,9 @@ public Commodore(final @NotNull WhoMine plugin) { plugin.getStatusHandler().addWatcher( StatusWatcher.builder() - .statuses(WhoMine.ENABLED) + .statuses(MainModule.ENABLED) .successRunnable( - () -> plugin.getServer().getPluginManager().registerEvents(new Listener() { - - @SuppressWarnings("UnstableApiUsage") - @EventHandler - public void onPlayerSendCommandsEvent(final @NotNull AsyncPlayerSendCommandsEvent event) { - if ( - event.isAsynchronous() - || !event.hasFiredAsync() - ) { - for (final var command : Commodore.this.commands) { - command.apply( - event.getPlayer(), - event.getCommandNode() - ); - } - } - } - }, plugin) + () -> plugin.getListenerManager().register(new AsyncPlayerSendCommandsListener()) ) .build() ); @@ -258,4 +245,25 @@ public void apply( root.addChild((CommandNode) this.node); } } + + @ListenFor(AsyncPlayerSendCommandsEvent.class) + public class AsyncPlayerSendCommandsListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerSendCommandsEvent(final @NotNull PaperEventContainer> container) { + final var event = container.getEvent(); + + if ( + event.isAsynchronous() + || !event.hasFiredAsync() + ) { + for (final var command : Commodore.this.commands) { + command.apply( + event.getPlayer(), + event.getCommandNode() + ); + } + } + } + } } diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/AddSkinCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/AddSkinCommand.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/discord/AddSkinCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/AddSkinCommand.java index 78e53d1c..a627b605 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/AddSkinCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/AddSkinCommand.java @@ -1,12 +1,12 @@ package com.minersstudios.whomine.command.impl.discord; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.SlashCommandExecutor; import com.minersstudios.whomine.command.api.discord.interaction.CommandHandler; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.skin.Skin; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.skin.Skin; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.utility.MSLogger; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; @@ -14,7 +14,7 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class AddSkinCommand extends SlashCommandExecutor { @@ -97,7 +97,7 @@ protected void onCommand(final @NotNull CommandHandler handler) { && signatureOption == null ) { try { - final Skin skin = Skin.create(this.getPlugin(), name, urlOption.getAsString()); + final Skin skin = Skin.create(this.getModule(), name, urlOption.getAsString()); if (skin == null) { handler.send(DISCORD_SKIN_SERVICE_UNAVAILABLE.asString()); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/EditSkinCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/EditSkinCommand.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/discord/EditSkinCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/EditSkinCommand.java index 42e8818f..c37e7d11 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/EditSkinCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/EditSkinCommand.java @@ -1,14 +1,14 @@ package com.minersstudios.whomine.command.impl.discord; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.utility.ChatUtils; import com.minersstudios.whomine.command.api.SlashCommandExecutor; import com.minersstudios.whomine.command.api.discord.interaction.CommandHandler; import com.minersstudios.whomine.command.api.discord.interaction.TabCompleterHandler; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.skin.Skin; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.skin.Skin; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -24,7 +24,7 @@ import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class EditSkinCommand extends SlashCommandExecutor { @@ -86,7 +86,7 @@ protected void onCommand(final @NotNull CommandHandler handler) { && signatureOption == null ) { try { - final Skin skin = Skin.create(this.getPlugin(), name, urlOption.getAsString()); + final Skin skin = Skin.create(this.getModule(), name, urlOption.getAsString()); if (skin == null) { handler.send(DISCORD_SKIN_SERVICE_UNAVAILABLE.asString()); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/HelpCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/HelpCommand.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/discord/HelpCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/HelpCommand.java index 7569b8be..9e6a92af 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/HelpCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/HelpCommand.java @@ -1,6 +1,6 @@ package com.minersstudios.whomine.command.impl.discord; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.discord.interaction.CommandHandler; import com.minersstudios.whomine.command.api.SlashCommandExecutor; import net.dv8tion.jda.api.interactions.commands.build.Commands; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/RemoveSkinCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/RemoveSkinCommand.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/discord/RemoveSkinCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/RemoveSkinCommand.java index b69709ab..b8a9d8d4 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/RemoveSkinCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/RemoveSkinCommand.java @@ -1,14 +1,14 @@ package com.minersstudios.whomine.command.impl.discord; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.utility.ChatUtils; import com.minersstudios.whomine.command.api.SlashCommandExecutor; import com.minersstudios.whomine.command.api.discord.interaction.CommandHandler; import com.minersstudios.whomine.command.api.discord.interaction.TabCompleterHandler; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.skin.Skin; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.skin.Skin; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -23,7 +23,7 @@ import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class RemoveSkinCommand extends SlashCommandExecutor { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/SkinListCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/SkinListCommand.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/discord/SkinListCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/SkinListCommand.java index 35e69e20..154ac7f7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/SkinListCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/SkinListCommand.java @@ -1,11 +1,11 @@ package com.minersstudios.whomine.command.impl.discord; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.locale.Translations; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.locale.Translations; import com.minersstudios.whomine.command.api.SlashCommandExecutor; import com.minersstudios.whomine.command.api.discord.interaction.CommandHandler; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.player.PlayerInfo; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/UnlinkCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/UnlinkCommand.java similarity index 78% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/discord/UnlinkCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/UnlinkCommand.java index 89a52b86..d40e75eb 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/UnlinkCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/discord/UnlinkCommand.java @@ -1,18 +1,18 @@ package com.minersstudios.whomine.command.impl.discord; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.ChatUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.utility.ChatUtils; import com.minersstudios.whomine.command.api.SlashCommandExecutor; import com.minersstudios.whomine.command.api.discord.interaction.CommandHandler; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.player.PlayerInfo; import net.dv8tion.jda.api.interactions.commands.build.Commands; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.locale.Translations.COMMAND_DISCORD_UNLINK_DISCORD_SUCCESS; -import static com.minersstudios.whomine.locale.Translations.COMMAND_DISCORD_UNLINK_MINECRAFT_SUCCESS; +import static com.minersstudios.wholib.locale.Translations.COMMAND_DISCORD_UNLINK_DISCORD_SUCCESS; +import static com.minersstudios.wholib.locale.Translations.COMMAND_DISCORD_UNLINK_MINECRAFT_SUCCESS; import static net.kyori.adventure.text.Component.text; public final class UnlinkCommand extends SlashCommandExecutor { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/CraftsCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/CraftsCommand.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/CraftsCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/CraftsCommand.java index f6f624a8..5008c1ba 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/CraftsCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/CraftsCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; import com.minersstudios.whomine.menu.CraftsMenu; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/MSCoreCommandHandler.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/MSCoreCommandHandler.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/MSCoreCommandHandler.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/MSCoreCommandHandler.java index 746ea8c2..a3cf48b2 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/MSCoreCommandHandler.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/MSCoreCommandHandler.java @@ -1,9 +1,9 @@ package com.minersstudios.whomine.command.impl.minecraft; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.utility.Font; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.permissions.PermissionDefault; @@ -43,7 +43,7 @@ public boolean onCommand( final String @NotNull ... args ) { return switch (args[0]) { - case "reloadconfig" -> ReloadConfigCommand.runCommand(this.getPlugin(), sender); + case "reloadconfig" -> ReloadConfigCommand.runCommand(this.getModule(), sender); default -> false; }; } diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/ReloadConfigCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/ReloadConfigCommand.java similarity index 82% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/ReloadConfigCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/ReloadConfigCommand.java index 952d9243..e0a703e8 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/ReloadConfigCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/ReloadConfigCommand.java @@ -1,8 +1,8 @@ package com.minersstudios.whomine.command.impl.minecraft; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/GetMapLocationCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/GetMapLocationCommand.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/GetMapLocationCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/GetMapLocationCommand.java index d1fe595c..dd3733bd 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/GetMapLocationCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/GetMapLocationCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft.admin; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.NamedTextColor; @@ -17,7 +17,7 @@ import org.bukkit.permissions.PermissionDefault; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class GetMapLocationCommand extends PluginCommandExecutor { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/KickCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/KickCommand.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/KickCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/KickCommand.java index a2d566f3..f64820ba 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/KickCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/KickCommand.java @@ -1,13 +1,13 @@ package com.minersstudios.whomine.command.impl.minecraft.admin; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.utility.MSPlayerUtils; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; import com.mojang.brigadier.arguments.StringArgumentType; import net.kyori.adventure.text.Component; import org.bukkit.command.Command; @@ -19,7 +19,7 @@ import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -60,7 +60,7 @@ public boolean onCommand( final Component reason = args.length > 1 ? text(ChatUtils.extractMessage(args, 1)) : COMMAND_KICK_DEFAULT_REASON.asTranslatable(); - final PlayerInfo playerInfo = PlayerInfo.fromString(this.getPlugin(), args[0]); + final PlayerInfo playerInfo = PlayerInfo.fromString(this.getModule(), args[0]); if (playerInfo == null) { MSLogger.severe( @@ -109,7 +109,7 @@ public boolean onCommand( final String @NotNull ... args ) { return args.length == 1 - ? MSPlayerUtils.getLocalPlayerNames(this.getPlugin()) + ? MSPlayerUtils.getLocalPlayerNames(this.getModule()) : EMPTY_TAB; } } diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/SetServerSpawn.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/SetServerSpawn.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/SetServerSpawn.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/SetServerSpawn.java index 57c6831f..e09ab753 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/SetServerSpawn.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/SetServerSpawn.java @@ -1,11 +1,12 @@ package com.minersstudios.whomine.command.impl.minecraft.admin; -import com.minersstudios.whomine.Config; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.PaperConfig; +import com.minersstudios.whomine.PaperConfigImpl; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.DoubleArgumentType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.commands.arguments.DimensionArgument; @@ -22,7 +23,7 @@ import java.util.Collections; import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -63,7 +64,7 @@ public boolean onCommand( final @NotNull String label, final String @NotNull ... args ) { - final Config config = this.getPlugin().getConfiguration(); + final PaperConfig config = this.getModule().getConfiguration(); final Server server = sender.getServer(); switch (args.length) { @@ -196,7 +197,7 @@ public boolean onCommand( final var names = new ObjectArrayList(); for (final var world : sender.getServer().getWorlds()) { - if (!this.getPlugin().getCache().getWorldDark().isWorldDark(world)) { + if (!this.getModule().getCache().getWorldDark().isWorldDark(world)) { names.add(world.getName()); } } @@ -250,7 +251,7 @@ public boolean onCommand( } private static void setNewLocation( - final @NotNull Config config, + final @NotNull PaperConfig config, final @NotNull CommandSender sender, final @NotNull Location location ) { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/WhitelistCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/WhitelistCommand.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/WhitelistCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/WhitelistCommand.java index c2d82da8..e70fd2d0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/WhitelistCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/WhitelistCommand.java @@ -1,12 +1,12 @@ package com.minersstudios.whomine.command.impl.minecraft.admin; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.collection.PlayerInfoMap; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.Server; @@ -18,7 +18,7 @@ import java.util.Arrays; import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -82,7 +82,7 @@ public boolean onCommand( return false; } - final PlayerInfo playerInfo = PlayerInfo.fromString(this.getPlugin(), playerArg); + final PlayerInfo playerInfo = PlayerInfo.fromString(this.getModule(), playerArg); if (playerInfo == null) { MSLogger.severe( @@ -122,7 +122,7 @@ public boolean onCommand( return false; } - final PlayerInfo playerInfo = PlayerInfo.fromString(this.getPlugin(), playerArg); + final PlayerInfo playerInfo = PlayerInfo.fromString(this.getModule(), playerArg); if (playerInfo == null) { MSLogger.severe( @@ -176,7 +176,7 @@ public boolean onCommand( final var completions = new ObjectArrayList(); if (args[0].equals("remove")) { - final PlayerInfoMap playerInfoMap = this.getPlugin().getCache().getPlayerInfoMap(); + final PlayerInfoMap playerInfoMap = this.getModule().getCache().getPlayerInfoMap(); for (final var offlinePlayer : sender.getServer().getWhitelistedPlayers()) { final int id = diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/BanCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/BanCommand.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/BanCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/BanCommand.java index 83fd3a9a..7756bd9d 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/BanCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/BanCommand.java @@ -1,13 +1,13 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.ban; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.DateUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.utility.DateUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.command.Command; @@ -19,7 +19,7 @@ import java.util.List; import java.util.UUID; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; @@ -73,7 +73,7 @@ public boolean onCommand( ? ChatUtils.extractMessage(args, 2) : COMMAND_BAN_DEFAULT_REASON.asString(); - final PlayerInfo playerInfo = PlayerInfo.fromString(this.getPlugin(), args[0]); + final PlayerInfo playerInfo = PlayerInfo.fromString(this.getModule(), args[0]); if (playerInfo == null) { MSLogger.severe( @@ -109,7 +109,7 @@ public boolean onCommand( continue; } - final int id = this.getPlugin().getCache().getIdMap().getID(uuid, false, false); + final int id = this.getModule().getCache().getIdMap().getID(uuid, false, false); if (id != -1) { completions.add(String.valueOf(id)); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/UnBanCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/UnBanCommand.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/UnBanCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/UnBanCommand.java index a439b0cf..0c33b372 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/UnBanCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/ban/UnBanCommand.java @@ -1,18 +1,18 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.ban; import com.destroystokyo.paper.profile.PlayerProfile; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.utility.Font; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.collection.PlayerInfoMap; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.mojang.brigadier.arguments.StringArgumentType; +import io.papermc.paper.ban.BanListType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.BanEntry; -import org.bukkit.BanList; import org.bukkit.Bukkit; import org.bukkit.ban.ProfileBanList; import org.bukkit.command.Command; @@ -59,7 +59,7 @@ public boolean onCommand( return false; } - final PlayerInfo playerInfo = PlayerInfo.fromString(this.getPlugin(), args[0]); + final PlayerInfo playerInfo = PlayerInfo.fromString(this.getModule(), args[0]); if (playerInfo == null) { MSLogger.severe( @@ -84,8 +84,8 @@ public boolean onCommand( ) { if (args.length == 1) { final var completions = new ObjectArrayList(); - final PlayerInfoMap playerInfoMap = this.getPlugin().getCache().getPlayerInfoMap(); - final ProfileBanList banList = Bukkit.getServer().getBanList(BanList.Type.PROFILE); + final PlayerInfoMap playerInfoMap = this.getModule().getCache().getPlayerInfoMap(); + final ProfileBanList banList = Bukkit.getServer().getBanList(BanListType.PROFILE); final Set> entries = banList.getEntries(); for (final var entry : entries) { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/MSEssentialsCommandHandler.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/MSEssentialsCommandHandler.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/MSEssentialsCommandHandler.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/MSEssentialsCommandHandler.java index 0bc1c198..5c32b0ae 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/MSEssentialsCommandHandler.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/MSEssentialsCommandHandler.java @@ -1,9 +1,9 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.msessentials; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.utility.Font; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.permissions.PermissionDefault; @@ -57,9 +57,9 @@ public boolean onCommand( ) { return args.length != 0 && switch (args[0]) { - case "reload" -> ReloadCommand.runCommand(this.getPlugin(), sender); - case "updateids" -> UpdateIdsCommand.runCommand(this.getPlugin(), sender); - case "updatemutes" -> UpdateMutesCommand.runCommand(this.getPlugin(), sender); + case "reload" -> ReloadCommand.runCommand(this.getModule(), sender); + case "updateids" -> UpdateIdsCommand.runCommand(this.getModule(), sender); + case "updatemutes" -> UpdateMutesCommand.runCommand(this.getModule(), sender); default -> false; }; } diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/ReloadCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/ReloadCommand.java similarity index 83% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/ReloadCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/ReloadCommand.java index 992cb1e5..89779d02 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/ReloadCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/ReloadCommand.java @@ -1,8 +1,8 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.msessentials; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateIdsCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateIdsCommand.java similarity index 71% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateIdsCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateIdsCommand.java index 5ec11e78..da4b03f4 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateIdsCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateIdsCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.msessentials; -import com.minersstudios.whomine.Cache; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.player.PlayerInfo; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -17,7 +17,7 @@ public static boolean runCommand( final @NotNull CommandSender sender ) { final long time = System.currentTimeMillis(); - final Cache cache = plugin.getCache(); + final PaperCache cache = plugin.getCache(); cache.getIdMap().reloadIds(); cache.getPlayerInfoMap().playerInfos().forEach(PlayerInfo::initNames); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateMutesCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateMutesCommand.java similarity index 82% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateMutesCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateMutesCommand.java index 4a5472a8..75511d09 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateMutesCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/msessentials/UpdateMutesCommand.java @@ -1,8 +1,8 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.msessentials; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/MuteCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/MuteCommand.java similarity index 87% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/MuteCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/MuteCommand.java index c7d59b86..893d341e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/MuteCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/MuteCommand.java @@ -1,16 +1,16 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.mute; -import com.minersstudios.whomine.Cache; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.collection.IDMap; -import com.minersstudios.whomine.player.collection.MuteMap; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.DateUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.collection.IDMap; +import com.minersstudios.wholib.paper.player.collection.MuteMap; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.utility.DateUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.command.Command; @@ -22,7 +22,7 @@ import java.util.List; import java.util.UUID; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; @@ -77,7 +77,7 @@ public boolean onCommand( ? ChatUtils.extractMessage(args, 2) : COMMAND_MUTE_DEFAULT_REASON.asString(); - final PlayerInfo playerInfo = PlayerInfo.fromString(this.getPlugin(), args[0]); + final PlayerInfo playerInfo = PlayerInfo.fromString(this.getModule(), args[0]); if (playerInfo == null) { MSLogger.severe( @@ -103,7 +103,7 @@ public boolean onCommand( switch (args.length) { case 1 -> { final var completions = new ObjectArrayList(); - final Cache cache = this.getPlugin().getCache(); + final PaperCache cache = this.getModule().getCache(); final MuteMap muteMap = cache.getMuteMap(); final IDMap idMap = cache.getIdMap(); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/UnMuteCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/UnMuteCommand.java similarity index 85% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/UnMuteCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/UnMuteCommand.java index 58b536e8..852ef708 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/UnMuteCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/mute/UnMuteCommand.java @@ -1,16 +1,16 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.mute; -import com.minersstudios.whomine.Cache; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.collection.IDMap; -import com.minersstudios.whomine.player.collection.MuteMap; -import com.minersstudios.whomine.utility.DateUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.collection.IDMap; +import com.minersstudios.wholib.paper.player.collection.MuteMap; +import com.minersstudios.wholib.paper.utility.DateUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.bukkit.OfflinePlayer; @@ -56,7 +56,7 @@ public boolean onCommand( return false; } - final PlayerInfo playerInfo = PlayerInfo.fromString(this.getPlugin(), args[0]); + final PlayerInfo playerInfo = PlayerInfo.fromString(this.getModule(), args[0]); if (playerInfo == null) { MSLogger.severe( @@ -82,7 +82,7 @@ public boolean onCommand( switch (args.length) { case 1 -> { final var completions = new ObjectArrayList(); - final Cache cache = this.getPlugin().getCache(); + final PaperCache cache = this.getModule().getCache(); final MuteMap muteMap = cache.getMuteMap(); final IDMap idMap = cache.getIdMap(); final Server server = sender.getServer(); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminBanInfoCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminBanInfoCommand.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminBanInfoCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminBanInfoCommand.java index 6649d8be..f917c6e5 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminBanInfoCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminBanInfoCommand.java @@ -1,11 +1,12 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; import com.destroystokyo.paper.profile.PlayerProfile; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.DateUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.utility.DateUtils; +import com.minersstudios.wholib.paper.utility.MSLogger; +import io.papermc.paper.ban.BanListType; import org.bukkit.BanList; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -14,7 +15,7 @@ import java.util.Date; import java.util.Locale; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class AdminBanInfoCommand { @@ -124,7 +125,7 @@ public static boolean runCommand( } final Date date = Date.from(instant); - final BanList banList = sender.getServer().getBanList(BanList.Type.PROFILE); + final BanList banList = sender.getServer().getBanList(BanListType.PROFILE); final var banEntry = banList.getBanEntry(playerInfo.getPlayerProfile()); playerInfo.setBannedTo(date); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminFirstJoinCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminFirstJoinCommand.java similarity index 79% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminFirstJoinCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminFirstJoinCommand.java index 9e6eb7d4..652073e1 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminFirstJoinCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminFirstJoinCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.DateUtils; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.utility.DateUtils; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminGameParamsCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminGameParamsCommand.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminGameParamsCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminGameParamsCommand.java index fb3fcc9f..f74a9fc1 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminGameParamsCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminGameParamsCommand.java @@ -1,8 +1,8 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; import org.bukkit.GameMode; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -10,7 +10,7 @@ import java.util.Locale; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class AdminGameParamsCommand { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminInfoCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminInfoCommand.java similarity index 84% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminInfoCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminInfoCommand.java index 636940e2..cf4655a3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminInfoCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminInfoCommand.java @@ -1,12 +1,13 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; -import com.minersstudios.whomine.Config; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.PlayerName; -import com.minersstudios.whomine.player.PlayerSettings; +import com.minersstudios.wholib.paper.PaperConfig; +import com.minersstudios.whomine.PaperConfigImpl; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.PlayerName; +import com.minersstudios.wholib.paper.player.PlayerSettings; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -18,7 +19,7 @@ public static boolean runCommand( final @NotNull CommandSender sender, final @NotNull PlayerInfo playerInfo ) { - final Config config = plugin.getConfiguration(); + final PaperConfig config = plugin.getConfiguration(); final PlayerFile playerFile = playerInfo.getPlayerFile(); final PlayerName playerName = playerFile.getPlayerName(); final PlayerSettings playerSettings = playerFile.getPlayerSettings(); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminMuteInfoCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminMuteInfoCommand.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminMuteInfoCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminMuteInfoCommand.java index dd57f446..14821939 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminMuteInfoCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminMuteInfoCommand.java @@ -1,18 +1,18 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.DateUtils; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.collection.MuteMap; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.utility.DateUtils; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.collection.MuteMap; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import java.time.Instant; import java.util.Locale; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class AdminMuteInfoCommand { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminNameCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminNameCommand.java similarity index 93% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminNameCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminNameCommand.java index 46dfedcc..d726b207 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminNameCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminNameCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.PlayerName; -import com.minersstudios.whomine.utility.MSPlayerUtils; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.PlayerName; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.YamlConfiguration; @@ -12,7 +12,7 @@ import java.util.Locale; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class AdminNameCommand { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPlayerCommandHandler.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPlayerCommandHandler.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPlayerCommandHandler.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPlayerCommandHandler.java index c90350cf..6e8a1bc6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPlayerCommandHandler.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPlayerCommandHandler.java @@ -1,14 +1,14 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.collection.IDMap; -import com.minersstudios.whomine.utility.DateUtils; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.utility.IDUtils; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.collection.IDMap; +import com.minersstudios.wholib.paper.utility.DateUtils; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.utility.IDUtils; import com.mojang.brigadier.arguments.DoubleArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; @@ -23,7 +23,7 @@ import java.util.Collections; import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; @@ -216,7 +216,7 @@ public boolean onCommand( return false; } - final WhoMine plugin = this.getPlugin(); + final WhoMine plugin = this.getModule(); final PlayerInfo playerInfo = PlayerInfo.fromString(plugin, args[0]); if (playerInfo == null) { @@ -252,7 +252,7 @@ public boolean onCommand( switch (args.length) { case 1 -> { final var completions = new ObjectArrayList(); - final IDMap idMap = this.getPlugin().getCache().getIdMap(); + final IDMap idMap = this.getModule().getCache().getIdMap(); for (final var offlinePlayer : sender.getServer().getOfflinePlayers()) { final String nickname = offlinePlayer.getName(); @@ -356,7 +356,7 @@ public boolean onCommand( final OfflinePlayer offlinePlayer; if (IDUtils.matchesIDRegex(args[0])) { - final IDMap idMap = this.getPlugin().getCache().getIdMap(); + final IDMap idMap = this.getModule().getCache().getIdMap(); offlinePlayer = idMap.getPlayerByID(args[0]); } else if (args[0].length() > 2) { offlinePlayer = sender.getServer().getOfflinePlayer(args[0]); @@ -364,7 +364,7 @@ public boolean onCommand( return EMPTY_TAB; } - final PlayerInfo playerInfo = PlayerInfo.fromOfflinePlayer(this.getPlugin(), offlinePlayer); + final PlayerInfo playerInfo = PlayerInfo.fromOfflinePlayer(this.getModule(), offlinePlayer); switch (args[3]) { case "set", "remove" -> { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPronounsCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPronounsCommand.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPronounsCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPronounsCommand.java index cf159dc6..b7015f90 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPronounsCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminPronounsCommand.java @@ -1,16 +1,16 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.Pronouns; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.Pronouns; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.Locale; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class AdminPronounsCommand { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminSettingsCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminSettingsCommand.java similarity index 95% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminSettingsCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminSettingsCommand.java index 9a85f425..1201afb8 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminSettingsCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminSettingsCommand.java @@ -1,14 +1,14 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.PlayerSettings; -import com.minersstudios.whomine.player.ResourcePack; -import com.minersstudios.whomine.player.skin.Skin; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.PlayerSettings; +import com.minersstudios.wholib.paper.player.ResourcePack; +import com.minersstudios.wholib.paper.player.skin.Skin; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -16,7 +16,7 @@ import java.util.Arrays; import java.util.Locale; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class AdminSettingsCommand { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminUpdateCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminUpdateCommand.java similarity index 81% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminUpdateCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminUpdateCommand.java index 09fae532..5e5a6090 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminUpdateCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/player/AdminUpdateCommand.java @@ -1,8 +1,8 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.player; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.player.PlayerInfo; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/TeleportToLastDeathLocationCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/TeleportToLastDeathLocationCommand.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/TeleportToLastDeathLocationCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/TeleportToLastDeathLocationCommand.java index cc693357..35e0e068 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/TeleportToLastDeathLocationCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/TeleportToLastDeathLocationCommand.java @@ -1,12 +1,12 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.teleport; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.utility.MSPlayerUtils; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; import com.mojang.brigadier.arguments.StringArgumentType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -15,7 +15,7 @@ import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -57,7 +57,7 @@ public boolean onCommand( return false; } - final PlayerInfo playerInfo = PlayerInfo.fromString(this.getPlugin(), args[0]); + final PlayerInfo playerInfo = PlayerInfo.fromString(this.getModule(), args[0]); if (playerInfo == null) { MSLogger.severe( @@ -99,7 +99,7 @@ public boolean onCommand( final String @NotNull ... args ) { return args.length == 1 - ? MSPlayerUtils.getLocalPlayerNames(this.getPlugin()) + ? MSPlayerUtils.getLocalPlayerNames(this.getModule()) : EMPTY_TAB; } } diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/WorldTeleportCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/WorldTeleportCommand.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/WorldTeleportCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/WorldTeleportCommand.java index 4098864d..c74de495 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/WorldTeleportCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/admin/teleport/WorldTeleportCommand.java @@ -1,12 +1,12 @@ package com.minersstudios.whomine.command.impl.minecraft.admin.teleport; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.utility.MSPlayerUtils; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; import com.mojang.brigadier.arguments.StringArgumentType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.commands.arguments.DimensionArgument; @@ -22,7 +22,7 @@ import java.util.Collections; import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -71,7 +71,7 @@ public boolean onCommand( return false; } - final PlayerInfo playerInfo = PlayerInfo.fromString(this.getPlugin(), args[0]); + final PlayerInfo playerInfo = PlayerInfo.fromString(this.getModule(), args[0]); if (playerInfo == null) { MSLogger.severe( @@ -161,7 +161,7 @@ public boolean onCommand( @NotNull String label, String @NotNull ... args ) { - final WhoMine plugin = this.getPlugin(); + final WhoMine plugin = this.getModule(); return switch (args.length) { case 1 -> MSPlayerUtils.getLocalPlayerNames(plugin); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/GiveCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/GiveCommand.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/GiveCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/GiveCommand.java index 121e5dcb..a17bd773 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/GiveCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/GiveCommand.java @@ -1,15 +1,15 @@ package com.minersstudios.whomine.command.impl.minecraft.block; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.player.PlayerInfo; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class GiveCommand { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/MSBlockCommandHandler.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/MSBlockCommandHandler.java similarity index 91% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/MSBlockCommandHandler.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/MSBlockCommandHandler.java index 93fa3c6d..453ab002 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/MSBlockCommandHandler.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/MSBlockCommandHandler.java @@ -1,11 +1,11 @@ package com.minersstudios.whomine.command.impl.minecraft.block; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.utility.MSPlayerUtils; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -60,8 +60,8 @@ public boolean onCommand( ) { return args.length != 0 && switch (args[0]) { - case "reload" -> ReloadCommand.runCommand(this.getPlugin(), sender); - case "give" -> GiveCommand.runCommand(this.getPlugin(), sender, args); + case "reload" -> ReloadCommand.runCommand(this.getModule(), sender); + case "give" -> GiveCommand.runCommand(this.getModule(), sender, args); default -> false; }; } @@ -77,7 +77,7 @@ && switch (args[0]) { return switch (args.length) { case 1 -> TAB; case 2 -> args[0].equals("give") - ? MSPlayerUtils.getLocalPlayerNames(this.getPlugin()) + ? MSPlayerUtils.getLocalPlayerNames(this.getModule()) : EMPTY_TAB; case 3 -> args[0].equals("give") ? new ObjectArrayList<>(CustomBlockRegistry.keySet()) diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/ReloadCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/ReloadCommand.java similarity index 79% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/ReloadCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/ReloadCommand.java index 45c9082e..bdd0c631 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/ReloadCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/block/ReloadCommand.java @@ -1,9 +1,9 @@ package com.minersstudios.whomine.command.impl.minecraft.block; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/GiveCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/GiveCommand.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/GiveCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/GiveCommand.java index e139a365..bce67db6 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/GiveCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/GiveCommand.java @@ -1,15 +1,15 @@ package com.minersstudios.whomine.command.impl.minecraft.decor; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.decor.CustomDecorData; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorData; +import com.minersstudios.wholib.paper.player.PlayerInfo; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; public final class GiveCommand { diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/MSDecorCommandHandler.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/MSDecorCommandHandler.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/MSDecorCommandHandler.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/MSDecorCommandHandler.java index 211db9b9..330942ca 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/MSDecorCommandHandler.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/decor/MSDecorCommandHandler.java @@ -1,11 +1,11 @@ package com.minersstudios.whomine.command.impl.minecraft.decor; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.custom.decor.CustomDecorType; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.utility.MSPlayerUtils; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorType; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -59,7 +59,7 @@ public boolean onCommand( ) { return args.length != 0 && switch (args[0]) { - case "give" -> GiveCommand.runCommand(this.getPlugin(), sender, args); + case "give" -> GiveCommand.runCommand(this.getModule(), sender, args); default -> false; }; } @@ -74,7 +74,7 @@ && switch (args[0]) { return switch (args.length) { case 1 -> TAB; case 2 -> args[0].equals("give") - ? MSPlayerUtils.getLocalPlayerNames(this.getPlugin()) + ? MSPlayerUtils.getLocalPlayerNames(this.getModule()) : EMPTY_TAB; case 3 -> args[0].equals("give") ? new ObjectArrayList<>(CustomDecorType.keySet()) diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/GiveCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/GiveCommand.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/GiveCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/GiveCommand.java index f04548cd..2285db51 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/GiveCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/GiveCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft.item; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.custom.item.CustomItem; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.custom.item.CustomItem; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/MSItemCommandHandler.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/MSItemCommandHandler.java similarity index 92% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/MSItemCommandHandler.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/MSItemCommandHandler.java index 887e1a70..f1b2d3f7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/MSItemCommandHandler.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/MSItemCommandHandler.java @@ -1,11 +1,11 @@ package com.minersstudios.whomine.command.impl.minecraft.item; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.custom.item.CustomItemType; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.utility.MSPlayerUtils; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -60,8 +60,8 @@ public boolean onCommand( ) { return args.length != 0 && switch (args[0]) { - case "reload" -> ReloadCommand.runCommand(this.getPlugin(), sender); - case "give" -> GiveCommand.runCommand(this.getPlugin(), sender, args); + case "reload" -> ReloadCommand.runCommand(this.getModule(), sender); + case "give" -> GiveCommand.runCommand(this.getModule(), sender, args); default -> false; }; } @@ -76,7 +76,7 @@ && switch (args[0]) { return switch (args.length) { case 1 -> TAB; case 2 -> args[0].equals("give") - ? MSPlayerUtils.getLocalPlayerNames(this.getPlugin()) + ? MSPlayerUtils.getLocalPlayerNames(this.getModule()) : EMPTY_TAB; case 3 -> args[0].equals("give") ? new ObjectArrayList<>(CustomItemType.keySet()) diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/ReloadCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/ReloadCommand.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/ReloadCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/ReloadCommand.java index 26e22a6f..9c229d12 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/ReloadCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/ReloadCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft.item; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.SharedConstants; -import com.minersstudios.whomine.custom.item.renameable.RenameableItemRegistry; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItemRegistry; import org.bukkit.Keyed; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -28,13 +28,13 @@ public static boolean runCommand( if ( recipe instanceof final Keyed keyed - && SharedConstants.MSITEMS_NAMESPACE.equals(keyed.getKey().getNamespace()) + && Resource.WMITEM.equals(keyed.getKey().getNamespace()) ) { server.removeRecipe(keyed.getKey()); } } - plugin.getCache().customItemRecipes.clear(); + plugin.getCache().getCustomItemRecipes().clear(); plugin.getCache().getRenameableMenuItems().clear(); RenameableItemRegistry.unregisterAll(); plugin.getConfiguration().reload(); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/RenamesCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/RenamesCommand.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/RenamesCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/RenamesCommand.java index 0bcb93f4..7304a23b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/RenamesCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/item/RenamesCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft.item; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; import com.minersstudios.whomine.menu.RenamesMenu; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.utility.Font; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/DiscordCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/DiscordCommand.java similarity index 83% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/DiscordCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/DiscordCommand.java index f4cfc296..479f9ca9 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/DiscordCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/DiscordCommand.java @@ -1,15 +1,14 @@ package com.minersstudios.whomine.command.impl.minecraft.player; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.discord.DiscordManager; -import com.minersstudios.whomine.menu.DiscordLinkCodeMenu; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.discord.DiscordManager; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.NamedTextColor; @@ -21,8 +20,8 @@ import java.util.Arrays; import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; -import static com.minersstudios.whomine.utility.SharedConstants.DISCORD_LINK; +import static com.minersstudios.wholib.locale.Translations.*; +import static com.minersstudios.wholib.utility.SharedConstants.DISCORD_LINK; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.event.HoverEvent.showText; @@ -65,12 +64,12 @@ public boolean onCommand( final @NotNull String label, final String @NotNull ... args ) { - final WhoMine plugin = this.getPlugin(); + final WhoMine plugin = this.getModule(); final Player player = (Player) sender; if (args.length > 0) { switch (args[0]) { - case "link" -> plugin.openCustomInventory(DiscordLinkCodeMenu.class, player); + case "link" -> plugin.getGuiManager().open("discord_link_code", player); case "unlink" -> { final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(plugin, player); final long id = playerInfo.unlinkDiscord(); @@ -84,11 +83,11 @@ public boolean onCommand( return true; } - final DiscordManager discordManager = plugin.getDiscordManager(); + final DiscordManager discordModule = plugin.getDiscordModule(); - discordManager.retrieveUser(id) + discordModule.retrieveUser(id) .ifPresent(user -> { - discordManager.sendEmbeds( + discordModule.sendEmbeds( user, BotHandler.craftEmbed( ChatUtils.serializePlainComponent( diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/PrivateMessageCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/PrivateMessageCommand.java similarity index 86% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/PrivateMessageCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/PrivateMessageCommand.java index 30c9abf9..2fb618a0 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/PrivateMessageCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/PrivateMessageCommand.java @@ -1,14 +1,14 @@ package com.minersstudios.whomine.command.impl.minecraft.player; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.utility.MSPlayerUtils; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; import com.mojang.brigadier.arguments.StringArgumentType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -17,7 +17,7 @@ import java.util.List; -import static com.minersstudios.whomine.utility.MessageUtils.sendPrivateMessage; +import static com.minersstudios.wholib.paper.utility.MessageUtils.sendPrivateMessage; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -60,7 +60,7 @@ public boolean onCommand( return false; } - final WhoMine plugin = this.getPlugin(); + final WhoMine plugin = this.getModule(); final PlayerInfo senderInfo = sender instanceof Player player ? PlayerInfo.fromOnlinePlayer(plugin, player) @@ -115,7 +115,7 @@ public boolean onCommand( final String @NotNull ... args ) { return args.length == 1 - ? MSPlayerUtils.getLocalPlayerNames(this.getPlugin()) + ? MSPlayerUtils.getLocalPlayerNames(this.getModule()) : EMPTY_TAB; } } diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/ResourcePackCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/ResourcePackCommand.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/ResourcePackCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/ResourcePackCommand.java index d048102d..21ce9886 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/ResourcePackCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/ResourcePackCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft.player; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; import com.minersstudios.whomine.menu.ResourcePackMenu; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -36,8 +36,8 @@ public boolean onCommand( final @NotNull String label, final String @NotNull ... args ) { - this.getPlugin().openCustomInventory( - ResourcePackMenu.class, + this.getModule().getGuiManager().open( + "resource_pack_choice", (Player) sender ); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/SkinsCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/SkinsCommand.java similarity index 89% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/SkinsCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/SkinsCommand.java index 5c395b7c..37de383f 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/SkinsCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/SkinsCommand.java @@ -1,10 +1,10 @@ package com.minersstudios.whomine.command.impl.minecraft.player; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; import com.minersstudios.whomine.menu.SkinsMenu; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -35,8 +35,8 @@ public boolean onCommand( final @NotNull String label, final String @NotNull ... args ) { - this.getPlugin().openCustomInventory( - SkinsMenu.class, + this.getModule().getGuiManager().open( + "skins_choice", (Player) sender ); diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/DoCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/DoCommand.java similarity index 81% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/DoCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/DoCommand.java index 9f9d390f..feb61703 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/DoCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/DoCommand.java @@ -1,21 +1,21 @@ package com.minersstudios.whomine.command.impl.minecraft.player.roleplay; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.DO; -import static com.minersstudios.whomine.utility.MessageUtils.sendRPEventMessage; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.DO; +import static com.minersstudios.wholib.paper.utility.MessageUtils.sendRPEventMessage; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -51,7 +51,7 @@ public boolean onCommand( } final Player player = (Player) sender; - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getModule(), player); if (playerInfo.isMuted()) { MSLogger.warning( diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/FartCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/FartCommand.java similarity index 76% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/FartCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/FartCommand.java index 846f5d5b..a75b4589 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/FartCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/FartCommand.java @@ -1,16 +1,16 @@ package com.minersstudios.whomine.command.impl.minecraft.player.roleplay; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.custom.decor.CustomDecorType; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.BlockUtils; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorType; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.world.location.MSPosition; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.utility.BlockUtils; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import org.bukkit.*; import org.bukkit.block.BlockFace; @@ -22,9 +22,9 @@ import java.security.SecureRandom; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.ME; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.TODO; -import static com.minersstudios.whomine.utility.MessageUtils.sendRPEventMessage; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.ME; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.TODO; +import static com.minersstudios.wholib.paper.utility.MessageUtils.sendRPEventMessage; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -59,7 +59,7 @@ public boolean onCommand( final String @NotNull ... args ) { final Player player = (Player) sender; - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getModule(), player); if (playerInfo.isMuted()) { MSLogger.warning( @@ -78,19 +78,25 @@ public boolean onCommand( && BlockUtils.isReplaceable(location.clone().getBlock().getType()); for (final var nearbyEntity : world.getNearbyEntities(location.getBlock().getLocation().add(0.5d, 0.5d, 0.5d), 0.5d, 0.5d, 0.5d)) { - if (nearbyEntity.getType() != EntityType.DROPPED_ITEM && nearbyEntity.getType() != EntityType.PLAYER) { + final EntityType entityType = nearbyEntity.getType(); + + if ( + entityType != EntityType.ITEM + && entityType != EntityType.PLAYER + ) { withPoop = false; + break; } } world.playSound(location.add(0, 0.4, 0), Sound.BLOCK_FIRE_EXTINGUISH, SoundCategory.PLAYERS, 1, 1); - world.spawnParticle(Particle.REDSTONE, location, 15, 0.0D, 0.0D, 0.0D, 0.5D, new Particle.DustOptions(Color.fromBGR(33, 54, 75), 10)); + world.spawnParticle(Particle.DUST, location, 15, 0.0D, 0.0D, 0.0D, 0.5D, new Particle.DustOptions(Color.fromBGR(33, 54, 75), 10)); if (withPoop) { CustomDecorType.POOP.getCustomDecorData() .place( - this.getPlugin(), + this.getModule(), MSPosition.of(location.toBlockLocation()), player, BlockFace.UP, diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/ItCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/ItCommand.java similarity index 80% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/ItCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/ItCommand.java index d95ac6e9..93bbf47e 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/ItCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/ItCommand.java @@ -1,21 +1,21 @@ package com.minersstudios.whomine.command.impl.minecraft.player.roleplay; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.IT; -import static com.minersstudios.whomine.utility.MessageUtils.sendRPEventMessage; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.IT; +import static com.minersstudios.wholib.paper.utility.MessageUtils.sendRPEventMessage; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -51,7 +51,7 @@ public boolean onCommand( } final Player player = (Player) sender; - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getModule(), player); if (playerInfo.isMuted()) { MSLogger.warning( diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/MeCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/MeCommand.java similarity index 80% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/MeCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/MeCommand.java index 669ffd56..15d36f86 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/MeCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/MeCommand.java @@ -1,21 +1,21 @@ package com.minersstudios.whomine.command.impl.minecraft.player.roleplay; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.ME; -import static com.minersstudios.whomine.utility.MessageUtils.sendRPEventMessage; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.ME; +import static com.minersstudios.wholib.paper.utility.MessageUtils.sendRPEventMessage; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -51,7 +51,7 @@ public boolean onCommand( } final Player player = (Player) sender; - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getModule(), player); if (playerInfo.isMuted()) { MSLogger.warning( diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SitCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SitCommand.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SitCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SitCommand.java index b9f251df..3815e3f7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SitCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SitCommand.java @@ -1,13 +1,13 @@ package com.minersstudios.whomine.command.impl.minecraft.player.roleplay; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import net.kyori.adventure.text.Component; import org.bukkit.command.Command; @@ -47,7 +47,7 @@ public boolean onCommand( final String @NotNull ... args ) { final Player player = (Player) sender; - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getModule(), player); if (!player.getLocation().subtract(0.0d, 0.2d, 0.0d).getBlock().getType().isSolid()) { MSLogger.warning( diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SpitCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SpitCommand.java similarity index 82% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SpitCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SpitCommand.java index aab0861f..25003e04 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SpitCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/SpitCommand.java @@ -1,13 +1,13 @@ package com.minersstudios.whomine.command.impl.minecraft.player.roleplay; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import org.bukkit.Location; import org.bukkit.Sound; @@ -19,9 +19,9 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.ME; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.TODO; -import static com.minersstudios.whomine.utility.MessageUtils.sendRPEventMessage; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.ME; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.TODO; +import static com.minersstudios.wholib.paper.utility.MessageUtils.sendRPEventMessage; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -55,7 +55,7 @@ public boolean onCommand( final Player player = (Player) sender; final World world = player.getWorld(); final Location location = player.getLocation(); - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getModule(), player); if (playerInfo.isMuted()) { MSLogger.warning( diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TodoCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TodoCommand.java similarity index 84% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TodoCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TodoCommand.java index d2eb8ff0..7cbbf575 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TodoCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TodoCommand.java @@ -1,21 +1,21 @@ package com.minersstudios.whomine.command.impl.minecraft.player.roleplay; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.TODO; -import static com.minersstudios.whomine.utility.MessageUtils.sendRPEventMessage; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.TODO; +import static com.minersstudios.wholib.paper.utility.MessageUtils.sendRPEventMessage; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -61,7 +61,7 @@ public boolean onCommand( } final Player player = (Player) sender; - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getModule(), player); if (playerInfo.isMuted()) { MSLogger.warning( diff --git a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TryCommand.java b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TryCommand.java similarity index 84% rename from paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TryCommand.java rename to platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TryCommand.java index 55760f1f..7e2bd654 100644 --- a/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TryCommand.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/command/impl/minecraft/player/roleplay/TryCommand.java @@ -1,12 +1,12 @@ package com.minersstudios.whomine.command.impl.minecraft.player.roleplay; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.utility.MSLogger; import com.minersstudios.whomine.command.api.PluginCommandExecutor; import com.minersstudios.whomine.command.api.minecraft.CommandData; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; import com.mojang.brigadier.arguments.StringArgumentType; import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.format.NamedTextColor; @@ -17,9 +17,9 @@ import java.security.SecureRandom; -import static com.minersstudios.whomine.locale.Translations.*; -import static com.minersstudios.whomine.utility.MessageUtils.RolePlayActionType.ME; -import static com.minersstudios.whomine.utility.MessageUtils.sendRPEventMessage; +import static com.minersstudios.wholib.locale.Translations.*; +import static com.minersstudios.wholib.paper.utility.MessageUtils.RolePlayActionType.ME; +import static com.minersstudios.wholib.paper.utility.MessageUtils.sendRPEventMessage; import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static net.kyori.adventure.text.Component.text; @@ -63,7 +63,7 @@ public boolean onCommand( } final Player player = (Player) sender; - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), player); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getModule(), player); if (playerInfo.isMuted()) { MSLogger.warning( diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/discord/CommandAutoCompleteInteractionListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/discord/CommandAutoCompleteInteractionListener.java new file mode 100644 index 00000000..9ff0b03c --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/discord/CommandAutoCompleteInteractionListener.java @@ -0,0 +1,18 @@ +package com.minersstudios.whomine.listener.discord; + +import com.minersstudios.wholib.discord.DiscordListener; +import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; +import org.jetbrains.annotations.NotNull; + +public class CommandAutoCompleteInteractionListener extends DiscordListener { + + @Override + public void onCommandAutoCompleteInteraction(final @NotNull CommandAutoCompleteInteractionEvent event) { + //final SlashCommandExecutor executor = + // this.getModule().getCommandManager().getDiscordExecutor(event.getCommandIdLong()); + + //if (executor != null) { + // executor.tabComplete(event); + //} + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/discord/MessageReceivedListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/discord/MessageReceivedListener.java new file mode 100644 index 00000000..59e92940 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/discord/MessageReceivedListener.java @@ -0,0 +1,81 @@ +package com.minersstudios.whomine.listener.discord; + +import com.minersstudios.wholib.discord.DiscordListener; +import com.minersstudios.wholib.utility.Font; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; +import org.jetbrains.annotations.NotNull; + +import static net.kyori.adventure.text.Component.text; + +public final class MessageReceivedListener extends DiscordListener { + + @Override + public void onMessageReceived(final @NotNull MessageReceivedEvent event) { + //final User user = event.getAuthor(); + //final Message message = event.getMessage(); +// + //if ( + // user.isBot() + // || user.isSystem() + //) { + // return; + //} +// + //if ( + // event.isFromGuild() + // && event.getChannel() == this.getModule().getDiscordManager().getGlobalChannel().orElse(null) + //) { + // final Message referencedMessage = message.getReferencedMessage(); + // final String reply = + // referencedMessage != null + // ? replaceReplyPlaceholders(referencedMessage) + // : ""; + // final Component messageComponent = craftComponent(message, reply); +// + // MessageUtils.sendGlobalMessage(messageComponent); + // MSLogger.info(null, messageComponent); + //} else if (event.isFromType(ChannelType.PRIVATE)) { + // final MainModule plugin = this.getModule(); + // final long userID = user.getIdLong(); + // final var handlerMap = plugin.getCache().getBotHandlers(); + // BotHandler handler = handlerMap.get(userID); +// + // if (handler == null) { + // handler = new BotHandler(plugin, event); +// + // handlerMap.put(userID, handler); + // } +// + // handler.handleMessage(message); + //} + } + + private static @NotNull Component craftComponent( + final @NotNull Message message, + final @NotNull String reply + ) { + return Font.Components.DISCORD + .color(NamedTextColor.WHITE) + .append(text(message.getAuthor().getName(), TextColor.color(112, 125, 223))) + .append(text(reply, TextColor.color(152, 162, 249))) + .append(text(" : ", TextColor.color(112, 125, 223))) + .append(text(craftAttachmentString(message), TextColor.color(165, 165, 255))) + .append(text(message.getContentDisplay(), TextColor.color(202, 202, 255))); + } + + private static @NotNull String replaceReplyPlaceholders(final @NotNull Message repliedMessage) { + return " (отвечая на \"" + craftAttachmentString(repliedMessage) + repliedMessage.getContentDisplay() + "\")"; + } + + private static @NotNull String craftAttachmentString(final @NotNull Message message) { + return message.getAttachments().isEmpty() + ? "" + : message.getAttachments().size() > 1 + ? "(вложения) " + : "(вложение) "; + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/discord/SlashCommandInteractionListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/discord/SlashCommandInteractionListener.java new file mode 100644 index 00000000..ddede2cd --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/discord/SlashCommandInteractionListener.java @@ -0,0 +1,18 @@ +package com.minersstudios.whomine.listener.discord; + +import com.minersstudios.wholib.discord.DiscordListener; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import org.jetbrains.annotations.NotNull; + +public final class SlashCommandInteractionListener extends DiscordListener { + + @Override + public void onSlashCommandInteraction(final @NotNull SlashCommandInteractionEvent event) { + //final SlashCommandExecutor executor = + // this.getModule().getCommandManager().getDiscordExecutor(event.getCommandIdLong()); +// + //if (executor != null) { + // executor.execute(event); + //} + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockBreakListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockBreakListener.java similarity index 86% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockBreakListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockBreakListener.java index cc8d088e..c74d8a28 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockBreakListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockBreakListener.java @@ -1,12 +1,15 @@ -package com.minersstudios.whomine.listener.impl.event.block; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.custom.block.params.ToolType; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.BlockUtils; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.whomine.listener.event.block; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.custom.block.params.ToolType; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.BlockUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.core.BlockPos; @@ -28,24 +31,21 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.type.NoteBlock; -import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory; +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; -public final class BlockBreakListener extends EventListener { +@ListenFor(BlockBreakEvent.class) +public final class BlockBreakListener extends PaperEventListener { - public BlockBreakListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler + public void onBlockBreak(final @NotNull PaperEventContainer container) { + final WhoMine module = container.getModule(); + final BlockBreakEvent event = container.getEvent(); - @EventHandler - public void onBlockBreak(final @NotNull BlockBreakEvent event) { final Player player = event.getPlayer(); final ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); final Block block = event.getBlock(); @@ -70,7 +70,7 @@ public void onBlockBreak(final @NotNull BlockBreakEvent event) { if ( gameMode == GameMode.CREATIVE - && this.destroyBlock(serverPlayer, blockPosition) + && this.destroyBlock(module, serverPlayer, blockPosition) ) { customBlockMaterial.getSoundGroup().playBreakSound(blockLocation.toCenterLocation()); } @@ -79,9 +79,8 @@ public void onBlockBreak(final @NotNull BlockBreakEvent event) { customBlockMaterial.getBlockSettings().getTool().getToolType() == ToolType.AXE && gameMode != GameMode.CREATIVE ) { - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 108000, -1, true, false, false)); block.getWorld().dropItemNaturally(blockLocation, customBlockMaterial.craftItemStack()); - this.destroyBlock(serverPlayer, blockPosition); + this.destroyBlock(module, serverPlayer, blockPosition); } return; @@ -92,12 +91,13 @@ public void onBlockBreak(final @NotNull BlockBreakEvent event) { || bottomBlock.getType() == Material.NOTE_BLOCK ) { event.setCancelled(true); - this.destroyBlock(serverPlayer, blockPosition); + this.destroyBlock(module, serverPlayer, blockPosition); } } @SuppressWarnings("DataFlowIssue") private boolean destroyBlock( + final @NotNull WhoMine module, final @NotNull ServerPlayer serverPlayer, final @NotNull BlockPos pos ) { @@ -168,7 +168,7 @@ private boolean destroyBlock( if (packet != null) { serverPlayer.connection.send(packet); } else { - this.getPlugin().getLogger().warning( + module.getLogger().warning( "TileEntity " + tileEntity + " failed to get an update packet!" ); } diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockDamageListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockDamageListener.java similarity index 53% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockDamageListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockDamageListener.java index e7bf68c1..951968ce 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockDamageListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockDamageListener.java @@ -1,30 +1,30 @@ -package com.minersstudios.whomine.listener.impl.event.block; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlock; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.custom.block.event.CustomBlockDamageEvent; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.BlockUtils; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.whomine.listener.event.block; + +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlock; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.custom.block.event.CustomBlockDamageEvent; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.BlockUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.type.NoteBlock; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockDamageEvent; import org.jetbrains.annotations.NotNull; -public final class BlockDamageListener extends EventListener { +@ListenFor(BlockDamageEvent.class) +public final class BlockDamageListener extends PaperEventListener { - public BlockDamageListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler + public void onBlockDamage(final @NotNull PaperEventContainer container) { + final BlockDamageEvent event = container.getEvent(); - @EventHandler - public void onBlockDamage(final @NotNull BlockDamageEvent event) { final Block block = event.getBlock(); final Material blockType = block.getType(); final Location blockLocation = block.getLocation().toCenterLocation(); @@ -42,7 +42,7 @@ public void onBlockDamage(final @NotNull BlockDamageEvent event) { final CustomBlock customBlock = new CustomBlock(block, customBlockData); final CustomBlockDamageEvent damageEvent = new CustomBlockDamageEvent(customBlock, player, event.getItemInHand()); - this.getPlugin().getServer().getPluginManager().callEvent(damageEvent); + container.getModule().getServer().getPluginManager().callEvent(damageEvent); if (!damageEvent.isCancelled()) { customBlockData.getSoundGroup().playHitSound(blockLocation); diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockDropItemListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockDropItemListener.java similarity index 59% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockDropItemListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockDropItemListener.java index 199fdcf0..d6623d76 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockDropItemListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockDropItemListener.java @@ -1,33 +1,32 @@ -package com.minersstudios.whomine.listener.impl.event.block; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.item.renameable.RenameableItemRegistry; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.ChatUtils; +package com.minersstudios.whomine.listener.event.block; + +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItemRegistry; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.utility.ChatUtils; import net.kyori.adventure.text.Component; import org.bukkit.Tag; import org.bukkit.entity.Item; -import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; -public final class BlockDropItemListener extends EventListener { - - public BlockDropItemListener(final @NotNull WhoMine plugin) { - super(plugin); - } +@ListenFor(BlockDropItemEvent.class) +public final class BlockDropItemListener extends PaperEventListener { - @EventHandler - public void onBlockDropItem(final @NotNull BlockDropItemEvent event) { + @CancellableHandler + public void onBlockDropItem(final @NotNull PaperEventContainer container) { + final BlockDropItemEvent event = container.getEvent(); final var items = event.getItems(); if (items.size() != 1) { return; } - final Item entity = items.get(0); + final Item entity = items.getFirst(); final ItemStack item = entity.getItemStack(); if (!Tag.SHULKER_BOXES.isTagged(item.getType())) { diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockExplodeListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockExplodeListener.java similarity index 51% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockExplodeListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockExplodeListener.java index df39f204..64a25ce1 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockExplodeListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockExplodeListener.java @@ -1,24 +1,23 @@ -package com.minersstudios.whomine.listener.impl.event.block; +package com.minersstudios.whomine.listener.event.block; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.listener.api.EventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.data.type.NoteBlock; -import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockExplodeEvent; import org.jetbrains.annotations.NotNull; -public final class BlockExplodeListener extends EventListener { +@ListenFor(BlockExplodeEvent.class) +public final class BlockExplodeListener extends PaperEventListener { - public BlockExplodeListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onBlockExplode(final @NotNull BlockExplodeEvent event) { + @CancellableHandler + public void onBlockExplode(final @NotNull PaperEventContainer container) { + final BlockExplodeEvent event = container.getEvent(); final World world = event.getBlock().getWorld(); for (final var block : event.blockList()) { diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockPistonExtendListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockPistonExtendListener.java new file mode 100644 index 00000000..b40d8e5d --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockPistonExtendListener.java @@ -0,0 +1,27 @@ +package com.minersstudios.whomine.listener.event.block; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.MSDecorUtils; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(BlockPistonExtendEvent.class) +public final class BlockPistonExtendListener extends PaperEventListener { + + @CancellableHandler(order = EventOrder.CUSTOM, ignoreCancelled = true) + public void onBlockPistonExtend(final @NotNull PaperEventContainer container) { + final BlockPistonExtendEvent event = container.getEvent(); + + for (final var block : event.getBlocks()) { + if (MSDecorUtils.isCustomDecorMaterial(block.getType())) { + event.setCancelled(true); + + break; + } + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockPistonRetractListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockPistonRetractListener.java new file mode 100644 index 00000000..dd1d15a9 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockPistonRetractListener.java @@ -0,0 +1,27 @@ +package com.minersstudios.whomine.listener.event.block; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.MSDecorUtils; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(BlockPistonRetractEvent.class) +public final class BlockPistonRetractListener extends PaperEventListener { + + @CancellableHandler(order = EventOrder.CUSTOM, ignoreCancelled = true) + public void onBlockPistonRetract(final @NotNull PaperEventContainer container) { + final BlockPistonRetractEvent event = container.getEvent(); + + for (final var block : event.getBlocks()) { + if (MSDecorUtils.isCustomDecorMaterial(block.getType())) { + event.setCancelled(true); + + break; + } + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockPlaceListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockPlaceListener.java similarity index 52% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockPlaceListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockPlaceListener.java index d6573497..f9879141 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/block/BlockPlaceListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/BlockPlaceListener.java @@ -1,29 +1,28 @@ -package com.minersstudios.whomine.listener.impl.event.block; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlock; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.BlockUtils; -import com.minersstudios.whomine.utility.MSDecorUtils; -import com.minersstudios.whomine.world.sound.SoundGroup; +package com.minersstudios.whomine.listener.event.block; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlock; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.BlockUtils; +import com.minersstudios.wholib.paper.utility.MSDecorUtils; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.block.BlockPlaceEvent; import org.jetbrains.annotations.NotNull; -public final class BlockPlaceListener extends EventListener { - - public BlockPlaceListener(final @NotNull WhoMine plugin) { - super(plugin); - } +@ListenFor(BlockPlaceEvent.class) +public final class BlockPlaceListener extends PaperEventListener { - @EventHandler(priority = EventPriority.MONITOR) - public void onBlockPlace(final @NotNull BlockPlaceEvent event) { + @CancellableHandler(order = EventOrder.CUSTOM) + public void onBlockPlace(final @NotNull PaperEventContainer container) { + final BlockPlaceEvent event = container.getEvent(); final Player player = event.getPlayer(); final Block block = event.getBlockPlaced(); final Material blockType = block.getType(); @@ -54,7 +53,7 @@ public void onBlockPlace(final @NotNull BlockPlaceEvent event) { if (blockType == Material.NOTE_BLOCK) { new CustomBlock(block, CustomBlockData.defaultData()) - .place(this.getPlugin(), player, event.getHand()); + .place(container.getModule(), player, event.getHand()); } } } diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/NotePlayListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/NotePlayListener.java new file mode 100644 index 00000000..d86eb9fa --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/block/NotePlayListener.java @@ -0,0 +1,30 @@ +package com.minersstudios.whomine.listener.event.block; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.params.NoteBlockData; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import org.bukkit.Instrument; +import org.bukkit.Note; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.block.NotePlayEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(NotePlayEvent.class) +public final class NotePlayListener extends PaperEventListener { + private static final Instrument DEFAULT_INSTRUMENT = NoteBlockData.defaultData().instrument(); + private static final Note DEFAULT_NOTE = NoteBlockData.defaultData().note(); + + @CancellableHandler(order = EventOrder.CUSTOM, ignoreCancelled = true) + public void onNotePlay(final @NotNull PaperEventContainer container) { + final NotePlayEvent event = container.getEvent(); + + if ( + !(event.getInstrument() == DEFAULT_INSTRUMENT + && event.getNote().equals(DEFAULT_NOTE)) + ) { + event.setCancelled(true); + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/chat/AsyncChatListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/chat/AsyncChatListener.java similarity index 69% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/chat/AsyncChatListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/chat/AsyncChatListener.java index 2abdea22..dfc97733 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/chat/AsyncChatListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/chat/AsyncChatListener.java @@ -1,37 +1,38 @@ -package com.minersstudios.whomine.listener.impl.event.chat; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.chat.ChatType; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.MessageUtils; +package com.minersstudios.whomine.listener.event.chat; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.chat.ChatType; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.paper.utility.MessageUtils; import io.papermc.paper.event.player.AsyncChatEvent; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.jetbrains.annotations.NotNull; import java.time.Instant; -import static com.minersstudios.whomine.locale.Translations.COMMAND_MUTE_ALREADY_RECEIVER; -import static com.minersstudios.whomine.locale.Translations.WARNING_YOU_CANT_DO_THIS_NOW; +import static com.minersstudios.wholib.locale.Translations.COMMAND_MUTE_ALREADY_RECEIVER; +import static com.minersstudios.wholib.locale.Translations.WARNING_YOU_CANT_DO_THIS_NOW; import static net.kyori.adventure.text.Component.text; -public final class AsyncChatListener extends EventListener { +@ListenFor(AsyncChatEvent.class) +public final class AsyncChatListener extends PaperEventListener { - public AsyncChatListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler(order = EventOrder.LOW, ignoreCancelled = true) + public void onAsyncChat(final @NotNull PaperEventContainer container) { + final AsyncChatEvent event = container.getEvent(); + final WhoMine module = container.getModule(); - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onAsyncChat(final @NotNull AsyncChatEvent event) { event.setCancelled(true); - final WhoMine plugin = this.getPlugin(); final Player player = event.getPlayer(); - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(plugin, player); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(module, player); if ( playerInfo.isInWorldDark() @@ -98,7 +99,7 @@ public void onAsyncChat(final @NotNull AsyncChatEvent event) { } } else { MessageUtils.sendMessageToChat(playerInfo, player.getLocation(), ChatType.LOCAL, text(message)); - plugin.getCache().getChatBuffer().receiveMessage(player, message + " "); + module.getCache().getChatBuffer().receiveMessage(player, message + " "); } } } diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/command/UnknownCommandListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/command/UnknownCommandListener.java new file mode 100644 index 00000000..2036bca7 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/command/UnknownCommandListener.java @@ -0,0 +1,26 @@ +package com.minersstudios.whomine.listener.event.command; + +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.MSLogger; +import org.bukkit.event.command.UnknownCommandEvent; +import org.jetbrains.annotations.NotNull; + +import static com.minersstudios.wholib.locale.Translations.ERROR_UNKNOWN_COMMAND; + +@ListenFor(UnknownCommandEvent.class) +public class UnknownCommandListener extends PaperEventListener { + + @CancellableHandler + public void onUnknownCommand(final @NotNull PaperEventContainer container) { + final UnknownCommandEvent event = container.getEvent(); + + event.message(null); + MSLogger.severe( + event.getSender(), + ERROR_UNKNOWN_COMMAND.asTranslatable() + ); + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityChangeBlockListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityChangeBlockListener.java new file mode 100644 index 00000000..4893c596 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityChangeBlockListener.java @@ -0,0 +1,30 @@ +package com.minersstudios.whomine.listener.event.entity; + +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.MSDecorUtils; +import org.bukkit.block.Block; +import org.bukkit.entity.FallingBlock; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +@ListenFor(EntityChangeBlockEvent.class) +public final class EntityChangeBlockListener extends PaperEventListener { + + @CancellableHandler + public void onEntityChangeBlock(final @NotNull PaperEventContainer container) { + final EntityChangeBlockEvent event = container.getEvent(); + final Block block = event.getBlock(); + + if ( + event.getEntity() instanceof FallingBlock + && MSDecorUtils.isCustomDecor(block) + ) { + event.setCancelled(true); + block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(event.getTo())); + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityDamageByEntityListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityDamageByEntityListener.java similarity index 60% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityDamageByEntityListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityDamageByEntityListener.java index 3a8d7a5e..54516224 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/entity/EntityDamageByEntityListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityDamageByEntityListener.java @@ -1,29 +1,28 @@ -package com.minersstudios.whomine.listener.impl.event.entity; +package com.minersstudios.whomine.listener.event.entity; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.decor.CustomDecor; -import com.minersstudios.whomine.custom.decor.event.CustomDecorClickEvent; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.decor.CustomDecor; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorClickEvent; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.utility.SharedConstants; import org.bukkit.GameMode; import org.bukkit.entity.Interaction; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.jetbrains.annotations.NotNull; -public final class EntityDamageByEntityListener extends EventListener { +@ListenFor(EntityDamageByEntityEvent.class) +public final class EntityDamageByEntityListener extends PaperEventListener { - public EntityDamageByEntityListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onEntityDamageByEntity(final @NotNull EntityDamageByEntityEvent event) { + @CancellableHandler + public void onEntityDamageByEntityNormal(final @NotNull PaperEventContainer container) { if ( - event.getEntity() instanceof final ItemFrame itemFrame + container.getEvent().getEntity() instanceof final ItemFrame itemFrame && itemFrame.getScoreboardTags().contains(SharedConstants.INVISIBLE_ITEM_FRAME_TAG) && !itemFrame.isVisible() ) { @@ -31,8 +30,10 @@ public void onEntityDamageByEntity(final @NotNull EntityDamageByEntityEvent even } } - @EventHandler(priority = EventPriority.MONITOR) - public void onEntityDamageByEntityMonitor(final @NotNull EntityDamageByEntityEvent event) { + @CancellableHandler(order = EventOrder.CUSTOM) + public void onEntityDamageByEntityCustom(final @NotNull PaperEventContainer container) { + final EntityDamageByEntityEvent event = container.getEvent(); + if ( !(event.getDamager() instanceof final Player player) || !(event.getEntity() instanceof final Interaction interaction) @@ -49,6 +50,8 @@ public void onEntityDamageByEntityMonitor(final @NotNull EntityDamageByEntityEve return; } + final WhoMine module = container.getModule(); + if ( ( player.isSneaking() @@ -56,7 +59,7 @@ public void onEntityDamageByEntityMonitor(final @NotNull EntityDamageByEntityEve ) || gameMode == GameMode.CREATIVE ) { - CustomDecor.destroy(this.getPlugin(), player, interaction); + CustomDecor.destroy(module, player, interaction); } else { CustomDecor.fromInteraction(interaction) .ifPresent( @@ -74,7 +77,7 @@ public void onEntityDamageByEntityMonitor(final @NotNull EntityDamageByEntityEve player.getServer().getPluginManager().callEvent(clickEvent); if (!clickEvent.isCancelled()) { - customDecor.getData().doClickAction(this.getPlugin(), clickEvent); + customDecor.getData().doClickAction(module, clickEvent); } } ); diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityDamageListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityDamageListener.java new file mode 100644 index 00000000..b15418ee --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityDamageListener.java @@ -0,0 +1,25 @@ +package com.minersstudios.whomine.listener.event.entity; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(EntityDamageEvent.class) +public final class EntityDamageListener extends PaperEventListener { + + @CancellableHandler(ignoreCancelled = true) + public void onEntityDamage(final @NotNull PaperEventContainer container) { + final EntityDamageEvent event = container.getEvent(); + + if ( + event.getEntity() instanceof Player player + && container.getModule().getCache().getWorldDark().isInWorldDark(player) + ) { + event.setCancelled(true); + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityDismountListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityDismountListener.java new file mode 100644 index 00000000..dbdb7797 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityDismountListener.java @@ -0,0 +1,23 @@ +package com.minersstudios.whomine.listener.event.entity; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.entity.EntityDismountEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(EntityDismountEvent.class) +public final class EntityDismountListener extends PaperEventListener { + + @CancellableHandler + public void onEntityDismount(final @NotNull PaperEventContainer container) { + if (container.getEvent().getEntity() instanceof final Player player) { + PlayerInfo + .fromOnlinePlayer(container.getModule(), player) + .unsetSitting(); + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityExplodeListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityExplodeListener.java new file mode 100644 index 00000000..158f77dc --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/entity/EntityExplodeListener.java @@ -0,0 +1,35 @@ +package com.minersstudios.whomine.listener.event.entity; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import org.bukkit.Material; +import org.bukkit.World; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(EntityExplodeEvent.class) +public final class EntityExplodeListener extends PaperEventListener { + + @CancellableHandler + public void onEntityExplode(final @NotNull PaperEventContainer container) { + final EntityExplodeEvent event = container.getEvent(); + final World world = event.getLocation().getWorld(); + + for (final var block : event.blockList()) { + if (block.getType() == Material.NOTE_BLOCK) { + block.setType(Material.AIR); + world.dropItemNaturally( + block.getLocation(), + CustomBlockRegistry + .fromBlockData(block.getBlockData()) + .orElse(CustomBlockData.defaultData()) + .craftItemStack() + ); + } + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/hanging/HangingBreakByEntityListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/hanging/HangingBreakByEntityListener.java new file mode 100644 index 00000000..a14d04d5 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/hanging/HangingBreakByEntityListener.java @@ -0,0 +1,25 @@ +package com.minersstudios.whomine.listener.event.hanging; + +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.utility.SharedConstants; +import org.bukkit.entity.ItemFrame; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(HangingBreakByEntityEvent.class) +public final class HangingBreakByEntityListener extends PaperEventListener { + + @CancellableHandler + public void onHangingBreakByEntity(final @NotNull PaperEventContainer container) { + if ( + container.getEvent().getEntity() instanceof final ItemFrame itemFrame + && itemFrame.getScoreboardTags().contains(SharedConstants.INVISIBLE_ITEM_FRAME_TAG) + && itemFrame.isVisible() + ) { + itemFrame.removeScoreboardTag(SharedConstants.INVISIBLE_ITEM_FRAME_TAG); + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryClickListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryClickListener.java similarity index 81% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryClickListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryClickListener.java index cb6247b3..d94b755d 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryClickListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryClickListener.java @@ -1,19 +1,21 @@ -package com.minersstudios.whomine.listener.impl.event.inventory; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.custom.item.CustomItem; -import com.minersstudios.whomine.custom.item.Wearable; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.inventory.InventoryButton; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.MSLogger; +package com.minersstudios.whomine.listener.event.inventory; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.custom.item.CustomItem; +import com.minersstudios.wholib.paper.custom.item.Wearable; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.inventory.InventoryButton; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; @@ -27,7 +29,8 @@ import static net.kyori.adventure.text.Component.text; -public final class InventoryClickListener extends EventListener { +@ListenFor(InventoryClickEvent.class) +public final class InventoryClickListener extends PaperEventListener { private static final int HELMET_SLOT = 39; private static final Set IGNORABLE_INVENTORY_TYPES = EnumSet.of( // @@ -46,12 +49,11 @@ public final class InventoryClickListener extends EventListener { // ); - public InventoryClickListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler(order = EventOrder.CUSTOM) + public void onInventoryClick(final @NotNull PaperEventContainer container) { + final InventoryClickEvent event = container.getEvent(); + final WhoMine module = container.getModule(); - @EventHandler(priority = EventPriority.MONITOR) - public void onInventoryClick(final @NotNull InventoryClickEvent event) { final Inventory clickedInventory = event.getClickedInventory(); final ClickType clickType = event.getClick(); final ItemStack currentItem = event.getCurrentItem(); @@ -86,10 +88,9 @@ public void onInventoryClick(final @NotNull InventoryClickEvent event) { } } - final WhoMine plugin = this.getPlugin(); final Player player = (Player) event.getWhoClicked(); - if (plugin.getCache().getWorldDark().isInWorldDark(player)) { + if (module.getCache().getWorldDark().isInWorldDark(player)) { event.setCancelled(true); } @@ -104,7 +105,7 @@ public void onInventoryClick(final @NotNull InventoryClickEvent event) { && !cursorItem.isEmpty() ) { player.setItemOnCursor(null); - plugin.runTask( + module.runTask( () -> player.getInventory().setHelmet(cursorItem) ); } @@ -158,7 +159,7 @@ public void onInventoryClick(final @NotNull InventoryClickEvent event) { return; } - this.getPlugin().runTask(() -> { + module.runTask(() -> { inventory.setHelmet(cursorItem); player.setItemOnCursor(currentItem); }); @@ -176,7 +177,7 @@ public void onInventoryClick(final @NotNull InventoryClickEvent event) { CustomItem.fromItemStack(currentItem, Wearable.class) .ifPresent(w -> { event.setCancelled(true); - this.getPlugin().runTask(() -> { + module.runTask(() -> { inventory.setHelmet(currentItem); currentItem.setAmount(0); }); diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryCloseListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryCloseListener.java new file mode 100644 index 00000000..089ed78b --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryCloseListener.java @@ -0,0 +1,22 @@ +package com.minersstudios.whomine.listener.event.inventory; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(InventoryCloseEvent.class) +public final class InventoryCloseListener extends PaperEventListener { + + @CancellableHandler + public void onInventoryClose(final @NotNull PaperEventContainer container) { + final InventoryCloseEvent event = container.getEvent(); + + if (event.getInventory() instanceof final CustomInventory customInventory) { + customInventory.doCloseAction(event); + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryCreativeListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryCreativeListener.java similarity index 53% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryCreativeListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryCreativeListener.java index 0469a159..32b43d1a 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/InventoryCreativeListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryCreativeListener.java @@ -1,27 +1,27 @@ -package com.minersstudios.whomine.listener.impl.event.inventory; +package com.minersstudios.whomine.listener.event.inventory; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.PlayerUtils; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.PlayerUtils; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.type.NoteBlock; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.inventory.InventoryCreativeEvent; import org.jetbrains.annotations.NotNull; -public final class InventoryCreativeListener extends EventListener { +@ListenFor(InventoryCreativeEvent.class) +public final class InventoryCreativeListener extends PaperEventListener { - public InventoryCreativeListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler(order = EventOrder.CUSTOM) + public void onInventoryCreative(final @NotNull PaperEventContainer container) { + final InventoryCreativeEvent event = container.getEvent(); - @EventHandler(priority = EventPriority.MONITOR) - public void onInventoryCreative(final @NotNull InventoryCreativeEvent event) { if (!event.getClick().isCreativeAction()) { return; } @@ -38,7 +38,7 @@ public void onInventoryCreative(final @NotNull InventoryCreativeEvent event) { } event.setCancelled(true); - this.getPlugin().runTask(() -> + container.getModule().runTask(() -> player.getInventory().setItem( event.getSlot(), CustomBlockRegistry diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryDragListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryDragListener.java new file mode 100644 index 00000000..5a868d0e --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryDragListener.java @@ -0,0 +1,29 @@ +package com.minersstudios.whomine.listener.event.inventory; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(InventoryDragEvent.class) +public final class InventoryDragListener extends PaperEventListener { + + @CancellableHandler(order = EventOrder.CUSTOM) + public void onInventoryDrag(final @NotNull PaperEventContainer container) { + final InventoryDragEvent event = container.getEvent(); + if (!(event.getInventory() instanceof final CustomInventory customInventory)) { + return; + } + + for (final int slot : event.getRawSlots()) { + if (slot >= 0 && slot < customInventory.getSize()) { + event.setCancelled(true); + break; + } + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryOpenListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryOpenListener.java new file mode 100644 index 00000000..44a02f07 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/InventoryOpenListener.java @@ -0,0 +1,22 @@ +package com.minersstudios.whomine.listener.event.inventory; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(InventoryOpenEvent.class) +public final class InventoryOpenListener extends PaperEventListener { + + @CancellableHandler + public void onInventoryOpen(final @NotNull PaperEventContainer container) { + final InventoryOpenEvent event = container.getEvent(); + + if (event.getInventory() instanceof final CustomInventory customInventory) { + customInventory.doOpenAction(event); + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/PrepareAnvilListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/PrepareAnvilListener.java new file mode 100644 index 00000000..9c7b7c65 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/PrepareAnvilListener.java @@ -0,0 +1,91 @@ +package com.minersstudios.whomine.listener.event.inventory; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorData; +import com.minersstudios.wholib.paper.custom.item.CustomItem; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItem; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItemRegistry; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.MSCustomUtils; +import org.bukkit.OfflinePlayer; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.inventory.PrepareAnvilEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PrepareAnvilEvent.class) +public final class PrepareAnvilListener extends PaperEventListener { + + @CancellableHandler + public void onPrepareAnvil(final @NotNull PaperEventContainer container) { + final PrepareAnvilEvent event = container.getEvent(); + final ItemStack resultItem = event.getResult(); + final ItemStack firstItem = event.getInventory().getFirstItem(); + @SuppressWarnings("UnstableApiUsage") + final String renameText = event.getView().getRenameText(); + + if ( + resultItem == null + || firstItem == null + ) { + return; + } + + final RenameableItem renameableItem = RenameableItemRegistry.fromRename(renameText, resultItem).orElse(null); + + if ( + renameableItem != null + && renameableItem.isWhiteListed((OfflinePlayer) event.getViewers().getFirst()) + ) { + final ItemStack renamedItem = renameableItem.craftRenamed(resultItem, renameText); + + if (renamedItem != null) { + event.setResult(renamedItem); + } + } else { + final ItemMeta meta = resultItem.getItemMeta(); + final var custom = MSCustomUtils.getCustom(firstItem).orElse(null); + ItemStack customStack = null; + + switch (custom) { + case null -> { + meta.setCustomModelData(null); + resultItem.setItemMeta(meta); + event.setResult(resultItem); + return; + } + case final CustomBlockData data -> customStack = data.craftItemStack(); + case final CustomItem item -> customStack = item.getItem().clone(); + case final CustomDecorData data -> customStack = data.getItem().clone(); + default -> { + } + } + + assert customStack != null; + + final ItemMeta customMeta = customStack.getItemMeta(); + final PersistentDataContainer dataContainer = meta.getPersistentDataContainer(); + final PersistentDataContainer customDataContainer = customMeta.getPersistentDataContainer(); + + meta.setCustomModelData(customMeta.getCustomModelData()); + meta.lore(customMeta.lore()); + dataContainer.getKeys().forEach(dataContainer::remove); + + for (final var key : customDataContainer.getKeys()) { + final String keyStr = customDataContainer.get(key, PersistentDataType.STRING); + + if (keyStr != null) { + dataContainer.set(key, PersistentDataType.STRING, keyStr); + } + } + + resultItem.setItemMeta(meta); + event.setResult(resultItem); + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/PrepareItemCraftListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/PrepareItemCraftListener.java similarity index 63% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/PrepareItemCraftListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/PrepareItemCraftListener.java index 52bd115f..2905d3b7 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/inventory/PrepareItemCraftListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/inventory/PrepareItemCraftListener.java @@ -1,10 +1,11 @@ -package com.minersstudios.whomine.listener.impl.event.inventory; +package com.minersstudios.whomine.listener.event.inventory; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.ItemUtils; -import org.bukkit.event.EventHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.ItemUtils; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; @@ -12,14 +13,12 @@ import org.jetbrains.annotations.NotNull; @SuppressWarnings("deprecation") -public final class PrepareItemCraftListener extends EventListener { +@ListenFor(PrepareItemCraftEvent.class) +public final class PrepareItemCraftListener extends PaperEventListener { - public PrepareItemCraftListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPrepareItemCraft(final @NotNull PrepareItemCraftEvent event) { + @CancellableHandler + public void onPrepareItemCraft(final @NotNull PaperEventContainer container) { + final PrepareItemCraftEvent event = container.getEvent(); final Recipe recipe = event.getRecipe(); if (recipe == null) { diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/BanSwordMechanic.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/BanSwordMechanic.java new file mode 100644 index 00000000..ec050a44 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/BanSwordMechanic.java @@ -0,0 +1,66 @@ +package com.minersstudios.whomine.listener.event.mechanic; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +public final class BanSwordMechanic { + + @Contract(" -> fail") + private BanSwordMechanic() throws AssertionError { + throw new AssertionError("Parent class"); + } + + @ListenFor(EntityDamageByEntityEvent.class) + public static final class EntityDamageByEntity extends PaperEventListener { + + @CancellableHandler(order = EventOrder.CUSTOM) + public void onEntityDamageByEntity(final @NotNull PaperEventContainer container) { + final EntityDamageByEntityEvent event = container.getEvent(); + + if ( + !(event.getDamager() instanceof final Player damager) + || CustomItemType.fromItemStack(damager.getInventory().getItemInMainHand()) != CustomItemType.BAN_SWORD + ) { + return; + } + + final Entity damagedEntity = event.getEntity(); + event.setCancelled(!damager.isOp() || damagedEntity instanceof Player); + + if (damager.isOp() && damagedEntity instanceof final Player damaged) { + damager.performCommand("ban " + damaged.getName() + " 1000y Вы были поражены великим Бан-Мечём"); + } + } + } + + @ListenFor(InventoryClickEvent.class) + public static final class InventoryClick extends PaperEventListener { + + @CancellableHandler(order = EventOrder.CUSTOM) + public void onInventoryClick(final @NotNull PaperEventContainer container) { + final InventoryClickEvent event = container.getEvent(); + final ItemStack currentItem = event.getCurrentItem(); + + if ( + currentItem == null + || CustomItemType.fromItemStack(currentItem) != CustomItemType.BAN_SWORD + ) { + return; + } + + currentItem.setAmount(0); + event.setCancelled(true); + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/CardBoxMechanic.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/CardBoxMechanic.java new file mode 100644 index 00000000..d3e6e455 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/CardBoxMechanic.java @@ -0,0 +1,141 @@ +package com.minersstudios.whomine.listener.event.mechanic; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.item.CustomItem; +import com.minersstudios.wholib.paper.custom.item.registry.cards.CardsBicycle; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.ItemUtils; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.event.inventory.InventoryMoveItemEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BundleMeta; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public final class CardBoxMechanic { + private static final List CARDS = new ObjectArrayList<>(); + + @Contract(" -> fail") + private CardBoxMechanic() throws AssertionError { + throw new AssertionError("Parent class"); + } + + @ListenFor(InventoryMoveItemEvent.class) + public static final class InventoryMoveItem extends PaperEventListener { + + @CancellableHandler(order = EventOrder.CUSTOM) + public void onInventoryMoveItem(final @NotNull PaperEventContainer container) { + final InventoryMoveItemEvent event = container.getEvent(); + + if (event.getDestination().getType() != InventoryType.SHULKER_BOX) { + return; + } + + CustomItem.fromItemStack(event.getItem()) + .filter(customItem -> customItem instanceof CardsBicycle) + .ifPresent( + c -> event.setCancelled(true) + ); + } + } + + @ListenFor(InventoryDragEvent.class) + public static final class InventoryDrag extends PaperEventListener { + + @CancellableHandler(order = EventOrder.CUSTOM) + public void onInventoryDrag(final @NotNull PaperEventContainer container) { + final InventoryDragEvent event = container.getEvent(); + + if (event.getInventory().getType() != InventoryType.SHULKER_BOX) { + return; + } + + CustomItem.fromItemStack(event.getOldCursor()) + .filter(customItem -> customItem instanceof CardsBicycle) + .ifPresent(c -> event.setCancelled(true)); + } + } + + @ListenFor(InventoryClickEvent.class) + public static final class InventoryClick extends PaperEventListener { + + @CancellableHandler(order = EventOrder.CUSTOM) + public void onInventoryClick(final @NotNull PaperEventContainer container) { + final InventoryClickEvent event = container.getEvent(); + final ItemStack cursorItem = event.getCursor(); + final ItemStack currentItem = event.getCurrentItem(); + final Inventory clickedInventory = event.getClickedInventory(); + + if ( + ( + clickedInventory != null + && clickedInventory.getType() == InventoryType.SHULKER_BOX + && CustomItem.fromItemStack(cursorItem).orElse(null) instanceof CardsBicycle + ) + || ( + event.isShiftClick() + && event.getWhoClicked().getOpenInventory().getType() == InventoryType.SHULKER_BOX + && CustomItem.fromItemStack(currentItem).orElse(null) instanceof CardsBicycle + ) + ) { + event.setCancelled(true); + } + + if ( + currentItem == null + || !event.isRightClick() + ) { + return; + } + + if ( + !cursorItem.getType().isAir() + && CustomItem.fromItemStack(currentItem).orElse(null) instanceof CardsBicycle + ) { + addCardToCardBox(event, currentItem, cursorItem); + } else if ( + !currentItem.getType().isAir() + && CustomItem.fromItemStack(cursorItem).orElse(null) instanceof CardsBicycle + ) { + addCardToCardBox(event, cursorItem, currentItem); + } + } + } + + @SuppressWarnings("UnstableApiUsage") + private static void addCardToCardBox( + final @NotNull InventoryClickEvent event, + final @NotNull ItemStack cardBoxItem, + final @NotNull ItemStack cardItem + ) { + if (CARDS.isEmpty()) { + CARDS.addAll(CardsBicycle.Blue.cardItems()); + CARDS.addAll(CardsBicycle.Red.cardItems()); + } + + if (ItemUtils.isContainsItem(CARDS, cardItem)) { + final BundleMeta bundleMeta = (BundleMeta) cardBoxItem.getItemMeta(); + final var itemStacks = new ObjectArrayList(); + + itemStacks.add(cardItem); + itemStacks.addAll(bundleMeta.getItems()); + + if (itemStacks.size() <= 54) { + bundleMeta.setItems(itemStacks); + cardBoxItem.setItemMeta(bundleMeta); + cardItem.setAmount(0); + } + } + + event.setCancelled(true); + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/CocaineMechanic.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/CocaineMechanic.java new file mode 100644 index 00000000..9db6eb3c --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/CocaineMechanic.java @@ -0,0 +1,44 @@ +package com.minersstudios.whomine.listener.event.mechanic; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.item.CustomItemType; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerItemConsumeEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +public final class CocaineMechanic { + + @Contract(" -> fail") + private CocaineMechanic() throws AssertionError { + throw new AssertionError("Parent class"); + } + + @ListenFor(PlayerItemConsumeEvent.class) + public static final class PlayerItemConsume extends PaperEventListener { + + @CancellableHandler + public void onInventoryClick(final @NotNull PaperEventContainer container) { + final PlayerItemConsumeEvent event = container.getEvent(); + final ItemStack itemStack = event.getItem(); + + if ( + !(itemStack.getItemMeta() instanceof PotionMeta) + || CustomItemType.fromItemStack(itemStack) != CustomItemType.COCAINE + ) { + return; + } + + container.getModule().runTask( + () -> event.getPlayer() + .getInventory() + .getItem(event.getHand()) + .setAmount(0) + ); + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/DamageableItemMechanic.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/DamageableItemMechanic.java new file mode 100644 index 00000000..84ec09e2 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/DamageableItemMechanic.java @@ -0,0 +1,35 @@ +package com.minersstudios.whomine.listener.event.mechanic; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.item.damageable.DamageableItem; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.ItemUtils; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerItemDamageEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +public final class DamageableItemMechanic { + + @Contract(" -> fail") + private DamageableItemMechanic() throws AssertionError { + throw new AssertionError("Parent class"); + } + + @ListenFor(PlayerItemDamageEvent.class) + public static final class PlayerItemDamage extends PaperEventListener { + + @CancellableHandler + public void onPlayerItemDamage(final @NotNull PaperEventContainer container) { + final PlayerItemDamageEvent event = container.getEvent(); + final ItemStack itemStack = event.getItem(); + + if (DamageableItem.fromItemStack(itemStack) != null) { + event.setCancelled(true); + ItemUtils.damageItem(event.getPlayer(), event.getItem(), event.getDamage()); + } + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/DosimeterMechanic.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/DosimeterMechanic.java new file mode 100644 index 00000000..062c70da --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/DosimeterMechanic.java @@ -0,0 +1,338 @@ +package com.minersstudios.whomine.listener.event.mechanic; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.anomaly.Anomaly; +import com.minersstudios.wholib.paper.custom.item.CustomItem; +import com.minersstudios.wholib.paper.custom.item.registry.Dosimeter; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.*; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import static net.kyori.adventure.text.Component.text; + +public final class DosimeterMechanic { + + @Contract(" -> fail") + private DosimeterMechanic() throws AssertionError { + throw new AssertionError("Parent class"); + } + + @ListenFor(PlayerSwapHandItemsEvent.class) + public static final class PlayerSwapHandItems extends PaperEventListener { + + @CancellableHandler + public void onPlayerSwapHandItems(final @NotNull PaperEventContainer container) { + final PlayerSwapHandItemsEvent event = container.getEvent(); + final Player player = event.getPlayer(); + final var players = container.getModule().getCache().getDosimeterPlayers(); + final EquipmentSlot equipmentSlot = players.get(player); + + if (equipmentSlot != null) { + players.put( + player, + equipmentSlot == EquipmentSlot.HAND + ? EquipmentSlot.OFF_HAND + : EquipmentSlot.HAND + ); + } + } + } + + @ListenFor(PlayerItemHeldEvent.class) + public static final class PlayerItemHeld extends PaperEventListener { + + @CancellableHandler + public void onPlayerItemHeld(final @NotNull PaperEventContainer container) { + final PlayerItemHeldEvent event = container.getEvent(); + final Player player = event.getPlayer(); + final var players = container.getModule().getCache().getDosimeterPlayers(); + final EquipmentSlot equipmentSlot = players.get(player); + + if (equipmentSlot == EquipmentSlot.HAND) { + final ItemStack dosimeterItem = player.getInventory().getItem(event.getPreviousSlot()); + + CustomItem.fromItemStack(dosimeterItem, Dosimeter.class).ifPresent(dosimeter -> { + final Dosimeter copy = dosimeter.copy(); + + assert dosimeterItem != null; + + copy.setItem(dosimeterItem); + copy.setEnabled(false); + players.remove(player); + }); + } + } + } + + @ListenFor(InventoryClickEvent.class) + public static final class InventoryClick extends PaperEventListener { + + @CancellableHandler + public void onInventoryClick(final @NotNull PaperEventContainer container) { + final InventoryClickEvent event = container.getEvent(); + final WhoMine module = container.getModule(); + + final Player player = (Player) event.getWhoClicked(); + final Inventory inventory = event.getClickedInventory(); + final ClickType clickType = event.getClick(); + + if (!(inventory instanceof final PlayerInventory playerInventory)) { + return; + } + + final var players = module.getCache().getDosimeterPlayers(); + final EquipmentSlot equipmentSlot = players.get(player); + + if (equipmentSlot == null) { + return; + } + + final ItemStack dosimeterItem = playerInventory.getItem(equipmentSlot); + + CustomItem.fromItemStack(dosimeterItem, Dosimeter.class) + .ifPresent(dosimeter -> { + final Dosimeter copy = dosimeter.copy(); + final EquipmentSlot newEquipmentSlot = equipmentSlot == EquipmentSlot.HAND ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND; + + if ( + clickType.isShiftClick() + || (clickType == ClickType.SWAP_OFFHAND + && equipmentSlot == EquipmentSlot.OFF_HAND + && event.getSlot() != playerInventory.getHeldItemSlot()) + ) { + copy.setItem(clickType.isShiftClick() ? Objects.requireNonNull(event.getCurrentItem()) : dosimeterItem); + copy.setEnabled(false); + players.remove(player); + + return; + } + + module.runTask(() -> { + if (dosimeterItem.equals(playerInventory.getItem(newEquipmentSlot))) { + players.put(player, newEquipmentSlot); + } else if (!dosimeterItem.equals(playerInventory.getItem(equipmentSlot))) { + copy.setItem( + clickType.isKeyboardClick() + ? dosimeterItem + : Objects.requireNonNull(event.getCursor()) + ); + copy.setEnabled(false); + players.remove(player); + } + }); + }); + } + } + + @ListenFor(PlayerDropItemEvent.class) + public static final class PlayerDropItem extends PaperEventListener { + + @CancellableHandler + public void onPlayerDropItem(final @NotNull PaperEventContainer container) { + final PlayerDropItemEvent event = container.getEvent(); + final Player player = event.getPlayer(); + final var players = container.getModule().getCache().getDosimeterPlayers(); + final EquipmentSlot equipmentSlot = players.get(player); + + if (equipmentSlot != null) { + final ItemStack drop = event.getItemDrop().getItemStack(); + final ItemStack itemStack = player.getInventory().getItem(equipmentSlot); + + CustomItem.fromItemStack(itemStack, Dosimeter.class) + .ifPresent(dosimeter -> { + if (CustomItem.fromItemStack(drop, Dosimeter.class).isEmpty()) { + return; + } + + final Dosimeter copy = dosimeter.copy(); + + copy.setItem(drop); + copy.setEnabled(false); + players.remove(player); + }); + } + } + } + + @ListenFor(PlayerQuitEvent.class) + public static final class PlayerQuit extends PaperEventListener { + + @CancellableHandler + public void onPlayerQuit(final @NotNull PaperEventContainer container) { + final PlayerQuitEvent event = container.getEvent(); + final Player player = event.getPlayer(); + final EquipmentSlot equipmentSlot = container.getModule().getCache().getDosimeterPlayers().remove(player); + + if (equipmentSlot != null) { + final ItemStack itemStack = player.getInventory().getItem(equipmentSlot); + + CustomItem.fromItemStack(itemStack, Dosimeter.class) + .ifPresent(dosimeter -> { + final Dosimeter copy = dosimeter.copy(); + + copy.setItem(itemStack); + copy.setEnabled(false); + }); + } + } + } + + @ListenFor(PlayerInteractEvent.class) + public static final class PlayerInteract extends PaperEventListener { + + @CancellableHandler + public void onPlayerInteract(final @NotNull PaperEventContainer container) { + final PlayerInteractEvent event = container.getEvent(); + + if (!event.getAction().isRightClick()) { + return; + } + + final Player player = event.getPlayer(); + final EquipmentSlot hand = event.getHand(); + + if ( + hand == null + || !hand.isHand() + ) { + return; + } + + final ItemStack itemInHand = player.getInventory().getItem(hand); + + CustomItem.fromItemStack(itemInHand, Dosimeter.class) + .ifPresent(dosimeter -> { + final var dosimeterPlayers = container.getModule().getCache().getDosimeterPlayers(); + final Dosimeter copy = dosimeter.copy(); + + event.setCancelled(true); + copy.setItem(itemInHand); + copy.setEnabled(!copy.isEnabled()); + + if (copy.isEnabled()) { + dosimeterPlayers.put(player, hand); + } else { + dosimeterPlayers.remove(player, hand); + } + }); + } + } + + public static class DosimeterTask { + private final WhoMine module; + private final Map players; + + public DosimeterTask(final @NotNull WhoMine module) { + this.module = module; + this.players = module.getCache().getDosimeterPlayers(); + } + + public void run() { + if (this.players.isEmpty()) { + return; + } + + this.players + .forEach((player, equipmentSlot) -> { + if (!player.isOnline()) { + return; + } + + final ItemStack itemStack = player.getInventory().getItem(equipmentSlot); + + if (CustomItem.fromItemStack(itemStack).orElse(null) instanceof final Dosimeter dosimeter) { + final Dosimeter copy = dosimeter.copy(); + + copy.setItem(itemStack); + + if (copy.isEnabled()) { + final var radiiPlayerInside = new Object2DoubleOpenHashMap(); + + for (final var anomaly : this.module.getCache().getAnomalies().values()) { + final double radiusInside = anomaly.getBoundingBox().getRadiusInside(player); + + if (radiusInside != -1.0d) { + radiiPlayerInside.put(anomaly, radiusInside); + } + } + + final var anomalyEntry = getEntryWithMinValue(radiiPlayerInside); + final List radii = + anomalyEntry == null + ? Collections.emptyList() + : anomalyEntry.getKey().getBoundingBox().getRadii(); + final Double radius = + anomalyEntry == null + ? null + : anomalyEntry.getValue(); + + copy.setItem(itemStack); + copy.setScreenTypeByRadius(radii, radius); + player.sendActionBar( + text("Уровень радиации : ") + .append(text(radiusToLevel(radii, radius, player.getLocation()))) + .append(text(" мк3в/ч")) + ); + + return; + } + } + + this.players.remove(player); + }); + } + + private static @NotNull String radiusToLevel( + final @NotNull List radii, + final @Nullable Double radius, + final @NotNull Location loc + ) { + final var reversedRadii = new ObjectArrayList<>(radii); + + Collections.reverse(reversedRadii); + + final double indexOfRadius = reversedRadii.indexOf(radius); + final double afterComma = Math.round(((Math.abs(loc.getX()) + Math.abs(loc.getY()) + Math.abs(loc.getZ())) % 1.0d) * 10.0d) / 10.0d; + + return (indexOfRadius == -1.0d ? 0.0d : indexOfRadius + 1.0d) + + Math.min(afterComma, 0.9d) + + String.valueOf(Math.min(Math.round(Math.random() * 10.0d), 9)); + } + + private static @Nullable Map.Entry getEntryWithMinValue(final @NotNull Map map) { + Map.Entry minEntry = null; + double minValue = Double.POSITIVE_INFINITY; + + for (final var entry : map.entrySet()) { + final double value = entry.getValue(); + + if (value < minValue) { + minValue = value; + minEntry = entry; + } + } + + return minEntry; + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/PoopMechanic.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/PoopMechanic.java new file mode 100644 index 00000000..af1c4b2d --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/mechanic/PoopMechanic.java @@ -0,0 +1,74 @@ +package com.minersstudios.whomine.listener.event.mechanic; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorType; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.data.Levelled; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +public final class PoopMechanic { + + @Contract(" -> fail") + private PoopMechanic() throws AssertionError { + throw new AssertionError("Parent class"); + } + + @ListenFor(PlayerInteractEvent.class) + public static final class PlayerInteract extends PaperEventListener { + + @CancellableHandler + public void onPlayerInteract(final @NotNull PaperEventContainer container) { + final PlayerInteractEvent event = container.getEvent(); + + if ( + event.getClickedBlock() == null + || event.getHand() == null + || event.getAction().isLeftClick() + ) { + return; + } + + final Block clickedBlock = event.getClickedBlock(); + + if (clickedBlock.getType() != Material.COMPOSTER) { + return; + } + + final Player player = event.getPlayer(); + final EquipmentSlot hand = event.getHand(); + final ItemStack itemInHand = player.getInventory().getItem(hand); + final GameMode gameMode = player.getGameMode(); + final Material handType = itemInHand.getType(); + + if ( + gameMode != GameMode.SPECTATOR + && !player.isSneaking() + && clickedBlock.getBlockData() instanceof final Levelled levelled + && ( + !handType.isBlock() + || handType == Material.AIR + ) + && levelled.getLevel() < levelled.getMaximumLevel() + && CustomDecorType.fromItemStack(itemInHand) == CustomDecorType.POOP + ) { + levelled.setLevel(levelled.getLevel() + 1); + clickedBlock.setBlockData(levelled); + player.swingHand(hand); + + if (gameMode != GameMode.CREATIVE) { + itemInHand.setAmount(itemInHand.getAmount() - 1); + } + } + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/AsyncPlayerPreLoginListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/AsyncPlayerPreLoginListener.java similarity index 74% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/AsyncPlayerPreLoginListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/AsyncPlayerPreLoginListener.java index 749e2445..e79c99b4 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/AsyncPlayerPreLoginListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/AsyncPlayerPreLoginListener.java @@ -1,26 +1,29 @@ -package com.minersstudios.whomine.listener.impl.event.player; +package com.minersstudios.whomine.listener.event.player; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.locale.TranslationRegistry; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.MSLogger; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.locale.TranslationRegistry; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.utility.MSLogger; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.TextDecoration; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; import static org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result.*; -public final class AsyncPlayerPreLoginListener extends EventListener { +@ListenFor(AsyncPlayerPreLoginEvent.class) +public final class AsyncPlayerPreLoginListener extends PaperEventListener { // private static final Style TITLE_STYLE = Style.style(NamedTextColor.RED, TextDecoration.BOLD); private static final Style SUBTITLE_STYLE = Style.style(NamedTextColor.GRAY); @@ -50,15 +53,13 @@ public final class AsyncPlayerPreLoginListener extends EventListener { ); // - public AsyncPlayerPreLoginListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler(order = EventOrder.CUSTOM, ignoreCancelled = true) + public void onAsyncPlayerPreLogin(final @NotNull PaperEventContainer container) { + final AsyncPlayerPreLoginEvent event = container.getEvent(); + final WhoMine module = container.getModule(); - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onAsyncPlayerPreLogin(final @NotNull AsyncPlayerPreLoginEvent event) { final String nickname = event.getName(); - final WhoMine plugin = this.getPlugin(); - final PlayerInfo playerInfo = PlayerInfo.fromProfile(plugin, event.getUniqueId(), nickname); + final PlayerInfo playerInfo = PlayerInfo.fromProfile(module, event.getUniqueId(), nickname); if (!playerInfo.isWhiteListed()) { event.disallow( @@ -76,13 +77,13 @@ public void onAsyncPlayerPreLogin(final @NotNull AsyncPlayerPreLoginEvent event) ) ) ); - } else if (!plugin.isFullyLoaded()) { + } else if (!module.isFullyLoaded()) { event.disallow( KICK_OTHER, MESSAGE_SERVER_NOT_FULLY_LOADED ); } else if ( - plugin.getConfiguration().isDeveloperMode() + module.getConfiguration().isDeveloperMode() && !playerInfo.getOfflinePlayer().isOp() ) { event.disallow( diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerAdvancementDoneListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerAdvancementDoneListener.java similarity index 65% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerAdvancementDoneListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerAdvancementDoneListener.java index 82cd8b83..8c11bb13 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerAdvancementDoneListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerAdvancementDoneListener.java @@ -1,13 +1,14 @@ -package com.minersstudios.whomine.listener.impl.event.player; +package com.minersstudios.whomine.listener.event.player; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.player.PlayerInfo; import io.papermc.paper.advancement.AdvancementDisplay; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.event.EventHandler; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.player.PlayerAdvancementDoneEvent; import org.jetbrains.annotations.NotNull; @@ -15,14 +16,12 @@ import static net.kyori.adventure.text.Component.*; -public final class PlayerAdvancementDoneListener extends EventListener { +@ListenFor(PlayerAdvancementDoneEvent.class) +public final class PlayerAdvancementDoneListener extends PaperEventListener { - public PlayerAdvancementDoneListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler - public void onPlayerAdvancementDone(final @NotNull PlayerAdvancementDoneEvent event) { + @CancellableHandler + public void onPlayerAdvancementDone(final @NotNull PaperEventContainer container) { + final PlayerAdvancementDoneEvent event = container.getEvent(); final AdvancementDisplay advancementDisplay = event.getAdvancement().getDisplay(); if ( @@ -33,7 +32,7 @@ public void onPlayerAdvancementDone(final @NotNull PlayerAdvancementDoneEvent ev } final AdvancementDisplay.Frame frame = advancementDisplay.frame(); - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), event.getPlayer()); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(container.getModule(), event.getPlayer()); final Component title = advancementDisplay.title(); final Component description = advancementDisplay.description(); diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerBucketEmptyListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerBucketEmptyListener.java new file mode 100644 index 00000000..ccf46b00 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerBucketEmptyListener.java @@ -0,0 +1,34 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.MSDecorUtils; +import org.bukkit.Material; +import org.bukkit.block.Block; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerBucketEmptyEvent.class) +public final class PlayerBucketEmptyListener extends PaperEventListener { + + @CancellableHandler(order = EventOrder.CUSTOM, ignoreCancelled = true) + public void onPlayerBucketEmpty(final @NotNull PaperEventContainer container) { + final PlayerBucketEmptyEvent event = container.getEvent(); + final Block block = event.getBlock(); + + if ( + block.getType() == Material.NOTE_BLOCK + || CustomBlockRegistry.isCustomBlock(event.getPlayer().getInventory().getItemInMainHand()) + || ( + event.getBucket() == Material.LAVA_BUCKET + && MSDecorUtils.isCustomDecor(block) + ) + ) { + event.setCancelled(true); + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerChangedWorldListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerChangedWorldListener.java new file mode 100644 index 00000000..c3f586b7 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerChangedWorldListener.java @@ -0,0 +1,21 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.MSPlayerUtils; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerChangedWorldEvent.class) +public final class PlayerChangedWorldListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerChangedWorld(final @NotNull PaperEventContainer container) { + MSPlayerUtils.hideNameTag( + container.getModule(), + container.getEvent().getPlayer() + ); + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerCommandPreprocessListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerCommandPreprocessListener.java new file mode 100644 index 00000000..88ee6e6e --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerCommandPreprocessListener.java @@ -0,0 +1,39 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.utility.MSLogger; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerCommandPreprocessEvent.class) +public final class PlayerCommandPreprocessListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerCommandPreprocess(final @NotNull PaperEventContainer container) { + final PlayerCommandPreprocessEvent event = container.getEvent(); + final Player player = event.getPlayer(); + final String message = event.getMessage(); + + if ( + ( + message.startsWith("/l") + && !message.startsWith("/logout") + ) + || message.startsWith("/reg") + || !container.getModule().getCache().getWorldDark().isInWorldDark(player) + ) { + return; + } + + event.setCancelled(true); + MSLogger.warning( + player, + Translations.WARNING_YOU_CANT_DO_THIS_NOW.asTranslatable() + ); + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerDeathListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerDeathListener.java new file mode 100644 index 00000000..06e251f5 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerDeathListener.java @@ -0,0 +1,33 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.utility.MessageUtils; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerDeathEvent.class) +public final class PlayerDeathListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerDeath(final @NotNull PaperEventContainer container) { + final PlayerDeathEvent event = container.getEvent(); + final WhoMine module = container.getModule(); + + final Player player = event.getEntity(); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(module, player); + final PaperCache cache = module.getCache(); + + cache.getDiggingMap().removeAll(player); + cache.getStepMap().put(player, 0.0d); + event.deathMessage(null); + playerInfo.unsetSitting(); + MessageUtils.sendDeathMessage(player, player.getKiller()); + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerDropItemListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerDropItemListener.java new file mode 100644 index 00000000..858c8a1b --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerDropItemListener.java @@ -0,0 +1,21 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerDropItemEvent.class) +public final class PlayerDropItemListener extends PaperEventListener { + + @CancellableHandler(ignoreCancelled = true) + public void onPlayerDropItem(final @NotNull PaperEventContainer container) { + final PlayerDropItemEvent event = container.getEvent(); + + if (container.getModule().getCache().getWorldDark().isInWorldDark(event.getPlayer())) { + event.setCancelled(true); + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerEditBookListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerEditBookListener.java similarity index 55% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerEditBookListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerEditBookListener.java index 5363ffb2..927c7c14 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerEditBookListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerEditBookListener.java @@ -1,29 +1,29 @@ -package com.minersstudios.whomine.listener.impl.event.player; +package com.minersstudios.whomine.listener.event.player; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.player.PlayerInfo; -import org.bukkit.event.EventHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.player.PlayerEditBookEvent; import org.bukkit.inventory.meta.BookMeta; import org.jetbrains.annotations.NotNull; import static net.kyori.adventure.text.Component.text; -public final class PlayerEditBookListener extends EventListener { +@ListenFor(PlayerEditBookEvent.class) +public final class PlayerEditBookListener extends PaperEventListener { - public PlayerEditBookListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler + public void onPlayerEditBook(final @NotNull PaperEventContainer container) { + final PlayerEditBookEvent event = container.getEvent(); - @EventHandler - public void onPlayerEditBook(final @NotNull PlayerEditBookEvent event) { if (!event.isSigning()) { return; } - final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), event.getPlayer()); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(container.getModule(), event.getPlayer()); final BookMeta bookMeta = event.getNewBookMeta(); final String title = bookMeta.getTitle(); final boolean isAnon = diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerGameModeChangeListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerGameModeChangeListener.java new file mode 100644 index 00000000..274a85bc --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerGameModeChangeListener.java @@ -0,0 +1,17 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerGameModeChangeEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerGameModeChangeEvent.class) +public final class PlayerGameModeChangeListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerGameModeChange(final @NotNull PaperEventContainer container) { + container.getModule().getCache().getDiggingMap().removeAll(container.getEvent().getPlayer()); + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerInteractAtEntityListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerInteractAtEntityListener.java similarity index 54% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerInteractAtEntityListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerInteractAtEntityListener.java index e25cad2a..ad281145 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerInteractAtEntityListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerInteractAtEntityListener.java @@ -1,22 +1,22 @@ -package com.minersstudios.whomine.listener.impl.event.player; +package com.minersstudios.whomine.listener.event.player; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.decor.CustomDecor; -import com.minersstudios.whomine.custom.decor.event.CustomDecorClickEvent; -import com.minersstudios.whomine.listener.api.EventListener; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.decor.CustomDecor; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorClickEvent; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; import org.bukkit.entity.Interaction; -import org.bukkit.event.EventHandler; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.jetbrains.annotations.NotNull; -public final class PlayerInteractAtEntityListener extends EventListener { +@ListenFor(PlayerInteractAtEntityEvent.class) +public final class PlayerInteractAtEntityListener extends PaperEventListener { - public PlayerInteractAtEntityListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler + public void onPlayerInteractAtEntity(final @NotNull PaperEventContainer container) { + final PlayerInteractAtEntityEvent event = container.getEvent(); - @EventHandler - public void onPlayerInteractAtEntity(final @NotNull PlayerInteractAtEntityEvent event) { if (!(event.getRightClicked() instanceof final Interaction interaction)) { return; } @@ -37,7 +37,7 @@ public void onPlayerInteractAtEntity(final @NotNull PlayerInteractAtEntityEvent interaction.getServer().getPluginManager().callEvent(clickEvent); if (!clickEvent.isCancelled()) { - customDecor.getData().doClickAction(this.getPlugin(), clickEvent); + customDecor.getData().doClickAction(container.getModule(), clickEvent); } } ); diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerInteractEntityListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerInteractEntityListener.java similarity index 75% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerInteractEntityListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerInteractEntityListener.java index e8059949..31cfd903 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerInteractEntityListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerInteractEntityListener.java @@ -1,36 +1,35 @@ -package com.minersstudios.whomine.listener.impl.event.player; +package com.minersstudios.whomine.listener.event.player; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.utility.MessageUtils; -import com.minersstudios.whomine.utility.SharedConstants; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.utility.MessageUtils; +import com.minersstudios.wholib.utility.SharedConstants; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.SoundCategory; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import java.security.SecureRandom; -public final class PlayerInteractEntityListener extends EventListener { +@ListenFor(PlayerInteractEntityEvent.class) +public final class PlayerInteractEntityListener extends PaperEventListener { private final SecureRandom random = new SecureRandom(); - public PlayerInteractEntityListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerInteractEntity(final @NotNull PlayerInteractEntityEvent event) { + @CancellableHandler(order = EventOrder.CUSTOM, ignoreCancelled = true) + public void onPlayerInteractEntity(final @NotNull PaperEventContainer container) { + final PlayerInteractEntityEvent event = container.getEvent(); final Player whoClicked = event.getPlayer(); if (event.getRightClicked() instanceof final Player clickedPlayer) { - final PlayerInfo clickedInfo = PlayerInfo.fromOnlinePlayer(this.getPlugin(), clickedPlayer); + final PlayerInfo clickedInfo = PlayerInfo.fromOnlinePlayer(container.getModule(), clickedPlayer); final ItemStack helmet = clickedPlayer.getInventory().getHelmet(); final float pitch = whoClicked.getEyeLocation().getPitch(); @@ -62,7 +61,7 @@ public void onPlayerInteractEntity(final @NotNull PlayerInteractEntityEvent even if (passengers.isEmpty()) { clickedPlayer.addPassenger(whoClicked); } else { - passengers.get(passengers.size() - 1).addPassenger(whoClicked); + passengers.getLast().addPassenger(whoClicked); } } } else if (event.getRightClicked() instanceof final ItemFrame itemFrame) { diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerInteractListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerInteractListener.java similarity index 88% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerInteractListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerInteractListener.java index c9161eb0..fefee809 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerInteractListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerInteractListener.java @@ -1,19 +1,26 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlock; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.custom.block.event.CustomBlockRightClickEvent; -import com.minersstudios.whomine.custom.block.params.BlockSettings; -import com.minersstudios.whomine.custom.block.params.PlacingType; -import com.minersstudios.whomine.custom.block.params.settings.Placing; -import com.minersstudios.whomine.custom.decor.CustomDecor; -import com.minersstudios.whomine.custom.decor.CustomDecorData; -import com.minersstudios.whomine.custom.decor.event.CustomDecorClickEvent; -import com.minersstudios.whomine.listener.api.EventListener; +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlock; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.custom.block.event.CustomBlockRightClickEvent; +import com.minersstudios.wholib.paper.custom.block.params.BlockSettings; +import com.minersstudios.wholib.paper.custom.block.params.PlacingType; +import com.minersstudios.wholib.paper.custom.block.params.settings.Placing; +import com.minersstudios.wholib.paper.custom.decor.CustomDecor; +import com.minersstudios.wholib.paper.custom.decor.CustomDecorData; +import com.minersstudios.wholib.paper.custom.decor.event.CustomDecorClickEvent; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.BlockUtils; +import com.minersstudios.wholib.paper.utility.CoreProtectUtils; +import com.minersstudios.wholib.paper.utility.MSDecorUtils; +import com.minersstudios.wholib.paper.utility.PlayerUtils; import com.minersstudios.whomine.utility.*; -import com.minersstudios.whomine.world.location.MSPosition; +import com.minersstudios.wholib.paper.world.location.MSPosition; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; @@ -27,12 +34,11 @@ import org.bukkit.block.data.*; import org.bukkit.block.data.type.NoteBlock; import org.bukkit.block.data.type.Slab; -import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; @@ -47,7 +53,8 @@ import java.util.Set; import java.util.UUID; -public final class PlayerInteractListener extends EventListener { +@ListenFor(PlayerInteractEvent.class) +public final class PlayerInteractListener extends PaperEventListener { private static final BlockFace[] FACES = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; private static final Set IGNORABLE_MATERIALS = EnumSet.of( // @@ -141,12 +148,9 @@ public final class PlayerInteractListener extends EventListener { ); private static final Set HAND_HANDLER = new ObjectOpenHashSet<>(); - public PlayerInteractListener(final @NotNull WhoMine plugin) { - super(plugin); - } - - @EventHandler(ignoreCancelled = true) - public void onDecorPlayerInteract(final @NotNull PlayerInteractEvent event) { + @CancellableHandler(ignoreCancelled = true) + public void onDecorPlayerInteract(final @NotNull PaperEventContainer container) { + final PlayerInteractEvent event = container.getEvent(); final Block block = event.getClickedBlock(); final EquipmentSlot hand = event.getHand(); @@ -157,7 +161,7 @@ public void onDecorPlayerInteract(final @NotNull PlayerInteractEvent event) { return; } - final WhoMine plugin = this.getPlugin(); + final WhoMine module = container.getModule(); final Player player = event.getPlayer(); final Material blockType = block.getType(); final GameMode gameMode = player.getGameMode(); @@ -176,13 +180,13 @@ public void onDecorPlayerInteract(final @NotNull PlayerInteractEvent event) { ) || gameMode == GameMode.CREATIVE ) { - CustomDecor.destroyInBlock(plugin, player, block); + CustomDecor.destroyInBlock(module, player, block); } else { final Location interactedLocation = event.getInteractionPoint(); if (interactedLocation != null) { callDecorClickEvent( - plugin, + module, player, block, hand, @@ -225,7 +229,7 @@ && isDoneForMainHand(player) if (interactedLocation != null) { callDecorClickEvent( - plugin, + module, player, block, hand, @@ -250,7 +254,7 @@ && isDoneForMainHand(player) CustomDecorData.fromItemStack(itemInHand) .ifPresent(data -> { data.place( - plugin, + module, MSPosition.of( BlockUtils.isReplaceable(blockType) ? block.getLocation() @@ -268,8 +272,9 @@ && isDoneForMainHand(player) } } - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerInteract(final @NotNull PlayerInteractEvent event) { + @CancellableHandler(order = EventOrder.CUSTOM, ignoreCancelled = true) + public void onPlayerInteract(final @NotNull PaperEventContainer container) { + final PlayerInteractEvent event = container.getEvent(); final Block clickedBlock = event.getClickedBlock(); EquipmentSlot hand = event.getHand(); @@ -305,7 +310,7 @@ public void onPlayerInteract(final @NotNull PlayerInteractEvent event) { hand = EquipmentSlot.HAND; } - final WhoMine plugin = this.getPlugin(); + final WhoMine module = container.getModule(); final Block blockAtFace = clickedBlock.getRelative(blockFace); final ItemStack itemInHand = player.getInventory().getItem(hand); final Location interactionPoint = getInteractionPoint(player.getEyeLocation(), 8); @@ -330,7 +335,7 @@ public void onPlayerInteract(final @NotNull PlayerInteractEvent event) { final CustomBlock customBlock = new CustomBlock(clickedBlock, clickedCustomBlockData); final CustomBlockRightClickEvent rightClickEvent = new CustomBlockRightClickEvent(customBlock, player, hand, blockFace, interactionPoint); - plugin.getServer().getPluginManager().callEvent(rightClickEvent); + module.getServer().getPluginManager().callEvent(rightClickEvent); if (rightClickEvent.isCancelled()) { return; @@ -378,17 +383,22 @@ public void onPlayerInteract(final @NotNull PlayerInteractEvent event) { final PlacingType placingType = placing.getType(); final CustomBlock customBlock = new CustomBlock(replaceableBlock, customBlockData); - if (placingType instanceof PlacingType.Default) { - customBlock.place(plugin, player, hand); - } else if (placingType instanceof PlacingType.Directional) { - customBlock.place(plugin, player, hand, blockFace, null); - } else if (placingType instanceof final PlacingType.Orientable orientable) { - final Location playerLocation = player.getLocation(); - final float yaw = playerLocation.getYaw(); - final float pitch = playerLocation.getPitch(); - final var blockAxes = orientable.getMap().keySet(); - - customBlock.place(plugin, player, hand, null, getAxisByEyes(yaw, pitch, blockAxes)); + switch (placingType) { + case PlacingType.Default defaultType -> customBlock.place(module, player, hand); + case PlacingType.Directional directional -> customBlock.place(module, player, hand, blockFace, null); + case final PlacingType.Orientable orientable -> { + final Location playerLocation = player.getLocation(); + final float yaw = playerLocation.getYaw(); + final float pitch = playerLocation.getPitch(); + final var blockAxes = orientable.getMap().keySet(); + + customBlock.place( + module, player, hand, null, + getAxisByEyes(yaw, pitch, blockAxes) + ); + } + default -> { + } } } } diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerJoinListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerJoinListener.java new file mode 100644 index 00000000..ed749131 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerJoinListener.java @@ -0,0 +1,70 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.packet.ChannelInjector; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerJoinEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerJoinEvent.class) +public final class PlayerJoinListener extends PaperEventListener { + + @CancellableHandler(order = EventOrder.LOWEST) + public void onPlayerJoin(final @NotNull PaperEventContainer container) { + final PlayerJoinEvent event = container.getEvent(); + final WhoMine module = container.getModule(); + + final Player player = event.getPlayer(); + final ChannelInjector injector = new ChannelInjector( + module, + ((CraftPlayer) player).getHandle().connection.connection + ); + + module.runTask(injector::inject); + + event.joinMessage(null); + + if (player.isDead()) { + module.runTaskLater(() -> { + player.spigot().respawn(); + this.handle(module, player); + }, 8L); + } else { + this.handle(module, player); + } + } + + private void handle( + final @NotNull WhoMine module, + final @NotNull Player player + ) { + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(module, player); + + playerInfo.hideNameTag(); + player.displayName(playerInfo.getDefaultName()); + module.getCache().getWorldDark() + .teleportToDarkWorld(player) + .thenRun(() -> module.runTaskTimer(task -> { + if (!player.isOnline()) { + task.cancel(); + return; + } + + if (playerInfo.isAuthenticated()) { + task.cancel(); + playerInfo.handleResourcePack().thenAccept(bool -> { + if (bool) { + playerInfo.handleJoin(); + } + }); + } + }, 0L, 10L)); + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerKickListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerKickListener.java similarity index 55% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerKickListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerKickListener.java index d700e8ae..1d77b418 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerKickListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerKickListener.java @@ -1,17 +1,19 @@ -package com.minersstudios.whomine.listener.impl.event.player; +package com.minersstudios.whomine.listener.event.player; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.EventListener; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; -import org.bukkit.event.EventHandler; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.player.PlayerKickEvent; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; -public class PlayerKickListener extends EventListener { +@ListenFor(PlayerKickEvent.class) +public class PlayerKickListener extends PaperEventListener { private static final TranslatableComponent SERVER_RESTARTING = FORMAT_LEAVE_MESSAGE.asTranslatable() .arguments( @@ -20,12 +22,10 @@ public class PlayerKickListener extends EventListener { ) .color(NamedTextColor.DARK_GRAY); - public PlayerKickListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler + public void onPlayerKick(final @NotNull PaperEventContainer container) { + final PlayerKickEvent event = container.getEvent(); - @EventHandler - public void onPlayerKick(final @NotNull PlayerKickEvent event) { if (event.getCause() == PlayerKickEvent.Cause.RESTART_COMMAND) { event.reason(SERVER_RESTARTING); } diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerMoveListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerMoveListener.java similarity index 51% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerMoveListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerMoveListener.java index 8b771816..4527c3a5 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/event/player/PlayerMoveListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerMoveListener.java @@ -1,30 +1,32 @@ -package com.minersstudios.whomine.listener.impl.event.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.listener.api.EventListener; -import com.minersstudios.whomine.utility.BlockUtils; +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.utility.BlockUtils; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; +import com.minersstudios.wholib.event.handle.CancellableHandler; import org.bukkit.event.player.PlayerMoveEvent; import org.jetbrains.annotations.NotNull; -public final class PlayerMoveListener extends EventListener { +@ListenFor(PlayerMoveEvent.class) +public final class PlayerMoveListener extends PaperEventListener { - public PlayerMoveListener(final @NotNull WhoMine plugin) { - super(plugin); - } + @CancellableHandler + public void onPlayerMove(final @NotNull PaperEventContainer container) { + final PlayerMoveEvent event = container.getEvent(); + final PaperCache cache = container.getModule().getCache(); - @EventHandler - public void onPlayerMove(final @NotNull PlayerMoveEvent event) { final Player player = event.getPlayer(); final Block block = player.getLocation().subtract(0.0d, 0.15d, 0.0d).getBlock(); - if (this.getPlugin().getCache().getWorldDark().isInWorldDark(event.getFrom())) { + if (cache.getWorldDark().isInWorldDark(event.getFrom())) { event.setCancelled(true); } @@ -37,7 +39,7 @@ public void onPlayerMove(final @NotNull PlayerMoveEvent event) { if ( distance != 0.0d - && this.getPlugin().getCache().getStepMap().addDistance(player, distance) + && cache.getStepMap().addDistance(player, distance) && BlockUtils.isWoodenSound(block.getType()) ) { final Location stepLocation = block.getLocation().toCenterLocation(); diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerQuitListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerQuitListener.java new file mode 100644 index 00000000..abb10e6d --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerQuitListener.java @@ -0,0 +1,33 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerQuitEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerQuitEvent.class) +public final class PlayerQuitListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerQuit(final @NotNull PaperEventContainer container) { + final PlayerQuitEvent event = container.getEvent(); + final WhoMine module = container.getModule(); + + final Player player = event.getPlayer(); + final PaperCache cache = module.getCache(); + + cache.getDiggingMap().removeAll(player); + cache.getStepMap().remove(player); + + event.quitMessage(null); + PlayerInfo + .fromOnlinePlayer(module, event.getPlayer()) + .handleQuit(); + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerResourcePackStatusListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerResourcePackStatusListener.java new file mode 100644 index 00000000..c587b439 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerResourcePackStatusListener.java @@ -0,0 +1,33 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.ResourcePack; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerResourcePackStatusEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerResourcePackStatusEvent.class) +public final class PlayerResourcePackStatusListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerResourcePackStatus(final @NotNull PaperEventContainer container) { + final PlayerResourcePackStatusEvent event = container.getEvent(); + final PlayerResourcePackStatusEvent.Status status = event.getStatus(); + final Player player = event.getPlayer(); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(container.getModule(), player); + final ResourcePack.Type currentType = playerInfo.getPlayerFile().getPlayerSettings().getResourcePackType(); + + if ( + currentType == ResourcePack.Type.NULL + || status == PlayerResourcePackStatusEvent.Status.ACCEPTED + ) { + return; + } + + playerInfo.completeResourcePackFuture(status); + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerSpawnLocationListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerSpawnLocationListener.java new file mode 100644 index 00000000..829d8b44 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerSpawnLocationListener.java @@ -0,0 +1,21 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.jetbrains.annotations.NotNull; +import org.spigotmc.event.player.PlayerSpawnLocationEvent; + +@ListenFor(PlayerSpawnLocationEvent.class) +public final class PlayerSpawnLocationListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerSpawnLocation(final @NotNull PaperEventContainer container) { + final PlayerSpawnLocationEvent event = container.getEvent(); + + if (!event.getPlayer().isDead()) { + event.setSpawnLocation(container.getModule().getCache().getWorldDark().getSpawnLocation()); + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerStopSpectatingEntityListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerStopSpectatingEntityListener.java new file mode 100644 index 00000000..37f49729 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerStopSpectatingEntityListener.java @@ -0,0 +1,21 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.destroystokyo.paper.event.player.PlayerStopSpectatingEntityEvent; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerStopSpectatingEntityEvent.class) +public final class PlayerStopSpectatingEntityListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerStopSpectatingEntity(final @NotNull PaperEventContainer container) { + final PlayerStopSpectatingEntityEvent event = container.getEvent(); + + if (container.getModule().getCache().getWorldDark().isInWorldDark(event.getPlayer())) { + event.setCancelled(true); + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerTeleportListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerTeleportListener.java new file mode 100644 index 00000000..cb4df00f --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/player/PlayerTeleportListener.java @@ -0,0 +1,40 @@ +package com.minersstudios.whomine.listener.event.player; + +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import org.bukkit.entity.Player; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(PlayerTeleportEvent.class) +public final class PlayerTeleportListener extends PaperEventListener { + + @CancellableHandler + public void onPlayerTeleport(final @NotNull PaperEventContainer container) { + final PlayerTeleportEvent event = container.getEvent(); + final WhoMine module = container.getModule(); + + final Player player = event.getPlayer(); + final PaperCache cache = module.getCache(); + final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(module, player); + + cache.getDiggingMap().removeAll(player); + cache.getStepMap().put(player, 0.0d); + + if (playerInfo.isSitting()) { + playerInfo.unsetSitting(); + } + + if ( + event.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE + && playerInfo.isInWorldDark() + ) { + event.setCancelled(true); + } + } +} diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/server/ServerCommandListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/server/ServerCommandListener.java new file mode 100644 index 00000000..8710357b --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/event/server/ServerCommandListener.java @@ -0,0 +1,27 @@ +package com.minersstudios.whomine.listener.event.server; + +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.paper.event.PaperEventContainer; +import com.minersstudios.wholib.paper.event.PaperEventListener; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import org.bukkit.event.server.ServerCommandEvent; +import org.jetbrains.annotations.NotNull; + +@ListenFor(ServerCommandEvent.class) +public final class ServerCommandListener extends PaperEventListener { + + @CancellableHandler + public void onServerCommand(final @NotNull PaperEventContainer container) { + final ServerCommandEvent event = container.getEvent(); + final String command = event.getCommand().split(" ")[0]; + + // TODO: fix getCommandManager + //if (container.getModule().getCommandManager().isPlayerOnly(command)) { + // MSLogger.severe( + // event.getSender(), + // Translations.ERROR_ONLY_PLAYER_COMMAND.asTranslatable() + // ); + // event.setCancelled(true); + //} + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/packet/player/PlayerActionListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/packet/player/PlayerActionListener.java similarity index 65% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/packet/player/PlayerActionListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/packet/player/PlayerActionListener.java index 52fb9b98..6ec6401b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/packet/player/PlayerActionListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/packet/player/PlayerActionListener.java @@ -1,29 +1,35 @@ -package com.minersstudios.whomine.listener.impl.packet.player; - -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.custom.block.CustomBlock; -import com.minersstudios.whomine.custom.block.CustomBlockData; -import com.minersstudios.whomine.custom.block.CustomBlockRegistry; -import com.minersstudios.whomine.collection.DiggingMap; -import com.minersstudios.whomine.listener.api.PacketListener; -import com.minersstudios.whomine.world.location.MSPosition; -import com.minersstudios.whomine.packet.PacketContainer; -import com.minersstudios.whomine.packet.PacketEvent; -import com.minersstudios.whomine.packet.PacketType; -import com.minersstudios.whomine.world.sound.SoundGroup; -import com.minersstudios.whomine.utility.BlockUtils; -import com.minersstudios.whomine.utility.PlayerUtils; -import com.minersstudios.whomine.utility.SharedConstants; +package com.minersstudios.whomine.listener.packet.player; + +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.paper.custom.block.CustomBlock; +import com.minersstudios.wholib.paper.custom.block.CustomBlockData; +import com.minersstudios.wholib.paper.custom.block.CustomBlockRegistry; +import com.minersstudios.wholib.paper.collection.DiggingMap; +import com.minersstudios.wholib.packet.registry.PlayPackets; +import com.minersstudios.wholib.paper.packet.PaperPacketContainer; +import com.minersstudios.wholib.paper.packet.PaperPacketEvent; +import com.minersstudios.wholib.paper.packet.PaperPacketListener; +import com.minersstudios.wholib.paper.utility.ApiConverter; +import com.minersstudios.wholib.paper.world.location.MSPosition; +import com.minersstudios.wholib.paper.world.sound.SoundGroup; +import com.minersstudios.wholib.paper.utility.BlockUtils; +import com.minersstudios.wholib.paper.utility.PlayerUtils; +import com.minersstudios.wholib.utility.ResourcedPath; +import com.minersstudios.wholib.utility.SharedConstants; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.level.GameType; import org.bukkit.Location; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.Block; import org.bukkit.block.data.type.NoteBlock; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlotGroup; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,44 +38,40 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; -import static net.minecraft.world.effect.MobEffectInstance.INFINITE_DURATION; -import static net.minecraft.world.effect.MobEffects.DIG_SLOWDOWN; -import static org.bukkit.event.entity.EntityPotionEffectEvent.Cause.PLUGIN; +public final class PlayerActionListener extends PaperPacketListener { -public final class PlayerActionListener extends PacketListener { private final Map handlerMap; - private final Map effectMap; final Map> clickRequestMap; - public PlayerActionListener(final @NotNull WhoMine plugin) { - super(plugin, PacketType.PLAY_SERVER_PLAYER_ACTION); + public PlayerActionListener() { + super(PlayPackets.SERVER_PLAYER_ACTION); this.handlerMap = new Object2ObjectOpenHashMap<>(); - this.effectMap = new Object2ObjectOpenHashMap<>(); this.clickRequestMap = new ConcurrentHashMap<>(); } - @Override - public void onPacketReceive(final @NotNull PacketEvent event) { + @CancellableHandler + public void onEvent(final @NotNull PaperPacketContainer container) { + final PaperPacketEvent event = container.getEvent(); final ServerPlayer player = event.getConnection().getPlayer(); - final PacketContainer container = event.getPacketContainer(); if (player.gameMode.getGameModeForPlayer() == GameType.SURVIVAL) { - final var packet = (ServerboundPlayerActionPacket) container.getPacket(); - final MSPosition position = MSPosition.of( - player.level().getWorld(), - packet.getPos() - ); - - switch (packet.getAction()) { - case START_DESTROY_BLOCK -> this.getHandler(player, position).ifPresent(Handler::start); - case ABORT_DESTROY_BLOCK -> this.getHandler(player, position).ifPresent(Handler::abort); - case STOP_DESTROY_BLOCK -> this.getHandler(player, position).ifPresent(Handler::finish); - } + final var packet = (ServerboundPlayerActionPacket) event.getPacket(); + final MSPosition position = MSPosition.of(player.level().getWorld(), packet.getPos()); + + this.getHandler(container.getModule(), player, position).ifPresent(handler -> { + switch (packet.getAction()) { + case START_DESTROY_BLOCK -> handler.start(); + case ABORT_DESTROY_BLOCK -> handler.abort(); + case STOP_DESTROY_BLOCK -> handler.finish(); + default -> {} // Do nothing + } + }); } } private @NotNull Optional getHandler( + final @NotNull WhoMine module, final @NotNull ServerPlayer serverPlayer, final @NotNull MSPosition position ) { @@ -84,7 +86,7 @@ public void onPacketReceive(final @NotNull PacketEvent event) { return Optional.of(handler); } - final Handler newHandler = new Handler(serverPlayer, position); + final Handler newHandler = new Handler(module, serverPlayer, position); this.handlerMap.put( serverPlayer.getStringUUID(), @@ -97,65 +99,10 @@ public void onPacketReceive(final @NotNull PacketEvent event) { this.handlerMap.remove(serverPlayer.getStringUUID()); } - this.getPlugin().runTask( - () -> this.removeSlowDigging(serverPlayer) - ); - return Optional.empty(); } } - private boolean addSlowDigging(final @NotNull ServerPlayer serverPlayer) { - final MobEffectInstance effect = serverPlayer.getEffect(DIG_SLOWDOWN); - final boolean hasSlowDigging = effect != null; - - if (hasSlowDigging) { - if (!effect.isVisible()) { - return false; - } - - this.effectMap.put( - serverPlayer.getStringUUID(), - new MobEffectInstance(effect) - ); - } - - serverPlayer.addEffect( - new MobEffectInstance( - DIG_SLOWDOWN, - INFINITE_DURATION, - Integer.MAX_VALUE, - false, - hasSlowDigging, - hasSlowDigging - ), - PLUGIN - ); - - return true; - } - - private boolean removeSlowDigging(final @NotNull ServerPlayer serverPlayer) { - final MobEffectInstance effect = serverPlayer.getEffect(DIG_SLOWDOWN); - - if ( - effect != null - && !effect.isVisible() - ) { - serverPlayer.removeEffect(DIG_SLOWDOWN, PLUGIN); - - final MobEffectInstance oldEffect = this.effectMap.remove(serverPlayer.getStringUUID()); - - if (oldEffect != null) { - serverPlayer.addEffect(oldEffect); - } - - return true; - } - - return false; - } - static @Nullable Block getTargetBlock(final @NotNull ServerPlayer serverPlayer) { final Player player = serverPlayer.getBukkitEntity(); final Block targetBlock = PlayerUtils.getTargetBlock(player); @@ -169,7 +116,16 @@ private boolean removeSlowDigging(final @NotNull ServerPlayer serverPlayer) { * Handles the block-breaking process */ private class Handler { - private final DiggingMap diggingMap; + @SuppressWarnings("UnstableApiUsage") + private static final AttributeModifier BREAK_SPEED_MODIFIER = + new AttributeModifier( + ApiConverter.apiToBukkit(ResourcedPath.whomine("custom_break_speed")), + -1, + AttributeModifier.Operation.MULTIPLY_SCALAR_1, + EquipmentSlotGroup.HAND + ); + + private final WhoMine module; private final ServerPlayer serverPlayer; private final MSPosition position; private final Block block; @@ -181,10 +137,11 @@ private class Handler { * @param position The position of the block */ Handler( + final @NotNull WhoMine module, final @NotNull ServerPlayer serverPlayer, final @NotNull MSPosition position ) { - this.diggingMap = PlayerActionListener.this.getPlugin().getCache().getDiggingMap(); + this.module = module; this.serverPlayer = serverPlayer; this.position = position; this.block = position.getBlock(); @@ -194,19 +151,12 @@ private class Handler { * Starts the block-breaking process */ public void start() { - final WhoMine plugin = PlayerActionListener.this.getPlugin(); - this.stop(); if (this.block.getBlockData() instanceof final NoteBlock noteBlock) { - plugin.runTask( - () -> PlayerActionListener.this.addSlowDigging(this.serverPlayer) - ); + this.addSpeedModifier(); this.handleNoteBlock(noteBlock); } else { - plugin.runTask( - () -> PlayerActionListener.this.removeSlowDigging(this.serverPlayer) - ); this.handleWoodenBlock(); } } @@ -227,29 +177,30 @@ public void abort() { * packet sent by the client */ public void abort(final boolean fromPacket) { - final DiggingMap.Entry entry = this.diggingMap.getEntry( + final DiggingMap diggingMap = this.module.getCache().getDiggingMap(); + final DiggingMap.Entry entry = diggingMap.getEntry( this.block, this.serverPlayer.getBukkitEntity() ); if (entry != null) { - final WhoMine plugin = PlayerActionListener.this.getPlugin(); final String uuid = this.serverPlayer.getStringUUID(); if (PlayerActionListener.this.clickRequestMap.containsKey(uuid)) { return; } - plugin.runTask(() -> { + this.module.runTask(() -> { if (fromPacket) { if (this.block.equals(getTargetBlock(this.serverPlayer))) { this.stop(entry); + return; } entry.setStage(-1); - if (this.diggingMap.getDiggingEntries(this.block).size() == 1) { + if (diggingMap.getDiggingEntries(this.block).size() == 1) { this.broadcastStage(this.block, -1); } } @@ -295,21 +246,23 @@ public void stop() { * the player will be stopped */ public void stop(final @Nullable DiggingMap.Entry entry) { - final WhoMine plugin = PlayerActionListener.this.getPlugin(); + this.removeSpeedModifier(); + + final DiggingMap diggingMap = this.module.getCache().getDiggingMap(); if (entry == null) { - final var removed = this.diggingMap.removeAll(this.serverPlayer.getBukkitEntity()); + final var removed = diggingMap.removeAll(this.serverPlayer.getBukkitEntity()); if (!removed.isEmpty()) { - plugin.runTask(() -> { + this.module.runTask(() -> { for (final var removedEntry : removed) { broadcastBiggestStage(removedEntry.getKey()); } }); } } else { - this.diggingMap.remove(this.block, entry); - plugin.runTask(() -> broadcastBiggestStage(this.block)); + diggingMap.remove(this.block, entry); + this.module.runTask(() -> broadcastBiggestStage(this.block)); } PlayerActionListener.this.clickRequestMap.remove(this.serverPlayer.getStringUUID()); @@ -320,12 +273,14 @@ public void stop(final @Nullable DiggingMap.Entry entry) { * with the block */ public void finish() { - if (this.diggingMap.containsBlock(this.block)) { - this.diggingMap.removeAll(this.block); + final DiggingMap diggingMap = this.module.getCache().getDiggingMap(); + + if (diggingMap.containsBlock(this.block)) { + diggingMap.removeAll(this.block); PlayerActionListener.this.clickRequestMap.remove( this.serverPlayer.getStringUUID() ); - PlayerActionListener.this.getPlugin().runTask( + this.module.runTask( () -> this.broadcastStage(this.block, -1) ); } @@ -361,7 +316,7 @@ public void broadcastStage( * @param block The block to get the biggest stage entry from */ public void broadcastBiggestStage(final @NotNull Block block) { - final DiggingMap.Entry entry = this.diggingMap.getBiggestStageEntry(block); + final DiggingMap.Entry entry = this.module.getCache().getDiggingMap().getBiggestStageEntry(block); this.broadcastStage( block, @@ -369,22 +324,26 @@ public void broadcastBiggestStage(final @NotNull Block block) { ); } - private int getSlowDiggingAmplifier() { - MobEffectInstance slowDigging = - PlayerActionListener.this.effectMap.get(this.serverPlayer.getStringUUID()); + private void addSpeedModifier() { + final AttributeInstance attributeInstance = + this.serverPlayer.getBukkitEntity().getAttribute(Attribute.GENERIC_ATTACK_SPEED); - if (slowDigging == null) { - slowDigging = this.serverPlayer.getEffect(DIG_SLOWDOWN); + if (attributeInstance != null) { + attributeInstance.removeModifier(BREAK_SPEED_MODIFIER); + attributeInstance.addTransientModifier(BREAK_SPEED_MODIFIER); } + } + + private void removeSpeedModifier() { + final AttributeInstance attributeInstance = + this.serverPlayer.getBukkitEntity().getAttribute(Attribute.GENERIC_ATTACK_SPEED); - return slowDigging == null - || slowDigging.isInfiniteDuration() - ? -1 - : slowDigging.getAmplifier(); + if (attributeInstance != null) { + attributeInstance.removeModifier(BREAK_SPEED_MODIFIER); + } } - private void handleNoteBlock(final NoteBlock noteBlock) { - final WhoMine plugin = PlayerActionListener.this.getPlugin(); + private void handleNoteBlock(final @NotNull NoteBlock noteBlock) { final Player player = this.serverPlayer.getBukkitEntity(); final Location center = this.position.center().toLocation(); final DiggingMap.Entry entry = DiggingMap.Entry.create(player); @@ -394,13 +353,10 @@ private void handleNoteBlock(final NoteBlock noteBlock) { .fromNoteBlock(noteBlock) .orElse(CustomBlockData.defaultData()); final SoundGroup soundGroup = customBlockData.getSoundGroup(); - final float digSpeed = customBlockData.getBlockSettings().calculateDigSpeed( - player, - this.getSlowDiggingAmplifier() - ); + final float digSpeed = customBlockData.getBlockSettings().calculateDigSpeed(player); - this.diggingMap.put(this.block, entry.setTaskId( - plugin.runTaskTimer(new Runnable() { + this.module.getCache().getDiggingMap().put(this.block, entry.setTaskId( + this.module.runTaskTimer(new Runnable() { float ticks = 0.0f; float progress = 0.0f; boolean isAlreadyAborted = false; @@ -440,8 +396,8 @@ public void run() { if (progressInStage > SharedConstants.FINAL_DESTROY_STAGE) { Handler.this.finish(); new CustomBlock(block, customBlockData) - .destroy(plugin, player); - } else if (entry.isStageTheBiggest(plugin, block)) { + .destroy(module, player); + } else if (entry.isStageTheBiggest(module, block)) { Handler.this.broadcastStage(block, progressInStage); } } @@ -454,8 +410,8 @@ private void handleWoodenBlock() { final DiggingMap.Entry entry = DiggingMap.Entry.create(this.serverPlayer.getBukkitEntity()); final Location center = this.position.center().toLocation(); - this.diggingMap.put(this.block, entry.setTaskId( - PlayerActionListener.this.getPlugin().runTaskTimer(new Runnable() { + this.module.getCache().getDiggingMap().put(this.block, entry.setTaskId( + this.module.runTaskTimer(new Runnable() { float ticks = 0.0f; boolean isAlreadyAborted = false; diff --git a/platform/paper/src/main/java/com/minersstudios/whomine/listener/packet/player/PlayerUpdateSignListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/packet/player/PlayerUpdateSignListener.java new file mode 100644 index 00000000..12b4d6a5 --- /dev/null +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/packet/player/PlayerUpdateSignListener.java @@ -0,0 +1,35 @@ +package com.minersstudios.whomine.listener.packet.player; + +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.paper.inventory.SignMenu; +import com.minersstudios.wholib.packet.registry.PlayPackets; +import com.minersstudios.wholib.paper.packet.PaperPacketContainer; +import com.minersstudios.wholib.paper.packet.PaperPacketListener; +import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public final class PlayerUpdateSignListener extends PaperPacketListener { + + public PlayerUpdateSignListener() { + super(PlayPackets.SERVER_UPDATE_SIGN); + } + + @CancellableHandler + public void onEvent(final @NotNull PaperPacketContainer container) { + final var event = container.getEvent(); + final Player player = event.getConnection().getPlayer().getBukkitEntity(); + final SignMenu menu = SignMenu.getSignMenu(player); + + if ( + menu != null + && event.getPacket() instanceof final ServerboundSignUpdatePacket packet + ) { + if (!menu.getResponse().test(player, packet.getLines())) { + container.getModule().runTaskLater(() -> menu.open(player), 2L); + } else { + menu.close(player); + } + } + } +} diff --git a/paper/src/main/java/com/minersstudios/whomine/listener/impl/packet/player/SwingArmListener.java b/platform/paper/src/main/java/com/minersstudios/whomine/listener/packet/player/SwingArmListener.java similarity index 51% rename from paper/src/main/java/com/minersstudios/whomine/listener/impl/packet/player/SwingArmListener.java rename to platform/paper/src/main/java/com/minersstudios/whomine/listener/packet/player/SwingArmListener.java index dee4ef46..2e7318e5 100644 --- a/paper/src/main/java/com/minersstudios/whomine/listener/impl/packet/player/SwingArmListener.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/listener/packet/player/SwingArmListener.java @@ -1,9 +1,10 @@ -package com.minersstudios.whomine.listener.impl.packet.player; +package com.minersstudios.whomine.listener.packet.player; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.listener.api.PacketListener; -import com.minersstudios.whomine.packet.PacketEvent; -import com.minersstudios.whomine.packet.PacketType; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.event.handle.CancellableHandler; +import com.minersstudios.wholib.packet.registry.PlayPackets; +import com.minersstudios.wholib.paper.packet.PaperPacketContainer; +import com.minersstudios.wholib.paper.packet.PaperPacketListener; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.GameType; import org.bukkit.block.Block; @@ -12,25 +13,30 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; -public final class SwingArmListener extends PacketListener { +public final class SwingArmListener extends PaperPacketListener { + private Map> clickRequestMap; - public SwingArmListener(final @NotNull WhoMine plugin) { - super(plugin, PacketType.PLAY_SERVER_SWING_ARM); + public SwingArmListener() { + super(PlayPackets.SERVER_SWING_ARM); } - @Override - public void onPacketReceive(final @NotNull PacketEvent event) { + @CancellableHandler + public void onEvent(final @NotNull PaperPacketContainer container) { + final WhoMine module = container.getModule(); + if (this.clickRequestMap == null) { - this.setupClickRequestMap(); + this.setupClickRequestMap(module); } + final ServerPlayer serverPlayer = container.getEvent().getConnection().getPlayer(); + + container.getEvent().setCancelled(true); + if (this.clickRequestMap.isEmpty()) { return; } - final ServerPlayer serverPlayer = event.getConnection().getPlayer(); - if (serverPlayer.gameMode.getGameModeForPlayer() == GameType.SURVIVAL) { final String uuid = serverPlayer.getStringUUID(); final var future = this.clickRequestMap.get(uuid); @@ -39,7 +45,7 @@ public void onPacketReceive(final @NotNull PacketEvent event) { return; } - this.getPlugin().runTask(() -> { + module.runTask(() -> { final Block targetBlock = PlayerActionListener.getTargetBlock(serverPlayer); if (targetBlock != null) { @@ -50,10 +56,17 @@ public void onPacketReceive(final @NotNull PacketEvent event) { } } - private void setupClickRequestMap() { - for (final var listener : this.getPlugin().getListenerManager().packetListeners()) { + private void setupClickRequestMap(final @NotNull WhoMine module) { + final var listeners = module.getListenerManager().getPacketListeners(PlayPackets.SERVER_PLAYER_ACTION); + + if (listeners == null) { + return; + } + + for (final var listener : listeners) { if (listener instanceof final PlayerActionListener playerActionListener) { this.clickRequestMap = playerActionListener.clickRequestMap; + break; } } diff --git a/paper/src/main/java/com/minersstudios/whomine/menu/CraftsMenu.java b/platform/paper/src/main/java/com/minersstudios/whomine/menu/CraftsMenu.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/menu/CraftsMenu.java rename to platform/paper/src/main/java/com/minersstudios/whomine/menu/CraftsMenu.java index bd2c2b87..b271564c 100644 --- a/paper/src/main/java/com/minersstudios/whomine/menu/CraftsMenu.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/menu/CraftsMenu.java @@ -1,7 +1,7 @@ package com.minersstudios.whomine.menu; -import com.minersstudios.whomine.inventory.*; -import com.minersstudios.whomine.inventory.action.ButtonClickAction; +import com.minersstudios.wholib.paper.inventory.*; +import com.minersstudios.wholib.paper.inventory.action.ButtonClickAction; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; import org.bukkit.Material; @@ -17,8 +17,8 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -import static com.minersstudios.whomine.locale.Translations.*; -import static com.minersstudios.whomine.utility.ChatUtils.DEFAULT_STYLE; +import static com.minersstudios.wholib.locale.Translations.*; +import static com.minersstudios.wholib.utility.ChatUtils.DEFAULT_STYLE; public final class CraftsMenu { public static final int RESULT_SLOT = 15; diff --git a/paper/src/main/java/com/minersstudios/whomine/menu/DiscordLinkCodeMenu.java b/platform/paper/src/main/java/com/minersstudios/whomine/menu/DiscordLinkCodeMenu.java similarity index 79% rename from paper/src/main/java/com/minersstudios/whomine/menu/DiscordLinkCodeMenu.java rename to platform/paper/src/main/java/com/minersstudios/whomine/menu/DiscordLinkCodeMenu.java index b14bf028..f6c55ea3 100644 --- a/paper/src/main/java/com/minersstudios/whomine/menu/DiscordLinkCodeMenu.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/menu/DiscordLinkCodeMenu.java @@ -1,11 +1,12 @@ package com.minersstudios.whomine.menu; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.inventory.holder.AbstractInventoryHolder; -import com.minersstudios.whomine.inventory.holder.InventoryHolder; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.utility.Font; -import com.minersstudios.whomine.player.PlayerInfo; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.inventory.holder.AbstractInventoryHolder; +import com.minersstudios.wholib.paper.inventory.holder.InventoryHolder; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.utility.Font; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.utility.ResourcedPath; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.format.NamedTextColor; @@ -16,7 +17,7 @@ import java.util.Arrays; import java.util.List; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; @InventoryHolder @@ -35,6 +36,10 @@ public final class DiscordLinkCodeMenu extends AbstractInventoryHolder { MENU_DISCORD_NUMBERS_9.asTranslatable() ); + public DiscordLinkCodeMenu() { + super("discord_link_code"); + } + @Override protected @Nullable CustomInventory createCustomInventory() { return null; // creates on open diff --git a/paper/src/main/java/com/minersstudios/whomine/menu/PronounMenu.java b/platform/paper/src/main/java/com/minersstudios/whomine/menu/PronounMenu.java similarity index 86% rename from paper/src/main/java/com/minersstudios/whomine/menu/PronounMenu.java rename to platform/paper/src/main/java/com/minersstudios/whomine/menu/PronounMenu.java index b15952db..c86eca46 100644 --- a/paper/src/main/java/com/minersstudios/whomine/menu/PronounMenu.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/menu/PronounMenu.java @@ -1,15 +1,15 @@ package com.minersstudios.whomine.menu; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.inventory.InventoryButton; -import com.minersstudios.whomine.inventory.holder.AbstractInventoryHolder; -import com.minersstudios.whomine.inventory.holder.InventoryHolder; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.Pronouns; -import com.minersstudios.whomine.player.RegistrationProcess; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.inventory.InventoryButton; +import com.minersstudios.wholib.paper.inventory.holder.AbstractInventoryHolder; +import com.minersstudios.wholib.paper.inventory.holder.InventoryHolder; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.Pronouns; +import com.minersstudios.wholib.paper.player.RegistrationProcess; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -19,11 +19,15 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; @InventoryHolder public final class PronounMenu extends AbstractInventoryHolder { + public PronounMenu() { + super("pronouns_choice"); + } + @Override protected @NotNull CustomInventory createCustomInventory() { final WhoMine plugin = this.getPlugin(); diff --git a/paper/src/main/java/com/minersstudios/whomine/menu/RenamesMenu.java b/platform/paper/src/main/java/com/minersstudios/whomine/menu/RenamesMenu.java similarity index 96% rename from paper/src/main/java/com/minersstudios/whomine/menu/RenamesMenu.java rename to platform/paper/src/main/java/com/minersstudios/whomine/menu/RenamesMenu.java index 84a56f8c..0741b75b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/menu/RenamesMenu.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/menu/RenamesMenu.java @@ -1,12 +1,12 @@ package com.minersstudios.whomine.menu; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.*; -import com.minersstudios.whomine.locale.Translations; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.custom.item.renameable.RenameCollection; -import com.minersstudios.whomine.custom.item.renameable.RenameableItem; -import com.minersstudios.whomine.custom.item.renameable.RenameableItemRegistry; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.*; +import com.minersstudios.wholib.locale.Translations; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameCollection; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItem; +import com.minersstudios.wholib.paper.custom.item.renameable.RenameableItemRegistry; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -27,7 +27,7 @@ import java.util.stream.IntStream; -import static com.minersstudios.whomine.inventory.InventoryButton.playClickSound; +import static com.minersstudios.wholib.paper.inventory.InventoryButton.playClickSound; public final class RenamesMenu { private static final int RENAMEABLE_ITEM_SLOT = 2; @@ -167,7 +167,7 @@ public static void update(final @NotNull WhoMine plugin) { 5 ); - renameInventory.setItem(RENAMEABLE_ITEM_SLOT, renameableItemStacks.get(0)); + renameInventory.setItem(RENAMEABLE_ITEM_SLOT, renameableItemStacks.getFirst()); renameInventory.setItem(RENAMED_ITEM_SLOT, resultItem); renameInventory.buttonAt( QUIT_RENAME_BUTTON_SLOT, @@ -320,7 +320,7 @@ private static void createRenamedItem( if ( renameableItem != null - && renameableItem.isWhiteListed((OfflinePlayer) inventory.getViewers().get(0)) + && renameableItem.isWhiteListed((OfflinePlayer) inventory.getViewers().getFirst()) ) { inventory.setItem(CURRENT_RENAMED_ITEM_SLOT, renameableItem.craftRenamed(itemStack, renameText)); diff --git a/paper/src/main/java/com/minersstudios/whomine/menu/ResourcePackMenu.java b/platform/paper/src/main/java/com/minersstudios/whomine/menu/ResourcePackMenu.java similarity index 91% rename from paper/src/main/java/com/minersstudios/whomine/menu/ResourcePackMenu.java rename to platform/paper/src/main/java/com/minersstudios/whomine/menu/ResourcePackMenu.java index e50969ff..2c912148 100644 --- a/paper/src/main/java/com/minersstudios/whomine/menu/ResourcePackMenu.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/menu/ResourcePackMenu.java @@ -1,13 +1,13 @@ package com.minersstudios.whomine.menu; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.inventory.InventoryButton; -import com.minersstudios.whomine.inventory.holder.AbstractInventoryHolder; -import com.minersstudios.whomine.inventory.holder.InventoryHolder; -import com.minersstudios.whomine.player.ResourcePack; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.PlayerSettings; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.inventory.InventoryButton; +import com.minersstudios.wholib.paper.inventory.holder.AbstractInventoryHolder; +import com.minersstudios.wholib.paper.inventory.holder.InventoryHolder; +import com.minersstudios.wholib.paper.player.ResourcePack; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.PlayerSettings; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -19,14 +19,18 @@ import java.util.Arrays; -import static com.minersstudios.whomine.locale.Translations.*; -import static com.minersstudios.whomine.utility.ChatUtils.COLORLESS_DEFAULT_STYLE; -import static com.minersstudios.whomine.utility.ChatUtils.DEFAULT_STYLE; +import static com.minersstudios.wholib.locale.Translations.*; +import static com.minersstudios.wholib.utility.ChatUtils.COLORLESS_DEFAULT_STYLE; +import static com.minersstudios.wholib.utility.ChatUtils.DEFAULT_STYLE; import static net.kyori.adventure.text.format.NamedTextColor.GRAY; @InventoryHolder public final class ResourcePackMenu extends AbstractInventoryHolder { + public ResourcePackMenu() { + super("resource_pack_choice"); + } + @Override protected @NotNull CustomInventory createCustomInventory() { final WhoMine plugin = this.getPlugin(); diff --git a/paper/src/main/java/com/minersstudios/whomine/menu/SkinsMenu.java b/platform/paper/src/main/java/com/minersstudios/whomine/menu/SkinsMenu.java similarity index 90% rename from paper/src/main/java/com/minersstudios/whomine/menu/SkinsMenu.java rename to platform/paper/src/main/java/com/minersstudios/whomine/menu/SkinsMenu.java index e1c6396f..c0fcf6e5 100644 --- a/paper/src/main/java/com/minersstudios/whomine/menu/SkinsMenu.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/menu/SkinsMenu.java @@ -1,16 +1,16 @@ package com.minersstudios.whomine.menu; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.inventory.CustomInventory; -import com.minersstudios.whomine.inventory.InventoryButton; -import com.minersstudios.whomine.inventory.holder.AbstractInventoryHolder; -import com.minersstudios.whomine.inventory.holder.InventoryHolder; -import com.minersstudios.whomine.utility.MSLogger; -import com.minersstudios.whomine.utility.ChatUtils; -import com.minersstudios.whomine.discord.BotHandler; -import com.minersstudios.whomine.player.PlayerFile; -import com.minersstudios.whomine.player.PlayerInfo; -import com.minersstudios.whomine.player.skin.Skin; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.inventory.CustomInventory; +import com.minersstudios.wholib.paper.inventory.InventoryButton; +import com.minersstudios.wholib.paper.inventory.holder.AbstractInventoryHolder; +import com.minersstudios.wholib.paper.inventory.holder.InventoryHolder; +import com.minersstudios.wholib.paper.utility.MSLogger; +import com.minersstudios.wholib.utility.ChatUtils; +import com.minersstudios.wholib.paper.discord.BotHandler; +import com.minersstudios.wholib.paper.player.PlayerFile; +import com.minersstudios.wholib.paper.player.PlayerInfo; +import com.minersstudios.wholib.paper.player.skin.Skin; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.kyori.adventure.text.Component; import org.bukkit.Material; @@ -21,7 +21,7 @@ import java.util.Collections; -import static com.minersstudios.whomine.locale.Translations.*; +import static com.minersstudios.wholib.locale.Translations.*; import static net.kyori.adventure.text.Component.text; @InventoryHolder @@ -33,6 +33,10 @@ public final class SkinsMenu extends AbstractInventoryHolder { private InventoryButton deleteButton; private InventoryButton deleteButtonEmpty; + public SkinsMenu() { + super("skins_choice"); + } + @Override protected @NotNull CustomInventory createCustomInventory() { final WhoMine plugin = this.getPlugin(); @@ -55,7 +59,7 @@ public final class SkinsMenu extends AbstractInventoryHolder { this.applyButton = new InventoryButton(applyItem, (event, inv) -> { final Player player = (Player) event.getWhoClicked(); final PlayerInfo playerInfo = PlayerInfo.fromOnlinePlayer(plugin, player); - final Skin skin = playerInfo.getPlayerFile().getSkin((int) inv.args().get(0)); + final Skin skin = playerInfo.getPlayerFile().getSkin((int) inv.args().getFirst()); if (skin == null) { return; @@ -88,7 +92,7 @@ public final class SkinsMenu extends AbstractInventoryHolder { final PlayerFile playerFile = playerInfo.getPlayerFile(); try { - final Skin selectedSkin = playerFile.getSkin((int) inv.args().get(0)); + final Skin selectedSkin = playerFile.getSkin((int) inv.args().getFirst()); if (selectedSkin == null) { return; @@ -155,14 +159,14 @@ public void open(final @NotNull Player player) { .item(head) .clickAction((event, inv) -> { final boolean havePrevious = !inv.args().isEmpty(); - final boolean isSame = havePrevious && ((int) inv.args().get(0)) == finalI; + final boolean isSame = havePrevious && ((int) inv.args().getFirst()) == finalI; final ItemMeta headItemMeta = head.getItemMeta(); headItemMeta.setCustomModelData(isSame ? null : 1); head.setItemMeta(headItemMeta); if (havePrevious) { - final int previous = (int) inv.args().get(0); + final int previous = (int) inv.args().getFirst(); final InventoryButton previousButton = skinButtons.get(previous); if (previousButton != null) { diff --git a/paper/src/main/java/com/minersstudios/whomine/scheduler/task/BanListTask.java b/platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/BanListTask.java similarity index 91% rename from paper/src/main/java/com/minersstudios/whomine/scheduler/task/BanListTask.java rename to platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/BanListTask.java index cec0e868..5900f61b 100644 --- a/paper/src/main/java/com/minersstudios/whomine/scheduler/task/BanListTask.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/BanListTask.java @@ -1,11 +1,11 @@ package com.minersstudios.whomine.scheduler.task; import com.destroystokyo.paper.profile.PlayerProfile; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; +import io.papermc.paper.ban.BanListType; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.bukkit.BanEntry; -import org.bukkit.BanList; import org.bukkit.Server; import org.bukkit.ban.ProfileBanList; import org.jetbrains.annotations.NotNull; @@ -28,7 +28,7 @@ public BanListTask(final @NotNull WhoMine plugin) { @Override public void run() { - final ProfileBanList banList = this.server.getBanList(BanList.Type.PROFILE); + final ProfileBanList banList = this.server.getBanList(BanListType.PROFILE); final Set> entries = banList.getEntries(); final Instant currentInstant = Instant.now(); diff --git a/paper/src/main/java/com/minersstudios/whomine/scheduler/task/MuteMapTask.java b/platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/MuteMapTask.java similarity index 87% rename from paper/src/main/java/com/minersstudios/whomine/scheduler/task/MuteMapTask.java rename to platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/MuteMapTask.java index 77e88a32..27d692fe 100644 --- a/paper/src/main/java/com/minersstudios/whomine/scheduler/task/MuteMapTask.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/MuteMapTask.java @@ -1,8 +1,8 @@ package com.minersstudios.whomine.scheduler.task; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.player.collection.MuteMap; -import com.minersstudios.whomine.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.player.collection.MuteMap; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/scheduler/task/PlayerListTask.java b/platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/PlayerListTask.java similarity index 78% rename from paper/src/main/java/com/minersstudios/whomine/scheduler/task/PlayerListTask.java rename to platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/PlayerListTask.java index 4da7e788..67d54fee 100644 --- a/paper/src/main/java/com/minersstudios/whomine/scheduler/task/PlayerListTask.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/PlayerListTask.java @@ -1,15 +1,15 @@ package com.minersstudios.whomine.scheduler.task; -import com.minersstudios.whomine.Cache; -import com.minersstudios.whomine.WhoMine; -import com.minersstudios.whomine.player.collection.PlayerInfoMap; -import com.minersstudios.whomine.world.WorldDark; +import com.minersstudios.wholib.paper.PaperCache; +import com.minersstudios.wholib.paper.WhoMine; +import com.minersstudios.wholib.paper.player.collection.PlayerInfoMap; +import com.minersstudios.wholib.paper.world.WorldDark; import org.bukkit.Server; import org.jetbrains.annotations.NotNull; public final class PlayerListTask implements Runnable { private final Server server; - private final Cache cache; + private final PaperCache cache; public PlayerListTask(final @NotNull WhoMine plugin) { this.server = plugin.getServer(); diff --git a/paper/src/main/java/com/minersstudios/whomine/scheduler/task/SeatsTask.java b/platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/SeatsTask.java similarity index 94% rename from paper/src/main/java/com/minersstudios/whomine/scheduler/task/SeatsTask.java rename to platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/SeatsTask.java index 33d35e02..d5731f53 100644 --- a/paper/src/main/java/com/minersstudios/whomine/scheduler/task/SeatsTask.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/scheduler/task/SeatsTask.java @@ -1,6 +1,6 @@ package com.minersstudios.whomine.scheduler.task; -import com.minersstudios.whomine.WhoMine; +import com.minersstudios.wholib.paper.WhoMine; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/paper/src/main/java/com/minersstudios/whomine/utility/UseBucketsAndSpawnableItems.java b/platform/paper/src/main/java/com/minersstudios/whomine/utility/UseBucketsAndSpawnableItems.java similarity index 97% rename from paper/src/main/java/com/minersstudios/whomine/utility/UseBucketsAndSpawnableItems.java rename to platform/paper/src/main/java/com/minersstudios/whomine/utility/UseBucketsAndSpawnableItems.java index e4513cb4..d56e251d 100644 --- a/paper/src/main/java/com/minersstudios/whomine/utility/UseBucketsAndSpawnableItems.java +++ b/platform/paper/src/main/java/com/minersstudios/whomine/utility/UseBucketsAndSpawnableItems.java @@ -1,5 +1,7 @@ package com.minersstudios.whomine.utility; +import com.minersstudios.wholib.paper.utility.BlockUtils; +import com.minersstudios.wholib.paper.utility.CoreProtectUtils; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -110,7 +112,7 @@ private void setBoat() { final Predicate filter = entity -> entity != this.player - && entity.getType() != EntityType.DROPPED_ITEM; + && entity.getType() != EntityType.ITEM; final RayTraceResult rayTraceEntities = this.world.rayTraceEntities(eyeLocation, eyeLocation.getDirection(), 4.5d, 0.1d, filter); final RayTraceResult rayTraceBlocks = this.world.rayTraceBlocks(eyeLocation, eyeLocation.getDirection(), 4.5d); @@ -121,7 +123,7 @@ private void setBoat() { final Location summonLocation = rayTraceBlocks.getHitPosition().toLocation(this.world); for (final var nearbyEntity : this.world.getNearbyEntities(summonLocation, 0.5d, 0.5d, 0.5d)) { - if (nearbyEntity.getType() != EntityType.DROPPED_ITEM) { + if (nearbyEntity.getType() != EntityType.ITEM) { return; } } @@ -194,7 +196,7 @@ private boolean checkForEntities() { final Predicate filter = entity -> entity != this.player - && entity.getType() != EntityType.DROPPED_ITEM; + && entity.getType() != EntityType.ITEM; final RayTraceResult rayTraceResult = this.world.rayTraceEntities(eyeLocation, eyeLocation.getDirection(), 4.5d, 0.1d, filter); if (rayTraceResult == null) { diff --git a/paper/src/main/resources/paper-plugin.yml b/platform/paper/src/main/resources/paper-plugin.yml similarity index 95% rename from paper/src/main/resources/paper-plugin.yml rename to platform/paper/src/main/resources/paper-plugin.yml index 94508216..bb6b17fb 100644 --- a/paper/src/main/resources/paper-plugin.yml +++ b/platform/paper/src/main/resources/paper-plugin.yml @@ -2,7 +2,7 @@ name: $name version: $version description: $description -author: [ $author ] +author: $author contributors: [ $contributors ] website: $website diff --git a/paper/src/main/resources/players/console.yml b/platform/paper/src/main/resources/players/console.yml similarity index 100% rename from paper/src/main/resources/players/console.yml rename to platform/paper/src/main/resources/players/console.yml diff --git a/paper/src/test/java/com/minersstudios/whomine/test/Main.java b/platform/paper/src/test/java/com/minersstudios/whomine/test/Main.java similarity index 100% rename from paper/src/test/java/com/minersstudios/whomine/test/Main.java rename to platform/paper/src/test/java/com/minersstudios/whomine/test/Main.java diff --git a/platform/velocity/build.gradle.kts b/platform/velocity/build.gradle.kts new file mode 100644 index 00000000..6784afa1 --- /dev/null +++ b/platform/velocity/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("whomine.platform") + id("whomine.velocitypowered") +} + +dependencies { + api(Libs.Velocity.asProject(rootProject)) + + runtimeClasspath(libs.asm.api) + runtimeClasspath(libs.asm.commons) + runtimeClasspath(libs.fastutil) + runtimeClasspath(libs.google.guava) + runtimeClasspath(libs.google.gson) + runtimeClasspath(libs.google.jsr305) + runtimeClasspath(libs.jackson.annotations) + runtimeClasspath(libs.jda) + runtimeClasspath(libs.jetbrains.annotations) + runtimeClasspath(libs.netty.buffer) +} diff --git a/platform/velocity/src/main/java/com/minersstudios/whomine/WhoMineImpl.java b/platform/velocity/src/main/java/com/minersstudios/whomine/WhoMineImpl.java new file mode 100644 index 00000000..5e7400f3 --- /dev/null +++ b/platform/velocity/src/main/java/com/minersstudios/whomine/WhoMineImpl.java @@ -0,0 +1,126 @@ +package com.minersstudios.whomine; + +import com.minersstudios.wholib.annotation.Resource; +import com.minersstudios.wholib.status.StatusHandler; +import com.minersstudios.wholib.velocity.VelocityCache; +import com.minersstudios.wholib.velocity.VelocityConfig; +import com.minersstudios.wholib.velocity.WhoMine; +import com.minersstudios.wholib.velocity.discord.DiscordModuleImpl; +import com.minersstudios.wholib.velocity.gui.VelocityGuiManager; +import com.minersstudios.wholib.velocity.listener.VelocityListenerManager; +import com.minersstudios.whomine.listener.player.PlayerChatListener; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.plugin.annotation.DataDirectory; +import com.velocitypowered.api.proxy.ProxyServer; +import org.jetbrains.annotations.NotNull; + +import javax.inject.Inject; +import java.nio.file.Path; +import java.util.logging.Logger; + +import static com.minersstudios.wholib.utility.ProjectInfo.*; + +@Plugin( + id = Resource.WHOMINE, + name = NAME, + version = VERSION, + description = DESCRIPTION, + url = WEBSITE, + authors = { AUTHOR } +) +public final class WhoMineImpl implements WhoMine { + + private final ProxyServer server; + private final Logger logger; + private final @DataDirectory Path dataDirectory; + + private final StatusHandler statusHandler; + private final VelocityCache cache; + private final VelocityConfig config; + private final VelocityListenerManager listenerManager; + private final VelocityGuiManager guiManager; + private final DiscordModuleImpl discordModule; + + @Inject + public WhoMineImpl( + final @NotNull ProxyServer server, + final @NotNull Logger logger, + final @NotNull @DataDirectory Path dataDirectory + ) { + this.server = server; + this.logger = logger; + this.dataDirectory = dataDirectory; + + this.statusHandler = new StatusHandler(); + this.cache = new VelocityCache(this); + this.config = new VelocityConfig(this); + this.listenerManager = new VelocityListenerManager(this); + this.guiManager = new VelocityGuiManager(this); + this.discordModule = new DiscordModuleImpl(); + } + + @Override + public @NotNull ProxyServer getServer() { + return this.server; + } + + @Override + public @NotNull Logger getLogger() { + return this.logger; + } + + @Override + public @NotNull Path getDataDirectory() { + return this.dataDirectory; + } + + @Override + public @NotNull StatusHandler getStatusHandler() { + return this.statusHandler; + } + + @Override + public @NotNull VelocityCache getCache() { + return this.cache; + } + + @Override + public @NotNull VelocityConfig getConfiguration() { + return this.config; + } + + @Override + public @NotNull VelocityListenerManager getListenerManager() { + return this.listenerManager; + } + + @Override + public @NotNull VelocityGuiManager getGuiManager() { + return this.guiManager; + } + + @Override + public @NotNull DiscordModuleImpl getDiscordModule() { + return this.discordModule; + } + + @Override + public boolean isFullyLoaded() { + return true; + } + + @Subscribe + public void onProxyInitialize(final @NotNull ProxyInitializeEvent ignored) { + this.bootstrap(); + } + + private void bootstrap() { + // + + this.listenerManager.register(new PlayerChatListener()); + + // + } +} diff --git a/platform/velocity/src/main/java/com/minersstudios/whomine/listener/player/PlayerChatListener.java b/platform/velocity/src/main/java/com/minersstudios/whomine/listener/player/PlayerChatListener.java new file mode 100644 index 00000000..816a83f6 --- /dev/null +++ b/platform/velocity/src/main/java/com/minersstudios/whomine/listener/player/PlayerChatListener.java @@ -0,0 +1,23 @@ +package com.minersstudios.whomine.listener.player; + +import com.minersstudios.wholib.event.EventOrder; +import com.minersstudios.wholib.event.handle.AsyncHandler; +import com.minersstudios.wholib.listener.ListenFor; +import com.minersstudios.wholib.velocity.event.VelocityEventContainer; +import com.minersstudios.wholib.velocity.event.VelocityEventListener; +import com.velocitypowered.api.event.player.PlayerChatEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.logging.Level; + +@ListenFor(PlayerChatEvent.class) +public class PlayerChatListener extends VelocityEventListener { + + @AsyncHandler(order = EventOrder.CUSTOM) + public void onPlayerChat(final @NotNull VelocityEventContainer container) { + container.getModule().getLogger().log( + Level.INFO, + container.getEvent().getPlayer().getUsername() + " : " + container.getEvent().getMessage() + ); + } +} diff --git a/platform/velocity/src/test/java/com/minersstudios/whomine/test/Main.java b/platform/velocity/src/test/java/com/minersstudios/whomine/test/Main.java new file mode 100644 index 00000000..666db391 --- /dev/null +++ b/platform/velocity/src/test/java/com/minersstudios/whomine/test/Main.java @@ -0,0 +1,8 @@ +package com.minersstudios.whomine.test; + +public final class Main { + + public static void main(final String[] args) { + System.out.println("Hello, Lays!"); + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 23dfa0c3..043e3ce6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,30 @@ +@file:Suppress("UnstableApiUsage") + +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + +pluginManagement { + includeBuild("build-logic") +} + rootProject.name = "WhoMine" -include( - "paper", - "common" -) +includeLib("common") +includeLib("paper") +includeLib("velocity") + +includePlatform("paper") +includePlatform("velocity") + +fun Settings.includeLib(libName: String) { + val path = ":WhoLib-$libName" + + include(path) + project(path).projectDir = File("lib/${libName}") +} + +fun Settings.includePlatform(platformName: String) { + val path = ":WhoMine-$platformName" + + include(path) + project(path).projectDir = File("platform/$platformName") +}