Skip to content

mark 1.21.6 as supported and adjust dependency resolution #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
val buildNum = System.getenv("GITHUB_RUN_NUMBER") ?: "SNAPSHOT"

group = "win.templeos.lualink"
version = "1.21.5-$buildNum"
version = "1.21.6-$buildNum"

repositories {
mavenLocal()
Expand All @@ -34,7 +34,7 @@ dependencies {
// Kotlin (downloaded and loaded at runtime)
paperLibrary(kotlin("stdlib"))
// Paper API
compileOnly("io.papermc.paper:paper-api:1.20-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT")
// LuaJava (cannot be easily relocated or downloaded at runtime)
implementation("party.iroiro.luajava:luajava:$luaJavaVersion") // Use our fork of the LuaJava library
implementation("party.iroiro.luajava:luajit:$luaJavaVersion")
Expand Down Expand Up @@ -64,7 +64,7 @@ modrinth {
versionNumber.set(version.toString())
versionType.set("release")
uploadFile.set(tasks.shadowJar.get())
gameVersions.addAll("1.21.4", "1.21.5")
gameVersions.addAll("1.21.4", "1.21.5", "1.21.6")
loaders.addAll("paper", "purpur")
changelog.set(System.getenv("GIT_COMMIT_MESSAGE"))
}
Expand All @@ -81,7 +81,7 @@ hangarPublish {
platforms {
register(Platforms.PAPER) {
jar.set(tasks.shadowJar.flatMap { it.archiveFile })
platformVersions.set(listOf("1.21.4", "1.21.5"))
platformVersions.set(listOf("1.21.4", "1.21.5", "1.21.6"))
}
}
}
Expand All @@ -92,7 +92,7 @@ tasks {
// Configure the Minecraft version for our task.
// This is the only required configuration besides applying the plugin.
// Your plugin's jar (or shadowJar if present) will be used automatically.
minecraftVersion("1.21.5")
minecraftVersion("1.21.6")

// Make sure runServer is ran with -add-opens=java.base/java.util=ALL-UNNAMED
jvmArgs(
Expand Down
44 changes: 40 additions & 4 deletions src/main/java/win/templeos/lualink/PluginLibrariesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.util.repository.AuthenticationBuilder;
import org.slf4j.Logger;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void classloader(final @NotNull PluginClasspathBuilder classpathBuilder)
throw new IOException("File 'paper-libraries.json' not found in the classpath.");
// Extracting file contents to new MavenLibraryResolver instance.
final MavenLibraryResolver iLibraries = gson.fromJson(new InputStreamReader(stream, StandardCharsets.UTF_8), PluginLibraries.class)
.toMavenLibraryResolver();
.toMavenLibraryResolver(classpathBuilder.getContext().getLogger(), RepositoryContext.INTERNAL);
// Adding library(-ies) to the PluginClasspathBuilder.
classpathBuilder.addLibrary(iLibraries);
} catch (final IOException e) {
Expand All @@ -77,7 +78,7 @@ public void classloader(final @NotNull PluginClasspathBuilder classpathBuilder)
try {
// Extracting file contents to new MavenLibraryResolver instance.
final MavenLibraryResolver eDependencies = gson.fromJson(new InputStreamReader(new FileInputStream(eLibrariesFile), StandardCharsets.UTF_8), PluginLibraries.class)
.toMavenLibraryResolver();
.toMavenLibraryResolver(classpathBuilder.getContext().getLogger(), RepositoryContext.USER_SPECIFIED);
// Adding library(-ies) to the PluginClasspathBuilder.
classpathBuilder.addLibrary(eDependencies);
} catch (final FileNotFoundException e) {
Expand All @@ -88,12 +89,40 @@ public void classloader(final @NotNull PluginClasspathBuilder classpathBuilder)

private record PluginLibraries(Map<String, RepositoryInfo> repositories, List<String> dependencies) {

public MavenLibraryResolver toMavenLibraryResolver() {
public MavenLibraryResolver toMavenLibraryResolver(final @NotNull Logger logger, final @NotNull RepositoryContext context) {
final MavenLibraryResolver resolver = new MavenLibraryResolver();
// Adding repositories to library resolver.
repositories.entrySet().stream()
.map(entry -> {
final RemoteRepository.Builder builder = new RemoteRepository.Builder(entry.getKey(), "default", entry.getValue().url);
// Preparing the RemoteRepository builder.
// This is filled in the next step, and re-used later to apply authentication credentials if specified.
RemoteRepository.Builder builder;
// Field 'MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR' was added in one of the recent Paper versions and may not be available on < 1.21.6.
try {
// Replacing Maven Central repository with a pre-configured mirror.
// See: https://docs.papermc.io/paper/dev/getting-started/paper-plugins/#loaders
if (entry.getValue().url.contains("maven.org") == true || entry.getValue().url.contains("maven.apache.org") == true) {
if (context == RepositoryContext.INTERNAL) {
builder = new RemoteRepository.Builder(entry.getKey(), "default", MavenLibraryResolver.MAVEN_CENTRAL_DEFAULT_MIRROR);
} else {
logger.warn("Found at least one Maven Central repository in use that was not automatically replaced. Adjust contents of 'libraries.json' to get rid of this warning.");
logger.warn("While the plugin should work as usual, please keep in mind that downloading from Maven Central may be against their TOS and can be subject to a rate-limit.");
logger.warn("- " + entry.getValue().url + " (" + context + ")");
builder = new RemoteRepository.Builder(entry.getKey(), "default", entry.getValue().url);
}
} else {
builder = new RemoteRepository.Builder(entry.getKey(), "default", entry.getValue().url);
}
} catch (final NoSuchFieldError e) {
if (context == RepositoryContext.INTERNAL) {
builder = new RemoteRepository.Builder(entry.getKey(), "default", "https://maven-central.storage-download.googleapis.com/maven2");
} else {
logger.warn("Replacing Maven Central repository with pre-configured mirror failed. As of now, this feature is available only on Paper 1.21.6 #11 and higher.");
logger.warn("While the plugin should work as usual, please keep in mind that downloading from Maven Central may be against their TOS and can be subject to a rate-limit.");
logger.warn("- " + entry.getValue().url + " (" + context + ")");
builder = new RemoteRepository.Builder(entry.getKey(), "default", entry.getValue().url);
}
}
// Building and adding Authentication if specified.
if (entry.getValue().username != null && entry.getValue().password != null)
builder.setAuthentication(new AuthenticationBuilder().addUsername(entry.getValue().username).addPassword(entry.getValue().password).build());
Expand All @@ -115,6 +144,13 @@ public MavenLibraryResolver toMavenLibraryResolver() {
*/
private record RepositoryInfo(@NotNull String url, @Nullable String username, @Nullable String password) { /* DATA ONLY */ }

/**
* Represents the context in which the library is being resolved.
*/
private enum RepositoryContext {
INTERNAL, USER_SPECIFIED
}

/**
* Converts JSON repository definition to {@link RepositoryInfo} object.
*
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/win/templeos/lualink/lua/LuaCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class LuaCommand(private val command: LuaValue) : Command(command.get("metadata"
this.aliases = aliasList.values.map { it.toString() }.toMutableList()
}
}
override fun execute(sender: CommandSender, commandLabel: String, args: Array<out String>?): Boolean {
override fun execute(sender: CommandSender, commandLabel: String, args: Array<out String>): Boolean {
command.get("handler").call(sender, args)
return true
}

override fun tabComplete(sender: CommandSender, alias: String, args: Array<out String>?): MutableList<String> {
override fun tabComplete(sender: CommandSender, alias: String, args: Array<out String>): MutableList<String> {
val tabCompleteHandler = command.get("metadata").get("tabComplete")
if (tabCompleteHandler.type() != Lua.LuaType.FUNCTION) {
// Default behavior: Return online player names
Expand All @@ -43,7 +43,7 @@ class LuaCommand(private val command: LuaValue) : Command(command.get("metadata"
val result = tabCompleteHandler.call(sender, args)[0]
if (result.type() == Lua.LuaType.TABLE) {
val list = result.toJavaObject() as HashMap<*, *>
return (if (args != null) list.values.filter { it.toString().contains(args.last(), true) } else list.values).toMutableList() as MutableList<String>
return (list.values.filter { it.toString().contains(args.last(), true) }).toMutableList() as MutableList<String>
}
// Default behavior: Return online player names
return null!!
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/libraries.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// External libraries to be loaded for use with scripts. Server must be restarted for the changes to take effect.
// IMPORTANT: If you wish to resolve libraries from Maven Central, you're strongly advised to instead use a mirror.
{
"repositories": {
// "RepositoryName": "https://repo.example.com/releases"
Expand Down