Skip to content

Commit 7338183

Browse files
authored
Fix Github actions & unit tests (#3244)
* chore: update github actions * test: fix initialization * test: add missing imports for test initialization
1 parent fb08567 commit 7338183

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout repository
12-
uses: actions/checkout@v3
12+
uses: actions/checkout@v4
1313

1414
- name: Setup java
15-
uses: actions/setup-java@v3
15+
uses: actions/setup-java@v4
1616
with:
1717
distribution: 'temurin'
1818
java-version: '21'
@@ -22,7 +22,7 @@ jobs:
2222
run: ./gradlew build shadowJar --no-daemon
2323

2424
- name: Upload plugin file
25-
uses: actions/upload-artifact@v2
25+
uses: actions/upload-artifact@v4
2626
with:
2727
name: ProtocolLib
2828
path: build/libs/ProtocolLib.jar

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ jobs:
2020

2121
steps:
2222
- name: Checkout repository
23-
uses: actions/checkout@v3
23+
uses: actions/checkout@v4
2424

2525
- name: Setup java
26-
uses: actions/setup-java@v3
26+
uses: actions/setup-java@v4
2727
with:
2828
distribution: 'temurin'
2929
java-version: '21'
3030
cache: 'gradle'
3131

3232
- name: Initialize CodeQL
33-
uses: github/codeql-action/init@v2
33+
uses: github/codeql-action/init@v3
3434
with:
3535
languages: 'java'
3636

3737
- name: Run gradle build lifecycle
3838
run: ./gradlew build -x test --no-daemon
3939

4040
- name: Perform CodeQL Analysis
41-
uses: github/codeql-action/analyze@v2
41+
uses: github/codeql-action/analyze@v3

src/test/java/com/comphenix/protocol/BukkitInitialization.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.comphenix.protocol;
22

33
import java.util.Collections;
4+
import java.util.Iterator;
45
import java.util.List;
56
import java.util.stream.Collectors;
7+
import java.util.stream.Stream;
8+
import java.util.stream.StreamSupport;
69

710
import com.comphenix.protocol.reflect.accessors.Accessors;
811
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
@@ -41,6 +44,7 @@
4144
import org.bukkit.Bukkit;
4245
import org.bukkit.Keyed;
4346
import org.bukkit.NamespacedKey;
47+
import org.bukkit.Registry;
4448
import org.bukkit.World;
4549
import org.bukkit.craftbukkit.v1_21_R1.CraftLootTable;
4650
import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry;
@@ -162,7 +166,14 @@ private void initialize() {
162166
});
163167
when(mockedServer.getRegistry(any())).thenAnswer(invocation -> {
164168
Class<Keyed> registryType = invocation.getArgument(0);
165-
return CraftRegistry.createRegistry(registryType, registryCustom);
169+
Object registry = CraftRegistry.createRegistry(registryType, registryCustom);
170+
171+
// this is very temporary fix to the version mismatch between spigot-api (spigot-repo) and spigot (dmulloy2-repo)
172+
// if you remove this fix please also remove the DummyRegistry class down below
173+
if (registry == null)
174+
return new DummyRegistry<>();
175+
176+
return registry;
166177
});
167178

168179
when(mockedServer.getTag(any(), any(), any())).then(mock -> {
@@ -250,4 +261,23 @@ private void setPackage() {
250261
MinecraftReflectionTestUtil.init();
251262
}
252263
}
264+
265+
class DummyRegistry<T extends Keyed> implements Registry<T> {
266+
267+
@Override
268+
public Iterator<T> iterator() {
269+
return Collections.emptyIterator();
270+
}
271+
272+
@Override
273+
public T get(NamespacedKey key) {
274+
return null;
275+
}
276+
277+
@Override
278+
public Stream<T> stream() {
279+
List<T> emtpy = Collections.emptyList();
280+
return emtpy.stream();
281+
}
282+
}
253283
}

0 commit comments

Comments
 (0)