feat(leaf): support Purpur 26.3
This commit is contained in:
1 parent
a375da547b
commit
a9e58b7c25
5 files changed
+437
-8
No files matched your search
@@ -1,12 +1,12 @@
|
|||||||
# Purpur Leaf
|
# Purpur Leaf
|
||||||
|
|
||||||
Leaf is a Purpur 26.2 plugin that lets non-aggressive players opt into visible Resistance and Strength protection.
|
Leaf is a Purpur 26.3 plugin that lets non-aggressive players opt into visible Resistance and Strength protection.
|
||||||
|
|
||||||
The approved behavior is specified in the [SoMC OKF wiki](https://git.garvis.dev/dmg/somc-okf/src/branch/main/projects/purpur-leaf/index.md).
|
The approved behavior is specified in the [SoMC OKF wiki](https://git.garvis.dev/dmg/somc-okf/src/branch/main/projects/purpur-leaf/index.md).
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- Purpur 26.2 build 2618
|
- Purpur 26.3 build 2651
|
||||||
- Java 25
|
- Java 25
|
||||||
|
|
||||||
Distribution repository, checkout and artifacts use `purpur-leaf`. Runtime `Leaf`, Java packages/entrypoint, `plugins/Leaf/`, commands/permissions and `leaf_protected` scoreboard team are unchanged. Replace the old JAR instead of installing both distributions. Old release tags/assets remain available. New releases no longer support Java 17.
|
Distribution repository, checkout and artifacts use `purpur-leaf`. Runtime `Leaf`, Java packages/entrypoint, `plugins/Leaf/`, commands/permissions and `leaf_protected` scoreboard team are unchanged. Replace the old JAR instead of installing both distributions. Old release tags/assets remain available. New releases no longer support Java 17.
|
||||||
@@ -19,6 +19,15 @@ Distribution repository, checkout and artifacts use `purpur-leaf`. Runtime `Leaf
|
|||||||
|
|
||||||
The plugin JAR is written to `build/libs/purpur-leaf-<version>.jar`.
|
The plugin JAR is written to `build/libs/purpur-leaf-<version>.jar`.
|
||||||
|
|
||||||
|
`check` includes `nativeLifecycleTest`. It downloads the exact Purpur 26.3 build 2651 launcher,
|
||||||
|
verifies SHA-256
|
||||||
|
`0677c1febecfbc2e5b0a7f76abd647b70a1f38d3cbdf3dd6a82e401b4262a598`, and runs Paperclip in
|
||||||
|
patch-only mode under `build/native-runtime/`. The native boundary loads the packaged entrypoint
|
||||||
|
through Purpur's plugin classloader, enables it with controlled server, scheduler, player and
|
||||||
|
scoreboard ports, restores persisted protection, exercises command-backed YAML persistence, and
|
||||||
|
disables it while verifying owned presentation cleanup. It does not start a listening server, open a
|
||||||
|
port, create a world, or provide live-client/deployed-server evidence.
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
|||||||
+63
-2
@@ -1,3 +1,6 @@
|
|||||||
|
import java.net.URI
|
||||||
|
import java.security.MessageDigest
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
}
|
}
|
||||||
@@ -23,9 +26,9 @@ tasks.withType<JavaCompile>().configureEach {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("org.purpurmc.purpur:purpur-api:26.2.build.2618-stable")
|
compileOnly("org.purpurmc.purpur:purpur-api:26.3.build.2651-stable")
|
||||||
|
|
||||||
testImplementation("org.purpurmc.purpur:purpur-api:26.2.build.2618-stable")
|
testImplementation("org.purpurmc.purpur:purpur-api:26.3.build.2651-stable")
|
||||||
testImplementation(platform("org.junit:junit-bom:5.13.4"))
|
testImplementation(platform("org.junit:junit-bom:5.13.4"))
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||||
testImplementation("org.mockito:mockito-core:5.18.0")
|
testImplementation("org.mockito:mockito-core:5.18.0")
|
||||||
@@ -40,6 +43,64 @@ tasks.test {
|
|||||||
systemProperty("distribution.version", project.version.toString())
|
systemProperty("distribution.version", project.version.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Patch and load the exact supported server without starting a world or opening a port.
|
||||||
|
val nativeRuntime = layout.buildDirectory.dir("native-runtime")
|
||||||
|
val downloadNativeRuntime = tasks.register("downloadNativeRuntime") {
|
||||||
|
val launcher = nativeRuntime.map { it.file("purpur-26.3-2651.jar") }
|
||||||
|
outputs.file(launcher)
|
||||||
|
doLast {
|
||||||
|
val file = launcher.get().asFile
|
||||||
|
file.parentFile.mkdirs()
|
||||||
|
val connection = URI("https://api.purpurmc.org/v2/purpur/26.3/2651/download")
|
||||||
|
.toURL().openConnection()
|
||||||
|
connection.connectTimeout = 30_000
|
||||||
|
connection.readTimeout = 120_000
|
||||||
|
val bytes = connection.getInputStream().use { it.readBytes() }
|
||||||
|
val digest = MessageDigest.getInstance("SHA-256").digest(bytes)
|
||||||
|
.joinToString("") { "%02x".format(it) }
|
||||||
|
check(digest == "0677c1febecfbc2e5b0a7f76abd647b70a1f38d3cbdf3dd6a82e401b4262a598") {
|
||||||
|
"Purpur 2651 checksum mismatch"
|
||||||
|
}
|
||||||
|
file.writeBytes(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val prepareNativeRuntime = tasks.register<JavaExec>("prepareNativeRuntime") {
|
||||||
|
dependsOn(downloadNativeRuntime)
|
||||||
|
javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(25) }
|
||||||
|
classpath = files(nativeRuntime.map { it.file("purpur-26.3-2651.jar") })
|
||||||
|
mainClass = "io.papermc.paperclip.Main"
|
||||||
|
jvmArgs("-Dpaperclip.patchonly=true")
|
||||||
|
workingDir(nativeRuntime)
|
||||||
|
outputs.dir(nativeRuntime.map { it.dir("versions") })
|
||||||
|
outputs.dir(nativeRuntime.map { it.dir("libraries") })
|
||||||
|
}
|
||||||
|
val nativeTest = sourceSets.create("nativeTest")
|
||||||
|
dependencies {
|
||||||
|
add(nativeTest.implementationConfigurationName, platform("org.junit:junit-bom:5.13.4"))
|
||||||
|
add(nativeTest.implementationConfigurationName, "org.junit.jupiter:junit-jupiter")
|
||||||
|
add(nativeTest.implementationConfigurationName, "org.mockito:mockito-core:5.18.0")
|
||||||
|
add(nativeTest.compileOnlyConfigurationName, "org.jetbrains:annotations:26.0.2")
|
||||||
|
add(nativeTest.compileOnlyConfigurationName, "org.checkerframework:checker-qual:3.49.2")
|
||||||
|
add(nativeTest.runtimeOnlyConfigurationName, "org.junit.platform:junit-platform-launcher")
|
||||||
|
}
|
||||||
|
val nativeRuntimeJars = files(fileTree(nativeRuntime) {
|
||||||
|
include("versions/**/*.jar", "libraries/**/*.jar")
|
||||||
|
}).builtBy(prepareNativeRuntime)
|
||||||
|
nativeTest.compileClasspath += sourceSets.main.get().output + nativeRuntimeJars
|
||||||
|
nativeTest.runtimeClasspath += sourceSets.main.get().runtimeClasspath + nativeRuntimeJars
|
||||||
|
val nativeLifecycleTest = tasks.register<Test>("nativeLifecycleTest") {
|
||||||
|
description = "Loads, enables, and disables the packaged plugin on the pinned Purpur runtime"
|
||||||
|
dependsOn(tasks.jar)
|
||||||
|
testClassesDirs = nativeTest.output.classesDirs
|
||||||
|
classpath = nativeTest.runtimeClasspath
|
||||||
|
useJUnitPlatform()
|
||||||
|
maxHeapSize = "1G"
|
||||||
|
workingDir(nativeRuntime)
|
||||||
|
systemProperty("distribution.jar", tasks.jar.get().archiveFile.get().asFile.absolutePath)
|
||||||
|
systemProperty("distribution.version", project.version.toString())
|
||||||
|
}
|
||||||
|
tasks.check { dependsOn(nativeLifecycleTest) }
|
||||||
|
|
||||||
val pluginVersion = version
|
val pluginVersion = version
|
||||||
|
|
||||||
tasks.processResources {
|
tasks.processResources {
|
||||||
|
|||||||
@@ -0,0 +1,267 @@
|
|||||||
|
package games.dmg.leaf;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import io.papermc.paper.plugin.configuration.PluginMeta;
|
||||||
|
import io.papermc.paper.plugin.provider.classloader.ConfiguredPluginClassLoader;
|
||||||
|
import io.papermc.paper.plugin.provider.classloader.PluginClassLoaderGroup;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.bukkit.scoreboard.Scoreboard;
|
||||||
|
import org.bukkit.scoreboard.ScoreboardManager;
|
||||||
|
import org.bukkit.scoreboard.Team;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
|
/** Exercises the packaged entrypoint through Purpur's native JavaPlugin lifecycle. */
|
||||||
|
class LeafLifecycleNativeTest {
|
||||||
|
private static final UUID PLAYER_ID = UUID.fromString("781f7e76-fadd-4437-aa12-fd7853b1a4cc");
|
||||||
|
|
||||||
|
@TempDir Path temporaryDirectory;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void bootstrap() throws Exception {
|
||||||
|
NativeRuntime.bootstrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void packagedPluginLoadsEnablesRestoresStateAndDisablesConservatively() throws Exception {
|
||||||
|
Path dataDirectory = temporaryDirectory.resolve("Leaf");
|
||||||
|
Files.createDirectories(dataDirectory);
|
||||||
|
Path stateFile = dataDirectory.resolve("state.yml");
|
||||||
|
Files.writeString(stateFile, """
|
||||||
|
future-root: retained
|
||||||
|
players:
|
||||||
|
%s:
|
||||||
|
name: Alex
|
||||||
|
opted-in: true
|
||||||
|
locked: false
|
||||||
|
first-join: '2026-08-10T12:34:56Z'
|
||||||
|
known-names:
|
||||||
|
- Alex
|
||||||
|
future-player-field: retained
|
||||||
|
""".formatted(PLAYER_ID));
|
||||||
|
|
||||||
|
AtomicReference<String> displayName = new AtomicReference<>("Alex");
|
||||||
|
AtomicReference<String> playerListName = new AtomicReference<>("Alex");
|
||||||
|
Map<PotionEffectType, PotionEffect> effects = new HashMap<>();
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(PLAYER_ID);
|
||||||
|
when(player.getName()).thenReturn("Alex");
|
||||||
|
when(player.getDisplayName()).thenAnswer(call -> displayName.get());
|
||||||
|
doAnswer(call -> { displayName.set(call.getArgument(0)); return null; })
|
||||||
|
.when(player).setDisplayName(anyString());
|
||||||
|
when(player.getPlayerListName()).thenAnswer(call -> playerListName.get());
|
||||||
|
doAnswer(call -> { playerListName.set(call.getArgument(0)); return null; })
|
||||||
|
.when(player).setPlayerListName(anyString());
|
||||||
|
when(player.getPotionEffect(any())).thenAnswer(call -> effects.get(call.getArgument(0)));
|
||||||
|
when(player.addPotionEffect(any())).thenAnswer(call -> {
|
||||||
|
PotionEffect effect = call.getArgument(0);
|
||||||
|
effects.put(effect.getType(), effect);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
doAnswer(call -> { effects.remove(call.getArgument(0)); return null; })
|
||||||
|
.when(player).removePotionEffect(any());
|
||||||
|
|
||||||
|
Team team = mock(Team.class);
|
||||||
|
Set<String> teamEntries = new HashSet<>(Set.of("Other"));
|
||||||
|
AtomicReference<String> teamPrefix = new AtomicReference<>("");
|
||||||
|
doAnswer(call -> { teamPrefix.set(call.getArgument(0)); return null; })
|
||||||
|
.when(team).setPrefix(anyString());
|
||||||
|
doAnswer(call -> { teamEntries.add(call.getArgument(0)); return null; })
|
||||||
|
.when(team).addEntry(anyString());
|
||||||
|
doAnswer(call -> { teamEntries.remove(call.getArgument(0)); return null; })
|
||||||
|
.when(team).removeEntry(anyString());
|
||||||
|
Scoreboard scoreboard = mock(Scoreboard.class);
|
||||||
|
AtomicBoolean teamCreated = new AtomicBoolean();
|
||||||
|
when(scoreboard.getEntryTeam(anyString())).thenAnswer(call ->
|
||||||
|
teamEntries.contains(call.getArgument(0)) && teamCreated.get() ? team : null);
|
||||||
|
when(scoreboard.getTeam("leaf_protected")).thenAnswer(call -> teamCreated.get() ? team : null);
|
||||||
|
when(scoreboard.registerNewTeam("leaf_protected")).thenAnswer(call -> {
|
||||||
|
teamCreated.set(true);
|
||||||
|
return team;
|
||||||
|
});
|
||||||
|
ScoreboardManager scoreboards = mock(ScoreboardManager.class);
|
||||||
|
when(scoreboards.getMainScoreboard()).thenReturn(scoreboard);
|
||||||
|
|
||||||
|
List<Class<?>> listeners = new ArrayList<>();
|
||||||
|
PluginManager manager = mock(PluginManager.class);
|
||||||
|
doAnswer(call -> { listeners.add(((Listener) call.getArgument(0)).getClass()); return null; })
|
||||||
|
.when(manager).registerEvents(any(Listener.class), any(Plugin.class));
|
||||||
|
doAnswer(call -> { throw new AssertionError("Native lifecycle initialization failed"); })
|
||||||
|
.when(manager).disablePlugin(any(Plugin.class));
|
||||||
|
record Scheduled(String type, long delay, long period) { }
|
||||||
|
List<Scheduled> scheduled = new ArrayList<>();
|
||||||
|
BukkitScheduler scheduler = mock(BukkitScheduler.class);
|
||||||
|
when(scheduler.runTaskTimer(any(Plugin.class), any(Runnable.class), anyLong(), anyLong()))
|
||||||
|
.thenAnswer(call -> {
|
||||||
|
scheduled.add(new Scheduled(call.getArgument(1).getClass().getSimpleName(),
|
||||||
|
call.getArgument(2), call.getArgument(3)));
|
||||||
|
return mock(BukkitTask.class);
|
||||||
|
});
|
||||||
|
|
||||||
|
AtomicReference<PluginCommand> command = new AtomicReference<>();
|
||||||
|
Server server = mock(Server.class);
|
||||||
|
when(server.getPluginManager()).thenReturn(manager);
|
||||||
|
when(server.getScheduler()).thenReturn(scheduler);
|
||||||
|
when(server.getPluginCommand("leaf")).thenAnswer(call -> command.get());
|
||||||
|
doReturn(List.of(player)).when(server).getOnlinePlayers();
|
||||||
|
when(server.getPlayer(PLAYER_ID)).thenReturn(player);
|
||||||
|
when(server.getScoreboardManager()).thenReturn(scoreboards);
|
||||||
|
when(server.getLogger()).thenReturn(Logger.getLogger("Leaf lifecycle fixture"));
|
||||||
|
when(server.getWarningState()).thenReturn(org.bukkit.Warning.WarningState.DEFAULT);
|
||||||
|
when(server.getName()).thenReturn("Purpur");
|
||||||
|
when(server.getVersion()).thenReturn("Purpur 2651 (MC: 26.3)");
|
||||||
|
when(server.getMinecraftVersion()).thenReturn("26.3");
|
||||||
|
when(server.getBukkitVersion()).thenReturn("26.3-R0.1-SNAPSHOT");
|
||||||
|
when(server.isPrimaryThread()).thenReturn(true);
|
||||||
|
|
||||||
|
try (var loader = new Loader(server, dataDirectory)) {
|
||||||
|
JavaPlugin plugin = (JavaPlugin) loader.loadClass("games.dmg.leaf.LeafPlugin")
|
||||||
|
.getConstructor().newInstance();
|
||||||
|
var constructor = PluginCommand.class.getDeclaredConstructor(
|
||||||
|
String.class, org.bukkit.plugin.Plugin.class);
|
||||||
|
constructor.setAccessible(true);
|
||||||
|
command.set(constructor.newInstance("leaf", plugin));
|
||||||
|
|
||||||
|
assertEquals("Leaf", plugin.getName());
|
||||||
|
assertEquals("games.dmg.leaf.LeafPlugin", loader.getConfiguration().getMainClass());
|
||||||
|
assertEquals("1.20", loader.getConfiguration().getAPIVersion());
|
||||||
|
assertEquals(Set.of("leaf"), loader.description.getCommands().keySet());
|
||||||
|
assertEquals(Set.of("leaf.use", "leaf.admin"), loader.description.getPermissions().stream()
|
||||||
|
.map(permission -> permission.getName()).collect(java.util.stream.Collectors.toSet()));
|
||||||
|
assertTrue(loader.description.getDepend().isEmpty());
|
||||||
|
assertEquals(dataDirectory.toFile(), plugin.getDataFolder());
|
||||||
|
assertFalse(plugin.isEnabled());
|
||||||
|
|
||||||
|
plugin.setEnabled(true);
|
||||||
|
try {
|
||||||
|
assertTrue(plugin.isEnabled());
|
||||||
|
assertTrue(Files.isRegularFile(dataDirectory.resolve("config.yml")));
|
||||||
|
assertEquals(List.of("LeafListener"), listeners.stream()
|
||||||
|
.map(Class::getSimpleName).toList());
|
||||||
|
assertEquals(2, scheduled.size());
|
||||||
|
assertEquals(new Scheduled("LeafRecoveryTask", 20L, 20L), scheduled.get(0));
|
||||||
|
assertEquals(600L, scheduled.get(1).delay());
|
||||||
|
assertEquals(600L, scheduled.get(1).period());
|
||||||
|
assertEquals("LeafCommand", command.get().getExecutor().getClass().getSimpleName());
|
||||||
|
assertSame(command.get().getExecutor(), command.get().getTabCompleter());
|
||||||
|
|
||||||
|
assertEquals(Set.of(PotionEffectType.RESISTANCE, PotionEffectType.STRENGTH), effects.keySet());
|
||||||
|
assertTrue(effects.values().stream().allMatch(effect ->
|
||||||
|
effect.getDuration() == PotionEffect.INFINITE_DURATION && effect.getAmplifier() == 0));
|
||||||
|
assertEquals("§a🍃 Alex", displayName.get());
|
||||||
|
assertEquals("§a🍃 Alex", playerListName.get());
|
||||||
|
assertTrue(teamCreated.get());
|
||||||
|
assertEquals("§a🍃 ", teamPrefix.get());
|
||||||
|
assertEquals(Set.of("Alex", "Other"), teamEntries);
|
||||||
|
|
||||||
|
CommandSender administrator = mock(CommandSender.class);
|
||||||
|
when(administrator.hasPermission("leaf.admin")).thenReturn(true);
|
||||||
|
assertTrue(command.get().execute(administrator, "leaf", new String[] {
|
||||||
|
"player", PLAYER_ID.toString(), "locked", "on"
|
||||||
|
}));
|
||||||
|
YamlConfiguration saved = YamlConfiguration.loadConfiguration(stateFile.toFile());
|
||||||
|
String playerPath = "players." + PLAYER_ID;
|
||||||
|
assertTrue(saved.getBoolean(playerPath + ".opted-in"));
|
||||||
|
assertTrue(saved.getBoolean(playerPath + ".locked"));
|
||||||
|
assertEquals("2026-08-10T12:34:56Z", saved.getString(playerPath + ".first-join"));
|
||||||
|
assertEquals("retained", saved.getString("future-root"));
|
||||||
|
assertEquals("retained", saved.getString(playerPath + ".future-player-field"));
|
||||||
|
} finally {
|
||||||
|
plugin.setEnabled(false);
|
||||||
|
}
|
||||||
|
assertFalse(plugin.isEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(effects.isEmpty());
|
||||||
|
assertEquals("Alex", displayName.get());
|
||||||
|
assertEquals("Alex", playerListName.get());
|
||||||
|
assertEquals(Set.of("Other"), teamEntries);
|
||||||
|
assertTrue(teamCreated.get(), "Disable preserves the owned scoreboard team itself");
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class Loader extends URLClassLoader implements ConfiguredPluginClassLoader {
|
||||||
|
private static final String PACKAGE = "games.dmg.leaf.";
|
||||||
|
private final Server server;
|
||||||
|
private final Path dataDirectory;
|
||||||
|
private final Path jar = Path.of(System.getProperty("distribution.jar"));
|
||||||
|
private final PluginDescriptionFile description;
|
||||||
|
private JavaPlugin plugin;
|
||||||
|
|
||||||
|
Loader(Server server, Path dataDirectory) throws Exception {
|
||||||
|
super(new URL[] {Path.of(System.getProperty("distribution.jar")).toUri().toURL()},
|
||||||
|
LeafLifecycleNativeTest.class.getClassLoader());
|
||||||
|
this.server = server;
|
||||||
|
this.dataDirectory = dataDirectory;
|
||||||
|
try (var archive = new JarFile(jar.toFile());
|
||||||
|
var input = archive.getInputStream(archive.getJarEntry("plugin.yml"))) {
|
||||||
|
description = new PluginDescriptionFile(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||||
|
synchronized (getClassLoadingLock(name)) {
|
||||||
|
if (!name.startsWith(PACKAGE) || name.equals(getClass().getName())) {
|
||||||
|
return super.loadClass(name, resolve);
|
||||||
|
}
|
||||||
|
Class<?> loaded = findLoadedClass(name);
|
||||||
|
if (loaded == null) {
|
||||||
|
loaded = findClass(name);
|
||||||
|
}
|
||||||
|
if (resolve) {
|
||||||
|
resolveClass(loaded);
|
||||||
|
}
|
||||||
|
return loaded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> loadClass(String name, boolean resolve, boolean global, boolean libraries)
|
||||||
|
throws ClassNotFoundException {
|
||||||
|
return loadClass(name, resolve);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public PluginMeta getConfiguration() { return description; }
|
||||||
|
@Override public JavaPlugin getPlugin() { return plugin; }
|
||||||
|
@Override public PluginClassLoaderGroup getGroup() { return null; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(JavaPlugin created) {
|
||||||
|
plugin = created;
|
||||||
|
created.init(server, description, dataDirectory.toFile(), jar.toFile(), this, description,
|
||||||
|
Logger.getLogger("Leaf lifecycle fixture"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package games.dmg.leaf;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import net.minecraft.SharedConstants;
|
||||||
|
import net.minecraft.commands.Commands;
|
||||||
|
import net.minecraft.core.HolderLookup;
|
||||||
|
import net.minecraft.core.LayeredRegistryAccess;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
|
import net.minecraft.resources.RegistryDataLoader;
|
||||||
|
import net.minecraft.server.Bootstrap;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.RegistryLayer;
|
||||||
|
import net.minecraft.server.ReloadableServerResources;
|
||||||
|
import net.minecraft.server.packs.PackType;
|
||||||
|
import net.minecraft.server.packs.repository.ServerPacksSource;
|
||||||
|
import net.minecraft.server.packs.resources.MultiPackResourceManager;
|
||||||
|
import net.minecraft.server.permissions.LevelBasedPermissionSet;
|
||||||
|
import net.minecraft.tags.TagLoader;
|
||||||
|
import net.minecraft.util.Util;
|
||||||
|
import net.minecraft.world.flag.FeatureFlags;
|
||||||
|
import net.minecraft.world.level.DataPackConfig;
|
||||||
|
import net.minecraft.world.level.WorldDataConfiguration;
|
||||||
|
import org.bukkit.craftbukkit.CraftRegistry;
|
||||||
|
|
||||||
|
/** Loads the exact Purpur runtime registries needed by the packaged lifecycle fixture. */
|
||||||
|
final class NativeRuntime {
|
||||||
|
private static boolean bootstrapped;
|
||||||
|
|
||||||
|
private NativeRuntime() { }
|
||||||
|
|
||||||
|
static synchronized void bootstrap() throws Exception {
|
||||||
|
if (bootstrapped) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SharedConstants.tryDetectVersion();
|
||||||
|
Bootstrap.bootStrap();
|
||||||
|
var flags = FeatureFlags.VANILLA_SET;
|
||||||
|
var packs = ServerPacksSource.createVanillaTrustedRepository();
|
||||||
|
MinecraftServer.configurePackRepository(packs, new WorldDataConfiguration(new DataPackConfig(
|
||||||
|
FeatureFlags.REGISTRY.toNames(flags).stream().map(Identifier::getPath).toList(),
|
||||||
|
List.of()), flags), true, false);
|
||||||
|
try (var resources = new MultiPackResourceManager(PackType.SERVER_DATA, packs.openAllSelected())) {
|
||||||
|
LayeredRegistryAccess<RegistryLayer> layers = RegistryLayer.createRegistryAccess();
|
||||||
|
List<Registry.PendingTags<?>> tags = TagLoader.loadTagsForExistingRegistries(
|
||||||
|
resources, layers.getLayer(RegistryLayer.STATIC));
|
||||||
|
List<HolderLookup.RegistryLookup<?>> lookups = TagLoader.buildUpdatedLookups(
|
||||||
|
layers.getAccessForLoading(RegistryLayer.WORLD), tags);
|
||||||
|
RegistryAccess.Frozen world = RegistryDataLoader.load(resources, lookups,
|
||||||
|
RegistryDataLoader.WORLD_REGISTRIES, Util.backgroundExecutor()).join();
|
||||||
|
layers = layers.replaceFrom(RegistryLayer.WORLD, world);
|
||||||
|
RegistryAccess.Frozen dimensions = RegistryDataLoader.load(resources,
|
||||||
|
Stream.concat(lookups.stream(), world.listRegistries()).toList(),
|
||||||
|
RegistryDataLoader.DIMENSION_REGISTRIES, Util.backgroundExecutor()).join();
|
||||||
|
layers = layers.replaceFrom(RegistryLayer.DIMENSIONS, dimensions);
|
||||||
|
Class.forName(org.bukkit.Registry.class.getName());
|
||||||
|
var datapack = ReloadableServerResources.loadResources(resources, layers, tags, flags,
|
||||||
|
Commands.CommandSelection.DEDICATED, LevelBasedPermissionSet.ALL_PERMISSIONS,
|
||||||
|
Util.backgroundExecutor(), Runnable::run).join();
|
||||||
|
datapack.updateComponentsAndStaticRegistryTags();
|
||||||
|
CraftRegistry.setMinecraftRegistry(layers.compositeAccess().freeze());
|
||||||
|
datapack.getRecipeManager().finalizeRecipeLoading(flags);
|
||||||
|
}
|
||||||
|
bootstrapped = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import java.io.DataInputStream;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
@@ -21,9 +22,21 @@ class PurpurDistributionTest {
|
|||||||
assertEquals(version, metadata.get("version"));
|
assertEquals(version, metadata.get("version"));
|
||||||
assertEquals("Leaf", metadata.get("name"), "Retain the data directory and persistent namespace");
|
assertEquals("Leaf", metadata.get("name"), "Retain the data directory and persistent namespace");
|
||||||
assertEquals("games.dmg.leaf.LeafPlugin", metadata.get("main"));
|
assertEquals("games.dmg.leaf.LeafPlugin", metadata.get("main"));
|
||||||
assertTrue(((Map<?, ?>) metadata.get("permissions")).containsKey("leaf.admin"));
|
assertEquals("1.20", metadata.get("api-version"));
|
||||||
|
assertEquals(Set.of("leaf"), ((Map<?, ?>) metadata.get("commands")).keySet());
|
||||||
|
Map<?, ?> permissions = (Map<?, ?>) metadata.get("permissions");
|
||||||
|
assertEquals(Set.of("leaf.use", "leaf.admin"), permissions.keySet());
|
||||||
|
assertEquals(true, ((Map<?, ?>) permissions.get("leaf.use")).get("default"));
|
||||||
|
assertEquals("op", ((Map<?, ?>) permissions.get("leaf.admin")).get("default"));
|
||||||
|
assertNull(metadata.get("depend"));
|
||||||
assertFalse(jar.stream().anyMatch(entry -> entry.getName().startsWith("org/bukkit/")
|
assertFalse(jar.stream().anyMatch(entry -> entry.getName().startsWith("org/bukkit/")
|
||||||
|| entry.getName().startsWith("org/purpurmc/") || entry.getName().endsWith("Test.class")));
|
|| entry.getName().startsWith("org/purpurmc/")
|
||||||
|
|| entry.getName().startsWith("io/papermc/")
|
||||||
|
|| entry.getName().startsWith("org/spigotmc/")
|
||||||
|
|| entry.getName().startsWith("net/minecraft/")
|
||||||
|
|| entry.getName().startsWith("com/comphenix/")
|
||||||
|
|| entry.getName().endsWith("Test.class")
|
||||||
|
|| entry.getName().contains("NativeRuntime")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,10 +52,21 @@ class PurpurDistributionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void releaseAndCiAgreeWithThePurpurDistributionNameAndToolchain() throws Exception {
|
void releaseAndCiAgreeWithTheExactPurpurRuntimeAndToolchain() throws Exception {
|
||||||
String build = Files.readString(Path.of("build.gradle.kts"));
|
String build = Files.readString(Path.of("build.gradle.kts"));
|
||||||
assertTrue(build.contains("purpur-api:26.2.build.2618-stable"));
|
assertTrue(build.contains("purpur-api:26.3.build.2651-stable"));
|
||||||
|
assertTrue(build.contains("purpur-26.3-2651.jar"));
|
||||||
|
assertTrue(build.contains("https://api.purpurmc.org/v2/purpur/26.3/2651/download"));
|
||||||
|
assertTrue(build.contains("0677c1febecfbc2e5b0a7f76abd647b70a1f38d3cbdf3dd6a82e401b4262a598"));
|
||||||
|
assertFalse(build.contains("26.2") || build.contains("2618"));
|
||||||
assertFalse(build.contains("org.spigotmc:spigot-api"));
|
assertFalse(build.contains("org.spigotmc:spigot-api"));
|
||||||
|
assertTrue(build.contains("nativeLifecycleTest"));
|
||||||
|
assertTrue(build.contains("tasks.check { dependsOn(nativeLifecycleTest) }"));
|
||||||
|
String readme = Files.readString(Path.of("README.md"));
|
||||||
|
assertTrue(readme.contains("Purpur 26.3 build 2651"));
|
||||||
|
assertTrue(readme.contains("nativeLifecycleTest"));
|
||||||
|
assertTrue(readme.contains("0677c1febecfbc2e5b0a7f76abd647b70a1f38d3cbdf3dd6a82e401b4262a598"));
|
||||||
|
assertFalse(readme.contains("26.2") || readme.contains("2618"));
|
||||||
for (String workflow : new String[] {"ci.yml", "release.yml"}) {
|
for (String workflow : new String[] {"ci.yml", "release.yml"}) {
|
||||||
String content = Files.readString(Path.of(".gitea/workflows", workflow));
|
String content = Files.readString(Path.of(".gitea/workflows", workflow));
|
||||||
assertTrue(content.contains("java-version: 25"));
|
assertTrue(content.contains("java-version: 25"));
|
||||||
|
|||||||
Reference in new issue
Block a user