From 5a62053b5d5f5f23560ab940fceeaf73064971c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ampflower=20=F0=9F=8C=BA?= Date: Wed, 7 Jul 2021 00:57:38 -0700 Subject: [PATCH 1/2] Add Spotless --- .internal/license-header.java | 5 +++++ build.gradle.kts | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 .internal/license-header.java diff --git a/.internal/license-header.java b/.internal/license-header.java new file mode 100644 index 0000000..6fd1aa6 --- /dev/null +++ b/.internal/license-header.java @@ -0,0 +1,5 @@ +/* Copyright (c) $YEAR Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index b10b657..021568a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,7 @@ plugins { id("fabric-loom") `maven-publish` id("io.github.juuxel.loom-quiltflower") + id("com.diffplug.spotless") } val minecraft_version: String by project @@ -44,6 +45,20 @@ dependencies { modImplementation("me.lucko", "fabric-permissions-api", fabric_permissions_version) } +spotless { + java { + importOrder() + removeUnusedImports() + + licenseHeaderFile(rootDir.resolve(".internal/license-header.java")) + } + kotlinGradle { + target("*.gradle.kts", "ply-*/*.gradle.kts") + ktfmt().googleStyle() + licenseHeaderFile(rootDir.resolve(".internal/license-header.java"), "import \\w+(\\.\\w+)*|plugins\\s*\\{") + } +} + tasks { withType { options.encoding = "UTF-8" From b4bae7d1ece0808f9d048bfad14119b5f5dc81eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ampflower=20=F0=9F=8C=BA?= Date: Tue, 13 Jul 2021 01:19:33 -0700 Subject: [PATCH 2/2] Pilot; dev branch requires refactoring --- .internal/license-header.java | 3 +- .internal/spotless.importorder | 8 + .internal/spotless.xml | 457 ++++++++++++++++++ build.gradle.kts | 66 +-- ply-anti-xray/build.gradle.kts | 41 +- ply-common/build.gradle.kts | 42 +- ply-database/build.gradle.kts | 45 +- ply-debug/build.gradle.kts | 41 +- ply-locking/build.gradle.kts | 41 +- ply-tracker/build.gradle.kts | 46 +- settings.gradle.kts | 16 +- .../java/gay/ampflower/helium/Helium.java | 21 +- .../helium/commands/HotspotCommand.java | 68 +++ .../commands/InventoryLookupCommand.java | 37 +- .../helium/commands/MappingCommand.java | 9 +- .../helium/mixins/AccessorMapState.java | 6 + .../helium/mixins/AccessorPlayerEntity.java | 6 + .../helium/mixins/MixinCommandManager.java | 9 +- 18 files changed, 795 insertions(+), 167 deletions(-) create mode 100644 .internal/spotless.importorder create mode 100644 .internal/spotless.xml create mode 100644 src/main/java/gay/ampflower/helium/commands/HotspotCommand.java diff --git a/.internal/license-header.java b/.internal/license-header.java index 6fd1aa6..921c123 100644 --- a/.internal/license-header.java +++ b/.internal/license-header.java @@ -2,4 +2,5 @@ * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ \ No newline at end of file + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + diff --git a/.internal/spotless.importorder b/.internal/spotless.importorder new file mode 100644 index 0000000..2f744df --- /dev/null +++ b/.internal/spotless.importorder @@ -0,0 +1,8 @@ +#Organize Import Order +#Wed Jul 07 02:53:11 PDT 2021 +0= +1=java +2=javax +3=\# +4=\#java +5=\#javax diff --git a/.internal/spotless.xml b/.internal/spotless.xml new file mode 100644 index 0000000..1e70965 --- /dev/null +++ b/.internal/spotless.xml @@ -0,0 +1,457 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.gradle.kts b/build.gradle.kts index 021568a..13bc8bd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + import java.net.URI plugins { @@ -22,11 +28,14 @@ val isActions = System.getenv("GITHUB_ACTIONS").toBoolean() val baseVersion: String = "$project_version+mc.$minecraft_version" group = "gay.ampflower" -version = when { - isRelease -> baseVersion - isActions -> "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" - else -> "$baseVersion-build.local" -} + +version = + when { + isRelease -> baseVersion + isActions -> + "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" + else -> "$baseVersion-build.local" + } java { sourceCompatibility = JavaVersion.VERSION_16 @@ -47,15 +56,16 @@ dependencies { spotless { java { - importOrder() - removeUnusedImports() + importOrderFile(rootDir.resolve(".internal/spotless.importorder")) + eclipse().configFile(rootDir.resolve(".internal/spotless.xml")) licenseHeaderFile(rootDir.resolve(".internal/license-header.java")) } kotlinGradle { target("*.gradle.kts", "ply-*/*.gradle.kts") - ktfmt().googleStyle() - licenseHeaderFile(rootDir.resolve(".internal/license-header.java"), "import \\w+(\\.\\w+)*|plugins\\s*\\{") + ktfmt().dropboxStyle() + licenseHeaderFile( + rootDir.resolve(".internal/license-header.java"), "(import|plugins|rootProject)") } } @@ -65,27 +75,24 @@ tasks { options.isDeprecation = true options.isWarnings = true } - val sourcesJar = register("sourcesJar") { - dependsOn("classes") - archiveClassifier.set("sources") - from(sourceSets.main.get().allSource) - } + val sourcesJar = + register("sourcesJar") { + dependsOn("classes") + archiveClassifier.set("sources") + from(sourceSets.main.get().allSource) + } processResources { - val map = mapOf( - "version" to project.version, - "project_version" to project_version, - "loader_version" to loader_version, - "minecraft_required" to project.property("minecraft_required")?.toString() - ) + val map = + mapOf( + "version" to project.version, + "project_version" to project_version, + "loader_version" to loader_version, + "minecraft_required" to project.property("minecraft_required")?.toString()) inputs.properties(map) - filesMatching("fabric.mod.json") { - expand(map) - } - } - withType { - from("LICENSE") + filesMatching("fabric.mod.json") { expand(map) } } + withType { from("LICENSE") } register("poolBuilds") { dependsOn(build) if (isPublish) { @@ -97,11 +104,14 @@ tasks { } else { for (p in subprojects) { if (p.name == "ply-debug" || !p.name.startsWith("ply-")) continue - from(p.tasks.jar, p.tasks.remapJar, p.tasks.getByName("sourcesJar"), p.tasks.remapSourcesJar) + from( + p.tasks.jar, + p.tasks.remapJar, + p.tasks.getByName("sourcesJar"), + p.tasks.remapSourcesJar) } from(jar, remapJar, sourcesJar, remapSourcesJar) } into(project.buildDir.resolve("pool")) } } - diff --git a/ply-anti-xray/build.gradle.kts b/ply-anti-xray/build.gradle.kts index 73fd3f5..836b747 100644 --- a/ply-anti-xray/build.gradle.kts +++ b/ply-anti-xray/build.gradle.kts @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + import com.modrinth.minotaur.TaskModrinthUpload import java.net.URI @@ -21,11 +27,14 @@ val isActions = System.getenv("GITHUB_ACTIONS").toBoolean() val baseVersion: String = "$project_version+mc.$minecraft_version" group = "gay.ampflower" -version = when { - isRelease -> baseVersion - isActions -> "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" - else -> "$baseVersion-build.local" -} + +version = + when { + isRelease -> baseVersion + isActions -> + "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" + else -> "$baseVersion-build.local" + } repositories { maven { url = URI.create("https://oss.sonatype.org/content/repositories/snapshots") } @@ -58,21 +67,17 @@ tasks { from(sourceSets.main.get().allSource) } processResources { - val map = mapOf( - "version" to project.version, - "project_version" to project_version, - "loader_version" to loader_version, - "minecraft_required" to project.property("minecraft_required")?.toString() - ) + val map = + mapOf( + "version" to project.version, + "project_version" to project_version, + "loader_version" to loader_version, + "minecraft_required" to project.property("minecraft_required")?.toString()) inputs.properties(map) - filesMatching("fabric.mod.json") { - expand(map) - } - } - withType { - from("LICENSE") + filesMatching("fabric.mod.json") { expand(map) } } + withType { from("LICENSE") } register("publishModrinth") { token = System.getenv("MODRINTH_TOKEN") projectId = modrinth_id @@ -82,4 +87,4 @@ tasks { addGameVersion(minecraft_version) addLoader("fabric") } -} \ No newline at end of file +} diff --git a/ply-common/build.gradle.kts b/ply-common/build.gradle.kts index 1d49bfd..c232dad 100644 --- a/ply-common/build.gradle.kts +++ b/ply-common/build.gradle.kts @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + import java.net.URI plugins { @@ -18,11 +24,14 @@ val isActions = System.getenv("GITHUB_ACTIONS").toBoolean() val baseVersion: String = "$project_version+mc.$minecraft_version" group = "gay.ampflower" -version = when { - isRelease -> baseVersion - isActions -> "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" - else -> "$baseVersion-build.local" -} + +version = + when { + isRelease -> baseVersion + isActions -> + "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" + else -> "$baseVersion-build.local" + } repositories { maven { url = URI.create("https://oss.sonatype.org/content/repositories/snapshots") } @@ -33,6 +42,7 @@ dependencies { mappings("net.fabricmc", "yarn", yarn_mappings, classifier = "v2") modImplementation("net.fabricmc", "fabric-loader", loader_version) } + java { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 @@ -50,19 +60,15 @@ tasks { from(sourceSets.main.get().allSource) } processResources { - val map = mapOf( - "version" to project.version, - "project_version" to project_version, - "loader_version" to loader_version, - "minecraft_required" to project.property("minecraft_required")?.toString() - ) + val map = + mapOf( + "version" to project.version, + "project_version" to project_version, + "loader_version" to loader_version, + "minecraft_required" to project.property("minecraft_required")?.toString()) inputs.properties(map) - filesMatching("fabric.mod.json") { - expand(map) - } - } - withType { - from("LICENSE") + filesMatching("fabric.mod.json") { expand(map) } } -} \ No newline at end of file + withType { from("LICENSE") } +} diff --git a/ply-database/build.gradle.kts b/ply-database/build.gradle.kts index 4689c9a..c240ac5 100644 --- a/ply-database/build.gradle.kts +++ b/ply-database/build.gradle.kts @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + import java.net.URI plugins { @@ -20,11 +26,14 @@ val isActions = System.getenv("GITHUB_ACTIONS").toBoolean() val baseVersion: String = "$project_version+mc.$minecraft_version" group = "gay.ampflower" -version = when { - isRelease -> baseVersion - isActions -> "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" - else -> "$baseVersion-build.local" -} + +version = + when { + isRelease -> baseVersion + isActions -> + "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" + else -> "$baseVersion-build.local" + } repositories { maven { url = URI.create("https://oss.sonatype.org/content/repositories/snapshots") } @@ -56,23 +65,17 @@ tasks { archiveClassifier.set("sources") from(sourceSets.main.get().allSource) } - remapJar { - dependsOn(":utilities:jar") - } + remapJar { dependsOn(":utilities:jar") } processResources { - val map = mapOf( - "version" to project.version, - "project_version" to project_version, - "loader_version" to loader_version, - "minecraft_required" to project.property("minecraft_required")?.toString() - ) + val map = + mapOf( + "version" to project.version, + "project_version" to project_version, + "loader_version" to loader_version, + "minecraft_required" to project.property("minecraft_required")?.toString()) inputs.properties(map) - filesMatching("fabric.mod.json") { - expand(map) - } - } - withType { - from("LICENSE") + filesMatching("fabric.mod.json") { expand(map) } } -} \ No newline at end of file + withType { from("LICENSE") } +} diff --git a/ply-debug/build.gradle.kts b/ply-debug/build.gradle.kts index d47e507..7d6a3cf 100644 --- a/ply-debug/build.gradle.kts +++ b/ply-debug/build.gradle.kts @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + import java.net.URI plugins { @@ -20,11 +26,14 @@ val isActions = System.getenv("GITHUB_ACTIONS").toBoolean() val baseVersion: String = "$project_version+mc.$minecraft_version" group = "gay.ampflower" -version = when { - isRelease -> baseVersion - isActions -> "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" - else -> "$baseVersion-build.local" -} + +version = + when { + isRelease -> baseVersion + isActions -> + "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" + else -> "$baseVersion-build.local" + } repositories { maven { url = URI.create("https://oss.sonatype.org/content/repositories/snapshots") } @@ -61,19 +70,15 @@ tasks { from(sourceSets.main.get().allSource) } processResources { - val map = mapOf( - "version" to project.version, - "project_version" to project_version, - "loader_version" to loader_version, - "minecraft_required" to project.property("minecraft_required")?.toString() - ) + val map = + mapOf( + "version" to project.version, + "project_version" to project_version, + "loader_version" to loader_version, + "minecraft_required" to project.property("minecraft_required")?.toString()) inputs.properties(map) - filesMatching("fabric.mod.json") { - expand(map) - } - } - withType { - from("LICENSE") + filesMatching("fabric.mod.json") { expand(map) } } -} \ No newline at end of file + withType { from("LICENSE") } +} diff --git a/ply-locking/build.gradle.kts b/ply-locking/build.gradle.kts index b46d193..28e079f 100644 --- a/ply-locking/build.gradle.kts +++ b/ply-locking/build.gradle.kts @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + import java.net.URI plugins { @@ -20,11 +26,14 @@ val isActions = System.getenv("GITHUB_ACTIONS").toBoolean() val baseVersion: String = "$project_version+mc.$minecraft_version" group = "gay.ampflower" -version = when { - isRelease -> baseVersion - isActions -> "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" - else -> "$baseVersion-build.local" -} + +version = + when { + isRelease -> baseVersion + isActions -> + "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" + else -> "$baseVersion-build.local" + } repositories { maven { url = URI.create("https://oss.sonatype.org/content/repositories/snapshots") } @@ -57,19 +66,15 @@ tasks { from(sourceSets.main.get().allSource) } processResources { - val map = mapOf( - "version" to project.version, - "project_version" to project_version, - "loader_version" to loader_version, - "minecraft_required" to project.property("minecraft_required")?.toString() - ) + val map = + mapOf( + "version" to project.version, + "project_version" to project_version, + "loader_version" to loader_version, + "minecraft_required" to project.property("minecraft_required")?.toString()) inputs.properties(map) - filesMatching("fabric.mod.json") { - expand(map) - } - } - withType { - from("LICENSE") + filesMatching("fabric.mod.json") { expand(map) } } -} \ No newline at end of file + withType { from("LICENSE") } +} diff --git a/ply-tracker/build.gradle.kts b/ply-tracker/build.gradle.kts index dd748a2..ac377fa 100644 --- a/ply-tracker/build.gradle.kts +++ b/ply-tracker/build.gradle.kts @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + import java.net.URI plugins { @@ -21,11 +27,14 @@ val isActions = System.getenv("GITHUB_ACTIONS").toBoolean() val baseVersion: String = "$project_version+mc.$minecraft_version" group = "gay.ampflower" -version = when { - isRelease -> baseVersion - isActions -> "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" - else -> "$baseVersion-build.local" -} + +version = + when { + isRelease -> baseVersion + isActions -> + "$baseVersion-build.${System.getenv("GITHUB_RUN_NUMBER")}-commit.${System.getenv("GITHUB_SHA").substring(0, 7)}-branch.${System.getenv("GITHUB_REF")?.substring(11)?.replace('/', '.') ?: "unknown"}" + else -> "$baseVersion-build.local" + } repositories { maven { url = URI.create("https://oss.sonatype.org/content/repositories/snapshots") } @@ -35,7 +44,10 @@ dependencies { minecraft("com.mojang", "minecraft", minecraft_version) mappings("net.fabricmc", "yarn", yarn_mappings, classifier = "v2") modImplementation("net.fabricmc", "fabric-loader", loader_version) - modImplementation(fabricApi.module("fabric-command-api-v1", fabric_api_version)) { include(this) } + modImplementation(fabricApi.module("fabric-command-api-v1", fabric_api_version)) { + include(this) + } + api(project(":utilities")) { include(this) } implementation(project(":ply-database")) implementation(project(":utilities")) { include(this) } // implementation(project(":commander")) { include(this) } @@ -59,19 +71,15 @@ tasks { from(sourceSets.main.get().allSource) } processResources { - val map = mapOf( - "version" to project.version, - "project_version" to project_version, - "loader_version" to loader_version, - "minecraft_required" to project.property("minecraft_required")?.toString() - ) + val map = + mapOf( + "version" to project.version, + "project_version" to project_version, + "loader_version" to loader_version, + "minecraft_required" to project.property("minecraft_required")?.toString()) inputs.properties(map) - filesMatching("fabric.mod.json") { - expand(map) - } - } - withType { - from("LICENSE") + filesMatching("fabric.mod.json") { expand(map) } } -} \ No newline at end of file + withType { from("LICENSE") } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 4fda258..d1dd107 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + rootProject.name = "plymouth" pluginManagement { @@ -20,4 +26,12 @@ pluginManagement { } } -include("utilities", "database", "ply-common", "ply-anti-xray", "ply-locking", "ply-tracker", "ply-database", "ply-debug") \ No newline at end of file +include( + "utilities", + "database", + "ply-common", + "ply-anti-xray", + "ply-locking", + "ply-tracker", + "ply-database", + "ply-debug") diff --git a/src/main/java/gay/ampflower/helium/Helium.java b/src/main/java/gay/ampflower/helium/Helium.java index fd7b231..4d474b1 100644 --- a/src/main/java/gay/ampflower/helium/Helium.java +++ b/src/main/java/gay/ampflower/helium/Helium.java @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + package gay.ampflower.helium; import com.mojang.datafixers.DataFixer; @@ -18,24 +24,24 @@ import static net.minecraft.util.Formatting.*; /** - * This class is a late-init-type class. It's expecting that - * by the time that it's called, all blocks would have been - * registered. + * This class is a late-init-type class. It's expecting that by the time that + * it's called, all blocks would have been registered. * * @author Ampflower * @since ${version} */ public class Helium { public static final Style LINK = Style.EMPTY.withFormatting(AQUA, UNDERLINE); - public static final Text - SEE_LOGS = new LiteralText("See the server logs for more information.").formatted(ITALIC), + public static final Text SEE_LOGS = new LiteralText("See the server logs for more information.") + .formatted(ITALIC), DID_YOU_MEAN = new TranslatableText("plymouth.dym", new KeybindText("key.inventory").formatted(AQUA)) .formatted(ITALIC, RED), ENDER_CHEST = new TranslatableText(Blocks.ENDER_CHEST.getTranslationKey()).formatted(DARK_PURPLE); public static final Logger logger = LogManager.getLogger("Plymouth"); /** - * [vanilla-copy] {@link net.minecraft.world.PersistentStateManager#readNbt(String, int)} + * [vanilla-copy] + * {@link net.minecraft.world.PersistentStateManager#readNbt(String, int)} * * @param stream Stream to read NBT data from. * @param dfu Server's DataFixer @@ -58,7 +64,8 @@ public static NbtCompound readTag(InputStream stream, DataFixer dfu, int dataVer } /** - * [vanilla-copy] {@link net.minecraft.world.PersistentStateManager#isCompressed(PushbackInputStream)} + * [vanilla-copy] + * {@link net.minecraft.world.PersistentStateManager#isCompressed(PushbackInputStream)} */ public static boolean isCompressed(PushbackInputStream pushback) throws IOException { byte[] bytes = new byte[2]; diff --git a/src/main/java/gay/ampflower/helium/commands/HotspotCommand.java b/src/main/java/gay/ampflower/helium/commands/HotspotCommand.java new file mode 100644 index 0000000..cc7f3e5 --- /dev/null +++ b/src/main/java/gay/ampflower/helium/commands/HotspotCommand.java @@ -0,0 +1,68 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +package gay.ampflower.helium.commands; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import me.lucko.fabric.api.permissions.v0.Permissions; +import net.minecraft.entity.EntityType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; + +import java.util.HashMap; +import java.util.function.Predicate; + +import static net.minecraft.server.command.CommandManager.literal; + +/** + * @author Ampflower + * @since ${version} + **/ +public class HotspotCommand { + public static final Predicate REQUIRE_HOTSPOT_PERMISSION = Permissions + .require("plymouth.admin.moderation.hotspot", 2); + + public static void register(CommandDispatcher dispatcher) { + dispatcher.register(literal("hotspot").requires(REQUIRE_HOTSPOT_PERMISSION) + .then(literal("entities").executes(HotspotCommand::entities))); + } + + private static int entities(CommandContext context) { + var primary = new HashMap, Long2ObjectOpenHashMap>(); + var source = context.getSource(); + var server = source.getMinecraftServer(); + for (var world : server.getWorlds()) { + primary.clear(); + for (var entity : world.iterateEntities()) { + primary.computeIfAbsent(entity.getType(), $0 -> new Long2ObjectOpenHashMap<>()) + .computeIfAbsent(packBlockPosAsChunkPos(entity.getBlockPos()), $0 -> new EntityRecord()) + .add(entity.getPos()); + } + + } + return Command.SINGLE_SUCCESS; + } + + private static long packBlockPosAsChunkPos(BlockPos pos) { + return BlockPos.asLong(pos.getX() >> 4, pos.getY() >> 4, pos.getZ() >> 4); + } + + private static class EntityRecord { + double x, y, z; + int c; + + void add(Vec3d v) { + x += v.x; + y += v.y; + z += v.z; + c++; + } + } +} diff --git a/src/main/java/gay/ampflower/helium/commands/InventoryLookupCommand.java b/src/main/java/gay/ampflower/helium/commands/InventoryLookupCommand.java index 0f769b4..c6fd289 100644 --- a/src/main/java/gay/ampflower/helium/commands/InventoryLookupCommand.java +++ b/src/main/java/gay/ampflower/helium/commands/InventoryLookupCommand.java @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + package gay.ampflower.helium.commands; import com.mojang.brigadier.Command; @@ -20,26 +26,27 @@ import static net.minecraft.server.command.CommandManager.literal; /** - * Player inventory lookup. Does not do offline players, only those that are online at the time. + * Player inventory lookup. Does not do offline players, only those that are + * online at the time. * * @author Ampflower * @since 0.0.0 **/ public class InventoryLookupCommand { - public static final Predicate - REQUIRE_INVSEE_PERMISSION = Permissions.require("helium.admin.moderation.invsee", 3), + public static final Predicate REQUIRE_INVSEE_PERMISSION = Permissions + .require("helium.admin.moderation.invsee", 3), REQUIRE_ENDSEE_PERMISSION = Permissions.require("helium.admin.moderation.endsee", 3); public static void register(CommandDispatcher dispatcher) { - var e0 = argument("target", player()) - .requires(REQUIRE_ENDSEE_PERMISSION).executes(s -> { - var p = getPlayer(s, "target"); - var sp = s.getSource().getPlayer(); - sp.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, pi, pe) -> - GenericContainerScreenHandler.createGeneric9x3(i, pi, p.getEnderChestInventory()), - p.getDisplayName().shallowCopy().append(" - ").append(Helium.ENDER_CHEST))); - return Command.SINGLE_SUCCESS; - }); + var e0 = argument("target", player()).requires(REQUIRE_ENDSEE_PERMISSION).executes(s -> { + var p = getPlayer(s, "target"); + var sp = s.getSource().getPlayer(); + sp.openHandledScreen(new SimpleNamedScreenHandlerFactory( + (i, pi, pe) -> GenericContainerScreenHandler.createGeneric9x3(i, pi, p.getEnderChestInventory()), + p.getDisplayName().shallowCopy().append(" - ") + .append(Helium.ENDER_CHEST))); + return Command.SINGLE_SUCCESS; + }); var p0 = argument("target", player()).requires(REQUIRE_INVSEE_PERMISSION).executes(s -> { var p = getPlayer(s, "target"); @@ -47,9 +54,9 @@ public static void register(CommandDispatcher dispatcher) { if (sp.equals(p)) { sp.sendSystemMessage(Helium.DID_YOU_MEAN, Util.NIL_UUID); } else { - // TODO: Replace with a better screen handler that accounts for hidden player inventory. - sp.openHandledScreen(new SimpleNamedScreenHandlerFactory((i, pi, pe) -> - new GenericContainerScreenHandler(ScreenHandlerType.GENERIC_9X4, i, pi, ((AccessorPlayerEntity) p).getInventory(), 4) { + sp.openHandledScreen(new SimpleNamedScreenHandlerFactory( + (i, pi, pe) -> new GenericContainerScreenHandler(ScreenHandlerType.GENERIC_9X4, i, pi, + ((AccessorPlayerEntity) p).getInventory(), 4) { @Override public boolean canUse(PlayerEntity player) { return true; diff --git a/src/main/java/gay/ampflower/helium/commands/MappingCommand.java b/src/main/java/gay/ampflower/helium/commands/MappingCommand.java index f351cee..8583e28 100644 --- a/src/main/java/gay/ampflower/helium/commands/MappingCommand.java +++ b/src/main/java/gay/ampflower/helium/commands/MappingCommand.java @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + package gay.ampflower.helium.commands; import com.mojang.brigadier.Command; @@ -28,8 +34,7 @@ * @since 0.0.0 **/ public class MappingCommand { - public static final Predicate - REQUIRE_MAPPING_PERMISSION = scs -> scs.hasPermissionLevel(3); + public static final Predicate REQUIRE_MAPPING_PERMISSION = scs -> scs.hasPermissionLevel(3); public static void register(CommandDispatcher dispatcher) { var m0 = argument("id", IntegerArgumentType.integer()) diff --git a/src/main/java/gay/ampflower/helium/mixins/AccessorMapState.java b/src/main/java/gay/ampflower/helium/mixins/AccessorMapState.java index 60108a3..ebd53e8 100644 --- a/src/main/java/gay/ampflower/helium/mixins/AccessorMapState.java +++ b/src/main/java/gay/ampflower/helium/mixins/AccessorMapState.java @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + package gay.ampflower.helium.mixins; import net.minecraft.item.map.MapState; diff --git a/src/main/java/gay/ampflower/helium/mixins/AccessorPlayerEntity.java b/src/main/java/gay/ampflower/helium/mixins/AccessorPlayerEntity.java index b347b79..f77b6af 100644 --- a/src/main/java/gay/ampflower/helium/mixins/AccessorPlayerEntity.java +++ b/src/main/java/gay/ampflower/helium/mixins/AccessorPlayerEntity.java @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + package gay.ampflower.helium.mixins; import net.minecraft.entity.player.PlayerEntity; diff --git a/src/main/java/gay/ampflower/helium/mixins/MixinCommandManager.java b/src/main/java/gay/ampflower/helium/mixins/MixinCommandManager.java index daa6cd8..1b1f4ab 100644 --- a/src/main/java/gay/ampflower/helium/mixins/MixinCommandManager.java +++ b/src/main/java/gay/ampflower/helium/mixins/MixinCommandManager.java @@ -1,3 +1,9 @@ +/* Copyright (c) 2021 Ampflower + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + package gay.ampflower.helium.mixins; import com.mojang.brigadier.CommandDispatcher; @@ -28,7 +34,8 @@ public abstract class MixinCommandManager { } @Inject(method = "execute(Lnet/minecraft/server/command/ServerCommandSource;Ljava/lang/String;)I", at = @At("HEAD")) - public void helium$execute$logCommandExecution(ServerCommandSource source, String str, CallbackInfoReturnable cbir) { + public void helium$execute$logCommandExecution(ServerCommandSource source, String str, + CallbackInfoReturnable cbir) { Helium.logger.info("{} has executed the following command: {}", source.getName(), str); } }