Fix Github actions & unit tests (#3244)

* chore: update github actions

* test: fix initialization

* test: add missing imports for test initialization
This commit is contained in:
Maurice Eisenblätter 2024-09-23 02:00:57 +02:00 committed by GitHub
parent fb085676a9
commit 7338183ed6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 8 deletions

View File

@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
@ -22,7 +22,7 @@ jobs:
run: ./gradlew build shadowJar --no-daemon
- name: Upload plugin file
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ProtocolLib
path: build/libs/ProtocolLib.jar

View File

@ -20,17 +20,17 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'gradle'
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: 'java'
@ -38,4 +38,4 @@ jobs:
run: ./gradlew build -x test --no-daemon
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3

View File

@ -1,8 +1,11 @@
package com.comphenix.protocol;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import com.comphenix.protocol.reflect.accessors.Accessors;
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
@ -41,6 +44,7 @@ import org.apache.logging.log4j.LogManager;
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_21_R1.CraftLootTable;
import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry;
@ -162,7 +166,14 @@ public class BukkitInitialization {
});
when(mockedServer.getRegistry(any())).thenAnswer(invocation -> {
Class<Keyed> registryType = invocation.getArgument(0);
return CraftRegistry.createRegistry(registryType, registryCustom);
Object registry = CraftRegistry.createRegistry(registryType, registryCustom);
// this is very temporary fix to the version mismatch between spigot-api (spigot-repo) and spigot (dmulloy2-repo)
// if you remove this fix please also remove the DummyRegistry class down below
if (registry == null)
return new DummyRegistry<>();
return registry;
});
when(mockedServer.getTag(any(), any(), any())).then(mock -> {
@ -250,4 +261,23 @@ public class BukkitInitialization {
MinecraftReflectionTestUtil.init();
}
}
class DummyRegistry<T extends Keyed> implements Registry<T> {
@Override
public Iterator<T> iterator() {
return Collections.emptyIterator();
}
@Override
public T get(NamespacedKey key) {
return null;
}
@Override
public Stream<T> stream() {
List<T> emtpy = Collections.emptyList();
return emtpy.stream();
}
}
}