Skip to content

Commit d8c799c

Browse files
Paper 26.1 Support (#8522)
1 parent 7b526a9 commit d8c799c

File tree

9 files changed

+152
-25
lines changed

9 files changed

+152
-25
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Java 25 CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'dev/**'
8+
pull_request:
9+
10+
jobs:
11+
prepare:
12+
name: Parallelize Tests
13+
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
14+
uses: ./.github/workflows/parallelize-tests.yml
15+
with:
16+
environments: 26.1.1
17+
java_version: 25
18+
parallel_jobs: 3
19+
20+
build:
21+
name: ${{ matrix.display }}
22+
needs: prepare
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
26+
steps:
27+
- uses: actions/checkout@v6
28+
with:
29+
submodules: recursive
30+
- name: validate gradle wrapper
31+
uses: gradle/actions/wrapper-validation@v6
32+
- name: Set up JDK 25
33+
uses: actions/setup-java@v5
34+
with:
35+
java-version: '25'
36+
distribution: 'adopt'
37+
cache: gradle
38+
- name: Grant execute permission for gradlew
39+
run: chmod +x gradlew
40+
- name: Build Skript and run test scripts
41+
run: ./gradlew clean customTest -PtestEnvs="${{ matrix.envs }}" -PtestEnvJavaVersion=25
42+
- name: Upload Nightly Build
43+
uses: actions/upload-artifact@v6
44+
if: success() && matrix.id == 1
45+
with:
46+
name: skript-nightly
47+
path: build/libs/*
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: JUnit 25
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'dev/**'
8+
pull_request:
9+
10+
jobs:
11+
prepare:
12+
name: Parallelize Tests
13+
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
14+
uses: ./.github/workflows/parallelize-tests.yml
15+
with:
16+
environments: 26.1.1
17+
java_version: 25
18+
parallel_jobs: 3
19+
20+
build:
21+
name: ${{ matrix.display }}
22+
needs: prepare
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
26+
steps:
27+
- uses: actions/checkout@v6
28+
with:
29+
submodules: recursive
30+
- name: validate gradle wrapper
31+
uses: gradle/actions/wrapper-validation@v6
32+
- name: Set up JDK 25
33+
uses: actions/setup-java@v5
34+
with:
35+
java-version: '25'
36+
distribution: 'adopt'
37+
cache: gradle
38+
- name: Grant execute permission for gradlew
39+
run: chmod +x gradlew
40+
- name: Build Skript and run test scripts
41+
run: ./gradlew clean customTest -PtestEnvs="${{ matrix.envs }}" -PtestEnvJavaVersion=25 -Pjunit=true

build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies {
2828
shadow group: 'io.papermc', name: 'paperlib', version: '1.0.8'
2929
shadow group: 'org.bstats', name: 'bstats-bukkit', version: '3.1.0'
3030

31-
implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.21.11-R0.1-SNAPSHOT'
31+
implementation group: 'io.papermc.paper', name: 'paper-api', version: '26.1.1.build.+'
3232
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'
3333

3434
// bundled with Minecraft 1.19.4+ for display entity transforms
@@ -246,18 +246,21 @@ void createTestTask(String name, String desc, String environments, int javaVersi
246246
}
247247

248248
def java21 = 21
249+
def java25 = 25
249250

250251
def env = project.testEnv + ".json"
251-
def latestJava = java21
252+
def latestJava = java25
252253
def oldestJava = java21
253254

254255
def latestJUnitEnv = env
255256
def latestJUnitJava = latestJava
256257

257258
java {
258259
toolchain.languageVersion.set(JavaLanguageVersion.of(latestJava))
259-
sourceCompatibility = oldestJava
260-
targetCompatibility = oldestJava
260+
}
261+
262+
tasks.withType(JavaCompile).configureEach {
263+
options.compilerArgs += ['-source', '' + oldestJava, '-target', '' + oldestJava]
261264
}
262265

263266
compileJava.options.encoding = 'UTF-8'
@@ -268,6 +271,7 @@ String environments = 'src/test/skript/environments/';
268271
int envJava = project.property('testEnvJavaVersion') == null ? latestJava : Integer.parseInt(project.property('testEnvJavaVersion') as String)
269272
createTestTask('quickTest', 'Runs tests on one environment being the latest supported Java and Minecraft.', environments + env, latestJava, 0)
270273
createTestTask('skriptTestJava21', 'Runs tests on all Java 21 environments.', environments + 'java21', java21, 0)
274+
createTestTask('skriptTestJava25', 'Runs tests on all Java 25 environments.', environments + 'java25', java25, 0)
271275
createTestTask('skriptTestDev', 'Runs testing server and uses \'system.in\' for command input, stop server to finish.', environments + env, envJava, 0, Modifiers.DEV_MODE, Modifiers.DEBUG)
272276
createTestTask('skriptProfile', 'Starts the testing server with JProfiler support.', environments + env, latestJava, -1, Modifiers.PROFILE)
273277
createTestTask('genNightlyDocs', 'Generates the Skript documentation website html files.', environments + env, envJava, 0, Modifiers.GEN_NIGHTLY_DOCS)
@@ -279,6 +283,7 @@ tasks.register('skriptTest') {
279283

280284
createTestTask('JUnitQuick', 'Runs JUnit tests on one environment being the latest supported Java and Minecraft.', environments + latestJUnitEnv, latestJUnitJava, 0, Modifiers.JUNIT)
281285
createTestTask('JUnitJava21', 'Runs JUnit tests on all Java 21 environments.', environments + 'java21', java21, 0, Modifiers.JUNIT)
286+
createTestTask('JUnitJava25', 'Runs JUnit tests on all Java 25 environments.', environments + 'java25', java25, 0, Modifiers.JUNIT)
282287
tasks.register('JUnit') {
283288
description = 'Runs JUnit tests on all environments.'
284289
dependsOn JUnitJava21

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ groupid=ch.njol
77
name=skript
88
version=2.15.0-pre1
99
jarName=Skript.jar
10-
testEnv=java21/paper-1.21.11
11-
testEnvJavaVersion=21
10+
testEnv=java25/paper-26.1.1
11+
testEnvJavaVersion=25

src/main/java/ch/njol/skript/aliases/Aliases.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import ch.njol.skript.Skript;
44
import ch.njol.skript.SkriptAddon;
55
import ch.njol.skript.SkriptConfig;
6+
import ch.njol.skript.bukkitutil.ItemUtils;
67
import ch.njol.skript.config.Config;
78
import ch.njol.skript.config.Node;
89
import ch.njol.skript.config.SectionNode;
@@ -18,6 +19,7 @@
1819
import org.bukkit.Material;
1920
import org.bukkit.NamespacedKey;
2021
import org.bukkit.Registry;
22+
import org.bukkit.inventory.ItemStack;
2123
import org.jetbrains.annotations.Nullable;
2224
import org.skriptlang.skript.lang.script.Script;
2325

@@ -34,7 +36,6 @@
3436
import java.util.regex.Pattern;
3537

3638
public abstract class Aliases {
37-
static final boolean USING_ITEM_COMPONENTS = Skript.isRunningMinecraft(1, 20, 5);
3839

3940
private static final AliasesProvider provider = createProvider(10000, null);
4041
private static final AliasesParser parser = createParser(provider);
@@ -400,6 +401,10 @@ public static void load() {
400401
* The returned value is true if the loading was successful, false otherwise.
401402
*/
402403
public static CompletableFuture<Boolean> loadAsync() {
404+
// Argument provider service will not load correctly if that load occurs from another thread
405+
// Make a call now to force it to load
406+
// See https://github.com/PaperMC/Paper/pull/12829
407+
ItemUtils.applyComponentData(ItemStack.empty(), "[]");
403408
return CompletableFuture.supplyAsync(() -> {
404409
try {
405410
long start = System.currentTimeMillis();

src/main/java/ch/njol/skript/aliases/AliasesParser.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,9 @@ protected Variation parseVariation(String item) {
201201
json = item.substring(firstBracket, jsonEndIndex + 1);
202202
id = id + item.substring(jsonEndIndex + 2); // essentially rips out json part
203203
}
204-
if (Aliases.USING_ITEM_COMPONENTS) {
205-
json = "[" + json.substring(1, json.length() - 1) + "]"; // replace brackets (not json :))
206-
tags = Collections.singletonMap("components", json);
207-
} else {
208-
tags = provider.parseMojangson(json);
209-
}
204+
// add component data
205+
json = "[" + json.substring(1, json.length() - 1) + "]"; // replace brackets (not json :))
206+
tags = Collections.singletonMap("components", json);
210207
}
211208

212209
// Separate block state from id

src/main/java/ch/njol/skript/aliases/AliasesProvider.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,10 @@ public int applyTags(ItemStack stack, Map<String, Object> tags) {
9595
return flags;
9696

9797
// Apply random tags using JSON
98-
if (Aliases.USING_ITEM_COMPONENTS) {
99-
String components = (String) tags.get("components"); // only components are supported for modifying a stack
100-
assert components != null;
101-
// for modifyItemStack to work, you have to include an item id ... e.g. "minecraft:dirt[<components>]"
102-
// just to be safe we use the same one as the provided stack
103-
components = stack.getType().getKey() + components;
104-
BukkitUnsafe.modifyItemStack(stack, components);
105-
} else {
106-
String json = gson.toJson(tags);
107-
assert json != null;
108-
BukkitUnsafe.modifyItemStack(stack, json);
109-
}
98+
String components = (String) tags.get("components"); // only components are supported for modifying a stack
99+
assert components != null;
100+
ItemUtils.applyComponentData(stack, components);
101+
110102
flags |= ItemFlags.CHANGED_TAGS;
111103

112104
return flags;

src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import ch.njol.skript.aliases.ItemType;
55
import ch.njol.skript.util.slot.Slot;
66
import com.destroystokyo.paper.profile.PlayerProfile;
7+
import com.mojang.brigadier.StringReader;
8+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
9+
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
710
import org.bukkit.Bukkit;
811
import org.bukkit.Material;
912
import org.bukkit.OfflinePlayer;
@@ -37,6 +40,26 @@ public class ItemUtils {
3740
// paper does not do texture lookups by default
3841
public static final boolean REQUIRES_TEXTURE_LOOKUP = Skript.classExists("com.destroystokyo.paper.profile.PlayerProfile") && Skript.isRunningMinecraft(1, 19, 4);
3942

43+
/**
44+
* Applies string format of component data to an item stack.
45+
* <b>Note: This overwrites the entire {@link ItemMeta} of the item.</b>
46+
* @param itemStack The item stack to apply data to.
47+
* @param data The data to apply.
48+
* This data is expected to be in the format used by the Brigadier item stack parser.
49+
* For example {@code [{minecraft:potion_contents={"potion":"minecraft:invisibility"}}]}
50+
*/
51+
public static void applyComponentData(ItemStack itemStack, String data) {
52+
// need to include item id: "minecraft:dirt[<components>]"
53+
// use the same one as the stack to be safe (likely needed for obtaining correct item meta)
54+
data = itemStack.getType().getKey() + data;
55+
try {
56+
ItemStack parsed = ArgumentTypes.itemStack().parse(new StringReader(data));
57+
itemStack.setItemMeta(parsed.getItemMeta());
58+
} catch (CommandSyntaxException e) {
59+
throw Skript.exception(e, "Failed to apply component data to ItemStack");
60+
}
61+
}
62+
4063
/**
4164
* Gets damage/durability of an item, or 0 if it does not have damage.
4265
* @param itemStack Item.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "paper-26.1.1",
3+
"resources": [
4+
{"source": "server.properties.generic", "target": "server.properties"}
5+
],
6+
"paperDownloads": [
7+
{
8+
"version": "26.1.1",
9+
"target": "paperclip.jar"
10+
}
11+
],
12+
"skriptTarget": "plugins/Skript.jar",
13+
"commandLine": [
14+
"-Dcom.mojang.eula.agree=true",
15+
"-jar", "paperclip.jar", "--nogui"
16+
]
17+
}

0 commit comments

Comments
 (0)