From b7a6f522cafb97b8e518b14601476e5fe12b5781 Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Mon, 23 Jun 2025 22:38:37 +0100 Subject: [PATCH 01/63] Set version to 10.2.0-SNAPSHOT --- commandapi-annotations/pom.xml | 2 +- commandapi-core/pom.xml | 2 +- commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml | 2 +- commandapi-kotlin/commandapi-core-kotlin/pom.xml | 2 +- commandapi-kotlin/commandapi-velocity-kotlin/pom.xml | 2 +- commandapi-kotlin/pom.xml | 2 +- .../commandapi-bukkit/commandapi-bukkit-core/pom.xml | 2 +- .../commandapi-bukkit-mojang-mapped/pom.xml | 2 +- .../commandapi-bukkit-networking-plugin/pom.xml | 2 +- .../commandapi-bukkit-1.20.2/pom.xml | 2 +- .../commandapi-bukkit-1.20.3/pom.xml | 2 +- .../commandapi-bukkit-1.20.5/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml | 2 +- .../commandapi-bukkit-1.21.2/pom.xml | 2 +- .../commandapi-bukkit-1.21.4/pom.xml | 2 +- .../commandapi-bukkit-1.21.5/pom.xml | 2 +- .../commandapi-bukkit-1.21.6/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml | 2 +- .../commandapi-bukkit-nms-common/pom.xml | 2 +- .../pom.xml | 2 +- .../commandapi-bukkit-nms-dependency/pom.xml | 2 +- .../commandapi-bukkit/commandapi-bukkit-nms/pom.xml | 2 +- .../commandapi-bukkit-plugin-common/pom.xml | 2 +- .../commandapi-bukkit-plugin-mojang-mapped/pom.xml | 2 +- .../commandapi-bukkit/commandapi-bukkit-plugin/pom.xml | 2 +- .../commandapi-bukkit-shade-mojang-mapped/pom.xml | 2 +- .../commandapi-bukkit/commandapi-bukkit-shade/pom.xml | 2 +- .../commandapi-bukkit-test-toolkit/pom.xml | 2 +- .../commandapi-bukkit-test-impl-1.20.2/pom.xml | 2 +- .../commandapi-bukkit-test-impl-1.20.3/pom.xml | 2 +- .../commandapi-bukkit-test-impl-1.20.5/pom.xml | 2 +- .../commandapi-bukkit-test-impl-1.20/pom.xml | 2 +- .../commandapi-bukkit-test-impl/pom.xml | 2 +- .../commandapi-bukkit/commandapi-bukkit-test/pom.xml | 2 +- .../commandapi-bukkit/commandapi-bukkit-vh/pom.xml | 2 +- commandapi-platforms/commandapi-bukkit/pom.xml | 2 +- .../commandapi-sponge/commandapi-sponge-core/pom.xml | 2 +- .../commandapi-sponge-plugin-test/pom.xml | 2 +- .../commandapi-sponge/commandapi-sponge-plugin/pom.xml | 2 +- .../commandapi-sponge/commandapi-sponge-shade/pom.xml | 2 +- commandapi-platforms/commandapi-sponge/pom.xml | 2 +- .../commandapi-velocity/commandapi-velocity-core/pom.xml | 2 +- .../commandapi-velocity-plugin-test/pom.xml | 2 +- .../commandapi-velocity-plugin/pom.xml | 2 +- .../commandapi-velocity/commandapi-velocity-shade/pom.xml | 2 +- commandapi-platforms/commandapi-velocity/pom.xml | 2 +- commandapi-platforms/pom.xml | 2 +- commandapi-plugin/pom.xml | 2 +- commandapi-preprocessor/pom.xml | 2 +- examples/bukkit/automated-tests-shaded/README.md | 4 ++-- examples/bukkit/automated-tests-shaded/pom.xml | 4 ++-- examples/bukkit/automated-tests/README.md | 4 ++-- examples/bukkit/automated-tests/pom.xml | 4 ++-- examples/bukkit/commandtrees/pom.xml | 2 +- examples/bukkit/gradle-groovy/README.md | 2 +- examples/bukkit/gradle-groovy/build.gradle | 2 +- examples/bukkit/gradle-kotlin/README.md | 2 +- examples/bukkit/gradle-kotlin/build.gradle.kts | 2 +- examples/bukkit/kotlindsl-gradle/README.md | 2 +- examples/bukkit/kotlindsl-gradle/build.gradle.kts | 4 ++-- examples/bukkit/kotlindsl/README.md | 2 +- examples/bukkit/kotlindsl/pom.xml | 4 ++-- examples/bukkit/maven-annotations/README.md | 6 +++--- examples/bukkit/maven-annotations/pom.xml | 6 +++--- examples/bukkit/maven-shaded-annotations/README.md | 6 +++--- examples/bukkit/maven-shaded-annotations/pom.xml | 6 +++--- examples/bukkit/maven-shaded-tests/pom.xml | 8 ++++---- examples/bukkit/maven-shaded/README.md | 2 +- examples/bukkit/maven-shaded/pom.xml | 2 +- examples/bukkit/maven/README.md | 2 +- examples/bukkit/maven/pom.xml | 2 +- examples/velocity/gradle-groovy/README.md | 2 +- examples/velocity/gradle-groovy/build.gradle | 2 +- examples/velocity/gradle-kotlin/README.md | 2 +- examples/velocity/gradle-kotlin/build.gradle.kts | 2 +- examples/velocity/maven-shaded/README.md | 2 +- examples/velocity/maven-shaded/pom.xml | 2 +- examples/velocity/maven/README.md | 2 +- examples/velocity/maven/pom.xml | 2 +- pom.xml | 2 +- 80 files changed, 97 insertions(+), 97 deletions(-) diff --git a/commandapi-annotations/pom.xml b/commandapi-annotations/pom.xml index 9c707b51c..63d372ed8 100644 --- a/commandapi-annotations/pom.xml +++ b/commandapi-annotations/pom.xml @@ -18,7 +18,7 @@ dev.jorel commandapi - 10.1.0 + 10.2.0-SNAPSHOT commandapi-annotations diff --git a/commandapi-core/pom.xml b/commandapi-core/pom.xml index b071904f5..1b494ed40 100644 --- a/commandapi-core/pom.xml +++ b/commandapi-core/pom.xml @@ -19,7 +19,7 @@ commandapi dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml b/commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml index bda964ea3..70d5c2867 100644 --- a/commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml +++ b/commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi-kotlin - 10.1.0 + 10.2.0-SNAPSHOT commandapi-bukkit-kotlin diff --git a/commandapi-kotlin/commandapi-core-kotlin/pom.xml b/commandapi-kotlin/commandapi-core-kotlin/pom.xml index 66fb5ce47..29936ef86 100644 --- a/commandapi-kotlin/commandapi-core-kotlin/pom.xml +++ b/commandapi-kotlin/commandapi-core-kotlin/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi-kotlin - 10.1.0 + 10.2.0-SNAPSHOT commandapi-core-kotlin diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/pom.xml b/commandapi-kotlin/commandapi-velocity-kotlin/pom.xml index 12cc0da22..5eb3ed72c 100644 --- a/commandapi-kotlin/commandapi-velocity-kotlin/pom.xml +++ b/commandapi-kotlin/commandapi-velocity-kotlin/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi-kotlin - 10.1.0 + 10.2.0-SNAPSHOT commandapi-velocity-kotlin diff --git a/commandapi-kotlin/pom.xml b/commandapi-kotlin/pom.xml index 0a536da88..3c918c103 100644 --- a/commandapi-kotlin/pom.xml +++ b/commandapi-kotlin/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi - 10.1.0 + 10.2.0-SNAPSHOT commandapi-kotlin diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml index 1b41e764a..88daea866 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml @@ -6,7 +6,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-bukkit-core diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml index b60eac173..b4432c9bf 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml @@ -24,7 +24,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml index 31adc9c55..7901438ee 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml @@ -6,7 +6,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-bukkit-networking-plugin diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml index 205c03f91..300170a7f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml index c332bd572..fe6526fd3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml index e0fa52de8..eb91ededc 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml index dd6c0b3db..29b0a897f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml index c47579793..5a339e215 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml index 0bb2743d8..5d40226eb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml index 244995c3a..36ed71d71 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml index 8a674188f..5b611ece6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml index 04bab1741..f12352bb2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index d75c01a56..dbcd56df1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -19,7 +19,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/pom.xml index 4dbe801c9..bd57db4d1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/pom.xml @@ -19,7 +19,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml index 05e4f1872..64b44c508 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml @@ -19,7 +19,7 @@ commandapi-bukkit-nms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml index b62f1e95e..3a127f204 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml @@ -26,7 +26,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-bukkit-nms diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml index 516611451..89a0992fb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi-bukkit - 10.1.0 + 10.2.0-SNAPSHOT commandapi-bukkit-plugin-common diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml index edf7e938b..601316ce3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml @@ -25,7 +25,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml index 600b7512d..187593759 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml @@ -25,7 +25,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml index 8842cd805..4d94c9dbf 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml @@ -25,7 +25,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml index 1d016fb91..f2c90a536 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml @@ -25,7 +25,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml index 5f089da5f..0463b5f3e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-bukkit - 10.1.0 + 10.2.0-SNAPSHOT commandapi-bukkit-test-toolkit diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml index c7bf6fbfa..b74549039 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml @@ -25,7 +25,7 @@ commandapi-bukkit-test dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml index 861f23960..62b34324a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml @@ -25,7 +25,7 @@ commandapi-bukkit-test dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml index eb599181f..08a7d105b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml @@ -25,7 +25,7 @@ commandapi-bukkit-test dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml index ceb721a85..431793077 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml @@ -25,7 +25,7 @@ commandapi-bukkit-test dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml index 9def293c6..2ce6d3b6f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml @@ -25,7 +25,7 @@ commandapi-bukkit-test dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/pom.xml index 4959e4e88..308c84244 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/pom.xml @@ -24,7 +24,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-bukkit-test CommandAPI - Bukkit support test library diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml index b69ede312..cb050deee 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml @@ -24,7 +24,7 @@ commandapi-bukkit dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/pom.xml b/commandapi-platforms/commandapi-bukkit/pom.xml index fcc3d6831..0dbb9efc7 100644 --- a/commandapi-platforms/commandapi-bukkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/pom.xml @@ -7,7 +7,7 @@ commandapi-platforms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-bukkit diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml index 8ed9b937f..2f0e04040 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-sponge-core diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml index b4ff8fff0..8027c751e 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-sponge-plugin-test diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml index 6ad908dca..8ea5e92d4 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-sponge-plugin diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml index cbad707d4..5d369bbcf 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-sponge-shade diff --git a/commandapi-platforms/commandapi-sponge/pom.xml b/commandapi-platforms/commandapi-sponge/pom.xml index b09f205ed..97bc7cdd9 100644 --- a/commandapi-platforms/commandapi-sponge/pom.xml +++ b/commandapi-platforms/commandapi-sponge/pom.xml @@ -7,7 +7,7 @@ commandapi-platforms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-sponge diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml index 7d96710d7..d5e8368df 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-velocity-core diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml index dbe7787ac..685c92b77 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-velocity-plugin-test diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml index e5e363ce1..2a772ea5c 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-velocity-plugin diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml index 69cc900d1..2e61aa6be 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-velocity-shade diff --git a/commandapi-platforms/commandapi-velocity/pom.xml b/commandapi-platforms/commandapi-velocity/pom.xml index 89288066f..56dcc5dcf 100644 --- a/commandapi-platforms/commandapi-velocity/pom.xml +++ b/commandapi-platforms/commandapi-velocity/pom.xml @@ -7,7 +7,7 @@ commandapi-platforms dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-velocity diff --git a/commandapi-platforms/pom.xml b/commandapi-platforms/pom.xml index cdf636126..a16d61785 100644 --- a/commandapi-platforms/pom.xml +++ b/commandapi-platforms/pom.xml @@ -7,7 +7,7 @@ commandapi dev.jorel - 10.1.0 + 10.2.0-SNAPSHOT commandapi-platforms diff --git a/commandapi-plugin/pom.xml b/commandapi-plugin/pom.xml index 3f9b34236..cd3eb7c0a 100644 --- a/commandapi-plugin/pom.xml +++ b/commandapi-plugin/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi - 10.1.0 + 10.2.0-SNAPSHOT commandapi-plugin diff --git a/commandapi-preprocessor/pom.xml b/commandapi-preprocessor/pom.xml index ae29467cd..d073d0b3f 100644 --- a/commandapi-preprocessor/pom.xml +++ b/commandapi-preprocessor/pom.xml @@ -25,7 +25,7 @@ dev.jorel commandapi - 10.1.0 + 10.2.0-SNAPSHOT 4.0.0 diff --git a/examples/bukkit/automated-tests-shaded/README.md b/examples/bukkit/automated-tests-shaded/README.md index 21bcd44d7..d92f9507c 100644 --- a/examples/bukkit/automated-tests-shaded/README.md +++ b/examples/bukkit/automated-tests-shaded/README.md @@ -18,14 +18,14 @@ Key points: dev.jorel commandapi-bukkit-test-toolkit - 10.1.0 + 10.2.0-SNAPSHOT test dev.jorel commandapi-bukkit-shade - 10.1.0 + 10.2.0-SNAPSHOT compile diff --git a/examples/bukkit/automated-tests-shaded/pom.xml b/examples/bukkit/automated-tests-shaded/pom.xml index 3878b1fbf..44b5ef970 100644 --- a/examples/bukkit/automated-tests-shaded/pom.xml +++ b/examples/bukkit/automated-tests-shaded/pom.xml @@ -32,7 +32,7 @@ dev.jorel commandapi-bukkit-test-toolkit - 10.1.0 + 10.2.0-SNAPSHOT test @@ -40,7 +40,7 @@ dev.jorel commandapi-bukkit-shade - 10.1.0 + 10.2.0-SNAPSHOT compile diff --git a/examples/bukkit/automated-tests/README.md b/examples/bukkit/automated-tests/README.md index 358b30203..c4c01cf2c 100644 --- a/examples/bukkit/automated-tests/README.md +++ b/examples/bukkit/automated-tests/README.md @@ -18,14 +18,14 @@ Key points: dev.jorel commandapi-bukkit-test-toolkit - 10.1.0 + 10.2.0-SNAPSHOT test dev.jorel commandapi-bukkit-core - 10.1.0 + 10.2.0-SNAPSHOT provided diff --git a/examples/bukkit/automated-tests/pom.xml b/examples/bukkit/automated-tests/pom.xml index db2047e60..09dd02506 100644 --- a/examples/bukkit/automated-tests/pom.xml +++ b/examples/bukkit/automated-tests/pom.xml @@ -32,7 +32,7 @@ dev.jorel commandapi-bukkit-test-toolkit - 10.1.0 + 10.2.0-SNAPSHOT test @@ -40,7 +40,7 @@ dev.jorel commandapi-bukkit-core - 10.1.0 + 10.2.0-SNAPSHOT provided diff --git a/examples/bukkit/commandtrees/pom.xml b/examples/bukkit/commandtrees/pom.xml index da2215725..b0025c1e1 100644 --- a/examples/bukkit/commandtrees/pom.xml +++ b/examples/bukkit/commandtrees/pom.xml @@ -20,7 +20,7 @@ dev.jorel commandapi-bukkit-core - 10.1.0 + 10.2.0-SNAPSHOT diff --git a/examples/bukkit/gradle-groovy/README.md b/examples/bukkit/gradle-groovy/README.md index fec461ee1..fc4f3737c 100644 --- a/examples/bukkit/gradle-groovy/README.md +++ b/examples/bukkit/gradle-groovy/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-bukkit-plugin` dependency is used: ```groovy - implementation 'dev.jorel:commandapi-bukkit-plugin:10.1.0' + implementation 'dev.jorel:commandapi-bukkit-plugin:10.2.0-SNAPSHOT' ``` - In the plugin.yml, CommandAPI is listed as a depend: diff --git a/examples/bukkit/gradle-groovy/build.gradle b/examples/bukkit/gradle-groovy/build.gradle index b57c94272..290e55a93 100644 --- a/examples/bukkit/gradle-groovy/build.gradle +++ b/examples/bukkit/gradle-groovy/build.gradle @@ -29,7 +29,7 @@ dependencies { implementation 'org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT' // The CommandAPI dependency used for Bukkit and it's forks - implementation 'dev.jorel:commandapi-bukkit-plugin:10.1.0' + implementation 'dev.jorel:commandapi-bukkit-plugin:10.2.0-SNAPSHOT' // NBT API to use NBT-based arguments implementation 'de.tr7zw:item-nbt-api-plugin:2.12.2' diff --git a/examples/bukkit/gradle-kotlin/README.md b/examples/bukkit/gradle-kotlin/README.md index 9112bdc4f..ee9040471 100644 --- a/examples/bukkit/gradle-kotlin/README.md +++ b/examples/bukkit/gradle-kotlin/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-bukkit-plugin` dependency is used: ```kotlin - implementation("dev.jorel:commandapi-bukkit-plugin:10.1.0") + implementation("dev.jorel:commandapi-bukkit-plugin:10.2.0-SNAPSHOT") ``` - In the plugin.yml, CommandAPI is listed as a depend: diff --git a/examples/bukkit/gradle-kotlin/build.gradle.kts b/examples/bukkit/gradle-kotlin/build.gradle.kts index c5ebb1566..679432201 100644 --- a/examples/bukkit/gradle-kotlin/build.gradle.kts +++ b/examples/bukkit/gradle-kotlin/build.gradle.kts @@ -25,7 +25,7 @@ dependencies { implementation("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT") // The CommandAPI dependency used for Bukkit and it's forks - implementation("dev.jorel:commandapi-bukkit-plugin:10.1.0") + implementation("dev.jorel:commandapi-bukkit-plugin:10.2.0-SNAPSHOT") // NBT API to use NBT-based arguments implementation("de.tr7zw:item-nbt-api-plugin:2.12.2") diff --git a/examples/bukkit/kotlindsl-gradle/README.md b/examples/bukkit/kotlindsl-gradle/README.md index 9c773d5fa..dc5fa7800 100644 --- a/examples/bukkit/kotlindsl-gradle/README.md +++ b/examples/bukkit/kotlindsl-gradle/README.md @@ -9,7 +9,7 @@ Key points: - Add the `commandapi-kotlin-bukkit` dependency to your project: ```kotlin - compileOnly("dev.jorel:commandapi-bukkit-kotlin:10.1.0") + compileOnly("dev.jorel:commandapi-bukkit-kotlin:10.2.0-SNAPSHOT") ``` - The Kotlin DSL must not be shaded into your plugin diff --git a/examples/bukkit/kotlindsl-gradle/build.gradle.kts b/examples/bukkit/kotlindsl-gradle/build.gradle.kts index c8da3bd4e..195b8c9a4 100644 --- a/examples/bukkit/kotlindsl-gradle/build.gradle.kts +++ b/examples/bukkit/kotlindsl-gradle/build.gradle.kts @@ -22,7 +22,7 @@ dependencies { implementation("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT") // The CommandAPI dependency used for Bukkit and it's forks - implementation("dev.jorel:commandapi-bukkit-core:10.1.0") + implementation("dev.jorel:commandapi-bukkit-core:10.2.0-SNAPSHOT") // Due to all functions available in the kotlindsl being inlined, we only need this dependency at compile-time - compileOnly("dev.jorel:commandapi-bukkit-kotlin:10.1.0") + compileOnly("dev.jorel:commandapi-bukkit-kotlin:10.2.0-SNAPSHOT") } \ No newline at end of file diff --git a/examples/bukkit/kotlindsl/README.md b/examples/bukkit/kotlindsl/README.md index 43cc69722..d4904d2fd 100644 --- a/examples/bukkit/kotlindsl/README.md +++ b/examples/bukkit/kotlindsl/README.md @@ -12,7 +12,7 @@ Key points: dev.jorel commandapi-kotlin-bukkit - 10.1.0 + 10.2.0-SNAPSHOT ``` diff --git a/examples/bukkit/kotlindsl/pom.xml b/examples/bukkit/kotlindsl/pom.xml index 5b8ed0121..f102e6195 100644 --- a/examples/bukkit/kotlindsl/pom.xml +++ b/examples/bukkit/kotlindsl/pom.xml @@ -21,13 +21,13 @@ dev.jorel commandapi-bukkit-core - 10.1.0 + 10.2.0-SNAPSHOT provided dev.jorel commandapi-bukkit-kotlin - 10.1.0 + 10.2.0-SNAPSHOT diff --git a/examples/bukkit/maven-annotations/README.md b/examples/bukkit/maven-annotations/README.md index c34ab7f70..5d383bbfd 100644 --- a/examples/bukkit/maven-annotations/README.md +++ b/examples/bukkit/maven-annotations/README.md @@ -11,13 +11,13 @@ Key points: dev.jorel commandapi-bukkit-plugin - 10.1.0 + 10.2.0-SNAPSHOT provided dev.jorel commandapi-annotations - 10.1.0 + 10.2.0-SNAPSHOT provided @@ -37,7 +37,7 @@ Key points: dev.jorel commandapi-annotations - 10.1.0 + 10.2.0-SNAPSHOT diff --git a/examples/bukkit/maven-annotations/pom.xml b/examples/bukkit/maven-annotations/pom.xml index 96b2f537f..cd3f32a93 100644 --- a/examples/bukkit/maven-annotations/pom.xml +++ b/examples/bukkit/maven-annotations/pom.xml @@ -28,7 +28,7 @@ dev.jorel commandapi-bukkit-plugin - 10.1.0 + 10.2.0-SNAPSHOT provided @@ -36,7 +36,7 @@ dev.jorel commandapi-annotations - 10.1.0 + 10.2.0-SNAPSHOT provided @@ -69,7 +69,7 @@ dev.jorel commandapi-annotations - 10.1.0 + 10.2.0-SNAPSHOT 17 diff --git a/examples/bukkit/maven-shaded-annotations/README.md b/examples/bukkit/maven-shaded-annotations/README.md index 6952bcce0..2e25100f8 100644 --- a/examples/bukkit/maven-shaded-annotations/README.md +++ b/examples/bukkit/maven-shaded-annotations/README.md @@ -11,12 +11,12 @@ Key points: dev.jorel commandapi-bukkit-shade - 10.1.0 + 10.2.0-SNAPSHOT dev.jorel commandapi-annotations - 10.1.0 + 10.2.0-SNAPSHOT provided @@ -36,7 +36,7 @@ Key points: dev.jorel commandapi-annotations - 10.1.0 + 10.2.0-SNAPSHOT diff --git a/examples/bukkit/maven-shaded-annotations/pom.xml b/examples/bukkit/maven-shaded-annotations/pom.xml index 25e1945b4..45f5e50dc 100644 --- a/examples/bukkit/maven-shaded-annotations/pom.xml +++ b/examples/bukkit/maven-shaded-annotations/pom.xml @@ -28,14 +28,14 @@ dev.jorel commandapi-bukkit-shade - 10.1.0 + 10.2.0-SNAPSHOT dev.jorel commandapi-annotations - 10.1.0 + 10.2.0-SNAPSHOT provided @@ -62,7 +62,7 @@ dev.jorel commandapi-annotations - 10.1.0 + 10.2.0-SNAPSHOT 17 diff --git a/examples/bukkit/maven-shaded-tests/pom.xml b/examples/bukkit/maven-shaded-tests/pom.xml index 308df627c..679395210 100644 --- a/examples/bukkit/maven-shaded-tests/pom.xml +++ b/examples/bukkit/maven-shaded-tests/pom.xml @@ -37,7 +37,7 @@ dev.jorel commandapi-bukkit-test-tests - 10.1.0 + 10.2.0-SNAPSHOT test-jar test @@ -46,7 +46,7 @@ dev.jorel commandapi-bukkit-shade - 10.1.0 + 10.2.0-SNAPSHOT @@ -69,14 +69,14 @@ dev.jorel commandapi-bukkit-test-impl - 10.1.0 + 10.2.0-SNAPSHOT test dev.jorel commandapi-bukkit-test-impl-1.20 - 10.1.0 + 10.2.0-SNAPSHOT test diff --git a/examples/bukkit/maven-shaded/README.md b/examples/bukkit/maven-shaded/README.md index 0dda6f97e..be4d9f9d9 100644 --- a/examples/bukkit/maven-shaded/README.md +++ b/examples/bukkit/maven-shaded/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-bukkit-shade - 10.1.0 + 10.2.0-SNAPSHOT ``` diff --git a/examples/bukkit/maven-shaded/pom.xml b/examples/bukkit/maven-shaded/pom.xml index 719078cda..ce7f574f2 100644 --- a/examples/bukkit/maven-shaded/pom.xml +++ b/examples/bukkit/maven-shaded/pom.xml @@ -28,7 +28,7 @@ dev.jorel commandapi-bukkit-shade - 10.1.0 + 10.2.0-SNAPSHOT diff --git a/examples/bukkit/maven/README.md b/examples/bukkit/maven/README.md index 5a139525f..9908b214a 100644 --- a/examples/bukkit/maven/README.md +++ b/examples/bukkit/maven/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-bukkit-plugin - 10.1.0 + 10.2.0-SNAPSHOT provided ``` diff --git a/examples/bukkit/maven/pom.xml b/examples/bukkit/maven/pom.xml index 87aa01e7e..0b572787a 100644 --- a/examples/bukkit/maven/pom.xml +++ b/examples/bukkit/maven/pom.xml @@ -28,7 +28,7 @@ dev.jorel commandapi-bukkit-plugin - 10.1.0 + 10.2.0-SNAPSHOT provided diff --git a/examples/velocity/gradle-groovy/README.md b/examples/velocity/gradle-groovy/README.md index 3943e3b68..545e729e4 100644 --- a/examples/velocity/gradle-groovy/README.md +++ b/examples/velocity/gradle-groovy/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-velocity-core` dependency is used ```groovy - implementation 'dev.jorel:commandapi-velocity-core:10.1.0' + implementation 'dev.jorel:commandapi-velocity-core:10.2.0-SNAPSHOT' ``` - In the `@Plugin` annotation, `commandapi` is listed as a dependency: diff --git a/examples/velocity/gradle-groovy/build.gradle b/examples/velocity/gradle-groovy/build.gradle index b27b3a8d8..45e7d9020 100644 --- a/examples/velocity/gradle-groovy/build.gradle +++ b/examples/velocity/gradle-groovy/build.gradle @@ -25,5 +25,5 @@ dependencies { implementation 'com.velocitypowered:velocity-api:3.1.1' // The CommandAPI dependency used for Velocity - implementation 'dev.jorel:commandapi-velocity-core:10.1.0' + implementation 'dev.jorel:commandapi-velocity-core:10.2.0-SNAPSHOT' } \ No newline at end of file diff --git a/examples/velocity/gradle-kotlin/README.md b/examples/velocity/gradle-kotlin/README.md index c8e4872b6..580b1b783 100644 --- a/examples/velocity/gradle-kotlin/README.md +++ b/examples/velocity/gradle-kotlin/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-velocity-core` dependency is used: ```kotlin - implementation("dev.jorel:commandapi-velocity-core:10.1.0") + implementation("dev.jorel:commandapi-velocity-core:10.2.0-SNAPSHOT") ``` - In the `@Plugin` annotation, `commandapi` is listed as a dependency: diff --git a/examples/velocity/gradle-kotlin/build.gradle.kts b/examples/velocity/gradle-kotlin/build.gradle.kts index acefaf849..527b6dbc6 100644 --- a/examples/velocity/gradle-kotlin/build.gradle.kts +++ b/examples/velocity/gradle-kotlin/build.gradle.kts @@ -23,5 +23,5 @@ dependencies { implementation("com.velocitypowered:velocity-api:3.1.1") // The CommandAPI dependency used for Velocity - implementation("dev.jorel:commandapi-velocity-core:10.1.0") + implementation("dev.jorel:commandapi-velocity-core:10.2.0-SNAPSHOT") } \ No newline at end of file diff --git a/examples/velocity/maven-shaded/README.md b/examples/velocity/maven-shaded/README.md index 3485cfb0c..cc3b6f3e7 100644 --- a/examples/velocity/maven-shaded/README.md +++ b/examples/velocity/maven-shaded/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-velocity-shade - 10.1.0 + 10.2.0-SNAPSHOT ``` diff --git a/examples/velocity/maven-shaded/pom.xml b/examples/velocity/maven-shaded/pom.xml index 97f52a8a8..781fac27e 100644 --- a/examples/velocity/maven-shaded/pom.xml +++ b/examples/velocity/maven-shaded/pom.xml @@ -21,7 +21,7 @@ dev.jorel commandapi-velocity-shade - 10.1.0 + 10.2.0-SNAPSHOT diff --git a/examples/velocity/maven/README.md b/examples/velocity/maven/README.md index 295b51e73..9d3edb4f2 100644 --- a/examples/velocity/maven/README.md +++ b/examples/velocity/maven/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-velocity-core - 10.1.0 + 10.2.0-SNAPSHOT provided ``` diff --git a/examples/velocity/maven/pom.xml b/examples/velocity/maven/pom.xml index d1f76cd00..50c6ee11f 100644 --- a/examples/velocity/maven/pom.xml +++ b/examples/velocity/maven/pom.xml @@ -21,7 +21,7 @@ dev.jorel commandapi-velocity-core - 10.1.0 + 10.2.0-SNAPSHOT provided diff --git a/pom.xml b/pom.xml index bdc946046..df8b7a995 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ dev.jorel commandapi - 10.1.0 + 10.2.0-SNAPSHOT pom commandapi From d22e28c2ac7246e4c41662b8b0d1eabd749f8cf4 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Tue, 24 Jun 2025 03:08:15 +0200 Subject: [PATCH 02/63] Paper CommandAPI (#517) --- .editorconfig | 6 + .github/workflows/build.yml | 27 +- .gitignore | 1 + README.md | 27 +- commandapi-annotations/pom.xml | 25 +- ...rgument.java => ADoubleRangeArgument.java} | 10 +- commandapi-codecov/pom.xml | 10 +- commandapi-core/pom.xml | 4 +- .../java/dev/jorel/commandapi/CommandAPI.java | 13 +- .../jorel/commandapi/CommandAPIPlatform.java | 47 +- .../commandapi/CommandAPIVersionHandler.java | 4 + .../arguments/CommandAPIArgumentType.java | 5 - .../{FloatRange.java => DoubleRange.java} | 54 +- .../pom.xml | 8 +- .../kotlindsl/CommandAPICommandDSL.kt | 15 +- .../commandapi/kotlindsl/CommandTreeDSL.kt | 27 +- .../jorel/commandapi/kotlindsl/ExecutorDSL.kt | 0 .../pom.xml | 6 +- .../commandapi/kotlindsl/CommandAPIDSL.kt | 0 .../commandapi-kotlin-paper/pom.xml | 99 ++ .../kotlindsl/PaperCommandAPICommandDSL.kt | 15 + .../kotlindsl/PaperCommandTreeDSL.kt | 16 + .../commandapi/kotlindsl/PaperExecutorDSL.kt | 31 + .../commandapi-kotlin-spigot/pom.xml | 99 ++ .../kotlindsl/SpigotCommandAPICommandDSL.kt | 15 + .../kotlindsl/SpigotCommandTreeDSL.kt | 16 + .../javadoc/README.md | 1 + .../pom.xml | 8 +- .../kotlindsl/CommandAPICommandDSL.kt | 0 .../commandapi/kotlindsl/CommandTreeDSL.kt | 0 .../jorel/commandapi/kotlindsl/ExecutorDSL.kt | 0 .../javadoc/README.md | 1 - commandapi-kotlin/pom.xml | 4 +- .../commandapi-bukkit-core/pom.xml | 4 +- .../jorel/commandapi/BukkitExecutable.java | 13 + .../dev/jorel/commandapi/BukkitPlatform.java | 25 + .../dev/jorel/commandapi/BukkitTooltip.java | 4 +- .../jorel/commandapi/CommandAPIBukkit.java | 385 +++----- .../commandapi/CommandAPIBukkitConfig.java | 56 +- .../java/dev/jorel/commandapi/Converter.java | 2 +- .../commandapi/InternalBukkitConfig.java | 33 +- .../commandapi/PaperCommandRegistration.java | 266 ----- .../commandapi/PaperImplementations.java | 177 ---- .../java/dev/jorel/commandapi/Platform.java | 16 + .../arguments/AdvancementArgument.java | 4 +- .../commandapi/arguments/AngleArgument.java | 4 +- .../arguments/AsyncOfflinePlayerArgument.java | 49 - .../commandapi/arguments/AxisArgument.java | 4 +- .../commandapi/arguments/BiomeArgument.java | 10 +- .../arguments/BlockPredicateArgument.java | 4 +- .../arguments/BlockStateArgument.java | 17 +- .../commandapi/arguments/CommandArgument.java | 4 +- ...Argument.java => DoubleRangeArgument.java} | 18 +- .../arguments/EnchantmentArgument.java | 4 +- .../arguments/EntitySelectorArgument.java | 18 +- .../arguments/EntityTypeArgument.java | 4 +- .../arguments/FunctionArgument.java | 4 +- .../arguments/IntegerRangeArgument.java | 4 +- .../arguments/ItemStackArgument.java | 4 +- .../arguments/ItemStackPredicateArgument.java | 4 +- .../arguments/Location2DArgument.java | 16 +- .../arguments/LocationArgument.java | 47 +- .../arguments/LootTableArgument.java | 4 +- .../arguments/MathOperationArgument.java | 4 +- .../arguments/NBTCompoundArgument.java | 4 +- .../arguments/NamespacedKeyArgument.java | 4 +- .../arguments/ObjectiveArgument.java | 4 +- .../arguments/ObjectiveCriteriaArgument.java | 4 +- .../arguments/ParticleArgument.java | 4 +- .../arguments/PotionEffectArgument.java | 8 +- .../commandapi/arguments/RecipeArgument.java | 4 +- .../arguments/RotationArgument.java | 4 +- .../arguments/ScoreHolderArgument.java | 8 +- .../arguments/ScoreboardSlotArgument.java | 4 +- .../commandapi/arguments/SoundArgument.java | 8 +- .../commandapi/arguments/TeamArgument.java | 4 +- .../commandapi/arguments/TimeArgument.java | 4 +- .../commandapi/arguments/UUIDArgument.java | 4 +- .../commandapi/arguments/WorldArgument.java | 4 +- .../parser/EntitySelectorParser.java | 16 + .../arguments/parser/RegistryParser.java | 11 + .../parser/function/ThrowingBiFunction.java | 7 + .../function/ThrowingFunctionParser.java | 9 + .../parser/function/ThrowingSupplier.java | 8 + .../function/ThrowingSupplyingParser.java | 9 + .../exceptions/PlatformException.java | 8 + .../java/dev/jorel/commandapi/nms/NMS.java | 73 +- .../wrappers/NativeProxyCommandSender.java | 2 +- .../wrappers/SimpleFunctionWrapper.java | 8 +- .../commandapi-bukkit-mojang-mapped/pom.xml | 33 - .../pom.xml | 4 +- .../commandapi-bukkit-1.20.2/pom.xml | 4 +- .../dev/jorel/commandapi/nms/NMS_1_20_R2.java | 198 ++-- .../nms/NativeProxyCommandSender_1_20_R2.java | 2 +- .../src/test/java/SafeReflect.java | 10 +- .../commandapi-bukkit-1.20.3/pom.xml | 4 +- .../dev/jorel/commandapi/nms/NMS_1_20_R3.java | 372 +++---- .../nms/NativeProxyCommandSender_1_20_R3.java | 2 +- .../src/test/java/SafeReflect.java | 10 +- .../commandapi-bukkit-1.20.5/pom.xml | 4 +- .../dev/jorel/commandapi/nms/NMS_1_20_R4.java | 438 ++++----- .../nms/NativeProxyCommandSender_1_20_R4.java | 2 +- .../src/test/java/SafeReflect.java | 10 +- .../commandapi-bukkit-1.20/pom.xml | 4 +- .../dev/jorel/commandapi/nms/NMS_1_20_R1.java | 194 ++-- .../nms/NativeProxyCommandSender_1_20_R1.java | 2 +- .../src/test/java/SafeReflect.java | 10 +- .../commandapi-bukkit-1.21.2/pom.xml | 4 +- .../dev/jorel/commandapi/nms/NMS_1_21_R2.java | 422 ++++---- .../nms/NativeProxyCommandSender_1_21_R2.java | 2 +- .../src/test/java/SafeReflect.java | 10 +- .../commandapi-bukkit-1.21.4/pom.xml | 4 +- .../dev/jorel/commandapi/nms/NMS_1_21_R3.java | 430 ++++---- .../nms/NativeProxyCommandSender_1_21_R3.java | 2 +- .../src/test/java/SafeReflect.java | 10 +- .../commandapi-bukkit-1.21.5/pom.xml | 4 +- .../dev/jorel/commandapi/nms/NMS_1_21_R4.java | 432 ++++---- .../nms/NativeProxyCommandSender_1_21_R4.java | 2 +- .../src/test/java/SafeReflect.java | 12 +- .../commandapi-bukkit-1.21.6/pom.xml | 4 +- .../dev/jorel/commandapi/nms/NMS_1_21_R5.java | 261 ++--- .../nms/NativeProxyCommandSender_1_21_R5.java | 2 +- .../src/test/java/SafeReflect.java | 3 + .../commandapi-bukkit-1.21/pom.xml | 6 +- .../dev/jorel/commandapi/nms/NMS_1_21_R1.java | 424 ++++---- .../nms/NativeProxyCommandSender_1_21_R1.java | 2 +- .../src/test/java/SafeReflect.java | 10 +- .../commandapi-bukkit-nms-common/pom.xml | 4 +- .../dev/jorel/commandapi/nms/NMS_Common.java | 24 +- .../dependency-reduced-pom.xml | 53 - .../commandapi-bukkit-nms-dependency/pom.xml | 4 +- .../commandapi-bukkit-nms/pom.xml | 5 +- .../commandapi-bukkit-plugin-common/pom.xml | 4 +- .../config/BukkitConfigurationAdapter.java | 5 - .../config/DefaultBukkitConfig.java | 22 +- .../javadoc/README.md | 1 - .../commandapi-bukkit-plugin/.gitignore | 4 - .../javadoc/README.md | 1 - .../commandapi-bukkit-shade/.gitignore | 4 - .../commandapi-bukkit-shade/javadoc/README.md | 1 - .../commandapi-bukkit-shade/pom.xml | 104 -- .../commandapi-bukkit-test-toolkit/pom.xml | 11 +- .../commandapi/MockCommandAPIBukkit.java | 19 +- .../commandapi/MockCommandAPIPlugin.java | 11 +- .../java/dev/jorel/commandapi/MockNMS.java | 422 ++++++++ .../arguments/ProfileArgumentTypeTests.java | 2 +- .../dev/jorel/commandapi/test/MockNMS.java | 4 +- .../dev/jorel/commandapi/test/MockNMS.java | 4 +- .../dev/jorel/commandapi/test/MockNMS.java | 6 +- .../dev/jorel/commandapi/test/MockNMS.java | 4 +- .../jorel/commandapi/test/MockPlatform.java | 4 +- .../commandapi-bukkit-vh/.gitignore | 2 - .../commandapi-bukkit-vh/pom.xml | 51 - .../commandapi/CommandAPIVersionHandler.java | 106 -- .../commandapi-bukkit/pom.xml | 23 +- .../commandapi-paper-annotations/pom.xml | 69 ++ .../commandapi/annotations/Annotations.java | 572 +++++++++++ .../AAsyncPlayerProfileArgument.java | 15 + .../annotations/arguments/AChatArgument.java | 6 +- .../arguments/AChatColorArgument.java | 15 + .../arguments/AChatComponentArgument.java | 6 +- .../arguments/APlayerProfileArgument.java | 8 +- .../src/test/java/TeleportCommand.java | 20 +- .../src/test/java/Test2Command.java | 0 .../src/test/java/TestCommand.java | 17 +- .../src/test/java/WarpCommand.java | 0 .../commandapi-paper-core/pom.xml | 102 ++ .../dev/jorel/commandapi/CommandAPIPaper.java | 276 ++++++ .../commandapi/CommandAPIPaperConfig.java | 55 ++ .../jorel/commandapi/InternalPaperConfig.java | 36 + .../commandapi/PaperCommandRegistration.java | 152 +++ .../java/dev/jorel/commandapi/Schedulers.java | 16 +- .../dev/jorel/commandapi/VersionContext.java | 11 + .../arguments/AsyncPlayerProfileArgument.java | 51 + .../commandapi/arguments/ChatArgument.java} | 21 +- .../arguments/ChatColorArgument.java} | 9 +- .../arguments/ChatComponentArgument.java} | 9 +- .../commandapi/arguments/CustomArgument.java | 354 +++++++ .../arguments/PlayerProfileArgument.java} | 26 +- .../dev/jorel/commandapi/nms/BundledNMS.java | 4 + .../dev/jorel/commandapi/nms/PaperNMS.java | 29 + .../pom.xml | 112 +++ .../commandapi/examples/java/Examples.java | 119 +++ .../commandapi/examples/kotlin/Examples.kt | 112 +++ .../examples/kotlin/ExamplesKotlinDSL.kt | 80 ++ .../commandapi-paper-mojang-mapped/pom.xml | 15 + .../MojangMappedVersionHandler.java | 0 .../commandapi-paper-1.20.5/pom.xml | 134 +++ .../commandapi/nms/PaperNMS_1_20_R4.java | 141 +++ .../commandapi-paper-1.21.2/pom.xml | 129 +++ .../commandapi/nms/PaperNMS_1_21_R2.java | 105 ++ .../commandapi-paper-1.21.4/pom.xml | 129 +++ .../commandapi/nms/PaperNMS_1_21_R3.java | 118 +++ .../commandapi-paper-1.21.5/pom.xml | 129 +++ .../commandapi/nms/PaperNMS_1_21_R4.java | 128 +++ .../commandapi-paper-1.21.6/pom.xml | 103 ++ .../commandapi/nms/PaperNMS_1_21_R5.java | 102 ++ .../commandapi-paper-1.21/pom.xml | 136 +++ .../commandapi/nms/PaperNMS_1_21_R1.java | 105 ++ .../commandapi-paper-api/pom.xml | 41 + .../jorel/commandapi/nms/APITypeProvider.java | 926 ++++++++++++++++++ .../commandapi-paper-nms-dependency/pom.xml | 106 ++ .../commandapi-paper-nms/pom.xml | 28 + .../commandapi-paper-plugin}/LICENSE | 0 .../commandapi-paper-plugin/pom.xml | 115 +++ .../jorel/commandapi/AdvancedConverter.java | 24 +- .../dev/jorel/commandapi/CommandAPIMain.java | 157 +++ .../src/main/resources/plugin.yml | 0 .../commandapi-paper-shade}/LICENSE | 0 .../commandapi-paper-shade/javadoc/README.md | 1 + .../commandapi-paper-shade/pom.xml | 84 ++ .../commandapi-paper-vh/pom.xml | 46 + .../commandapi/CommandAPIVersionHandler.java | 72 ++ .../UnsupportedVersionException.java | 0 commandapi-platforms/commandapi-paper/pom.xml | 36 + .../commandapi-spigot-annotations/pom.xml | 69 ++ .../commandapi/annotations/Annotations.java | 75 +- .../AAsyncPlayerProfileArgument.java | 8 +- .../annotations/arguments/AChatArgument.java | 0 .../arguments/AChatColorArgument.java | 0 .../arguments/AChatComponentArgument.java | 0 .../arguments/APlayerProfileArgument.java | 8 +- .../commandapi-spigot-core/pom.xml | 95 ++ .../jorel/commandapi/CommandAPISpigot.java | 134 +++ .../commandapi/CommandAPISpigotConfig.java | 29 + .../commandapi/InternalSpigotConfig.java | 21 + .../arguments/AsyncPlayerProfileArgument.java | 50 + .../commandapi/arguments/ChatArgument.java | 6 +- .../arguments/ChatColorArgument.java | 5 +- .../arguments/ChatComponentArgument.java | 5 +- .../commandapi/arguments/CustomArgument.java | 33 +- .../arguments/PlayerProfileArgument.java} | 31 +- .../dev/jorel/commandapi/nms/SpigotNMS.java | 25 + .../pom.xml | 102 ++ .../commandapi/examples/java/Examples.java | 120 +++ .../commandapi/examples/kotlin/Examples.kt | 116 +++ .../examples/kotlin/ExamplesKotlinDSL.kt | 62 ++ .../commandapi-spigot-mojang-mapped/pom.xml | 15 + .../MojangMappedVersionHandler.java | 12 + .../commandapi-spigot-1.20.2/pom.xml | 148 +++ .../commandapi/nms/SpigotNMS_1_20_R2.java | 74 ++ .../commandapi-spigot-1.20.3/pom.xml | 148 +++ .../commandapi/nms/SpigotNMS_1_20_R3.java | 74 ++ .../commandapi-spigot-1.20.5/pom.xml | 148 +++ .../commandapi/nms/SpigotNMS_1_20_R4.java | 88 ++ .../commandapi-spigot-1.20/pom.xml | 148 +++ .../commandapi/nms/SpigotNMS_1_20_R1.java | 74 ++ .../commandapi-spigot-1.21.2/pom.xml | 148 +++ .../commandapi/nms/SpigotNMS_1_21_R2.java | 88 ++ .../commandapi-spigot-1.21.4/pom.xml | 148 +++ .../commandapi/nms/SpigotNMS_1_21_R3.java | 88 ++ .../commandapi-spigot-1.21.5/pom.xml | 148 +++ .../commandapi/nms/SpigotNMS_1_21_R4.java | 88 ++ .../commandapi-spigot-1.21.6/pom.xml | 149 +++ .../commandapi/nms/SpigotNMS_1_21_R5.java | 88 ++ .../commandapi-spigot-1.21/pom.xml | 148 +++ .../commandapi/nms/SpigotNMS_1_21_R1.java | 88 ++ .../pom.xml | 87 +- .../commandapi-spigot-nms-dependency/pom.xml | 113 +++ .../commandapi-spigot-nms/pom.xml | 31 + .../pom.xml | 92 +- .../jorel/commandapi/AdvancedConverter.java | 314 ++++++ .../dev/jorel/commandapi/CommandAPIMain.java | 10 +- .../src/main/resources/config.yml | 74 ++ .../src/main/resources/plugin.yml | 0 .../commandapi-spigot-plugin/LICENSE | 21 + .../commandapi-spigot-plugin}/pom.xml | 64 +- .../jorel/commandapi/AdvancedConverter.java | 314 ++++++ .../dev/jorel/commandapi/CommandAPIMain.java | 155 +++ .../src/main/resources/config.yml | 74 ++ .../src/main/resources/plugin.yml | 13 + .../pom.xml | 44 +- .../commandapi-spigot-shade/LICENSE | 21 + .../commandapi-spigot-shade/javadoc/README.md | 1 + .../commandapi-spigot-shade/pom.xml | 84 ++ .../commandapi-spigot-vh/pom.xml | 33 + .../commandapi/CommandAPIVersionHandler.java | 65 ++ .../UnsupportedVersionException.java | 37 + .../commandapi-spigot/pom.xml | 34 + .../commandapi-sponge-core/pom.xml | 2 +- .../jorel/commandapi/CommandAPISponge.java | 6 +- .../commandapi-sponge-plugin-test/pom.xml | 2 +- .../commandapi-sponge-plugin/pom.xml | 2 +- .../dev/jorel/commandapi/CommandAPIMain.java | 2 +- .../commandapi-sponge-shade/pom.xml | 2 +- .../commandapi-sponge/pom.xml | 2 +- .../commandapi-velocity-core/pom.xml | 2 +- .../jorel/commandapi/CommandAPIVelocity.java | 1 - .../commandapi-velocity-plugin-test/pom.xml | 2 +- .../commandapi-velocity-plugin/pom.xml | 2 +- .../dev/jorel/commandapi/CommandAPIMain.java | 7 +- .../config/VelocityConfigurationAdapter.java | 9 +- .../commandapi-velocity-shade/pom.xml | 2 +- .../commandapi-velocity/pom.xml | 2 +- commandapi-platforms/pom.xml | 36 +- commandapi-plugin/pom.xml | 4 +- .../config/ConfigurationAdapter.java | 6 +- commandapi-preprocessor/pom.xml | 4 +- .../commandapi-testing-paper/pom.xml | 59 ++ .../jorel/commandapi/testing/TestPlugin.java | 173 ++++ .../src/main/resources/plugin.yml | 6 + commandapi-testing/pom.xml | 20 + .../bukkit/automated-tests-shaded/README.md | 4 +- .../bukkit/automated-tests-shaded/pom.xml | 4 +- examples/bukkit/automated-tests/README.md | 4 +- examples/bukkit/automated-tests/pom.xml | 4 +- examples/bukkit/commandtrees/pom.xml | 16 +- .../jorelali/BetterBossBarsCommand.java | 12 +- examples/bukkit/gradle-groovy/build.gradle | 10 +- .../java/io/github/jorelali/MyCommands.java | 4 +- .../bukkit/gradle-kotlin/build.gradle.kts | 10 +- .../java/io/github/jorelali/MyCommands.java | 4 +- .../bukkit/kotlindsl-gradle/build.gradle.kts | 13 +- examples/bukkit/kotlindsl/README.md | 2 +- examples/bukkit/kotlindsl/pom.xml | 20 +- examples/bukkit/maven-annotations/README.md | 6 +- examples/bukkit/maven-annotations/pom.xml | 22 +- .../bukkit/maven-shaded-annotations/README.md | 6 +- .../bukkit/maven-shaded-annotations/pom.xml | 20 +- .../main/java/io/github/jorelali/Main.java | 4 +- examples/bukkit/maven-shaded-tests/pom.xml | 22 +- .../main/java/io/github/jorelali/MyMain.java | 4 +- examples/bukkit/maven-shaded/README.md | 2 +- examples/bukkit/maven-shaded/pom.xml | 14 +- .../main/java/io/github/jorelali/Main.java | 4 +- .../java/io/github/jorelali/MyCommands.java | 4 +- examples/bukkit/maven/README.md | 2 +- examples/bukkit/maven/pom.xml | 16 +- .../java/io/github/jorelali/MyCommands.java | 4 +- examples/velocity/gradle-groovy/README.md | 2 +- examples/velocity/gradle-groovy/build.gradle | 2 +- examples/velocity/gradle-kotlin/README.md | 2 +- .../velocity/gradle-kotlin/build.gradle.kts | 2 +- examples/velocity/maven-shaded/README.md | 2 +- examples/velocity/maven-shaded/pom.xml | 2 +- examples/velocity/maven/README.md | 2 +- examples/velocity/maven/pom.xml | 2 +- pom.xml | 5 +- setupPaperNMS.sh | 19 + update.sh | 23 +- 340 files changed, 13095 insertions(+), 4034 deletions(-) rename commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/{AFloatRangeArgument.java => ADoubleRangeArgument.java} (88%) rename commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/{FloatRange.java => DoubleRange.java} (62%) rename commandapi-kotlin/{commandapi-bukkit-kotlin => commandapi-kotlin-bukkit}/pom.xml (92%) rename commandapi-kotlin/{commandapi-bukkit-kotlin => commandapi-kotlin-bukkit}/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt (85%) rename commandapi-kotlin/{commandapi-bukkit-kotlin => commandapi-kotlin-bukkit}/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt (85%) rename commandapi-kotlin/{commandapi-bukkit-kotlin => commandapi-kotlin-bukkit}/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt (100%) rename commandapi-kotlin/{commandapi-core-kotlin => commandapi-kotlin-core}/pom.xml (92%) rename commandapi-kotlin/{commandapi-core-kotlin => commandapi-kotlin-core}/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt (100%) create mode 100644 commandapi-kotlin/commandapi-kotlin-paper/pom.xml create mode 100644 commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt create mode 100644 commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt create mode 100644 commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperExecutorDSL.kt create mode 100644 commandapi-kotlin/commandapi-kotlin-spigot/pom.xml create mode 100644 commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt create mode 100644 commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt create mode 100644 commandapi-kotlin/commandapi-kotlin-velocity/javadoc/README.md rename commandapi-kotlin/{commandapi-velocity-kotlin => commandapi-kotlin-velocity}/pom.xml (92%) rename commandapi-kotlin/{commandapi-velocity-kotlin => commandapi-kotlin-velocity}/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt (100%) rename commandapi-kotlin/{commandapi-velocity-kotlin => commandapi-kotlin-velocity}/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt (100%) rename commandapi-kotlin/{commandapi-velocity-kotlin => commandapi-kotlin-velocity}/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt (100%) delete mode 100644 commandapi-kotlin/commandapi-velocity-kotlin/javadoc/README.md create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperImplementations.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Platform.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AsyncOfflinePlayerArgument.java rename commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/{FloatRangeArgument.java => DoubleRangeArgument.java} (72%) create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/EntitySelectorParser.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/RegistryParser.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingBiFunction.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingFunctionParser.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingSupplier.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingSupplyingParser.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/exceptions/PlatformException.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/dependency-reduced-pom.xml delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/javadoc/README.md delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/.gitignore delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/javadoc/README.md delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/.gitignore delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/javadoc/README.md delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/.gitignore delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncPlayerProfileArgument.java rename commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatArgument.java => commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java (90%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java rename commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatComponentArgument.java => commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java (89%) rename commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AOfflinePlayerArgument.java => commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerProfileArgument.java (88%) rename {commandapi-annotations => commandapi-platforms/commandapi-paper/commandapi-paper-annotations}/src/test/java/TeleportCommand.java (75%) rename {commandapi-annotations => commandapi-platforms/commandapi-paper/commandapi-paper-annotations}/src/test/java/Test2Command.java (100%) rename {commandapi-annotations => commandapi-platforms/commandapi-paper/commandapi-paper-annotations}/src/test/java/TestCommand.java (81%) rename {commandapi-annotations => commandapi-platforms/commandapi-paper/commandapi-paper-annotations}/src/test/java/WarpCommand.java (100%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core => commandapi-paper/commandapi-paper-core}/src/main/java/dev/jorel/commandapi/Schedulers.java (77%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/AsyncPlayerProfileArgument.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java => commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java} (74%) rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatColorArgument.java => commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java} (87%) rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatComponentArgument.java => commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java} (88%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PlayerArgument.java => commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/PlayerProfileArgument.java} (70%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-mojang-mapped => commandapi-paper/commandapi-paper-mojang-mapped}/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java (100%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-plugin => commandapi-paper/commandapi-paper-plugin}/LICENSE (100%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-plugin-common => commandapi-paper/commandapi-paper-plugin}/src/main/java/dev/jorel/commandapi/AdvancedConverter.java (94%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped => commandapi-paper/commandapi-paper-plugin}/src/main/resources/plugin.yml (100%) rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-shade => commandapi-paper/commandapi-paper-shade}/LICENSE (100%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-shade/javadoc/README.md create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-vh => commandapi-paper/commandapi-paper-vh}/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java (100%) create mode 100644 commandapi-platforms/commandapi-paper/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml rename {commandapi-annotations => commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations}/src/main/java/dev/jorel/commandapi/annotations/Annotations.java (94%) rename commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncOfflinePlayerArgument.java => commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncPlayerProfileArgument.java (52%) rename {commandapi-annotations => commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations}/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java (100%) rename {commandapi-annotations => commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations}/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java (100%) rename {commandapi-annotations => commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations}/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java (100%) rename commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerArgument.java => commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerProfileArgument.java (88%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigotConfig.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/InternalSpigotConfig.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/AsyncPlayerProfileArgument.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core => commandapi-spigot/commandapi-spigot-core}/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java (93%) rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core => commandapi-spigot/commandapi-spigot-core}/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java (89%) rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core => commandapi-spigot/commandapi-spigot-core}/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java (92%) rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core => commandapi-spigot/commandapi-spigot-core}/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java (93%) rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/OfflinePlayerArgument.java => commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/PlayerProfileArgument.java} (61%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped => commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped}/pom.xml (50%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped => commandapi-spigot/commandapi-spigot-plugin-mojang-mapped}/pom.xml (61%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-plugin-common => commandapi-spigot/commandapi-spigot-plugin-mojang-mapped}/src/main/java/dev/jorel/commandapi/CommandAPIMain.java (96%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-plugin => commandapi-spigot/commandapi-spigot-plugin-mojang-mapped}/src/main/resources/plugin.yml (100%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/LICENSE rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-plugin => commandapi-spigot/commandapi-spigot-plugin}/pom.xml (55%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/config.yml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/plugin.yml rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped => commandapi-spigot/commandapi-spigot-shade-mojang-mapped}/pom.xml (64%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/LICENSE create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/javadoc/README.md create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java create mode 100644 commandapi-platforms/commandapi-spigot/pom.xml create mode 100644 commandapi-testing/commandapi-testing-paper/pom.xml create mode 100644 commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java create mode 100644 commandapi-testing/commandapi-testing-paper/src/main/resources/plugin.yml create mode 100644 commandapi-testing/pom.xml create mode 100755 setupPaperNMS.sh diff --git a/.editorconfig b/.editorconfig index 03a8209fa..4b2065012 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,9 @@ indent_style = space [commandapi-documentation-velocity-code/**{.java,.kt}] indent_style = space + +[commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/**{.java,.kt}] +indent_style = space + +[commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/**{.java,.kt}] +indent_style = space diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff9e64621..1abb56d05 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,6 +49,9 @@ jobs: ### Compilation ### + - name: Setup Paper NMS for all applicable versions + run: ./setupPaperNMS.sh + - name: Build the CommandAPI (Bukkit+Velocity) using maven run: mvn clean install --batch-mode -P Platform.Bukkit,Platform.Velocity @@ -140,15 +143,25 @@ jobs: ### Upload .jar artifacts ### - - name: Upload CommandAPI (Bukkit) plugin artifact + - name: Upload CommandAPI (Spigot) plugin artifact if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS uses: actions/upload-artifact@v4 with: - name: CommandAPI (Bukkit plugin) + name: CommandAPI (Spigot plugin) path: | - commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/target/CommandAPI*.jar - !commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/target/*sources.jar - !commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/target/*javadoc.jar + commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/target/CommandAPI*.jar + !commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/target/*sources.jar + !commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/target/*javadoc.jar + + - name: Upload CommandAPI (Paper) plugin artifact + if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS + uses: actions/upload-artifact@v4 + with: + name: CommandAPI (Paper plugin) + path: | + commandapi-platforms/commandapi-paper/commandapi-paper-plugin/target/CommandAPI*.jar + !commandapi-platforms/commandapi-paper/commandapi-paper-plugin/target/*sources.jar + !commandapi-platforms/commandapi-paper/commandapi-paper-plugin/target/*javadoc.jar - name: Upload CommandAPI (Velocity) plugin artifact if: ${{ runner.os == 'Linux' && matrix.java == '21' }} # Only upload artifacts built from latest java on one OS @@ -162,8 +175,8 @@ jobs: ### Examples ### - - name: Build CommandAPI example plugins in examples/ folder - run: cd ./examples; ./build.sh; + #- name: Build CommandAPI example plugins in examples/ folder + # run: cd ./examples; ./build.sh; ### Save PR information for 'SonarAnalyze' - name: Save PR number to file diff --git a/.gitignore b/.gitignore index c681da171..2ae3cf246 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ docssrc/src/.markdownlint-cli2.yaml .gradle *.versionsBackup dependency-reduced-pom.xml +.paper-nms diff --git a/README.md b/README.md index 1da415073..f8202f8ed 100644 --- a/README.md +++ b/README.md @@ -392,6 +392,31 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025): + + 11.0.0 + ??? + + + + 10.1.0 June 2025 @@ -449,7 +474,7 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025): - + 9.7.0 December 2024 diff --git a/commandapi-annotations/pom.xml b/commandapi-annotations/pom.xml index 63d372ed8..6f8548bdc 100644 --- a/commandapi-annotations/pom.xml +++ b/commandapi-annotations/pom.xml @@ -18,11 +18,11 @@ dev.jorel commandapi - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-annotations - CommandAPI - Annotations Library + Annotations Library @@ -36,6 +36,7 @@ dev.jorel commandapi-bukkit-core ${project.version} + provided com.google.auto.service @@ -50,25 +51,5 @@ provided - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - testCompile - - - - dev.jorel.commandapi.annotations.Annotations - - - - - - - \ No newline at end of file diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AFloatRangeArgument.java b/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ADoubleRangeArgument.java similarity index 88% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AFloatRangeArgument.java rename to commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ADoubleRangeArgument.java index 2e6aa0675..b9a93471e 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AFloatRangeArgument.java +++ b/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ADoubleRangeArgument.java @@ -20,18 +20,18 @@ *******************************************************************************/ package dev.jorel.commandapi.annotations.arguments; +import dev.jorel.commandapi.arguments.DoubleRangeArgument; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import dev.jorel.commandapi.arguments.FloatRangeArgument; - /** - * Annotation equivalent of the {@link FloatRangeArgument} + * Annotation equivalent of the {@link DoubleRangeArgument} */ -@Primitive("dev.jorel.commandapi.wrappers.FloatRange") +@Primitive("dev.jorel.commandapi.wrappers.DoubleRange") @Retention(RetentionPolicy.SOURCE) @Target(ElementType.PARAMETER) -public @interface AFloatRangeArgument { +public @interface ADoubleRangeArgument { } diff --git a/commandapi-codecov/pom.xml b/commandapi-codecov/pom.xml index 27a4bfdb2..1ecc1af59 100644 --- a/commandapi-codecov/pom.xml +++ b/commandapi-codecov/pom.xml @@ -51,7 +51,7 @@ ${project.version} - + - - + ${project.version}--> + + diff --git a/commandapi-core/pom.xml b/commandapi-core/pom.xml index 1b494ed40..0aae7c12f 100644 --- a/commandapi-core/pom.xml +++ b/commandapi-core/pom.xml @@ -19,12 +19,12 @@ commandapi dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-core - CommandAPI - Core library + Core library diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java index 44574d9c8..551065cee 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java @@ -80,10 +80,11 @@ public static void setLogger(CommandAPILogger logger) { * @return the CommandAPI's logger */ public static CommandAPILogger getLogger() { - if (logger == null) { - logger = CommandAPIHandler.getInstance().getPlatform().getLogger(); + if (logger != null) { + // A custom logger was defined, use that + return logger; } - return logger; + return CommandAPIHandler.getInstance().getPlatform().getLogger(); } // Loading, enabling, and disabling @@ -114,6 +115,9 @@ public static void onLoad(CommandAPIConfig config) { new CommandAPIHandler<>(platform); loadContext.context().run(); + // Load the platform + CommandAPIHandler.getInstance().onLoad(config); + // Log platform load final String platformClassHierarchy; { @@ -129,9 +133,6 @@ public static void onLoad(CommandAPIConfig config) { } logNormal("Loaded platform " + platformClassHierarchy); - // Finish loading - CommandAPIHandler.getInstance().onLoad(config); - loaded = true; } else { getLogger().severe("You've tried to call the CommandAPI's onLoad() method more than once!"); diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java index 16e9f87c4..dba63d0af 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java @@ -33,18 +33,17 @@ public interface CommandAPIPlatform config); + void onLoad(CommandAPIConfig config); /** - * Platform-specific stuff that should happen when the CommandAPI is enabled, - * such as registering event listeners. + * Platform-specific stuff that should happen when the CommandAPI is enabled */ - public abstract void onEnable(); + void onEnable(); /** * Platform-specific stuff that should happen when the CommandAPI is disabled. */ - public abstract void onDisable(); + void onDisable(); // Converting between CommandSender, AbstractCommandSender, and Brigadier Sources @@ -55,7 +54,7 @@ public interface CommandAPIPlatform getSenderForCommand(CommandContext cmdCtx, boolean forceNative); + AbstractCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); /** * Converts the class used by Brigadier when running commands into an AbstractCommandSender wrapping the platform's CommandSender @@ -63,7 +62,7 @@ public interface CommandAPIPlatform getCommandSenderFromCommandSource(Source source); + AbstractCommandSender getCommandSenderFromCommandSource(Source source); /** * Converts a CommandSender wrapped in an AbstractCommandSender to an object Brigadier can use when running its commands @@ -71,7 +70,7 @@ public interface CommandAPIPlatform sender); + Source getBrigadierSourceFromCommandSender(AbstractCommandSender sender); /** * Wraps a CommandSender in an AbstractCommandSender class, the inverse operation to {@link AbstractCommandSender#getSource()} @@ -79,14 +78,14 @@ public interface CommandAPIPlatform wrapCommandSender(CommandSender sender); + AbstractCommandSender wrapCommandSender(CommandSender sender); // Registers a permission. Bukkit's permission system requires permissions to be "registered" // before they can be used. - public abstract void registerPermission(String string); + void registerPermission(String string); // Some commands have existing suggestion providers - public abstract SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider); + SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider); /** * Stuff to run before a command is generated. For Bukkit, this involves checking @@ -94,7 +93,7 @@ public interface CommandAPIPlatform resultantNode, List> aliasNodes); + void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode resultantNode, List> aliasNodes); /** * Registers a Brigadier command node and returns the built node. */ - public abstract LiteralCommandNode registerCommandNode(LiteralArgumentBuilder node, String namespace); + LiteralCommandNode registerCommandNode(LiteralArgumentBuilder node, String namespace); /** @@ -119,7 +118,7 @@ public interface CommandAPIPlatform setupMessenger(); + CommandAPIMessenger setupMessenger(); /** * @return The Brigadier CommandDispatcher tree being used by the platform's server */ - public abstract CommandDispatcher getBrigadierDispatcher(); + CommandDispatcher getBrigadierDispatcher(); /** * Creates a JSON file that describes the hierarchical structure of the commands @@ -142,13 +141,13 @@ public interface CommandAPIPlatform dispatcher) throws IOException; + void createDispatcherFile(File file, CommandDispatcher dispatcher) throws IOException; /** * @return A new default Logger meant for the CommandAPI to use. This logger will be used by the CommandAPI * if one is not set using {@link CommandAPI#setLogger(CommandAPILogger)}. */ - public default CommandAPILogger getLogger() { + default CommandAPILogger getLogger() { return new CommandAPILogger() { private static final String PREFIX = "[CommandAPI] "; private static final String YELLOW = "\u001B[33m"; @@ -181,19 +180,19 @@ public void severe(String message, Throwable throwable) { /** * Reloads the server's data packs to include CommandAPI commands */ - public abstract void reloadDataPacks(); + void reloadDataPacks(); /** * Updates the requirements required for a given player to execute a command. * * @param player the player to update */ - public abstract void updateRequirements(AbstractPlayer player); + void updateRequirements(AbstractPlayer player); // Create the concrete instances of objects implemented by the platform - public abstract AbstractCommandAPICommand newConcreteCommandAPICommand(CommandMetaData meta); + AbstractCommandAPICommand newConcreteCommandAPICommand(CommandMetaData meta); - public abstract Argument newConcreteMultiLiteralArgument(String nodeName, String[] literals); + Argument newConcreteMultiLiteralArgument(String nodeName, String[] literals); - public abstract Argument newConcreteLiteralArgument(String nodeName, String literal); + Argument newConcreteLiteralArgument(String nodeName, String literal); } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index a28b569b1..297da6925 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -7,6 +7,10 @@ */ public abstract class CommandAPIVersionHandler { + static Object getVersion() { + throw new IllegalStateException("You have the wrong copy of the CommandAPI! If you're shading, did you use commandapi-core instead of commandapi-{platform}-shade?"); + } + /** * Returns an instance of the version's implementation of CommandAPIPlatform. * diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/CommandAPIArgumentType.java b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/CommandAPIArgumentType.java index ee90c2cc5..bd6537938 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/CommandAPIArgumentType.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/CommandAPIArgumentType.java @@ -219,11 +219,6 @@ public enum CommandAPIArgumentType { */ OBJECTIVE_CRITERIA("minecraft:objective_criteria"), - /** - * The OfflinePlayerArgument - */ - OFFLINE_PLAYER("api:offline_player"), - /** * The ParticleArgument */ diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/FloatRange.java b/commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/DoubleRange.java similarity index 62% rename from commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/FloatRange.java rename to commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/DoubleRange.java index c2dc8d606..9dfe26ed7 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/FloatRange.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/wrappers/DoubleRange.java @@ -23,46 +23,46 @@ import java.util.Objects; /** - * A class representing a range of floats + * A class representing a range of doubles */ -public class FloatRange { +public class DoubleRange { - private final float low; - private final float high; + private final double low; + private final double high; /** - * Constructs a FloatRange with a lower bound and an upper bound + * Constructs a DoubleRange with a lower bound and an upper bound * @param low the lower bound of this range * @param high the upper bound of this range */ - public FloatRange(float low, float high) { + public DoubleRange(double low, double high) { this.low = low; this.high = high; } /** - * Constructs a FloatRange with a given lower bound and no upper bound + * Constructs a DoubleRange with a given lower bound and no upper bound * @param min the lower bound of this range - * @return a FloatRange min.. + * @return a DoubleRange min.. */ - public static FloatRange floatRangeGreaterThanOrEq(float min) { - return new FloatRange(min, Float.MAX_VALUE); + public static DoubleRange doubleRangeGreaterThanOrEq(double min) { + return new DoubleRange(min, Double.MAX_VALUE); } /** - * Constructs a FloatRange with a given upper bound and no lower bound + * Constructs a DoubleRange with a given upper bound and no lower bound * @param max the upper bound of this range - * @return a FloatRange ..max + * @return a DoubleRange ..max */ - public static FloatRange floatRangeLessThanOrEq(float max) { - return new FloatRange(-Float.MAX_VALUE, max); + public static DoubleRange doubleRangeLessThanOrEq(double max) { + return new DoubleRange(-Double.MAX_VALUE, max); } /** * The lower bound of this range. * @return the lower bound of this range */ - public float getLowerBound() { + public double getLowerBound() { return this.low; } @@ -70,28 +70,28 @@ public float getLowerBound() { * The upper bound of this range. * @return the upper bound of this range */ - public float getUpperBound() { + public double getUpperBound() { return this.high; } /** - * Determines if a float is within range of the lower bound (inclusive) and the upper bound (inclusive). - * @param f the float to check within range - * @return true if the given float is within the declared range + * Determines if a double is within range of the lower bound (inclusive) and the upper bound (inclusive). + * @param f the double to check within range + * @return true if the given double is within the declared range */ - public boolean isInRange(float f) { + public boolean isInRange(double f) { return f >= low && f <= high; } /** - * Converts this FloatRange to a Minecraft string for use with arguments + * Converts this DoubleRange to a Minecraft string for use with arguments * @return a Minecraft string for use with arguments */ @Override public String toString() { - if(this.high == Float.MAX_VALUE) { + if(this.high == Double.MAX_VALUE) { return this.low + ".."; - } else if(this.low == -Float.MAX_VALUE) { + } else if(this.low == -Double.MAX_VALUE) { return ".." + this.high; } else { return this.low + ".." + this.high; @@ -108,12 +108,12 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (!(obj instanceof FloatRange)) { + if (!(obj instanceof DoubleRange)) { return false; } - FloatRange other = (FloatRange) obj; - return Float.floatToIntBits(high) == Float.floatToIntBits(other.high) && - Float.floatToIntBits(low) == Float.floatToIntBits(other.low); + DoubleRange other = (DoubleRange) obj; + return Double.doubleToLongBits(high) == Double.doubleToLongBits(other.high) && + Double.doubleToLongBits(low) == Double.doubleToLongBits(other.low); } } diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml b/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml similarity index 92% rename from commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml rename to commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml index 70d5c2867..735ce90eb 100644 --- a/commandapi-kotlin/commandapi-bukkit-kotlin/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml @@ -7,11 +7,11 @@ dev.jorel commandapi-kotlin - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT - commandapi-bukkit-kotlin - CommandAPI - Bukkit support in Kotlin + commandapi-kotlin-bukkit + Bukkit support in Kotlin src/main/kotlin @@ -92,7 +92,7 @@ dev.jorel - commandapi-core-kotlin + commandapi-kotlin-core ${project.version} diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt similarity index 85% rename from commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt rename to commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt index 201322207..594a49620 100644 --- a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt @@ -4,9 +4,7 @@ package dev.jorel.commandapi.kotlindsl import dev.jorel.commandapi.* import dev.jorel.commandapi.arguments.* -import org.bukkit.command.CommandSender import org.bukkit.plugin.java.JavaPlugin -import java.util.function.Predicate inline fun commandAPICommand(name: String, command: CommandAPICommand.() -> Unit = {}) = CommandAPICommand(name).apply(command).register() inline fun commandAPICommand(name: String, namespace: String, command: CommandAPICommand.() -> Unit = {}) = CommandAPICommand(name).apply(command).register(namespace) @@ -28,10 +26,10 @@ inline fun CommandAPICommand.integerRangeArgument(nodeName: String, optional: Bo // Float arguments inline fun CommandAPICommand.floatArgument(nodeName: String, min: Float = -Float.MAX_VALUE, max: Float = Float.MAX_VALUE, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(FloatArgument(nodeName, min, max).setOptional(optional).apply(block)) -inline fun CommandAPICommand.floatRangeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(FloatRangeArgument(nodeName).setOptional(optional).apply(block)) // Double arguments inline fun CommandAPICommand.doubleArgument(nodeName: String, min: Double = -Double.MAX_VALUE, max: Double = Double.MAX_VALUE, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(DoubleArgument(nodeName, min, max).setOptional(optional).apply(block)) +inline fun CommandAPICommand.doubleRangeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(DoubleRangeArgument(nodeName).setOptional(optional).apply(block)) // Long arguments inline fun CommandAPICommand.longArgument(nodeName: String, min: Long = Long.MIN_VALUE, max: Long = Long.MAX_VALUE, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(LongArgument(nodeName, min, max).setOptional(optional).apply(block)) @@ -50,22 +48,11 @@ inline fun CommandAPICommand.location2DArgument(nodeName: String, locationType: inline fun CommandAPICommand.rotationArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(RotationArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.axisArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AxisArgument(nodeName).setOptional(optional).apply(block)) -// Chat arguments -inline fun CommandAPICommand.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.adventureChatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AdventureChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.adventureChatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AdventureChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.adventureChatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AdventureChatArgument(nodeName).setOptional(optional).apply(block)) - // Entity & Player arguments inline fun CommandAPICommand.entitySelectorArgumentOneEntity(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(EntitySelectorArgument.OneEntity(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.entitySelectorArgumentManyEntities(nodeName: String, allowEmpty: Boolean = true, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(EntitySelectorArgument.ManyEntities(nodeName, allowEmpty).setOptional(optional).apply(block)) inline fun CommandAPICommand.entitySelectorArgumentOnePlayer(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(EntitySelectorArgument.OnePlayer(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.entitySelectorArgumentManyPlayers(nodeName: String, allowEmpty: Boolean = true, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(EntitySelectorArgument.ManyPlayers(nodeName, allowEmpty).setOptional(optional).apply(block)) -inline fun CommandAPICommand.playerArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(PlayerArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.offlinePlayerArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(OfflinePlayerArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.asyncOfflinePlayerArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AsyncOfflinePlayerArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.entityTypeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(EntityTypeArgument(nodeName).setOptional(optional).apply(block)) // Scoreboard arguments diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt similarity index 85% rename from commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt rename to commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt index 43799994e..9ba00806c 100644 --- a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt @@ -4,7 +4,6 @@ import dev.jorel.commandapi.* import dev.jorel.commandapi.arguments.* import org.bukkit.command.CommandSender import org.bukkit.plugin.java.JavaPlugin -import java.util.function.Predicate const val WILL_NOT_REGISTER = "will-not-reg" @@ -35,10 +34,10 @@ inline fun CommandTree.integerRangeArgument(nodeName: String, optional: Boolean // Float arguments inline fun CommandTree.floatArgument(nodeName: String, min: Float = -Float.MAX_VALUE, max: Float = Float.MAX_VALUE, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(FloatArgument(nodeName, min, max).setOptional(optional).apply(block)) -inline fun CommandTree.floatRangeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(FloatRangeArgument(nodeName).setOptional(optional).apply(block)) // Double arguments inline fun CommandTree.doubleArgument(nodeName: String, min: Double = -Double.MAX_VALUE, max: Double = Double.MAX_VALUE, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(DoubleArgument(nodeName, min, max).setOptional(optional).apply(block)) +inline fun CommandTree.doubleRangeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(DoubleRangeArgument(nodeName).setOptional(optional).apply(block)) // Long arguments inline fun CommandTree.longArgument(nodeName: String, min: Long = Long.MIN_VALUE, max: Long = Long.MAX_VALUE, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(LongArgument(nodeName, min, max).setOptional(optional).apply(block)) @@ -57,22 +56,11 @@ inline fun CommandTree.location2DArgument(nodeName: String, locationType: Locati inline fun CommandTree.rotationArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(RotationArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.axisArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AxisArgument(nodeName).setOptional(optional).apply(block)) -// Chat arguments -inline fun CommandTree.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.adventureChatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AdventureChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.adventureChatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AdventureChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.adventureChatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AdventureChatArgument(nodeName).setOptional(optional).apply(block)) - // Entity & Player arguments inline fun CommandTree.entitySelectorArgumentOneEntity(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(EntitySelectorArgument.OneEntity(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.entitySelectorArgumentManyEntities(nodeName: String, allowEmpty: Boolean = true, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(EntitySelectorArgument.ManyEntities(nodeName, allowEmpty).setOptional(optional).apply(block)) inline fun CommandTree.entitySelectorArgumentOnePlayer(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(EntitySelectorArgument.OnePlayer(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.entitySelectorArgumentManyPlayers(nodeName: String, allowEmpty: Boolean = true, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(EntitySelectorArgument.ManyPlayers(nodeName, allowEmpty).setOptional(optional).apply(block)) -inline fun CommandTree.playerArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(PlayerArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.offlinePlayerArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(OfflinePlayerArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.asyncOfflinePlayerArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AsyncOfflinePlayerArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.entityTypeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(EntityTypeArgument(nodeName).setOptional(optional).apply(block)) // Scoreboard arguments @@ -149,10 +137,10 @@ inline fun Argument<*>.integerRangeArgument(nodeName: String, optional: Boolean // Float arguments inline fun Argument<*>.floatArgument(nodeName: String, min: Float = -Float.MAX_VALUE, max: Float = Float.MAX_VALUE, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(FloatArgument(nodeName, min, max).setOptional(optional).apply(block)) -inline fun Argument<*>.floatRangeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(FloatRangeArgument(nodeName).setOptional(optional).apply(block)) // Double arguments inline fun Argument<*>.doubleArgument(nodeName: String, min: Double = -Double.MAX_VALUE, max: Double = Double.MAX_VALUE, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(DoubleArgument(nodeName, min, max).setOptional(optional).apply(block)) +inline fun Argument<*>.doubleRangeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(DoubleRangeArgument(nodeName).setOptional(optional).apply(block)) // Long arguments inline fun Argument<*>.longArgument(nodeName: String, min: Long = Long.MIN_VALUE, max: Long = Long.MAX_VALUE, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(LongArgument(nodeName, min, max).setOptional(optional).apply(block)) @@ -171,22 +159,11 @@ inline fun Argument<*>.location2DArgument(nodeName: String, locationType: Locati inline fun Argument<*>.rotationArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(RotationArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.axisArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AxisArgument(nodeName).setOptional(optional).apply(block)) -// Chat arguments -inline fun Argument<*>.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.adventureChatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AdventureChatColorArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.adventureChatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AdventureChatComponentArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.adventureChatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AdventureChatArgument(nodeName).setOptional(optional).apply(block)) - // Entity & Player arguments inline fun Argument<*>.entitySelectorArgumentOneEntity(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(EntitySelectorArgument.OneEntity(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.entitySelectorArgumentManyEntities(nodeName: String, allowEmpty: Boolean = true, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(EntitySelectorArgument.ManyEntities(nodeName, allowEmpty).setOptional(optional).apply(block)) inline fun Argument<*>.entitySelectorArgumentOnePlayer(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(EntitySelectorArgument.OnePlayer(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.entitySelectorArgumentManyPlayers(nodeName: String, allowEmpty: Boolean = true, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(EntitySelectorArgument.ManyPlayers(nodeName, allowEmpty).setOptional(optional).apply(block)) -inline fun Argument<*>.playerArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(PlayerArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.offlinePlayerArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(OfflinePlayerArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.asyncOfflinePlayerArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AsyncOfflinePlayerArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.entityTypeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(EntityTypeArgument(nodeName).setOptional(optional).apply(block)) // Scoreboard arguments diff --git a/commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-bukkit-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt rename to commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt diff --git a/commandapi-kotlin/commandapi-core-kotlin/pom.xml b/commandapi-kotlin/commandapi-kotlin-core/pom.xml similarity index 92% rename from commandapi-kotlin/commandapi-core-kotlin/pom.xml rename to commandapi-kotlin/commandapi-kotlin-core/pom.xml index 29936ef86..4dd5c3567 100644 --- a/commandapi-kotlin/commandapi-core-kotlin/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-core/pom.xml @@ -7,11 +7,11 @@ dev.jorel commandapi-kotlin - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT - commandapi-core-kotlin - CommandAPI - Bukkit support in Kotlin core library + commandapi-kotlin-core + Bukkit support in Kotlin core library src/main/kotlin diff --git a/commandapi-kotlin/commandapi-core-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt b/commandapi-kotlin/commandapi-kotlin-core/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-core-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt rename to commandapi-kotlin/commandapi-kotlin-core/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPIDSL.kt diff --git a/commandapi-kotlin/commandapi-kotlin-paper/pom.xml b/commandapi-kotlin/commandapi-kotlin-paper/pom.xml new file mode 100644 index 000000000..b9907dbc3 --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-paper/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + dev.jorel + commandapi-kotlin + 11.0.0-SNAPSHOT + + + commandapi-kotlin-paper + Paper support in Kotlin + + + src/main/kotlin + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 17 + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + provided + + + dev.jorel + commandapi-paper-core + ${project.version} + provided + + + dev.jorel + commandapi-kotlin-bukkit + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt new file mode 100644 index 000000000..fa0db51ca --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt @@ -0,0 +1,15 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.Argument +import dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument +import dev.jorel.commandapi.arguments.ChatArgument +import dev.jorel.commandapi.arguments.ChatColorArgument +import dev.jorel.commandapi.arguments.ChatComponentArgument +import dev.jorel.commandapi.arguments.PlayerProfileArgument + +inline fun CommandAPICommand.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt new file mode 100644 index 000000000..94d98e7dd --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt @@ -0,0 +1,16 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.* +import dev.jorel.commandapi.arguments.* + +inline fun CommandTree.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) + +inline fun Argument<*>.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperExecutorDSL.kt b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperExecutorDSL.kt new file mode 100644 index 000000000..6ebb82efd --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperExecutorDSL.kt @@ -0,0 +1,31 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.BukkitExecutable +import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender +import dev.jorel.commandapi.executors.CommandArguments +import dev.jorel.commandapi.executors.ExecutionInfo +import dev.jorel.commandapi.executors.FeedbackForwardingCommandExecutor +import dev.jorel.commandapi.executors.FeedbackForwardingExecutionInfo +import dev.jorel.commandapi.executors.FeedbackForwardingResultingCommandExecutor +import dev.jorel.commandapi.executors.FeedbackForwardingResultingExecutionInfo +import org.bukkit.command.CommandSender + +// Executors for CommandAPICommand, CommandTree and ArgumentTree +inline fun BukkitExecutable<*>.feedbackForwardingExecutor(crossinline executor: (CommandSender, CommandArguments) -> Unit): BukkitExecutable<*> = executesFeedbackForwarding(FeedbackForwardingCommandExecutor { sender, args -> + executor(sender, args) +}) + +// Resulting executors +inline fun BukkitExecutable<*>.feedbackForwardingResultingExecutor(crossinline executor: (CommandSender, CommandArguments) -> Int): BukkitExecutable<*> = executesFeedbackForwarding(FeedbackForwardingResultingCommandExecutor { sender, args -> + executor(sender, args) +}) + +// ExecutionInfo normal executors +inline fun BukkitExecutable<*>.feedbackForwardingExecutionInfo(crossinline executor: (ExecutionInfo>) -> Unit): BukkitExecutable<*> = executesFeedbackForwarding(FeedbackForwardingExecutionInfo { info -> + executor(info) +}) + +// ExecutionInfo resulting executors +inline fun BukkitExecutable<*>.feedbackForwardingResultingExecutionInfo(crossinline executor: (ExecutionInfo>) -> Int): BukkitExecutable<*> = executesFeedbackForwarding(FeedbackForwardingResultingExecutionInfo { info -> + executor(info) +}) \ No newline at end of file diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml new file mode 100644 index 000000000..8ac862ba1 --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + dev.jorel + commandapi-kotlin + 11.0.0-SNAPSHOT + + + commandapi-kotlin-spigot + Spigot support in Kotlin + + + src/main/kotlin + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + + 17 + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + provided + + + dev.jorel + commandapi-spigot-core + ${project.version} + provided + + + dev.jorel + commandapi-kotlin-bukkit + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt new file mode 100644 index 000000000..fa0db51ca --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt @@ -0,0 +1,15 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.arguments.Argument +import dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument +import dev.jorel.commandapi.arguments.ChatArgument +import dev.jorel.commandapi.arguments.ChatColorArgument +import dev.jorel.commandapi.arguments.ChatComponentArgument +import dev.jorel.commandapi.arguments.PlayerProfileArgument + +inline fun CommandAPICommand.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt new file mode 100644 index 000000000..94d98e7dd --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt @@ -0,0 +1,16 @@ +package dev.jorel.commandapi.kotlindsl + +import dev.jorel.commandapi.* +import dev.jorel.commandapi.arguments.* + +inline fun CommandTree.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) + +inline fun Argument<*>.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-velocity/javadoc/README.md b/commandapi-kotlin/commandapi-kotlin-velocity/javadoc/README.md new file mode 100644 index 000000000..364e20c8b --- /dev/null +++ b/commandapi-kotlin/commandapi-kotlin-velocity/javadoc/README.md @@ -0,0 +1 @@ +# commandapi-kotlin-velocity \ No newline at end of file diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/pom.xml b/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml similarity index 92% rename from commandapi-kotlin/commandapi-velocity-kotlin/pom.xml rename to commandapi-kotlin/commandapi-kotlin-velocity/pom.xml index 5eb3ed72c..3c835bc18 100644 --- a/commandapi-kotlin/commandapi-velocity-kotlin/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml @@ -7,11 +7,11 @@ dev.jorel commandapi-kotlin - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT - commandapi-velocity-kotlin - CommandAPI - Velocity support in Kotlin + commandapi-kotlin-velocity + Velocity support in Kotlin src/main/kotlin @@ -85,7 +85,7 @@ dev.jorel - commandapi-core-kotlin + commandapi-kotlin-core ${project.version} diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt rename to commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt rename to commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt b/commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt similarity index 100% rename from commandapi-kotlin/commandapi-velocity-kotlin/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt rename to commandapi-kotlin/commandapi-kotlin-velocity/src/main/kotlin/dev/jorel/commandapi/kotlindsl/ExecutorDSL.kt diff --git a/commandapi-kotlin/commandapi-velocity-kotlin/javadoc/README.md b/commandapi-kotlin/commandapi-velocity-kotlin/javadoc/README.md deleted file mode 100644 index c21da588d..000000000 --- a/commandapi-kotlin/commandapi-velocity-kotlin/javadoc/README.md +++ /dev/null @@ -1 +0,0 @@ -# commandapi-velocity-kotlin diff --git a/commandapi-kotlin/pom.xml b/commandapi-kotlin/pom.xml index 3c918c103..b5ed72db8 100644 --- a/commandapi-kotlin/pom.xml +++ b/commandapi-kotlin/pom.xml @@ -6,11 +6,11 @@ dev.jorel commandapi - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-kotlin - CommandAPI - Kotlin support + Kotlin support pom \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml index 88daea866..571c74820 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml @@ -6,11 +6,11 @@ commandapi-bukkit dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-bukkit-core - CommandAPI - Bukkit support core library + Bukkit support core library diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java index 08d26ffa6..13c93ab0b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java @@ -1,6 +1,7 @@ package dev.jorel.commandapi; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.exceptions.PlatformException; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.executors.*; import org.bukkit.command.CommandSender; @@ -462,6 +463,9 @@ default Impl executesRemoteConsole(RemoteConsoleResultingExecutionInfo info) { * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingCommandExecutor executor) { + if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + } getExecutor().addNormalExecutor(executor); return instance(); } @@ -473,6 +477,9 @@ default Impl executesFeedbackForwarding(FeedbackForwardingCommandExecutor execut * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingExecutionInfo info) { + if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingExecutionInfo on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + } getExecutor().addNormalExecutor(info); return instance(); } @@ -484,6 +491,9 @@ default Impl executesFeedbackForwarding(FeedbackForwardingExecutionInfo info) { * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingResultingCommandExecutor executor) { + if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingResultingCommandExecutor on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + } getExecutor().addResultingExecutor(executor); return instance(); } @@ -495,6 +505,9 @@ default Impl executesFeedbackForwarding(FeedbackForwardingResultingCommandExecut * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingResultingExecutionInfo info) { + if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingResultingExecutionInfo on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + } getExecutor().addResultingExecutor(info); return instance(); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java new file mode 100644 index 000000000..e333b95b4 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java @@ -0,0 +1,25 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.network.BukkitCommandAPIMessenger; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; + +public interface BukkitPlatform extends CommandAPIPlatform, CommandSender, Source> { + + @Override + void onLoad(CommandAPIConfig config); + + CommandMap getCommandMap(); + + @Override + BukkitCommandSender wrapCommandSender(CommandSender sender); + + Platform activePlatform(); + + BukkitCommandAPIMessenger getMessenger(); + + CommandRegistrationStrategy createCommandRegistrationStrategy(); + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitTooltip.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitTooltip.java index 06b4578f6..8fb084845 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitTooltip.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitTooltip.java @@ -144,7 +144,7 @@ public static Tooltip ofAdventureComponent(S object, ComponentLike toolti * @return native minecraft message object which can be used natively by brigadier. */ public static Message messageFromBaseComponents(BaseComponent... components) { - return CommandAPIBukkit.get().generateMessageFromJson(ComponentSerializer.toString(components)); + return CommandAPIBukkit.get().getNMS().generateMessageFromJson(ComponentSerializer.toString(components)); } /** @@ -157,7 +157,7 @@ public static Message messageFromBaseComponents(BaseComponent... components) { * @return native minecraft message object which can be used natively by brigadier. */ public static Message messageFromAdventureComponent(ComponentLike component) { - return CommandAPIBukkit.get().generateMessageFromJson(GsonComponentSerializer.gson().serialize(component.asComponent())); + return CommandAPIBukkit.get().getNMS().generateMessageFromJson(GsonComponentSerializer.gson().serialize(component.asComponent())); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java index aec38eda7..e5bc92547 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java @@ -1,49 +1,10 @@ package dev.jorel.commandapi; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CRAFTBUKKIT; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CSS; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_MINECRAFT_SERVER; -import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Keyed; -import org.bukkit.command.BlockCommandSender; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.command.PluginCommand; -import org.bukkit.command.ProxiedCommandSender; -import org.bukkit.command.RemoteConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.server.ServerLoadEvent; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.Recipe; -import org.bukkit.permissions.Permission; -import org.bukkit.plugin.java.JavaPlugin; - import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.tree.LiteralCommandNode; - import dev.jorel.commandapi.arguments.AbstractArgument; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.LiteralArgument; @@ -51,78 +12,118 @@ import dev.jorel.commandapi.arguments.SuggestionProviders; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.AbstractPlayer; -import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitEntity; -import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitPlayer; -import dev.jorel.commandapi.commandsenders.BukkitProxiedCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.network.BukkitCommandAPIMessenger; import dev.jorel.commandapi.nms.NMS; -import dev.jorel.commandapi.preprocessor.Unimplemented; -import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; -import net.kyori.adventure.text.ComponentLike; -import net.md_5.bungee.api.chat.BaseComponent; +import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Keyed; +import org.bukkit.command.CommandSender; +import org.bukkit.command.PluginCommand; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerLoadEvent; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; +import org.bukkit.permissions.Permission; +import org.bukkit.plugin.java.JavaPlugin; -// CommandAPIBukkit is an CommandAPIPlatform, but also needs all of the methods from -// NMS, so it implements NMS. Our implementation of CommandAPIBukkit is now derived -// using the version handler (and thus, deferred to our NMS-specific implementations) -public abstract class CommandAPIBukkit implements CommandAPIPlatform, CommandSender, Source>, NMS { +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.logging.Level; +import java.util.logging.Logger; + +public abstract class CommandAPIBukkit implements BukkitPlatform { // References to utility classes - private static CommandAPIBukkit instance; - private static InternalBukkitConfig config; - private PaperImplementations paper; - private CommandRegistrationStrategy commandRegistrationStrategy; + private static CommandAPIBukkit bukkit; + protected static InternalBukkitConfig config; private BukkitCommandAPIMessenger messenger; + protected JavaPlugin plugin; + protected NMS nms; + private CommandRegistrationStrategy commandRegistrationStrategy; + + private CommandAPILogger logger; + + private final boolean isPaperBrigAPI; + protected CommandAPIBukkit() { - CommandAPIBukkit.instance = this; + CommandAPIBukkit.bukkit = this; + + boolean paperCommandSourceStackPresent; + try { + Class.forName("io.papermc.paper.command.brigadier.CommandSourceStack"); + paperCommandSourceStackPresent = true; + } catch (ClassNotFoundException e) { + paperCommandSourceStackPresent = false; + } + this.isPaperBrigAPI = paperCommandSourceStackPresent; } @SuppressWarnings("unchecked") public static CommandAPIBukkit get() { - if(CommandAPIBukkit.instance != null) { - return (CommandAPIBukkit) instance; - } else { - throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + if (CommandAPIBukkit.bukkit != null) { + return (CommandAPIBukkit) bukkit; + } + throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + } + + @SuppressWarnings("unchecked") + public static > T platform() { + if (CommandAPIBukkit.bukkit != null) { + return (T) bukkit; } + throw new IllegalStateException("Tried to access the Bukkit platform, but it was null! Are you using CommandAPI features before calling CommandPAI#onLoad?"); } - public PaperImplementations getPaper() { - return paper; + public JavaPlugin getPlugin() { + return plugin; + } + + public NMS getNMS() { + if (nms != null) { + return nms; + } + throw new IllegalStateException("Tried to access NMS instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); } public static InternalBukkitConfig getConfiguration() { - if(config != null) { + if (config != null) { return config; - } else { - throw new IllegalStateException("Tried to access InternalBukkitConfig, but it was null! Did you load the CommandAPI properly with CommandAPI#onLoad?"); } + throw new IllegalStateException("Tried to access InternalBukkitConfig, but it was null! Did you load the CommandAPI properly with CommandAPI#onLoad?"); } public CommandRegistrationStrategy getCommandRegistrationStrategy() { return commandRegistrationStrategy; } - @Override - public void onLoad(CommandAPIConfig config) { - if(config instanceof CommandAPIBukkitConfig bukkitConfig) { - CommandAPIBukkit.setInternalConfig(new InternalBukkitConfig(bukkitConfig)); - } else { - CommandAPI.logError("CommandAPIBukkit was loaded with non-Bukkit config!"); - CommandAPI.logError("Attempts to access Bukkit-specific config variables will fail!"); - } - + public void onLoad() { checkDependencies(); } - - private static void setInternalConfig(InternalBukkitConfig internalBukkitConfig) { - CommandAPIBukkit.config = internalBukkitConfig; + + protected void stopCommandRegistrations() { + // Prevent command registration after server has loaded + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + // We want the lowest priority so that we always get to this first, in case a dependent plugin is using + // CommandAPI features in their own ServerLoadEvent listener for some reason + @EventHandler(priority = EventPriority.LOWEST) + public void onServerLoad(ServerLoadEvent event) { + CommandAPI.stopCommandRegistration(); + } + }, plugin); } private void checkDependencies() { @@ -142,72 +143,7 @@ private void checkDependencies() { } } - try { - Class.forName("net.kyori.adventure.text.Component"); - CommandAPI.logNormal("Hooked into Adventure for AdventureChat/AdventureChatComponents"); - } catch (ClassNotFoundException e) { - if (CommandAPI.getConfiguration().hasVerboseOutput()) { - CommandAPI.logWarning("Could not hook into Adventure for AdventureChat/AdventureChatComponents"); - } - } - - boolean isPaperPresent = false; - - try { - Class.forName("io.papermc.paper.event.server.ServerResourcesReloadedEvent"); - isPaperPresent = true; - CommandAPI.logNormal("Hooked into Paper for paper-specific API implementations"); - } catch (ClassNotFoundException e) { - isPaperPresent = false; - if (CommandAPI.getConfiguration().hasVerboseOutput()) { - CommandAPI.logWarning("Could not hook into Paper for /minecraft:reload. Consider upgrading to Paper: https://papermc.io/"); - } - } - - boolean isFoliaPresent = false; - - try { - Class.forName("io.papermc.paper.threadedregions.RegionizedServerInitEvent"); - isFoliaPresent = true; - CommandAPI.logNormal("Hooked into Folia for folia-specific API implementations"); - CommandAPI.logNormal("Folia support is still in development. Please report any issues to the CommandAPI developers!"); - } catch (ClassNotFoundException e) { - isFoliaPresent = false; - } - - paper = new PaperImplementations(isPaperPresent, isFoliaPresent, this); - - commandRegistrationStrategy = createCommandRegistrationStrategy(); - } - - @Override - public void onEnable() { - JavaPlugin plugin = config.getPlugin(); - - new Schedulers(paper).scheduleSyncDelayed(plugin, () -> { - commandRegistrationStrategy.runTasksAfterServerStart(); - - if (paper.isFoliaPresent()) { - CommandAPI.logNormal("Skipping initial datapack reloading because Folia was detected"); - } else { - if (!getConfiguration().skipReloadDatapacks()) { - reloadDataPacks(); - } - } - updateHelpForCommands(CommandAPI.getRegisteredCommands()); - }, 0L); - - // Prevent command registration after server has loaded - Bukkit.getServer().getPluginManager().registerEvents(new Listener() { - // We want the lowest priority so that we always get to this first, in case a dependent plugin is using - // CommandAPI features in their own ServerLoadEvent listener for some reason - @EventHandler(priority = EventPriority.LOWEST) - public void onServerLoad(ServerLoadEvent event) { - CommandAPI.stopCommandRegistration(); - } - }, getConfiguration().getPlugin()); - - paper.registerReloadHandler(plugin); + commandRegistrationStrategy = ((BukkitPlatform) bukkit).createCommandRegistrationStrategy(); } /* @@ -278,7 +214,7 @@ void updateHelpForCommands(List commands) { Map helpTopicsToAdd = new HashMap<>(); for (RegisteredCommand command : commands) { - if (getPaper().isPaperBrigAPI() && !command.shouldGenerateHelpTopic()) continue; + if (isPaperBrigAPI && !command.shouldGenerateHelpTopic()) continue; // Don't override the plugin help topic String commandPrefix = generateCommandHelpPrefix(command.commandName()); @@ -303,7 +239,7 @@ void updateHelpForCommands(List commands) { } else if (fullDescriptionOptional.isPresent()) { shortDescription = fullDescriptionOptional.get(); } else { - shortDescription = "A command by the " + config.getPlugin().getName() + " plugin."; + shortDescription = "A command by the " + plugin.getName() + " plugin."; } // Generate full description @@ -322,7 +258,7 @@ void updateHelpForCommands(List commands) { sb.append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.WHITE).append(String.join(", ", command.aliases())); } - helpTopic = generateHelpTopic(commandPrefix, shortDescription, sb.toString().trim(), permission); + helpTopic = nms.generateHelpTopic(commandPrefix, shortDescription, sb.toString().trim(), permission); } helpTopicsToAdd.put(commandPrefix, helpTopic); @@ -343,14 +279,15 @@ void updateHelpForCommands(List commands) { // Don't override the plugin help topic commandPrefix = generateCommandHelpPrefix(alias); - helpTopic = generateHelpTopic(commandPrefix, shortDescription, currentAliasSb.toString().trim(), permission); + + helpTopic = nms.generateHelpTopic(commandPrefix, shortDescription, currentAliasSb.toString().trim(), permission); } helpTopicsToAdd.put(commandPrefix, helpTopic); } } // We have to use helpTopics.put (instead of .addTopic) because we're overwriting an existing help topic, not adding a new help topic - getHelpMap().putAll(helpTopicsToAdd); + nms.getHelpMap().putAll(helpTopicsToAdd); } @Override @@ -359,56 +296,7 @@ public void onDisable() { } @Override - @Unimplemented(because = REQUIRES_CSS) - public abstract BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); - - @Override - @Unimplemented(because = REQUIRES_CSS) - public abstract BukkitCommandSender getCommandSenderFromCommandSource(Source cs); - - @Override - @Unimplemented(because = REQUIRES_CRAFTBUKKIT) - public abstract Source getBrigadierSourceFromCommandSender(AbstractCommandSender sender); - - public BukkitCommandSender wrapCommandSender(CommandSender sender) { - if (sender instanceof BlockCommandSender block) { - return new BukkitBlockCommandSender(block); - } - if (sender instanceof ConsoleCommandSender console) { - return new BukkitConsoleCommandSender(console); - } - if (sender instanceof Player player) { - return new BukkitPlayer(player); - } - if (sender instanceof org.bukkit.entity.Entity entity) { - return new BukkitEntity(entity); - } - if (sender instanceof NativeProxyCommandSender nativeProxy) { - return new BukkitNativeProxyCommandSender(nativeProxy); - } - if (sender instanceof ProxiedCommandSender proxy) { - return new BukkitProxiedCommandSender(proxy); - } - if (sender instanceof RemoteConsoleCommandSender remote) { - return new BukkitRemoteConsoleCommandSender(remote); - } - if (paper.isPaperPresent()) { - final Class FeedbackForwardingSender = paper.getFeedbackForwardingCommandSender(); - if (FeedbackForwardingSender.isInstance(sender)) { - // We literally cannot type this at compile-time, so let's use a placeholder CommandSender instance - return new BukkitFeedbackForwardingCommandSender(FeedbackForwardingSender.cast(sender)); - } - - final Class NullCommandSender = paper.getNullCommandSender(); - if (NullCommandSender != null && NullCommandSender.isInstance(sender)) { - // Since this should only be during a function load or setting up - // help topics, this is just a placeholder to evade the exception. - return null; - } - - } - throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender"); - } + public abstract BukkitCommandSender wrapCommandSender(CommandSender sender); @Override public void registerPermission(String string) { @@ -419,12 +307,11 @@ public void registerPermission(String string) { } } - @Override - @Unimplemented(because = REQUIRES_MINECRAFT_SERVER) - public abstract SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider); - @Override public void preCommandRegistration(String commandName) { + if (Bukkit.getServer() == null) { + return; // and pray that nothing happens later + } // Warn if the command we're registering already exists in this plugin's // plugin.yml file final PluginCommand pluginCommand = Bukkit.getPluginCommand(commandName); @@ -432,7 +319,7 @@ public void preCommandRegistration(String commandName) { return; } String pluginName = pluginCommand.getPlugin().getName(); - if (config.getPlugin().getName().equals(pluginName)) { + if (plugin.getName().equals(pluginName)) { CommandAPI.logWarning( "Plugin command /%s is registered by Bukkit (%s). Did you forget to remove this from your plugin.yml file?" .formatted(commandName, pluginName)); @@ -494,7 +381,7 @@ private void unregisterInternal(String commandName, boolean unregisterNamespaces if (!CommandAPI.canRegister()) { // Help topics (from Bukkit and CommandAPI) are only setup after plugins enable, so we only need to worry // about removing them once the server is loaded. - getHelpMap().remove("/" + commandName); + nms.getHelpMap().remove("/" + commandName); // Notify players for (Player p : Bukkit.getOnlinePlayers()) { @@ -505,10 +392,11 @@ private void unregisterInternal(String commandName, boolean unregisterNamespaces @Override public BukkitCommandAPIMessenger setupMessenger() { - messenger = new BukkitCommandAPIMessenger(getConfiguration().getPlugin()); + messenger = new BukkitCommandAPIMessenger(plugin); return messenger; } + @Override public BukkitCommandAPIMessenger getMessenger() { return messenger; } @@ -518,16 +406,11 @@ public final CommandDispatcher getBrigadierDispatcher() { return commandRegistrationStrategy.getBrigadierDispatcher(); } - @Override - @Unimplemented(because = {REQUIRES_MINECRAFT_SERVER, VERSION_SPECIFIC_IMPLEMENTATION}) - public abstract void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException; - - @Unimplemented(because = REQUIRES_MINECRAFT_SERVER) // What are the odds? - public abstract T getMinecraftServer(); - - @Override public CommandAPILogger getLogger() { - return new DefaultLogger(); + if (logger == null) { + logger = new DefaultLogger(); + } + return logger; } private static class DefaultLogger extends Logger implements CommandAPILogger { @@ -543,10 +426,6 @@ public void severe(String message, Throwable exception) { } } - @Override - @Unimplemented(because = VERSION_SPECIFIC_IMPLEMENTATION) - public abstract void reloadDataPacks(); - @Override public void updateRequirements(AbstractPlayer player) { ((Player) player.getSource()).updateCommands(); @@ -566,28 +445,6 @@ public Argument newConcreteLiteralArgument(String nodeName, String liter public CommandAPICommand newConcreteCommandAPICommand(CommandMetaData meta) { return new CommandAPICommand(meta); } - - /** - * Forces a command to return a success value of 0 - * - * @param message Description of the error message, formatted as an array of base components - * @return a {@link WrapperCommandSyntaxException} that wraps Brigadier's - * {@link CommandSyntaxException} - */ - public static WrapperCommandSyntaxException failWithBaseComponents(BaseComponent... message) { - return CommandAPI.failWithMessage(BukkitTooltip.messageFromBaseComponents(message)); - } - - /** - * Forces a command to return a success value of 0 - * - * @param message Description of the error message, formatted as an adventure chat component - * @return a {@link WrapperCommandSyntaxException} that wraps Brigadier's - * {@link CommandSyntaxException} - */ - public static WrapperCommandSyntaxException failWithAdventureComponent(ComponentLike message) { - return CommandAPI.failWithMessage(BukkitTooltip.messageFromAdventureComponent(message)); - } /** * Initializes the CommandAPI's implementation of an NBT API. If you are shading @@ -608,8 +465,8 @@ public static WrapperCommandSyntaxException failWithAdventureComponent(Component public static void initializeNBTAPI(Class nbtContainerClass, Function nbtContainerConstructor) { getConfiguration().lateInitializeNBT(nbtContainerClass, nbtContainerConstructor); } - - protected void registerBukkitRecipesSafely(Iterator recipes) { + + public void registerBukkitRecipesSafely(Iterator recipes) { Recipe recipe; while (recipes.hasNext()) { recipe = recipes.next(); @@ -644,4 +501,38 @@ boolean isInvalidNamespace(String commandName, String namespace) { } return false; } + + /* + * Implement several methods from CommandAPIPlatform that just need to delegate to NMS + */ + + @Override + public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { + return nms.getSenderForCommand(cmdCtx, forceNative); + } + + @Override + public Source getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { + return nms.getBrigadierSourceFromCommandSender(sender); + } + + @Override + public SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider) { + return nms.getSuggestionProvider(suggestionProvider); + } + + @Override + public BukkitCommandSender getCommandSenderFromCommandSource(Source css) { + return nms.getCommandSenderFromCommandSource(css); + } + + @Override + public void createDispatcherFile(File file, CommandDispatcher dispatcher) throws IOException { + nms.createDispatcherFile(file, dispatcher); + } + + @Override + public void reloadDataPacks() { + nms.reloadDataPacks(); + } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java index b23020a5c..f3c9c1d61 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java @@ -1,54 +1,26 @@ package dev.jorel.commandapi; -import io.papermc.paper.event.server.ServerResourcesReloadedEvent; import org.bukkit.plugin.java.JavaPlugin; /** * A class that contains information needed to configure the CommandAPI on Bukkit-based servers. */ -public class CommandAPIBukkitConfig extends CommandAPIConfig { +public abstract class CommandAPIBukkitConfig> extends CommandAPIConfig { - JavaPlugin plugin; + String pluginName; // Default configuration - boolean shouldHookPaperReload = false; boolean skipReloadDatapacks = true; /** * Creates a new CommandAPIBukkitConfig object. Variables in this * constructor are required to load the CommandAPI on Bukkit properly. * - * @param plugin The {@link JavaPlugin} that is loading the CommandAPI - * This is used when registering events. + * @param pluginName The name of the {@link JavaPlugin} that is loading the CommandAPI */ - public CommandAPIBukkitConfig(JavaPlugin plugin) { - this.plugin = plugin; - super.setNamespace(plugin.getName().toLowerCase()); - } - - /** - * Sets the CommandAPI to hook into Paper's {@link ServerResourcesReloadedEvent} when available - * if true. This helps CommandAPI commands to work in datapacks after {@code /minecraft:reload} - * is run. - * - * @param hooked whether the CommandAPI should hook into Paper's {@link ServerResourcesReloadedEvent} - * @return this CommandAPIBukkitConfig - */ - public CommandAPIBukkitConfig shouldHookPaperReload(boolean hooked) { - this.shouldHookPaperReload = hooked; - return this; - } - - /** - * Sets whether the CommandAPI should skip its datapack reload step after the server - * has finished loading. This does not skip reloading of datapacks when invoked manually - * when {@link #shouldHookPaperReload(boolean)} is set. - * @param skip whether the CommandAPI should skip reloading datapacks when the server has finished loading - * @return this CommandAPIBukkitConfig - */ - public CommandAPIBukkitConfig skipReloadDatapacks(boolean skip) { - this.skipReloadDatapacks = skip; - return this; + public CommandAPIBukkitConfig(String pluginName) { + this.pluginName = pluginName; + super.setNamespace(pluginName.toLowerCase()); } /** @@ -56,30 +28,28 @@ public CommandAPIBukkitConfig skipReloadDatapacks(boolean skip) { * @return this CommandAPIBukkitConfig */ @Deprecated(since = "10.0.0", forRemoval = true) - public CommandAPIBukkitConfig usePluginNamespace() { - super.setNamespace(plugin.getName().toLowerCase()); + public T usePluginNamespace() { + super.setNamespace(pluginName.toLowerCase()); super.usePluginNamespace = true; - return this; + return instance(); } @Override - public CommandAPIBukkitConfig setNamespace(String namespace) { + public T setNamespace(String namespace) { if (namespace == null) { throw new NullPointerException("Default namespace can't be null!"); } if (namespace.isEmpty()) { CommandAPI.logNormal("Did not set namespace to an empty value! Namespace '" + super.namespace + "' is used as the default namespace!"); - return this; + return instance(); } if (!CommandAPIHandler.NAMESPACE_PATTERN.matcher(namespace).matches()) { CommandAPI.logNormal("Did not set namespace to the provided '" + namespace + "' namespace because only 0-9, a-z, underscores, periods and hyphens are allowed!"); - return this; + return instance(); } return super.setNamespace(namespace); } @Override - public CommandAPIBukkitConfig instance() { - return this; - } + public abstract T instance(); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java index 58dedd464..84b8a3500 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java @@ -196,7 +196,7 @@ private static void convertPluginCommand(JavaPlugin plugin, String commandName, org.bukkit.command.Command command = plugin.getCommand(commandName); if (command == null) { - command = CommandAPIBukkit.get().getSimpleCommandMap() + command = CommandAPIBukkit.get().getNMS().getSimpleCommandMap() .getCommand(commandName); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java index 371f24fe4..417074a45 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java @@ -1,6 +1,5 @@ package dev.jorel.commandapi; -import io.papermc.paper.event.server.ServerResourcesReloadedEvent; import org.bukkit.plugin.java.JavaPlugin; /** @@ -8,13 +7,10 @@ * only ever read from, nothing is ever written to it. That's why there's only * getter methods. */ -public class InternalBukkitConfig extends InternalConfig { - // The plugin that is loading the CommandAPI - private final JavaPlugin plugin; +public abstract class InternalBukkitConfig extends InternalConfig { + // The name of the plugin that is loading the CommandAPI + private final String pluginName; - // Whether to hook into paper's reload event to reload datapacks when /minecraft:reload is run - private final boolean shouldHookPaperReload; - private final boolean skipReloadDatapacks; /** @@ -22,35 +18,24 @@ public class InternalBukkitConfig extends InternalConfig { * * @param config The configuration to use to set up this internal configuration */ - public InternalBukkitConfig(CommandAPIBukkitConfig config) { + public InternalBukkitConfig(CommandAPIBukkitConfig> config) { super(config); - this.plugin = config.plugin; - this.shouldHookPaperReload = config.shouldHookPaperReload; + this.pluginName = config.pluginName; this.skipReloadDatapacks = config.skipReloadDatapacks; } /** - * @return The {@link JavaPlugin} that is loading the CommandAPI + * @return The name of the {@link JavaPlugin} that is loading the CommandAPI */ - public JavaPlugin getPlugin() { - return plugin; + public String getPluginName() { + return pluginName; } - /** - * @return Whether the CommandAPI should hook into Paper's {@link ServerResourcesReloadedEvent} - * when available to perform the CommandAPI's custom datapack reload when {@code /minecraft:reload} - * is run. - */ - public boolean shouldHookPaperReload() { - return shouldHookPaperReload; - } - - - /** * @return Whether the CommandAPI should skip reloading datapacks when the server has finished loading */ public boolean skipReloadDatapacks() { return skipReloadDatapacks; } + } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java deleted file mode 100644 index 324b33990..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java +++ /dev/null @@ -1,266 +0,0 @@ -package dev.jorel.commandapi; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.tree.CommandNode; -import com.mojang.brigadier.tree.LiteralCommandNode; -import com.mojang.brigadier.tree.RootCommandNode; -import io.papermc.paper.plugin.configuration.PluginMeta; -import org.bukkit.help.HelpTopic; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; -import java.util.function.Supplier; - -/** - * Handles logic for registering commands after Paper build 65, where https://github.com/PaperMC/Paper/pull/8235 - * changed a bunch of the behind-the-scenes logic. - */ -public class PaperCommandRegistration extends CommandRegistrationStrategy { - // References to necessary methods - private final Supplier> getBrigadierDispatcher; - private final Runnable reloadHelpTopics; - private final Predicate> isBukkitCommand; - - // Store registered commands nodes for eventual reloads - private final RootCommandNode registeredNodes = new RootCommandNode<>(); - - private static final Object paperCommandsInstance; - private static final Field dispatcherField; - - private static final Constructor pluginCommandNodeConstructor; - private static final SafeVarHandle, Object> metaField; - - static { - // Deal with retrieving the dispatcher in the PaperCommands class - Object paperCommandsInstanceObject = null; - Field dispatcherFieldObject = null; - - try { - Class paperCommands = Class.forName("io.papermc.paper.command.brigadier.PaperCommands"); - paperCommandsInstanceObject = paperCommands.getField("INSTANCE").get(null); - dispatcherFieldObject = paperCommands.getDeclaredField("dispatcher"); - } catch (ReflectiveOperationException e) { - // Doesn't happen, or rather, shouldn't happen - } - - paperCommandsInstance = paperCommandsInstanceObject; - dispatcherField = dispatcherFieldObject; - dispatcherField.setAccessible(true); - - // Deal with retrieving a constructor to mark a command as a plugin command - Constructor commandNode; - SafeVarHandle, ?> metaFieldHandle = null; - try { - commandNode = Class.forName("io.papermc.paper.command.brigadier.PluginCommandNode").getDeclaredConstructor(String.class, PluginMeta.class, LiteralCommandNode.class, String.class); - } catch (ClassNotFoundException | NoSuchMethodException e) { - try { - // If this happens, plugin commands on Paper are not identified with the PluginCommandNode anymore - Class pluginCommandMeta = Class.forName("io.papermc.paper.command.brigadier.PluginCommandMeta"); - commandNode = pluginCommandMeta.getDeclaredConstructor(PluginMeta.class, String.class, List.class); - metaFieldHandle = SafeVarHandle.ofOrNull(CommandNode.class, "pluginCommandMeta", "pluginCommandMeta", pluginCommandMeta); - } catch (ClassNotFoundException | NoSuchMethodException e1) { - try { - // If this happens, the PluginCommandMeta as been renamed to APICommandMeta - Class apiCommandMeta = Class.forName("io.papermc.paper.command.brigadier.APICommandMeta"); - commandNode = apiCommandMeta.getDeclaredConstructor(PluginMeta.class, String.class, List.class, String.class, boolean.class); - metaFieldHandle = SafeVarHandle.ofOrNull(CommandNode.class, "apiCommandMeta", "apiCommandMeta", apiCommandMeta); - } catch (ClassNotFoundException | NoSuchMethodException e2) { - try { - // If this happens, the boolean parameter was removed from APICommandMeta - Class apiCommandMeta = Class.forName("io.papermc.paper.command.brigadier.APICommandMeta"); - commandNode = apiCommandMeta.getDeclaredConstructor(PluginMeta.class, String. class, List.class, String.class); - metaFieldHandle = SafeVarHandle.ofOrNull(CommandNode.class, "apiCommandMeta", "apiCommandMeta", apiCommandMeta); - } catch (ClassNotFoundException |NoSuchMethodException e3) { - commandNode = null; - } - } - } - } - pluginCommandNodeConstructor = commandNode; - metaField = (SafeVarHandle, Object>) metaFieldHandle; - } - - public PaperCommandRegistration(Supplier> getBrigadierDispatcher, Runnable reloadHelpTopics, Predicate> isBukkitCommand) { - this.getBrigadierDispatcher = getBrigadierDispatcher; - this.reloadHelpTopics = reloadHelpTopics; - this.isBukkitCommand = isBukkitCommand; - } - - // Provide access to internal functions that may be useful to developers - - /** - * Checks if a Brigadier command node came from wrapping a Bukkit command - * - * @param node The CommandNode to check - * @return true if the CommandNode is being handled by Paper's BukkitCommandNode - */ - public boolean isBukkitCommand(CommandNode node) { - return isBukkitCommand.test(node); - } - - @SuppressWarnings("unchecked") - public CommandDispatcher getPaperDispatcher() { - try { - return (CommandDispatcher) dispatcherField.get(paperCommandsInstance); - } catch (IllegalAccessException e) { - // This doesn't happen - return null; - } - } - - // Implement CommandRegistrationStrategy methods - @Override - public CommandDispatcher getBrigadierDispatcher() { - return getBrigadierDispatcher.get(); - } - - @Override - public void runTasksAfterServerStart() { - // Nothing to do - } - - @Override - public void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode resultantNode, List> aliasNodes) { - // Nothing to do - } - - @Override - public LiteralCommandNode registerCommandNode(LiteralArgumentBuilder node, String namespace) { - LiteralCommandNode commandNode = asPluginCommand(node.build()); - LiteralCommandNode namespacedCommandNode = asPluginCommand(CommandAPIHandler.getInstance().namespaceNode(commandNode, namespace)); - - // Add to registered command nodes - registeredNodes.addChild(commandNode); - registeredNodes.addChild(namespacedCommandNode); - - // Register commands - RootCommandNode root = getPaperDispatcher().getRoot(); - root.addChild(commandNode); - root.addChild(namespacedCommandNode); - - return commandNode; - } - - @Override - public void unregister(String commandName, boolean unregisterNamespaces, boolean unregisterBukkit) { - // Remove nodes from the dispatcher - removeBrigadierCommands(getBrigadierDispatcher().getRoot(), commandName, unregisterNamespaces, - // If we are unregistering a Bukkit command, ONLY unregister BukkitCommandNodes - // If we are unregistering a Vanilla command, DO NOT unregister BukkitCommandNodes - c -> !unregisterBukkit ^ isBukkitCommand.test(c)); - - // CommandAPI commands count as non-Bukkit - if (!unregisterBukkit) { - // Don't add nodes back after a reload - removeBrigadierCommands(registeredNodes, commandName, unregisterNamespaces, c -> true); - } - - // Update the dispatcher file - CommandAPIHandler.getInstance().writeDispatcherToFile(); - } - - @Override - public void preReloadDataPacks() { - RootCommandNode root = getPaperDispatcher().getRoot(); - for (CommandNode commandNode : registeredNodes.getChildren()) { - root.addChild(commandNode); - } - reloadHelpTopics.run(); - CommandAPIBukkit.get().updateHelpForCommands(CommandAPI.getRegisteredCommands()); - } - - @SuppressWarnings("unchecked") - private LiteralCommandNode asPluginCommand(LiteralCommandNode commandNode) { - try { - if (metaField == null) { - return (LiteralCommandNode) pluginCommandNodeConstructor.newInstance( - commandNode.getLiteral(), - CommandAPIBukkit.getConfiguration().getPlugin().getPluginMeta(), - commandNode, - getDescription(commandNode.getLiteral()) - ); - } else { - setPluginCommandMeta(commandNode); - return commandNode; - } - } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - private void setPluginCommandMeta(LiteralCommandNode node) { - try { - metaField.set(node, pluginCommandNodeConstructor.newInstance( - CommandAPIBukkit.getConfiguration().getPlugin().getPluginMeta(), - getDescription(node.getLiteral()), - getAliasesForCommand(node.getLiteral()) - )); - } catch (ReflectiveOperationException | IllegalArgumentException e) { - try { - metaField.set(node, pluginCommandNodeConstructor.newInstance( - CommandAPIBukkit.getConfiguration().getPlugin().getPluginMeta(), - getDescription(node.getLiteral()), - getAliasesForCommand(node.getLiteral()), - CommandAPIBukkit.getConfiguration().getNamespace(), // Don't think this matters actually - false // Indicates a server side only command - )); - } catch (ReflectiveOperationException | IllegalArgumentException e1) { - try { - metaField.set(node, pluginCommandNodeConstructor.newInstance( - CommandAPIBukkit.getConfiguration().getPlugin().getPluginMeta(), - getDescription(node.getLiteral()), - getAliasesForCommand(node.getLiteral()), - CommandAPIBukkit.getConfiguration().getNamespace() // Probably still doesn't matter - )); - } catch (ReflectiveOperationException e2) { - // This doesn't happen - } - } - } - } - - private String getDescription(String commandName) { - String namespaceStripped; - if (commandName.contains(":")) { - namespaceStripped = commandName.split(":")[1]; - } else { - namespaceStripped = commandName; - } - for (RegisteredCommand command : CommandAPI.getRegisteredCommands()) { - if (command.commandName().equals(namespaceStripped) || Arrays.asList(command.aliases()).contains(namespaceStripped)) { - Object helpTopic = command.helpTopic().orElse(null); - if (helpTopic != null) { - return ((HelpTopic) helpTopic).getShortText(); - } else { - return command.shortDescription().orElse("A command by the " + CommandAPIBukkit.getConfiguration().getPlugin().getName() + " plugin."); - } - } - } - return ""; - } - - private List getAliasesForCommand(String commandName) { - Set aliases = new HashSet<>(); - String namespaceStripped; - if (commandName.contains(":")) { - namespaceStripped = commandName.split(":")[1]; - } else { - namespaceStripped = commandName; - } - for (RegisteredCommand command : CommandAPI.getRegisteredCommands()) { - if (command.commandName().equals(namespaceStripped)) { - aliases.addAll(Arrays.asList(command.aliases())); - } - } - return new ArrayList<>(aliases); - } - -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperImplementations.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperImplementations.java deleted file mode 100644 index 2605321b9..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/PaperImplementations.java +++ /dev/null @@ -1,177 +0,0 @@ -package dev.jorel.commandapi; - -import com.mojang.brigadier.Message; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; -import dev.jorel.commandapi.nms.NMS; -import io.papermc.paper.event.server.ServerResourcesReloadedEvent; -import net.kyori.adventure.text.ComponentLike; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandMap; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.plugin.Plugin; - -public class PaperImplementations { - - private final boolean isPaperPresent; - private final boolean isFoliaPresent; - private final boolean isPaperBrigAPI; - private final NMS nmsInstance; - private final Class feedbackForwardingCommandSender; - private final Class nullCommandSender; - - /** - * Constructs a PaperImplementations object - * - * @param isPaperPresent Whether this is a Paper server or not - * @param isFoliaPresent Whether this is a Folia server or not - * @param nmsInstance The instance of NMS - */ - @SuppressWarnings("unchecked") - public PaperImplementations(boolean isPaperPresent, boolean isFoliaPresent, NMS nmsInstance) { - this.isPaperPresent = isPaperPresent; - this.isFoliaPresent = isFoliaPresent; - this.nmsInstance = nmsInstance; - - Class tempFeedbackForwardingCommandSender = null; - try { - tempFeedbackForwardingCommandSender = (Class) Class.forName("io.papermc.paper.commands.FeedbackForwardingSender"); - } catch (ClassNotFoundException e) { - // uhh... - } - - this.feedbackForwardingCommandSender = tempFeedbackForwardingCommandSender; - - Class tempNullCommandSender = null; - try { - tempNullCommandSender = (Class) Class.forName("io.papermc.paper.brigadier.NullCommandSender"); - } catch (ClassNotFoundException e) { - // uhh... - } - - this.nullCommandSender = tempNullCommandSender; - - boolean paperCommandSourceStackPresent; - try { - Class.forName("io.papermc.paper.command.brigadier.CommandSourceStack"); - paperCommandSourceStackPresent = true; - } catch (ClassNotFoundException e) { - paperCommandSourceStackPresent = false; - } - this.isPaperBrigAPI = paperCommandSourceStackPresent; - } - - /** - * Hooks into Paper's {@link ServerResourcesReloadedEvent} to detect if - * {@code /minecraft:reload} is called, and registers a reload handler that - * automatically calls the CommandAPI's internal datapack reloading function - * - * @param plugin the plugin that the CommandAPI is being used from - */ - public void registerReloadHandler(Plugin plugin) { - if (isPaperPresent) { - Bukkit.getServer().getPluginManager().registerEvents(new Listener() { - @EventHandler - public void onServerReloadResources(ServerResourcesReloadedEvent event) { - // This event is called after Paper is done with everything command related - // which means we can put commands back - CommandAPIBukkit.get().getCommandRegistrationStrategy().preReloadDataPacks(); - - // Normally, the reloadDataPacks() method is responsible for updating commands for - // online players. If, however, datapacks aren't supposed to be reloaded upon /minecraft:reload - // we have to do this manually here. This won't have any effect on Spigot and Paper version prior to - // paper-1.20.6-65 - if (!CommandAPIBukkit.getConfiguration().shouldHookPaperReload()) { - for (Player player : Bukkit.getOnlinePlayers()) { - player.updateCommands(); - } - return; - } - CommandAPI.logNormal("/minecraft:reload detected. Reloading CommandAPI commands!"); - nmsInstance.reloadDataPacks(); - } - - }, plugin); - CommandAPI.logNormal("Hooked into Paper ServerResourcesReloadedEvent"); - } else { - CommandAPI.logNormal("Did not hook into Paper ServerResourcesReloadedEvent"); - } - } - - /** - * @return Bukkit's {@link CommandMap} - */ - public CommandMap getCommandMap() { - if (isPaperPresent) { - return Bukkit.getServer().getCommandMap(); - } else { - return nmsInstance.getSimpleCommandMap(); - } - } - - /** - * @return whether we're using paper or not - */ - public boolean isPaperPresent() { - return this.isPaperPresent; - } - - /** - * @return whether we're running a Paper server with the Paper Brigadier command API - */ - public boolean isPaperBrigAPI() { - return this.isPaperBrigAPI; - } - - /** - * @return whether we're using folia or not - */ - public boolean isFoliaPresent() { - return this.isFoliaPresent; - } - - /** - * @return a class reference pointing to {@code io.papermc.paper.commands.FeedbackForwardingSender} - */ - public Class getFeedbackForwardingCommandSender() { - return this.feedbackForwardingCommandSender; - } - - /** - * @return a class reference pointing to {@code io.papermc.paper.brigadier.NullCommandSender} - */ - public Class getNullCommandSender() { - return this.nullCommandSender; - } - - /** - * Builds a {@link WrapperCommandSyntaxException} from a message with colour codes like {@link ChatColor} or using the § symbol. - * - * @param message the error message to be displayed - * @return A {@link WrapperCommandSyntaxException} with the given message as error message - */ - public WrapperCommandSyntaxException getExceptionFromString(String message) { - Message brigadierMessage; - if (isPaperPresent) { - // Java is doing something weird here. - // It's like when the class loads, it makes sure all the function calls use the right classes, - // but it doesn't check casts until the code runs. When it checks if classes are compatible, - // it doesn't need to load the class if they are exactly the same, but to check inheritance - // it does actually need to load the classes. But I don't know ¯\_(ツ)_/¯. - // Whatever Java thinks it is doing, this code loads on Spigot, while - // more obvious things cause `ClassNotFound: ComponentLike`. - brigadierMessage = BukkitTooltip.messageFromAdventureComponent( - (ComponentLike) (Object) LegacyComponentSerializer.legacySection().deserialize(message) - ); - } else { - brigadierMessage = BukkitTooltip.messageFromBaseComponents(TextComponent.fromLegacyText(message)); - } - return new WrapperCommandSyntaxException(new SimpleCommandExceptionType(brigadierMessage).create()); - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Platform.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Platform.java new file mode 100644 index 000000000..e4cad3d7a --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Platform.java @@ -0,0 +1,16 @@ +package dev.jorel.commandapi; + +/** + * The Bukkit platform that is used at runtime + */ +public enum Platform { + /** + * Represents the Spigot platform, uses module commandapi-spigot + */ + SPIGOT, + + /** + * Represents the Paper platform, uses module commandapi-paper + */ + PAPER +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdvancementArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdvancementArgument.java index 11d724fd1..ae08f1f21 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdvancementArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdvancementArgument.java @@ -40,7 +40,7 @@ public class AdvancementArgument extends SafeOverrideableArgument Advancement parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAdvancement(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getAdvancement(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AngleArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AngleArgument.java index 52b5e6066..e3826aff4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AngleArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AngleArgument.java @@ -44,7 +44,7 @@ public class AngleArgument extends SafeOverrideableArgument { * @param nodeName the name of the node for argument */ public AngleArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentAngle(), String::valueOf); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentAngle(), String::valueOf); } @Override @@ -60,6 +60,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Float parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAngle(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getAngle(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AsyncOfflinePlayerArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AsyncOfflinePlayerArgument.java deleted file mode 100644 index daeac7ba4..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AsyncOfflinePlayerArgument.java +++ /dev/null @@ -1,49 +0,0 @@ -package dev.jorel.commandapi.arguments; - -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import dev.jorel.commandapi.CommandAPIBukkit; -import dev.jorel.commandapi.executors.CommandArguments; -import org.bukkit.OfflinePlayer; - -import java.util.concurrent.CompletableFuture; - -/** - * An argument that represents the Bukkit OfflinePlayer object with asynchronous support. - * - * @since 9.7.1 - */ -public class AsyncOfflinePlayerArgument extends SafeOverrideableArgument, OfflinePlayer> { - - /** - * A Player argument. Produces a single player, regardless of whether - * @a, @p, @r or @e is used. - * - * @param nodeName the name of the node for this argument - */ - public AsyncOfflinePlayerArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentProfile(), OfflinePlayer::getName); - } - - @SuppressWarnings("unchecked") - @Override - public Class> getPrimitiveType() { - return (Class>) (Class) CompletableFuture.class; - } - - @Override - public CommandAPIArgumentType getArgumentType() { - return CommandAPIArgumentType.ASYNC_OFFLINE_PLAYER; - } - - @Override - public CompletableFuture parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) { - return CompletableFuture.supplyAsync(() -> { - try { - return CommandAPIBukkit.get().getOfflinePlayer(cmdCtx, key); - } catch (CommandSyntaxException e) { - throw new RuntimeException(e); - } - }); - } -} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AxisArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AxisArgument.java index 2cdc750b7..1fa529771 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AxisArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AxisArgument.java @@ -45,7 +45,7 @@ public class AxisArgument extends SafeOverrideableArgument e.stream().map(Axis::name).map(String::toLowerCase).reduce(String::concat).get()); } @@ -63,6 +63,6 @@ public CommandAPIArgumentType getArgumentType() { public EnumSet parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAxis(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getAxis(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BiomeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BiomeArgument.java index 942153960..884771170 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BiomeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BiomeArgument.java @@ -43,8 +43,8 @@ public class BiomeArgument extends SafeOverrideableArgument implem * @param nodeName the name of the node for argument */ public BiomeArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentSyntheticBiome(), - ((Function) Biome::name).andThen(String::toLowerCase)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentSyntheticBiome(), + ((Function) biome -> biome.name() /* Hopefully this makes it compatible with older and newer versions */).andThen(String::toLowerCase)); } @Override @@ -65,7 +65,7 @@ public SuggestionProviders getSuggestionProvider() { @Override public Biome parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Biome) CommandAPIBukkit.get().getBiome(cmdCtx, key, ArgumentSubType.BIOME_BIOME); + return CommandAPIBukkit.get().getNMS().getBiome(cmdCtx, key).type().get(); } /** @@ -82,7 +82,7 @@ public static class NamespacedKey extends SafeOverrideableArgument org.bukkit.NamespacedKey parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (org.bukkit.NamespacedKey) CommandAPIBukkit.get().getBiome(cmdCtx, key, ArgumentSubType.BIOME_NAMESPACEDKEY); + return CommandAPIBukkit.get().getNMS().getBiome(cmdCtx, key).key().get(); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockPredicateArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockPredicateArgument.java index 7ede3fc9e..97179aade 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockPredicateArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockPredicateArgument.java @@ -45,7 +45,7 @@ public class BlockPredicateArgument extends Argument { * @param nodeName the name of the node for argument */ public BlockPredicateArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentBlockPredicate()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentBlockPredicate()); } @Override @@ -61,6 +61,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Predicate parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getBlockPredicate(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getBlockPredicate(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockStateArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockStateArgument.java index 20f514abb..41485995b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockStateArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/BlockStateArgument.java @@ -24,17 +24,18 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.executors.CommandArguments; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; /** - * An argument that represents the Bukkit BlockData object + * An argument that represents the Bukkit BlockState object * * @since 3.1 * - * @apiNote Returns a {@link BlockData} object + * @apiNote Returns a {@link org.bukkit.block.BlockState} object * */ -public class BlockStateArgument extends Argument { +public class BlockStateArgument extends Argument { /** * Constructs a BlockStateArgument with a given node name. @@ -42,12 +43,12 @@ public class BlockStateArgument extends Argument { * @param nodeName the name of the node for argument */ public BlockStateArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentBlockState()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentBlockState()); } @Override - public Class getPrimitiveType() { - return BlockData.class; + public Class getPrimitiveType() { + return BlockState.class; } @Override @@ -56,8 +57,8 @@ public CommandAPIArgumentType getArgumentType() { } @Override - public BlockData parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) + public BlockState parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getBlockState(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getBlockState(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java index aa9dd98b1..fda7d333c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java @@ -45,7 +45,7 @@ private void applySuggestions() { super.replaceSuggestions((info, builder) -> { // Extract information CommandSender sender = info.sender(); - CommandMap commandMap = CommandAPIBukkit.get().getSimpleCommandMap(); + CommandMap commandMap = CommandAPIBukkit.get().getNMS().getSimpleCommandMap(); String command = info.currentArg(); // Setup context for errors @@ -193,7 +193,7 @@ public CommandAPIArgumentType getArgumentType() { public CommandResult parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { // Extract information String command = cmdCtx.getArgument(key, String.class); - CommandMap commandMap = CommandAPIBukkit.get().getSimpleCommandMap(); + CommandMap commandMap = CommandAPIBukkit.get().getNMS().getSimpleCommandMap(); CommandSender sender = CommandAPIBukkit.get().getSenderForCommand(cmdCtx, false).getSource(); StringReader context = new StringReader(command); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FloatRangeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/DoubleRangeArgument.java similarity index 72% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FloatRangeArgument.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/DoubleRangeArgument.java index fd3bb278f..23849f5ba 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FloatRangeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/DoubleRangeArgument.java @@ -24,26 +24,26 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.executors.CommandArguments; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; /** * An argument that represents a range of float values * * @since 3.0 */ -public class FloatRangeArgument extends SafeOverrideableArgument { +public class DoubleRangeArgument extends SafeOverrideableArgument { /** - * A FloatRange argument that represents a range of floating-point values + * A DoubleRange argument that represents a range of floating-point values * @param nodeName the name of the node for this argument */ - public FloatRangeArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentFloatRange(), FloatRange::toString); + public DoubleRangeArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentFloatRange(), DoubleRange::toString); } @Override - public Class getPrimitiveType() { - return FloatRange.class; + public Class getPrimitiveType() { + return DoubleRange.class; } @Override @@ -52,7 +52,7 @@ public CommandAPIArgumentType getArgumentType() { } @Override - public FloatRange parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getFloatRange(cmdCtx, key); + public DoubleRange parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { + return CommandAPIBukkit.get().getNMS().getDoubleRange(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EnchantmentArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EnchantmentArgument.java index 83ef7848f..a32220d9f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EnchantmentArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EnchantmentArgument.java @@ -40,7 +40,7 @@ public class EnchantmentArgument extends SafeOverrideableArgument Enchantment parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getEnchantment(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getEnchantment(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntitySelectorArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntitySelectorArgument.java index 3e01bc006..85db62782 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntitySelectorArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntitySelectorArgument.java @@ -54,7 +54,7 @@ public static class OneEntity extends Argument { * @param nodeName the name of the node for this argument */ public OneEntity(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_ONE_ENTITY)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_ONE_ENTITY)); } @Override @@ -69,7 +69,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Entity parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Entity) CommandAPIBukkit.get().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_ONE_ENTITY, true); + return CommandAPIBukkit.get().getNMS().getEntitySelector(cmdCtx, key).entity().get(); } @Override @@ -91,7 +91,7 @@ public static class OnePlayer extends Argument { * @param nodeName the name of the node for this argument */ public OnePlayer(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_ONE_PLAYER)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_ONE_PLAYER)); } @Override @@ -106,7 +106,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Player parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Player) CommandAPIBukkit.get().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_ONE_PLAYER, true); + return CommandAPIBukkit.get().getNMS().getEntitySelector(cmdCtx, key).player().get(); } @Override @@ -140,7 +140,7 @@ public ManyEntities(String nodeName) { * @param allowEmpty whether this entity selector should allow no entities found, or should throw an error instead */ public ManyEntities(String nodeName, boolean allowEmpty) { - super(nodeName, CommandAPIBukkit.get()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_MANY_ENTITIES)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_MANY_ENTITIES)); this.allowEmpty = allowEmpty; } @@ -154,10 +154,9 @@ public CommandAPIArgumentType getArgumentType() { return CommandAPIArgumentType.ENTITY_SELECTOR; } - @SuppressWarnings("unchecked") @Override public Collection parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Collection) CommandAPIBukkit.get().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_MANY_ENTITIES, this.allowEmpty); + return CommandAPIBukkit.get().getNMS().getEntitySelector(cmdCtx, key).entities().apply(this.allowEmpty); } @SuppressWarnings("unchecked") @@ -196,7 +195,7 @@ public ManyPlayers(String nodeName) { * * @param allowEmpty whether this entity selector should allow no entities found, or should throw an error instead */ public ManyPlayers(String nodeName, boolean allowEmpty) { - super(nodeName, CommandAPIBukkit.get()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_MANY_PLAYERS)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentEntity(ArgumentSubType.ENTITYSELECTOR_MANY_PLAYERS)); this.allowEmpty = allowEmpty; } @@ -210,10 +209,9 @@ public CommandAPIArgumentType getArgumentType() { return CommandAPIArgumentType.ENTITY_SELECTOR; } - @SuppressWarnings("unchecked") @Override public Collection parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Collection) CommandAPIBukkit.get().getEntitySelector(cmdCtx, key, ArgumentSubType.ENTITYSELECTOR_MANY_PLAYERS, allowEmpty); + return CommandAPIBukkit.get().getNMS().getEntitySelector(cmdCtx, key).players().apply(this.allowEmpty); } @SuppressWarnings("unchecked") diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntityTypeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntityTypeArgument.java index 8ebd9b04b..e91280361 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntityTypeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/EntityTypeArgument.java @@ -38,7 +38,7 @@ public class EntityTypeArgument extends SafeOverrideableArgument EntityType parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getEntityType(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getEntityType(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FunctionArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FunctionArgument.java index 9bf736c11..b2dd155b7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FunctionArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/FunctionArgument.java @@ -41,7 +41,7 @@ public class FunctionArgument extends SafeOverrideableArgument n)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentTag(), fromKey(n -> n)); } @Override @@ -61,6 +61,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public FunctionWrapper[] parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getFunction(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getFunction(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/IntegerRangeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/IntegerRangeArgument.java index 85bfc8f28..289c5ebe6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/IntegerRangeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/IntegerRangeArgument.java @@ -38,7 +38,7 @@ public class IntegerRangeArgument extends SafeOverrideableArgument IntegerRange parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getIntRange(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getIntRange(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackArgument.java index edfa6369c..b68aca41b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackArgument.java @@ -38,7 +38,7 @@ public class ItemStackArgument extends SafeOverrideableArgument ItemStack parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getItemStack(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getItemStack(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackPredicateArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackPredicateArgument.java index 1b6183d9c..8b952a28c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackPredicateArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ItemStackPredicateArgument.java @@ -41,7 +41,7 @@ public class ItemStackPredicateArgument extends Argument { * @param nodeName the name of the node for this argument */ public ItemStackPredicateArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentItemPredicate()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentItemPredicate()); } @Override @@ -56,6 +56,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Predicate parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getItemStackPredicate(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getItemStackPredicate(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/Location2DArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/Location2DArgument.java index 3e6f2de75..4bb3367a1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/Location2DArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/Location2DArgument.java @@ -59,10 +59,14 @@ public Location2DArgument(String nodeName, LocationType type) { * @param centerPosition whether LocationType.PRECISE_POSITION should center the position of the location within a block */ public Location2DArgument(String nodeName, LocationType type, boolean centerPosition) { - super(nodeName, type == LocationType.BLOCK_POSITION ? CommandAPIBukkit.get()._ArgumentPosition2D() - : CommandAPIBukkit.get()._ArgumentVec2(centerPosition), - type == LocationType.BLOCK_POSITION ? (Location2D l) -> l.getBlockX() + " " + l.getBlockZ() - : (Location2D l) -> l.getX() + " " + l.getZ()); + super(nodeName, + type == LocationType.BLOCK_POSITION + ? CommandAPIBukkit.get().getNMS()._ArgumentPosition2D() + : CommandAPIBukkit.get().getNMS()._ArgumentVec2(centerPosition), + type == LocationType.BLOCK_POSITION + ? (Location2D l) -> l.getBlockX() + " " + l.getBlockZ() + : (Location2D l) -> l.getX() + " " + l.getZ() + ); isPrecise = type == LocationType.PRECISE_POSITION; } @@ -89,7 +93,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Location2D parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { return isPrecise ? - CommandAPIBukkit.get().getLocation2DPrecise(cmdCtx, key) : - CommandAPIBukkit.get().getLocation2DBlock(cmdCtx, key); + CommandAPIBukkit.get().getNMS().getLocation2DPrecise(cmdCtx, key) : + CommandAPIBukkit.get().getNMS().getLocation2DBlock(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LocationArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LocationArgument.java index fe477594f..80a2afffd 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LocationArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LocationArgument.java @@ -28,68 +28,75 @@ /** * An argument that represents the Bukkit {@link Location} object - * - * @since 1.1 + * * @apiNote Returns a {@link Location} object + * @since 1.1 */ public class LocationArgument extends SafeOverrideableArgument { - + /** * A Location argument. Represents Minecraft locations. Defaults to {@link LocationType#PRECISE_POSITION} + * * @param nodeName the name of the node for this argument */ public LocationArgument(String nodeName) { this(nodeName, LocationType.PRECISE_POSITION); } - + /** * A Location argument. Represents Minecraft locations + * * @param nodeName the name of the node for this argument - * @param type the location type of this location, either {@link LocationType#BLOCK_POSITION} or {@link LocationType#PRECISE_POSITION} + * @param type the location type of this location, either {@link LocationType#BLOCK_POSITION} or {@link LocationType#PRECISE_POSITION} */ public LocationArgument(String nodeName, LocationType type) { this(nodeName, type, true); } - + /** * A Location argument. Represents Minecraft locations - * @param nodeName the name of the node for this argument - * @param type the location type of this location, either {@link LocationType#BLOCK_POSITION} or {@link LocationType#PRECISE_POSITION} + * + * @param nodeName the name of the node for this argument + * @param type the location type of this location, either {@link LocationType#BLOCK_POSITION} or {@link LocationType#PRECISE_POSITION} * @param centerPosition whether LocationType.PRECISE_POSITION should center the position of the location within a block */ public LocationArgument(String nodeName, LocationType type, boolean centerPosition) { - super(nodeName, type == LocationType.BLOCK_POSITION ? CommandAPIBukkit.get()._ArgumentPosition() - : CommandAPIBukkit.get()._ArgumentVec3(centerPosition), - type == LocationType.BLOCK_POSITION - ? (Location l) -> l.getBlockX() + " " + l.getBlockY() + " " + l.getBlockZ() - : (Location l) -> l.getX() + " " + l.getY() + " " + l.getZ()); + super(nodeName, + type == LocationType.BLOCK_POSITION + ? CommandAPIBukkit.get().getNMS()._ArgumentPosition() + : CommandAPIBukkit.get().getNMS()._ArgumentVec3(centerPosition), + type == LocationType.BLOCK_POSITION + ? (Location l) -> l.getBlockX() + " " + l.getBlockY() + " " + l.getBlockZ() + : (Location l) -> l.getX() + " " + l.getY() + " " + l.getZ() + ); isPrecise = type == LocationType.PRECISE_POSITION; } - + private final boolean isPrecise; /** * Returns whether this argument is {@link LocationType#BLOCK_POSITION} or {@link LocationType#PRECISE_POSITION} + * * @return the location type of this argument */ public LocationType getLocationType() { return isPrecise ? LocationType.PRECISE_POSITION : LocationType.BLOCK_POSITION; } - + @Override public Class getPrimitiveType() { return Location.class; } - + @Override public CommandAPIArgumentType getArgumentType() { return CommandAPIArgumentType.LOCATION; } - + @Override public Location parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return isPrecise ? - CommandAPIBukkit.get().getLocationPrecise(cmdCtx, key) : - CommandAPIBukkit.get().getLocationBlock(cmdCtx, key); + return isPrecise + ? CommandAPIBukkit.get().getNMS().getLocationPrecise(cmdCtx, key) + : CommandAPIBukkit.get().getNMS().getLocationBlock(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LootTableArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LootTableArgument.java index ae14acb56..8d3232766 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LootTableArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/LootTableArgument.java @@ -39,7 +39,7 @@ public class LootTableArgument extends SafeOverrideableArgument LootTable parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getLootTable(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getLootTable(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/MathOperationArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/MathOperationArgument.java index 1df682386..d5dfb712a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/MathOperationArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/MathOperationArgument.java @@ -38,7 +38,7 @@ public class MathOperationArgument extends SafeOverrideableArgument MathOperation parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getMathOperation(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getMathOperation(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java index efefb6b32..df6ca6024 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java @@ -40,7 +40,7 @@ public class NBTCompoundArgument extends SafeOverrideableArgument< * @param nodeName the name of the node for this argument */ public NBTCompoundArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentNBTCompound(), NBTContainer::toString); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentNBTCompound(), NBTContainer::toString); if (CommandAPI.getConfiguration().getNBTContainerClass() == null || CommandAPI.getConfiguration().getNBTContainerConstructor() == null) { throw new NullPointerException( "The NBTCompoundArgument hasn't been initialized properly! Use CommandAPIConfig.initializeNBTAPI() in your onLoad() method"); @@ -62,6 +62,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public NBTContainer parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (NBTContainer) CommandAPIBukkit.get().getNBTCompound(cmdCtx, key, CommandAPI.getConfiguration().getNBTContainerConstructor()); + return (NBTContainer) CommandAPIBukkit.get().getNMS().getNBTCompound(cmdCtx, key, CommandAPI.getConfiguration().getNBTContainerConstructor()); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NamespacedKeyArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NamespacedKeyArgument.java index 0f09352c6..3e7fc8163 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NamespacedKeyArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NamespacedKeyArgument.java @@ -43,7 +43,7 @@ public class NamespacedKeyArgument extends SafeOverrideableArgument NamespacedKey parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getMinecraftKey(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getMinecraftKey(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveArgument.java index 6192e830b..ee270e10d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveArgument.java @@ -38,7 +38,7 @@ public class ObjectiveArgument extends SafeOverrideableArgument Objective parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getObjective(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getObjective(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveCriteriaArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveCriteriaArgument.java index 9c5e8ad0c..06e3cf8bb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveCriteriaArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ObjectiveCriteriaArgument.java @@ -37,7 +37,7 @@ public class ObjectiveCriteriaArgument extends Argument { * @param nodeName the name of the node for this argument */ public ObjectiveCriteriaArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentScoreboardCriteria()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentScoreboardCriteria()); } @Override @@ -52,6 +52,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public String parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getObjectiveCriteria(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getObjectiveCriteria(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ParticleArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ParticleArgument.java index aa6f1a74a..36186b73b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ParticleArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ParticleArgument.java @@ -39,7 +39,7 @@ public class ParticleArgument extends SafeOverrideableArgument ParticleData parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getParticle(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getParticle(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PotionEffectArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PotionEffectArgument.java index 45985192e..d4399901d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PotionEffectArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PotionEffectArgument.java @@ -39,7 +39,7 @@ public class PotionEffectArgument extends SafeOverrideableArgument PotionEffectType parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (PotionEffectType) CommandAPIBukkit.get().getPotionEffect(cmdCtx, key, ArgumentSubType.POTION_EFFECT_POTION_EFFECT); + return CommandAPIBukkit.get().getNMS().getPotionEffect(cmdCtx, key).type().get(); } /** @@ -70,7 +70,7 @@ public static class NamespacedKey extends SafeOverrideableArgument org.bukkit.NamespacedKey parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (org.bukkit.NamespacedKey) CommandAPIBukkit.get().getPotionEffect(cmdCtx, key, ArgumentSubType.POTION_EFFECT_NAMESPACEDKEY); + return CommandAPIBukkit.get().getNMS().getPotionEffect(cmdCtx, key).key().get(); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java index 405f97986..c70669477 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java @@ -39,7 +39,7 @@ public class RecipeArgument extends SafeOverrideableArgument imp * @param nodeName the name of the node for this argument */ public RecipeArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentRecipe(), fromKey((Recipe r) -> ((Keyed) r).getKey())); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentRecipe(), fromKey((Recipe r) -> ((Keyed) r).getKey())); } @Override @@ -59,7 +59,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Recipe parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getRecipe(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getRecipe(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RotationArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RotationArgument.java index 52cc6a477..890a49b1d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RotationArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RotationArgument.java @@ -38,7 +38,7 @@ public class RotationArgument extends SafeOverrideableArgument Rotation parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getRotation(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getRotation(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreHolderArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreHolderArgument.java index 763726cef..472d6e904 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreHolderArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreHolderArgument.java @@ -50,7 +50,7 @@ public static class Single extends Argument { * @param nodeName the name of the node for this argument */ public Single(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentScoreholder(ArgumentSubType.SCOREHOLDER_SINGLE)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentScoreholder(ArgumentSubType.SCOREHOLDER_SINGLE)); } @Override @@ -65,7 +65,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public String parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getScoreHolderSingle(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getScoreHolderSingle(cmdCtx, key); } } @@ -83,7 +83,7 @@ public static class Multiple extends Argument { * @param nodeName the name of the node for this argument */ public Multiple(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentScoreholder(ArgumentSubType.SCOREHOLDER_MULTIPLE)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentScoreholder(ArgumentSubType.SCOREHOLDER_MULTIPLE)); } @Override @@ -98,7 +98,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Collection parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getScoreHolderMultiple(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getScoreHolderMultiple(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreboardSlotArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreboardSlotArgument.java index e4838d9f8..921499bac 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreboardSlotArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ScoreboardSlotArgument.java @@ -38,7 +38,7 @@ public class ScoreboardSlotArgument extends SafeOverrideableArgument ScoreboardSlot parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getScoreboardSlot(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getScoreboardSlot(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/SoundArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/SoundArgument.java index 47f84e2f9..0370a8efc 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/SoundArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/SoundArgument.java @@ -40,7 +40,7 @@ public class SoundArgument extends SafeOverrideableArgument implem * @param nodeName the name of the node for this argument */ public SoundArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentMinecraftKeyRegistered(), CommandAPIBukkit.get()::convert); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentMinecraftKeyRegistered(), CommandAPIBukkit.get().getNMS()::convert); } @Override @@ -60,7 +60,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Sound parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (Sound) CommandAPIBukkit.get().getSound(cmdCtx, key, ArgumentSubType.SOUND_SOUND); + return CommandAPIBukkit.get().getNMS().getSound(cmdCtx, key).type().get(); } /** @@ -77,7 +77,7 @@ public static class NamespacedKey extends SafeOverrideableArgument org.bukkit.NamespacedKey parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (org.bukkit.NamespacedKey) CommandAPIBukkit.get().getSound(cmdCtx, key, ArgumentSubType.SOUND_NAMESPACEDKEY); + return CommandAPIBukkit.get().getNMS().getSound(cmdCtx, key).key().get(); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TeamArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TeamArgument.java index 99fc31fbd..fa2e28c60 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TeamArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TeamArgument.java @@ -38,7 +38,7 @@ public class TeamArgument extends SafeOverrideableArgument { * @param nodeName the name of the node for this argument */ public TeamArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentScoreboardTeam(), Team::getName); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentScoreboardTeam(), Team::getName); } @Override @@ -53,6 +53,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Team parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getTeam(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getTeam(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TimeArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TimeArgument.java index a246d8b39..2f969df5e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TimeArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/TimeArgument.java @@ -38,7 +38,7 @@ public class TimeArgument extends SafeOverrideableArgument { * @param nodeName the name of the node for this argument */ public TimeArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentTime(), Time::toString); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentTime(), Time::toString); } @Override @@ -53,6 +53,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Integer parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getTime(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getTime(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/UUIDArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/UUIDArgument.java index 9b74d706d..f6f396a28 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/UUIDArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/UUIDArgument.java @@ -39,7 +39,7 @@ public class UUIDArgument extends SafeOverrideableArgument { * @param nodeName the name of the node for this argument */ public UUIDArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentUUID(), UUID::toString); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentUUID(), UUID::toString); } @Override @@ -54,6 +54,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public UUID parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getUUID(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getUUID(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/WorldArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/WorldArgument.java index 62263ea0a..6460ba2c4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/WorldArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/WorldArgument.java @@ -43,7 +43,7 @@ public class WorldArgument extends SafeOverrideableArgument { public WorldArgument(String nodeName) { // Dev note: DO NOT use a method reference for the World class! See // https://github.com/JorelAli/CommandAPI/issues/397 for more info - super(nodeName, CommandAPIBukkit.get()._ArgumentDimension(), world -> world.getName().toLowerCase()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentDimension(), world -> world.getName().toLowerCase()); } @Override @@ -62,6 +62,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public World parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getDimension(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getDimension(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/EntitySelectorParser.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/EntitySelectorParser.java new file mode 100644 index 000000000..d327189e0 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/EntitySelectorParser.java @@ -0,0 +1,16 @@ +package dev.jorel.commandapi.arguments.parser; + +import dev.jorel.commandapi.arguments.parser.function.ThrowingFunctionParser; +import dev.jorel.commandapi.arguments.parser.function.ThrowingSupplyingParser; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.util.Collection; + +public record EntitySelectorParser( + ThrowingSupplyingParser player, + ThrowingSupplyingParser entity, + ThrowingFunctionParser> players, + ThrowingFunctionParser> entities +) { +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/RegistryParser.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/RegistryParser.java new file mode 100644 index 000000000..56981dd2f --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/RegistryParser.java @@ -0,0 +1,11 @@ +package dev.jorel.commandapi.arguments.parser; + +import dev.jorel.commandapi.arguments.parser.function.ThrowingSupplyingParser; +import org.bukkit.NamespacedKey; +import org.bukkit.potion.PotionEffectType; + +public record RegistryParser( + ThrowingSupplyingParser type, + ThrowingSupplyingParser key +) { +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingBiFunction.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingBiFunction.java new file mode 100644 index 000000000..1c23724da --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingBiFunction.java @@ -0,0 +1,7 @@ +package dev.jorel.commandapi.arguments.parser.function; + +public interface ThrowingBiFunction { + + R apply(T t, U u) throws E; + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingFunctionParser.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingFunctionParser.java new file mode 100644 index 000000000..64932807d --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingFunctionParser.java @@ -0,0 +1,9 @@ +package dev.jorel.commandapi.arguments.parser.function; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +public interface ThrowingFunctionParser { + + R apply(T t) throws CommandSyntaxException; + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingSupplier.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingSupplier.java new file mode 100644 index 000000000..74d112997 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingSupplier.java @@ -0,0 +1,8 @@ +package dev.jorel.commandapi.arguments.parser.function; + +@FunctionalInterface +public interface ThrowingSupplier { + + T get() throws Exception; + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingSupplyingParser.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingSupplyingParser.java new file mode 100644 index 000000000..a538b515a --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/parser/function/ThrowingSupplyingParser.java @@ -0,0 +1,9 @@ +package dev.jorel.commandapi.arguments.parser.function; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +public interface ThrowingSupplyingParser { + + T get() throws CommandSyntaxException; + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/exceptions/PlatformException.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/exceptions/PlatformException.java new file mode 100644 index 000000000..8c1bf8b5f --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/exceptions/PlatformException.java @@ -0,0 +1,8 @@ +package dev.jorel.commandapi.exceptions; + +public class PlatformException extends RuntimeException { + + public PlatformException(String message) { + super(message); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java index c850689be..9e694bca6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java @@ -20,6 +20,8 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; +import java.io.File; +import java.io.IOException; import java.util.Collection; import java.util.EnumSet; import java.util.Map; @@ -28,22 +30,26 @@ import java.util.function.Function; import java.util.function.Predicate; -import dev.jorel.commandapi.CommandRegistrationStrategy; +import com.mojang.brigadier.CommandDispatcher; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; +import dev.jorel.commandapi.commandsenders.AbstractCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.preprocessor.Unimplemented; import org.bukkit.Axis; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; +import org.bukkit.block.BlockState; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; import org.bukkit.help.HelpTopic; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; @@ -60,7 +66,7 @@ import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; @@ -70,9 +76,11 @@ import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.md_5.bungee.api.chat.BaseComponent; + +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CRAFTBUKKIT; +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_CSS; +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.REQUIRES_MINECRAFT_SERVER; +import static dev.jorel.commandapi.preprocessor.Unimplemented.REASON.VERSION_SPECIFIC_IMPLEMENTATION; public interface NMS { @@ -292,39 +300,26 @@ public interface NMS { Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key); - - Component getAdventureChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException; - float getAngle(CommandContext cmdCtx, String key); EnumSet getAxis(CommandContext cmdCtx, String key); - Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException; + RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException; Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException; - BlockData getBlockState(CommandContext cmdCtx, String key); - - BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - ChatColor getChatColor(CommandContext cmdCtx, String key); - - BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException; + BlockState getBlockState(CommandContext cmdCtx, String key); World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException; Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException; // Throws exception in 1.19.3 - Object getEntitySelector(CommandContext cmdCtx, String key, ArgumentSubType subType, boolean allowEmpty) - throws CommandSyntaxException; + EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String key); EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException; - FloatRange getFloatRange(CommandContext cmdCtx, String key); + DoubleRange getDoubleRange(CommandContext cmdCtx, String key); FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) throws CommandSyntaxException; @@ -348,8 +343,7 @@ Location2D getLocation2DPrecise(CommandContext cmdCtx, S Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException; - Location getLocationPrecise(CommandContext cmdCtx, String str) - throws CommandSyntaxException; + Location getLocationPrecise(CommandContext cmdCtx, String str) throws CommandSyntaxException; LootTable getLootTable(CommandContext cmdCtx, String key); @@ -368,17 +362,14 @@ Objective getObjective(CommandContext cmdCtx, String key ParticleData getParticle(CommandContext cmdCtx, String key); - Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException; - OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException; + RegistryParser getPotionEffect(CommandContext cmdCtx, String key); Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException; - Rotation getRotation(CommandContext cmdCtx, String key); + Rotation getRotation(CommandContext cmdCtx, String key) throws CommandSyntaxException; ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key); @@ -403,7 +394,7 @@ String getScoreHolderSingle(CommandContext cmdCtx, Strin */ SimpleCommandMap getSimpleCommandMap(); - Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType); + RegistryParser getSound(CommandContext cmdCtx, String key); /** * Retrieve a specific NMS implemented SuggestionProvider @@ -428,7 +419,21 @@ String getScoreHolderSingle(CommandContext cmdCtx, Strin Message generateMessageFromJson(String json); - CommandRegistrationStrategy createCommandRegistrationStrategy(); + @Unimplemented(because = REQUIRES_CSS) + BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); + + @Unimplemented(because = REQUIRES_CSS) + BukkitCommandSender getCommandSenderFromCommandSource(Source css); + + @Unimplemented(because = REQUIRES_CRAFTBUKKIT) + CommandListenerWrapper getBrigadierSourceFromCommandSender(AbstractCommandSender sender); + + @Unimplemented(because = {REQUIRES_MINECRAFT_SERVER, VERSION_SPECIFIC_IMPLEMENTATION}) + void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException; + + @Unimplemented(because = REQUIRES_MINECRAFT_SERVER) // What are the odds? + T getMinecraftServer(); NativeProxyCommandSender createNativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world); + } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/NativeProxyCommandSender.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/NativeProxyCommandSender.java index ddfa4ddac..97912de9a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/NativeProxyCommandSender.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/NativeProxyCommandSender.java @@ -40,7 +40,7 @@ public interface NativeProxyCommandSender extends ProxiedCommandSender { * @param world the proxied world that the command will be run in */ static NativeProxyCommandSender from(CommandSender caller, CommandSender callee, Location location, World world) { - return CommandAPIBukkit.get().createNativeProxyCommandSender(caller, callee, location, world); + return CommandAPIBukkit.get().getNMS().createNativeProxyCommandSender(caller, callee, location, world); } /** diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java index 1d3398e93..9541d9162 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/SimpleFunctionWrapper.java @@ -63,7 +63,7 @@ public SimpleFunctionWrapper(NamespacedKey minecraftKey, @SuppressWarnings("rawt * @return a SimpleFunctionWrapper[], which is an array of all of the functions that this tag contains */ public static SimpleFunctionWrapper[] getTag(NamespacedKey key) { - return CommandAPIBukkit.get().getTag(key); + return CommandAPIBukkit.get().getNMS().getTag(key); } /** @@ -72,7 +72,7 @@ public static SimpleFunctionWrapper[] getTag(NamespacedKey key) { * @return a SimpleFunctionWrapper representation of the Minecraft function for the provided NamespacedKey */ public static SimpleFunctionWrapper getFunction(NamespacedKey key) { - return CommandAPIBukkit.get().getFunction(key); + return CommandAPIBukkit.get().getNMS().getFunction(key); } /** @@ -80,7 +80,7 @@ public static SimpleFunctionWrapper getFunction(NamespacedKey key) { * @return a set of all functions that the server has registered */ public static Set getFunctions() { - return CommandAPIBukkit.get().getFunctions(); + return CommandAPIBukkit.get().getNMS().getFunctions(); } /** @@ -88,7 +88,7 @@ public static Set getFunctions() { * @return a set of all tags that the server has registered */ public static Set getTags() { - return CommandAPIBukkit.get().getTags(); + return CommandAPIBukkit.get().getNMS().getTags(); } /** diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml deleted file mode 100644 index b4432c9bf..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - commandapi-bukkit - dev.jorel - 10.2.0-SNAPSHOT - - 4.0.0 - - commandapi-bukkit-mojang-mapped - CommandAPI - Bukkit support Mojang-mapped version handler - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml index 7901438ee..96ccf3528 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml @@ -6,11 +6,11 @@ commandapi-bukkit dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-bukkit-networking-plugin - CommandAPI - Bukkit support Velocity networking plugin + Bukkit support Velocity networking plugin diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml index 300170a7f..8c08bf773 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml @@ -21,12 +21,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-1.20.2 - CommandAPI - Bukkit support for 1.20.2 + Bukkit support for 1.20.2 1.20.2-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java index d3dc99b46..87ca19069 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java @@ -21,8 +21,6 @@ package dev.jorel.commandapi.nms; import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.Message; import com.mojang.brigadier.arguments.ArgumentType; @@ -32,12 +30,12 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.logging.LogUtils; import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; -import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; @@ -45,7 +43,7 @@ import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; @@ -54,22 +52,15 @@ import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandFunction; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; @@ -78,19 +69,15 @@ import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; import net.minecraft.commands.arguments.TeamArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; import net.minecraft.commands.arguments.item.ItemArgument; import net.minecraft.commands.arguments.item.ItemInput; import net.minecraft.commands.arguments.item.ItemPredicateArgument; import net.minecraft.commands.arguments.selector.EntitySelector; -import net.minecraft.commands.synchronization.ArgumentUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.RegistryAccess.Frozen; import net.minecraft.core.particles.BlockParticleOption; @@ -111,7 +98,6 @@ import net.minecraft.server.MinecraftServer.ReloadableResources; import net.minecraft.server.ServerFunctionLibrary; import net.minecraft.server.ServerFunctionManager; -import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; @@ -127,7 +113,6 @@ import net.minecraft.world.level.DataPackConfig; import net.minecraft.world.level.Level; import net.minecraft.world.level.WorldDataConfiguration; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; import net.minecraft.world.level.gameevent.BlockPositionSource; import net.minecraft.world.level.storage.loot.LootDataType; import net.minecraft.world.phys.Vec2; @@ -139,13 +124,14 @@ import org.bukkit.Particle; import org.bukkit.Particle.DustOptions; import org.bukkit.Particle.DustTransition; +import org.bukkit.Sound; import org.bukkit.Vibration; import org.bukkit.Vibration.Destination; import org.bukkit.Vibration.Destination.BlockDestination; import org.bukkit.World; import org.bukkit.advancement.Advancement; import org.bukkit.block.Biome; -import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; @@ -154,8 +140,9 @@ import org.bukkit.craftbukkit.v1_20_R2.CraftServer; import org.bukkit.craftbukkit.v1_20_R2.CraftSound; import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockStates; import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R2.command.BukkitCommandWrapper; import org.bukkit.craftbukkit.v1_20_R2.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_20_R2.help.CustomHelpTopic; @@ -163,19 +150,16 @@ import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_20_R2.potion.CraftPotionEffectType; import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.help.HelpTopic; import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; -import java.io.File; -import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -197,12 +181,14 @@ @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) public class NMS_1_20_R2 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; private static final Field entitySelectorUsesSelector; private static final SafeVarHandle itemInput; private static final Field serverFunctionLibraryDispatcher; + private static final SafeVarHandle blockInputTag; // Derived from net.minecraft.commands.Commands; private static final CommandBuildContext COMMAND_BUILD_CONTEXT; @@ -222,6 +208,7 @@ public class NMS_1_20_R2 extends NMS_Common { itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "g", "dispatcher"); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); } @Override @@ -297,42 +284,30 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str } @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - - @Override - public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); - return switch(subType) { - case BIOME_BIOME -> { - Biome biome = null; + return new RegistryParser<>( + () -> { + Biome biome; try { biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); } catch(IllegalArgumentException biomeNotFound) { biome = null; } - yield biome; - } - case BIOME_NAMESPACEDKEY -> (NamespacedKey) fromResourceLocation(resourceLocation); - default -> null; - }; + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); } @Override - public final BlockData getBlockState(CommandContext cmdCtx, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + blockEntitySnapshot.loadData(blockInputTag.get(input)); + } + return snapshot; } @Override @@ -340,16 +315,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { return DimensionArgument.getDimension(cmdCtx, key).getWorld(); @@ -361,7 +326,7 @@ public final Enchantment getEnchantment(CommandContext cmdCt } @Override - public final Object getEntitySelector(CommandContext cmdCtx, String str, ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { // We override the rule whereby players need "minecraft.command.selector" and // have to have level 2 permissions in order to use entity selectors. We're @@ -374,56 +339,58 @@ public final Object getEntitySelector(CommandContext cmdCtx, // Shouldn't happen, CommandAPIHandler#getField makes it accessible } - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES: + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { try { - List result = new ArrayList<>(); - for (Entity entity : argument.findEntities(cmdCtx.getSource())) { - result.add(entity.getBukkitEntity()); + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); } if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_ENTITIES_FOUND.create(); + throw EntityArgument.NO_PLAYERS_FOUND.create(); } else { - yield result; + return result; } } catch (CommandSyntaxException e) { - yield new ArrayList(); + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } - case ENTITYSELECTOR_MANY_PLAYERS: + }, + (allowEmpty) -> { try { - List result = new ArrayList<>(); - for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { - result.add(player.getBukkitEntity()); + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); } if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_PLAYERS_FOUND.create(); + throw EntityArgument.NO_ENTITIES_FOUND.create(); } else { - yield result; + return result; } } catch (CommandSyntaxException e) { if (allowEmpty) { - yield new ArrayList(); + return new ArrayList(); } else { throw e; } } - case ENTITYSELECTOR_ONE_ENTITY: - yield argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(); - case ENTITYSELECTOR_ONE_PLAYER: - yield argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(); - default: - throw new IllegalArgumentException("Unexpected value: " + subType); - }; + } + ); } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); final Double lowBoxed = range.min().orElse(null); final Double highBoxed = range.max().orElse(null); - final double low = lowBoxed == null ? -Float.MAX_VALUE : lowBoxed; - final double high = highBoxed == null ? Float.MAX_VALUE : highBoxed; - return new FloatRange((float) low, (float) high); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); } @Override @@ -590,12 +557,11 @@ private ParticleData getParticleDataAsVibrationParticleOption(CommandContext< } @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return switch (subType) { - case POTION_EFFECT_POTION_EFFECT -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()); - case POTION_EFFECT_NAMESPACEDKEY -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); } @Differs(from = "1.20.1", by = "ResourceLocationArgument#getRecipe returns RecipeHolder now. Recipe id is access via id() instead of getId()") @@ -647,7 +613,7 @@ public BukkitCommandSender getSenderForCommand(CommandC } return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_20_R2(css, sender, proxy)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -656,7 +622,7 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal if (callee == null) callee = caller; // Most parameters default to what is defined by the caller - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(caller)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); // Position and rotation may be overridden by the Location if (location != null) { @@ -688,22 +654,19 @@ public final SimpleCommandMap getSimpleCommandMap() { @Differs(from = "1.20.1", by = "Uses CraftSound#minecraftToBukit instead of CraftSound#toBukkit") @Override - public final Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { + public final RegistryParser getSound(CommandContext cmdCtx, String key) { final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); - return switch(subType) { - case SOUND_SOUND -> { + return new RegistryParser<>( + () -> { final SoundEvent soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); if(soundEvent == null) { - yield null; + return null; } else { - yield CraftSound.minecraftToBukkit(soundEvent); + return CraftSound.minecraftToBukkit(soundEvent); } - } - case SOUND_NAMESPACEDKEY -> { - yield NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()); - } - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); } @Override @@ -775,7 +738,8 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -866,7 +830,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -904,16 +868,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R2.java index 7ee7daf6f..434e20c77 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R2.java @@ -19,7 +19,7 @@ public NativeProxyCommandSender_1_20_R2(CommandSourceStack css, CommandSender ca Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); - this.world = CommandAPIBukkit.get().getWorldForCSS(css); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/test/java/SafeReflect.java index fb7f07d95..7011ae3dc 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/test/java/SafeReflect.java @@ -18,21 +18,23 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -import java.util.Map; - -import org.bukkit.craftbukkit.v1_20_R2.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; import com.mojang.datafixers.util.Either; - import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.CustomFunctionManager; import net.minecraft.world.level.gameevent.EntityPositionSource; +import org.bukkit.craftbukkit.v1_20_R2.help.SimpleHelpMap; + +import java.util.Map; //Spigot-Mapped reflection @RequireField(in = CustomFunctionManager.class, name = "g", ofType = CommandDispatcher.class) @RequireField(in = EntitySelector.class, name = "p", ofType = boolean.class) @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "c", ofType = Either.class) +@RequireField(in = ArgumentTileLocation.class, name = "c", ofType = NBTTagCompound.class) public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml index fe6526fd3..b4e5e77cf 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml @@ -21,12 +21,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-1.20.3 - CommandAPI - Bukkit support for 1.20.3 + Bukkit support for 1.20.3 1.20.4-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java index 92f6fb07f..a32820a94 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java @@ -20,73 +20,7 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -import dev.jorel.commandapi.*; -import dev.jorel.commandapi.wrappers.Rotation; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; -import net.minecraft.commands.arguments.MessageArgument; -import net.minecraft.commands.arguments.ObjectiveArgument; -import net.minecraft.commands.arguments.TeamArgument; -import net.minecraft.commands.arguments.coordinates.RotationArgument; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Particle.DustOptions; -import org.bukkit.Particle.DustTransition; -import org.bukkit.Registry; -import org.bukkit.Vibration; -import org.bukkit.Vibration.Destination; -import org.bukkit.Vibration.Destination.BlockDestination; -import org.bukkit.World; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_20_R3.CraftLootTable; -import org.bukkit.craftbukkit.v1_20_R3.CraftParticle; -import org.bukkit.craftbukkit.v1_20_R3.CraftServer; -import org.bukkit.craftbukkit.v1_20_R3.CraftSound; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R3.command.BukkitCommandWrapper; -import org.bukkit.craftbukkit.v1_20_R3.command.VanillaCommandWrapper; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_20_R3.help.CustomHelpTopic; -import org.bukkit.craftbukkit.v1_20_R3.help.SimpleHelpMap; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R3.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.Recipe; - import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.Message; import com.mojang.brigadier.arguments.ArgumentType; @@ -95,9 +29,13 @@ import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.logging.LogUtils; - -import dev.jorel.commandapi.arguments.ArgumentSubType; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIHandler; +import dev.jorel.commandapi.SafeVarHandle; import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; @@ -105,17 +43,15 @@ import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -123,22 +59,21 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; import net.minecraft.commands.arguments.item.ItemArgument; import net.minecraft.commands.arguments.item.ItemInput; @@ -147,7 +82,6 @@ import net.minecraft.commands.execution.ExecutionContext; import net.minecraft.commands.functions.CommandFunction; import net.minecraft.commands.functions.InstantiatedFunction; -import net.minecraft.commands.synchronization.ArgumentUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.RegistryAccess.Frozen; import net.minecraft.core.particles.BlockParticleOption; @@ -168,7 +102,6 @@ import net.minecraft.server.MinecraftServer.ReloadableResources; import net.minecraft.server.ServerFunctionLibrary; import net.minecraft.server.ServerFunctionManager; -import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; @@ -185,15 +118,68 @@ import net.minecraft.world.level.DataPackConfig; import net.minecraft.world.level.Level; import net.minecraft.world.level.WorldDataConfiguration; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; import net.minecraft.world.level.gameevent.BlockPositionSource; import net.minecraft.world.level.storage.loot.LootDataType; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.Particle.DustOptions; +import org.bukkit.Particle.DustTransition; +import org.bukkit.Registry; +import org.bukkit.Sound; +import org.bukkit.Vibration; +import org.bukkit.Vibration.Destination; +import org.bukkit.Vibration.Destination.BlockDestination; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R3.CraftLootTable; +import org.bukkit.craftbukkit.v1_20_R3.CraftParticle; +import org.bukkit.craftbukkit.v1_20_R3.CraftServer; +import org.bukkit.craftbukkit.v1_20_R3.CraftSound; +import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockStates; +import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_20_R3.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_20_R3.help.CustomHelpTopic; +import org.bukkit.craftbukkit.v1_20_R3.help.SimpleHelpMap; +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_20_R3.potion.CraftPotionEffectType; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; +import java.util.function.ToIntFunction; + // Mojang-Mapped reflection /** * NMS implementation for Minecraft 1.20.3 and 1.20.4 @@ -203,12 +189,14 @@ @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) public class NMS_1_20_R3 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; private static final Field entitySelectorUsesSelector; private static final SafeVarHandle itemInput; private static final Field serverFunctionLibraryDispatcher; + private static final SafeVarHandle blockInputTag; // Derived from net.minecraft.commands.Commands; private static final CommandBuildContext COMMAND_BUILD_CONTEXT; @@ -229,6 +217,7 @@ public class NMS_1_20_R3 extends NMS_Common { itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "g", "dispatcher"); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); } @Override @@ -298,7 +287,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher(), css); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher(), css); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -321,7 +311,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher(), null); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher(), null); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -348,63 +339,37 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str } @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); + return new RegistryParser<>( + () -> { + Biome biome; + try { + biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); + } catch(IllegalArgumentException biomeNotFound) { + biome = null; + } + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); } @Override - public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException { - final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key() - .location(); - return switch (subType) { - case BIOME_BIOME -> { - Biome biome = null; - try { - biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); - } catch (IllegalArgumentException biomeNotFound) { - biome = null; - } - yield biome; + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + blockEntitySnapshot.loadData(blockInputTag.get(input)); } - case BIOME_NAMESPACEDKEY -> (NamespacedKey) fromResourceLocation(resourceLocation); - default -> null; - }; + return snapshot; } @Override - public final BlockData getBlockState(CommandContext cmdCtx, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); - } - - @Override - public CommandSourceStack getBrigadierSourceFromCommandSender( - AbstractCommandSender sender) { + public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -419,8 +384,7 @@ public final Enchantment getEnchantment(CommandContext cmdCt } @Override - public final Object getEntitySelector(CommandContext cmdCtx, String str, - ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { // We override the rule whereby players need "minecraft.command.selector" and // have to have level 2 permissions in order to use entity selectors. We're @@ -433,60 +397,58 @@ public final Object getEntitySelector(CommandContext cmdCtx, // Shouldn't happen, CommandAPIHandler#getField makes it accessible } - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES: - try { - List result = new ArrayList<>(); - for (Entity entity : argument.findEntities(cmdCtx.getSource())) { - result.add(entity.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_ENTITIES_FOUND.create(); - } else { - yield result; - } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; - } - } - case ENTITYSELECTOR_MANY_PLAYERS: - try { - List result = new ArrayList<>(); - for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { - result.add(player.getBukkitEntity()); + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_PLAYERS_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_PLAYERS_FOUND.create(); - } else { - yield result; - } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; + }, + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_ENTITIES_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } } - case ENTITYSELECTOR_ONE_ENTITY: - yield argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(); - case ENTITYSELECTOR_ONE_PLAYER: - yield argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(); - default: - throw new IllegalArgumentException("Unexpected value: " + subType); - }; + ); } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); final Double lowBoxed = range.min().orElse(null); final Double highBoxed = range.max().orElse(null); - final double low = lowBoxed == null ? -Float.MAX_VALUE : lowBoxed; - final double high = highBoxed == null ? Float.MAX_VALUE : highBoxed; - return new FloatRange((float) low, (float) high); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); } @Override @@ -652,12 +614,11 @@ private ParticleData getParticleDataAsVibrationParticleOption(CommandContext< } @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return switch (subType) { - case POTION_EFFECT_POTION_EFFECT -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()); - case POTION_EFFECT_NAMESPACEDKEY -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); } @Differs(from = "1.20.1", by = "ResourceLocationArgument#getRecipe returns RecipeHolder now. Recipe id is access via id() instead of getId()") @@ -718,7 +679,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_20_R3(css, sender, proxy)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -727,7 +688,7 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal if (callee == null) callee = caller; // Most parameters default to what is defined by the caller - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(caller)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); // Position and rotation may be overridden by the Location if (location != null) { @@ -759,22 +720,19 @@ public final SimpleCommandMap getSimpleCommandMap() { @Differs(from = "1.20.1", by = "Uses CraftSound#minecraftToBukit instead of CraftSound#toBukkit") @Override - public final Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { + public final RegistryParser getSound(CommandContext cmdCtx, String key) { final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); - return switch (subType) { - case SOUND_SOUND -> { - final SoundEvent soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); - if (soundEvent == null) { - yield null; - } else { - yield CraftSound.minecraftToBukkit(soundEvent); - } - } - case SOUND_NAMESPACEDKEY -> { - yield NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()); - } - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + return new RegistryParser<>( + () -> { + final SoundEvent soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); + if(soundEvent == null) { + return null; + } else { + return CraftSound.minecraftToBukkit(soundEvent); + } + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); } @Override @@ -849,7 +807,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -948,7 +906,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -986,16 +944,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R3.java index b61c6b50c..0ae8c5a54 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R3.java @@ -19,7 +19,7 @@ public NativeProxyCommandSender_1_20_R3(CommandSourceStack css, CommandSender ca Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); - this.world = CommandAPIBukkit.get().getWorldForCSS(css); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/test/java/SafeReflect.java index 7a627ff6b..dddcfb9e2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/test/java/SafeReflect.java @@ -18,21 +18,23 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -import java.util.Map; - -import org.bukkit.craftbukkit.v1_20_R3.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; import com.mojang.datafixers.util.Either; - import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.CustomFunctionManager; import net.minecraft.world.level.gameevent.EntityPositionSource; +import org.bukkit.craftbukkit.v1_20_R3.help.SimpleHelpMap; + +import java.util.Map; //Spigot-Mapped reflection @RequireField(in = CustomFunctionManager.class, name = "g", ofType = CommandDispatcher.class) @RequireField(in = EntitySelector.class, name = "p", ofType = boolean.class) @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "c", ofType = Either.class) +@RequireField(in = ArgumentTileLocation.class, name = "c", ofType = NBTTagCompound.class) public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml index eb91ededc..66f9978ba 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml @@ -21,12 +21,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-1.20.5 - CommandAPI - Bukkit support for 1.20.5 + Bukkit support for 1.20.5 1.20.6-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java index 44b17dce9..2d274ad9b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java @@ -20,70 +20,7 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -import dev.jorel.commandapi.*; -import dev.jorel.commandapi.wrappers.Rotation; -import net.minecraft.commands.arguments.ObjectiveArgument; -import net.minecraft.commands.arguments.TeamArgument; -import net.minecraft.commands.arguments.coordinates.RotationArgument; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Particle.DustOptions; -import org.bukkit.Particle.DustTransition; -import org.bukkit.Registry; -import org.bukkit.Vibration; -import org.bukkit.Vibration.Destination; -import org.bukkit.Vibration.Destination.BlockDestination; -import org.bukkit.World; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_20_R4.CraftLootTable; -import org.bukkit.craftbukkit.v1_20_R4.CraftParticle; -import org.bukkit.craftbukkit.v1_20_R4.CraftServer; -import org.bukkit.craftbukkit.v1_20_R4.CraftSound; -import org.bukkit.craftbukkit.v1_20_R4.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R4.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R4.command.BukkitCommandWrapper; -import org.bukkit.craftbukkit.v1_20_R4.command.VanillaCommandWrapper; -import org.bukkit.craftbukkit.v1_20_R4.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_20_R4.help.CustomHelpTopic; -import org.bukkit.craftbukkit.v1_20_R4.help.SimpleHelpMap; -import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R4.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.Recipe; - import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.Message; import com.mojang.brigadier.arguments.ArgumentType; @@ -94,9 +31,13 @@ import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; - -import dev.jorel.commandapi.arguments.ArgumentSubType; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIHandler; +import dev.jorel.commandapi.SafeVarHandle; import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; @@ -104,19 +45,15 @@ import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -124,23 +61,21 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; import net.minecraft.commands.arguments.item.ItemArgument; import net.minecraft.commands.arguments.item.ItemInput; @@ -149,7 +84,6 @@ import net.minecraft.commands.execution.ExecutionContext; import net.minecraft.commands.functions.CommandFunction; import net.minecraft.commands.functions.InstantiatedFunction; -import net.minecraft.commands.synchronization.ArgumentUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.component.PatchedDataComponentMap; @@ -173,7 +107,6 @@ import net.minecraft.server.MinecraftServer.ReloadableResources; import net.minecraft.server.ServerFunctionLibrary; import net.minecraft.server.ServerFunctionManager; -import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; @@ -190,14 +123,69 @@ import net.minecraft.world.level.DataPackConfig; import net.minecraft.world.level.Level; import net.minecraft.world.level.WorldDataConfiguration; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; import net.minecraft.world.level.gameevent.BlockPositionSource; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.Particle.DustOptions; +import org.bukkit.Particle.DustTransition; +import org.bukkit.Registry; +import org.bukkit.Sound; +import org.bukkit.Vibration; +import org.bukkit.Vibration.Destination; +import org.bukkit.Vibration.Destination.BlockDestination; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R4.CraftLootTable; +import org.bukkit.craftbukkit.v1_20_R4.CraftParticle; +import org.bukkit.craftbukkit.v1_20_R4.CraftRegistry; +import org.bukkit.craftbukkit.v1_20_R4.CraftServer; +import org.bukkit.craftbukkit.v1_20_R4.CraftSound; +import org.bukkit.craftbukkit.v1_20_R4.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R4.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_20_R4.block.CraftBlockStates; +import org.bukkit.craftbukkit.v1_20_R4.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_20_R4.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R4.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_20_R4.help.CustomHelpTopic; +import org.bukkit.craftbukkit.v1_20_R4.help.SimpleHelpMap; +import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_20_R4.potion.CraftPotionEffectType; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToIntFunction; + // Mojang-Mapped reflection /** * NMS implementation for Minecraft 1.20.5, 1.20.6 @@ -207,48 +195,37 @@ @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) // @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) public class NMS_1_20_R4 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; private static final Field entitySelectorUsesSelector; // private static final SafeVarHandle itemInput; private static final Field serverFunctionLibraryDispatcher; - private static final boolean vanillaCommandDispatcherFieldExists; + private static final SafeVarHandle blockInputTag; // Derived from net.minecraft.commands.Commands; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + private final Supplier commandBuildContext; + + public NMS_1_20_R4(Supplier commandBuildContext) { + this.commandBuildContext = commandBuildContext; + } // Compute all var handles all in one go so we don't do this during main server // runtime static { - if (Bukkit.getServer() instanceof CraftServer server) { - COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), - server.getServer().getWorldData().getDataConfiguration().enabledFeatures()); - } else { - COMMAND_BUILD_CONTEXT = null; - } - helpMapTopics = SafeVarHandle.ofOrNull(SimpleHelpMap.class, "helpTopics", "helpTopics", Map.class); // For some reason, MethodHandles fails for this field, but Field works okay entitySelectorUsesSelector = CommandAPIHandler.getField(EntitySelector.class, "p", "usesSelector"); // itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "g", "dispatcher"); - - boolean fieldExists; - try { - MinecraftServer.class.getDeclaredField("vanillaCommandDispatcher"); - fieldExists = true; - } catch (NoSuchFieldException | SecurityException e) { - // Expected on Paper-1.20.6-65 or later due to https://github.com/PaperMC/Paper/pull/8235 - fieldExists = false; - } - vanillaCommandDispatcherFieldExists = fieldExists; + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); } @Override protected CommandBuildContext getCommandBuildContext() { - return COMMAND_BUILD_CONTEXT; + return commandBuildContext.get(); } @Override @@ -259,12 +236,12 @@ public ArgumentType _ArgumentAdvancement() { @Differs(from = "1.20.4", by = "Now needs a command build context") @Override public ArgumentType _ArgumentChatComponent() { - return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); + return ComponentArgument.textComponent(commandBuildContext.get()); } @Override public final ArgumentType _ArgumentEnchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT); } @Override @@ -274,7 +251,7 @@ public ArgumentType _ArgumentRecipe() { @Override public final ArgumentType _ArgumentSyntheticBiome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); + return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME); } @Override @@ -287,9 +264,9 @@ public String[] compatibleVersions() { return new String[] { "1.20.5", "1.20.6" }; }; - private static String serializeNMSItemStack(ItemStack is) { + private String serializeNMSItemStack(ItemStack is) { final DataComponentMap patchedMap = PatchedDataComponentMap.fromPatch(PatchedDataComponentMap.EMPTY, is.getComponentsPatch()); - return new ItemInput(is.getItemHolder(), patchedMap).serialize(COMMAND_BUILD_CONTEXT); + return new ItemInput(is.getItemHolder(), patchedMap).serialize(commandBuildContext.get()); } @Differs(from = "1.20.4", by = "Everything") @@ -332,7 +309,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -355,7 +333,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -380,49 +359,32 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str throws CommandSyntaxException { return ResourceLocationArgument.getAdvancement(cmdCtx, key).toBukkit(); } - - @Differs(from = "1.20.4", by = "Serializer.toJson now needs a Provider") - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - // TODO: Figure out if an empty provider is suitable for this context - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); + return new RegistryParser<>( + () -> { + Biome biome; + try { + biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); + } catch(IllegalArgumentException biomeNotFound) { + biome = null; + } + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); } @Override - public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException { - final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key() - .location(); - return switch (subType) { - case BIOME_BIOME -> { - Biome biome = null; - try { - biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); - } catch (IllegalArgumentException biomeNotFound) { - biome = null; - } - yield biome; + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(CraftRegistry.getMinecraftRegistry(), BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + blockEntitySnapshot.loadData(blockInputTag.get(input)); } - case BIOME_NAMESPACEDKEY -> (NamespacedKey) fromResourceLocation(resourceLocation); - default -> null; - }; - } - - @Override - public final BlockData getBlockState(CommandContext cmdCtx, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); + return snapshot; } @Override @@ -431,17 +393,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Differs(from = "1.20.4", by = "Serializer.toJson now needs a Provider") - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -456,8 +407,7 @@ public final Enchantment getEnchantment(CommandContext cmdCt } @Override - public final Object getEntitySelector(CommandContext cmdCtx, String str, - ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { // We override the rule whereby players need "minecraft.command.selector" and // have to have level 2 permissions in order to use entity selectors. We're @@ -470,60 +420,58 @@ public final Object getEntitySelector(CommandContext cmdCtx, // Shouldn't happen, CommandAPIHandler#getField makes it accessible } - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES: - try { - List result = new ArrayList<>(); - for (Entity entity : argument.findEntities(cmdCtx.getSource())) { - result.add(entity.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_ENTITIES_FOUND.create(); - } else { - yield result; - } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; - } - } - case ENTITYSELECTOR_MANY_PLAYERS: - try { - List result = new ArrayList<>(); - for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { - result.add(player.getBukkitEntity()); + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_PLAYERS_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_PLAYERS_FOUND.create(); - } else { - yield result; - } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; + }, + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_ENTITIES_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } } - case ENTITYSELECTOR_ONE_ENTITY: - yield argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(); - case ENTITYSELECTOR_ONE_PLAYER: - yield argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(); - default: - throw new IllegalArgumentException("Unexpected value: " + subType); - }; + ); } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); final Double lowBoxed = range.min().orElse(null); final Double highBoxed = range.max().orElse(null); - final double low = lowBoxed == null ? -Float.MAX_VALUE : lowBoxed; - final double high = highBoxed == null ? Float.MAX_VALUE : highBoxed; - return new FloatRange((float) low, (float) high); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); } @Override @@ -704,12 +652,11 @@ private ParticleData getParticleDataAsVibrationParticleOption(CommandContext< } @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return switch (subType) { - case POTION_EFFECT_POTION_EFFECT -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()); - case POTION_EFFECT_NAMESPACEDKEY -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); } @Override @@ -767,7 +714,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_20_R4(css, sender, proxy)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -776,7 +723,7 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal if (callee == null) callee = caller; // Most parameters default to what is defined by the caller - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(caller)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); // Position and rotation may be overridden by the Location if (location != null) { @@ -807,22 +754,19 @@ public final SimpleCommandMap getSimpleCommandMap() { } @Override - public final Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { + public final RegistryParser getSound(CommandContext cmdCtx, String key) { final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); - return switch (subType) { - case SOUND_SOUND -> { - final SoundEvent soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); - if (soundEvent == null) { - yield null; - } else { - yield CraftSound.minecraftToBukkit(soundEvent); - } - } - case SOUND_NAMESPACEDKEY -> { - yield NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()); - } - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + return new RegistryParser<>( + () -> { + final SoundEvent soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); + if(soundEvent == null) { + return null; + } else { + return CraftSound.minecraftToBukkit(soundEvent); + } + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); } @Override @@ -895,7 +839,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -993,7 +937,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1010,7 +954,7 @@ public final void reloadDataPacks() { @Override public Message generateMessageFromJson(String json) { // TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here - return Serializer.fromJson(json, COMMAND_BUILD_CONTEXT); + return Serializer.fromJson(json, commandBuildContext.get()); } @SuppressWarnings("unchecked") @@ -1025,45 +969,11 @@ public T getMinecraftServer() { @Override public ArgumentType _ArgumentMobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT); } @Override public ArgumentType _ArgumentEntitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); - } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - () -> { - SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); - helpMap.clear(); - helpMap.initializeGeneralTopics(); - helpMap.initializeCommands(); - }, - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R4.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R4.java index 4bce8ce3a..ecf9ce6cb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R4.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R4.java @@ -19,7 +19,7 @@ public NativeProxyCommandSender_1_20_R4(CommandSourceStack css, CommandSender ca Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); - this.world = CommandAPIBukkit.get().getWorldForCSS(css); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/test/java/SafeReflect.java index 0d0debda0..ceb068354 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/test/java/SafeReflect.java @@ -18,21 +18,23 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -import java.util.Map; - -import org.bukkit.craftbukkit.v1_20_R4.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; import com.mojang.datafixers.util.Either; - import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.CustomFunctionManager; import net.minecraft.world.level.gameevent.EntityPositionSource; +import org.bukkit.craftbukkit.v1_20_R4.help.SimpleHelpMap; + +import java.util.Map; // Spigot-Mapped reflection @RequireField(in = CustomFunctionManager.class, name = "g", ofType = CommandDispatcher.class) @RequireField(in = EntitySelector.class, name = "p", ofType = boolean.class) @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "e", ofType = Either.class) +@RequireField(in = ArgumentTileLocation.class, name = "c", ofType = NBTTagCompound.class) public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml index 29b0a897f..5320f1fb5 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml @@ -21,12 +21,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-1.20 - CommandAPI - Bukkit support for 1.20 + Bukkit support for 1.20 1.20.1-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java index cd70bf71f..0976cc5c3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java @@ -21,8 +21,6 @@ package dev.jorel.commandapi.nms; import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.Message; import com.mojang.brigadier.arguments.ArgumentType; @@ -32,12 +30,12 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.logging.LogUtils; import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; -import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; @@ -45,7 +43,7 @@ import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; @@ -54,21 +52,14 @@ import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandFunction; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; @@ -77,19 +68,15 @@ import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; import net.minecraft.commands.arguments.TeamArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; import net.minecraft.commands.arguments.item.ItemArgument; import net.minecraft.commands.arguments.item.ItemInput; import net.minecraft.commands.arguments.item.ItemPredicateArgument; import net.minecraft.commands.arguments.selector.EntitySelector; -import net.minecraft.commands.synchronization.ArgumentUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.RegistryAccess.Frozen; import net.minecraft.core.particles.BlockParticleOption; @@ -110,7 +97,6 @@ import net.minecraft.server.MinecraftServer.ReloadableResources; import net.minecraft.server.ServerFunctionLibrary; import net.minecraft.server.ServerFunctionManager; -import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; @@ -125,7 +111,6 @@ import net.minecraft.world.level.DataPackConfig; import net.minecraft.world.level.Level; import net.minecraft.world.level.WorldDataConfiguration; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; import net.minecraft.world.level.gameevent.BlockPositionSource; import net.minecraft.world.level.storage.loot.LootDataType; import net.minecraft.world.phys.Vec2; @@ -137,13 +122,14 @@ import org.bukkit.Particle; import org.bukkit.Particle.DustOptions; import org.bukkit.Particle.DustTransition; +import org.bukkit.Sound; import org.bukkit.Vibration; import org.bukkit.Vibration.Destination; import org.bukkit.Vibration.Destination.BlockDestination; import org.bukkit.World; import org.bukkit.advancement.Advancement; import org.bukkit.block.Biome; -import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; @@ -152,8 +138,9 @@ import org.bukkit.craftbukkit.v1_20_R1.CraftServer; import org.bukkit.craftbukkit.v1_20_R1.CraftSound; import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockStates; import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R1.command.BukkitCommandWrapper; import org.bukkit.craftbukkit.v1_20_R1.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_20_R1.help.CustomHelpTopic; @@ -161,19 +148,16 @@ import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_20_R1.potion.CraftPotionEffectType; import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.help.HelpTopic; import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; -import java.io.File; -import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -195,12 +179,14 @@ @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) public class NMS_1_20_R1 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; private static final Field entitySelectorUsesSelector; private static final SafeVarHandle itemInput; private static final Field serverFunctionLibraryDispatcher; + private static final SafeVarHandle blockInputTag; // Derived from net.minecraft.commands.Commands; private static final CommandBuildContext COMMAND_BUILD_CONTEXT; @@ -220,6 +206,7 @@ public class NMS_1_20_R1 extends NMS_Common { itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "g", "dispatcher"); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); } @Override @@ -295,42 +282,30 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str } @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - - @Override - public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); - return switch(subType) { - case BIOME_BIOME -> { - Biome biome = null; + return new RegistryParser<>( + () -> { + Biome biome; try { biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); } catch(IllegalArgumentException biomeNotFound) { biome = null; } - yield biome; - } - case BIOME_NAMESPACEDKEY -> (NamespacedKey) fromResourceLocation(resourceLocation); - default -> null; - }; + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); } @Override - public final BlockData getBlockState(CommandContext cmdCtx, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + snapshot = CraftBlockStates.getBlockState(BlockPos.ZERO, input.getState(), blockEntitySnapshot.getSnapshotNBT()); + } + return snapshot; } @Override @@ -338,16 +313,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { return DimensionArgument.getDimension(cmdCtx, key).getWorld(); @@ -359,7 +324,7 @@ public final Enchantment getEnchantment(CommandContext cmdCt } @Override - public final Object getEntitySelector(CommandContext cmdCtx, String str, ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { // We override the rule whereby players need "minecraft.command.selector" and // have to have level 2 permissions in order to use entity selectors. We're @@ -372,60 +337,58 @@ public final Object getEntitySelector(CommandContext cmdCtx, // Shouldn't happen, CommandAPIHandler#getField makes it accessible } - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES: + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { try { - List result = new ArrayList<>(); - for (Entity entity : argument.findEntities(cmdCtx.getSource())) { - result.add(entity.getBukkitEntity()); + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); } if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_ENTITIES_FOUND.create(); + throw EntityArgument.NO_PLAYERS_FOUND.create(); } else { - yield result; + return result; } } catch (CommandSyntaxException e) { if (allowEmpty) { - yield new ArrayList(); + return new ArrayList(); } else { throw e; } } - case ENTITYSELECTOR_MANY_PLAYERS: + }, + (allowEmpty) -> { try { - List result = new ArrayList<>(); - for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { - result.add(player.getBukkitEntity()); + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); } if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_PLAYERS_FOUND.create(); + throw EntityArgument.NO_ENTITIES_FOUND.create(); } else { - yield result; + return result; } } catch (CommandSyntaxException e) { if (allowEmpty) { - yield new ArrayList(); + return new ArrayList(); } else { throw e; } } - case ENTITYSELECTOR_ONE_ENTITY: - yield argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(); - case ENTITYSELECTOR_ONE_PLAYER: - yield argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(); - default: - throw new IllegalArgumentException("Unexpected value: " + subType); - }; + } + ); } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); final Double lowBoxed = range.getMin(); final Double highBoxed = range.getMax(); - final double low = lowBoxed == null ? -Float.MAX_VALUE : lowBoxed; - final double high = highBoxed == null ? Float.MAX_VALUE : highBoxed; - return new FloatRange((float) low, (float) high); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); } @Override @@ -592,12 +555,11 @@ private ParticleData getParticleDataAsVibrationParticleOption(CommandContext< } @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return switch (subType) { - case POTION_EFFECT_POTION_EFFECT -> CraftPotionEffectType.getByKey(fromResourceLocation(BuiltInRegistries.MOB_EFFECT.getKey(ResourceArgument.getMobEffect(cmdCtx, key).value()))); - case POTION_EFFECT_NAMESPACEDKEY -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.getByKey(fromResourceLocation(BuiltInRegistries.MOB_EFFECT.getKey(ResourceArgument.getMobEffect(cmdCtx, key).value()))), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); } @Override @@ -648,7 +610,7 @@ public BukkitCommandSender getSenderForCommand(CommandC } return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_20_R1(css, sender, proxy)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -657,7 +619,7 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal if (callee == null) callee = caller; // Most parameters default to what is defined by the caller - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(caller)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); // Position and rotation may be overridden by the Location if (location != null) { @@ -688,22 +650,19 @@ public final SimpleCommandMap getSimpleCommandMap() { } @Override - public final Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { + public final RegistryParser getSound(CommandContext cmdCtx, String key) { final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); - return switch(subType) { - case SOUND_SOUND -> { + return new RegistryParser<>( + () -> { final SoundEvent soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); if(soundEvent == null) { - yield null; + return null; } else { - yield CraftSound.getBukkit(soundEvent); + return CraftSound.getBukkit(soundEvent); } - } - case SOUND_NAMESPACEDKEY -> { - yield NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()); - } - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); } @Override @@ -775,7 +734,8 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -866,7 +826,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -904,16 +864,4 @@ public ArgumentType _ArgumentMobEffect() { public ArgumentType _ArgumentEntitySummon() { return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R1.java index 0f485451c..8b3cd444b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_20_R1.java @@ -19,7 +19,7 @@ public NativeProxyCommandSender_1_20_R1(CommandSourceStack css, CommandSender ca Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); - this.world = CommandAPIBukkit.get().getWorldForCSS(css); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/test/java/SafeReflect.java index 6713742c5..7d65cf302 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/test/java/SafeReflect.java @@ -18,21 +18,23 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -import java.util.Map; - -import org.bukkit.craftbukkit.v1_20_R1.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; import com.mojang.datafixers.util.Either; - import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.CustomFunctionManager; import net.minecraft.world.level.gameevent.EntityPositionSource; +import org.bukkit.craftbukkit.v1_20_R1.help.SimpleHelpMap; + +import java.util.Map; //Spigot-Mapped reflection @RequireField(in = CustomFunctionManager.class, name = "g", ofType = CommandDispatcher.class) @RequireField(in = EntitySelector.class, name = "p", ofType = boolean.class) @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "c", ofType = Either.class) +@RequireField(in = ArgumentTileLocation.class, name = "c", ofType = NBTTagCompound.class) public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml index 5a339e215..d182b8d9b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml @@ -21,12 +21,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-1.21.2 - CommandAPI - Bukkit support for 1.21.2 + Bukkit support for 1.21.2 1.21.3-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java index bf2595c61..ba5d05144 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java @@ -20,69 +20,7 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -import dev.jorel.commandapi.wrappers.Rotation; -import net.minecraft.commands.arguments.ObjectiveArgument; -import net.minecraft.commands.arguments.TeamArgument; -import net.minecraft.commands.arguments.coordinates.RotationArgument; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Particle.DustOptions; -import org.bukkit.Particle.DustTransition; -import org.bukkit.Registry; -import org.bukkit.Vibration; -import org.bukkit.Vibration.Destination; -import org.bukkit.Vibration.Destination.BlockDestination; -import org.bukkit.World; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_21_R2.CraftLootTable; -import org.bukkit.craftbukkit.v1_21_R2.CraftParticle; -import org.bukkit.craftbukkit.v1_21_R2.CraftServer; -import org.bukkit.craftbukkit.v1_21_R2.CraftSound; -import org.bukkit.craftbukkit.v1_21_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R2.command.BukkitCommandWrapper; -import org.bukkit.craftbukkit.v1_21_R2.command.VanillaCommandWrapper; -import org.bukkit.craftbukkit.v1_21_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_21_R2.help.CustomHelpTopic; -import org.bukkit.craftbukkit.v1_21_R2.help.SimpleHelpMap; -import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_21_R2.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.Recipe; - import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.Message; import com.mojang.brigadier.arguments.ArgumentType; @@ -93,15 +31,13 @@ import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; - import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; -import dev.jorel.commandapi.PaperCommandRegistration; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; -import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; @@ -109,19 +45,15 @@ import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -129,11 +61,10 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; @@ -141,12 +72,11 @@ import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; import net.minecraft.commands.arguments.item.ItemArgument; import net.minecraft.commands.arguments.item.ItemInput; @@ -155,7 +85,6 @@ import net.minecraft.commands.execution.ExecutionContext; import net.minecraft.commands.functions.CommandFunction; import net.minecraft.commands.functions.InstantiatedFunction; -import net.minecraft.commands.synchronization.ArgumentUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.particles.BlockParticleOption; @@ -178,7 +107,6 @@ import net.minecraft.server.MinecraftServer.ReloadableResources; import net.minecraft.server.ServerFunctionLibrary; import net.minecraft.server.ServerFunctionManager; -import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; @@ -198,14 +126,69 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.WorldDataConfiguration; import net.minecraft.world.level.block.entity.FuelValues; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; import net.minecraft.world.level.gameevent.BlockPositionSource; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.Particle.DustOptions; +import org.bukkit.Particle.DustTransition; +import org.bukkit.Registry; +import org.bukkit.Sound; +import org.bukkit.Vibration; +import org.bukkit.Vibration.Destination; +import org.bukkit.Vibration.Destination.BlockDestination; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R2.CraftLootTable; +import org.bukkit.craftbukkit.v1_21_R2.CraftParticle; +import org.bukkit.craftbukkit.v1_21_R2.CraftRegistry; +import org.bukkit.craftbukkit.v1_21_R2.CraftServer; +import org.bukkit.craftbukkit.v1_21_R2.CraftSound; +import org.bukkit.craftbukkit.v1_21_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_21_R2.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_21_R2.block.CraftBlockStates; +import org.bukkit.craftbukkit.v1_21_R2.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_21_R2.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R2.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_21_R2.help.CustomHelpTopic; +import org.bukkit.craftbukkit.v1_21_R2.help.SimpleHelpMap; +import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R2.potion.CraftPotionEffectType; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToIntFunction; + // Mojang-Mapped reflection /** * NMS implementation for Minecraft 1.21.2 and 1.21.3 @@ -216,6 +199,7 @@ // @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) @RequireField(in = MinecraftServer.class, name = "fuelValues", ofType = FuelValues.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) public class NMS_1_21_R2 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; @@ -224,26 +208,25 @@ public class NMS_1_21_R2 extends NMS_Common { private static final Field serverFunctionLibraryDispatcher; private static final boolean vanillaCommandDispatcherFieldExists; private static final SafeVarHandle minecraftServerFuelValues; + private static final SafeVarHandle blockInputTag; // Derived from net.minecraft.commands.Commands; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + private final Supplier commandBuildContext; + + public NMS_1_21_R2(Supplier commandBuildContext) { + this.commandBuildContext = commandBuildContext; + } // Compute all var handles all in one go so we don't do this during main server // runtime static { - if (Bukkit.getServer() instanceof CraftServer server) { - COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), - server.getServer().getWorldData().getDataConfiguration().enabledFeatures()); - } else { - COMMAND_BUILD_CONTEXT = null; - } - helpMapTopics = SafeVarHandle.ofOrNull(SimpleHelpMap.class, "helpTopics", "helpTopics", Map.class); // For some reason, MethodHandles fails for this field, but Field works okay entitySelectorUsesSelector = CommandAPIHandler.getField(EntitySelector.class, "p", "usesSelector"); // itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "h", "dispatcher"); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); boolean fieldExists; try { @@ -260,7 +243,7 @@ public class NMS_1_21_R2 extends NMS_Common { @Override protected CommandBuildContext getCommandBuildContext() { - return COMMAND_BUILD_CONTEXT; + return commandBuildContext.get(); } @Differs(from = "1.21.1", by = "New advancement argument implementation") @@ -271,12 +254,12 @@ public ArgumentType _ArgumentAdvancement() { @Override public ArgumentType _ArgumentChatComponent() { - return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); + return ComponentArgument.textComponent(commandBuildContext.get()); } @Override public final ArgumentType _ArgumentEnchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT); } @Differs(from = "1.21.1", by = "New recipe argument implementation") @@ -287,7 +270,7 @@ public ArgumentType _ArgumentRecipe() { @Override public final ArgumentType _ArgumentSyntheticBiome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); + return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME); } @Override @@ -301,8 +284,8 @@ public String[] compatibleVersions() { }; @Differs(from = "1.20.6", by = "ItemInput constructor uses a data components patch, instead of a data components map") - private static String serializeNMSItemStack(ItemStack is) { - return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(COMMAND_BUILD_CONTEXT); + private String serializeNMSItemStack(ItemStack is) { + return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext.get()); } @Override @@ -344,7 +327,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -367,7 +351,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -393,47 +378,32 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str throws CommandSyntaxException { return ResourceKeyArgument.getAdvancement(cmdCtx, key).toBukkit(); } - - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); + return new RegistryParser<>( + () -> { + Biome biome; + try { + biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); + } catch(IllegalArgumentException biomeNotFound) { + biome = null; + } + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); } @Override - public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException { - final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key() - .location(); - return switch (subType) { - case BIOME_BIOME -> { - Biome biome = null; - try { - biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); - } catch (IllegalArgumentException biomeNotFound) { - biome = null; - } - yield biome; + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(CraftRegistry.getMinecraftRegistry(), BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + blockEntitySnapshot.loadData(blockInputTag.get(input)); } - case BIOME_NAMESPACEDKEY -> (NamespacedKey) fromResourceLocation(resourceLocation); - default -> null; - }; - } - - @Override - public final BlockData getBlockState(CommandContext cmdCtx, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); + return snapshot; } @Override @@ -442,16 +412,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -467,8 +427,7 @@ public final Enchantment getEnchantment(CommandContext cmdCt } @Override - public final Object getEntitySelector(CommandContext cmdCtx, String str, - ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { // We override the rule whereby players need "minecraft.command.selector" and // have to have level 2 permissions in order to use entity selectors. We're @@ -481,60 +440,58 @@ public final Object getEntitySelector(CommandContext cmdCtx, // Shouldn't happen, CommandAPIHandler#getField makes it accessible } - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES: - try { - List result = new ArrayList<>(); - for (Entity entity : argument.findEntities(cmdCtx.getSource())) { - result.add(entity.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_ENTITIES_FOUND.create(); - } else { - yield result; - } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; - } - } - case ENTITYSELECTOR_MANY_PLAYERS: - try { - List result = new ArrayList<>(); - for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { - result.add(player.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_PLAYERS_FOUND.create(); - } else { - yield result; + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_PLAYERS_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; + }, + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_ENTITIES_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } } - case ENTITYSELECTOR_ONE_ENTITY: - yield argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(); - case ENTITYSELECTOR_ONE_PLAYER: - yield argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(); - default: - throw new IllegalArgumentException("Unexpected value: " + subType); - }; + ); } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); final Double lowBoxed = range.min().orElse(null); final Double highBoxed = range.max().orElse(null); - final double low = lowBoxed == null ? -Float.MAX_VALUE : lowBoxed; - final double high = highBoxed == null ? Float.MAX_VALUE : highBoxed; - return new FloatRange((float) low, (float) high); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); } @Override @@ -713,12 +670,11 @@ private ParticleData getParticleDataAsVibrationParticleOption(CommandContext< } @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return switch (subType) { - case POTION_EFFECT_POTION_EFFECT -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()); - case POTION_EFFECT_NAMESPACEDKEY -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); } @Differs(from = "1.21.1", by = "Uses ResourceKeyArgument instead of ResourceLocationArgument") @@ -777,7 +733,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_21_R2(css, sender, proxy)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -786,7 +742,7 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal if (callee == null) callee = caller; // Most parameters default to what is defined by the caller - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(caller)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); // Position and rotation may be overridden by the Location if (location != null) { @@ -817,22 +773,19 @@ public final SimpleCommandMap getSimpleCommandMap() { } @Override - public final Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { + public final RegistryParser getSound(CommandContext cmdCtx, String key) { final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); - return switch (subType) { - case SOUND_SOUND -> { - final Optional> soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); - if (soundEvent.isEmpty()) { - yield null; - } else { - yield CraftSound.minecraftToBukkit(soundEvent.get().value()); - } - } - case SOUND_NAMESPACEDKEY -> { - yield NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()); - } - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + return new RegistryParser<>( + () -> { + final Optional> soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); + if(soundEvent.isEmpty()) { + return null; + } else { + return CraftSound.minecraftToBukkit(soundEvent.get().value()); + } + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); } @Override @@ -909,7 +862,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -1020,7 +973,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1037,7 +990,7 @@ public final void reloadDataPacks() { @Override public Message generateMessageFromJson(String json) { // TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here - return Serializer.fromJson(json, COMMAND_BUILD_CONTEXT); + return Serializer.fromJson(json, commandBuildContext.get()); } @SuppressWarnings("unchecked") @@ -1052,45 +1005,12 @@ public T getMinecraftServer() { @Override public ArgumentType _ArgumentMobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT); } @Override public ArgumentType _ArgumentEntitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE); } - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - () -> { - SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); - helpMap.clear(); - helpMap.initializeGeneralTopics(); - helpMap.initializeCommands(); - }, - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R2.java index 7e4ffba40..7acbf7d4b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R2.java @@ -19,7 +19,7 @@ public NativeProxyCommandSender_1_21_R2(CommandSourceStack css, CommandSender ca Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); - this.world = CommandAPIBukkit.get().getWorldForCSS(css); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/test/java/SafeReflect.java index f5f3a7de8..3d1fb9927 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/test/java/SafeReflect.java @@ -18,19 +18,20 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -import java.util.Map; - -import org.bukkit.craftbukkit.v1_21_R2.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; import com.mojang.datafixers.util.Either; - import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.CustomFunctionManager; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.block.entity.FuelValues; import net.minecraft.world.level.gameevent.EntityPositionSource; +import org.bukkit.craftbukkit.v1_21_R2.help.SimpleHelpMap; + +import java.util.Map; // Spigot-Mapped reflection @RequireField(in = CustomFunctionManager.class, name = "h", ofType = CommandDispatcher.class) @@ -38,4 +39,5 @@ @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "e", ofType = Either.class) @RequireField(in = MinecraftServer.class, name = "aE", ofType = FuelValues.class) +@RequireField(in = ArgumentTileLocation.class, name = "c", ofType = NBTTagCompound.class) public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml index 5d40226eb..a3be63527 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml @@ -21,12 +21,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-1.21.4 - CommandAPI - Bukkit support for 1.21.4 + Bukkit support for 1.21.4 1.21.4-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java index 89e7d0036..317b4611f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java @@ -20,73 +20,7 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -import dev.jorel.commandapi.wrappers.Rotation; -import net.minecraft.commands.arguments.ObjectiveArgument; -import net.minecraft.commands.arguments.TeamArgument; -import net.minecraft.commands.arguments.coordinates.RotationArgument; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Particle.DustOptions; -import org.bukkit.Particle.DustTransition; -import org.bukkit.Particle.Trail; -import org.bukkit.Registry; -import org.bukkit.Vibration; -import org.bukkit.Vibration.Destination; -import org.bukkit.Vibration.Destination.BlockDestination; -import org.bukkit.World; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_21_R3.CraftLootTable; -import org.bukkit.craftbukkit.v1_21_R3.CraftParticle; -import org.bukkit.craftbukkit.v1_21_R3.CraftServer; -import org.bukkit.craftbukkit.v1_21_R3.CraftSound; -import org.bukkit.craftbukkit.v1_21_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R3.command.BukkitCommandWrapper; -import org.bukkit.craftbukkit.v1_21_R3.command.VanillaCommandWrapper; -import org.bukkit.craftbukkit.v1_21_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_21_R3.help.CustomHelpTopic; -import org.bukkit.craftbukkit.v1_21_R3.help.SimpleHelpMap; -import org.bukkit.craftbukkit.v1_21_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_21_R3.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.Recipe; - import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.Message; import com.mojang.brigadier.arguments.ArgumentType; @@ -97,15 +31,13 @@ import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; - import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; -import dev.jorel.commandapi.PaperCommandRegistration; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; -import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; @@ -113,19 +45,15 @@ import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -133,11 +61,10 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; @@ -145,12 +72,11 @@ import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; import net.minecraft.commands.arguments.item.ItemArgument; import net.minecraft.commands.arguments.item.ItemInput; @@ -159,7 +85,6 @@ import net.minecraft.commands.execution.ExecutionContext; import net.minecraft.commands.functions.CommandFunction; import net.minecraft.commands.functions.InstantiatedFunction; -import net.minecraft.commands.synchronization.ArgumentUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.particles.BlockParticleOption; @@ -183,7 +108,6 @@ import net.minecraft.server.MinecraftServer.ReloadableResources; import net.minecraft.server.ServerFunctionLibrary; import net.minecraft.server.ServerFunctionManager; -import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; @@ -203,14 +127,73 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.WorldDataConfiguration; import net.minecraft.world.level.block.entity.FuelValues; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; import net.minecraft.world.level.gameevent.BlockPositionSource; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.Particle.DustOptions; +import org.bukkit.Particle.DustTransition; +import org.bukkit.Particle.Trail; +import org.bukkit.Registry; +import org.bukkit.Sound; +import org.bukkit.Vibration; +import org.bukkit.Vibration.Destination; +import org.bukkit.Vibration.Destination.BlockDestination; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R3.CraftLootTable; +import org.bukkit.craftbukkit.v1_21_R3.CraftParticle; +import org.bukkit.craftbukkit.v1_21_R3.CraftRegistry; +import org.bukkit.craftbukkit.v1_21_R3.CraftServer; +import org.bukkit.craftbukkit.v1_21_R3.CraftSound; +import org.bukkit.craftbukkit.v1_21_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_21_R3.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_21_R3.block.CraftBlockStates; +import org.bukkit.craftbukkit.v1_21_R3.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_21_R3.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_21_R3.help.CustomHelpTopic; +import org.bukkit.craftbukkit.v1_21_R3.help.SimpleHelpMap; +import org.bukkit.craftbukkit.v1_21_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R3.potion.CraftPotionEffectType; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToIntFunction; + // Mojang-Mapped reflection /** * NMS implementation for Minecraft 1.21.4 @@ -221,6 +204,7 @@ // @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) @RequireField(in = MinecraftServer.class, name = "fuelValues", ofType = FuelValues.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) public class NMS_1_21_R3 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; @@ -230,26 +214,25 @@ public class NMS_1_21_R3 extends NMS_Common { private static final MethodHandle minecraftServerSetSelected; private static final boolean vanillaCommandDispatcherFieldExists; private static final SafeVarHandle minecraftServerFuelValues; + private static final SafeVarHandle blockInputTag; // Derived from net.minecraft.commands.Commands; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + private final Supplier commandBuildContext; + + public NMS_1_21_R3(Supplier commandBuildContext) { + this.commandBuildContext = commandBuildContext; + } // Compute all var handles all in one go so we don't do this during main server // runtime static { - if (Bukkit.getServer() instanceof CraftServer server) { - COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), - server.getServer().getWorldData().getDataConfiguration().enabledFeatures()); - } else { - COMMAND_BUILD_CONTEXT = null; - } - helpMapTopics = SafeVarHandle.ofOrNull(SimpleHelpMap.class, "helpTopics", "helpTopics", Map.class); // For some reason, MethodHandles fails for this field, but Field works okay entitySelectorUsesSelector = CommandAPIHandler.getField(EntitySelector.class, "p", "usesSelector"); // itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "h", "dispatcher"); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodHandle setSelected; @@ -276,7 +259,7 @@ public class NMS_1_21_R3 extends NMS_Common { @Override protected CommandBuildContext getCommandBuildContext() { - return COMMAND_BUILD_CONTEXT; + return commandBuildContext.get(); } @Differs(from = "1.21.1", by = "New advancement argument implementation") @@ -287,12 +270,12 @@ public ArgumentType _ArgumentAdvancement() { @Override public ArgumentType _ArgumentChatComponent() { - return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); + return ComponentArgument.textComponent(commandBuildContext.get()); } @Override public final ArgumentType _ArgumentEnchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT); } @Differs(from = "1.21.1", by = "New recipe argument implementation") @@ -303,7 +286,7 @@ public ArgumentType _ArgumentRecipe() { @Override public final ArgumentType _ArgumentSyntheticBiome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); + return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME); } @Override @@ -317,8 +300,8 @@ public String[] compatibleVersions() { }; @Differs(from = "1.20.6", by = "ItemInput constructor uses a data components patch, instead of a data components map") - private static String serializeNMSItemStack(ItemStack is) { - return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(COMMAND_BUILD_CONTEXT); + private String serializeNMSItemStack(ItemStack is) { + return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext.get()); } @Override @@ -360,7 +343,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -383,7 +367,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -409,47 +394,32 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str throws CommandSyntaxException { return ResourceKeyArgument.getAdvancement(cmdCtx, key).toBukkit(); } - - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); + return new RegistryParser<>( + () -> { + Biome biome; + try { + biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); + } catch(IllegalArgumentException biomeNotFound) { + biome = null; + } + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); } @Override - public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException { - final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key() - .location(); - return switch (subType) { - case BIOME_BIOME -> { - Biome biome = null; - try { - biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); - } catch (IllegalArgumentException biomeNotFound) { - biome = null; - } - yield biome; + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(CraftRegistry.getMinecraftRegistry(), BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + blockEntitySnapshot.loadData(blockInputTag.get(input)); } - case BIOME_NAMESPACEDKEY -> (NamespacedKey) fromResourceLocation(resourceLocation); - default -> null; - }; - } - - @Override - public final BlockData getBlockState(CommandContext cmdCtx, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); + return snapshot; } @Override @@ -458,16 +428,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -483,8 +443,7 @@ public final Enchantment getEnchantment(CommandContext cmdCt } @Override - public final Object getEntitySelector(CommandContext cmdCtx, String str, - ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { // We override the rule whereby players need "minecraft.command.selector" and // have to have level 2 permissions in order to use entity selectors. We're @@ -497,60 +456,58 @@ public final Object getEntitySelector(CommandContext cmdCtx, // Shouldn't happen, CommandAPIHandler#getField makes it accessible } - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES: - try { - List result = new ArrayList<>(); - for (Entity entity : argument.findEntities(cmdCtx.getSource())) { - result.add(entity.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_ENTITIES_FOUND.create(); - } else { - yield result; - } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; - } - } - case ENTITYSELECTOR_MANY_PLAYERS: - try { - List result = new ArrayList<>(); - for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { - result.add(player.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_PLAYERS_FOUND.create(); - } else { - yield result; + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_PLAYERS_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; + }, + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_ENTITIES_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } } - case ENTITYSELECTOR_ONE_ENTITY: - yield argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(); - case ENTITYSELECTOR_ONE_PLAYER: - yield argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(); - default: - throw new IllegalArgumentException("Unexpected value: " + subType); - }; + ); } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); final Double lowBoxed = range.min().orElse(null); final Double highBoxed = range.max().orElse(null); - final double low = lowBoxed == null ? -Float.MAX_VALUE : lowBoxed; - final double high = highBoxed == null ? Float.MAX_VALUE : highBoxed; - return new FloatRange((float) low, (float) high); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); } @Override @@ -740,12 +697,11 @@ private ParticleData getParticleDataAsVibrationParticleOption(CommandContext< } @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return switch (subType) { - case POTION_EFFECT_POTION_EFFECT -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()); - case POTION_EFFECT_NAMESPACEDKEY -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); } @Differs(from = "1.21.1", by = "Uses ResourceKeyArgument instead of ResourceLocationArgument") @@ -804,7 +760,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_21_R3(css, sender, proxy)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -813,7 +769,7 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal if (callee == null) callee = caller; // Most parameters default to what is defined by the caller - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(caller)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); // Position and rotation may be overridden by the Location if (location != null) { @@ -844,22 +800,19 @@ public final SimpleCommandMap getSimpleCommandMap() { } @Override - public final Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { + public final RegistryParser getSound(CommandContext cmdCtx, String key) { final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); - return switch (subType) { - case SOUND_SOUND -> { - final Optional> soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); - if (soundEvent.isEmpty()) { - yield null; - } else { - yield CraftSound.minecraftToBukkit(soundEvent.get().value()); - } - } - case SOUND_NAMESPACEDKEY -> { - yield NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()); - } - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + return new RegistryParser<>( + () -> { + final Optional> soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); + if(soundEvent.isEmpty()) { + return null; + } else { + return CraftSound.minecraftToBukkit(soundEvent.get().value()); + } + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); } @Override @@ -936,7 +889,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -1066,7 +1019,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1083,7 +1036,7 @@ public final void reloadDataPacks() { @Override public Message generateMessageFromJson(String json) { // TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here - return Serializer.fromJson(json, COMMAND_BUILD_CONTEXT); + return Serializer.fromJson(json, commandBuildContext.get()); } @SuppressWarnings("unchecked") @@ -1098,45 +1051,12 @@ public T getMinecraftServer() { @Override public ArgumentType _ArgumentMobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT); } @Override public ArgumentType _ArgumentEntitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE); } - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - () -> { - SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); - helpMap.clear(); - helpMap.initializeGeneralTopics(); - helpMap.initializeCommands(); - }, - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R3.java index 70309584e..63f5fcfe3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R3.java @@ -19,7 +19,7 @@ public NativeProxyCommandSender_1_21_R3(CommandSourceStack css, CommandSender ca Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); - this.world = CommandAPIBukkit.get().getWorldForCSS(css); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/test/java/SafeReflect.java index 6ac91a8d9..082876cf9 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/test/java/SafeReflect.java @@ -18,19 +18,20 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -import java.util.Map; - -import org.bukkit.craftbukkit.v1_21_R3.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; import com.mojang.datafixers.util.Either; - import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.CustomFunctionManager; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.block.entity.FuelValues; import net.minecraft.world.level.gameevent.EntityPositionSource; +import org.bukkit.craftbukkit.v1_21_R3.help.SimpleHelpMap; + +import java.util.Map; // Spigot-Mapped reflection @RequireField(in = CustomFunctionManager.class, name = "h", ofType = CommandDispatcher.class) @@ -38,4 +39,5 @@ @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "e", ofType = Either.class) @RequireField(in = MinecraftServer.class, name = "aE", ofType = FuelValues.class) +@RequireField(in = ArgumentTileLocation.class, name = "c", ofType = NBTTagCompound.class) public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml index 36ed71d71..52199c8f1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml @@ -21,12 +21,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-1.21.5 - CommandAPI - Bukkit support for 1.21.5 + Bukkit support for 1.21.5 1.21.5-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java index 8869a4551..01fbbe61f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java @@ -20,73 +20,7 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -import dev.jorel.commandapi.wrappers.Rotation; -import net.minecraft.commands.arguments.ObjectiveArgument; -import net.minecraft.commands.arguments.TeamArgument; -import net.minecraft.commands.arguments.coordinates.RotationArgument; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Particle.DustOptions; -import org.bukkit.Particle.DustTransition; -import org.bukkit.Particle.Trail; -import org.bukkit.Registry; -import org.bukkit.Vibration; -import org.bukkit.Vibration.Destination; -import org.bukkit.Vibration.Destination.BlockDestination; -import org.bukkit.World; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_21_R4.CraftLootTable; -import org.bukkit.craftbukkit.v1_21_R4.CraftParticle; -import org.bukkit.craftbukkit.v1_21_R4.CraftServer; -import org.bukkit.craftbukkit.v1_21_R4.CraftSound; -import org.bukkit.craftbukkit.v1_21_R4.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R4.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R4.command.BukkitCommandWrapper; -import org.bukkit.craftbukkit.v1_21_R4.command.VanillaCommandWrapper; -import org.bukkit.craftbukkit.v1_21_R4.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_21_R4.help.CustomHelpTopic; -import org.bukkit.craftbukkit.v1_21_R4.help.SimpleHelpMap; -import org.bukkit.craftbukkit.v1_21_R4.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_21_R4.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.Recipe; - import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.Message; import com.mojang.brigadier.arguments.ArgumentType; @@ -97,15 +31,13 @@ import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; - import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; -import dev.jorel.commandapi.PaperCommandRegistration; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; -import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; @@ -113,19 +45,15 @@ import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -133,11 +61,10 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; @@ -145,12 +72,11 @@ import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; import net.minecraft.commands.arguments.item.ItemArgument; import net.minecraft.commands.arguments.item.ItemInput; @@ -159,7 +85,6 @@ import net.minecraft.commands.execution.ExecutionContext; import net.minecraft.commands.functions.CommandFunction; import net.minecraft.commands.functions.InstantiatedFunction; -import net.minecraft.commands.synchronization.ArgumentUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.particles.BlockParticleOption; @@ -183,7 +108,6 @@ import net.minecraft.server.MinecraftServer.ReloadableResources; import net.minecraft.server.ServerFunctionLibrary; import net.minecraft.server.ServerFunctionManager; -import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; @@ -203,14 +127,73 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.WorldDataConfiguration; import net.minecraft.world.level.block.entity.FuelValues; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; import net.minecraft.world.level.gameevent.BlockPositionSource; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.Particle.DustOptions; +import org.bukkit.Particle.DustTransition; +import org.bukkit.Particle.Trail; +import org.bukkit.Registry; +import org.bukkit.Sound; +import org.bukkit.Vibration; +import org.bukkit.Vibration.Destination; +import org.bukkit.Vibration.Destination.BlockDestination; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R4.CraftLootTable; +import org.bukkit.craftbukkit.v1_21_R4.CraftParticle; +import org.bukkit.craftbukkit.v1_21_R4.CraftRegistry; +import org.bukkit.craftbukkit.v1_21_R4.CraftServer; +import org.bukkit.craftbukkit.v1_21_R4.CraftSound; +import org.bukkit.craftbukkit.v1_21_R4.CraftWorld; +import org.bukkit.craftbukkit.v1_21_R4.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_21_R4.block.CraftBlockStates; +import org.bukkit.craftbukkit.v1_21_R4.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_21_R4.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R4.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_21_R4.help.CustomHelpTopic; +import org.bukkit.craftbukkit.v1_21_R4.help.SimpleHelpMap; +import org.bukkit.craftbukkit.v1_21_R4.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R4.potion.CraftPotionEffectType; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToIntFunction; + // Mojang-Mapped reflection /** * NMS implementation for Minecraft 1.21.5 @@ -221,6 +204,7 @@ // @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) @RequireField(in = MinecraftServer.class, name = "fuelValues", ofType = FuelValues.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) public class NMS_1_21_R4 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; @@ -230,26 +214,25 @@ public class NMS_1_21_R4 extends NMS_Common { private static final MethodHandle minecraftServerSetSelected; private static final boolean vanillaCommandDispatcherFieldExists; private static final SafeVarHandle minecraftServerFuelValues; + private static final SafeVarHandle blockInputTag; // Derived from net.minecraft.commands.Commands; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + private final Supplier commandBuildContext; + + public NMS_1_21_R4(Supplier commandBuildContext) { + this.commandBuildContext = commandBuildContext; + } // Compute all var handles all in one go so we don't do this during main server // runtime static { - if (Bukkit.getServer() instanceof CraftServer server) { - COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), - server.getServer().getWorldData().getDataConfiguration().enabledFeatures()); - } else { - COMMAND_BUILD_CONTEXT = null; - } - helpMapTopics = SafeVarHandle.ofOrNull(SimpleHelpMap.class, "helpTopics", "helpTopics", Map.class); // For some reason, MethodHandles fails for this field, but Field works okay entitySelectorUsesSelector = CommandAPIHandler.getField(EntitySelector.class, "p", "usesSelector"); // itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "h", "dispatcher"); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodHandle setSelected; @@ -276,7 +259,7 @@ public class NMS_1_21_R4 extends NMS_Common { @Override protected CommandBuildContext getCommandBuildContext() { - return COMMAND_BUILD_CONTEXT; + return commandBuildContext.get(); } @Override @@ -286,12 +269,12 @@ public ArgumentType _ArgumentAdvancement() { @Override public ArgumentType _ArgumentChatComponent() { - return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); + return ComponentArgument.textComponent(commandBuildContext.get()); } @Override public final ArgumentType _ArgumentEnchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT); } @Override @@ -301,7 +284,7 @@ public ArgumentType _ArgumentRecipe() { @Override public final ArgumentType _ArgumentSyntheticBiome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); + return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME); } @Override @@ -314,8 +297,8 @@ public String[] compatibleVersions() { return new String[] { "1.21.5" }; }; - private static String serializeNMSItemStack(ItemStack is) { - return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(COMMAND_BUILD_CONTEXT); + private String serializeNMSItemStack(ItemStack is) { + return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext.get()); } @Override @@ -357,7 +340,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -380,7 +364,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -405,48 +390,32 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str throws CommandSyntaxException { return ResourceKeyArgument.getAdvancement(cmdCtx, key).toBukkit(); } - - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Differs(from = "1.21.4", by = "Uses getResolvedComponent instead of getComponent") - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); // TODO: Check if this is correct + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); + return new RegistryParser<>( + () -> { + Biome biome; + try { + biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); + } catch(IllegalArgumentException biomeNotFound) { + biome = null; + } + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); } @Override - public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException { - final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key() - .location(); - return switch (subType) { - case BIOME_BIOME -> { - Biome biome = null; - try { - biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); - } catch (IllegalArgumentException biomeNotFound) { - biome = null; - } - yield biome; + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(CraftRegistry.getMinecraftRegistry(), BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + blockEntitySnapshot.loadData(blockInputTag.get(input)); } - case BIOME_NAMESPACEDKEY -> (NamespacedKey) fromResourceLocation(resourceLocation); - default -> null; - }; - } - - @Override - public final BlockData getBlockState(CommandContext cmdCtx, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); + return snapshot; } @Override @@ -455,16 +424,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public final BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -480,8 +439,7 @@ public final Enchantment getEnchantment(CommandContext cmdCt } @Override - public final Object getEntitySelector(CommandContext cmdCtx, String str, - ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { // We override the rule whereby players need "minecraft.command.selector" and // have to have level 2 permissions in order to use entity selectors. We're @@ -494,60 +452,58 @@ public final Object getEntitySelector(CommandContext cmdCtx, // Shouldn't happen, CommandAPIHandler#getField makes it accessible } - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES: - try { - List result = new ArrayList<>(); - for (Entity entity : argument.findEntities(cmdCtx.getSource())) { - result.add(entity.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_ENTITIES_FOUND.create(); - } else { - yield result; - } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; - } - } - case ENTITYSELECTOR_MANY_PLAYERS: - try { - List result = new ArrayList<>(); - for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { - result.add(player.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_PLAYERS_FOUND.create(); - } else { - yield result; + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_PLAYERS_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; + }, + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_ENTITIES_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } } - case ENTITYSELECTOR_ONE_ENTITY: - yield argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(); - case ENTITYSELECTOR_ONE_PLAYER: - yield argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(); - default: - throw new IllegalArgumentException("Unexpected value: " + subType); - }; + ); } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); final Double lowBoxed = range.min().orElse(null); final Double highBoxed = range.max().orElse(null); - final double low = lowBoxed == null ? -Float.MAX_VALUE : lowBoxed; - final double high = highBoxed == null ? Float.MAX_VALUE : highBoxed; - return new FloatRange((float) low, (float) high); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); } @Override @@ -736,12 +692,11 @@ private ParticleData getParticleDataAsVibrationParticleOption(CommandContext< } @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return switch (subType) { - case POTION_EFFECT_POTION_EFFECT -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()); - case POTION_EFFECT_NAMESPACEDKEY -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); } @Override @@ -799,7 +754,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_21_R4(css, sender, proxy)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -808,7 +763,7 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal if (callee == null) callee = caller; // Most parameters default to what is defined by the caller - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(caller)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); // Position and rotation may be overridden by the Location if (location != null) { @@ -839,22 +794,19 @@ public final SimpleCommandMap getSimpleCommandMap() { } @Override - public final Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { + public final RegistryParser getSound(CommandContext cmdCtx, String key) { final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); - return switch (subType) { - case SOUND_SOUND -> { - final Optional> soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); - if (soundEvent.isEmpty()) { - yield null; - } else { - yield CraftSound.minecraftToBukkit(soundEvent.get().value()); - } - } - case SOUND_NAMESPACEDKEY -> { - yield NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()); - } - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + return new RegistryParser<>( + () -> { + final Optional> soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); + if(soundEvent.isEmpty()) { + return null; + } else { + return CraftSound.minecraftToBukkit(soundEvent.get().value()); + } + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); } @Override @@ -930,7 +882,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -1060,7 +1012,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1077,7 +1029,7 @@ public final void reloadDataPacks() { @Override public Message generateMessageFromJson(String json) { // TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here - return Serializer.fromJson(json, COMMAND_BUILD_CONTEXT); + return Serializer.fromJson(json, commandBuildContext.get()); } @SuppressWarnings("unchecked") @@ -1092,45 +1044,11 @@ public T getMinecraftServer() { @Override public ArgumentType _ArgumentMobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT); } @Override public ArgumentType _ArgumentEntitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); - } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - () -> { - SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); - helpMap.clear(); - helpMap.initializeGeneralTopics(); - helpMap.initializeCommands(); - }, - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R4.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R4.java index ff4f8cd4f..49a907066 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R4.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R4.java @@ -19,7 +19,7 @@ public NativeProxyCommandSender_1_21_R4(CommandSourceStack css, CommandSender ca Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); - this.world = CommandAPIBukkit.get().getWorldForCSS(css); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/test/java/SafeReflect.java index f61cab759..806db107e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/test/java/SafeReflect.java @@ -18,19 +18,20 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -import java.util.Map; - -import org.bukkit.craftbukkit.v1_21_R4.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; import com.mojang.datafixers.util.Either; - import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.CustomFunctionManager; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.block.entity.FuelValues; import net.minecraft.world.level.gameevent.EntityPositionSource; +import org.bukkit.craftbukkit.v1_21_R4.help.SimpleHelpMap; + +import java.util.Map; // Spigot-Mapped reflection @RequireField(in = CustomFunctionManager.class, name = "h", ofType = CommandDispatcher.class) @@ -38,4 +39,5 @@ @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "e", ofType = Either.class) @RequireField(in = MinecraftServer.class, name = "aE", ofType = FuelValues.class) -public class SafeReflect {} \ No newline at end of file +@RequireField(in = ArgumentTileLocation.class, name = "c", ofType = NBTTagCompound.class) +public class SafeReflect {} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml index 5b611ece6..65710ab07 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml @@ -21,12 +21,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-1.21.6 - CommandAPI - Bukkit support for 1.21.6 + Bukkit support for 1.21.6 1.21.6-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java index eb5955349..8c7f2b5d2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java @@ -30,20 +30,18 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.SuggestionProvider; -import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.datafixers.util.Pair; import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.JsonOps; import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; -import dev.jorel.commandapi.PaperCommandRegistration; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; -import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; @@ -51,7 +49,7 @@ import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; @@ -60,11 +58,6 @@ import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -72,11 +65,9 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; @@ -86,6 +77,7 @@ import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockStateArgument; import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; @@ -97,6 +89,7 @@ import net.minecraft.commands.execution.ExecutionContext; import net.minecraft.commands.functions.CommandFunction; import net.minecraft.commands.functions.InstantiatedFunction; +import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; import net.minecraft.core.RegistryAccess; import net.minecraft.core.particles.BlockParticleOption; @@ -143,7 +136,6 @@ import net.minecraft.world.level.WorldDataConfiguration; import net.minecraft.world.level.block.entity.FuelValues; import net.minecraft.world.level.gameevent.BlockPositionSource; -import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; @@ -156,22 +148,26 @@ import org.bukkit.Particle.DustTransition; import org.bukkit.Particle.Trail; import org.bukkit.Registry; +import org.bukkit.Sound; import org.bukkit.Vibration; import org.bukkit.Vibration.Destination; import org.bukkit.Vibration.Destination.BlockDestination; import org.bukkit.World; import org.bukkit.advancement.Advancement; import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; import org.bukkit.craftbukkit.v1_21_R5.CraftLootTable; import org.bukkit.craftbukkit.v1_21_R5.CraftParticle; +import org.bukkit.craftbukkit.v1_21_R5.CraftRegistry; import org.bukkit.craftbukkit.v1_21_R5.CraftServer; import org.bukkit.craftbukkit.v1_21_R5.CraftSound; import org.bukkit.craftbukkit.v1_21_R5.CraftWorld; +import org.bukkit.craftbukkit.v1_21_R5.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_21_R5.block.CraftBlockStates; import org.bukkit.craftbukkit.v1_21_R5.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R5.command.BukkitCommandWrapper; import org.bukkit.craftbukkit.v1_21_R5.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.v1_21_R5.entity.CraftEntity; import org.bukkit.craftbukkit.v1_21_R5.help.CustomHelpTopic; @@ -182,6 +178,7 @@ import org.bukkit.entity.Player; import org.bukkit.help.HelpTopic; import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; @@ -202,6 +199,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.function.ToIntFunction; // Mojang-Mapped reflection @@ -215,6 +213,7 @@ // @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) @RequireField(in = MinecraftServer.class, name = "fuelValues", ofType = FuelValues.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) public class NMS_1_21_R5 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; @@ -224,26 +223,25 @@ public class NMS_1_21_R5 extends NMS_Common { private static final MethodHandle minecraftServerSetSelected; private static final boolean vanillaCommandDispatcherFieldExists; private static final SafeVarHandle minecraftServerFuelValues; + private static final SafeVarHandle blockInputTag; // Derived from net.minecraft.commands.Commands; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + private final Supplier commandBuildContext; + + public NMS_1_21_R5(Supplier commandBuildContext) { + this.commandBuildContext = commandBuildContext; + } // Compute all var handles all in one go so we don't do this during main server // runtime static { - if (Bukkit.getServer() instanceof CraftServer server) { - COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), - server.getServer().getWorldData().getDataConfiguration().enabledFeatures()); - } else { - COMMAND_BUILD_CONTEXT = null; - } - helpMapTopics = SafeVarHandle.ofOrNull(SimpleHelpMap.class, "helpTopics", "helpTopics", Map.class); // For some reason, MethodHandles fails for this field, but Field works okay entitySelectorUsesSelector = CommandAPIHandler.getField(EntitySelector.class, "p", "usesSelector"); // itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "h", "dispatcher"); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodHandle setSelected; @@ -269,7 +267,7 @@ public class NMS_1_21_R5 extends NMS_Common { } // Implementation taken from io.papermc.paper.adventure.WrapperAwareSerializer#deserialize(Component) - private String toJson(net.minecraft.network.chat.Component component) { + String toJson(net.minecraft.network.chat.Component component) { MinecraftServer server = this.getMinecraftServer(); RegistryAccess.Frozen access = server.registryAccess(); RegistryOps ops = access.createSerializationContext(JsonOps.INSTANCE); @@ -278,7 +276,7 @@ private String toJson(net.minecraft.network.chat.Component component) { return new Gson().toJson(element); } - private net.minecraft.network.chat.Component fromJson(String json) { + net.minecraft.network.chat.Component fromJson(String json) { Pair result = ComponentSerialization.CODEC.decode(JsonOps.INSTANCE, JsonParser.parseString(json)) .getOrThrow(s -> new RuntimeException("Failed to decode Component: " + json + "; " + s)); return result.getFirst(); @@ -286,7 +284,7 @@ private net.minecraft.network.chat.Component fromJson(String json) { @Override protected CommandBuildContext getCommandBuildContext() { - return COMMAND_BUILD_CONTEXT; + return commandBuildContext.get(); } @Override @@ -296,12 +294,12 @@ public ArgumentType _ArgumentAdvancement() { @Override public ArgumentType _ArgumentChatComponent() { - return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); + return ComponentArgument.textComponent(commandBuildContext.get()); } @Override public final ArgumentType _ArgumentEnchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT); } @Override @@ -311,7 +309,7 @@ public ArgumentType _ArgumentRecipe() { @Override public final ArgumentType _ArgumentSyntheticBiome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); + return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME); } @Override @@ -324,8 +322,8 @@ public String[] compatibleVersions() { return new String[]{"1.21.5"}; } - private static String serializeNMSItemStack(ItemStack is) { - return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(COMMAND_BUILD_CONTEXT); + private String serializeNMSItemStack(ItemStack is) { + return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext.get()); } @Override @@ -367,7 +365,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -390,7 +389,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -416,48 +416,31 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str return ResourceKeyArgument.getAdvancement(cmdCtx, key).toBukkit(); } - @Differs(from = "1.21.5", by = "#toJson is now implemented in this class") - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(this.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Differs(from = "1.21.5", by = "#toJson is now implemented in this class") - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson() - .deserialize(this.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key))); - } - @Override - public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException { - final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key() - .location(); - return switch (subType) { - case BIOME_BIOME -> { - Biome biome = null; + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); + return new RegistryParser<>( + () -> { + Biome biome; try { biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); - } catch (IllegalArgumentException biomeNotFound) { + } catch(IllegalArgumentException biomeNotFound) { biome = null; } - yield biome; - } - case BIOME_NAMESPACEDKEY -> (NamespacedKey) fromResourceLocation(resourceLocation); - default -> null; - }; + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); } @Override - public final BlockData getBlockState(CommandContext cmdCtx, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(CraftRegistry.getMinecraftRegistry(), BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + blockEntitySnapshot.loadData(blockInputTag.get(input)); + } + return snapshot; } @Override @@ -466,18 +449,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Differs(from = "1.21.5", by = "#toJson is now implemented in this class") - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(this.toJson(MessageArgument.getMessage(cmdCtx, key))); - } - - @Differs(from = "1.21.5", by = "#toJson is now implemented in this class") - @Override - public final BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(this.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key))); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -493,8 +464,7 @@ public final Enchantment getEnchantment(CommandContext cmdCt } @Override - public final Object getEntitySelector(CommandContext cmdCtx, String str, - ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { // We override the rule whereby players need "minecraft.command.selector" and // have to have level 2 permissions in order to use entity selectors. We're @@ -507,60 +477,58 @@ public final Object getEntitySelector(CommandContext cmdCtx, // Shouldn't happen, CommandAPIHandler#getField makes it accessible } - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES: + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { try { - List result = new ArrayList<>(); - for (Entity entity : argument.findEntities(cmdCtx.getSource())) { - result.add(entity.getBukkitEntity()); + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); } if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_ENTITIES_FOUND.create(); + throw EntityArgument.NO_PLAYERS_FOUND.create(); } else { - yield result; + return result; } } catch (CommandSyntaxException e) { if (allowEmpty) { - yield new ArrayList(); + return new ArrayList(); } else { throw e; } } - case ENTITYSELECTOR_MANY_PLAYERS: + }, + (allowEmpty) -> { try { - List result = new ArrayList<>(); - for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { - result.add(player.getBukkitEntity()); + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); } if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_PLAYERS_FOUND.create(); + throw EntityArgument.NO_ENTITIES_FOUND.create(); } else { - yield result; + return result; } } catch (CommandSyntaxException e) { if (allowEmpty) { - yield new ArrayList(); + return new ArrayList(); } else { throw e; } } - case ENTITYSELECTOR_ONE_ENTITY: - yield argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(); - case ENTITYSELECTOR_ONE_PLAYER: - yield argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(); - default: - throw new IllegalArgumentException("Unexpected value: " + subType); - }; + } + ); } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); final Double lowBoxed = range.min().orElse(null); final Double highBoxed = range.max().orElse(null); - final double low = lowBoxed == null ? -Float.MAX_VALUE : lowBoxed; - final double high = highBoxed == null ? Float.MAX_VALUE : highBoxed; - return new FloatRange((float) low, (float) high); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); } @Override @@ -749,13 +717,11 @@ private ParticleData getParticleDataAsVibrationParticleOption(CommandContext< } @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return switch (subType) { - case POTION_EFFECT_POTION_EFFECT -> - CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()); - case POTION_EFFECT_NAMESPACEDKEY -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); } @Override @@ -813,7 +779,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_21_R5(css, sender, proxy)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -822,7 +788,7 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal if (callee == null) callee = caller; // Most parameters default to what is defined by the caller - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(caller)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); // Position and rotation may be overridden by the Location if (location != null) { @@ -853,22 +819,19 @@ public final SimpleCommandMap getSimpleCommandMap() { } @Override - public final Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { + public final RegistryParser getSound(CommandContext cmdCtx, String key) { final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); - return switch (subType) { - case SOUND_SOUND -> { + return new RegistryParser<>( + () -> { final Optional> soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); - if (soundEvent.isEmpty()) { - yield null; + if(soundEvent.isEmpty()) { + return null; } else { - yield CraftSound.minecraftToBukkit(soundEvent.get().value()); + return CraftSound.minecraftToBukkit(soundEvent.get().value()); } - } - case SOUND_NAMESPACEDKEY -> { - yield NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()); - } - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); } @Differs(from = "1.21.5", by = "Suggestion providers are per command context, not globally defined") @@ -949,7 +912,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -1079,7 +1042,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1111,45 +1074,11 @@ public T getMinecraftServer() { @Override public ArgumentType _ArgumentMobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT); } @Override public ArgumentType _ArgumentEntitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); - } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - () -> { - SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); - helpMap.clear(); - helpMap.initializeGeneralTopics(); - helpMap.initializeCommands(); - }, - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R5.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R5.java index ad5307a1e..a49ba8a48 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R5.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R5.java @@ -19,7 +19,7 @@ public NativeProxyCommandSender_1_21_R5(CommandSourceStack css, CommandSender ca Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); - this.world = CommandAPIBukkit.get().getWorldForCSS(css); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/test/java/SafeReflect.java index e76fb1717..7cb9d1e00 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/test/java/SafeReflect.java @@ -20,6 +20,8 @@ *******************************************************************************/ import java.util.Map; +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; +import net.minecraft.nbt.NBTTagCompound; import org.bukkit.craftbukkit.v1_21_R5.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; @@ -38,4 +40,5 @@ @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "e", ofType = Either.class) @RequireField(in = MinecraftServer.class, name = "aE", ofType = FuelValues.class) +@RequireField(in = ArgumentTileLocation.class, name = "d", ofType = NBTTagCompound.class) public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml index f12352bb2..e1d1a69cf 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml @@ -21,17 +21,17 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-1.21 - CommandAPI - Bukkit support for 1.21 + Bukkit support for 1.21 1.21.1-R0.1-SNAPSHOT 1.21.1-R0.1-SNAPSHOT - 1.21-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java index 781b8ad19..3fa6e3cc8 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java @@ -20,69 +20,7 @@ *******************************************************************************/ package dev.jorel.commandapi.nms; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Field; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; - -import dev.jorel.commandapi.wrappers.Rotation; -import net.minecraft.commands.arguments.ObjectiveArgument; -import net.minecraft.commands.arguments.TeamArgument; -import net.minecraft.commands.arguments.coordinates.RotationArgument; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.Particle; -import org.bukkit.Particle.DustOptions; -import org.bukkit.Particle.DustTransition; -import org.bukkit.Registry; -import org.bukkit.Vibration; -import org.bukkit.Vibration.Destination; -import org.bukkit.Vibration.Destination.BlockDestination; -import org.bukkit.World; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_21_R1.CraftLootTable; -import org.bukkit.craftbukkit.v1_21_R1.CraftParticle; -import org.bukkit.craftbukkit.v1_21_R1.CraftServer; -import org.bukkit.craftbukkit.v1_21_R1.CraftSound; -import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R1.command.BukkitCommandWrapper; -import org.bukkit.craftbukkit.v1_21_R1.command.VanillaCommandWrapper; -import org.bukkit.craftbukkit.v1_21_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_21_R1.help.CustomHelpTopic; -import org.bukkit.craftbukkit.v1_21_R1.help.SimpleHelpMap; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_21_R1.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.Recipe; - import com.google.common.collect.ImmutableList; -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.Message; import com.mojang.brigadier.arguments.ArgumentType; @@ -93,15 +31,13 @@ import com.mojang.logging.LogUtils; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; - import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; -import dev.jorel.commandapi.CommandRegistrationStrategy; -import dev.jorel.commandapi.PaperCommandRegistration; import dev.jorel.commandapi.SafeVarHandle; -import dev.jorel.commandapi.SpigotCommandRegistration; -import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; @@ -109,19 +45,15 @@ import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; -import dev.jorel.commandapi.wrappers.FloatRange; +import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; import dev.jorel.commandapi.wrappers.Location2D; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.chat.ComponentSerializer; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.critereon.MinMaxBounds; import net.minecraft.commands.CommandBuildContext; @@ -129,23 +61,21 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.FunctionInstantiationException; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.ColorArgument; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.DimensionArgument; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.RangeArgument; import net.minecraft.commands.arguments.ResourceArgument; import net.minecraft.commands.arguments.ResourceLocationArgument; import net.minecraft.commands.arguments.ScoreHolderArgument; import net.minecraft.commands.arguments.ScoreboardSlotArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.Vec2Argument; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; import net.minecraft.commands.arguments.item.FunctionArgument; import net.minecraft.commands.arguments.item.ItemArgument; import net.minecraft.commands.arguments.item.ItemInput; @@ -154,7 +84,6 @@ import net.minecraft.commands.execution.ExecutionContext; import net.minecraft.commands.functions.CommandFunction; import net.minecraft.commands.functions.InstantiatedFunction; -import net.minecraft.commands.synchronization.ArgumentUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.BlockParticleOption; import net.minecraft.core.particles.ColorParticleOption; @@ -176,7 +105,6 @@ import net.minecraft.server.MinecraftServer.ReloadableResources; import net.minecraft.server.ServerFunctionLibrary; import net.minecraft.server.ServerFunctionManager; -import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.PackResources; import net.minecraft.server.packs.PackType; @@ -193,14 +121,69 @@ import net.minecraft.world.level.DataPackConfig; import net.minecraft.world.level.Level; import net.minecraft.world.level.WorldDataConfiguration; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; import net.minecraft.world.level.gameevent.BlockPositionSource; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.Particle.DustOptions; +import org.bukkit.Particle.DustTransition; +import org.bukkit.Registry; +import org.bukkit.Sound; +import org.bukkit.Vibration; +import org.bukkit.Vibration.Destination; +import org.bukkit.Vibration.Destination.BlockDestination; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R1.CraftLootTable; +import org.bukkit.craftbukkit.v1_21_R1.CraftParticle; +import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry; +import org.bukkit.craftbukkit.v1_21_R1.CraftServer; +import org.bukkit.craftbukkit.v1_21_R1.CraftSound; +import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_21_R1.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_21_R1.block.CraftBlockStates; +import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_21_R1.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_21_R1.help.CustomHelpTopic; +import org.bukkit.craftbukkit.v1_21_R1.help.SimpleHelpMap; +import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R1.potion.CraftPotionEffectType; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToIntFunction; + // Mojang-Mapped reflection /** * NMS implementation for Minecraft 1.21 and 1.21.1 @@ -210,6 +193,7 @@ @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) // @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) public class NMS_1_21_R1 extends NMS_Common { private static final SafeVarHandle> helpMapTopics; @@ -217,26 +201,25 @@ public class NMS_1_21_R1 extends NMS_Common { // private static final SafeVarHandle itemInput; private static final Field serverFunctionLibraryDispatcher; private static final boolean vanillaCommandDispatcherFieldExists; + private static final SafeVarHandle blockInputTag; // Derived from net.minecraft.commands.Commands; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + private final Supplier commandBuildContext; + + public NMS_1_21_R1(Supplier commandBuildContext) { + this.commandBuildContext = commandBuildContext; + } // Compute all var handles all in one go so we don't do this during main server // runtime static { - if (Bukkit.getServer() instanceof CraftServer server) { - COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), - server.getServer().getWorldData().getDataConfiguration().enabledFeatures()); - } else { - COMMAND_BUILD_CONTEXT = null; - } - helpMapTopics = SafeVarHandle.ofOrNull(SimpleHelpMap.class, "helpTopics", "helpTopics", Map.class); // For some reason, MethodHandles fails for this field, but Field works okay entitySelectorUsesSelector = CommandAPIHandler.getField(EntitySelector.class, "p", "usesSelector"); // itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "h", "dispatcher"); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); boolean fieldExists; try { @@ -251,7 +234,7 @@ public class NMS_1_21_R1 extends NMS_Common { @Override protected CommandBuildContext getCommandBuildContext() { - return COMMAND_BUILD_CONTEXT; + return commandBuildContext.get(); } @Override @@ -261,12 +244,12 @@ public ArgumentType _ArgumentAdvancement() { @Override public ArgumentType _ArgumentChatComponent() { - return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); + return ComponentArgument.textComponent(commandBuildContext.get()); } @Override public final ArgumentType _ArgumentEnchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT); } @Override @@ -276,7 +259,7 @@ public ArgumentType _ArgumentRecipe() { @Override public final ArgumentType _ArgumentSyntheticBiome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); + return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME); } @Override @@ -290,8 +273,8 @@ public String[] compatibleVersions() { }; @Differs(from = "1.20.6", by = "ItemInput constructor uses a data components patch, instead of a data components map") - private static String serializeNMSItemStack(ItemStack is) { - return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(COMMAND_BUILD_CONTEXT); + private String serializeNMSItemStack(ItemStack is) { + return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext.get()); } @Override @@ -332,7 +315,8 @@ private final int runCommandFunction(CommandFunction command CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); try { - final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); }); @@ -355,7 +339,8 @@ private final SimpleFunctionWrapper convertFunction(CommandFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, this.getBrigadierDispatcher()); + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); List cArr = instantiatedFunction.entries(); commands = new String[cArr.size()]; @@ -382,46 +367,30 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str } @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public final Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - // TODO: Figure out if an empty provider is suitable for this context - return GsonComponentSerializer.gson() - .deserialize(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); + return new RegistryParser<>( + () -> { + Biome biome; + try { + biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); + } catch(IllegalArgumentException biomeNotFound) { + biome = null; + } + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); } @Override - public final Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException { - final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key() - .location(); - return switch (subType) { - case BIOME_BIOME -> { - Biome biome = null; - try { - biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); - } catch (IllegalArgumentException biomeNotFound) { - biome = null; - } - yield biome; + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(CraftRegistry.getMinecraftRegistry(), BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + blockEntitySnapshot.loadData(blockInputTag.get(input)); } - case BIOME_NAMESPACEDKEY -> (NamespacedKey) fromResourceLocation(resourceLocation); - default -> null; - }; - } - - @Override - public final BlockData getBlockState(CommandContext cmdCtx, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cmdCtx, key).getState()); + return snapshot; } @Override @@ -430,16 +399,6 @@ public CommandSourceStack getBrigadierSourceFromCommandSender( return VanillaCommandWrapper.getListener(sender.getSource()); } - @Override - public final BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ComponentSerializer.parse(Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); - } - @Override public final World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { @@ -455,8 +414,7 @@ public final Enchantment getEnchantment(CommandContext cmdCt } @Override - public final Object getEntitySelector(CommandContext cmdCtx, String str, - ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { // We override the rule whereby players need "minecraft.command.selector" and // have to have level 2 permissions in order to use entity selectors. We're @@ -469,60 +427,58 @@ public final Object getEntitySelector(CommandContext cmdCtx, // Shouldn't happen, CommandAPIHandler#getField makes it accessible } - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES: - try { - List result = new ArrayList<>(); - for (Entity entity : argument.findEntities(cmdCtx.getSource())) { - result.add(entity.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_ENTITIES_FOUND.create(); - } else { - yield result; + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_PLAYERS_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; + }, + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_ENTITIES_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } } } - case ENTITYSELECTOR_MANY_PLAYERS: - try { - List result = new ArrayList<>(); - for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { - result.add(player.getBukkitEntity()); - } - if (result.isEmpty() && !allowEmpty) { - throw EntityArgument.NO_PLAYERS_FOUND.create(); - } else { - yield result; - } - } catch (CommandSyntaxException e) { - if (allowEmpty) { - yield new ArrayList(); - } else { - throw e; - } - } - case ENTITYSELECTOR_ONE_ENTITY: - yield argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(); - case ENTITYSELECTOR_ONE_PLAYER: - yield argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(); - default: - throw new IllegalArgumentException("Unexpected value: " + subType); - }; + ); } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); final Double lowBoxed = range.min().orElse(null); final Double highBoxed = range.max().orElse(null); - final double low = lowBoxed == null ? -Float.MAX_VALUE : lowBoxed; - final double high = highBoxed == null ? Float.MAX_VALUE : highBoxed; - return new FloatRange((float) low, (float) high); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); } @Override @@ -701,12 +657,11 @@ private ParticleData getParticleDataAsVibrationParticleOption(CommandContext< } @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - return switch (subType) { - case POTION_EFFECT_POTION_EFFECT -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()); - case POTION_EFFECT_NAMESPACEDKEY -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); } @Override @@ -764,7 +719,7 @@ public BukkitCommandSender getSenderForCommand(CommandC return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_21_R1(css, sender, proxy)); } else { - return wrapCommandSender(sender); + return CommandAPIBukkit.get().wrapCommandSender(sender); } } @@ -773,7 +728,7 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal if (callee == null) callee = caller; // Most parameters default to what is defined by the caller - CommandSourceStack css = getBrigadierSourceFromCommandSender(wrapCommandSender(caller)); + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); // Position and rotation may be overridden by the Location if (location != null) { @@ -804,22 +759,19 @@ public final SimpleCommandMap getSimpleCommandMap() { } @Override - public final Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { + public final RegistryParser getSound(CommandContext cmdCtx, String key) { final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); - return switch (subType) { - case SOUND_SOUND -> { - final SoundEvent soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); - if (soundEvent == null) { - yield null; - } else { - yield CraftSound.minecraftToBukkit(soundEvent); - } - } - case SOUND_NAMESPACEDKEY -> { - yield NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()); - } - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; + return new RegistryParser<>( + () -> { + final SoundEvent soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); + if(soundEvent == null) { + return null; + } else { + return CraftSound.minecraftToBukkit(soundEvent); + } + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); } @Override @@ -892,8 +844,7 @@ public final void reloadDataPacks() { // Update the ServerFunctionLibrary's command dispatcher with the new one try { - serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), - getBrigadierDispatcher()); + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), CommandAPIBukkit.get().getBrigadierDispatcher()); } catch (IllegalAccessException ignored) { // Shouldn't happen, CommandAPIHandler#getField makes it accessible } @@ -991,7 +942,7 @@ public final void reloadDataPacks() { // Register recipes again because reloading datapacks // removes all non-vanilla recipes - registerBukkitRecipesSafely(recipes); + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); CommandAPI.logNormal("Finished reloading datapacks"); } catch (Exception e) { @@ -1008,7 +959,7 @@ public final void reloadDataPacks() { @Override public Message generateMessageFromJson(String json) { // TODO: Same as #getAdventureChatComponent, figure out if an empty provider is suitable here - return Serializer.fromJson(json, COMMAND_BUILD_CONTEXT); + return Serializer.fromJson(json, commandBuildContext.get()); } @SuppressWarnings("unchecked") @@ -1023,45 +974,12 @@ public T getMinecraftServer() { @Override public ArgumentType _ArgumentMobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); + return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT); } @Override public ArgumentType _ArgumentEntitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE); } - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - this.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) getPaper().getCommandMap(), - () -> this.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(this.getMinecraftServer().vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - // This class is Paper-server specific, so we need to use paper's userdev plugin to - // access it directly. That might need gradle, but there might also be a maven version? - // https://discord.com/channels/289587909051416579/1121227200277004398/1246910745761812480 - Class bukkitCommandNode_bukkitBrigCommand; - try { - bukkitCommandNode_bukkitBrigCommand = Class.forName("io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Expected to find class", e); - } - return new PaperCommandRegistration<>( - () -> this.getMinecraftServer().getCommands().getDispatcher(), - () -> { - SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); - helpMap.clear(); - helpMap.initializeGeneralTopics(); - helpMap.initializeCommands(); - }, - node -> bukkitCommandNode_bukkitBrigCommand.isInstance(node.getCommand()) - ); - } - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R1.java index 4806adff8..e6dc4e229 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R1.java @@ -19,7 +19,7 @@ public NativeProxyCommandSender_1_21_R1(CommandSourceStack css, CommandSender ca Vec3 pos = css.getPosition(); Vec2 rot = css.getRotation(); - this.world = CommandAPIBukkit.get().getWorldForCSS(css); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/test/java/SafeReflect.java index 92bba1058..117ef76fe 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/test/java/SafeReflect.java @@ -18,21 +18,23 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ -import java.util.Map; - -import org.bukkit.craftbukkit.v1_21_R1.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; import com.mojang.datafixers.util.Either; - import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.CustomFunctionManager; import net.minecraft.world.level.gameevent.EntityPositionSource; +import org.bukkit.craftbukkit.v1_21_R1.help.SimpleHelpMap; + +import java.util.Map; // Spigot-Mapped reflection @RequireField(in = CustomFunctionManager.class, name = "h", ofType = CommandDispatcher.class) @RequireField(in = EntitySelector.class, name = "p", ofType = boolean.class) @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "e", ofType = Either.class) +@RequireField(in = ArgumentTileLocation.class, name = "c", ofType = NBTTagCompound.class) public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index dbcd56df1..f063c26df 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -19,12 +19,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-nms-common - CommandAPI - Bukkit support NMS common library + Bukkit support NMS common library 1.20.1-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java index 4b76e13c2..1d3f8f650 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java @@ -104,9 +104,8 @@ * NMS classes to maintain an error-free NMS_Common module that is applicable to all * versions. */ -public abstract class NMS_Common extends CommandAPIBukkit { - - public final NamespacedKey fromResourceLocation(ResourceLocation key) { +public abstract class NMS_Common implements NMS { + public NamespacedKey fromResourceLocation(ResourceLocation key) { return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); } @@ -315,14 +314,9 @@ public final Predicate getBlockPredicate(CommandContext cmdCtx, String key) { - return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); - } - - @Override - public final BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack css) { + public final BukkitCommandSender getCommandSenderFromCommandSource(Source css) { try { - return wrapCommandSender(css.getBukkitSender()); + return CommandAPIBukkit.get().wrapCommandSender(((CommandSourceStack) css).getBukkitSender()); } catch (UnsupportedOperationException e) { return null; } @@ -375,16 +369,6 @@ public final OfflinePlayer getOfflinePlayer(CommandContext c return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cmdCtx, key).iterator().next().getId()); } - @Override - public final Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(GameProfileArgument.getGameProfiles(cmdCtx, key).iterator().next().getId()); - if (target == null) { - throw GameProfileArgument.ERROR_UNKNOWN_PLAYER.create(); - } else { - return target; - } - } - @Override public final int getTime(CommandContext cmdCtx, String key) { return cmdCtx.getArgument(key, Integer.class); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/dependency-reduced-pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/dependency-reduced-pom.xml deleted file mode 100644 index c4270cdec..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/dependency-reduced-pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - commandapi-bukkit-nms - dev.jorel - 9.0.0 - - 4.0.0 - commandapi-bukkit-nms-dependency-mojang-mapped - - - - maven-shade-plugin - - - normal - package - - shade - - - true - true - - - - dev/jorel/commandapi/nms/* - - - - - - - - - maven-jar-plugin - - - empty-javadoc-jar - package - - jar - - - javadoc - ${basedir}/javadoc - - - - - - - diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml index 64b44c508..e414d6f3e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml @@ -19,12 +19,12 @@ commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-bukkit-nms-dependency - CommandAPI - Bukkit support Spigot-mapped NMS dependency + Bukkit support Spigot-mapped NMS dependency pom diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml index 3a127f204..36becebc6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml @@ -26,11 +26,11 @@ commandapi-bukkit dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-bukkit-nms - CommandAPI - Bukkit support NMS library + Bukkit support NMS library pom @@ -48,7 +48,6 @@ commandapi-bukkit-nms-dependency - commandapi-bukkit-nms-dependency-mojang-mapped diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml index 89a0992fb..de0e5a027 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml @@ -7,11 +7,11 @@ dev.jorel commandapi-bukkit - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-bukkit-plugin-common - CommandAPI - Bukkit support plugin common library + Bukkit support plugin common library diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/BukkitConfigurationAdapter.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/BukkitConfigurationAdapter.java index 75bab1923..a8c1065bb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/BukkitConfigurationAdapter.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/BukkitConfigurationAdapter.java @@ -109,11 +109,6 @@ public ConfigurationAdapter createNew() { return new BukkitConfigurationAdapter(new YamlConfiguration(), configFile); } - @Override - public DefaultBukkitConfig createDefaultConfig() { - return DefaultBukkitConfig.createDefault(); - } - @Override public ConfigurationAdapter loadFromFile() { YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java index bc2ac5838..735f22e75 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; +@SuppressWarnings("DuplicatedCode") public class DefaultBukkitConfig extends DefaultConfig { public static final CommentedConfigOption USE_LATEST_NMS_VERSION = new CommentedConfigOption<>( @@ -74,7 +75,7 @@ public class DefaultBukkitConfig extends DefaultConfig { private DefaultBukkitConfig() { } - public static DefaultBukkitConfig createDefault() { + public static DefaultBukkitConfig createDefaultPaperConfig() { Map> options = new LinkedHashMap<>(); options.put("verbose-outputs", VERBOSE_OUTPUTS); options.put("silent-logs", SILENT_LOGS); @@ -94,6 +95,25 @@ public static DefaultBukkitConfig createDefault() { return DefaultBukkitConfig.create(options, sections); } + public static DefaultBukkitConfig createDefaultSpigotConfig() { + Map> options = new LinkedHashMap<>(); + options.put("verbose-outputs", VERBOSE_OUTPUTS); + options.put("silent-logs", SILENT_LOGS); + options.put("messages.missing-executor-implementation", MISSING_EXECUTOR_IMPLEMENTATION); + options.put("create-dispatcher-json", CREATE_DISPATCHER_JSON); + options.put("use-latest-nms-version", USE_LATEST_NMS_VERSION); + options.put("be-lenient-for-minor-versions", BE_LENIENT_FOR_MINOR_VERSIONS); + options.put("skip-initial-datapack-reload", SKIP_RELOAD_DATAPACKS); + options.put("plugins-to-convert", PLUGINS_TO_CONVERT); + options.put("other-commands-to-convert", OTHER_COMMANDS_TO_CONVERT); + options.put("skip-sender-proxy", SKIP_SENDER_PROXY); + + Map sections = new LinkedHashMap<>(); + sections.put("messages", SECTION_MESSAGE); + + return DefaultBukkitConfig.create(options, sections); + } + public static DefaultBukkitConfig create(Map> options, Map sections) { DefaultBukkitConfig config = new DefaultBukkitConfig(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/javadoc/README.md b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/javadoc/README.md deleted file mode 100644 index 9e78f8c11..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/javadoc/README.md +++ /dev/null @@ -1 +0,0 @@ -# commandapi-bukkit-plugin-mojang-mapped diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/.gitignore b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/.gitignore deleted file mode 100644 index a87f02033..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.apt_generated/ -/.apt_generated_tests/ - -/dependency-reduced-pom.xml diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/javadoc/README.md b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/javadoc/README.md deleted file mode 100644 index 42aba932e..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/javadoc/README.md +++ /dev/null @@ -1 +0,0 @@ -# commandapi-bukkit-plugin diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/.gitignore b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/.gitignore deleted file mode 100644 index a87f02033..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.apt_generated/ -/.apt_generated_tests/ - -/dependency-reduced-pom.xml diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/javadoc/README.md b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/javadoc/README.md deleted file mode 100644 index 0cabf7a94..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/javadoc/README.md +++ /dev/null @@ -1 +0,0 @@ -# commandapi-bukkit-shade diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml deleted file mode 100644 index f2c90a536..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - commandapi-bukkit - dev.jorel - 10.2.0-SNAPSHOT - - - 4.0.0 - - commandapi-bukkit-shade - CommandAPI - Bukkit support Spigot-mapped shade library - - - - dev.jorel - commandapi-bukkit-core - ${project.version} - compile - - - dev.jorel - commandapi-bukkit-vh - ${project.version} - - - dev.jorel - commandapi-bukkit-nms-dependency - ${project.version} - pom - - - - - - - org.apache.maven.plugins - maven-shade-plugin - - - normal - package - - shade - - - true - true - - - - dev.jorel:commandapi-core - - dev/jorel/commandapi/CommandAPIVersionHandler** - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - empty-javadoc-jar - package - - jar - - - javadoc - ${basedir}/javadoc - - - - - - - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml index 0463b5f3e..f60906934 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml @@ -10,7 +10,7 @@ commandapi-bukkit-test-toolkit - CommandAPI - Bukkit support testing toolkit + Bukkit support testing toolkit 21 @@ -45,7 +45,7 @@ dev.jorel - commandapi-bukkit-core + commandapi-paper-core ${project.version} provided @@ -58,6 +58,13 @@ compile + + io.papermc.paper + paper-api + 1.20.6-R0.1-SNAPSHOT + provided + + com.mojang diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java index 5c520b8a2..ff7bf98ae 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java @@ -21,6 +21,7 @@ import org.bukkit.advancement.Advancement; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; import org.bukkit.enchantments.Enchantment; @@ -45,7 +46,7 @@ * An implementation of {@link CommandAPIBukkit} that is compatible with a MockBukkit testing environment. * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. */ -public class MockCommandAPIBukkit extends CommandAPIBukkit { +public class MockCommandAPIBukkit extends CommandAPIBukkit implements MockNMS { // Static instance private static MockCommandAPIBukkit instance; @@ -101,6 +102,10 @@ public void onLoad(CommandAPIConfig config) { super.onLoad(config); } + public static void onEnable() { + CommandAPI.onEnable(); + } + /** * @return The {@link CommandAPIHandlerSpy} object intercepting calls to {@link CommandAPIHandler} methods. */ @@ -108,6 +113,16 @@ public CommandAPIHandlerSpy getCommandAPIHandlerSpy() { return commandAPIHandlerSpy; } + @Override + public CommandMap getCommandMap() { + return Bukkit.getCommandMap(); + } + + @Override + public Platform activePlatform() { + return Platform.PAPER; + } + @Override public CommandRegistrationStrategy createCommandRegistrationStrategy() { return commandRegistrationStrategy; @@ -487,7 +502,7 @@ public EntityType getEntityType(CommandContext cmdCtx, String } @Override - public FloatRange getFloatRange(CommandContext cmdCtx, String key) { + public DoubleRange getFloatRange(CommandContext cmdCtx, String key) { throw new UnimplementedMethodException(); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java index 3120e1bc8..84229307e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java @@ -1,5 +1,6 @@ package dev.jorel.commandapi; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; import org.mockbukkit.mockbukkit.MockBukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -15,7 +16,7 @@ public class MockCommandAPIPlugin extends JavaPlugin { // Allow loading with settings, // Default to none if `MockBukkit.load(MockCommandAPIPlugin.class)` is used directly - private static Consumer configureSettings = null; + private static Consumer> configureSettings = null; /** * Loads the CommandAPI plugin using {@link MockBukkit#load(Class)}. @@ -29,18 +30,18 @@ public static MockCommandAPIPlugin load() { /** * Loads the CommandAPI plugin using {@link MockBukkit#load(Class)}. * - * @param configureSettings A {@link Consumer} that can configure the settings of the {@link CommandAPIBukkitConfig} + * @param configureSettings A {@link Consumer} that can configure the settings of the {@link dev.jorel.commandapi.CommandAPIPaperConfig} * before it is used to load the CommandAPI plugin. * @return The {@link MockCommandAPIPlugin} instance that was loaded. */ - public static MockCommandAPIPlugin load(Consumer configureSettings) { + public static MockCommandAPIPlugin load(Consumer> configureSettings) { MockCommandAPIPlugin.configureSettings = configureSettings; return MockBukkit.load(MockCommandAPIPlugin.class); } @Override public void onLoad() { - CommandAPIBukkitConfig config = new CommandAPIBukkitConfig(this); + CommandAPIPaperConfig config = new CommandAPIPaperConfig<>(this.getPluginMeta(), this); if (configureSettings != null) { configureSettings.accept(config); @@ -52,7 +53,7 @@ public void onLoad() { @Override public void onEnable() { - CommandAPI.onEnable(); + CommandAPIPaper.onEnable(this); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java new file mode 100644 index 000000000..4dc3f6dd3 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java @@ -0,0 +1,422 @@ +package dev.jorel.commandapi; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.Message; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import dev.jorel.commandapi.arguments.ArgumentSubType; +import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.commandsenders.AbstractCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.wrappers.DoubleRange; +import dev.jorel.commandapi.wrappers.FunctionWrapper; +import dev.jorel.commandapi.wrappers.IntegerRange; +import dev.jorel.commandapi.wrappers.Location2D; +import dev.jorel.commandapi.wrappers.MathOperation; +import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; +import dev.jorel.commandapi.wrappers.ScoreboardSlot; +import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.Axis; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.OfflinePlayer; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; +import org.bukkit.loot.LootTable; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.EnumSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.function.Function; +import java.util.function.Predicate; + +public interface MockNMS { + + /** + * @return Advancement argument (api:advancement) + */ + ArgumentType _ArgumentAdvancement(); + + /** + * @return Angle argument (minecraft:angle) + */ + ArgumentType _ArgumentAngle(); + + /** + * @return Axis argument (minecraft:swizzle) + */ + ArgumentType _ArgumentAxis(); + + /** + * @return Block predicate argument (minecraft:block_predicate) + */ + ArgumentType _ArgumentBlockPredicate(); + + /** + * @return Block state argument (minecraft:block_state) + */ + ArgumentType _ArgumentBlockState(); + + /** + * @return Chat argument (minecraft:message) + */ + ArgumentType _ArgumentChat(); + + /** + * @return Chat component argument (minecraft:component) + */ + ArgumentType _ArgumentChatComponent(); + + /** + * @return Chat color argument (minecraft:color) + */ + ArgumentType _ArgumentChatFormat(); + + /** + * @return Dimension argument (minecraft:dimension) + */ + ArgumentType _ArgumentDimension(); + + /** + * @return Enchantment argument (minecraft:item_enchantment) + */ + ArgumentType _ArgumentEnchantment(); + + /** + * @param subType one of {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_MANY_ENTITIES}, + * {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_MANY_PLAYERS}, + * {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_ONE_ENTITY} or + * {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_ONE_PLAYER} + * @return Entity selector argument (minecraft:entity) + */ + ArgumentType _ArgumentEntity(ArgumentSubType subType); + + /** + * @return Entity type argument (minecraft:entity_summon) + */ + ArgumentType _ArgumentEntitySummon(); + + /** + * @return Float range argument (minecraft:float_range) + */ + ArgumentType _ArgumentFloatRange(); + + /** + * @return Int range argument (minecraft:int_range) + */ + ArgumentType _ArgumentIntRange(); + + /** + * @return Item predicate argument (minecraft:item_predicate) + */ + ArgumentType _ArgumentItemPredicate(); + + /** + * @return Itemstack argument (minecraft:item_stack) + */ + ArgumentType _ArgumentItemStack(); + + /** + * @return Math operation argument (minecraft:operation) + */ + ArgumentType _ArgumentMathOperation(); + + /** + * @return Minecraft key argument (minecraft:resource_location) + */ + ArgumentType _ArgumentMinecraftKeyRegistered(); + + /** + * @return Potion effect argument (minecraft:mob_effect) + */ + ArgumentType _ArgumentMobEffect(); + + /** + * @return NBT compound tag argument (minecraft:nbt_compound_tag) + */ + ArgumentType _ArgumentNBTCompound(); + + /** + * @return Particle argument (minecraft:particle) + */ + ArgumentType _ArgumentParticle(); + + /** + * @return Position argument (minecraft:block_pos) + */ + ArgumentType _ArgumentPosition(); + + /** + * @return 2D position (column) argument (minecraft:column_pos) + */ + ArgumentType _ArgumentPosition2D(); + + /** + * @return Player argument (minecraft:game_profile) + */ + ArgumentType _ArgumentProfile(); + + /** + * @return Recipe argument (api:recipe) + */ + ArgumentType _ArgumentRecipe(); + + /** + * @return Rotation argument (minecraft:rotation) + */ + ArgumentType _ArgumentRotation(); + + /** + * @return Scoreboard objective criteria argument (minecraft:objective_criteria) + */ + ArgumentType _ArgumentScoreboardCriteria(); + + /** + * @return Scoreboard objective argument (minecraft:objective) + */ + ArgumentType _ArgumentScoreboardObjective(); + + /** + * @return Scoreboard slot argument (minecraft:scoreboard_slot) + */ + ArgumentType _ArgumentScoreboardSlot(); + + /** + * @return Scoreboard team argument (minecraft:team) + */ + ArgumentType _ArgumentScoreboardTeam(); + + /** + * @param subType one of {@link ArgumentSubType#SCOREHOLDER_MULTIPLE} or + * {@link ArgumentSubType#SCOREHOLDER_SINGLE} + * @return Scoreholder argument (minecraft:score_holder) + */ + ArgumentType _ArgumentScoreholder(ArgumentSubType subType); + + /** + * @return Function argument (minecraft:function) + */ + ArgumentType _ArgumentTag(); + + /** + * @return Time argument (minecraft:time) + */ + ArgumentType _ArgumentTime(); + + /** + * @return UUID argument (minecraft:uuid) + */ + ArgumentType _ArgumentUUID(); + + /** + * @return Location 2D argument (precise position) (minecraft:vec2) + */ + ArgumentType _ArgumentVec2(boolean centerPosition); + + /** + * @return Location argument (precise position) (minecraft:vec3) + */ + ArgumentType _ArgumentVec3(boolean centerPosition); + + /* + * Synthetic arguments - arguments that don't actually exist, but have + * version-specific implementations, so we can switch their implementation as + * needed. For example, the BiomeArgument is both a + * _ArgumentMinecraftKeyRegistered and a _ArgumentResourceOrTag, but we'll refer + * to it as an _ArgumentSyntheticBiome + */ + + ArgumentType _ArgumentSyntheticBiome(); + + /** + * A String array of Minecraft versions that this NMS implementation is + * compatible with. For example, ["1.14", "1.14.1", "1.14.2", "1.14.3"]. This + * can be found by opening a Minecraft jar file, viewing the version.json file + * and reading the object "name". + * + * @return A String array of compatible Minecraft versions + */ + String[] compatibleVersions(); + + String convert(ItemStack is); + + String convert(ParticleData particle); + + String convert(PotionEffectType potion); + + String convert(Sound sound); + + Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key); + + Component getAdventureChatComponent(CommandContext cmdCtx, String key); + + float getAngle(CommandContext cmdCtx, String key); + + EnumSet getAxis(CommandContext cmdCtx, String key); + + Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException; + + Predicate getBlockPredicate(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + BlockData getBlockState(CommandContext cmdCtx, String key); + + BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + ChatColor getChatColor(CommandContext cmdCtx, String key); + + BaseComponent[] getChatComponent(CommandContext cmdCtx, String key); + + World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException; // Throws exception in 1.19.3 + + Object getEntitySelector(CommandContext cmdCtx, String key, ArgumentSubType subType, boolean allowEmpty) + throws CommandSyntaxException; + + EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + DoubleRange getFloatRange(CommandContext cmdCtx, String key); + + FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + SimpleFunctionWrapper getFunction(NamespacedKey key); + + Set getFunctions(); + + IntegerRange getIntRange(CommandContext cmdCtx, String key); + + ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + Predicate getItemStackPredicate(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Location2D getLocation2DBlock(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException; + + Location getLocationPrecise(CommandContext cmdCtx, String str) + throws CommandSyntaxException; + + LootTable getLootTable(CommandContext cmdCtx, String key); + + MathOperation getMathOperation(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key); + + Object getNBTCompound(CommandContext cmdCtx, String key, + Function nbtContainerConstructor); + + Objective getObjective(CommandContext cmdCtx, String key) + throws IllegalArgumentException, CommandSyntaxException; + + String getObjectiveCriteria(CommandContext cmdCtx, String key); + + ParticleData getParticle(CommandContext cmdCtx, String key); + + Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) + throws CommandSyntaxException; + + Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + Rotation getRotation(CommandContext cmdCtx, String key); + + ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key); + + Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + String getScoreHolderSingle(CommandContext cmdCtx, String key) + throws CommandSyntaxException; + + Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + int getTime(CommandContext cmdCtx, String key); + + UUID getUUID(CommandContext cmdCtx, String key); + + World getWorldForCSS(CommandSource clw); + + /** + * Returns the Server's internal (OBC) CommandMap + * + * @return A SimpleCommandMap from the OBC server + */ + SimpleCommandMap getSimpleCommandMap(); + + Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType); + + /** + * Retrieve a specific NMS implemented SuggestionProvider + * + * @param provider The SuggestionProvider type to retrieve + * @return A SuggestionProvider that matches the SuggestionProviders input + */ + SuggestionProvider getSuggestionProvider(SuggestionProviders provider); + + SimpleFunctionWrapper[] getTag(NamespacedKey key); + + Set getTags(); + + /** + * Reloads the datapacks by using the updated the commandDispatcher tree + */ + void reloadDataPacks(); + + HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission); + + Map getHelpMap(); + + Message generateMessageFromJson(String json); + + BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); + + BukkitCommandSender getCommandSenderFromCommandSource(CommandSource css); + + CommandSource getBrigadierSourceFromCommandSender(AbstractCommandSender sender); + + void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException; + + T getMinecraftServer(); + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java index 1749f087a..2b468970e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java @@ -30,7 +30,7 @@ private void registerCommand(boolean offlinePlayer) { .withArguments( offlinePlayer ? new OfflinePlayerArgument("offline") : - new PlayerArgument("player") + new PlayerProfileArgument("player") ) .executes(DEFAULT_EXECUTOR) .register(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java index a289a5321..403bbf0a9 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -307,7 +307,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen Mockito.when(craftPlayerMock.getName()).thenReturn(name); Mockito.when(craftPlayerMock.getUniqueId()).thenReturn(uuid); Mockito.when(entityPlayerMock.getBukkitEntity()).thenReturn(craftPlayerMock); - Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(net.minecraft.network.chat.Component.literal(name)); // ChatArgument, AdventureChatArgument + Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(Component.literal(name)); // ChatArgument, AdventureChatArgument Mockito.when(entityPlayerMock.getType()).thenReturn((net.minecraft.world.entity.EntityType) net.minecraft.world.entity.EntityType.PLAYER); // EntitySelectorArgument players.add(entityPlayerMock); } @@ -630,7 +630,7 @@ public Player setupMockedCraftPlayer(String name) { // getName and getDisplayName are used when CommandSourceStack#withEntity is called - net.minecraft.network.chat.Component nameComponent = net.minecraft.network.chat.Component.literal(name); + Component nameComponent = Component.literal(name); Mockito.when(handle.getName()).thenReturn(nameComponent); Mockito.when(handle.getDisplayName()).thenReturn(nameComponent); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 141e0586c..64fda5185 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -316,7 +316,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen Mockito.when(craftPlayerMock.getName()).thenReturn(name); Mockito.when(craftPlayerMock.getUniqueId()).thenReturn(uuid); Mockito.when(entityPlayerMock.getBukkitEntity()).thenReturn(craftPlayerMock); - Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(net.minecraft.network.chat.Component.literal(name)); // ChatArgument, AdventureChatArgument + Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(Component.literal(name)); // ChatArgument, AdventureChatArgument Mockito.when(entityPlayerMock.getScoreboardName()).thenReturn(name); // ScoreHolderArgument Mockito.when(entityPlayerMock.getType()).thenReturn((net.minecraft.world.entity.EntityType) net.minecraft.world.entity.EntityType.PLAYER); // EntitySelectorArgument players.add(entityPlayerMock); @@ -643,7 +643,7 @@ public Player setupMockedCraftPlayer(String name) { // getName and getDisplayName are used when CommandSourceStack#withEntity is called - net.minecraft.network.chat.Component nameComponent = net.minecraft.network.chat.Component.literal(name); + Component nameComponent = Component.literal(name); Mockito.when(handle.getName()).thenReturn(nameComponent); Mockito.when(handle.getDisplayName()).thenReturn(nameComponent); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 566443b7e..86de13669 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -335,7 +335,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen Mockito.when(craftPlayerMock.getName()).thenReturn(name); Mockito.when(craftPlayerMock.getUniqueId()).thenReturn(uuid); Mockito.when(entityPlayerMock.getBukkitEntity()).thenReturn(craftPlayerMock); - Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(net.minecraft.network.chat.Component.literal(name)); // ChatArgument, AdventureChatArgument + Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(Component.literal(name)); // ChatArgument, AdventureChatArgument Mockito.when(entityPlayerMock.getScoreboardName()).thenReturn(name); // ScoreHolderArgument Mockito.when(entityPlayerMock.getType()).thenReturn((net.minecraft.world.entity.EntityType) net.minecraft.world.entity.EntityType.PLAYER); // EntitySelectorArgument players.add(entityPlayerMock); @@ -447,7 +447,7 @@ public String getNMSParticleNameFromBukkit(Particle particle) { // return BuiltInRegistries.PARTICLE_TYPE.getKey(CraftParticle.bukkitToMinecraft(particle)).toString(); // return particle.getKey().toString(); - Map particleMap = Map.ofEntries( + Map particleMap = Map.ofEntries( Map.entry(Particle.valueOf("EXPLOSION_NORMAL"), "poof"), Map.entry(Particle.valueOf("EXPLOSION_LARGE"), "explosion"), Map.entry(Particle.valueOf("EXPLOSION_HUGE"), "explosion_emitter"), @@ -772,7 +772,7 @@ public Player setupMockedCraftPlayer(String name) { // getName and getDisplayName are used when CommandSourceStack#withEntity is called - net.minecraft.network.chat.Component nameComponent = net.minecraft.network.chat.Component.literal(name); + Component nameComponent = Component.literal(name); Mockito.when(handle.getName()).thenReturn(nameComponent); Mockito.when(handle.getDisplayName()).thenReturn(nameComponent); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java index 88f307236..9268fab56 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java @@ -307,7 +307,7 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen Mockito.when(craftPlayerMock.getName()).thenReturn(name); Mockito.when(craftPlayerMock.getUniqueId()).thenReturn(uuid); Mockito.when(entityPlayerMock.getBukkitEntity()).thenReturn(craftPlayerMock); - Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(net.minecraft.network.chat.Component.literal(name)); // ChatArgument, AdventureChatArgument + Mockito.when(entityPlayerMock.getDisplayName()).thenReturn(Component.literal(name)); // ChatArgument, AdventureChatArgument Mockito.when(entityPlayerMock.getType()).thenReturn((net.minecraft.world.entity.EntityType) net.minecraft.world.entity.EntityType.PLAYER); // EntitySelectorArgument players.add(entityPlayerMock); } @@ -631,7 +631,7 @@ public Player setupMockedCraftPlayer(String name) { // getName and getDisplayName are used when CommandSourceStack#withEntity is called - net.minecraft.network.chat.Component nameComponent = net.minecraft.network.chat.Component.literal(name); + Component nameComponent = Component.literal(name); Mockito.when(handle.getName()).thenReturn(nameComponent); Mockito.when(handle.getDisplayName()).thenReturn(nameComponent); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockPlatform.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockPlatform.java index e5900ad3f..10b87f832 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockPlatform.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockPlatform.java @@ -245,9 +245,9 @@ public UnimplementedError() { public abstract org.bukkit.loot.LootTables[] getLootTables(); - public abstract org.bukkit.potion.PotionEffectType[] getPotionEffects(); + public abstract PotionEffectType[] getPotionEffects(); - public abstract org.bukkit.Sound[] getSounds(); + public abstract Sound[] getSounds(); public abstract org.bukkit.block.Biome[] getBiomes(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/.gitignore b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/.gitignore deleted file mode 100644 index 00d2ab71d..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/.apt_generated/ -/.apt_generated_tests/ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml deleted file mode 100644 index cb050deee..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - commandapi-bukkit - dev.jorel - 10.2.0-SNAPSHOT - - 4.0.0 - - commandapi-bukkit-vh - CommandAPI - Bukkit support version handler - - - - dev.jorel - commandapi-bukkit-nms-dependency - ${project.version} - pom - - - - - org.spigotmc - spigot - ${paper.version} - remapped-mojang - provided - - - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java deleted file mode 100644 index b75473c2c..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi; - -import dev.jorel.commandapi.exceptions.UnsupportedVersionException; -import dev.jorel.commandapi.nms.NMS_1_20_R1; -import dev.jorel.commandapi.nms.NMS_1_20_R2; -import dev.jorel.commandapi.nms.NMS_1_20_R3; -import dev.jorel.commandapi.nms.NMS_1_20_R4; -import dev.jorel.commandapi.nms.NMS_1_21_R1; -import dev.jorel.commandapi.nms.NMS_1_21_R2; -import dev.jorel.commandapi.nms.NMS_1_21_R3; -import dev.jorel.commandapi.nms.NMS_1_21_R4; -import dev.jorel.commandapi.nms.NMS_1_21_R5; -import org.bukkit.Bukkit; - -/** - * This file handles the NMS version to be loaded. The CommandAPIVersionHandler - * file within the commandapi-core module is NOT used at compile time. Instead, - * the commandapi-vh module is loaded instead, which doesn't use reflection to - * load NMS instances. - *

- * NMS classes implement {@code NMS}. The type - * CommandListenerWrapper isn't visible as in this Maven module (it's not - * included and in some cases, cannot be included because Maven will only select - * one version of a specific project (in this case, it'll only import one copy - * of Spigot, almost always the latest stable version (from 1.16.5)). In - * Eclipse, this can produce an error saying that a class cannot be resolved - * because it is indirectly referenced from required .class files So sidestep - * this, we introduce a second intermediary class NMSWrapper_VERSION which - * depends on CommandListenerWrapper and then our main NMS_VERSION class extends - * that. - */ -public abstract class CommandAPIVersionHandler { - - /** - * Returns an instance of the current running version's implementation of the Bukkit NMS. - * - * @return an instance of NMS which can run on the specified Minecraft version - */ - static LoadContext getPlatform() { - final String latestMajorVersion = "21"; // Change this for Minecraft's major update - - try { - if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) { - return new LoadContext(new NMS_1_21_R5(), () -> { - CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); - CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); - }); - } else { - final String version = Bukkit.getBukkitVersion().split("-")[0]; - CommandAPIPlatform platform = switch (version) { - case "1.20", "1.20.1" -> new NMS_1_20_R1(); - case "1.20.2" -> new NMS_1_20_R2(); - case "1.20.3", "1.20.4" -> new NMS_1_20_R3(); - case "1.20.5", "1.20.6" -> new NMS_1_20_R4(); - case "1.21", "1.21.1" -> new NMS_1_21_R1(); - case "1.21.2", "1.21.3" -> new NMS_1_21_R2(); - case "1.21.4" -> new NMS_1_21_R3(); - case "1.21.5" -> new NMS_1_21_R4(); - case "1.21.6" -> new NMS_1_21_R5(); - default -> null; - }; - if (platform != null) { - return new LoadContext(platform); - } - if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) { - final String currentMajorVersion = version.split("\\.")[1]; - if (latestMajorVersion.equals(currentMajorVersion)) { - return new LoadContext(new NMS_1_21_R5(), () -> { - CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation."); - CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); - }); - } - } - throw new UnsupportedVersionException(version); - } - } catch (Throwable error) { - // Something went sideways when trying to load a platform. This probably means we're shading the wrong mappings. - // Because this is an error we'll just rethrow this (instead of piping it into logError, which we can't really - // do anyway since the CommandAPILogger isn't loaded), but include some helpful(?) logging that might point - // users in the right direction - throw new IllegalStateException("The CommandAPI's NMS hook failed to load! This version of the CommandAPI is " + - (MojangMappedVersionHandler.isMojangMapped() ? "Mojang" : "Spigot") + "-mapped. Have you checked that " + - "you are using a CommandAPI version that matches the mappings that your plugin is using?", error); - } - } -} diff --git a/commandapi-platforms/commandapi-bukkit/pom.xml b/commandapi-platforms/commandapi-bukkit/pom.xml index 0dbb9efc7..a99832114 100644 --- a/commandapi-platforms/commandapi-bukkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/pom.xml @@ -7,11 +7,11 @@ commandapi-platforms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-bukkit - CommandAPI - Bukkit support + Bukkit support pom @@ -21,23 +21,14 @@ commandapi-bukkit-nms - - commandapi-bukkit-vh - commandapi-bukkit-mojang-mapped - commandapi-bukkit-plugin-common - - - commandapi-bukkit-plugin - commandapi-bukkit-shade - commandapi-bukkit-plugin-mojang-mapped - commandapi-bukkit-shade-mojang-mapped - - commandapi-bukkit-test-toolkit commandapi-bukkit-networking-plugin - - commandapi-bukkit-test + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml new file mode 100644 index 000000000..19e329d0b --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 11.0.0-SNAPSHOT + + + commandapi-paper-annotations + Paper Annotations + + + + papermc + https://repo.papermc.io/repository/maven-public + + + + + + dev.jorel + commandapi-annotations + ${project.version} + compile + + + dev.jorel + commandapi-paper-core + ${project.version} + + + com.google.auto.service + auto-service + ${auto-service.version} + provided + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + testCompile + + + + dev.jorel.commandapi.annotations.Annotations + + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java new file mode 100644 index 000000000..41415a8ec --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java @@ -0,0 +1,572 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi.annotations; + +import com.google.auto.service.AutoService; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.annotations.arguments.AAdvancementArgument; +import dev.jorel.commandapi.annotations.arguments.AAngleArgument; +import dev.jorel.commandapi.annotations.arguments.AAsyncPlayerProfileArgument; +import dev.jorel.commandapi.annotations.arguments.AAxisArgument; +import dev.jorel.commandapi.annotations.arguments.ABiomeArgument; +import dev.jorel.commandapi.annotations.arguments.ABlockPredicateArgument; +import dev.jorel.commandapi.annotations.arguments.ABlockStateArgument; +import dev.jorel.commandapi.annotations.arguments.ABooleanArgument; +import dev.jorel.commandapi.annotations.arguments.AChatArgument; +import dev.jorel.commandapi.annotations.arguments.AChatColorArgument; +import dev.jorel.commandapi.annotations.arguments.AChatComponentArgument; +import dev.jorel.commandapi.annotations.arguments.ADoubleArgument; +import dev.jorel.commandapi.annotations.arguments.AEnchantmentArgument; +import dev.jorel.commandapi.annotations.arguments.AEntitySelectorArgument; +import dev.jorel.commandapi.annotations.arguments.AEntityTypeArgument; +import dev.jorel.commandapi.annotations.arguments.AFloatArgument; +import dev.jorel.commandapi.annotations.arguments.ADoubleRangeArgument; +import dev.jorel.commandapi.annotations.arguments.AFunctionArgument; +import dev.jorel.commandapi.annotations.arguments.AGreedyStringArgument; +import dev.jorel.commandapi.annotations.arguments.AIntegerArgument; +import dev.jorel.commandapi.annotations.arguments.AIntegerRangeArgument; +import dev.jorel.commandapi.annotations.arguments.AItemStackArgument; +import dev.jorel.commandapi.annotations.arguments.AItemStackPredicateArgument; +import dev.jorel.commandapi.annotations.arguments.ALiteralArgument; +import dev.jorel.commandapi.annotations.arguments.ALocation2DArgument; +import dev.jorel.commandapi.annotations.arguments.ALocationArgument; +import dev.jorel.commandapi.annotations.arguments.ALongArgument; +import dev.jorel.commandapi.annotations.arguments.ALootTableArgument; +import dev.jorel.commandapi.annotations.arguments.AMathOperationArgument; +import dev.jorel.commandapi.annotations.arguments.AMultiLiteralArgument; +import dev.jorel.commandapi.annotations.arguments.ANBTCompoundArgument; +import dev.jorel.commandapi.annotations.arguments.ANamespacedKeyArgument; +import dev.jorel.commandapi.annotations.arguments.AObjectiveArgument; +import dev.jorel.commandapi.annotations.arguments.AObjectiveCriteriaArgument; +import dev.jorel.commandapi.annotations.arguments.AParticleArgument; +import dev.jorel.commandapi.annotations.arguments.APlayerProfileArgument; +import dev.jorel.commandapi.annotations.arguments.APotionEffectArgument; +import dev.jorel.commandapi.annotations.arguments.ARecipeArgument; +import dev.jorel.commandapi.annotations.arguments.ARotationArgument; +import dev.jorel.commandapi.annotations.arguments.AScoreHolderArgument; +import dev.jorel.commandapi.annotations.arguments.AScoreboardSlotArgument; +import dev.jorel.commandapi.annotations.arguments.ASoundArgument; +import dev.jorel.commandapi.annotations.arguments.AStringArgument; +import dev.jorel.commandapi.annotations.arguments.ATeamArgument; +import dev.jorel.commandapi.annotations.arguments.ATextArgument; +import dev.jorel.commandapi.annotations.arguments.ATimeArgument; +import dev.jorel.commandapi.annotations.arguments.AUUIDArgument; +import dev.jorel.commandapi.annotations.arguments.AWorldArgument; +import dev.jorel.commandapi.annotations.arguments.Primitive; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.ExecutableType; +import javax.tools.Diagnostic.Kind; +import javax.tools.JavaFileObject; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * The main annotation processor for annotation-based arguments + */ +@AutoService(Processor.class) +public class Annotations extends AbstractProcessor { + + private static final Class[] ARGUMENT_ANNOTATIONS = new Class[] { AAdvancementArgument.class, + AAngleArgument.class, AAxisArgument.class, AAsyncPlayerProfileArgument.class, ABiomeArgument.class, ABlockPredicateArgument.class, + ABlockStateArgument.class, ABooleanArgument.class, + AChatArgument.class, AChatColorArgument.class, AChatComponentArgument.class, ADoubleArgument.class, + AEnchantmentArgument.class, AEntitySelectorArgument.ManyEntities.class, AEntitySelectorArgument.ManyPlayers.class, + AEntitySelectorArgument.OneEntity.class, AEntitySelectorArgument.OnePlayer.class, AEntityTypeArgument.class, + AFloatArgument.class, ADoubleRangeArgument.class, AFunctionArgument.class, + AGreedyStringArgument.class, AIntegerArgument.class, AIntegerRangeArgument.class, AItemStackArgument.class, + AItemStackPredicateArgument.class, ALiteralArgument.class, ALocation2DArgument.class, + ALocationArgument.class, ALongArgument.class, ALootTableArgument.class, AMathOperationArgument.class, + AMultiLiteralArgument.class, ANamespacedKeyArgument.class, ANBTCompoundArgument.class, AObjectiveArgument.class, + AObjectiveCriteriaArgument.class, AParticleArgument.class, APlayerProfileArgument.class, + APotionEffectArgument.class, ARecipeArgument.class, ARotationArgument.class, AScoreboardSlotArgument.class, + AScoreHolderArgument.Single.class, AScoreHolderArgument.Multiple.class, ASoundArgument.class, AStringArgument.class, ATeamArgument.class, + ATextArgument.class, ATimeArgument.class, AUUIDArgument.class, AWorldArgument.class }; + + // List of stuff we can deal with + @Override + public Set getSupportedAnnotationTypes() { + return Stream + .concat(Arrays.stream(new Class[] { Alias.class, Command.class, Default.class, NeedsOp.class, + Permission.class, Subcommand.class, Help.class }), Arrays.stream(ARGUMENT_ANNOTATIONS)) + .map(Class::getCanonicalName).collect(Collectors.toSet()); + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + for (Element element : roundEnv.getElementsAnnotatedWith(Command.class)) { + try { + processCommand(element); + } catch (IOException e) { + e.printStackTrace(); + } + } + return true; + } + + // Indentation, because half of this file is actually just making stuff look nice + private String indent(int indent) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < indent; i++) { + builder.append(" "); + } + return builder.toString(); + } + + private String simpleFromQualified(String name) { + if(name == null) { + return null; + } + return name.split("\\.")[name.split("\\.").length - 1]; + } + + private SortedSet calculateImports(Element classElement) { + SortedSet imports = new TreeSet<>(); + + imports.add(CommandAPICommand.class.getCanonicalName()); + if(classElement.getAnnotation(NeedsOp.class) != null) { + imports.add(CommandPermission.class.getCanonicalName()); + } + for (Element methodElement : classElement.getEnclosedElements()) { + if (methodElement.getAnnotation(Subcommand.class) != null) { + imports.add(MultiLiteralArgument.class.getCanonicalName()); + } + if (methodElement.getAnnotation(NeedsOp.class) != null) { + imports.add(CommandPermission.class.getCanonicalName()); + } + + if(methodElement instanceof ExecutableElement method) { + for(VariableElement parameter : method.getParameters()) { + Annotation argument = getArgument(parameter); + if(argument != null) { + + if (argument instanceof ANBTCompoundArgument) { + // Get NBTCompoundArgument type from type mirror + imports.add(parameter.asType().toString()); + } else { + imports.addAll(Arrays.asList(getPrimitive(argument).value())); + } + + if(argument.annotationType().getEnclosingClass() == null) { + // Normal arguments + imports.add("dev.jorel.commandapi.arguments." + argument.annotationType().getSimpleName().substring(1)); + } else { + // Nested arguments, like EntitySelectorArgument + imports.add("dev.jorel.commandapi.arguments." + argument.annotationType().getEnclosingClass().getSimpleName().substring(1)); + } + + if(argument instanceof ALocationArgument || argument instanceof ALocation2DArgument) { + imports.add(LocationType.class.getCanonicalName()); + } + } + + } + } + } + + for(String import_ : new TreeSet<>(imports)) { + if(import_.contains("<")) { + imports.add(import_.substring(0, import_.indexOf("<"))); + imports.add(import_.substring(import_.indexOf("<") + 1, import_.indexOf(">"))); + } + } + + return imports; + } + + private void emitImports(PrintWriter out, Element classElement) { + String previousImport = ""; + for(String import_ : calculateImports(classElement)) { + // Separate different packages + if(previousImport.contains(".") && import_.contains(".") && + !previousImport.substring(0, previousImport.indexOf(".")).equals(import_.substring(0, import_.indexOf(".")))) { + out.println(); + } + // Don't import stuff like "String" + if(!import_.contains(".") || import_.contains("<")) { + continue; + } + + out.print("import "); + out.print(import_); + out.println(";"); + previousImport = import_; + } + out.println(); + } + + // (https://www.baeldung.com/java-annotation-processing-builder) + private void emitPackage(PrintWriter out, TypeElement commandClass) { + int lastDot = commandClass.getQualifiedName().toString().lastIndexOf('.'); + if (lastDot > 0) { + out.print("package "); + out.print(commandClass.getQualifiedName().toString().substring(0, lastDot)); + out.println(";"); + out.println(); + } + } + + private int emitSubcommand(PrintWriter out, Element methodElement, int indent) { + if (methodElement.getAnnotation(Subcommand.class) != null) { + out.println(indent(indent) + ".withArguments("); + indent++; + out.print(indent(indent) + "new MultiLiteralArgument(\"subcommand\", "); + + if(methodElement.getAnnotation(Subcommand.class).value().length == 0) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Invalid @Subcommand on " + methodElement.getSimpleName() + " - no subcommand name was found"); + } + + // @Subcommand (name) + out.print(Arrays.stream(methodElement.getAnnotation(Subcommand.class).value()) + .map(x -> "\"" + x + "\"").collect(Collectors.joining(", "))); + + out.println(")"); + indent++; + out.println(indent(indent) + ".setListed(false)"); + + // @NeedsOp + if (methodElement.getAnnotation(NeedsOp.class) != null) { + out.println(indent(indent) + ".withPermission(CommandPermission.OP)"); + } + + // @Permission + if (methodElement.getAnnotation(Permission.class) != null) { + out.print(indent(indent) + ".withPermission(\""); + out.print(methodElement.getAnnotation(Permission.class).value()); + out.println("\")"); + } + indent--; + indent--; + out.println(indent(indent) + ")"); + } + return indent; + } + + private Map emitArgumentsAndGenerateArgumentMapping(PrintWriter out, Element methodElement, int indent) throws IllegalArgumentException { + Map argumentMapping = new HashMap<>(); + + ExecutableElement executableMethodElement = (ExecutableElement) methodElement; + for(int i = 1; i < executableMethodElement.getParameters().size(); i++) { + VariableElement parameter = executableMethodElement.getParameters().get(i); + T argumentAnnotation = getArgument(parameter); + if (argumentAnnotation == null) { + processingEnv.getMessager().printMessage(Kind.ERROR, + "Parameter " + parameter.getSimpleName() + " in method " + + methodElement.getSimpleName() + + " does not have an argument annotation on it! "); + throw new IllegalArgumentException(); + } + + emitArgument(out, argumentAnnotation, parameter, indent); + + // Handle return types + Primitive primitive = getPrimitive(argumentAnnotation); + if (argumentAnnotation instanceof ANBTCompoundArgument) { + argumentMapping.put(i - 1, parameter.asType().toString()); + } else { + if(primitive.value().length == 1) { + argumentMapping.put(i - 1, primitive.value()[0]); + } + } + } + + return argumentMapping; + } + + private int emitExecutes(PrintWriter out, Map argumentMapping, ExecutableType methodType, TypeElement commandClass, Element methodElement, int indent) { + String[] firstParam = methodType.getParameterTypes().get(0).toString().split("\\."); + out.print(indent(indent)); + switch (firstParam[firstParam.length - 1]) { + case "Player" -> out.print(".executesPlayer"); + case "ConsoleCommandSender" -> out.print(".executesConsole"); + case "BlockCommandSender" -> out.print(".executesCommandBlock"); + case "ProxiedCommandSender" -> out.print(".executesProxy"); + case "NativeProxyCommandSender" -> out.print(".executesNative"); + case "Entity" -> out.print(".executesEntity"); + case "CommandSender" -> out.print(".executes"); + default -> out.print(".executes"); + } + + out.println("((sender, args) -> {"); + indent++; + out.print(indent(indent)); + + // Return int or void? + if (methodType.getReturnType().toString().equals("int")) { + out.print("return "); + } + + out.print(commandClass.getSimpleName()); + out.print("."); + out.print(methodElement.getSimpleName()); + out.print("(sender"); + + for(int i = 0; i < argumentMapping.size(); i++) { + String fromArgumentMap = argumentMapping.get(i); + out.print(", ("); + + if(fromArgumentMap.contains("<")) { + out.print(simpleFromQualified(fromArgumentMap.substring(0, fromArgumentMap.indexOf("<")))); + out.print("<"); + out.print(simpleFromQualified(fromArgumentMap.substring(fromArgumentMap.indexOf("<") + 1, fromArgumentMap.indexOf(">")))); + out.print(">"); + } else { + out.print(simpleFromQualified(fromArgumentMap)); + } + out.print(") args.get("); + out.print(i); + out.print(")"); + } + //populate stuff here + + out.println(");"); + indent--; + out.println(indent(indent) + "})"); + + return indent; + } + + private int emitClassDeclarationStart(PrintWriter out, TypeElement commandClass, int indent) { + out.println("// This class was automatically generated by the CommandAPI"); + out.print("public class "); + out.print(commandClass.getSimpleName() + "$Command"); + out.println(" {"); + out.println(); + indent++; + return indent; + } + + private void emitPermission(PrintWriter out, Element classElement, int indent) { + if (classElement.getAnnotation(Permission.class) != null) { + out.print(indent(indent) + ".withPermission(\""); + out.print(classElement.getAnnotation(Permission.class).value()); + out.println("\")"); + } + } + + private void emitAlias(PrintWriter out, Element classElement, int indent) { + if (classElement.getAnnotation(Alias.class) != null) { + out.print(indent(indent) + ".withAliases("); + out.print(Arrays.stream(classElement.getAnnotation(Alias.class).value()) + .map(x -> "\"" + x + "\"").collect(Collectors.joining(", "))); + out.println(")"); + } + } + + private void emitNeedsOp(PrintWriter out, Element classElement, int indent) { + if (classElement.getAnnotation(NeedsOp.class) != null) { + out.println(indent(indent) + ".withPermission(CommandPermission.OP)"); + } + } + + private void emitHelp(PrintWriter out, Element classElement, int indent) { + if (classElement.getAnnotation(Help.class) != null) { + Help helpAnnotation = classElement.getAnnotation(Help.class); + + if(helpAnnotation.shortDescription().isEmpty()) { + out.print(indent(indent) + ".withFullDescription(\""); + out.print(helpAnnotation.value()); + out.println("\")"); + } else { + out.print(indent(indent) + ".withHelp(\""); + out.print(helpAnnotation.shortDescription()); + out.print("\", \""); + out.print(helpAnnotation.value()); + out.println("\")"); + } + } + } + + private void processCommand(Element classElement) throws IOException { + TypeElement commandClass = (TypeElement) classElement; + JavaFileObject builderFile = processingEnv.getFiler().createSourceFile(commandClass.getQualifiedName() + "$Command"); + int indent = 0; + + try (PrintWriter out = new PrintWriter(builderFile.openWriter())) { + emitPackage(out, commandClass); // Package name + emitImports(out, classElement); // Imports + emitClassDeclarationStart(out, commandClass, indent); // Class declaration + + // Main registration method + out.println(indent(indent) + "@SuppressWarnings(\"unchecked\")"); + out.println(indent(indent) + "public static void register() {"); + out.println(); + indent++; + + for (Element methodElement : classElement.getEnclosedElements()) { + if (methodElement.getAnnotation(Default.class) != null + || methodElement.getAnnotation(Subcommand.class) != null) { + + ExecutableType methodType = (ExecutableType) methodElement.asType(); + if(!methodElement.getModifiers().contains(Modifier.STATIC)) { + processingEnv.getMessager().printMessage(Kind.ERROR, "Method " + methodElement.getSimpleName() + " must be static to be used as a command"); + } + + out.print(indent(indent) + "new CommandAPICommand(\""); + out.print(commandClass.getAnnotation(Command.class).value()); + out.println("\")"); + indent++; + + indent = emitSubcommand(out, methodElement, indent); // @Subcommand (Also handle @Alias for @Subcommand) + emitNeedsOp(out, classElement, indent); // @NeedsOp + emitPermission(out, classElement, indent); // @Permission + emitAlias(out, classElement, indent); // @Alias + emitHelp(out, classElement, indent); // @Help + + //Maps parameter index to argument's primitive type + Map argumentMapping = null; + try { + argumentMapping = emitArgumentsAndGenerateArgumentMapping(out, methodElement, indent); + } catch (IllegalArgumentException e) { + return; + } + + // .executes + indent = emitExecutes(out, argumentMapping, methodType, commandClass, methodElement, indent); + + // Register command + out.println(indent(indent) + ".register();"); + out.println(); + indent--; + } + } + out.println(indent(indent) + "}"); // register() + indent--; + out.println(); + out.println("}"); // $Command class + } + } + + private void emitArgument(PrintWriter out, T argumentAnnotation, VariableElement parameter, int indent) { + out.print(indent(indent) + ".withArguments(new "); + // We're assuming that the name of the argument MUST be "A" + the same name + if(argumentAnnotation.annotationType().getEnclosingClass() == null) { + // Normal arguments + out.print(argumentAnnotation.annotationType().getSimpleName().substring(1)); + } else { + // Nested arguments, like EntitySelectorArgument + out.print(argumentAnnotation.annotationType().getEnclosingClass().getSimpleName().substring(1)); + out.print("."); + out.print(argumentAnnotation.annotationType().getSimpleName()); + } + + // Node name + out.print("(\""); + out.print(parameter.getSimpleName()); + out.print("\""); + + // Handle parameters + // Number arguments + if(argumentAnnotation instanceof AIntegerArgument argument) { + out.print(", " + argument.min() + ", " + argument.max()); + } else if(argumentAnnotation instanceof ALongArgument argument) { + out.print(", " + argument.min() + "L, " + argument.max() + "L"); + } else if(argumentAnnotation instanceof AFloatArgument argument) { + out.print(", " + argument.min() + "F, " + argument.max() + "F"); + } else if(argumentAnnotation instanceof ADoubleArgument argument) { + out.print(", " + argument.min() + "D, " + argument.max() + "D"); + } + + // Non-number arguments + else if(argumentAnnotation instanceof ALocation2DArgument argument) { + out.print(", " + LocationType.class.getSimpleName() + "." + argument.value().toString()); + } else if(argumentAnnotation instanceof ALocationArgument argument) { + out.print(", " + LocationType.class.getSimpleName() + "." + argument.value().toString()); + } else if(argumentAnnotation instanceof AMultiLiteralArgument argument) { + out.print(", " + Arrays.stream(argument.value()).map(s -> "\"" + s + "\"").collect(Collectors.joining(", "))); + } else if(argumentAnnotation instanceof ALiteralArgument argument) { + out.print(", \""); + out.print(argument.value()); + out.print("\""); + } + + out.print(")"); + + if(argumentAnnotation instanceof ALiteralArgument) { + out.print(".setListed(true)"); + } + + out.println(")"); + } + + // Checks if an annotation mirror is an argument annotation + private boolean isArgument(AnnotationMirror mirror) { + final String mirrorName = mirror.getAnnotationType().toString(); + return Arrays.stream(ARGUMENT_ANNOTATIONS).map(Class::getCanonicalName).anyMatch(mirrorName::equals); + } + + // Get the Primitive annotation from an annotation + private Primitive getPrimitive(T annotation) { + return annotation.annotationType().getDeclaredAnnotation(Primitive.class); + } + + @SuppressWarnings("unchecked") + private T getArgument(VariableElement tMirror) { + for(AnnotationMirror mirror : tMirror.getAnnotationMirrors()) { + if(isArgument(mirror)) { + T argumentAnnotation = null; + String mirrorCanonicalName = mirror.getAnnotationType().toString(); + try { + argumentAnnotation = tMirror.getAnnotationsByType((Class) Class.forName(mirrorCanonicalName))[0]; + } catch (ClassNotFoundException e) { + // We might be in a nested class. Let's try accessing that + try { + // Replace final . with $ + mirrorCanonicalName = mirrorCanonicalName.substring(0, mirrorCanonicalName.lastIndexOf(".")) + "$" + mirrorCanonicalName.substring(mirrorCanonicalName.lastIndexOf(".") + 1); + argumentAnnotation = tMirror.getAnnotationsByType((Class) Class.forName(mirrorCanonicalName))[0]; + } catch (ClassNotFoundException e1) { + e1.printStackTrace(); + } + } + + return argumentAnnotation; + } + } + return null; + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncPlayerProfileArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncPlayerProfileArgument.java new file mode 100644 index 000000000..bb9563699 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncPlayerProfileArgument.java @@ -0,0 +1,15 @@ +package dev.jorel.commandapi.annotations.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation equivalent of the {@link dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument} + */ +@Primitive("java.util.concurrent.CompletableFuture>") +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.PARAMETER) +public @interface AAsyncPlayerProfileArgument { +} \ No newline at end of file diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java similarity index 90% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java index 862994ec4..5fbb2bc3e 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java @@ -25,13 +25,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import dev.jorel.commandapi.arguments.AdventureChatArgument; +import dev.jorel.commandapi.arguments.ChatArgument; /** - * Annotation equivalent of the {@link AdventureChatArgument} + * Annotation equivalent of the {@link ChatArgument} */ @Primitive("net.kyori.adventure.text.Component") @Retention(RetentionPolicy.SOURCE) @Target(ElementType.PARAMETER) -public @interface AAdventureChatArgument { +public @interface AChatArgument { } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java new file mode 100644 index 000000000..99fe26a25 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java @@ -0,0 +1,15 @@ +package dev.jorel.commandapi.annotations.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation equivalent of the {@link dev.jorel.commandapi.arguments.ChatColorArgument} + */ +@Primitive("net.kyori.adventure.text.format.Component") +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.PARAMETER) +public @interface AChatColorArgument { +} diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatComponentArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java similarity index 89% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatComponentArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java index 934ea89e8..5e87c0c8e 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAdventureChatComponentArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java @@ -25,13 +25,13 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import dev.jorel.commandapi.arguments.AdventureChatComponentArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; /** - * Annotation equivalent of the {@link AdventureChatComponentArgument} + * Annotation equivalent of the {@link ChatComponentArgument} */ @Primitive("net.kyori.adventure.text.Component") @Retention(RetentionPolicy.SOURCE) @Target(ElementType.PARAMETER) -public @interface AAdventureChatComponentArgument { +public @interface AChatComponentArgument { } diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AOfflinePlayerArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerProfileArgument.java similarity index 88% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AOfflinePlayerArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerProfileArgument.java index bb8913fee..e68e55df6 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AOfflinePlayerArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerProfileArgument.java @@ -25,13 +25,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import dev.jorel.commandapi.arguments.OfflinePlayerArgument; - /** - * Annotation equivalent of the {@link OfflinePlayerArgument} + * Annotation equivalent of the {@link dev.jorel.commandapi.arguments.PlayerProfileArgument} */ -@Primitive("org.bukkit.OfflinePlayer") +@Primitive("java.util.List") @Retention(RetentionPolicy.SOURCE) @Target(ElementType.PARAMETER) -public @interface AOfflinePlayerArgument { +public @interface APlayerProfileArgument { } diff --git a/commandapi-annotations/src/test/java/TeleportCommand.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/TeleportCommand.java similarity index 75% rename from commandapi-annotations/src/test/java/TeleportCommand.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/TeleportCommand.java index 45a454a12..99509d15e 100644 --- a/commandapi-annotations/src/test/java/TeleportCommand.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/TeleportCommand.java @@ -18,13 +18,17 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ +import com.destroystokyo.paper.profile.PlayerProfile; +import dev.jorel.commandapi.annotations.arguments.APlayerProfileArgument; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import dev.jorel.commandapi.annotations.Alias; import dev.jorel.commandapi.annotations.Command; import dev.jorel.commandapi.annotations.Subcommand; -import dev.jorel.commandapi.annotations.arguments.APlayerArgument; + +import java.util.List; /* ANCHOR: teleport_command */ @Command("teleport") @@ -34,10 +38,16 @@ public class TeleportCommand { /* ANCHOR: teleport_subcommand */ @Subcommand({"teleport", "tp"}) -public static void teleport(Player player, @APlayerArgument OfflinePlayer target) { - if(target.isOnline() && target instanceof Player onlineTarget) { - player.teleport(onlineTarget); - } +public static void teleport(Player player, @APlayerProfileArgument List target) { + for (PlayerProfile profile : target) { + if (profile.getId() == null) { + continue; + } + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(profile.getId()); + if (offlinePlayer.isOnline() && offlinePlayer instanceof Player onlineTarget) { + player.teleport(onlineTarget); + } + } } /* ANCHOR_END: teleport_subcommand */ diff --git a/commandapi-annotations/src/test/java/Test2Command.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/Test2Command.java similarity index 100% rename from commandapi-annotations/src/test/java/Test2Command.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/Test2Command.java diff --git a/commandapi-annotations/src/test/java/TestCommand.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/TestCommand.java similarity index 81% rename from commandapi-annotations/src/test/java/TestCommand.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/TestCommand.java index 894d2629a..603568010 100644 --- a/commandapi-annotations/src/test/java/TestCommand.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/TestCommand.java @@ -19,8 +19,12 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *******************************************************************************/ import java.util.HashMap; +import java.util.List; import java.util.Map; +import com.destroystokyo.paper.profile.PlayerProfile; +import dev.jorel.commandapi.annotations.arguments.APlayerProfileArgument; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -31,7 +35,6 @@ import dev.jorel.commandapi.annotations.Help; import dev.jorel.commandapi.annotations.Permission; import dev.jorel.commandapi.annotations.Subcommand; -import dev.jorel.commandapi.annotations.arguments.APlayerArgument; import dev.jorel.commandapi.annotations.arguments.AStringArgument; @Command("warp") @@ -63,9 +66,15 @@ public static void createWarp(Player player, @AStringArgument String warpName) { @Subcommand("create") @Permission("warps.create") - public static void tpWarp(CommandSender sender, @APlayerArgument OfflinePlayer target, @AStringArgument String warpName) { - if(target.isOnline() && target instanceof Player onlineTarget) { - onlineTarget.teleport(warps.get(warpName)); + public static void tpWarp(CommandSender sender, @APlayerProfileArgument List target, @AStringArgument String warpName) { + for (PlayerProfile profile : target) { + if (profile.getId() == null) { + continue; + } + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(profile.getId()); + if (offlinePlayer.isOnline() && offlinePlayer instanceof Player onlineTarget) { + onlineTarget.teleport(warps.get(warpName)); + } } } diff --git a/commandapi-annotations/src/test/java/WarpCommand.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/WarpCommand.java similarity index 100% rename from commandapi-annotations/src/test/java/WarpCommand.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/test/java/WarpCommand.java diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml new file mode 100644 index 000000000..40777943f --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 11.0.0-SNAPSHOT + + + commandapi-paper-core + Paper support core library + + + + minecraft-libraries + https://libraries.minecraft.net + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + + + + dev.jorel + commandapi-bukkit-core + ${project.version} + + + dev.jorel + commandapi-preprocessor + ${project.version} + provided + + + dev.folia + folia-api + ${paper.version} + provided + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + com.mojang + brigadier + 1.0.18 + provided + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -Xlint + + + dev.jorel.commandapi.preprocessor.Preprocessor + + + + + org.jacoco + jacoco-maven-plugin + + + + default-prepare-agent + + prepare-agent + + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java new file mode 100644 index 000000000..7d78f8d44 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -0,0 +1,276 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitEntity; +import dev.jorel.commandapi.commandsenders.BukkitFeedbackForwardingCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.commandsenders.BukkitProxiedCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; +import dev.jorel.commandapi.nms.BundledNMS; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; +import io.papermc.paper.event.server.ServerResourcesReloadedEvent; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; +import net.kyori.adventure.text.ComponentLike; +import net.kyori.adventure.text.logger.slf4j.ComponentLogger; +import org.bukkit.Bukkit; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.ProxiedCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +public class CommandAPIPaper extends CommandAPIBukkit { + + private static CommandAPIPaper paper; + + private boolean isPaperPresent = true; + private boolean isFoliaPresent = false; + private final Class feedbackForwardingCommandSender; + private final Class nullCommandSender; + + private CommandAPILogger bootstrapLogger; + + private LifecycleEventOwner lifecycleEventOwner; + private final BundledNMS nms; + + @SuppressWarnings("unchecked") + protected CommandAPIPaper() { + CommandAPIPaper.paper = this; + + VersionContext context = (VersionContext) CommandAPIVersionHandler.getVersion(); + context.context().run(); + this.nms = (BundledNMS) context.nms(); + super.nms = this.nms; + + Class tempFeedbackForwardingCommandSender = null; + Class tempNullCommandSender = null; + try { + tempFeedbackForwardingCommandSender = (Class) Class.forName("io.papermc.paper.commands.FeedbackForwardingSender"); + } catch (ClassNotFoundException e) { + // uhh... + } + try { + tempNullCommandSender = (Class) Class.forName("io.papermc.paper.brigadier.NullCommandSender"); + } catch (ClassNotFoundException e) { + // Uhh.. + } + + this.feedbackForwardingCommandSender = tempFeedbackForwardingCommandSender; + this.nullCommandSender = tempNullCommandSender; + } + + @SuppressWarnings("unchecked") + public static CommandAPIPaper getPaper() { + if (paper != null) { + return (CommandAPIPaper) paper; + } + throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + } + + public static InternalPaperConfig getConfiguration() { + return (InternalPaperConfig) CommandAPIBukkit.getConfiguration(); + } + + public LifecycleEventOwner getLifecycleEventOwner() { + return lifecycleEventOwner; + } + + private static void setInternalConfig(InternalPaperConfig config) { + CommandAPIBukkit.config = config; + } + + @Override + public BundledNMS getNMS() { + if (nms != null) { + return this.nms; + } + throw new IllegalStateException("Tried to access NMS instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + } + + @Override + public void onLoad(CommandAPIConfig config) { + if (config instanceof CommandAPIPaperConfig paperConfig) { + CommandAPIPaper.setInternalConfig(new InternalPaperConfig(paperConfig)); + this.lifecycleEventOwner = paperConfig.lifecycleEventOwner; + } else { + CommandAPI.logError("CommandAPIBukkit was loaded with non-Bukkit config!"); + CommandAPI.logError("Attempts to access Bukkit-specific config variables will fail!"); + } + super.onLoad(); + checkPaperDependencies(); + PaperCommandRegistration registration = (PaperCommandRegistration) CommandAPIBukkit.get().getCommandRegistrationStrategy(); + registration.registerLifecycleEvent(); + } + + /** + * Enables the CommandAPI. This should be placed at the start of your + * onEnable() method. + */ + @Override + public void onEnable() { + super.plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(getConfiguration().getPluginName()); + CommandAPIPaper.getPaper().lifecycleEventOwner = super.plugin; + + new Schedulers(paper.isFoliaPresent).scheduleSyncDelayed(plugin, () -> { + CommandAPIBukkit.get().getCommandRegistrationStrategy().runTasksAfterServerStart(); + if (paper.isFoliaPresent) { + CommandAPI.logNormal("Skipping initial datapack reloading because Folia was detected"); + } else { + if (!getConfiguration().skipReloadDatapacks()) { + CommandAPIBukkit.get().reloadDataPacks(); + } + } + CommandAPIBukkit.get().updateHelpForCommands(CommandAPI.getRegisteredCommands()); + }, 0L); + + super.stopCommandRegistrations(); + + // Basically just a check to ensure we're actually running Paper + if (paper.isPaperPresent) { + Bukkit.getServer().getPluginManager().registerEvents(new Listener() { + @EventHandler + public void onServerReloadResources(ServerResourcesReloadedEvent event) { + // This event is called after Paper is done with everything command related + // which means we can put commands back + CommandAPIBukkit.get().getCommandRegistrationStrategy().preReloadDataPacks(); + + // Normally, the reloadDataPacks() method is responsible for updating commands for + // online players. If, however, datapacks aren't supposed to be reloaded upon /minecraft:reload + // we have to do this manually here. This won't have any effect on Spigot and Paper version prior to + // paper-1.20.6-65 + if (!CommandAPIPaper.getConfiguration().shouldHookPaperReload()) { + for (Player player : Bukkit.getOnlinePlayers()) { + player.updateCommands(); + } + return; + } + CommandAPI.logNormal("/minecraft:reload detected. Reloading CommandAPI commands!"); + CommandAPIBukkit.get().reloadDataPacks(); + } + }, plugin); + CommandAPI.logNormal("Hooked into Paper ServerResourcesReloadedEvent"); + } else { + CommandAPI.logNormal("Did not hook into Paper ServerResourcesReloadedEvent while using commandapi-paper. Are you actually using Paper?"); + } + + PaperCommandRegistration registration = (PaperCommandRegistration) super.getCommandRegistrationStrategy(); + registration.registerLifecycleEvent(); + } + + private void checkPaperDependencies() { + try { + Class.forName("net.kyori.adventure.text.Component"); + CommandAPI.logNormal("Hooked into Adventure for AdventureChat/AdventureChatComponents"); + } catch (ClassNotFoundException e) { + if (CommandAPI.getConfiguration().hasVerboseOutput()) { + CommandAPI.logWarning("Could not hook into Adventure for AdventureChat/AdventureChatComponents"); + } + } + + isPaperPresent = false; + + try { + Class.forName("io.papermc.paper.event.server.ServerResourcesReloadedEvent"); + isPaperPresent = true; + CommandAPI.logNormal("Hooked into Paper for paper-specific API implementations"); + } catch (ClassNotFoundException e) { + isPaperPresent = false; + if (CommandAPI.getConfiguration().hasVerboseOutput()) { + CommandAPI.logWarning("Could not hook into Paper for /minecraft:reload. Consider upgrading to Paper: https://papermc.io/"); + } + } + + isFoliaPresent = false; + + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServerInitEvent"); + isFoliaPresent = true; + CommandAPI.logNormal("Hooked into Folia for folia-specific API implementations"); + CommandAPI.logNormal("Folia support is still in development. Please report any issues to the CommandAPI developers!"); + } catch (ClassNotFoundException e) { + isFoliaPresent = false; + } + } + + public CommandMap getCommandMap() { + return Bukkit.getCommandMap(); + } + + @Override + public Platform activePlatform() { + return Platform.PAPER; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return nms.createCommandRegistrationStrategy(); + } + + @Override + public BukkitCommandSender wrapCommandSender(CommandSender sender) { + if (sender instanceof BlockCommandSender block) { + return new BukkitBlockCommandSender(block); + } + if (sender instanceof ConsoleCommandSender console) { + return new BukkitConsoleCommandSender(console); + } + if (sender instanceof Player player) { + return new BukkitPlayer(player); + } + if (sender instanceof org.bukkit.entity.Entity entity) { + return new BukkitEntity(entity); + } + if (sender instanceof NativeProxyCommandSender nativeProxy) { + return new BukkitNativeProxyCommandSender(nativeProxy); + } + if (sender instanceof ProxiedCommandSender proxy) { + return new BukkitProxiedCommandSender(proxy); + } + if (sender instanceof RemoteConsoleCommandSender remote) { + return new BukkitRemoteConsoleCommandSender(remote); + } + if (this.feedbackForwardingCommandSender.isInstance(sender)) { + // We literally cannot type this at compile-time, so let's use a placeholder CommandSender instance + return new BukkitFeedbackForwardingCommandSender(this.feedbackForwardingCommandSender.cast(sender)); + } + if (this.nullCommandSender != null && this.nullCommandSender.isInstance(sender)) { + // Since this should only be during a function load or setting up + // help topics, this is just a placeholder to evade the exception. + return null; + } + throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender"); + } + + /** + * Forces a command to return a success value of 0 + * + * @param message Description of the error message, formatted as an adventure chat component + * @return a {@link WrapperCommandSyntaxException} that wraps Brigadier's + * {@link com.mojang.brigadier.exceptions.CommandSyntaxException} + */ + public static WrapperCommandSyntaxException failWithAdventureComponent(ComponentLike message) { + return CommandAPI.failWithMessage(BukkitTooltip.messageFromAdventureComponent(message)); + } + + @SuppressWarnings("ConstantValue") + @Override + public CommandAPILogger getLogger() { + if (Bukkit.getServer() != null) { + return super.getLogger(); + } + if (bootstrapLogger == null) { + bootstrapLogger = CommandAPILogger.fromSlf4jLogger(ComponentLogger.logger("CommandAPI")); + } + return bootstrapLogger; + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java new file mode 100644 index 000000000..a61baf2db --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java @@ -0,0 +1,55 @@ +package dev.jorel.commandapi; + +import io.papermc.paper.plugin.configuration.PluginMeta; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; + +@SuppressWarnings("UnstableApiUsage") +public class CommandAPIPaperConfig extends CommandAPIBukkitConfig> { + + PluginMeta pluginMeta; + LifecycleEventOwner lifecycleEventOwner; + boolean shouldHookPaperReload = false; + + /** + * Creates a new {@code CommandAPIPaperConfig} object + * + * @param pluginMeta the {@link io.papermc.paper.plugin.configuration.PluginMeta} of the plugin loading the CommandAPI + * @param lifecycleEventOwner a {@link io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner}. + * Can be a {@link org.bukkit.plugin.java.JavaPlugin} or a {@link io.papermc.paper.plugin.bootstrap.BootstrapContext} + */ + public CommandAPIPaperConfig(PluginMeta pluginMeta, T lifecycleEventOwner) { + super(pluginMeta.getName()); + this.pluginMeta = pluginMeta; + this.lifecycleEventOwner = lifecycleEventOwner; + } + + /** + * Sets whether the CommandAPI should skip its datapack reload step after the server + * has finished loading. This does not skip reloading of datapacks when invoked manually + * when {@link #shouldHookPaperReload(boolean)} is set. + * @param skip whether the CommandAPI should skip reloading datapacks when the server has finished loading + * @return this CommandAPIPaperConfig + */ + public CommandAPIPaperConfig skipReloadDatapacks(boolean skip) { + this.skipReloadDatapacks = skip; + return this; + } + + /** + * Sets the CommandAPI to hook into Paper's {@link io.papermc.paper.event.server.ServerResourcesReloadedEvent} when available + * if true. This helps CommandAPI commands to work in datapacks after {@code /minecraft:reload} + * is run. + * + * @param hooked whether the CommandAPI should hook into Paper's {@link io.papermc.paper.event.server.ServerResourcesReloadedEvent} + * @return this CommandAPIPaperConfig + */ + public CommandAPIPaperConfig shouldHookPaperReload(boolean hooked) { + this.shouldHookPaperReload = hooked; + return this; + } + + @Override + public CommandAPIPaperConfig instance() { + return this; + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java new file mode 100644 index 000000000..6c476b0b8 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java @@ -0,0 +1,36 @@ +package dev.jorel.commandapi; + +import io.papermc.paper.plugin.configuration.PluginMeta; +import net.kyori.adventure.text.logger.slf4j.ComponentLogger; + +@SuppressWarnings("UnstableApiUsage") +public class InternalPaperConfig extends InternalBukkitConfig { + + private final PluginMeta pluginMeta; + + // Whether to hook into paper's reload event to reload datapacks when /minecraft:reload is run + private final boolean shouldHookPaperReload; + + public InternalPaperConfig(CommandAPIPaperConfig config) { + super(config); + this.pluginMeta = config.pluginMeta; + this.shouldHookPaperReload = config.shouldHookPaperReload; + } + + /** + * @return The {@link PluginMeta} of the plugin loading the CommandAPI + */ + public PluginMeta getPluginMeta() { + return pluginMeta; + } + + /** + * @return Whether the CommandAPI should hook into Paper's {@link io.papermc.paper.event.server.ServerResourcesReloadedEvent} + * when available to perform the CommandAPI's custom datapack reload when {@code /minecraft:reload} + * is run. + */ + public boolean shouldHookPaperReload() { + return shouldHookPaperReload; + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java new file mode 100644 index 000000000..d47a4ddd3 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java @@ -0,0 +1,152 @@ +package dev.jorel.commandapi; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.mojang.brigadier.tree.ArgumentCommandNode; +import com.mojang.brigadier.tree.CommandNode; +import com.mojang.brigadier.tree.LiteralCommandNode; +import com.mojang.brigadier.tree.RootCommandNode; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; +import io.papermc.paper.plugin.bootstrap.BootstrapContext; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; +import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; +import org.bukkit.Bukkit; +import org.bukkit.help.HelpTopic; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +/** + * Handles logic for registering commands after Paper build 65, where https://github.com/PaperMC/Paper/pull/8235 + * changed a bunch of the behind-the-scenes logic. + */ +public class PaperCommandRegistration extends CommandRegistrationStrategy { + // References to necessary methods + private final Supplier> getBrigadierDispatcher; + private final Runnable reloadHelpTopics; + private final Predicate> isBukkitCommand; + + private final boolean[] lifecycleEventRegistered = new boolean[2]; + private final CommandDispatcher bootstrapDispatcher = new CommandDispatcher<>(); + private final CommandDispatcher pluginDispatcher = new CommandDispatcher<>(); + + public PaperCommandRegistration(Supplier> getBrigadierDispatcher, Runnable reloadHelpTopics, Predicate> isBukkitCommand) { + this.getBrigadierDispatcher = getBrigadierDispatcher; + this.reloadHelpTopics = reloadHelpTopics; + this.isBukkitCommand = isBukkitCommand; + } + + // Provide access to internal functions that may be useful to developers + + /** + * Checks if a Brigadier command node came from wrapping a Bukkit command + * + * @param node The CommandNode to check + * @return true if the CommandNode is being handled by Paper's BukkitCommandNode + */ + public boolean isBukkitCommand(CommandNode node) { + return isBukkitCommand.test(node); + } + + // Implement CommandRegistrationStrategy methods + @Override + public CommandDispatcher getBrigadierDispatcher() { + return getBrigadierDispatcher.get(); + } + + @Override + public void runTasksAfterServerStart() { + // Nothing to do + } + + @Override + public void postCommandRegistration(RegisteredCommand registeredCommand, LiteralCommandNode resultantNode, List> aliasNodes) { + // Nothing to do + } + + @Override + public LiteralCommandNode registerCommandNode(LiteralArgumentBuilder node, String namespace) { + LiteralCommandNode built = node.build(); + if (Bukkit.getServer() == null) { + bootstrapDispatcher.getRoot().addChild((CommandNode) built); + } else { + pluginDispatcher.getRoot().addChild((CommandNode) built); + } + return built; + } + + @Override + public void unregister(String commandName, boolean unregisterNamespaces, boolean unregisterBukkit) { + // Remove nodes from the dispatcher + removeBrigadierCommands(getBrigadierDispatcher().getRoot(), commandName, unregisterNamespaces, + // If we are unregistering a Bukkit command, ONLY unregister BukkitCommandNodes + // If we are unregistering a Vanilla command, DO NOT unregister BukkitCommandNodes + c -> !unregisterBukkit ^ isBukkitCommand.test(c)); + + // Update the dispatcher file + CommandAPIHandler.getInstance().writeDispatcherToFile(); + } + + @Override + public void preReloadDataPacks() { + reloadHelpTopics.run(); + CommandAPIBukkit.get().updateHelpForCommands(CommandAPI.getRegisteredCommands()); + } + + void registerLifecycleEvent() { + boolean bootstrap = Bukkit.getServer() == null; + if (bootstrap && !lifecycleEventRegistered[0]) { + BootstrapContext context = (BootstrapContext) CommandAPIPaper.getPaper().getLifecycleEventOwner(); + lifecycleEventRegistered[0] = true; + registerLifecycleEvent(context.getLifecycleManager(), bootstrapDispatcher); + return; + } + if (!bootstrap && !lifecycleEventRegistered[1]) { + JavaPlugin plugin = (JavaPlugin) CommandAPIPaper.getPaper().getLifecycleEventOwner(); + lifecycleEventRegistered[1] = true; + registerLifecycleEvent(plugin.getLifecycleManager(), pluginDispatcher); + } + } + + private void registerLifecycleEvent(LifecycleEventManager lifecycleEventManager, CommandDispatcher dispatcher) { + lifecycleEventManager.registerEventHandler(LifecycleEvents.COMMANDS, event -> { + for (CommandNode commandNode : dispatcher.getRoot().getChildren()) { + LiteralCommandNode node = (LiteralCommandNode) commandNode; + event.registrar().register(node, getDescription(node.getLiteral())); + } + }); + } + + private String getDescription(String commandName) { + String namespaceStripped; + if (commandName.contains(":")) { + namespaceStripped = commandName.split(":")[1]; + } else { + namespaceStripped = commandName; + } + for (RegisteredCommand command : CommandAPI.getRegisteredCommands()) { + if (command.commandName().equals(namespaceStripped) || Arrays.asList(command.aliases()).contains(namespaceStripped)) { + Object helpTopic = command.helpTopic().orElse(null); + if (helpTopic != null) { + return ((HelpTopic) helpTopic).getShortText(); + } else { + return command.shortDescription().orElse("A command by the " + CommandAPIBukkit.getConfiguration().getPluginName() + " plugin."); + } + } + } + return ""; + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Schedulers.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/Schedulers.java similarity index 77% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Schedulers.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/Schedulers.java index 28e00a54d..e324e8594 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Schedulers.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/Schedulers.java @@ -4,14 +4,14 @@ public class Schedulers { - private final PaperImplementations paperImplementations; + private final boolean isFoliaPresent; - public Schedulers(PaperImplementations paperImplementations) { - this.paperImplementations = paperImplementations; + public Schedulers(boolean isFoliaPresent) { + this.isFoliaPresent = isFoliaPresent; } public int scheduleSyncRepeatingTask(Plugin plugin, Runnable runnable, long delay, long period) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, task -> runnable.run(), delay <= 0 ? 1 : delay, period); return 1; } else { @@ -20,7 +20,7 @@ public int scheduleSyncRepeatingTask(Plugin plugin, Runnable runnable, long dela } public void cancelTask(Plugin plugin, int id) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getGlobalRegionScheduler().cancelTasks(plugin); } else { plugin.getServer().getScheduler().cancelTask(id); @@ -28,7 +28,7 @@ public void cancelTask(Plugin plugin, int id) { } public void scheduleSync(Plugin plugin, Runnable runnable) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getGlobalRegionScheduler().execute(plugin, runnable); } else { plugin.getServer().getScheduler().runTask(plugin, runnable); @@ -36,7 +36,7 @@ public void scheduleSync(Plugin plugin, Runnable runnable) { } public void scheduleSyncDelayed(Plugin plugin, Runnable runnable, long delay) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin, task -> runnable.run(), delay <= 0 ? 1 : delay); } else { plugin.getServer().getScheduler().runTaskLater(plugin, runnable, delay); @@ -44,7 +44,7 @@ public void scheduleSyncDelayed(Plugin plugin, Runnable runnable, long delay) { } public void scheduleAsync(Plugin plugin, Runnable runnable) { - if (paperImplementations.isFoliaPresent()) { + if (isFoliaPresent) { plugin.getServer().getAsyncScheduler().runNow(plugin, task -> runnable.run()); } else { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, runnable); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java new file mode 100644 index 000000000..98e5527c0 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java @@ -0,0 +1,11 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.nms.BundledNMS; + +public record VersionContext(BundledNMS nms, Runnable context) { + + public VersionContext(BundledNMS nms) { + this(nms, () -> {}); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/AsyncPlayerProfileArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/AsyncPlayerProfileArgument.java new file mode 100644 index 000000000..4a3961571 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/AsyncPlayerProfileArgument.java @@ -0,0 +1,51 @@ +package dev.jorel.commandapi.arguments; + +import com.destroystokyo.paper.profile.PlayerProfile; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.executors.CommandArguments; +import org.bukkit.OfflinePlayer; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +/** + * An argument that represents a list of the Paper PlayerProfile object with asynchronous support. + * + * @since 11.0.0 + */ +public class AsyncPlayerProfileArgument extends SafeOverrideableArgument>, PlayerProfile> { + + /** + * A PlayerProfile argument. Returns a {@link List} + * + * @param nodeName the name of the node for this argument + */ + public AsyncPlayerProfileArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentProfile(), PlayerProfile::getName); + } + + @SuppressWarnings("unchecked") + @Override + public Class>> getPrimitiveType() { + return (Class>>) (Class) CompletableFuture.class; + } + + @Override + public CommandAPIArgumentType getArgumentType() { + return CommandAPIArgumentType.ASYNC_OFFLINE_PLAYER; + } + + @Override + public CompletableFuture> parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) { + return CompletableFuture.supplyAsync(() -> { + try { + return CommandAPIPaper.getPaper().getNMS().getProfile(cmdCtx, key); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } + }); + } +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java similarity index 74% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java index a28cd6b81..8b99fd9ee 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java @@ -22,10 +22,11 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; - import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.exceptions.PaperAdventureNotFoundException; import dev.jorel.commandapi.executors.CommandArguments; +import net.kyori.adventure.chat.SignedMessage; import net.kyori.adventure.text.Component; /** @@ -33,9 +34,9 @@ * * @since 5.10 * - * @apiNote Returns a {@link Component} object + * @apiNote Returns a {@link net.kyori.adventure.chat.SignedMessage} object */ -public class AdventureChatArgument extends Argument implements GreedyArgument { +public class ChatArgument extends Argument implements GreedyArgument { /** * Constructs a Chat argument with a given node name. Represents fancy greedy @@ -43,19 +44,19 @@ public class AdventureChatArgument extends Argument implements Greedy * * @param nodeName the name of the node for argument */ - public AdventureChatArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentChat()); + public ChatArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChat()); try { - Class.forName("net.kyori.adventure.text.Component"); + Class.forName("net.kyori.adventure.chat.SignedMessage"); } catch (ClassNotFoundException e) { throw new PaperAdventureNotFoundException(this.getClass()); } } @Override - public Class getPrimitiveType() { - return Component.class; + public Class getPrimitiveType() { + return SignedMessage.class; } @Override @@ -64,7 +65,7 @@ public CommandAPIArgumentType getArgumentType() { } @Override - public Component parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAdventureChat(cmdCtx, key); + public SignedMessage parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { + return CommandAPIPaper.getPaper().getNMS().getChat(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatColorArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java similarity index 87% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatColorArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java index 3a2a6abec..91cbaf414 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatColorArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java @@ -20,6 +20,7 @@ *******************************************************************************/ package dev.jorel.commandapi.arguments; +import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.exceptions.PaperAdventureNotFoundException; import org.bukkit.ChatColor; @@ -37,7 +38,7 @@ * * @apiNote Returns a {@link ChatColor} object */ -public class AdventureChatColorArgument extends SafeOverrideableArgument { +public class ChatColorArgument extends SafeOverrideableArgument { /** * Constructs a ChatColor argument with a given node name. Represents a color or @@ -45,8 +46,8 @@ public class AdventureChatColorArgument extends SafeOverrideableArgument NamedTextColor parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAdventureChatColor(cmdCtx, key); + return CommandAPIPaper.getPaper().getNMS().getChatColor(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatComponentArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java similarity index 88% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatComponentArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java index 389e41f29..c16eb5b9a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/AdventureChatComponentArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java @@ -23,6 +23,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.exceptions.PaperAdventureNotFoundException; import dev.jorel.commandapi.executors.CommandArguments; import net.kyori.adventure.text.Component; @@ -33,15 +34,15 @@ * @since 5.10 * @apiNote Returns a {@link Component} object */ -public class AdventureChatComponentArgument extends Argument { +public class ChatComponentArgument extends Argument { /** * Constructs a ChatComponent argument with a given node name. Represents raw JSON text, used in Book MetaData, Chat and other various areas of Minecraft * @see Raw JSON text * @param nodeName the name of the node for argument */ - public AdventureChatComponentArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentChatComponent()); + public ChatComponentArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChatComponent()); try { Class.forName("net.kyori.adventure.text.Component"); @@ -62,6 +63,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public Component parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getAdventureChatComponent(cmdCtx, key); + return CommandAPIPaper.getPaper().getNMS().getChatComponent(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java new file mode 100644 index 000000000..474502307 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java @@ -0,0 +1,354 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi.arguments; + +import com.mojang.brigadier.LiteralMessage; +import com.mojang.brigadier.Message; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import dev.jorel.commandapi.BukkitTooltip; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIHandler; +import dev.jorel.commandapi.executors.CommandArguments; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.bukkit.command.CommandSender; + +import java.io.Serializable; + +/** + * An argument that represents any custom object + * + * @param the return type of this custom argument when it is used + * @param the return type of the underlying base argument {@code base}. For + * example, this would be {@code Integer} for an + * {@link IntegerArgument} + * + * @since 2.0 + * @apiNote Returns a {@link T} object + */ +public class CustomArgument extends Argument { + + private final CustomArgumentInfoParser infoParser; + private final Argument base; + + private static final String INPUT = "%input%"; + private static final String FULL_INPUT = "%finput%"; + + /** + * Creates a CustomArgument with a valid parser, with an underlying base + * argument as its parsing implementation. + * + * @param base the base argument to use for this custom argument. This base + * argument will represent the parsing implementation for client + * side and server side parsing. This base argument cannot be a + * {@link LiteralArgument} or {@link MultiLiteralArgument} + * @param parser A {@link CustomArgumentInfo} parser object which includes + * information such as the command sender, previously declared + * arguments and current input. This parser should return an + * object of your choice. + *

+ * {@code } the return type of this custom argument when + * it is used
+ * {@code } the return type of the underlying base + * argument {@code base}. For example, this would be + * {@code Integer} for an {@link IntegerArgument} + *

+ */ + public CustomArgument(Argument base, CustomArgumentInfoParser parser) { + super(base.getNodeName(), base.getRawType()); + if (base instanceof LiteralArgument || base instanceof MultiLiteralArgument) { + throw new IllegalArgumentException(base.getClass().getSimpleName() + " is not a suitable base argument type for a CustomArgument"); + } + this.base = base; + this.infoParser = parser; + } + + @Override + public Class getPrimitiveType() { + return null; + } + + @Override + public CommandAPIArgumentType getArgumentType() { + return CommandAPIArgumentType.CUSTOM; + } + + @Override + public T parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) + throws CommandSyntaxException { + // Get the raw input and parsed input + final String customresult = CommandAPIHandler.getRawArgumentInput(cmdCtx, key); + final B parsedInput = base.parseArgument(cmdCtx, key, previousArgs); + + try { + return infoParser.apply(new CustomArgumentInfo<>(CommandAPIBukkit.get().getCommandSenderFromCommandSource(cmdCtx.getSource()).getSource(), + previousArgs, customresult, parsedInput)); + } catch (CustomArgumentException e) { + throw e.toCommandSyntax(customresult, cmdCtx); + } catch (Exception e) { + String errorMsg = new MessageBuilder("Error in executing command ").appendFullInput().append(" - ") + .appendArgInput().appendHere().toString().replace(INPUT, customresult) + .replace(FULL_INPUT, cmdCtx.getInput()); + throw new SimpleCommandExceptionType(() -> errorMsg).create(); + } + } + + /** + * MessageBuilder is used to create error messages for invalid argument inputs + */ + public static class MessageBuilder implements Serializable { + + private static final long serialVersionUID = 838497662821791798L; + + StringBuilder builder; + + /** + * Create a blank message + */ + public MessageBuilder() { + builder = new StringBuilder(); + } + + /** + * Create a message with an input string + * + * @param str The string to start the message with + */ + public MessageBuilder(String str) { + builder = new StringBuilder(str); + } + + /** + * Appends the argument input that the CommandSender used in this command.
+ * For example, if /foo bar was executed and an error occurs with + * the CustomArgument bar, then the arg input will append + * bar to the end of the message.
+ *
+ * This input is determined at runtime, and is stored as %input% + * until executed + * + * @return A reference to this object + */ + public MessageBuilder appendArgInput() { + builder.append(INPUT); + return this; + } + + /** + * Appends the whole input that the CommandSender used in this command.
+ * For example, if /foo bar was executed, then foo bar + * will be appended to the end of the message.
+ *
+ * This input is determined at runtime, and is stored as %finput% + * until executed + * + * @return A reference to this object + */ + public MessageBuilder appendFullInput() { + builder.append(FULL_INPUT); + return this; + } + + /** + * Appends <--[HERE] to the end of the message + * + * @return A reference to this object + */ + public MessageBuilder appendHere() { + builder.append("<--[HERE]"); + return this; + } + + /** + * Appends a string to the end of this message + * + * @param str The string to append to the end of this message + * @return A reference to this object + */ + public MessageBuilder append(String str) { + builder.append(str); + return this; + } + + /** + * Appends an object to the end of this message + * + * @param obj The object to append to the end of this message + * @return A reference to this object + */ + public MessageBuilder append(Object obj) { + builder.append(obj); + return this; + } + + /** + * Returns the String content of this MessageBuilder + * + * @return the String content of this MessageBuilder + */ + @Override + public String toString() { + return builder.toString(); + } + } + + /** + * An exception used to create command-related errors for the CustomArgument + */ + @SuppressWarnings("serial") + public static class CustomArgumentException extends Exception { + + private ComponentLike errorComponent = null; + private String errorMessage = null; + private MessageBuilder errorMessageBuilder = null; + + /* Prevent instantiation from any other sources */ + private CustomArgumentException() { + + } + + /** + * Constructs a CustomArgumentException with a given error message + * + * @param errorMessage the error message to display to the user when this + * exception is thrown + */ + public static CustomArgumentException fromString(String errorMessage) { + CustomArgumentException exception = new CustomArgumentException(); + exception.errorMessage = errorMessage; + return exception; + } + + /** + * Constructs a CustomArgumentException with a given error message + * + * @param errorMessage the error message to display to the user when this + * exception is thrown + */ + public static CustomArgumentException fromAdventureComponent(ComponentLike errorMessage) { + CustomArgumentException exception = new CustomArgumentException(); + exception.errorComponent = errorMessage; + return exception; + } + + /** + * Constructs a CustomArgumentException with a given error message + * + * @param errorMessage the error message to display to the user when this + * exception is thrown + */ + public static CustomArgumentException fromMessageBuilder(MessageBuilder errorMessage) { + CustomArgumentException exception = new CustomArgumentException(); + exception.errorMessageBuilder = errorMessage; + return exception; + } + + /** + * Converts this CustomArgumentException into a CommandSyntaxException + * + * @param result the argument that the user entered that caused this exception + * to arise + * @param cmdCtx the command context that executed this command + * @return a Brigadier CommandSyntaxException + */ + public CommandSyntaxException toCommandSyntax(String result, CommandContext cmdCtx) { + if (errorComponent != null) { + // Deal with Adventure Component + Message brigadierMessage = BukkitTooltip.messageFromAdventureComponent(errorComponent); + return new SimpleCommandExceptionType(brigadierMessage).create(); + } + + if (errorMessageBuilder != null) { + // Deal with MessageBuilder + String errorMsg = errorMessageBuilder.toString().replace(INPUT, result).replace(FULL_INPUT, + cmdCtx.getInput()); + return new SimpleCommandExceptionType(new LiteralMessage(errorMsg)).create(); + } + + if (errorMessage != null) { + // Deal with String + Component component = LegacyComponentSerializer.legacyAmpersand().deserialize(errorMessage); + return new SimpleCommandExceptionType(BukkitTooltip.messageFromAdventureComponent(component)).create(); + } + + throw new IllegalStateException("No error component, error message creator or error message specified"); + } + + } + + /** + * A record which contains information which can be passed to the custom + * argument's parser. + * + * @param sender the sender that types this argument + * @param previousArgs previousArgs - a {@link CommandArguments} object holding previously declared (parsed) + * arguments. This can be used as if it were arguments in a command executor method. + * @param input the current input which the user has typed for this + * argument + * @param currentInput the current input, when parsed with the underlying base + * argument. + */ + public record CustomArgumentInfo( + /** + * sender - the sender that types this argument + */ + CommandSender sender, + + /** + * previousArgs - a {@link CommandArguments} object holding previously declared (parsed) arguments. This can + * be used as if it were arguments in a command executor method. + */ + CommandArguments previousArgs, + + /** + * input - the current input which the user has typed for this argument + */ + String input, + + /** + * currentInput - the current input, when parsed with the underlying base + * argument. + */ + B currentInput) { + } + + /** + * A FunctionalInterface that takes in a {@link CustomArgumentInfo}, returns T + * and can throw a {@link CustomArgumentException} + * + * @param the type that is returned when applying this parser + */ + @FunctionalInterface + public static interface CustomArgumentInfoParser { + + /** + * Applies a CustomArgumentInfo input to this custom argument parser + * + * @param info the custom argument info to apply to this parser + * @return the applied output represented by this FunctionalInterface + * @throws CustomArgumentException if an error occurs during parsing + */ + public T apply(CustomArgumentInfo info) throws CustomArgumentException; + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PlayerArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/PlayerProfileArgument.java similarity index 70% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PlayerArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/PlayerProfileArgument.java index 220bc56f3..349d2a3ab 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/PlayerArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/PlayerProfileArgument.java @@ -20,35 +20,37 @@ *******************************************************************************/ package dev.jorel.commandapi.arguments; +import com.destroystokyo.paper.profile.PlayerProfile; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.executors.CommandArguments; -import org.bukkit.entity.Player; + +import java.util.List; /** - * An argument that represents the Bukkit Player object. + * An argument that represents the Paper PlayerProfile object. *

* Note that this Argument internally references Mojang's authentication servers to resolve * usernames, which gives it a slight performance overhead compared to {@link EntitySelectorArgument.OnePlayer}. * - * @since 1.1 + * @since 11.0.0 */ -public class PlayerArgument extends SafeOverrideableArgument { +public class PlayerProfileArgument extends SafeOverrideableArgument { /** - * A Player argument. Produces a single player, regardless of whether - * @a, @p, @r or @e is used. + * A PlayerProfile argument. Returns a {@link List} * * @param nodeName the name of the node for this argument */ - public PlayerArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentProfile(), Player::getName); + public PlayerProfileArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentProfile(), PlayerProfile::getName); } @Override - public Class getPrimitiveType() { - return Player.class; + public Class getPrimitiveType() { + return List.class; } @Override @@ -57,7 +59,7 @@ public CommandAPIArgumentType getArgumentType() { } @Override - public Player parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getPlayer(cmdCtx, key); + public List parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { + return CommandAPIPaper.getPaper().getNMS().getProfile(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java new file mode 100644 index 000000000..1af07042c --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java @@ -0,0 +1,4 @@ +package dev.jorel.commandapi.nms; + +public abstract class BundledNMS implements NMS, PaperNMS { +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java new file mode 100644 index 000000000..e517a186d --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java @@ -0,0 +1,29 @@ +package dev.jorel.commandapi.nms; + +import com.destroystokyo.paper.profile.PlayerProfile; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.LiteralCommandNode; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.List; + +public interface PaperNMS { + + SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + NamedTextColor getChatColor(CommandContext cmdCtx, String key); + + Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + NMS bukkitNMS(); + + CommandRegistrationStrategy createCommandRegistrationStrategy(); + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml new file mode 100644 index 000000000..a938c4fce --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml @@ -0,0 +1,112 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 10.2.0-SNAPSHOT + + + commandapi-paper-documentation-code + Paper documentation code + + + + minecraft-libraries + https://libraries.minecraft.net + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + + + + + com.mojang + brigadier + 1.0.17 + provided + + + com.mojang + authlib + 3.3.39 + provided + + + + + net.kyori + adventure-platform-bukkit + 4.2.0 + test + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + + + dev.jorel + commandapi-kotlin-paper + ${project.version} + + + + + de.tr7zw + item-nbt-api + 2.11.1 + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + test-compile + + test-compile + + + + ${project.basedir}/src/main/kotlin/ + + + + + + 16 + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java new file mode 100644 index 000000000..99d345252 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java @@ -0,0 +1,119 @@ +package dev.jorel.commandapi.examples.java; + +import de.tr7zw.changeme.nbtapi.NBTContainer; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.CommandAPIPaperConfig; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.PlayerProfileArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.TextArgument; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; +import net.kyori.adventure.inventory.Book; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public class Examples { + +void argument_chatAdventure() { +/* ANCHOR: argumentChatAdventure1 */ +new CommandAPICommand("namecolor") + .withArguments(new ChatColorArgument("chatcolor")) + .executesPlayer((player, args) -> { + NamedTextColor color = (NamedTextColor) args.get("chatcolor"); + player.displayName(Component.text().color(color).append(Component.text(player.getName())).build()); + }) + .register(); +/* ANCHOR_END: argumentChatAdventure1 */ + +/* ANCHOR: argumentChatAdventure2 */ +new CommandAPICommand("showbook") + .withArguments(new PlayerProfileArgument("target")) + .withArguments(new TextArgument("title")) + .withArguments(new StringArgument("author")) + .withArguments(new ChatComponentArgument("contents")) + .executes((sender, args) -> { + Player target = (Player) args.get("target"); + String title = (String) args.get("title"); + String author = (String) args.get("author"); + Component content = (Component) args.get("contents"); + + // Create a book and show it to the user (Requires Paper) + Book mybook = Book.book(Component.text(title), Component.text(author), content); + target.openBook(mybook); + }) + .register(); +/* ANCHOR_END: argumentChatAdventure2 */ + +/* ANCHOR: argumentChatAdventure3 */ +new CommandAPICommand("pbroadcast") + .withArguments(new ChatArgument("message")) + .executes((sender, args) -> { + Component message = (Component) args.get("message"); + + // Broadcast the message to everyone with broadcast permissions. + Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS); + Bukkit.getServer().broadcast(message); + }) + .register(); +/* ANCHOR_END: argumentChatAdventure3 */ +} + +class argument_nbt extends JavaPlugin { +/* ANCHOR: argumentNBT1 */ +@Override +public void onLoad() { + CommandAPI.onLoad(new CommandAPIPaperConfig<>(this.getPluginMeta(), this) + .initializeNBTAPI(NBTContainer.class, NBTContainer::new) + ); +} +/* ANCHOR_END: argumentNBT1 */ +} + +class setupShading { +JavaPlugin plugin = new JavaPlugin() {}; + +{ +/* ANCHOR: setupShading1 */ +CommandAPI.onLoad(new CommandAPIPaperConfig(plugin.getPluginMeta(), (LifecycleEventOwner) this).silentLogs(true)); +/* ANCHOR_END: setupShading1 */ +} + +/* ANCHOR: setupShading2 */ +class MyPlugin extends JavaPlugin { + + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPIPaperConfig<>(this.getPluginMeta(), this).verboseOutput(true)); // Load with verbose output + + new CommandAPICommand("ping") + .executes((sender, args) -> { + sender.sendMessage("pong!"); + }) + .register(); + } + + @Override + public void onEnable() { + CommandAPIPaper.onEnable(this); + + // Register commands, listeners etc. + } + + @Override + public void onDisable() { + CommandAPI.onDisable(); + } + +} +/* ANCHOR_END: setupShading2 */ +} + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt new file mode 100644 index 000000000..90cf516a4 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt @@ -0,0 +1,112 @@ +package dev.jorel.commandapi.examples.kotlin + +import de.tr7zw.changeme.nbtapi.NBTContainer +import dev.jorel.commandapi.CommandAPI +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.CommandAPIPaperConfig +import dev.jorel.commandapi.arguments.* +import dev.jorel.commandapi.executors.CommandExecutor +import dev.jorel.commandapi.executors.PlayerCommandExecutor +import net.kyori.adventure.inventory.Book +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor +import org.bukkit.Bukkit +import org.bukkit.Server +import org.bukkit.entity.Player +import org.bukkit.plugin.java.JavaPlugin + +class Examples { + +fun argument_chatAdventure() { +/* ANCHOR: argumentChatAdventure1 */ +CommandAPICommand("namecolor") + .withArguments(ChatColorArgument("chatcolor")) + .executesPlayer(PlayerCommandExecutor { player, args -> + val color = args["chatcolor"] as NamedTextColor + player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) + }) + .register() +/* ANCHOR_END: argumentChatAdventure1 */ + +/* ANCHOR: argumentChatAdventure2 */ +CommandAPICommand("showbook") + .withArguments(PlayerProfileArgument("target")) + .withArguments(TextArgument("title")) + .withArguments(StringArgument("author")) + .withArguments(ChatComponentArgument("contents")) + .executes(CommandExecutor { _, args -> + val target = args["target"] as Player + val title = args["title"] as String + val author = args["author"] as String + val content = args["contents"] as Component + + // Create a book and show it to the user (Requires Paper) + val mybook = Book.book(Component.text(title), Component.text(author), content) + target.openBook(mybook) + }) + .register() +/* ANCHOR_END: argumentChatAdventure2 */ + +/* ANCHOR: argumentChatAdventure3 */ +CommandAPICommand("pbroadcast") + .withArguments(ChatArgument("message")) + .executes(CommandExecutor { _, args -> + val message = args["message"] as Component + + // Broadcast the message to everyone with broadcast permissions. + Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) + Bukkit.getServer().broadcast(message) + }) + .register() +/* ANCHOR_END: argumentChatAdventure3 */ +} + +class argument_nbt : JavaPlugin() { + +/* ANCHOR: argumentNBT1 */ +override fun onLoad() { + CommandAPI.onLoad(CommandAPIPaperConfig(this.pluginMeta, this) + .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) + ) +} +/* ANCHOR_END: argumentNBT1 */ + +} + +class setupShading { +val plugin: JavaPlugin = object : JavaPlugin() {} + +fun setupShading1() { +/* ANCHOR: setupShading1 */ +CommandAPI.onLoad(CommandAPIPaperConfig<>(plugin.pluginMeta, this).silentLogs(true)) +/* ANCHOR_END: setupShading1 */ +} + +/* ANCHOR: setupShading2 */ +class MyPlugin : JavaPlugin() { + + override fun onLoad() { + CommandAPI.onLoad(CommandAPIPaperConfig(this.pluginMeta, this).verboseOutput(true)) // Load with verbose output + + CommandAPICommand("ping") + .executes(CommandExecutor { sender, _ -> + sender.sendMessage("pong!") + }) + .register() + } + + override fun onEnable() { + CommandAPI.onEnable(this) + + // Register commands, listeners etc. + } + + override fun onDisable() { + CommandAPI.onDisable() + } + +} +/* ANCHOR_END: setupShading2 */ +} + +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt new file mode 100644 index 000000000..08a72c561 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt @@ -0,0 +1,80 @@ +package dev.jorel.commandapi.examples.kotlin + +import de.tr7zw.changeme.nbtapi.NBTContainer +import dev.jorel.commandapi.kotlindsl.anyExecutor +import dev.jorel.commandapi.kotlindsl.chatArgument +import dev.jorel.commandapi.kotlindsl.chatColorArgument +import dev.jorel.commandapi.kotlindsl.chatComponentArgument +import dev.jorel.commandapi.kotlindsl.commandAPICommand +import dev.jorel.commandapi.kotlindsl.nbtCompoundArgument +import dev.jorel.commandapi.kotlindsl.playerArgument +import dev.jorel.commandapi.kotlindsl.playerExecutor +import dev.jorel.commandapi.kotlindsl.stringArgument +import dev.jorel.commandapi.kotlindsl.textArgument +import net.kyori.adventure.inventory.Book +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor +import org.bukkit.Bukkit +import org.bukkit.Server +import org.bukkit.entity.Player + +class ExamplesKotlinDSL { + +fun argument_chatAdventure() { +/* ANCHOR: argumentChatAdventure1 */ +commandAPICommand("namecolor") { + chatColorArgument("chatcolor") + playerExecutor { player, args -> + val color = args["chatcolor"] as NamedTextColor + player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) + } +} +/* ANCHOR_END: argumentChatAdventure1 */ + +/* ANCHOR: argumentChatAdventure2 */ +commandAPICommand("showbook") { + playerArgument("target") + textArgument("title") + stringArgument("author") + chatComponentArgument("contents") + anyExecutor { _, args -> + val target = args["target"] as Player + val title = args["title"] as String + val author = args["author"] as String + val content = args["contents"] as Component + + // Create a book and show it to the user (Requires Paper) + val mybook = Book.book(Component.text(title), Component.text(author), content) + target.openBook(mybook) + } +} +/* ANCHOR_END: argumentChatAdventure2 */ + +/* ANCHOR: argumentChatAdventure3 */ +commandAPICommand("pbroadcast") { + chatArgument("message") + anyExecutor { _, args -> + val message = args["message"] as Component + + // Broadcast the message to everyone with broadcast permissions. + Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) + Bukkit.getServer().broadcast(message) + } +} +/* ANCHOR_END: argumentChatAdventure3 */ +} + +fun argument_nbt() { +/* ANCHOR: argumentNBT1 */ +commandAPICommand("award") { + nbtCompoundArgument("nbt") + anyExecutor { _, args -> + val nbt = args["nbt"] as NBTContainer + + // Do something with "nbt" here... + } +} +/* ANCHOR_END: argumentNBT1 */ +} + +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml new file mode 100644 index 000000000..c073780cc --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 11.0.0-SNAPSHOT + + + commandapi-paper-mojang-mapped + Paper mojang mapped dependency + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml new file mode 100644 index 000000000..61aae12d3 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml @@ -0,0 +1,134 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 11.0.0-SNAPSHOT + + + commandapi-paper-1.20.5 + Paper support for 1.20.6 + + + 1.20.6-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + ca.bkaw + paper-nms + 1.20.6-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20.5 + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + compile + + jar + + + mojang-mapped + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.7 + + + process-classes + + remap + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java new file mode 100644 index 000000000..2c0ed7cfb --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java @@ -0,0 +1,141 @@ +package dev.jorel.commandapi.nms; + +import com.destroystokyo.paper.profile.CraftPlayerProfile; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.google.common.collect.Collections2; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.LiteralCommandNode; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import dev.jorel.commandapi.SpigotCommandRegistration; +import io.papermc.paper.command.brigadier.PaperCommands; +import io.papermc.paper.command.brigadier.PluginCommandNode; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.help.SimpleHelpMap; + +import java.lang.reflect.Field; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class PaperNMS_1_20_R4 implements PaperNMS { + + private CommandBuildContext commandBuildContext; + private static final boolean vanillaCommandDispatcherFieldExists; + private static final Commands vanillaCommandDispatcher; + + private NMS_1_20_R4 bukkitNMS; + + static { + boolean fieldExists; + Commands commandDispatcher; + try { + Field vanillaCommandDispatcherField = MinecraftServer.class.getDeclaredField("vanillaCommandDispatcher"); + commandDispatcher = (Commands) vanillaCommandDispatcherField.get(CommandAPIPaper.getPaper().getNMS().getMinecraftServer()); + fieldExists = true; + } catch (NoSuchFieldException | SecurityException | IllegalAccessException e) { + // Expected on Paper-1.20.6-65 or later due to https://github.com/PaperMC/Paper/pull/8235 + commandDispatcher = null; + fieldExists = false; + } + vanillaCommandDispatcher = commandDispatcher; + vanillaCommandDispatcherFieldExists = fieldExists; + } + + private CommandBuildContext getCommandBuildContext() { + if (commandBuildContext != null) { + return commandBuildContext; + } + if (Bukkit.getServer() instanceof CraftServer server) { + commandBuildContext = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + return commandBuildContext; + } else { + return PaperCommands.INSTANCE.getBuildContext(); + } + } + + @Override + public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + CompletableFuture future = new CompletableFuture<>(); + MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); + return future.join(); + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), getCommandBuildContext())); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R4(this::getCommandBuildContext); + } + return (NMS) bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + if (vanillaCommandDispatcherFieldExists) { + return new SpigotCommandRegistration<>( + vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) CommandAPIBukkit.get().getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } else { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + () -> { + SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); + helpMap.clear(); + helpMap.initializeGeneralTopics(); + helpMap.initializeCommands(); + }, + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml new file mode 100644 index 000000000..d4d576b4c --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml @@ -0,0 +1,129 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 11.0.0-SNAPSHOT + + + commandapi-paper-1.21.2 + Paper support for 1.21.2 + + + 1.21.3-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + + ca.bkaw + paper-nms + 1.21.3-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.2 + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + compile + + jar + + + mojang-mapped + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.7 + + + process-classes + + remap + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java new file mode 100644 index 000000000..f992445f8 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java @@ -0,0 +1,105 @@ +package dev.jorel.commandapi.nms; + +import com.destroystokyo.paper.profile.CraftPlayerProfile; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.google.common.collect.Collections2; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.LiteralCommandNode; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import io.papermc.paper.command.brigadier.PaperCommands; +import io.papermc.paper.command.brigadier.PluginCommandNode; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.help.SimpleHelpMap; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class PaperNMS_1_21_R2 implements PaperNMS { + + private CommandBuildContext commandBuildContext; + + private NMS_1_21_R2 bukkitNMS; + + private CommandBuildContext getCommandBuildContext() { + if (commandBuildContext != null) { + return commandBuildContext; + } + if (Bukkit.getServer() instanceof CraftServer server) { + commandBuildContext = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + return commandBuildContext; + } else { + return PaperCommands.INSTANCE.getBuildContext(); + } + } + + @Override + public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + CompletableFuture future = new CompletableFuture<>(); + MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); + return future.join(); + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), getCommandBuildContext())); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R2(this::getCommandBuildContext); + } + return (NMS) bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + () -> { + SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); + helpMap.clear(); + helpMap.initializeGeneralTopics(); + helpMap.initializeCommands(); + }, + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml new file mode 100644 index 000000000..81e57c7f1 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml @@ -0,0 +1,129 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 11.0.0-SNAPSHOT + + + commandapi-paper-1.21.4 + Paper support for 1.21.4 + + + 1.21.4-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + + ca.bkaw + paper-nms + 1.21.4-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.4 + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + compile + + jar + + + mojang-mapped + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.7 + + + process-classes + + remap + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java new file mode 100644 index 000000000..cfa088d64 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java @@ -0,0 +1,118 @@ +package dev.jorel.commandapi.nms; + +import com.destroystokyo.paper.profile.CraftPlayerProfile; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.google.common.collect.Collections2; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.LiteralCommandNode; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import io.papermc.paper.command.brigadier.PaperCommands; +import io.papermc.paper.command.brigadier.PluginCommandMeta; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import io.papermc.paper.plugin.configuration.PluginMeta; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.help.SimpleHelpMap; + +import java.lang.reflect.Constructor; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class PaperNMS_1_21_R3 implements PaperNMS { + + private CommandBuildContext commandBuildContext; + + private static final Constructor pluginCommandNodeConstructor; + + private NMS_1_21_R3 bukkitNMS; + + static { + Constructor pluginCommandNode; + try { + pluginCommandNode = Class.forName("io.papermc.paper.command.brigadier.PluginCommandNode").getDeclaredConstructor(String.class, PluginMeta.class, LiteralCommandNode.class, String.class); + } catch (ReflectiveOperationException e) { + pluginCommandNode = null; + } + pluginCommandNodeConstructor = pluginCommandNode; + } + + private CommandBuildContext getCommandBuildContext() { + if (commandBuildContext != null) { + return commandBuildContext; + } + if (Bukkit.getServer() instanceof CraftServer server) { + commandBuildContext = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + return commandBuildContext; + } else { + return PaperCommands.INSTANCE.getBuildContext(); + } + } + + @Override + public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + CompletableFuture future = new CompletableFuture<>(); + MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); + return future.join(); + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), getCommandBuildContext())); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R3(this::getCommandBuildContext); + } + return (NMS) bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + () -> { + SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); + helpMap.clear(); + helpMap.initializeGeneralTopics(); + helpMap.initializeCommands(); + }, + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml new file mode 100644 index 000000000..711413c1f --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml @@ -0,0 +1,129 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 11.0.0-SNAPSHOT + + + commandapi-paper-1.21.5 + Paper support for 1.21.5 + + + 1.21.5-R0.1-SNAPSHOT + 1.21.5-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + + ca.bkaw + paper-nms + 1.21.5-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.5 + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + compile + + jar + + + mojang-mapped + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.7 + + + process-classes + + remap + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java new file mode 100644 index 000000000..90cef0ee5 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java @@ -0,0 +1,128 @@ +package dev.jorel.commandapi.nms; + +import com.destroystokyo.paper.profile.CraftPlayerProfile; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.google.common.collect.Collections2; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.CommandNode; +import com.mojang.brigadier.tree.LiteralCommandNode; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import dev.jorel.commandapi.SafeVarHandle; +import io.papermc.paper.command.brigadier.APICommandMeta; +import io.papermc.paper.command.brigadier.PaperCommands; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import io.papermc.paper.plugin.configuration.PluginMeta; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.help.SimpleHelpMap; + +import java.lang.reflect.Constructor; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +public class PaperNMS_1_21_R4 implements PaperNMS { + + private CommandBuildContext commandBuildContext; + private static final Constructor pluginCommandNodeConstructor; + private static final SafeVarHandle, Object> metaField; + + private NMS_1_21_R4 bukkitNMS; + + static { + Constructor pluginCommandNode; + SafeVarHandle, ?> metaFieldHandle = null; + try { + Class pluginCommandMeta = Class.forName("io.papermc.paper.command.brigadier.PluginCommandMeta"); + pluginCommandNode = pluginCommandMeta.getDeclaredConstructor(PluginMeta.class, String.class, List.class); + metaFieldHandle = SafeVarHandle.ofOrNull(CommandNode.class, "pluginCommandNode", "pluginCommandNode", pluginCommandMeta); + } catch (ReflectiveOperationException e) { + pluginCommandNode = null; + } + pluginCommandNodeConstructor = pluginCommandNode; + metaField = (SafeVarHandle, Object>) metaFieldHandle; + } + + private CommandBuildContext getCommandBuildContext() { + if (commandBuildContext != null) { + return commandBuildContext; + } + if (Bukkit.getServer() instanceof CraftServer server) { + commandBuildContext = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + return commandBuildContext; + } else { + return PaperCommands.INSTANCE.getBuildContext(); + } + } + + @Override + public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + CompletableFuture future = new CompletableFuture<>(); + MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); + return future.join(); + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key), getCommandBuildContext())); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R4(this::getCommandBuildContext); + } + return (NMS) bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + () -> { + SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); + helpMap.clear(); + helpMap.initializeGeneralTopics(); + helpMap.initializeCommands(); + }, + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml new file mode 100644 index 000000000..397126e3a --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml @@ -0,0 +1,103 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 11.0.0-SNAPSHOT + + + commandapi-paper-1.21.6 + Paper support for 1.21.6 + + + 1.21.6-R0.1-SNAPSHOT + 1.21.6-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + + ca.bkaw + paper-nms + 1.21.6-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.6 + ${project.version} + mojang-mapped + + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.5-SNAPSHOT + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java new file mode 100644 index 000000000..b58c43bd0 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java @@ -0,0 +1,102 @@ +package dev.jorel.commandapi.nms; + +import com.destroystokyo.paper.profile.CraftPlayerProfile; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.google.common.collect.Collections2; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import io.papermc.paper.command.brigadier.PaperCommands; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.help.SimpleHelpMap; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class PaperNMS_1_21_R5 implements PaperNMS { + + private CommandBuildContext commandBuildContext; + + private NMS_1_21_R5 bukkitNMS; + + private CommandBuildContext getCommandBuildContext() { + if (commandBuildContext != null) { + return commandBuildContext; + } + if (Bukkit.getServer() instanceof CraftServer server) { + commandBuildContext = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + return commandBuildContext; + } else { + return PaperCommands.INSTANCE.getBuildContext(); + } + } + + @Override + public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + CompletableFuture future = new CompletableFuture<>(); + MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); + return future.join(); + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(bukkitNMS.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key))); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R5(this::getCommandBuildContext); + } + return (NMS) bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + () -> { + SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); + helpMap.clear(); + helpMap.initializeGeneralTopics(); + helpMap.initializeCommands(); + }, + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml new file mode 100644 index 000000000..112b4e9c1 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 11.0.0-SNAPSHOT + + + commandapi-paper-1.21 + Paper support for 1.21 + + + 1.21-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + ca.bkaw + paper-nms + 1.21-SNAPSHOT + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21 + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + compile + + jar + + + mojang-mapped + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.7 + + + process-classes + + remap + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java new file mode 100644 index 000000000..405459b00 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java @@ -0,0 +1,105 @@ +package dev.jorel.commandapi.nms; + +import com.destroystokyo.paper.profile.CraftPlayerProfile; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.google.common.collect.Collections2; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.LiteralCommandNode; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import io.papermc.paper.command.brigadier.PaperCommands; +import io.papermc.paper.command.brigadier.PluginCommandNode; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.help.SimpleHelpMap; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class PaperNMS_1_21_R1 implements PaperNMS { + + private CommandBuildContext commandBuildContext; + + private NMS_1_21_R1 bukkitNMS; + + private CommandBuildContext getCommandBuildContext() { + if (commandBuildContext != null) { + return commandBuildContext; + } + if (Bukkit.getServer() instanceof CraftServer server) { + commandBuildContext = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + return commandBuildContext; + } else { + return PaperCommands.INSTANCE.getBuildContext(); + } + } + + @Override + public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + CompletableFuture future = new CompletableFuture<>(); + MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); + return future.join(); + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); + return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), getCommandBuildContext())); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R1(this::getCommandBuildContext); + } + return (NMS) bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + () -> { + SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); + helpMap.clear(); + helpMap.initializeGeneralTopics(); + helpMap.initializeCommands(); + }, + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml new file mode 100644 index 000000000..c4c7ea678 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 11.0.0-SNAPSHOT + + + commandapi-paper-api + Paper API support + + + 1.21.6-R0.1-SNAPSHOT + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + dev.jorel + commandapi-paper-core + ${project.version} + provided + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java new file mode 100644 index 000000000..70d194569 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -0,0 +1,926 @@ +package dev.jorel.commandapi.nms; + +import com.destroystokyo.paper.profile.PlayerProfile; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.Message; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.mojang.brigadier.tree.LiteralCommandNode; +import dev.jorel.commandapi.BukkitTooltip; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.arguments.ArgumentSubType; +import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; +import dev.jorel.commandapi.arguments.parser.function.ThrowingBiFunction; +import dev.jorel.commandapi.arguments.parser.function.ThrowingSupplier; +import dev.jorel.commandapi.commandsenders.AbstractCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.wrappers.DoubleRange; +import dev.jorel.commandapi.wrappers.FunctionWrapper; +import dev.jorel.commandapi.wrappers.IntegerRange; +import dev.jorel.commandapi.wrappers.Location2D; +import dev.jorel.commandapi.wrappers.MathOperation; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; +import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; +import dev.jorel.commandapi.wrappers.ScoreboardSlot; +import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.command.brigadier.argument.SignedMessageResolver; +import io.papermc.paper.command.brigadier.argument.predicate.ItemStackPredicate; +import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider; +import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider; +import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver; +import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver; +import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver; +import io.papermc.paper.command.brigadier.argument.resolvers.RotationResolver; +import io.papermc.paper.command.brigadier.argument.resolvers.selector.EntitySelectorArgumentResolver; +import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver; +import io.papermc.paper.math.BlockPosition; +import io.papermc.paper.math.FinePosition; +import io.papermc.paper.registry.RegistryKey; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Axis; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.OfflinePlayer; +import org.bukkit.Registry; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; +import org.bukkit.loot.LootTable; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.Criteria; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.function.Supplier; + +@SuppressWarnings("UnstableApiUsage") +public class APITypeProvider extends BundledNMS { + + private final PaperNMS paperNMS; + + public APITypeProvider(PaperNMS paperNMS) { + this.paperNMS = paperNMS; + bukkitNMS(); + } + + private ArgumentType getArgumentType(ThrowingSupplier> paper, Supplier> nms) { + try { + return paper.get(); + } catch (Throwable t) { + return nms.get(); + } + } + + private ArgumentType getArgumentType(Supplier> nms) { + return nms.get(); + } + + private T parseT( + CommandContext cmdCtx, + String key, + ThrowingBiFunction, String, T, Exception> api, + ThrowingBiFunction, String, T, CommandSyntaxException> nms) throws CommandSyntaxException { + try { + return api.apply(cmdCtx, key); + } catch (Throwable t) { + return nms.apply(cmdCtx, key); + } + } + + private T parse( + CommandContext cmdCtx, + String key, + BiFunction, String, T> api, + BiFunction, String, T> nms) { + try { + return api.apply(cmdCtx, key); + } catch (Throwable t) { + return nms.apply(cmdCtx, key); + } + } + + private T parseT( + CommandContext cmdCtx, + String key, + ThrowingBiFunction, String, T, CommandSyntaxException> nms) throws CommandSyntaxException { + return nms.apply(cmdCtx, key); + } + + private T parse( + CommandContext cmdCtx, + String key, + BiFunction, String, T> nms) { + return nms.apply(cmdCtx, key); + } + + @Override + public ArgumentType _ArgumentAdvancement() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentAdvancement() + ); + } + + @Override + public ArgumentType _ArgumentAngle() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentAngle() + ); + } + + @Override + public ArgumentType _ArgumentAxis() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentAxis() + ); + } + + @Override + public ArgumentType _ArgumentBlockPredicate() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentBlockPredicate() + ); + } + + @Override + public ArgumentType _ArgumentBlockState() { + return getArgumentType( + () -> ArgumentTypes.blockState(), + () -> paperNMS.bukkitNMS()._ArgumentBlockState() + ); + } + + @Override + public ArgumentType _ArgumentChat() { + return getArgumentType( + () -> ArgumentTypes.signedMessage(), + () -> paperNMS.bukkitNMS()._ArgumentChat() + ); + } + + @Override + public ArgumentType _ArgumentChatComponent() { + return getArgumentType( + () -> ArgumentTypes.component(), + () -> paperNMS.bukkitNMS()._ArgumentChatComponent() + ); + } + + @Override + public ArgumentType _ArgumentChatFormat() { + return getArgumentType( + () -> ArgumentTypes.namedColor(), + () -> paperNMS.bukkitNMS()._ArgumentChatFormat() + ); + } + + @Override + public ArgumentType _ArgumentDimension() { + return getArgumentType( + () -> ArgumentTypes.world(), + () -> paperNMS.bukkitNMS()._ArgumentDimension() + ); + } + + @Override + public ArgumentType _ArgumentEnchantment() { + return getArgumentType( + () -> ArgumentTypes.resource(RegistryKey.ENCHANTMENT), + () -> paperNMS.bukkitNMS()._ArgumentEnchantment() + ); + } + + @Override + public ArgumentType _ArgumentEntity(ArgumentSubType subType) { + return getArgumentType( + () -> switch (subType) { + case ENTITYSELECTOR_ONE_ENTITY -> ArgumentTypes.entity(); + case ENTITYSELECTOR_MANY_ENTITIES -> ArgumentTypes.entities(); + case ENTITYSELECTOR_ONE_PLAYER -> ArgumentTypes.player(); + case ENTITYSELECTOR_MANY_PLAYERS -> ArgumentTypes.players(); + default -> throw new Exception(); // Doesn't matter too much, it'll get to the right exception anyway + }, + () -> paperNMS.bukkitNMS()._ArgumentEntity(subType) + ); + } + + @Override + public ArgumentType _ArgumentEntitySummon() { + return getArgumentType( + () -> ArgumentTypes.resource(RegistryKey.ENTITY_TYPE), + () -> paperNMS.bukkitNMS()._ArgumentEntitySummon() + ); + } + + @Override + public ArgumentType _ArgumentFloatRange() { + return getArgumentType( + () -> ArgumentTypes.doubleRange(), + () -> paperNMS.bukkitNMS()._ArgumentFloatRange() + ); + } + + @Override + public ArgumentType _ArgumentIntRange() { + return getArgumentType( + () -> ArgumentTypes.integerRange(), + () -> paperNMS.bukkitNMS()._ArgumentIntRange() + ); + } + + @Override + public ArgumentType _ArgumentItemPredicate() { + return getArgumentType( + () -> ArgumentTypes.itemPredicate(), + () -> paperNMS.bukkitNMS()._ArgumentItemPredicate() + ); + } + + @Override + public ArgumentType _ArgumentItemStack() { + return getArgumentType( + () -> ArgumentTypes.itemStack(), + () -> paperNMS.bukkitNMS()._ArgumentItemStack() + ); + } + + @Override + public ArgumentType _ArgumentMathOperation() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentMathOperation() + ); + } + + @Override + public ArgumentType _ArgumentMinecraftKeyRegistered() { + return getArgumentType( + () -> ArgumentTypes.namespacedKey(), + () -> paperNMS.bukkitNMS()._ArgumentMinecraftKeyRegistered() + ); + } + + @Override + public ArgumentType _ArgumentMobEffect() { + return getArgumentType( + () -> ArgumentTypes.resource(RegistryKey.MOB_EFFECT), + () -> paperNMS.bukkitNMS()._ArgumentMobEffect() + ); + } + + @Override + public ArgumentType _ArgumentNBTCompound() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentNBTCompound() + ); + } + + @Override + public ArgumentType _ArgumentParticle() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentParticle() + ); + } + + @Override + public ArgumentType _ArgumentPosition() { + return getArgumentType( + () -> ArgumentTypes.blockPosition(), + () -> paperNMS.bukkitNMS()._ArgumentPosition() + ); + } + + @Override + public ArgumentType _ArgumentPosition2D() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentPosition2D() + ); + } + + @Override + public ArgumentType _ArgumentProfile() { + return getArgumentType( + () -> ArgumentTypes.playerProfiles(), + () -> paperNMS.bukkitNMS()._ArgumentProfile() + ); + } + + @Override + public ArgumentType _ArgumentRecipe() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentRecipe() + ); + } + + @Override + public ArgumentType _ArgumentRotation() { + return getArgumentType( + () -> ArgumentTypes.rotation(), + () -> paperNMS.bukkitNMS()._ArgumentRotation() + ); + } + + @Override + public ArgumentType _ArgumentScoreboardCriteria() { + return getArgumentType( + () -> ArgumentTypes.objectiveCriteria(), + () -> paperNMS.bukkitNMS()._ArgumentScoreboardCriteria() + ); + } + + @Override + public ArgumentType _ArgumentScoreboardObjective() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentScoreboardObjective() + ); + } + + @Override + public ArgumentType _ArgumentScoreboardSlot() { + return getArgumentType( + () -> ArgumentTypes.scoreboardDisplaySlot(), + () -> paperNMS.bukkitNMS()._ArgumentScoreboardSlot() + ); + } + + @Override + public ArgumentType _ArgumentScoreboardTeam() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentScoreboardTeam() + ); + } + + @Override + public ArgumentType _ArgumentScoreholder(ArgumentSubType subType) { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentScoreholder(subType) + ); + } + + @Override + public ArgumentType _ArgumentTag() { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentTag() + ); + } + + @Override + public ArgumentType _ArgumentTime() { + return getArgumentType( + () -> ArgumentTypes.time(), + () -> paperNMS.bukkitNMS()._ArgumentTime() + ); + } + + @Override + public ArgumentType _ArgumentUUID() { + return getArgumentType( + () -> ArgumentTypes.uuid(), + () -> paperNMS.bukkitNMS()._ArgumentUUID() + ); + } + + @Override + public ArgumentType _ArgumentVec2(boolean centerPosition) { + return getArgumentType( + () -> paperNMS.bukkitNMS()._ArgumentVec2(centerPosition) + ); + } + + @Override + public ArgumentType _ArgumentVec3(boolean centerPosition) { + return getArgumentType( + () -> ArgumentTypes.finePosition(centerPosition), + () -> paperNMS.bukkitNMS()._ArgumentVec3(centerPosition) + ); + } + + @Override + public ArgumentType _ArgumentSyntheticBiome() { + return getArgumentType( + () -> ArgumentTypes.resource(RegistryKey.BIOME), + () -> paperNMS.bukkitNMS()._ArgumentSyntheticBiome() + ); + } + + @Override + public String[] compatibleVersions() { + return paperNMS.bukkitNMS().compatibleVersions(); + } + + @Override + public String convert(ItemStack is) { + return paperNMS.bukkitNMS().convert(is); + } + + @Override + public String convert(ParticleData particle) { + return paperNMS.bukkitNMS().convert(particle); + } + + @Override + public String convert(PotionEffectType potion) { + return paperNMS.bukkitNMS().convert(potion); + } + + @Override + public String convert(Sound sound) { + return paperNMS.bukkitNMS().convert(sound); + } + + @Override + public Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getAdvancement(ctx, name) + ); + } + + @Override + public float getAngle(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getAngle(ctx, name) + ); + } + + @Override + public EnumSet getAxis(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getAxis(ctx, name) + ); + } + + @Override + public RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT( + cmdCtx, key, + (ctx, name) -> new RegistryParser<>( + () -> ctx.getArgument(name, Biome.class), + () -> ctx.getArgument(name, Biome.class).getKey() + ), + (ctx, name) -> paperNMS.bukkitNMS().getBiome(ctx, name) + ); + } + + @Override + public Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getBlockPredicate(ctx, name) + ); + } + + @Override + public BlockState getBlockState(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, BlockState.class), + (ctx, name) -> paperNMS.bukkitNMS().getBlockState(ctx, name) + ); + } + + @Override + public World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, World.class), + (ctx, name) -> paperNMS.bukkitNMS().getDimension(ctx, name) + ); + } + + @Override + public Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, Enchantment.class), + (ctx, name) -> paperNMS.bukkitNMS().getEnchantment(ctx, name) + ); + } + + @Override + public EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> new EntitySelectorParser( + () -> ctx.getArgument(name, PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()).getFirst(), + () -> ctx.getArgument(name, EntitySelectorArgumentResolver.class).resolve(ctx.getSource()).getFirst(), + (allowEmpty) -> ctx.getArgument(name, PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()), + (allowEmpty) -> ctx.getArgument(name, EntitySelectorArgumentResolver.class).resolve(ctx.getSource()) + ), + (ctx, name) -> paperNMS.bukkitNMS().getEntitySelector(ctx, name) + ); + } + + @Override + public EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, EntityType.class), + (ctx, name) -> paperNMS.bukkitNMS().getEntityType(ctx, name) + ); + } + + @Override + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> { + DoubleRangeProvider rangeProvider = ctx.getArgument(name, DoubleRangeProvider.class); + final double low = rangeProvider.range().hasLowerBound() ? rangeProvider.range().lowerEndpoint() : -Double.MAX_VALUE; + final double high = rangeProvider.range().hasUpperBound() ? rangeProvider.range().upperEndpoint() : Double.MAX_VALUE; + return new DoubleRange(low, high); + }, + (ctx, name) -> paperNMS.bukkitNMS().getDoubleRange(ctx, name) + ); + } + + @Override + public FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getFunction(ctx, name) + ); + } + + @Override + public SimpleFunctionWrapper getFunction(NamespacedKey key) { + return paperNMS.bukkitNMS().getFunction(key); + } + + @Override + public Set getFunctions() { + return paperNMS.bukkitNMS().getFunctions(); + } + + @Override + public IntegerRange getIntRange(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> { + IntegerRangeProvider rangeProvider = ctx.getArgument(name, IntegerRangeProvider.class); + final int low = rangeProvider.range().hasLowerBound() ? rangeProvider.range().lowerEndpoint() : Integer.MIN_VALUE; + final int high = rangeProvider.range().hasUpperBound() ? rangeProvider.range().upperEndpoint() : Integer.MAX_VALUE; + return new IntegerRange(low, high); + }, + (ctx, name) -> paperNMS.bukkitNMS().getIntRange(ctx, name) + ); + } + + @Override + public ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, ItemStack.class), + (ctx, name) -> paperNMS.bukkitNMS().getItemStack(ctx, name) + ); + } + + @Override + public Predicate getItemStackPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, ItemStackPredicate.class), + (ctx, name) -> paperNMS.bukkitNMS().getItemStackPredicate(ctx, name) + ); + } + + @Override + public Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getLocation2DBlock(ctx, name) + ); + } + + @Override + public Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getLocation2DPrecise(ctx, name) + ); + } + + @Override + public Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException { + return parseT(cmdCtx, str, + (ctx, name) -> { + BlockPosition blockPosition = ctx.getArgument(name, BlockPositionResolver.class).resolve(ctx.getSource()); + return new Location(getWorldForCSS(ctx.getSource()), blockPosition.blockX(), blockPosition.blockY(), blockPosition.blockZ()); + }, + (ctx, name) -> paperNMS.bukkitNMS().getLocationBlock(ctx, name) + ); + } + + @Override + public Location getLocationPrecise(CommandContext cmdCtx, String str) throws CommandSyntaxException { + return parseT(cmdCtx, str, + (ctx, name) -> { + FinePosition finePosition = ctx.getArgument(name, FinePositionResolver.class).resolve(ctx.getSource()); + return new Location(getWorldForCSS(ctx.getSource()), finePosition.x(), finePosition.y(), finePosition.z()); + }, + (ctx, name) -> paperNMS.bukkitNMS().getLocationPrecise(ctx, name) + ); + } + + @Override + public LootTable getLootTable(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> Bukkit.getLootTable(ctx.getArgument(name, NamespacedKey.class)), + (ctx, name) -> paperNMS.bukkitNMS().getLootTable(ctx, name) + ); + } + + @Override + public MathOperation getMathOperation(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getMathOperation(ctx, name) + ); + } + + @Override + public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, NamespacedKey.class), + (ctx, name) -> paperNMS.bukkitNMS().getMinecraftKey(ctx, name) + ); + } + + @Override + public Object getNBTCompound(CommandContext cmdCtx, String key, Function nbtContainerConstructor) { + return parse(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getNBTCompound(ctx, name, nbtContainerConstructor) + ); + } + + @Override + public Objective getObjective(CommandContext cmdCtx, String key) throws IllegalArgumentException, CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getObjective(ctx, name) + ); + } + + @Override + public String getObjectiveCriteria(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, Criteria.class).getName(), + (ctx, name) -> paperNMS.bukkitNMS().getObjectiveCriteria(ctx, name) + ); + } + + @Override + public ParticleData getParticle(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getParticle(ctx, name) + ); + } + + @Override + public OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> Bukkit.getOfflinePlayer(getIdFromProfile(ctx, name)), + (ctx, name) -> paperNMS.bukkitNMS().getOfflinePlayer(ctx, name) + ); + } + + private UUID getIdFromProfile(CommandContext ctx, String name) throws CommandSyntaxException { + Collection playerProfiles = ctx.getArgument(name, PlayerProfileListResolver.class).resolve((CommandSourceStack) ctx.getSource()); + UUID id = playerProfiles.iterator().next().getId(); + if (id == null) { + throw new SimpleCommandExceptionType(BukkitTooltip.messageFromAdventureComponent(Component.translatable("argument.player.unknown"))).create(); + } + return id; + } + + @Override + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> new RegistryParser<>( + () -> ctx.getArgument(name, PotionEffectType.class), + () -> ctx.getArgument(name, PotionEffectType.class).getKey() + ), + (ctx, name) -> paperNMS.bukkitNMS().getPotionEffect(ctx, name) + ); + } + + @Override + public Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getRecipe(ctx, name) + ); + } + + @Override + public Rotation getRotation(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> { + io.papermc.paper.math.Rotation rotation = ctx.getArgument(name, RotationResolver.class).resolve((CommandSourceStack) ctx.getSource()); + return new Rotation(rotation.yaw(), rotation.pitch()); + }, + (ctx, name) -> paperNMS.bukkitNMS().getRotation(ctx, name) + ); + } + + @Override + public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> { + DisplaySlot displaySlot = ctx.getArgument(name, DisplaySlot.class); + return ScoreboardSlot.of(displaySlot); + }, + (ctx, name) -> paperNMS.bukkitNMS().getScoreboardSlot(ctx, name) + ); + } + + @Override + public Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getScoreHolderMultiple(ctx, name) + ); + } + + @Override + public String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getScoreHolderSingle(ctx, name) + ); + } + + @Override + public Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> paperNMS.bukkitNMS().getTeam(ctx, name) + ); + } + + @Override + public int getTime(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, Integer.class), + (ctx, name) -> paperNMS.bukkitNMS().getTime(ctx, name) + ); + } + + @Override + public UUID getUUID(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, UUID.class), + (ctx, name) -> paperNMS.bukkitNMS().getUUID(ctx, name) + ); + } + + @Override + public World getWorldForCSS(CommandSourceStack clw) { + return paperNMS.bukkitNMS().getWorldForCSS(clw); + } + + @Override + public SimpleCommandMap getSimpleCommandMap() { + return paperNMS.bukkitNMS().getSimpleCommandMap(); + } + + @Override + public RegistryParser getSound(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> { + NamespacedKey namespace = ctx.getArgument(name, NamespacedKey.class); + return new RegistryParser<>( + () -> Registry.SOUND_EVENT.get(namespace), + () -> namespace + ); + }, + (ctx, name) -> paperNMS.bukkitNMS().getSound(ctx, name) + ); + } + + @Override + public SuggestionProvider getSuggestionProvider(SuggestionProviders provider) { + return paperNMS.bukkitNMS().getSuggestionProvider(provider); + } + + @Override + public SimpleFunctionWrapper[] getTag(NamespacedKey key) { + return paperNMS.bukkitNMS().getTag(key); + } + + @Override + public Set getTags() { + return paperNMS.bukkitNMS().getTags(); + } + + @Override + public void reloadDataPacks() { + paperNMS.bukkitNMS().reloadDataPacks(); + } + + @Override + public HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { + return paperNMS.bukkitNMS().generateHelpTopic(commandName, shortDescription, fullDescription, permission); + } + + @Override + public Map getHelpMap() { + return paperNMS.bukkitNMS().getHelpMap(); + } + + @Override + public Message generateMessageFromJson(String json) { + return paperNMS.bukkitNMS().generateMessageFromJson(json); + } + + @Override + public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { + return paperNMS.bukkitNMS().getSenderForCommand(cmdCtx, forceNative); + } + + @Override + public BukkitCommandSender getCommandSenderFromCommandSource(Source css) { + return paperNMS.bukkitNMS().getCommandSenderFromCommandSource(css); + } + + @Override + public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { + return paperNMS.bukkitNMS().getBrigadierSourceFromCommandSender(sender); + } + + @Override + public void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException { + paperNMS.bukkitNMS().createDispatcherFile(file, brigadierDispatcher); + } + + @Override + public T getMinecraftServer() { + return paperNMS.bukkitNMS().getMinecraftServer(); + } + + @Override + public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world) { + return paperNMS.bukkitNMS().createNativeProxyCommandSender(caller, callee, location, world); + } + + @Override + public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> { + CompletableFuture signedMessageResolver = ctx.getArgument(name, SignedMessageResolver.class).resolveSignedMessage(name, ctx); + return signedMessageResolver.join(); + }, + ((PaperNMS) paperNMS)::getChat + ); + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + return parse(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, NamedTextColor.class), + ((PaperNMS) paperNMS)::getChatColor + ); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> ctx.getArgument(name, Component.class), + ((PaperNMS) paperNMS)::getChatComponent + ); + } + + @Override + public List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> { + PlayerProfileListResolver profileListResolver = ctx.getArgument(name, PlayerProfileListResolver.class); + return new ArrayList<>(profileListResolver.resolve(ctx.getSource())); + }, + (ctx, name) -> ((PaperNMS) paperNMS).getProfile(ctx, name) + ); + } + + @Override + public NMS bukkitNMS() { + return paperNMS.bukkitNMS(); + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return ((PaperNMS) paperNMS).createCommandRegistrationStrategy(); + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml new file mode 100644 index 000000000..3629b6efc --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml @@ -0,0 +1,106 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 11.0.0-SNAPSHOT + + + commandapi-paper-nms-dependency + Paper support NMS library + pom + + + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + + + + + dev.jorel + commandapi-paper-api + ${project.version} + + + + + dev.jorel + commandapi-paper-1.21.6 + ${project.version} + + + dev.jorel + commandapi-paper-1.21.5 + ${project.version} + + + dev.jorel + commandapi-paper-1.21.4 + ${project.version} + + + dev.jorel + commandapi-paper-1.21.2 + ${project.version} + + + dev.jorel + commandapi-paper-1.21 + ${project.version} + + + dev.jorel + commandapi-paper-1.20.5 + ${project.version} + + + + + dev.jorel + commandapi-bukkit-1.21.5 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.21.4 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.21.2 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.21 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20.5 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20.3 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20.2 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20 + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml new file mode 100644 index 000000000..a28a1e074 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 11.0.0-SNAPSHOT + + + commandapi-paper-nms + Paper support NMS library + pom + + + commandapi-paper-1.21.6 + commandapi-paper-1.21.5 + commandapi-paper-1.21.4 + commandapi-paper-1.21.2 + commandapi-paper-1.21 + commandapi-paper-1.20.5 + + commandapi-paper-nms-dependency + commandapi-paper-api + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/LICENSE b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/LICENSE similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/LICENSE rename to commandapi-platforms/commandapi-paper/commandapi-paper-plugin/LICENSE diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml new file mode 100644 index 000000000..cae1a1b79 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml @@ -0,0 +1,115 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 11.0.0-SNAPSHOT + + + commandapi-paper-plugin + Paper support plugin + + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-paper-vh + ${project.version} + + + dev.jorel + commandapi-paper-nms-dependency + ${project.version} + pom + + + dev.jorel + commandapi-bukkit-plugin-common + ${project.version} + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + + dev.jorel:commandapi-core + + dev/jorel/commandapi/CommandAPIVersionHandler** + + + + + + LICENSE + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/AdvancedConverter.java b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java similarity index 94% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/AdvancedConverter.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java index 163c68082..4f7c59663 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/AdvancedConverter.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java @@ -25,22 +25,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import dev.jorel.commandapi.arguments.DoubleRangeArgument; import org.bukkit.plugin.java.JavaPlugin; import dev.jorel.commandapi.arguments.AdvancementArgument; -import dev.jorel.commandapi.arguments.AdventureChatArgument; -import dev.jorel.commandapi.arguments.AdventureChatComponentArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; import dev.jorel.commandapi.arguments.AngleArgument; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.AxisArgument; -import dev.jorel.commandapi.arguments.AsyncOfflinePlayerArgument; +import dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument; import dev.jorel.commandapi.arguments.BiomeArgument; import dev.jorel.commandapi.arguments.BlockPredicateArgument; import dev.jorel.commandapi.arguments.BlockStateArgument; import dev.jorel.commandapi.arguments.BooleanArgument; -import dev.jorel.commandapi.arguments.ChatArgument; import dev.jorel.commandapi.arguments.ChatColorArgument; -import dev.jorel.commandapi.arguments.ChatComponentArgument; import dev.jorel.commandapi.arguments.CommandAPIArgumentType; import dev.jorel.commandapi.arguments.CommandArgument; import dev.jorel.commandapi.arguments.DoubleArgument; @@ -48,7 +47,6 @@ import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.EntityTypeArgument; import dev.jorel.commandapi.arguments.FloatArgument; -import dev.jorel.commandapi.arguments.FloatRangeArgument; import dev.jorel.commandapi.arguments.FunctionArgument; import dev.jorel.commandapi.arguments.GreedyStringArgument; import dev.jorel.commandapi.arguments.IntegerArgument; @@ -66,9 +64,8 @@ import dev.jorel.commandapi.arguments.NamespacedKeyArgument; import dev.jorel.commandapi.arguments.ObjectiveArgument; import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; -import dev.jorel.commandapi.arguments.OfflinePlayerArgument; import dev.jorel.commandapi.arguments.ParticleArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.PlayerProfileArgument; import dev.jorel.commandapi.arguments.PotionEffectArgument; import dev.jorel.commandapi.arguments.RecipeArgument; import dev.jorel.commandapi.arguments.RotationArgument; @@ -232,10 +229,10 @@ private Argument parseRange(String nodeName, String[] bounds) throws InvalidN private Argument parseDefinedArgumentType(String argumentType, String nodeName) throws UnknownArgumentException { return switch (CommandAPIArgumentType.fromInternal(argumentType)) { case ADVANCEMENT -> new AdvancementArgument(nodeName); - case ADVENTURE_CHAT -> new AdventureChatArgument(nodeName); - case ADVENTURE_CHAT_COMPONENT -> new AdventureChatComponentArgument(nodeName); + case ADVENTURE_CHAT -> new ChatArgument(nodeName); + case ADVENTURE_CHAT_COMPONENT -> new ChatComponentArgument(nodeName); case ANGLE -> new AngleArgument(nodeName); - case ASYNC_OFFLINE_PLAYER -> new AsyncOfflinePlayerArgument(nodeName); + case ASYNC_OFFLINE_PLAYER -> new AsyncPlayerProfileArgument(nodeName); case AXIS -> new AxisArgument(nodeName); case BIOME -> new BiomeArgument(nodeName); case BLOCKSTATE -> new BlockStateArgument(nodeName); @@ -247,7 +244,7 @@ private Argument parseDefinedArgumentType(String argumentType, String nodeNam case ENCHANTMENT -> new EnchantmentArgument(nodeName); case ENTITY_SELECTOR -> new EntitySelectorArgument.OneEntity(nodeName); case ENTITY_TYPE -> new EntityTypeArgument(nodeName); - case FLOAT_RANGE -> new FloatRangeArgument(nodeName); + case FLOAT_RANGE -> new DoubleRangeArgument(nodeName); case FUNCTION -> new FunctionArgument(nodeName); case INT_RANGE -> new IntegerRangeArgument(nodeName); case ITEMSTACK -> new ItemStackArgument(nodeName); @@ -260,9 +257,8 @@ private Argument parseDefinedArgumentType(String argumentType, String nodeNam case NBT_COMPOUND -> new NBTCompoundArgument(nodeName); case OBJECTIVE -> new ObjectiveArgument(nodeName); case OBJECTIVE_CRITERIA -> new ObjectiveCriteriaArgument(nodeName); - case OFFLINE_PLAYER -> new OfflinePlayerArgument(nodeName); case PARTICLE -> new ParticleArgument(nodeName); - case PLAYER -> new PlayerArgument(nodeName); + case PLAYER -> new PlayerProfileArgument(nodeName); case POTION_EFFECT -> new PotionEffectArgument(nodeName); case RECIPE -> new RecipeArgument(nodeName); case ROTATION -> new RotationArgument(nodeName); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java new file mode 100644 index 000000000..1f7eafdfb --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.config.BukkitConfigurationAdapter; +import dev.jorel.commandapi.config.DefaultBukkitConfig; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * Main CommandAPI plugin entrypoint + */ +public class CommandAPIMain extends JavaPlugin { + + private static final String PLUGINS_TO_CONVERT = "plugins-to-convert"; + + @Override + public void onLoad() { + // Read config file + saveDefaultConfig(); + FileConfiguration fileConfig = getConfig(); + CommandAPIPaperConfig config = new CommandAPIPaperConfig<>(this.getPluginMeta(), this) + .verboseOutput(fileConfig.getBoolean("verbose-outputs")) + .silentLogs(fileConfig.getBoolean("silent-logs")) + .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) + .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) + .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) + .shouldHookPaperReload(fileConfig.getBoolean("hook-paper-reload")) + .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")) + .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")); + + for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { + if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { + config.addSkipSenderProxy(pluginName); + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + } + + // Main CommandAPI loading + CommandAPI.setLogger(CommandAPILogger.fromJavaLogger(getLogger())); + CommandAPI.onLoad(config); + + // Convert all plugins to be converted + if (!fileConfig.getList(PLUGINS_TO_CONVERT).isEmpty() + && fileConfig.getMapList(PLUGINS_TO_CONVERT).isEmpty()) { + CommandAPI.logError("plugins-to-convert has an invalid type. Did you miss a colon (:) after a plugin name?"); + } + + convertCommands(fileConfig); + } + + private void convertCommands(FileConfiguration fileConfig) { + // Load all plugins at the same time + Map pluginsToConvert = new HashMap<>(); + for (Map map : fileConfig.getMapList(PLUGINS_TO_CONVERT)) { + String[] pluginCommands; + if (map.values().size() == 1 && map.values().iterator().next() == null) { + pluginCommands = new String[0]; + } else { + @SuppressWarnings("unchecked") + List commands = (List) map.values().iterator().next(); + pluginCommands = commands.toArray(new String[0]); + } + + // Get the plugin, if it doesn't exist, scream in the console (but + // don't crash, we want to continue!) + final JavaPlugin plugin = getAndValidatePlugin((String) map.keySet().iterator().next()); + if (plugin != null) { + pluginsToConvert.put(plugin, pluginCommands); + } + } + + // Convert plugin commands + for (Entry pluginToConvert : pluginsToConvert.entrySet()) { + if (pluginToConvert.getValue().length == 0) { + Converter.convert(pluginToConvert.getKey()); + } else { + for (String command : pluginToConvert.getValue()) { + new AdvancedConverter(pluginToConvert.getKey(), command).convert(); + } + } + } + + // Convert all arbitrary commands + for (String commandName : fileConfig.getStringList("other-commands-to-convert")) { + new AdvancedConverter(commandName).convertCommand(); + } + } + + private JavaPlugin getAndValidatePlugin(String pluginName) { + Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (plugin != null) { + if (plugin instanceof JavaPlugin javaPlugin) { + return javaPlugin; + } else { + new InvalidPluginException("Plugin " + pluginName + " is not a JavaPlugin!").printStackTrace(); + } + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + return null; + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + } + + /** + * In contrast to the superclass' method {@link org.bukkit.plugin.java.JavaPlugin#saveDefaultConfig()}, + * this doesn't fail silently if the config.yml already exists but instead will update the config with + * new values if available. + *

+ * This should fail silently if all values are set already. + */ + @Override + public void saveDefaultConfig() { + File configFile = new File(getDataFolder(), "config.yml"); + BukkitConfigurationAdapter.createMinimalInstance(configFile).saveDefaultConfig( + DefaultBukkitConfig.createDefaultPaperConfig(), + getDataFolder(), + getLogger() + ); + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/src/main/resources/plugin.yml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/resources/plugin.yml similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/src/main/resources/plugin.yml rename to commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/resources/plugin.yml diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/LICENSE b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/LICENSE similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade/LICENSE rename to commandapi-platforms/commandapi-paper/commandapi-paper-shade/LICENSE diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/javadoc/README.md b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/javadoc/README.md new file mode 100644 index 000000000..809bd4251 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/javadoc/README.md @@ -0,0 +1 @@ +# commandapi-shade \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml new file mode 100644 index 000000000..a5d7c1176 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 11.0.0-SNAPSHOT + + + commandapi-paper-shade + Paper support shade library + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-paper-vh + ${project.version} + + + dev.jorel + commandapi-paper-nms-dependency + ${project.version} + pom + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + normal + package + + shade + + + true + true + + + + dev.jorel:commandapi-core + + dev/jorel/commandapi/CommandAPIVersionHandler** + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml new file mode 100644 index 000000000..32e867d77 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 11.0.0-SNAPSHOT + + + commandapi-paper-vh + Paper support version handler + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + dev.jorel + commandapi-paper-nms-dependency + ${project.version} + pom + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java new file mode 100644 index 000000000..286b24dfe --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -0,0 +1,72 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.exceptions.UnsupportedVersionException; +import dev.jorel.commandapi.nms.APITypeProvider; +import dev.jorel.commandapi.nms.PaperNMS; +import dev.jorel.commandapi.nms.PaperNMS_1_20_R4; +import dev.jorel.commandapi.nms.PaperNMS_1_21_R1; +import dev.jorel.commandapi.nms.PaperNMS_1_21_R2; +import dev.jorel.commandapi.nms.PaperNMS_1_21_R3; +import dev.jorel.commandapi.nms.PaperNMS_1_21_R4; +import dev.jorel.commandapi.nms.PaperNMS_1_21_R5; +import org.bukkit.Bukkit; +import io.papermc.paper.ServerBuildInfo; + +public abstract class CommandAPIVersionHandler { + + static LoadContext getPlatform() { + return new LoadContext(new CommandAPIPaper<>()); + } + + @SuppressWarnings("ConstantValue") + static Object getVersion() { + String latestMajorVersion = "21"; // Change this for Minecraft's major update + + try { + if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) { + return new VersionContext(new APITypeProvider(new PaperNMS_1_21_R5()), () -> { + CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); + CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + }); + } else { + String version = ServerBuildInfo.buildInfo().minecraftVersionId(); + PaperNMS versionAdapter = switch (version) { + case "1.20.6" -> new PaperNMS_1_20_R4(); + case "1.21", "1.21.1" -> new PaperNMS_1_21_R1(); + case "1.21.2", "1.21.3" -> new PaperNMS_1_21_R2(); + case "1.21.4" -> new PaperNMS_1_21_R3(); + case "1.21.5" -> new PaperNMS_1_21_R4(); + case "1.21.6" -> new PaperNMS_1_21_R5(); + default -> null; + }; + if (versionAdapter != null) { + return new VersionContext(new APITypeProvider(versionAdapter)); + } + if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) { + String currentMajorVersion = version.split("\\.")[1]; + if (latestMajorVersion.equals(currentMajorVersion)) { + return new VersionContext(new APITypeProvider(new PaperNMS_1_21_R5()), () -> { + CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation."); + CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + }); + } + } + throw new UnsupportedVersionException(version); + } + } catch (Throwable error) { + if (error instanceof ClassNotFoundException cnfe) { + // Thrown when users use versions before the ServerBuildInfo was added. We should inform them + // to update since Paper 1.20.6 was experimental then anyway + throw new IllegalStateException("The CommandAPI doesn't support any version before 1.20.6 build 79. Please update!", cnfe); + } + // Something went sideways when trying to load a platform. This probably means we're shading the wrong mappings. + // Because this is an error we'll just rethrow this (instead of piping it into logError, which we can't really + // do anyway since the CommandAPILogger isn't loaded), but include some helpful(?) logging that might point + // users in the right direction + throw new IllegalStateException("The CommandAPI's NMS hook failed to load! This version of the CommandAPI is " + + (MojangMappedVersionHandler.isMojangMapped() ? "Mojang" : "Spigot") + "-mapped. Have you checked that " + + "you are using a CommandAPI version that matches the mappings that your plugin is using?", error); + } + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java diff --git a/commandapi-platforms/commandapi-paper/pom.xml b/commandapi-platforms/commandapi-paper/pom.xml new file mode 100644 index 000000000..911d50a6c --- /dev/null +++ b/commandapi-platforms/commandapi-paper/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + dev.jorel + commandapi-platforms + 11.0.0-SNAPSHOT + + + commandapi-paper + Paper support + pom + + + 1.20.6-R0.1-SNAPSHOT + + + + commandapi-paper-annotations + commandapi-paper-core + commandapi-paper-vh + commandapi-paper-mojang-mapped + commandapi-paper-nms + commandapi-paper-shade + commandapi-paper-plugin + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml new file mode 100644 index 000000000..9b5b9ace0 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 11.0.0-SNAPSHOT + + + commandapi-spigot-annotations + Spigot Annotations + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + dev.jorel + commandapi-annotations + ${project.version} + compile + + + dev.jorel + commandapi-spigot-core + ${project.version} + + + com.google.auto.service + auto-service + ${auto-service.version} + provided + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + testCompile + + + + dev.jorel.commandapi.annotations.Annotations + + + + + + + + + \ No newline at end of file diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java similarity index 94% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java index 8e6c6eda3..c5c99c293 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/Annotations.java @@ -20,37 +20,13 @@ *******************************************************************************/ package dev.jorel.commandapi.annotations; -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.annotation.Annotation; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.Processor; -import javax.annotation.processing.RoundEnvironment; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; -import javax.lang.model.type.ExecutableType; -import javax.tools.Diagnostic.Kind; -import javax.tools.JavaFileObject; - import com.google.auto.service.AutoService; - import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandPermission; import dev.jorel.commandapi.annotations.arguments.AAdvancementArgument; -import dev.jorel.commandapi.annotations.arguments.AAdventureChatArgument; -import dev.jorel.commandapi.annotations.arguments.AAdventureChatComponentArgument; import dev.jorel.commandapi.annotations.arguments.AAngleArgument; +import dev.jorel.commandapi.annotations.arguments.AAsyncPlayerProfileArgument; import dev.jorel.commandapi.annotations.arguments.AAxisArgument; -import dev.jorel.commandapi.annotations.arguments.AAsyncOfflinePlayerArgument; import dev.jorel.commandapi.annotations.arguments.ABiomeArgument; import dev.jorel.commandapi.annotations.arguments.ABlockPredicateArgument; import dev.jorel.commandapi.annotations.arguments.ABlockStateArgument; @@ -63,7 +39,7 @@ import dev.jorel.commandapi.annotations.arguments.AEntitySelectorArgument; import dev.jorel.commandapi.annotations.arguments.AEntityTypeArgument; import dev.jorel.commandapi.annotations.arguments.AFloatArgument; -import dev.jorel.commandapi.annotations.arguments.AFloatRangeArgument; +import dev.jorel.commandapi.annotations.arguments.ADoubleRangeArgument; import dev.jorel.commandapi.annotations.arguments.AFunctionArgument; import dev.jorel.commandapi.annotations.arguments.AGreedyStringArgument; import dev.jorel.commandapi.annotations.arguments.AIntegerArgument; @@ -81,9 +57,8 @@ import dev.jorel.commandapi.annotations.arguments.ANamespacedKeyArgument; import dev.jorel.commandapi.annotations.arguments.AObjectiveArgument; import dev.jorel.commandapi.annotations.arguments.AObjectiveCriteriaArgument; -import dev.jorel.commandapi.annotations.arguments.AOfflinePlayerArgument; import dev.jorel.commandapi.annotations.arguments.AParticleArgument; -import dev.jorel.commandapi.annotations.arguments.APlayerArgument; +import dev.jorel.commandapi.annotations.arguments.APlayerProfileArgument; import dev.jorel.commandapi.annotations.arguments.APotionEffectArgument; import dev.jorel.commandapi.annotations.arguments.ARecipeArgument; import dev.jorel.commandapi.annotations.arguments.ARotationArgument; @@ -100,28 +75,52 @@ import dev.jorel.commandapi.arguments.LocationType; import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.ExecutableType; +import javax.tools.Diagnostic.Kind; +import javax.tools.JavaFileObject; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.stream.Collectors; +import java.util.stream.Stream; + /** * The main annotation processor for annotation-based arguments */ @AutoService(Processor.class) public class Annotations extends AbstractProcessor { - private static final Class[] ARGUMENT_ANNOTATIONS = new Class[] { AAdvancementArgument.class, - AAdventureChatArgument.class, AAdventureChatComponentArgument.class, AAngleArgument.class, - AAxisArgument.class, AAsyncOfflinePlayerArgument.class, ABiomeArgument.class, ABlockPredicateArgument.class, ABlockStateArgument.class, - ABooleanArgument.class, AChatArgument.class, AChatColorArgument.class, AChatComponentArgument.class, - ADoubleArgument.class, AEnchantmentArgument.class, AEntitySelectorArgument.ManyEntities.class, - AEntitySelectorArgument.ManyPlayers.class, AEntitySelectorArgument.OneEntity.class, - AEntitySelectorArgument.OnePlayer.class, AEntityTypeArgument.class, - AFloatArgument.class, AFloatRangeArgument.class, AFunctionArgument.class, + private static final Class[] ARGUMENT_ANNOTATIONS = new Class[] { AAdvancementArgument.class, + AAngleArgument.class, AAxisArgument.class, AAsyncPlayerProfileArgument.class, ABiomeArgument.class, ABlockPredicateArgument.class, + ABlockStateArgument.class, ABooleanArgument.class, AChatArgument.class, + AChatColorArgument.class, AChatComponentArgument.class, ADoubleArgument.class, + AEnchantmentArgument.class, AEntitySelectorArgument.ManyEntities.class, AEntitySelectorArgument.ManyPlayers.class, + AEntitySelectorArgument.OneEntity.class, AEntitySelectorArgument.OnePlayer.class, AEntityTypeArgument.class, + AFloatArgument.class, ADoubleRangeArgument.class, AFunctionArgument.class, AGreedyStringArgument.class, AIntegerArgument.class, AIntegerRangeArgument.class, AItemStackArgument.class, AItemStackPredicateArgument.class, ALiteralArgument.class, ALocation2DArgument.class, ALocationArgument.class, ALongArgument.class, ALootTableArgument.class, AMathOperationArgument.class, AMultiLiteralArgument.class, ANamespacedKeyArgument.class, ANBTCompoundArgument.class, AObjectiveArgument.class, - AObjectiveCriteriaArgument.class, AOfflinePlayerArgument.class, AParticleArgument.class, APlayerArgument.class, + AObjectiveCriteriaArgument.class, AParticleArgument.class, APlayerProfileArgument.class, APotionEffectArgument.class, ARecipeArgument.class, ARotationArgument.class, AScoreboardSlotArgument.class, AScoreHolderArgument.Single.class, AScoreHolderArgument.Multiple.class, ASoundArgument.class, AStringArgument.class, ATeamArgument.class, - ATextArgument.class, ATimeArgument.class, AUUIDArgument.class, AWorldArgument.class}; + ATextArgument.class, ATimeArgument.class, AUUIDArgument.class, AWorldArgument.class }; // List of stuff we can deal with @Override diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncOfflinePlayerArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncPlayerProfileArgument.java similarity index 52% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncOfflinePlayerArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncPlayerProfileArgument.java index eaf983fb6..78ccec39d 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncOfflinePlayerArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AAsyncPlayerProfileArgument.java @@ -1,17 +1,15 @@ package dev.jorel.commandapi.annotations.arguments; -import dev.jorel.commandapi.arguments.AsyncOfflinePlayerArgument; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Annotation equivalent of the {@link AsyncOfflinePlayerArgument} + * Annotation equivalent of the {@link dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument} */ -@Primitive("java.util.concurrent.CompletableFuture") +@Primitive("java.util.concurrent.CompletableFuture>") @Retention(RetentionPolicy.SOURCE) @Target(ElementType.PARAMETER) -public @interface AAsyncOfflinePlayerArgument { +public @interface AAsyncPlayerProfileArgument { } \ No newline at end of file diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java similarity index 100% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatArgument.java diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java similarity index 100% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatColorArgument.java diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java similarity index 100% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AChatComponentArgument.java diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerProfileArgument.java similarity index 88% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerProfileArgument.java index 048f128a3..7fcd0c59c 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/APlayerProfileArgument.java @@ -25,13 +25,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import dev.jorel.commandapi.arguments.PlayerArgument; - /** - * Annotation equivalent of the {@link PlayerArgument} + * Annotation equivalent of the {@link dev.jorel.commandapi.arguments.PlayerProfileArgument} */ -@Primitive("org.bukkit.entity.Player") +@Primitive("java.util.List") @Retention(RetentionPolicy.SOURCE) @Target(ElementType.PARAMETER) -public @interface APlayerArgument { +public @interface APlayerProfileArgument { } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml new file mode 100644 index 000000000..269262351 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 11.0.0-SNAPSHOT + + + commandapi-spigot-core + Spigot support core library + + + + minecraft-libraries + https://libraries.minecraft.net + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + + + + dev.jorel + commandapi-bukkit-core + ${project.version} + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + dev.jorel + commandapi-preprocessor + ${project.version} + provided + + + com.mojang + brigadier + 1.0.18 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -Xlint + + + dev.jorel.commandapi.preprocessor.Preprocessor + + + + + org.jacoco + jacoco-maven-plugin + + + + default-prepare-agent + + prepare-agent + + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java new file mode 100644 index 000000000..72eea29cf --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java @@ -0,0 +1,134 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.commandsenders.BukkitBlockCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitConsoleCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitEntity; +import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitPlayer; +import dev.jorel.commandapi.commandsenders.BukkitProxiedCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitRemoteConsoleCommandSender; +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; +import dev.jorel.commandapi.nms.NMS; +import dev.jorel.commandapi.nms.SpigotNMS; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.Bukkit; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.ProxiedCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.server.ServerLoadEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public abstract class CommandAPISpigot extends CommandAPIBukkit implements SpigotNMS { + + private static CommandAPISpigot spigot; + + @SuppressWarnings("unchecked") + protected CommandAPISpigot() { + this.nms = (NMS) bukkitNMS(); + CommandAPISpigot.spigot = this; + } + + @SuppressWarnings("unchecked") + public static CommandAPISpigot getSpigot() { + if (spigot != null) { + return (CommandAPISpigot) spigot; + } + throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + } + + public static InternalSpigotConfig getConfiguration() { + return (InternalSpigotConfig) CommandAPIBukkit.getConfiguration(); + } + + private static void setInternalConfig(InternalSpigotConfig config) { + CommandAPIBukkit.config = config; + } + + @Override + public void onLoad(CommandAPIConfig config) { + if (config instanceof CommandAPISpigotConfig spigotConfig) { + CommandAPISpigot.setInternalConfig(new InternalSpigotConfig(spigotConfig)); + } else { + CommandAPI.logError("CommandAPIBukkit was loaded with non-Bukkit config!"); + CommandAPI.logError("Attempts to access Bukkit-specific config variables will fail!"); + } + super.onLoad(); + } + + /** + * Enables the CommandAPI. This should be placed at the start of your + * onEnable() method. + */ + @Override + public void onEnable() { + super.plugin = getConfiguration().getPlugin(); + + Bukkit.getScheduler().scheduleSyncDelayedTask(CommandAPIBukkit.get().plugin, () -> { + // Sort out permissions after the server has finished registering them all + CommandAPIBukkit.get().getCommandRegistrationStrategy().runTasksAfterServerStart(); + if (!getConfiguration().skipReloadDatapacks()) { + CommandAPIBukkit.get().reloadDataPacks(); + } + CommandAPIBukkit.get().updateHelpForCommands(CommandAPI.getRegisteredCommands()); + }, 0L); + + super.stopCommandRegistrations(); + } + + @Override + public CommandMap getCommandMap() { + return getNMS().getSimpleCommandMap(); + } + + @Override + public Platform activePlatform() { + return Platform.SPIGOT; + } + + @Override + public BukkitCommandSender wrapCommandSender(CommandSender sender) { + if (sender instanceof BlockCommandSender block) { + return new BukkitBlockCommandSender(block); + } + if (sender instanceof ConsoleCommandSender console) { + return new BukkitConsoleCommandSender(console); + } + if (sender instanceof Player player) { + return new BukkitPlayer(player); + } + if (sender instanceof org.bukkit.entity.Entity entity) { + return new BukkitEntity(entity); + } + if (sender instanceof NativeProxyCommandSender nativeProxy) { + return new BukkitNativeProxyCommandSender(nativeProxy); + } + if (sender instanceof ProxiedCommandSender proxy) { + return new BukkitProxiedCommandSender(proxy); + } + if (sender instanceof RemoteConsoleCommandSender remote) { + return new BukkitRemoteConsoleCommandSender(remote); + } + throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender"); + } + + /** + * Forces a command to return a success value of 0 + * + * @param message Description of the error message, formatted as an array of base components + * @return a {@link dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException} that wraps Brigadier's + * {@link com.mojang.brigadier.exceptions.CommandSyntaxException} + */ + public static WrapperCommandSyntaxException failWithBaseComponents(BaseComponent... message) { + return CommandAPI.failWithMessage(BukkitTooltip.messageFromBaseComponents(message)); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigotConfig.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigotConfig.java new file mode 100644 index 000000000..d360cf68c --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigotConfig.java @@ -0,0 +1,29 @@ +package dev.jorel.commandapi; + +import org.bukkit.plugin.java.JavaPlugin; + +public class CommandAPISpigotConfig extends CommandAPIBukkitConfig { + + JavaPlugin plugin; + + public CommandAPISpigotConfig(JavaPlugin plugin) { + super(plugin.getName()); + this.plugin = plugin; + } + + /** + * Sets whether the CommandAPI should skip its datapack reload step after the server + * has finished loading. + * @param skip whether the CommandAPI should skip reloading datapacks when the server has finished loading + * @return this CommandAPIBukkitConfig + */ + public CommandAPISpigotConfig skipReloadDatapacks(boolean skip) { + this.skipReloadDatapacks = skip; + return this; + } + + @Override + public CommandAPISpigotConfig instance() { + return this; + } +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/InternalSpigotConfig.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/InternalSpigotConfig.java new file mode 100644 index 000000000..4a3b7ab2b --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/InternalSpigotConfig.java @@ -0,0 +1,21 @@ +package dev.jorel.commandapi; + +import org.bukkit.plugin.java.JavaPlugin; + +public class InternalSpigotConfig extends InternalBukkitConfig { + + private final JavaPlugin plugin; + + public InternalSpigotConfig(CommandAPISpigotConfig config) { + super(config); + this.plugin = config.plugin; + } + + /** + * @return the {@link JavaPlugin} loading the CommandAPI + */ + public JavaPlugin getPlugin() { + return plugin; + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/AsyncPlayerProfileArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/AsyncPlayerProfileArgument.java new file mode 100644 index 000000000..41e6b565f --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/AsyncPlayerProfileArgument.java @@ -0,0 +1,50 @@ +package dev.jorel.commandapi.arguments; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.executors.CommandArguments; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +/** + * An argument that represents a list of the Bukkit PlayerProfile object with asynchronous support. + * + * @since 11.0.0 + */ +public class AsyncPlayerProfileArgument extends SafeOverrideableArgument>, PlayerProfile> { + + /** + * A PlayerProfile argument. Returns a {@link List} + * + * @param nodeName the name of the node for this argument + */ + public AsyncPlayerProfileArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentProfile(), PlayerProfile::getName); + } + + @SuppressWarnings("unchecked") + @Override + public Class>> getPrimitiveType() { + return (Class>>) (Class) CompletableFuture.class; + } + + @Override + public CommandAPIArgumentType getArgumentType() { + return CommandAPIArgumentType.ASYNC_OFFLINE_PLAYER; + } + + @Override + public CompletableFuture> parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) { + return CompletableFuture.supplyAsync(() -> { + try { + return CommandAPISpigot.getSpigot().getProfile(cmdCtx, key); + } catch (CommandSyntaxException e) { + throw new RuntimeException(e); + } + }); + } +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java similarity index 93% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java index 2ba947e84..462559bb3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatArgument.java @@ -22,8 +22,8 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; - import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.exceptions.SpigotNotFoundException; import dev.jorel.commandapi.executors.CommandArguments; import net.md_5.bungee.api.chat.BaseComponent; @@ -44,7 +44,7 @@ public class ChatArgument extends Argument implements GreedyArg * @param nodeName the name of the node for argument */ public ChatArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentChat()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChat()); try { Class.forName("org.spigotmc.SpigotConfig"); @@ -65,6 +65,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public BaseComponent[] parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getChat(cmdCtx, key); + return CommandAPISpigot.getSpigot().getChat(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java similarity index 89% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java index 9936ed1d2..216a66315 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatColorArgument.java @@ -23,6 +23,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.executors.CommandArguments; import org.bukkit.ChatColor; @@ -44,7 +45,7 @@ public class ChatColorArgument extends SafeOverrideableArgument) ChatColor::name).andThen(String::toLowerCase)); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChatFormat(), ((Function) ChatColor::name).andThen(String::toLowerCase)); } @Override @@ -59,6 +60,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public ChatColor parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getChatColor(cmdCtx, key); + return CommandAPISpigot.getSpigot().getChatColor(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java similarity index 92% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java index 774d4a8ff..145ac1fa6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/ChatComponentArgument.java @@ -23,6 +23,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.exceptions.SpigotNotFoundException; import dev.jorel.commandapi.executors.CommandArguments; import net.md_5.bungee.api.chat.BaseComponent; @@ -45,7 +46,7 @@ public class ChatComponentArgument extends Argument { * @param nodeName the name of the node for argument */ public ChatComponentArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentChatComponent()); + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentChatComponent()); try { Class.forName("org.spigotmc.SpigotConfig"); @@ -67,6 +68,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public BaseComponent[] parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getChatComponent(cmdCtx, key); + return CommandAPISpigot.getSpigot().getChatComponent(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java similarity index 93% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java index 09bd09bb9..16a6b9763 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/CustomArgument.java @@ -20,22 +20,20 @@ *******************************************************************************/ package dev.jorel.commandapi.arguments; -import java.io.Serializable; - -import org.bukkit.command.CommandSender; - import com.mojang.brigadier.LiteralMessage; import com.mojang.brigadier.Message; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; - import dev.jorel.commandapi.BukkitTooltip; import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIHandler; import dev.jorel.commandapi.executors.CommandArguments; -import net.kyori.adventure.text.ComponentLike; import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.command.CommandSender; + +import java.io.Serializable; /** * An argument that represents any custom object @@ -221,7 +219,6 @@ public String toString() { public static class CustomArgumentException extends Exception { private BaseComponent[] errorBaseComponent = null; - private ComponentLike errorComponent = null; private String errorMessage = null; private MessageBuilder errorMessageBuilder = null; @@ -232,7 +229,7 @@ private CustomArgumentException() { /** * Constructs a CustomArgumentException with a given error message - * + * * @param errorMessage the error message to display to the user when this * exception is thrown */ @@ -253,17 +250,6 @@ public static CustomArgumentException fromString(String errorMessage) { exception.errorMessage = errorMessage; return exception; } - /** - * Constructs a CustomArgumentException with a given error message - * - * @param errorMessage the error message to display to the user when this - * exception is thrown - */ - public static CustomArgumentException fromAdventureComponent(ComponentLike errorMessage) { - CustomArgumentException exception = new CustomArgumentException(); - exception.errorComponent = errorMessage; - return exception; - } /** * Constructs a CustomArgumentException with a given error message @@ -292,12 +278,6 @@ public CommandSyntaxException toCommandSyntax(String result, CommandContext c return new SimpleCommandExceptionType(brigadierMessage).create(); } - if (errorComponent != null) { - // Deal with Adventure Component - Message brigadierMessage = BukkitTooltip.messageFromAdventureComponent(errorComponent); - return new SimpleCommandExceptionType(brigadierMessage).create(); - } - if (errorMessageBuilder != null) { // Deal with MessageBuilder String errorMsg = errorMessageBuilder.toString().replace(INPUT, result).replace(FULL_INPUT, @@ -307,7 +287,8 @@ public CommandSyntaxException toCommandSyntax(String result, CommandContext c if (errorMessage != null) { // Deal with String - return CommandAPIBukkit.get().getPaper().getExceptionFromString(errorMessage).getException(); + BaseComponent[] component = TextComponent.fromLegacyText(errorMessage); + return new SimpleCommandExceptionType(BukkitTooltip.messageFromBaseComponents(component)).create(); } throw new IllegalStateException("No error component, error message creator or error message specified"); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/OfflinePlayerArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/PlayerProfileArgument.java similarity index 61% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/OfflinePlayerArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/PlayerProfileArgument.java index 34321f297..c8ec8fe1c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/OfflinePlayerArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/PlayerProfileArgument.java @@ -23,38 +23,43 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.executors.CommandArguments; -import org.bukkit.OfflinePlayer; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; /** - * An argument that represents the Bukkit Player object + * An argument that represents the Spigot PlayerProfile object. + *

+ * Note that this Argument internally references Mojang's authentication servers to resolve + * usernames, which gives it a slight performance overhead compared to {@link dev.jorel.commandapi.arguments.EntitySelectorArgument.OnePlayer}. * - * @since 6.0.0 + * @since 11.0.0 */ -public class OfflinePlayerArgument extends SafeOverrideableArgument { +public class PlayerProfileArgument extends SafeOverrideableArgument { /** - * A Player argument. Produces a single player, regardless of whether - * @a, @p, @r or @e is used. + * A PlayerProfile argument. Returns a {@link List} * * @param nodeName the name of the node for this argument */ - public OfflinePlayerArgument(String nodeName) { - super(nodeName, CommandAPIBukkit.get()._ArgumentProfile(), OfflinePlayer::getName); + public PlayerProfileArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentProfile(), PlayerProfile::getName); } @Override - public Class getPrimitiveType() { - return OfflinePlayer.class; + public Class getPrimitiveType() { + return List.class; } @Override public CommandAPIArgumentType getArgumentType() { - return CommandAPIArgumentType.OFFLINE_PLAYER; + return CommandAPIArgumentType.PLAYER; } @Override - public OfflinePlayer parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getOfflinePlayer(cmdCtx, key); + public List parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { + return CommandAPISpigot.getSpigot().getProfile(cmdCtx, key); } } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java new file mode 100644 index 000000000..59f557a39 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java @@ -0,0 +1,25 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.CommandNode; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public interface SpigotNMS { + + BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + ChatColor getChatColor(CommandContext cmdCtx, String key); + + BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + NMS bukkitNMS(); + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml new file mode 100644 index 000000000..51e576d68 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 10.2.0-SNAPSHOT + + + commandapi-spigot-documentation-code + Spigot documentation code + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + + + + + com.mojang + brigadier + 1.0.17 + provided + + + com.mojang + authlib + 3.3.39 + provided + + + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + + + dev.jorel + commandapi-kotlin-spigot + ${project.version} + + + + + de.tr7zw + item-nbt-api + 2.11.1 + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + test-compile + + test-compile + + + + ${project.basedir}/src/main/kotlin/ + + + + + + 16 + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java new file mode 100644 index 000000000..460d73d23 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java @@ -0,0 +1,120 @@ +package dev.jorel.commandapi.examples.java; + +import de.tr7zw.changeme.nbtapi.NBTContainer; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandAPISpigotConfig; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.PlayerProfileArgument; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; +import org.bukkit.plugin.java.JavaPlugin; + +public class Examples { + +void argument_chatSpigot() { +/* ANCHOR: argumentChatSpigot1 */ +new CommandAPICommand("namecolor") + .withArguments(new ChatColorArgument("chatcolor")) + .executesPlayer((player, args) -> { + ChatColor color = (ChatColor) args.get("chatcolor"); + player.setDisplayName(color + player.getName()); + }) + .register(); +/* ANCHOR_END: argumentChatSpigot1 */ + +/* ANCHOR: argumentChatSpigot2 */ +new CommandAPICommand("makebook") + .withArguments(new PlayerProfileArgument("player")) + .withArguments(new ChatComponentArgument("contents")) + .executes((sender, args) -> { + Player player = (Player) args.get("player"); + BaseComponent[] arr = (BaseComponent[]) args.get("contents"); + + // Create book + ItemStack is = new ItemStack(Material.WRITTEN_BOOK); + BookMeta meta = (BookMeta) is.getItemMeta(); + meta.setTitle("Custom Book"); + meta.setAuthor(player.getName()); + meta.spigot().setPages(arr); + is.setItemMeta(meta); + + // Give player the book + player.getInventory().addItem(is); + }) + .register(); +/* ANCHOR_END: argumentChatSpigot2 */ + +/* ANCHOR: argumentChatSpigot3 */ +new CommandAPICommand("pbroadcast") + .withArguments(new ChatArgument("message")) + .executes((sender, args) -> { + BaseComponent[] message = (BaseComponent[]) args.get("message"); + + // Broadcast the message to everyone on the server + Bukkit.getServer().spigot().broadcast(message); + }) + .register(); +/* ANCHOR_END: argumentChatSpigot3 */ +} + +class argument_nbt extends JavaPlugin { +/* ANCHOR: argumentNBT1 */ +@Override +public void onLoad() { + CommandAPI.onLoad(new CommandAPISpigotConfig(this) + .initializeNBTAPI(NBTContainer.class, NBTContainer::new) + ); +} +/* ANCHOR_END: argumentNBT1 */ +} + +class setupShading { +JavaPlugin plugin = new JavaPlugin() { +}; + +{ +/* ANCHOR: setupShading1 */ +CommandAPI.onLoad(new CommandAPISpigotConfig(plugin).silentLogs(true)); +/* ANCHOR_END: setupShading1 */ +} + +/* ANCHOR: setupShading2 */ +class MyPlugin extends JavaPlugin { + + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPISpigotConfig(this).verboseOutput(true)); // Load with verbose output + + new CommandAPICommand("ping") + .executes((sender, args) -> { + sender.sendMessage("pong!"); + }) + .register(); + } + + @Override + public void onEnable() { + CommandAPISpigot.onEnable(); + + // Register commands, listeners etc. + } + + @Override + public void onDisable() { + CommandAPI.onDisable(); + } + +} +/* ANCHOR_END: setupShading2 */ +} + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt new file mode 100644 index 000000000..99dee753f --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt @@ -0,0 +1,116 @@ +package dev.jorel.commandapi.examples.kotlin + +import de.tr7zw.changeme.nbtapi.NBTContainer +import dev.jorel.commandapi.CommandAPI +import dev.jorel.commandapi.CommandAPICommand +import dev.jorel.commandapi.CommandAPISpigotConfig +import dev.jorel.commandapi.arguments.* +import dev.jorel.commandapi.executors.CommandArguments +import dev.jorel.commandapi.executors.CommandExecutor +import dev.jorel.commandapi.executors.PlayerCommandExecutor +import net.md_5.bungee.api.chat.BaseComponent +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.meta.BookMeta +import org.bukkit.plugin.java.JavaPlugin + +class Examples { + +fun argument_chatSpigot() { +/* ANCHOR: argumentChatSpigot1 */ +CommandAPICommand("namecolor") + .withArguments(ChatColorArgument("chatColor")) + .executesPlayer(PlayerCommandExecutor { player: Player, args: CommandArguments -> + val color = args["chatColor"] as ChatColor + player.setDisplayName("$color${player.name}") + }) + .register() +/* ANCHOR_END: argumentChatSpigot1 */ + +/* ANCHOR: argumentChatSpigot2 */ +CommandAPICommand("makebook") + .withArguments(PlayerProfileArgument("player")) + .withArguments(ChatComponentArgument("contents")) + .executes(CommandExecutor { _, args -> + val player = args["player"] as Player + val arr = args["contents"] as Array + + // Create book + val item = ItemStack(Material.WRITTEN_BOOK) + val meta = item.itemMeta as BookMeta + meta.title = "Custom Book" + meta.author = player.name + meta.spigot().setPages(arr) + item.itemMeta = meta + + // Give player the book + player.inventory.addItem(item) + }) + .register() +/* ANCHOR_END: argumentChatSpigot2 */ + +/* ANCHOR: argumentChatSpigot3 */ +CommandAPICommand("pbroadcast") + .withArguments(ChatArgument("message")) + .executes(CommandExecutor { _, args -> + val message = args["message"] as Array + + // Broadcast the message to everyone on the server + Bukkit.getServer().spigot().broadcast(*message) + }) + .register() +/* ANCHOR_END: argumentChatSpigot3 */ +} + +class argument_nbt : JavaPlugin() { + +/* ANCHOR: argumentNBT1 */ +override fun onLoad() { + CommandAPI.onLoad(CommandAPISpigotConfig(this) + .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) + ) +} +/* ANCHOR_END: argumentNBT1 */ +} + +class setupShading { +val plugin: JavaPlugin = object : JavaPlugin() {} + +fun setupShading1() { +/* ANCHOR: setupShading1 */ +CommandAPI.onLoad(CommandAPISpigotConfig(plugin).silentLogs(true)) +/* ANCHOR_END: setupShading1 */ +} + +/* ANCHOR: setupShading2 */ +class MyPlugin : JavaPlugin() { + + override fun onLoad() { + CommandAPI.onLoad(CommandAPISpigotConfig(this).verboseOutput(true)) // Load with verbose output + + CommandAPICommand("ping") + .executes(CommandExecutor { sender: CommandSender, _ -> + sender.sendMessage("pong!") + }) + .register() + } + + override fun onEnable() { + CommandAPI.onEnable(this) + + // Register commands, listeners etc. + } + + override fun onDisable() { + CommandAPI.onDisable() + } + +} +/* ANCHOR_END: setupShading2 */ +} + +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt new file mode 100644 index 000000000..22e0715ef --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt @@ -0,0 +1,62 @@ +package dev.jorel.commandapi.examples.kotlin + +import de.tr7zw.changeme.nbtapi.NBTContainer +import dev.jorel.commandapi.executors.CommandArguments +import dev.jorel.commandapi.kotlindsl.* +import net.md_5.bungee.api.chat.BaseComponent +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.meta.BookMeta + +class ExamplesKotlinDSL { + +fun argument_chatSpigot() { +/* ANCHOR: argumentChatSpigot1 */ +commandAPICommand("namecolor") { + chatColorArgument("chatcolor") + playerExecutor { player: Player, args: CommandArguments -> + val color = args["chatcolor"] as ChatColor + player.setDisplayName("$color${player.name}") + } +} +/* ANCHOR_END: argumentChatSpigot1 */ + +/* ANCHOR: argumentChatSpigot2 */ +commandAPICommand("makebook") { + playerArgument("player") + chatComponentArgument("contents") + anyExecutor { _, args -> + val player = args["player"] as Player + val array = args["contents"] as Array + + // Create book + val item = ItemStack(Material.WRITTEN_BOOK) + val meta = item.itemMeta as BookMeta + meta.title = "Custom Book" + meta.author = player.name + meta.spigot().setPages(array) + item.itemMeta = meta + + // Give player the book + player.inventory.addItem(item) + } +} +/* ANCHOR_END: argumentChatSpigot2 */ + +/* ANCHOR: argumentChatSpigot3 */ +commandAPICommand("pbroadcast") { + chatArgument("message") + anyExecutor { _, args -> + val message = args["message"] as Array + + // Broadcast the message to everyone on the server + Bukkit.getServer().spigot().broadcast(*message) + } +} +/* ANCHOR_END: argumentChatSpigot3 */ +} + +} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml new file mode 100644 index 000000000..f8d2896ef --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 11.0.0-SNAPSHOT + + + commandapi-spigot-mojang-mapped + Spigot mojang mapped dependency + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java new file mode 100644 index 000000000..80db4c1b7 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java @@ -0,0 +1,12 @@ +package dev.jorel.commandapi; + +/** + * This file handles loading the correct mappings information. The MojangMappedVersionHandler + * file within the commandapi-core module may not be used at run time. Instead, if a platform module + * wants to be mojang-mapped, they can replace it with this class where {@link #isMojangMapped()} returns {@code true}. + */ +public interface MojangMappedVersionHandler { + static boolean isMojangMapped() { + return true; + } +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml new file mode 100644 index 000000000..ce12493c1 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.20.2 + Spigot support for 1.20.2 + + + 1.20.2-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20.2 + ${project.version} + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.5 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java new file mode 100644 index 000000000..ed07d812b --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java @@ -0,0 +1,74 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R2.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R2.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public class SpigotNMS_1_20_R2 extends CommandAPISpigot { + + private NMS_1_20_R2 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R2(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml new file mode 100644 index 000000000..c64239e6c --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.20.3 + Spigot support for 1.20.3 + + + 1.20.4-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20.3 + ${project.version} + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.5 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java new file mode 100644 index 000000000..8967280b0 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java @@ -0,0 +1,74 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R3.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R3.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R3.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public class SpigotNMS_1_20_R3 extends CommandAPISpigot { + + private NMS_1_20_R3 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R3(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml new file mode 100644 index 000000000..738ab3633 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.20.5 + Spigot support for 1.20.5 + + + 1.20.6-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20.5 + ${project.version} + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java new file mode 100644 index 000000000..943c98ae9 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java @@ -0,0 +1,88 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R4.CraftServer; +import org.bukkit.craftbukkit.v1_20_R4.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R4.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R4.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public class SpigotNMS_1_20_R4 extends CommandAPISpigot { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_20_R4 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R4(() -> COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml new file mode 100644 index 000000000..fa3c77dc8 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.20 + Spigot support for 1.20 + + + 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.20 + ${project.version} + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.4 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java new file mode 100644 index 000000000..89ab4277d --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java @@ -0,0 +1,74 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_20_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R1.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_20_R1.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public class SpigotNMS_1_20_R1 extends CommandAPISpigot { + + private NMS_1_20_R1 bukkitNMS; + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key))); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_20_R1(); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml new file mode 100644 index 000000000..9f525f022 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.21.2 + Spigot support for 1.21.2 + + + 1.21.3-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.2 + ${project.version} + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java new file mode 100644 index 000000000..733561d67 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java @@ -0,0 +1,88 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R2.CraftServer; +import org.bukkit.craftbukkit.v1_21_R2.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R2.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R2.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public class SpigotNMS_1_21_R2 extends CommandAPISpigot { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R2 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R2(() -> COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml new file mode 100644 index 000000000..33fe3921d --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.21.4 + Spigot support for 1.21.4 + + + 1.21.4-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.4 + ${project.version} + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java new file mode 100644 index 000000000..057eb23f2 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java @@ -0,0 +1,88 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R3.CraftServer; +import org.bukkit.craftbukkit.v1_21_R3.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R3.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R3.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public class SpigotNMS_1_21_R3 extends CommandAPISpigot { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R3 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R3(() -> COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml new file mode 100644 index 000000000..de29d9110 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.21.5 + Spigot support for 1.21.5 + + + 1.21.5-R0.1-SNAPSHOT + 1.21.5-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.5 + ${project.version} + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java new file mode 100644 index 000000000..09caabe84 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java @@ -0,0 +1,88 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R4.CraftServer; +import org.bukkit.craftbukkit.v1_21_R4.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R4.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R4.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public class SpigotNMS_1_21_R4 extends CommandAPISpigot { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R4 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R4(() -> COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml new file mode 100644 index 000000000..21280efec --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml @@ -0,0 +1,149 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.21.6 + Spigot support for 1.21.6 + + + 1.21.6-R0.1-SNAPSHOT + 1.21.6-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.6 + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java new file mode 100644 index 000000000..6e287311a --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java @@ -0,0 +1,88 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R5.CraftServer; +import org.bukkit.craftbukkit.v1_21_R5.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R5.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R5.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public class SpigotNMS_1_21_R5 extends CommandAPISpigot { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R5 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(bukkitNMS.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(bukkitNMS.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key))); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R5(() -> COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml new file mode 100644 index 000000000..d6457d79a --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.21 + Spigot support for 1.21 + + + 1.21.1-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21 + ${project.version} + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java new file mode 100644 index 000000000..573d03ba5 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java @@ -0,0 +1,88 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R1.CraftServer; +import org.bukkit.craftbukkit.v1_21_R1.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R1.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R1.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public class SpigotNMS_1_21_R1 extends CommandAPISpigot { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R1 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { + return ComponentSerializer.parse(Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), COMMAND_BUILD_CONTEXT)); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return result instanceof GameProfileArgument.SelectorResult selectorResult + ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) + : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R1(() -> COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml similarity index 50% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/pom.xml rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml index bd57db4d1..6c2052bbd 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml @@ -1,34 +1,20 @@ - - - + + 4.0.0 - commandapi-bukkit-nms dev.jorel - 10.2.0-SNAPSHOT + commandapi-spigot-nms + 11.0.0-SNAPSHOT - 4.0.0 - commandapi-bukkit-nms-dependency-mojang-mapped - CommandAPI - Bukkit support Mojang-mapped NMS dependency + commandapi-spigot-nms-dependency-mojang-mapped + Spigot support Mojang-mapped NMS dependency pom - + dev.jorel commandapi-bukkit-nms-common @@ -36,13 +22,63 @@ mojang-mapped - + + + dev.jorel + commandapi-spigot-1.21.6 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.21.5 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.21.4 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.21.2 + ${project.version} + mojang-mapped + dev.jorel - commandapi-bukkit-1.21.6 + commandapi-spigot-1.21 ${project.version} mojang-mapped + + dev.jorel + commandapi-spigot-1.20.5 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.20.3 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.20.2 + ${project.version} + mojang-mapped + + + dev.jorel + commandapi-spigot-1.20 + ${project.version} + mojang-mapped + + + dev.jorel commandapi-bukkit-1.21.5 @@ -92,4 +128,5 @@ mojang-mapped + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml new file mode 100644 index 000000000..c2b6a6fc2 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml @@ -0,0 +1,113 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-nms-dependency + Spigot support Spigot-mapped NMS dependency + pom + + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + + + + + dev.jorel + commandapi-spigot-1.21.6 + ${project.version} + + + dev.jorel + commandapi-spigot-1.21.5 + ${project.version} + + + dev.jorel + commandapi-spigot-1.21.4 + ${project.version} + + + dev.jorel + commandapi-spigot-1.21.2 + ${project.version} + + + dev.jorel + commandapi-spigot-1.21 + ${project.version} + + + dev.jorel + commandapi-spigot-1.20.5 + ${project.version} + + + dev.jorel + commandapi-spigot-1.20.3 + ${project.version} + + + dev.jorel + commandapi-spigot-1.20.2 + ${project.version} + + + dev.jorel + commandapi-spigot-1.20 + ${project.version} + + + + + dev.jorel + commandapi-bukkit-1.21.5 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.21.4 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.21.2 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.21 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20.5 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20.3 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20.2 + ${project.version} + + + dev.jorel + commandapi-bukkit-1.20 + ${project.version} + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml new file mode 100644 index 000000000..b03ab718a --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 11.0.0-SNAPSHOT + + + commandapi-spigot-nms + Paper support NMS library + pom + + + commandapi-spigot-1.21.6 + commandapi-spigot-1.21.5 + commandapi-spigot-1.21.4 + commandapi-spigot-1.21.2 + commandapi-spigot-1.21 + commandapi-spigot-1.20.5 + commandapi-spigot-1.20.3 + commandapi-spigot-1.20.2 + commandapi-spigot-1.20 + + commandapi-spigot-nms-dependency + commandapi-spigot-nms-dependency-mojang-mapped + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml similarity index 61% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml index 601316ce3..6308ba5df 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml @@ -1,37 +1,16 @@ - - - - + + 4.0.0 - commandapi-bukkit dev.jorel - 10.2.0-SNAPSHOT + commandapi-spigot + 11.0.0-SNAPSHOT - 4.0.0 - - commandapi-bukkit-plugin-mojang-mapped - CommandAPI - Bukkit support Mojang-mapped plugin + commandapi-spigot-plugin-mojang-mapped + Spigot support Mojang-mapped plugin @@ -43,43 +22,33 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - papermc - https://repo.papermc.io/repository/maven-public/ - dev.jorel - commandapi-bukkit-core + commandapi-spigot-core ${project.version} compile - + dev.jorel - commandapi-bukkit-nms-dependency-mojang-mapped + commandapi-spigot-nms-dependency-mojang-mapped ${project.version} pom dev.jorel - commandapi-bukkit-vh + commandapi-spigot-vh ${project.version} dev.jorel - commandapi-bukkit-mojang-mapped + commandapi-spigot-mojang-mapped ${project.version} - - io.papermc.paper - paper-api - ${paper.version} - provided - org.spigotmc spigot-api @@ -111,8 +80,8 @@ shade - + dev.jorel:commandapi-core @@ -143,10 +112,6 @@ org.bukkit.craftbukkit.v1_21_R4 org.bukkit.craftbukkit - - org.bukkit.craftbukkit.v1_21_R5 - org.bukkit.craftbukkit - @@ -157,19 +122,9 @@ - org.apache.maven.plugins maven-jar-plugin - 3.4.2 - - - - mojang - - - empty-javadoc-jar @@ -184,6 +139,21 @@ + + + org.apache.maven.plugins + maven-jar-plugin + 3.4.1 + + + + mojang + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java new file mode 100644 index 000000000..0d22eacca --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java @@ -0,0 +1,314 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.arguments.AdvancementArgument; +import dev.jorel.commandapi.arguments.AngleArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument; +import dev.jorel.commandapi.arguments.AxisArgument; +import dev.jorel.commandapi.arguments.BiomeArgument; +import dev.jorel.commandapi.arguments.BlockPredicateArgument; +import dev.jorel.commandapi.arguments.BlockStateArgument; +import dev.jorel.commandapi.arguments.BooleanArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.CommandAPIArgumentType; +import dev.jorel.commandapi.arguments.CommandArgument; +import dev.jorel.commandapi.arguments.DoubleArgument; +import dev.jorel.commandapi.arguments.DoubleRangeArgument; +import dev.jorel.commandapi.arguments.EnchantmentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.FloatArgument; +import dev.jorel.commandapi.arguments.FunctionArgument; +import dev.jorel.commandapi.arguments.GreedyStringArgument; +import dev.jorel.commandapi.arguments.IntegerArgument; +import dev.jorel.commandapi.arguments.IntegerRangeArgument; +import dev.jorel.commandapi.arguments.ItemStackArgument; +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; +import dev.jorel.commandapi.arguments.Location2DArgument; +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.LongArgument; +import dev.jorel.commandapi.arguments.LootTableArgument; +import dev.jorel.commandapi.arguments.MathOperationArgument; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import dev.jorel.commandapi.arguments.NamespacedKeyArgument; +import dev.jorel.commandapi.arguments.ObjectiveArgument; +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; +import dev.jorel.commandapi.arguments.ParticleArgument; +import dev.jorel.commandapi.arguments.PlayerProfileArgument; +import dev.jorel.commandapi.arguments.PotionEffectArgument; +import dev.jorel.commandapi.arguments.RecipeArgument; +import dev.jorel.commandapi.arguments.RotationArgument; +import dev.jorel.commandapi.arguments.ScoreHolderArgument; +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; +import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.TeamArgument; +import dev.jorel.commandapi.arguments.TextArgument; +import dev.jorel.commandapi.arguments.TimeArgument; +import dev.jorel.commandapi.arguments.UUIDArgument; +import dev.jorel.commandapi.exceptions.InvalidNumberException; +import dev.jorel.commandapi.exceptions.UnknownArgumentException; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A command parsing system that converts string arguments into something way + * more useful + */ +class AdvancedConverter { + + /** + * Pattern for arguments, which are of the form {@code [type]} + *

    + *
  • {@code node_name} is a standard node name.
  • + *
  • {@code type} is either a namespaced key representing the argument + * (described in {@code conversionforownerssingleargs.md} in the main + * documentation), or a numerical range of the form {@code n..n}, {@code ..n} or + * {@code n..} where {@code n} is a constant integer or floating point + * number
  • + *
+ */ + private static final Pattern ARGUMENT_PATTERN = Pattern.compile("<(\\w+)>\\[([a-z:_]+|(?:[0-9\\.]+)?\\.\\.(?:[0-9\\.]+)?)\\]"); + + /** + * Pattern for literal, of the form {@code (node_name)}. It also supports + * multiple node names of the form + * {@code (node_name_1|node_name_2|...|node_name_n)} + */ + private static final Pattern LITERAL_PATTERN = Pattern.compile("\\(\\w+(\\|\\w+)*+\\)"); + + private final JavaPlugin plugin; + private final String command; + private int argumentIndex = 1; + + public AdvancedConverter(JavaPlugin plugin, String command) { + this.plugin = plugin; + this.command = command; + } + + public AdvancedConverter(String command) { + this.plugin = null; + this.command = command; + } + + public void convert() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(plugin, commandName); + } else { + Converter.convert(plugin, commandName, arguments); + } + + } + + public void convertCommand() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(commandName); + } else { + Converter.convert(commandName, arguments); + } + } + + /** + *
+	 * plugins-to-convert: 
+	 *   - Essentials: 
+	 *     - speed [0..10]
+	 *     - speed [minecraft:game_profile]
+	 *     - speed (walk|fly) [0..10]
+	 *     - speed (walk|fly) [0..10] [minecraft:game_profile]
+	 * 
+ */ + private List> parseArguments(String command) throws UnknownArgumentException, InvalidNumberException { + List> arguments = new ArrayList<>(); + String[] parts = command.split(" "); + for (argumentIndex = 1; argumentIndex < parts.length; argumentIndex++) { + arguments.add(parseArgument(parts[argumentIndex])); + } + return arguments; + } + + private boolean isRangeAnInteger(double value) { + return value == (long) value; + } + + private double parseValue(String bound) throws InvalidNumberException { + try { + return Double.parseDouble(bound); + } catch (NumberFormatException e) { + throw new InvalidNumberException(bound, command, argumentIndex); + } + } + + private Argument parseRange(String nodeName, String[] bounds) throws InvalidNumberException { + if (bounds.length == 1) { + // x.. + double value = parseValue(bounds[0]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, (long) value); + } else { + return new DoubleArgument(nodeName, value); + } + } else if (bounds[0].length() == 0) { + // ..x + double value = parseValue(bounds[1]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, Long.MIN_VALUE, (long) value); + } else { + return new DoubleArgument(nodeName, -Double.MAX_VALUE, value); + } + } else { + // x..x + double value0 = parseValue(bounds[0]); + double value1 = parseValue(bounds[1]); + if (!isRangeAnInteger(value0) || !isRangeAnInteger(value1)) { + return new DoubleArgument(nodeName, value0, value1); + } else { + return new LongArgument(nodeName, (long) value0, (long) value1); + } + } + } + + /* + * CodeFactor will always complain about this method because it's really bulky + * and adding a generator (i.e. Function>) inside the + * CommandAPIArgumentType class would be better, EXCEPT in practice, this is + * worse because then CommandAPIArgumentType would have to depend on every + * argument and every argument depends on CommandAPIArgumentType, so that would + * mean every argument would always have to be packaged in the CommandAPI - jar + * minimisation wouldn't be able to minimise this as best as it could. + * + * Additionally, we only need this for the plugin version of the CommandAPI, not + * the main API. + */ + @SuppressWarnings("rawtypes") + private Argument parseDefinedArgumentType(String argumentType, String nodeName) throws UnknownArgumentException { + return switch (CommandAPIArgumentType.fromInternal(argumentType)) { + case ADVANCEMENT -> new AdvancementArgument(nodeName); + case ADVENTURE_CHAT -> new ChatArgument(nodeName); + case ADVENTURE_CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case ANGLE -> new AngleArgument(nodeName); + case ASYNC_OFFLINE_PLAYER -> new AsyncPlayerProfileArgument(nodeName); + case AXIS -> new AxisArgument(nodeName); + case BIOME -> new BiomeArgument(nodeName); + case BLOCKSTATE -> new BlockStateArgument(nodeName); + case BLOCK_PREDICATE -> new BlockPredicateArgument(nodeName); + case CHAT -> new ChatArgument(nodeName); + case CHATCOLOR -> new ChatColorArgument(nodeName); + case CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case COMMAND -> new CommandArgument(nodeName); + case ENCHANTMENT -> new EnchantmentArgument(nodeName); + case ENTITY_SELECTOR -> new EntitySelectorArgument.OneEntity(nodeName); + case ENTITY_TYPE -> new EntityTypeArgument(nodeName); + case FLOAT_RANGE -> new DoubleRangeArgument(nodeName); + case FUNCTION -> new FunctionArgument(nodeName); + case INT_RANGE -> new IntegerRangeArgument(nodeName); + case ITEMSTACK -> new ItemStackArgument(nodeName); + case ITEMSTACK_PREDICATE -> new ItemStackPredicateArgument(nodeName); + case LOCATION -> new LocationArgument(nodeName, LocationType.BLOCK_POSITION); + case LOCATION_2D -> new Location2DArgument(nodeName, LocationType.BLOCK_POSITION); + case LOOT_TABLE -> new LootTableArgument(nodeName); + case MATH_OPERATION -> new MathOperationArgument(nodeName); + case NAMESPACED_KEY -> new NamespacedKeyArgument(nodeName); + case NBT_COMPOUND -> new NBTCompoundArgument(nodeName); + case OBJECTIVE -> new ObjectiveArgument(nodeName); + case OBJECTIVE_CRITERIA -> new ObjectiveCriteriaArgument(nodeName); + case PARTICLE -> new ParticleArgument(nodeName); + case PLAYER -> new PlayerProfileArgument(nodeName); + case POTION_EFFECT -> new PotionEffectArgument(nodeName); + case RECIPE -> new RecipeArgument(nodeName); + case ROTATION -> new RotationArgument(nodeName); + case SCOREBOARD_SLOT -> new ScoreboardSlotArgument(nodeName); + case SCORE_HOLDER -> new ScoreHolderArgument.Single(nodeName); + case SOUND -> new SoundArgument(nodeName); + case TEAM -> new TeamArgument(nodeName); + case TIME -> new TimeArgument(nodeName); + case UUID -> new UUIDArgument(nodeName); + case PRIMITIVE_BOOLEAN -> new BooleanArgument(nodeName); + case PRIMITIVE_DOUBLE -> new DoubleArgument(nodeName); + case PRIMITIVE_FLOAT -> new FloatArgument(nodeName); + case PRIMITIVE_GREEDY_STRING -> new GreedyStringArgument(nodeName); + case PRIMITIVE_INTEGER -> new IntegerArgument(nodeName); + case PRIMITIVE_LONG -> new LongArgument(nodeName); + case PRIMITIVE_STRING -> new StringArgument(nodeName); + case PRIMITIVE_TEXT -> new TextArgument(nodeName); + case LITERAL, MULTI_LITERAL, CUSTOM -> throw new UnknownArgumentException(argumentType); + default -> throw new UnknownArgumentException(argumentType); + }; + } + + private Argument parseArgument(String argument) throws UnknownArgumentException, InvalidNumberException { + Matcher literalMatcher = LITERAL_PATTERN.matcher(argument); + Matcher argumentMatcher = ARGUMENT_PATTERN.matcher(argument); + if (literalMatcher.matches()) { + // Parse literals + return new MultiLiteralArgument("literals", literalMatcher.group().substring(1, literalMatcher.group().length() - 1).split("\\|")); + } else if (argumentMatcher.matches()) { + // Parse arguments + String nodeName = argumentMatcher.group(1); + String argumentType = argumentMatcher.group(2); + + if (argumentType.contains("..")) { + // Parse ranges + return parseRange(nodeName, argumentType.split("\\.\\.")); + } else { + // We have a few edge cases to handle + return switch (argumentType) { + case "api:entity" -> new EntitySelectorArgument.OneEntity(nodeName); + case "api:entities" -> new EntitySelectorArgument.ManyEntities(nodeName); + case "api:player" -> new EntitySelectorArgument.OnePlayer(nodeName); + case "api:players" -> new EntitySelectorArgument.ManyPlayers(nodeName); + case "minecraft:vec3" -> new LocationArgument(nodeName, LocationType.PRECISE_POSITION); + case "minecraft:vec2" -> new Location2DArgument(nodeName, LocationType.PRECISE_POSITION); + default -> parseDefinedArgumentType(argumentType, nodeName); + }; + } + } else { + throw new UnknownArgumentException(argument); + } + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java similarity index 96% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/CommandAPIMain.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java index 06b984520..2d6c4639a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -21,6 +21,7 @@ package dev.jorel.commandapi; import dev.jorel.commandapi.config.BukkitConfigurationAdapter; +import dev.jorel.commandapi.config.DefaultBukkitConfig; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.InvalidPluginException; @@ -45,13 +46,12 @@ public void onLoad() { // Read config file saveDefaultConfig(); FileConfiguration fileConfig = getConfig(); - CommandAPIBukkitConfig config = new CommandAPIBukkitConfig(this) + CommandAPISpigotConfig config = new CommandAPISpigotConfig(this) .verboseOutput(fileConfig.getBoolean("verbose-outputs")) .silentLogs(fileConfig.getBoolean("silent-logs")) .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) - .shouldHookPaperReload(fileConfig.getBoolean("hook-paper-reload")) .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")) .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")); @@ -145,7 +145,11 @@ public void onEnable() { @Override public void saveDefaultConfig() { File configFile = new File(getDataFolder(), "config.yml"); - BukkitConfigurationAdapter.createMinimalInstance(configFile).saveDefaultConfig(getDataFolder(), getLogger()); + BukkitConfigurationAdapter.createMinimalInstance(configFile).saveDefaultConfig( + DefaultBukkitConfig.createDefaultSpigotConfig(), + getDataFolder(), + getLogger() + ); } } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml new file mode 100644 index 000000000..9714bb0dc --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml @@ -0,0 +1,74 @@ +################################################################################ +# Logging # +################################################################################ + +# Verbose outputs (default: false) +# If "true", outputs command registration and unregistration logs in the console +verbose-outputs: false + +# Silent logs (default: false) +# If "true", turns off all logging from the CommandAPI, except for errors. +silent-logs: false + +################################################################################ +# Messages # +################################################################################ + +# Messages +# Controls messages that the CommandAPI displays to players +messages: + + # Missing executor implementation (default: "This command has no implementations for %s") + # The message to display to senders when a command has no executor. Available + # parameters are: + # %s - the executor class (lowercase) + # %S - the executor class (normal case) + missing-executor-implementation: "This command has no implementations for %s" + +################################################################################ +# Debugging # +################################################################################ + +# Create dispatcher JSON (default: false) +# If "true", the CommandAPI creates a command_registration.json file showing the +# mapping of registered commands. This is designed to be used by developers - +# setting this to "false" will improve command registration performance. +create-dispatcher-json: false + +# Use latest version (default: false) +# If "true", the CommandAPI will use the latest available NMS implementation +# when the CommandAPI is used. This avoids all checks to see if the latest NMS +# implementation is actually compatible with the current Minecraft version. +use-latest-nms-version: false + +# Be lenient with version checks when loading for new minor Minecraft versions (default: false) +# If "true", the CommandAPI loads NMS implementations for (potentially unsupported) Minecraft versions. +# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing +# but will not allow an update from 1.21.2 to 1.22. +# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary. +be-lenient-for-minor-versions: false + +# Skips the initial datapack reload when the server loads (default: false) +# If "true", the CommandAPI will not reload datapacks when the server has finished +# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" +# is set to "true" and /minecraft:reload is run. +skip-initial-datapack-reload: false + +################################################################################ +# Command conversion # +################################################################################ + +# Plugins to convert (default: []) +# Controls the list of plugins to process for command conversion. +plugins-to-convert: [] + +# Other commands to convert (default: []) +# A list of other commands to convert. This should be used for commands which +# are not declared in a plugin.yml file. +other-commands-to-convert: [] + +# Skip sender proxy (default: []) +# Determines whether the proxy sender should be skipped when converting a +# command. If you are having issues with plugin command conversion, add the +# plugin to this list. +skip-sender-proxy: [] \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/src/main/resources/plugin.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/plugin.yml similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/src/main/resources/plugin.yml rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/plugin.yml diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/LICENSE b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/LICENSE new file mode 100644 index 000000000..29bc4dd17 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 - 2022 Jorel Ali + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml similarity index 55% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml index 187593759..49866893d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml @@ -1,37 +1,16 @@ - - - - + + 4.0.0 - commandapi-bukkit dev.jorel - 10.2.0-SNAPSHOT + commandapi-spigot + 11.0.0-SNAPSHOT - 4.0.0 - - commandapi-bukkit-plugin - CommandAPI - Bukkit support Spigot-mapped plugin + commandapi-spigot-plugin + Spigot support Spigot-mapped plugin @@ -43,35 +22,30 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - papermc - https://repo.papermc.io/repository/maven-public/ - dev.jorel - commandapi-bukkit-core + commandapi-spigot-core ${project.version} compile dev.jorel - commandapi-bukkit-vh + commandapi-spigot-vh ${project.version} dev.jorel - commandapi-bukkit-nms-dependency + commandapi-spigot-nms-dependency ${project.version} pom - io.papermc.paper - paper-api - ${paper.version} - provided + dev.jorel + commandapi-bukkit-plugin-common + ${project.version} org.spigotmc @@ -79,11 +53,6 @@ ${paper.version} provided - - dev.jorel - commandapi-bukkit-plugin-common - ${project.version} - @@ -91,7 +60,7 @@ src/main/resources true - + @@ -104,7 +73,7 @@ shade - @@ -142,4 +111,5 @@ + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java new file mode 100644 index 000000000..727f50a3e --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/AdvancedConverter.java @@ -0,0 +1,314 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.arguments.AdvancementArgument; +import dev.jorel.commandapi.arguments.AngleArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument; +import dev.jorel.commandapi.arguments.AxisArgument; +import dev.jorel.commandapi.arguments.BiomeArgument; +import dev.jorel.commandapi.arguments.BlockPredicateArgument; +import dev.jorel.commandapi.arguments.BlockStateArgument; +import dev.jorel.commandapi.arguments.BooleanArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.CommandAPIArgumentType; +import dev.jorel.commandapi.arguments.CommandArgument; +import dev.jorel.commandapi.arguments.DoubleArgument; +import dev.jorel.commandapi.arguments.EnchantmentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.FloatArgument; +import dev.jorel.commandapi.arguments.DoubleRangeArgument; +import dev.jorel.commandapi.arguments.FunctionArgument; +import dev.jorel.commandapi.arguments.GreedyStringArgument; +import dev.jorel.commandapi.arguments.IntegerArgument; +import dev.jorel.commandapi.arguments.IntegerRangeArgument; +import dev.jorel.commandapi.arguments.ItemStackArgument; +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; +import dev.jorel.commandapi.arguments.Location2DArgument; +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.LongArgument; +import dev.jorel.commandapi.arguments.LootTableArgument; +import dev.jorel.commandapi.arguments.MathOperationArgument; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import dev.jorel.commandapi.arguments.NamespacedKeyArgument; +import dev.jorel.commandapi.arguments.ObjectiveArgument; +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; +import dev.jorel.commandapi.arguments.ParticleArgument; +import dev.jorel.commandapi.arguments.PlayerProfileArgument; +import dev.jorel.commandapi.arguments.PotionEffectArgument; +import dev.jorel.commandapi.arguments.RecipeArgument; +import dev.jorel.commandapi.arguments.RotationArgument; +import dev.jorel.commandapi.arguments.ScoreHolderArgument; +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; +import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.TeamArgument; +import dev.jorel.commandapi.arguments.TextArgument; +import dev.jorel.commandapi.arguments.TimeArgument; +import dev.jorel.commandapi.arguments.UUIDArgument; +import dev.jorel.commandapi.exceptions.InvalidNumberException; +import dev.jorel.commandapi.exceptions.UnknownArgumentException; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A command parsing system that converts string arguments into something way + * more useful + */ +class AdvancedConverter { + + /** + * Pattern for arguments, which are of the form {@code [type]} + *
    + *
  • {@code node_name} is a standard node name.
  • + *
  • {@code type} is either a namespaced key representing the argument + * (described in {@code conversionforownerssingleargs.md} in the main + * documentation), or a numerical range of the form {@code n..n}, {@code ..n} or + * {@code n..} where {@code n} is a constant integer or floating point + * number
  • + *
+ */ + private static final Pattern ARGUMENT_PATTERN = Pattern.compile("<(\\w+)>\\[([a-z:_]+|(?:[0-9\\.]+)?\\.\\.(?:[0-9\\.]+)?)\\]"); + + /** + * Pattern for literal, of the form {@code (node_name)}. It also supports + * multiple node names of the form + * {@code (node_name_1|node_name_2|...|node_name_n)} + */ + private static final Pattern LITERAL_PATTERN = Pattern.compile("\\(\\w+(\\|\\w+)*+\\)"); + + private final JavaPlugin plugin; + private final String command; + private int argumentIndex = 1; + + public AdvancedConverter(JavaPlugin plugin, String command) { + this.plugin = plugin; + this.command = command; + } + + public AdvancedConverter(String command) { + this.plugin = null; + this.command = command; + } + + public void convert() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(plugin, commandName); + } else { + Converter.convert(plugin, commandName, arguments); + } + + } + + public void convertCommand() { + String commandName = command.split(" ")[0]; + List> arguments; + try { + arguments = parseArguments(command); + } catch (UnknownArgumentException | InvalidNumberException e) { + CommandAPI.logError(e.getMessage()); + return; + } + if (arguments.isEmpty()) { + Converter.convert(commandName); + } else { + Converter.convert(commandName, arguments); + } + } + + /** + *
+	 * plugins-to-convert: 
+	 *   - Essentials: 
+	 *     - speed [0..10]
+	 *     - speed [minecraft:game_profile]
+	 *     - speed (walk|fly) [0..10]
+	 *     - speed (walk|fly) [0..10] [minecraft:game_profile]
+	 * 
+ */ + private List> parseArguments(String command) throws UnknownArgumentException, InvalidNumberException { + List> arguments = new ArrayList<>(); + String[] parts = command.split(" "); + for (argumentIndex = 1; argumentIndex < parts.length; argumentIndex++) { + arguments.add(parseArgument(parts[argumentIndex])); + } + return arguments; + } + + private boolean isRangeAnInteger(double value) { + return value == (long) value; + } + + private double parseValue(String bound) throws InvalidNumberException { + try { + return Double.parseDouble(bound); + } catch (NumberFormatException e) { + throw new InvalidNumberException(bound, command, argumentIndex); + } + } + + private Argument parseRange(String nodeName, String[] bounds) throws InvalidNumberException { + if (bounds.length == 1) { + // x.. + double value = parseValue(bounds[0]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, (long) value); + } else { + return new DoubleArgument(nodeName, value); + } + } else if (bounds[0].length() == 0) { + // ..x + double value = parseValue(bounds[1]); + if (isRangeAnInteger(value)) { + return new LongArgument(nodeName, Long.MIN_VALUE, (long) value); + } else { + return new DoubleArgument(nodeName, -Double.MAX_VALUE, value); + } + } else { + // x..x + double value0 = parseValue(bounds[0]); + double value1 = parseValue(bounds[1]); + if (!isRangeAnInteger(value0) || !isRangeAnInteger(value1)) { + return new DoubleArgument(nodeName, value0, value1); + } else { + return new LongArgument(nodeName, (long) value0, (long) value1); + } + } + } + + /* + * CodeFactor will always complain about this method because it's really bulky + * and adding a generator (i.e. Function>) inside the + * CommandAPIArgumentType class would be better, EXCEPT in practice, this is + * worse because then CommandAPIArgumentType would have to depend on every + * argument and every argument depends on CommandAPIArgumentType, so that would + * mean every argument would always have to be packaged in the CommandAPI - jar + * minimisation wouldn't be able to minimise this as best as it could. + * + * Additionally, we only need this for the plugin version of the CommandAPI, not + * the main API. + */ + @SuppressWarnings("rawtypes") + private Argument parseDefinedArgumentType(String argumentType, String nodeName) throws UnknownArgumentException { + return switch (CommandAPIArgumentType.fromInternal(argumentType)) { + case ADVANCEMENT -> new AdvancementArgument(nodeName); + case ADVENTURE_CHAT -> new ChatArgument(nodeName); + case ADVENTURE_CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case ANGLE -> new AngleArgument(nodeName); + case ASYNC_OFFLINE_PLAYER -> new AsyncPlayerProfileArgument(nodeName); + case AXIS -> new AxisArgument(nodeName); + case BIOME -> new BiomeArgument(nodeName); + case BLOCKSTATE -> new BlockStateArgument(nodeName); + case BLOCK_PREDICATE -> new BlockPredicateArgument(nodeName); + case CHAT -> new ChatArgument(nodeName); + case CHATCOLOR -> new ChatColorArgument(nodeName); + case CHAT_COMPONENT -> new ChatComponentArgument(nodeName); + case COMMAND -> new CommandArgument(nodeName); + case ENCHANTMENT -> new EnchantmentArgument(nodeName); + case ENTITY_SELECTOR -> new EntitySelectorArgument.OneEntity(nodeName); + case ENTITY_TYPE -> new EntityTypeArgument(nodeName); + case FLOAT_RANGE -> new DoubleRangeArgument(nodeName); + case FUNCTION -> new FunctionArgument(nodeName); + case INT_RANGE -> new IntegerRangeArgument(nodeName); + case ITEMSTACK -> new ItemStackArgument(nodeName); + case ITEMSTACK_PREDICATE -> new ItemStackPredicateArgument(nodeName); + case LOCATION -> new LocationArgument(nodeName, LocationType.BLOCK_POSITION); + case LOCATION_2D -> new Location2DArgument(nodeName, LocationType.BLOCK_POSITION); + case LOOT_TABLE -> new LootTableArgument(nodeName); + case MATH_OPERATION -> new MathOperationArgument(nodeName); + case NAMESPACED_KEY -> new NamespacedKeyArgument(nodeName); + case NBT_COMPOUND -> new NBTCompoundArgument(nodeName); + case OBJECTIVE -> new ObjectiveArgument(nodeName); + case OBJECTIVE_CRITERIA -> new ObjectiveCriteriaArgument(nodeName); + case PARTICLE -> new ParticleArgument(nodeName); + case PLAYER -> new PlayerProfileArgument(nodeName); + case POTION_EFFECT -> new PotionEffectArgument(nodeName); + case RECIPE -> new RecipeArgument(nodeName); + case ROTATION -> new RotationArgument(nodeName); + case SCOREBOARD_SLOT -> new ScoreboardSlotArgument(nodeName); + case SCORE_HOLDER -> new ScoreHolderArgument.Single(nodeName); + case SOUND -> new SoundArgument(nodeName); + case TEAM -> new TeamArgument(nodeName); + case TIME -> new TimeArgument(nodeName); + case UUID -> new UUIDArgument(nodeName); + case PRIMITIVE_BOOLEAN -> new BooleanArgument(nodeName); + case PRIMITIVE_DOUBLE -> new DoubleArgument(nodeName); + case PRIMITIVE_FLOAT -> new FloatArgument(nodeName); + case PRIMITIVE_GREEDY_STRING -> new GreedyStringArgument(nodeName); + case PRIMITIVE_INTEGER -> new IntegerArgument(nodeName); + case PRIMITIVE_LONG -> new LongArgument(nodeName); + case PRIMITIVE_STRING -> new StringArgument(nodeName); + case PRIMITIVE_TEXT -> new TextArgument(nodeName); + case LITERAL, MULTI_LITERAL, CUSTOM -> throw new UnknownArgumentException(argumentType); + default -> throw new UnknownArgumentException(argumentType); + }; + } + + private Argument parseArgument(String argument) throws UnknownArgumentException, InvalidNumberException { + Matcher literalMatcher = LITERAL_PATTERN.matcher(argument); + Matcher argumentMatcher = ARGUMENT_PATTERN.matcher(argument); + if (literalMatcher.matches()) { + // Parse literals + return new MultiLiteralArgument("literals", literalMatcher.group().substring(1, literalMatcher.group().length() - 1).split("\\|")); + } else if (argumentMatcher.matches()) { + // Parse arguments + String nodeName = argumentMatcher.group(1); + String argumentType = argumentMatcher.group(2); + + if (argumentType.contains("..")) { + // Parse ranges + return parseRange(nodeName, argumentType.split("\\.\\.")); + } else { + // We have a few edge cases to handle + return switch (argumentType) { + case "api:entity" -> new EntitySelectorArgument.OneEntity(nodeName); + case "api:entities" -> new EntitySelectorArgument.ManyEntities(nodeName); + case "api:player" -> new EntitySelectorArgument.OnePlayer(nodeName); + case "api:players" -> new EntitySelectorArgument.ManyPlayers(nodeName); + case "minecraft:vec3" -> new LocationArgument(nodeName, LocationType.PRECISE_POSITION); + case "minecraft:vec2" -> new Location2DArgument(nodeName, LocationType.PRECISE_POSITION); + default -> parseDefinedArgumentType(argumentType, nodeName); + }; + } + } else { + throw new UnknownArgumentException(argument); + } + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java new file mode 100644 index 000000000..2d6c4639a --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.config.BukkitConfigurationAdapter; +import dev.jorel.commandapi.config.DefaultBukkitConfig; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.InvalidPluginException; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * Main CommandAPI plugin entrypoint + */ +public class CommandAPIMain extends JavaPlugin { + + private static final String PLUGINS_TO_CONVERT = "plugins-to-convert"; + + @Override + public void onLoad() { + // Read config file + saveDefaultConfig(); + FileConfiguration fileConfig = getConfig(); + CommandAPISpigotConfig config = new CommandAPISpigotConfig(this) + .verboseOutput(fileConfig.getBoolean("verbose-outputs")) + .silentLogs(fileConfig.getBoolean("silent-logs")) + .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) + .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) + .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) + .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")) + .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")); + + for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { + if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { + config.addSkipSenderProxy(pluginName); + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + } + + // Main CommandAPI loading + CommandAPI.setLogger(CommandAPILogger.fromJavaLogger(getLogger())); + CommandAPI.onLoad(config); + + // Convert all plugins to be converted + if (!fileConfig.getList(PLUGINS_TO_CONVERT).isEmpty() + && fileConfig.getMapList(PLUGINS_TO_CONVERT).isEmpty()) { + CommandAPI.logError("plugins-to-convert has an invalid type. Did you miss a colon (:) after a plugin name?"); + } + + convertCommands(fileConfig); + } + + private void convertCommands(FileConfiguration fileConfig) { + // Load all plugins at the same time + Map pluginsToConvert = new HashMap<>(); + for (Map map : fileConfig.getMapList(PLUGINS_TO_CONVERT)) { + String[] pluginCommands; + if (map.values().size() == 1 && map.values().iterator().next() == null) { + pluginCommands = new String[0]; + } else { + @SuppressWarnings("unchecked") + List commands = (List) map.values().iterator().next(); + pluginCommands = commands.toArray(new String[0]); + } + + // Get the plugin, if it doesn't exist, scream in the console (but + // don't crash, we want to continue!) + final JavaPlugin plugin = getAndValidatePlugin((String) map.keySet().iterator().next()); + if (plugin != null) { + pluginsToConvert.put(plugin, pluginCommands); + } + } + + // Convert plugin commands + for (Entry pluginToConvert : pluginsToConvert.entrySet()) { + if (pluginToConvert.getValue().length == 0) { + Converter.convert(pluginToConvert.getKey()); + } else { + for (String command : pluginToConvert.getValue()) { + new AdvancedConverter(pluginToConvert.getKey(), command).convert(); + } + } + } + + // Convert all arbitrary commands + for (String commandName : fileConfig.getStringList("other-commands-to-convert")) { + new AdvancedConverter(commandName).convertCommand(); + } + } + + private JavaPlugin getAndValidatePlugin(String pluginName) { + Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); + if (plugin != null) { + if (plugin instanceof JavaPlugin javaPlugin) { + return javaPlugin; + } else { + new InvalidPluginException("Plugin " + pluginName + " is not a JavaPlugin!").printStackTrace(); + } + } else { + new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") + .printStackTrace(); + } + return null; + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + } + + /** + * In contrast to the superclass' method {@link org.bukkit.plugin.java.JavaPlugin#saveDefaultConfig()}, + * this doesn't fail silently if the config.yml already exists but instead will update the config with + * new values if available. + *

+ * This should fail silently if all values are set already. + */ + @Override + public void saveDefaultConfig() { + File configFile = new File(getDataFolder(), "config.yml"); + BukkitConfigurationAdapter.createMinimalInstance(configFile).saveDefaultConfig( + DefaultBukkitConfig.createDefaultSpigotConfig(), + getDataFolder(), + getLogger() + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/config.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/config.yml new file mode 100644 index 000000000..9714bb0dc --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/config.yml @@ -0,0 +1,74 @@ +################################################################################ +# Logging # +################################################################################ + +# Verbose outputs (default: false) +# If "true", outputs command registration and unregistration logs in the console +verbose-outputs: false + +# Silent logs (default: false) +# If "true", turns off all logging from the CommandAPI, except for errors. +silent-logs: false + +################################################################################ +# Messages # +################################################################################ + +# Messages +# Controls messages that the CommandAPI displays to players +messages: + + # Missing executor implementation (default: "This command has no implementations for %s") + # The message to display to senders when a command has no executor. Available + # parameters are: + # %s - the executor class (lowercase) + # %S - the executor class (normal case) + missing-executor-implementation: "This command has no implementations for %s" + +################################################################################ +# Debugging # +################################################################################ + +# Create dispatcher JSON (default: false) +# If "true", the CommandAPI creates a command_registration.json file showing the +# mapping of registered commands. This is designed to be used by developers - +# setting this to "false" will improve command registration performance. +create-dispatcher-json: false + +# Use latest version (default: false) +# If "true", the CommandAPI will use the latest available NMS implementation +# when the CommandAPI is used. This avoids all checks to see if the latest NMS +# implementation is actually compatible with the current Minecraft version. +use-latest-nms-version: false + +# Be lenient with version checks when loading for new minor Minecraft versions (default: false) +# If "true", the CommandAPI loads NMS implementations for (potentially unsupported) Minecraft versions. +# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing +# but will not allow an update from 1.21.2 to 1.22. +# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary. +be-lenient-for-minor-versions: false + +# Skips the initial datapack reload when the server loads (default: false) +# If "true", the CommandAPI will not reload datapacks when the server has finished +# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" +# is set to "true" and /minecraft:reload is run. +skip-initial-datapack-reload: false + +################################################################################ +# Command conversion # +################################################################################ + +# Plugins to convert (default: []) +# Controls the list of plugins to process for command conversion. +plugins-to-convert: [] + +# Other commands to convert (default: []) +# A list of other commands to convert. This should be used for commands which +# are not declared in a plugin.yml file. +other-commands-to-convert: [] + +# Skip sender proxy (default: []) +# Determines whether the proxy sender should be skipped when converting a +# command. If you are having issues with plugin command conversion, add the +# plugin to this list. +skip-sender-proxy: [] \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/plugin.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/plugin.yml new file mode 100644 index 000000000..c31f8ced8 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/resources/plugin.yml @@ -0,0 +1,13 @@ +name: CommandAPI +main: dev.jorel.commandapi.CommandAPIMain +version: ${project.version} +description: An API to use Minecraft 1.13s new command UI +authors: + - Skepter + - Will Kroboth + - DerEchtePilz +website: https://www.jorel.dev/CommandAPI/ +softdepend: + - NBTAPI +api-version: 1.13 +folia-supported: true diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml similarity index 64% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml index 4d94c9dbf..b9ea01151 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-shade-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml @@ -1,59 +1,38 @@ - - - - + + 4.0.0 - commandapi-bukkit dev.jorel - 10.2.0-SNAPSHOT + commandapi-spigot + 11.0.0-SNAPSHOT - 4.0.0 - commandapi-bukkit-shade-mojang-mapped - CommandAPI - Bukkit support Mojang-mapped shade library + Spigot support Mojang-mapped shade library dev.jorel - commandapi-bukkit-core + commandapi-spigot-core ${project.version} compile dev.jorel - commandapi-bukkit-nms-dependency-mojang-mapped + commandapi-spigot-nms-dependency-mojang-mapped ${project.version} pom dev.jorel - commandapi-bukkit-vh + commandapi-spigot-vh ${project.version} dev.jorel - commandapi-bukkit-mojang-mapped + commandapi-spigot-mojang-mapped ${project.version} @@ -133,4 +112,5 @@ + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/LICENSE b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/LICENSE new file mode 100644 index 000000000..29bc4dd17 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 - 2022 Jorel Ali + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/javadoc/README.md b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/javadoc/README.md new file mode 100644 index 000000000..809bd4251 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/javadoc/README.md @@ -0,0 +1 @@ +# commandapi-shade \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml new file mode 100644 index 000000000..43e235222 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 11.0.0-SNAPSHOT + + + commandapi-spigot-shade + Spigot support Spigot-mapped shade library + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-spigot-vh + ${project.version} + + + dev.jorel + commandapi-spigot-nms-dependency + ${project.version} + pom + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + normal + package + + shade + + + true + true + + + + dev.jorel:commandapi-core + + dev/jorel/commandapi/CommandAPIVersionHandler** + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + empty-javadoc-jar + package + + jar + + + javadoc + ${basedir}/javadoc + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml new file mode 100644 index 000000000..b2998ac63 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 11.0.0-SNAPSHOT + + + commandapi-spigot-vh + Spigot support version handler + + + + dev.jorel + commandapi-spigot-nms-dependency + ${project.version} + pom + + + + + org.spigotmc + spigot + ${paper.version} + remapped-mojang + provided + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java new file mode 100644 index 000000000..ecc678394 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -0,0 +1,65 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.exceptions.UnsupportedVersionException; +import dev.jorel.commandapi.nms.SpigotNMS_1_20_R1; +import dev.jorel.commandapi.nms.SpigotNMS_1_20_R2; +import dev.jorel.commandapi.nms.SpigotNMS_1_20_R3; +import dev.jorel.commandapi.nms.SpigotNMS_1_20_R4; +import dev.jorel.commandapi.nms.SpigotNMS_1_21_R1; +import dev.jorel.commandapi.nms.SpigotNMS_1_21_R2; +import dev.jorel.commandapi.nms.SpigotNMS_1_21_R3; +import dev.jorel.commandapi.nms.SpigotNMS_1_21_R4; +import dev.jorel.commandapi.nms.SpigotNMS_1_21_R5; +import org.bukkit.Bukkit; + +public abstract class CommandAPIVersionHandler { + + static LoadContext getPlatform() { + String latestMajorVersion = "21"; // Change this for Minecraft's major update + + try { + if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) { + return new LoadContext(new SpigotNMS_1_21_R5(), () -> { + CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); + CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + }); + } else { + String version = Bukkit.getBukkitVersion().split("-")[0]; + CommandAPIPlatform platform = switch (version) { + case "1.20", "1.20.1" -> new SpigotNMS_1_20_R1(); + case "1.20.2" -> new SpigotNMS_1_20_R2(); + case "1.20.3", "1.20.4" -> new SpigotNMS_1_20_R3(); + case "1.20.5", "1.20.6" -> new SpigotNMS_1_20_R4(); + case "1.21", "1.21.1" -> new SpigotNMS_1_21_R1(); + case "1.21.2", "1.21.3" -> new SpigotNMS_1_21_R2(); + case "1.21.4" -> new SpigotNMS_1_21_R3(); + case "1.21.5" -> new SpigotNMS_1_21_R4(); + case "1.21.6" -> new SpigotNMS_1_21_R5(); + default -> null; + }; + if (platform != null) { + return new LoadContext(platform); + } + if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) { + String currentMajorVersion = version.split("\\.")[1]; + if (latestMajorVersion.equals(currentMajorVersion)) { + return new LoadContext(new SpigotNMS_1_21_R5(), () -> { + CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation."); + CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + }); + } + } + throw new UnsupportedVersionException(version); + } + } catch (Throwable error) { + // Something went sideways when trying to load a platform. This probably means we're shading the wrong mappings. + // Because this is an error we'll just rethrow this (instead of piping it into logError, which we can't really + // do anyway since the CommandAPILogger isn't loaded), but include some helpful(?) logging that might point + // users in the right direction + throw new IllegalStateException("The CommandAPI's NMS hook failed to load! This version of the CommandAPI is " + + (MojangMappedVersionHandler.isMojangMapped() ? "Mojang" : "Spigot") + "-mapped. Have you checked that " + + "you are using a CommandAPI version that matches the mappings that your plugin is using?", error); + } + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java new file mode 100644 index 000000000..8cf6fc0d5 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/exceptions/UnsupportedVersionException.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi.exceptions; + +/** + * An exception that occurs when this version of Minecraft is unsupported + */ +@SuppressWarnings("serial") +public class UnsupportedVersionException extends RuntimeException { + + /** + * Creates an UnsupportedVersionException + * @param version the version of Minecraft that is unsupported + */ + public UnsupportedVersionException(String version) { + super("This version of Minecraft is unsupported: " + version); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/pom.xml b/commandapi-platforms/commandapi-spigot/pom.xml new file mode 100644 index 000000000..16f61141f --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + dev.jorel + commandapi-platforms + 11.0.0-SNAPSHOT + + + commandapi-spigot + Spigot support + pom + + + commandapi-spigot-annotations + commandapi-spigot-core + commandapi-spigot-nms + commandapi-spigot-vh + commandapi-spigot-mojang-mapped + commandapi-spigot-plugin + commandapi-spigot-shade + commandapi-spigot-plugin-mojang-mapped + commandapi-spigot-shade-mojang-mapped + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml index 2f0e04040..074359e1c 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-sponge-core diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/src/main/java/dev/jorel/commandapi/CommandAPISponge.java b/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/src/main/java/dev/jorel/commandapi/CommandAPISponge.java index 8f9d20cec..6771a5b4e 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/src/main/java/dev/jorel/commandapi/CommandAPISponge.java +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/src/main/java/dev/jorel/commandapi/CommandAPISponge.java @@ -56,9 +56,9 @@ public void onLoad(CommandAPIConfig config) { } } - @Override - public void onEnable() { - commandManager = config.getServer().commandManager(); + public static void onEnable() { + CommandAPI.onEnable(); + CommandAPISponge.get().commandManager = config.getServer().commandManager(); } @Override diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml index 8027c751e..5506074e0 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-sponge-plugin-test diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml index 8ea5e92d4..414239d6f 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-sponge-plugin diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java index 46daf6dc3..53e7141af 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -33,7 +33,7 @@ public void onServerStarting(final StartingEngineEvent event) { @Listener public void onServerStart(final StartedEngineEvent event) { - CommandAPI.onEnable(); + CommandAPISponge.onEnable(); } @Listener diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml index 5d369bbcf..09e673a5d 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-sponge-shade diff --git a/commandapi-platforms/commandapi-sponge/pom.xml b/commandapi-platforms/commandapi-sponge/pom.xml index 97bc7cdd9..0bc2d6682 100644 --- a/commandapi-platforms/commandapi-sponge/pom.xml +++ b/commandapi-platforms/commandapi-sponge/pom.xml @@ -7,7 +7,7 @@ commandapi-platforms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-sponge diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml index d5e8368df..518e9dee1 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-velocity-core diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java index 41ee40e3e..f0ec5cf2a 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java @@ -95,7 +95,6 @@ private static void setInternalConfig(InternalVelocityConfig internalVelocityCon @Override public void onEnable() { - // Nothing to do } @Override diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml index 685c92b77..4c1a67692 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-velocity-plugin-test diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml index 2a772ea5c..4a1b2928e 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-velocity-plugin diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java index b1cb25e6a..856e197f7 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -8,6 +8,7 @@ import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.ProxyServer; +import dev.jorel.commandapi.config.DefaultVelocityConfig; import dev.jorel.commandapi.config.VelocityConfigurationAdapter; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.yaml.NodeStyle; @@ -41,7 +42,11 @@ public CommandAPIMain(ProxyServer server, Logger logger, @DataDirectory Path dat .build(); // Create or update config - VelocityConfigurationAdapter.createMinimalInstance(loader).saveDefaultConfig(configFile.getParent().toFile(), logger); + VelocityConfigurationAdapter.createMinimalInstance(loader).saveDefaultConfig( + DefaultVelocityConfig.createDefault(), + configFile.getParent().toFile(), + logger + ); // Load the file as a yaml node ConfigurationNode configYAML; diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/config/VelocityConfigurationAdapter.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/config/VelocityConfigurationAdapter.java index cab8d6237..eb2a0646f 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/config/VelocityConfigurationAdapter.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/src/main/java/dev/jorel/commandapi/config/VelocityConfigurationAdapter.java @@ -72,17 +72,12 @@ public ConfigurationAdapter complete() { @Override public ConfigurationAdapter createNew() { - return new VelocityConfigurationAdapter(loader, loader.createNode(), createDefaultConfig()); - } - - @Override - public DefaultVelocityConfig createDefaultConfig() { - return DefaultVelocityConfig.createDefault(); + return new VelocityConfigurationAdapter(loader, loader.createNode(), DefaultVelocityConfig.createDefault()); } @Override public ConfigurationAdapter loadFromFile() throws IOException { - return new VelocityConfigurationAdapter(loader, loader.load(), createDefaultConfig()); + return new VelocityConfigurationAdapter(loader, loader.load(), DefaultVelocityConfig.createDefault()); } @Override diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml index 2e61aa6be..81cb278d6 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-velocity-shade diff --git a/commandapi-platforms/commandapi-velocity/pom.xml b/commandapi-platforms/commandapi-velocity/pom.xml index 56dcc5dcf..a0218cf05 100644 --- a/commandapi-platforms/commandapi-velocity/pom.xml +++ b/commandapi-platforms/commandapi-velocity/pom.xml @@ -7,7 +7,7 @@ commandapi-platforms dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-velocity diff --git a/commandapi-platforms/pom.xml b/commandapi-platforms/pom.xml index a16d61785..713a54798 100644 --- a/commandapi-platforms/pom.xml +++ b/commandapi-platforms/pom.xml @@ -7,11 +7,11 @@ commandapi dev.jorel - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-platforms - CommandAPI - Multi-platform support + Multi-platform support pom @@ -20,8 +20,32 @@ Platform.Bukkit commandapi-bukkit - ../commandapi-kotlin/commandapi-core-kotlin - ../commandapi-kotlin/commandapi-bukkit-kotlin + commandapi-paper + commandapi-spigot + ../commandapi-kotlin/commandapi-kotlin-core + ../commandapi-kotlin/commandapi-kotlin-bukkit + ../commandapi-kotlin/commandapi-kotlin-paper + ../commandapi-kotlin/commandapi-kotlin-spigot + + + + Platform.Paper + + commandapi-bukkit + commandapi-paper + ../commandapi-kotlin/commandapi-kotlin-core + ../commandapi-kotlin/commandapi-kotlin-bukkit + ../commandapi-kotlin/commandapi-kotlin-paper + + + + Platform.Spigot + + commandapi-bukkit + commandapi-spigot + ../commandapi-kotlin/commandapi-kotlin-core + ../commandapi-kotlin/commandapi-kotlin-bukkit + ../commandapi-kotlin/commandapi-kotlin-spigot @@ -34,8 +58,8 @@ Platform.Velocity commandapi-velocity - ../commandapi-kotlin/commandapi-core-kotlin - ../commandapi-kotlin/commandapi-velocity-kotlin + ../commandapi-kotlin/commandapi-kotlin-core + ../commandapi-kotlin/commandapi-kotlin-velocity diff --git a/commandapi-plugin/pom.xml b/commandapi-plugin/pom.xml index cd3eb7c0a..19bb57ed1 100644 --- a/commandapi-plugin/pom.xml +++ b/commandapi-plugin/pom.xml @@ -7,11 +7,11 @@ dev.jorel commandapi - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-plugin - CommandAPI - Shared plugin library + Shared plugin library diff --git a/commandapi-plugin/src/main/java/dev/jorel/commandapi/config/ConfigurationAdapter.java b/commandapi-plugin/src/main/java/dev/jorel/commandapi/config/ConfigurationAdapter.java index 86c9336c0..c11258b9f 100644 --- a/commandapi-plugin/src/main/java/dev/jorel/commandapi/config/ConfigurationAdapter.java +++ b/commandapi-plugin/src/main/java/dev/jorel/commandapi/config/ConfigurationAdapter.java @@ -27,14 +27,12 @@ public interface ConfigurationAdapter { ConfigurationAdapter createNew(); - DefaultConfig createDefaultConfig(); - ConfigurationAdapter loadFromFile() throws IOException; void saveToFile() throws IOException; - default void saveDefaultConfig(File directory, Logger logger) { - ConfigGenerator generator = ConfigGenerator.createNew(createDefaultConfig()); + default void saveDefaultConfig(DefaultConfig defaultConfig, File directory, Logger logger) { + ConfigGenerator generator = ConfigGenerator.createNew(defaultConfig); ConfigurationAdapter existingConfig; if (!directory.exists()) { if (!directory.mkdirs()) { diff --git a/commandapi-preprocessor/pom.xml b/commandapi-preprocessor/pom.xml index d073d0b3f..952a2185d 100644 --- a/commandapi-preprocessor/pom.xml +++ b/commandapi-preprocessor/pom.xml @@ -25,12 +25,12 @@ dev.jorel commandapi - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 4.0.0 commandapi-preprocessor - CommandAPI - Development Maven preprocessor + Development Maven preprocessor \ No newline at end of file diff --git a/commandapi-testing/commandapi-testing-paper/pom.xml b/commandapi-testing/commandapi-testing-paper/pom.xml new file mode 100644 index 000000000..8b7d66ceb --- /dev/null +++ b/commandapi-testing/commandapi-testing-paper/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + dev.jorel + commandapi-testing + 11.0.0-SNAPSHOT + + + commandapi-testing-paper + Testing plugin for Paper + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + io.papermc.paper + paper-api + 1.20.6-R0.1-SNAPSHOT + provided + + + dev.jorel + commandapi-paper-shade + ${project.version} + + + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + + + + \ No newline at end of file diff --git a/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java new file mode 100644 index 000000000..0afe56b4f --- /dev/null +++ b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java @@ -0,0 +1,173 @@ +package dev.jorel.commandapi.testing; + +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.CommandAPIPaperConfig; +import dev.jorel.commandapi.arguments.AdvancementArgument; +import dev.jorel.commandapi.arguments.AngleArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.AxisArgument; +import dev.jorel.commandapi.arguments.BiomeArgument; +import dev.jorel.commandapi.arguments.BlockPredicateArgument; +import dev.jorel.commandapi.arguments.BlockStateArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.EnchantmentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.DoubleRangeArgument; +import dev.jorel.commandapi.arguments.FunctionArgument; +import dev.jorel.commandapi.arguments.IntegerRangeArgument; +import dev.jorel.commandapi.arguments.ItemStackArgument; +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; +import dev.jorel.commandapi.arguments.Location2DArgument; +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.LootTableArgument; +import dev.jorel.commandapi.arguments.MathOperationArgument; +import dev.jorel.commandapi.arguments.NamespacedKeyArgument; +import dev.jorel.commandapi.arguments.ObjectiveArgument; +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; +import dev.jorel.commandapi.arguments.ParticleArgument; +import dev.jorel.commandapi.arguments.PlayerProfileArgument; +import dev.jorel.commandapi.arguments.PotionEffectArgument; +import dev.jorel.commandapi.arguments.RecipeArgument; +import dev.jorel.commandapi.arguments.RotationArgument; +import dev.jorel.commandapi.arguments.ScoreHolderArgument; +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; +import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.TeamArgument; +import dev.jorel.commandapi.arguments.TimeArgument; +import dev.jorel.commandapi.arguments.UUIDArgument; +import dev.jorel.commandapi.arguments.WorldArgument; +import dev.jorel.commandapi.wrappers.DoubleRange; +import dev.jorel.commandapi.wrappers.FunctionWrapper; +import dev.jorel.commandapi.wrappers.IntegerRange; +import dev.jorel.commandapi.wrappers.Location2D; +import dev.jorel.commandapi.wrappers.MathOperation; +import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; +import dev.jorel.commandapi.wrappers.ScoreboardSlot; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; +import net.kyori.adventure.chat.ChatType; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; +import org.bukkit.command.CommandSender; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; +import org.bukkit.loot.LootTable; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; + +import java.util.Arrays; +import java.util.Collection; +import java.util.EnumSet; +import java.util.List; +import java.util.UUID; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.function.Predicate; + +public class TestPlugin extends JavaPlugin { + + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPIPaperConfig<>(this.getPluginMeta(), this)); + + register(new AdvancementArgument("advancementtype"), Advancement.class, advancement -> advancement.key().asString()); + register(new AngleArgument("angletype"), float.class, Object::toString); + register(new AxisArgument("axistype"), EnumSet.class, Object::toString); + register(new BiomeArgument("biome_biometype"), Biome.class, biome -> biome.getKey().asString()); + register(new BiomeArgument.NamespacedKey("biome_keytype"), NamespacedKey.class, Object::toString); + register(new BlockPredicateArgument("blockpredicatetype"), Predicate.class, Object::toString); + register(new BlockStateArgument("blockstatetype"), BlockState.class, Object::toString); + register(new ChatArgument("chattype"), SignedMessage.class, (message, sender) -> sender.sendMessage(message, ChatType.CHAT.bind(Component.text("local")))); + register(new ChatColorArgument("chatcolortype"), color -> Component.text("Test", color), NamedTextColor.class); + register(new ChatComponentArgument("chatcomponenttype"), Function.identity(), Component.class); + register(new EnchantmentArgument("enchantmenttype"), Enchantment.class, enchantment -> enchantment.key().asString()); + register(new EntitySelectorArgument.OnePlayer("oneplayertype"), Player.class, Player::getName); + register(new EntitySelectorArgument.OneEntity("onenentitytype"), Entity.class, Entity::getName); + register(new EntitySelectorArgument.ManyPlayers("manyplayerstype"), Collection.class, Object::toString); + register(new EntitySelectorArgument.ManyEntities("manyentitiestype"), Collection.class, Object::toString); + register(new EntityTypeArgument("entitytype"), EntityType.class, Object::toString); + register(new DoubleRangeArgument("floatrangetype"), DoubleRange.class, range -> range.getLowerBound() + ".." + range.getUpperBound()); + register(new FunctionArgument("functionstype"), FunctionWrapper[].class, Arrays::toString); + register(new IntegerRangeArgument("integerrangetype"), IntegerRange.class, range -> range.getLowerBound() + ".." + range.getUpperBound()); + register(new ItemStackArgument("itemstacktype"), ItemStack.class, stack -> stack.getType().getItemTranslationKey()); + register(new ItemStackPredicateArgument("itemstackpredicatetype"), Predicate.class, Object::toString); + register(new Location2DArgument("location2dblocktype", LocationType.BLOCK_POSITION), Location2D.class, loc -> loc.getX() + ", " + loc.getZ()); + register(new Location2DArgument("location2dprecisetype", LocationType.PRECISE_POSITION, true), Location2D.class, loc -> loc.getX() + ", " + loc.getZ()); + register(new LocationArgument("locationblocktype", LocationType.BLOCK_POSITION), Location.class, loc -> loc.getX() + ", " + loc.getY() + ", " + loc.getZ()); + register(new LocationArgument("locationprecisetype", LocationType.PRECISE_POSITION, true), Location.class, loc -> loc.getX() + ", " + loc.getY() + ", " + loc.getZ()); + register(new LootTableArgument("loottabletype"), LootTable.class, loot -> loot.key().asString()); + register(new MathOperationArgument("mathoperationtype"), MathOperation.class, MathOperation::toString); + register(new NamespacedKeyArgument("namespacedkeytype"), NamespacedKey.class, NamespacedKey::asString); + register(new ObjectiveArgument("objectivetype"), Objective.class, Objective::getName); + register(new ObjectiveCriteriaArgument("objectivecriteriatype"), String.class, Function.identity()); + register(new ParticleArgument("particletype"), ParticleData.class, data -> data.particle().toString()); + register(new PlayerProfileArgument("playertype"), List.class, Object::toString); + register(new PotionEffectArgument("potioneffect_potioneffecttype"), PotionEffectType.class, PotionEffectType::toString); + register(new PotionEffectArgument.NamespacedKey("potioneffect_keytype"), NamespacedKey.class, NamespacedKey::asString); + register(new RecipeArgument("recipetype"), Recipe.class, recipe -> recipe.getResult().getType().getKey().asString()); + register(new RotationArgument("rotationtype"), Rotation.class, rotation -> rotation.getYaw() + ", " + rotation.getPitch()); + register(new ScoreboardSlotArgument("scoreboardslottype"), ScoreboardSlot.class, ScoreboardSlot::toString); + register(new ScoreHolderArgument.Single("scoreholder_singletype"), String.class, Function.identity()); + register(new ScoreHolderArgument.Multiple("scoreholder_multipletype"), Collection.class, coll -> String.join(", ", coll)); + register(new SoundArgument("sound_soundtype"), Sound.class, s -> s.key().asString()); + register(new SoundArgument.NamespacedKey("sound_keytype"), NamespacedKey.class, NamespacedKey::asString); + register(new TeamArgument("teamtype"), Team.class, Team::getName); + register(new TimeArgument("timetype"), int.class, Object::toString); + register(new UUIDArgument("uuidtype"), UUID.class, UUID::toString); + register(new WorldArgument("worldtype"), World.class, World::getName); + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + } + + private void register(Argument argument, Class castType, Function toString) { + new CommandAPICommand(argument.getNodeName()) + .withArguments(argument) + .executes(info -> { + info.sender().sendPlainMessage(toString.apply(info.args().getByClass(argument.getNodeName(), castType))); + }) + .register(); + } + + private void register(Argument argument, Function toString, Class castType) { + new CommandAPICommand(argument.getNodeName()) + .withArguments(argument) + .executes(info -> { + info.sender().sendMessage(toString.apply(info.args().getByClass(argument.getNodeName(), castType))); + }) + .register(); + } + + private void register(Argument argument, Class castType, BiConsumer action) { + new CommandAPICommand(argument.getNodeName()) + .withArguments(argument) + .executes(info -> { + T argumentType = info.args().getByClass(argument.getNodeName(), castType); + action.accept(argumentType, info.sender()); + }) + .register(); + } + +} diff --git a/commandapi-testing/commandapi-testing-paper/src/main/resources/plugin.yml b/commandapi-testing/commandapi-testing-paper/src/main/resources/plugin.yml new file mode 100644 index 000000000..d871db218 --- /dev/null +++ b/commandapi-testing/commandapi-testing-paper/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: PaperTestPlugin +main: dev.jorel.commandapi.testing.TestPlugin +version: ${project.version} +description: A plugin to test all arguments the CommandAPI offers. +author: DerEchtePilz +api-version: '1.20' \ No newline at end of file diff --git a/commandapi-testing/pom.xml b/commandapi-testing/pom.xml new file mode 100644 index 000000000..1ef2a8e96 --- /dev/null +++ b/commandapi-testing/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + dev.jorel + commandapi + 11.0.0-SNAPSHOT + + + commandapi-testing + Collection of testing plugins for different platforms + pom + + + commandapi-testing-paper + + + \ No newline at end of file diff --git a/examples/bukkit/automated-tests-shaded/README.md b/examples/bukkit/automated-tests-shaded/README.md index d92f9507c..394d812dc 100644 --- a/examples/bukkit/automated-tests-shaded/README.md +++ b/examples/bukkit/automated-tests-shaded/README.md @@ -18,14 +18,14 @@ Key points: dev.jorel commandapi-bukkit-test-toolkit - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT test dev.jorel commandapi-bukkit-shade - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT compile diff --git a/examples/bukkit/automated-tests-shaded/pom.xml b/examples/bukkit/automated-tests-shaded/pom.xml index 44b5ef970..ffb8e91be 100644 --- a/examples/bukkit/automated-tests-shaded/pom.xml +++ b/examples/bukkit/automated-tests-shaded/pom.xml @@ -32,7 +32,7 @@ dev.jorel commandapi-bukkit-test-toolkit - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT test @@ -40,7 +40,7 @@ dev.jorel commandapi-bukkit-shade - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT compile diff --git a/examples/bukkit/automated-tests/README.md b/examples/bukkit/automated-tests/README.md index c4c01cf2c..d50e91e6c 100644 --- a/examples/bukkit/automated-tests/README.md +++ b/examples/bukkit/automated-tests/README.md @@ -18,14 +18,14 @@ Key points: dev.jorel commandapi-bukkit-test-toolkit - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT test dev.jorel commandapi-bukkit-core - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT provided diff --git a/examples/bukkit/automated-tests/pom.xml b/examples/bukkit/automated-tests/pom.xml index 09dd02506..46fb1674a 100644 --- a/examples/bukkit/automated-tests/pom.xml +++ b/examples/bukkit/automated-tests/pom.xml @@ -32,7 +32,7 @@ dev.jorel commandapi-bukkit-test-toolkit - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT test @@ -40,7 +40,7 @@ dev.jorel commandapi-bukkit-core - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT provided diff --git a/examples/bukkit/commandtrees/pom.xml b/examples/bukkit/commandtrees/pom.xml index b0025c1e1..e8dd378d2 100644 --- a/examples/bukkit/commandtrees/pom.xml +++ b/examples/bukkit/commandtrees/pom.xml @@ -9,24 +9,24 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ dev.jorel - commandapi-bukkit-core - 10.2.0-SNAPSHOT + commandapi-paper-core + 11.0.0-SNAPSHOT - + - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.20.1-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/commandtrees/src/main/java/io/github/jorelali/BetterBossBarsCommand.java b/examples/bukkit/commandtrees/src/main/java/io/github/jorelali/BetterBossBarsCommand.java index 19c4f5aca..d74d419a2 100644 --- a/examples/bukkit/commandtrees/src/main/java/io/github/jorelali/BetterBossBarsCommand.java +++ b/examples/bukkit/commandtrees/src/main/java/io/github/jorelali/BetterBossBarsCommand.java @@ -8,6 +8,8 @@ import java.util.stream.StreamSupport; import dev.jorel.commandapi.executors.CommandArguments; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.boss.BarColor; @@ -198,11 +200,15 @@ private void getValue(CommandSender sender, CommandArguments args) { private void addBossbar(CommandSender sender, CommandArguments args) { NamespacedKey id = (NamespacedKey) args.get(0); - BaseComponent[] name = (BaseComponent[]) args.get(1); + Component name = (Component) args.get(1); - Bukkit.createBossBar(id, BaseComponent.toLegacyText(name), BarColor.WHITE, BarStyle.SOLID); + net.kyori.adventure.bossbar.BossBar bossBar = net.kyori.adventure.bossbar.BossBar.bossBar(name, 1.0f, net.kyori.adventure.bossbar.BossBar.Color.WHITE, net.kyori.adventure.bossbar.BossBar.Overlay.PROGRESS); this.maxValues.put(id, 100); - sender.sendMessage("Created custom bossbar [" + BaseComponent.toLegacyText(name) + ChatColor.WHITE + "]"); + sender.sendMessage(Component.text() + .append(Component.text("Created custom bossbar [")) + .append(bossBar.name()) + .append(Component.text("]")) + ); } private void list(CommandSender sender, CommandArguments args) { diff --git a/examples/bukkit/gradle-groovy/build.gradle b/examples/bukkit/gradle-groovy/build.gradle index 290e55a93..97d56d058 100644 --- a/examples/bukkit/gradle-groovy/build.gradle +++ b/examples/bukkit/gradle-groovy/build.gradle @@ -16,7 +16,7 @@ repositories { mavenCentral() // This adds the Spigot Maven repository to the build maven { - url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' + url 'https://papermc.io/repo/repository/maven-public/' } // CodeMC repository for the NBT API maven { @@ -25,12 +25,12 @@ repositories { } dependencies { - // This adds the Spigot API artifact to the build - implementation 'org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT' + // This adds the Paper API artifact to the build + implementation 'io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT' // The CommandAPI dependency used for Bukkit and it's forks - implementation 'dev.jorel:commandapi-bukkit-plugin:10.2.0-SNAPSHOT' - + implementation 'dev.jorel:commandapi-paper-plugin:11.0.0-SNAPSHOT' + // NBT API to use NBT-based arguments implementation 'de.tr7zw:item-nbt-api-plugin:2.12.2' } \ No newline at end of file diff --git a/examples/bukkit/gradle-groovy/src/main/java/io/github/jorelali/MyCommands.java b/examples/bukkit/gradle-groovy/src/main/java/io/github/jorelali/MyCommands.java index 67683f9a1..4e2083640 100644 --- a/examples/bukkit/gradle-groovy/src/main/java/io/github/jorelali/MyCommands.java +++ b/examples/bukkit/gradle-groovy/src/main/java/io/github/jorelali/MyCommands.java @@ -37,7 +37,7 @@ public void registerAllCommands() { // the /effect command. The potion effect with be a level 1 potion // effect and the duration will be 5 minutes (300 seconds x 20 ticks) new CommandAPICommand("myeffect") - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new PotionEffectArgument("potion")) .executes((sender, args) -> { Player target = (Player) args.get(0); @@ -85,7 +85,7 @@ public void registerAllCommandTrees() { PotionEffectType potionEffectType = (PotionEffectType) args.get(0); player.addPotionEffect(new PotionEffect(potionEffectType, 300 * 20, 1)); }) - .then(new PlayerArgument("target") + .then(new EntitySelectorArgument.OnePlayer("target") .executes((sender, args) -> { // Register /myeffect // This command works exactly the same as the example diff --git a/examples/bukkit/gradle-kotlin/build.gradle.kts b/examples/bukkit/gradle-kotlin/build.gradle.kts index 679432201..f3d4374a9 100644 --- a/examples/bukkit/gradle-kotlin/build.gradle.kts +++ b/examples/bukkit/gradle-kotlin/build.gradle.kts @@ -14,18 +14,18 @@ version = "0.0.1-SNAPSHOT" repositories { // Use Maven Central for resolving dependencies. mavenCentral() - // This adds the Spigot Maven repository to the build - maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + // This adds the Paper Maven repository to the build + maven("https://papermc.io/repo/repository/maven-public/") // CodeMC repository for the NBT API maven("https://repo.codemc.org/repository/maven-public/") } dependencies { - // This adds the Spigot API artifact to the build - implementation("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT") + // This adds the Paper API artifact to the build + implementation("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") // The CommandAPI dependency used for Bukkit and it's forks - implementation("dev.jorel:commandapi-bukkit-plugin:10.2.0-SNAPSHOT") + implementation("dev.jorel:commandapi-paper-plugin:11.0.0-SNAPSHOT") // NBT API to use NBT-based arguments implementation("de.tr7zw:item-nbt-api-plugin:2.12.2") diff --git a/examples/bukkit/gradle-kotlin/src/main/java/io/github/jorelali/MyCommands.java b/examples/bukkit/gradle-kotlin/src/main/java/io/github/jorelali/MyCommands.java index 67683f9a1..4e2083640 100644 --- a/examples/bukkit/gradle-kotlin/src/main/java/io/github/jorelali/MyCommands.java +++ b/examples/bukkit/gradle-kotlin/src/main/java/io/github/jorelali/MyCommands.java @@ -37,7 +37,7 @@ public void registerAllCommands() { // the /effect command. The potion effect with be a level 1 potion // effect and the duration will be 5 minutes (300 seconds x 20 ticks) new CommandAPICommand("myeffect") - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new PotionEffectArgument("potion")) .executes((sender, args) -> { Player target = (Player) args.get(0); @@ -85,7 +85,7 @@ public void registerAllCommandTrees() { PotionEffectType potionEffectType = (PotionEffectType) args.get(0); player.addPotionEffect(new PotionEffect(potionEffectType, 300 * 20, 1)); }) - .then(new PlayerArgument("target") + .then(new EntitySelectorArgument.OnePlayer("target") .executes((sender, args) -> { // Register /myeffect // This command works exactly the same as the example diff --git a/examples/bukkit/kotlindsl-gradle/build.gradle.kts b/examples/bukkit/kotlindsl-gradle/build.gradle.kts index 195b8c9a4..f14256045 100644 --- a/examples/bukkit/kotlindsl-gradle/build.gradle.kts +++ b/examples/bukkit/kotlindsl-gradle/build.gradle.kts @@ -11,18 +11,19 @@ version = "0.0.1-SNAPSHOT" repositories { // Use Maven Central for resolving dependencies. mavenCentral() - // This adds the Spigot Maven repository to the build - maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + // This adds the Paper Maven repository to the build + maven("https://papermc.io/repo/repository/maven-public/") } dependencies { implementation(kotlin("stdlib-jdk8")) - // This adds the Spigot API artifact to the build - implementation("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT") + // This adds the Paper API artifact to the build + implementation("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") // The CommandAPI dependency used for Bukkit and it's forks - implementation("dev.jorel:commandapi-bukkit-core:10.2.0-SNAPSHOT") + implementation("dev.jorel:commandapi-paper-core:11.0.0-SNAPSHOT") + // Due to all functions available in the kotlindsl being inlined, we only need this dependency at compile-time - compileOnly("dev.jorel:commandapi-bukkit-kotlin:10.2.0-SNAPSHOT") + compileOnly("dev.jorel:commandapi-kotlin-paper:11.0.0-SNAPSHOT") } \ No newline at end of file diff --git a/examples/bukkit/kotlindsl/README.md b/examples/bukkit/kotlindsl/README.md index d4904d2fd..0f5ec3773 100644 --- a/examples/bukkit/kotlindsl/README.md +++ b/examples/bukkit/kotlindsl/README.md @@ -12,7 +12,7 @@ Key points: dev.jorel commandapi-kotlin-bukkit - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT ``` diff --git a/examples/bukkit/kotlindsl/pom.xml b/examples/bukkit/kotlindsl/pom.xml index f102e6195..a19f9e3c4 100644 --- a/examples/bukkit/kotlindsl/pom.xml +++ b/examples/bukkit/kotlindsl/pom.xml @@ -10,30 +10,30 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ dev.jorel - commandapi-bukkit-core - 10.2.0-SNAPSHOT + commandapi-paper-core + 11.0.0-SNAPSHOT provided dev.jorel - commandapi-bukkit-kotlin - 10.2.0-SNAPSHOT + commandapi-kotlin-paper + 11.0.0-SNAPSHOT - + - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.20.1-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven-annotations/README.md b/examples/bukkit/maven-annotations/README.md index 5d383bbfd..1d03a3b79 100644 --- a/examples/bukkit/maven-annotations/README.md +++ b/examples/bukkit/maven-annotations/README.md @@ -11,13 +11,13 @@ Key points: dev.jorel commandapi-bukkit-plugin - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT provided dev.jorel commandapi-annotations - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT provided @@ -37,7 +37,7 @@ Key points: dev.jorel commandapi-annotations - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT diff --git a/examples/bukkit/maven-annotations/pom.xml b/examples/bukkit/maven-annotations/pom.xml index cd3f32a93..c49d942d6 100644 --- a/examples/bukkit/maven-annotations/pom.xml +++ b/examples/bukkit/maven-annotations/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -27,23 +27,23 @@ dev.jorel - commandapi-bukkit-plugin - 10.2.0-SNAPSHOT + commandapi-paper-plugin + 11.0.0-SNAPSHOT provided dev.jorel - commandapi-annotations - 10.2.0-SNAPSHOT + commandapi-paper-annotations + 11.0.0-SNAPSHOT provided - + - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.20.1-R0.1-SNAPSHOT provided @@ -69,7 +69,7 @@ dev.jorel commandapi-annotations - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 17 diff --git a/examples/bukkit/maven-shaded-annotations/README.md b/examples/bukkit/maven-shaded-annotations/README.md index 2e25100f8..4fb22edc8 100644 --- a/examples/bukkit/maven-shaded-annotations/README.md +++ b/examples/bukkit/maven-shaded-annotations/README.md @@ -11,12 +11,12 @@ Key points: dev.jorel commandapi-bukkit-shade - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT dev.jorel commandapi-annotations - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT provided @@ -36,7 +36,7 @@ Key points: dev.jorel commandapi-annotations - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT diff --git a/examples/bukkit/maven-shaded-annotations/pom.xml b/examples/bukkit/maven-shaded-annotations/pom.xml index 45f5e50dc..01da54996 100644 --- a/examples/bukkit/maven-shaded-annotations/pom.xml +++ b/examples/bukkit/maven-shaded-annotations/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -27,22 +27,22 @@ dev.jorel - commandapi-bukkit-shade - 10.2.0-SNAPSHOT + commandapi-paper-shade + 11.0.0-SNAPSHOT dev.jorel commandapi-annotations - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT provided - + - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.20.1-R0.1-SNAPSHOT provided @@ -62,7 +62,7 @@ dev.jorel commandapi-annotations - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT 17 diff --git a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java index e9271c9b8..cf145a0bd 100644 --- a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java +++ b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java @@ -1,7 +1,7 @@ package io.github.jorelali; import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPIBukkitConfig; +import dev.jorel.commandapi.CommandAPIPaperConfig; import dev.jorel.commandapi.CommandAPIConfig; import dev.jorel.commandapi.CommandAPILogger; import org.bukkit.plugin.java.JavaPlugin; @@ -17,7 +17,7 @@ public void onLoad() { // Load the CommandAPI CommandAPI.onLoad( // Configure the CommandAPI - new CommandAPIBukkitConfig(this) + new CommandAPIPaperConfig(this) // Turn on verbose output for command registration logs .verboseOutput(true) // Give file where Brigadier's command registration tree should be dumped diff --git a/examples/bukkit/maven-shaded-tests/pom.xml b/examples/bukkit/maven-shaded-tests/pom.xml index 679395210..e2a57b47e 100644 --- a/examples/bukkit/maven-shaded-tests/pom.xml +++ b/examples/bukkit/maven-shaded-tests/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -37,7 +37,7 @@ dev.jorel commandapi-bukkit-test-tests - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT test-jar test @@ -45,14 +45,14 @@ dev.jorel - commandapi-bukkit-shade - 10.2.0-SNAPSHOT + commandapi-paper-shade + 11.0.0-SNAPSHOT - + - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.20.1-R0.1-SNAPSHOT provided @@ -69,14 +69,14 @@ dev.jorel commandapi-bukkit-test-impl - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT test dev.jorel commandapi-bukkit-test-impl-1.20 - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT test diff --git a/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java b/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java index f151eac1c..1f48b9652 100644 --- a/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java +++ b/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java @@ -8,7 +8,7 @@ import de.tr7zw.changeme.nbtapi.NBTContainer; import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPIBukkitConfig; +import dev.jorel.commandapi.CommandAPIPaperConfig; import dev.jorel.commandapi.CommandAPILogger; public class MyMain extends JavaPlugin { @@ -20,7 +20,7 @@ public void onLoad() { // Load the CommandAPI CommandAPI.onLoad( // Configure the CommandAPI - new CommandAPIBukkitConfig(this) + new CommandAPIPaperConfig(this) // Turn on verbose output for command registration logs .verboseOutput(true) // Give file where Brigadier's command registration tree should be dumped diff --git a/examples/bukkit/maven-shaded/README.md b/examples/bukkit/maven-shaded/README.md index be4d9f9d9..caa9c589e 100644 --- a/examples/bukkit/maven-shaded/README.md +++ b/examples/bukkit/maven-shaded/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-bukkit-shade - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT ``` diff --git a/examples/bukkit/maven-shaded/pom.xml b/examples/bukkit/maven-shaded/pom.xml index ce7f574f2..92a43945e 100644 --- a/examples/bukkit/maven-shaded/pom.xml +++ b/examples/bukkit/maven-shaded/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -27,14 +27,14 @@ dev.jorel - commandapi-bukkit-shade - 10.2.0-SNAPSHOT + commandapi-paper-shade + 11.0.0-SNAPSHOT - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.20.1-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java b/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java index ed3ec4bca..fdf3a39d9 100644 --- a/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java +++ b/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java @@ -3,7 +3,7 @@ import java.io.File; import de.tr7zw.changeme.nbtapi.NBTContainer; -import dev.jorel.commandapi.CommandAPIBukkitConfig; +import dev.jorel.commandapi.CommandAPIPaperConfig; import dev.jorel.commandapi.CommandAPILogger; import org.bukkit.plugin.java.JavaPlugin; @@ -19,7 +19,7 @@ public void onLoad() { // Load the CommandAPI CommandAPI.onLoad( // Configure the CommandAPI - new CommandAPIBukkitConfig(this) + new CommandAPIPaperConfig(this) // Turn on verbose output for command registration logs .verboseOutput(true) // Give file where Brigadier's command registration tree should be dumped diff --git a/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/MyCommands.java b/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/MyCommands.java index 32686b3e6..2c5aca36c 100644 --- a/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/MyCommands.java +++ b/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/MyCommands.java @@ -37,7 +37,7 @@ public void registerAllCommands() { // the /effect command. The potion effect with be a level 1 potion // effect and the duration will be 5 minutes (300 seconds x 20 ticks) new CommandAPICommand("myeffect") - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new PotionEffectArgument("potion")) .executes((sender, args) -> { Player target = (Player) args.get(0); @@ -85,7 +85,7 @@ public void registerAllCommandTrees() { PotionEffectType potionEffectType = (PotionEffectType) args.get(0); player.addPotionEffect(new PotionEffect(potionEffectType, 300 * 20, 1)); }) - .then(new PlayerArgument("target") + .then(new EntitySelectorArgument.OnePlayer("target") .executes((sender, args) -> { // Register /myeffect // This command works exactly the same as the example diff --git a/examples/bukkit/maven/README.md b/examples/bukkit/maven/README.md index 9908b214a..53732a9ed 100644 --- a/examples/bukkit/maven/README.md +++ b/examples/bukkit/maven/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-bukkit-plugin - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT provided ``` diff --git a/examples/bukkit/maven/pom.xml b/examples/bukkit/maven/pom.xml index 0b572787a..b8bdd30e8 100644 --- a/examples/bukkit/maven/pom.xml +++ b/examples/bukkit/maven/pom.xml @@ -9,10 +9,10 @@ - + - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://papermc.io/repo/repository/maven-public/ @@ -27,15 +27,15 @@ dev.jorel - commandapi-bukkit-plugin - 10.2.0-SNAPSHOT + commandapi-paper-plugin + 11.0.0-SNAPSHOT provided - + - org.spigotmc - spigot-api + io.papermc.paper + paper-api 1.20.1-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven/src/main/java/io/github/jorelali/MyCommands.java b/examples/bukkit/maven/src/main/java/io/github/jorelali/MyCommands.java index 52b3ec9b2..c4b0793b7 100644 --- a/examples/bukkit/maven/src/main/java/io/github/jorelali/MyCommands.java +++ b/examples/bukkit/maven/src/main/java/io/github/jorelali/MyCommands.java @@ -41,7 +41,7 @@ public void registerAllCommands() { // the /effect command. The potion effect with be a level 1 potion // effect and the duration will be 5 minutes (300 seconds x 20 ticks) new CommandAPICommand("myeffect") - .withArguments(new PlayerArgument("target")) + .withArguments(new EntitySelectorArgument.OnePlayer("target")) .withArguments(new PotionEffectArgument("potion")) .executes((sender, args) -> { Player target = (Player) args.get(0); @@ -89,7 +89,7 @@ public void registerAllCommandTrees() { PotionEffectType potionEffectType = (PotionEffectType) args.get(0); player.addPotionEffect(new PotionEffect(potionEffectType, 300 * 20, 1)); }) - .then(new PlayerArgument("target") + .then(new EntitySelectorArgument.OnePlayer("target") .executes((sender, args) -> { // Register /myeffect // This command works exactly the same as the example diff --git a/examples/velocity/gradle-groovy/README.md b/examples/velocity/gradle-groovy/README.md index 545e729e4..fc8b546be 100644 --- a/examples/velocity/gradle-groovy/README.md +++ b/examples/velocity/gradle-groovy/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-velocity-core` dependency is used ```groovy - implementation 'dev.jorel:commandapi-velocity-core:10.2.0-SNAPSHOT' + implementation 'dev.jorel:commandapi-velocity-core:11.0.0-SNAPSHOT' ``` - In the `@Plugin` annotation, `commandapi` is listed as a dependency: diff --git a/examples/velocity/gradle-groovy/build.gradle b/examples/velocity/gradle-groovy/build.gradle index 45e7d9020..57ab9dbc2 100644 --- a/examples/velocity/gradle-groovy/build.gradle +++ b/examples/velocity/gradle-groovy/build.gradle @@ -25,5 +25,5 @@ dependencies { implementation 'com.velocitypowered:velocity-api:3.1.1' // The CommandAPI dependency used for Velocity - implementation 'dev.jorel:commandapi-velocity-core:10.2.0-SNAPSHOT' + implementation 'dev.jorel:commandapi-velocity-core:11.0.0-SNAPSHOT' } \ No newline at end of file diff --git a/examples/velocity/gradle-kotlin/README.md b/examples/velocity/gradle-kotlin/README.md index 580b1b783..e48f6790c 100644 --- a/examples/velocity/gradle-kotlin/README.md +++ b/examples/velocity/gradle-kotlin/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-velocity-core` dependency is used: ```kotlin - implementation("dev.jorel:commandapi-velocity-core:10.2.0-SNAPSHOT") + implementation("dev.jorel:commandapi-velocity-core:11.0.0-SNAPSHOT") ``` - In the `@Plugin` annotation, `commandapi` is listed as a dependency: diff --git a/examples/velocity/gradle-kotlin/build.gradle.kts b/examples/velocity/gradle-kotlin/build.gradle.kts index 527b6dbc6..8179049de 100644 --- a/examples/velocity/gradle-kotlin/build.gradle.kts +++ b/examples/velocity/gradle-kotlin/build.gradle.kts @@ -23,5 +23,5 @@ dependencies { implementation("com.velocitypowered:velocity-api:3.1.1") // The CommandAPI dependency used for Velocity - implementation("dev.jorel:commandapi-velocity-core:10.2.0-SNAPSHOT") + implementation("dev.jorel:commandapi-velocity-core:11.0.0-SNAPSHOT") } \ No newline at end of file diff --git a/examples/velocity/maven-shaded/README.md b/examples/velocity/maven-shaded/README.md index cc3b6f3e7..dbcdfc82f 100644 --- a/examples/velocity/maven-shaded/README.md +++ b/examples/velocity/maven-shaded/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-velocity-shade - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT ``` diff --git a/examples/velocity/maven-shaded/pom.xml b/examples/velocity/maven-shaded/pom.xml index 781fac27e..dabfea1f1 100644 --- a/examples/velocity/maven-shaded/pom.xml +++ b/examples/velocity/maven-shaded/pom.xml @@ -21,7 +21,7 @@ dev.jorel commandapi-velocity-shade - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT diff --git a/examples/velocity/maven/README.md b/examples/velocity/maven/README.md index 9d3edb4f2..3070ffb35 100644 --- a/examples/velocity/maven/README.md +++ b/examples/velocity/maven/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-velocity-core - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT provided ``` diff --git a/examples/velocity/maven/pom.xml b/examples/velocity/maven/pom.xml index 50c6ee11f..b8a41c550 100644 --- a/examples/velocity/maven/pom.xml +++ b/examples/velocity/maven/pom.xml @@ -21,7 +21,7 @@ dev.jorel commandapi-velocity-core - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT provided diff --git a/pom.xml b/pom.xml index df8b7a995..163a4ea16 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ dev.jorel commandapi - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT pom commandapi @@ -70,8 +70,9 @@ commandapi-annotations + commandapi-testing - + diff --git a/setupPaperNMS.sh b/setupPaperNMS.sh new file mode 100755 index 000000000..2aef69a05 --- /dev/null +++ b/setupPaperNMS.sh @@ -0,0 +1,19 @@ +echo "Setup Paper NMS for version 1.20.5..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.20.5 -P Platform.Paper + +echo "Setup Paper NMS for version 1.21..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.21 -P Platform.Paper + +echo "Setup Paper NMS for version 1.21.2..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.21.2 -P Platform.Paper + +echo "Setup Paper NMS for version 1.21.4..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.21.4 -P Platform.Paper + +echo "Setup Paper NMS for version 1.21.5..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.21.5 -P Platform.Paper + +echo "Setup Paper NMS for version 1.21.6..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.21.6 -P Platform.Paper + +echo "Done!" \ No newline at end of file diff --git a/update.sh b/update.sh index ce51ba598..50d56195a 100755 --- a/update.sh +++ b/update.sh @@ -53,20 +53,21 @@ sed -i "s/$oldVer<\/version>/$newVer<\/version>/" examples/vel # Gradle example projects # ########################### -########## -# Bukkit # -########## +######### +# Paper # +######### -sed -i "s/dev\.jorel:commandapi-bukkit-plugin:$oldVer/dev\.jorel:commandapi-bukkit-plugin:$newVer/" examples/bukkit/gradle-groovy/README.md -sed -i "s/dev\.jorel:commandapi-bukkit-plugin:$oldVer/dev\.jorel:commandapi-bukkit-plugin:$newVer/" examples/bukkit/gradle-groovy/build.gradle +# We're using Paper as the example dependency for example projects +sed -i "s/dev\.jorel:commandapi-paper-plugin:$oldVer/dev\.jorel:commandapi-paper-plugin:$newVer/" examples/bukkit/gradle-groovy/README.md +sed -i "s/dev\.jorel:commandapi-paper-plugin:$oldVer/dev\.jorel:commandapi-paper-plugin:$newVer/" examples/bukkit/gradle-groovy/build.gradle -sed -i "s/dev\.jorel:commandapi-bukkit-plugin:$oldVer/dev\.jorel:commandapi-bukkit-plugin:$newVer/" examples/bukkit/gradle-kotlin/README.md -sed -i "s/dev\.jorel:commandapi-bukkit-plugin:$oldVer/dev\.jorel:commandapi-bukkit-plugin:$newVer/" examples/bukkit/gradle-kotlin/build.gradle.kts +sed -i "s/dev\.jorel:commandapi-paper-plugin:$oldVer/dev\.jorel:commandapi-paper-plugin:$newVer/" examples/bukkit/gradle-kotlin/README.md +sed -i "s/dev\.jorel:commandapi-paper-plugin:$oldVer/dev\.jorel:commandapi-paper-plugin:$newVer/" examples/bukkit/gradle-kotlin/build.gradle.kts -sed -i "s/dev\.jorel:commandapi-bukkit-core:$oldVer/dev\.jorel:commandapi-bukkit-core:$newVer/" examples/bukkit/kotlindsl-gradle/README.md -sed -i "s/dev\.jorel:commandapi-bukkit-core:$oldVer/dev\.jorel:commandapi-bukkit-core:$newVer/" examples/bukkit/kotlindsl-gradle/build.gradle.kts -sed -i "s/dev\.jorel:commandapi-bukkit-kotlin:$oldVer/dev\.jorel:commandapi-bukkit-kotlin:$newVer/" examples/bukkit/kotlindsl-gradle/README.md -sed -i "s/dev\.jorel:commandapi-bukkit-kotlin:$oldVer/dev\.jorel:commandapi-bukkit-kotlin:$newVer/" examples/bukkit/kotlindsl-gradle/build.gradle.kts +sed -i "s/dev\.jorel:commandapi-paper-core:$oldVer/dev\.jorel:commandapi-paper-core:$newVer/" examples/bukkit/kotlindsl-gradle/README.md +sed -i "s/dev\.jorel:commandapi-paper-core:$oldVer/dev\.jorel:commandapi-paper-core:$newVer/" examples/bukkit/kotlindsl-gradle/build.gradle.kts +sed -i "s/dev\.jorel:commandapi-kotlin-paper:$oldVer/dev\.jorel:commandapi-kotlin-paper:$newVer/" examples/bukkit/kotlindsl-gradle/README.md +sed -i "s/dev\.jorel:commandapi-kotlin-paper:$oldVer/dev\.jorel:commandapi-kotlin-paper:$newVer/" examples/bukkit/kotlindsl-gradle/build.gradle.kts ############ # Velocity # From 4d376b9cb30e3ad237d0c48bb47f079c646c2740 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 3 Jul 2025 10:58:12 +0200 Subject: [PATCH 03/63] Update to 1.21.7 --- .github/workflows/build.yml | 3 +++ .../src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java | 6 +++--- .../java/dev/jorel/commandapi/CommandAPIVersionHandler.java | 2 +- .../java/dev/jorel/commandapi/CommandAPIVersionHandler.java | 2 +- compileNMSCommon.sh | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1abb56d05..909dc6175 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -81,6 +81,9 @@ jobs: - name: Compile NMS_Common for 1.21.5 run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R4 + - name: Compile NMS_Common for 1.21.6 and 1.21.7 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R5 + - name: Copy BytecodeAnalyser to nms-common target folder run: mv BytecodeAnalyser/build/libs/BytecodeAnalyser*.jar commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/target diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java index 8c7f2b5d2..3267472b3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java @@ -205,9 +205,9 @@ // Mojang-Mapped reflection /** - * NMS implementation for Minecraft 1.21.5 + * NMS implementation for Minecraft 1.21.6 */ -@NMSMeta(compatibleWith = {"1.21.5"}) +@NMSMeta(compatibleWith = {"1.21.6", "1.21.7"}) @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) // @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @@ -319,7 +319,7 @@ public final Map getHelpMap() { @Override public String[] compatibleVersions() { - return new String[]{"1.21.5"}; + return new String[]{"1.21.6", "1.21.7"}; } private String serializeNMSItemStack(ItemStack is) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 286b24dfe..76fd393e8 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -36,7 +36,7 @@ static Object getVersion() { case "1.21.2", "1.21.3" -> new PaperNMS_1_21_R2(); case "1.21.4" -> new PaperNMS_1_21_R3(); case "1.21.5" -> new PaperNMS_1_21_R4(); - case "1.21.6" -> new PaperNMS_1_21_R5(); + case "1.21.6", "1.21.7" -> new PaperNMS_1_21_R5(); default -> null; }; if (versionAdapter != null) { diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index ecc678394..42b6729d7 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -34,7 +34,7 @@ static LoadContext getPlatform() { case "1.21.2", "1.21.3" -> new SpigotNMS_1_21_R2(); case "1.21.4" -> new SpigotNMS_1_21_R3(); case "1.21.5" -> new SpigotNMS_1_21_R4(); - case "1.21.6" -> new SpigotNMS_1_21_R5(); + case "1.21.6", "1.21.7" -> new SpigotNMS_1_21_R5(); default -> null; }; if (platform != null) { diff --git a/compileNMSCommon.sh b/compileNMSCommon.sh index 517b77fcb..cd21c4560 100755 --- a/compileNMSCommon.sh +++ b/compileNMSCommon.sh @@ -11,4 +11,4 @@ compileVersion "1.21 and 1.21.1" "Spigot_1_21_R1" compileVersion "1.21.2 and 1.21.3" "Spigot_1_21_R2" compileVersion "1.21.4" "Spigot_1_21_R3" compileVersion "1.21.5" "Spigot_1_21_R4" -compileVersion "1.21.6" "Spigot_1_21_R5" \ No newline at end of file +compileVersion "1.21.6 and 1.21.7" "Spigot_1_21_R5" \ No newline at end of file From 5e0ab022864f213e2fbf77e2d9bcab7a48fc564e Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Tue, 22 Jul 2025 13:39:57 +0200 Subject: [PATCH 04/63] Update README.md for 1.21.7 --- README.md | 73 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index f8202f8ed..befce39fa 100644 --- a/README.md +++ b/README.md @@ -43,37 +43,38 @@ The list of what version of the CommandAPI you'll need to run on a specific version of Minecraft is as follows: -| Minecraft version | Compatible versions | Latest compatible
version | Minimum Java
version required
to run latest version | -|--------------------|------------------------------|------------------------------|-----------------------------------------------------------| -| **1.13.x** | v1.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | -| **1.14.1, 1.14.2** | v2.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | -| **1.14.3, 1.14.4** | v2.1 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | -| **1.15.x** | v2.3a - 5.12, 8.3.0 - 9.3.0 | 9.3.0 | 16 | -| **1.16.1** | v3.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.2** | v4.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.3** | v4.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.4** | v5.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.5** | v5.7 - 7.0.0, 8.3.0 - 9.7.0 | 9.7.0 | 16 | -| **1.17** | 6.0.x - 9.7.0 | 9.7.0 | 16 | -| **1.17.1** | 6.1.x - 9.7.0 | 9.7.0 | 16 | -| **1.18, 1.18.1** | 6.5.2 - 9.7.0 | 9.7.0 | 16 | -| **1.18.2** | 6.5.4 - 9.7.0 | 9.7.0 | 16 | -| **1.19** | 8.3.0 - 9.7.0 | 9.7.0 | 16 | -| **1.19.1** | 8.5.0 - 9.7.0 | 9.7.0 | 16 | -| **1.19.2** | 8.5.1 - 9.7.0 | 9.7.0 | 16 | -| **1.19.3** | 8.7.0 - 9.7.0 | 9.7.0 | 16 | -| **1.19.4** | 8.8.0 - 9.7.0 | 9.7.0 | 16 | -| **1.20** | 9.0.2 - 10.1.0 | 10.1.0 | 17 | -| **1.20.1** | 9.0.3 - 10.1.0 | 10.1.0 | 17 | -| **1.20.2** | 9.2.0 - 10.1.0 | 10.1.0 | 17 | -| **1.20.3, 1.20.4** | 9.3.0 - 10.1.0 | 10.1.0 | 17 | -| **1.20.5, 1.20.6** | 9.4.0 - 10.1.0 | 10.1.0 | 17 | -| **1.21** | 9.5.0 - 10.1.0 | 10.1.0 | 17 | -| **1.21.1** | 9.5.2 - 10.1.0 | 10.1.0 | 17 | -| **1.21.2, 1.21.3** | 9.6.0 - 10.1.0 | 10.1.0 | 17 | -| **1.21.4** | 9.7.0 - 10.1.0 | 10.1.0 | 17 | -| **1.21.5** | 10.0.0 - 10.1.0 | 10.1.0 | 17 | -| **1.21.6** | 10.1.0 | 10.1.0 | 17 | +| Minecraft version | Compatible versions | Latest compatible
version | Minimum Java
version required
to run latest version | +|--------------------|-----------------------------|------------------------------|-----------------------------------------------------------| +| **1.13.x** | v1.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | +| **1.14.1, 1.14.2** | v2.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | +| **1.14.3, 1.14.4** | v2.1 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | +| **1.15.x** | v2.3a - 5.12, 8.3.0 - 9.3.0 | 9.3.0 | 16 | +| **1.16.1** | v3.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.2** | v4.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.3** | v4.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.4** | v5.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.5** | v5.7 - 7.0.0, 8.3.0 - 9.7.0 | 9.7.0 | 16 | +| **1.17** | 6.0.x - 9.7.0 | 9.7.0 | 16 | +| **1.17.1** | 6.1.x - 9.7.0 | 9.7.0 | 16 | +| **1.18, 1.18.1** | 6.5.2 - 9.7.0 | 9.7.0 | 16 | +| **1.18.2** | 6.5.4 - 9.7.0 | 9.7.0 | 16 | +| **1.19** | 8.3.0 - 9.7.0 | 9.7.0 | 16 | +| **1.19.1** | 8.5.0 - 9.7.0 | 9.7.0 | 16 | +| **1.19.2** | 8.5.1 - 9.7.0 | 9.7.0 | 16 | +| **1.19.3** | 8.7.0 - 9.7.0 | 9.7.0 | 16 | +| **1.19.4** | 8.8.0 - 9.7.0 | 9.7.0 | 16 | +| **1.20** | 9.0.2 - 10.1.1 | 10.1.1 | 17 | +| **1.20.1** | 9.0.3 - 10.1.1 | 10.1.1 | 17 | +| **1.20.2** | 9.2.0 - 10.1.1 | 10.1.1 | 17 | +| **1.20.3, 1.20.4** | 9.3.0 - 10.1.1 | 10.1.1 | 17 | +| **1.20.5, 1.20.6** | 9.4.0 - 10.1.1 | 10.1.1 | 17 | +| **1.21** | 9.5.0 - 10.1.1 | 10.1.1 | 17 | +| **1.21.1** | 9.5.2 - 10.1.1 | 10.1.1 | 17 | +| **1.21.2, 1.21.3** | 9.6.0 - 10.1.1 | 10.1.1 | 17 | +| **1.21.4** | 9.7.0 - 10.1.1 | 10.1.1 | 17 | +| **1.21.5** | 10.0.0 - 10.1.1 | 10.1.1 | 17 | +| **1.21.6** | 10.1.0 - 10.1.1 | 10.1.1 | 17 | +| **1.21.7** | 10.1.1 | 10.1.1 | 17 | ----- @@ -417,6 +418,16 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025): + + 10.1.1 + July 2025 + + Minecraft Version Changes: +

    +
  • Adds support for Minecraft 1.21.7
  • +
+ + 10.1.0 June 2025 From 31778bde56d3d346c110f63ec27ce83d0d8f2d21 Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Mon, 21 Jul 2025 20:38:28 +0100 Subject: [PATCH 05/63] Update global changelog. Adds script to get publishable artifacts --- README.md | 75 +++++++++++++++++------------- scripts/getPublishableArtifacts.sh | 38 +++++++++++++++ 2 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 scripts/getPublishableArtifacts.sh diff --git a/README.md b/README.md index befce39fa..288d61a9d 100644 --- a/README.md +++ b/README.md @@ -43,38 +43,39 @@ The list of what version of the CommandAPI you'll need to run on a specific version of Minecraft is as follows: -| Minecraft version | Compatible versions | Latest compatible
version | Minimum Java
version required
to run latest version | -|--------------------|-----------------------------|------------------------------|-----------------------------------------------------------| -| **1.13.x** | v1.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | -| **1.14.1, 1.14.2** | v2.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | -| **1.14.3, 1.14.4** | v2.1 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | -| **1.15.x** | v2.3a - 5.12, 8.3.0 - 9.3.0 | 9.3.0 | 16 | -| **1.16.1** | v3.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.2** | v4.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.3** | v4.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.4** | v5.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.5** | v5.7 - 7.0.0, 8.3.0 - 9.7.0 | 9.7.0 | 16 | -| **1.17** | 6.0.x - 9.7.0 | 9.7.0 | 16 | -| **1.17.1** | 6.1.x - 9.7.0 | 9.7.0 | 16 | -| **1.18, 1.18.1** | 6.5.2 - 9.7.0 | 9.7.0 | 16 | -| **1.18.2** | 6.5.4 - 9.7.0 | 9.7.0 | 16 | -| **1.19** | 8.3.0 - 9.7.0 | 9.7.0 | 16 | -| **1.19.1** | 8.5.0 - 9.7.0 | 9.7.0 | 16 | -| **1.19.2** | 8.5.1 - 9.7.0 | 9.7.0 | 16 | -| **1.19.3** | 8.7.0 - 9.7.0 | 9.7.0 | 16 | -| **1.19.4** | 8.8.0 - 9.7.0 | 9.7.0 | 16 | -| **1.20** | 9.0.2 - 10.1.1 | 10.1.1 | 17 | -| **1.20.1** | 9.0.3 - 10.1.1 | 10.1.1 | 17 | -| **1.20.2** | 9.2.0 - 10.1.1 | 10.1.1 | 17 | -| **1.20.3, 1.20.4** | 9.3.0 - 10.1.1 | 10.1.1 | 17 | -| **1.20.5, 1.20.6** | 9.4.0 - 10.1.1 | 10.1.1 | 17 | -| **1.21** | 9.5.0 - 10.1.1 | 10.1.1 | 17 | -| **1.21.1** | 9.5.2 - 10.1.1 | 10.1.1 | 17 | -| **1.21.2, 1.21.3** | 9.6.0 - 10.1.1 | 10.1.1 | 17 | -| **1.21.4** | 9.7.0 - 10.1.1 | 10.1.1 | 17 | -| **1.21.5** | 10.0.0 - 10.1.1 | 10.1.1 | 17 | -| **1.21.6** | 10.1.0 - 10.1.1 | 10.1.1 | 17 | -| **1.21.7** | 10.1.1 | 10.1.1 | 17 | +| Minecraft version | Compatible versions | Latest compatible
version | Minimum Java
version required
to run latest version | +|--------------------|------------------------------|------------------------------|-----------------------------------------------------------| +| **1.13.x** | v1.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | +| **1.14.1, 1.14.2** | v2.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | +| **1.14.3, 1.14.4** | v2.1 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | +| **1.15.x** | v2.3a - 5.12, 8.3.0 - 9.3.0 | 9.3.0 | 16 | +| **1.16.1** | v3.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.2** | v4.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.3** | v4.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.4** | v5.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.5** | v5.7 - 7.0.0, 8.3.0 - 9.7.0 | 9.7.0 | 16 | +| **1.17** | 6.0.x - 9.7.0 | 9.7.0 | 16 | +| **1.17.1** | 6.1.x - 9.7.0 | 9.7.0 | 16 | +| **1.18, 1.18.1** | 6.5.2 - 9.7.0 | 9.7.0 | 16 | +| **1.18.2** | 6.5.4 - 9.7.0 | 9.7.0 | 16 | +| **1.19** | 8.3.0 - 9.7.0 | 9.7.0 | 16 | +| **1.19.1** | 8.5.0 - 9.7.0 | 9.7.0 | 16 | +| **1.19.2** | 8.5.1 - 9.7.0 | 9.7.0 | 16 | +| **1.19.3** | 8.7.0 - 9.7.0 | 9.7.0 | 16 | +| **1.19.4** | 8.8.0 - 9.7.0 | 9.7.0 | 16 | +| **1.20** | 9.0.2 - 10.1.2 | 10.1.2 | 17 | +| **1.20.1** | 9.0.3 - 10.1.2 | 10.1.2 | 17 | +| **1.20.2** | 9.2.0 - 10.1.2 | 10.1.2 | 17 | +| **1.20.3, 1.20.4** | 9.3.0 - 10.1.2 | 10.1.2 | 17 | +| **1.20.5, 1.20.6** | 9.4.0 - 10.1.2 | 10.1.2 | 17 | +| **1.21** | 9.5.0 - 10.1.2 | 10.1.2 | 17 | +| **1.21.1** | 9.5.2 - 10.1.2 | 10.1.2 | 17 | +| **1.21.2, 1.21.3** | 9.6.0 - 10.1.2 | 10.1.2 | 17 | +| **1.21.4** | 9.7.0 - 10.1.2 | 10.1.2 | 17 | +| **1.21.5** | 10.0.0 - 10.1.2 | 10.1.2 | 17 | +| **1.21.6** | 10.1.0 - 10.1.2 | 10.1.2 | 17 | +| **1.21.7** | 10.1.1 - 10.1.2 | 10.1.2 | 17 | +| **1.21.8** | 10.1.2 | 10.1.2 | 17 | ----- @@ -418,6 +419,16 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025): + + 10.1.2 + July 2025 + + Minecraft Version Changes: +
    +
  • Adds support for Minecraft 1.21.8
  • +
+ + 10.1.1 July 2025 diff --git a/scripts/getPublishableArtifacts.sh b/scripts/getPublishableArtifacts.sh new file mode 100644 index 000000000..1a86963c8 --- /dev/null +++ b/scripts/getPublishableArtifacts.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Exit on error +set -e + +# Output directory +DEST_DIR=$(pwd) + +cd .. +version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + +# Declare associative array: [module_path]=custom_name +declare -A MODULES_TO_COPY=( + ["commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin"]="CommandAPI-$version.jar" + ["commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped"]="CommandAPI-$version-Mojang-Mapped.jar" + ["commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin"]="CommandAPI-$version-Networking-Plugin.jar" + ["commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin"]="CommandAPI-$version-Velocity.jar" +) + +# Iterate over the array +for module in "${!MODULES_TO_COPY[@]}"; do + custom_name="${MODULES_TO_COPY[$module]}" + target_dir="$module/target" + + # Find main artifact (ignore sources/javadoc) + artifact=$(find "$target_dir" -maxdepth 1 -type f \ + \( -name "*.jar" -o -name "*.war" \) \ + ! -name "*-sources.jar" ! -name "*-javadoc.jar" | head -n 1) + + if [[ -n "$artifact" ]]; then + cp "$artifact" "$DEST_DIR/$custom_name" + echo "Copied $artifact → $DEST_DIR/$custom_name" + else + echo "Warning: No artifact found in $target_dir" + fi +done + +echo "Done. Artifacts are in $DEST_DIR" From a5464c3602ce5d9e4dd37358864368a5e0a56604 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Tue, 22 Jul 2025 13:50:29 +0200 Subject: [PATCH 06/63] Update to 1.21.8 --- .github/workflows/build.yml | 2 +- .../src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java | 6 +++--- .../java/dev/jorel/commandapi/CommandAPIVersionHandler.java | 2 +- .../java/dev/jorel/commandapi/CommandAPIVersionHandler.java | 2 +- compileNMSCommon.sh | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 909dc6175..26eacdad6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -81,7 +81,7 @@ jobs: - name: Compile NMS_Common for 1.21.5 run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R4 - - name: Compile NMS_Common for 1.21.6 and 1.21.7 + - name: Compile NMS_Common for 1.21.6 and 1.21.7 and 1.21.8 run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R5 - name: Copy BytecodeAnalyser to nms-common target folder diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java index 3267472b3..1d194ff08 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java @@ -205,9 +205,9 @@ // Mojang-Mapped reflection /** - * NMS implementation for Minecraft 1.21.6 + * NMS implementation for Minecraft 1.21.6, 1.21.7 and 1.21.8 */ -@NMSMeta(compatibleWith = {"1.21.6", "1.21.7"}) +@NMSMeta(compatibleWith = {"1.21.6", "1.21.7", "1.21.8"}) @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) // @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) @@ -319,7 +319,7 @@ public final Map getHelpMap() { @Override public String[] compatibleVersions() { - return new String[]{"1.21.6", "1.21.7"}; + return new String[]{"1.21.6", "1.21.7", "1.21.8"}; } private String serializeNMSItemStack(ItemStack is) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 76fd393e8..a3098ddd0 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -36,7 +36,7 @@ static Object getVersion() { case "1.21.2", "1.21.3" -> new PaperNMS_1_21_R2(); case "1.21.4" -> new PaperNMS_1_21_R3(); case "1.21.5" -> new PaperNMS_1_21_R4(); - case "1.21.6", "1.21.7" -> new PaperNMS_1_21_R5(); + case "1.21.6", "1.21.7", "1.21.8" -> new PaperNMS_1_21_R5(); default -> null; }; if (versionAdapter != null) { diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 42b6729d7..d2acf9c7f 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -34,7 +34,7 @@ static LoadContext getPlatform() { case "1.21.2", "1.21.3" -> new SpigotNMS_1_21_R2(); case "1.21.4" -> new SpigotNMS_1_21_R3(); case "1.21.5" -> new SpigotNMS_1_21_R4(); - case "1.21.6", "1.21.7" -> new SpigotNMS_1_21_R5(); + case "1.21.6", "1.21.7", "1.21.8" -> new SpigotNMS_1_21_R5(); default -> null; }; if (platform != null) { diff --git a/compileNMSCommon.sh b/compileNMSCommon.sh index cd21c4560..7004ade27 100755 --- a/compileNMSCommon.sh +++ b/compileNMSCommon.sh @@ -11,4 +11,4 @@ compileVersion "1.21 and 1.21.1" "Spigot_1_21_R1" compileVersion "1.21.2 and 1.21.3" "Spigot_1_21_R2" compileVersion "1.21.4" "Spigot_1_21_R3" compileVersion "1.21.5" "Spigot_1_21_R4" -compileVersion "1.21.6 and 1.21.7" "Spigot_1_21_R5" \ No newline at end of file +compileVersion "1.21.6 and 1.21.7 and 1.21.8" "Spigot_1_21_R5" \ No newline at end of file From 18e36a6ebfa24c4f25ca47ebdc26ef65c73c3075 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Tue, 22 Jul 2025 13:52:19 +0200 Subject: [PATCH 07/63] Update getPublishableArtifacts.sh to account for the new project structure --- scripts/getPublishableArtifacts.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/getPublishableArtifacts.sh b/scripts/getPublishableArtifacts.sh index 1a86963c8..a8d25426f 100644 --- a/scripts/getPublishableArtifacts.sh +++ b/scripts/getPublishableArtifacts.sh @@ -11,8 +11,8 @@ version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) # Declare associative array: [module_path]=custom_name declare -A MODULES_TO_COPY=( - ["commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin"]="CommandAPI-$version.jar" - ["commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped"]="CommandAPI-$version-Mojang-Mapped.jar" + ["commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin"]="CommandAPI-Spigot-$version.jar" + ["commandapi-platforms/commandapi-paper/commandapi-paper-plugin"]="CommandAPI-Paper-$version.jar" ["commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin"]="CommandAPI-$version-Networking-Plugin.jar" ["commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin"]="CommandAPI-$version-Velocity.jar" ) From 6594158902634bb53465c0b0ec1a0b176fdcfab0 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Fri, 27 Jun 2025 00:21:11 +0200 Subject: [PATCH 08/63] CommandAPI Paper follow-up --- .../dev/jorel/commandapi/nms/BundledNMS.java | 18 +++ .../dev/jorel/commandapi/nms/PaperNMS.java | 18 --- .../commandapi/nms/PaperNMS_1_20_R4.java | 108 +++--------------- .../commandapi/nms/PaperNMS_1_21_R2.java | 46 -------- .../commandapi/nms/PaperNMS_1_21_R3.java | 60 ---------- .../commandapi/nms/PaperNMS_1_21_R4.java | 69 ----------- .../commandapi/nms/PaperNMS_1_21_R5.java | 43 ------- .../commandapi/nms/PaperNMS_1_21_R1.java | 46 -------- .../commandapi/CommandAPIVersionHandler.java | 15 +-- 9 files changed, 37 insertions(+), 386 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java index 1af07042c..ae41a6254 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java @@ -1,4 +1,22 @@ package dev.jorel.commandapi.nms; +import com.destroystokyo.paper.profile.PlayerProfile; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.List; + public abstract class BundledNMS implements NMS, PaperNMS { + + public abstract SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + public abstract NamedTextColor getChatColor(CommandContext cmdCtx, String key); + + public abstract Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException; + + public abstract List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException; + } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java index e517a186d..a96787495 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java @@ -1,27 +1,9 @@ package dev.jorel.commandapi.nms; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.tree.LiteralCommandNode; import dev.jorel.commandapi.CommandRegistrationStrategy; -import net.kyori.adventure.chat.SignedMessage; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; - -import java.util.List; public interface PaperNMS { - SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - NamedTextColor getChatColor(CommandContext cmdCtx, String key); - - Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException; - NMS bukkitNMS(); CommandRegistrationStrategy createCommandRegistrationStrategy(); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java index 2c0ed7cfb..68346a81e 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java @@ -1,68 +1,23 @@ package dev.jorel.commandapi.nms; -import com.destroystokyo.paper.profile.CraftPlayerProfile; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.google.common.collect.Collections2; import com.mojang.brigadier.Command; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.tree.LiteralCommandNode; -import dev.jorel.commandapi.CommandAPIBukkit; -import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.PaperCommandRegistration; -import dev.jorel.commandapi.SpigotCommandRegistration; import io.papermc.paper.command.brigadier.PaperCommands; -import io.papermc.paper.command.brigadier.PluginCommandNode; import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; -import net.kyori.adventure.chat.SignedMessage; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; -import net.minecraft.commands.arguments.ColorArgument; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.commands.arguments.GameProfileArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; -import org.bukkit.command.SimpleCommandMap; import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.command.BukkitCommandWrapper; -import org.bukkit.craftbukkit.command.VanillaCommandWrapper; import org.bukkit.craftbukkit.help.SimpleHelpMap; -import java.lang.reflect.Field; -import java.util.List; -import java.util.concurrent.CompletableFuture; - public class PaperNMS_1_20_R4 implements PaperNMS { private CommandBuildContext commandBuildContext; - private static final boolean vanillaCommandDispatcherFieldExists; - private static final Commands vanillaCommandDispatcher; private NMS_1_20_R4 bukkitNMS; - static { - boolean fieldExists; - Commands commandDispatcher; - try { - Field vanillaCommandDispatcherField = MinecraftServer.class.getDeclaredField("vanillaCommandDispatcher"); - commandDispatcher = (Commands) vanillaCommandDispatcherField.get(CommandAPIPaper.getPaper().getNMS().getMinecraftServer()); - fieldExists = true; - } catch (NoSuchFieldException | SecurityException | IllegalAccessException e) { - // Expected on Paper-1.20.6-65 or later due to https://github.com/PaperMC/Paper/pull/8235 - commandDispatcher = null; - fieldExists = false; - } - vanillaCommandDispatcher = commandDispatcher; - vanillaCommandDispatcherFieldExists = fieldExists; - } - private CommandBuildContext getCommandBuildContext() { if (commandBuildContext != null) { return commandBuildContext; @@ -76,32 +31,6 @@ private CommandBuildContext getCommandBuildContext() { } } - @Override - public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - CompletableFuture future = new CompletableFuture<>(); - MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); - return future.join(); - } - - @Override - public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public Component getChatComponent(CommandContext cmdCtx, String key) { - return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), getCommandBuildContext())); - } - - @Override - public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { - GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); - } - @Override public NMS bukkitNMS() { if (bukkitNMS == null) { @@ -112,30 +41,19 @@ public NMS bukkitNMS() { @Override public CommandRegistrationStrategy createCommandRegistrationStrategy() { - if (vanillaCommandDispatcherFieldExists) { - return new SpigotCommandRegistration<>( - vanillaCommandDispatcher.getDispatcher(), - (SimpleCommandMap) CommandAPIBukkit.get().getCommandMap(), - () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), - command -> command instanceof VanillaCommandWrapper, - node -> new VanillaCommandWrapper(vanillaCommandDispatcher, node), - node -> node.getCommand() instanceof BukkitCommandWrapper - ); - } else { - return new PaperCommandRegistration<>( - () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), - () -> { - SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); - helpMap.clear(); - helpMap.initializeGeneralTopics(); - helpMap.initializeCommands(); - }, - node -> { - Command command = node.getCommand(); - return command instanceof BukkitCommandNode.BukkitBrigCommand; - } - ); - } + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + () -> { + SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); + helpMap.clear(); + helpMap.initializeGeneralTopics(); + helpMap.initializeCommands(); + }, + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); } } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java index f992445f8..d523d7987 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java @@ -1,37 +1,17 @@ package dev.jorel.commandapi.nms; -import com.destroystokyo.paper.profile.CraftPlayerProfile; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.google.common.collect.Collections2; import com.mojang.brigadier.Command; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.tree.LiteralCommandNode; -import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.PaperCommandRegistration; import io.papermc.paper.command.brigadier.PaperCommands; -import io.papermc.paper.command.brigadier.PluginCommandNode; import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; -import net.kyori.adventure.chat.SignedMessage; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.arguments.ColorArgument; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.commands.arguments.GameProfileArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.help.SimpleHelpMap; -import java.util.List; -import java.util.concurrent.CompletableFuture; - public class PaperNMS_1_21_R2 implements PaperNMS { private CommandBuildContext commandBuildContext; @@ -51,32 +31,6 @@ private CommandBuildContext getCommandBuildContext() { } } - @Override - public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - CompletableFuture future = new CompletableFuture<>(); - MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); - return future.join(); - } - - @Override - public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), getCommandBuildContext())); - } - - @Override - public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { - GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); - } - @Override public NMS bukkitNMS() { if (bukkitNMS == null) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java index cfa088d64..2d1db8ba7 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java @@ -1,57 +1,23 @@ package dev.jorel.commandapi.nms; -import com.destroystokyo.paper.profile.CraftPlayerProfile; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.google.common.collect.Collections2; import com.mojang.brigadier.Command; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.tree.LiteralCommandNode; -import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.PaperCommandRegistration; import io.papermc.paper.command.brigadier.PaperCommands; -import io.papermc.paper.command.brigadier.PluginCommandMeta; import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; -import io.papermc.paper.plugin.configuration.PluginMeta; -import net.kyori.adventure.chat.SignedMessage; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.arguments.ColorArgument; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.commands.arguments.GameProfileArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.help.SimpleHelpMap; -import java.lang.reflect.Constructor; -import java.util.List; -import java.util.concurrent.CompletableFuture; - public class PaperNMS_1_21_R3 implements PaperNMS { private CommandBuildContext commandBuildContext; - private static final Constructor pluginCommandNodeConstructor; - private NMS_1_21_R3 bukkitNMS; - static { - Constructor pluginCommandNode; - try { - pluginCommandNode = Class.forName("io.papermc.paper.command.brigadier.PluginCommandNode").getDeclaredConstructor(String.class, PluginMeta.class, LiteralCommandNode.class, String.class); - } catch (ReflectiveOperationException e) { - pluginCommandNode = null; - } - pluginCommandNodeConstructor = pluginCommandNode; - } - private CommandBuildContext getCommandBuildContext() { if (commandBuildContext != null) { return commandBuildContext; @@ -65,32 +31,6 @@ private CommandBuildContext getCommandBuildContext() { } } - @Override - public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - CompletableFuture future = new CompletableFuture<>(); - MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); - return future.join(); - } - - @Override - public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), getCommandBuildContext())); - } - - @Override - public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { - GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); - } - @Override public NMS bukkitNMS() { if (bukkitNMS == null) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java index 90cef0ee5..8258bb892 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java @@ -1,66 +1,23 @@ package dev.jorel.commandapi.nms; -import com.destroystokyo.paper.profile.CraftPlayerProfile; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.google.common.collect.Collections2; import com.mojang.brigadier.Command; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.tree.CommandNode; -import com.mojang.brigadier.tree.LiteralCommandNode; -import dev.jorel.commandapi.CommandAPIBukkit; -import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.PaperCommandRegistration; -import dev.jorel.commandapi.SafeVarHandle; -import io.papermc.paper.command.brigadier.APICommandMeta; import io.papermc.paper.command.brigadier.PaperCommands; import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; -import io.papermc.paper.plugin.configuration.PluginMeta; -import net.kyori.adventure.chat.SignedMessage; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.arguments.ColorArgument; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.commands.arguments.GameProfileArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.help.SimpleHelpMap; -import java.lang.reflect.Constructor; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - public class PaperNMS_1_21_R4 implements PaperNMS { private CommandBuildContext commandBuildContext; - private static final Constructor pluginCommandNodeConstructor; - private static final SafeVarHandle, Object> metaField; private NMS_1_21_R4 bukkitNMS; - static { - Constructor pluginCommandNode; - SafeVarHandle, ?> metaFieldHandle = null; - try { - Class pluginCommandMeta = Class.forName("io.papermc.paper.command.brigadier.PluginCommandMeta"); - pluginCommandNode = pluginCommandMeta.getDeclaredConstructor(PluginMeta.class, String.class, List.class); - metaFieldHandle = SafeVarHandle.ofOrNull(CommandNode.class, "pluginCommandNode", "pluginCommandNode", pluginCommandMeta); - } catch (ReflectiveOperationException e) { - pluginCommandNode = null; - } - pluginCommandNodeConstructor = pluginCommandNode; - metaField = (SafeVarHandle, Object>) metaFieldHandle; - } - private CommandBuildContext getCommandBuildContext() { if (commandBuildContext != null) { return commandBuildContext; @@ -74,32 +31,6 @@ private CommandBuildContext getCommandBuildContext() { } } - @Override - public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - CompletableFuture future = new CompletableFuture<>(); - MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); - return future.join(); - } - - @Override - public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key), getCommandBuildContext())); - } - - @Override - public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { - GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); - } - @Override public NMS bukkitNMS() { if (bukkitNMS == null) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java index b58c43bd0..54d04f229 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java @@ -1,34 +1,17 @@ package dev.jorel.commandapi.nms; -import com.destroystokyo.paper.profile.CraftPlayerProfile; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.google.common.collect.Collections2; import com.mojang.brigadier.Command; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.PaperCommandRegistration; import io.papermc.paper.command.brigadier.PaperCommands; import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; -import net.kyori.adventure.chat.SignedMessage; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.arguments.ColorArgument; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.commands.arguments.GameProfileArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.help.SimpleHelpMap; -import java.util.List; -import java.util.concurrent.CompletableFuture; - public class PaperNMS_1_21_R5 implements PaperNMS { private CommandBuildContext commandBuildContext; @@ -48,32 +31,6 @@ private CommandBuildContext getCommandBuildContext() { } } - @Override - public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - CompletableFuture future = new CompletableFuture<>(); - MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); - return future.join(); - } - - @Override - public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(bukkitNMS.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key))); - } - - @Override - public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { - GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); - } - @Override public NMS bukkitNMS() { if (bukkitNMS == null) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java index 405459b00..964e3658f 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java @@ -1,37 +1,17 @@ package dev.jorel.commandapi.nms; -import com.destroystokyo.paper.profile.CraftPlayerProfile; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.google.common.collect.Collections2; import com.mojang.brigadier.Command; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.tree.LiteralCommandNode; -import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.PaperCommandRegistration; import io.papermc.paper.command.brigadier.PaperCommands; -import io.papermc.paper.command.brigadier.PluginCommandNode; import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; -import net.kyori.adventure.chat.SignedMessage; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.arguments.ColorArgument; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.commands.arguments.GameProfileArgument; -import net.minecraft.commands.arguments.MessageArgument; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.help.SimpleHelpMap; -import java.util.List; -import java.util.concurrent.CompletableFuture; - public class PaperNMS_1_21_R1 implements PaperNMS { private CommandBuildContext commandBuildContext; @@ -51,32 +31,6 @@ private CommandBuildContext getCommandBuildContext() { } } - @Override - public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - CompletableFuture future = new CompletableFuture<>(); - MessageArgument.resolveChatMessage(cmdCtx, key, (message) -> future.complete(message.adventureView())); - return future.join(); - } - - @Override - public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { - final Integer color = ColorArgument.getColor(cmdCtx, key).getColor(); - return color == null ? NamedTextColor.WHITE : NamedTextColor.namedColor(color); - } - - @Override - public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return GsonComponentSerializer.gson().deserialize(net.minecraft.network.chat.Component.Serializer.toJson(ComponentArgument.getComponent(cmdCtx, key), getCommandBuildContext())); - } - - @Override - public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { - GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); - } - @Override public NMS bukkitNMS() { if (bukkitNMS == null) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index a3098ddd0..54e38182a 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -29,7 +29,8 @@ static Object getVersion() { CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); }); } else { - String version = ServerBuildInfo.buildInfo().minecraftVersionId(); + ServerBuildInfo buildInfo = ServerBuildInfo.buildInfo(); + String version = buildInfo.minecraftVersionId(); PaperNMS versionAdapter = switch (version) { case "1.20.6" -> new PaperNMS_1_20_R4(); case "1.21", "1.21.1" -> new PaperNMS_1_21_R1(); @@ -51,21 +52,17 @@ static Object getVersion() { }); } } + version = buildInfo.asString(ServerBuildInfo.StringRepresentation.VERSION_SIMPLE); throw new UnsupportedVersionException(version); } } catch (Throwable error) { if (error instanceof ClassNotFoundException cnfe) { // Thrown when users use versions before the ServerBuildInfo was added. We should inform them // to update since Paper 1.20.6 was experimental then anyway - throw new IllegalStateException("The CommandAPI doesn't support any version before 1.20.6 build 79. Please update!", cnfe); + throw new IllegalStateException("The CommandAPI doesn't support any version before Paper 1.20.6 build 79. Please update your server!", cnfe); + } else { + throw error; } - // Something went sideways when trying to load a platform. This probably means we're shading the wrong mappings. - // Because this is an error we'll just rethrow this (instead of piping it into logError, which we can't really - // do anyway since the CommandAPILogger isn't loaded), but include some helpful(?) logging that might point - // users in the right direction - throw new IllegalStateException("The CommandAPI's NMS hook failed to load! This version of the CommandAPI is " + - (MojangMappedVersionHandler.isMojangMapped() ? "Mojang" : "Spigot") + "-mapped. Have you checked that " + - "you are using a CommandAPI version that matches the mappings that your plugin is using?", error); } } From 49b78ed7f8a6b801deea387c3bd4efeaf5c690bb Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sun, 29 Jun 2025 23:50:26 +0200 Subject: [PATCH 09/63] Remove the datapack reloading step for plugins that shade --- .../config/DefaultBukkitConfig.java | 2 -- .../dev/jorel/commandapi/CommandAPIPaper.java | 16 +++--------- .../commandapi/CommandAPIPaperConfig.java | 26 +++---------------- .../jorel/commandapi/InternalPaperConfig.java | 22 ++++++---------- .../commandapi/PaperCommandRegistration.java | 3 ++- .../jorel/commandapi/nms/APITypeProvider.java | 26 +++---------------- .../dev/jorel/commandapi/CommandAPIMain.java | 5 ++-- 7 files changed, 22 insertions(+), 78 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java index 735f22e75..ceac67650 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java @@ -83,8 +83,6 @@ public static DefaultBukkitConfig createDefaultPaperConfig() { options.put("create-dispatcher-json", CREATE_DISPATCHER_JSON); options.put("use-latest-nms-version", USE_LATEST_NMS_VERSION); options.put("be-lenient-for-minor-versions", BE_LENIENT_FOR_MINOR_VERSIONS); - options.put("hook-paper-reload", SHOULD_HOOK_PAPER_RELOAD); - options.put("skip-initial-datapack-reload", SKIP_RELOAD_DATAPACKS); options.put("plugins-to-convert", PLUGINS_TO_CONVERT); options.put("other-commands-to-convert", OTHER_COMMANDS_TO_CONVERT); options.put("skip-sender-proxy", SKIP_SENDER_PROXY); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java index 7d78f8d44..b709b638a 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -139,22 +139,12 @@ public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(new Listener() { @EventHandler public void onServerReloadResources(ServerResourcesReloadedEvent event) { - // This event is called after Paper is done with everything command related - // which means we can put commands back CommandAPIBukkit.get().getCommandRegistrationStrategy().preReloadDataPacks(); - // Normally, the reloadDataPacks() method is responsible for updating commands for - // online players. If, however, datapacks aren't supposed to be reloaded upon /minecraft:reload - // we have to do this manually here. This won't have any effect on Spigot and Paper version prior to - // paper-1.20.6-65 - if (!CommandAPIPaper.getConfiguration().shouldHookPaperReload()) { - for (Player player : Bukkit.getOnlinePlayers()) { - player.updateCommands(); - } - return; + if (getConfiguration().isCommandAPIPlugin()) { + CommandAPI.logNormal("/minecraft:reload detected. Reloading CommandAPI commands!"); + CommandAPIBukkit.get().reloadDataPacks(); } - CommandAPI.logNormal("/minecraft:reload detected. Reloading CommandAPI commands!"); - CommandAPIBukkit.get().reloadDataPacks(); } }, plugin); CommandAPI.logNormal("Hooked into Paper ServerResourcesReloadedEvent"); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java index a61baf2db..9c3434921 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java @@ -8,7 +8,7 @@ public class CommandAPIPaperConfig extends Comman PluginMeta pluginMeta; LifecycleEventOwner lifecycleEventOwner; - boolean shouldHookPaperReload = false; + boolean isCommandAPIPlugin = false; /** * Creates a new {@code CommandAPIPaperConfig} object @@ -23,28 +23,8 @@ public CommandAPIPaperConfig(PluginMeta pluginMeta, T lifecycleEventOwner) { this.lifecycleEventOwner = lifecycleEventOwner; } - /** - * Sets whether the CommandAPI should skip its datapack reload step after the server - * has finished loading. This does not skip reloading of datapacks when invoked manually - * when {@link #shouldHookPaperReload(boolean)} is set. - * @param skip whether the CommandAPI should skip reloading datapacks when the server has finished loading - * @return this CommandAPIPaperConfig - */ - public CommandAPIPaperConfig skipReloadDatapacks(boolean skip) { - this.skipReloadDatapacks = skip; - return this; - } - - /** - * Sets the CommandAPI to hook into Paper's {@link io.papermc.paper.event.server.ServerResourcesReloadedEvent} when available - * if true. This helps CommandAPI commands to work in datapacks after {@code /minecraft:reload} - * is run. - * - * @param hooked whether the CommandAPI should hook into Paper's {@link io.papermc.paper.event.server.ServerResourcesReloadedEvent} - * @return this CommandAPIPaperConfig - */ - public CommandAPIPaperConfig shouldHookPaperReload(boolean hooked) { - this.shouldHookPaperReload = hooked; + CommandAPIPaperConfig isCommandAPIPlugin(boolean isCommandAPIPlugin) { + this.isCommandAPIPlugin = isCommandAPIPlugin; return this; } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java index 6c476b0b8..5c6e08c10 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java @@ -1,20 +1,23 @@ package dev.jorel.commandapi; import io.papermc.paper.plugin.configuration.PluginMeta; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; @SuppressWarnings("UnstableApiUsage") public class InternalPaperConfig extends InternalBukkitConfig { private final PluginMeta pluginMeta; + private final boolean isCommandAPIPlugin; - // Whether to hook into paper's reload event to reload datapacks when /minecraft:reload is run - private final boolean shouldHookPaperReload; - - public InternalPaperConfig(CommandAPIPaperConfig config) { + public InternalPaperConfig(CommandAPIPaperConfig config) { super(config); this.pluginMeta = config.pluginMeta; - this.shouldHookPaperReload = config.shouldHookPaperReload; + this.isCommandAPIPlugin = config.isCommandAPIPlugin; + } + + boolean isCommandAPIPlugin() { + return isCommandAPIPlugin; } /** @@ -24,13 +27,4 @@ public PluginMeta getPluginMeta() { return pluginMeta; } - /** - * @return Whether the CommandAPI should hook into Paper's {@link io.papermc.paper.event.server.ServerResourcesReloadedEvent} - * when available to perform the CommandAPI's custom datapack reload when {@code /minecraft:reload} - * is run. - */ - public boolean shouldHookPaperReload() { - return shouldHookPaperReload; - } - } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java index d47a4ddd3..3d7014984 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java @@ -101,10 +101,11 @@ public void unregister(String commandName, boolean unregisterNamespaces, boolean @Override public void preReloadDataPacks() { - reloadHelpTopics.run(); + reloadHelpTopics.run(); // TODO: Is this necessary CommandAPIBukkit.get().updateHelpForCommands(CommandAPI.getRegisteredCommands()); } + @SuppressWarnings("ConstantValue") void registerLifecycleEvent() { boolean bootstrap = Bukkit.getServer() == null; if (bootstrap && !lifecycleEventRegistered[0]) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index 70d194569..5edc9f8eb 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -878,40 +878,22 @@ public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender cal @Override public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT(cmdCtx, key, - (ctx, name) -> { - CompletableFuture signedMessageResolver = ctx.getArgument(name, SignedMessageResolver.class).resolveSignedMessage(name, ctx); - return signedMessageResolver.join(); - }, - ((PaperNMS) paperNMS)::getChat - ); + return cmdCtx.getArgument(key, SignedMessageResolver.class).resolveSignedMessage(key, cmdCtx).join(); } @Override public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, NamedTextColor.class), - ((PaperNMS) paperNMS)::getChatColor - ); + return cmdCtx.getArgument(key, NamedTextColor.class); } @Override public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, Component.class), - ((PaperNMS) paperNMS)::getChatComponent - ); + return cmdCtx.getArgument(key, Component.class); } @Override public List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT(cmdCtx, key, - (ctx, name) -> { - PlayerProfileListResolver profileListResolver = ctx.getArgument(name, PlayerProfileListResolver.class); - return new ArrayList<>(profileListResolver.resolve(ctx.getSource())); - }, - (ctx, name) -> ((PaperNMS) paperNMS).getProfile(ctx, name) - ); + return new ArrayList<>(cmdCtx.getArgument(key, PlayerProfileListResolver.class).resolve(cmdCtx.getSource())); } @Override diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java index 1f7eafdfb..970cccc04 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -53,9 +53,8 @@ public void onLoad() { .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) - .shouldHookPaperReload(fileConfig.getBoolean("hook-paper-reload")) - .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")) - .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")); + .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")) + .isCommandAPIPlugin(true); for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { From b18c62564c4865e55f5aea7302bfce8bf89d709e Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sun, 29 Jun 2025 23:59:22 +0200 Subject: [PATCH 10/63] Remove useless parameter --- .../main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java | 4 ++-- .../src/main/java/dev/jorel/commandapi/CommandAPIMain.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java index 9c3434921..fe6cd93bb 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java @@ -23,8 +23,8 @@ public CommandAPIPaperConfig(PluginMeta pluginMeta, T lifecycleEventOwner) { this.lifecycleEventOwner = lifecycleEventOwner; } - CommandAPIPaperConfig isCommandAPIPlugin(boolean isCommandAPIPlugin) { - this.isCommandAPIPlugin = isCommandAPIPlugin; + CommandAPIPaperConfig isCommandAPIPlugin() { + this.isCommandAPIPlugin = true; return this; } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java index 970cccc04..6269bbd77 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -54,7 +54,7 @@ public void onLoad() { .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")) - .isCommandAPIPlugin(true); + .isCommandAPIPlugin(); for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { From fc262c5273794d58e4ca00b3365aa4deaf101cc8 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sat, 5 Jul 2025 16:25:40 +0200 Subject: [PATCH 11/63] Fix bukkitNMS returning NMS instead of NMS --- .../dev/jorel/commandapi/nms/PaperNMS.java | 2 +- .../commandapi-paper-1.20.5/pom.xml | 1 + .../commandapi/nms/PaperNMS_1_20_R4.java | 4 +- .../commandapi-paper-1.21.2/pom.xml | 1 + .../commandapi/nms/PaperNMS_1_21_R2.java | 4 +- .../commandapi-paper-1.21.4/pom.xml | 1 + .../commandapi/nms/PaperNMS_1_21_R3.java | 4 +- .../commandapi-paper-1.21.5/pom.xml | 1 + .../commandapi/nms/PaperNMS_1_21_R4.java | 4 +- .../commandapi-paper-1.21.6/pom.xml | 1 + .../commandapi/nms/PaperNMS_1_21_R5.java | 4 +- .../commandapi-paper-1.21/pom.xml | 1 + .../commandapi/nms/PaperNMS_1_21_R1.java | 4 +- .../jorel/commandapi/nms/APITypeProvider.java | 202 +++++++++--------- .../jorel/commandapi/CommandAPISpigot.java | 2 +- .../dev/jorel/commandapi/nms/SpigotNMS.java | 4 +- .../commandapi-spigot-1.20.2/pom.xml | 2 + .../commandapi/nms/SpigotNMS_1_20_R2.java | 2 +- .../commandapi-spigot-1.20.3/pom.xml | 2 + .../commandapi/nms/SpigotNMS_1_20_R3.java | 2 +- .../commandapi-spigot-1.20.5/pom.xml | 2 + .../commandapi/nms/SpigotNMS_1_20_R4.java | 2 +- .../commandapi-spigot-1.20/pom.xml | 2 + .../commandapi/nms/SpigotNMS_1_20_R1.java | 2 +- .../commandapi-spigot-1.21.2/pom.xml | 2 + .../commandapi/nms/SpigotNMS_1_21_R2.java | 2 +- .../commandapi-spigot-1.21.4/pom.xml | 2 + .../commandapi/nms/SpigotNMS_1_21_R3.java | 2 +- .../commandapi-spigot-1.21.5/pom.xml | 2 + .../commandapi/nms/SpigotNMS_1_21_R4.java | 2 +- .../commandapi-spigot-1.21.6/pom.xml | 1 + .../commandapi/nms/SpigotNMS_1_21_R5.java | 3 +- .../commandapi-spigot-1.21/pom.xml | 2 + .../commandapi/nms/SpigotNMS_1_21_R1.java | 2 +- 34 files changed, 147 insertions(+), 129 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java index a96787495..11d3065a8 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/PaperNMS.java @@ -4,7 +4,7 @@ public interface PaperNMS { - NMS bukkitNMS(); + NMS bukkitNMS(); CommandRegistrationStrategy createCommandRegistrationStrategy(); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml index 61aae12d3..45b3c4d70 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml @@ -71,6 +71,7 @@ dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided
diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java index 68346a81e..64eb3f606 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_20_R4.java @@ -32,11 +32,11 @@ private CommandBuildContext getCommandBuildContext() { } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_20_R4(this::getCommandBuildContext); } - return (NMS) bukkitNMS; + return bukkitNMS; } @Override diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml index d4d576b4c..582a4f97d 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml @@ -66,6 +66,7 @@ dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java index d523d7987..80dad1d59 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R2.java @@ -32,11 +32,11 @@ private CommandBuildContext getCommandBuildContext() { } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R2(this::getCommandBuildContext); } - return (NMS) bukkitNMS; + return bukkitNMS; } @Override diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml index 81e57c7f1..dbc846eb2 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml @@ -66,6 +66,7 @@ dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java index 2d1db8ba7..a76646138 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R3.java @@ -32,11 +32,11 @@ private CommandBuildContext getCommandBuildContext() { } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R3(this::getCommandBuildContext); } - return (NMS) bukkitNMS; + return bukkitNMS; } @Override diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml index 711413c1f..7580e0a52 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml @@ -66,6 +66,7 @@ dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java index 8258bb892..deb645a6c 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R4.java @@ -32,11 +32,11 @@ private CommandBuildContext getCommandBuildContext() { } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R4(this::getCommandBuildContext); } - return (NMS) bukkitNMS; + return bukkitNMS; } @Override diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml index 397126e3a..86ccec63f 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml @@ -66,6 +66,7 @@ dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java index 54d04f229..49cd65d05 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R5.java @@ -32,11 +32,11 @@ private CommandBuildContext getCommandBuildContext() { } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R5(this::getCommandBuildContext); } - return (NMS) bukkitNMS; + return bukkitNMS; } @Override diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml index 112b4e9c1..2e343f006 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml @@ -73,6 +73,7 @@ dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java index 964e3658f..604ac2fb1 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R1.java @@ -32,11 +32,11 @@ private CommandBuildContext getCommandBuildContext() { } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R1(this::getCommandBuildContext); } - return (NMS) bukkitNMS; + return bukkitNMS; } @Override diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index 5edc9f8eb..c5e1637a9 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -8,7 +8,6 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.SuggestionProvider; -import com.mojang.brigadier.tree.LiteralCommandNode; import dev.jorel.commandapi.BukkitTooltip; import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.arguments.ArgumentSubType; @@ -82,7 +81,6 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.concurrent.CompletableFuture; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; @@ -91,10 +89,10 @@ @SuppressWarnings("UnstableApiUsage") public class APITypeProvider extends BundledNMS { - private final PaperNMS paperNMS; + private final PaperNMS paperNMS; public APITypeProvider(PaperNMS paperNMS) { - this.paperNMS = paperNMS; + this.paperNMS = (PaperNMS) paperNMS; bukkitNMS(); } @@ -151,28 +149,28 @@ private T parse( @Override public ArgumentType _ArgumentAdvancement() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentAdvancement() + () -> paperNMS.bukkitNMS()._ArgumentAdvancement() ); } @Override public ArgumentType _ArgumentAngle() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentAngle() + () -> paperNMS.bukkitNMS()._ArgumentAngle() ); } @Override public ArgumentType _ArgumentAxis() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentAxis() + () -> paperNMS.bukkitNMS()._ArgumentAxis() ); } @Override public ArgumentType _ArgumentBlockPredicate() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentBlockPredicate() + () -> paperNMS.bukkitNMS()._ArgumentBlockPredicate() ); } @@ -180,7 +178,7 @@ public ArgumentType _ArgumentBlockPredicate() { public ArgumentType _ArgumentBlockState() { return getArgumentType( () -> ArgumentTypes.blockState(), - () -> paperNMS.bukkitNMS()._ArgumentBlockState() + () -> paperNMS.bukkitNMS()._ArgumentBlockState() ); } @@ -188,7 +186,7 @@ public ArgumentType _ArgumentBlockState() { public ArgumentType _ArgumentChat() { return getArgumentType( () -> ArgumentTypes.signedMessage(), - () -> paperNMS.bukkitNMS()._ArgumentChat() + () -> paperNMS.bukkitNMS()._ArgumentChat() ); } @@ -196,7 +194,7 @@ public ArgumentType _ArgumentChat() { public ArgumentType _ArgumentChatComponent() { return getArgumentType( () -> ArgumentTypes.component(), - () -> paperNMS.bukkitNMS()._ArgumentChatComponent() + () -> paperNMS.bukkitNMS()._ArgumentChatComponent() ); } @@ -204,7 +202,7 @@ public ArgumentType _ArgumentChatComponent() { public ArgumentType _ArgumentChatFormat() { return getArgumentType( () -> ArgumentTypes.namedColor(), - () -> paperNMS.bukkitNMS()._ArgumentChatFormat() + () -> paperNMS.bukkitNMS()._ArgumentChatFormat() ); } @@ -212,7 +210,7 @@ public ArgumentType _ArgumentChatFormat() { public ArgumentType _ArgumentDimension() { return getArgumentType( () -> ArgumentTypes.world(), - () -> paperNMS.bukkitNMS()._ArgumentDimension() + () -> paperNMS.bukkitNMS()._ArgumentDimension() ); } @@ -220,7 +218,7 @@ public ArgumentType _ArgumentDimension() { public ArgumentType _ArgumentEnchantment() { return getArgumentType( () -> ArgumentTypes.resource(RegistryKey.ENCHANTMENT), - () -> paperNMS.bukkitNMS()._ArgumentEnchantment() + () -> paperNMS.bukkitNMS()._ArgumentEnchantment() ); } @@ -234,7 +232,7 @@ public ArgumentType _ArgumentEntity(ArgumentSubType subType) { case ENTITYSELECTOR_MANY_PLAYERS -> ArgumentTypes.players(); default -> throw new Exception(); // Doesn't matter too much, it'll get to the right exception anyway }, - () -> paperNMS.bukkitNMS()._ArgumentEntity(subType) + () -> paperNMS.bukkitNMS()._ArgumentEntity(subType) ); } @@ -242,7 +240,7 @@ public ArgumentType _ArgumentEntity(ArgumentSubType subType) { public ArgumentType _ArgumentEntitySummon() { return getArgumentType( () -> ArgumentTypes.resource(RegistryKey.ENTITY_TYPE), - () -> paperNMS.bukkitNMS()._ArgumentEntitySummon() + () -> paperNMS.bukkitNMS()._ArgumentEntitySummon() ); } @@ -250,7 +248,7 @@ public ArgumentType _ArgumentEntitySummon() { public ArgumentType _ArgumentFloatRange() { return getArgumentType( () -> ArgumentTypes.doubleRange(), - () -> paperNMS.bukkitNMS()._ArgumentFloatRange() + () -> paperNMS.bukkitNMS()._ArgumentFloatRange() ); } @@ -258,7 +256,7 @@ public ArgumentType _ArgumentFloatRange() { public ArgumentType _ArgumentIntRange() { return getArgumentType( () -> ArgumentTypes.integerRange(), - () -> paperNMS.bukkitNMS()._ArgumentIntRange() + () -> paperNMS.bukkitNMS()._ArgumentIntRange() ); } @@ -266,7 +264,7 @@ public ArgumentType _ArgumentIntRange() { public ArgumentType _ArgumentItemPredicate() { return getArgumentType( () -> ArgumentTypes.itemPredicate(), - () -> paperNMS.bukkitNMS()._ArgumentItemPredicate() + () -> paperNMS.bukkitNMS()._ArgumentItemPredicate() ); } @@ -274,14 +272,14 @@ public ArgumentType _ArgumentItemPredicate() { public ArgumentType _ArgumentItemStack() { return getArgumentType( () -> ArgumentTypes.itemStack(), - () -> paperNMS.bukkitNMS()._ArgumentItemStack() + () -> paperNMS.bukkitNMS()._ArgumentItemStack() ); } @Override public ArgumentType _ArgumentMathOperation() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentMathOperation() + () -> paperNMS.bukkitNMS()._ArgumentMathOperation() ); } @@ -289,7 +287,7 @@ public ArgumentType _ArgumentMathOperation() { public ArgumentType _ArgumentMinecraftKeyRegistered() { return getArgumentType( () -> ArgumentTypes.namespacedKey(), - () -> paperNMS.bukkitNMS()._ArgumentMinecraftKeyRegistered() + () -> paperNMS.bukkitNMS()._ArgumentMinecraftKeyRegistered() ); } @@ -297,21 +295,21 @@ public ArgumentType _ArgumentMinecraftKeyRegistered() { public ArgumentType _ArgumentMobEffect() { return getArgumentType( () -> ArgumentTypes.resource(RegistryKey.MOB_EFFECT), - () -> paperNMS.bukkitNMS()._ArgumentMobEffect() + () -> paperNMS.bukkitNMS()._ArgumentMobEffect() ); } @Override public ArgumentType _ArgumentNBTCompound() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentNBTCompound() + () -> paperNMS.bukkitNMS()._ArgumentNBTCompound() ); } @Override public ArgumentType _ArgumentParticle() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentParticle() + () -> paperNMS.bukkitNMS()._ArgumentParticle() ); } @@ -319,14 +317,14 @@ public ArgumentType _ArgumentParticle() { public ArgumentType _ArgumentPosition() { return getArgumentType( () -> ArgumentTypes.blockPosition(), - () -> paperNMS.bukkitNMS()._ArgumentPosition() + () -> paperNMS.bukkitNMS()._ArgumentPosition() ); } @Override public ArgumentType _ArgumentPosition2D() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentPosition2D() + () -> paperNMS.bukkitNMS()._ArgumentPosition2D() ); } @@ -334,14 +332,14 @@ public ArgumentType _ArgumentPosition2D() { public ArgumentType _ArgumentProfile() { return getArgumentType( () -> ArgumentTypes.playerProfiles(), - () -> paperNMS.bukkitNMS()._ArgumentProfile() + () -> paperNMS.bukkitNMS()._ArgumentProfile() ); } @Override public ArgumentType _ArgumentRecipe() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentRecipe() + () -> paperNMS.bukkitNMS()._ArgumentRecipe() ); } @@ -349,7 +347,7 @@ public ArgumentType _ArgumentRecipe() { public ArgumentType _ArgumentRotation() { return getArgumentType( () -> ArgumentTypes.rotation(), - () -> paperNMS.bukkitNMS()._ArgumentRotation() + () -> paperNMS.bukkitNMS()._ArgumentRotation() ); } @@ -357,14 +355,14 @@ public ArgumentType _ArgumentRotation() { public ArgumentType _ArgumentScoreboardCriteria() { return getArgumentType( () -> ArgumentTypes.objectiveCriteria(), - () -> paperNMS.bukkitNMS()._ArgumentScoreboardCriteria() + () -> paperNMS.bukkitNMS()._ArgumentScoreboardCriteria() ); } @Override public ArgumentType _ArgumentScoreboardObjective() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentScoreboardObjective() + () -> paperNMS.bukkitNMS()._ArgumentScoreboardObjective() ); } @@ -372,28 +370,28 @@ public ArgumentType _ArgumentScoreboardObjective() { public ArgumentType _ArgumentScoreboardSlot() { return getArgumentType( () -> ArgumentTypes.scoreboardDisplaySlot(), - () -> paperNMS.bukkitNMS()._ArgumentScoreboardSlot() + () -> paperNMS.bukkitNMS()._ArgumentScoreboardSlot() ); } @Override public ArgumentType _ArgumentScoreboardTeam() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentScoreboardTeam() + () -> paperNMS.bukkitNMS()._ArgumentScoreboardTeam() ); } @Override public ArgumentType _ArgumentScoreholder(ArgumentSubType subType) { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentScoreholder(subType) + () -> paperNMS.bukkitNMS()._ArgumentScoreholder(subType) ); } @Override public ArgumentType _ArgumentTag() { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentTag() + () -> paperNMS.bukkitNMS()._ArgumentTag() ); } @@ -401,7 +399,7 @@ public ArgumentType _ArgumentTag() { public ArgumentType _ArgumentTime() { return getArgumentType( () -> ArgumentTypes.time(), - () -> paperNMS.bukkitNMS()._ArgumentTime() + () -> paperNMS.bukkitNMS()._ArgumentTime() ); } @@ -409,14 +407,14 @@ public ArgumentType _ArgumentTime() { public ArgumentType _ArgumentUUID() { return getArgumentType( () -> ArgumentTypes.uuid(), - () -> paperNMS.bukkitNMS()._ArgumentUUID() + () -> paperNMS.bukkitNMS()._ArgumentUUID() ); } @Override public ArgumentType _ArgumentVec2(boolean centerPosition) { return getArgumentType( - () -> paperNMS.bukkitNMS()._ArgumentVec2(centerPosition) + () -> paperNMS.bukkitNMS()._ArgumentVec2(centerPosition) ); } @@ -424,7 +422,7 @@ public ArgumentType _ArgumentVec2(boolean centerPosition) { public ArgumentType _ArgumentVec3(boolean centerPosition) { return getArgumentType( () -> ArgumentTypes.finePosition(centerPosition), - () -> paperNMS.bukkitNMS()._ArgumentVec3(centerPosition) + () -> paperNMS.bukkitNMS()._ArgumentVec3(centerPosition) ); } @@ -432,53 +430,53 @@ public ArgumentType _ArgumentVec3(boolean centerPosition) { public ArgumentType _ArgumentSyntheticBiome() { return getArgumentType( () -> ArgumentTypes.resource(RegistryKey.BIOME), - () -> paperNMS.bukkitNMS()._ArgumentSyntheticBiome() + () -> paperNMS.bukkitNMS()._ArgumentSyntheticBiome() ); } @Override public String[] compatibleVersions() { - return paperNMS.bukkitNMS().compatibleVersions(); + return paperNMS.bukkitNMS().compatibleVersions(); } @Override public String convert(ItemStack is) { - return paperNMS.bukkitNMS().convert(is); + return paperNMS.bukkitNMS().convert(is); } @Override public String convert(ParticleData particle) { - return paperNMS.bukkitNMS().convert(particle); + return paperNMS.bukkitNMS().convert(particle); } @Override public String convert(PotionEffectType potion) { - return paperNMS.bukkitNMS().convert(potion); + return paperNMS.bukkitNMS().convert(potion); } @Override public String convert(Sound sound) { - return paperNMS.bukkitNMS().convert(sound); + return paperNMS.bukkitNMS().convert(sound); } @Override public Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getAdvancement(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getAdvancement(ctx, name) ); } @Override public float getAngle(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getAngle(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getAngle(ctx, name) ); } @Override public EnumSet getAxis(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getAxis(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getAxis(ctx, name) ); } @@ -490,14 +488,14 @@ public RegistryParser getBiome(CommandContext cmdCtx, () -> ctx.getArgument(name, Biome.class), () -> ctx.getArgument(name, Biome.class).getKey() ), - (ctx, name) -> paperNMS.bukkitNMS().getBiome(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getBiome(ctx, name) ); } @Override public Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getBlockPredicate(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getBlockPredicate(ctx, name) ); } @@ -505,7 +503,7 @@ public Predicate getBlockPredicate(CommandContext cmd public BlockState getBlockState(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, BlockState.class), - (ctx, name) -> paperNMS.bukkitNMS().getBlockState(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getBlockState(ctx, name) ); } @@ -513,7 +511,7 @@ public BlockState getBlockState(CommandContext cmdCtx, Strin public World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, World.class), - (ctx, name) -> paperNMS.bukkitNMS().getDimension(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getDimension(ctx, name) ); } @@ -521,7 +519,7 @@ public World getDimension(CommandContext cmdCtx, String key) public Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, Enchantment.class), - (ctx, name) -> paperNMS.bukkitNMS().getEnchantment(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getEnchantment(ctx, name) ); } @@ -534,7 +532,7 @@ public EntitySelectorParser getEntitySelector(CommandContext (allowEmpty) -> ctx.getArgument(name, PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()), (allowEmpty) -> ctx.getArgument(name, EntitySelectorArgumentResolver.class).resolve(ctx.getSource()) ), - (ctx, name) -> paperNMS.bukkitNMS().getEntitySelector(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getEntitySelector(ctx, name) ); } @@ -542,7 +540,7 @@ public EntitySelectorParser getEntitySelector(CommandContext public EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, EntityType.class), - (ctx, name) -> paperNMS.bukkitNMS().getEntityType(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getEntityType(ctx, name) ); } @@ -555,25 +553,25 @@ public DoubleRange getDoubleRange(CommandContext cmdCtx, Str final double high = rangeProvider.range().hasUpperBound() ? rangeProvider.range().upperEndpoint() : Double.MAX_VALUE; return new DoubleRange(low, high); }, - (ctx, name) -> paperNMS.bukkitNMS().getDoubleRange(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getDoubleRange(ctx, name) ); } @Override public FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getFunction(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getFunction(ctx, name) ); } @Override public SimpleFunctionWrapper getFunction(NamespacedKey key) { - return paperNMS.bukkitNMS().getFunction(key); + return paperNMS.bukkitNMS().getFunction(key); } @Override public Set getFunctions() { - return paperNMS.bukkitNMS().getFunctions(); + return paperNMS.bukkitNMS().getFunctions(); } @Override @@ -585,7 +583,7 @@ public IntegerRange getIntRange(CommandContext cmdCtx, Strin final int high = rangeProvider.range().hasUpperBound() ? rangeProvider.range().upperEndpoint() : Integer.MAX_VALUE; return new IntegerRange(low, high); }, - (ctx, name) -> paperNMS.bukkitNMS().getIntRange(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getIntRange(ctx, name) ); } @@ -593,7 +591,7 @@ public IntegerRange getIntRange(CommandContext cmdCtx, Strin public ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, ItemStack.class), - (ctx, name) -> paperNMS.bukkitNMS().getItemStack(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getItemStack(ctx, name) ); } @@ -601,21 +599,21 @@ public ItemStack getItemStack(CommandContext cmdCtx, String public Predicate getItemStackPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, ItemStackPredicate.class), - (ctx, name) -> paperNMS.bukkitNMS().getItemStackPredicate(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getItemStackPredicate(ctx, name) ); } @Override public Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getLocation2DBlock(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getLocation2DBlock(ctx, name) ); } @Override public Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getLocation2DPrecise(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getLocation2DPrecise(ctx, name) ); } @@ -626,7 +624,7 @@ public Location getLocationBlock(CommandContext cmdCtx, Stri BlockPosition blockPosition = ctx.getArgument(name, BlockPositionResolver.class).resolve(ctx.getSource()); return new Location(getWorldForCSS(ctx.getSource()), blockPosition.blockX(), blockPosition.blockY(), blockPosition.blockZ()); }, - (ctx, name) -> paperNMS.bukkitNMS().getLocationBlock(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getLocationBlock(ctx, name) ); } @@ -637,7 +635,7 @@ public Location getLocationPrecise(CommandContext cmdCtx, St FinePosition finePosition = ctx.getArgument(name, FinePositionResolver.class).resolve(ctx.getSource()); return new Location(getWorldForCSS(ctx.getSource()), finePosition.x(), finePosition.y(), finePosition.z()); }, - (ctx, name) -> paperNMS.bukkitNMS().getLocationPrecise(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getLocationPrecise(ctx, name) ); } @@ -645,14 +643,14 @@ public Location getLocationPrecise(CommandContext cmdCtx, St public LootTable getLootTable(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, (ctx, name) -> Bukkit.getLootTable(ctx.getArgument(name, NamespacedKey.class)), - (ctx, name) -> paperNMS.bukkitNMS().getLootTable(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getLootTable(ctx, name) ); } @Override public MathOperation getMathOperation(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getMathOperation(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getMathOperation(ctx, name) ); } @@ -660,21 +658,21 @@ public MathOperation getMathOperation(CommandContext cmdCtx, public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, NamespacedKey.class), - (ctx, name) -> paperNMS.bukkitNMS().getMinecraftKey(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getMinecraftKey(ctx, name) ); } @Override public Object getNBTCompound(CommandContext cmdCtx, String key, Function nbtContainerConstructor) { return parse(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getNBTCompound(ctx, name, nbtContainerConstructor) + (ctx, name) -> paperNMS.bukkitNMS().getNBTCompound(ctx, name, nbtContainerConstructor) ); } @Override public Objective getObjective(CommandContext cmdCtx, String key) throws IllegalArgumentException, CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getObjective(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getObjective(ctx, name) ); } @@ -682,14 +680,14 @@ public Objective getObjective(CommandContext cmdCtx, String public String getObjectiveCriteria(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, Criteria.class).getName(), - (ctx, name) -> paperNMS.bukkitNMS().getObjectiveCriteria(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getObjectiveCriteria(ctx, name) ); } @Override public ParticleData getParticle(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getParticle(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getParticle(ctx, name) ); } @@ -697,7 +695,7 @@ public ParticleData getParticle(CommandContext cmdCtx, St public OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, (ctx, name) -> Bukkit.getOfflinePlayer(getIdFromProfile(ctx, name)), - (ctx, name) -> paperNMS.bukkitNMS().getOfflinePlayer(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getOfflinePlayer(ctx, name) ); } @@ -717,14 +715,14 @@ public RegistryParser getPotionEffect(CommandContext ctx.getArgument(name, PotionEffectType.class), () -> ctx.getArgument(name, PotionEffectType.class).getKey() ), - (ctx, name) -> paperNMS.bukkitNMS().getPotionEffect(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getPotionEffect(ctx, name) ); } @Override public Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getRecipe(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getRecipe(ctx, name) ); } @@ -735,7 +733,7 @@ public Rotation getRotation(CommandContext cmdCtx, String ke io.papermc.paper.math.Rotation rotation = ctx.getArgument(name, RotationResolver.class).resolve((CommandSourceStack) ctx.getSource()); return new Rotation(rotation.yaw(), rotation.pitch()); }, - (ctx, name) -> paperNMS.bukkitNMS().getRotation(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getRotation(ctx, name) ); } @@ -746,28 +744,28 @@ public ScoreboardSlot getScoreboardSlot(CommandContext cmdCt DisplaySlot displaySlot = ctx.getArgument(name, DisplaySlot.class); return ScoreboardSlot.of(displaySlot); }, - (ctx, name) -> paperNMS.bukkitNMS().getScoreboardSlot(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getScoreboardSlot(ctx, name) ); } @Override public Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getScoreHolderMultiple(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getScoreHolderMultiple(ctx, name) ); } @Override public String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getScoreHolderSingle(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getScoreHolderSingle(ctx, name) ); } @Override public Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getTeam(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getTeam(ctx, name) ); } @@ -775,7 +773,7 @@ public Team getTeam(CommandContext cmdCtx, String key) throw public int getTime(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, Integer.class), - (ctx, name) -> paperNMS.bukkitNMS().getTime(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getTime(ctx, name) ); } @@ -783,18 +781,18 @@ public int getTime(CommandContext cmdCtx, String key) { public UUID getUUID(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, (ctx, name) -> ctx.getArgument(name, UUID.class), - (ctx, name) -> paperNMS.bukkitNMS().getUUID(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getUUID(ctx, name) ); } @Override public World getWorldForCSS(CommandSourceStack clw) { - return paperNMS.bukkitNMS().getWorldForCSS(clw); + return paperNMS.bukkitNMS().getWorldForCSS(clw); } @Override public SimpleCommandMap getSimpleCommandMap() { - return paperNMS.bukkitNMS().getSimpleCommandMap(); + return paperNMS.bukkitNMS().getSimpleCommandMap(); } @Override @@ -807,73 +805,73 @@ public RegistryParser getSound(CommandContext cmdCtx, () -> namespace ); }, - (ctx, name) -> paperNMS.bukkitNMS().getSound(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getSound(ctx, name) ); } @Override public SuggestionProvider getSuggestionProvider(SuggestionProviders provider) { - return paperNMS.bukkitNMS().getSuggestionProvider(provider); + return paperNMS.bukkitNMS().getSuggestionProvider(provider); } @Override public SimpleFunctionWrapper[] getTag(NamespacedKey key) { - return paperNMS.bukkitNMS().getTag(key); + return paperNMS.bukkitNMS().getTag(key); } @Override public Set getTags() { - return paperNMS.bukkitNMS().getTags(); + return paperNMS.bukkitNMS().getTags(); } @Override public void reloadDataPacks() { - paperNMS.bukkitNMS().reloadDataPacks(); + paperNMS.bukkitNMS().reloadDataPacks(); } @Override public HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { - return paperNMS.bukkitNMS().generateHelpTopic(commandName, shortDescription, fullDescription, permission); + return paperNMS.bukkitNMS().generateHelpTopic(commandName, shortDescription, fullDescription, permission); } @Override public Map getHelpMap() { - return paperNMS.bukkitNMS().getHelpMap(); + return paperNMS.bukkitNMS().getHelpMap(); } @Override public Message generateMessageFromJson(String json) { - return paperNMS.bukkitNMS().generateMessageFromJson(json); + return paperNMS.bukkitNMS().generateMessageFromJson(json); } @Override public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - return paperNMS.bukkitNMS().getSenderForCommand(cmdCtx, forceNative); + return paperNMS.bukkitNMS().getSenderForCommand(cmdCtx, forceNative); } @Override public BukkitCommandSender getCommandSenderFromCommandSource(Source css) { - return paperNMS.bukkitNMS().getCommandSenderFromCommandSource(css); + return paperNMS.bukkitNMS().getCommandSenderFromCommandSource(css); } @Override public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { - return paperNMS.bukkitNMS().getBrigadierSourceFromCommandSender(sender); + return paperNMS.bukkitNMS().getBrigadierSourceFromCommandSender(sender); } @Override public void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException { - paperNMS.bukkitNMS().createDispatcherFile(file, brigadierDispatcher); + paperNMS.bukkitNMS().createDispatcherFile(file, brigadierDispatcher); } @Override public T getMinecraftServer() { - return paperNMS.bukkitNMS().getMinecraftServer(); + return paperNMS.bukkitNMS().getMinecraftServer(); } @Override public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world) { - return paperNMS.bukkitNMS().createNativeProxyCommandSender(caller, callee, location, world); + return paperNMS.bukkitNMS().createNativeProxyCommandSender(caller, callee, location, world); } @Override @@ -897,8 +895,8 @@ public List getProfile(CommandContext cmdCtx, } @Override - public NMS bukkitNMS() { - return paperNMS.bukkitNMS(); + public NMS bukkitNMS() { + return ((PaperNMS) paperNMS).bukkitNMS(); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java index 72eea29cf..1e1d1b633 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java @@ -33,7 +33,7 @@ public abstract class CommandAPISpigot extends CommandAPIBukkit @SuppressWarnings("unchecked") protected CommandAPISpigot() { - this.nms = (NMS) bukkitNMS(); + this.nms = bukkitNMS(); CommandAPISpigot.spigot = this; } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java index 59f557a39..5fbc4d9b5 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/nms/SpigotNMS.java @@ -2,10 +2,8 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.tree.CommandNode; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.ChatColor; -import org.bukkit.command.Command; import org.bukkit.profile.PlayerProfile; import java.util.List; @@ -20,6 +18,6 @@ public interface SpigotNMS { List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException; - NMS bukkitNMS(); + NMS bukkitNMS(); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml index ce12493c1..c3817e289 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml @@ -60,12 +60,14 @@ dev.jorel commandapi-bukkit-1.20.2 ${project.version} + mojang-mapped provided dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java index ed07d812b..b878286bc 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java @@ -52,7 +52,7 @@ public final List getProfile(CommandContext c } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_20_R2(); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml index c64239e6c..a1c20be76 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml @@ -60,12 +60,14 @@ dev.jorel commandapi-bukkit-1.20.3 ${project.version} + mojang-mapped provided dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java index 8967280b0..8e951def6 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java @@ -52,7 +52,7 @@ public final List getProfile(CommandContext c } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_20_R3(); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml index 738ab3633..95d1b98df 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml @@ -60,12 +60,14 @@ dev.jorel commandapi-bukkit-1.20.5 ${project.version} + mojang-mapped provided dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java index 943c98ae9..2257ff598 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java @@ -66,7 +66,7 @@ public final List getProfile(CommandContext c } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_20_R4(() -> COMMAND_BUILD_CONTEXT); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml index fa3c77dc8..26da61d4f 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml @@ -60,12 +60,14 @@ dev.jorel commandapi-bukkit-1.20 ${project.version} + mojang-mapped provided dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java index 89ab4277d..de1e4d51a 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java @@ -52,7 +52,7 @@ public final List getProfile(CommandContext c } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_20_R1(); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml index 9f525f022..5a3482d84 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml @@ -60,12 +60,14 @@ dev.jorel commandapi-bukkit-1.21.2 ${project.version} + mojang-mapped provided dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java index 733561d67..6b84d1c8e 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java @@ -66,7 +66,7 @@ public final List getProfile(CommandContext c } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R2(() -> COMMAND_BUILD_CONTEXT); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml index 33fe3921d..a9fde11f1 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml @@ -60,12 +60,14 @@ dev.jorel commandapi-bukkit-1.21.4 ${project.version} + mojang-mapped provided dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java index 057eb23f2..19a41d0df 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java @@ -66,7 +66,7 @@ public final List getProfile(CommandContext c } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R3(() -> COMMAND_BUILD_CONTEXT); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml index de29d9110..99bfb5616 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml @@ -60,12 +60,14 @@ dev.jorel commandapi-bukkit-1.21.5 ${project.version} + mojang-mapped provided dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java index 09caabe84..206450723 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java @@ -66,7 +66,7 @@ public final List getProfile(CommandContext c } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R4(() -> COMMAND_BUILD_CONTEXT); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml index 21280efec..2c94f6573 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml @@ -67,6 +67,7 @@ dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java index 6e287311a..331ffdc30 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java @@ -14,7 +14,6 @@ import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.commands.arguments.GameProfileArgument; import net.minecraft.commands.arguments.MessageArgument; -import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -66,7 +65,7 @@ public final List getProfile(CommandContext c } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R5(() -> COMMAND_BUILD_CONTEXT); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml index d6457d79a..92c0d8805 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml @@ -60,12 +60,14 @@ dev.jorel commandapi-bukkit-1.21 ${project.version} + mojang-mapped provided dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java index 573d03ba5..ba0baccd6 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java @@ -66,7 +66,7 @@ public final List getProfile(CommandContext c } @Override - public NMS bukkitNMS() { + public NMS bukkitNMS() { if (bukkitNMS == null) { this.bukkitNMS = new NMS_1_21_R1(() -> COMMAND_BUILD_CONTEXT); } From 812fdcf72cc8cf342ba7c10145c8db01e27396a4 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Tue, 8 Jul 2025 19:40:20 +0200 Subject: [PATCH 12/63] Finish cleaning up paper-nms classes --- .../jorel/commandapi/nms/APITypeProvider.java | 247 +++++------------- 1 file changed, 62 insertions(+), 185 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index c5e1637a9..c0ff08475 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -176,104 +176,68 @@ public ArgumentType _ArgumentBlockPredicate() { @Override public ArgumentType _ArgumentBlockState() { - return getArgumentType( - () -> ArgumentTypes.blockState(), - () -> paperNMS.bukkitNMS()._ArgumentBlockState() - ); + return ArgumentTypes.blockState(); } @Override public ArgumentType _ArgumentChat() { - return getArgumentType( - () -> ArgumentTypes.signedMessage(), - () -> paperNMS.bukkitNMS()._ArgumentChat() - ); + return ArgumentTypes.signedMessage(); } @Override public ArgumentType _ArgumentChatComponent() { - return getArgumentType( - () -> ArgumentTypes.component(), - () -> paperNMS.bukkitNMS()._ArgumentChatComponent() - ); + return ArgumentTypes.component(); } @Override public ArgumentType _ArgumentChatFormat() { - return getArgumentType( - () -> ArgumentTypes.namedColor(), - () -> paperNMS.bukkitNMS()._ArgumentChatFormat() - ); + return ArgumentTypes.namedColor(); } @Override public ArgumentType _ArgumentDimension() { - return getArgumentType( - () -> ArgumentTypes.world(), - () -> paperNMS.bukkitNMS()._ArgumentDimension() - ); + return ArgumentTypes.world(); } @Override public ArgumentType _ArgumentEnchantment() { - return getArgumentType( - () -> ArgumentTypes.resource(RegistryKey.ENCHANTMENT), - () -> paperNMS.bukkitNMS()._ArgumentEnchantment() - ); + return ArgumentTypes.resource(RegistryKey.ENCHANTMENT); } @Override public ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return getArgumentType( - () -> switch (subType) { - case ENTITYSELECTOR_ONE_ENTITY -> ArgumentTypes.entity(); - case ENTITYSELECTOR_MANY_ENTITIES -> ArgumentTypes.entities(); - case ENTITYSELECTOR_ONE_PLAYER -> ArgumentTypes.player(); - case ENTITYSELECTOR_MANY_PLAYERS -> ArgumentTypes.players(); - default -> throw new Exception(); // Doesn't matter too much, it'll get to the right exception anyway - }, - () -> paperNMS.bukkitNMS()._ArgumentEntity(subType) - ); + return switch (subType) { + case ENTITYSELECTOR_ONE_ENTITY -> ArgumentTypes.entity(); + case ENTITYSELECTOR_MANY_ENTITIES -> ArgumentTypes.entities(); + case ENTITYSELECTOR_ONE_PLAYER -> ArgumentTypes.player(); + case ENTITYSELECTOR_MANY_PLAYERS -> ArgumentTypes.players(); + default -> throw new IllegalArgumentException("Unexpected value: " + subType); + }; } @Override public ArgumentType _ArgumentEntitySummon() { - return getArgumentType( - () -> ArgumentTypes.resource(RegistryKey.ENTITY_TYPE), - () -> paperNMS.bukkitNMS()._ArgumentEntitySummon() - ); + return ArgumentTypes.resource(RegistryKey.ENTITY_TYPE); } @Override public ArgumentType _ArgumentFloatRange() { - return getArgumentType( - () -> ArgumentTypes.doubleRange(), - () -> paperNMS.bukkitNMS()._ArgumentFloatRange() - ); + return ArgumentTypes.doubleRange(); } @Override public ArgumentType _ArgumentIntRange() { - return getArgumentType( - () -> ArgumentTypes.integerRange(), - () -> paperNMS.bukkitNMS()._ArgumentIntRange() - ); + return ArgumentTypes.integerRange(); } @Override public ArgumentType _ArgumentItemPredicate() { - return getArgumentType( - () -> ArgumentTypes.itemPredicate(), - () -> paperNMS.bukkitNMS()._ArgumentItemPredicate() - ); + return ArgumentTypes.itemPredicate(); } @Override public ArgumentType _ArgumentItemStack() { - return getArgumentType( - () -> ArgumentTypes.itemStack(), - () -> paperNMS.bukkitNMS()._ArgumentItemStack() - ); + return ArgumentTypes.itemStack(); } @Override @@ -285,18 +249,12 @@ public ArgumentType _ArgumentMathOperation() { @Override public ArgumentType _ArgumentMinecraftKeyRegistered() { - return getArgumentType( - () -> ArgumentTypes.namespacedKey(), - () -> paperNMS.bukkitNMS()._ArgumentMinecraftKeyRegistered() - ); + return ArgumentTypes.namespacedKey(); } @Override public ArgumentType _ArgumentMobEffect() { - return getArgumentType( - () -> ArgumentTypes.resource(RegistryKey.MOB_EFFECT), - () -> paperNMS.bukkitNMS()._ArgumentMobEffect() - ); + return ArgumentTypes.resource(RegistryKey.MOB_EFFECT); } @Override @@ -315,10 +273,7 @@ public ArgumentType _ArgumentParticle() { @Override public ArgumentType _ArgumentPosition() { - return getArgumentType( - () -> ArgumentTypes.blockPosition(), - () -> paperNMS.bukkitNMS()._ArgumentPosition() - ); + return ArgumentTypes.blockPosition(); } @Override @@ -330,10 +285,7 @@ public ArgumentType _ArgumentPosition2D() { @Override public ArgumentType _ArgumentProfile() { - return getArgumentType( - () -> ArgumentTypes.playerProfiles(), - () -> paperNMS.bukkitNMS()._ArgumentProfile() - ); + return ArgumentTypes.playerProfiles(); } @Override @@ -346,17 +298,14 @@ public ArgumentType _ArgumentRecipe() { @Override public ArgumentType _ArgumentRotation() { return getArgumentType( - () -> ArgumentTypes.rotation(), + () -> ArgumentTypes.rotation(), // Since 1.21.4 () -> paperNMS.bukkitNMS()._ArgumentRotation() ); } @Override public ArgumentType _ArgumentScoreboardCriteria() { - return getArgumentType( - () -> ArgumentTypes.objectiveCriteria(), - () -> paperNMS.bukkitNMS()._ArgumentScoreboardCriteria() - ); + return ArgumentTypes.objectiveCriteria(); } @Override @@ -368,10 +317,7 @@ public ArgumentType _ArgumentScoreboardObjective() { @Override public ArgumentType _ArgumentScoreboardSlot() { - return getArgumentType( - () -> ArgumentTypes.scoreboardDisplaySlot(), - () -> paperNMS.bukkitNMS()._ArgumentScoreboardSlot() - ); + return ArgumentTypes.scoreboardDisplaySlot(); } @Override @@ -397,18 +343,12 @@ public ArgumentType _ArgumentTag() { @Override public ArgumentType _ArgumentTime() { - return getArgumentType( - () -> ArgumentTypes.time(), - () -> paperNMS.bukkitNMS()._ArgumentTime() - ); + return ArgumentTypes.time(); } @Override public ArgumentType _ArgumentUUID() { - return getArgumentType( - () -> ArgumentTypes.uuid(), - () -> paperNMS.bukkitNMS()._ArgumentUUID() - ); + return ArgumentTypes.uuid(); } @Override @@ -421,17 +361,14 @@ public ArgumentType _ArgumentVec2(boolean centerPosition) { @Override public ArgumentType _ArgumentVec3(boolean centerPosition) { return getArgumentType( - () -> ArgumentTypes.finePosition(centerPosition), + () -> ArgumentTypes.finePosition(centerPosition), // Since 1.21 () -> paperNMS.bukkitNMS()._ArgumentVec3(centerPosition) ); } @Override public ArgumentType _ArgumentSyntheticBiome() { - return getArgumentType( - () -> ArgumentTypes.resource(RegistryKey.BIOME), - () -> paperNMS.bukkitNMS()._ArgumentSyntheticBiome() - ); + return ArgumentTypes.resource(RegistryKey.BIOME); } @Override @@ -482,13 +419,9 @@ public EnumSet getAxis(CommandContext cmdCtx, String k @Override public RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT( - cmdCtx, key, - (ctx, name) -> new RegistryParser<>( - () -> ctx.getArgument(name, Biome.class), - () -> ctx.getArgument(name, Biome.class).getKey() - ), - (ctx, name) -> paperNMS.bukkitNMS().getBiome(ctx, name) + return new RegistryParser<>( + () -> cmdCtx.getArgument(key, Biome.class), + () -> cmdCtx.getArgument(key, Biome.class).getKey() ); } @@ -501,60 +434,40 @@ public Predicate getBlockPredicate(CommandContext cmd @Override public BlockState getBlockState(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, BlockState.class), - (ctx, name) -> paperNMS.bukkitNMS().getBlockState(ctx, name) - ); + return cmdCtx.getArgument(key, BlockState.class); } @Override public World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, World.class), - (ctx, name) -> paperNMS.bukkitNMS().getDimension(ctx, name) - ); + return cmdCtx.getArgument(key, World.class); } @Override public Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, Enchantment.class), - (ctx, name) -> paperNMS.bukkitNMS().getEnchantment(ctx, name) - ); + return cmdCtx.getArgument(key, Enchantment.class); } @Override public EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> new EntitySelectorParser( - () -> ctx.getArgument(name, PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()).getFirst(), - () -> ctx.getArgument(name, EntitySelectorArgumentResolver.class).resolve(ctx.getSource()).getFirst(), - (allowEmpty) -> ctx.getArgument(name, PlayerSelectorArgumentResolver.class).resolve(ctx.getSource()), - (allowEmpty) -> ctx.getArgument(name, EntitySelectorArgumentResolver.class).resolve(ctx.getSource()) - ), - (ctx, name) -> paperNMS.bukkitNMS().getEntitySelector(ctx, name) + return new EntitySelectorParser( + () -> cmdCtx.getArgument(key, PlayerSelectorArgumentResolver.class).resolve(cmdCtx.getSource()).getFirst(), + () -> cmdCtx.getArgument(key, EntitySelectorArgumentResolver.class).resolve(cmdCtx.getSource()).getFirst(), + (allowEmpty) -> cmdCtx.getArgument(key, PlayerSelectorArgumentResolver.class).resolve(cmdCtx.getSource()), + (allowEmpty) -> cmdCtx.getArgument(key, EntitySelectorArgumentResolver.class).resolve(cmdCtx.getSource()) ); } @Override public EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, EntityType.class), - (ctx, name) -> paperNMS.bukkitNMS().getEntityType(ctx, name) - ); + return cmdCtx.getArgument(key, EntityType.class); } @Override public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> { - DoubleRangeProvider rangeProvider = ctx.getArgument(name, DoubleRangeProvider.class); - final double low = rangeProvider.range().hasLowerBound() ? rangeProvider.range().lowerEndpoint() : -Double.MAX_VALUE; - final double high = rangeProvider.range().hasUpperBound() ? rangeProvider.range().upperEndpoint() : Double.MAX_VALUE; - return new DoubleRange(low, high); - }, - (ctx, name) -> paperNMS.bukkitNMS().getDoubleRange(ctx, name) - ); + DoubleRangeProvider rangeProvider = cmdCtx.getArgument(key, DoubleRangeProvider.class); + final double low = rangeProvider.range().hasLowerBound() ? rangeProvider.range().lowerEndpoint() : -Double.MAX_VALUE; + final double high = rangeProvider.range().hasUpperBound() ? rangeProvider.range().upperEndpoint() : Double.MAX_VALUE; + return new DoubleRange(low, high); } @Override @@ -576,31 +489,20 @@ public Set getFunctions() { @Override public IntegerRange getIntRange(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> { - IntegerRangeProvider rangeProvider = ctx.getArgument(name, IntegerRangeProvider.class); - final int low = rangeProvider.range().hasLowerBound() ? rangeProvider.range().lowerEndpoint() : Integer.MIN_VALUE; - final int high = rangeProvider.range().hasUpperBound() ? rangeProvider.range().upperEndpoint() : Integer.MAX_VALUE; - return new IntegerRange(low, high); - }, - (ctx, name) -> paperNMS.bukkitNMS().getIntRange(ctx, name) - ); + IntegerRangeProvider rangeProvider = cmdCtx.getArgument(key, IntegerRangeProvider.class); + final int low = rangeProvider.range().hasLowerBound() ? rangeProvider.range().lowerEndpoint() : Integer.MIN_VALUE; + final int high = rangeProvider.range().hasUpperBound() ? rangeProvider.range().upperEndpoint() : Integer.MAX_VALUE; + return new IntegerRange(low, high); } @Override public ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, ItemStack.class), - (ctx, name) -> paperNMS.bukkitNMS().getItemStack(ctx, name) - ); + return cmdCtx.getArgument(key, ItemStack.class); } @Override public Predicate getItemStackPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, ItemStackPredicate.class), - (ctx, name) -> paperNMS.bukkitNMS().getItemStackPredicate(ctx, name) - ); + return cmdCtx.getArgument(key, ItemStackPredicate.class); } @Override @@ -619,13 +521,8 @@ public Location2D getLocation2DPrecise(CommandContext cmdCtx @Override public Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException { - return parseT(cmdCtx, str, - (ctx, name) -> { - BlockPosition blockPosition = ctx.getArgument(name, BlockPositionResolver.class).resolve(ctx.getSource()); - return new Location(getWorldForCSS(ctx.getSource()), blockPosition.blockX(), blockPosition.blockY(), blockPosition.blockZ()); - }, - (ctx, name) -> paperNMS.bukkitNMS().getLocationBlock(ctx, name) - ); + BlockPosition blockPosition = cmdCtx.getArgument(str, BlockPositionResolver.class).resolve(cmdCtx.getSource()); + return new Location(getWorldForCSS(cmdCtx.getSource()), blockPosition.blockX(), blockPosition.blockY(), blockPosition.blockZ()); } @Override @@ -656,10 +553,7 @@ public MathOperation getMathOperation(CommandContext cmdCtx, @Override public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, NamespacedKey.class), - (ctx, name) -> paperNMS.bukkitNMS().getMinecraftKey(ctx, name) - ); + return cmdCtx.getArgument(key, NamespacedKey.class); } @Override @@ -678,10 +572,7 @@ public Objective getObjective(CommandContext cmdCtx, String @Override public String getObjectiveCriteria(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, Criteria.class).getName(), - (ctx, name) -> paperNMS.bukkitNMS().getObjectiveCriteria(ctx, name) - ); + return cmdCtx.getArgument(key, Criteria.class).getName(); } @Override @@ -710,12 +601,9 @@ private UUID getIdFromProfile(CommandContext ctx, String nam @Override public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> new RegistryParser<>( - () -> ctx.getArgument(name, PotionEffectType.class), - () -> ctx.getArgument(name, PotionEffectType.class).getKey() - ), - (ctx, name) -> paperNMS.bukkitNMS().getPotionEffect(ctx, name) + return new RegistryParser<>( + () -> cmdCtx.getArgument(key, PotionEffectType.class), + () -> cmdCtx.getArgument(key, PotionEffectType.class).getKey() ); } @@ -739,13 +627,8 @@ public Rotation getRotation(CommandContext cmdCtx, String ke @Override public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> { - DisplaySlot displaySlot = ctx.getArgument(name, DisplaySlot.class); - return ScoreboardSlot.of(displaySlot); - }, - (ctx, name) -> paperNMS.bukkitNMS().getScoreboardSlot(ctx, name) - ); + DisplaySlot displaySlot = cmdCtx.getArgument(key, DisplaySlot.class); + return ScoreboardSlot.of(displaySlot); } @Override @@ -771,18 +654,12 @@ public Team getTeam(CommandContext cmdCtx, String key) throw @Override public int getTime(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, Integer.class), - (ctx, name) -> paperNMS.bukkitNMS().getTime(ctx, name) - ); + return cmdCtx.getArgument(key, Integer.class); } @Override public UUID getUUID(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, - (ctx, name) -> ctx.getArgument(name, UUID.class), - (ctx, name) -> paperNMS.bukkitNMS().getUUID(ctx, name) - ); + return cmdCtx.getArgument(key, UUID.class); } @Override From a1c1c8c09aae491ccaaa050932a7fdb17e98c54a Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Wed, 23 Jul 2025 14:19:13 +0200 Subject: [PATCH 13/63] Fixes --- .../commandapi-paper-1.20.5/pom.xml | 26 ------------------ .../commandapi-paper-1.21.2/pom.xml | 26 ------------------ .../commandapi-paper-1.21.4/pom.xml | 26 ------------------ .../commandapi-paper-1.21.5/pom.xml | 26 ------------------ .../commandapi-paper-1.21.6/pom.xml | 1 + .../commandapi-paper-1.21/pom.xml | 26 ------------------ .../jorel/commandapi/nms/APITypeProvider.java | 22 +++++++++++++-- .../commandapi-paper-nms-dependency/pom.xml | 27 +++++++++---------- .../commandapi-paper-shade/pom.xml | 26 ++++++++++++++++++ 9 files changed, 59 insertions(+), 147 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml index 45b3c4d70..75b948594 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml @@ -78,36 +78,10 @@ - - - org.apache.maven.plugins - maven-jar-plugin - - - Mojang-Mapped - compile - - jar - - - mojang-mapped - - - - - ca.bkaw paper-nms-maven-plugin 1.4.7 - - - process-classes - - remap - - - diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml index 582a4f97d..f053a81ef 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml @@ -73,36 +73,10 @@ - - - org.apache.maven.plugins - maven-jar-plugin - - - Mojang-Mapped - compile - - jar - - - mojang-mapped - - - - - ca.bkaw paper-nms-maven-plugin 1.4.7 - - - process-classes - - remap - - - diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml index dbc846eb2..136ef0db7 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml @@ -73,36 +73,10 @@ - - - org.apache.maven.plugins - maven-jar-plugin - - - Mojang-Mapped - compile - - jar - - - mojang-mapped - - - - - ca.bkaw paper-nms-maven-plugin 1.4.7 - - - process-classes - - remap - - - diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml index 7580e0a52..d70fb1464 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml @@ -73,36 +73,10 @@ - - - org.apache.maven.plugins - maven-jar-plugin - - - Mojang-Mapped - compile - - jar - - - mojang-mapped - - - - - ca.bkaw paper-nms-maven-plugin 1.4.7 - - - process-classes - - remap - - - diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml index 86ccec63f..beb37b1e1 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml @@ -60,6 +60,7 @@ commandapi-bukkit-1.21.6 ${project.version} mojang-mapped + provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml index 2e343f006..0fca60096 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml @@ -80,36 +80,10 @@ - - - org.apache.maven.plugins - maven-jar-plugin - - - Mojang-Mapped - compile - - jar - - - mojang-mapped - - - - - ca.bkaw paper-nms-maven-plugin 1.4.7 - - - process-classes - - remap - - - diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index c0ff08475..56a7f2e38 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -46,6 +46,7 @@ import net.kyori.adventure.chat.SignedMessage; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import org.bukkit.Axis; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -61,7 +62,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.help.HelpTopic; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; @@ -449,11 +452,26 @@ public Enchantment getEnchantment(CommandContext cmdCtx, Str @Override public EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String key) { + GsonComponentSerializer gson = GsonComponentSerializer.gson(); + SimpleCommandExceptionType NO_ENTITIES_FOUND = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.entity")))); + SimpleCommandExceptionType NO_PLAYERS_FOUND = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.player")))); return new EntitySelectorParser( () -> cmdCtx.getArgument(key, PlayerSelectorArgumentResolver.class).resolve(cmdCtx.getSource()).getFirst(), () -> cmdCtx.getArgument(key, EntitySelectorArgumentResolver.class).resolve(cmdCtx.getSource()).getFirst(), - (allowEmpty) -> cmdCtx.getArgument(key, PlayerSelectorArgumentResolver.class).resolve(cmdCtx.getSource()), - (allowEmpty) -> cmdCtx.getArgument(key, EntitySelectorArgumentResolver.class).resolve(cmdCtx.getSource()) + (allowEmpty) -> { + List players = cmdCtx.getArgument(key, PlayerSelectorArgumentResolver.class).resolve(cmdCtx.getSource()); + if (players.isEmpty() && !allowEmpty) { + throw NO_PLAYERS_FOUND.create(); + } + return players; + }, + (allowEmpty) -> { + List entities = cmdCtx.getArgument(key, EntitySelectorArgumentResolver.class).resolve(cmdCtx.getSource()); + if (entities.isEmpty() && !allowEmpty) { + throw NO_ENTITIES_FOUND.create(); + } + return entities; + } ); } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml index 3629b6efc..31467b79c 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml @@ -19,6 +19,7 @@ dev.jorel commandapi-bukkit-nms-common ${project.version} + mojang-mapped @@ -61,45 +62,41 @@ + + dev.jorel + commandapi-bukkit-1.21.6 + ${project.version} + mojang-mapped + dev.jorel commandapi-bukkit-1.21.5 ${project.version} + mojang-mapped dev.jorel commandapi-bukkit-1.21.4 ${project.version} + mojang-mapped dev.jorel commandapi-bukkit-1.21.2 ${project.version} + mojang-mapped dev.jorel commandapi-bukkit-1.21 ${project.version} + mojang-mapped dev.jorel commandapi-bukkit-1.20.5 ${project.version} - - - dev.jorel - commandapi-bukkit-1.20.3 - ${project.version} - - - dev.jorel - commandapi-bukkit-1.20.2 - ${project.version} - - - dev.jorel - commandapi-bukkit-1.20 - ${project.version} + mojang-mapped diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml index a5d7c1176..504f60fd4 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml @@ -57,6 +57,32 @@ + + + org.bukkit.craftbukkit.v1_20_R4 + org.bukkit.craftbukkit + + + org.bukkit.craftbukkit.v1_21_R1 + org.bukkit.craftbukkit + + + org.bukkit.craftbukkit.v1_21_R2 + org.bukkit.craftbukkit + + + org.bukkit.craftbukkit.v1_21_R3 + org.bukkit.craftbukkit + + + org.bukkit.craftbukkit.v1_21_R4 + org.bukkit.craftbukkit + + + org.bukkit.craftbukkit.v1_21_R5 + org.bukkit.craftbukkit + + From d80a672f24d3e41f156e50aeecfb1a107f99510f Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Wed, 23 Jul 2025 14:31:48 +0200 Subject: [PATCH 14/63] More fixes --- .../java/dev/jorel/commandapi/nms/NMS_1_21_R5.java | 2 +- .../commandapi-paper/commandapi-paper-shade/pom.xml | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java index 1d194ff08..151a8e30a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java @@ -241,7 +241,7 @@ public NMS_1_21_R5(Supplier commandBuildContext) { // itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); // For some reason, MethodHandles fails for this field, but Field works okay serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "h", "dispatcher"); - blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "c", "tag", CompoundTag.class); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "d", "tag", CompoundTag.class); MethodHandles.Lookup lookup = MethodHandles.lookup(); MethodHandle setSelected; diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml index 504f60fd4..94163f142 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml @@ -30,6 +30,11 @@ ${project.version} pom + + dev.jorel + commandapi-paper-mojang-mapped + ${project.version} + @@ -56,6 +61,12 @@ dev/jorel/commandapi/CommandAPIVersionHandler** + + dev.jorel:commandapi-core + + dev/jorel/commandapi/MojangMappedVersionHandler** + + From 6881cdc61acbc2e345370930c6dd50791c9e05a3 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Wed, 6 Aug 2025 00:24:21 +0200 Subject: [PATCH 15/63] Remove Mojang-mapped modules for Spigot --- .../commandapi-spigot-mojang-mapped/pom.xml | 15 - .../MojangMappedVersionHandler.java | 12 - .../pom.xml | 132 -------- .../commandapi-spigot-nms/pom.xml | 1 - .../pom.xml | 159 --------- .../jorel/commandapi/AdvancedConverter.java | 314 ------------------ .../dev/jorel/commandapi/CommandAPIMain.java | 155 --------- .../src/main/resources/config.yml | 74 ----- .../src/main/resources/plugin.yml | 13 - .../pom.xml | 116 ------- .../commandapi-spigot/pom.xml | 3 - 11 files changed, 994 deletions(-) delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/plugin.yml delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml deleted file mode 100644 index f8d2896ef..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/pom.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - 4.0.0 - - dev.jorel - commandapi-spigot - 11.0.0-SNAPSHOT - - - commandapi-spigot-mojang-mapped - Spigot mojang mapped dependency - - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java deleted file mode 100644 index 80db4c1b7..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-mojang-mapped/src/main/java/dev/jorel/commandapi/MojangMappedVersionHandler.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.jorel.commandapi; - -/** - * This file handles loading the correct mappings information. The MojangMappedVersionHandler - * file within the commandapi-core module may not be used at run time. Instead, if a platform module - * wants to be mojang-mapped, they can replace it with this class where {@link #isMojangMapped()} returns {@code true}. - */ -public interface MojangMappedVersionHandler { - static boolean isMojangMapped() { - return true; - } -} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml deleted file mode 100644 index 6c2052bbd..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency-mojang-mapped/pom.xml +++ /dev/null @@ -1,132 +0,0 @@ - - - 4.0.0 - - dev.jorel - commandapi-spigot-nms - 11.0.0-SNAPSHOT - - - commandapi-spigot-nms-dependency-mojang-mapped - Spigot support Mojang-mapped NMS dependency - pom - - - - - dev.jorel - commandapi-bukkit-nms-common - ${project.version} - mojang-mapped - - - - - dev.jorel - commandapi-spigot-1.21.6 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-spigot-1.21.5 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-spigot-1.21.4 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-spigot-1.21.2 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-spigot-1.21 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-spigot-1.20.5 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-spigot-1.20.3 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-spigot-1.20.2 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-spigot-1.20 - ${project.version} - mojang-mapped - - - - - dev.jorel - commandapi-bukkit-1.21.5 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-bukkit-1.21.4 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-bukkit-1.21.2 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-bukkit-1.21 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-bukkit-1.20.5 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-bukkit-1.20.3 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-bukkit-1.20.2 - ${project.version} - mojang-mapped - - - dev.jorel - commandapi-bukkit-1.20 - ${project.version} - mojang-mapped - - - - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml index b03ab718a..17c22b641 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml @@ -25,7 +25,6 @@ commandapi-spigot-1.20 commandapi-spigot-nms-dependency - commandapi-spigot-nms-dependency-mojang-mapped \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml deleted file mode 100644 index 6308ba5df..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/pom.xml +++ /dev/null @@ -1,159 +0,0 @@ - - - 4.0.0 - - dev.jorel - commandapi-spigot - 11.0.0-SNAPSHOT - - - commandapi-spigot-plugin-mojang-mapped - Spigot support Mojang-mapped plugin - - - - codemc-repo - https://repo.codemc.org/repository/maven-public/ - default - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - - - - dev.jorel - commandapi-spigot-core - ${project.version} - compile - - - - dev.jorel - commandapi-spigot-nms-dependency-mojang-mapped - ${project.version} - pom - - - dev.jorel - commandapi-spigot-vh - ${project.version} - - - dev.jorel - commandapi-spigot-mojang-mapped - ${project.version} - - - org.spigotmc - spigot-api - ${paper.version} - provided - - - dev.jorel - commandapi-bukkit-plugin-common - ${project.version} - - - - - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - - - - dev.jorel:commandapi-core - - dev/jorel/commandapi/CommandAPIVersionHandler** - dev/jorel/commandapi/MojangMappedVersionHandler** - - - - - - org.bukkit.craftbukkit.v1_20_R4 - org.bukkit.craftbukkit - - - org.bukkit.craftbukkit.v1_21_R1 - org.bukkit.craftbukkit - - - org.bukkit.craftbukkit.v1_21_R2 - org.bukkit.craftbukkit - - - org.bukkit.craftbukkit.v1_21_R3 - org.bukkit.craftbukkit - - - org.bukkit.craftbukkit.v1_21_R4 - org.bukkit.craftbukkit - - - - - LICENSE - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - empty-javadoc-jar - package - - jar - - - javadoc - ${basedir}/javadoc - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.4.1 - - - - mojang - - - - - - - - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java deleted file mode 100644 index 0d22eacca..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/AdvancedConverter.java +++ /dev/null @@ -1,314 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi; - -import dev.jorel.commandapi.arguments.AdvancementArgument; -import dev.jorel.commandapi.arguments.AngleArgument; -import dev.jorel.commandapi.arguments.Argument; -import dev.jorel.commandapi.arguments.AsyncPlayerProfileArgument; -import dev.jorel.commandapi.arguments.AxisArgument; -import dev.jorel.commandapi.arguments.BiomeArgument; -import dev.jorel.commandapi.arguments.BlockPredicateArgument; -import dev.jorel.commandapi.arguments.BlockStateArgument; -import dev.jorel.commandapi.arguments.BooleanArgument; -import dev.jorel.commandapi.arguments.ChatArgument; -import dev.jorel.commandapi.arguments.ChatColorArgument; -import dev.jorel.commandapi.arguments.ChatComponentArgument; -import dev.jorel.commandapi.arguments.CommandAPIArgumentType; -import dev.jorel.commandapi.arguments.CommandArgument; -import dev.jorel.commandapi.arguments.DoubleArgument; -import dev.jorel.commandapi.arguments.DoubleRangeArgument; -import dev.jorel.commandapi.arguments.EnchantmentArgument; -import dev.jorel.commandapi.arguments.EntitySelectorArgument; -import dev.jorel.commandapi.arguments.EntityTypeArgument; -import dev.jorel.commandapi.arguments.FloatArgument; -import dev.jorel.commandapi.arguments.FunctionArgument; -import dev.jorel.commandapi.arguments.GreedyStringArgument; -import dev.jorel.commandapi.arguments.IntegerArgument; -import dev.jorel.commandapi.arguments.IntegerRangeArgument; -import dev.jorel.commandapi.arguments.ItemStackArgument; -import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; -import dev.jorel.commandapi.arguments.Location2DArgument; -import dev.jorel.commandapi.arguments.LocationArgument; -import dev.jorel.commandapi.arguments.LocationType; -import dev.jorel.commandapi.arguments.LongArgument; -import dev.jorel.commandapi.arguments.LootTableArgument; -import dev.jorel.commandapi.arguments.MathOperationArgument; -import dev.jorel.commandapi.arguments.MultiLiteralArgument; -import dev.jorel.commandapi.arguments.NBTCompoundArgument; -import dev.jorel.commandapi.arguments.NamespacedKeyArgument; -import dev.jorel.commandapi.arguments.ObjectiveArgument; -import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; -import dev.jorel.commandapi.arguments.ParticleArgument; -import dev.jorel.commandapi.arguments.PlayerProfileArgument; -import dev.jorel.commandapi.arguments.PotionEffectArgument; -import dev.jorel.commandapi.arguments.RecipeArgument; -import dev.jorel.commandapi.arguments.RotationArgument; -import dev.jorel.commandapi.arguments.ScoreHolderArgument; -import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; -import dev.jorel.commandapi.arguments.SoundArgument; -import dev.jorel.commandapi.arguments.StringArgument; -import dev.jorel.commandapi.arguments.TeamArgument; -import dev.jorel.commandapi.arguments.TextArgument; -import dev.jorel.commandapi.arguments.TimeArgument; -import dev.jorel.commandapi.arguments.UUIDArgument; -import dev.jorel.commandapi.exceptions.InvalidNumberException; -import dev.jorel.commandapi.exceptions.UnknownArgumentException; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * A command parsing system that converts string arguments into something way - * more useful - */ -class AdvancedConverter { - - /** - * Pattern for arguments, which are of the form {@code [type]} - *
    - *
  • {@code node_name} is a standard node name.
  • - *
  • {@code type} is either a namespaced key representing the argument - * (described in {@code conversionforownerssingleargs.md} in the main - * documentation), or a numerical range of the form {@code n..n}, {@code ..n} or - * {@code n..} where {@code n} is a constant integer or floating point - * number
  • - *
- */ - private static final Pattern ARGUMENT_PATTERN = Pattern.compile("<(\\w+)>\\[([a-z:_]+|(?:[0-9\\.]+)?\\.\\.(?:[0-9\\.]+)?)\\]"); - - /** - * Pattern for literal, of the form {@code (node_name)}. It also supports - * multiple node names of the form - * {@code (node_name_1|node_name_2|...|node_name_n)} - */ - private static final Pattern LITERAL_PATTERN = Pattern.compile("\\(\\w+(\\|\\w+)*+\\)"); - - private final JavaPlugin plugin; - private final String command; - private int argumentIndex = 1; - - public AdvancedConverter(JavaPlugin plugin, String command) { - this.plugin = plugin; - this.command = command; - } - - public AdvancedConverter(String command) { - this.plugin = null; - this.command = command; - } - - public void convert() { - String commandName = command.split(" ")[0]; - List> arguments; - try { - arguments = parseArguments(command); - } catch (UnknownArgumentException | InvalidNumberException e) { - CommandAPI.logError(e.getMessage()); - return; - } - if (arguments.isEmpty()) { - Converter.convert(plugin, commandName); - } else { - Converter.convert(plugin, commandName, arguments); - } - - } - - public void convertCommand() { - String commandName = command.split(" ")[0]; - List> arguments; - try { - arguments = parseArguments(command); - } catch (UnknownArgumentException | InvalidNumberException e) { - CommandAPI.logError(e.getMessage()); - return; - } - if (arguments.isEmpty()) { - Converter.convert(commandName); - } else { - Converter.convert(commandName, arguments); - } - } - - /** - *
-	 * plugins-to-convert: 
-	 *   - Essentials: 
-	 *     - speed [0..10]
-	 *     - speed [minecraft:game_profile]
-	 *     - speed (walk|fly) [0..10]
-	 *     - speed (walk|fly) [0..10] [minecraft:game_profile]
-	 * 
- */ - private List> parseArguments(String command) throws UnknownArgumentException, InvalidNumberException { - List> arguments = new ArrayList<>(); - String[] parts = command.split(" "); - for (argumentIndex = 1; argumentIndex < parts.length; argumentIndex++) { - arguments.add(parseArgument(parts[argumentIndex])); - } - return arguments; - } - - private boolean isRangeAnInteger(double value) { - return value == (long) value; - } - - private double parseValue(String bound) throws InvalidNumberException { - try { - return Double.parseDouble(bound); - } catch (NumberFormatException e) { - throw new InvalidNumberException(bound, command, argumentIndex); - } - } - - private Argument parseRange(String nodeName, String[] bounds) throws InvalidNumberException { - if (bounds.length == 1) { - // x.. - double value = parseValue(bounds[0]); - if (isRangeAnInteger(value)) { - return new LongArgument(nodeName, (long) value); - } else { - return new DoubleArgument(nodeName, value); - } - } else if (bounds[0].length() == 0) { - // ..x - double value = parseValue(bounds[1]); - if (isRangeAnInteger(value)) { - return new LongArgument(nodeName, Long.MIN_VALUE, (long) value); - } else { - return new DoubleArgument(nodeName, -Double.MAX_VALUE, value); - } - } else { - // x..x - double value0 = parseValue(bounds[0]); - double value1 = parseValue(bounds[1]); - if (!isRangeAnInteger(value0) || !isRangeAnInteger(value1)) { - return new DoubleArgument(nodeName, value0, value1); - } else { - return new LongArgument(nodeName, (long) value0, (long) value1); - } - } - } - - /* - * CodeFactor will always complain about this method because it's really bulky - * and adding a generator (i.e. Function>) inside the - * CommandAPIArgumentType class would be better, EXCEPT in practice, this is - * worse because then CommandAPIArgumentType would have to depend on every - * argument and every argument depends on CommandAPIArgumentType, so that would - * mean every argument would always have to be packaged in the CommandAPI - jar - * minimisation wouldn't be able to minimise this as best as it could. - * - * Additionally, we only need this for the plugin version of the CommandAPI, not - * the main API. - */ - @SuppressWarnings("rawtypes") - private Argument parseDefinedArgumentType(String argumentType, String nodeName) throws UnknownArgumentException { - return switch (CommandAPIArgumentType.fromInternal(argumentType)) { - case ADVANCEMENT -> new AdvancementArgument(nodeName); - case ADVENTURE_CHAT -> new ChatArgument(nodeName); - case ADVENTURE_CHAT_COMPONENT -> new ChatComponentArgument(nodeName); - case ANGLE -> new AngleArgument(nodeName); - case ASYNC_OFFLINE_PLAYER -> new AsyncPlayerProfileArgument(nodeName); - case AXIS -> new AxisArgument(nodeName); - case BIOME -> new BiomeArgument(nodeName); - case BLOCKSTATE -> new BlockStateArgument(nodeName); - case BLOCK_PREDICATE -> new BlockPredicateArgument(nodeName); - case CHAT -> new ChatArgument(nodeName); - case CHATCOLOR -> new ChatColorArgument(nodeName); - case CHAT_COMPONENT -> new ChatComponentArgument(nodeName); - case COMMAND -> new CommandArgument(nodeName); - case ENCHANTMENT -> new EnchantmentArgument(nodeName); - case ENTITY_SELECTOR -> new EntitySelectorArgument.OneEntity(nodeName); - case ENTITY_TYPE -> new EntityTypeArgument(nodeName); - case FLOAT_RANGE -> new DoubleRangeArgument(nodeName); - case FUNCTION -> new FunctionArgument(nodeName); - case INT_RANGE -> new IntegerRangeArgument(nodeName); - case ITEMSTACK -> new ItemStackArgument(nodeName); - case ITEMSTACK_PREDICATE -> new ItemStackPredicateArgument(nodeName); - case LOCATION -> new LocationArgument(nodeName, LocationType.BLOCK_POSITION); - case LOCATION_2D -> new Location2DArgument(nodeName, LocationType.BLOCK_POSITION); - case LOOT_TABLE -> new LootTableArgument(nodeName); - case MATH_OPERATION -> new MathOperationArgument(nodeName); - case NAMESPACED_KEY -> new NamespacedKeyArgument(nodeName); - case NBT_COMPOUND -> new NBTCompoundArgument(nodeName); - case OBJECTIVE -> new ObjectiveArgument(nodeName); - case OBJECTIVE_CRITERIA -> new ObjectiveCriteriaArgument(nodeName); - case PARTICLE -> new ParticleArgument(nodeName); - case PLAYER -> new PlayerProfileArgument(nodeName); - case POTION_EFFECT -> new PotionEffectArgument(nodeName); - case RECIPE -> new RecipeArgument(nodeName); - case ROTATION -> new RotationArgument(nodeName); - case SCOREBOARD_SLOT -> new ScoreboardSlotArgument(nodeName); - case SCORE_HOLDER -> new ScoreHolderArgument.Single(nodeName); - case SOUND -> new SoundArgument(nodeName); - case TEAM -> new TeamArgument(nodeName); - case TIME -> new TimeArgument(nodeName); - case UUID -> new UUIDArgument(nodeName); - case PRIMITIVE_BOOLEAN -> new BooleanArgument(nodeName); - case PRIMITIVE_DOUBLE -> new DoubleArgument(nodeName); - case PRIMITIVE_FLOAT -> new FloatArgument(nodeName); - case PRIMITIVE_GREEDY_STRING -> new GreedyStringArgument(nodeName); - case PRIMITIVE_INTEGER -> new IntegerArgument(nodeName); - case PRIMITIVE_LONG -> new LongArgument(nodeName); - case PRIMITIVE_STRING -> new StringArgument(nodeName); - case PRIMITIVE_TEXT -> new TextArgument(nodeName); - case LITERAL, MULTI_LITERAL, CUSTOM -> throw new UnknownArgumentException(argumentType); - default -> throw new UnknownArgumentException(argumentType); - }; - } - - private Argument parseArgument(String argument) throws UnknownArgumentException, InvalidNumberException { - Matcher literalMatcher = LITERAL_PATTERN.matcher(argument); - Matcher argumentMatcher = ARGUMENT_PATTERN.matcher(argument); - if (literalMatcher.matches()) { - // Parse literals - return new MultiLiteralArgument("literals", literalMatcher.group().substring(1, literalMatcher.group().length() - 1).split("\\|")); - } else if (argumentMatcher.matches()) { - // Parse arguments - String nodeName = argumentMatcher.group(1); - String argumentType = argumentMatcher.group(2); - - if (argumentType.contains("..")) { - // Parse ranges - return parseRange(nodeName, argumentType.split("\\.\\.")); - } else { - // We have a few edge cases to handle - return switch (argumentType) { - case "api:entity" -> new EntitySelectorArgument.OneEntity(nodeName); - case "api:entities" -> new EntitySelectorArgument.ManyEntities(nodeName); - case "api:player" -> new EntitySelectorArgument.OnePlayer(nodeName); - case "api:players" -> new EntitySelectorArgument.ManyPlayers(nodeName); - case "minecraft:vec3" -> new LocationArgument(nodeName, LocationType.PRECISE_POSITION); - case "minecraft:vec2" -> new Location2DArgument(nodeName, LocationType.PRECISE_POSITION); - default -> parseDefinedArgumentType(argumentType, nodeName); - }; - } - } else { - throw new UnknownArgumentException(argument); - } - } - -} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java deleted file mode 100644 index 2d6c4639a..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - *******************************************************************************/ -package dev.jorel.commandapi; - -import dev.jorel.commandapi.config.BukkitConfigurationAdapter; -import dev.jorel.commandapi.config.DefaultBukkitConfig; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.InvalidPluginException; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -/** - * Main CommandAPI plugin entrypoint - */ -public class CommandAPIMain extends JavaPlugin { - - private static final String PLUGINS_TO_CONVERT = "plugins-to-convert"; - - @Override - public void onLoad() { - // Read config file - saveDefaultConfig(); - FileConfiguration fileConfig = getConfig(); - CommandAPISpigotConfig config = new CommandAPISpigotConfig(this) - .verboseOutput(fileConfig.getBoolean("verbose-outputs")) - .silentLogs(fileConfig.getBoolean("silent-logs")) - .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) - .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) - .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) - .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")) - .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")); - - for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { - if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { - config.addSkipSenderProxy(pluginName); - } else { - new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") - .printStackTrace(); - } - } - - // Main CommandAPI loading - CommandAPI.setLogger(CommandAPILogger.fromJavaLogger(getLogger())); - CommandAPI.onLoad(config); - - // Convert all plugins to be converted - if (!fileConfig.getList(PLUGINS_TO_CONVERT).isEmpty() - && fileConfig.getMapList(PLUGINS_TO_CONVERT).isEmpty()) { - CommandAPI.logError("plugins-to-convert has an invalid type. Did you miss a colon (:) after a plugin name?"); - } - - convertCommands(fileConfig); - } - - private void convertCommands(FileConfiguration fileConfig) { - // Load all plugins at the same time - Map pluginsToConvert = new HashMap<>(); - for (Map map : fileConfig.getMapList(PLUGINS_TO_CONVERT)) { - String[] pluginCommands; - if (map.values().size() == 1 && map.values().iterator().next() == null) { - pluginCommands = new String[0]; - } else { - @SuppressWarnings("unchecked") - List commands = (List) map.values().iterator().next(); - pluginCommands = commands.toArray(new String[0]); - } - - // Get the plugin, if it doesn't exist, scream in the console (but - // don't crash, we want to continue!) - final JavaPlugin plugin = getAndValidatePlugin((String) map.keySet().iterator().next()); - if (plugin != null) { - pluginsToConvert.put(plugin, pluginCommands); - } - } - - // Convert plugin commands - for (Entry pluginToConvert : pluginsToConvert.entrySet()) { - if (pluginToConvert.getValue().length == 0) { - Converter.convert(pluginToConvert.getKey()); - } else { - for (String command : pluginToConvert.getValue()) { - new AdvancedConverter(pluginToConvert.getKey(), command).convert(); - } - } - } - - // Convert all arbitrary commands - for (String commandName : fileConfig.getStringList("other-commands-to-convert")) { - new AdvancedConverter(commandName).convertCommand(); - } - } - - private JavaPlugin getAndValidatePlugin(String pluginName) { - Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName); - if (plugin != null) { - if (plugin instanceof JavaPlugin javaPlugin) { - return javaPlugin; - } else { - new InvalidPluginException("Plugin " + pluginName + " is not a JavaPlugin!").printStackTrace(); - } - } else { - new InvalidPluginException("Could not find a plugin " + pluginName + "! Has it been loaded properly?") - .printStackTrace(); - } - return null; - } - - @Override - public void onEnable() { - CommandAPI.onEnable(); - } - - /** - * In contrast to the superclass' method {@link org.bukkit.plugin.java.JavaPlugin#saveDefaultConfig()}, - * this doesn't fail silently if the config.yml already exists but instead will update the config with - * new values if available. - *

- * This should fail silently if all values are set already. - */ - @Override - public void saveDefaultConfig() { - File configFile = new File(getDataFolder(), "config.yml"); - BukkitConfigurationAdapter.createMinimalInstance(configFile).saveDefaultConfig( - DefaultBukkitConfig.createDefaultSpigotConfig(), - getDataFolder(), - getLogger() - ); - } - -} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml deleted file mode 100644 index 9714bb0dc..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/config.yml +++ /dev/null @@ -1,74 +0,0 @@ -################################################################################ -# Logging # -################################################################################ - -# Verbose outputs (default: false) -# If "true", outputs command registration and unregistration logs in the console -verbose-outputs: false - -# Silent logs (default: false) -# If "true", turns off all logging from the CommandAPI, except for errors. -silent-logs: false - -################################################################################ -# Messages # -################################################################################ - -# Messages -# Controls messages that the CommandAPI displays to players -messages: - - # Missing executor implementation (default: "This command has no implementations for %s") - # The message to display to senders when a command has no executor. Available - # parameters are: - # %s - the executor class (lowercase) - # %S - the executor class (normal case) - missing-executor-implementation: "This command has no implementations for %s" - -################################################################################ -# Debugging # -################################################################################ - -# Create dispatcher JSON (default: false) -# If "true", the CommandAPI creates a command_registration.json file showing the -# mapping of registered commands. This is designed to be used by developers - -# setting this to "false" will improve command registration performance. -create-dispatcher-json: false - -# Use latest version (default: false) -# If "true", the CommandAPI will use the latest available NMS implementation -# when the CommandAPI is used. This avoids all checks to see if the latest NMS -# implementation is actually compatible with the current Minecraft version. -use-latest-nms-version: false - -# Be lenient with version checks when loading for new minor Minecraft versions (default: false) -# If "true", the CommandAPI loads NMS implementations for (potentially unsupported) Minecraft versions. -# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing -# but will not allow an update from 1.21.2 to 1.22. -# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary. -be-lenient-for-minor-versions: false - -# Skips the initial datapack reload when the server loads (default: false) -# If "true", the CommandAPI will not reload datapacks when the server has finished -# loading. Datapacks will still be reloaded if performed manually when "hook-paper-reload" -# is set to "true" and /minecraft:reload is run. -skip-initial-datapack-reload: false - -################################################################################ -# Command conversion # -################################################################################ - -# Plugins to convert (default: []) -# Controls the list of plugins to process for command conversion. -plugins-to-convert: [] - -# Other commands to convert (default: []) -# A list of other commands to convert. This should be used for commands which -# are not declared in a plugin.yml file. -other-commands-to-convert: [] - -# Skip sender proxy (default: []) -# Determines whether the proxy sender should be skipped when converting a -# command. If you are having issues with plugin command conversion, add the -# plugin to this list. -skip-sender-proxy: [] \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/plugin.yml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/plugin.yml deleted file mode 100644 index c31f8ced8..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin-mojang-mapped/src/main/resources/plugin.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: CommandAPI -main: dev.jorel.commandapi.CommandAPIMain -version: ${project.version} -description: An API to use Minecraft 1.13s new command UI -authors: - - Skepter - - Will Kroboth - - DerEchtePilz -website: https://www.jorel.dev/CommandAPI/ -softdepend: - - NBTAPI -api-version: 1.13 -folia-supported: true diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml deleted file mode 100644 index b9ea01151..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade-mojang-mapped/pom.xml +++ /dev/null @@ -1,116 +0,0 @@ - - - 4.0.0 - - dev.jorel - commandapi-spigot - 11.0.0-SNAPSHOT - - - commandapi-bukkit-shade-mojang-mapped - Spigot support Mojang-mapped shade library - - - - dev.jorel - commandapi-spigot-core - ${project.version} - compile - - - dev.jorel - commandapi-spigot-nms-dependency-mojang-mapped - ${project.version} - pom - - - dev.jorel - commandapi-spigot-vh - ${project.version} - - - dev.jorel - commandapi-spigot-mojang-mapped - ${project.version} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - - - normal - package - - shade - - - true - true - - - - dev.jorel:commandapi-core - - dev/jorel/commandapi/CommandAPIVersionHandler** - dev/jorel/commandapi/MojangMappedVersionHandler** - - - - - - org.bukkit.craftbukkit.v1_20_R4 - org.bukkit.craftbukkit - - - org.bukkit.craftbukkit.v1_21_R1 - org.bukkit.craftbukkit - - - org.bukkit.craftbukkit.v1_21_R2 - org.bukkit.craftbukkit - - - org.bukkit.craftbukkit.v1_21_R3 - org.bukkit.craftbukkit - - - org.bukkit.craftbukkit.v1_21_R4 - org.bukkit.craftbukkit - - - org.bukkit.craftbukkit.v1_21_R5 - org.bukkit.craftbukkit - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - empty-javadoc-jar - package - - jar - - - javadoc - ${basedir}/javadoc - - - - - - - - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/pom.xml b/commandapi-platforms/commandapi-spigot/pom.xml index 16f61141f..438521ed3 100644 --- a/commandapi-platforms/commandapi-spigot/pom.xml +++ b/commandapi-platforms/commandapi-spigot/pom.xml @@ -18,11 +18,8 @@ commandapi-spigot-core commandapi-spigot-nms commandapi-spigot-vh - commandapi-spigot-mojang-mapped commandapi-spigot-plugin commandapi-spigot-shade - commandapi-spigot-plugin-mojang-mapped - commandapi-spigot-shade-mojang-mapped From 9ee041866ae7c75e194d130bb9988313719a560c Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:02:04 +0200 Subject: [PATCH 16/63] Implement fallback-to-latest-version config option --- .../java/dev/jorel/commandapi/CommandAPI.java | 3 +- .../jorel/commandapi/CommandAPIConfig.java | 78 ------------------- .../commandapi/CommandAPIVersionHandler.java | 6 +- .../dev/jorel/commandapi/InternalConfig.java | 59 -------------- .../jorel/commandapi/CommandAPIBukkit.java | 4 +- .../commandapi/CommandAPIBukkitConfig.java | 61 +++++++++++++-- .../java/dev/jorel/commandapi/Converter.java | 2 +- .../commandapi/InternalBukkitConfig.java | 53 +++++++++++++ .../arguments/NBTCompoundArgument.java | 6 +- .../config/DefaultBukkitConfig.java | 45 +++-------- .../dev/jorel/commandapi/CommandAPIPaper.java | 3 +- .../commandapi/CommandAPIPaperConfig.java | 1 + .../dev/jorel/commandapi/CommandAPIMain.java | 3 +- .../commandapi/CommandAPIVersionHandler.java | 58 +++++++------- .../dev/jorel/commandapi/CommandAPIMain.java | 5 +- .../commandapi/CommandAPIVersionHandler.java | 56 ++++++------- .../commandapi/CommandAPIVelocityConfig.java | 5 +- .../commandapi/CommandAPIVersionHandler.java | 7 +- 18 files changed, 199 insertions(+), 256 deletions(-) diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java index 551065cee..0a995a477 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java @@ -108,9 +108,10 @@ public static void onLoad(CommandAPIConfig config) { // Setup variables CommandAPI.config = new InternalConfig(config); + InternalConfig platformConfig = CommandAPIVersionHandler.getConfig(config); // Initialize handlers - LoadContext loadContext = CommandAPIVersionHandler.getPlatform(); + LoadContext loadContext = CommandAPIVersionHandler.getPlatform(platformConfig); CommandAPIPlatform platform = loadContext.platform(); new CommandAPIHandler<>(platform); loadContext.context().run(); diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIConfig.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIConfig.java index 45b51fa81..e49400406 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIConfig.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIConfig.java @@ -38,18 +38,10 @@ public abstract class CommandAPIConfig skipSenderProxy = new ArrayList<>(); - - // NBT API - Class nbtContainerClass = null; - Function nbtContainerConstructor = null; - boolean usePluginNamespace = false; String namespace = null; @@ -76,36 +68,6 @@ public Impl silentLogs(boolean value) { return instance(); } - /** - * Sets whether the CommandAPI should run the latest available version of NMS - * support, regardless of Minecraft version. This may produce unexpected results - * if the latest NMS version is not supported by the CommandAPI. This can be - * used to potentially provide compatibility with future Minecraft versions - * before the CommandAPI pushes a release to support it. - * - * @param value whether the latest version of NMS should be used - * @return this CommandAPIConfig - */ - public Impl useLatestNMSVersion(boolean value) { - this.useLatestNMSVersion = value; - return instance(); - } - - /** - * Sets whether the CommandAPI should load a (potentially unsupported) NMS version - * when updating to a minor release of Minecraft. As an example, this setting can allow - * updating to 1.21.2 from 1.21.1 but doesn't allow updating to 1.22 from 1.21.2. - * Unlike {@link #useLatestNMSVersion(boolean)}, this setting does - * not blindly load the latest NMS version, but will prefer loading the correct NMS implementation when available. - * - * @param value whether the CommandAPI should assume that minor Minecraft releases do not cause incompatibilities - * @return this CommandAPIConfig - */ - public Impl beLenientForMinorVersions(boolean value) { - this.beLenientForMinorVersions = value; - return instance(); - } - /** * Sets the message to display to users when a command has no executor. * Available formatting parameters are: @@ -138,37 +100,6 @@ public Impl dispatcherFile(File file) { return instance(); } - public Impl addSkipSenderProxy(String... names) { - this.skipSenderProxy.addAll(List.of(names)); - return instance(); - } - - public Impl addSkipSenderProxy(List names) { - this.skipSenderProxy.addAll(names); - return instance(); - } - - /** - * Initializes the CommandAPI's implementation of an NBT API. - * - * @param the type that the NBT compound container class - * is - * @param nbtContainerClass the NBT compound container class. For example, - * {@code NBTContainer.class} - * @param nbtContainerConstructor a function that takes an Object (NMS - * {@code NBTTagCompound}) and returns an - * instance of the provided NBT compound - * container. For example, - * {@code NBTContainer::new}. - * @return this CommandAPIConfig - */ - public Impl initializeNBTAPI(Class nbtContainerClass, - Function nbtContainerConstructor) { - this.nbtContainerClass = nbtContainerClass; - this.nbtContainerConstructor = nbtContainerConstructor; - return instance(); - } - /** * Sets the default namespace to use when register commands * @@ -182,13 +113,4 @@ public Impl setNamespace(String namespace) { return instance(); } - /** - * Sets whether the CommandAPI should use the plugin's name as the default namespace - *

- * If called, any call to {@link CommandAPIConfig#setNamespace(String)} will be ignored - * - * @return this CommandAPIConfig - */ - public abstract Impl usePluginNamespace(); - } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 297da6925..0e395b15d 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -16,7 +16,11 @@ static Object getVersion() { * * @return an instance of CommandAPIPlatform which can run on the currently active server */ - static LoadContext getPlatform() { + static LoadContext getPlatform(InternalConfig config) { + throw new IllegalStateException("You have the wrong copy of the CommandAPI! If you're shading, did you use commandapi-core instead of commandapi-{platform}-shade?"); + } + + static InternalConfig getConfig(CommandAPIConfig config) { throw new IllegalStateException("You have the wrong copy of the CommandAPI! If you're shading, did you use commandapi-core instead of commandapi-{platform}-shade?"); } } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/InternalConfig.java b/commandapi-core/src/main/java/dev/jorel/commandapi/InternalConfig.java index 5459fc24a..c80339ec5 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/InternalConfig.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/InternalConfig.java @@ -37,24 +37,12 @@ public class InternalConfig { // Whether we should suppress all logs private final boolean silentLogs; - // Whether we should use the latest NMS version (which may not be compatible) - private final boolean useLatestNMSVersion; - - private final boolean beLenientForMinorVersions; - // The message to display when an executor implementation is missing private final String messageMissingExecutorImplementation; // Create a command_registration.json file private final File dispatcherFile; - // List of plugins which should ignore proxied senders - private final List skipSenderProxy; - - // NBT API configuration - private Class nbtContainerClass; - private Function nbtContainerConstructor; - // The default command namespace private final String namespace; @@ -66,13 +54,8 @@ public class InternalConfig { public InternalConfig(CommandAPIConfig config) { this.verboseOutput = config.verboseOutput; this.silentLogs = config.silentLogs; - this.useLatestNMSVersion = config.useLatestNMSVersion; - this.beLenientForMinorVersions = config.beLenientForMinorVersions; this.messageMissingExecutorImplementation = config.missingExecutorImplementationMessage; this.dispatcherFile = config.dispatcherFile; - this.skipSenderProxy = config.skipSenderProxy; - this.nbtContainerClass = config.nbtContainerClass; - this.nbtContainerConstructor = config.nbtContainerConstructor; this.namespace = config.namespace; } @@ -90,20 +73,6 @@ public boolean hasSilentLogs() { return this.silentLogs; } - /** - * @return Whether the CommandAPI should use the latest available NMS version - */ - public boolean shouldUseLatestNMSVersion() { - return this.useLatestNMSVersion; - } - - /** - * @return Whether the CommandAPI should assume that minor versions of officially unsupported versions do not cause incompatibilities - */ - public boolean shouldBeLenientForMinorVersions() { - return this.beLenientForMinorVersions; - } - /** * @return The message to display if a command executor does not have an * implementation for a given type @@ -120,34 +89,6 @@ public File getDispatcherFile() { return this.dispatcherFile; } - /** - * @param commandName A command where sender proxying should be skipped - * @return Whether sender proxying should be skipped for a given command - */ - public boolean shouldSkipSenderProxy(String commandName) { - return this.skipSenderProxy.contains(commandName); - } - - /** - * @return The NBT Tag Compound implementation class - */ - public Class getNBTContainerClass() { - return this.nbtContainerClass; - } - - /** - * @return A function that takes in an Object (NMS NBTTagCompound) and returns - * an implementation of an NBT Tag Compound - */ - public Function getNBTContainerConstructor() { - return this.nbtContainerConstructor; - } - - public void lateInitializeNBT(Class nbtContainerClass, Function nbtContainerConstructor) { - this.nbtContainerClass = nbtContainerClass; - this.nbtContainerConstructor = nbtContainerConstructor; - } - /** * @return The default namespace used to register commands */ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java index e5bc92547..0de296607 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java @@ -128,8 +128,8 @@ public void onServerLoad(ServerLoadEvent event) { private void checkDependencies() { // Log successful hooks - Class nbtContainerClass = CommandAPI.getConfiguration().getNBTContainerClass(); - if (nbtContainerClass != null && CommandAPI.getConfiguration().getNBTContainerConstructor() != null) { + Class nbtContainerClass = CommandAPIBukkit.getConfiguration().getNBTContainerClass(); + if (nbtContainerClass != null && CommandAPIBukkit.getConfiguration().getNBTContainerConstructor() != null) { CommandAPI.logNormal("Hooked into an NBT API with class " + nbtContainerClass.getName()); } // We don't need to log if no NBT was found, constructing an NBTCompoundArgument without one will do that for us diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java index f3c9c1d61..a4febd712 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java @@ -2,6 +2,10 @@ import org.bukkit.plugin.java.JavaPlugin; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; + /** * A class that contains information needed to configure the CommandAPI on Bukkit-based servers. */ @@ -10,8 +14,15 @@ public abstract class CommandAPIBukkitConfig String pluginName; // Default configuration + boolean fallbackToLatestNMS = false; boolean skipReloadDatapacks = true; + List skipSenderProxy = new ArrayList<>(); + + // NBT API + Class nbtContainerClass = null; + Function nbtContainerConstructor = null; + /** * Creates a new CommandAPIBukkitConfig object. Variables in this * constructor are required to load the CommandAPI on Bukkit properly. @@ -24,16 +35,54 @@ public CommandAPIBukkitConfig(String pluginName) { } /** - * @deprecated The plugin namespace is now the default namespace - * @return this CommandAPIBukkitConfig + * Sets whether the CommandAPI should fall back to the latest nms version + * if no implementation for the current version was found. + * + * @param fallbackToLatestNMS whether to fall back to the latest versions + * @return this CommandAPIConfig */ - @Deprecated(since = "10.0.0", forRemoval = true) - public T usePluginNamespace() { - super.setNamespace(pluginName.toLowerCase()); - super.usePluginNamespace = true; + public T fallbackToLatestNMS(boolean fallbackToLatestNMS) { + this.fallbackToLatestNMS = fallbackToLatestNMS; + return instance(); + } + + public T addSkipSenderProxy(String... names) { + this.skipSenderProxy.addAll(List.of(names)); + return instance(); + } + + public T addSkipSenderProxy(List names) { + this.skipSenderProxy.addAll(names); + return instance(); + } + + /** + * Initializes the CommandAPI's implementation of an NBT API. + * + * @param the type that the NBT compound container class + * is + * @param nbtContainerClass the NBT compound container class. For example, + * {@code NBTContainer.class} + * @param nbtContainerConstructor a function that takes an Object (NMS + * {@code NBTTagCompound}) and returns an + * instance of the provided NBT compound + * container. For example, + * {@code NBTContainer::new}. + * @return this CommandAPIConfig + */ + public T initializeNBTAPI(Class nbtContainerClass, + Function nbtContainerConstructor) { + this.nbtContainerClass = nbtContainerClass; + this.nbtContainerConstructor = nbtContainerConstructor; return instance(); } + /** + * Sets the default namespace to use when register commands + * + * @param namespace the namespace to use when register commands + * @return this CommandAPIConfig + */ @Override public T setNamespace(String namespace) { if (namespace == null) { diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java index 84b8a3500..2fa992489 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/Converter.java @@ -200,7 +200,7 @@ private static void convertPluginCommand(JavaPlugin plugin, String commandName, .getCommand(commandName); } - CommandSender proxiedSender = CommandAPI.getConfiguration().shouldSkipSenderProxy(plugin.getName()) + CommandSender proxiedSender = CommandAPIBukkit.getConfiguration().shouldSkipSenderProxy(plugin.getName()) ? sender.getCallee() : mergeProxySender(sender); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java index 417074a45..db9a548dd 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/InternalBukkitConfig.java @@ -2,6 +2,9 @@ import org.bukkit.plugin.java.JavaPlugin; +import java.util.List; +import java.util.function.Function; + /** * Configuration wrapper class for Bukkit. The config.yml file used by the CommandAPI is * only ever read from, nothing is ever written to it. That's why there's only @@ -11,8 +14,18 @@ public abstract class InternalBukkitConfig extends InternalConfig { // The name of the plugin that is loading the CommandAPI private final String pluginName; + // Whether we should use the latest NMS version (which may not be compatible) + private final boolean fallbackToLatestNMS; + private final boolean skipReloadDatapacks; + // List of plugins which should ignore proxied senders + private final List skipSenderProxy; + + // NBT API configuration + private Class nbtContainerClass; + private Function nbtContainerConstructor; + /** * Creates an {@link InternalBukkitConfig} from a {@link CommandAPIBukkitConfig} * @@ -21,7 +34,11 @@ public abstract class InternalBukkitConfig extends InternalConfig { public InternalBukkitConfig(CommandAPIBukkitConfig> config) { super(config); this.pluginName = config.pluginName; + this.fallbackToLatestNMS = config.fallbackToLatestNMS; this.skipReloadDatapacks = config.skipReloadDatapacks; + this.skipSenderProxy = config.skipSenderProxy; + this.nbtContainerClass = config.nbtContainerClass; + this.nbtContainerConstructor = config.nbtContainerConstructor; } /** @@ -31,6 +48,14 @@ public String getPluginName() { return pluginName; } + /** + * @return Whether the CommandAPI should fall back to the latest version if no specific + * implementation for the current version was found + */ + public boolean fallbackToLatestNMS() { + return fallbackToLatestNMS; + } + /** * @return Whether the CommandAPI should skip reloading datapacks when the server has finished loading */ @@ -38,4 +63,32 @@ public boolean skipReloadDatapacks() { return skipReloadDatapacks; } + /** + * @param commandName A command where sender proxying should be skipped + * @return Whether sender proxying should be skipped for a given command + */ + public boolean shouldSkipSenderProxy(String commandName) { + return this.skipSenderProxy.contains(commandName); + } + + /** + * @return The NBT Tag Compound implementation class + */ + public Class getNBTContainerClass() { + return this.nbtContainerClass; + } + + /** + * @return A function that takes in an Object (NMS NBTTagCompound) and returns + * an implementation of an NBT Tag Compound + */ + public Function getNBTContainerConstructor() { + return this.nbtContainerConstructor; + } + + public void lateInitializeNBT(Class nbtContainerClass, Function nbtContainerConstructor) { + this.nbtContainerClass = nbtContainerClass; + this.nbtContainerConstructor = nbtContainerConstructor; + } + } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java index df6ca6024..2c4c155d1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/NBTCompoundArgument.java @@ -41,7 +41,7 @@ public class NBTCompoundArgument extends SafeOverrideableArgument< */ public NBTCompoundArgument(String nodeName) { super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentNBTCompound(), NBTContainer::toString); - if (CommandAPI.getConfiguration().getNBTContainerClass() == null || CommandAPI.getConfiguration().getNBTContainerConstructor() == null) { + if (CommandAPIBukkit.getConfiguration().getNBTContainerClass() == null || CommandAPIBukkit.getConfiguration().getNBTContainerConstructor() == null) { throw new NullPointerException( "The NBTCompoundArgument hasn't been initialized properly! Use CommandAPIConfig.initializeNBTAPI() in your onLoad() method"); } @@ -50,7 +50,7 @@ public NBTCompoundArgument(String nodeName) { @SuppressWarnings("unchecked") @Override public Class getPrimitiveType() { - return (Class) CommandAPI.getConfiguration().getNBTContainerClass(); + return (Class) CommandAPIBukkit.getConfiguration().getNBTContainerClass(); } @Override @@ -62,6 +62,6 @@ public CommandAPIArgumentType getArgumentType() { @Override public NBTContainer parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return (NBTContainer) CommandAPIBukkit.get().getNMS().getNBTCompound(cmdCtx, key, CommandAPI.getConfiguration().getNBTContainerConstructor()); + return (NBTContainer) CommandAPIBukkit.get().getNMS().getNBTCompound(cmdCtx, key, CommandAPIBukkit.getConfiguration().getNBTContainerConstructor()); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java index ceac67650..3d8c111e1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java @@ -8,36 +8,15 @@ @SuppressWarnings("DuplicatedCode") public class DefaultBukkitConfig extends DefaultConfig { - public static final CommentedConfigOption USE_LATEST_NMS_VERSION = new CommentedConfigOption<>( - new String[] { - "Use latest version (default: false)", - "If \"true\", the CommandAPI will use the latest available NMS implementation", - "when the CommandAPI is used. This avoids all checks to see if the latest NMS", - "implementation is actually compatible with the current Minecraft version." - }, false - ); - - public static final CommentedConfigOption BE_LENIENT_FOR_MINOR_VERSIONS = new CommentedConfigOption<>( - new String[] { - "Be lenient with version checks when loading for new minor Minecraft versions (default: false)", - "If \"true\", the CommandAPI loads NMS implementations for potentially unsupported Minecraft versions.", - "For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing", - "but will not allow an update from 1.21.2 to 1.22.", - "Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary." - }, false - ); - - public static final CommentedConfigOption SHOULD_HOOK_PAPER_RELOAD = new CommentedConfigOption<>( - new String[] { - "Hook into Paper's ServerResourcesReloadedEvent (default: false)", - "If \"true\", and the CommandAPI detects it is running on a Paper server, it will", - "hook into Paper's ServerResourcesReloadedEvent to detect when /minecraft:reload is run.", - "This allows the CommandAPI to automatically call its custom datapack-reloading", - "function which allows CommandAPI commands to be used in datapacks.", - "If you set this to false, CommandAPI commands may not work inside datapacks after", - "reloading datapacks." - }, false - ); + public static CommentedConfigOption FALLBACK_TO_LATEST_NMS(boolean paper) { + return new CommentedConfigOption<>(new String[]{ + "Fallback to latest version (default: " + (paper ? "true" : "false") + ")", + "If \"true\", the CommandAPI will fall back to the latest available NMS", + "implementation when the CommandAPI is used and no implementation for the", + "current Minecraft version was found." + }, paper + ); + } public static final CommentedConfigOption SKIP_RELOAD_DATAPACKS = new CommentedConfigOption<>( new String[] { @@ -81,8 +60,7 @@ public static DefaultBukkitConfig createDefaultPaperConfig() { options.put("silent-logs", SILENT_LOGS); options.put("messages.missing-executor-implementation", MISSING_EXECUTOR_IMPLEMENTATION); options.put("create-dispatcher-json", CREATE_DISPATCHER_JSON); - options.put("use-latest-nms-version", USE_LATEST_NMS_VERSION); - options.put("be-lenient-for-minor-versions", BE_LENIENT_FOR_MINOR_VERSIONS); + options.put("fallback-to-latest-nms", FALLBACK_TO_LATEST_NMS(true)); options.put("plugins-to-convert", PLUGINS_TO_CONVERT); options.put("other-commands-to-convert", OTHER_COMMANDS_TO_CONVERT); options.put("skip-sender-proxy", SKIP_SENDER_PROXY); @@ -99,8 +77,7 @@ public static DefaultBukkitConfig createDefaultSpigotConfig() { options.put("silent-logs", SILENT_LOGS); options.put("messages.missing-executor-implementation", MISSING_EXECUTOR_IMPLEMENTATION); options.put("create-dispatcher-json", CREATE_DISPATCHER_JSON); - options.put("use-latest-nms-version", USE_LATEST_NMS_VERSION); - options.put("be-lenient-for-minor-versions", BE_LENIENT_FOR_MINOR_VERSIONS); + options.put("fallback-to-latest-nms", FALLBACK_TO_LATEST_NMS(false)); options.put("skip-initial-datapack-reload", SKIP_RELOAD_DATAPACKS); options.put("plugins-to-convert", PLUGINS_TO_CONVERT); options.put("other-commands-to-convert", OTHER_COMMANDS_TO_CONVERT); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java index b709b638a..868b14ba4 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -43,8 +43,9 @@ public class CommandAPIPaper extends CommandAPIBukkit { private final BundledNMS nms; @SuppressWarnings("unchecked") - protected CommandAPIPaper() { + protected CommandAPIPaper(InternalPaperConfig config) { CommandAPIPaper.paper = this; + setInternalConfig(config); VersionContext context = (VersionContext) CommandAPIVersionHandler.getVersion(); context.context().run(); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java index fe6cd93bb..6abc2761a 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java @@ -21,6 +21,7 @@ public CommandAPIPaperConfig(PluginMeta pluginMeta, T lifecycleEventOwner) { super(pluginMeta.getName()); this.pluginMeta = pluginMeta; this.lifecycleEventOwner = lifecycleEventOwner; + fallbackToLatestNMS(true); } CommandAPIPaperConfig isCommandAPIPlugin() { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java index 6269bbd77..c86cf7619 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -50,10 +50,9 @@ public void onLoad() { CommandAPIPaperConfig config = new CommandAPIPaperConfig<>(this.getPluginMeta(), this) .verboseOutput(fileConfig.getBoolean("verbose-outputs")) .silentLogs(fileConfig.getBoolean("silent-logs")) - .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) + .fallbackToLatestNMS(fileConfig.getBoolean("fallback-to-latest-nms")) .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) - .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")) .isCommandAPIPlugin(); for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 54e38182a..21afc0691 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -9,52 +9,41 @@ import dev.jorel.commandapi.nms.PaperNMS_1_21_R3; import dev.jorel.commandapi.nms.PaperNMS_1_21_R4; import dev.jorel.commandapi.nms.PaperNMS_1_21_R5; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; import org.bukkit.Bukkit; import io.papermc.paper.ServerBuildInfo; public abstract class CommandAPIVersionHandler { - static LoadContext getPlatform() { - return new LoadContext(new CommandAPIPaper<>()); + static LoadContext getPlatform(InternalConfig config) { + InternalPaperConfig paperConfig = (InternalPaperConfig) config; + return new LoadContext(new CommandAPIPaper<>(paperConfig)); } - @SuppressWarnings("ConstantValue") static Object getVersion() { - String latestMajorVersion = "21"; // Change this for Minecraft's major update - try { - if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) { + ServerBuildInfo buildInfo = ServerBuildInfo.buildInfo(); + String version = buildInfo.minecraftVersionId(); + PaperNMS versionAdapter = switch (version) { + case "1.20.6" -> new PaperNMS_1_20_R4(); + case "1.21", "1.21.1" -> new PaperNMS_1_21_R1(); + case "1.21.2", "1.21.3" -> new PaperNMS_1_21_R2(); + case "1.21.4" -> new PaperNMS_1_21_R3(); + case "1.21.5" -> new PaperNMS_1_21_R4(); + case "1.21.6", "1.21.7", "1.21.8" -> new PaperNMS_1_21_R5(); + default -> null; + }; + if (versionAdapter != null) { + return new VersionContext(new APITypeProvider(versionAdapter)); + } + if (CommandAPIPaper.getConfiguration().fallbackToLatestNMS()) { return new VersionContext(new APITypeProvider(new PaperNMS_1_21_R5()), () -> { CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); }); - } else { - ServerBuildInfo buildInfo = ServerBuildInfo.buildInfo(); - String version = buildInfo.minecraftVersionId(); - PaperNMS versionAdapter = switch (version) { - case "1.20.6" -> new PaperNMS_1_20_R4(); - case "1.21", "1.21.1" -> new PaperNMS_1_21_R1(); - case "1.21.2", "1.21.3" -> new PaperNMS_1_21_R2(); - case "1.21.4" -> new PaperNMS_1_21_R3(); - case "1.21.5" -> new PaperNMS_1_21_R4(); - case "1.21.6", "1.21.7", "1.21.8" -> new PaperNMS_1_21_R5(); - default -> null; - }; - if (versionAdapter != null) { - return new VersionContext(new APITypeProvider(versionAdapter)); - } - if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) { - String currentMajorVersion = version.split("\\.")[1]; - if (latestMajorVersion.equals(currentMajorVersion)) { - return new VersionContext(new APITypeProvider(new PaperNMS_1_21_R5()), () -> { - CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation."); - CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); - }); - } - } - version = buildInfo.asString(ServerBuildInfo.StringRepresentation.VERSION_SIMPLE); - throw new UnsupportedVersionException(version); } + version = buildInfo.asString(ServerBuildInfo.StringRepresentation.VERSION_SIMPLE); + throw new UnsupportedVersionException(version); } catch (Throwable error) { if (error instanceof ClassNotFoundException cnfe) { // Thrown when users use versions before the ServerBuildInfo was added. We should inform them @@ -66,4 +55,9 @@ static Object getVersion() { } } + static InternalConfig getConfig(CommandAPIConfig config) { + // This should never be a casting error since only the Paper module has this version handler and the CommandAPIPaperConfig + return new InternalPaperConfig((CommandAPIPaperConfig) config); + } + } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java index 2d6c4639a..e4c75adb6 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/src/main/java/dev/jorel/commandapi/CommandAPIMain.java @@ -49,11 +49,10 @@ public void onLoad() { CommandAPISpigotConfig config = new CommandAPISpigotConfig(this) .verboseOutput(fileConfig.getBoolean("verbose-outputs")) .silentLogs(fileConfig.getBoolean("silent-logs")) - .useLatestNMSVersion(fileConfig.getBoolean("use-latest-nms-version")) + .fallbackToLatestNMS(fileConfig.getBoolean("fallback-to-latest-nms")) .missingExecutorImplementationMessage(fileConfig.getString("messages.missing-executor-implementation")) .dispatcherFile(fileConfig.getBoolean("create-dispatcher-json") ? new File(getDataFolder(), "command_registration.json") : null) - .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")) - .beLenientForMinorVersions(fileConfig.getBoolean("be-lenient-for-minor-versions")); + .skipReloadDatapacks(fileConfig.getBoolean("skip-initial-datapack-reload")); for (String pluginName : fileConfig.getStringList("skip-sender-proxy")) { if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index d2acf9c7f..4e68a7733 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -14,43 +14,32 @@ public abstract class CommandAPIVersionHandler { - static LoadContext getPlatform() { - String latestMajorVersion = "21"; // Change this for Minecraft's major update - + static LoadContext getPlatform(InternalConfig config) { + InternalSpigotConfig spigotConfig = (InternalSpigotConfig) config; try { - if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) { + String version = Bukkit.getBukkitVersion().split("-")[0]; + CommandAPIPlatform platform = switch (version) { + case "1.20", "1.20.1" -> new SpigotNMS_1_20_R1(); + case "1.20.2" -> new SpigotNMS_1_20_R2(); + case "1.20.3", "1.20.4" -> new SpigotNMS_1_20_R3(); + case "1.20.5", "1.20.6" -> new SpigotNMS_1_20_R4(); + case "1.21", "1.21.1" -> new SpigotNMS_1_21_R1(); + case "1.21.2", "1.21.3" -> new SpigotNMS_1_21_R2(); + case "1.21.4" -> new SpigotNMS_1_21_R3(); + case "1.21.5" -> new SpigotNMS_1_21_R4(); + case "1.21.6", "1.21.7", "1.21.8" -> new SpigotNMS_1_21_R5(); + default -> null; + }; + if (platform != null) { + return new LoadContext(platform); + } + if (spigotConfig.fallbackToLatestNMS()) { return new LoadContext(new SpigotNMS_1_21_R5(), () -> { CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); }); - } else { - String version = Bukkit.getBukkitVersion().split("-")[0]; - CommandAPIPlatform platform = switch (version) { - case "1.20", "1.20.1" -> new SpigotNMS_1_20_R1(); - case "1.20.2" -> new SpigotNMS_1_20_R2(); - case "1.20.3", "1.20.4" -> new SpigotNMS_1_20_R3(); - case "1.20.5", "1.20.6" -> new SpigotNMS_1_20_R4(); - case "1.21", "1.21.1" -> new SpigotNMS_1_21_R1(); - case "1.21.2", "1.21.3" -> new SpigotNMS_1_21_R2(); - case "1.21.4" -> new SpigotNMS_1_21_R3(); - case "1.21.5" -> new SpigotNMS_1_21_R4(); - case "1.21.6", "1.21.7", "1.21.8" -> new SpigotNMS_1_21_R5(); - default -> null; - }; - if (platform != null) { - return new LoadContext(platform); - } - if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) { - String currentMajorVersion = version.split("\\.")[1]; - if (latestMajorVersion.equals(currentMajorVersion)) { - return new LoadContext(new SpigotNMS_1_21_R5(), () -> { - CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation."); - CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); - }); - } - } - throw new UnsupportedVersionException(version); } + throw new UnsupportedVersionException(version); } catch (Throwable error) { // Something went sideways when trying to load a platform. This probably means we're shading the wrong mappings. // Because this is an error we'll just rethrow this (instead of piping it into logError, which we can't really @@ -62,4 +51,9 @@ static LoadContext getPlatform() { } } + static InternalConfig getConfig(CommandAPIConfig config) { + // This should never be a casting error since only the Spigot module has this version handler and the CommandAPISpigotConfig + return new InternalSpigotConfig((CommandAPISpigotConfig) config); + } + } diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocityConfig.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocityConfig.java index 34d9987ad..a11209bc2 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocityConfig.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocityConfig.java @@ -28,9 +28,12 @@ public CommandAPIVelocityConfig(ProxyServer server, Object plugin) { } /** + * Sets whether the CommandAPI should use the plugin's name as the default namespace + *

+ * If called, any call to {@link CommandAPIConfig#setNamespace(String)} will be ignored + * * @return this CommandAPIVelocityConfig */ - @Override public CommandAPIVelocityConfig usePluginNamespace() { Optional pluginContainerOptional = server.getPluginManager().fromInstance(plugin); if (pluginContainerOptional.isEmpty()) { diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index b3019d3f3..02776d5d1 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -1,7 +1,12 @@ package dev.jorel.commandapi; public abstract class CommandAPIVersionHandler { - static LoadContext getPlatform() { + static LoadContext getPlatform(InternalConfig config) { return new LoadContext(new CommandAPIVelocity()); } + + static InternalConfig getConfig(CommandAPIConfig config) { + // This should never be a casting error since only the Velocity module has this version handler and the CommandAPIVelocityConfig + return new InternalVelocityConfig((CommandAPIVelocityConfig) config); + } } From dddd8d7a810966080e7f354bcc7c1a1851733b60 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sat, 9 Aug 2025 12:06:03 +0200 Subject: [PATCH 17/63] Fix some messages --- .../src/main/java/dev/jorel/commandapi/CommandAPIPaper.java | 6 +++--- .../main/java/dev/jorel/commandapi/CommandAPISpigot.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java index 868b14ba4..57179676c 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -74,7 +74,7 @@ public static CommandAPIPaper getPaper() { if (paper != null) { return (CommandAPIPaper) paper; } - throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + throw new IllegalStateException("Tried to access CommandAPIPaper instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); } public static InternalPaperConfig getConfiguration() { @@ -103,8 +103,8 @@ public void onLoad(CommandAPIConfig config) { CommandAPIPaper.setInternalConfig(new InternalPaperConfig(paperConfig)); this.lifecycleEventOwner = paperConfig.lifecycleEventOwner; } else { - CommandAPI.logError("CommandAPIBukkit was loaded with non-Bukkit config!"); - CommandAPI.logError("Attempts to access Bukkit-specific config variables will fail!"); + CommandAPI.logError("CommandAPIPaper was loaded with non-Paper config!"); + CommandAPI.logError("Attempts to access Paper-specific config variables will fail!"); } super.onLoad(); checkPaperDependencies(); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java index 1e1d1b633..32e730842 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java @@ -42,7 +42,7 @@ public static CommandAPISpigot getSpigot() { if (spigot != null) { return (CommandAPISpigot) spigot; } - throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); + throw new IllegalStateException("Tried to access CommandAPISpigot instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); } public static InternalSpigotConfig getConfiguration() { @@ -58,8 +58,8 @@ public void onLoad(CommandAPIConfig config) { if (config instanceof CommandAPISpigotConfig spigotConfig) { CommandAPISpigot.setInternalConfig(new InternalSpigotConfig(spigotConfig)); } else { - CommandAPI.logError("CommandAPIBukkit was loaded with non-Bukkit config!"); - CommandAPI.logError("Attempts to access Bukkit-specific config variables will fail!"); + CommandAPI.logError("CommandAPISpigot was loaded with non-Spigot config!"); + CommandAPI.logError("Attempts to access Spigot-specific config variables will fail!"); } super.onLoad(); } From 67c335335b9d63e73d72b0b8e2bcc5d889caf6b0 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sat, 9 Aug 2025 12:50:51 +0200 Subject: [PATCH 18/63] Log the version on Paper too --- .../dev/jorel/commandapi/CommandAPIPaper.java | 3 +- .../dev/jorel/commandapi/VersionContext.java | 10 ++++-- .../commandapi/CommandAPIVersionHandler.java | 35 +++++++++++++++---- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java index 57179676c..378248709 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -48,7 +48,8 @@ protected CommandAPIPaper(InternalPaperConfig config) { setInternalConfig(config); VersionContext context = (VersionContext) CommandAPIVersionHandler.getVersion(); - context.context().run(); + context.context().accept(getLogger()); + context.additionalContext().accept(getLogger()); this.nms = (BundledNMS) context.nms(); super.nms = this.nms; diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java index 98e5527c0..167bd46c8 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java @@ -2,10 +2,16 @@ import dev.jorel.commandapi.nms.BundledNMS; -public record VersionContext(BundledNMS nms, Runnable context) { +import java.util.function.Consumer; + +public record VersionContext(BundledNMS nms, Consumer context, Consumer additionalContext) { + + public VersionContext(BundledNMS nms, Consumer context) { + this(nms, context, (logger) -> {}); + } public VersionContext(BundledNMS nms) { - this(nms, () -> {}); + this(nms, (logger) -> {}); } } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 21afc0691..e91242c5f 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -2,6 +2,7 @@ import dev.jorel.commandapi.exceptions.UnsupportedVersionException; import dev.jorel.commandapi.nms.APITypeProvider; +import dev.jorel.commandapi.nms.BundledNMS; import dev.jorel.commandapi.nms.PaperNMS; import dev.jorel.commandapi.nms.PaperNMS_1_20_R4; import dev.jorel.commandapi.nms.PaperNMS_1_21_R1; @@ -9,9 +10,11 @@ import dev.jorel.commandapi.nms.PaperNMS_1_21_R3; import dev.jorel.commandapi.nms.PaperNMS_1_21_R4; import dev.jorel.commandapi.nms.PaperNMS_1_21_R5; -import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; -import org.bukkit.Bukkit; import io.papermc.paper.ServerBuildInfo; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; + +import java.util.ArrayList; +import java.util.List; public abstract class CommandAPIVersionHandler { @@ -34,12 +37,16 @@ static Object getVersion() { default -> null; }; if (versionAdapter != null) { - return new VersionContext(new APITypeProvider(versionAdapter)); + return new VersionContext( + new APITypeProvider(versionAdapter), + (logger) -> {}, + (logger) -> logger.info("Loaded version " + getPlatformMessage(versionAdapter)) + ); } if (CommandAPIPaper.getConfiguration().fallbackToLatestNMS()) { - return new VersionContext(new APITypeProvider(new PaperNMS_1_21_R5()), () -> { - CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); - CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + return new VersionContext(new APITypeProvider(new PaperNMS_1_21_R5()), (logger) -> { + logger.warning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); + logger.warning("While you may find success with this, further updates might be necessary to fully support the version you are using."); }); } version = buildInfo.asString(ServerBuildInfo.StringRepresentation.VERSION_SIMPLE); @@ -60,4 +67,20 @@ static InternalConfig getConfig(CommandAPIConfig config) { return new InternalPaperConfig((CommandAPIPaperConfig) config); } + private static String getPlatformMessage(PaperNMS nms) { + final String platformClassHierarchy; + { + List platformClassHierarchyList = new ArrayList<>(); + Class platformClass = nms.getClass(); + // Goes up through class inheritance only (ending at Object, but we don't want to include that) + // CommandAPIPlatform is an interface, so it is not included + while (platformClass != null && platformClass != Object.class) { + platformClassHierarchyList.add(platformClass.getSimpleName()); + platformClass = platformClass.getSuperclass(); + } + platformClassHierarchy = String.join(" > ", platformClassHierarchyList); + } + return platformClassHierarchy; + } + } From 84612141914f219ca6bf33698d890bcbe3f21dee Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Mon, 18 Aug 2025 20:48:40 +0200 Subject: [PATCH 19/63] Address code reviews --- .../java/dev/jorel/commandapi/CommandAPI.java | 35 ++++++------ .../jorel/commandapi/CommandAPIHandler.java | 4 +- .../jorel/commandapi/CommandAPIPlatform.java | 4 +- .../commandapi/CommandAPIVersionHandler.java | 9 +--- .../dev/jorel/commandapi/BukkitPlatform.java | 2 +- .../commandapi/CommandAPIBukkitConfig.java | 2 + .../dev/jorel/commandapi/CommandAPIPaper.java | 25 +++------ .../jorel/commandapi/InternalPaperConfig.java | 9 ++++ .../dev/jorel/commandapi/VersionContext.java | 6 +-- .../jorel/commandapi/nms/APITypeProvider.java | 22 ++++---- .../commandapi/CommandAPIVersionHandler.java | 54 +++++++------------ .../jorel/commandapi/CommandAPISpigot.java | 18 +------ .../commandapi/nms/SpigotNMS_1_20_R2.java | 5 ++ .../commandapi/nms/SpigotNMS_1_20_R3.java | 5 ++ .../commandapi/nms/SpigotNMS_1_20_R4.java | 5 ++ .../commandapi/nms/SpigotNMS_1_20_R1.java | 5 ++ .../commandapi/nms/SpigotNMS_1_21_R2.java | 5 ++ .../commandapi/nms/SpigotNMS_1_21_R3.java | 5 ++ .../commandapi/nms/SpigotNMS_1_21_R4.java | 5 ++ .../commandapi/nms/SpigotNMS_1_21_R5.java | 5 ++ .../commandapi/nms/SpigotNMS_1_21_R1.java | 5 ++ .../commandapi/CommandAPIVersionHandler.java | 36 ++++++------- .../jorel/commandapi/CommandAPIVelocity.java | 16 ++---- .../commandapi/CommandAPIVersionHandler.java | 15 +++--- 24 files changed, 151 insertions(+), 151 deletions(-) diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java index 0a995a477..d618f39d9 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java @@ -108,31 +108,18 @@ public static void onLoad(CommandAPIConfig config) { // Setup variables CommandAPI.config = new InternalConfig(config); - InternalConfig platformConfig = CommandAPIVersionHandler.getConfig(config); // Initialize handlers - LoadContext loadContext = CommandAPIVersionHandler.getPlatform(platformConfig); + LoadContext loadContext = CommandAPIVersionHandler.getPlatform(config); CommandAPIPlatform platform = loadContext.platform(); new CommandAPIHandler<>(platform); loadContext.context().run(); // Load the platform - CommandAPIHandler.getInstance().onLoad(config); + CommandAPIHandler.getInstance().onLoad(); // Log platform load - final String platformClassHierarchy; - { - List platformClassHierarchyList = new ArrayList<>(); - Class platformClass = platform.getClass(); - // Goes up through class inheritance only (ending at Object, but we don't want to include that) - // CommandAPIPlatform is an interface, so it is not included - while (platformClass != null && platformClass != Object.class) { - platformClassHierarchyList.add(platformClass.getSimpleName()); - platformClass = platformClass.getSuperclass(); - } - platformClassHierarchy = String.join(" > ", platformClassHierarchyList); - } - logNormal("Loaded platform " + platformClassHierarchy); + logNormal("Loaded platform " + getPlatformMessage(platform)); loaded = true; } else { @@ -148,6 +135,22 @@ public static void onLoad(CommandAPIConfig config) { } } + static String getPlatformMessage(Object platform) { + final String platformClassHierarchy; + { + List platformClassHierarchyList = new ArrayList<>(); + Class platformClass = platform.getClass(); + // Goes up through class inheritance only (ending at Object, but we don't want to include that) + // CommandAPIPlatform is an interface, so it is not included + while (platformClass != null && platformClass != Object.class) { + platformClassHierarchyList.add(platformClass.getSimpleName()); + platformClass = platformClass.getSuperclass(); + } + platformClassHierarchy = String.join(" > ", platformClassHierarchyList); + } + return platformClassHierarchy; + } + /** * Enables the CommandAPI. This should be placed at the start of your * onEnable() method. diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java index be3156ee6..604662c48 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIHandler.java @@ -134,9 +134,9 @@ protected CommandAPIHandler(CommandAPIPlatform CommandAPIHandler.instance = this; } - public void onLoad(CommandAPIConfig config) { + public void onLoad() { checkDependencies(); - platform.onLoad(config); + platform.onLoad(); } private void checkDependencies() { diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java index dba63d0af..609a0a5ad 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIPlatform.java @@ -30,10 +30,8 @@ public interface CommandAPIPlatform config); + void onLoad(); /** * Platform-specific stuff that should happen when the CommandAPI is enabled diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 0e395b15d..61bbfbaa1 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -7,20 +7,13 @@ */ public abstract class CommandAPIVersionHandler { - static Object getVersion() { - throw new IllegalStateException("You have the wrong copy of the CommandAPI! If you're shading, did you use commandapi-core instead of commandapi-{platform}-shade?"); - } - /** * Returns an instance of the version's implementation of CommandAPIPlatform. * * @return an instance of CommandAPIPlatform which can run on the currently active server */ - static LoadContext getPlatform(InternalConfig config) { + static LoadContext getPlatform(CommandAPIConfig config) { throw new IllegalStateException("You have the wrong copy of the CommandAPI! If you're shading, did you use commandapi-core instead of commandapi-{platform}-shade?"); } - static InternalConfig getConfig(CommandAPIConfig config) { - throw new IllegalStateException("You have the wrong copy of the CommandAPI! If you're shading, did you use commandapi-core instead of commandapi-{platform}-shade?"); - } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java index e333b95b4..bbf9f0500 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitPlatform.java @@ -9,7 +9,7 @@ public interface BukkitPlatform extends CommandAPIPlatform, CommandSender, Source> { @Override - void onLoad(CommandAPIConfig config); + void onLoad(); CommandMap getCommandMap(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java index a4febd712..ee6a04f7b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkitConfig.java @@ -79,6 +79,8 @@ public T initializeNBTAPI(Class nbtContainerClass, /** * Sets the default namespace to use when register commands + *

+ * This namespace can't be {@code null} or empty and has to match the regex: {@code [0-9a-z_.-]+} * * @param namespace the namespace to use when register commands * @return this CommandAPIConfig diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java index 378248709..ce0fa996d 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -40,18 +40,14 @@ public class CommandAPIPaper extends CommandAPIBukkit { private CommandAPILogger bootstrapLogger; private LifecycleEventOwner lifecycleEventOwner; - private final BundledNMS nms; @SuppressWarnings("unchecked") - protected CommandAPIPaper(InternalPaperConfig config) { + protected CommandAPIPaper(InternalPaperConfig config, BundledNMS nms) { CommandAPIPaper.paper = this; setInternalConfig(config); + this.lifecycleEventOwner = config.getLifecycleEventOwner(); - VersionContext context = (VersionContext) CommandAPIVersionHandler.getVersion(); - context.context().accept(getLogger()); - context.additionalContext().accept(getLogger()); - this.nms = (BundledNMS) context.nms(); - super.nms = this.nms; + super.nms = nms; Class tempFeedbackForwardingCommandSender = null; Class tempNullCommandSender = null; @@ -93,20 +89,13 @@ private static void setInternalConfig(InternalPaperConfig config) { @Override public BundledNMS getNMS() { if (nms != null) { - return this.nms; + return (BundledNMS) this.nms; } throw new IllegalStateException("Tried to access NMS instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); } @Override - public void onLoad(CommandAPIConfig config) { - if (config instanceof CommandAPIPaperConfig paperConfig) { - CommandAPIPaper.setInternalConfig(new InternalPaperConfig(paperConfig)); - this.lifecycleEventOwner = paperConfig.lifecycleEventOwner; - } else { - CommandAPI.logError("CommandAPIPaper was loaded with non-Paper config!"); - CommandAPI.logError("Attempts to access Paper-specific config variables will fail!"); - } + public void onLoad() { super.onLoad(); checkPaperDependencies(); PaperCommandRegistration registration = (PaperCommandRegistration) CommandAPIBukkit.get().getCommandRegistrationStrategy(); @@ -120,7 +109,7 @@ public void onLoad(CommandAPIConfig config) { @Override public void onEnable() { super.plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(getConfiguration().getPluginName()); - CommandAPIPaper.getPaper().lifecycleEventOwner = super.plugin; + this.lifecycleEventOwner = super.plugin; new Schedulers(paper.isFoliaPresent).scheduleSyncDelayed(plugin, () -> { CommandAPIBukkit.get().getCommandRegistrationStrategy().runTasksAfterServerStart(); @@ -204,7 +193,7 @@ public Platform activePlatform() { @Override public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return nms.createCommandRegistrationStrategy(); + return getNMS().createCommandRegistrationStrategy(); } @Override diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java index 5c6e08c10..fafd6a8d5 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/InternalPaperConfig.java @@ -8,11 +8,13 @@ public class InternalPaperConfig extends InternalBukkitConfig { private final PluginMeta pluginMeta; + private final LifecycleEventOwner lifecycleEventOwner; private final boolean isCommandAPIPlugin; public InternalPaperConfig(CommandAPIPaperConfig config) { super(config); this.pluginMeta = config.pluginMeta; + this.lifecycleEventOwner = config.lifecycleEventOwner; this.isCommandAPIPlugin = config.isCommandAPIPlugin; } @@ -20,6 +22,13 @@ boolean isCommandAPIPlugin() { return isCommandAPIPlugin; } + /** + * @return the {@link LifecycleEventOwner} loading the CommandAPI + */ + public LifecycleEventOwner getLifecycleEventOwner() { + return lifecycleEventOwner; + } + /** * @return The {@link PluginMeta} of the plugin loading the CommandAPI */ diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java index 167bd46c8..229b8d9cd 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java @@ -4,11 +4,7 @@ import java.util.function.Consumer; -public record VersionContext(BundledNMS nms, Consumer context, Consumer additionalContext) { - - public VersionContext(BundledNMS nms, Consumer context) { - this(nms, context, (logger) -> {}); - } +public record VersionContext(BundledNMS nms, Consumer context) { public VersionContext(BundledNMS nms) { this(nms, (logger) -> {}); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index 56a7f2e38..b4bbe96d6 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -94,9 +94,16 @@ public class APITypeProvider extends BundledNMS { private final PaperNMS paperNMS; + private final SimpleCommandExceptionType noEntitiesFound; + private final SimpleCommandExceptionType noPlayersFound; + public APITypeProvider(PaperNMS paperNMS) { this.paperNMS = (PaperNMS) paperNMS; bukkitNMS(); + + GsonComponentSerializer gson = GsonComponentSerializer.gson(); + this.noEntitiesFound = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.entity")))); + this.noPlayersFound = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.player")))); } private ArgumentType getArgumentType(ThrowingSupplier> paper, Supplier> nms) { @@ -452,23 +459,20 @@ public Enchantment getEnchantment(CommandContext cmdCtx, Str @Override public EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String key) { - GsonComponentSerializer gson = GsonComponentSerializer.gson(); - SimpleCommandExceptionType NO_ENTITIES_FOUND = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.entity")))); - SimpleCommandExceptionType NO_PLAYERS_FOUND = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.player")))); return new EntitySelectorParser( () -> cmdCtx.getArgument(key, PlayerSelectorArgumentResolver.class).resolve(cmdCtx.getSource()).getFirst(), () -> cmdCtx.getArgument(key, EntitySelectorArgumentResolver.class).resolve(cmdCtx.getSource()).getFirst(), (allowEmpty) -> { List players = cmdCtx.getArgument(key, PlayerSelectorArgumentResolver.class).resolve(cmdCtx.getSource()); if (players.isEmpty() && !allowEmpty) { - throw NO_PLAYERS_FOUND.create(); + throw noPlayersFound.create(); } return players; }, (allowEmpty) -> { List entities = cmdCtx.getArgument(key, EntitySelectorArgumentResolver.class).resolve(cmdCtx.getSource()); if (entities.isEmpty() && !allowEmpty) { - throw NO_ENTITIES_FOUND.create(); + throw noEntitiesFound.create(); } return entities; } @@ -609,7 +613,7 @@ public OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, } private UUID getIdFromProfile(CommandContext ctx, String name) throws CommandSyntaxException { - Collection playerProfiles = ctx.getArgument(name, PlayerProfileListResolver.class).resolve((CommandSourceStack) ctx.getSource()); + Collection playerProfiles = ctx.getArgument(name, PlayerProfileListResolver.class).resolve(ctx.getSource()); UUID id = playerProfiles.iterator().next().getId(); if (id == null) { throw new SimpleCommandExceptionType(BukkitTooltip.messageFromAdventureComponent(Component.translatable("argument.player.unknown"))).create(); @@ -636,7 +640,7 @@ public Recipe getRecipe(CommandContext cmdCtx, String key) t public Rotation getRotation(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, (ctx, name) -> { - io.papermc.paper.math.Rotation rotation = ctx.getArgument(name, RotationResolver.class).resolve((CommandSourceStack) ctx.getSource()); + io.papermc.paper.math.Rotation rotation = ctx.getArgument(name, RotationResolver.class).resolve(ctx.getSource()); return new Rotation(rotation.yaw(), rotation.pitch()); }, (ctx, name) -> paperNMS.bukkitNMS().getRotation(ctx, name) @@ -791,11 +795,11 @@ public List getProfile(CommandContext cmdCtx, @Override public NMS bukkitNMS() { - return ((PaperNMS) paperNMS).bukkitNMS(); + return paperNMS.bukkitNMS(); } @Override public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return ((PaperNMS) paperNMS).createCommandRegistrationStrategy(); + return paperNMS.createCommandRegistrationStrategy(); } } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index e91242c5f..a22b94217 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -2,7 +2,6 @@ import dev.jorel.commandapi.exceptions.UnsupportedVersionException; import dev.jorel.commandapi.nms.APITypeProvider; -import dev.jorel.commandapi.nms.BundledNMS; import dev.jorel.commandapi.nms.PaperNMS; import dev.jorel.commandapi.nms.PaperNMS_1_20_R4; import dev.jorel.commandapi.nms.PaperNMS_1_21_R1; @@ -18,12 +17,14 @@ public abstract class CommandAPIVersionHandler { - static LoadContext getPlatform(InternalConfig config) { - InternalPaperConfig paperConfig = (InternalPaperConfig) config; - return new LoadContext(new CommandAPIPaper<>(paperConfig)); - } + static LoadContext getPlatform(CommandAPIConfig config) { + InternalPaperConfig internalPaperConfig; + if (config instanceof CommandAPIPaperConfig paperConfig) { + internalPaperConfig = new InternalPaperConfig(paperConfig); + } else { + throw new IllegalArgumentException("CommandAPIPaper was loaded with non-Paper config!"); + } - static Object getVersion() { try { ServerBuildInfo buildInfo = ServerBuildInfo.buildInfo(); String version = buildInfo.minecraftVersionId(); @@ -37,17 +38,21 @@ static Object getVersion() { default -> null; }; if (versionAdapter != null) { - return new VersionContext( - new APITypeProvider(versionAdapter), - (logger) -> {}, - (logger) -> logger.info("Loaded version " + getPlatformMessage(versionAdapter)) + return new LoadContext( + new CommandAPIPaper<>(internalPaperConfig, new APITypeProvider(versionAdapter)), + () -> CommandAPI.logNormal("Loaded version " + CommandAPI.getPlatformMessage(versionAdapter)) ); } if (CommandAPIPaper.getConfiguration().fallbackToLatestNMS()) { - return new VersionContext(new APITypeProvider(new PaperNMS_1_21_R5()), (logger) -> { - logger.warning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); - logger.warning("While you may find success with this, further updates might be necessary to fully support the version you are using."); - }); + PaperNMS paperNMS = new PaperNMS_1_21_R5(); + return new LoadContext( + new CommandAPIPaper<>(internalPaperConfig, new APITypeProvider(paperNMS)), + () -> { + CommandAPI.logNormal("Loaded version " + CommandAPI.getPlatformMessage(paperNMS)); + CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); + CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); + } + ); } version = buildInfo.asString(ServerBuildInfo.StringRepresentation.VERSION_SIMPLE); throw new UnsupportedVersionException(version); @@ -62,25 +67,4 @@ static Object getVersion() { } } - static InternalConfig getConfig(CommandAPIConfig config) { - // This should never be a casting error since only the Paper module has this version handler and the CommandAPIPaperConfig - return new InternalPaperConfig((CommandAPIPaperConfig) config); - } - - private static String getPlatformMessage(PaperNMS nms) { - final String platformClassHierarchy; - { - List platformClassHierarchyList = new ArrayList<>(); - Class platformClass = nms.getClass(); - // Goes up through class inheritance only (ending at Object, but we don't want to include that) - // CommandAPIPlatform is an interface, so it is not included - while (platformClass != null && platformClass != Object.class) { - platformClassHierarchyList.add(platformClass.getSimpleName()); - platformClass = platformClass.getSuperclass(); - } - platformClassHierarchy = String.join(" > ", platformClassHierarchyList); - } - return platformClassHierarchy; - } - } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java index 32e730842..ed2fab2b6 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/CommandAPISpigot.java @@ -32,8 +32,9 @@ public abstract class CommandAPISpigot extends CommandAPIBukkit private static CommandAPISpigot spigot; @SuppressWarnings("unchecked") - protected CommandAPISpigot() { + protected CommandAPISpigot(InternalSpigotConfig config) { this.nms = bukkitNMS(); + CommandAPIBukkit.config = config; CommandAPISpigot.spigot = this; } @@ -49,21 +50,6 @@ public static InternalSpigotConfig getConfiguration() { return (InternalSpigotConfig) CommandAPIBukkit.getConfiguration(); } - private static void setInternalConfig(InternalSpigotConfig config) { - CommandAPIBukkit.config = config; - } - - @Override - public void onLoad(CommandAPIConfig config) { - if (config instanceof CommandAPISpigotConfig spigotConfig) { - CommandAPISpigot.setInternalConfig(new InternalSpigotConfig(spigotConfig)); - } else { - CommandAPI.logError("CommandAPISpigot was loaded with non-Spigot config!"); - CommandAPI.logError("Attempts to access Spigot-specific config variables will fail!"); - } - super.onLoad(); - } - /** * Enables the CommandAPI. This should be placed at the start of your * onEnable() method. diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java index b878286bc..cded70de8 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; import dev.jorel.commandapi.SpigotCommandRegistration; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -28,6 +29,10 @@ public class SpigotNMS_1_20_R2 extends CommandAPISpigot { private NMS_1_20_R2 bukkitNMS; + public SpigotNMS_1_20_R2(InternalSpigotConfig config) { + super(config); + } + @Override public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java index 8e951def6..a87c582da 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; import dev.jorel.commandapi.SpigotCommandRegistration; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -28,6 +29,10 @@ public class SpigotNMS_1_20_R3 extends CommandAPISpigot { private NMS_1_20_R3 bukkitNMS; + public SpigotNMS_1_20_R3(InternalSpigotConfig config) { + super(config); + } + @Override public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java index 2257ff598..18b69c268 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; import dev.jorel.commandapi.SpigotCommandRegistration; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -42,6 +43,10 @@ public class SpigotNMS_1_20_R4 extends CommandAPISpigot { } } + public SpigotNMS_1_20_R4(InternalSpigotConfig config) { + super(config); + } + @Override public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java index de1e4d51a..3b8a06c39 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; import dev.jorel.commandapi.SpigotCommandRegistration; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -28,6 +29,10 @@ public class SpigotNMS_1_20_R1 extends CommandAPISpigot { private NMS_1_20_R1 bukkitNMS; + public SpigotNMS_1_20_R1(InternalSpigotConfig config) { + super(config); + } + @Override public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key))); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java index 6b84d1c8e..5a201ae6f 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; import dev.jorel.commandapi.SpigotCommandRegistration; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -42,6 +43,10 @@ public class SpigotNMS_1_21_R2 extends CommandAPISpigot { } } + public SpigotNMS_1_21_R2(InternalSpigotConfig config) { + super(config); + } + @Override public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java index 19a41d0df..b2c936f27 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; import dev.jorel.commandapi.SpigotCommandRegistration; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -42,6 +43,10 @@ public class SpigotNMS_1_21_R3 extends CommandAPISpigot { } } + public SpigotNMS_1_21_R3(InternalSpigotConfig config) { + super(config); + } + @Override public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java index 206450723..6309dfe03 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; import dev.jorel.commandapi.SpigotCommandRegistration; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -42,6 +43,10 @@ public class SpigotNMS_1_21_R4 extends CommandAPISpigot { } } + public SpigotNMS_1_21_R4(InternalSpigotConfig config) { + super(config); + } + @Override public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java index 331ffdc30..632285822 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; import dev.jorel.commandapi.SpigotCommandRegistration; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -41,6 +42,10 @@ public class SpigotNMS_1_21_R5 extends CommandAPISpigot { } } + public SpigotNMS_1_21_R5(InternalSpigotConfig config) { + super(config); + } + @Override public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { return ComponentSerializer.parse(bukkitNMS.toJson(MessageArgument.getMessage(cmdCtx, key))); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java index ba0baccd6..6e14e86f3 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPISpigot; import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; import dev.jorel.commandapi.SpigotCommandRegistration; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -42,6 +43,10 @@ public class SpigotNMS_1_21_R1 extends CommandAPISpigot { } } + public SpigotNMS_1_21_R1(InternalSpigotConfig config) { + super(config); + } + @Override public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { return ComponentSerializer.parse(Component.Serializer.toJson(MessageArgument.getMessage(cmdCtx, key), COMMAND_BUILD_CONTEXT)); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 4e68a7733..a4337958a 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -14,27 +14,32 @@ public abstract class CommandAPIVersionHandler { - static LoadContext getPlatform(InternalConfig config) { - InternalSpigotConfig spigotConfig = (InternalSpigotConfig) config; + static LoadContext getPlatform(CommandAPIConfig config) { + InternalSpigotConfig internalSpigotConfig; + if (config instanceof CommandAPISpigotConfig spigotConfig) { + internalSpigotConfig = new InternalSpigotConfig(spigotConfig); + } else { + throw new IllegalArgumentException("CommandAPISpigot was loaded with non-Spigot config!"); + } try { String version = Bukkit.getBukkitVersion().split("-")[0]; CommandAPIPlatform platform = switch (version) { - case "1.20", "1.20.1" -> new SpigotNMS_1_20_R1(); - case "1.20.2" -> new SpigotNMS_1_20_R2(); - case "1.20.3", "1.20.4" -> new SpigotNMS_1_20_R3(); - case "1.20.5", "1.20.6" -> new SpigotNMS_1_20_R4(); - case "1.21", "1.21.1" -> new SpigotNMS_1_21_R1(); - case "1.21.2", "1.21.3" -> new SpigotNMS_1_21_R2(); - case "1.21.4" -> new SpigotNMS_1_21_R3(); - case "1.21.5" -> new SpigotNMS_1_21_R4(); - case "1.21.6", "1.21.7", "1.21.8" -> new SpigotNMS_1_21_R5(); + case "1.20", "1.20.1" -> new SpigotNMS_1_20_R1(internalSpigotConfig); + case "1.20.2" -> new SpigotNMS_1_20_R2(internalSpigotConfig); + case "1.20.3", "1.20.4" -> new SpigotNMS_1_20_R3(internalSpigotConfig); + case "1.20.5", "1.20.6" -> new SpigotNMS_1_20_R4(internalSpigotConfig); + case "1.21", "1.21.1" -> new SpigotNMS_1_21_R1(internalSpigotConfig); + case "1.21.2", "1.21.3" -> new SpigotNMS_1_21_R2(internalSpigotConfig); + case "1.21.4" -> new SpigotNMS_1_21_R3(internalSpigotConfig); + case "1.21.5" -> new SpigotNMS_1_21_R4(internalSpigotConfig); + case "1.21.6", "1.21.7", "1.21.8" -> new SpigotNMS_1_21_R5(internalSpigotConfig); default -> null; }; if (platform != null) { return new LoadContext(platform); } - if (spigotConfig.fallbackToLatestNMS()) { - return new LoadContext(new SpigotNMS_1_21_R5(), () -> { + if (internalSpigotConfig.fallbackToLatestNMS()) { + return new LoadContext(new SpigotNMS_1_21_R5(internalSpigotConfig), () -> { CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); }); @@ -51,9 +56,4 @@ static LoadContext getPlatform(InternalConfig config) { } } - static InternalConfig getConfig(CommandAPIConfig config) { - // This should never be a casting error since only the Spigot module has this version handler and the CommandAPISpigotConfig - return new InternalSpigotConfig((CommandAPISpigotConfig) config); - } - } diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java index f0ec5cf2a..13caf6255 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVelocity.java @@ -46,7 +46,8 @@ public class CommandAPIVelocity implements CommandAPIPlatform, Comma private CommandManager commandManager; private CommandDispatcher dispatcher; - public CommandAPIVelocity() { + public CommandAPIVelocity(InternalVelocityConfig config) { + CommandAPIVelocity.config = config; CommandAPIVelocity.instance = this; } @@ -67,14 +68,7 @@ public static InternalVelocityConfig getConfiguration() { } @Override - public void onLoad(CommandAPIConfig config) { - if (config instanceof CommandAPIVelocityConfig velocityConfig) { - CommandAPIVelocity.setInternalConfig(new InternalVelocityConfig(velocityConfig)); - } else { - CommandAPI.logError("CommandAPIVelocity was loaded with non-Velocity config!"); - CommandAPI.logError("Attempts to access Velocity-specific config variables will fail!"); - } - + public void onLoad() { commandManager = getConfiguration().getServer().getCommandManager(); // We can't use a SafeVarHandle here because we don't have direct access to the @@ -89,10 +83,6 @@ public void onLoad(CommandAPIConfig config) { } } - private static void setInternalConfig(InternalVelocityConfig internalVelocityConfig) { - CommandAPIVelocity.config = internalVelocityConfig; - } - @Override public void onEnable() { } diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 02776d5d1..c7e18cfcf 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -1,12 +1,13 @@ package dev.jorel.commandapi; public abstract class CommandAPIVersionHandler { - static LoadContext getPlatform(InternalConfig config) { - return new LoadContext(new CommandAPIVelocity()); - } - - static InternalConfig getConfig(CommandAPIConfig config) { - // This should never be a casting error since only the Velocity module has this version handler and the CommandAPIVelocityConfig - return new InternalVelocityConfig((CommandAPIVelocityConfig) config); + static LoadContext getPlatform(CommandAPIConfig config) { + InternalVelocityConfig internalVelocityConfig; + if (config instanceof CommandAPIVelocityConfig velocityConfig) { + internalVelocityConfig = new InternalVelocityConfig(velocityConfig); + } else { + throw new IllegalArgumentException("CommandAPIVelocity was loaded with non-Velocity config!"); + } + return new LoadContext(new CommandAPIVelocity(internalVelocityConfig)); } } From 408ceaec59ef3e41c04e754b28c718b879f0ccbe Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Mon, 18 Aug 2025 21:01:55 +0200 Subject: [PATCH 20/63] Update changelog --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 288d61a9d..d2130d22b 100644 --- a/README.md +++ b/README.md @@ -403,7 +403,7 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025):

  • Removes the commandapi-bukkit-shade module and the commandapi-bukkit-shade-mojang-mapped module
  • Adds the commandapi-paper-core, commandapi-paper-shade and the commandapi-paper-shade-mojang-mapped modules which are made to work on Paper
  • -
  • Adds the commandapi-spigot-core, commandapi-spigot-shade and the commandapi-spigot-shade-mojang-mapped modules which do not include the logic required for Paper
  • +
  • Adds the commandapi-spigot-core, commandapi-spigot-shade and the commandapi-spigot-shade-mojang-mapped modules which are made to work on Spigot
  • Changed the CommandAPIBukkitConfig class into an abstract one in favour of the newly added CommandAPIPaperConfig or CommandAPISpigotConfig classes, depending on the modules you use
  • Moves and adds a few Kotlin DSL modules:
      @@ -414,6 +414,18 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025):
    • Newly added: commandapi-kotlin-spigot
  • +
  • On Paper it is now possible to register commands at bootstrap
  • +
  • Drops support for 1.20.5 and below on Paper
  • +
  • Changes and updates a few arguments: +
      +
    • The FloatRangeArgument has been renamed to DoubleRangeArgument and now returns a DoubleRange
    • +
    • The PlayerArgument and OfflinePlayerArgument have been replaced by the PlayerProfileArgument which returns a List<PlayerProfile>. The PlayerProfile class changes depending on if you are on Paper or on Spigot.
    • +
    • The AsyncOfflinePlayerArgument has been replaced by the AsyncPlayerProfileArgument
    • +
    • The ChatArgument, ChatComponentArgument and ChatColorArgument do no longer have any Adventure prefixes and return different types depending on the platform.
    • +
    • The ChatArgument returns a SignedMessage object on Paper
    • +
    • The BlockStateArgument now returns a BlockState object instead of a BlockData object
    • +
    +
From cce0c74cc366947683255bcdfa687b2fd222adfb Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Mon, 18 Aug 2025 22:14:30 +0200 Subject: [PATCH 21/63] More reviews --- README.md | 2 +- .../java/dev/jorel/commandapi/CommandAPI.java | 20 ++++++++----------- .../dev/jorel/commandapi/CommandAPIPaper.java | 6 +----- .../dev/jorel/commandapi/VersionContext.java | 13 ------------ .../jorel/commandapi/nms/APITypeProvider.java | 4 +++- 5 files changed, 13 insertions(+), 32 deletions(-) delete mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java diff --git a/README.md b/README.md index d2130d22b..4903b2dbb 100644 --- a/README.md +++ b/README.md @@ -419,7 +419,7 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025):
  • Changes and updates a few arguments:
    • The FloatRangeArgument has been renamed to DoubleRangeArgument and now returns a DoubleRange
    • -
    • The PlayerArgument and OfflinePlayerArgument have been replaced by the PlayerProfileArgument which returns a List<PlayerProfile>. The PlayerProfile class changes depending on if you are on Paper or on Spigot.
    • +
    • The PlayerArgument and OfflinePlayerArgument have been replaced by the PlayerProfileArgument which returns a List<PlayerProfile>. The PlayerProfile class changes depending on if you are on Paper or on Spigot. Use the EntitySelectorArgument.OnePlayer if you want a Player object.
    • The AsyncOfflinePlayerArgument has been replaced by the AsyncPlayerProfileArgument
    • The ChatArgument, ChatComponentArgument and ChatColorArgument do no longer have any Adventure prefixes and return different types depending on the platform.
    • The ChatArgument returns a SignedMessage object on Paper
    • diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java index d618f39d9..56983adbd 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandAPI.java @@ -136,19 +136,15 @@ public static void onLoad(CommandAPIConfig config) { } static String getPlatformMessage(Object platform) { - final String platformClassHierarchy; - { - List platformClassHierarchyList = new ArrayList<>(); - Class platformClass = platform.getClass(); - // Goes up through class inheritance only (ending at Object, but we don't want to include that) - // CommandAPIPlatform is an interface, so it is not included - while (platformClass != null && platformClass != Object.class) { - platformClassHierarchyList.add(platformClass.getSimpleName()); - platformClass = platformClass.getSuperclass(); - } - platformClassHierarchy = String.join(" > ", platformClassHierarchyList); + List platformClassHierarchyList = new ArrayList<>(); + Class platformClass = platform.getClass(); + // Goes up through class inheritance only (ending at Object, but we don't want to include that) + // CommandAPIPlatform is an interface, so it is not included + while (platformClass != null && platformClass != Object.class) { + platformClassHierarchyList.add(platformClass.getSimpleName()); + platformClass = platformClass.getSuperclass(); } - return platformClassHierarchy; + return String.join(" > ", platformClassHierarchyList); } /** diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java index ce0fa996d..56e79643e 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -44,7 +44,7 @@ public class CommandAPIPaper extends CommandAPIBukkit { @SuppressWarnings("unchecked") protected CommandAPIPaper(InternalPaperConfig config, BundledNMS nms) { CommandAPIPaper.paper = this; - setInternalConfig(config); + CommandAPIBukkit.config = config; this.lifecycleEventOwner = config.getLifecycleEventOwner(); super.nms = nms; @@ -82,10 +82,6 @@ public LifecycleEventOwner getLifecycleEventOwner() { return lifecycleEventOwner; } - private static void setInternalConfig(InternalPaperConfig config) { - CommandAPIBukkit.config = config; - } - @Override public BundledNMS getNMS() { if (nms != null) { diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java deleted file mode 100644 index 229b8d9cd..000000000 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/VersionContext.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.jorel.commandapi; - -import dev.jorel.commandapi.nms.BundledNMS; - -import java.util.function.Consumer; - -public record VersionContext(BundledNMS nms, Consumer context) { - - public VersionContext(BundledNMS nms) { - this(nms, (logger) -> {}); - } - -} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index b4bbe96d6..7629425ba 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -96,6 +96,7 @@ public class APITypeProvider extends BundledNMS { private final SimpleCommandExceptionType noEntitiesFound; private final SimpleCommandExceptionType noPlayersFound; + private final SimpleCommandExceptionType unknownPlayer; public APITypeProvider(PaperNMS paperNMS) { this.paperNMS = (PaperNMS) paperNMS; @@ -104,6 +105,7 @@ public APITypeProvider(PaperNMS paperNMS) { GsonComponentSerializer gson = GsonComponentSerializer.gson(); this.noEntitiesFound = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.entity")))); this.noPlayersFound = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.player")))); + this.unknownPlayer = new SimpleCommandExceptionType(BukkitTooltip.messageFromAdventureComponent(Component.translatable("argument.player.unknown"))); } private ArgumentType getArgumentType(ThrowingSupplier> paper, Supplier> nms) { @@ -616,7 +618,7 @@ private UUID getIdFromProfile(CommandContext ctx, String nam Collection playerProfiles = ctx.getArgument(name, PlayerProfileListResolver.class).resolve(ctx.getSource()); UUID id = playerProfiles.iterator().next().getId(); if (id == null) { - throw new SimpleCommandExceptionType(BukkitTooltip.messageFromAdventureComponent(Component.translatable("argument.player.unknown"))).create(); + throw unknownPlayer.create(); } return id; } From f40d66926310b8a3dcd5a85dec271f590c55d74c Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Tue, 19 Aug 2025 21:36:45 +0200 Subject: [PATCH 22/63] Hopefully do some fixing --- .../src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java | 2 +- commandapi-testing/commandapi-testing-paper/pom.xml | 2 +- .../src/main/resources/{plugin.yml => paper-plugin.yml} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename commandapi-testing/commandapi-testing-paper/src/main/resources/{plugin.yml => paper-plugin.yml} (100%) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index 7629425ba..604969ddc 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -105,7 +105,7 @@ public APITypeProvider(PaperNMS paperNMS) { GsonComponentSerializer gson = GsonComponentSerializer.gson(); this.noEntitiesFound = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.entity")))); this.noPlayersFound = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.player")))); - this.unknownPlayer = new SimpleCommandExceptionType(BukkitTooltip.messageFromAdventureComponent(Component.translatable("argument.player.unknown"))); + this.unknownPlayer = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.player.unknown")))); } private ArgumentType getArgumentType(ThrowingSupplier> paper, Supplier> nms) { diff --git a/commandapi-testing/commandapi-testing-paper/pom.xml b/commandapi-testing/commandapi-testing-paper/pom.xml index 8b7d66ceb..1e5e32a3c 100644 --- a/commandapi-testing/commandapi-testing-paper/pom.xml +++ b/commandapi-testing/commandapi-testing-paper/pom.xml @@ -37,7 +37,7 @@ src/main/resources - true + true diff --git a/commandapi-testing/commandapi-testing-paper/src/main/resources/plugin.yml b/commandapi-testing/commandapi-testing-paper/src/main/resources/paper-plugin.yml similarity index 100% rename from commandapi-testing/commandapi-testing-paper/src/main/resources/plugin.yml rename to commandapi-testing/commandapi-testing-paper/src/main/resources/paper-plugin.yml From 4594dc5a05c4e943f2c0d42417ee14d195042ee8 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Wed, 20 Aug 2025 23:12:51 +0200 Subject: [PATCH 23/63] Add a changelog entry for the fallback-to-latest-nms config option --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4903b2dbb..a7f9806cd 100644 --- a/README.md +++ b/README.md @@ -399,7 +399,7 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025): ???
        -
      • https://github.com/JorelAli/CommandAPI/pull/517 Splits up the CommandAPI into modules specific for Paper and Spigot: +
      • https://github.com/CommandAPI/CommandAPI/pull/517 Splits up the CommandAPI into modules specific for Paper and Spigot:
        • Removes the commandapi-bukkit-shade module and the commandapi-bukkit-shade-mojang-mapped module
        • Adds the commandapi-paper-core, commandapi-paper-shade and the commandapi-paper-shade-mojang-mapped modules which are made to work on Paper
        • @@ -426,6 +426,13 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025):
        • The BlockStateArgument now returns a BlockState object instead of a BlockData object
      • +
      • Replaces the use-latest-nms-version and be-lenient-for-minor-versions config options with a fallback-to-latest-nms config option: +
          +
        • When loading the CommandAPI and this config option is set to true it will first check if the current version is supported and chooses that
        • +
        • In case the current version isn't a supported version, the CommandAPI will choose the latest nms version available which might or might not work correctly
        • +
        • This config option is set to true by default on Paper and false on Spigot
        • +
        +
    From e6f00dc3cd5cfcb7fa61b3db15849d9c9d1ef763 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Fri, 22 Aug 2025 22:18:48 +0200 Subject: [PATCH 24/63] Fix paper plugin not working on Paper --- .../commandapi-paper-plugin/pom.xml | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml index cae1a1b79..7c630b37a 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml @@ -27,20 +27,8 @@ dev.jorel - commandapi-paper-core + commandapi-paper-shade ${project.version} - compile - - - dev.jorel - commandapi-paper-vh - ${project.version} - - - dev.jorel - commandapi-paper-nms-dependency - ${project.version} - pom dev.jorel @@ -73,16 +61,6 @@ shade - - - - dev.jorel:commandapi-core - - dev/jorel/commandapi/CommandAPIVersionHandler** - - - LICENSE @@ -108,6 +86,13 @@ + + + + mojang + + + From 4929c14a6390e6943b29bd6694cb9f37ff412b2d Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Fri, 22 Aug 2025 22:53:18 +0200 Subject: [PATCH 25/63] Fix spigot plugin not working on latest Spigot --- .../commandapi-spigot-core/pom.xml | 1 + .../commandapi-spigot-nms-dependency/pom.xml | 5 +++++ .../commandapi-spigot-plugin/pom.xml | 14 +------------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml index 269262351..474a392f9 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml @@ -50,6 +50,7 @@ com.mojang brigadier 1.0.18 + provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml index c2b6a6fc2..10c3524d3 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml @@ -68,6 +68,11 @@ + + dev.jorel + commandapi-bukkit-1.21.6 + ${project.version} + dev.jorel commandapi-bukkit-1.21.5 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml index 49866893d..9eac05ad4 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml @@ -27,20 +27,8 @@ dev.jorel - commandapi-spigot-core + commandapi-spigot-shade ${project.version} - compile - - - dev.jorel - commandapi-spigot-vh - ${project.version} - - - dev.jorel - commandapi-spigot-nms-dependency - ${project.version} - pom dev.jorel From 63bd21025fb0201ef9739b2e191792efab9f9993 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sun, 31 Aug 2025 18:36:21 +0200 Subject: [PATCH 26/63] Update APITypeProvider to use newly added API methods --- .../java/dev/jorel/commandapi/nms/NMS.java | 2 +- .../dev/jorel/commandapi/nms/NMS_Common.java | 2 +- .../commandapi-paper-api/pom.xml | 2 +- .../jorel/commandapi/nms/APITypeProvider.java | 36 +++++++++++++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java index 9e694bca6..eb1b547dc 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java @@ -300,7 +300,7 @@ public interface NMS { Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException; - float getAngle(CommandContext cmdCtx, String key); + float getAngle(CommandContext cmdCtx, String key) throws CommandSyntaxException; EnumSet getAxis(CommandContext cmdCtx, String key); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java index 1d3f8f650..d7686515f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java @@ -288,7 +288,7 @@ public final void createDispatcherFile(File file, CommandDispatcher cmdCtx, String key) { + public final float getAngle(CommandContext cmdCtx, String key) throws CommandSyntaxException { return AngleArgument.getAngle(cmdCtx, key); } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml index c4c7ea678..9ad75bbf2 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml @@ -13,7 +13,7 @@ Paper API support - 1.21.6-R0.1-SNAPSHOT + 1.21.8-R0.1-SNAPSHOT diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index 604969ddc..4b87c6a97 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -30,11 +30,18 @@ import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.command.brigadier.argument.AxisSet; import io.papermc.paper.command.brigadier.argument.SignedMessageResolver; +import io.papermc.paper.command.brigadier.argument.position.ColumnBlockPosition; +import io.papermc.paper.command.brigadier.argument.position.ColumnFinePosition; +import io.papermc.paper.command.brigadier.argument.predicate.BlockInWorldPredicate; import io.papermc.paper.command.brigadier.argument.predicate.ItemStackPredicate; import io.papermc.paper.command.brigadier.argument.range.DoubleRangeProvider; import io.papermc.paper.command.brigadier.argument.range.IntegerRangeProvider; +import io.papermc.paper.command.brigadier.argument.resolvers.AngleResolver; import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver; +import io.papermc.paper.command.brigadier.argument.resolvers.ColumnBlockPositionResolver; +import io.papermc.paper.command.brigadier.argument.resolvers.ColumnFinePositionResolver; import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver; import io.papermc.paper.command.brigadier.argument.resolvers.PlayerProfileListResolver; import io.papermc.paper.command.brigadier.argument.resolvers.RotationResolver; @@ -168,6 +175,7 @@ public ArgumentType _ArgumentAdvancement() { @Override public ArgumentType _ArgumentAngle() { return getArgumentType( + () -> ArgumentTypes.angle(), // Since 1.21.8 () -> paperNMS.bukkitNMS()._ArgumentAngle() ); } @@ -175,6 +183,7 @@ public ArgumentType _ArgumentAngle() { @Override public ArgumentType _ArgumentAxis() { return getArgumentType( + () -> ArgumentTypes.axes(), // Since 1.21.8 () -> paperNMS.bukkitNMS()._ArgumentAxis() ); } @@ -182,6 +191,7 @@ public ArgumentType _ArgumentAxis() { @Override public ArgumentType _ArgumentBlockPredicate() { return getArgumentType( + () -> ArgumentTypes.blockInWorldPredicate(), // Since 1.21.8 () -> paperNMS.bukkitNMS()._ArgumentBlockPredicate() ); } @@ -291,6 +301,7 @@ public ArgumentType _ArgumentPosition() { @Override public ArgumentType _ArgumentPosition2D() { return getArgumentType( + () -> ArgumentTypes.columnBlockPosition(), // Since 1.21.8 () -> paperNMS.bukkitNMS()._ArgumentPosition2D() ); } @@ -366,6 +377,7 @@ public ArgumentType _ArgumentUUID() { @Override public ArgumentType _ArgumentVec2(boolean centerPosition) { return getArgumentType( + () -> ArgumentTypes.columnFinePosition(centerPosition), // Since 1.21.8 () -> paperNMS.bukkitNMS()._ArgumentVec2(centerPosition) ); } @@ -416,8 +428,12 @@ public Advancement getAdvancement(CommandContext cmdCtx, Str } @Override - public float getAngle(CommandContext cmdCtx, String key) { - return parse(cmdCtx, key, + public float getAngle(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return parseT(cmdCtx, key, + (ctx, name) -> { + AngleResolver resolver = ctx.getArgument(name, AngleResolver.class); + return resolver.resolve(ctx.getSource()); + }, (ctx, name) -> paperNMS.bukkitNMS().getAngle(ctx, name) ); } @@ -425,6 +441,10 @@ public float getAngle(CommandContext cmdCtx, String key) { @Override public EnumSet getAxis(CommandContext cmdCtx, String key) { return parse(cmdCtx, key, + (ctx, name) -> { + AxisSet axisSet = ctx.getArgument(name, AxisSet.class); + return EnumSet.copyOf(axisSet); + }, (ctx, name) -> paperNMS.bukkitNMS().getAxis(ctx, name) ); } @@ -440,6 +460,10 @@ public RegistryParser getBiome(CommandContext cmdCtx, @Override public Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, + (ctx, name) -> { + BlockInWorldPredicate predicate = ctx.getArgument(key, BlockInWorldPredicate.class); + return block -> predicate.testBlock(block).asBoolean(); + }, (ctx, name) -> paperNMS.bukkitNMS().getBlockPredicate(ctx, name) ); } @@ -532,6 +556,10 @@ public Predicate getItemStackPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, + (ctx, name) -> { + ColumnBlockPosition resolver = ctx.getArgument(key, ColumnBlockPositionResolver.class).resolve(ctx.getSource()); + return new Location2D(getWorldForCSS(ctx.getSource()), resolver.blockX(), resolver.blockZ()); + }, (ctx, name) -> paperNMS.bukkitNMS().getLocation2DBlock(ctx, name) ); } @@ -539,6 +567,10 @@ public Location2D getLocation2DBlock(CommandContext cmdCtx, @Override public Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { return parseT(cmdCtx, key, + (ctx, name) -> { + ColumnFinePosition columnFinePosition = ctx.getArgument(key, ColumnFinePositionResolver.class).resolve(ctx.getSource()); + return new Location2D(getWorldForCSS(ctx.getSource()), columnFinePosition.x(), columnFinePosition.z()); + }, (ctx, name) -> paperNMS.bukkitNMS().getLocation2DPrecise(ctx, name) ); } From 731022bf367ef619cce721512d27ac94058b99f5 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sun, 31 Aug 2025 18:54:49 +0200 Subject: [PATCH 27/63] Fix folia detection The RegionizedServerInitEvent was added to Paper so our check incorrectly detected a Paper server as folia --- .../src/main/java/dev/jorel/commandapi/CommandAPIPaper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java index 56e79643e..72d41327c 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -169,7 +169,7 @@ private void checkPaperDependencies() { isFoliaPresent = false; try { - Class.forName("io.papermc.paper.threadedregions.RegionizedServerInitEvent"); + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); isFoliaPresent = true; CommandAPI.logNormal("Hooked into Folia for folia-specific API implementations"); CommandAPI.logNormal("Folia support is still in development. Please report any issues to the CommandAPI developers!"); From a998e1e7d5a497c1a8b966109dcfb6cdea7187a1 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Mon, 1 Sep 2025 21:43:00 +0200 Subject: [PATCH 28/63] Handle registrations and unregistrations at runtime correctly --- .../commandapi/PaperCommandRegistration.java | 48 ++++++++++++++--- .../jorel/commandapi/testing/TestPlugin.java | 51 ++++++++++++++++++- 2 files changed, 89 insertions(+), 10 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java index 3d7014984..67c1d8e69 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java @@ -42,6 +42,8 @@ public class PaperCommandRegistration extends CommandRegistrationStrateg private final CommandDispatcher bootstrapDispatcher = new CommandDispatcher<>(); private final CommandDispatcher pluginDispatcher = new CommandDispatcher<>(); + private final List unregisterInformationList = new ArrayList<>(); + public PaperCommandRegistration(Supplier> getBrigadierDispatcher, Runnable reloadHelpTopics, Predicate> isBukkitCommand) { this.getBrigadierDispatcher = getBrigadierDispatcher; this.reloadHelpTopics = reloadHelpTopics; @@ -84,19 +86,20 @@ public LiteralCommandNode registerCommandNode(LiteralArgumentBuilder) built); } + if (!CommandAPI.canRegister()) { + // Since we register commands into our dispatchers, we need to run the lifecycle events again + // This can happen when using /minecraft:reload or this method + Bukkit.reloadData(); + } return built; } @Override public void unregister(String commandName, boolean unregisterNamespaces, boolean unregisterBukkit) { - // Remove nodes from the dispatcher - removeBrigadierCommands(getBrigadierDispatcher().getRoot(), commandName, unregisterNamespaces, - // If we are unregistering a Bukkit command, ONLY unregister BukkitCommandNodes - // If we are unregistering a Vanilla command, DO NOT unregister BukkitCommandNodes - c -> !unregisterBukkit ^ isBukkitCommand.test(c)); - - // Update the dispatcher file - CommandAPIHandler.getInstance().writeDispatcherToFile(); + unregisterInformationList.add(new UnregisterInformation(commandName, unregisterNamespaces, unregisterBukkit)); + if (!CommandAPI.canRegister()) { + Bukkit.reloadData(); + } } @Override @@ -118,6 +121,33 @@ void registerLifecycleEvent() { JavaPlugin plugin = (JavaPlugin) CommandAPIPaper.getPaper().getLifecycleEventOwner(); lifecycleEventRegistered[1] = true; registerLifecycleEvent(plugin.getLifecycleManager(), pluginDispatcher); + + plugin.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS.newHandler(event -> { + if (!unregisterInformationList.isEmpty()) { + for (UnregisterInformation unregisterInformation : unregisterInformationList) { + // Remove nodes from the dispatcher + removeBrigadierCommands(getBrigadierDispatcher().getRoot(), unregisterInformation.commandName(), unregisterInformation.unregisterNamespaces(), + // If we are unregistering a Bukkit command, ONLY unregister BukkitCommandNodes + // If we are unregistering a Vanilla command, DO NOT unregister BukkitCommandNodes + c -> !unregisterInformation.unregisterBukkit() ^ isBukkitCommand.test(c)); + + // Remove nodes from our dispatchers + removeBrigadierCommands((RootCommandNode) bootstrapDispatcher.getRoot(), + unregisterInformation.commandName(), + unregisterInformation.unregisterNamespaces(), + c -> !unregisterInformation.unregisterBukkit() ^ isBukkitCommand.test(c) + ); + removeBrigadierCommands((RootCommandNode) pluginDispatcher.getRoot(), + unregisterInformation.commandName(), + unregisterInformation.unregisterNamespaces(), + c -> !unregisterInformation.unregisterBukkit() ^ isBukkitCommand.test(c) + ); + } + + // Update the dispatcher file + CommandAPIHandler.getInstance().writeDispatcherToFile(); + } + }).priority(1)); } } @@ -150,4 +180,6 @@ private String getDescription(String commandName) { return ""; } + private record UnregisterInformation(String commandName, boolean unregisterNamespaces, boolean unregisterBukkit) {} + } diff --git a/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java index 0afe56b4f..e2ee0b781 100644 --- a/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java +++ b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java @@ -1,5 +1,6 @@ package dev.jorel.commandapi.testing; +import com.mojang.brigadier.tree.CommandNode; import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandAPIPaper; @@ -7,6 +8,7 @@ import dev.jorel.commandapi.arguments.AdvancementArgument; import dev.jorel.commandapi.arguments.AngleArgument; import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.ArgumentSuggestions; import dev.jorel.commandapi.arguments.AxisArgument; import dev.jorel.commandapi.arguments.BiomeArgument; import dev.jorel.commandapi.arguments.BlockPredicateArgument; @@ -14,10 +16,10 @@ import dev.jorel.commandapi.arguments.ChatArgument; import dev.jorel.commandapi.arguments.ChatColorArgument; import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.DoubleRangeArgument; import dev.jorel.commandapi.arguments.EnchantmentArgument; import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.EntityTypeArgument; -import dev.jorel.commandapi.arguments.DoubleRangeArgument; import dev.jorel.commandapi.arguments.FunctionArgument; import dev.jorel.commandapi.arguments.IntegerRangeArgument; import dev.jorel.commandapi.arguments.ItemStackArgument; @@ -38,6 +40,7 @@ import dev.jorel.commandapi.arguments.ScoreHolderArgument; import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.StringArgument; import dev.jorel.commandapi.arguments.TeamArgument; import dev.jorel.commandapi.arguments.TimeArgument; import dev.jorel.commandapi.arguments.UUIDArgument; @@ -50,7 +53,6 @@ import dev.jorel.commandapi.wrappers.ParticleData; import dev.jorel.commandapi.wrappers.Rotation; import dev.jorel.commandapi.wrappers.ScoreboardSlot; -import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; import net.kyori.adventure.chat.ChatType; import net.kyori.adventure.chat.SignedMessage; import net.kyori.adventure.text.Component; @@ -75,6 +77,7 @@ import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; @@ -135,6 +138,35 @@ public void onLoad() { register(new TimeArgument("timetype"), int.class, Object::toString); register(new UUIDArgument("uuidtype"), UUID.class, UUID::toString); register(new WorldArgument("worldtype"), World.class, World::getName); + + // Unregistration/Registration test commands + registerExecutor(new StringArgument("register"), String.class, (name, sender) -> { + new CommandAPICommand(name) + .executes(info -> { + info.sender().sendMessage(Component.text().content("Command /" + name + " was registered and executed successfully!")); + }) + .register(); + }); + registerExecutor(new StringArgument("unregister") + .replaceSuggestions(ArgumentSuggestions.strings(info -> CommandAPIPaper.getPaper() + .getBrigadierDispatcher() + .getRoot() + .getChildren() + .stream() + .map(CommandNode::getName) + .filter(name -> !fixedCommandNames.contains(name)) + .toArray(String[]::new) + )), + String.class, + (name, sender) -> { + if (fixedCommandNames.contains(name)) { + sender.sendMessage(Component.text("Sorry, the command /" + name + " cannot be unregistered!", NamedTextColor.RED)); + return; + } + CommandAPI.unregister(name, true); + sender.sendMessage(Component.text("Command " + name + " was unregistered successfully!", NamedTextColor.GREEN)); + } + ); } @Override @@ -142,7 +174,10 @@ public void onEnable() { CommandAPI.onEnable(); } + private final List fixedCommandNames = new ArrayList<>(); + private void register(Argument argument, Class castType, Function toString) { + fixedCommandNames.add(argument.getNodeName()); new CommandAPICommand(argument.getNodeName()) .withArguments(argument) .executes(info -> { @@ -152,6 +187,7 @@ private void register(Argument argument, Class castType, Function void register(Argument argument, Function toString, Class castType) { + fixedCommandNames.add(argument.getNodeName()); new CommandAPICommand(argument.getNodeName()) .withArguments(argument) .executes(info -> { @@ -161,6 +197,7 @@ private void register(Argument argument, Function toString, } private void register(Argument argument, Class castType, BiConsumer action) { + fixedCommandNames.add(argument.getNodeName()); new CommandAPICommand(argument.getNodeName()) .withArguments(argument) .executes(info -> { @@ -170,4 +207,14 @@ private void register(Argument argument, Class castType, BiConsumer void registerExecutor(Argument argument, Class castType, BiConsumer executor) { + fixedCommandNames.add(argument.getNodeName()); + new CommandAPICommand(argument.getNodeName()) + .withArguments(argument) + .executes(info -> { + executor.accept(info.args().getByClass(argument.getNodeName(), castType), info.sender()); + }) + .register(); + } + } From 90f50db4c3f9e19714ed537c36de47eaec901df0 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Mon, 15 Sep 2025 15:04:49 +0200 Subject: [PATCH 29/63] Remove left over documentation code modules --- .../pom.xml | 112 ---------------- .../commandapi/examples/java/Examples.java | 119 ----------------- .../commandapi/examples/kotlin/Examples.kt | 112 ---------------- .../examples/kotlin/ExamplesKotlinDSL.kt | 80 ------------ .../pom.xml | 102 --------------- .../commandapi/examples/java/Examples.java | 120 ------------------ .../commandapi/examples/kotlin/Examples.kt | 116 ----------------- .../examples/kotlin/ExamplesKotlinDSL.kt | 62 --------- 8 files changed, 823 deletions(-) delete mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml delete mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java delete mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt delete mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt delete mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml deleted file mode 100644 index a938c4fce..000000000 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/pom.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - 4.0.0 - - dev.jorel - commandapi-paper - 10.2.0-SNAPSHOT - - - commandapi-paper-documentation-code - Paper documentation code - - - - minecraft-libraries - https://libraries.minecraft.net - - - papermc - https://repo.papermc.io/repository/maven-public/ - - - codemc-repo - https://repo.codemc.org/repository/maven-public/ - default - - - - - - - com.mojang - brigadier - 1.0.17 - provided - - - com.mojang - authlib - 3.3.39 - provided - - - - - net.kyori - adventure-platform-bukkit - 4.2.0 - test - - - io.papermc.paper - paper-api - ${paper.version} - provided - - - - - dev.jorel - commandapi-paper-core - ${project.version} - - - dev.jorel - commandapi-kotlin-paper - ${project.version} - - - - - de.tr7zw - item-nbt-api - 2.11.1 - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - test-compile - - test-compile - - - - ${project.basedir}/src/main/kotlin/ - - - - - - 16 - - - - - - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java deleted file mode 100644 index 99d345252..000000000 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java +++ /dev/null @@ -1,119 +0,0 @@ -package dev.jorel.commandapi.examples.java; - -import de.tr7zw.changeme.nbtapi.NBTContainer; -import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.CommandAPIPaper; -import dev.jorel.commandapi.CommandAPIPaperConfig; -import dev.jorel.commandapi.arguments.ChatArgument; -import dev.jorel.commandapi.arguments.ChatColorArgument; -import dev.jorel.commandapi.arguments.ChatComponentArgument; -import dev.jorel.commandapi.arguments.PlayerProfileArgument; -import dev.jorel.commandapi.arguments.StringArgument; -import dev.jorel.commandapi.arguments.TextArgument; -import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; -import net.kyori.adventure.inventory.Book; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.Bukkit; -import org.bukkit.Server; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public class Examples { - -void argument_chatAdventure() { -/* ANCHOR: argumentChatAdventure1 */ -new CommandAPICommand("namecolor") - .withArguments(new ChatColorArgument("chatcolor")) - .executesPlayer((player, args) -> { - NamedTextColor color = (NamedTextColor) args.get("chatcolor"); - player.displayName(Component.text().color(color).append(Component.text(player.getName())).build()); - }) - .register(); -/* ANCHOR_END: argumentChatAdventure1 */ - -/* ANCHOR: argumentChatAdventure2 */ -new CommandAPICommand("showbook") - .withArguments(new PlayerProfileArgument("target")) - .withArguments(new TextArgument("title")) - .withArguments(new StringArgument("author")) - .withArguments(new ChatComponentArgument("contents")) - .executes((sender, args) -> { - Player target = (Player) args.get("target"); - String title = (String) args.get("title"); - String author = (String) args.get("author"); - Component content = (Component) args.get("contents"); - - // Create a book and show it to the user (Requires Paper) - Book mybook = Book.book(Component.text(title), Component.text(author), content); - target.openBook(mybook); - }) - .register(); -/* ANCHOR_END: argumentChatAdventure2 */ - -/* ANCHOR: argumentChatAdventure3 */ -new CommandAPICommand("pbroadcast") - .withArguments(new ChatArgument("message")) - .executes((sender, args) -> { - Component message = (Component) args.get("message"); - - // Broadcast the message to everyone with broadcast permissions. - Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS); - Bukkit.getServer().broadcast(message); - }) - .register(); -/* ANCHOR_END: argumentChatAdventure3 */ -} - -class argument_nbt extends JavaPlugin { -/* ANCHOR: argumentNBT1 */ -@Override -public void onLoad() { - CommandAPI.onLoad(new CommandAPIPaperConfig<>(this.getPluginMeta(), this) - .initializeNBTAPI(NBTContainer.class, NBTContainer::new) - ); -} -/* ANCHOR_END: argumentNBT1 */ -} - -class setupShading { -JavaPlugin plugin = new JavaPlugin() {}; - -{ -/* ANCHOR: setupShading1 */ -CommandAPI.onLoad(new CommandAPIPaperConfig(plugin.getPluginMeta(), (LifecycleEventOwner) this).silentLogs(true)); -/* ANCHOR_END: setupShading1 */ -} - -/* ANCHOR: setupShading2 */ -class MyPlugin extends JavaPlugin { - - @Override - public void onLoad() { - CommandAPI.onLoad(new CommandAPIPaperConfig<>(this.getPluginMeta(), this).verboseOutput(true)); // Load with verbose output - - new CommandAPICommand("ping") - .executes((sender, args) -> { - sender.sendMessage("pong!"); - }) - .register(); - } - - @Override - public void onEnable() { - CommandAPIPaper.onEnable(this); - - // Register commands, listeners etc. - } - - @Override - public void onDisable() { - CommandAPI.onDisable(); - } - -} -/* ANCHOR_END: setupShading2 */ -} - -} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt deleted file mode 100644 index 90cf516a4..000000000 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt +++ /dev/null @@ -1,112 +0,0 @@ -package dev.jorel.commandapi.examples.kotlin - -import de.tr7zw.changeme.nbtapi.NBTContainer -import dev.jorel.commandapi.CommandAPI -import dev.jorel.commandapi.CommandAPICommand -import dev.jorel.commandapi.CommandAPIPaperConfig -import dev.jorel.commandapi.arguments.* -import dev.jorel.commandapi.executors.CommandExecutor -import dev.jorel.commandapi.executors.PlayerCommandExecutor -import net.kyori.adventure.inventory.Book -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.format.NamedTextColor -import org.bukkit.Bukkit -import org.bukkit.Server -import org.bukkit.entity.Player -import org.bukkit.plugin.java.JavaPlugin - -class Examples { - -fun argument_chatAdventure() { -/* ANCHOR: argumentChatAdventure1 */ -CommandAPICommand("namecolor") - .withArguments(ChatColorArgument("chatcolor")) - .executesPlayer(PlayerCommandExecutor { player, args -> - val color = args["chatcolor"] as NamedTextColor - player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) - }) - .register() -/* ANCHOR_END: argumentChatAdventure1 */ - -/* ANCHOR: argumentChatAdventure2 */ -CommandAPICommand("showbook") - .withArguments(PlayerProfileArgument("target")) - .withArguments(TextArgument("title")) - .withArguments(StringArgument("author")) - .withArguments(ChatComponentArgument("contents")) - .executes(CommandExecutor { _, args -> - val target = args["target"] as Player - val title = args["title"] as String - val author = args["author"] as String - val content = args["contents"] as Component - - // Create a book and show it to the user (Requires Paper) - val mybook = Book.book(Component.text(title), Component.text(author), content) - target.openBook(mybook) - }) - .register() -/* ANCHOR_END: argumentChatAdventure2 */ - -/* ANCHOR: argumentChatAdventure3 */ -CommandAPICommand("pbroadcast") - .withArguments(ChatArgument("message")) - .executes(CommandExecutor { _, args -> - val message = args["message"] as Component - - // Broadcast the message to everyone with broadcast permissions. - Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) - Bukkit.getServer().broadcast(message) - }) - .register() -/* ANCHOR_END: argumentChatAdventure3 */ -} - -class argument_nbt : JavaPlugin() { - -/* ANCHOR: argumentNBT1 */ -override fun onLoad() { - CommandAPI.onLoad(CommandAPIPaperConfig(this.pluginMeta, this) - .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) - ) -} -/* ANCHOR_END: argumentNBT1 */ - -} - -class setupShading { -val plugin: JavaPlugin = object : JavaPlugin() {} - -fun setupShading1() { -/* ANCHOR: setupShading1 */ -CommandAPI.onLoad(CommandAPIPaperConfig<>(plugin.pluginMeta, this).silentLogs(true)) -/* ANCHOR_END: setupShading1 */ -} - -/* ANCHOR: setupShading2 */ -class MyPlugin : JavaPlugin() { - - override fun onLoad() { - CommandAPI.onLoad(CommandAPIPaperConfig(this.pluginMeta, this).verboseOutput(true)) // Load with verbose output - - CommandAPICommand("ping") - .executes(CommandExecutor { sender, _ -> - sender.sendMessage("pong!") - }) - .register() - } - - override fun onEnable() { - CommandAPI.onEnable(this) - - // Register commands, listeners etc. - } - - override fun onDisable() { - CommandAPI.onDisable() - } - -} -/* ANCHOR_END: setupShading2 */ -} - -} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt b/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt deleted file mode 100644 index 08a72c561..000000000 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt +++ /dev/null @@ -1,80 +0,0 @@ -package dev.jorel.commandapi.examples.kotlin - -import de.tr7zw.changeme.nbtapi.NBTContainer -import dev.jorel.commandapi.kotlindsl.anyExecutor -import dev.jorel.commandapi.kotlindsl.chatArgument -import dev.jorel.commandapi.kotlindsl.chatColorArgument -import dev.jorel.commandapi.kotlindsl.chatComponentArgument -import dev.jorel.commandapi.kotlindsl.commandAPICommand -import dev.jorel.commandapi.kotlindsl.nbtCompoundArgument -import dev.jorel.commandapi.kotlindsl.playerArgument -import dev.jorel.commandapi.kotlindsl.playerExecutor -import dev.jorel.commandapi.kotlindsl.stringArgument -import dev.jorel.commandapi.kotlindsl.textArgument -import net.kyori.adventure.inventory.Book -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.format.NamedTextColor -import org.bukkit.Bukkit -import org.bukkit.Server -import org.bukkit.entity.Player - -class ExamplesKotlinDSL { - -fun argument_chatAdventure() { -/* ANCHOR: argumentChatAdventure1 */ -commandAPICommand("namecolor") { - chatColorArgument("chatcolor") - playerExecutor { player, args -> - val color = args["chatcolor"] as NamedTextColor - player.displayName(Component.text().color(color).append(Component.text(player.name)).build()) - } -} -/* ANCHOR_END: argumentChatAdventure1 */ - -/* ANCHOR: argumentChatAdventure2 */ -commandAPICommand("showbook") { - playerArgument("target") - textArgument("title") - stringArgument("author") - chatComponentArgument("contents") - anyExecutor { _, args -> - val target = args["target"] as Player - val title = args["title"] as String - val author = args["author"] as String - val content = args["contents"] as Component - - // Create a book and show it to the user (Requires Paper) - val mybook = Book.book(Component.text(title), Component.text(author), content) - target.openBook(mybook) - } -} -/* ANCHOR_END: argumentChatAdventure2 */ - -/* ANCHOR: argumentChatAdventure3 */ -commandAPICommand("pbroadcast") { - chatArgument("message") - anyExecutor { _, args -> - val message = args["message"] as Component - - // Broadcast the message to everyone with broadcast permissions. - Bukkit.getServer().broadcast(message, Server.BROADCAST_CHANNEL_USERS) - Bukkit.getServer().broadcast(message) - } -} -/* ANCHOR_END: argumentChatAdventure3 */ -} - -fun argument_nbt() { -/* ANCHOR: argumentNBT1 */ -commandAPICommand("award") { - nbtCompoundArgument("nbt") - anyExecutor { _, args -> - val nbt = args["nbt"] as NBTContainer - - // Do something with "nbt" here... - } -} -/* ANCHOR_END: argumentNBT1 */ -} - -} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml deleted file mode 100644 index 51e576d68..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/pom.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - 4.0.0 - - dev.jorel - commandapi-spigot - 10.2.0-SNAPSHOT - - - commandapi-spigot-documentation-code - Spigot documentation code - - - - minecraft-libraries - https://libraries.minecraft.net - - - codemc-repo - https://repo.codemc.org/repository/maven-public/ - default - - - - - - - com.mojang - brigadier - 1.0.17 - provided - - - com.mojang - authlib - 3.3.39 - provided - - - - - org.spigotmc - spigot-api - ${paper.version} - provided - - - - - dev.jorel - commandapi-spigot-core - ${project.version} - - - dev.jorel - commandapi-kotlin-spigot - ${project.version} - - - - - de.tr7zw - item-nbt-api - 2.11.1 - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - - - - - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - - - test-compile - - test-compile - - - - ${project.basedir}/src/main/kotlin/ - - - - - - 16 - - - - - - \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java deleted file mode 100644 index 460d73d23..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java +++ /dev/null @@ -1,120 +0,0 @@ -package dev.jorel.commandapi.examples.java; - -import de.tr7zw.changeme.nbtapi.NBTContainer; -import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.CommandAPISpigot; -import dev.jorel.commandapi.CommandAPISpigotConfig; -import dev.jorel.commandapi.arguments.ChatArgument; -import dev.jorel.commandapi.arguments.ChatColorArgument; -import dev.jorel.commandapi.arguments.ChatComponentArgument; -import dev.jorel.commandapi.arguments.PlayerProfileArgument; -import net.md_5.bungee.api.chat.BaseComponent; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.plugin.java.JavaPlugin; - -public class Examples { - -void argument_chatSpigot() { -/* ANCHOR: argumentChatSpigot1 */ -new CommandAPICommand("namecolor") - .withArguments(new ChatColorArgument("chatcolor")) - .executesPlayer((player, args) -> { - ChatColor color = (ChatColor) args.get("chatcolor"); - player.setDisplayName(color + player.getName()); - }) - .register(); -/* ANCHOR_END: argumentChatSpigot1 */ - -/* ANCHOR: argumentChatSpigot2 */ -new CommandAPICommand("makebook") - .withArguments(new PlayerProfileArgument("player")) - .withArguments(new ChatComponentArgument("contents")) - .executes((sender, args) -> { - Player player = (Player) args.get("player"); - BaseComponent[] arr = (BaseComponent[]) args.get("contents"); - - // Create book - ItemStack is = new ItemStack(Material.WRITTEN_BOOK); - BookMeta meta = (BookMeta) is.getItemMeta(); - meta.setTitle("Custom Book"); - meta.setAuthor(player.getName()); - meta.spigot().setPages(arr); - is.setItemMeta(meta); - - // Give player the book - player.getInventory().addItem(is); - }) - .register(); -/* ANCHOR_END: argumentChatSpigot2 */ - -/* ANCHOR: argumentChatSpigot3 */ -new CommandAPICommand("pbroadcast") - .withArguments(new ChatArgument("message")) - .executes((sender, args) -> { - BaseComponent[] message = (BaseComponent[]) args.get("message"); - - // Broadcast the message to everyone on the server - Bukkit.getServer().spigot().broadcast(message); - }) - .register(); -/* ANCHOR_END: argumentChatSpigot3 */ -} - -class argument_nbt extends JavaPlugin { -/* ANCHOR: argumentNBT1 */ -@Override -public void onLoad() { - CommandAPI.onLoad(new CommandAPISpigotConfig(this) - .initializeNBTAPI(NBTContainer.class, NBTContainer::new) - ); -} -/* ANCHOR_END: argumentNBT1 */ -} - -class setupShading { -JavaPlugin plugin = new JavaPlugin() { -}; - -{ -/* ANCHOR: setupShading1 */ -CommandAPI.onLoad(new CommandAPISpigotConfig(plugin).silentLogs(true)); -/* ANCHOR_END: setupShading1 */ -} - -/* ANCHOR: setupShading2 */ -class MyPlugin extends JavaPlugin { - - @Override - public void onLoad() { - CommandAPI.onLoad(new CommandAPISpigotConfig(this).verboseOutput(true)); // Load with verbose output - - new CommandAPICommand("ping") - .executes((sender, args) -> { - sender.sendMessage("pong!"); - }) - .register(); - } - - @Override - public void onEnable() { - CommandAPISpigot.onEnable(); - - // Register commands, listeners etc. - } - - @Override - public void onDisable() { - CommandAPI.onDisable(); - } - -} -/* ANCHOR_END: setupShading2 */ -} - -} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt deleted file mode 100644 index 99dee753f..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt +++ /dev/null @@ -1,116 +0,0 @@ -package dev.jorel.commandapi.examples.kotlin - -import de.tr7zw.changeme.nbtapi.NBTContainer -import dev.jorel.commandapi.CommandAPI -import dev.jorel.commandapi.CommandAPICommand -import dev.jorel.commandapi.CommandAPISpigotConfig -import dev.jorel.commandapi.arguments.* -import dev.jorel.commandapi.executors.CommandArguments -import dev.jorel.commandapi.executors.CommandExecutor -import dev.jorel.commandapi.executors.PlayerCommandExecutor -import net.md_5.bungee.api.chat.BaseComponent -import org.bukkit.Bukkit -import org.bukkit.ChatColor -import org.bukkit.Material -import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import org.bukkit.inventory.ItemStack -import org.bukkit.inventory.meta.BookMeta -import org.bukkit.plugin.java.JavaPlugin - -class Examples { - -fun argument_chatSpigot() { -/* ANCHOR: argumentChatSpigot1 */ -CommandAPICommand("namecolor") - .withArguments(ChatColorArgument("chatColor")) - .executesPlayer(PlayerCommandExecutor { player: Player, args: CommandArguments -> - val color = args["chatColor"] as ChatColor - player.setDisplayName("$color${player.name}") - }) - .register() -/* ANCHOR_END: argumentChatSpigot1 */ - -/* ANCHOR: argumentChatSpigot2 */ -CommandAPICommand("makebook") - .withArguments(PlayerProfileArgument("player")) - .withArguments(ChatComponentArgument("contents")) - .executes(CommandExecutor { _, args -> - val player = args["player"] as Player - val arr = args["contents"] as Array - - // Create book - val item = ItemStack(Material.WRITTEN_BOOK) - val meta = item.itemMeta as BookMeta - meta.title = "Custom Book" - meta.author = player.name - meta.spigot().setPages(arr) - item.itemMeta = meta - - // Give player the book - player.inventory.addItem(item) - }) - .register() -/* ANCHOR_END: argumentChatSpigot2 */ - -/* ANCHOR: argumentChatSpigot3 */ -CommandAPICommand("pbroadcast") - .withArguments(ChatArgument("message")) - .executes(CommandExecutor { _, args -> - val message = args["message"] as Array - - // Broadcast the message to everyone on the server - Bukkit.getServer().spigot().broadcast(*message) - }) - .register() -/* ANCHOR_END: argumentChatSpigot3 */ -} - -class argument_nbt : JavaPlugin() { - -/* ANCHOR: argumentNBT1 */ -override fun onLoad() { - CommandAPI.onLoad(CommandAPISpigotConfig(this) - .initializeNBTAPI(NBTContainer::class.java, ::NBTContainer) - ) -} -/* ANCHOR_END: argumentNBT1 */ -} - -class setupShading { -val plugin: JavaPlugin = object : JavaPlugin() {} - -fun setupShading1() { -/* ANCHOR: setupShading1 */ -CommandAPI.onLoad(CommandAPISpigotConfig(plugin).silentLogs(true)) -/* ANCHOR_END: setupShading1 */ -} - -/* ANCHOR: setupShading2 */ -class MyPlugin : JavaPlugin() { - - override fun onLoad() { - CommandAPI.onLoad(CommandAPISpigotConfig(this).verboseOutput(true)) // Load with verbose output - - CommandAPICommand("ping") - .executes(CommandExecutor { sender: CommandSender, _ -> - sender.sendMessage("pong!") - }) - .register() - } - - override fun onEnable() { - CommandAPI.onEnable(this) - - // Register commands, listeners etc. - } - - override fun onDisable() { - CommandAPI.onDisable() - } - -} -/* ANCHOR_END: setupShading2 */ -} - -} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt b/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt deleted file mode 100644 index 22e0715ef..000000000 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt +++ /dev/null @@ -1,62 +0,0 @@ -package dev.jorel.commandapi.examples.kotlin - -import de.tr7zw.changeme.nbtapi.NBTContainer -import dev.jorel.commandapi.executors.CommandArguments -import dev.jorel.commandapi.kotlindsl.* -import net.md_5.bungee.api.chat.BaseComponent -import org.bukkit.Bukkit -import org.bukkit.ChatColor -import org.bukkit.Material -import org.bukkit.entity.Player -import org.bukkit.inventory.ItemStack -import org.bukkit.inventory.meta.BookMeta - -class ExamplesKotlinDSL { - -fun argument_chatSpigot() { -/* ANCHOR: argumentChatSpigot1 */ -commandAPICommand("namecolor") { - chatColorArgument("chatcolor") - playerExecutor { player: Player, args: CommandArguments -> - val color = args["chatcolor"] as ChatColor - player.setDisplayName("$color${player.name}") - } -} -/* ANCHOR_END: argumentChatSpigot1 */ - -/* ANCHOR: argumentChatSpigot2 */ -commandAPICommand("makebook") { - playerArgument("player") - chatComponentArgument("contents") - anyExecutor { _, args -> - val player = args["player"] as Player - val array = args["contents"] as Array - - // Create book - val item = ItemStack(Material.WRITTEN_BOOK) - val meta = item.itemMeta as BookMeta - meta.title = "Custom Book" - meta.author = player.name - meta.spigot().setPages(array) - item.itemMeta = meta - - // Give player the book - player.inventory.addItem(item) - } -} -/* ANCHOR_END: argumentChatSpigot2 */ - -/* ANCHOR: argumentChatSpigot3 */ -commandAPICommand("pbroadcast") { - chatArgument("message") - anyExecutor { _, args -> - val message = args["message"] as Array - - // Broadcast the message to everyone on the server - Bukkit.getServer().spigot().broadcast(*message) - } -} -/* ANCHOR_END: argumentChatSpigot3 */ -} - -} \ No newline at end of file From 95c31fd39dafcea67d429d94246c3fc383169266 Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Sun, 17 Aug 2025 13:26:25 -0400 Subject: [PATCH 30/63] Fix javadoc error that stops GH Actions build --- .../src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java index 0de296607..2cce67ea2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java @@ -449,7 +449,7 @@ public CommandAPICommand newConcreteCommandAPICommand(CommandMetaData the type that the NBT compound container class From f5ea09fa9f436442cbfb7d8720082206546ff69f Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Sun, 17 Aug 2025 13:53:21 -0400 Subject: [PATCH 31/63] Start fixing the test-toolkit TODO: Make modules for Spigot and Paper --- .github/workflows/build.yml | 4 +- .../jorel/commandapi/BukkitExecutable.java | 20 +- .../jorel/commandapi/CommandAPIBukkit.java | 12 +- .../java/dev/jorel/commandapi/nms/NMS.java | 5 +- .../dev/jorel/commandapi/nms/NMS_Common.java | 9 +- .../commandapi-bukkit-test-toolkit/pom.xml | 11 +- .../commandapi/CommandAPITestUtilities.java | 12 +- .../dev/jorel/commandapi/MockCommandAPI.java | 86 ++ .../commandapi/MockCommandAPIBukkit.java | 688 -------------- .../java/dev/jorel/commandapi/MockNMS.java | 898 ++++++++++-------- .../CommandAPIVersionHandler.java | 0 ...mmandAPIVersionHandlerOverridingTests.java | 10 +- .../src/old/MockCommandAPIBukkit.java | 66 ++ .../MockCommandAPIPlugin.java | 6 +- .../MockCommandAPIPluginLoadingTests.java | 0 .../ProfileArgumentTypeTests.java | 0 .../commandapi/CommandAPIVersionHandler.java | 14 + .../dev/jorel/commandapi/CommandTestBase.java | 2 +- .../commandapi/MockCommandAPIBukkit.java | 94 ++ .../MockCommandAPIBukkitConfig.java | 17 + .../commandapi/MockCommandAPIPlugin.java | 23 + .../commandapi/MockInternalBukkitConfig.java | 25 + .../spying/ExecutionQueueTests.java | 2 +- .../commandapi-bukkit/pom.xml | 4 +- .../jorel/commandapi/nms/APITypeProvider.java | 23 +- .../commandapi-paper-test-toolkit/pom.xml | 20 + commandapi-platforms/commandapi-paper/pom.xml | 3 +- .../jorel/commandapi/CommandAPISpigot.java | 8 - 28 files changed, 893 insertions(+), 1169 deletions(-) create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java delete mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java rename commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/{main/java/dev/jorel/commandapi => old}/CommandAPIVersionHandler.java (100%) rename commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/{test/java/dev/jorel/commandapi => old}/CommandAPIVersionHandlerOverridingTests.java (79%) create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIBukkit.java rename commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/{main/java/dev/jorel/commandapi => old}/MockCommandAPIPlugin.java (77%) rename commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/{test/java/dev/jorel/commandapi => old}/MockCommandAPIPluginLoadingTests.java (100%) rename commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/{test/java/dev/jorel/commandapi/arguments => old}/ProfileArgumentTypeTests.java (100%) create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandler.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkit.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkitConfig.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPlugin.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockInternalBukkitConfig.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26eacdad6..ba86719c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -178,8 +178,8 @@ jobs: ### Examples ### - #- name: Build CommandAPI example plugins in examples/ folder - # run: cd ./examples; ./build.sh; + - name: Build CommandAPI example plugins in examples/ folder + run: cd ./examples; ./build.sh; ### Save PR information for 'SonarAnalyze' - name: Save PR number to file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java index 13c93ab0b..099436f95 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java @@ -463,8 +463,9 @@ default Impl executesRemoteConsole(RemoteConsoleResultingExecutionInfo info) { * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingCommandExecutor executor) { - if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { - throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + Platform platform = CommandAPIBukkit.get().activePlatform(); + if (platform != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + platform.name() + ")!"); } getExecutor().addNormalExecutor(executor); return instance(); @@ -477,8 +478,9 @@ default Impl executesFeedbackForwarding(FeedbackForwardingCommandExecutor execut * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingExecutionInfo info) { - if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { - throw new PlatformException("Attempted to use a FeedbackForwardingExecutionInfo on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + Platform platform = CommandAPIBukkit.get().activePlatform(); + if (platform != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + platform.name() + ")!"); } getExecutor().addNormalExecutor(info); return instance(); @@ -491,8 +493,9 @@ default Impl executesFeedbackForwarding(FeedbackForwardingExecutionInfo info) { * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingResultingCommandExecutor executor) { - if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { - throw new PlatformException("Attempted to use a FeedbackForwardingResultingCommandExecutor on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + Platform platform = CommandAPIBukkit.get().activePlatform(); + if (platform != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + platform.name() + ")!"); } getExecutor().addResultingExecutor(executor); return instance(); @@ -505,8 +508,9 @@ default Impl executesFeedbackForwarding(FeedbackForwardingResultingCommandExecut * @return this command builder */ default Impl executesFeedbackForwarding(FeedbackForwardingResultingExecutionInfo info) { - if (CommandAPIBukkit.platform().activePlatform() != Platform.PAPER) { - throw new PlatformException("Attempted to use a FeedbackForwardingResultingExecutionInfo on a non-paper platform (" + CommandAPIBukkit.platform().activePlatform().name() + ")!"); + Platform platform = CommandAPIBukkit.get().activePlatform(); + if (platform != Platform.PAPER) { + throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + platform.name() + ")!"); } getExecutor().addResultingExecutor(info); return instance(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java index 2cce67ea2..207b764f7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java @@ -15,7 +15,6 @@ import dev.jorel.commandapi.commandsenders.BukkitCommandSender; import dev.jorel.commandapi.network.BukkitCommandAPIMessenger; import dev.jorel.commandapi.nms.NMS; -import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Keyed; @@ -80,14 +79,6 @@ public static CommandAPIBukkit get() { throw new IllegalStateException("Tried to access CommandAPIBukkit instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?"); } - @SuppressWarnings("unchecked") - public static > T platform() { - if (CommandAPIBukkit.bukkit != null) { - return (T) bukkit; - } - throw new IllegalStateException("Tried to access the Bukkit platform, but it was null! Are you using CommandAPI features before calling CommandPAI#onLoad?"); - } - public JavaPlugin getPlugin() { return plugin; } @@ -143,7 +134,7 @@ private void checkDependencies() { } } - commandRegistrationStrategy = ((BukkitPlatform) bukkit).createCommandRegistrationStrategy(); + commandRegistrationStrategy = createCommandRegistrationStrategy(); } /* @@ -406,6 +397,7 @@ public final CommandDispatcher getBrigadierDispatcher() { return commandRegistrationStrategy.getBrigadierDispatcher(); } + @Override public CommandAPILogger getLogger() { if (logger == null) { logger = new DefaultLogger(); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java index eb1b547dc..cc03dc2be 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java @@ -362,9 +362,6 @@ Objective getObjective(CommandContext cmdCtx, String key ParticleData getParticle(CommandContext cmdCtx, String key); - OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - RegistryParser getPotionEffect(CommandContext cmdCtx, String key); Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException; @@ -423,7 +420,7 @@ String getScoreHolderSingle(CommandContext cmdCtx, Strin BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); @Unimplemented(because = REQUIRES_CSS) - BukkitCommandSender getCommandSenderFromCommandSource(Source css); + BukkitCommandSender getCommandSenderFromCommandSource(CommandListenerWrapper css); @Unimplemented(because = REQUIRES_CRAFTBUKKIT) CommandListenerWrapper getBrigadierSourceFromCommandSender(AbstractCommandSender sender); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java index d7686515f..5097e4d0c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/src/main/java/dev/jorel/commandapi/nms/NMS_Common.java @@ -314,9 +314,9 @@ public final Predicate getBlockPredicate(CommandContext BukkitCommandSender getCommandSenderFromCommandSource(Source css) { + public final BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack css) { try { - return CommandAPIBukkit.get().wrapCommandSender(((CommandSourceStack) css).getBukkitSender()); + return CommandAPIBukkit.get().wrapCommandSender(css.getBukkitSender()); } catch (UnsupportedOperationException e) { return null; } @@ -364,11 +364,6 @@ public final String getObjectiveCriteria(CommandContext cmdC return ObjectiveCriteriaArgument.getCriteria(cmdCtx, key).getName(); } - @Override - public final OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cmdCtx, key).iterator().next().getId()); - } - @Override public final int getTime(CommandContext cmdCtx, String key) { return cmdCtx.getArgument(key, Integer.class); diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml index f60906934..209f20a0d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-bukkit - 10.2.0-SNAPSHOT + 11.0.0-SNAPSHOT commandapi-bukkit-test-toolkit @@ -45,7 +45,7 @@ dev.jorel - commandapi-paper-core + commandapi-bukkit-core ${project.version} provided @@ -58,13 +58,6 @@ compile - - io.papermc.paper - paper-api - 1.20.6-R0.1-SNAPSHOT - provided - - com.mojang diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPITestUtilities.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPITestUtilities.java index e08f0708f..549bf65e2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPITestUtilities.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPITestUtilities.java @@ -40,10 +40,10 @@ public class CommandAPITestUtilities { /////////////////////// /** - * @return The {@link MockCommandAPIBukkit} platform class currently loaded. + * @return The {@link MockCommandAPI} class currently loaded. */ - public static MockCommandAPIBukkit getCommandAPIPlatform() { - return MockCommandAPIBukkit.getInstance(); + public static MockCommandAPI getMockCommandAPI() { + return MockCommandAPI.getInstance(); } ////////////////////// @@ -60,7 +60,7 @@ public static MockCommandAPIBukkit getCommandAPIPlatform() { * @see #assertCommandFails(CommandSender, String, String) */ public static void dispatchCommand(CommandSender sender, String command) throws CommandSyntaxException { - getCommandAPIPlatform().getBrigadierDispatcher().execute(command, new MockCommandSource(sender)); + getMockCommandAPI().getCommandAPIBukkit().getBrigadierDispatcher().execute(command, new MockCommandSource(sender)); } /** @@ -112,7 +112,7 @@ public static CommandSyntaxException assertCommandFails(CommandSender sender, St ///////////////////////// private static ExecutionInfo> getExecutionInfo(Runnable executeCommand) { - ExecutionQueue executions = getCommandAPIPlatform().getCommandAPIHandlerSpy().getExecutionQueue(); + ExecutionQueue executions = getMockCommandAPI().getCommandAPIHandlerSpy().getExecutionQueue(); executions.clear(); executeCommand.run(); @@ -257,7 +257,7 @@ public static void assertCommandFailsWithArguments( * @see #assertCommandSuggestsTooltips(CommandSender, String, int, Suggestion...) */ public static Suggestions getSuggestions(CommandSender sender, String command) { - CommandDispatcher dispatcher = getCommandAPIPlatform().getBrigadierDispatcher(); + CommandDispatcher dispatcher = getMockCommandAPI().getCommandAPIBukkit().getBrigadierDispatcher(); ParseResults parse = dispatcher.parse(command, new MockCommandSource(sender)); return dispatcher.getCompletionSuggestions(parse).join(); } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java new file mode 100644 index 000000000..df8deb06e --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java @@ -0,0 +1,86 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.spying.CommandAPIHandlerSpy; +import org.bukkit.command.CommandSender; + +import java.lang.reflect.Field; + +// TODO: Update javadocs +/** + * An implementation of {@link CommandAPIBukkit} that is compatible with a MockBukkit testing environment. + * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. + */ +public class MockCommandAPI { + // Static instance + private static MockCommandAPI instance; + private final CommandAPIBukkit commandAPIBukkit; + + protected MockCommandAPI(CommandAPIBukkit commandAPIBukkit) { + MockCommandAPI.instance = this; + + this.commandAPIBukkit = commandAPIBukkit; + } + + /** + * @return The {@link MockCommandAPI} instance currently loaded. This is the same object as is returned by + * {@link CommandAPIBukkit#get()}, but explicitly using the {@link MockCommandAPI} class. + */ + public static MockCommandAPI getInstance() { + return instance; + } + + public CommandAPIBukkit getCommandAPIBukkit() { + return commandAPIBukkit; + } + + // Reflection helpers + + /** + * Sets a field inside a target object to the given value. Ignores private access or final status. + * + * @param targetClass The {@link Class} that contains the field. + * @param fieldName The name of the field to change. + * @param target The object whose field will be changed. If the field is static, this is ignored and can be null. + * @param value The new value for the field. + * @param The type of the target object. + * @throws IllegalArgumentException If the field cannot be set. + */ + public static void setField(Class targetClass, String fieldName, Target target, Object value) { + try { + Field field = targetClass.getDeclaredField(fieldName); + field.setAccessible(true); + field.set(target, value); + } catch (ReflectiveOperationException e) { + throw new IllegalArgumentException("Reflection failed", e); + } + } + + // References to utility classes + private CommandAPIHandlerSpy commandAPIHandlerSpy; + private MockCommandRegistrationStrategy commandRegistrationStrategy; + + public void onLoad() { + // Intercept calls to CommandAPIHandler + commandAPIHandlerSpy = new CommandAPIHandlerSpy(CommandAPIHandler.getInstance()); + CommandAPIHandler, CommandSender, MockCommandSource> commandAPIHandler = commandAPIHandlerSpy.spyHandler(); + setField(CommandAPIHandler.class, "instance", null, commandAPIHandler); + + // Setup objects + commandRegistrationStrategy = new MockCommandRegistrationStrategy(commandAPIHandler); + } + + /** + * @return The {@link CommandAPIHandlerSpy} object intercepting calls to {@link CommandAPIHandler} methods. + */ + public CommandAPIHandlerSpy getCommandAPIHandlerSpy() { + return commandAPIHandlerSpy; + } + + /** + * @return The {@link MockCommandRegistrationStrategy} handling Brigadier command logic. + */ + public MockCommandRegistrationStrategy getCommandRegistrationStrategy() { + return commandRegistrationStrategy; + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java deleted file mode 100644 index ff7bf98ae..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIBukkit.java +++ /dev/null @@ -1,688 +0,0 @@ -package dev.jorel.commandapi; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.Message; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import dev.jorel.commandapi.arguments.*; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.spying.CommandAPIHandlerSpy; -import dev.jorel.commandapi.wrappers.Rotation; -import dev.jorel.commandapi.wrappers.*; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandMap; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Team; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.*; -import java.util.function.Function; -import java.util.function.Predicate; - -/** - * An implementation of {@link CommandAPIBukkit} that is compatible with a MockBukkit testing environment. - * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. - */ -public class MockCommandAPIBukkit extends CommandAPIBukkit implements MockNMS { - // Static instance - private static MockCommandAPIBukkit instance; - - /** - * @return The {@link MockCommandAPIBukkit} instance currently loaded. This is the same object as is returned by - * {@link CommandAPIBukkit#get()}, but explicitly using the {@link MockCommandAPIBukkit} class. - */ - public static MockCommandAPIBukkit getInstance() { - return instance; - } - - protected MockCommandAPIBukkit() { - MockCommandAPIBukkit.instance = this; - } - - // Reflection helpers - - /** - * Sets a field inside a target object to the given value. Ignores private access or final status. - * - * @param targetClass The {@link Class} that contains the field. - * @param fieldName The name of the field to change. - * @param target The object whose field will be changed. If the field is static, this is ignored and can be null. - * @param value The new value for the field. - * @param The type of the target object. - * @throws IllegalArgumentException If the field cannot be set. - */ - public static void setField(Class targetClass, String fieldName, Target target, Object value) { - try { - Field field = targetClass.getDeclaredField(fieldName); - field.setAccessible(true); - field.set(target, value); - } catch (ReflectiveOperationException e) { - throw new IllegalArgumentException("Reflection failed", e); - } - } - - // References to utility classes - private CommandAPIHandlerSpy commandAPIHandlerSpy; - private MockCommandRegistrationStrategy commandRegistrationStrategy; - - @Override - public void onLoad(CommandAPIConfig config) { - // Intercept calls to CommandAPIHandler - commandAPIHandlerSpy = new CommandAPIHandlerSpy(CommandAPIHandler.getInstance()); - CommandAPIHandler, CommandSender, MockCommandSource> commandAPIHandler = commandAPIHandlerSpy.spyHandler(); - setField(CommandAPIHandler.class, "instance", null, commandAPIHandler); - - // Setup objects - commandRegistrationStrategy = new MockCommandRegistrationStrategy(commandAPIHandler); - - // Continue load - super.onLoad(config); - } - - public static void onEnable() { - CommandAPI.onEnable(); - } - - /** - * @return The {@link CommandAPIHandlerSpy} object intercepting calls to {@link CommandAPIHandler} methods. - */ - public CommandAPIHandlerSpy getCommandAPIHandlerSpy() { - return commandAPIHandlerSpy; - } - - @Override - public CommandMap getCommandMap() { - return Bukkit.getCommandMap(); - } - - @Override - public Platform activePlatform() { - return Platform.PAPER; - } - - @Override - public CommandRegistrationStrategy createCommandRegistrationStrategy() { - return commandRegistrationStrategy; - } - - // CommandSender/MockCommandSource methods - @Override - public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { - // TODO: Implement `forceNative` if necessary - return getCommandSenderFromCommandSource(cmdCtx.getSource()); - } - - @Override - public BukkitCommandSender getCommandSenderFromCommandSource(MockCommandSource cs) { - return super.wrapCommandSender(cs.bukkitSender()); - } - - @Override - public MockCommandSource getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { - return new MockCommandSource(sender.getSource()); - } - - @Override - public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world) { - return new MockNativeProxyCommandSender(caller, callee, location, world); - } - - // Miscellaneous methods - /** - * A global toggle for whether the default logger returned by {@link #getLogger()} should print messages to the - * console. This is {@code false} by default, so not messages will appear. If you don't provide your own logger - * using {@link CommandAPI#setLogger(CommandAPILogger)} and set this to {@code true} before calling - * {@link CommandAPI#onLoad(CommandAPIConfig)}, then the CommandAPI will write messages into the test log. - */ - public static boolean ENABLE_LOGGING = false; - - @Override - public CommandAPILogger getLogger() { - return ENABLE_LOGGING ? - super.getLogger() : - CommandAPILogger.bindToMethods(msg -> {}, msg -> {}, msg -> {}, (msg, ex) -> {}); - } - - @Override - public Message generateMessageFromJson(String json) { - Component component = GsonComponentSerializer.gson().deserialize(json); - String text = PlainTextComponentSerializer.plainText().serialize(component); - - return () -> text; - } - - // Arguments - @Override - public ArgumentType _ArgumentEntity(ArgumentSubType subType) { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntitySelectorArgumentType.entities(); - case ENTITYSELECTOR_MANY_PLAYERS -> EntitySelectorArgumentType.players(); - case ENTITYSELECTOR_ONE_ENTITY -> EntitySelectorArgumentType.entity(); - case ENTITYSELECTOR_ONE_PLAYER -> EntitySelectorArgumentType.player(); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public Object getEntitySelector(CommandContext cmdCtx, String key, ArgumentSubType subType, boolean allowEmpty) throws CommandSyntaxException { - return switch (subType) { - case ENTITYSELECTOR_MANY_ENTITIES -> EntitySelectorArgumentType.findManyEntities(cmdCtx, key, allowEmpty); - case ENTITYSELECTOR_MANY_PLAYERS -> EntitySelectorArgumentType.findManyPlayers(cmdCtx, key, allowEmpty); - case ENTITYSELECTOR_ONE_ENTITY -> EntitySelectorArgumentType.findSingleEntity(cmdCtx, key); - case ENTITYSELECTOR_ONE_PLAYER -> EntitySelectorArgumentType.findSinglePlayer(cmdCtx, key); - default -> throw new IllegalArgumentException("Unexpected value: " + subType); - }; - } - - @Override - public ArgumentType _ArgumentIntRange() { - return IntegerRangeArgumentType.INSTANCE; - } - - @Override - public IntegerRange getIntRange(CommandContext cmdCtx, String key) { - return IntegerRangeArgumentType.getRange(cmdCtx, key); - } - - @Override - public ArgumentType _ArgumentProfile() { - return ProfileArgumentType.INSTANCE; - } - - @Override - public Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(ProfileArgumentType.getProfiles(cmdCtx, key).iterator().next()); - if (target == null) { - throw ProfileArgumentType.ERROR_UNKNOWN_PLAYER.create(); - } else { - return target; - } - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(ProfileArgumentType.getProfiles(cmdCtx, key).iterator().next()); - } - - /////////////////////////// - // UNIMPLEMENTED METHODS // - /////////////////////////// - - @Override - public ArgumentType _ArgumentAdvancement() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentAngle() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentAxis() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentBlockPredicate() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentBlockState() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentChat() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentChatComponent() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentChatFormat() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentDimension() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentEnchantment() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentEntitySummon() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentFloatRange() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentItemPredicate() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentItemStack() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentMathOperation() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentMinecraftKeyRegistered() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentMobEffect() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentNBTCompound() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentParticle() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentPosition() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentPosition2D() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentRecipe() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentRotation() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentScoreboardCriteria() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentScoreboardObjective() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentScoreboardSlot() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentScoreboardTeam() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentScoreholder(ArgumentSubType subType) { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentTag() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentTime() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentUUID() { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentVec2(boolean centerPosition) { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentVec3(boolean centerPosition) { - throw new UnimplementedMethodException(); - } - - @Override - public ArgumentType _ArgumentSyntheticBiome() { - throw new UnimplementedMethodException(); - } - - @Override - public String[] compatibleVersions() { - throw new UnimplementedMethodException(); - } - - @Override - public String convert(ItemStack is) { - throw new UnimplementedMethodException(); - } - - @Override - public String convert(ParticleData particle) { - throw new UnimplementedMethodException(); - } - - @Override - public String convert(PotionEffectType potion) { - throw new UnimplementedMethodException(); - } - - @Override - public String convert(Sound sound) { - throw new UnimplementedMethodException(); - } - - @Override - public Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public Component getAdventureChatComponent(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public float getAngle(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public EnumSet getAxis(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public BlockData getBlockState(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public ChatColor getChatColor(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public DoubleRange getFloatRange(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public SimpleFunctionWrapper getFunction(NamespacedKey key) { - throw new UnimplementedMethodException(); - } - - @Override - public Set getFunctions() { - throw new UnimplementedMethodException(); - } - - @Override - public ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Predicate getItemStackPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Location getLocationPrecise(CommandContext cmdCtx, String str) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public LootTable getLootTable(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public MathOperation getMathOperation(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public Object getNBTCompound(CommandContext cmdCtx, String key, Function nbtContainerConstructor) { - throw new UnimplementedMethodException(); - } - - @Override - public Objective getObjective(CommandContext cmdCtx, String key) throws IllegalArgumentException, CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public String getObjectiveCriteria(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public ParticleData getParticle(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Rotation getRotation(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { - throw new UnimplementedMethodException(); - } - - @Override - public int getTime(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public UUID getUUID(CommandContext cmdCtx, String key) { - throw new UnimplementedMethodException(); - } - - @Override - public World getWorldForCSS(MockCommandSource clw) { - throw new UnimplementedMethodException(); - } - - @Override - public SimpleCommandMap getSimpleCommandMap() { - throw new UnimplementedMethodException(); - } - - @Override - public Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType) { - throw new UnimplementedMethodException(); - } - - @Override - public SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider) { - throw new UnimplementedMethodException(); - } - - @Override - public SimpleFunctionWrapper[] getTag(NamespacedKey key) { - throw new UnimplementedMethodException(); - } - - @Override - public Set getTags() { - throw new UnimplementedMethodException(); - } - - @Override - public void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException { - throw new UnimplementedMethodException(); - } - - @Override - public T getMinecraftServer() { - throw new UnimplementedMethodException(); - } - - @Override - public void reloadDataPacks() { - throw new UnimplementedMethodException(); - } - - @Override - public HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { - throw new UnimplementedMethodException(); - } - - @Override - public Map getHelpMap() { - throw new UnimplementedMethodException(); - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java index 4dc3f6dd3..8ea75089c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java @@ -6,37 +6,26 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.SuggestionProvider; -import dev.jorel.commandapi.arguments.ArgumentSubType; -import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.*; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.wrappers.DoubleRange; -import dev.jorel.commandapi.wrappers.FunctionWrapper; -import dev.jorel.commandapi.wrappers.IntegerRange; -import dev.jorel.commandapi.wrappers.Location2D; -import dev.jorel.commandapi.wrappers.MathOperation; -import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.nms.NMS; +import dev.jorel.commandapi.wrappers.*; import dev.jorel.commandapi.wrappers.Rotation; -import dev.jorel.commandapi.wrappers.ScoreboardSlot; -import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.md_5.bungee.api.chat.BaseComponent; -import org.bukkit.Axis; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.OfflinePlayer; -import org.bukkit.Sound; -import org.bukkit.World; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +import org.bukkit.*; import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; +import org.bukkit.block.BlockState; import org.bukkit.command.CommandSender; import org.bukkit.command.SimpleCommandMap; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; import org.bukkit.help.HelpTopic; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; @@ -47,376 +36,505 @@ import java.io.File; import java.io.IOException; -import java.util.Collection; -import java.util.EnumSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.function.Function; import java.util.function.Predicate; -public interface MockNMS { - - /** - * @return Advancement argument (api:advancement) - */ - ArgumentType _ArgumentAdvancement(); - - /** - * @return Angle argument (minecraft:angle) - */ - ArgumentType _ArgumentAngle(); - - /** - * @return Axis argument (minecraft:swizzle) - */ - ArgumentType _ArgumentAxis(); - - /** - * @return Block predicate argument (minecraft:block_predicate) - */ - ArgumentType _ArgumentBlockPredicate(); - - /** - * @return Block state argument (minecraft:block_state) - */ - ArgumentType _ArgumentBlockState(); - - /** - * @return Chat argument (minecraft:message) - */ - ArgumentType _ArgumentChat(); - - /** - * @return Chat component argument (minecraft:component) - */ - ArgumentType _ArgumentChatComponent(); - - /** - * @return Chat color argument (minecraft:color) - */ - ArgumentType _ArgumentChatFormat(); - - /** - * @return Dimension argument (minecraft:dimension) - */ - ArgumentType _ArgumentDimension(); - - /** - * @return Enchantment argument (minecraft:item_enchantment) - */ - ArgumentType _ArgumentEnchantment(); - - /** - * @param subType one of {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_MANY_ENTITIES}, - * {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_MANY_PLAYERS}, - * {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_ONE_ENTITY} or - * {@link dev.jorel.commandapi.arguments.ArgumentSubType#ENTITYSELECTOR_ONE_PLAYER} - * @return Entity selector argument (minecraft:entity) - */ - ArgumentType _ArgumentEntity(ArgumentSubType subType); - - /** - * @return Entity type argument (minecraft:entity_summon) - */ - ArgumentType _ArgumentEntitySummon(); - - /** - * @return Float range argument (minecraft:float_range) - */ - ArgumentType _ArgumentFloatRange(); - - /** - * @return Int range argument (minecraft:int_range) - */ - ArgumentType _ArgumentIntRange(); - - /** - * @return Item predicate argument (minecraft:item_predicate) - */ - ArgumentType _ArgumentItemPredicate(); - - /** - * @return Itemstack argument (minecraft:item_stack) - */ - ArgumentType _ArgumentItemStack(); - - /** - * @return Math operation argument (minecraft:operation) - */ - ArgumentType _ArgumentMathOperation(); - - /** - * @return Minecraft key argument (minecraft:resource_location) - */ - ArgumentType _ArgumentMinecraftKeyRegistered(); - - /** - * @return Potion effect argument (minecraft:mob_effect) - */ - ArgumentType _ArgumentMobEffect(); - - /** - * @return NBT compound tag argument (minecraft:nbt_compound_tag) - */ - ArgumentType _ArgumentNBTCompound(); - - /** - * @return Particle argument (minecraft:particle) - */ - ArgumentType _ArgumentParticle(); - - /** - * @return Position argument (minecraft:block_pos) - */ - ArgumentType _ArgumentPosition(); - - /** - * @return 2D position (column) argument (minecraft:column_pos) - */ - ArgumentType _ArgumentPosition2D(); - - /** - * @return Player argument (minecraft:game_profile) - */ - ArgumentType _ArgumentProfile(); - - /** - * @return Recipe argument (api:recipe) - */ - ArgumentType _ArgumentRecipe(); - - /** - * @return Rotation argument (minecraft:rotation) - */ - ArgumentType _ArgumentRotation(); - - /** - * @return Scoreboard objective criteria argument (minecraft:objective_criteria) - */ - ArgumentType _ArgumentScoreboardCriteria(); - - /** - * @return Scoreboard objective argument (minecraft:objective) - */ - ArgumentType _ArgumentScoreboardObjective(); - - /** - * @return Scoreboard slot argument (minecraft:scoreboard_slot) - */ - ArgumentType _ArgumentScoreboardSlot(); - - /** - * @return Scoreboard team argument (minecraft:team) - */ - ArgumentType _ArgumentScoreboardTeam(); - - /** - * @param subType one of {@link ArgumentSubType#SCOREHOLDER_MULTIPLE} or - * {@link ArgumentSubType#SCOREHOLDER_SINGLE} - * @return Scoreholder argument (minecraft:score_holder) - */ - ArgumentType _ArgumentScoreholder(ArgumentSubType subType); - - /** - * @return Function argument (minecraft:function) - */ - ArgumentType _ArgumentTag(); - - /** - * @return Time argument (minecraft:time) - */ - ArgumentType _ArgumentTime(); - - /** - * @return UUID argument (minecraft:uuid) - */ - ArgumentType _ArgumentUUID(); - - /** - * @return Location 2D argument (precise position) (minecraft:vec2) - */ - ArgumentType _ArgumentVec2(boolean centerPosition); - - /** - * @return Location argument (precise position) (minecraft:vec3) - */ - ArgumentType _ArgumentVec3(boolean centerPosition); - - /* - * Synthetic arguments - arguments that don't actually exist, but have - * version-specific implementations, so we can switch their implementation as - * needed. For example, the BiomeArgument is both a - * _ArgumentMinecraftKeyRegistered and a _ArgumentResourceOrTag, but we'll refer - * to it as an _ArgumentSyntheticBiome - */ - - ArgumentType _ArgumentSyntheticBiome(); - - /** - * A String array of Minecraft versions that this NMS implementation is - * compatible with. For example, ["1.14", "1.14.1", "1.14.2", "1.14.3"]. This - * can be found by opening a Minecraft jar file, viewing the version.json file - * and reading the object "name". - * - * @return A String array of compatible Minecraft versions - */ - String[] compatibleVersions(); - - String convert(ItemStack is); - - String convert(ParticleData particle); - - String convert(PotionEffectType potion); - - String convert(Sound sound); - - Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - Component getAdventureChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - NamedTextColor getAdventureChatColor(CommandContext cmdCtx, String key); - - Component getAdventureChatComponent(CommandContext cmdCtx, String key); - - float getAngle(CommandContext cmdCtx, String key); - - EnumSet getAxis(CommandContext cmdCtx, String key); - - Object getBiome(CommandContext cmdCtx, String key, ArgumentSubType subType) throws CommandSyntaxException; - - Predicate getBlockPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - BlockData getBlockState(CommandContext cmdCtx, String key); - - BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - ChatColor getChatColor(CommandContext cmdCtx, String key); - - BaseComponent[] getChatComponent(CommandContext cmdCtx, String key); - - World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException; // Throws exception in 1.19.3 - - Object getEntitySelector(CommandContext cmdCtx, String key, ArgumentSubType subType, boolean allowEmpty) - throws CommandSyntaxException; - - EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - DoubleRange getFloatRange(CommandContext cmdCtx, String key); - - FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - SimpleFunctionWrapper getFunction(NamespacedKey key); - - Set getFunctions(); - - IntegerRange getIntRange(CommandContext cmdCtx, String key); - - ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - Predicate getItemStackPredicate(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - Location2D getLocation2DBlock(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException; - - Location getLocationPrecise(CommandContext cmdCtx, String str) - throws CommandSyntaxException; - - LootTable getLootTable(CommandContext cmdCtx, String key); - - MathOperation getMathOperation(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key); - - Object getNBTCompound(CommandContext cmdCtx, String key, - Function nbtContainerConstructor); - - Objective getObjective(CommandContext cmdCtx, String key) - throws IllegalArgumentException, CommandSyntaxException; - - String getObjectiveCriteria(CommandContext cmdCtx, String key); - - ParticleData getParticle(CommandContext cmdCtx, String key); - - Player getPlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - Object getPotionEffect(CommandContext cmdCtx, String key, ArgumentSubType subType) - throws CommandSyntaxException; - - Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - Rotation getRotation(CommandContext cmdCtx, String key); - - ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key); - - Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - String getScoreHolderSingle(CommandContext cmdCtx, String key) - throws CommandSyntaxException; - - Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException; - - int getTime(CommandContext cmdCtx, String key); - - UUID getUUID(CommandContext cmdCtx, String key); - - World getWorldForCSS(CommandSource clw); - - /** - * Returns the Server's internal (OBC) CommandMap - * - * @return A SimpleCommandMap from the OBC server - */ - SimpleCommandMap getSimpleCommandMap(); - - Object getSound(CommandContext cmdCtx, String key, ArgumentSubType subType); - - /** - * Retrieve a specific NMS implemented SuggestionProvider - * - * @param provider The SuggestionProvider type to retrieve - * @return A SuggestionProvider that matches the SuggestionProviders input - */ - SuggestionProvider getSuggestionProvider(SuggestionProviders provider); - - SimpleFunctionWrapper[] getTag(NamespacedKey key); - - Set getTags(); - - /** - * Reloads the datapacks by using the updated the commandDispatcher tree - */ - void reloadDataPacks(); - - HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission); - - Map getHelpMap(); - - Message generateMessageFromJson(String json); - - BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative); - - BukkitCommandSender getCommandSenderFromCommandSource(CommandSource css); - - CommandSource getBrigadierSourceFromCommandSender(AbstractCommandSender sender); - - void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException; - - T getMinecraftServer(); - +public class MockNMS implements NMS { + // CommandSender/MockCommandSource methods + @Override + public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean forceNative) { + // TODO: Implement `forceNative` if necessary + return getCommandSenderFromCommandSource(cmdCtx.getSource()); + } + + @Override + public BukkitCommandSender getCommandSenderFromCommandSource(MockCommandSource css) { + return CommandAPIBukkit.get().wrapCommandSender(css.bukkitSender()); + } + + @Override + public MockCommandSource getBrigadierSourceFromCommandSender(AbstractCommandSender sender) { + return new MockCommandSource(sender.getSource()); + } + + @Override + public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world) { + return new MockNativeProxyCommandSender(caller, callee, location, world); + } + + // Miscellaneous methods + @Override + public Message generateMessageFromJson(String json) { + Component component = GsonComponentSerializer.gson().deserialize(json); + String text = PlainTextComponentSerializer.plainText().serialize(component); + + return () -> text; + } + + // Arguments + @Override + public ArgumentType _ArgumentEntity(ArgumentSubType subType) { + return switch (subType) { + case ENTITYSELECTOR_MANY_ENTITIES -> EntitySelectorArgumentType.entities(); + case ENTITYSELECTOR_MANY_PLAYERS -> EntitySelectorArgumentType.players(); + case ENTITYSELECTOR_ONE_ENTITY -> EntitySelectorArgumentType.entity(); + case ENTITYSELECTOR_ONE_PLAYER -> EntitySelectorArgumentType.player(); + default -> throw new IllegalArgumentException("Unexpected value: " + subType); + }; + } + + @Override + public EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String key) { + return new EntitySelectorParser( + () -> EntitySelectorArgumentType.findSinglePlayer(cmdCtx, key), + () -> EntitySelectorArgumentType.findSingleEntity(cmdCtx, key), + (allowEmpty) -> EntitySelectorArgumentType.findManyPlayers(cmdCtx, key, allowEmpty), + (allowEmpty) -> (Collection) EntitySelectorArgumentType.findManyEntities(cmdCtx, key, allowEmpty) + ); + } + + @Override + public ArgumentType _ArgumentIntRange() { + return IntegerRangeArgumentType.INSTANCE; + } + + @Override + public IntegerRange getIntRange(CommandContext cmdCtx, String key) { + return IntegerRangeArgumentType.getRange(cmdCtx, key); + } + + @Override + public ArgumentType _ArgumentProfile() { + return ProfileArgumentType.INSTANCE; + } + + /////////////////////////// + // UNIMPLEMENTED METHODS // + /////////////////////////// + + @Override + public ArgumentType _ArgumentAdvancement() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentAngle() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentAxis() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentBlockPredicate() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentBlockState() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentChat() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentChatComponent() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentChatFormat() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentDimension() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentEnchantment() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentEntitySummon() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentFloatRange() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentItemPredicate() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentItemStack() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentMathOperation() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentMinecraftKeyRegistered() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentMobEffect() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentNBTCompound() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentParticle() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentPosition() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentPosition2D() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentRecipe() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentRotation() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentScoreboardCriteria() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentScoreboardObjective() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentScoreboardSlot() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentScoreboardTeam() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentScoreholder(ArgumentSubType subType) { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentTag() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentTime() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentUUID() { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentVec2(boolean centerPosition) { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentVec3(boolean centerPosition) { + throw new UnimplementedMethodException(); + } + + @Override + public ArgumentType _ArgumentSyntheticBiome() { + throw new UnimplementedMethodException(); + } + + @Override + public String[] compatibleVersions() { + throw new UnimplementedMethodException(); + } + + @Override + public String convert(ItemStack is) { + throw new UnimplementedMethodException(); + } + + @Override + public String convert(ParticleData particle) { + throw new UnimplementedMethodException(); + } + + @Override + public String convert(PotionEffectType potion) { + throw new UnimplementedMethodException(); + } + + @Override + public String convert(Sound sound) { + throw new UnimplementedMethodException(); + } + + @Override + public Advancement getAdvancement(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public float getAngle(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public EnumSet getAxis(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public Predicate getBlockPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public BlockState getBlockState(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public World getDimension(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public Enchantment getEnchantment(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public EntityType getEntityType(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public SimpleFunctionWrapper getFunction(NamespacedKey key) { + throw new UnimplementedMethodException(); + } + + @Override + public Set getFunctions() { + throw new UnimplementedMethodException(); + } + + @Override + public ItemStack getItemStack(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public Predicate getItemStackPredicate(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public Location2D getLocation2DBlock(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public Location getLocationBlock(CommandContext cmdCtx, String str) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public Location getLocationPrecise(CommandContext cmdCtx, String str) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public LootTable getLootTable(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public MathOperation getMathOperation(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public Object getNBTCompound(CommandContext cmdCtx, String key, Function nbtContainerConstructor) { + throw new UnimplementedMethodException(); + } + + @Override + public Objective getObjective(CommandContext cmdCtx, String key) throws IllegalArgumentException, CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public String getObjectiveCriteria(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public ParticleData getParticle(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public Rotation getRotation(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public int getTime(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public UUID getUUID(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public World getWorldForCSS(MockCommandSource clw) { + throw new UnimplementedMethodException(); + } + + @Override + public SimpleCommandMap getSimpleCommandMap() { + throw new UnimplementedMethodException(); + } + + @Override + public RegistryParser getSound(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public SuggestionProvider getSuggestionProvider(SuggestionProviders suggestionProvider) { + throw new UnimplementedMethodException(); + } + + @Override + public SimpleFunctionWrapper[] getTag(NamespacedKey key) { + throw new UnimplementedMethodException(); + } + + @Override + public Set getTags() { + throw new UnimplementedMethodException(); + } + + @Override + public void createDispatcherFile(File file, CommandDispatcher brigadierDispatcher) throws IOException { + throw new UnimplementedMethodException(); + } + + @Override + public T getMinecraftServer() { + throw new UnimplementedMethodException(); + } + + @Override + public void reloadDataPacks() { + throw new UnimplementedMethodException(); + } + + @Override + public HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, String permission) { + throw new UnimplementedMethodException(); + } + + @Override + public Map getHelpMap() { + throw new UnimplementedMethodException(); + } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandler.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandler.java diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandlerOverridingTests.java similarity index 79% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandlerOverridingTests.java index 389299dbf..f0dc95949 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandlerOverridingTests.java @@ -22,7 +22,7 @@ public void tearDown() { MockBukkit.unmock(); } - private static class CustomMockCommandAPIBukkit extends MockCommandAPIBukkit { + private static class CustomMockCommandAPIBukkit extends MockCommandAPI { } @@ -31,7 +31,7 @@ private static class CustomMockCommandAPIBukkit extends MockCommandAPIBukkit { void testDefaultPlatform() { MockCommandAPIPlugin.load(); - assertEquals(MockCommandAPIBukkit.class, CommandAPITestUtilities.getCommandAPIPlatform().getClass()); + assertEquals(MockCommandAPI.class, CommandAPITestUtilities.getMockCommandAPI().getClass()); } @Test @@ -39,7 +39,7 @@ void testChangingPlatform() { CommandAPIVersionHandler.usePlatformImplementation(new CustomMockCommandAPIBukkit()); MockCommandAPIPlugin.load(); - assertEquals(CustomMockCommandAPIBukkit.class, CommandAPITestUtilities.getCommandAPIPlatform().getClass()); + assertEquals(CustomMockCommandAPIBukkit.class, CommandAPITestUtilities.getMockCommandAPI().getClass()); } @Test @@ -47,12 +47,12 @@ void testPlatformDoesNotPersist() { CommandAPIVersionHandler.usePlatformImplementation(new CustomMockCommandAPIBukkit()); MockCommandAPIPlugin.load(); - assertEquals(CustomMockCommandAPIBukkit.class, CommandAPITestUtilities.getCommandAPIPlatform().getClass()); + assertEquals(CustomMockCommandAPIBukkit.class, CommandAPITestUtilities.getMockCommandAPI().getClass()); MockBukkit.unmock(); MockBukkit.mock(); MockCommandAPIPlugin.load(); - assertEquals(MockCommandAPIBukkit.class, CommandAPITestUtilities.getCommandAPIPlatform().getClass()); + assertEquals(MockCommandAPI.class, CommandAPITestUtilities.getMockCommandAPI().getClass()); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIBukkit.java new file mode 100644 index 000000000..4e8a73646 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIBukkit.java @@ -0,0 +1,66 @@ +package dev.jorel.commandapi; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.Message; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import dev.jorel.commandapi.arguments.*; +import dev.jorel.commandapi.commandsenders.AbstractCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.spying.CommandAPIHandlerSpy; +import dev.jorel.commandapi.wrappers.Rotation; +import dev.jorel.commandapi.wrappers.*; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.*; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; +import org.bukkit.loot.LootTable; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.*; +import java.util.function.Function; +import java.util.function.Predicate; + +/** + * An implementation of {@link CommandAPIBukkit} that is compatible with a MockBukkit testing environment. + * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. + */ +public class MockCommandAPIBukkit extends CommandAPIBukkit { + + // Miscellaneous methods + /** + * A global toggle for whether the default logger returned by {@link #getLogger()} should print messages to the + * console. This is {@code false} by default, so not messages will appear. If you don't provide your own logger + * using {@link CommandAPI#setLogger(CommandAPILogger)} and set this to {@code true} before calling + * {@link CommandAPI#onLoad(CommandAPIConfig)}, then the CommandAPI will write messages into the test log. + */ + public static boolean ENABLE_LOGGING = false; + + @Override + public CommandAPILogger getLogger() { + return ENABLE_LOGGING ? + super.getLogger() : + CommandAPILogger.bindToMethods(msg -> {}, msg -> {}, msg -> {}, (msg, ex) -> {}); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPlugin.java similarity index 77% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPlugin.java index 84229307e..f6ce39480 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPlugin.java @@ -7,11 +7,7 @@ import java.util.function.Consumer; /** - * A {@link JavaPlugin} that loads the CommandAPI in a testing environment. If your plugin depends on the CommandAPI - * plugin when running on a server (you aren't shading the CommandAPI), load this class before loading your own plugin - * with {@link MockBukkit}. You can do this directly using {@code MockBukkit.load(MockCommandAPIPlugin.class);}, or with - * {@link MockCommandAPIPlugin#load()}. If you need to configure settings usually located in the CommandAPI's plugin.yml, - * use {@link MockCommandAPIPlugin#load(Consumer)}. + * Loads the CommandAPI in this abstract Bukkit environment. */ public class MockCommandAPIPlugin extends JavaPlugin { // Allow loading with settings, diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPluginLoadingTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPluginLoadingTests.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPluginLoadingTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPluginLoadingTests.java diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/ProfileArgumentTypeTests.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/ProfileArgumentTypeTests.java diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandler.java new file mode 100644 index 000000000..52a1c60a5 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -0,0 +1,14 @@ +package dev.jorel.commandapi; + +public abstract class CommandAPIVersionHandler { + static LoadContext getPlatform(CommandAPIConfig config) { + MockInternalBukkitConfig mockInternalBukkitConfig; + if (config instanceof MockCommandAPIBukkitConfig bukkitConfig) { + mockInternalBukkitConfig = new MockInternalBukkitConfig(bukkitConfig); + } else { + throw new IllegalStateException("MockCommandAPIBukkit was loaded with non-MockBukkit config!"); + } + + return new LoadContext(new MockCommandAPIBukkit(mockInternalBukkitConfig)); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java index a6e3a50ee..021661b4b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java @@ -57,7 +57,7 @@ public AssertionFailedError assertAssertionFails(Executable executable, String e public CommandContext createContextWithParser( CommandSender source, String key, Parser parser, String input ) throws CommandSyntaxException { - CommandDispatcher dispatcher = getCommandAPIPlatform().getBrigadierDispatcher(); + CommandDispatcher dispatcher = getMockCommandAPI().getCommandAPIBukkit().getBrigadierDispatcher(); CommandContextBuilder contextBuilder = new CommandContextBuilder<>( dispatcher, new MockCommandSource(source), diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkit.java new file mode 100644 index 000000000..d6de6bd0e --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkit.java @@ -0,0 +1,94 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.commandsenders.*; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; +import org.bukkit.Bukkit; +import org.bukkit.command.*; +import org.bukkit.entity.Player; + +/** + * An implementation of {@link CommandAPIBukkit} that is compatible with a MockBukkit testing environment. + * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. + */ +public class MockCommandAPIBukkit extends CommandAPIBukkit { + // Instance + private final MockCommandAPI mockCommandAPI; + + public MockCommandAPIBukkit(MockInternalBukkitConfig config) { + this.nms = new MockNMS(); + this.mockCommandAPI = new MockCommandAPI(this); + + CommandAPIBukkit.config = config; + } + + // Config + public static MockInternalBukkitConfig getConfiguration() { + return (MockInternalBukkitConfig) CommandAPIBukkit.getConfiguration(); + } + + // Load + @Override + public void onLoad() { + mockCommandAPI.onLoad(); + super.onLoad(); + } + + // Enable + @Override + public void onEnable() { + super.plugin = getConfiguration().getPlugin(); + super.stopCommandRegistrations(); + } + + // Test environment-specific + @Override + public CommandMap getCommandMap() { + return Bukkit.getCommandMap(); + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return mockCommandAPI.getCommandRegistrationStrategy(); + } + + public static boolean ENABLE_LOGGING = false; + + @Override + public CommandAPILogger getLogger() { + return ENABLE_LOGGING ? + super.getLogger() : + CommandAPILogger.bindToMethods(msg -> {}, msg -> {}, msg -> {}, (msg, ex) -> {}); + } + + // This logic copied from CommandAPISpigot + @Override + public BukkitCommandSender wrapCommandSender(CommandSender sender) { + if (sender instanceof BlockCommandSender block) { + return new BukkitBlockCommandSender(block); + } + if (sender instanceof ConsoleCommandSender console) { + return new BukkitConsoleCommandSender(console); + } + if (sender instanceof Player player) { + return new BukkitPlayer(player); + } + if (sender instanceof org.bukkit.entity.Entity entity) { + return new BukkitEntity(entity); + } + if (sender instanceof NativeProxyCommandSender nativeProxy) { + return new BukkitNativeProxyCommandSender(nativeProxy); + } + if (sender instanceof ProxiedCommandSender proxy) { + return new BukkitProxiedCommandSender(proxy); + } + if (sender instanceof RemoteConsoleCommandSender remote) { + return new BukkitRemoteConsoleCommandSender(remote); + } + throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender"); + } + + @Override + public Platform activePlatform() { + return Platform.SPIGOT; + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkitConfig.java new file mode 100644 index 000000000..e8631913e --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkitConfig.java @@ -0,0 +1,17 @@ +package dev.jorel.commandapi; + +import org.bukkit.plugin.java.JavaPlugin; + +public class MockCommandAPIBukkitConfig extends CommandAPIBukkitConfig { + JavaPlugin plugin; + + public MockCommandAPIBukkitConfig(JavaPlugin plugin) { + super(plugin.getName()); + this.plugin = plugin; + } + + @Override + public MockCommandAPIBukkitConfig instance() { + return this; + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPlugin.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPlugin.java new file mode 100644 index 000000000..5c52b0f1b --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPlugin.java @@ -0,0 +1,23 @@ +package dev.jorel.commandapi; + +import org.bukkit.plugin.java.JavaPlugin; + +/** + * Loads the CommandAPI in this abstract Bukkit environment. + */ +public class MockCommandAPIPlugin extends JavaPlugin { + @Override + public void onLoad() { + CommandAPI.onLoad(new MockCommandAPIBukkitConfig(this)); + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + } + + @Override + public void onDisable() { + CommandAPI.onDisable(); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockInternalBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockInternalBukkitConfig.java new file mode 100644 index 000000000..ace4a8f86 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockInternalBukkitConfig.java @@ -0,0 +1,25 @@ +package dev.jorel.commandapi; + +import org.bukkit.plugin.java.JavaPlugin; + +public class MockInternalBukkitConfig extends InternalBukkitConfig { + + private final JavaPlugin plugin; + + /** + * Creates an {@link InternalBukkitConfig} from a {@link CommandAPIBukkitConfig} + * + * @param config The configuration to use to set up this internal configuration + */ + public MockInternalBukkitConfig(MockCommandAPIBukkitConfig config) { + super(config); + this.plugin = config.plugin; + } + + /** + * @return the {@link JavaPlugin} loading the CommandAPI + */ + public JavaPlugin getPlugin() { + return plugin; + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/spying/ExecutionQueueTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/spying/ExecutionQueueTests.java index dec850032..0c72e9fec 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/spying/ExecutionQueueTests.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/spying/ExecutionQueueTests.java @@ -24,7 +24,7 @@ class ExecutionQueueTests extends CommandTestBase { public void setUp() { super.setUp(); - queue = getCommandAPIPlatform().getCommandAPIHandlerSpy().getExecutionQueue(); + queue = getMockCommandAPI().getCommandAPIHandlerSpy().getExecutionQueue(); new CommandAPICommand("test") .withOptionalArguments(new BooleanArgument("shouldFail")) diff --git a/commandapi-platforms/commandapi-bukkit/pom.xml b/commandapi-platforms/commandapi-bukkit/pom.xml index a99832114..45c182237 100644 --- a/commandapi-platforms/commandapi-bukkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/pom.xml @@ -25,8 +25,8 @@ commandapi-bukkit-plugin-common commandapi-bukkit-networking-plugin - + + commandapi-bukkit-test-toolkit diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index 4b87c6a97..0a38625d0 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -8,7 +8,6 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.SuggestionProvider; -import dev.jorel.commandapi.BukkitTooltip; import dev.jorel.commandapi.CommandRegistrationStrategy; import dev.jorel.commandapi.arguments.ArgumentSubType; import dev.jorel.commandapi.arguments.SuggestionProviders; @@ -58,7 +57,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.NamespacedKey; -import org.bukkit.OfflinePlayer; import org.bukkit.Registry; import org.bukkit.Sound; import org.bukkit.World; @@ -103,7 +101,6 @@ public class APITypeProvider extends BundledNMS { private final SimpleCommandExceptionType noEntitiesFound; private final SimpleCommandExceptionType noPlayersFound; - private final SimpleCommandExceptionType unknownPlayer; public APITypeProvider(PaperNMS paperNMS) { this.paperNMS = (PaperNMS) paperNMS; @@ -112,7 +109,6 @@ public APITypeProvider(PaperNMS paperNMS) { GsonComponentSerializer gson = GsonComponentSerializer.gson(); this.noEntitiesFound = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.entity")))); this.noPlayersFound = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.entity.notfound.player")))); - this.unknownPlayer = new SimpleCommandExceptionType(paperNMS.bukkitNMS().generateMessageFromJson(gson.serialize(Component.translatable("argument.player.unknown")))); } private ArgumentType getArgumentType(ThrowingSupplier> paper, Supplier> nms) { @@ -638,23 +634,6 @@ public ParticleData getParticle(CommandContext cmdCtx, St ); } - @Override - public OfflinePlayer getOfflinePlayer(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return parseT(cmdCtx, key, - (ctx, name) -> Bukkit.getOfflinePlayer(getIdFromProfile(ctx, name)), - (ctx, name) -> paperNMS.bukkitNMS().getOfflinePlayer(ctx, name) - ); - } - - private UUID getIdFromProfile(CommandContext ctx, String name) throws CommandSyntaxException { - Collection playerProfiles = ctx.getArgument(name, PlayerProfileListResolver.class).resolve(ctx.getSource()); - UUID id = playerProfiles.iterator().next().getId(); - if (id == null) { - throw unknownPlayer.create(); - } - return id; - } - @Override public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { return new RegistryParser<>( @@ -783,7 +762,7 @@ public BukkitCommandSender getSenderForCommand(CommandC } @Override - public BukkitCommandSender getCommandSenderFromCommandSource(Source css) { + public BukkitCommandSender getCommandSenderFromCommandSource(CommandSourceStack css) { return paperNMS.bukkitNMS().getCommandSenderFromCommandSource(css); } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml new file mode 100644 index 000000000..248c72e1c --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper + 11.0.0-SNAPSHOT + + + commandapi-paper-test-toolkit + + + 21 + 21 + UTF-8 + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/pom.xml b/commandapi-platforms/commandapi-paper/pom.xml index 911d50a6c..105a14776 100644 --- a/commandapi-platforms/commandapi-paper/pom.xml +++ b/commandapi-platforms/commandapi-paper/pom.xml @@ -25,8 +25,9 @@ commandapi-paper-nms commandapi-paper-shade commandapi-paper-plugin + commandapi-paper-test-toolkit - + - - org.apache.maven.plugins - maven-shade-plugin - - - package - - shade - - - - - dev.jorel:commandapi-core - - dev/jorel/commandapi/CommandAPIVersionHandler** - - - - - - LICENSE - - - - - - - org.apache.maven.plugins diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java index df8deb06e..9a5f0e96f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java @@ -83,4 +83,13 @@ public CommandAPIHandlerSpy getCommandAPIHandlerSpy() { public MockCommandRegistrationStrategy getCommandRegistrationStrategy() { return commandRegistrationStrategy; } + + // Logging + /** + * A global toggle for whether the default logger returned by {@link CommandAPIBukkit#getLogger()} should print + * messages to the console. This is {@code false} by default, so not messages will appear. If you don't provide + * your own logger using {@link CommandAPI#setLogger(CommandAPILogger)} and set this to {@code true} before calling + * {@link CommandAPI#onLoad(CommandAPIConfig)}, then the CommandAPI will write messages into the test log. + */ + public static boolean ENABLE_LOGGING = false; } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/arguments/ProfileArgumentType.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/arguments/ProfileArgumentType.java index 4df0f2833..baaaa4850 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/arguments/ProfileArgumentType.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/arguments/ProfileArgumentType.java @@ -13,8 +13,10 @@ import dev.jorel.commandapi.arguments.parser.Result; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.profile.PlayerProfile; -import java.util.*; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CompletableFuture; public class ProfileArgumentType implements ArgumentType { @@ -28,7 +30,7 @@ private ProfileArgumentType() { // ArgumentType implementation @FunctionalInterface public interface ProfileSelector { - Collection getProfiles(MockCommandSource source) throws CommandSyntaxException; + List getProfiles(MockCommandSource source) throws CommandSyntaxException; } public static final SimpleCommandExceptionType ERROR_UNKNOWN_PLAYER = new SimpleCommandExceptionType( @@ -52,9 +54,9 @@ public interface ProfileSelector { throw EntitySelectorArgumentType.NO_PLAYERS_FOUND.create(); } - List profiles = new ArrayList<>(players.size()); + List profiles = new ArrayList<>(players.size()); for (Player player : players) { - profiles.add(player.getUniqueId()); + profiles.add(player.getPlayerProfile()); } return profiles; }; @@ -72,7 +74,7 @@ public interface ProfileSelector { if (player == null) { throw ERROR_UNKNOWN_PLAYER.create(); } - return Collections.singleton(player.getUniqueId()); + return List.of(player.getPlayerProfile()); }) // Name was not parsed, pass error unchanged ); @@ -88,7 +90,7 @@ public CompletableFuture listSuggestions(CommandContext cont return EntitySelectorParser.parser.listSuggestions(context, builder); } - public static Collection getProfiles(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public static List getProfiles(CommandContext cmdCtx, String key) throws CommandSyntaxException { return cmdCtx.getArgument(key, ProfileSelector.class).getProfiles(cmdCtx.getSource()); } } diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockNMS.java similarity index 98% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java rename to commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockNMS.java index 8ea75089c..2b4f4968d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockNMS.java @@ -1,4 +1,4 @@ -package dev.jorel.commandapi; +package dev.jorel.commandapi.nms; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.Message; @@ -6,12 +6,14 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.SuggestionProvider; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.MockCommandSource; +import dev.jorel.commandapi.UnimplementedMethodException; import dev.jorel.commandapi.arguments.*; import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; import dev.jorel.commandapi.arguments.parser.RegistryParser; import dev.jorel.commandapi.commandsenders.AbstractCommandSender; import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.nms.NMS; import dev.jorel.commandapi.wrappers.*; import dev.jorel.commandapi.wrappers.Rotation; import net.kyori.adventure.text.Component; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandler.java deleted file mode 100644 index b3a18cce0..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandler.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.jorel.commandapi; - -public abstract class CommandAPIVersionHandler { - // Allow loading a different platform implementation (most likely to implement something `MockCommandAPIBukkit` doesn't) - private static CommandAPIPlatform alternativePlatform = null; - - /** - * Configures the test kit to use the given {@link CommandAPIPlatform} when the CommandAPI is loaded. - * - * @param platform The {@link CommandAPIPlatform} to use for the next test. This will likely be a custom - * implementation of {@link MockCommandAPIBukkit} that overrides a method you need to run - * tests that doesn't have a proper implementation in {@link MockCommandAPIBukkit}. - */ - public static void usePlatformImplementation(CommandAPIPlatform platform) { - alternativePlatform = platform; - } - - static LoadContext getPlatform() { - // Default to MockCommandAPIBukkit if not given - CommandAPIPlatform platform = alternativePlatform == null ? new MockCommandAPIBukkit() : alternativePlatform; - - // Reset to avoid platform persisting between tests - alternativePlatform = null; - - return new LoadContext(platform); - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandlerOverridingTests.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandlerOverridingTests.java deleted file mode 100644 index f0dc95949..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/CommandAPIVersionHandlerOverridingTests.java +++ /dev/null @@ -1,58 +0,0 @@ -package dev.jorel.commandapi; - -import org.mockbukkit.mockbukkit.MockBukkit; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -/** - * Tests for using {@link CommandAPIVersionHandler#usePlatformImplementation(CommandAPIPlatform)} - */ -class CommandAPIVersionHandlerOverridingTests { - // Setup - @BeforeEach - public void setUp() { - MockBukkit.mock(); - } - - @AfterEach - public void tearDown() { - MockBukkit.unmock(); - } - - private static class CustomMockCommandAPIBukkit extends MockCommandAPI { - - } - - // Tests - @Test - void testDefaultPlatform() { - MockCommandAPIPlugin.load(); - - assertEquals(MockCommandAPI.class, CommandAPITestUtilities.getMockCommandAPI().getClass()); - } - - @Test - void testChangingPlatform() { - CommandAPIVersionHandler.usePlatformImplementation(new CustomMockCommandAPIBukkit()); - MockCommandAPIPlugin.load(); - - assertEquals(CustomMockCommandAPIBukkit.class, CommandAPITestUtilities.getMockCommandAPI().getClass()); - } - - @Test - void testPlatformDoesNotPersist() { - CommandAPIVersionHandler.usePlatformImplementation(new CustomMockCommandAPIBukkit()); - MockCommandAPIPlugin.load(); - - assertEquals(CustomMockCommandAPIBukkit.class, CommandAPITestUtilities.getMockCommandAPI().getClass()); - - MockBukkit.unmock(); - MockBukkit.mock(); - - MockCommandAPIPlugin.load(); - assertEquals(MockCommandAPI.class, CommandAPITestUtilities.getMockCommandAPI().getClass()); - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIBukkit.java deleted file mode 100644 index 4e8a73646..000000000 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIBukkit.java +++ /dev/null @@ -1,66 +0,0 @@ -package dev.jorel.commandapi; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.Message; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import dev.jorel.commandapi.arguments.*; -import dev.jorel.commandapi.commandsenders.AbstractCommandSender; -import dev.jorel.commandapi.commandsenders.BukkitCommandSender; -import dev.jorel.commandapi.spying.CommandAPIHandlerSpy; -import dev.jorel.commandapi.wrappers.Rotation; -import dev.jorel.commandapi.wrappers.*; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import net.md_5.bungee.api.chat.BaseComponent; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandMap; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.help.HelpTopic; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Team; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.*; -import java.util.function.Function; -import java.util.function.Predicate; - -/** - * An implementation of {@link CommandAPIBukkit} that is compatible with a MockBukkit testing environment. - * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. - */ -public class MockCommandAPIBukkit extends CommandAPIBukkit { - - // Miscellaneous methods - /** - * A global toggle for whether the default logger returned by {@link #getLogger()} should print messages to the - * console. This is {@code false} by default, so not messages will appear. If you don't provide your own logger - * using {@link CommandAPI#setLogger(CommandAPILogger)} and set this to {@code true} before calling - * {@link CommandAPI#onLoad(CommandAPIConfig)}, then the CommandAPI will write messages into the test log. - */ - public static boolean ENABLE_LOGGING = false; - - @Override - public CommandAPILogger getLogger() { - return ENABLE_LOGGING ? - super.getLogger() : - CommandAPILogger.bindToMethods(msg -> {}, msg -> {}, msg -> {}, (msg, ex) -> {}); - } -} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkit.java index d6de6bd0e..635432316 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIBukkit.java @@ -1,6 +1,7 @@ package dev.jorel.commandapi; import dev.jorel.commandapi.commandsenders.*; +import dev.jorel.commandapi.nms.MockNMS; import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; import org.bukkit.Bukkit; import org.bukkit.command.*; @@ -11,7 +12,7 @@ * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. */ public class MockCommandAPIBukkit extends CommandAPIBukkit { - // Instance + // References to utility classes private final MockCommandAPI mockCommandAPI; public MockCommandAPIBukkit(MockInternalBukkitConfig config) { @@ -51,13 +52,9 @@ public CommandRegistrationStrategy createCommandRegistrationS return mockCommandAPI.getCommandRegistrationStrategy(); } - public static boolean ENABLE_LOGGING = false; - @Override public CommandAPILogger getLogger() { - return ENABLE_LOGGING ? - super.getLogger() : - CommandAPILogger.bindToMethods(msg -> {}, msg -> {}, msg -> {}, (msg, ex) -> {}); + return MockCommandAPI.ENABLE_LOGGING ? super.getLogger() : CommandAPILogger.silent(); } // This logic copied from CommandAPISpigot diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java index cded70de8..2e52005d0 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R2.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_20_R2.profile.CraftPlayerProfile; import org.bukkit.profile.PlayerProfile; +import java.util.ArrayList; import java.util.List; public class SpigotNMS_1_20_R2 extends CommandAPISpigot { @@ -51,9 +52,7 @@ public BaseComponent[] getChatComponent(CommandContext cmdCt @Override public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java index a87c582da..64c6035e9 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R3.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_20_R3.profile.CraftPlayerProfile; import org.bukkit.profile.PlayerProfile; +import java.util.ArrayList; import java.util.List; public class SpigotNMS_1_20_R3 extends CommandAPISpigot { @@ -51,9 +52,7 @@ public BaseComponent[] getChatComponent(CommandContext cmdCt @Override public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java index 18b69c268..dc58973b3 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R4.java @@ -26,6 +26,7 @@ import org.bukkit.craftbukkit.v1_20_R4.profile.CraftPlayerProfile; import org.bukkit.profile.PlayerProfile; +import java.util.ArrayList; import java.util.List; public class SpigotNMS_1_20_R4 extends CommandAPISpigot { @@ -65,9 +66,7 @@ public BaseComponent[] getChatComponent(CommandContext cmdCt @Override public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java index 3b8a06c39..ae28f0df9 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_20_R1.java @@ -23,6 +23,7 @@ import org.bukkit.craftbukkit.v1_20_R1.profile.CraftPlayerProfile; import org.bukkit.profile.PlayerProfile; +import java.util.ArrayList; import java.util.List; public class SpigotNMS_1_20_R1 extends CommandAPISpigot { @@ -51,9 +52,7 @@ public BaseComponent[] getChatComponent(CommandContext cmdCt @Override public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java index 5a201ae6f..25357309a 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R2.java @@ -26,6 +26,7 @@ import org.bukkit.craftbukkit.v1_21_R2.profile.CraftPlayerProfile; import org.bukkit.profile.PlayerProfile; +import java.util.ArrayList; import java.util.List; public class SpigotNMS_1_21_R2 extends CommandAPISpigot { @@ -65,9 +66,7 @@ public BaseComponent[] getChatComponent(CommandContext cmdCt @Override public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java index b2c936f27..e5317f065 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R3.java @@ -26,6 +26,7 @@ import org.bukkit.craftbukkit.v1_21_R3.profile.CraftPlayerProfile; import org.bukkit.profile.PlayerProfile; +import java.util.ArrayList; import java.util.List; public class SpigotNMS_1_21_R3 extends CommandAPISpigot { @@ -65,9 +66,7 @@ public BaseComponent[] getChatComponent(CommandContext cmdCt @Override public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java index 6309dfe03..889bd890c 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R4.java @@ -26,6 +26,7 @@ import org.bukkit.craftbukkit.v1_21_R4.profile.CraftPlayerProfile; import org.bukkit.profile.PlayerProfile; +import java.util.ArrayList; import java.util.List; public class SpigotNMS_1_21_R4 extends CommandAPISpigot { @@ -65,9 +66,7 @@ public BaseComponent[] getChatComponent(CommandContext cmdCt @Override public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java index 632285822..c9e20f319 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R5.java @@ -25,6 +25,7 @@ import org.bukkit.craftbukkit.v1_21_R5.profile.CraftPlayerProfile; import org.bukkit.profile.PlayerProfile; +import java.util.ArrayList; import java.util.List; public class SpigotNMS_1_21_R5 extends CommandAPISpigot { @@ -64,9 +65,7 @@ public BaseComponent[] getChatComponent(CommandContext cmdCt @Override public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java index 6e14e86f3..cd0bac5bd 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R1.java @@ -26,6 +26,7 @@ import org.bukkit.craftbukkit.v1_21_R1.profile.CraftPlayerProfile; import org.bukkit.profile.PlayerProfile; +import java.util.ArrayList; import java.util.List; public class SpigotNMS_1_21_R1 extends CommandAPISpigot { @@ -65,9 +66,7 @@ public BaseComponent[] getChatComponent(CommandContext cmdCt @Override public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); - return result instanceof GameProfileArgument.SelectorResult selectorResult - ? List.of(Collections2.transform(selectorResult.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])) - : List.of(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new).toArray(new PlayerProfile[0])); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml new file mode 100644 index 000000000..0033901ee --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml @@ -0,0 +1,133 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot + 11.0.0-SNAPSHOT + + + commandapi-spigot-test-toolkit + Spigot support testing toolkit + + + 21 + 21 + UTF-8 + + + + + minecraft-libraries + Minecraft Libraries + https://libraries.minecraft.net + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + + + + org.mockbukkit.mockbukkit + mockbukkit-v1.21 + 4.45.1 + provided + + + dev.jorel + commandapi-bukkit-test-toolkit + ${project.version} + compile + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + dev.jorel:commandapi-core + + dev/jorel/commandapi/CommandAPIVersionHandler** + + + + + + LICENSE + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.3.0 + + false + + + + + + + + + + org.jacoco + jacoco-maven-plugin + + + + default-prepare-agent + + prepare-agent + + + + + report + verify + + report + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java new file mode 100644 index 000000000..d21e9e26e --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -0,0 +1,39 @@ +package dev.jorel.commandapi; + +import java.util.function.Function; + +public abstract class CommandAPIVersionHandler { + // Allow loading a different platform implementation (most likely to implement something `MockCommandAPISpigot` doesn't) + private static Function> alternativePlatform = null; + + /** + * Configures the test kit to use the given {@link CommandAPIPlatform} when the CommandAPI is loaded. + * + * @param platform A {@link Function} that uses a {@link InternalSpigotConfig} to create the + * {@link CommandAPIPlatform} to use for the next test. This will likely be a custom + * implementation of {@link MockCommandAPISpigot} that overrides a method you need to run + * tests that doesn't have a proper implementation in {@link MockCommandAPISpigot}. + */ + public static void usePlatformImplementation(Function> platform) { + alternativePlatform = platform; + } + + static LoadContext getPlatform(CommandAPIConfig config) { + InternalSpigotConfig internalSpigotConfig; + if (config instanceof CommandAPISpigotConfig spigotConfig) { + internalSpigotConfig = new InternalSpigotConfig(spigotConfig); + } else { + throw new IllegalArgumentException("CommandAPISpigot was loaded with non-Spigot config!"); + } + + // Default to MockCommandAPIBukkit if not given + CommandAPIPlatform platform = alternativePlatform == null ? + new MockCommandAPISpigot(internalSpigotConfig) : + alternativePlatform.apply(internalSpigotConfig); + + // Reset to avoid platform persisting between tests + alternativePlatform = null; + + return new LoadContext(platform); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPlugin.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java similarity index 73% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPlugin.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java index f6ce39480..861518d9f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPlugin.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java @@ -1,6 +1,5 @@ package dev.jorel.commandapi; -import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; import org.mockbukkit.mockbukkit.MockBukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -12,7 +11,7 @@ public class MockCommandAPIPlugin extends JavaPlugin { // Allow loading with settings, // Default to none if `MockBukkit.load(MockCommandAPIPlugin.class)` is used directly - private static Consumer> configureSettings = null; + private static Consumer configureSettings = null; /** * Loads the CommandAPI plugin using {@link MockBukkit#load(Class)}. @@ -26,18 +25,18 @@ public static MockCommandAPIPlugin load() { /** * Loads the CommandAPI plugin using {@link MockBukkit#load(Class)}. * - * @param configureSettings A {@link Consumer} that can configure the settings of the {@link dev.jorel.commandapi.CommandAPIPaperConfig} + * @param configureSettings A {@link Consumer} that can configure the settings of the {@link CommandAPISpigotConfig} * before it is used to load the CommandAPI plugin. * @return The {@link MockCommandAPIPlugin} instance that was loaded. */ - public static MockCommandAPIPlugin load(Consumer> configureSettings) { + public static MockCommandAPIPlugin load(Consumer configureSettings) { MockCommandAPIPlugin.configureSettings = configureSettings; return MockBukkit.load(MockCommandAPIPlugin.class); } @Override public void onLoad() { - CommandAPIPaperConfig config = new CommandAPIPaperConfig<>(this.getPluginMeta(), this); + CommandAPISpigotConfig config = new CommandAPISpigotConfig(this); if (configureSettings != null) { configureSettings.accept(config); @@ -49,7 +48,7 @@ public void onLoad() { @Override public void onEnable() { - CommandAPIPaper.onEnable(this); + CommandAPI.onEnable(); } @Override diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPISpigot.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPISpigot.java new file mode 100644 index 000000000..28dc93433 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPISpigot.java @@ -0,0 +1,47 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.nms.MockNMS; +import dev.jorel.commandapi.nms.MockSpigotNMS; +import dev.jorel.commandapi.nms.NMS; + +/** + * An implementation of {@link CommandAPISpigot} that is compatible with a MockBukkit testing environment. + * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. + */ +public class MockCommandAPISpigot extends CommandAPISpigot implements MockSpigotNMS { + // References to utility classes + private MockNMS mockNMS; + private final MockCommandAPI mockCommandAPI; + + public MockCommandAPISpigot(InternalSpigotConfig config) { + super(config); + this.mockCommandAPI = new MockCommandAPI(this); + } + + // Load + @Override + public void onLoad() { + mockCommandAPI.onLoad(); + + super.onLoad(); + } + + // Test environment-specific + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return mockCommandAPI.getCommandRegistrationStrategy(); + } + + @Override + public NMS bukkitNMS() { + if (mockNMS == null) { + this.mockNMS = new MockNMS(); + } + return mockNMS; + } + + @Override + public CommandAPILogger getLogger() { + return MockCommandAPI.ENABLE_LOGGING ? super.getLogger() : CommandAPILogger.silent(); + } +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockSpigotNMS.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockSpigotNMS.java new file mode 100644 index 000000000..9c15eaa89 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockSpigotNMS.java @@ -0,0 +1,38 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.MockCommandSource; +import dev.jorel.commandapi.UnimplementedMethodException; +import dev.jorel.commandapi.arguments.ProfileArgumentType; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.ChatColor; +import org.bukkit.profile.PlayerProfile; + +import java.util.List; + +public interface MockSpigotNMS extends SpigotNMS { + // Arguments + @Override + default List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ProfileArgumentType.getProfiles(cmdCtx, key); + } + + /////////////////////////// + // UNIMPLEMENTED METHODS // + /////////////////////////// + @Override + default BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + default ChatColor getChatColor(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + default BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java new file mode 100644 index 000000000..8a18e091e --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java @@ -0,0 +1,58 @@ +package dev.jorel.commandapi; + +import org.mockbukkit.mockbukkit.MockBukkit; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests for using {@link CommandAPIVersionHandler#usePlatformImplementation(Function)} + */ +class CommandAPIVersionHandlerOverridingTests extends CommandAPITestUtilities { + // Setup + @BeforeEach + public void setUp() { + MockBukkit.mock(); + } + + @AfterEach + public void tearDown() { + MockBukkit.unmock(); + } + + private static class CustomMockCommandAPISpigot extends MockCommandAPISpigot { + public CustomMockCommandAPISpigot(InternalSpigotConfig config) { + super(config); + } + } + + // Tests + @Test + void testDefaultPlatform() { + MockCommandAPIPlugin.load(); + + assertEquals(MockCommandAPISpigot.class, getMockCommandAPI().getCommandAPIBukkit().getClass()); + } + + @Test + void testChangingPlatform() { + CommandAPIVersionHandler.usePlatformImplementation(CustomMockCommandAPISpigot::new); + MockCommandAPIPlugin.load(); + + assertEquals(CustomMockCommandAPISpigot.class, getMockCommandAPI().getCommandAPIBukkit().getClass()); + } + + @Test + void testPlatformDoesNotPersist() { + testChangingPlatform(); + + MockBukkit.unmock(); + MockBukkit.mock(); + + testDefaultPlatform(); + } +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java new file mode 100644 index 000000000..9d7a48c24 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java @@ -0,0 +1,80 @@ +package dev.jorel.commandapi; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.context.CommandContextBuilder; +import com.mojang.brigadier.context.ParsedArgument; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.arguments.parser.Parser; +import dev.jorel.commandapi.arguments.parser.ParserArgument; +import dev.jorel.commandapi.executors.CommandExecutionInfo; +import org.bukkit.command.CommandSender; +import org.junit.jupiter.api.function.Executable; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.opentest4j.AssertionFailedError; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public abstract class CommandTestBase extends CommandAPITestUtilities { + // Useful objects + public static CommandExecutionInfo DEFAULT_EXECUTOR = info -> {}; + + // Setup + protected ServerMock server; + protected MockCommandAPIPlugin plugin; + + public void setUp() { + server = MockBukkit.mock(); + plugin = MockBukkit.load(MockCommandAPIPlugin.class); + } + + public void tearDown() { + MockBukkit.unmock(); + } + + // Additional test utilities + @CanIgnoreReturnValue + public T assertThrowsWithMessage(Class exceptionClass, Executable executable, String expectedMessage) { + T exception = assertThrows(exceptionClass, executable); + String actualMessage = exception.getMessage(); + if (!expectedMessage.equals(actualMessage)) { + throw new AssertionFailedError( + "Exception messages did not match. Expected <" + expectedMessage + "> but was <" + actualMessage + ">.", + expectedMessage, actualMessage, exception + ); + } + return exception; + } + + @CanIgnoreReturnValue + public AssertionFailedError assertAssertionFails(Executable executable, String expectedMessage) { + return assertThrowsWithMessage(AssertionFailedError.class, executable, expectedMessage); + } + + public CommandContext createContextWithParser( + CommandSender source, String key, Parser parser, String input + ) throws CommandSyntaxException { + CommandDispatcher dispatcher = getMockCommandAPI().getCommandAPIBukkit().getBrigadierDispatcher(); + CommandContextBuilder contextBuilder = new CommandContextBuilder<>( + dispatcher, + new MockCommandSource(source), + dispatcher.getRoot(), + 0 + ); + + StringReader reader = new StringReader(input); + T result = parser.parse(reader); + contextBuilder.withArgument(key, new ParsedArgument<>(0, reader.getCursor(), result)); + + return contextBuilder.build(input); + } + + public CommandContext createContextWithParser( + CommandSender source, String key, ParserArgument parser, String input + ) throws CommandSyntaxException { + return createContextWithParser(source, key, (Parser) parser, input); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPluginLoadingTests.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPluginLoadingTests.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/MockCommandAPIPluginLoadingTests.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPluginLoadingTests.java diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/ProfileArgumentTypeTests.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java similarity index 71% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/ProfileArgumentTypeTests.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java index 2b468970e..739f9c2f2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/old/ProfileArgumentTypeTests.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java @@ -1,16 +1,20 @@ package dev.jorel.commandapi.arguments; -import org.mockbukkit.mockbukkit.command.ConsoleCommandSenderMock; -import org.mockbukkit.mockbukkit.entity.PlayerMock; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandTestBase; import dev.jorel.commandapi.MockCommandSource; +import org.bukkit.entity.Player; +import org.bukkit.profile.PlayerProfile; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.command.ConsoleCommandSenderMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; + +import java.util.ArrayList; +import java.util.List; class ProfileArgumentTypeTests extends CommandTestBase { // Setup @@ -24,23 +28,26 @@ public void tearDown() { super.tearDown(); } - private void registerCommand(boolean offlinePlayer) { - // Both arguments reference ProfileArgumentType + private void registerCommand() { new CommandAPICommand("test") - .withArguments( - offlinePlayer ? - new OfflinePlayerArgument("offline") : - new PlayerProfileArgument("player") - ) + .withArguments(new PlayerProfileArgument("player")) .executes(DEFAULT_EXECUTOR) .register(); } + private List profileList(Player... players) { + List profileList = new ArrayList<>(players.length); + for (Player player : players) { + profileList.add(player.getPlayerProfile()); + } + + return profileList; + } + // Test - @ParameterizedTest - @ValueSource(booleans = {false, true}) - void testEmptyInputs(boolean offlinePlayer) throws CommandSyntaxException { - registerCommand(offlinePlayer); + @Test + void testEmptyInputs() throws CommandSyntaxException { + registerCommand(); PlayerMock player = server.addPlayer(); @@ -65,10 +72,9 @@ void testEmptyInputs(boolean offlinePlayer) throws CommandSyntaxException { ); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - void testDefaultSuggestions(boolean offlinePlayer) { - registerCommand(offlinePlayer); + @Test + void testDefaultSuggestions() { + registerCommand(); server.addPlayer("Player1"); server.addPlayer("Player2"); @@ -88,10 +94,9 @@ void testDefaultSuggestions(boolean offlinePlayer) { ); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - void testEntitySelectorErrors(boolean offlinePlayer) { - registerCommand(offlinePlayer); + @Test + void testEntitySelectorErrors() { + registerCommand(); ConsoleCommandSenderMock console = server.getConsoleSender(); assertCommandFails( @@ -110,10 +115,9 @@ void testEntitySelectorErrors(boolean offlinePlayer) { ); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - void testEntitySelectorSuccess(boolean offlinePlayer) { - registerCommand(offlinePlayer); + @Test + void testEntitySelectorSuccess() { + registerCommand(); // Layout: p1 p2 PlayerMock p1 = server.addPlayer(); @@ -122,32 +126,30 @@ void testEntitySelectorSuccess(boolean offlinePlayer) { PlayerMock p2 = server.addPlayer(); p2.teleport(p2.getLocation().set(1, 0, 0)); - // When multiple are selected, defaults to first in order - // Arbitrary order ends up selecting first player, since it references a LinkedHashSet + // Arbitrary order uses creation order, since it references a LinkedHashSet assertCommandSucceedsWithArguments( p1, "test @a", - p1 + profileList(p1, p2) ); assertCommandSucceedsWithArguments( p2, "test @a", - p1 + profileList(p1, p2) ); // @p selects nearest assertCommandSucceedsWithArguments( p1, "test @p", - p1 + profileList(p1) ); assertCommandSucceedsWithArguments( p2, "test @p", - p2 + profileList(p2) ); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - void testEntitySelectorSuggestions(boolean offlinePlayer) { - registerCommand(offlinePlayer); + @Test + void testEntitySelectorSuggestions() { + registerCommand(); server.addPlayer("Player1"); server.addPlayer("Player2"); @@ -165,10 +167,9 @@ void testEntitySelectorSuggestions(boolean offlinePlayer) { ); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - void testNameSelectorErrors(boolean offlinePlayer) { - registerCommand(offlinePlayer); + @Test + void testNameSelectorErrors() { + registerCommand(); PlayerMock playerA = server.addPlayer("PlayerA"); @@ -178,10 +179,9 @@ void testNameSelectorErrors(boolean offlinePlayer) { ); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - void testNameSelectorSuccess(boolean offlinePlayer) { - registerCommand(offlinePlayer); + @Test + void testNameSelectorSuccess() { + registerCommand(); PlayerMock playerA = server.addPlayer("PlayerA"); PlayerMock playerB = server.addPlayer("PlayerB"); @@ -190,24 +190,23 @@ void testNameSelectorSuccess(boolean offlinePlayer) { assertCommandSucceedsWithArguments( console, "test PlayerA", - playerA + profileList(playerA) ); assertCommandSucceedsWithArguments( console, "test PlayerB", - playerB + profileList(playerB) ); // Not case-sensitive assertCommandSucceedsWithArguments( console, "test pLAyeRa", - playerA + profileList(playerA) ); } - @ParameterizedTest - @ValueSource(booleans = {false, true}) - void testNameSuggestions(boolean offlinePlayer) { - registerCommand(offlinePlayer); + @Test + void testNameSuggestions() { + registerCommand(); server.addPlayer("alice"); server.addPlayer("allan"); diff --git a/commandapi-platforms/commandapi-spigot/pom.xml b/commandapi-platforms/commandapi-spigot/pom.xml index 438521ed3..cc919858d 100644 --- a/commandapi-platforms/commandapi-spigot/pom.xml +++ b/commandapi-platforms/commandapi-spigot/pom.xml @@ -20,8 +20,9 @@ commandapi-spigot-vh commandapi-spigot-plugin commandapi-spigot-shade + commandapi-spigot-test-toolkit - + org.spigotmc spigot-api @@ -52,7 +51,7 @@ Key points: public class Main extends JavaPlugin { @Override public void onLoad() { - CommandAPI.onLoad(new CommandAPIBukkitConfig(this)); + CommandAPI.onLoad(new CommandAPISpigotConfig(this)); } @Override diff --git a/examples/bukkit/automated-tests-shaded/pom.xml b/examples/bukkit/automated-tests-shaded/pom.xml index ffb8e91be..4f859be2d 100644 --- a/examples/bukkit/automated-tests-shaded/pom.xml +++ b/examples/bukkit/automated-tests-shaded/pom.xml @@ -21,17 +21,17 @@ - com.github.seeseemelk - MockBukkit-v1.21 - 3.133.2 - test + org.mockbukkit.mockbukkit + mockbukkit-v1.21 + 4.45.1 + provided dev.jorel - commandapi-bukkit-test-toolkit + commandapi-spigot-test-toolkit 11.0.0-SNAPSHOT test @@ -39,13 +39,12 @@ dev.jorel - commandapi-bukkit-shade + commandapi-spigot-shade 11.0.0-SNAPSHOT compile - org.spigotmc spigot-api diff --git a/examples/bukkit/automated-tests-shaded/src/main/java/io/github/jorelali/Main.java b/examples/bukkit/automated-tests-shaded/src/main/java/io/github/jorelali/Main.java index 3734b8770..5c29abe06 100644 --- a/examples/bukkit/automated-tests-shaded/src/main/java/io/github/jorelali/Main.java +++ b/examples/bukkit/automated-tests-shaded/src/main/java/io/github/jorelali/Main.java @@ -1,9 +1,6 @@ package io.github.jorelali; -import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPIBukkitConfig; -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.Tooltip; +import dev.jorel.commandapi.*; import dev.jorel.commandapi.arguments.IntegerArgument; import dev.jorel.commandapi.arguments.IntegerRangeArgument; import dev.jorel.commandapi.arguments.SafeSuggestions; @@ -14,7 +11,7 @@ public class Main extends JavaPlugin { @Override public void onLoad() { // Load CommandAPI as usual - CommandAPI.onLoad(new CommandAPIBukkitConfig(this)); + CommandAPI.onLoad(new CommandAPISpigotConfig(this)); } @Override diff --git a/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/PingPongCommandTests.java b/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/PingPongCommandTests.java index b0e9cc353..403b86d8f 100644 --- a/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/PingPongCommandTests.java +++ b/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/PingPongCommandTests.java @@ -1,15 +1,19 @@ package io.github.jorelali; -import be.seeseemelk.mockbukkit.MockBukkit; -import be.seeseemelk.mockbukkit.ServerMock; -import be.seeseemelk.mockbukkit.entity.PlayerMock; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; // Import helper methods from CommandAPITestUtilities import static dev.jorel.commandapi.CommandAPITestUtilities.assertCommandSucceeds; +// Import MockBukkit assertions +import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedAnyMessageMatcher.hasNotReceivedAny; +import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedMessageMatcher.hasReceived; + class PingPongCommandTests { // Setup private ServerMock server; @@ -36,7 +40,7 @@ void runCommand() { assertCommandSucceeds(player, "ping"); - player.assertSaid("pong!"); - player.assertNoMoreSaid(); + hasReceived("pong!").matches(player); + hasNotReceivedAny().matches(player); } } diff --git a/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/RangeCheckTests.java b/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/RangeCheckTests.java index 091b8d5cc..56ea76374 100644 --- a/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/RangeCheckTests.java +++ b/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/RangeCheckTests.java @@ -1,18 +1,21 @@ package io.github.jorelali; -import be.seeseemelk.mockbukkit.MockBukkit; -import be.seeseemelk.mockbukkit.ServerMock; -import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.CommandAPITestUtilities; -import dev.jorel.commandapi.MockCommandAPIPlugin; import dev.jorel.commandapi.wrappers.IntegerRange; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; import java.util.List; import java.util.Map; +// Import MockBukkit assertions +import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedAnyMessageMatcher.hasNotReceivedAny; +import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedMessageMatcher.hasReceived; + // Access helper methods by extending CommandAPITestUtilities public class RangeCheckTests extends CommandAPITestUtilities { // Setup @@ -40,14 +43,14 @@ public void tearDown() { void testCommandExecution() { // Testing successful usage of command assertCommandSucceeds(player, "rangecheck 10..15 13"); - player.assertSaid("Number 13 is within range 10..15"); + hasReceived("Number 13 is within range 10..15").matches(player); assertCommandSucceedsWithArguments( player, "rangecheck 10..15 10", // Verifying argument array new IntegerRange(10, 15), 10 ); - player.assertSaid("Number 10 is within range 10..15"); + hasReceived("Number 10 is within range 10..15").matches(player); assertCommandSucceedsWithArguments( player, "rangecheck -3..-3 -3", @@ -57,7 +60,7 @@ void testCommandExecution() { "number", -3 ) ); - player.assertSaid("Number -3 is within range -3..-3"); + hasReceived("Number -3 is within range -3..-3").matches(player); // Test unsuccessful usage of command assertCommandFails( @@ -81,6 +84,9 @@ void testCommandExecution() { "number", 10 ) ); + + // Make sure no extra messages were sent + hasNotReceivedAny().matches(player); } @Test diff --git a/examples/bukkit/automated-tests/README.md b/examples/bukkit/automated-tests/README.md index d50e91e6c..f9470a415 100644 --- a/examples/bukkit/automated-tests/README.md +++ b/examples/bukkit/automated-tests/README.md @@ -4,32 +4,31 @@ A simple example showcasing testing CommandAPI commands with [MockBukkit](https: Key points: -- The MockBukkit and `commandapi-bukkit-test-toolkit` dependencies are listed with the `test` scope before the normal dependencies for `commandapi-bukkit-core` and `spigot-api`. This ensures that when running tests, certain classes that are compatible with the testing environment override the regular classes. There is also a dependency for the [JUnit](https://junit.org/junit5/) API, which helps when writing the tests. +- The MockBukkit and `commandapi-spigot-test-toolkit` dependencies are listed with the `test` scope before the normal dependencies for `commandapi-spigot-core` and `spigot-api`. This ensures that when running tests, certain classes that are compatible with the testing environment override the regular classes. There is also a dependency for the [JUnit](https://junit.org/junit5/) API, which helps when writing the tests. ```xml - com.github.seeseemelk - MockBukkit-v1.21 - 3.128.0 + org.mockbukkit.mockbukkit + mockbukkit-v1.21 + 4.45.1 test dev.jorel - commandapi-bukkit-test-toolkit + commandapi-spigot-test-toolkit 11.0.0-SNAPSHOT test dev.jorel - commandapi-bukkit-core + commandapi-spigot-core 11.0.0-SNAPSHOT provided - org.spigotmc spigot-api diff --git a/examples/bukkit/automated-tests/pom.xml b/examples/bukkit/automated-tests/pom.xml index 46fb1674a..46640d3fb 100644 --- a/examples/bukkit/automated-tests/pom.xml +++ b/examples/bukkit/automated-tests/pom.xml @@ -21,9 +21,9 @@ - com.github.seeseemelk - MockBukkit-v1.21 - 3.133.2 + org.mockbukkit.mockbukkit + mockbukkit-v1.21 + 4.45.1 test @@ -31,7 +31,7 @@ dev.jorel - commandapi-bukkit-test-toolkit + commandapi-spigot-test-toolkit 11.0.0-SNAPSHOT test @@ -39,13 +39,12 @@ dev.jorel - commandapi-bukkit-core + commandapi-spigot-core 11.0.0-SNAPSHOT provided - org.spigotmc spigot-api diff --git a/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/PingPongCommandTests.java b/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/PingPongCommandTests.java index 9f32dd065..40699a135 100644 --- a/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/PingPongCommandTests.java +++ b/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/PingPongCommandTests.java @@ -1,16 +1,20 @@ package io.github.jorelali; -import be.seeseemelk.mockbukkit.MockBukkit; -import be.seeseemelk.mockbukkit.ServerMock; -import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.MockCommandAPIPlugin; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; // Import helper methods from CommandAPITestUtilities import static dev.jorel.commandapi.CommandAPITestUtilities.assertCommandSucceeds; +// Import MockBukkit assertions +import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedAnyMessageMatcher.hasNotReceivedAny; +import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedMessageMatcher.hasReceived; + class PingPongCommandTests { // Setup private ServerMock server; @@ -40,7 +44,7 @@ void runCommand() { assertCommandSucceeds(player, "ping"); - player.assertSaid("pong!"); - player.assertNoMoreSaid(); + hasReceived("pong!").matches(player); + hasNotReceivedAny().matches(player); } } diff --git a/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/RangeCheckTests.java b/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/RangeCheckTests.java index 523d57cf0..b4b945e7d 100644 --- a/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/RangeCheckTests.java +++ b/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/RangeCheckTests.java @@ -1,18 +1,22 @@ package io.github.jorelali; -import be.seeseemelk.mockbukkit.MockBukkit; -import be.seeseemelk.mockbukkit.ServerMock; -import be.seeseemelk.mockbukkit.entity.PlayerMock; import dev.jorel.commandapi.CommandAPITestUtilities; import dev.jorel.commandapi.MockCommandAPIPlugin; import dev.jorel.commandapi.wrappers.IntegerRange; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; import java.util.List; import java.util.Map; +// Import MockBukkit assertions +import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedAnyMessageMatcher.hasNotReceivedAny; +import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedMessageMatcher.hasReceived; + // Access helper methods by extending CommandAPITestUtilities public class RangeCheckTests extends CommandAPITestUtilities { // Setup @@ -43,14 +47,14 @@ public void tearDown() { void testCommandExecution() { // Testing successful usage of command assertCommandSucceeds(player, "rangecheck 10..15 13"); - player.assertSaid("Number 13 is within range 10..15"); + hasReceived("Number 13 is within range 10..15").matches(player); assertCommandSucceedsWithArguments( player, "rangecheck 10..15 10", // Verifying argument array new IntegerRange(10, 15), 10 ); - player.assertSaid("Number 10 is within range 10..15"); + hasReceived("Number 10 is within range 10..15").matches(player); assertCommandSucceedsWithArguments( player, "rangecheck -3..-3 -3", @@ -60,7 +64,7 @@ void testCommandExecution() { "number", -3 ) ); - player.assertSaid("Number -3 is within range -3..-3"); + hasReceived("Number -3 is within range -3..-3").matches(player); // Test unsuccessful usage of command assertCommandFails( @@ -84,6 +88,9 @@ void testCommandExecution() { "number", 10 ) ); + + // Make sure no extra messages were sent + hasNotReceivedAny().matches(player); } @Test diff --git a/examples/bukkit/commandtrees/pom.xml b/examples/bukkit/commandtrees/pom.xml index e8dd378d2..a148d9392 100644 --- a/examples/bukkit/commandtrees/pom.xml +++ b/examples/bukkit/commandtrees/pom.xml @@ -12,7 +12,7 @@ papermc - https://papermc.io/repo/repository/maven-public/ + https://repo.papermc.io/repository/maven-public/ diff --git a/examples/bukkit/gradle-groovy/README.md b/examples/bukkit/gradle-groovy/README.md index fc4f3737c..677730dff 100644 --- a/examples/bukkit/gradle-groovy/README.md +++ b/examples/bukkit/gradle-groovy/README.md @@ -4,10 +4,10 @@ A simple example of making a plugin that uses the CommandAPI with Maven. Key points: -- The `commandapi-bukkit-plugin` dependency is used: +- The `commandapi-paper-plugin` dependency is used: ```groovy - implementation 'dev.jorel:commandapi-bukkit-plugin:10.2.0-SNAPSHOT' + implementation 'dev.jorel:commandapi-paper-plugin:11.0.0-SNAPSHOT' ``` - In the plugin.yml, CommandAPI is listed as a depend: diff --git a/examples/bukkit/gradle-groovy/build.gradle b/examples/bukkit/gradle-groovy/build.gradle index 97d56d058..32fe872c3 100644 --- a/examples/bukkit/gradle-groovy/build.gradle +++ b/examples/bukkit/gradle-groovy/build.gradle @@ -16,11 +16,11 @@ repositories { mavenCentral() // This adds the Spigot Maven repository to the build maven { - url 'https://papermc.io/repo/repository/maven-public/' + url = 'https://repo.papermc.io/repository/maven-public/' } // CodeMC repository for the NBT API maven { - url 'https://repo.codemc.org/repository/maven-public/' + url = 'https://repo.codemc.org/repository/maven-public/' } } diff --git a/examples/bukkit/gradle-kotlin/README.md b/examples/bukkit/gradle-kotlin/README.md index ee9040471..ca670bef8 100644 --- a/examples/bukkit/gradle-kotlin/README.md +++ b/examples/bukkit/gradle-kotlin/README.md @@ -4,10 +4,10 @@ A simple example of making a plugin that uses the CommandAPI with Maven. Key points: -- The `commandapi-bukkit-plugin` dependency is used: +- The `commandapi-paper-plugin` dependency is used: ```kotlin - implementation("dev.jorel:commandapi-bukkit-plugin:10.2.0-SNAPSHOT") + implementation("dev.jorel:commandapi-paper-plugin:11.0.0-SNAPSHOT") ``` - In the plugin.yml, CommandAPI is listed as a depend: diff --git a/examples/bukkit/gradle-kotlin/build.gradle.kts b/examples/bukkit/gradle-kotlin/build.gradle.kts index f3d4374a9..de61544e6 100644 --- a/examples/bukkit/gradle-kotlin/build.gradle.kts +++ b/examples/bukkit/gradle-kotlin/build.gradle.kts @@ -15,7 +15,7 @@ repositories { // Use Maven Central for resolving dependencies. mavenCentral() // This adds the Paper Maven repository to the build - maven("https://papermc.io/repo/repository/maven-public/") + maven("https://repo.papermc.io/repository/maven-public/") // CodeMC repository for the NBT API maven("https://repo.codemc.org/repository/maven-public/") } diff --git a/examples/bukkit/kotlindsl-gradle/README.md b/examples/bukkit/kotlindsl-gradle/README.md index dc5fa7800..a7159747e 100644 --- a/examples/bukkit/kotlindsl-gradle/README.md +++ b/examples/bukkit/kotlindsl-gradle/README.md @@ -6,10 +6,10 @@ Key points: - You do not need to use the `.register()` method - You do not need to initialise any arguments. -- Add the `commandapi-kotlin-bukkit` dependency to your project: +- Add the `commandapi-kotlin-paper` dependency to your project: ```kotlin - compileOnly("dev.jorel:commandapi-bukkit-kotlin:10.2.0-SNAPSHOT") + compileOnly("dev.jorel:commandapi-kotlin-paper:11.0.0-SNAPSHOT") ``` - The Kotlin DSL must not be shaded into your plugin diff --git a/examples/bukkit/kotlindsl-gradle/build.gradle.kts b/examples/bukkit/kotlindsl-gradle/build.gradle.kts index f14256045..bf70e2504 100644 --- a/examples/bukkit/kotlindsl-gradle/build.gradle.kts +++ b/examples/bukkit/kotlindsl-gradle/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("jvm") version "1.8.20" + kotlin("jvm") version "2.2.10" } kotlin { @@ -12,7 +12,7 @@ repositories { // Use Maven Central for resolving dependencies. mavenCentral() // This adds the Paper Maven repository to the build - maven("https://papermc.io/repo/repository/maven-public/") + maven("https://repo.papermc.io/repository/maven-public/") } dependencies { diff --git a/examples/bukkit/kotlindsl-gradle/src/main/kotlin/io/github/jorelali/SayHelloCommand.kt b/examples/bukkit/kotlindsl-gradle/src/main/kotlin/io/github/jorelali/SayHelloCommand.kt index e0db0957f..acaed0c3c 100644 --- a/examples/bukkit/kotlindsl-gradle/src/main/kotlin/io/github/jorelali/SayHelloCommand.kt +++ b/examples/bukkit/kotlindsl-gradle/src/main/kotlin/io/github/jorelali/SayHelloCommand.kt @@ -7,7 +7,7 @@ class SayHelloCommand { fun register() { commandTree("sayhello") { - playerArgument("target") { + entitySelectorArgumentOnePlayer("target") { playerExecutor { player, args -> val target: Player = args[0] as Player target.sendMessage("§6${player.name} says hello to you!") diff --git a/examples/bukkit/kotlindsl/README.md b/examples/bukkit/kotlindsl/README.md index 0f5ec3773..78a602999 100644 --- a/examples/bukkit/kotlindsl/README.md +++ b/examples/bukkit/kotlindsl/README.md @@ -6,12 +6,12 @@ Key points: - You do not need to use the `.register()` method - You do not need to initialise any arguments. -- Add the `commandapi-kotlin-bukkit` dependency to your project: +- Add the `commandapi-kotlin-paper` dependency to your project: ```xml dev.jorel - commandapi-kotlin-bukkit + commandapi-kotlin-paper 11.0.0-SNAPSHOT ``` diff --git a/examples/bukkit/kotlindsl/pom.xml b/examples/bukkit/kotlindsl/pom.xml index a19f9e3c4..d51b475d9 100644 --- a/examples/bukkit/kotlindsl/pom.xml +++ b/examples/bukkit/kotlindsl/pom.xml @@ -13,7 +13,7 @@ papermc - https://papermc.io/repo/repository/maven-public/ + https://repo.papermc.io/repository/maven-public/ diff --git a/examples/bukkit/kotlindsl/src/main/kotlin/io/github/jorelali/SayHelloCommand.kt b/examples/bukkit/kotlindsl/src/main/kotlin/io/github/jorelali/SayHelloCommand.kt index 0259cf8b9..8842e69b1 100644 --- a/examples/bukkit/kotlindsl/src/main/kotlin/io/github/jorelali/SayHelloCommand.kt +++ b/examples/bukkit/kotlindsl/src/main/kotlin/io/github/jorelali/SayHelloCommand.kt @@ -7,7 +7,7 @@ class SayHelloCommand { fun register() { commandTree("sayhello") { - playerArgument("target") { + entitySelectorArgumentOnePlayer("target") { playerExecutor { player, args -> val target: Player = args[0] as Player target.sendMessage("§6${player.name} says hello to you!") diff --git a/examples/bukkit/maven-annotations/README.md b/examples/bukkit/maven-annotations/README.md index 1d03a3b79..0dedfab69 100644 --- a/examples/bukkit/maven-annotations/README.md +++ b/examples/bukkit/maven-annotations/README.md @@ -4,19 +4,19 @@ A simple example of making a plugin that uses the CommandAPI with Maven. Key points: -- The `commandapi-bukkit-plugin` and `commandapi-annotations` dependencies are both added with the provided scope: +- The `commandapi-paper-plugin` and `commandapi-paper-annotations` dependencies are both added with the provided scope: ```xml dev.jorel - commandapi-bukkit-plugin + commandapi-paper-plugin 11.0.0-SNAPSHOT provided dev.jorel - commandapi-annotations + commandapi-paper-annotations 11.0.0-SNAPSHOT provided diff --git a/examples/bukkit/maven-annotations/pom.xml b/examples/bukkit/maven-annotations/pom.xml index c49d942d6..3d21c9989 100644 --- a/examples/bukkit/maven-annotations/pom.xml +++ b/examples/bukkit/maven-annotations/pom.xml @@ -12,7 +12,7 @@ papermc - https://papermc.io/repo/repository/maven-public/ + https://repo.papermc.io/repository/maven-public/ diff --git a/examples/bukkit/maven-annotations/src/main/java/io/github/jorelali/EffectCommand.java b/examples/bukkit/maven-annotations/src/main/java/io/github/jorelali/EffectCommand.java index 1103aa9e9..f8e308d81 100644 --- a/examples/bukkit/maven-annotations/src/main/java/io/github/jorelali/EffectCommand.java +++ b/examples/bukkit/maven-annotations/src/main/java/io/github/jorelali/EffectCommand.java @@ -2,7 +2,7 @@ import dev.jorel.commandapi.annotations.Command; import dev.jorel.commandapi.annotations.Default; -import dev.jorel.commandapi.annotations.arguments.APlayerArgument; +import dev.jorel.commandapi.annotations.arguments.AEntitySelectorArgument; import dev.jorel.commandapi.annotations.arguments.APotionEffectArgument; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -17,7 +17,7 @@ public static void applyEffect(Player player, @APotionEffectArgument PotionEffec } @Default - public static void applyEffect(CommandSender sender, @APotionEffectArgument PotionEffectType effectType, @APlayerArgument Player player) { + public static void applyEffect(CommandSender sender, @APotionEffectArgument PotionEffectType effectType, @AEntitySelectorArgument.OnePlayer Player player) { player.addPotionEffect(new PotionEffect(effectType, 300 * 20, 1)); } } diff --git a/examples/bukkit/maven-shaded-annotations/README.md b/examples/bukkit/maven-shaded-annotations/README.md index 4fb22edc8..c53013e48 100644 --- a/examples/bukkit/maven-shaded-annotations/README.md +++ b/examples/bukkit/maven-shaded-annotations/README.md @@ -4,18 +4,18 @@ A simple example of making a plugin that uses the CommandAPI with Maven. Key points: -- The `commandapi-bukkit-shade` and `commandapi-annotations` dependencies are both added, with annotations having the provided scope: +- The `commandapi-paper-shade` and `commandapi-paper-annotations` dependencies are both added, with annotations having the provided scope: ```xml dev.jorel - commandapi-bukkit-shade + commandapi-paper-shade 11.0.0-SNAPSHOT dev.jorel - commandapi-annotations + commandapi-paper-annotations 11.0.0-SNAPSHOT provided diff --git a/examples/bukkit/maven-shaded-annotations/pom.xml b/examples/bukkit/maven-shaded-annotations/pom.xml index 01da54996..30d018e66 100644 --- a/examples/bukkit/maven-shaded-annotations/pom.xml +++ b/examples/bukkit/maven-shaded-annotations/pom.xml @@ -12,7 +12,7 @@ papermc - https://papermc.io/repo/repository/maven-public/ + https://repo.papermc.io/repository/maven-public/ @@ -34,7 +34,7 @@ dev.jorel - commandapi-annotations + commandapi-paper-annotations 11.0.0-SNAPSHOT provided @@ -43,7 +43,7 @@ io.papermc.paper paper-api - 1.20.1-R0.1-SNAPSHOT + 1.21.8-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/EffectCommand.java b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/EffectCommand.java index 1103aa9e9..f8e308d81 100644 --- a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/EffectCommand.java +++ b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/EffectCommand.java @@ -2,7 +2,7 @@ import dev.jorel.commandapi.annotations.Command; import dev.jorel.commandapi.annotations.Default; -import dev.jorel.commandapi.annotations.arguments.APlayerArgument; +import dev.jorel.commandapi.annotations.arguments.AEntitySelectorArgument; import dev.jorel.commandapi.annotations.arguments.APotionEffectArgument; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -17,7 +17,7 @@ public static void applyEffect(Player player, @APotionEffectArgument PotionEffec } @Default - public static void applyEffect(CommandSender sender, @APotionEffectArgument PotionEffectType effectType, @APlayerArgument Player player) { + public static void applyEffect(CommandSender sender, @APotionEffectArgument PotionEffectType effectType, @AEntitySelectorArgument.OnePlayer Player player) { player.addPotionEffect(new PotionEffect(effectType, 300 * 20, 1)); } } diff --git a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java index cf145a0bd..c8417227d 100644 --- a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java +++ b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/Main.java @@ -2,7 +2,6 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIPaperConfig; -import dev.jorel.commandapi.CommandAPIConfig; import dev.jorel.commandapi.CommandAPILogger; import org.bukkit.plugin.java.JavaPlugin; diff --git a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/WarpCommand.java b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/WarpCommand.java index b41148f71..2d6cac0cc 100644 --- a/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/WarpCommand.java +++ b/examples/bukkit/maven-shaded-annotations/src/main/java/io/github/jorelali/WarpCommand.java @@ -1,20 +1,14 @@ package io.github.jorelali; -import java.util.HashMap; -import java.util.Map; - +import dev.jorel.commandapi.annotations.*; +import dev.jorel.commandapi.annotations.arguments.AEntitySelectorArgument; +import dev.jorel.commandapi.annotations.arguments.AStringArgument; import org.bukkit.Location; -import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import dev.jorel.commandapi.annotations.Command; -import dev.jorel.commandapi.annotations.Default; -import dev.jorel.commandapi.annotations.Help; -import dev.jorel.commandapi.annotations.Permission; -import dev.jorel.commandapi.annotations.Subcommand; -import dev.jorel.commandapi.annotations.arguments.APlayerArgument; -import dev.jorel.commandapi.annotations.arguments.AStringArgument; +import java.util.HashMap; +import java.util.Map; @Command("warp") @Help(value = "Manages all warps on the server", shortDescription = "Manages warps") @@ -43,12 +37,10 @@ public static void createWarp(Player player, @AStringArgument String warpName) { warps.put(warpName, player.getLocation()); } - @Subcommand("create") - @Permission("warps.create") - public static void tpWarp(CommandSender sender, @APlayerArgument OfflinePlayer target, @AStringArgument String warpName) { - if (target.isOnline() && target instanceof Player onlineTarget) { - onlineTarget.teleport(warps.get(warpName)); - } + @Subcommand("tp") + @Permission("warps.tp") + public static void tpWarp(CommandSender sender, @AEntitySelectorArgument.OnePlayer Player target, @AStringArgument String warpName) { + target.teleport(warps.get(warpName)); } } \ No newline at end of file diff --git a/examples/bukkit/maven-shaded-tests/README.md b/examples/bukkit/maven-shaded-tests/README.md deleted file mode 100644 index 911201add..000000000 --- a/examples/bukkit/maven-shaded-tests/README.md +++ /dev/null @@ -1,142 +0,0 @@ -# Maven-shaded-tests - -An example showcasing using MockBukkit and the CommandAPI testing suite to test commands registered using the CommandAPI. - -> **Dev note:** -> -> Testing using the CommandAPI is still in its early stage and is only set up for Minecraft 1.20, so the following is subject to change! - ------ - -## Set up - -### Set up (pom.xml) - -In your `pom.xml`, you need the following: - -- Mojang's Brigadier dependency -- The CommandAPI dependencies (in this order): - - `commandapi-bukkit-test-tests` (rewrites CommandAPIVersionHandler to hook into testing NMS implementations) - - `commandapi-bukkit-shade` (as normal for shading) - - `commandapi-bukkit-test-impl` (Test implementation with utility methods and initial test setups for version-specific implementations) - - `commandapi-bukkit-test-impl-1.20` (Test implementation for Minecraft 1.20) -- A full copy of Spigot (not using Mojang mappings) - -For testing, you'll need: - -- JUnit (e.g. JUnit 5) - -> ⚠️ You do _not_ need `MockBukkit`, this is automatically included when you include `commandapi-bukkit-test-impl-1.20`. - -For building and setup, you'll need: - -- Maven Surefire plugin - -A sample `pom.xml` can be found in this folder. - -### Set up (test directory) - -In your test directory, you'll need: - -- A copy of your `plugin.yml` file from your main source directory. This needs to go in a `test/resources` directory -- Your tests in `test/java/...` - -```txt -. -├── README.md -├── pom.xml -├── src -│ ├── main -│ │ ├── java -│ │ │ └── io -│ │ │ └── github -│ │ │ └── jorelali -│ │ │ ├── MyCommands.java -│ │ │ └── MyMain.java -│ │ └── resources -│ │ └── plugin.yml -│ └── test -│ ├── java -│ │ └── io -│ │ └── github -│ │ └── jorelali -│ │ └── MyCommandTests.java -│ └── resources -│ └── plugin.yml -``` - -### Set up (main code) - -- Add the additional `JavaPlugin` constructors to your main plugin class. For example, for a main class callead `MyMain`: - -```java -// Additional constructors required for MockBukkit -public MyMain() { - super(); -} - -public MyMain(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { - super(loader, description, dataFolder, file); -} -``` - -More information about this can be found at [MockBukkit](https://github.com/MockBukkit/MockBukkit#using-mockbukkit) - -### Troubleshooting - -- **Problem:** No tests were found - - **Answer:** Read [Why Maven Doesn’t Find JUnit Tests to Run](https://www.baeldung.com/maven-cant-find-junit-tests) - ------ - -## Writing tests - -Assuming you're using JUnit 5 or greater: - -- Create a class that extends `dev.jorel.commandapi.test.TestBase` -- Add a `@BeforeEach` method that calls `super.setUp()` with your main plugin class file -- Add a `@AfterEach` method that calls `super.tearDown()` -- Call commands using `server.dispatchCommand()` - -```java -class MyCommandTests extends TestBase { - - @BeforeEach - public void setUp() { - super.setUp(MyMain.class); - } - - @AfterEach - public void tearDown() { - super.tearDown(); - } - - @Test - void testMyEffectCommand() { - PlayerMock player = server.addPlayer(); - - server.dispatchCommand(player, "myeffect " + player.getName() + " speed"); - assertNotNull(player.getPotionEffect(PotionEffectType.SPEED)); - } -} - -``` - -Other useful methods that you may want to use: - -- `server.dispatchCommand` - - Runs a command that was registered via the CommandAPI. If this command fails, this automatically fails the test. This should not have the leading `/` character - -- `server.dispatchThrowableCommand` - - This throws a Brigadier `CommandSyntaxException` and does not automatically fail the test. This should not have the leading `/` character - -- `server.getSuggestions` - - Lists the suggestions that was displayed to the user if they typed a certain command string. This should not have the leading `/` character - -- `server.addAdvancement` - - Adds an advancement to the current running server instance. This method registers advancements using NMS, making them compatible with CommandAPI advancement-related arguments diff --git a/examples/bukkit/maven-shaded-tests/pom.xml b/examples/bukkit/maven-shaded-tests/pom.xml deleted file mode 100644 index e2a57b47e..000000000 --- a/examples/bukkit/maven-shaded-tests/pom.xml +++ /dev/null @@ -1,161 +0,0 @@ - - 4.0.0 - dev.jorel - maven-shaded-tests - 0.0.1-SNAPSHOT - - - UTF-8 - - - - - - papermc - https://papermc.io/repo/repository/maven-public/ - - - - - codemc-repo - https://repo.codemc.org/repository/maven-public/ - default - - - - - minecraft-libraries - https://libraries.minecraft.net - - - - - - - dev.jorel - commandapi-bukkit-test-tests - 11.0.0-SNAPSHOT - test-jar - test - - - - - dev.jorel - commandapi-paper-shade - 11.0.0-SNAPSHOT - - - - - io.papermc.paper - paper-api - 1.20.1-R0.1-SNAPSHOT - provided - - - - - de.tr7zw - item-nbt-api - 2.10.0 - - - - - - dev.jorel - commandapi-bukkit-test-impl - 11.0.0-SNAPSHOT - test - - - - dev.jorel - commandapi-bukkit-test-impl-1.20 - 11.0.0-SNAPSHOT - test - - - - com.mojang - brigadier - 1.0.17 - provided - - - - org.spigotmc - spigot - 1.20.1-R0.1-SNAPSHOT - test - - - org.junit.jupiter - junit-jupiter-engine - 5.8.2 - test - - - - - clean package - - - maven-compiler-plugin - 3.11.0 - - 17 - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.6.0 - - - shade - package - - shade - - - false - false - - - - dev.jorel.commandapi - io.github.jorelali.commandapi - - - - de.tr7zw.changeme.nbtapi - io.github.jorelali.nbtapi - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.0 - - false - - - Minecraft_1_20 - - - - - - \ No newline at end of file diff --git a/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyCommands.java b/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyCommands.java deleted file mode 100644 index 32686b3e6..000000000 --- a/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyCommands.java +++ /dev/null @@ -1,100 +0,0 @@ -package io.github.jorelali; - -import de.tr7zw.changeme.nbtapi.NBTContainer; -import dev.jorel.commandapi.CommandTree; -import dev.jorel.commandapi.arguments.*; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import dev.jorel.commandapi.CommandAPICommand; - -public class MyCommands { - - // Plugin reference in case we need to access anything about the plugin, - // such as its config.yml or something - private Plugin plugin; - - public MyCommands(Plugin plugin) { - this.plugin = plugin; - } - - public void registerAllCommands() { - // /break - // Breaks a block at . Can only be executed by a player - new CommandAPICommand("break") - // We want to target blocks in particular, so use BLOCK_POSITION - .withArguments(new LocationArgument("block", LocationType.BLOCK_POSITION)) - .executesPlayer((player, args) -> { - ((Location) args.get(0)).getBlock().breakNaturally(); - }) - .register(); - - // /myeffect - // Applies a potion effect to a player. Basically a simple version of - // the /effect command. The potion effect with be a level 1 potion - // effect and the duration will be 5 minutes (300 seconds x 20 ticks) - new CommandAPICommand("myeffect") - .withArguments(new PlayerArgument("target")) - .withArguments(new PotionEffectArgument("potion")) - .executes((sender, args) -> { - Player target = (Player) args.get(0); - PotionEffectType potionEffectType = (PotionEffectType) args.get(1); - target.addPotionEffect(new PotionEffect(potionEffectType, 300 * 20, 1)); - }) - .register(); - - // An example of the NBTCompoundArgument - // We need to give CommandAPI the NBT API we're using during - // CommandAPI.onLoad(CommandAPIConfig) to use this Argument - new CommandAPICommand("nbt") - .withArguments(new NBTCompoundArgument<>("nbt")) - .executes(((sender, args) -> { - NBTContainer nbt = (NBTContainer) args.get(0); - - sender.sendMessage(nbt.toString()); - })) - .register(); - } - - public void registerAllCommandTrees() { - // This is a different method of registering commands - // Just for demonstration purposes I will use the same commands - // that have been registered in registerAllCommands() - - // /break - new CommandTree("break") - .then(new LocationArgument("block", LocationType.BLOCK_POSITION) - .executesPlayer((player, args) -> { - ((Location) args.get(0)).getBlock().breakNaturally(); - })) - .register(); - - // /myeffect - // This command will be changed a bit to demonstrate - // a way of optional arguments because it is not possible to - // add optional arguments using the CommandAPICommand method - new CommandTree("myeffect") - .then(new PotionEffectArgument("potion") - .executesPlayer((player, args) -> { - // Register /myeffect - // This command just adds the potion effect to the player that - // executes the command - PotionEffectType potionEffectType = (PotionEffectType) args.get(0); - player.addPotionEffect(new PotionEffect(potionEffectType, 300 * 20, 1)); - }) - .then(new PlayerArgument("target") - .executes((sender, args) -> { - // Register /myeffect - // This command works exactly the same as the example - // shown in registerAllCommands() - PotionEffectType potionEffectType = (PotionEffectType) args.get(0); - Player target = (Player) args.get(1); - target.addPotionEffect(new PotionEffect(potionEffectType, 300 * 20, 1)); - }))) - .register(); - } - -} diff --git a/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java b/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java deleted file mode 100644 index 1f48b9652..000000000 --- a/examples/bukkit/maven-shaded-tests/src/main/java/io/github/jorelali/MyMain.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.github.jorelali; - -import java.io.File; - -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.plugin.java.JavaPluginLoader; - -import de.tr7zw.changeme.nbtapi.NBTContainer; -import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPIPaperConfig; -import dev.jorel.commandapi.CommandAPILogger; - -public class MyMain extends JavaPlugin { - @Override - public void onLoad() { - // Set CommandAPI to use this plugin's logger - CommandAPI.setLogger(CommandAPILogger.fromJavaLogger(getLogger())); - - // Load the CommandAPI - CommandAPI.onLoad( - // Configure the CommandAPI - new CommandAPIPaperConfig(this) - // Turn on verbose output for command registration logs - .verboseOutput(true) - // Give file where Brigadier's command registration tree should be dumped - .dispatcherFile(new File(getDataFolder(), "command_registration.json")) - // Point to the NBT API we want to use - .initializeNBTAPI(NBTContainer.class, NBTContainer::new)); - } - - @Override - public void onEnable() { - // Enable the CommandAPI - CommandAPI.onEnable(); - - // Register commands using our MyCommands class - MyCommands myCommands = new MyCommands(this); - myCommands.registerAllCommands(); - myCommands.registerAllCommandTrees(); - } - - // Additional constructors required for MockBukkit - public MyMain() { - super(); - } - - public MyMain(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { - super(loader, description, dataFolder, file); - } - -} diff --git a/examples/bukkit/maven-shaded-tests/src/main/resources/plugin.yml b/examples/bukkit/maven-shaded-tests/src/main/resources/plugin.yml deleted file mode 100644 index 363a1b09f..000000000 --- a/examples/bukkit/maven-shaded-tests/src/main/resources/plugin.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: ExamplePlugin -main: io.github.jorelali.MyMain -version: 0.0.1 -author: Skepter -website: https://www.jorel.dev/CommandAPI/ -api-version: 1.13 \ No newline at end of file diff --git a/examples/bukkit/maven-shaded-tests/src/test/java/io/github/jorelali/MyCommandTests.java b/examples/bukkit/maven-shaded-tests/src/test/java/io/github/jorelali/MyCommandTests.java deleted file mode 100644 index c1d76ee88..000000000 --- a/examples/bukkit/maven-shaded-tests/src/test/java/io/github/jorelali/MyCommandTests.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.jorelali; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.bukkit.potion.PotionEffectType; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import be.seeseemelk.mockbukkit.entity.PlayerMock; -import dev.jorel.commandapi.test.TestBase; - -class MyCommandTests extends TestBase { - - @BeforeEach - public void setUp() { - super.setUp(MyMain.class); - } - - @AfterEach - public void tearDown() { - super.tearDown(); - } - - @Test - void testMyEffectCommand() { - PlayerMock player = server.addPlayer(); - - server.dispatchCommand(player, "myeffect " + player.getName() + " speed"); - assertNotNull(player.getPotionEffect(PotionEffectType.SPEED)); - } -} diff --git a/examples/bukkit/maven-shaded-tests/src/test/resources/plugin.yml b/examples/bukkit/maven-shaded-tests/src/test/resources/plugin.yml deleted file mode 100644 index 363a1b09f..000000000 --- a/examples/bukkit/maven-shaded-tests/src/test/resources/plugin.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: ExamplePlugin -main: io.github.jorelali.MyMain -version: 0.0.1 -author: Skepter -website: https://www.jorel.dev/CommandAPI/ -api-version: 1.13 \ No newline at end of file diff --git a/examples/bukkit/maven-shaded/README.md b/examples/bukkit/maven-shaded/README.md index caa9c589e..1d5b1daea 100644 --- a/examples/bukkit/maven-shaded/README.md +++ b/examples/bukkit/maven-shaded/README.md @@ -4,12 +4,12 @@ A simple example of shading the CommandAPI with Maven. Key points: -- The `commandapi-bukit-shade` dependency is used: +- The `commandapi-paper-shade` dependency is used: ```xml dev.jorel - commandapi-bukkit-shade + commandapi-paper-shade 11.0.0-SNAPSHOT ``` diff --git a/examples/bukkit/maven-shaded/pom.xml b/examples/bukkit/maven-shaded/pom.xml index 92a43945e..509f0326e 100644 --- a/examples/bukkit/maven-shaded/pom.xml +++ b/examples/bukkit/maven-shaded/pom.xml @@ -12,7 +12,7 @@ papermc - https://papermc.io/repo/repository/maven-public/ + https://repo.papermc.io/repository/maven-public/ @@ -31,11 +31,11 @@ 11.0.0-SNAPSHOT - + io.papermc.paper paper-api - 1.20.1-R0.1-SNAPSHOT + 1.21.8-R0.1-SNAPSHOT provided diff --git a/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java b/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java index fdf3a39d9..f6fc247ca 100644 --- a/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java +++ b/examples/bukkit/maven-shaded/src/main/java/io/github/jorelali/Main.java @@ -1,14 +1,12 @@ package io.github.jorelali; -import java.io.File; - import de.tr7zw.changeme.nbtapi.NBTContainer; -import dev.jorel.commandapi.CommandAPIPaperConfig; +import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPILogger; +import dev.jorel.commandapi.CommandAPIPaperConfig; import org.bukkit.plugin.java.JavaPlugin; -import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPIConfig; +import java.io.File; public class Main extends JavaPlugin { @Override diff --git a/examples/bukkit/maven/README.md b/examples/bukkit/maven/README.md index 53732a9ed..e44956f58 100644 --- a/examples/bukkit/maven/README.md +++ b/examples/bukkit/maven/README.md @@ -4,12 +4,12 @@ A simple example of making a plugin that uses the CommandAPI with Maven. Key points: -- The `commandapi-bukkit-plugin` dependency is used with the provided scope +- The `commandapi-paper-plugin` dependency is used with the provided scope ```xml dev.jorel - commandapi-bukkit-plugin + commandapi-paper-plugin 11.0.0-SNAPSHOT provided diff --git a/examples/bukkit/maven/pom.xml b/examples/bukkit/maven/pom.xml index b8bdd30e8..69598c23f 100644 --- a/examples/bukkit/maven/pom.xml +++ b/examples/bukkit/maven/pom.xml @@ -12,7 +12,7 @@ papermc - https://papermc.io/repo/repository/maven-public/ + https://repo.papermc.io/repository/maven-public/ @@ -44,7 +44,7 @@ de.tr7zw item-nbt-api-plugin - 2.12.4 + 2.15.1 diff --git a/examples/bukkit/maven/src/main/java/io/github/jorelali/MyCommands.java b/examples/bukkit/maven/src/main/java/io/github/jorelali/MyCommands.java index c4b0793b7..f77aea3aa 100644 --- a/examples/bukkit/maven/src/main/java/io/github/jorelali/MyCommands.java +++ b/examples/bukkit/maven/src/main/java/io/github/jorelali/MyCommands.java @@ -9,10 +9,10 @@ import de.tr7zw.nbtapi.NBTContainer; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.CommandTree; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; import dev.jorel.commandapi.arguments.LocationArgument; import dev.jorel.commandapi.arguments.LocationType; import dev.jorel.commandapi.arguments.NBTCompoundArgument; -import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.arguments.PotionEffectArgument; public class MyCommands { diff --git a/examples/velocity/gradle-groovy/build.gradle b/examples/velocity/gradle-groovy/build.gradle index 57ab9dbc2..64d4d79d8 100644 --- a/examples/velocity/gradle-groovy/build.gradle +++ b/examples/velocity/gradle-groovy/build.gradle @@ -16,7 +16,7 @@ repositories { mavenCentral() // This adds the Velocity Maven repository to the build maven { - url 'https://repo.papermc.io/repository/maven-public/' + url = 'https://repo.papermc.io/repository/maven-public/' } } From e6c2f766cec5964a59196b80309706b8bf5b27c7 Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Sun, 17 Aug 2025 20:09:24 -0400 Subject: [PATCH 34/63] Include Paper NMS dependencies during Sonar analysis Note: I don't think these changes affect anything until they are on the `main` branch on GitHub --- .github/workflows/sonar.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 92e058c57..0dd7a6a14 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -88,6 +88,8 @@ jobs: restore-keys: ${{ runner.os }}-m2 # Apply SonarCloud + - name: Setup Paper NMS for all applicable versions + run: ./setupPaperNMS.sh - name: SonarCloud Analyze run: mvn -B test-compile org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=JorelAli_CommandAPI -P Platform.Bukkit,Platform.Velocity -Dmaven.javadoc.skip=true env: From 13d44f77bee4ac8686e66b23edcf03ca3165dff7 Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Wed, 20 Aug 2025 10:12:10 -0400 Subject: [PATCH 35/63] Implement commandapi-paper-test-toolkit, Enable code coverage --- commandapi-codecov/pom.xml | 40 ++- .../jorel/commandapi/CommandAPIBukkit.java | 2 +- .../commandapi-bukkit-test-toolkit/pom.xml | 14 +- .../arguments/ProfileArgumentType.java | 2 +- .../dev/jorel/commandapi/nms/BundledNMS.java | 10 +- .../jorel/commandapi/nms/APITypeProvider.java | 2 +- .../commandapi-paper-test-toolkit/pom.xml | 111 ++++++++ .../commandapi/CommandAPIVersionHandler.java | 42 ++++ .../jorel/commandapi/MockCommandAPIPaper.java | 42 ++++ .../commandapi/MockCommandAPIPlugin.java | 58 +++++ .../jorel/commandapi/nms/MockPaperNMS.java | 48 ++++ ...mmandAPIVersionHandlerOverridingTests.java | 59 +++++ .../dev/jorel/commandapi/CommandTestBase.java | 80 ++++++ .../MockCommandAPIPluginLoadingTests.java | 64 +++++ .../arguments/ProfileArgumentTypeTests.java | 237 ++++++++++++++++++ .../commandapi-spigot-test-toolkit/pom.xml | 9 +- .../commandapi/MockCommandAPIPlugin.java | 2 +- .../jorel/commandapi/nms/MockSpigotNMS.java | 2 +- pom.xml | 13 +- 19 files changed, 793 insertions(+), 44 deletions(-) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPaper.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockPaperNMS.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPluginLoadingTests.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java diff --git a/commandapi-codecov/pom.xml b/commandapi-codecov/pom.xml index 1ecc1af59..221f0833e 100644 --- a/commandapi-codecov/pom.xml +++ b/commandapi-codecov/pom.xml @@ -14,13 +14,13 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 dev.jorel commandapi - 10.0.0 + 11.0.0-SNAPSHOT commandapi-codecov @@ -30,11 +30,13 @@ + dev.jorel commandapi-core ${project.version} + dev.jorel commandapi-bukkit-core @@ -42,45 +44,39 @@ dev.jorel - commandapi-plugin + commandapi-spigot-core ${project.version} dev.jorel - commandapi-bukkit-plugin-common + commandapi-paper-core ${project.version} - - + + + + dev.jorel commandapi-bukkit-test-toolkit - ${project.version}--> - - - - - + ${project.version} + dev.jorel - commandapi-bukkit-nms-common + commandapi-spigot-test-toolkit ${project.version} - mojang-mapped - - dev.jorel - commandapi-bukkit-1.20 + commandapi-paper-test-toolkit ${project.version} - mojang-mapped diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java index 207b764f7..6aebb7f7a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/CommandAPIBukkit.java @@ -117,7 +117,7 @@ public void onServerLoad(ServerLoadEvent event) { }, plugin); } - private void checkDependencies() { + protected void checkDependencies() { // Log successful hooks Class nbtContainerClass = CommandAPIBukkit.getConfiguration().getNBTContainerClass(); if (nbtContainerClass != null && CommandAPIBukkit.getConfiguration().getNBTContainerConstructor() != null) { diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml index 83f7cd5ce..a18a0c624 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml @@ -38,8 +38,6 @@ org.mockbukkit.mockbukkit mockbukkit-v1.21 - 4.45.1 - provided @@ -72,17 +70,23 @@ org.slf4j slf4j-nop - 2.0.9 + 2.0.16 compile - + + org.junit.jupiter + junit-jupiter-params + 5.13.3 + test + org.junit.jupiter junit-jupiter-engine - 5.11.0 + 5.13.3 test diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/arguments/ProfileArgumentType.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/arguments/ProfileArgumentType.java index baaaa4850..8b5d696ee 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/arguments/ProfileArgumentType.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/arguments/ProfileArgumentType.java @@ -90,7 +90,7 @@ public CompletableFuture listSuggestions(CommandContext cont return EntitySelectorParser.parser.listSuggestions(context, builder); } - public static List getProfiles(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public static List getProfiles(CommandContext cmdCtx, String key) throws CommandSyntaxException { return cmdCtx.getArgument(key, ProfileSelector.class).getProfiles(cmdCtx.getSource()); } } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java index ae41a6254..702747ef0 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/nms/BundledNMS.java @@ -9,14 +9,14 @@ import java.util.List; -public abstract class BundledNMS implements NMS, PaperNMS { +public interface BundledNMS extends NMS, PaperNMS { - public abstract SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; + SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException; - public abstract NamedTextColor getChatColor(CommandContext cmdCtx, String key); + NamedTextColor getChatColor(CommandContext cmdCtx, String key); - public abstract Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException; + Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException; - public abstract List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException; + List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException; } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index 0a38625d0..284345271 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -95,7 +95,7 @@ import java.util.function.Supplier; @SuppressWarnings("UnstableApiUsage") -public class APITypeProvider extends BundledNMS { +public class APITypeProvider implements BundledNMS { private final PaperNMS paperNMS; diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml index 248c72e1c..52d431514 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml @@ -10,6 +10,7 @@ commandapi-paper-test-toolkit + Paper support testing toolkit 21 @@ -17,4 +18,114 @@ UTF-8 + + + minecraft-libraries + Minecraft Libraries + https://libraries.minecraft.net + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + + + org.mockbukkit.mockbukkit + mockbukkit-v1.21 + + + dev.jorel + commandapi-bukkit-test-toolkit + ${project.version} + compile + + + + + dev.jorel + commandapi-paper-core + ${project.version} + provided + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + dev.jorel:commandapi-core + + dev/jorel/commandapi/CommandAPIVersionHandler** + + + + + + LICENSE + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.3.0 + + false + + + + + + + + + + org.jacoco + jacoco-maven-plugin + + + + default-prepare-agent + + prepare-agent + + + + + report + verify + + report + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java new file mode 100644 index 000000000..9b0a93c76 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -0,0 +1,42 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.nms.*; + +import java.util.function.Function; + +public abstract class CommandAPIVersionHandler { + // Allow loading a different platform implementation (most likely to implement something `MockCommandAPISpigot` doesn't) + private static Function> alternativePlatform = null; + + /** + * Configures the test kit to use the given {@link CommandAPIPlatform} when the CommandAPI is loaded. + * + * @param platform A {@link Function} that uses a {@link InternalPaperConfig} to create the + * {@link CommandAPIPlatform} to use for the next test. This will likely be a custom + * implementation of {@link MockCommandAPIPaper} that overrides a method you need to run + * tests that doesn't have a proper implementation in {@link MockCommandAPIPaper}. + */ + public static void usePlatformImplementation(Function> platform) { + alternativePlatform = platform; + } + + static LoadContext getPlatform(CommandAPIConfig config) { + InternalPaperConfig internalPaperConfig; + if (config instanceof CommandAPIPaperConfig paperConfig) { + internalPaperConfig = new InternalPaperConfig(paperConfig); + } else { + throw new IllegalArgumentException("CommandAPIPaper was loaded with non-Paper config!"); + } + + // Default to MockCommandAPIBukkit if not given + CommandAPIPlatform platform = alternativePlatform == null ? + new MockCommandAPIPaper(internalPaperConfig, new MockPaperNMS()) : + alternativePlatform.apply(internalPaperConfig); + + + // Reset to avoid platform persisting between tests + alternativePlatform = null; + + return new LoadContext(platform); + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPaper.java new file mode 100644 index 000000000..f5d84f3de --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPaper.java @@ -0,0 +1,42 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.nms.BundledNMS; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * An implementation of {@link CommandAPIPaper} that is compatible with a MockBukkit testing environment. + * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. + */ +public class MockCommandAPIPaper extends CommandAPIPaper { + // References to utility classes + private final MockCommandAPI mockCommandAPI; + + public MockCommandAPIPaper(InternalPaperConfig config, BundledNMS nms) { + super(config, nms); + this.mockCommandAPI = new MockCommandAPI(this); + } + + // Load + // Not calling super implementations of `onLoad` and `onEnable` to avoid casting + // our MockCommandRegistrationStrategy to PaperCommandRegistration. + // Seems kinda weird that CommandAPIPaper is even doing that... + // We probably don't need SpigotCommandRegistration and PaperCommandRegistration + // now that we have CommandAPISpigot and CommandAPIPaper. + @Override + public void onLoad() { + mockCommandAPI.onLoad(); + super.checkDependencies(); + } + + @Override + public void onEnable() { + super.plugin = (JavaPlugin) Bukkit.getPluginManager().getPlugin(getConfiguration().getPluginName()); + } + + // Test environment-specific + @Override + public CommandAPILogger getLogger() { + return MockCommandAPI.ENABLE_LOGGING ? super.getLogger() : CommandAPILogger.silent(); + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java new file mode 100644 index 000000000..c45b4ca94 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java @@ -0,0 +1,58 @@ +package dev.jorel.commandapi; + +import org.bukkit.plugin.java.JavaPlugin; +import org.mockbukkit.mockbukkit.MockBukkit; + +import java.util.function.Consumer; + +/** + * Loads the CommandAPI in this mock Paper environment. + */ +public class MockCommandAPIPlugin extends JavaPlugin { + // Allow loading with settings, + // Default to none if `MockBukkit.load(MockCommandAPIPlugin.class)` is used directly + private static Consumer configureSettings = null; + + /** + * Loads the CommandAPI plugin using {@link MockBukkit#load(Class)}. + * + * @return The {@link MockCommandAPIPlugin} instance that was loaded. + */ + public static MockCommandAPIPlugin load() { + return load(null); + } + + /** + * Loads the CommandAPI plugin using {@link MockBukkit#load(Class)}. + * + * @param configureSettings A {@link Consumer} that can configure the settings of the {@link CommandAPIPaperConfig} + * before it is used to load the CommandAPI plugin. + * @return The {@link MockCommandAPIPlugin} instance that was loaded. + */ + public static MockCommandAPIPlugin load(Consumer configureSettings) { + MockCommandAPIPlugin.configureSettings = configureSettings; + return MockBukkit.load(MockCommandAPIPlugin.class); + } + + @Override + public void onLoad() { + CommandAPIPaperConfig config = new CommandAPIPaperConfig(this); + + if (configureSettings != null) { + configureSettings.accept(config); + } + configureSettings = null; // Reset to avoid configs persisting between tests + + CommandAPI.onLoad(config); + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + } + + @Override + public void onDisable() { + CommandAPI.onDisable(); + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockPaperNMS.java b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockPaperNMS.java new file mode 100644 index 000000000..87b484fa6 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockPaperNMS.java @@ -0,0 +1,48 @@ +package dev.jorel.commandapi.nms; + +import com.destroystokyo.paper.profile.PlayerProfile; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.*; +import dev.jorel.commandapi.arguments.ProfileArgumentType; +import net.kyori.adventure.chat.SignedMessage; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.List; + +public class MockPaperNMS extends MockNMS implements BundledNMS { + @Override + public NMS bukkitNMS() { + return this; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return MockCommandAPI.getInstance().getCommandRegistrationStrategy(); + } + + @Override + public List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return (List) ProfileArgumentType.getProfiles(cmdCtx, key); + } + + /////////////////////////// + // UNIMPLEMENTED METHODS // + /////////////////////////// + + @Override + public SignedMessage getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } + + @Override + public NamedTextColor getChatColor(CommandContext cmdCtx, String key) { + throw new UnimplementedMethodException(); + } + + @Override + public Component getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + throw new UnimplementedMethodException(); + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java new file mode 100644 index 000000000..b465ee9fa --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandlerOverridingTests.java @@ -0,0 +1,59 @@ +package dev.jorel.commandapi; + +import dev.jorel.commandapi.nms.MockPaperNMS; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; + +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests for using {@link CommandAPIVersionHandler#usePlatformImplementation(Function)} + */ +class CommandAPIVersionHandlerOverridingTests extends CommandAPITestUtilities { + // Setup + @BeforeEach + public void setUp() { + MockBukkit.mock(); + } + + @AfterEach + public void tearDown() { + MockBukkit.unmock(); + } + + private static class CustomMockCommandAPIPaper extends MockCommandAPIPaper { + public CustomMockCommandAPIPaper(InternalPaperConfig config) { + super(config, new MockPaperNMS()); + } + } + + // Tests + @Test + void testDefaultPlatform() { + MockCommandAPIPlugin.load(); + + assertEquals(MockCommandAPIPaper.class, getMockCommandAPI().getCommandAPIBukkit().getClass()); + } + + @Test + void testChangingPlatform() { + CommandAPIVersionHandler.usePlatformImplementation(CustomMockCommandAPIPaper::new); + MockCommandAPIPlugin.load(); + + assertEquals(CustomMockCommandAPIPaper.class, getMockCommandAPI().getCommandAPIBukkit().getClass()); + } + + @Test + void testPlatformDoesNotPersist() { + testChangingPlatform(); + + MockBukkit.unmock(); + MockBukkit.mock(); + + testDefaultPlatform(); + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java new file mode 100644 index 000000000..9d7a48c24 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/CommandTestBase.java @@ -0,0 +1,80 @@ +package dev.jorel.commandapi; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.context.CommandContextBuilder; +import com.mojang.brigadier.context.ParsedArgument; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.arguments.parser.Parser; +import dev.jorel.commandapi.arguments.parser.ParserArgument; +import dev.jorel.commandapi.executors.CommandExecutionInfo; +import org.bukkit.command.CommandSender; +import org.junit.jupiter.api.function.Executable; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.opentest4j.AssertionFailedError; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public abstract class CommandTestBase extends CommandAPITestUtilities { + // Useful objects + public static CommandExecutionInfo DEFAULT_EXECUTOR = info -> {}; + + // Setup + protected ServerMock server; + protected MockCommandAPIPlugin plugin; + + public void setUp() { + server = MockBukkit.mock(); + plugin = MockBukkit.load(MockCommandAPIPlugin.class); + } + + public void tearDown() { + MockBukkit.unmock(); + } + + // Additional test utilities + @CanIgnoreReturnValue + public T assertThrowsWithMessage(Class exceptionClass, Executable executable, String expectedMessage) { + T exception = assertThrows(exceptionClass, executable); + String actualMessage = exception.getMessage(); + if (!expectedMessage.equals(actualMessage)) { + throw new AssertionFailedError( + "Exception messages did not match. Expected <" + expectedMessage + "> but was <" + actualMessage + ">.", + expectedMessage, actualMessage, exception + ); + } + return exception; + } + + @CanIgnoreReturnValue + public AssertionFailedError assertAssertionFails(Executable executable, String expectedMessage) { + return assertThrowsWithMessage(AssertionFailedError.class, executable, expectedMessage); + } + + public CommandContext createContextWithParser( + CommandSender source, String key, Parser parser, String input + ) throws CommandSyntaxException { + CommandDispatcher dispatcher = getMockCommandAPI().getCommandAPIBukkit().getBrigadierDispatcher(); + CommandContextBuilder contextBuilder = new CommandContextBuilder<>( + dispatcher, + new MockCommandSource(source), + dispatcher.getRoot(), + 0 + ); + + StringReader reader = new StringReader(input); + T result = parser.parse(reader); + contextBuilder.withArgument(key, new ParsedArgument<>(0, reader.getCursor(), result)); + + return contextBuilder.build(input); + } + + public CommandContext createContextWithParser( + CommandSender source, String key, ParserArgument parser, String input + ) throws CommandSyntaxException { + return createContextWithParser(source, key, (Parser) parser, input); + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPluginLoadingTests.java b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPluginLoadingTests.java new file mode 100644 index 000000000..2d69adb1e --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/MockCommandAPIPluginLoadingTests.java @@ -0,0 +1,64 @@ +package dev.jorel.commandapi; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests for loading the {@link MockCommandAPIPlugin}. + */ +class MockCommandAPIPluginLoadingTests { + // Setup + @BeforeEach + public void setUp() { + MockBukkit.mock(); + } + + @AfterEach + public void tearDown() { + MockBukkit.unmock(); + } + + // Tests + @Test + void testMockBukkitLoad() { + MockCommandAPIPlugin plugin = MockBukkit.load(MockCommandAPIPlugin.class); + + assertTrue(plugin.isEnabled()); + } + + @Test + void testLoadMethod() { + MockCommandAPIPlugin plugin = MockCommandAPIPlugin.load(); + + assertTrue(plugin.isEnabled()); + } + + @Test + void testLoadWithConfiguration() { + MockCommandAPIPlugin plugin = MockCommandAPIPlugin.load(config -> config.verboseOutput(true)); + + assertTrue(plugin.isEnabled()); + assertTrue(CommandAPIBukkit.getConfiguration().hasVerboseOutput()); + } + + @Test + void testConfigurationDoesNotPersist() { + MockCommandAPIPlugin plugin = MockCommandAPIPlugin.load(config -> config.verboseOutput(true)); + + assertTrue(plugin.isEnabled()); + assertTrue(CommandAPIBukkit.getConfiguration().hasVerboseOutput()); + + MockBukkit.unmock(); + MockBukkit.mock(); + + plugin = MockBukkit.load(MockCommandAPIPlugin.class); + + assertTrue(plugin.isEnabled()); + assertFalse(CommandAPIBukkit.getConfiguration().hasVerboseOutput()); + } +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java new file mode 100644 index 000000000..9be2117b3 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/test/java/dev/jorel/commandapi/arguments/ProfileArgumentTypeTests.java @@ -0,0 +1,237 @@ +package dev.jorel.commandapi.arguments; + +import com.destroystokyo.paper.profile.PlayerProfile; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandTestBase; +import dev.jorel.commandapi.MockCommandSource; +import org.bukkit.entity.Player; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.command.ConsoleCommandSenderMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; + +import java.util.ArrayList; +import java.util.List; + +class ProfileArgumentTypeTests extends CommandTestBase { + // Setup + @BeforeEach + public void setUp() { + super.setUp(); + } + + @AfterEach + public void tearDown() { + super.tearDown(); + } + + private void registerCommand() { + new CommandAPICommand("test") + .withArguments(new PlayerProfileArgument("player")) + .executes(DEFAULT_EXECUTOR) + .register(); + } + + private List profileList(Player... players) { + List profileList = new ArrayList<>(players.length); + for (Player player : players) { + profileList.add(player.getPlayerProfile()); + } + + return profileList; + } + + // Test + @Test + void testEmptyInputs() throws CommandSyntaxException { + registerCommand(); + + PlayerMock player = server.addPlayer(); + + // Fully empty input, cannot read + CommandContext emptyNameContext = createContextWithParser( + player, "player", ProfileArgumentType.INSTANCE::parse, "" + ); + assertThrowsWithMessage( + CommandSyntaxException.class, + () -> ProfileArgumentType.getProfiles(emptyNameContext, "player"), + "That player does not exist" + ); + + // Empty input, but can read + CommandContext spaceNameContext = createContextWithParser( + player, "player", ProfileArgumentType.INSTANCE::parse, " " + ); + assertThrowsWithMessage( + CommandSyntaxException.class, + () -> ProfileArgumentType.getProfiles(spaceNameContext, "player"), + "That player does not exist" + ); + } + + @Test + void testDefaultSuggestions() { + registerCommand(); + + server.addPlayer("Player1"); + server.addPlayer("Player2"); + + ConsoleCommandSenderMock console = server.getConsoleSender(); + assertCommandSuggestsTooltips( + console, "test ", + 5, + makeTooltip("@a", "All players"), + makeTooltip("@e", "All entities"), + makeTooltip("@n", "Nearest entity"), + makeTooltip("@p", "Nearest player"), + makeTooltip("@r", "Random player"), + makeTooltip("@s", "Current entity"), + makeTooltip("Player1", null), + makeTooltip("Player2", null) + ); + } + + @Test + void testEntitySelectorErrors() { + registerCommand(); + ConsoleCommandSenderMock console = server.getConsoleSender(); + + assertCommandFails( + console, "test @", + "Missing selector type at position 6: test @<--[HERE]" + ); + + assertCommandFails( + console, "test @e", + "Only players may be affected by this command, but the provided selector includes entities" + ); + + assertCommandFails( + console, "test @a", + "No player was found" + ); + } + + @Test + void testEntitySelectorSuccess() { + registerCommand(); + + // Layout: p1 p2 + PlayerMock p1 = server.addPlayer(); + p1.teleport(p1.getLocation().set(0, 0, 0)); + + PlayerMock p2 = server.addPlayer(); + p2.teleport(p2.getLocation().set(1, 0, 0)); + + // Arbitrary order uses creation order, since it references a LinkedHashSet + assertCommandSucceedsWithArguments( + p1, "test @a", + profileList(p1, p2) + ); + assertCommandSucceedsWithArguments( + p2, "test @a", + profileList(p1, p2) + ); + + // @p selects nearest + assertCommandSucceedsWithArguments( + p1, "test @p", + profileList(p1) + ); + assertCommandSucceedsWithArguments( + p2, "test @p", + profileList(p2) + ); + } + + @Test + void testEntitySelectorSuggestions() { + registerCommand(); + + server.addPlayer("Player1"); + server.addPlayer("Player2"); + + ConsoleCommandSenderMock console = server.getConsoleSender(); + assertCommandSuggestsTooltips( + console, "test @", + 5, + makeTooltip("@a", "All players"), + makeTooltip("@e", "All entities"), + makeTooltip("@n", "Nearest entity"), + makeTooltip("@p", "Nearest player"), + makeTooltip("@r", "Random player"), + makeTooltip("@s", "Current entity") + ); + } + + @Test + void testNameSelectorErrors() { + registerCommand(); + + PlayerMock playerA = server.addPlayer("PlayerA"); + + assertCommandFails( + playerA, "test invalid", + "That player does not exist" + ); + } + + @Test + void testNameSelectorSuccess() { + registerCommand(); + + PlayerMock playerA = server.addPlayer("PlayerA"); + PlayerMock playerB = server.addPlayer("PlayerB"); + + ConsoleCommandSenderMock console = server.getConsoleSender(); + + assertCommandSucceedsWithArguments( + console, "test PlayerA", + profileList(playerA) + ); + assertCommandSucceedsWithArguments( + console, "test PlayerB", + profileList(playerB) + ); + + // Not case-sensitive + assertCommandSucceedsWithArguments( + console, "test pLAyeRa", + profileList(playerA) + ); + } + + @Test + void testNameSuggestions() { + registerCommand(); + + server.addPlayer("alice"); + server.addPlayer("allan"); + server.addPlayer("bob"); + + ConsoleCommandSenderMock console = server.getConsoleSender(); + + // Only suggests names that match remaining + assertCommandSuggests( + console, "test a", + 5, "alice", "allan" + ); + assertCommandSuggests( + console, "test all", + 5, "allan" + ); + assertCommandSuggests( + console, "test b", + 5, "bob" + ); + + // Suggestions are not case-sensitive + assertCommandSuggests( + console, "test AL", + 5, "alice", "allan" + ); + } +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml index 0033901ee..7e7c4ee50 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml @@ -31,7 +31,6 @@ - - - - + + + diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java index 861518d9f..369795232 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPIPlugin.java @@ -6,7 +6,7 @@ import java.util.function.Consumer; /** - * Loads the CommandAPI in this abstract Bukkit environment. + * Loads the CommandAPI in this mock Spigot environment. */ public class MockCommandAPIPlugin extends JavaPlugin { // Allow loading with settings, diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockSpigotNMS.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockSpigotNMS.java index 9c15eaa89..60164442d 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockSpigotNMS.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockSpigotNMS.java @@ -15,7 +15,7 @@ public interface MockSpigotNMS extends SpigotNMS { // Arguments @Override default List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { - return ProfileArgumentType.getProfiles(cmdCtx, key); + return (List) ProfileArgumentType.getProfiles(cmdCtx, key); } /////////////////////////// diff --git a/pom.xml b/pom.xml index 163a4ea16..bc132b308 100644 --- a/pom.xml +++ b/pom.xml @@ -73,9 +73,20 @@ commandapi-testing - + commandapi-codecov + + + + org.mockbukkit.mockbukkit + mockbukkit-v1.21 + 4.72.8 + provided + + + + UTF-8 UTF-8 From eae577616589ee3100eed891f6e2fcac4cf3e21f Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Thu, 28 Aug 2025 12:28:19 -0400 Subject: [PATCH 36/63] Fix usage of MockBukkit Hamcrest matchers --- .../java/io/github/jorelali/PingPongCommandTests.java | 5 +++-- .../test/java/io/github/jorelali/RangeCheckTests.java | 9 +++++---- .../java/io/github/jorelali/PingPongCommandTests.java | 5 +++-- .../test/java/io/github/jorelali/RangeCheckTests.java | 9 +++++---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/PingPongCommandTests.java b/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/PingPongCommandTests.java index 403b86d8f..ef7feec63 100644 --- a/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/PingPongCommandTests.java +++ b/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/PingPongCommandTests.java @@ -11,6 +11,7 @@ import static dev.jorel.commandapi.CommandAPITestUtilities.assertCommandSucceeds; // Import MockBukkit assertions +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedAnyMessageMatcher.hasNotReceivedAny; import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedMessageMatcher.hasReceived; @@ -40,7 +41,7 @@ void runCommand() { assertCommandSucceeds(player, "ping"); - hasReceived("pong!").matches(player); - hasNotReceivedAny().matches(player); + assertThat(player, hasReceived("pong!")); + assertThat(player, hasNotReceivedAny()); } } diff --git a/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/RangeCheckTests.java b/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/RangeCheckTests.java index 56ea76374..c8250bb97 100644 --- a/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/RangeCheckTests.java +++ b/examples/bukkit/automated-tests-shaded/src/test/java/io/github/jorelali/RangeCheckTests.java @@ -13,6 +13,7 @@ import java.util.Map; // Import MockBukkit assertions +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedAnyMessageMatcher.hasNotReceivedAny; import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedMessageMatcher.hasReceived; @@ -43,14 +44,14 @@ public void tearDown() { void testCommandExecution() { // Testing successful usage of command assertCommandSucceeds(player, "rangecheck 10..15 13"); - hasReceived("Number 13 is within range 10..15").matches(player); + assertThat(player, hasReceived("Number 13 is within range 10..15")); assertCommandSucceedsWithArguments( player, "rangecheck 10..15 10", // Verifying argument array new IntegerRange(10, 15), 10 ); - hasReceived("Number 10 is within range 10..15").matches(player); + assertThat(player, hasReceived("Number 10 is within range 10..15")); assertCommandSucceedsWithArguments( player, "rangecheck -3..-3 -3", @@ -60,7 +61,7 @@ void testCommandExecution() { "number", -3 ) ); - hasReceived("Number -3 is within range -3..-3").matches(player); + assertThat(player, hasReceived("Number -3 is within range -3..-3")); // Test unsuccessful usage of command assertCommandFails( @@ -86,7 +87,7 @@ void testCommandExecution() { ); // Make sure no extra messages were sent - hasNotReceivedAny().matches(player); + assertThat(player, hasNotReceivedAny()); } @Test diff --git a/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/PingPongCommandTests.java b/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/PingPongCommandTests.java index 40699a135..07cf60e76 100644 --- a/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/PingPongCommandTests.java +++ b/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/PingPongCommandTests.java @@ -12,6 +12,7 @@ import static dev.jorel.commandapi.CommandAPITestUtilities.assertCommandSucceeds; // Import MockBukkit assertions +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedAnyMessageMatcher.hasNotReceivedAny; import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedMessageMatcher.hasReceived; @@ -44,7 +45,7 @@ void runCommand() { assertCommandSucceeds(player, "ping"); - hasReceived("pong!").matches(player); - hasNotReceivedAny().matches(player); + assertThat(player, hasReceived("pong!")); + assertThat(player, hasNotReceivedAny()); } } diff --git a/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/RangeCheckTests.java b/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/RangeCheckTests.java index b4b945e7d..008dd5a46 100644 --- a/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/RangeCheckTests.java +++ b/examples/bukkit/automated-tests/src/test/java/io/github/jorelali/RangeCheckTests.java @@ -14,6 +14,7 @@ import java.util.Map; // Import MockBukkit assertions +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedAnyMessageMatcher.hasNotReceivedAny; import static org.mockbukkit.mockbukkit.matcher.command.MessageTargetReceivedMessageMatcher.hasReceived; @@ -47,14 +48,14 @@ public void tearDown() { void testCommandExecution() { // Testing successful usage of command assertCommandSucceeds(player, "rangecheck 10..15 13"); - hasReceived("Number 13 is within range 10..15").matches(player); + assertThat(player, hasReceived("Number 13 is within range 10..15")); assertCommandSucceedsWithArguments( player, "rangecheck 10..15 10", // Verifying argument array new IntegerRange(10, 15), 10 ); - hasReceived("Number 10 is within range 10..15").matches(player); + assertThat(player, hasReceived("Number 10 is within range 10..15")); assertCommandSucceedsWithArguments( player, "rangecheck -3..-3 -3", @@ -64,7 +65,7 @@ void testCommandExecution() { "number", -3 ) ); - hasReceived("Number -3 is within range -3..-3").matches(player); + assertThat(player, hasReceived("Number -3 is within range -3..-3")); // Test unsuccessful usage of command assertCommandFails( @@ -90,7 +91,7 @@ void testCommandExecution() { ); // Make sure no extra messages were sent - hasNotReceivedAny().matches(player); + assertThat(player, hasNotReceivedAny()); } @Test From 86ab41a9660f910b8299b3dacf38558d6f8e265e Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Sat, 6 Sep 2025 17:00:17 -0400 Subject: [PATCH 37/63] Fix MockBukkit version for Paper API changes https://github.com/MockBukkit/MockBukkit/pull/1447 --- .../commandapi-bukkit-test-toolkit/pom.xml | 11 +++++++--- .../commandapi-paper-test-toolkit/pom.xml | 11 +++++++--- .../commandapi-spigot-test-toolkit/pom.xml | 11 +++++++--- .../bukkit/automated-tests-shaded/README.md | 20 +++++++++---------- .../bukkit/automated-tests-shaded/pom.xml | 18 ++++++++--------- .../main/java/io/github/jorelali/Main.java | 2 +- examples/bukkit/automated-tests/README.md | 16 +++++++-------- examples/bukkit/automated-tests/pom.xml | 18 ++++++++--------- pom.xml | 2 +- 9 files changed, 62 insertions(+), 47 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml index a18a0c624..d2f2e35eb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml @@ -32,14 +32,19 @@ - org.mockbukkit.mockbukkit mockbukkit-v1.21 + + + io.papermc.paper + paper-api + 1.21.8-R0.1-SNAPSHOT + provided + + dev.jorel diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml index 52d431514..4f5214607 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml @@ -33,9 +33,6 @@ - org.mockbukkit.mockbukkit mockbukkit-v1.21 @@ -47,6 +44,14 @@ compile + + + io.papermc.paper + paper-api + 1.21.8-R0.1-SNAPSHOT + provided + + dev.jorel diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml index 7e7c4ee50..91ab8cb74 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml @@ -33,9 +33,6 @@ - org.mockbukkit.mockbukkit mockbukkit-v1.21 @@ -47,6 +44,14 @@ compile + + + io.papermc.paper + paper-api + 1.21.8-R0.1-SNAPSHOT + provided + + dev.jorel diff --git a/examples/bukkit/automated-tests-shaded/README.md b/examples/bukkit/automated-tests-shaded/README.md index 7adb38d5a..d30aff246 100644 --- a/examples/bukkit/automated-tests-shaded/README.md +++ b/examples/bukkit/automated-tests-shaded/README.md @@ -4,42 +4,42 @@ A simple example showcasing testing CommandAPI commands with [MockBukkit](https: Key points: -- The MockBukkit and `commandapi-spigot-test-toolkit` dependencies are listed with the `test` scope before the normal dependencies for `commandapi-spigot-shade` and `spigot-api`. This ensures that when running tests, certain classes that are compatible with the testing environment override the regular classes. There is also a dependency for the [JUnit](https://junit.org/junit5/) API, which helps when writing the tests. +- The MockBukkit and `commandapi-paper-test-toolkit` dependencies are listed with the `test` scope before the normal dependencies for `commandapi-paper-shade` and `paper-api`. This ensures that when running tests, certain classes that are compatible with the testing environment override the regular classes. There is also a dependency for the [JUnit](https://junit.org/junit5/) API, which helps when writing the tests. ```xml - com.github.seeseemelk - MockBukkit-v1.21 - 3.128.0 + org.mockbukkit.mockbukkit + mockbukkit-v1.21 + 4.76.0 test dev.jorel - commandapi-bukkit-test-toolkit + commandapi-paper-test-toolkit 11.0.0-SNAPSHOT test dev.jorel - commandapi-bukkit-shade + commandapi-paper-shade 11.0.0-SNAPSHOT compile - org.spigotmc - spigot-api - 1.21.1-R0.1-SNAPSHOT + io.papermc.paper + paper-api + 1.21.8-R0.1-SNAPSHOT provided org.junit.jupiter junit-jupiter-engine - 5.8.2 + 5.13.3 test diff --git a/examples/bukkit/automated-tests-shaded/pom.xml b/examples/bukkit/automated-tests-shaded/pom.xml index 4f859be2d..0ac41c201 100644 --- a/examples/bukkit/automated-tests-shaded/pom.xml +++ b/examples/bukkit/automated-tests-shaded/pom.xml @@ -18,12 +18,12 @@ - + org.mockbukkit.mockbukkit mockbukkit-v1.21 - 4.45.1 + 4.76.0 provided @@ -31,7 +31,7 @@ dev.jorel - commandapi-spigot-test-toolkit + commandapi-paper-test-toolkit 11.0.0-SNAPSHOT test @@ -39,16 +39,16 @@ dev.jorel - commandapi-spigot-shade + commandapi-paper-shade 11.0.0-SNAPSHOT compile - + - org.spigotmc - spigot-api - 1.21.1-R0.1-SNAPSHOT + io.papermc.paper + paper-api + 1.21.8-R0.1-SNAPSHOT provided @@ -56,7 +56,7 @@ org.junit.jupiter junit-jupiter-engine - 5.8.2 + 5.13.3 test diff --git a/examples/bukkit/automated-tests-shaded/src/main/java/io/github/jorelali/Main.java b/examples/bukkit/automated-tests-shaded/src/main/java/io/github/jorelali/Main.java index 5c29abe06..0d96cbeeb 100644 --- a/examples/bukkit/automated-tests-shaded/src/main/java/io/github/jorelali/Main.java +++ b/examples/bukkit/automated-tests-shaded/src/main/java/io/github/jorelali/Main.java @@ -11,7 +11,7 @@ public class Main extends JavaPlugin { @Override public void onLoad() { // Load CommandAPI as usual - CommandAPI.onLoad(new CommandAPISpigotConfig(this)); + CommandAPI.onLoad(new CommandAPIPaperConfig(this)); } @Override diff --git a/examples/bukkit/automated-tests/README.md b/examples/bukkit/automated-tests/README.md index f9470a415..4ede288d8 100644 --- a/examples/bukkit/automated-tests/README.md +++ b/examples/bukkit/automated-tests/README.md @@ -4,42 +4,42 @@ A simple example showcasing testing CommandAPI commands with [MockBukkit](https: Key points: -- The MockBukkit and `commandapi-spigot-test-toolkit` dependencies are listed with the `test` scope before the normal dependencies for `commandapi-spigot-core` and `spigot-api`. This ensures that when running tests, certain classes that are compatible with the testing environment override the regular classes. There is also a dependency for the [JUnit](https://junit.org/junit5/) API, which helps when writing the tests. +- The MockBukkit and `commandapi-paper-test-toolkit` dependencies are listed with the `test` scope before the normal dependencies for `commandapi-paper-core` and `paper-api`. This ensures that when running tests, certain classes that are compatible with the testing environment override the regular classes. There is also a dependency for the [JUnit](https://junit.org/junit5/) API, which helps when writing the tests. ```xml org.mockbukkit.mockbukkit mockbukkit-v1.21 - 4.45.1 + 4.76.0 test dev.jorel - commandapi-spigot-test-toolkit + commandapi-paper-test-toolkit 11.0.0-SNAPSHOT test dev.jorel - commandapi-spigot-core + commandapi-paper-core 11.0.0-SNAPSHOT provided - org.spigotmc - spigot-api - 1.21.1-R0.1-SNAPSHOT + io.papermc.paper + paper-api + 1.21.8-R0.1-SNAPSHOT provided org.junit.jupiter junit-jupiter-engine - 5.8.2 + 5.13.3 test diff --git a/examples/bukkit/automated-tests/pom.xml b/examples/bukkit/automated-tests/pom.xml index 46640d3fb..5c02c2c6a 100644 --- a/examples/bukkit/automated-tests/pom.xml +++ b/examples/bukkit/automated-tests/pom.xml @@ -18,12 +18,12 @@ - + org.mockbukkit.mockbukkit mockbukkit-v1.21 - 4.45.1 + 4.76.0 test @@ -31,7 +31,7 @@ dev.jorel - commandapi-spigot-test-toolkit + commandapi-paper-test-toolkit 11.0.0-SNAPSHOT test @@ -39,16 +39,16 @@ dev.jorel - commandapi-spigot-core + commandapi-paper-core 11.0.0-SNAPSHOT provided - + - org.spigotmc - spigot-api - 1.21.1-R0.1-SNAPSHOT + io.papermc.paper + paper-api + 1.21.8-R0.1-SNAPSHOT provided @@ -56,7 +56,7 @@ org.junit.jupiter junit-jupiter-engine - 5.8.2 + 5.13.3 test diff --git a/pom.xml b/pom.xml index bc132b308..79968b198 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ org.mockbukkit.mockbukkit mockbukkit-v1.21 - 4.72.8 + 4.76.0 provided From d1db2c258615c8931938508114137b768041fff2 Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Sat, 6 Sep 2025 17:08:40 -0400 Subject: [PATCH 38/63] Update javadocs in MockCommandAPI.java --- .../main/java/dev/jorel/commandapi/MockCommandAPI.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java index 9a5f0e96f..621b958eb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/MockCommandAPI.java @@ -6,9 +6,8 @@ import java.lang.reflect.Field; -// TODO: Update javadocs /** - * An implementation of {@link CommandAPIBukkit} that is compatible with a MockBukkit testing environment. + * Additional logic that helps the CommandAPI run in a MockBukkit testing environment. * Does not rely on any version-specific Minecraft code to (ideally) support testing in any version. */ public class MockCommandAPI { @@ -23,13 +22,16 @@ protected MockCommandAPI(CommandAPIBukkit commandAPIBukkit) { } /** - * @return The {@link MockCommandAPI} instance currently loaded. This is the same object as is returned by - * {@link CommandAPIBukkit#get()}, but explicitly using the {@link MockCommandAPI} class. + * @return The {@link MockCommandAPI} instance currently loaded. */ public static MockCommandAPI getInstance() { return instance; } + /** + * @return The implementation of {@link CommandAPIBukkit} which is currently loaded. This is the same object + * as is returned by {@link CommandAPIBukkit#get()}, but explicitly using the {@link MockCommandSource} class. + */ public CommandAPIBukkit getCommandAPIBukkit() { return commandAPIBukkit; } From 4311e34224f69e86f3351aaa36241a319be07392 Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Sat, 6 Sep 2025 17:26:05 -0400 Subject: [PATCH 39/63] Fix some comments --- .../dev/jorel/commandapi/MockInternalBukkitConfig.java | 9 --------- .../dev/jorel/commandapi/CommandAPIVersionHandler.java | 4 ++-- .../dev/jorel/commandapi/CommandAPIVersionHandler.java | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockInternalBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockInternalBukkitConfig.java index ace4a8f86..2f3b385ef 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockInternalBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/test/java/dev/jorel/commandapi/MockInternalBukkitConfig.java @@ -3,22 +3,13 @@ import org.bukkit.plugin.java.JavaPlugin; public class MockInternalBukkitConfig extends InternalBukkitConfig { - private final JavaPlugin plugin; - /** - * Creates an {@link InternalBukkitConfig} from a {@link CommandAPIBukkitConfig} - * - * @param config The configuration to use to set up this internal configuration - */ public MockInternalBukkitConfig(MockCommandAPIBukkitConfig config) { super(config); this.plugin = config.plugin; } - /** - * @return the {@link JavaPlugin} loading the CommandAPI - */ public JavaPlugin getPlugin() { return plugin; } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 9b0a93c76..64db6977d 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -5,7 +5,7 @@ import java.util.function.Function; public abstract class CommandAPIVersionHandler { - // Allow loading a different platform implementation (most likely to implement something `MockCommandAPISpigot` doesn't) + // Allow loading a different platform implementation (most likely to implement something `MockCommandAPIPaper` doesn't) private static Function> alternativePlatform = null; /** @@ -28,7 +28,7 @@ static LoadContext getPlatform(CommandAPIConfig config) { throw new IllegalArgumentException("CommandAPIPaper was loaded with non-Paper config!"); } - // Default to MockCommandAPIBukkit if not given + // Default to MockCommandAPIPaper if not given CommandAPIPlatform platform = alternativePlatform == null ? new MockCommandAPIPaper(internalPaperConfig, new MockPaperNMS()) : alternativePlatform.apply(internalPaperConfig); diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index d21e9e26e..604836bd7 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -26,7 +26,7 @@ static LoadContext getPlatform(CommandAPIConfig config) { throw new IllegalArgumentException("CommandAPISpigot was loaded with non-Spigot config!"); } - // Default to MockCommandAPIBukkit if not given + // Default to MockCommandAPISpigot if not given CommandAPIPlatform platform = alternativePlatform == null ? new MockCommandAPISpigot(internalSpigotConfig) : alternativePlatform.apply(internalSpigotConfig); From 160a8fcc878036c9476c615eb75a21e0ec9f8d7e Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sun, 28 Sep 2025 02:31:25 +0200 Subject: [PATCH 40/63] Exclude the non-existent spark dependency --- .../commandapi-paper-nms/commandapi-paper-1.21/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml index 0fca60096..80e636984 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml @@ -53,6 +53,12 @@ paper-nms 1.21-SNAPSHOT provided + + + me.lucko + spark-paper + + From d219f4610d1d4a0502366adad7901a97a3d3ad42 Mon Sep 17 00:00:00 2001 From: willkroboth <46540330+willkroboth@users.noreply.github.com> Date: Sun, 28 Sep 2025 18:02:09 -0400 Subject: [PATCH 41/63] Apply suggestions from code review Fix copy-paste error Co-authored-by: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> --- .../main/java/dev/jorel/commandapi/BukkitExecutable.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java index 099436f95..69625673c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/BukkitExecutable.java @@ -480,7 +480,7 @@ default Impl executesFeedbackForwarding(FeedbackForwardingCommandExecutor execut default Impl executesFeedbackForwarding(FeedbackForwardingExecutionInfo info) { Platform platform = CommandAPIBukkit.get().activePlatform(); if (platform != Platform.PAPER) { - throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + platform.name() + ")!"); + throw new PlatformException("Attempted to use a FeedbackForwardingExecutionInfo on a non-paper platform (" + platform.name() + ")!"); } getExecutor().addNormalExecutor(info); return instance(); @@ -495,7 +495,7 @@ default Impl executesFeedbackForwarding(FeedbackForwardingExecutionInfo info) { default Impl executesFeedbackForwarding(FeedbackForwardingResultingCommandExecutor executor) { Platform platform = CommandAPIBukkit.get().activePlatform(); if (platform != Platform.PAPER) { - throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + platform.name() + ")!"); + throw new PlatformException("Attempted to use a FeedbackForwardingResultingCommandExecutor on a non-paper platform (" + platform.name() + ")!"); } getExecutor().addResultingExecutor(executor); return instance(); @@ -510,7 +510,7 @@ default Impl executesFeedbackForwarding(FeedbackForwardingResultingCommandExecut default Impl executesFeedbackForwarding(FeedbackForwardingResultingExecutionInfo info) { Platform platform = CommandAPIBukkit.get().activePlatform(); if (platform != Platform.PAPER) { - throw new PlatformException("Attempted to use a FeedbackForwardingCommandExecutor on a non-paper platform (" + platform.name() + ")!"); + throw new PlatformException("Attempted to use a FeedbackForwardingResultingExecutionInfo on a non-paper platform (" + platform.name() + ")!"); } getExecutor().addResultingExecutor(info); return instance(); From 19f00fc229d4a1cfc29d8dbe92de048126707d9a Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Wed, 1 Oct 2025 00:36:20 +0200 Subject: [PATCH 42/63] Add support for Minecraft 1.21.9 --- .../commandapi-bukkit-1.21.9/pom.xml | 168 +++ .../dev/jorel/commandapi/nms/NMS_1_21_R6.java | 1073 +++++++++++++++++ .../nms/NativeProxyCommandSender_1_21_R6.java | 35 + .../src/test/java/SafeReflect.java | 44 + .../commandapi-bukkit-nms-dependency/pom.xml | 5 + .../commandapi-bukkit-nms/pom.xml | 1 + .../commandapi-paper-1.20.5/pom.xml | 2 +- .../commandapi-paper-1.21.2/pom.xml | 2 +- .../commandapi-paper-1.21.4/pom.xml | 2 +- .../commandapi-paper-1.21.5/pom.xml | 2 +- .../commandapi-paper-1.21.6/pom.xml | 2 +- .../commandapi-paper-1.21.9/pom.xml | 111 ++ .../commandapi/nms/PaperNMS_1_21_R6.java | 59 + .../commandapi-paper-1.21/pom.xml | 2 +- .../commandapi-paper-nms-dependency/pom.xml | 11 + .../commandapi-paper-nms/pom.xml | 1 + .../commandapi-paper-shade/pom.xml | 4 + .../commandapi/CommandAPIVersionHandler.java | 4 +- .../commandapi-spigot-1.21.9/pom.xml | 150 +++ .../commandapi/nms/SpigotNMS_1_21_R6.java | 91 ++ .../commandapi-spigot-nms-dependency/pom.xml | 10 + .../commandapi-spigot-nms/pom.xml | 1 + .../commandapi/CommandAPIVersionHandler.java | 4 +- commandapi-platforms/pom.xml | 12 +- setupPaperNMS.sh | 3 + 25 files changed, 1785 insertions(+), 14 deletions(-) create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R6.java create mode 100644 commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/test/java/SafeReflect.java create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R6.java create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R6.java diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml new file mode 100644 index 000000000..647d0f20d --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml @@ -0,0 +1,168 @@ + + + + + + commandapi-bukkit-nms + dev.jorel + 11.0.0-SNAPSHOT + + 4.0.0 + + commandapi-bukkit-1.21.9 + Bukkit support for 1.21.9 + + + 1.21.9-R0.1-SNAPSHOT + 1.21.9-R0.1-SNAPSHOT + 1.21.9-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + dev.jorel + commandapi-bukkit-core + ${project.version} + compile + + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java new file mode 100644 index 000000000..143f0855d --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java @@ -0,0 +1,1073 @@ +/******************************************************************************* + * Copyright 2024 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.ImmutableList; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.Message; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.mojang.datafixers.util.Pair; +import com.mojang.logging.LogUtils; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIHandler; +import dev.jorel.commandapi.SafeVarHandle; +import dev.jorel.commandapi.arguments.SuggestionProviders; +import dev.jorel.commandapi.arguments.parser.EntitySelectorParser; +import dev.jorel.commandapi.arguments.parser.RegistryParser; +import dev.jorel.commandapi.commandsenders.AbstractCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitCommandSender; +import dev.jorel.commandapi.commandsenders.BukkitNativeProxyCommandSender; +import dev.jorel.commandapi.preprocessor.Differs; +import dev.jorel.commandapi.preprocessor.NMSMeta; +import dev.jorel.commandapi.preprocessor.RequireField; +import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; +import dev.jorel.commandapi.wrappers.DoubleRange; +import dev.jorel.commandapi.wrappers.FunctionWrapper; +import dev.jorel.commandapi.wrappers.IntegerRange; +import dev.jorel.commandapi.wrappers.Location2D; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; +import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; +import dev.jorel.commandapi.wrappers.ScoreboardSlot; +import dev.jorel.commandapi.wrappers.SimpleFunctionWrapper; +import net.minecraft.advancements.AdvancementHolder; +import net.minecraft.advancements.critereon.MinMaxBounds; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandResultCallback; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.FunctionInstantiationException; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.DimensionArgument; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.commands.arguments.ObjectiveArgument; +import net.minecraft.commands.arguments.ParticleArgument; +import net.minecraft.commands.arguments.RangeArgument; +import net.minecraft.commands.arguments.ResourceArgument; +import net.minecraft.commands.arguments.ResourceKeyArgument; +import net.minecraft.commands.arguments.ResourceLocationArgument; +import net.minecraft.commands.arguments.ScoreHolderArgument; +import net.minecraft.commands.arguments.ScoreboardSlotArgument; +import net.minecraft.commands.arguments.TeamArgument; +import net.minecraft.commands.arguments.blocks.BlockInput; +import net.minecraft.commands.arguments.blocks.BlockStateArgument; +import net.minecraft.commands.arguments.coordinates.RotationArgument; +import net.minecraft.commands.arguments.coordinates.Vec2Argument; +import net.minecraft.commands.arguments.item.FunctionArgument; +import net.minecraft.commands.arguments.item.ItemArgument; +import net.minecraft.commands.arguments.item.ItemInput; +import net.minecraft.commands.arguments.item.ItemPredicateArgument; +import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.commands.execution.ExecutionContext; +import net.minecraft.commands.functions.CommandFunction; +import net.minecraft.commands.functions.InstantiatedFunction; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.particles.BlockParticleOption; +import net.minecraft.core.particles.ColorParticleOption; +import net.minecraft.core.particles.DustColorTransitionOptions; +import net.minecraft.core.particles.DustParticleOptions; +import net.minecraft.core.particles.ItemParticleOption; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.SculkChargeParticleOptions; +import net.minecraft.core.particles.ShriekParticleOption; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.core.particles.TrailParticleOption; +import net.minecraft.core.particles.VibrationParticleOption; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.network.chat.ComponentSerialization; +import net.minecraft.resources.RegistryOps; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.MinecraftServer.ReloadableResources; +import net.minecraft.server.ServerFunctionLibrary; +import net.minecraft.server.ServerFunctionManager; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.packs.PackResources; +import net.minecraft.server.packs.PackType; +import net.minecraft.server.packs.repository.Pack; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.server.packs.resources.MultiPackResourceManager; +import net.minecraft.server.packs.resources.SimpleReloadInstance; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.util.Unit; +import net.minecraft.util.profiling.Profiler; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.flag.FeatureFlagSet; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; +import net.minecraft.world.level.DataPackConfig; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.WorldDataConfiguration; +import net.minecraft.world.level.block.entity.FuelValues; +import net.minecraft.world.level.gameevent.BlockPositionSource; +import net.minecraft.world.phys.Vec2; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.scores.ScoreHolder; +import org.bukkit.Bukkit; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.Particle.DustOptions; +import org.bukkit.Particle.DustTransition; +import org.bukkit.Particle.Trail; +import org.bukkit.Registry; +import org.bukkit.Sound; +import org.bukkit.Vibration; +import org.bukkit.Vibration.Destination; +import org.bukkit.Vibration.Destination.BlockDestination; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.command.CommandSender; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R6.CraftLootTable; +import org.bukkit.craftbukkit.v1_21_R6.CraftParticle; +import org.bukkit.craftbukkit.v1_21_R6.CraftRegistry; +import org.bukkit.craftbukkit.v1_21_R6.CraftServer; +import org.bukkit.craftbukkit.v1_21_R6.CraftSound; +import org.bukkit.craftbukkit.v1_21_R6.CraftWorld; +import org.bukkit.craftbukkit.v1_21_R6.block.CraftBlockEntityState; +import org.bukkit.craftbukkit.v1_21_R6.block.CraftBlockStates; +import org.bukkit.craftbukkit.v1_21_R6.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_21_R6.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R6.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_21_R6.help.CustomHelpTopic; +import org.bukkit.craftbukkit.v1_21_R6.help.SimpleHelpMap; +import org.bukkit.craftbukkit.v1_21_R6.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_21_R6.potion.CraftPotionEffectType; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.help.HelpTopic; +import org.bukkit.inventory.Recipe; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.ToIntFunction; + +// Mojang-Mapped reflection + +/** + * NMS implementation for Minecraft 1.21.9 + */ +@NMSMeta(compatibleWith = {"1.21.9"}) +@RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) +@RequireField(in = EntitySelector.class, name = "usesSelector", ofType = boolean.class) +// @RequireField(in = ItemInput.class, name = "tag", ofType = CompoundTag.class) +@RequireField(in = ServerFunctionLibrary.class, name = "dispatcher", ofType = CommandDispatcher.class) +@RequireField(in = MinecraftServer.class, name = "fuelValues", ofType = FuelValues.class) +@RequireField(in = BlockInput.class, name = "tag", ofType = CompoundTag.class) +public class NMS_1_21_R6 extends NMS_Common { + + private static final SafeVarHandle> helpMapTopics; + private static final Field entitySelectorUsesSelector; + // private static final SafeVarHandle itemInput; + private static final Field serverFunctionLibraryDispatcher; + private static final MethodHandle minecraftServerSetSelected; + private static final SafeVarHandle minecraftServerFuelValues; + private static final SafeVarHandle blockInputTag; + + // Derived from net.minecraft.commands.Commands; + private final Supplier commandBuildContext; + + public NMS_1_21_R6(Supplier commandBuildContext) { + this.commandBuildContext = commandBuildContext; + } + + // Compute all var handles all in one go so we don't do this during main server + // runtime + static { + helpMapTopics = SafeVarHandle.ofOrNull(SimpleHelpMap.class, "helpTopics", "helpTopics", Map.class); + // For some reason, MethodHandles fails for this field, but Field works okay + entitySelectorUsesSelector = CommandAPIHandler.getField(EntitySelector.class, "p", "usesSelector"); + // itemInput = SafeVarHandle.ofOrNull(ItemInput.class, "c", "tag", CompoundTag.class); + // For some reason, MethodHandles fails for this field, but Field works okay + serverFunctionLibraryDispatcher = CommandAPIHandler.getField(ServerFunctionLibrary.class, "h", "dispatcher"); + blockInputTag = SafeVarHandle.ofOrNull(BlockInput.class, "d", "tag", CompoundTag.class); + + MethodHandles.Lookup lookup = MethodHandles.lookup(); + MethodHandle setSelected; + try { + setSelected = lookup.findVirtual(PackRepository.class, "setSelected", MethodType.methodType(void.class, Collection.class, boolean.class)); + } catch (NoSuchMethodException | IllegalAccessException e) { + // We're on Spigot or Paper 1.21.4 build 62 or earlier + setSelected = null; + } + minecraftServerSetSelected = setSelected; + + minecraftServerFuelValues = SafeVarHandle.ofOrNull(MinecraftServer.class, "aE", "fuelValues", FuelValues.class); + } + + // Implementation taken from io.papermc.paper.adventure.WrapperAwareSerializer#deserialize(Component) + String toJson(net.minecraft.network.chat.Component component) { + MinecraftServer server = this.getMinecraftServer(); + RegistryAccess.Frozen access = server.registryAccess(); + RegistryOps ops = access.createSerializationContext(JsonOps.INSTANCE); + JsonElement element = ComponentSerialization.CODEC.encodeStart(ops, component) + .getOrThrow(s -> new RuntimeException("Failed to encode Minecraft Component: " + component + "; " + s)); + return new Gson().toJson(element); + } + + net.minecraft.network.chat.Component fromJson(String json) { + Pair result = ComponentSerialization.CODEC.decode(JsonOps.INSTANCE, JsonParser.parseString(json)) + .getOrThrow(s -> new RuntimeException("Failed to decode Component: " + json + "; " + s)); + return result.getFirst(); + } + + @Override + protected CommandBuildContext getCommandBuildContext() { + return commandBuildContext.get(); + } + + @Override + public ArgumentType _ArgumentAdvancement() { + return ResourceKeyArgument.key(Registries.ADVANCEMENT); + } + + @Override + public ArgumentType _ArgumentChatComponent() { + return ComponentArgument.textComponent(commandBuildContext.get()); + } + + @Override + public final ArgumentType _ArgumentEnchantment() { + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENCHANTMENT); + } + + @Override + public ArgumentType _ArgumentRecipe() { + return ResourceKeyArgument.key(Registries.RECIPE); + } + + @Override + public final ArgumentType _ArgumentSyntheticBiome() { + return ResourceArgument.resource(commandBuildContext.get(), Registries.BIOME); + } + + @Override + public final Map getHelpMap() { + return helpMapTopics.get((SimpleHelpMap) Bukkit.getHelpMap()); + } + + @Override + public String[] compatibleVersions() { + return new String[]{"1.21.6", "1.21.7", "1.21.8"}; + } + + private String serializeNMSItemStack(ItemStack is) { + return new ItemInput(is.getItemHolder(), is.getComponentsPatch()).serialize(commandBuildContext.get()); + } + + @Override + public final String convert(org.bukkit.inventory.ItemStack is) { + return serializeNMSItemStack(CraftItemStack.asNMSCopy(is)); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Override + public final String convert(ParticleData particle) { + final ParticleOptions particleOptions = CraftParticle.createParticleParam(particle.particle(), particle.data()); + final ResourceLocation particleKey = BuiltInRegistries.PARTICLE_TYPE.getKey(particleOptions.getType()); + + // /particle dust{scale:2,color:[1,2,2]} + // Use the particle option's codec to convert the data into NBT. If we have any tags, add them + // to the end, otherwise leave it as it is (e.g. `/particle crit` as opposed to `/particle crit{}`) + final Codec codec = particleOptions.getType().codec().codec(); + final DataResult result = codec.encodeStart(NbtOps.INSTANCE, particleOptions); + final CompoundTag particleOptionsTag = result.result().get(); + final String dataString = particleOptionsTag.keySet().isEmpty() ? "" : particleOptionsTag.toString(); // TODO: Check if this is correct + return particleKey.toString() + dataString; + } + + /** + * An implementation of {@link ServerFunctionManager#execute(CommandFunction, CommandSourceStack)} with a specified + * command result callback instead of {@link CommandResultCallback.EMPTY} + * + * @param commandFunction the command function to run + * @param css the command source stack to execute this command + * @return the result of our function. This is either 0 is the command failed, or greater than 0 if the command succeeded + */ + private final int runCommandFunction(CommandFunction commandFunction, CommandSourceStack css) { + // Profile the function. We want to simulate the execution sequence exactly + ProfilerFiller profiler = Profiler.get(); + profiler.push(() -> "function " + commandFunction.id()); + + // Store our function result + AtomicInteger result = new AtomicInteger(); + CommandResultCallback onCommandResult = (succeeded, resultValue) -> result.set(resultValue); + + try { + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); + net.minecraft.commands.Commands.executeCommandInContext(css, (executioncontext) -> { + ExecutionContext.queueInitialFunctionCall(executioncontext, instantiatedFunction, css, onCommandResult); + }); + } catch (FunctionInstantiationException functionInstantiationException) { + // We don't care if the function failed to instantiate + assert true; + } catch (Exception exception) { + LogUtils.getLogger().warn("Failed to execute function {}", commandFunction.id(), exception); + } finally { + profiler.pop(); + } + + return result.get(); + } + + // Converts NMS function to SimpleFunctionWrapper + private final SimpleFunctionWrapper convertFunction(CommandFunction commandFunction) { + ToIntFunction appliedObj = (CommandSourceStack css) -> runCommandFunction(commandFunction, css); + + // Unpack the commands by instantiating the function with no CSS, then retrieving its entries + String[] commands = new String[0]; + try { + final InstantiatedFunction instantiatedFunction = commandFunction.instantiate((CompoundTag) null, + CommandAPIBukkit.get().getBrigadierDispatcher()); + + List cArr = instantiatedFunction.entries(); + commands = new String[cArr.size()]; + for (int i = 0, size = cArr.size(); i < size; i++) { + commands[i] = cArr.get(i).toString(); + } + } catch (FunctionInstantiationException functionInstantiationException) { + // We don't care if the function failed to instantiate + assert true; + } + return new SimpleFunctionWrapper(fromResourceLocation(commandFunction.id()), appliedObj, commands); + } + + @Override + public final HelpTopic generateHelpTopic(String commandName, String shortDescription, String fullDescription, + String permission) { + return new CustomHelpTopic(commandName, shortDescription, fullDescription, permission); + } + + @Override + public Advancement getAdvancement(CommandContext cmdCtx, String key) + throws CommandSyntaxException { + return ResourceKeyArgument.getAdvancement(cmdCtx, key).toBukkit(); + } + + @Override + public final RegistryParser getBiome(CommandContext cmdCtx, String key) throws CommandSyntaxException { + final ResourceLocation resourceLocation = ResourceArgument.getResource(cmdCtx, key, Registries.BIOME).key().location(); + return new RegistryParser<>( + () -> { + Biome biome; + try { + biome = Biome.valueOf(resourceLocation.getPath().toUpperCase()); + } catch(IllegalArgumentException biomeNotFound) { + biome = null; + } + return biome; + }, + () -> fromResourceLocation(resourceLocation) + ); + } + + @Override + public final BlockState getBlockState(CommandContext cmdCtx, String key) { + BlockInput input = BlockStateArgument.getBlock(cmdCtx, key); + BlockState snapshot = CraftBlockStates.getBlockState(CraftRegistry.getMinecraftRegistry(), BlockPos.ZERO, input.getState(), null); + if (blockInputTag.get(input) != null && snapshot instanceof CraftBlockEntityState blockEntitySnapshot) { + blockEntitySnapshot.loadData(blockInputTag.get(input)); + } + return snapshot; + } + + @Override + public CommandSourceStack getBrigadierSourceFromCommandSender( + AbstractCommandSender sender) { + return VanillaCommandWrapper.getListener(sender.getSource()); + } + + @Override + public final World getDimension(CommandContext cmdCtx, String key) + throws CommandSyntaxException { + return DimensionArgument.getDimension(cmdCtx, key).getWorld(); + } + + @Override + public final Enchantment getEnchantment(CommandContext cmdCtx, String key) + throws CommandSyntaxException { + final net.minecraft.world.item.enchantment.Enchantment enchantment = ResourceArgument.getEnchantment(cmdCtx, key).value(); + final ResourceLocation resource = this.getMinecraftServer().registryAccess().lookupOrThrow(Registries.ENCHANTMENT).getKey(enchantment); + return Registry.ENCHANTMENT.get(fromResourceLocation(resource)); + } + + @Override + public final EntitySelectorParser getEntitySelector(CommandContext cmdCtx, String str) { + + // We override the rule whereby players need "minecraft.command.selector" and + // have to have level 2 permissions in order to use entity selectors. We're + // trying to allow entity selectors to be used by anyone that registers a + // command via the CommandAPI. + EntitySelector argument = cmdCtx.getArgument(str, EntitySelector.class); + try { + entitySelectorUsesSelector.set(argument, false); + } catch (IllegalAccessException e) { + // Shouldn't happen, CommandAPIHandler#getField makes it accessible + } + + return new EntitySelectorParser( + () -> argument.findSinglePlayer(cmdCtx.getSource()).getBukkitEntity(), + () -> argument.findSingleEntity(cmdCtx.getSource()).getBukkitEntity(), + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (ServerPlayer player : argument.findPlayers(cmdCtx.getSource())) { + result.add(player.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_PLAYERS_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } + } + }, + (allowEmpty) -> { + try { + List result = new ArrayList<>(); + for (Entity entity : argument.findEntities(cmdCtx.getSource())) { + result.add(entity.getBukkitEntity()); + } + if (result.isEmpty() && !allowEmpty) { + throw EntityArgument.NO_ENTITIES_FOUND.create(); + } else { + return result; + } + } catch (CommandSyntaxException e) { + if (allowEmpty) { + return new ArrayList(); + } else { + throw e; + } + } + } + ); + } + + @Override + public DoubleRange getDoubleRange(CommandContext cmdCtx, String key) { + MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cmdCtx, key); + final Double lowBoxed = range.min().orElse(null); + final Double highBoxed = range.max().orElse(null); + final double low = lowBoxed == null ? -Double.MAX_VALUE : lowBoxed; + final double high = highBoxed == null ? Double.MAX_VALUE : highBoxed; + return new DoubleRange(low, high); + } + + @Override + public final FunctionWrapper[] getFunction(CommandContext cmdCtx, String key) + throws CommandSyntaxException { + List result = new ArrayList<>(); + CommandSourceStack css = cmdCtx.getSource().withSuppressedOutput().withMaximumPermission(2); + + for (CommandFunction commandFunction : FunctionArgument.getFunctions(cmdCtx, key)) { + result.add(FunctionWrapper.fromSimpleFunctionWrapper(convertFunction(commandFunction), css, + entity -> cmdCtx.getSource().withEntity(((CraftEntity) entity).getHandle()))); + } + return result.toArray(new FunctionWrapper[0]); + } + + @Override + public SimpleFunctionWrapper getFunction(NamespacedKey key) { + final ResourceLocation resourceLocation = ResourceLocation.fromNamespaceAndPath(key.getNamespace(), key.getKey()); + Optional> commandFunctionOptional = this + .getMinecraftServer().getFunctions().get(resourceLocation); + if (commandFunctionOptional.isPresent()) { + return convertFunction(commandFunctionOptional.get()); + } else { + throw new IllegalStateException("Failed to get defined function " + key + + "! This should never happen - please report this to the CommandAPI" + + "developers, we'd love to know how you got this error message!"); + } + } + + @Override + public Set getFunctions() { + Set result = new HashSet<>(); + for (ResourceLocation resourceLocation : this.getMinecraftServer().getFunctions() + .getFunctionNames()) { + result.add(fromResourceLocation(resourceLocation)); + } + return result; + } + + @Override + public IntegerRange getIntRange(CommandContext cmdCtx, String key) { + MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cmdCtx, key); + final Integer lowBoxed = range.min().orElse(null); + final Integer highBoxed = range.max().orElse(null); + final int low = lowBoxed == null ? Integer.MIN_VALUE : lowBoxed; + final int high = highBoxed == null ? Integer.MAX_VALUE : highBoxed; + return new IntegerRange(low, high); + } + + @Override + public final org.bukkit.inventory.ItemStack getItemStack(CommandContext cmdCtx, String key) + throws CommandSyntaxException { + ItemInput input = ItemArgument.getItem(cmdCtx, key); + + // Create the basic ItemStack with an amount of 1 + net.minecraft.world.item.ItemStack item = input.createItemStack(1, false); + return CraftItemStack.asBukkitCopy(item); + } + + @Override + public final Predicate getItemStackPredicate( + CommandContext cmdCtx, String key) throws CommandSyntaxException { + // Not inside the lambda because getItemPredicate throws CommandSyntaxException + Predicate predicate = ItemPredicateArgument.getItemPredicate(cmdCtx, key); + return item -> predicate.test(CraftItemStack.asNMSCopy(item)); + } + + @Override + public final Location2D getLocation2DPrecise(CommandContext cmdCtx, String key) throws CommandSyntaxException { + Vec2 vecPos = Vec2Argument.getVec2(cmdCtx, key); + return new Location2D(getWorldForCSS(cmdCtx.getSource()), vecPos.x, vecPos.y); + } + + @Override + public final org.bukkit.loot.LootTable getLootTable(CommandContext cmdCtx, String key) { + return CraftLootTable.minecraftToBukkit(ResourceLocationArgument.getId(cmdCtx, key)); + } + + @Override + public NamespacedKey getMinecraftKey(CommandContext cmdCtx, String key) { + return fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)); + } + + @Override + public final Objective getObjective(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String objectiveName = ObjectiveArgument.getObjective(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getObjective(objectiveName); + } + + @Override + public final ParticleData getParticle(CommandContext cmdCtx, String key) { + final ParticleOptions particleOptions = ParticleArgument.getParticle(cmdCtx, key); + + // In our test suite, we can't parse particles via CraftParticle.minecraftToBukkit + // on 1.20.3+ because initializing CraftParticle's static constructor requires + // implementing a registry. We don't care about a registry for the sake of testing, + // all we're actually interested in is testing that the particle data is being parsed + // and converted to Bukkit properly, because that's what actually matters. If the + // Bukkit#getServer is a CraftServer, that means we're running on a normal (Bukkit/Spigot/Paper) + // server. If it isn't, that means we're running in our test environment (i.e. a mocked + // server instance), or some weird flavour of Bukkit that we're not supposed to use. + final Particle particle; + if (Bukkit.getServer() instanceof CraftServer server) { + particle = CraftParticle.minecraftToBukkit(particleOptions.getType()); + } else { + particle = null; + } + + if (particleOptions instanceof SimpleParticleType) { + return new ParticleData(particle, null); + } else if (particleOptions instanceof BlockParticleOption options) { + return new ParticleData(particle, CraftBlockData.fromData(options.getState())); + } else if (particleOptions instanceof DustColorTransitionOptions options) { + return getParticleDataAsDustColorTransitionOption(particle, options); + } else if (particleOptions instanceof DustParticleOptions options) { + final Color color = Color.fromRGB((int) (options.getColor().x() * 255.0F), + (int) (options.getColor().y() * 255.0F), (int) (options.getColor().z() * 255.0F)); + return new ParticleData(particle, new DustOptions(color, options.getScale())); + } else if (particleOptions instanceof ItemParticleOption options) { + return new ParticleData(particle, + CraftItemStack.asBukkitCopy(options.getItem())); + } else if (particleOptions instanceof VibrationParticleOption options) { + return getParticleDataAsVibrationParticleOption(cmdCtx, particle, options); + } else if (particleOptions instanceof ShriekParticleOption options) { + // CraftBukkit implements shriek particles as a (boxed) Integer object + return new ParticleData(particle, Integer.valueOf(options.getDelay())); + } else if (particleOptions instanceof SculkChargeParticleOptions options) { + // CraftBukkit implements sculk charge particles as a (boxed) Float object + return new ParticleData(particle, Float.valueOf(options.roll())); + } else if (particleOptions instanceof ColorParticleOption options) { + return getParticleDataAsColorParticleOption(particle, options); + } else if (particleOptions instanceof TrailParticleOption options) { + return getParticleDataAsTrailParticleOption(cmdCtx, particle, options); + } else { + CommandAPI.getLogger().warning("Invalid particle data type for " + particle.getDataType().toString()); + return new ParticleData(particle, null); + } + } + + private ParticleData getParticleDataAsTrailParticleOption(CommandContext cmdCtx, + Particle particle, TrailParticleOption options) { + final Level level = cmdCtx.getSource().getLevel(); + final Vec3 target = options.target(); + final Location targetLocation = new Location(level.getWorld(), target.x, target.y, target.z); + final Color color = Color.fromARGB(options.color()); + return new ParticleData(particle, new Trail(targetLocation, color, options.duration())); + } + + private ParticleData getParticleDataAsColorParticleOption(Particle particle, + ColorParticleOption options) { + final Color color = Color.fromARGB( + (int) (options.getAlpha() * 255.0F), + (int) (options.getRed() * 255.0F), + (int) (options.getGreen() * 255.0F), + (int) (options.getBlue() * 255.0F) + ); + return new ParticleData(particle, color); + } + + private ParticleData getParticleDataAsDustColorTransitionOption(Particle particle, + DustColorTransitionOptions options) { + final Color color = Color.fromRGB((int) (options.getFromColor().x() * 255.0F), + (int) (options.getFromColor().y() * 255.0F), (int) (options.getFromColor().z() * 255.0F)); + final Color toColor = Color.fromRGB((int) (options.getToColor().x() * 255.0F), + (int) (options.getToColor().y() * 255.0F), (int) (options.getToColor().z() * 255.0F)); + return new ParticleData(particle, new DustTransition(color, toColor, options.getScale())); + } + + private ParticleData getParticleDataAsVibrationParticleOption(CommandContext cmdCtx, + Particle particle, VibrationParticleOption options) { + // The "from" part of the Vibration object in Bukkit is completely ignored now, + // so we just populate it with some "feasible" information + final Vec3 origin = cmdCtx.getSource().getPosition(); + Level level = cmdCtx.getSource().getLevel(); + Location from = new Location(level.getWorld(), origin.x, origin.y, origin.z); + final Destination destination; + + if (options.getDestination() instanceof BlockPositionSource positionSource) { + Vec3 to = positionSource.getPosition(level).get(); + destination = new BlockDestination(new Location(level.getWorld(), to.x(), to.y(), to.z())); + } else { + CommandAPI.getLogger().warning("Unknown or unsupported vibration destination " + options.getDestination()); + return new ParticleData(particle, null); + } + return new ParticleData(particle, new Vibration(from, destination, options.getArrivalInTicks())); + } + + @Override + public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) { + return new RegistryParser<>( + () -> CraftPotionEffectType.minecraftToBukkit(ResourceArgument.getMobEffect(cmdCtx, key).value()), + () -> fromResourceLocation(ResourceLocationArgument.getId(cmdCtx, key)) + ); + } + + @Override + public final Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException { + RecipeHolder recipe = ResourceKeyArgument.getRecipe(cmdCtx, key); + return new ComplexRecipeImpl(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); + } + + @Override + public final Rotation getRotation(CommandContext cmdCtx, String key) { + Vec2 rotation = RotationArgument.getRotation(cmdCtx, key).getRotation(cmdCtx.getSource()); + return new Rotation(rotation.y, rotation.x); + } + + @Override + public ScoreboardSlot getScoreboardSlot(CommandContext cmdCtx, String key) { + return ScoreboardSlot.ofMinecraft(ScoreboardSlotArgument.getDisplaySlot(cmdCtx, key).id()); + } + + @Override + public Collection getScoreHolderMultiple(CommandContext cmdCtx, String key) throws CommandSyntaxException { + final Collection scoreHolders = ScoreHolderArgument.getNames(cmdCtx, key); + Set scoreHolderNames = new HashSet<>(); + for (ScoreHolder scoreHolder : scoreHolders) { + scoreHolderNames.add(scoreHolder.getScoreboardName()); + } + return scoreHolderNames; + } + + @Override + public String getScoreHolderSingle(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ScoreHolderArgument.getName(cmdCtx, key).getScoreboardName(); + } + + @Override + public BukkitCommandSender getSenderForCommand(CommandContext cmdCtx, boolean isNative) { + CommandSourceStack css = cmdCtx.getSource(); + + CommandSender sender = css.getBukkitSender(); + if (sender == null) { + // Sender CANNOT be null. This can occur when using a remote console + // sender. You can access it directly using + // this.getMinecraftServer().remoteConsole + // however this may also be null, so delegate to the next most-meaningful + // sender. + sender = Bukkit.getConsoleSender(); + } + + Entity proxyEntity = css.getEntity(); + CommandSender proxy = proxyEntity == null ? null : proxyEntity.getBukkitEntity(); + if (isNative || (proxy != null && !sender.equals(proxy))) { + if (proxy == null) { + proxy = sender; + } + + return new BukkitNativeProxyCommandSender(new NativeProxyCommandSender_1_21_R6(css, sender, proxy)); + } else { + return CommandAPIBukkit.get().wrapCommandSender(sender); + } + } + + @Override + public NativeProxyCommandSender createNativeProxyCommandSender(CommandSender caller, CommandSender callee, Location location, World world) { + if (callee == null) callee = caller; + + // Most parameters default to what is defined by the caller + CommandSourceStack css = getBrigadierSourceFromCommandSender(CommandAPIBukkit.get().wrapCommandSender(caller)); + + // Position and rotation may be overridden by the Location + if (location != null) { + css = css + .withPosition(new Vec3(location.getX(), location.getY(), location.getZ())) + .withRotation(new Vec2(location.getPitch(), location.getYaw())); + } + + // ServerLevel may be overridden by the World + if (world == null && location != null) { + world = location.getWorld(); + } + if (world != null) { + css = css.withLevel(((CraftWorld) world).getHandle()); + } + + // The proxied sender can only be an Entity in the CommandSourceStack + if (callee instanceof org.bukkit.entity.Entity e) { + css = css.withEntity(((CraftEntity) e).getHandle()); + } + + return new NativeProxyCommandSender_1_21_R6(css, caller, callee); + } + + @Override + public final SimpleCommandMap getSimpleCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } + + @Override + public final RegistryParser getSound(CommandContext cmdCtx, String key) { + final ResourceLocation soundResource = ResourceLocationArgument.getId(cmdCtx, key); + return new RegistryParser<>( + () -> { + final Optional> soundEvent = BuiltInRegistries.SOUND_EVENT.get(soundResource); + if(soundEvent.isEmpty()) { + return null; + } else { + return CraftSound.minecraftToBukkit(soundEvent.get().value()); + } + }, + () -> NamespacedKey.fromString(soundResource.getNamespace() + ":" + soundResource.getPath()) + ); + } + + @Differs(from = "1.21.5", by = "Suggestion providers are per command context, not globally defined") + @Override + public SuggestionProvider getSuggestionProvider(SuggestionProviders provider) { + return switch (provider) { + case FUNCTION -> (context, builder) -> { + ServerFunctionManager functionData = this.getMinecraftServer().getFunctions(); + SharedSuggestionProvider.suggestResource(functionData.getTagNames(), builder, "#"); + return SharedSuggestionProvider.suggestResource(functionData.getFunctionNames(), builder); + }; + case RECIPES -> (cmdCtx, builder) -> SharedSuggestionProvider.suggestResource(this.getMinecraftServer().getRecipeManager() + .getRecipes().stream().map(holder -> holder.id().location()), builder); + case SOUNDS -> + (cmdCtx, builder) -> SharedSuggestionProvider.suggestResource(cmdCtx.getSource().getAvailableSounds(), builder); + case ADVANCEMENTS -> (cmdCtx, builder) -> SharedSuggestionProvider.suggestResource(this.getMinecraftServer().getAdvancements() + .getAllAdvancements().stream().map(AdvancementHolder::id), builder); + case LOOT_TABLES -> + (cmdCtx, builder) -> { + // TODO: Test this actually works + final List LootTableKeys = this.getMinecraftServer().reloadableRegistries().lookup().lookupOrThrow(Registries.LOOT_TABLE).listElementIds().map(ResourceKey::location).toList(); + return SharedSuggestionProvider.suggestResource(LootTableKeys, builder); + }; + case BIOMES -> _ArgumentSyntheticBiome()::listSuggestions; + case ENTITIES -> (cmdCtx, builder) -> SharedSuggestionProvider.suggestResource( + BuiltInRegistries.ENTITY_TYPE + .stream() + .filter(type -> type.isEnabled(cmdCtx.getSource().enabledFeatures()) && type.canSummon()), + builder, EntityType::getKey, EntityType::getDescription + ); + case POTION_EFFECTS -> + (context, builder) -> SharedSuggestionProvider.suggestResource(BuiltInRegistries.MOB_EFFECT.keySet(), builder); + }; + } + + @Override + public final SimpleFunctionWrapper[] getTag(NamespacedKey key) { + Collection> customFunctions = this.getMinecraftServer().getFunctions().getTag(ResourceLocation.fromNamespaceAndPath(key.getNamespace(), key.getKey())); + SimpleFunctionWrapper[] convertedCustomFunctions = new SimpleFunctionWrapper[customFunctions.size()]; + int index = 0; + for (CommandFunction customFunction : customFunctions) { + convertedCustomFunctions[index++] = convertFunction(customFunction); + } + return convertedCustomFunctions; + } + + @Override + public Set getTags() { + Set result = new HashSet<>(); + for (ResourceLocation resourceLocation : this.getMinecraftServer().getFunctions().getTagNames()) { + result.add(fromResourceLocation(resourceLocation)); + } + return result; + } + + @Override + public final Team getTeam(CommandContext cmdCtx, String key) throws CommandSyntaxException { + String teamName = TeamArgument.getTeam(cmdCtx, key).getName(); + return Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName); + } + + @Override + public World getWorldForCSS(CommandSourceStack css) { + return (css.getLevel() == null) ? null : css.getLevel().getWorld(); + } + + @Override + public final void reloadDataPacks() { + CommandAPI.logNormal("Reloading datapacks..."); + + // Get previously declared recipes to be re-registered later + Iterator recipes = Bukkit.recipeIterator(); + + // Update the commandDispatcher with the current server's commandDispatcher + ReloadableResources serverResources = this.getMinecraftServer().resources; + serverResources.managers().commands = this.getMinecraftServer().getCommands(); + + // Update the ServerFunctionLibrary's command dispatcher with the new one + try { + serverFunctionLibraryDispatcher.set(serverResources.managers().getFunctionLibrary(), + CommandAPIBukkit.get().getBrigadierDispatcher()); + } catch (IllegalAccessException ignored) { + // Shouldn't happen, CommandAPIHandler#getField makes it accessible + } + + // From this.getMinecraftServer().reloadResources // + // Discover new packs + Collection collection; + { + List packIDs = new ArrayList<>( + this.getMinecraftServer().getPackRepository().getSelectedIds()); + List disabledPacks = this.getMinecraftServer().getWorldData() + .getDataConfiguration().dataPacks().getDisabled(); + + for (String availablePack : this.getMinecraftServer().getPackRepository() + .getAvailableIds()) { + // Add every other available pack that is not disabled + // and is not already in the list of existing packs + if (!disabledPacks.contains(availablePack) && !packIDs.contains(availablePack)) { + packIDs.add(availablePack); + } + } + collection = packIDs; + } + + // Step 1: Construct an async supplier of a list of all resource packs to + // be loaded in the reload phase + CompletableFuture> first = CompletableFuture.supplyAsync(() -> { + PackRepository serverPackRepository = this.getMinecraftServer().getPackRepository(); + + List packResources = new ArrayList<>(); + for (String packID : collection) { + Pack pack = serverPackRepository.getPack(packID); + if (pack != null) { + packResources.add(pack.open()); + } + } + return packResources; + }).exceptionally(exception -> { + CommandAPI.logException("Something went wrong while trying to collect resource packs!", exception); + // Return all currently selected packs + return this.getMinecraftServer().getPackRepository().openAllSelected(); + }); + + // Step 2: Convert all of the resource packs into ReloadableResources which + // are replaced by our custom server resources with defined commands + CompletableFuture second = first.thenCompose(packResources -> { + MultiPackResourceManager resourceManager = new MultiPackResourceManager(PackType.SERVER_DATA, + packResources); + + // TODO: I'm not sure if this is sufficient anymore - Do we not want to load tags for existing + // registries here as well? + // List> TagList = TagLoader.loadTagsForExistingRegistries(resourceManager, this.getMinecraftServer().registries().compositeAccess()); + + // Not using packResources, because we really really want this to work + CompletableFuture simpleReloadInstance = SimpleReloadInstance.create(resourceManager, + serverResources.managers().listeners(), this.getMinecraftServer().executor, + this.getMinecraftServer(), CompletableFuture + .completedFuture(Unit.INSTANCE) /* ReloadableServerResources.DATA_RELOAD_INITIAL_TASK */, + LogUtils.getLogger().isDebugEnabled()).done(); + + return simpleReloadInstance.thenApply(x -> serverResources); + }).exceptionally(exception -> { + CommandAPI.logException("Something went wrong while trying to convert resource packs into ReloadableResources", exception); + // Return existing resources + return this.getMinecraftServer().resources; + }); + + // Step 3: Actually load all of the resources + CompletableFuture third = second.thenAcceptAsync(resources -> { + this.getMinecraftServer().resources.close(); + this.getMinecraftServer().resources = serverResources; + this.getMinecraftServer().server.syncCommands(); + if (minecraftServerSetSelected == null) { + this.getMinecraftServer().getPackRepository().setSelected(collection); + } else { + try { + minecraftServerSetSelected.invoke(this.getMinecraftServer().getPackRepository(), collection, true); + } catch (Throwable e) { + CommandAPI.logException("Something went wrong while trying to invoke PackRepository#setSelected(Collection, boolean)", e); + } + } + + final FeatureFlagSet enabledFeatures = this.getMinecraftServer().getWorldData().getDataConfiguration().enabledFeatures(); + + // this.getMinecraftServer().getSelectedPacks + Collection selectedIDs = this.getMinecraftServer().getPackRepository() + .getSelectedIds(); + List enabledIDs = ImmutableList.copyOf(selectedIDs); + List disabledIDs = new ArrayList<>( + this.getMinecraftServer().getPackRepository().getAvailableIds()); + + disabledIDs.removeIf(enabledIDs::contains); + + this.getMinecraftServer().getWorldData() + .setDataConfiguration(new WorldDataConfiguration(new DataPackConfig(enabledIDs, disabledIDs), enabledFeatures)); + // this.getMinecraftServer().resources.managers().updateRegistryTags(registryAccess); + this.getMinecraftServer().resources.managers().updateStaticRegistryTags(); // TODO: Review this + this.getMinecraftServer().resources.managers().getRecipeManager().finalizeRecipeLoading(enabledFeatures); + + // May need to be commented out, may not. Comment it out just in case. + // For some reason, calling getPlayerList().saveAll() may just hang + // the server indefinitely. Not sure why! + // this.getMinecraftServer().getPlayerList().saveAll(); + // this.getMinecraftServer().getPlayerList().reloadResources(); + // this.getMinecraftServer().getFunctions().replaceLibrary(this.getMinecraftServer().resources.managers().getFunctionLibrary()); + this.getMinecraftServer().getStructureManager() + .onResourceManagerReload(this.getMinecraftServer().resources.resourceManager()); + + // Set fuel values with the new loaded fuel values from the list of enabled features + minecraftServerFuelValues.set(this.getMinecraftServer(), + FuelValues.vanillaBurnTimes(this.getMinecraftServer().registries().compositeAccess(), + enabledFeatures + ) + ); + }).exceptionally(exception -> { + CommandAPI.logException("Something went wrong while trying to load resources.", exception); + return null; + }); + + // Step 4: Block the thread until everything's done + if (this.getMinecraftServer().isSameThread()) { + this.getMinecraftServer().managedBlock(third::isDone); + } + + // Run the completableFuture (and bind tags?) + try { + + // Register recipes again because reloading datapacks + // removes all non-vanilla recipes + CommandAPIBukkit.get().registerBukkitRecipesSafely(recipes); + + CommandAPI.logNormal("Finished reloading datapacks"); + } catch (Exception e) { + StringWriter stringWriter = new StringWriter(); + PrintWriter printWriter = new PrintWriter(stringWriter); + e.printStackTrace(printWriter); + + CommandAPI.logError( + "Failed to load datapacks, can't proceed with normal server load procedure. Try fixing your datapacks?\n" + + stringWriter.toString()); + } + } + + @Differs(from = "1.21.5", by = "#toJson is now implemented in this class") + @Override + public Message generateMessageFromJson(String json) { + return this.fromJson(json); + } + + @SuppressWarnings("unchecked") + @Override + public T getMinecraftServer() { + if (Bukkit.getServer() instanceof CraftServer server) { + return (T) server.getServer(); + } else { + return null; + } + } + + @Override + public ArgumentType _ArgumentMobEffect() { + return ResourceArgument.resource(commandBuildContext.get(), Registries.MOB_EFFECT); + } + + @Override + public ArgumentType _ArgumentEntitySummon() { + return ResourceArgument.resource(commandBuildContext.get(), Registries.ENTITY_TYPE); + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R6.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R6.java new file mode 100644 index 000000000..cc2185cba --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NativeProxyCommandSender_1_21_R6.java @@ -0,0 +1,35 @@ +package dev.jorel.commandapi.nms; + +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.wrappers.NativeProxyCommandSender; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.world.phys.Vec2; +import net.minecraft.world.phys.Vec3; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.v1_21_R6.command.ProxiedNativeCommandSender; + +public class NativeProxyCommandSender_1_21_R6 extends ProxiedNativeCommandSender implements NativeProxyCommandSender { + private final World world; + private final Location location; + + public NativeProxyCommandSender_1_21_R6(CommandSourceStack css, CommandSender caller, CommandSender callee) { + super(css, caller, callee); + + Vec3 pos = css.getPosition(); + Vec2 rot = css.getRotation(); + this.world = CommandAPIBukkit.get().getNMS().getWorldForCSS(css); + this.location = new Location(this.world, pos.x(), pos.y(), pos.z(), rot.y, rot.x); + } + + @Override + public Location getLocation() { + return location; + } + + @Override + public World getWorld() { + return world; + } +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/test/java/SafeReflect.java new file mode 100644 index 000000000..7cb9d1e00 --- /dev/null +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/test/java/SafeReflect.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright 2024 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +import java.util.Map; + +import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; +import net.minecraft.nbt.NBTTagCompound; +import org.bukkit.craftbukkit.v1_21_R5.help.SimpleHelpMap; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.datafixers.util.Either; + +import dev.jorel.commandapi.preprocessor.RequireField; +import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.server.CustomFunctionManager; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.level.block.entity.FuelValues; +import net.minecraft.world.level.gameevent.EntityPositionSource; + +// Spigot-Mapped reflection +@RequireField(in = CustomFunctionManager.class, name = "h", ofType = CommandDispatcher.class) +@RequireField(in = EntitySelector.class, name = "p", ofType = boolean.class) +@RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) +@RequireField(in = EntityPositionSource.class, name = "e", ofType = Either.class) +@RequireField(in = MinecraftServer.class, name = "aE", ofType = FuelValues.class) +@RequireField(in = ArgumentTileLocation.class, name = "d", ofType = NBTTagCompound.class) +public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml index e414d6f3e..e769c3e43 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml @@ -36,6 +36,11 @@ + + dev.jorel + commandapi-bukkit-1.21.9 + ${project.version} + dev.jorel commandapi-bukkit-1.21.6 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml index 36becebc6..793bf69fa 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml @@ -36,6 +36,7 @@ commandapi-bukkit-nms-common + commandapi-bukkit-1.21.9 commandapi-bukkit-1.21.6 commandapi-bukkit-1.21.5 commandapi-bukkit-1.21.4 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml index 75b948594..0c8a74e26 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml @@ -81,7 +81,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.7 + 1.4.10 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml index f053a81ef..43c5135da 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml @@ -76,7 +76,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.7 + 1.4.10 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml index 136ef0db7..1ab984d2a 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml @@ -76,7 +76,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.7 + 1.4.10 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml index d70fb1464..10ad872e8 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml @@ -76,7 +76,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.7 + 1.4.10 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml index beb37b1e1..277289bc2 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml @@ -77,7 +77,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.5-SNAPSHOT + 1.4.10 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml new file mode 100644 index 000000000..2bbc43127 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml @@ -0,0 +1,111 @@ + + + 4.0.0 + + dev.jorel + commandapi-paper-nms + 11.0.0-SNAPSHOT + + + commandapi-paper-1.21.9 + Paper support for 1.21.9 + + + 1.21.9-R0.1-SNAPSHOT + 1.21.9-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + bytecode.space + https://repo.bytecode.space/repository/maven-public/ + + + + + + + ca.bkaw + paper-nms + 1.21.9-SNAPSHOT + provided + + + io.papermc.paper + paper-api + ${paper.version} + provided + + + + + dev.jorel + commandapi-paper-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.9 + ${project.version} + mojang-mapped + provided + + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.10 + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R6.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R6.java new file mode 100644 index 000000000..66caf302e --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/src/main/java/dev/jorel/commandapi/nms/PaperNMS_1_21_R6.java @@ -0,0 +1,59 @@ +package dev.jorel.commandapi.nms; + +import com.mojang.brigadier.Command; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.PaperCommandRegistration; +import io.papermc.paper.command.brigadier.PaperCommands; +import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.help.SimpleHelpMap; + +public class PaperNMS_1_21_R6 implements PaperNMS { + + private CommandBuildContext commandBuildContext; + + private NMS_1_21_R6 bukkitNMS; + + private CommandBuildContext getCommandBuildContext() { + if (commandBuildContext != null) { + return commandBuildContext; + } + if (Bukkit.getServer() instanceof CraftServer server) { + commandBuildContext = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + return commandBuildContext; + } else { + return PaperCommands.INSTANCE.getBuildContext(); + } + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R6(this::getCommandBuildContext); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new PaperCommandRegistration<>( + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + () -> { + SimpleHelpMap helpMap = (SimpleHelpMap) Bukkit.getServer().getHelpMap(); + helpMap.clear(); + helpMap.initializeGeneralTopics(); + helpMap.initializeCommands(); + }, + node -> { + Command command = node.getCommand(); + return command instanceof BukkitCommandNode.BukkitBrigCommand; + } + ); + } + +} diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml index 80e636984..9b5bfb88f 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml @@ -89,7 +89,7 @@ ca.bkaw paper-nms-maven-plugin - 1.4.7 + 1.4.10 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml index 31467b79c..cff8ed886 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml @@ -30,6 +30,11 @@ + + dev.jorel + commandapi-paper-1.21.9 + ${project.version} + dev.jorel commandapi-paper-1.21.6 @@ -62,6 +67,12 @@ + + dev.jorel + commandapi-bukkit-1.21.9 + ${project.version} + mojang-mapped + dev.jorel commandapi-bukkit-1.21.6 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml index a28a1e074..36b432a60 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml @@ -14,6 +14,7 @@ pom + commandapi-paper-1.21.9 commandapi-paper-1.21.6 commandapi-paper-1.21.5 commandapi-paper-1.21.4 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml index 94163f142..0a077546c 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml @@ -93,6 +93,10 @@ org.bukkit.craftbukkit.v1_21_R5 org.bukkit.craftbukkit + + org.bukkit.craftbukkit.v1_21_R6 + org.bukkit.craftbukkit + diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index af8f7ef41..ac03e3fcf 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -9,6 +9,7 @@ import dev.jorel.commandapi.nms.PaperNMS_1_21_R3; import dev.jorel.commandapi.nms.PaperNMS_1_21_R4; import dev.jorel.commandapi.nms.PaperNMS_1_21_R5; +import dev.jorel.commandapi.nms.PaperNMS_1_21_R6; import io.papermc.paper.ServerBuildInfo; public abstract class CommandAPIVersionHandler { @@ -30,6 +31,7 @@ static LoadContext getPlatform(CommandAPIConfig config) { case "1.21.4" -> new PaperNMS_1_21_R3(); case "1.21.5" -> new PaperNMS_1_21_R4(); case "1.21.6", "1.21.7", "1.21.8" -> new PaperNMS_1_21_R5(); + case "1.21.9" -> new PaperNMS_1_21_R6(); default -> null; }; if (versionAdapter != null) { @@ -39,7 +41,7 @@ static LoadContext getPlatform(CommandAPIConfig config) { ); } if (CommandAPIPaper.getConfiguration().fallbackToLatestNMS()) { - PaperNMS paperNMS = new PaperNMS_1_21_R5(); + PaperNMS paperNMS = new PaperNMS_1_21_R6(); return new LoadContext( new CommandAPIPaper<>(internalPaperConfig, new APITypeProvider(paperNMS)), () -> { diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml new file mode 100644 index 000000000..77129814b --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml @@ -0,0 +1,150 @@ + + + 4.0.0 + + dev.jorel + commandapi-spigot-nms + 11.0.0-SNAPSHOT + + + commandapi-spigot-1.21.9 + Spigot support for 1.21.9 + + + 1.21.9-R0.1-SNAPSHOT + 1.21.9-R0.1-SNAPSHOT + + + + + minecraft-libraries + https://libraries.minecraft.net + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + + org.spigotmc + spigot + ${spigot.version} + test + + + + org.spigotmc + spigot + ${spigot.version} + remapped-mojang + provided + + + + + dev.jorel + commandapi-spigot-core + ${project.version} + compile + + + dev.jorel + commandapi-bukkit-1.21.9 + ${project.version} + mojang-mapped + provided + + + dev.jorel + commandapi-bukkit-nms-common + ${project.version} + mojang-mapped + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + Mojang-Mapped + + jar + + + mojang-mapped + + + + + + + net.md-5 + specialsource-maven-plugin + 2.0.2 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.mappings}:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.mappings}:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.mappings}:jar:remapped-obf + + + + + + + org.jacoco + jacoco-maven-plugin + + + default-prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + \ No newline at end of file diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R6.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R6.java new file mode 100644 index 000000000..0c11bf4c8 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/src/main/java/dev/jorel/commandapi/nms/SpigotNMS_1_21_R6.java @@ -0,0 +1,91 @@ +package dev.jorel.commandapi.nms; + +import com.google.common.collect.Collections2; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandRegistrationStrategy; +import dev.jorel.commandapi.InternalSpigotConfig; +import dev.jorel.commandapi.SpigotCommandRegistration; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.ColorArgument; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.commands.arguments.GameProfileArgument; +import net.minecraft.commands.arguments.MessageArgument; +import net.minecraft.server.MinecraftServer; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.SimpleCommandMap; +import org.bukkit.craftbukkit.v1_21_R6.CraftServer; +import org.bukkit.craftbukkit.v1_21_R6.command.BukkitCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R6.command.VanillaCommandWrapper; +import org.bukkit.craftbukkit.v1_21_R6.profile.CraftPlayerProfile; +import org.bukkit.profile.PlayerProfile; + +import java.util.ArrayList; +import java.util.List; + +public class SpigotNMS_1_21_R6 extends CommandAPISpigot { + + private static final CommandBuildContext COMMAND_BUILD_CONTEXT; + + private NMS_1_21_R6 bukkitNMS; + + static { + if (Bukkit.getServer() instanceof CraftServer server) { + COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(server.getServer().registryAccess(), + server.getServer().getWorldData().enabledFeatures()); + } else { + COMMAND_BUILD_CONTEXT = null; + } + } + + public SpigotNMS_1_21_R6(InternalSpigotConfig config) { + super(config); + } + + @Override + public BaseComponent[] getChat(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(bukkitNMS.toJson(MessageArgument.getMessage(cmdCtx, key))); + } + + @Override + public ChatColor getChatColor(CommandContext cmdCtx, String key) { + return ChatColor.getByChar(ColorArgument.getColor(cmdCtx, key).getChar()); + } + + @Override + public BaseComponent[] getChatComponent(CommandContext cmdCtx, String key) throws CommandSyntaxException { + return ComponentSerializer.parse(bukkitNMS.toJson(ComponentArgument.getResolvedComponent(cmdCtx, key))); + } + + @Override + public final List getProfile(CommandContext cmdCtx, String key) throws CommandSyntaxException { + GameProfileArgument.Result result = cmdCtx.getArgument(key, GameProfileArgument.Result.class); + return new ArrayList<>(Collections2.transform(result.getNames(cmdCtx.getSource()), CraftPlayerProfile::new)); + } + + @Override + public NMS bukkitNMS() { + if (bukkitNMS == null) { + this.bukkitNMS = new NMS_1_21_R6(() -> COMMAND_BUILD_CONTEXT); + } + return bukkitNMS; + } + + @Override + public CommandRegistrationStrategy createCommandRegistrationStrategy() { + return new SpigotCommandRegistration<>( + bukkitNMS.getMinecraftServer().vanillaCommandDispatcher.getDispatcher(), + (SimpleCommandMap) getCommandMap(), + () -> bukkitNMS.getMinecraftServer().getCommands().getDispatcher(), + command -> command instanceof VanillaCommandWrapper, + node -> new VanillaCommandWrapper(bukkitNMS.getMinecraftServer().vanillaCommandDispatcher, node), + node -> node.getCommand() instanceof BukkitCommandWrapper + ); + } + +} diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml index 10c3524d3..f1e03db45 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml @@ -21,6 +21,11 @@ + + dev.jorel + commandapi-spigot-1.21.9 + ${project.version} + dev.jorel commandapi-spigot-1.21.6 @@ -68,6 +73,11 @@ + + dev.jorel + commandapi-bukkit-1.21.9 + ${project.version} + dev.jorel commandapi-bukkit-1.21.6 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml index 17c22b641..7af183d86 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml @@ -14,6 +14,7 @@ pom + commandapi-spigot-1.21.9 commandapi-spigot-1.21.6 commandapi-spigot-1.21.5 commandapi-spigot-1.21.4 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index a4337958a..96ae60f35 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -10,6 +10,7 @@ import dev.jorel.commandapi.nms.SpigotNMS_1_21_R3; import dev.jorel.commandapi.nms.SpigotNMS_1_21_R4; import dev.jorel.commandapi.nms.SpigotNMS_1_21_R5; +import dev.jorel.commandapi.nms.SpigotNMS_1_21_R6; import org.bukkit.Bukkit; public abstract class CommandAPIVersionHandler { @@ -33,13 +34,14 @@ static LoadContext getPlatform(CommandAPIConfig config) { case "1.21.4" -> new SpigotNMS_1_21_R3(internalSpigotConfig); case "1.21.5" -> new SpigotNMS_1_21_R4(internalSpigotConfig); case "1.21.6", "1.21.7", "1.21.8" -> new SpigotNMS_1_21_R5(internalSpigotConfig); + case "1.21.9" -> new SpigotNMS_1_21_R6(internalSpigotConfig); default -> null; }; if (platform != null) { return new LoadContext(platform); } if (internalSpigotConfig.fallbackToLatestNMS()) { - return new LoadContext(new SpigotNMS_1_21_R5(internalSpigotConfig), () -> { + return new LoadContext(new SpigotNMS_1_21_R6(internalSpigotConfig), () -> { CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation."); CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using."); }); diff --git a/commandapi-platforms/pom.xml b/commandapi-platforms/pom.xml index 713a54798..f12d3a3dc 100644 --- a/commandapi-platforms/pom.xml +++ b/commandapi-platforms/pom.xml @@ -48,12 +48,12 @@ ../commandapi-kotlin/commandapi-kotlin-spigot - - Platform.Sponge - - commandapi-sponge - - + + + + + + Platform.Velocity diff --git a/setupPaperNMS.sh b/setupPaperNMS.sh index 2aef69a05..aaa933b2e 100755 --- a/setupPaperNMS.sh +++ b/setupPaperNMS.sh @@ -16,4 +16,7 @@ mvn --quiet paper-nms:init -pl :commandapi-paper-1.21.5 -P Platform.Paper echo "Setup Paper NMS for version 1.21.6..." mvn --quiet paper-nms:init -pl :commandapi-paper-1.21.6 -P Platform.Paper +echo "Setup Paper NMS for version 1.21.9..." +mvn --quiet paper-nms:init -pl :commandapi-paper-1.21.9 -P Platform.Paper + echo "Done!" \ No newline at end of file From 6607dbfdf6dd03411fcd66d0abaa2262fe5b39a9 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Wed, 1 Oct 2025 01:06:22 +0200 Subject: [PATCH 43/63] Fix compilation issues --- .../java/dev/jorel/commandapi/nms/NMS_1_21_R6.java | 2 +- .../src/test/java/SafeReflect.java | 4 ++-- .../commandapi-bukkit-nms-common/pom.xml | 11 +++++++++++ .../jorel/commandapi/PaperCommandRegistration.java | 2 ++ .../java/dev/jorel/commandapi/testing/TestPlugin.java | 1 + compileNMSCommon.sh | 3 ++- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java index 143f0855d..98ea45ea3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java @@ -252,7 +252,7 @@ public NMS_1_21_R6(Supplier commandBuildContext) { } minecraftServerSetSelected = setSelected; - minecraftServerFuelValues = SafeVarHandle.ofOrNull(MinecraftServer.class, "aE", "fuelValues", FuelValues.class); + minecraftServerFuelValues = SafeVarHandle.ofOrNull(MinecraftServer.class, "aG", "fuelValues", FuelValues.class); } // Implementation taken from io.papermc.paper.adventure.WrapperAwareSerializer#deserialize(Component) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/test/java/SafeReflect.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/test/java/SafeReflect.java index 7cb9d1e00..56fd7fdb9 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/test/java/SafeReflect.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/test/java/SafeReflect.java @@ -22,7 +22,7 @@ import net.minecraft.commands.arguments.blocks.ArgumentTileLocation; import net.minecraft.nbt.NBTTagCompound; -import org.bukkit.craftbukkit.v1_21_R5.help.SimpleHelpMap; +import org.bukkit.craftbukkit.v1_21_R6.help.SimpleHelpMap; import com.mojang.brigadier.CommandDispatcher; import com.mojang.datafixers.util.Either; @@ -39,6 +39,6 @@ @RequireField(in = EntitySelector.class, name = "p", ofType = boolean.class) @RequireField(in = SimpleHelpMap.class, name = "helpTopics", ofType = Map.class) @RequireField(in = EntityPositionSource.class, name = "e", ofType = Either.class) -@RequireField(in = MinecraftServer.class, name = "aE", ofType = FuelValues.class) +@RequireField(in = MinecraftServer.class, name = "aG", ofType = FuelValues.class) @RequireField(in = ArgumentTileLocation.class, name = "d", ofType = NBTTagCompound.class) public class SafeReflect {} \ No newline at end of file diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index f063c26df..13774ecf7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -134,6 +134,17 @@ + + Spigot_1_21_R6 + + 1.21.9-R0.1-SNAPSHOT + 1.21.9-R0.1-SNAPSHOT + 1.21.9-R0.1-SNAPSHOT + + + ${project.basedir}/target/1.21.9 + + Spigot_1_21_R5 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java index 3737a98f6..cb8328d5b 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/PaperCommandRegistration.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; +import com.mojang.brigadier.tree.RootCommandNode; import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.plugin.bootstrap.BootstrapContext; import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager; @@ -12,6 +13,7 @@ import org.bukkit.help.HelpTopic; import org.bukkit.plugin.java.JavaPlugin; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.function.Predicate; diff --git a/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java index c6bcc280f..d3e158463 100644 --- a/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java +++ b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java @@ -3,6 +3,7 @@ import com.mojang.brigadier.tree.CommandNode; import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPIPaper; import dev.jorel.commandapi.CommandAPIPaperConfig; import dev.jorel.commandapi.arguments.AdvancementArgument; import dev.jorel.commandapi.arguments.AngleArgument; diff --git a/compileNMSCommon.sh b/compileNMSCommon.sh index 7004ade27..bb7a3895a 100755 --- a/compileNMSCommon.sh +++ b/compileNMSCommon.sh @@ -11,4 +11,5 @@ compileVersion "1.21 and 1.21.1" "Spigot_1_21_R1" compileVersion "1.21.2 and 1.21.3" "Spigot_1_21_R2" compileVersion "1.21.4" "Spigot_1_21_R3" compileVersion "1.21.5" "Spigot_1_21_R4" -compileVersion "1.21.6 and 1.21.7 and 1.21.8" "Spigot_1_21_R5" \ No newline at end of file +compileVersion "1.21.6 and 1.21.7 and 1.21.8" "Spigot_1_21_R5" +compileVersion "1.21.9" "Spigot_1_21_R6" \ No newline at end of file From b996097d1524c0c01978d3333142afdebfe77cde Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Wed, 1 Oct 2025 01:09:52 +0200 Subject: [PATCH 44/63] Add GH step to compile 1.21.9 --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba86719c7..bdb36334a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -84,6 +84,9 @@ jobs: - name: Compile NMS_Common for 1.21.6 and 1.21.7 and 1.21.8 run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R5 + - name: Compile NMS_Common for 1.21.9 + run: mvn clean package -Dmaven.source.skip=true -Dmaven.javadoc.skip=true -pl :commandapi-bukkit-nms-common -am -P Platform.Bukkit,Spigot_1_21_R6 + - name: Copy BytecodeAnalyser to nms-common target folder run: mv BytecodeAnalyser/build/libs/BytecodeAnalyser*.jar commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/target From 51af54fcf397c1bcba3714455a77c096ed515d95 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Wed, 1 Oct 2025 01:38:21 +0200 Subject: [PATCH 45/63] Set API version to 1.21.9-R0.1-SNAPSHOT in the API module --- .../commandapi-paper-nms/commandapi-paper-api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml index 9ad75bbf2..9b39856cd 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml @@ -13,7 +13,7 @@ Paper API support - 1.21.8-R0.1-SNAPSHOT + 1.21.9-R0.1-SNAPSHOT From 4501286df43a4ab446980657ce2fc41a63d4c0d9 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 2 Oct 2025 01:15:42 +0200 Subject: [PATCH 46/63] Fix RecipeArgument throwing exceptions on Spigot Fixes #608 --- .../kotlindsl/CommandAPICommandDSL.kt | 1 - .../commandapi/kotlindsl/CommandTreeDSL.kt | 2 - .../kotlindsl/PaperCommandAPICommandDSL.kt | 2 + .../kotlindsl/PaperCommandTreeDSL.kt | 2 + .../kotlindsl/SpigotCommandAPICommandDSL.kt | 2 + .../kotlindsl/SpigotCommandTreeDSL.kt | 2 + .../java/dev/jorel/commandapi/nms/NMS.java | 3 +- .../dev/jorel/commandapi/nms/NMS_1_20_R2.java | 6 +- .../dev/jorel/commandapi/nms/NMS_1_20_R3.java | 6 +- .../dev/jorel/commandapi/nms/NMS_1_20_R4.java | 6 +- .../dev/jorel/commandapi/nms/NMS_1_20_R1.java | 6 +- .../dev/jorel/commandapi/nms/NMS_1_21_R2.java | 6 +- .../dev/jorel/commandapi/nms/NMS_1_21_R3.java | 6 +- .../dev/jorel/commandapi/nms/NMS_1_21_R4.java | 6 +- .../dev/jorel/commandapi/nms/NMS_1_21_R5.java | 6 +- .../dev/jorel/commandapi/nms/NMS_1_21_R6.java | 6 +- .../dev/jorel/commandapi/nms/NMS_1_21_R1.java | 6 +- .../dev/jorel/commandapi/nms/MockNMS.java | 3 +- .../arguments/ARecipeArgument.java | 4 +- .../commandapi/arguments/RecipeArgument.java | 67 ++++++ .../wrappers/ComplexRecipeImpl.java | 0 .../jorel/commandapi/nms/APITypeProvider.java | 4 +- .../arguments/ARecipeArgument.java | 35 +++ .../commandapi/arguments/RecipeArgument.java | 3 +- .../wrappers/ComplexRecipeImpl.java | 37 +++ .../commandapi-testing-spigot/pom.xml | 69 ++++++ .../jorel/commandapi/testing/TestPlugin.java | 218 ++++++++++++++++++ .../src/main/resources/plugin.yml | 6 + commandapi-testing/pom.xml | 1 + 29 files changed, 480 insertions(+), 41 deletions(-) rename {commandapi-annotations => commandapi-platforms/commandapi-paper/commandapi-paper-annotations}/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java (93%) create mode 100644 commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core => commandapi-paper/commandapi-paper-core}/src/main/java/dev/jorel/commandapi/wrappers/ComplexRecipeImpl.java (100%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java rename commandapi-platforms/{commandapi-bukkit/commandapi-bukkit-core => commandapi-spigot/commandapi-spigot-core}/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java (96%) create mode 100644 commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/wrappers/ComplexRecipeImpl.java create mode 100644 commandapi-testing/commandapi-testing-spigot/pom.xml create mode 100644 commandapi-testing/commandapi-testing-spigot/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java create mode 100644 commandapi-testing/commandapi-testing-spigot/src/main/resources/plugin.yml diff --git a/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt index 594a49620..0c1ef4e85 100644 --- a/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandAPICommandDSL.kt @@ -81,7 +81,6 @@ inline fun CommandAPICommand.namespacedKeyArgument(nodeName: String, optional: B inline fun CommandAPICommand.particleArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ParticleArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.potionEffectArgument(nodeName: String, useNamespacedKey: Boolean = false, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = if (useNamespacedKey) withArguments(PotionEffectArgument.NamespacedKey(nodeName).setOptional(optional).apply(block)) else withArguments(PotionEffectArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandAPICommand.recipeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(RecipeArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.soundArgument(nodeName: String, useNamespacedKey: Boolean = false, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = if (useNamespacedKey) withArguments(SoundArgument.NamespacedKey(nodeName).setOptional(optional).apply(block)) else withArguments(SoundArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt index 9ba00806c..23c71c06c 100644 --- a/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/src/main/kotlin/dev/jorel/commandapi/kotlindsl/CommandTreeDSL.kt @@ -89,7 +89,6 @@ inline fun CommandTree.namespacedKeyArgument(nodeName: String, optional: Boolean inline fun CommandTree.particleArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ParticleArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.potionEffectArgument(nodeName: String, useNamespacedKey: Boolean = false, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = if (useNamespacedKey) then(PotionEffectArgument.NamespacedKey(nodeName).setOptional(optional).apply(block)) else then(PotionEffectArgument(nodeName).setOptional(optional).apply(block)) -inline fun CommandTree.recipeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(RecipeArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.soundArgument(nodeName: String, useNamespacedKey: Boolean = false, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = if (useNamespacedKey) then(SoundArgument.NamespacedKey(nodeName).setOptional(optional).apply(block)) else then(SoundArgument(nodeName).setOptional(optional).apply(block)) @@ -192,7 +191,6 @@ inline fun Argument<*>.namespacedKeyArgument(nodeName: String, optional: Boolean inline fun Argument<*>.particleArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ParticleArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.potionEffectArgument(nodeName: String, useNamespacedKey: Boolean = false, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = if (useNamespacedKey) then(PotionEffectArgument.NamespacedKey(nodeName).setOptional(optional).apply(block)) else then(PotionEffectArgument(nodeName).setOptional(optional).apply(block)) -inline fun Argument<*>.recipeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(RecipeArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.soundArgument(nodeName: String, useNamespacedKey: Boolean = false, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = if (useNamespacedKey) then(SoundArgument.NamespacedKey(nodeName).setOptional(optional).apply(block)) else then(SoundArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt index fa0db51ca..b4e1d6576 100644 --- a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandAPICommandDSL.kt @@ -7,9 +7,11 @@ import dev.jorel.commandapi.arguments.ChatArgument import dev.jorel.commandapi.arguments.ChatColorArgument import dev.jorel.commandapi.arguments.ChatComponentArgument import dev.jorel.commandapi.arguments.PlayerProfileArgument +import dev.jorel.commandapi.arguments.RecipeArgument inline fun CommandAPICommand.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatColorArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.recipeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(RecipeArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt index 94d98e7dd..7e49666b2 100644 --- a/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-paper/src/main/kotlin/dev/jorel/commandapi/kotlindsl/PaperCommandTreeDSL.kt @@ -8,9 +8,11 @@ inline fun CommandTree.chatComponentArgument(nodeName: String, optional: Boolean inline fun CommandTree.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.recipeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(RecipeArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.recipeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(RecipeArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt index fa0db51ca..b4e1d6576 100644 --- a/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandAPICommandDSL.kt @@ -7,9 +7,11 @@ import dev.jorel.commandapi.arguments.ChatArgument import dev.jorel.commandapi.arguments.ChatColorArgument import dev.jorel.commandapi.arguments.ChatComponentArgument import dev.jorel.commandapi.arguments.PlayerProfileArgument +import dev.jorel.commandapi.arguments.RecipeArgument inline fun CommandAPICommand.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatColorArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(ChatArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandAPICommand.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandAPICommand.recipeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandAPICommand = withArguments(RecipeArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt index 94d98e7dd..7e49666b2 100644 --- a/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt +++ b/commandapi-kotlin/commandapi-kotlin-spigot/src/main/kotlin/dev/jorel/commandapi/kotlindsl/SpigotCommandTreeDSL.kt @@ -8,9 +8,11 @@ inline fun CommandTree.chatComponentArgument(nodeName: String, optional: Boolean inline fun CommandTree.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(ChatArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) inline fun CommandTree.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun CommandTree.recipeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): CommandTree = then(RecipeArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.chatColorArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatColorArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.chatComponentArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatComponentArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.chatArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(ChatArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.playerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(PlayerProfileArgument(nodeName).setOptional(optional).apply(block)) inline fun Argument<*>.asyncPlayerProfileArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(AsyncPlayerProfileArgument(nodeName).setOptional(optional).apply(block)) +inline fun Argument<*>.recipeArgument(nodeName: String, optional: Boolean = false, block: Argument<*>.() -> Unit = {}): Argument<*> = then(RecipeArgument(nodeName).setOptional(optional).apply(block)) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java index cc03dc2be..fb941c3a7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/nms/NMS.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; @@ -364,7 +365,7 @@ Objective getObjective(CommandContext cmdCtx, String key RegistryParser getPotionEffect(CommandContext cmdCtx, String key); - Recipe getRecipe(CommandContext cmdCtx, String key) throws CommandSyntaxException; + T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException; Rotation getRotation(CommandContext cmdCtx, String key) throws CommandSyntaxException; diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java index 87ca19069..80ff928ba 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R2.java @@ -42,7 +42,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -169,6 +168,7 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.ToIntFunction; @@ -566,9 +566,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { RecipeHolder recipe = ResourceLocationArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java index a32820a94..3255356d6 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R3.java @@ -42,7 +42,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -177,6 +176,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.ToIntFunction; @@ -623,9 +623,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { RecipeHolder recipe = ResourceLocationArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java index 2d274ad9b..f6b6c0bd5 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java @@ -44,7 +44,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -182,6 +181,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToIntFunction; @@ -660,9 +660,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { RecipeHolder recipe = ResourceLocationArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java index 0976cc5c3..4dd7f2eec 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R1.java @@ -42,7 +42,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -167,6 +166,7 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.ToIntFunction; @@ -563,9 +563,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { net.minecraft.world.item.crafting.Recipe recipe = ResourceLocationArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.getId()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.getId()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java index ba5d05144..d6d6733c1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R2.java @@ -44,7 +44,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -185,6 +184,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToIntFunction; @@ -679,9 +679,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { RecipeHolder recipe = ResourceKeyArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java index 317b4611f..c509741ee 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R3.java @@ -44,7 +44,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -190,6 +189,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToIntFunction; @@ -706,9 +706,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { RecipeHolder recipe = ResourceKeyArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java index 01fbbe61f..06c27bfd1 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R4.java @@ -44,7 +44,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -190,6 +189,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToIntFunction; @@ -700,9 +700,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { RecipeHolder recipe = ResourceKeyArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java index 151a8e30a..d3c0d9814 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R5.java @@ -48,7 +48,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -198,6 +197,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToIntFunction; @@ -725,9 +725,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { RecipeHolder recipe = ResourceKeyArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java index 98ea45ea3..28f4be29d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R6.java @@ -48,7 +48,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -198,6 +197,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToIntFunction; @@ -714,9 +714,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { RecipeHolder recipe = ResourceKeyArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.id().registry()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java index 3fa6e3cc8..45050b9cb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/src/main/java/dev/jorel/commandapi/nms/NMS_1_21_R1.java @@ -44,7 +44,6 @@ import dev.jorel.commandapi.preprocessor.Differs; import dev.jorel.commandapi.preprocessor.NMSMeta; import dev.jorel.commandapi.preprocessor.RequireField; -import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import dev.jorel.commandapi.wrappers.DoubleRange; import dev.jorel.commandapi.wrappers.FunctionWrapper; import dev.jorel.commandapi.wrappers.IntegerRange; @@ -180,6 +179,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BiFunction; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToIntFunction; @@ -665,9 +665,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public final T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { RecipeHolder recipe = ResourceLocationArgument.getRecipe(cmdCtx, key); - return new ComplexRecipeImpl(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); + return result.apply(fromResourceLocation(recipe.id()), recipe.toBukkitRecipe()); } @Override diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockNMS.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockNMS.java index 2b4f4968d..6faeb86a4 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockNMS.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/src/main/java/dev/jorel/commandapi/nms/MockNMS.java @@ -39,6 +39,7 @@ import java.io.File; import java.io.IOException; import java.util.*; +import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; @@ -446,7 +447,7 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { throw new UnimplementedMethodException(); } diff --git a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java similarity index 93% rename from commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java index 907bd362d..08991719f 100644 --- a/commandapi-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java @@ -25,10 +25,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import dev.jorel.commandapi.arguments.RecipeArgument; - /** - * Annotation equivalent of the {@link RecipeArgument} + * Annotation equivalent of the {@link dev.jorel.commandapi.arguments.RecipeArgument} */ @Primitive("org.bukkit.inventory.Recipe") @Retention(RetentionPolicy.SOURCE) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java new file mode 100644 index 000000000..8d1450e78 --- /dev/null +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi.arguments; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dev.jorel.commandapi.CommandAPIBukkit; +import dev.jorel.commandapi.CommandAPIPaper; +import dev.jorel.commandapi.executors.CommandArguments; +import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; +import org.bukkit.Keyed; +import org.bukkit.inventory.Recipe; + +/** + * An argument that represents the Bukkit Recipe object + * + * @since 2.1 + */ +public class RecipeArgument extends SafeOverrideableArgument implements CustomProvidedArgument { + + /** + * A Recipe argument. Represents a Bukkit Recipe or ComplexRecipe + * @param nodeName the name of the node for this argument + */ + public RecipeArgument(String nodeName) { + super(nodeName, CommandAPIBukkit.get().getNMS()._ArgumentRecipe(), fromKey((Recipe r) -> ((Keyed) r).getKey())); + } + + @Override + public Class getPrimitiveType() { + return Recipe.class; + } + + @Override + public SuggestionProviders getSuggestionProvider() { + return SuggestionProviders.RECIPES; + } + + @Override + public CommandAPIArgumentType getArgumentType() { + return CommandAPIArgumentType.RECIPE; + } + + @Override + public Recipe parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { + return CommandAPIBukkit.get().getNMS().getRecipe(cmdCtx, key, ComplexRecipeImpl::new); + } + +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/ComplexRecipeImpl.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/wrappers/ComplexRecipeImpl.java similarity index 100% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/wrappers/ComplexRecipeImpl.java rename to commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/wrappers/ComplexRecipeImpl.java diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java index 284345271..56ba921bb 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/src/main/java/dev/jorel/commandapi/nms/APITypeProvider.java @@ -643,9 +643,9 @@ public RegistryParser getPotionEffect(CommandContext cmdCtx, String key) throws CommandSyntaxException { + public T getRecipe(CommandContext cmdCtx, String key, BiFunction result) throws CommandSyntaxException { return parseT(cmdCtx, key, - (ctx, name) -> paperNMS.bukkitNMS().getRecipe(ctx, name) + (ctx, name) -> paperNMS.bukkitNMS().getRecipe(ctx, name, result) ); } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java new file mode 100644 index 000000000..08991719f --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/ARecipeArgument.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + *******************************************************************************/ +package dev.jorel.commandapi.annotations.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation equivalent of the {@link dev.jorel.commandapi.arguments.RecipeArgument} + */ +@Primitive("org.bukkit.inventory.Recipe") +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.PARAMETER) +public @interface ARecipeArgument { +} diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java similarity index 96% rename from commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java rename to commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java index c70669477..25da2e0aa 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/arguments/RecipeArgument.java @@ -24,6 +24,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.executors.CommandArguments; +import dev.jorel.commandapi.wrappers.ComplexRecipeImpl; import org.bukkit.Keyed; import org.bukkit.inventory.Recipe; @@ -59,7 +60,7 @@ public CommandAPIArgumentType getArgumentType() { @Override public Recipe parseArgument(CommandContext cmdCtx, String key, CommandArguments previousArgs) throws CommandSyntaxException { - return CommandAPIBukkit.get().getNMS().getRecipe(cmdCtx, key); + return CommandAPIBukkit.get().getNMS().getRecipe(cmdCtx, key, ComplexRecipeImpl::new); } } diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/wrappers/ComplexRecipeImpl.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/wrappers/ComplexRecipeImpl.java new file mode 100644 index 000000000..dc07c9d36 --- /dev/null +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/src/main/java/dev/jorel/commandapi/wrappers/ComplexRecipeImpl.java @@ -0,0 +1,37 @@ +package dev.jorel.commandapi.wrappers; + +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ComplexRecipe; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; + +import javax.annotation.Nonnull; + +/** + * Creates a ComplexRecipe based on a NamespacedKey and a Recipe object. + * @param key the namespaced key + * @param recipe the recipe + */ +public record ComplexRecipeImpl(NamespacedKey key, Recipe recipe) implements ComplexRecipe { + + /** + * Get the result of this recipe. + * + * @return The result stack + */ + @Override + public @Nonnull ItemStack getResult() { + return recipe.getResult(); + } + + /** + * Return the namespaced identifier for this object. + * + * @return this object's key + */ + @Override + public @Nonnull NamespacedKey getKey() { + return key; + } + +} diff --git a/commandapi-testing/commandapi-testing-spigot/pom.xml b/commandapi-testing/commandapi-testing-spigot/pom.xml new file mode 100644 index 000000000..a75967a5a --- /dev/null +++ b/commandapi-testing/commandapi-testing-spigot/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + dev.jorel + commandapi-testing + 11.0.0-SNAPSHOT + + + commandapi-testing-spigot + Testing plugin for Spigot + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + minecraft-libraries + https://libraries.minecraft.net + + + + + + org.spigotmc + spigot-api + 1.20.1-R0.1-SNAPSHOT + provided + + + dev.jorel + commandapi-spigot-shade + ${project.version} + + + com.mojang + brigadier + 1.3.10 + provided + + + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + + + + \ No newline at end of file diff --git a/commandapi-testing/commandapi-testing-spigot/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java b/commandapi-testing/commandapi-testing-spigot/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java new file mode 100644 index 000000000..0353c58a2 --- /dev/null +++ b/commandapi-testing/commandapi-testing-spigot/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java @@ -0,0 +1,218 @@ +package dev.jorel.commandapi.testing; + +import com.mojang.brigadier.tree.CommandNode; +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPISpigot; +import dev.jorel.commandapi.CommandAPISpigotConfig; +import dev.jorel.commandapi.arguments.AdvancementArgument; +import dev.jorel.commandapi.arguments.AngleArgument; +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.AxisArgument; +import dev.jorel.commandapi.arguments.BiomeArgument; +import dev.jorel.commandapi.arguments.BlockPredicateArgument; +import dev.jorel.commandapi.arguments.BlockStateArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.DoubleRangeArgument; +import dev.jorel.commandapi.arguments.EnchantmentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.FunctionArgument; +import dev.jorel.commandapi.arguments.IntegerRangeArgument; +import dev.jorel.commandapi.arguments.ItemStackArgument; +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; +import dev.jorel.commandapi.arguments.Location2DArgument; +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LocationType; +import dev.jorel.commandapi.arguments.LootTableArgument; +import dev.jorel.commandapi.arguments.MathOperationArgument; +import dev.jorel.commandapi.arguments.NamespacedKeyArgument; +import dev.jorel.commandapi.arguments.ObjectiveArgument; +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; +import dev.jorel.commandapi.arguments.ParticleArgument; +import dev.jorel.commandapi.arguments.PlayerProfileArgument; +import dev.jorel.commandapi.arguments.PotionEffectArgument; +import dev.jorel.commandapi.arguments.RecipeArgument; +import dev.jorel.commandapi.arguments.RotationArgument; +import dev.jorel.commandapi.arguments.ScoreHolderArgument; +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; +import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.TeamArgument; +import dev.jorel.commandapi.arguments.TimeArgument; +import dev.jorel.commandapi.arguments.UUIDArgument; +import dev.jorel.commandapi.arguments.WorldArgument; +import dev.jorel.commandapi.wrappers.DoubleRange; +import dev.jorel.commandapi.wrappers.FunctionWrapper; +import dev.jorel.commandapi.wrappers.IntegerRange; +import dev.jorel.commandapi.wrappers.Location2D; +import dev.jorel.commandapi.wrappers.MathOperation; +import dev.jorel.commandapi.wrappers.ParticleData; +import dev.jorel.commandapi.wrappers.Rotation; +import dev.jorel.commandapi.wrappers.ScoreboardSlot; +import net.md_5.bungee.api.chat.BaseComponent; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.Biome; +import org.bukkit.block.BlockState; +import org.bukkit.command.CommandSender; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; +import org.bukkit.loot.LootTable; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Team; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.EnumSet; +import java.util.List; +import java.util.UUID; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.function.Predicate; + +public class TestPlugin extends JavaPlugin { + + @Override + public void onLoad() { + CommandAPI.onLoad(new CommandAPISpigotConfig(this)); + + register(new AdvancementArgument("advancementtype"), Advancement.class, advancement -> advancement.getKey().toString()); + register(new AngleArgument("angletype"), float.class, Object::toString); + register(new AxisArgument("axistype"), EnumSet.class, Object::toString); + register(new BiomeArgument("biome_biometype"), Biome.class, biome -> biome.getKey().toString()); + register(new BiomeArgument.NamespacedKey("biome_keytype"), NamespacedKey.class, Object::toString); + register(new BlockPredicateArgument("blockpredicatetype"), Predicate.class, Object::toString); + register(new BlockStateArgument("blockstatetype"), BlockState.class, Object::toString); + register(new ChatArgument("chattype"), BaseComponent[].class, (message, sender) -> sender.spigot().sendMessage(message)); + register(new ChatColorArgument("chatcolortype"), ChatColor.class, color -> color + "Test"); + register(new ChatComponentArgument("chatcomponenttype"), Function.identity(), BaseComponent[].class); + register(new EnchantmentArgument("enchantmenttype"), Enchantment.class, enchantment -> enchantment.getKey().toString()); + register(new EntitySelectorArgument.OnePlayer("oneplayertype"), Player.class, Player::getName); + register(new EntitySelectorArgument.OneEntity("onenentitytype"), Entity.class, Entity::getName); + register(new EntitySelectorArgument.ManyPlayers("manyplayerstype"), Collection.class, Object::toString); + register(new EntitySelectorArgument.ManyEntities("manyentitiestype"), Collection.class, Object::toString); + register(new EntityTypeArgument("entitytype"), EntityType.class, Object::toString); + register(new DoubleRangeArgument("floatrangetype"), DoubleRange.class, range -> range.getLowerBound() + ".." + range.getUpperBound()); + register(new FunctionArgument("functionstype"), FunctionWrapper[].class, Arrays::toString); + register(new IntegerRangeArgument("integerrangetype"), IntegerRange.class, range -> range.getLowerBound() + ".." + range.getUpperBound()); + register(new ItemStackArgument("itemstacktype"), ItemStack.class, stack -> stack.getType().getItemTranslationKey()); + register(new ItemStackPredicateArgument("itemstackpredicatetype"), Predicate.class, Object::toString); + register(new Location2DArgument("location2dblocktype", LocationType.BLOCK_POSITION), Location2D.class, loc -> loc.getX() + ", " + loc.getZ()); + register(new Location2DArgument("location2dprecisetype", LocationType.PRECISE_POSITION, true), Location2D.class, loc -> loc.getX() + ", " + loc.getZ()); + register(new LocationArgument("locationblocktype", LocationType.BLOCK_POSITION), Location.class, loc -> loc.getX() + ", " + loc.getY() + ", " + loc.getZ()); + register(new LocationArgument("locationprecisetype", LocationType.PRECISE_POSITION, true), Location.class, loc -> loc.getX() + ", " + loc.getY() + ", " + loc.getZ()); + register(new LootTableArgument("loottabletype"), LootTable.class, loot -> loot.getKey().toString()); + register(new MathOperationArgument("mathoperationtype"), MathOperation.class, MathOperation::toString); + register(new NamespacedKeyArgument("namespacedkeytype"), NamespacedKey.class, NamespacedKey::toString); + register(new ObjectiveArgument("objectivetype"), Objective.class, Objective::getName); + register(new ObjectiveCriteriaArgument("objectivecriteriatype"), String.class, Function.identity()); + register(new ParticleArgument("particletype"), ParticleData.class, data -> data.particle().toString()); + register(new PlayerProfileArgument("playertype"), List.class, Object::toString); + register(new PotionEffectArgument("potioneffect_potioneffecttype"), PotionEffectType.class, PotionEffectType::toString); + register(new PotionEffectArgument.NamespacedKey("potioneffect_keytype"), NamespacedKey.class, NamespacedKey::toString); + register(new RecipeArgument("recipetype"), Recipe.class, recipe -> recipe.getResult().getType().getKey().toString()); + register(new RotationArgument("rotationtype"), Rotation.class, rotation -> rotation.getYaw() + ", " + rotation.getPitch()); + register(new ScoreboardSlotArgument("scoreboardslottype"), ScoreboardSlot.class, ScoreboardSlot::toString); + register(new ScoreHolderArgument.Single("scoreholder_singletype"), String.class, Function.identity()); + register(new ScoreHolderArgument.Multiple("scoreholder_multipletype"), Collection.class, coll -> String.join(", ", coll)); + register(new SoundArgument("sound_soundtype"), Sound.class, s -> s.getKey().toString()); + register(new SoundArgument.NamespacedKey("sound_keytype"), NamespacedKey.class, NamespacedKey::toString); + register(new TeamArgument("teamtype"), Team.class, Team::getName); + register(new TimeArgument("timetype"), int.class, Object::toString); + register(new UUIDArgument("uuidtype"), UUID.class, UUID::toString); + register(new WorldArgument("worldtype"), World.class, World::getName); + + // Unregistration/Registration test commands + registerExecutor(new StringArgument("register"), String.class, (name, sender) -> { + new CommandAPICommand(name) + .executes(info -> { + info.sender().sendMessage("Command /" + name + " was registered and executed successfully!"); + }) + .register(); + }); + registerExecutor(new StringArgument("unregister") + .replaceSuggestions(ArgumentSuggestions.strings(info -> CommandAPISpigot.getSpigot() + .getBrigadierDispatcher() + .getRoot() + .getChildren() + .stream() + .map(CommandNode::getName) + .filter(name -> !fixedCommandNames.contains(name)) + .toArray(String[]::new) + )), + String.class, + (name, sender) -> { + if (fixedCommandNames.contains(name)) { + sender.sendMessage("§cSorry, the command /" + name + " cannot be unregistered!"); + return; + } + CommandAPI.unregister(name, true); + sender.sendMessage("§aCommand " + name + " was unregistered successfully!"); + } + ); + } + + @Override + public void onEnable() { + CommandAPI.onEnable(); + } + + private final List fixedCommandNames = new ArrayList<>(); + + private void register(Argument argument, Class castType, Function toString) { + fixedCommandNames.add(argument.getNodeName()); + new CommandAPICommand(argument.getNodeName()) + .withArguments(argument) + .executes(info -> { + info.sender().sendMessage(toString.apply(info.args().getByClass(argument.getNodeName(), castType))); + }) + .register(); + } + + private void register(Argument argument, Function toString, Class castType) { + fixedCommandNames.add(argument.getNodeName()); + new CommandAPICommand(argument.getNodeName()) + .withArguments(argument) + .executes(info -> { + info.sender().spigot().sendMessage(toString.apply(info.args().getByClass(argument.getNodeName(), castType))); + }) + .register(); + } + + private void register(Argument argument, Class castType, BiConsumer action) { + fixedCommandNames.add(argument.getNodeName()); + new CommandAPICommand(argument.getNodeName()) + .withArguments(argument) + .executes(info -> { + T argumentType = info.args().getByClass(argument.getNodeName(), castType); + action.accept(argumentType, info.sender()); + }) + .register(); + } + + private void registerExecutor(Argument argument, Class castType, BiConsumer executor) { + fixedCommandNames.add(argument.getNodeName()); + new CommandAPICommand(argument.getNodeName()) + .withArguments(argument) + .executes(info -> { + executor.accept(info.args().getByClass(argument.getNodeName(), castType), info.sender()); + }) + .register(); + } + +} diff --git a/commandapi-testing/commandapi-testing-spigot/src/main/resources/plugin.yml b/commandapi-testing/commandapi-testing-spigot/src/main/resources/plugin.yml new file mode 100644 index 000000000..3a7cddd91 --- /dev/null +++ b/commandapi-testing/commandapi-testing-spigot/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: SpigotTestPlugin +main: dev.jorel.commandapi.testing.TestPlugin +version: ${project.version} +description: A plugin to test all arguments the CommandAPI offers. +author: DerEchtePilz +api-version: '1.20' \ No newline at end of file diff --git a/commandapi-testing/pom.xml b/commandapi-testing/pom.xml index 1ef2a8e96..debacfcd5 100644 --- a/commandapi-testing/pom.xml +++ b/commandapi-testing/pom.xml @@ -15,6 +15,7 @@ commandapi-testing-paper + commandapi-testing-spigot \ No newline at end of file From 8d3ebf26504625decf481eb297256458fba8ed59 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 2 Oct 2025 13:01:24 +0200 Subject: [PATCH 47/63] Add bootstrap registration to the testing plugin --- .../commandapi/testing/TestBootstrap.java | 24 +++++++++++++++++++ .../jorel/commandapi/testing/TestPlugin.java | 2 -- .../src/main/resources/paper-plugin.yml | 3 ++- .../jorel/commandapi/testing/TestPlugin.java | 2 +- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestBootstrap.java diff --git a/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestBootstrap.java b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestBootstrap.java new file mode 100644 index 000000000..5dc048859 --- /dev/null +++ b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestBootstrap.java @@ -0,0 +1,24 @@ +package dev.jorel.commandapi.testing; + +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.CommandAPIPaperConfig; +import io.papermc.paper.plugin.bootstrap.BootstrapContext; +import io.papermc.paper.plugin.bootstrap.PluginBootstrap; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.jetbrains.annotations.NotNull; + +public class TestBootstrap implements PluginBootstrap { + + @Override + public void bootstrap(@NotNull BootstrapContext bootstrapContext) { + CommandAPI.onLoad(new CommandAPIPaperConfig(bootstrapContext).verboseOutput(true)); + + new CommandAPICommand("bootstrap") + .executes(info -> { + info.sender().sendMessage(Component.text("Registration from bootstrap works!")); + }) + .register(); + } +} diff --git a/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java index d3e158463..37f49e3be 100644 --- a/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java +++ b/commandapi-testing/commandapi-testing-paper/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java @@ -91,8 +91,6 @@ public class TestPlugin extends JavaPlugin { @Override public void onLoad() { - CommandAPI.onLoad(new CommandAPIPaperConfig(this)); - register(new AdvancementArgument("advancementtype"), Advancement.class, advancement -> advancement.key().asString()); register(new AngleArgument("angletype"), float.class, Object::toString); register(new AxisArgument("axistype"), EnumSet.class, Object::toString); diff --git a/commandapi-testing/commandapi-testing-paper/src/main/resources/paper-plugin.yml b/commandapi-testing/commandapi-testing-paper/src/main/resources/paper-plugin.yml index d871db218..d15f289eb 100644 --- a/commandapi-testing/commandapi-testing-paper/src/main/resources/paper-plugin.yml +++ b/commandapi-testing/commandapi-testing-paper/src/main/resources/paper-plugin.yml @@ -1,6 +1,7 @@ name: PaperTestPlugin main: dev.jorel.commandapi.testing.TestPlugin +bootstrapper: dev.jorel.commandapi.testing.TestBootstrap version: ${project.version} description: A plugin to test all arguments the CommandAPI offers. author: DerEchtePilz -api-version: '1.20' \ No newline at end of file +api-version: '1.20.6' \ No newline at end of file diff --git a/commandapi-testing/commandapi-testing-spigot/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java b/commandapi-testing/commandapi-testing-spigot/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java index 0353c58a2..7ed097a03 100644 --- a/commandapi-testing/commandapi-testing-spigot/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java +++ b/commandapi-testing/commandapi-testing-spigot/src/main/java/dev/jorel/commandapi/testing/TestPlugin.java @@ -89,7 +89,7 @@ public class TestPlugin extends JavaPlugin { @Override public void onLoad() { - CommandAPI.onLoad(new CommandAPISpigotConfig(this)); + CommandAPI.onLoad(new CommandAPISpigotConfig(this).verboseOutput(true)); register(new AdvancementArgument("advancementtype"), Advancement.class, advancement -> advancement.getKey().toString()); register(new AngleArgument("angletype"), float.class, Object::toString); From 274203de4a3f5a4b46b789a0a48c65737277505b Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Thu, 2 Oct 2025 23:15:23 +0200 Subject: [PATCH 48/63] Add 1.21.10 to the version handler --- .../java/dev/jorel/commandapi/CommandAPIVersionHandler.java | 2 +- .../java/dev/jorel/commandapi/CommandAPIVersionHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index ac03e3fcf..ebc4e05ed 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -31,7 +31,7 @@ static LoadContext getPlatform(CommandAPIConfig config) { case "1.21.4" -> new PaperNMS_1_21_R3(); case "1.21.5" -> new PaperNMS_1_21_R4(); case "1.21.6", "1.21.7", "1.21.8" -> new PaperNMS_1_21_R5(); - case "1.21.9" -> new PaperNMS_1_21_R6(); + case "1.21.9", "1.21.10" -> new PaperNMS_1_21_R6(); default -> null; }; if (versionAdapter != null) { diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java index 96ae60f35..89273105c 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java @@ -34,7 +34,7 @@ static LoadContext getPlatform(CommandAPIConfig config) { case "1.21.4" -> new SpigotNMS_1_21_R3(internalSpigotConfig); case "1.21.5" -> new SpigotNMS_1_21_R4(internalSpigotConfig); case "1.21.6", "1.21.7", "1.21.8" -> new SpigotNMS_1_21_R5(internalSpigotConfig); - case "1.21.9" -> new SpigotNMS_1_21_R6(internalSpigotConfig); + case "1.21.9", "1.21.10" -> new SpigotNMS_1_21_R6(internalSpigotConfig); default -> null; }; if (platform != null) { From a9bc226807fb7510f6381546619e92c37ecd57d3 Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Fri, 3 Oct 2025 23:46:26 +0100 Subject: [PATCH 49/63] Change version from 11.0.0-SNAPSHOT -> 11.0.0 --- commandapi-annotations/pom.xml | 2 +- commandapi-codecov/pom.xml | 2 +- commandapi-core/pom.xml | 2 +- commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml | 2 +- commandapi-kotlin/commandapi-kotlin-core/pom.xml | 2 +- commandapi-kotlin/commandapi-kotlin-paper/pom.xml | 2 +- commandapi-kotlin/commandapi-kotlin-spigot/pom.xml | 2 +- commandapi-kotlin/commandapi-kotlin-velocity/pom.xml | 2 +- commandapi-kotlin/pom.xml | 2 +- .../commandapi-bukkit/commandapi-bukkit-core/pom.xml | 2 +- .../commandapi-bukkit-networking-plugin/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml | 2 +- .../commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml | 2 +- .../commandapi-bukkit-nms-common/pom.xml | 2 +- .../commandapi-bukkit-nms-dependency/pom.xml | 2 +- .../commandapi-bukkit/commandapi-bukkit-nms/pom.xml | 2 +- .../commandapi-bukkit-plugin-common/pom.xml | 2 +- .../commandapi-bukkit-test-toolkit/pom.xml | 2 +- commandapi-platforms/commandapi-bukkit/pom.xml | 2 +- .../commandapi-paper/commandapi-paper-annotations/pom.xml | 2 +- .../commandapi-paper/commandapi-paper-core/pom.xml | 2 +- .../commandapi-paper/commandapi-paper-mojang-mapped/pom.xml | 2 +- .../commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml | 2 +- .../commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml | 2 +- .../commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml | 2 +- .../commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml | 2 +- .../commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml | 2 +- .../commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml | 2 +- .../commandapi-paper-nms/commandapi-paper-1.21/pom.xml | 2 +- .../commandapi-paper-nms/commandapi-paper-api/pom.xml | 2 +- .../commandapi-paper-nms-dependency/pom.xml | 2 +- .../commandapi-paper/commandapi-paper-nms/pom.xml | 2 +- .../commandapi-paper/commandapi-paper-plugin/pom.xml | 2 +- .../commandapi-paper/commandapi-paper-shade/pom.xml | 2 +- .../commandapi-paper/commandapi-paper-test-toolkit/pom.xml | 2 +- .../commandapi-paper/commandapi-paper-vh/pom.xml | 2 +- commandapi-platforms/commandapi-paper/pom.xml | 2 +- .../commandapi-spigot/commandapi-spigot-annotations/pom.xml | 2 +- .../commandapi-spigot/commandapi-spigot-core/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml | 2 +- .../commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml | 2 +- .../commandapi-spigot-nms-dependency/pom.xml | 2 +- .../commandapi-spigot/commandapi-spigot-nms/pom.xml | 2 +- .../commandapi-spigot/commandapi-spigot-plugin/pom.xml | 2 +- .../commandapi-spigot/commandapi-spigot-shade/pom.xml | 2 +- .../commandapi-spigot-test-toolkit/pom.xml | 2 +- .../commandapi-spigot/commandapi-spigot-vh/pom.xml | 2 +- commandapi-platforms/commandapi-spigot/pom.xml | 2 +- .../commandapi-sponge/commandapi-sponge-core/pom.xml | 2 +- .../commandapi-sponge/commandapi-sponge-plugin-test/pom.xml | 2 +- .../commandapi-sponge/commandapi-sponge-plugin/pom.xml | 2 +- .../commandapi-sponge/commandapi-sponge-shade/pom.xml | 2 +- commandapi-platforms/commandapi-sponge/pom.xml | 2 +- .../commandapi-velocity/commandapi-velocity-core/pom.xml | 2 +- .../commandapi-velocity-plugin-test/pom.xml | 2 +- .../commandapi-velocity/commandapi-velocity-plugin/pom.xml | 2 +- .../commandapi-velocity/commandapi-velocity-shade/pom.xml | 2 +- commandapi-platforms/commandapi-velocity/pom.xml | 2 +- commandapi-platforms/pom.xml | 2 +- commandapi-plugin/pom.xml | 2 +- commandapi-preprocessor/pom.xml | 2 +- commandapi-testing/commandapi-testing-paper/pom.xml | 2 +- commandapi-testing/commandapi-testing-spigot/pom.xml | 2 +- commandapi-testing/pom.xml | 2 +- examples/bukkit/automated-tests-shaded/README.md | 4 ++-- examples/bukkit/automated-tests-shaded/pom.xml | 4 ++-- examples/bukkit/automated-tests/README.md | 4 ++-- examples/bukkit/automated-tests/pom.xml | 4 ++-- examples/bukkit/commandtrees/pom.xml | 2 +- examples/bukkit/gradle-groovy/README.md | 2 +- examples/bukkit/gradle-groovy/build.gradle | 2 +- examples/bukkit/gradle-kotlin/README.md | 2 +- examples/bukkit/gradle-kotlin/build.gradle.kts | 2 +- examples/bukkit/kotlindsl-gradle/README.md | 2 +- examples/bukkit/kotlindsl-gradle/build.gradle.kts | 4 ++-- examples/bukkit/kotlindsl/README.md | 2 +- examples/bukkit/kotlindsl/pom.xml | 4 ++-- examples/bukkit/maven-annotations/README.md | 6 +++--- examples/bukkit/maven-annotations/pom.xml | 6 +++--- examples/bukkit/maven-shaded-annotations/README.md | 6 +++--- examples/bukkit/maven-shaded-annotations/pom.xml | 6 +++--- examples/bukkit/maven-shaded/README.md | 2 +- examples/bukkit/maven-shaded/pom.xml | 2 +- examples/bukkit/maven/README.md | 2 +- examples/bukkit/maven/pom.xml | 2 +- examples/velocity/gradle-groovy/README.md | 2 +- examples/velocity/gradle-groovy/build.gradle | 2 +- examples/velocity/gradle-kotlin/README.md | 2 +- examples/velocity/gradle-kotlin/build.gradle.kts | 2 +- examples/velocity/maven-shaded/README.md | 2 +- examples/velocity/maven-shaded/pom.xml | 2 +- examples/velocity/maven/README.md | 2 +- examples/velocity/maven/pom.xml | 2 +- pom.xml | 2 +- 110 files changed, 124 insertions(+), 124 deletions(-) diff --git a/commandapi-annotations/pom.xml b/commandapi-annotations/pom.xml index 6f8548bdc..a7ad4f841 100644 --- a/commandapi-annotations/pom.xml +++ b/commandapi-annotations/pom.xml @@ -18,7 +18,7 @@ dev.jorel commandapi - 11.0.0-SNAPSHOT + 11.0.0 commandapi-annotations diff --git a/commandapi-codecov/pom.xml b/commandapi-codecov/pom.xml index 221f0833e..f51be2e64 100644 --- a/commandapi-codecov/pom.xml +++ b/commandapi-codecov/pom.xml @@ -20,7 +20,7 @@ dev.jorel commandapi - 11.0.0-SNAPSHOT + 11.0.0 commandapi-codecov diff --git a/commandapi-core/pom.xml b/commandapi-core/pom.xml index 0aae7c12f..3df3c7c7b 100644 --- a/commandapi-core/pom.xml +++ b/commandapi-core/pom.xml @@ -19,7 +19,7 @@ commandapi dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml b/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml index 735ce90eb..7db52c9ad 100644 --- a/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi-kotlin - 11.0.0-SNAPSHOT + 11.0.0 commandapi-kotlin-bukkit diff --git a/commandapi-kotlin/commandapi-kotlin-core/pom.xml b/commandapi-kotlin/commandapi-kotlin-core/pom.xml index 4dd5c3567..5dc31d0bd 100644 --- a/commandapi-kotlin/commandapi-kotlin-core/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-core/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi-kotlin - 11.0.0-SNAPSHOT + 11.0.0 commandapi-kotlin-core diff --git a/commandapi-kotlin/commandapi-kotlin-paper/pom.xml b/commandapi-kotlin/commandapi-kotlin-paper/pom.xml index bf54ccf37..f8f8d3951 100644 --- a/commandapi-kotlin/commandapi-kotlin-paper/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-paper/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-kotlin - 11.0.0-SNAPSHOT + 11.0.0 commandapi-kotlin-paper diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml index 8ac862ba1..11abb051a 100644 --- a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-kotlin - 11.0.0-SNAPSHOT + 11.0.0 commandapi-kotlin-spigot diff --git a/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml b/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml index 3c835bc18..1c4a345eb 100644 --- a/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi-kotlin - 11.0.0-SNAPSHOT + 11.0.0 commandapi-kotlin-velocity diff --git a/commandapi-kotlin/pom.xml b/commandapi-kotlin/pom.xml index b5ed72db8..34c8f0c0b 100644 --- a/commandapi-kotlin/pom.xml +++ b/commandapi-kotlin/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi - 11.0.0-SNAPSHOT + 11.0.0 commandapi-kotlin diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml index 571c74820..81692d692 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml @@ -6,7 +6,7 @@ commandapi-bukkit dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-bukkit-core diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml index 96ccf3528..db7a07d3e 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml @@ -6,7 +6,7 @@ commandapi-bukkit dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-bukkit-networking-plugin diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml index 8c08bf773..cbef35ccd 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml index b4e5e77cf..5580c02a9 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml index 66f9978ba..33993956a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml index 5320f1fb5..c9d1d6317 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml index d182b8d9b..2d1f56d77 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml index a3be63527..9347d1681 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml index 52199c8f1..f1b4c3261 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml index 65710ab07..9b1a742bb 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml index 647d0f20d..122ee261c 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml index e1d1a69cf..4c7fe3f6b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml @@ -21,7 +21,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index 13774ecf7..4fc42304b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -19,7 +19,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml index e769c3e43..fd2c1d6ae 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-dependency/pom.xml @@ -19,7 +19,7 @@ commandapi-bukkit-nms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml index 793bf69fa..a8b6e8a00 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/pom.xml @@ -26,7 +26,7 @@ commandapi-bukkit dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-bukkit-nms diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml index de0e5a027..1e2cb9bdf 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi-bukkit - 11.0.0-SNAPSHOT + 11.0.0 commandapi-bukkit-plugin-common diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml index d2f2e35eb..d7ac0b4bc 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test-toolkit/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-bukkit - 11.0.0-SNAPSHOT + 11.0.0 commandapi-bukkit-test-toolkit diff --git a/commandapi-platforms/commandapi-bukkit/pom.xml b/commandapi-platforms/commandapi-bukkit/pom.xml index 45c182237..28498a597 100644 --- a/commandapi-platforms/commandapi-bukkit/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/pom.xml @@ -7,7 +7,7 @@ commandapi-platforms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-bukkit diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml index 19e329d0b..f35533f53 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-annotations diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml index 40777943f..574e03ac0 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-core diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml index c073780cc..850c6c0f0 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-mojang-mapped/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-mojang-mapped diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml index 0c8a74e26..992eaf48f 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-1.20.5 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml index 43c5135da..3184cdef8 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.2/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-1.21.2 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml index 1ab984d2a..89fc4be2b 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.4/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-1.21.4 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml index 10ad872e8..0a8f058d4 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.5/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-1.21.5 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml index 277289bc2..0d6b999d2 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.6/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-1.21.6 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml index 2bbc43127..e0c364a6d 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-1.21.9 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml index 9b5bfb88f..827796818 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-1.21 diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml index 9b39856cd..1f06ab239 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-api diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml index cff8ed886..bcb594498 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-nms-dependency/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-nms-dependency diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml index 36b432a60..b1a24bed7 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-nms diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml index 7c630b37a..8b6bbbf8c 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-plugin diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml index 0a077546c..8f4211217 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-shade/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-shade diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml index 4f5214607..302615f36 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-test-toolkit/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-test-toolkit diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml index 32e867d77..53ff8a1f7 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-paper - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper-vh diff --git a/commandapi-platforms/commandapi-paper/pom.xml b/commandapi-platforms/commandapi-paper/pom.xml index 105a14776..056e8af35 100644 --- a/commandapi-platforms/commandapi-paper/pom.xml +++ b/commandapi-platforms/commandapi-paper/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-platforms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-paper diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml index 9b5b9ace0..6834915ed 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-annotations diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml index 474a392f9..37ee2cb5e 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-core diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml index c3817e289..84db40495 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.20.2 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml index a1c20be76..979735105 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.20.3 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml index 95d1b98df..3afd0ad17 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.20.5 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml index 26da61d4f..75434cf83 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.20 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml index 5a3482d84..e54db8a96 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.21.2 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml index a9fde11f1..3fa40972e 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.21.4 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml index 99bfb5616..f6191874b 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.21.5 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml index 2c94f6573..7ce0d3a11 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.21.6 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml index 77129814b..7372f7cf2 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.21.9 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml index 92c0d8805..8de1a5a92 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-1.21 diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml index f1e03db45..c93e8977b 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-nms-dependency/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot-nms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-nms-dependency diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml index 7af183d86..b1f6705d8 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-nms diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml index 9eac05ad4..d51a95904 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-plugin diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml index 43e235222..b7aad8c76 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-shade/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-shade diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml index 91ab8cb74..798bfaa2b 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-test-toolkit/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-test-toolkit diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml index b2998ac63..cc513cea7 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-spigot - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot-vh diff --git a/commandapi-platforms/commandapi-spigot/pom.xml b/commandapi-platforms/commandapi-spigot/pom.xml index cc919858d..8e9e9f5ba 100644 --- a/commandapi-platforms/commandapi-spigot/pom.xml +++ b/commandapi-platforms/commandapi-spigot/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-platforms - 11.0.0-SNAPSHOT + 11.0.0 commandapi-spigot diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml index 074359e1c..a32681d57 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-core/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-sponge-core diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml index 5506074e0..b0c4f553c 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin-test/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-sponge-plugin-test diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml index 414239d6f..8490902a9 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-plugin/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-sponge-plugin diff --git a/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml b/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml index 09e673a5d..93a27c781 100644 --- a/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml +++ b/commandapi-platforms/commandapi-sponge/commandapi-sponge-shade/pom.xml @@ -7,7 +7,7 @@ commandapi-sponge dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-sponge-shade diff --git a/commandapi-platforms/commandapi-sponge/pom.xml b/commandapi-platforms/commandapi-sponge/pom.xml index 0bc2d6682..02239828b 100644 --- a/commandapi-platforms/commandapi-sponge/pom.xml +++ b/commandapi-platforms/commandapi-sponge/pom.xml @@ -7,7 +7,7 @@ commandapi-platforms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-sponge diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml index 518e9dee1..e6e9bc9f5 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-velocity-core diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml index 4c1a67692..9643bfe84 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin-test/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-velocity-plugin-test diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml index 4a1b2928e..7701a6c2e 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-velocity-plugin diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml index 81cb278d6..eaeef4a72 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-shade/pom.xml @@ -7,7 +7,7 @@ commandapi-velocity dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-velocity-shade diff --git a/commandapi-platforms/commandapi-velocity/pom.xml b/commandapi-platforms/commandapi-velocity/pom.xml index a0218cf05..4403beb3d 100644 --- a/commandapi-platforms/commandapi-velocity/pom.xml +++ b/commandapi-platforms/commandapi-velocity/pom.xml @@ -7,7 +7,7 @@ commandapi-platforms dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-velocity diff --git a/commandapi-platforms/pom.xml b/commandapi-platforms/pom.xml index f12d3a3dc..76498e477 100644 --- a/commandapi-platforms/pom.xml +++ b/commandapi-platforms/pom.xml @@ -7,7 +7,7 @@ commandapi dev.jorel - 11.0.0-SNAPSHOT + 11.0.0 commandapi-platforms diff --git a/commandapi-plugin/pom.xml b/commandapi-plugin/pom.xml index 19bb57ed1..86c0e99eb 100644 --- a/commandapi-plugin/pom.xml +++ b/commandapi-plugin/pom.xml @@ -7,7 +7,7 @@ dev.jorel commandapi - 11.0.0-SNAPSHOT + 11.0.0 commandapi-plugin diff --git a/commandapi-preprocessor/pom.xml b/commandapi-preprocessor/pom.xml index 952a2185d..7e9f2d1e1 100644 --- a/commandapi-preprocessor/pom.xml +++ b/commandapi-preprocessor/pom.xml @@ -25,7 +25,7 @@ dev.jorel commandapi - 11.0.0-SNAPSHOT + 11.0.0 4.0.0 diff --git a/commandapi-testing/commandapi-testing-paper/pom.xml b/commandapi-testing/commandapi-testing-paper/pom.xml index 1e5e32a3c..01f565aff 100644 --- a/commandapi-testing/commandapi-testing-paper/pom.xml +++ b/commandapi-testing/commandapi-testing-paper/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-testing - 11.0.0-SNAPSHOT + 11.0.0 commandapi-testing-paper diff --git a/commandapi-testing/commandapi-testing-spigot/pom.xml b/commandapi-testing/commandapi-testing-spigot/pom.xml index a75967a5a..092deb13a 100644 --- a/commandapi-testing/commandapi-testing-spigot/pom.xml +++ b/commandapi-testing/commandapi-testing-spigot/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi-testing - 11.0.0-SNAPSHOT + 11.0.0 commandapi-testing-spigot diff --git a/commandapi-testing/pom.xml b/commandapi-testing/pom.xml index debacfcd5..3366f73eb 100644 --- a/commandapi-testing/pom.xml +++ b/commandapi-testing/pom.xml @@ -6,7 +6,7 @@ dev.jorel commandapi - 11.0.0-SNAPSHOT + 11.0.0 commandapi-testing diff --git a/examples/bukkit/automated-tests-shaded/README.md b/examples/bukkit/automated-tests-shaded/README.md index d30aff246..34efacd8c 100644 --- a/examples/bukkit/automated-tests-shaded/README.md +++ b/examples/bukkit/automated-tests-shaded/README.md @@ -18,14 +18,14 @@ Key points: dev.jorel commandapi-paper-test-toolkit - 11.0.0-SNAPSHOT + 11.0.0 test dev.jorel commandapi-paper-shade - 11.0.0-SNAPSHOT + 11.0.0 compile diff --git a/examples/bukkit/automated-tests-shaded/pom.xml b/examples/bukkit/automated-tests-shaded/pom.xml index 0ac41c201..1faefac02 100644 --- a/examples/bukkit/automated-tests-shaded/pom.xml +++ b/examples/bukkit/automated-tests-shaded/pom.xml @@ -32,7 +32,7 @@ dev.jorel commandapi-paper-test-toolkit - 11.0.0-SNAPSHOT + 11.0.0 test @@ -40,7 +40,7 @@ dev.jorel commandapi-paper-shade - 11.0.0-SNAPSHOT + 11.0.0 compile diff --git a/examples/bukkit/automated-tests/README.md b/examples/bukkit/automated-tests/README.md index 4ede288d8..a2ca1445c 100644 --- a/examples/bukkit/automated-tests/README.md +++ b/examples/bukkit/automated-tests/README.md @@ -18,14 +18,14 @@ Key points: dev.jorel commandapi-paper-test-toolkit - 11.0.0-SNAPSHOT + 11.0.0 test dev.jorel commandapi-paper-core - 11.0.0-SNAPSHOT + 11.0.0 provided diff --git a/examples/bukkit/automated-tests/pom.xml b/examples/bukkit/automated-tests/pom.xml index 5c02c2c6a..957a17b08 100644 --- a/examples/bukkit/automated-tests/pom.xml +++ b/examples/bukkit/automated-tests/pom.xml @@ -32,7 +32,7 @@ dev.jorel commandapi-paper-test-toolkit - 11.0.0-SNAPSHOT + 11.0.0 test @@ -40,7 +40,7 @@ dev.jorel commandapi-paper-core - 11.0.0-SNAPSHOT + 11.0.0 provided diff --git a/examples/bukkit/commandtrees/pom.xml b/examples/bukkit/commandtrees/pom.xml index a148d9392..d658ccc0d 100644 --- a/examples/bukkit/commandtrees/pom.xml +++ b/examples/bukkit/commandtrees/pom.xml @@ -20,7 +20,7 @@ dev.jorel commandapi-paper-core - 11.0.0-SNAPSHOT + 11.0.0 diff --git a/examples/bukkit/gradle-groovy/README.md b/examples/bukkit/gradle-groovy/README.md index 677730dff..a029b409d 100644 --- a/examples/bukkit/gradle-groovy/README.md +++ b/examples/bukkit/gradle-groovy/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-paper-plugin` dependency is used: ```groovy - implementation 'dev.jorel:commandapi-paper-plugin:11.0.0-SNAPSHOT' + implementation 'dev.jorel:commandapi-paper-plugin:11.0.0' ``` - In the plugin.yml, CommandAPI is listed as a depend: diff --git a/examples/bukkit/gradle-groovy/build.gradle b/examples/bukkit/gradle-groovy/build.gradle index 32fe872c3..c860e4a29 100644 --- a/examples/bukkit/gradle-groovy/build.gradle +++ b/examples/bukkit/gradle-groovy/build.gradle @@ -29,7 +29,7 @@ dependencies { implementation 'io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT' // The CommandAPI dependency used for Bukkit and it's forks - implementation 'dev.jorel:commandapi-paper-plugin:11.0.0-SNAPSHOT' + implementation 'dev.jorel:commandapi-paper-plugin:11.0.0' // NBT API to use NBT-based arguments implementation 'de.tr7zw:item-nbt-api-plugin:2.12.2' diff --git a/examples/bukkit/gradle-kotlin/README.md b/examples/bukkit/gradle-kotlin/README.md index ca670bef8..0bfcadace 100644 --- a/examples/bukkit/gradle-kotlin/README.md +++ b/examples/bukkit/gradle-kotlin/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-paper-plugin` dependency is used: ```kotlin - implementation("dev.jorel:commandapi-paper-plugin:11.0.0-SNAPSHOT") + implementation("dev.jorel:commandapi-paper-plugin:11.0.0") ``` - In the plugin.yml, CommandAPI is listed as a depend: diff --git a/examples/bukkit/gradle-kotlin/build.gradle.kts b/examples/bukkit/gradle-kotlin/build.gradle.kts index de61544e6..dd8da2e1c 100644 --- a/examples/bukkit/gradle-kotlin/build.gradle.kts +++ b/examples/bukkit/gradle-kotlin/build.gradle.kts @@ -25,7 +25,7 @@ dependencies { implementation("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") // The CommandAPI dependency used for Bukkit and it's forks - implementation("dev.jorel:commandapi-paper-plugin:11.0.0-SNAPSHOT") + implementation("dev.jorel:commandapi-paper-plugin:11.0.0") // NBT API to use NBT-based arguments implementation("de.tr7zw:item-nbt-api-plugin:2.12.2") diff --git a/examples/bukkit/kotlindsl-gradle/README.md b/examples/bukkit/kotlindsl-gradle/README.md index a7159747e..d6c1f1258 100644 --- a/examples/bukkit/kotlindsl-gradle/README.md +++ b/examples/bukkit/kotlindsl-gradle/README.md @@ -9,7 +9,7 @@ Key points: - Add the `commandapi-kotlin-paper` dependency to your project: ```kotlin - compileOnly("dev.jorel:commandapi-kotlin-paper:11.0.0-SNAPSHOT") + compileOnly("dev.jorel:commandapi-kotlin-paper:11.0.0") ``` - The Kotlin DSL must not be shaded into your plugin diff --git a/examples/bukkit/kotlindsl-gradle/build.gradle.kts b/examples/bukkit/kotlindsl-gradle/build.gradle.kts index bf70e2504..587a5710c 100644 --- a/examples/bukkit/kotlindsl-gradle/build.gradle.kts +++ b/examples/bukkit/kotlindsl-gradle/build.gradle.kts @@ -22,8 +22,8 @@ dependencies { implementation("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") // The CommandAPI dependency used for Bukkit and it's forks - implementation("dev.jorel:commandapi-paper-core:11.0.0-SNAPSHOT") + implementation("dev.jorel:commandapi-paper-core:11.0.0") // Due to all functions available in the kotlindsl being inlined, we only need this dependency at compile-time - compileOnly("dev.jorel:commandapi-kotlin-paper:11.0.0-SNAPSHOT") + compileOnly("dev.jorel:commandapi-kotlin-paper:11.0.0") } \ No newline at end of file diff --git a/examples/bukkit/kotlindsl/README.md b/examples/bukkit/kotlindsl/README.md index 78a602999..b6d874cd2 100644 --- a/examples/bukkit/kotlindsl/README.md +++ b/examples/bukkit/kotlindsl/README.md @@ -12,7 +12,7 @@ Key points: dev.jorel commandapi-kotlin-paper - 11.0.0-SNAPSHOT + 11.0.0 ``` diff --git a/examples/bukkit/kotlindsl/pom.xml b/examples/bukkit/kotlindsl/pom.xml index d51b475d9..135f41ddd 100644 --- a/examples/bukkit/kotlindsl/pom.xml +++ b/examples/bukkit/kotlindsl/pom.xml @@ -21,13 +21,13 @@ dev.jorel commandapi-paper-core - 11.0.0-SNAPSHOT + 11.0.0 provided dev.jorel commandapi-kotlin-paper - 11.0.0-SNAPSHOT + 11.0.0 diff --git a/examples/bukkit/maven-annotations/README.md b/examples/bukkit/maven-annotations/README.md index 0dedfab69..81c4ca256 100644 --- a/examples/bukkit/maven-annotations/README.md +++ b/examples/bukkit/maven-annotations/README.md @@ -11,13 +11,13 @@ Key points: dev.jorel commandapi-paper-plugin - 11.0.0-SNAPSHOT + 11.0.0 provided dev.jorel commandapi-paper-annotations - 11.0.0-SNAPSHOT + 11.0.0 provided @@ -37,7 +37,7 @@ Key points: dev.jorel commandapi-annotations - 11.0.0-SNAPSHOT + 11.0.0 diff --git a/examples/bukkit/maven-annotations/pom.xml b/examples/bukkit/maven-annotations/pom.xml index 3d21c9989..18fe34c37 100644 --- a/examples/bukkit/maven-annotations/pom.xml +++ b/examples/bukkit/maven-annotations/pom.xml @@ -28,7 +28,7 @@ dev.jorel commandapi-paper-plugin - 11.0.0-SNAPSHOT + 11.0.0 provided @@ -36,7 +36,7 @@ dev.jorel commandapi-paper-annotations - 11.0.0-SNAPSHOT + 11.0.0 provided @@ -69,7 +69,7 @@ dev.jorel commandapi-annotations - 11.0.0-SNAPSHOT + 11.0.0 17 diff --git a/examples/bukkit/maven-shaded-annotations/README.md b/examples/bukkit/maven-shaded-annotations/README.md index c53013e48..8aa552eb3 100644 --- a/examples/bukkit/maven-shaded-annotations/README.md +++ b/examples/bukkit/maven-shaded-annotations/README.md @@ -11,12 +11,12 @@ Key points: dev.jorel commandapi-paper-shade - 11.0.0-SNAPSHOT + 11.0.0 dev.jorel commandapi-paper-annotations - 11.0.0-SNAPSHOT + 11.0.0 provided @@ -36,7 +36,7 @@ Key points: dev.jorel commandapi-annotations - 11.0.0-SNAPSHOT + 11.0.0 diff --git a/examples/bukkit/maven-shaded-annotations/pom.xml b/examples/bukkit/maven-shaded-annotations/pom.xml index 30d018e66..dd71aebf0 100644 --- a/examples/bukkit/maven-shaded-annotations/pom.xml +++ b/examples/bukkit/maven-shaded-annotations/pom.xml @@ -28,14 +28,14 @@ dev.jorel commandapi-paper-shade - 11.0.0-SNAPSHOT + 11.0.0 dev.jorel commandapi-paper-annotations - 11.0.0-SNAPSHOT + 11.0.0 provided @@ -62,7 +62,7 @@ dev.jorel commandapi-annotations - 11.0.0-SNAPSHOT + 11.0.0 17 diff --git a/examples/bukkit/maven-shaded/README.md b/examples/bukkit/maven-shaded/README.md index 1d5b1daea..7290e69a1 100644 --- a/examples/bukkit/maven-shaded/README.md +++ b/examples/bukkit/maven-shaded/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-paper-shade - 11.0.0-SNAPSHOT + 11.0.0 ``` diff --git a/examples/bukkit/maven-shaded/pom.xml b/examples/bukkit/maven-shaded/pom.xml index 509f0326e..f072bc49c 100644 --- a/examples/bukkit/maven-shaded/pom.xml +++ b/examples/bukkit/maven-shaded/pom.xml @@ -28,7 +28,7 @@ dev.jorel commandapi-paper-shade - 11.0.0-SNAPSHOT + 11.0.0 diff --git a/examples/bukkit/maven/README.md b/examples/bukkit/maven/README.md index e44956f58..04b105d8b 100644 --- a/examples/bukkit/maven/README.md +++ b/examples/bukkit/maven/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-paper-plugin - 11.0.0-SNAPSHOT + 11.0.0 provided ``` diff --git a/examples/bukkit/maven/pom.xml b/examples/bukkit/maven/pom.xml index 69598c23f..730a5fdef 100644 --- a/examples/bukkit/maven/pom.xml +++ b/examples/bukkit/maven/pom.xml @@ -28,7 +28,7 @@ dev.jorel commandapi-paper-plugin - 11.0.0-SNAPSHOT + 11.0.0 provided diff --git a/examples/velocity/gradle-groovy/README.md b/examples/velocity/gradle-groovy/README.md index fc8b546be..fe33e8102 100644 --- a/examples/velocity/gradle-groovy/README.md +++ b/examples/velocity/gradle-groovy/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-velocity-core` dependency is used ```groovy - implementation 'dev.jorel:commandapi-velocity-core:11.0.0-SNAPSHOT' + implementation 'dev.jorel:commandapi-velocity-core:11.0.0' ``` - In the `@Plugin` annotation, `commandapi` is listed as a dependency: diff --git a/examples/velocity/gradle-groovy/build.gradle b/examples/velocity/gradle-groovy/build.gradle index 64d4d79d8..33f01fefe 100644 --- a/examples/velocity/gradle-groovy/build.gradle +++ b/examples/velocity/gradle-groovy/build.gradle @@ -25,5 +25,5 @@ dependencies { implementation 'com.velocitypowered:velocity-api:3.1.1' // The CommandAPI dependency used for Velocity - implementation 'dev.jorel:commandapi-velocity-core:11.0.0-SNAPSHOT' + implementation 'dev.jorel:commandapi-velocity-core:11.0.0' } \ No newline at end of file diff --git a/examples/velocity/gradle-kotlin/README.md b/examples/velocity/gradle-kotlin/README.md index e48f6790c..c99612a85 100644 --- a/examples/velocity/gradle-kotlin/README.md +++ b/examples/velocity/gradle-kotlin/README.md @@ -7,7 +7,7 @@ Key points: - The `commandapi-velocity-core` dependency is used: ```kotlin - implementation("dev.jorel:commandapi-velocity-core:11.0.0-SNAPSHOT") + implementation("dev.jorel:commandapi-velocity-core:11.0.0") ``` - In the `@Plugin` annotation, `commandapi` is listed as a dependency: diff --git a/examples/velocity/gradle-kotlin/build.gradle.kts b/examples/velocity/gradle-kotlin/build.gradle.kts index 8179049de..562a6cfbe 100644 --- a/examples/velocity/gradle-kotlin/build.gradle.kts +++ b/examples/velocity/gradle-kotlin/build.gradle.kts @@ -23,5 +23,5 @@ dependencies { implementation("com.velocitypowered:velocity-api:3.1.1") // The CommandAPI dependency used for Velocity - implementation("dev.jorel:commandapi-velocity-core:11.0.0-SNAPSHOT") + implementation("dev.jorel:commandapi-velocity-core:11.0.0") } \ No newline at end of file diff --git a/examples/velocity/maven-shaded/README.md b/examples/velocity/maven-shaded/README.md index dbcdfc82f..869506f5f 100644 --- a/examples/velocity/maven-shaded/README.md +++ b/examples/velocity/maven-shaded/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-velocity-shade - 11.0.0-SNAPSHOT + 11.0.0 ``` diff --git a/examples/velocity/maven-shaded/pom.xml b/examples/velocity/maven-shaded/pom.xml index dabfea1f1..e8a6210e8 100644 --- a/examples/velocity/maven-shaded/pom.xml +++ b/examples/velocity/maven-shaded/pom.xml @@ -21,7 +21,7 @@ dev.jorel commandapi-velocity-shade - 11.0.0-SNAPSHOT + 11.0.0 diff --git a/examples/velocity/maven/README.md b/examples/velocity/maven/README.md index 3070ffb35..1973d2610 100644 --- a/examples/velocity/maven/README.md +++ b/examples/velocity/maven/README.md @@ -10,7 +10,7 @@ Key points: dev.jorel commandapi-velocity-core - 11.0.0-SNAPSHOT + 11.0.0 provided ``` diff --git a/examples/velocity/maven/pom.xml b/examples/velocity/maven/pom.xml index b8a41c550..3b383daea 100644 --- a/examples/velocity/maven/pom.xml +++ b/examples/velocity/maven/pom.xml @@ -21,7 +21,7 @@ dev.jorel commandapi-velocity-core - 11.0.0-SNAPSHOT + 11.0.0 provided diff --git a/pom.xml b/pom.xml index 79968b198..fbba9f94b 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ dev.jorel commandapi - 11.0.0-SNAPSHOT + 11.0.0 pom commandapi From 6b1210a145147e422c67b852a11f58080a93d7ab Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Fri, 3 Oct 2025 23:48:20 +0100 Subject: [PATCH 50/63] Remove maven-shaded-tests from update script --- update.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/update.sh b/update.sh index 50d56195a..5a045ed14 100755 --- a/update.sh +++ b/update.sh @@ -36,9 +36,6 @@ sed -i "s/$oldVer<\/version>/$newVer<\/version>/" examples/buk sed -i "s/$oldVer<\/version>/$newVer<\/version>/" examples/bukkit/maven-shaded-annotations/README.md sed -i "s/$oldVer<\/version>/$newVer<\/version>/" examples/bukkit/maven-shaded-annotations/pom.xml -# maven-shaded-tests README dose not reference a dependency version -sed -i "s/$oldVer<\/version>/$newVer<\/version>/" examples/bukkit/maven-shaded-tests/pom.xml - ############ # Velocity # ############ From 63d259791b4d9a048fcff822daad475da1167247 Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sat, 4 Oct 2025 00:48:27 +0200 Subject: [PATCH 51/63] Update version supported table, roadmap and changelog --- README.md | 109 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index a7f9806cd..b06f58f75 100644 --- a/README.md +++ b/README.md @@ -43,39 +43,40 @@ The list of what version of the CommandAPI you'll need to run on a specific version of Minecraft is as follows: -| Minecraft version | Compatible versions | Latest compatible
    version | Minimum Java
    version required
    to run latest version | -|--------------------|------------------------------|------------------------------|-----------------------------------------------------------| -| **1.13.x** | v1.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | -| **1.14.1, 1.14.2** | v2.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | -| **1.14.3, 1.14.4** | v2.1 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | -| **1.15.x** | v2.3a - 5.12, 8.3.0 - 9.3.0 | 9.3.0 | 16 | -| **1.16.1** | v3.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.2** | v4.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.3** | v4.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.4** | v5.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | -| **1.16.5** | v5.7 - 7.0.0, 8.3.0 - 9.7.0 | 9.7.0 | 16 | -| **1.17** | 6.0.x - 9.7.0 | 9.7.0 | 16 | -| **1.17.1** | 6.1.x - 9.7.0 | 9.7.0 | 16 | -| **1.18, 1.18.1** | 6.5.2 - 9.7.0 | 9.7.0 | 16 | -| **1.18.2** | 6.5.4 - 9.7.0 | 9.7.0 | 16 | -| **1.19** | 8.3.0 - 9.7.0 | 9.7.0 | 16 | -| **1.19.1** | 8.5.0 - 9.7.0 | 9.7.0 | 16 | -| **1.19.2** | 8.5.1 - 9.7.0 | 9.7.0 | 16 | -| **1.19.3** | 8.7.0 - 9.7.0 | 9.7.0 | 16 | -| **1.19.4** | 8.8.0 - 9.7.0 | 9.7.0 | 16 | -| **1.20** | 9.0.2 - 10.1.2 | 10.1.2 | 17 | -| **1.20.1** | 9.0.3 - 10.1.2 | 10.1.2 | 17 | -| **1.20.2** | 9.2.0 - 10.1.2 | 10.1.2 | 17 | -| **1.20.3, 1.20.4** | 9.3.0 - 10.1.2 | 10.1.2 | 17 | -| **1.20.5, 1.20.6** | 9.4.0 - 10.1.2 | 10.1.2 | 17 | -| **1.21** | 9.5.0 - 10.1.2 | 10.1.2 | 17 | -| **1.21.1** | 9.5.2 - 10.1.2 | 10.1.2 | 17 | -| **1.21.2, 1.21.3** | 9.6.0 - 10.1.2 | 10.1.2 | 17 | -| **1.21.4** | 9.7.0 - 10.1.2 | 10.1.2 | 17 | -| **1.21.5** | 10.0.0 - 10.1.2 | 10.1.2 | 17 | -| **1.21.6** | 10.1.0 - 10.1.2 | 10.1.2 | 17 | -| **1.21.7** | 10.1.1 - 10.1.2 | 10.1.2 | 17 | -| **1.21.8** | 10.1.2 | 10.1.2 | 17 | +| Minecraft version | Compatible versions | Latest compatible
    version | Minimum Java
    version required
    to run latest version | +|---------------------|-----------------------------|------------------------------|-----------------------------------------------------------| +| **1.13.x** | v1.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | +| **1.14.1, 1.14.2** | v2.0 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | +| **1.14.3, 1.14.4** | v2.1 - 5.12, 8.3.0 - 8.8.0 | 8.8.0 | 16 | +| **1.15.x** | v2.3a - 5.12, 8.3.0 - 9.3.0 | 9.3.0 | 16 | +| **1.16.1** | v3.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.2** | v4.0 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.3** | v4.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.4** | v5.2 - 5.12, 8.3.0 - 9.4.2 | 9.4.2 | 16 | +| **1.16.5** | v5.7 - 7.0.0, 8.3.0 - 9.7.0 | 9.7.0 | 16 | +| **1.17** | 6.0.x - 9.7.0 | 9.7.0 | 16 | +| **1.17.1** | 6.1.x - 9.7.0 | 9.7.0 | 16 | +| **1.18, 1.18.1** | 6.5.2 - 9.7.0 | 9.7.0 | 16 | +| **1.18.2** | 6.5.4 - 9.7.0 | 9.7.0 | 16 | +| **1.19** | 8.3.0 - 9.7.0 | 9.7.0 | 16 | +| **1.19.1** | 8.5.0 - 9.7.0 | 9.7.0 | 16 | +| **1.19.2** | 8.5.1 - 9.7.0 | 9.7.0 | 16 | +| **1.19.3** | 8.7.0 - 9.7.0 | 9.7.0 | 16 | +| **1.19.4** | 8.8.0 - 9.7.0 | 9.7.0 | 16 | +| **1.20** | 9.0.2 - 11.0.0 | 11.0.0 | 17 | +| **1.20.1** | 9.0.3 - 11.0.0 | 11.0.0 | 17 | +| **1.20.2** | 9.2.0 - 11.0.0 | 11.0.0 | 17 | +| **1.20.3, 1.20.4** | 9.3.0 - 11.0.0 | 11.0.0 | 17 | +| **1.20.5, 1.20.6** | 9.4.0 - 11.0.0 | 11.0.0 | 17 | +| **1.21** | 9.5.0 - 11.0.0 | 11.0.0 | 17 | +| **1.21.1** | 9.5.2 - 11.0.0 | 11.0.0 | 17 | +| **1.21.2, 1.21.3** | 9.6.0 - 11.0.0 | 11.0.0 | 17 | +| **1.21.4** | 9.7.0 - 11.0.0 | 11.0.0 | 17 | +| **1.21.5** | 10.0.0 - 11.0.0 | 11.0.0 | 17 | +| **1.21.6** | 10.1.0 - 11.0.0 | 11.0.0 | 17 | +| **1.21.7** | 10.1.1 - 11.0.0 | 11.0.0 | 17 | +| **1.21.8** | 10.1.2 - 11.0.0 | 11.0.0 | 17 | +| **1.21.9, 1.21.10** | 11.0.0 | 11.0.0 | 17 | ----- @@ -341,16 +342,16 @@ The CommandAPI is built using the Maven build tool - if you don't have it, you c Notable artifacts can be found here: -- Spigot-mapped Spigot/Paper plugin `.jar`: +- Paper Plugin `.jar`: ```sh - commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/target/CommandAPI-X.X.X_DATE.jar + commandapi-platforms/commandapi-paper/commandapi-paper-plugin/target/CommandAPI-X.X.X_DATE.jar ``` -- Mojang-mapped Spigot/Paper plugin `.jar`: +- Spigot Plugin `.jar`: ```sh - commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/target/CommandAPI-X.X.X_DATE.jar + commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/target/CommandAPI-X.X.X_DATE.jar ``` - Velocity Plugin `.jar`: @@ -363,11 +364,7 @@ Notable artifacts can be found here: ## CommandAPI Project Timeline -This is the current roadmap for the CommandAPI (as of 1st April 2025): - -- **Hard Paper fork support** - - Paper's moving up in the world and it's about time the CommandAPI got with the times. We've got an active PR https://github.com/CommandAPI/CommandAPI/pull/517 that will have better support for Paper. In future, we'll only release Paper builds on Hangar and Spigot builds on SpigotMC. Modrinth will support both releases. +This is the current roadmap for the CommandAPI (as of 3rd October 2025): - **Annotation improvements** @@ -396,14 +393,16 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025): 11.0.0 - ??? + October 2025 + CommandAPI Changes:
      -
    • https://github.com/CommandAPI/CommandAPI/pull/517 Splits up the CommandAPI into modules specific for Paper and Spigot: +
    • https://github.com/CommandAPI/CommandAPI/issues/414, https://github.com/CommandAPI/CommandAPI/pull/517 Splits up the CommandAPI into modules specific for Paper and Spigot:
      • Removes the commandapi-bukkit-shade module and the commandapi-bukkit-shade-mojang-mapped module
      • -
      • Adds the commandapi-paper-core, commandapi-paper-shade and the commandapi-paper-shade-mojang-mapped modules which are made to work on Paper
      • -
      • Adds the commandapi-spigot-core, commandapi-spigot-shade and the commandapi-spigot-shade-mojang-mapped modules which are made to work on Spigot
      • +
      • Adds the commandapi-paper-core and the commandapi-paper-shade modules which are made to work on Paper
      • +
      • Adds the commandapi-spigot-core and the commandapi-spigot-shade modules which are made to work on Spigot
      • +
      • Adds the commandapi-paper-test-toolkit and the commandapi-spigot-test-toolkit which are replacing commandapi-bukkit-test-toolkit for Paper and Spigot respectively
      • Changed the CommandAPIBukkitConfig class into an abstract one in favour of the newly added CommandAPIPaperConfig or CommandAPISpigotConfig classes, depending on the modules you use
      • Moves and adds a few Kotlin DSL modules:
          @@ -415,14 +414,13 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025):
      • On Paper it is now possible to register commands at bootstrap
      • -
      • Drops support for 1.20.5 and below on Paper
      • Changes and updates a few arguments:
        • The FloatRangeArgument has been renamed to DoubleRangeArgument and now returns a DoubleRange
        • The PlayerArgument and OfflinePlayerArgument have been replaced by the PlayerProfileArgument which returns a List<PlayerProfile>. The PlayerProfile class changes depending on if you are on Paper or on Spigot. Use the EntitySelectorArgument.OnePlayer if you want a Player object.
        • The AsyncOfflinePlayerArgument has been replaced by the AsyncPlayerProfileArgument
        • The ChatArgument, ChatComponentArgument and ChatColorArgument do no longer have any Adventure prefixes and return different types depending on the platform.
        • -
        • The ChatArgument returns a SignedMessage object on Paper
        • +
        • The ChatArgument returns a SignedMessage object on Paper. Also resolves https://github.com/CommandAPI/CommandAPI/issues/381
        • The BlockStateArgument now returns a BlockState object instead of a BlockData object
      • @@ -436,6 +434,21 @@ This is the current roadmap for the CommandAPI (as of 1st April 2025):
    + Minecraft Version Changes: +
      +
    • Adds support for Minecraft 1.21.9 and 1.21.10 +
        +
      • Note: 1.21.10 isn't released at the time of writing. The diff between 1.21.9 and 1.21.10-rc1 seems to be very small though so we expect no breakages.
      • +
      +
    • +
    • Drops support for Minecraft 1.20.5 and below on Paper
    • +
    + Bug Fixes: +
      +
    • https://github.com/CommandAPI/CommandAPI/issues/631 Fixes unregistered commands reappearing after a minecraft:reload. This comes with some other notable changes around command registrations and unregistrations. You can read about these on the command unregistration page in the documentation.
    • +
    • https://github.com/CommandAPI/CommandAPI/issues/608 The RecipeArgument no longer throws any exceptions on Spigot
    • +
    • https://github.com/CommandAPI/CommandAPI/issues/494, https://github.com/CommandAPI/CommandAPI/isues/503 Fixes the ConcurrentModificationException from happening when registering/unregistering commands at runtime
    • +
    From 0303e6952e58aa76fb72ba49ca72a16861be5ec1 Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Sat, 4 Oct 2025 11:19:16 +0100 Subject: [PATCH 52/63] Flag setupPaperNMS.sh as an executable shell script. Adds a name to codecov module --- commandapi-codecov/pom.xml | 1 + setupPaperNMS.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/commandapi-codecov/pom.xml b/commandapi-codecov/pom.xml index f51be2e64..4265dee06 100644 --- a/commandapi-codecov/pom.xml +++ b/commandapi-codecov/pom.xml @@ -24,6 +24,7 @@ commandapi-codecov + CommandAPI - Code Coverage Utility true diff --git a/setupPaperNMS.sh b/setupPaperNMS.sh index aaa933b2e..f0d750c35 100755 --- a/setupPaperNMS.sh +++ b/setupPaperNMS.sh @@ -1,3 +1,4 @@ +#!/bin/sh echo "Setup Paper NMS for version 1.20.5..." mvn --quiet paper-nms:init -pl :commandapi-paper-1.20.5 -P Platform.Paper From 09a50ef06328700ab744db4aff70784e2e8cb0ee Mon Sep 17 00:00:00 2001 From: DerEchtePilz <81232921+DerEchtePilz@users.noreply.github.com> Date: Sat, 4 Oct 2025 13:28:43 +0200 Subject: [PATCH 53/63] Add back hook-paper-reload and skip-initial-datapack-reload for the Paper plugin --- .../jorel/commandapi/config/DefaultBukkitConfig.java | 11 +++++++++++ .../java/dev/jorel/commandapi/CommandAPIPaper.java | 2 +- .../dev/jorel/commandapi/CommandAPIPaperConfig.java | 11 ++++++++--- .../dev/jorel/commandapi/InternalPaperConfig.java | 8 ++++---- .../java/dev/jorel/commandapi/CommandAPIMain.java | 3 ++- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java index 3d8c111e1..5238ff604 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/src/main/java/dev/jorel/commandapi/config/DefaultBukkitConfig.java @@ -27,6 +27,15 @@ public static CommentedConfigOption FALLBACK_TO_LATEST_NMS(boolean pape }, true ); + public static final CommentedConfigOption HOOK_PAPER_RELOAD = new CommentedConfigOption<>( + new String[] { + "Hook into Paper's ServerResourcesReloadedEvent (default: false)", + "If \"true\", the CommandAPI will hook into Paper's ServerResourcesReloadedEvent to detect when", + "/minecraft:reload is run. This allows the CommandAPI to automatically call its custom datapack-reloading", + "function which allows CommandAPI commands to be used in datapacks." + }, false + ); + public static final CommentedConfigOption> PLUGINS_TO_CONVERT = new CommentedConfigOption<>( new String[] { "Plugins to convert (default: [])", @@ -61,6 +70,8 @@ public static DefaultBukkitConfig createDefaultPaperConfig() { options.put("messages.missing-executor-implementation", MISSING_EXECUTOR_IMPLEMENTATION); options.put("create-dispatcher-json", CREATE_DISPATCHER_JSON); options.put("fallback-to-latest-nms", FALLBACK_TO_LATEST_NMS(true)); + options.put("skip-initial-datapack-reload", SKIP_RELOAD_DATAPACKS); // TODO: Remove once the Paper plugin utilizes the bootstrapper + options.put("hook-paper-reload", HOOK_PAPER_RELOAD); // TODO: Remove once the Paper plugin utilizes the bootstrapper options.put("plugins-to-convert", PLUGINS_TO_CONVERT); options.put("other-commands-to-convert", OTHER_COMMANDS_TO_CONVERT); options.put("skip-sender-proxy", SKIP_SENDER_PROXY); diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java index 0d7437253..294bf813f 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaper.java @@ -128,7 +128,7 @@ public void onEnable() { public void onServerReloadResources(ServerResourcesReloadedEvent event) { CommandAPIBukkit.get().getCommandRegistrationStrategy().preReloadDataPacks(); - if (getConfiguration().isCommandAPIPlugin()) { + if (getConfiguration().hookPaperReload()) { CommandAPI.logNormal("/minecraft:reload detected. Reloading CommandAPI commands!"); CommandAPIBukkit.get().reloadDataPacks(); } diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java index 433376948..cb15b8218 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/src/main/java/dev/jorel/commandapi/CommandAPIPaperConfig.java @@ -10,7 +10,7 @@ public class CommandAPIPaperConfig extends CommandAPIBukkitConfig Date: Sat, 4 Oct 2025 13:26:35 +0100 Subject: [PATCH 54/63] Migrate versions to the root package so resolved snapshot versions can be assigned easily --- commandapi-annotations/pom.xml | 2 +- .../commandapi-kotlin-bukkit/pom.xml | 2 +- .../commandapi-kotlin-paper/pom.xml | 2 +- .../commandapi-kotlin-spigot/pom.xml | 2 +- .../commandapi-bukkit-core/pom.xml | 2 +- .../pom.xml | 2 +- .../commandapi-bukkit-1.20.2/pom.xml | 8 ++- .../commandapi-bukkit-1.20.3/pom.xml | 8 ++- .../commandapi-bukkit-1.20.5/pom.xml | 8 ++- .../commandapi-bukkit-1.20/pom.xml | 8 ++- .../commandapi-bukkit-1.21.2/pom.xml | 8 ++- .../commandapi-bukkit-1.21.4/pom.xml | 9 ++-- .../commandapi-bukkit-1.21.5/pom.xml | 9 ++-- .../commandapi-bukkit-1.21.6/pom.xml | 8 ++- .../commandapi-bukkit-1.21.9/pom.xml | 8 ++- .../commandapi-bukkit-1.21/pom.xml | 8 ++- .../commandapi-bukkit-nms-common/pom.xml | 7 ++- .../pom.xml | 6 +-- .../pom.xml | 6 +-- .../pom.xml | 6 +-- .../commandapi-bukkit-test-impl-1.20/pom.xml | 6 +-- .../commandapi-bukkit-test-impl/pom.xml | 4 +- .../commandapi-paper-annotations/pom.xml | 2 +- .../commandapi-paper-core/pom.xml | 4 +- .../commandapi-paper-1.20.5/pom.xml | 2 +- .../commandapi-paper-1.21.9/pom.xml | 3 +- .../commandapi-paper-1.21/pom.xml | 4 +- .../commandapi-paper-api/pom.xml | 7 +-- .../commandapi-paper-plugin/pom.xml | 2 +- .../commandapi-paper-vh/pom.xml | 4 +- .../commandapi-spigot-annotations/pom.xml | 2 +- .../commandapi-spigot-core/pom.xml | 2 +- .../commandapi-spigot-1.20.2/pom.xml | 5 +- .../commandapi-spigot-1.20.3/pom.xml | 5 +- .../commandapi-spigot-1.20.5/pom.xml | 5 +- .../commandapi-spigot-1.20/pom.xml | 5 +- .../commandapi-spigot-1.21.2/pom.xml | 5 +- .../commandapi-spigot-1.21.4/pom.xml | 5 +- .../commandapi-spigot-1.21.5/pom.xml | 5 +- .../commandapi-spigot-1.21.6/pom.xml | 5 +- .../commandapi-spigot-1.21.9/pom.xml | 5 +- .../commandapi-spigot-1.21/pom.xml | 5 +- .../commandapi-spigot-plugin/pom.xml | 2 +- .../commandapi-spigot-vh/pom.xml | 2 +- pom.xml | 49 +++++++++++++++++-- 45 files changed, 131 insertions(+), 133 deletions(-) diff --git a/commandapi-annotations/pom.xml b/commandapi-annotations/pom.xml index a7ad4f841..07db1e300 100644 --- a/commandapi-annotations/pom.xml +++ b/commandapi-annotations/pom.xml @@ -47,7 +47,7 @@ org.spigotmc spigot-api - ${paper.version} + ${spigot.version.common} provided diff --git a/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml b/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml index 7db52c9ad..3a90f2550 100644 --- a/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-bukkit/pom.xml @@ -75,7 +75,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.20.1} provided diff --git a/commandapi-kotlin/commandapi-kotlin-paper/pom.xml b/commandapi-kotlin/commandapi-kotlin-paper/pom.xml index f8f8d3951..75dcdbb48 100644 --- a/commandapi-kotlin/commandapi-kotlin-paper/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-paper/pom.xml @@ -74,7 +74,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.20.1} provided diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml index 11abb051a..3c25b758f 100644 --- a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml @@ -74,7 +74,7 @@ org.spigotmc spigot-api - ${paper.version} + ${spigot.version.common} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml index 81692d692..96025c7ff 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml @@ -57,7 +57,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.20.1} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml index db7a07d3e..d3825a938 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml @@ -22,7 +22,7 @@ org.spigotmc spigot-api - ${paper.version} + ${spigot.version.common} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml index cbef35ccd..3e10516f3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.2/pom.xml @@ -30,8 +30,6 @@ 1.20.2-R0.1-SNAPSHOT - 1.20.2-R0.1-SNAPSHOT - 1.20.2-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.2} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.2} remapped-mojang provided @@ -70,7 +68,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.20.2} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml index 5580c02a9..cdde1be34 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.3/pom.xml @@ -30,8 +30,6 @@ 1.20.4-R0.1-SNAPSHOT - 1.20.4-R0.1-SNAPSHOT - 1.20.4-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.4} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.4} remapped-mojang provided @@ -70,7 +68,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.20.4} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml index 33993956a..81c8679d2 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/pom.xml @@ -30,8 +30,6 @@ 1.20.6-R0.1-SNAPSHOT - 1.20.6-R0.1-SNAPSHOT - 1.20.6-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.6} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.6} remapped-mojang provided @@ -70,7 +68,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.20.6} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml index c9d1d6317..40819052d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20/pom.xml @@ -30,8 +30,6 @@ 1.20.1-R0.1-SNAPSHOT - 1.20.1-R0.1-SNAPSHOT - 1.20.1-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.1} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.1} remapped-mojang provided @@ -70,7 +68,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.20.1} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml index 2d1f56d77..386777528 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.2/pom.xml @@ -30,8 +30,6 @@ 1.21.3-R0.1-SNAPSHOT - 1.21.3-R0.1-SNAPSHOT - 1.21.3-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.3} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.3} remapped-mojang provided @@ -70,7 +68,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.21.3} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml index 9347d1681..237290e8b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.4/pom.xml @@ -30,8 +30,6 @@ 1.21.4-R0.1-SNAPSHOT - 1.21.4-R0.1-SNAPSHOT - 1.21.3-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.4} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.4} remapped-mojang provided @@ -70,7 +68,8 @@ io.papermc.paper paper-api - ${paper.version} + + ${paper.version.1.21.3} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml index f1b4c3261..98c49aa2d 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.5/pom.xml @@ -30,8 +30,6 @@ 1.21.5-R0.1-SNAPSHOT - 1.21.5-R0.1-SNAPSHOT - 1.21.4-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.5} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.5} remapped-mojang provided @@ -70,7 +68,8 @@ io.papermc.paper paper-api - ${paper.version} + + ${paper.version.1.21.4} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml index 9b1a742bb..8ddaa5246 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.6/pom.xml @@ -30,8 +30,6 @@ 1.21.6-R0.1-SNAPSHOT - 1.21.6-R0.1-SNAPSHOT - 1.21.6-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.6} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.6} remapped-mojang provided @@ -70,7 +68,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.21.6} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml index 122ee261c..cf6f8abba 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21.9/pom.xml @@ -30,8 +30,6 @@ 1.21.9-R0.1-SNAPSHOT - 1.21.9-R0.1-SNAPSHOT - 1.21.9-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.9} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.9} remapped-mojang provided @@ -70,7 +68,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.21.9} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml index 4c7fe3f6b..0b2b4dd51 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.21/pom.xml @@ -30,8 +30,6 @@ 1.21.1-R0.1-SNAPSHOT - 1.21.1-R0.1-SNAPSHOT - 1.21.1-R0.1-SNAPSHOT @@ -55,14 +53,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.1} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.1} remapped-mojang provided @@ -70,7 +68,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.21.1} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index 4fc42304b..4b3b4980f 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -28,7 +28,6 @@ 1.20.1-R0.1-SNAPSHOT - 1.20.1-R0.1-SNAPSHOT @@ -51,14 +50,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.common} provided remapped-mojang @@ -67,7 +66,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.common} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml index b74549039..7018e9236 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml @@ -35,8 +35,6 @@ 1.20.2-R0.1-SNAPSHOT - 1.20.2-R0.1-SNAPSHOT - 1.20.2-R0.1-SNAPSHOT @@ -106,7 +104,7 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.2} remapped-mojang provided @@ -118,7 +116,7 @@ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml index 62b34324a..793d14064 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml @@ -35,8 +35,6 @@ 1.20.4-R0.1-SNAPSHOT - 1.20.4-R0.1-SNAPSHOT - 1.20.4-R0.1-SNAPSHOT @@ -106,7 +104,7 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.4} remapped-mojang provided @@ -118,7 +116,7 @@ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml index 08a7d105b..34fc3da89 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml @@ -35,8 +35,6 @@ 1.20.5-R0.1-SNAPSHOT - 1.20.5-R0.1-SNAPSHOT - 1.20.4-R0.1-SNAPSHOT @@ -106,7 +104,7 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.5} remapped-mojang provided @@ -118,7 +116,7 @@ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml index 431793077..106ca5b13 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml @@ -35,8 +35,6 @@ 1.20.1-R0.1-SNAPSHOT - 1.20.1-R0.1-SNAPSHOT - 1.20.1-R0.1-SNAPSHOT @@ -106,7 +104,7 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.1} remapped-mojang provided @@ -118,7 +116,7 @@ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml index 2ce6d3b6f..7b78e5c28 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml @@ -72,13 +72,13 @@ io.papermc.paper paper-api - ${spigot.version} + ${paper.version.common} provided org.spigotmc spigot - ${spigot.version} + ${spigot.version.common} provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml index f35533f53..bf409b326 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-annotations/pom.xml @@ -40,7 +40,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.common} provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml index 574e03ac0..3b29dccc6 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml @@ -43,13 +43,13 @@ dev.folia folia-api - ${paper.version} + ${folia.version.common} provided io.papermc.paper paper-api - ${paper.version} + ${paper.version.common} provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml index 992eaf48f..82d88bc17 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.20.5/pom.xml @@ -44,7 +44,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.20.6} provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml index e0c364a6d..282e20a28 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21.9/pom.xml @@ -14,7 +14,6 @@ 1.21.9-R0.1-SNAPSHOT - 1.21.9-R0.1-SNAPSHOT @@ -50,7 +49,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.21.9} provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml index 827796818..6649bf51e 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-1.21/pom.xml @@ -14,8 +14,6 @@ 1.21-R0.1-SNAPSHOT - 1.21-R0.1-SNAPSHOT - 1.21-R0.1-SNAPSHOT @@ -45,7 +43,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.1.21} provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml index 1f06ab239..0d31e38ca 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-nms/commandapi-paper-api/pom.xml @@ -12,10 +12,6 @@ commandapi-paper-api Paper API support - - 1.21.9-R0.1-SNAPSHOT - - papermc @@ -27,7 +23,8 @@ io.papermc.paper paper-api - ${paper.version} + + ${paper.version.1.21.9} provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml index 8b6bbbf8c..89bfed1ba 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-plugin/pom.xml @@ -38,7 +38,7 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.common} provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml index 53ff8a1f7..5b4b6b269 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-vh/pom.xml @@ -30,14 +30,14 @@ io.papermc.paper paper-api - ${paper.version} + ${paper.version.common} provided - + diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml index 6834915ed..447ea3fcd 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml @@ -40,7 +40,7 @@ org.spigotmc spigot-api - ${paper.version} + ${spigot.version.common} provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml index 37ee2cb5e..fbf01137d 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml @@ -37,7 +37,7 @@ org.spigotmc spigot-api - ${paper.version} + ${spigot.version.common} provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml index 84db40495..b95e921be 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml @@ -14,7 +14,6 @@ 1.20.2-R0.1-SNAPSHOT - 1.20.2-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.2} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.2} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml index 979735105..9c0343db7 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml @@ -14,7 +14,6 @@ 1.20.4-R0.1-SNAPSHOT - 1.20.4-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.4} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.4} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml index 3afd0ad17..3dc39e8c1 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml @@ -14,7 +14,6 @@ 1.20.6-R0.1-SNAPSHOT - 1.20.6-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.6} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.6} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml index 75434cf83..3d91f2bfa 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml @@ -14,7 +14,6 @@ 1.20.1-R0.1-SNAPSHOT - 1.20.1-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.1} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.20.1} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml index e54db8a96..a638abd38 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml @@ -14,7 +14,6 @@ 1.21.3-R0.1-SNAPSHOT - 1.21.3-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.3} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.3} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml index 3fa40972e..2a1df93f1 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml @@ -14,7 +14,6 @@ 1.21.4-R0.1-SNAPSHOT - 1.21.4-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.4} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.4} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml index f6191874b..b2469b42c 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml @@ -14,7 +14,6 @@ 1.21.5-R0.1-SNAPSHOT - 1.21.5-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.5} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.5} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml index 7ce0d3a11..f9f8439ed 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml @@ -14,7 +14,6 @@ 1.21.6-R0.1-SNAPSHOT - 1.21.6-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.6} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.6} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml index 7372f7cf2..dd4f95b2e 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml @@ -14,7 +14,6 @@ 1.21.9-R0.1-SNAPSHOT - 1.21.9-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.9} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.9} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml index 8de1a5a92..09c41ae9e 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml @@ -14,7 +14,6 @@ 1.21.1-R0.1-SNAPSHOT - 1.21.1-R0.1-SNAPSHOT @@ -37,14 +36,14 @@ org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.1} test org.spigotmc spigot - ${spigot.version} + ${spigot.version.1.21.1} remapped-mojang provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml index d51a95904..3ba271b29 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml @@ -38,7 +38,7 @@ org.spigotmc spigot-api - ${paper.version} + ${spigot.version.common} provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml index cc513cea7..4e33b1797 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-vh/pom.xml @@ -24,7 +24,7 @@ org.spigotmc spigot - ${paper.version} + ${spigot.version.common} remapped-mojang provided diff --git a/pom.xml b/pom.xml index fbba9f94b..02299b01a 100644 --- a/pom.xml +++ b/pom.xml @@ -98,10 +98,51 @@ 17 1.9.0 - - 1.20.1-R0.1-SNAPSHOT + + 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT + + + 1.20.1-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT + 1.20.3-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT + 1.20.5-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT + 1.21.2-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT + 1.21.5-R0.1-SNAPSHOT + 1.21.6-R0.1-SNAPSHOT + 1.21.7-R0.1-SNAPSHOT + 1.21.8-R0.1-SNAPSHOT + 1.21.9-R0.1-SNAPSHOT + + 1.20.1-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT + 1.20.3-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT + 1.20.5-R0.1-SNAPSHOT + 1.20.6-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT + 1.21.1-R0.1-SNAPSHOT + 1.21.2-R0.1-SNAPSHOT + 1.21.3-R0.1-SNAPSHOT + 1.21.4-R0.1-SNAPSHOT + 1.21.5-R0.1-SNAPSHOT + 1.21.6-R0.1-SNAPSHOT + 1.21.7-R0.1-SNAPSHOT + 1.21.8-R0.1-SNAPSHOT + 1.21.9-R0.1-SNAPSHOT + 1.0.1 From a34451989eab0330a2771871a659b901eb96df0d Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Sat, 4 Oct 2025 13:52:04 +0100 Subject: [PATCH 55/63] Resolve snapshot versions with a snapshot resolving script --- pom.xml | 72 ++++++++++----------- resolve-snapshots.py | 145 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 36 deletions(-) create mode 100644 resolve-snapshots.py diff --git a/pom.xml b/pom.xml index 02299b01a..146e4e3ed 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ commandapi-annotations commandapi-testing - + commandapi-codecov @@ -101,47 +101,47 @@ - 1.20.1-R0.1-SNAPSHOT - 1.20.1-R0.1-SNAPSHOT - 1.20.1-R0.1-SNAPSHOT + 1.20.1-R0.1-20230921.165251-11 + 1.20.1-R0.1-20230911.182805-18 + 1.20.1-R0.1-20230921.165944-178 - 1.20.1-R0.1-SNAPSHOT - 1.20.2-R0.1-SNAPSHOT - 1.20.3-R0.1-SNAPSHOT - 1.20.4-R0.1-SNAPSHOT - 1.20.5-R0.1-SNAPSHOT - 1.20.6-R0.1-SNAPSHOT - 1.21-R0.1-SNAPSHOT - 1.21.1-R0.1-SNAPSHOT - 1.21.2-R0.1-SNAPSHOT - 1.21.3-R0.1-SNAPSHOT - 1.21.4-R0.1-SNAPSHOT - 1.21.5-R0.1-SNAPSHOT - 1.21.6-R0.1-SNAPSHOT - 1.21.7-R0.1-SNAPSHOT - 1.21.8-R0.1-SNAPSHOT - 1.21.9-R0.1-SNAPSHOT + 1.20.1-R0.1-20230921.165251-11 + 1.20.2-R0.1-20231205.170307-10 + 1.20.3-R0.1-20231207.200753-2 + 1.20.4-R0.1-20240423.154232-27 + 1.20.5-R0.1-20240429.203257-8 + 1.20.6-R0.1-20240613.152322-4 + + 1.21.1-R0.1-20241120.105205-27 + + 1.21.3-R0.1-20250116.085943-60 + 1.21.4-R0.1-20250425.052153-78 + 1.21.5-R0.1-20250723.090352-41 + 1.21.6-R0.1-20250617.185834-1 + 1.21.7-R0.1-20250630.172254-1 + 1.21.8-R0.1-20251003.231743-18 + 1.21.9-R0.1-20250930.202015-1 - 1.20.1-R0.1-SNAPSHOT - 1.20.2-R0.1-SNAPSHOT - 1.20.3-R0.1-SNAPSHOT - 1.20.4-R0.1-SNAPSHOT - 1.20.5-R0.1-SNAPSHOT - 1.20.6-R0.1-SNAPSHOT - 1.21-R0.1-SNAPSHOT - 1.21.1-R0.1-SNAPSHOT - 1.21.2-R0.1-SNAPSHOT - 1.21.3-R0.1-SNAPSHOT - 1.21.4-R0.1-SNAPSHOT - 1.21.5-R0.1-SNAPSHOT - 1.21.6-R0.1-SNAPSHOT - 1.21.7-R0.1-SNAPSHOT - 1.21.8-R0.1-SNAPSHOT - 1.21.9-R0.1-SNAPSHOT + 1.20.1-R0.1-20230921.165944-178 + 1.20.2-R0.1-20231203.034718-122 + 1.20.3-R0.1-20231207.043048-3 + 1.20.4-R0.1-20241030.192207-176 + 1.20.5-R0.1-20240429.035133-20 + 1.20.6-R0.1-20241030.191541-127 + 1.21-R0.1-20240810.100446-132 + 1.21.1-R0.1-20250328.161643-128 + + 1.21.3-R0.1-20250328.155925-87 + 1.21.4-R0.1-20250925.065901-231 + 1.21.5-R0.1-20250925.065803-26 + 1.21.6-R0.1-20250630.094942-50 + 1.21.7-R0.1-20250716.201120-28 + 1.21.8-R0.1-20250906.215025-55 + 1.21.9-R0.1-20251003.181801-9 1.0.1 diff --git a/resolve-snapshots.py b/resolve-snapshots.py new file mode 100644 index 000000000..6ae821ac8 --- /dev/null +++ b/resolve-snapshots.py @@ -0,0 +1,145 @@ +# resolve-snapshots.py +# +# Usage: +# python resolve-snapshots.py +# +# Description: +# Resolves snapshot versions in the root pom.xml file. To have +# a snapshot resolve, add a entry, give +# it a version with -SNAPSHOT, and then run this script. This +# script will update the pom.xml file accordingly. This script +# will also remove all comments, but I CBA to fix that right +# now. + +import re +import sys +import time +import argparse +import urllib.request +import urllib.error +import xml.etree.ElementTree as ET +from pathlib import Path + +SPIGOT_SNAP = "https://repo.codemc.io/repository/nms/" +PAPER_SNAP = "https://repo.papermc.io/repository/maven-public" + +def coord_for_property(prop_name: str): + if prop_name.startswith("spigot.version."): + return ("org.spigotmc", "spigot-api", SPIGOT_SNAP) + if prop_name.startswith("paper.version."): + return ("io.papermc.paper", "paper-api", PAPER_SNAP) + return None + +def fetch_text(url: str, timeout=8, retries=3, verbose=False) -> str: + last_err = None + for attempt in range(1, retries + 1): + if verbose: + print(f"[http] GET {url} (attempt {attempt}/{retries})", flush=True) + try: + req = urllib.request.Request( + url, + headers={"User-Agent": "snapshot-resolver/1.0 (+https://example.invalid)"} + ) + with urllib.request.urlopen(req, timeout=timeout) as resp: + return resp.read().decode("utf-8") + except (urllib.error.HTTPError, urllib.error.URLError, TimeoutError) as e: + last_err = e + if verbose: + print(f"[http] Error: {e}", flush=True) + # small backoff + time.sleep(0.8 * attempt) + raise RuntimeError(f"Failed to fetch {url}: {last_err}") + +def latest_snapshot_value(repo_base: str, group: str, artifact: str, snapshot_version: str, verbose=False) -> str: + meta_url = "/".join([ + repo_base.rstrip("/"), + group.replace(".", "/"), + artifact, + snapshot_version, + "maven-metadata.xml" + ]) + xml = fetch_text(meta_url, verbose=verbose) + md = ET.fromstring(xml) + + svs = md.findall("./versioning/snapshotVersions/snapshotVersion") + pom_value = None + any_value = None + for sv in svs: + ext = sv.findtext("extension", "") + val = sv.findtext("value") + if val: + any_value = val + if ext == "pom": + pom_value = val + if pom_value: + return pom_value + if any_value: + return any_value + + snap = md.find("./versioning/snapshot") + if snap is not None: + ts = snap.findtext("timestamp") + bn = snap.findtext("buildNumber") + if ts and bn: + base = snapshot_version.replace("-SNAPSHOT", "") + return f"{base}-{ts}-{bn}" + raise RuntimeError("No snapshot value found in metadata") + +def resolve_properties(pom_path: Path, verbose=False): + ns = {"m": "http://maven.apache.org/POM/4.0.0"} + ET.register_namespace("", "http://maven.apache.org/POM/4.0.0") + tree = ET.parse(pom_path) + root = tree.getroot() + + props = root.find("m:properties", ns) + if props is None: + print("No found.") + return + + changes = [] + for child in list(props): + tag = re.sub(r"^\{.*\}", "", child.tag) # strip ns + coord = coord_for_property(tag) + if not coord: + continue + + current = (child.text or "").strip() + if not current.endswith("-SNAPSHOT"): + if verbose: + print(f"[skip] {tag}: already pinned: {current}", flush=True) + continue + + group, artifact, repo = coord + print(f"[resolving] {tag}: {current} -> …", flush=True) + try: + resolved = latest_snapshot_value(repo, group, artifact, current, verbose=verbose) + if resolved and resolved != current: + print(f"[resolved] {tag}: {resolved}", flush=True) + changes.append((tag, current, resolved)) + child.text = resolved + else: + print(f"[no-change] {tag}: {current}", flush=True) + except Exception as e: + print(f"[WARN] {tag}: {current} -> could not resolve: {e}", flush=True) + + if not changes: + print("No snapshot properties needed updates.") + return + + backup = pom_path.with_suffix(".xml.bak") + pom_path.rename(backup) + tree.write(pom_path, encoding="utf-8", xml_declaration=True) + + print(f"\nUpdated {pom_path.name}. Backup: {backup.name}") + for tag, old, new in changes: + print(f" - {tag}: {old} -> {new}") + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("pom", nargs="?", default="pom.xml") + ap.add_argument("-v", "--verbose", action="store_true") + args = ap.parse_args() + resolve_properties(Path(args.pom), verbose=args.verbose) + +if __name__ == "__main__": + main() \ No newline at end of file From e2ef59bd5a92a58c3fc81c869fca7ab3c4e92cad Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Sat, 4 Oct 2025 14:07:18 +0100 Subject: [PATCH 56/63] Update resolution to include spigot-api and velocity-api as well. Stop resolve snapshots writing directly to the pom.xml file --- commandapi-annotations/pom.xml | 2 +- .../commandapi-kotlin-spigot/pom.xml | 2 +- .../commandapi-kotlin-velocity/pom.xml | 2 +- .../commandapi-bukkit-core/pom.xml | 2 +- .../pom.xml | 2 +- .../commandapi-bukkit-plugin-common/pom.xml | 2 +- .../commandapi-spigot-annotations/pom.xml | 2 +- .../commandapi-spigot-core/pom.xml | 2 +- .../commandapi-spigot-plugin/pom.xml | 2 +- .../commandapi-velocity-core/pom.xml | 2 +- .../commandapi-velocity-plugin/pom.xml | 2 +- .../commandapi-testing-spigot/pom.xml | 2 +- pom.xml | 19 +++++++++++++++++-- resolve-snapshots.py | 18 +++++++++++------- 14 files changed, 40 insertions(+), 21 deletions(-) diff --git a/commandapi-annotations/pom.xml b/commandapi-annotations/pom.xml index 07db1e300..ff50f9a6b 100644 --- a/commandapi-annotations/pom.xml +++ b/commandapi-annotations/pom.xml @@ -47,7 +47,7 @@ org.spigotmc spigot-api - ${spigot.version.common} + ${spigot.api.version.common} provided diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml index 3c25b758f..7243e7262 100644 --- a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml @@ -74,7 +74,7 @@ org.spigotmc spigot-api - ${spigot.version.common} + ${spigot.api.version.common} provided diff --git a/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml b/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml index 1c4a345eb..04b9f2b88 100644 --- a/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-velocity/pom.xml @@ -72,7 +72,7 @@ com.velocitypowered velocity-api - 3.3.0-SNAPSHOT + ${velocity.version.common} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml index 96025c7ff..5a3ea8ad3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-core/pom.xml @@ -51,7 +51,7 @@ dev.folia folia-api - 1.20.1-R0.1-SNAPSHOT + ${folia.version.common} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml index d3825a938..3b9ce8940 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml @@ -22,7 +22,7 @@ org.spigotmc spigot-api - ${spigot.version.common} + ${spigot.api.version.common} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml index 1e2cb9bdf..ad2087ad3 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-common/pom.xml @@ -63,7 +63,7 @@ io.papermc.paper paper-api - 1.21.1-R0.1-SNAPSHOT + ${paper.version.1.21.1} provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml index 447ea3fcd..08273b5d5 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml @@ -40,7 +40,7 @@ org.spigotmc spigot-api - ${spigot.version.common} + ${spigot.api.version.common} provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml index fbf01137d..adeee6450 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml @@ -37,7 +37,7 @@ org.spigotmc spigot-api - ${spigot.version.common} + ${spigot.api.version.common} provided diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml index 3ba271b29..6a3380676 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml @@ -38,7 +38,7 @@ org.spigotmc spigot-api - ${spigot.version.common} + ${spigot.api.version.common} provided diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml index e6e9bc9f5..69113a292 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-core/pom.xml @@ -43,7 +43,7 @@ com.velocitypowered velocity-api - 3.3.0-SNAPSHOT + ${velocity.version.common} provided diff --git a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml index 7701a6c2e..9e5f18c39 100644 --- a/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml +++ b/commandapi-platforms/commandapi-velocity/commandapi-velocity-plugin/pom.xml @@ -25,7 +25,7 @@ com.velocitypowered velocity-api - 3.3.0-SNAPSHOT + ${velocity.version.common} provided diff --git a/commandapi-testing/commandapi-testing-spigot/pom.xml b/commandapi-testing/commandapi-testing-spigot/pom.xml index 092deb13a..b2a369c68 100644 --- a/commandapi-testing/commandapi-testing-spigot/pom.xml +++ b/commandapi-testing/commandapi-testing-spigot/pom.xml @@ -27,7 +27,7 @@ org.spigotmc spigot-api - 1.20.1-R0.1-SNAPSHOT + ${spigot.api.version.common} provided diff --git a/pom.xml b/pom.xml index 146e4e3ed..529b6f617 100644 --- a/pom.xml +++ b/pom.xml @@ -102,8 +102,10 @@ plugin which doesn't need a dedicated NMS version. This should be (ideally) the lowest version amongst versions --> 1.20.1-R0.1-20230921.165251-11 + 1.20.1-R0.1-20230921.165347-11 1.20.1-R0.1-20230911.182805-18 1.20.1-R0.1-20230921.165944-178 + 3.3.0-20240916.013244-136 1.21.1-R0.1-20241120.105205-27 - 1.21.3-R0.1-20250116.085943-60 1.21.4-R0.1-20250425.052153-78 1.21.5-R0.1-20250723.090352-41 @@ -126,6 +126,21 @@ 1.21.8-R0.1-20251003.231743-18 1.21.9-R0.1-20250930.202015-1 + 1.20.1-R0.1-20230921.165347-11 + 1.20.2-R0.1-20231205.170413-10 + 1.20.3-R0.1-20231207.200858-2 + 1.20.4-R0.1-20240423.154326-27 + 1.20.5-R0.1-20240429.203257-8 + 1.20.6-R0.1-20240613.152322-4 + 1.21.1-R0.1-20241120.105205-27 + 1.21.3-R0.1-20250116.085943-59 + 1.21.4-R0.1-20250425.052153-76 + 1.21.5-R0.1-20250723.090352-40 + 1.21.6-R0.1-20250617.185834-1 + 1.21.7-R0.1-20250630.172254-1 + 1.21.8-R0.1-20251003.231743-17 + 1.21.9-R0.1-20250930.202015-1 + 1.20.1-R0.1-20230921.165944-178 1.20.2-R0.1-20231203.034718-122 1.20.3-R0.1-20231207.043048-3 diff --git a/resolve-snapshots.py b/resolve-snapshots.py index 6ae821ac8..4a28291b8 100644 --- a/resolve-snapshots.py +++ b/resolve-snapshots.py @@ -7,9 +7,8 @@ # Resolves snapshot versions in the root pom.xml file. To have # a snapshot resolve, add a entry, give # it a version with -SNAPSHOT, and then run this script. This -# script will update the pom.xml file accordingly. This script -# will also remove all comments, but I CBA to fix that right -# now. +# script will then dump the resolved versions to the terminal +# for you to update the pom.xml file manually. import re import sys @@ -26,8 +25,12 @@ def coord_for_property(prop_name: str): if prop_name.startswith("spigot.version."): return ("org.spigotmc", "spigot-api", SPIGOT_SNAP) + if prop_name.startswith("spigot.api.version."): + return ("org.spigotmc", "spigot", SPIGOT_SNAP) if prop_name.startswith("paper.version."): return ("io.papermc.paper", "paper-api", PAPER_SNAP) + if prop_name.startswith("velocity.version."): + return ("com.velocitypowered", "velocity-api", PAPER_SNAP) return None def fetch_text(url: str, timeout=8, retries=3, verbose=False) -> str: @@ -126,11 +129,12 @@ def resolve_properties(pom_path: Path, verbose=False): print("No snapshot properties needed updates.") return - backup = pom_path.with_suffix(".xml.bak") - pom_path.rename(backup) - tree.write(pom_path, encoding="utf-8", xml_declaration=True) + # backup = pom_path.with_suffix(".xml.bak") + # pom_path.rename(backup) + # tree.write(pom_path, encoding="utf-8", xml_declaration=True) - print(f"\nUpdated {pom_path.name}. Backup: {backup.name}") + # print(f"\nUpdated {pom_path.name}. Backup: {backup.name}") + print("Completed resolving. Resolution:") for tag, old, new in changes: print(f" - {tag}: {old} -> {new}") From 43aa711a74c3d60551ca0261196a0f0d9a2ed711 Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Sat, 4 Oct 2025 14:14:06 +0100 Subject: [PATCH 57/63] Fix spigot-api and spigot having mismatched IDs. Fix bukkit-networking-plugin having the wrong repository --- .../pom.xml | 7 ++++ pom.xml | 36 +++++++++---------- resolve-snapshots.py | 4 +-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml index 3b9ce8940..aea96cf01 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-networking-plugin/pom.xml @@ -12,6 +12,13 @@ commandapi-bukkit-networking-plugin Bukkit support Velocity networking plugin + + + codemc-repo + https://repo.codemc.io/repository/nms/ + + + dev.jorel diff --git a/pom.xml b/pom.xml index 529b6f617..1dc4e7a8e 100644 --- a/pom.xml +++ b/pom.xml @@ -101,8 +101,8 @@ - 1.20.1-R0.1-20230921.165251-11 - 1.20.1-R0.1-20230921.165347-11 + 1.20.1-R0.1-20230921.165347-11 + 1.20.1-R0.1-20230921.165251-11 1.20.1-R0.1-20230911.182805-18 1.20.1-R0.1-20230921.165944-178 3.3.0-20240916.013244-136 @@ -111,34 +111,34 @@ in pom.xml files anymore, we need to get specific versions of SNAPSHOT builds Instead of declaring this in every pom.xml, we'll just have a mega chungus list here instead. --> - 1.20.1-R0.1-20230921.165251-11 - 1.20.2-R0.1-20231205.170307-10 - 1.20.3-R0.1-20231207.200753-2 - 1.20.4-R0.1-20240423.154232-27 + 1.20.1-R0.1-20230921.165347-11 + 1.20.2-R0.1-20231205.170413-10 + 1.20.3-R0.1-20231207.200858-2 + 1.20.4-R0.1-20240423.154326-27 1.20.5-R0.1-20240429.203257-8 1.20.6-R0.1-20240613.152322-4 1.21.1-R0.1-20241120.105205-27 - 1.21.3-R0.1-20250116.085943-60 - 1.21.4-R0.1-20250425.052153-78 - 1.21.5-R0.1-20250723.090352-41 + 1.21.3-R0.1-20250116.085943-59 + 1.21.4-R0.1-20250425.052153-76 + 1.21.5-R0.1-20250723.090352-40 1.21.6-R0.1-20250617.185834-1 1.21.7-R0.1-20250630.172254-1 - 1.21.8-R0.1-20251003.231743-18 + 1.21.8-R0.1-20251003.231743-17 1.21.9-R0.1-20250930.202015-1 - 1.20.1-R0.1-20230921.165347-11 - 1.20.2-R0.1-20231205.170413-10 - 1.20.3-R0.1-20231207.200858-2 - 1.20.4-R0.1-20240423.154326-27 + 1.20.1-R0.1-20230921.165251-11 + 1.20.2-R0.1-20231205.170307-10 + 1.20.3-R0.1-20231207.200753-2 + 1.20.4-R0.1-20240423.154232-27 1.20.5-R0.1-20240429.203257-8 1.20.6-R0.1-20240613.152322-4 1.21.1-R0.1-20241120.105205-27 - 1.21.3-R0.1-20250116.085943-59 - 1.21.4-R0.1-20250425.052153-76 - 1.21.5-R0.1-20250723.090352-40 + 1.21.3-R0.1-20250116.085943-60 + 1.21.4-R0.1-20250425.052153-78 + 1.21.5-R0.1-20250723.090352-41 1.21.6-R0.1-20250617.185834-1 1.21.7-R0.1-20250630.172254-1 - 1.21.8-R0.1-20251003.231743-17 + 1.21.8-R0.1-20251003.231743-18 1.21.9-R0.1-20250930.202015-1 1.20.1-R0.1-20230921.165944-178 diff --git a/resolve-snapshots.py b/resolve-snapshots.py index 4a28291b8..84b412b8d 100644 --- a/resolve-snapshots.py +++ b/resolve-snapshots.py @@ -24,9 +24,9 @@ def coord_for_property(prop_name: str): if prop_name.startswith("spigot.version."): - return ("org.spigotmc", "spigot-api", SPIGOT_SNAP) - if prop_name.startswith("spigot.api.version."): return ("org.spigotmc", "spigot", SPIGOT_SNAP) + if prop_name.startswith("spigot.api.version."): + return ("org.spigotmc", "spigot-api", SPIGOT_SNAP) if prop_name.startswith("paper.version."): return ("io.papermc.paper", "paper-api", PAPER_SNAP) if prop_name.startswith("velocity.version."): From b0fd09a38275cbd23ddd08f4fc3392b18eae53b4 Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Sat, 4 Oct 2025 14:25:01 +0100 Subject: [PATCH 58/63] Prefer using the codemc repo over the spigot repo for spigot-api snapshots --- commandapi-annotations/pom.xml | 4 ++-- commandapi-kotlin/commandapi-kotlin-spigot/pom.xml | 4 ++-- .../commandapi-bukkit-kotlin-test/pom.xml | 4 ---- .../commandapi-bukkit-test-impl-1.20.2/pom.xml | 4 ---- .../commandapi-bukkit-test-impl-1.20.3/pom.xml | 4 ---- .../commandapi-bukkit-test-impl-1.20.5/pom.xml | 4 ---- .../commandapi-bukkit-test-impl-1.20/pom.xml | 4 ---- .../commandapi-bukkit-test-impl/pom.xml | 4 ---- .../commandapi-bukkit-test-tests/pom.xml | 4 ---- .../commandapi-spigot-annotations/pom.xml | 4 ++-- .../commandapi-spigot/commandapi-spigot-core/pom.xml | 7 +------ .../commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml | 4 ---- .../commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml | 4 ---- .../commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml | 4 ---- .../commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml | 4 ---- .../commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml | 4 ---- .../commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml | 4 ---- .../commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml | 4 ---- .../commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml | 4 ---- .../commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml | 4 ---- .../commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml | 4 ---- .../commandapi-spigot/commandapi-spigot-plugin/pom.xml | 4 ---- commandapi-testing/commandapi-testing-spigot/pom.xml | 4 ++-- 23 files changed, 9 insertions(+), 86 deletions(-) diff --git a/commandapi-annotations/pom.xml b/commandapi-annotations/pom.xml index ff50f9a6b..d871a64e8 100644 --- a/commandapi-annotations/pom.xml +++ b/commandapi-annotations/pom.xml @@ -26,8 +26,8 @@ - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + codemc-repo + https://repo.codemc.io/repository/nms/ diff --git a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml index 7243e7262..3159cf533 100644 --- a/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml +++ b/commandapi-kotlin/commandapi-kotlin-spigot/pom.xml @@ -61,8 +61,8 @@ - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + codemc-repo + https://repo.codemc.io/repository/nms/ sonatype diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/pom.xml index 0b729e171..61b107131 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/pom.xml @@ -26,10 +26,6 @@ https://repo.codemc.io/repository/nms/ default - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - papermc https://repo.papermc.io/repository/maven-public/ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml index 7018e9236..9161e5d36 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/pom.xml @@ -49,10 +49,6 @@ https://repo.codemc.io/repository/nms/ default - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - papermc https://repo.papermc.io/repository/maven-public/ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml index 793d14064..38ba8803a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/pom.xml @@ -49,10 +49,6 @@ https://repo.codemc.io/repository/nms/ default - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - papermc https://repo.papermc.io/repository/maven-public/ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml index 34fc3da89..48a34ab0b 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/pom.xml @@ -49,10 +49,6 @@ https://repo.codemc.io/repository/nms/ default - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - papermc https://repo.papermc.io/repository/maven-public/ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml index 106ca5b13..2be28dd4a 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/pom.xml @@ -49,10 +49,6 @@ https://repo.codemc.io/repository/nms/ default - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - papermc https://repo.papermc.io/repository/maven-public/ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml index 7b78e5c28..f143e9218 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml @@ -43,10 +43,6 @@ https://repo.codemc.io/repository/nms/ default - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - papermc https://repo.papermc.io/repository/maven-public/ diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/pom.xml index 6953e2b7d..9fd926cf5 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/pom.xml @@ -44,10 +44,6 @@ https://repo.codemc.io/repository/nms/ default - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - papermc https://repo.papermc.io/repository/maven-public/ diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml index 08273b5d5..ddfb7016c 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-annotations/pom.xml @@ -14,8 +14,8 @@ - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + codemc-repo + https://repo.codemc.io/repository/nms/ diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml index adeee6450..8d0b55369 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-core/pom.xml @@ -17,14 +17,9 @@ minecraft-libraries https://libraries.minecraft.net - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - codemc-repo - https://repo.codemc.org/repository/maven-public/ - default + https://repo.codemc.io/repository/nms/ diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml index b95e921be..00d004b19 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.2/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml index 9c0343db7..873a71d77 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.3/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml index 3dc39e8c1..d261d0713 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20.5/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml index 3d91f2bfa..10ef89d2f 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.20/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml index a638abd38..3516875a2 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.2/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml index 2a1df93f1..054bae9f5 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.4/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml index b2469b42c..981a01bdb 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.5/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml index f9f8439ed..a8e6ab71b 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.6/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml index dd4f95b2e..2c3821998 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21.9/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml index 09c41ae9e..56dadcc76 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-nms/commandapi-spigot-1.21/pom.xml @@ -25,10 +25,6 @@ codemc-repo https://repo.codemc.io/repository/nms/ - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml index 6a3380676..3e5df523f 100644 --- a/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml +++ b/commandapi-platforms/commandapi-spigot/commandapi-spigot-plugin/pom.xml @@ -18,10 +18,6 @@ https://repo.codemc.org/repository/maven-public/ default - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - diff --git a/commandapi-testing/commandapi-testing-spigot/pom.xml b/commandapi-testing/commandapi-testing-spigot/pom.xml index b2a369c68..3a7a007cb 100644 --- a/commandapi-testing/commandapi-testing-spigot/pom.xml +++ b/commandapi-testing/commandapi-testing-spigot/pom.xml @@ -14,8 +14,8 @@ - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + codemc-repo + https://repo.codemc.io/repository/nms/ minecraft-libraries From 46fa33c3bff250af43cd17b7daa4c2238a033500 Mon Sep 17 00:00:00 2001 From: Jorel Ali Date: Sat, 4 Oct 2025 14:40:45 +0100 Subject: [PATCH 59/63] Tweak some paper common versions --- .../commandapi-bukkit-nms-common/pom.xml | 2 +- .../commandapi-bukkit-test-impl/pom.xml | 2 +- .../commandapi-paper/commandapi-paper-core/pom.xml | 14 ++++++++------ pom.xml | 3 ++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml index 4b3b4980f..ef02dab00 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-nms-common/pom.xml @@ -66,7 +66,7 @@ io.papermc.paper paper-api - ${paper.version.common} + ${paper.version.bukkit.common} provided diff --git a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml index f143e9218..a854ca5c7 100644 --- a/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml +++ b/commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/pom.xml @@ -68,7 +68,7 @@ io.papermc.paper paper-api - ${paper.version.common} + ${paper.version.bukkit.common} provided diff --git a/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml index 3b29dccc6..146b88986 100644 --- a/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml +++ b/commandapi-platforms/commandapi-paper/commandapi-paper-core/pom.xml @@ -29,6 +29,14 @@ + + + io.papermc.paper + paper-api + ${paper.version.common} + provided + dev.jorel commandapi-bukkit-core @@ -46,12 +54,6 @@ ${folia.version.common} provided - - io.papermc.paper - paper-api - ${paper.version.common} - provided - com.mojang brigadier diff --git a/pom.xml b/pom.xml index 1dc4e7a8e..f0c31d917 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,8 @@ 1.20.1-R0.1-20230921.165347-11 1.20.1-R0.1-20230921.165251-11 1.20.1-R0.1-20230911.182805-18 - 1.20.1-R0.1-20230921.165944-178 + 1.20.1-R0.1-20230921.165944-178 + 1.20.6-R0.1-20241030.191541-127 3.3.0-20240916.013244-136