This commit is contained in:
Jerrit Fritzsche 2026-11-24 19:16:50 +01:00
parent e044e1a088
commit 1441bb36b8
15 changed files with 67 additions and 50 deletions

View File

@ -2,6 +2,6 @@
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="externalSystemId" value="Gradle" />
<option name="version" value="2.4.10" />
<option name="version" value="2.4.21" />
</component>
</project>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>

9
Jenkinsfile vendored
View File

@ -16,17 +16,12 @@ pipeline {
steps {
withCredentials([
usernamePassword(credentialsId: 'jf-repo',
usernameVariable: 'REPO_USER',
passwordVariable: 'REPO_PASS')
usernameVariable: 'ORG_GRADLE_PROJECT_repoUsername',
passwordVariable: 'ORG_GRADLE_PROJECT_repoPassword')
]) {
sh '''
echo "repoUser=$REPO_USER" > gradle.properties
echo "repoPassword=$REPO_PASS" >> gradle.properties
chmod +x ./gradlew
./gradlew clean shadowJar webDistribution
rm -f gradle.properties
'''
}
}

View File

@ -7,6 +7,6 @@ repositories {
}
dependencies {
implementation("net.kyori", "indra-common", "3.2.0")
implementation("com.google.code.gson", "gson", "2.15.0")
implementation("net.kyori:indra-common:3.2.0")
implementation("com.google.code.gson:gson:2.15.0")
}

View File

@ -18,27 +18,28 @@ fun Project.applyJarMetadata(mainClass: String, module: String) {
fun Project.applyJarMetadata(mainClass: String, module: String, preMain: String?) {
if ("jar" in tasks.names) {
val git = git()
val commit = providers.provider { git?.commit()?.name }
val branch = providers.provider { git?.branchName() }
val baseVersion = version.toString()
tasks.named<Jar>("jar") {
manifest.attributes(
"Main-Class" to mainClass,
"Automatic-Module-Name" to module,
"Implementation-Vendor" to "WCloudService",
"Implementation-Title" to Versions.wCloudCodeName,
"Implementation-Version" to project.version.toString() + "-${shortCommitHash()}")
"Implementation-Version" to commit.map { "$baseVersion-${it.take(8)}" }
.orElse("$baseVersion-unknown"),
"Git-Commit" to commit,
"Git-Branch" to branch)
// apply the pre-main class if given
if (preMain != null) {
manifest.attributes("Premain-Class" to preMain)
}
// apply git information to manifest
git()?.applyVcsInformationToManifest(manifest)
}
}
}
fun Project.shortCommitHash(): String {
return git()?.commit()?.name?.substring(0, 8) ?: "unknown"
}
fun Project.git(): IndraGitExtension? = rootProject.extensions.findByType()
fun Project.sourceSets(): SourceSetContainer = the<JavaPluginExtension>().sourceSets

View File

@ -12,7 +12,7 @@ defaultTasks("build", "test", "shadowJar")
tasks.register<Zip>("webDistribution") {
group = "distribution"
description = "Packages a self-contained single-master wCloud installation and its modules."
archiveFileName.set("wcloud-web.zip")
archiveFileName.set("wcloud.zip")
destinationDirectory.set(layout.buildDirectory.dir("distributions"))
fun includeJar(projectPath: String, jarName: String, target: String) {
@ -24,17 +24,17 @@ tasks.register<Zip>("webDistribution") {
includeJar(":wcloud-runnable:wcloud-master", Files.master, "dependency")
includeJar(":wcloud-api", Files.api, "local/GLOBAL/EVERY/plugins")
includeJar(":wcloud-plugin", Files.plugin, "local/GLOBAL/EVERY/plugins")
includeJar(":wcloud-modules:wmodule-permissions", Files.permissions, "modules")
includeJar(":wcloud-modules:wmodule-signs", Files.signs, "modules")
includeJar(":wcloud-modules:wmodule-npc", Files.npc, "modules")
includeJar(":wcloud-modules:wmodule-syncplayer", Files.syncplayer, "modules")
includeJar(":wcloud-modules:wmodule-permissions", Files.permissions, "optional-modules")
includeJar(":wcloud-modules:wmodule-signs", Files.signs, "optional-modules")
includeJar(":wcloud-modules:wmodule-npc", Files.npc, "optional-modules")
includeJar(":wcloud-modules:wmodule-syncplayer", Files.syncplayer, "optional-modules")
includeJar(":wcloud-modules:wmodule-cloudflare", Files.cloudflare, "optional-modules")
includeJar(":wcloud-modules:wmodule-discord", Files.discord, "optional-modules")
includeJar(":wcloud-modules:wmodule-hub", Files.hub, "optional-modules")
includeJar(":wcloud-modules:wmodule-notify", Files.notify, "optional-modules")
includeJar(":wcloud-modules:wmodule-reboot", Files.reboot, "optional-modules")
includeJar(":wcloud-modules:wmodule-syncproxy", Files.syncproxy, "modules")
includeJar(":wcloud-modules:wmodule-scoreboard", Files.scoreboard, "modules")
includeJar(":wcloud-modules:wmodule-scoreboard", Files.scoreboard, "optional-modules")
includeJar(":wcloud-modules:wmodule-moderation", Files.moderation, "optional-modules")
from("wcloud-launcher/src/main/dist")
}

View File

@ -1,5 +1,4 @@
org.gradle.caching=true
org.gradle.parallel=true
org.gradle.warning.mode=all
org.gradle.logging.level=info
org.gradle.jvmargs=-Xmx5G -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8

Binary file not shown.

View File

@ -1,8 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=a1bb7e9651ef09e4cd9a62d471564e0ee23b5757e5f21fd7358d7cfc21018fdf
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-all.zip
networkTimeout=60000
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true

0
gradlew vendored Normal file → Executable file
View File

View File

@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
alias(libs.plugins.shadow)
}
@ -18,6 +20,9 @@ dependencies {
implementation(projects.wcloudNetworking)
}
tasks.named("shadowJar") {
tasks.named<ShadowJar>("shadowJar") {
dependsOn(":wcloud-driver:shadowJar")
filesMatching("META-INF/*.kotlin_module") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}

View File

@ -96,7 +96,7 @@ public class EventDriver {
return;
}
Class<? extends EventAdapter> realParam = (Class<? extends EventAdapter>) param;
Class<? extends EventAdapter> realParam = param.asSubclass(EventAdapter.class);
var eventHandlersForEvent =
this.bindings.computeIfAbsent(

View File

@ -47,11 +47,11 @@ import java.util.TimerTask;
@Getter
@Accessors(fluent = true)
@Plugin(
id = "metacloudplugin",
id = "wcloudplugin",
name = "metacloud-plugin",
version = "2.0.0-SNAPSHOT",
authors = "Weapie",
dependencies = {@Dependency(id = "metacloudapi")})
dependencies = {@Dependency(id = "wcloudapi")})
public class VelocityBootstrap {
@Getter private static VelocityBootstrap instance;
@ -90,9 +90,10 @@ public class VelocityBootstrap {
this,
() -> {
var api = CloudAPI.instance();
if (api == null
|| NettyDriver.instance().client().channel() == null
|| !NettyDriver.instance().client().channel().isActive()) {
var netty = NettyDriver.instance();
var client = netty == null ? null : netty.client();
var channel = client == null ? null : client.channel();
if (api == null || channel == null || !channel.isActive()) {
return;
}
var plugins =
@ -129,11 +130,17 @@ public class VelocityBootstrap {
new TimerTask() {
@Override
public void run() {
if (NettyDriver.instance().client().closed()) {
var netty = NettyDriver.instance();
var client = netty == null ? null : netty.client();
if (client == null || client.closed()) {
cancel();
return;
}
if (!NettyDriver.instance().client().channel().isActive()) {
var channel = client.channel();
if (channel == null) {
return;
}
if (!channel.isActive()) {
System.exit(0);
}

View File

@ -20,6 +20,7 @@ import lombok.NonNull;
import org.jetbrains.annotations.ApiStatus;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
@ -66,8 +67,12 @@ public final class ClassAllocationUtil {
var unsafeClass = Class.forName("sun.misc.Unsafe");
var unsafeField = unsafeClass.getDeclaredField("theUnsafe");
var theUnsafe = getInaccessibleFieldValue(unsafeField);
unsafeAllocator = makeUnsafeAlloc(theUnsafe);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException exception) {
var allocateInstance = MethodHandles.publicLookup()
.unreflect(unsafeClass.getMethod("allocateInstance", Class.class))
.bindTo(theUnsafe);
unsafeAllocator = makeUnsafeAlloc(allocateInstance);
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException
| IllegalAccessException exception) {
unsafeAllocator = null;
}
UNSAFE_ALLOCATOR = unsafeAllocator;
@ -115,8 +120,9 @@ public final class ClassAllocationUtil {
SUPPLIER_GET_SIGNATURE,
noArgsConstructor,
SUPPLIER_FACTORY_SIGNATURE);
//noinspection unchecked
return (Supplier<Object>) callSite.getTarget().invokeExact();
@SuppressWarnings("unchecked")
var supplier = (Supplier<Object>) callSite.getTarget().invokeExact();
return supplier;
} catch (NoSuchMethodException exception) {
// unable to find a no-args constructor in the target class
return null;
@ -131,20 +137,23 @@ public final class ClassAllocationUtil {
* constructors are run when obtaining the class instance, which is fine as this is only used to obtain instances of
* data classes (whose fields are initialized later).
*
* @param theUnsafe the singleton instance of sun.misc.Unsafe.
* @param allocateInstance the method handle bound to the Unsafe singleton.
* @return the allocator factory function which creates new class instances using sun.misc.Unsafe.
* @throws NullPointerException if the given unsafe instance is null.
* @throws NullPointerException if the method handle is null.
*/
private static @NonNull Function<Class<?>, Supplier<Object>> makeUnsafeAlloc(
@NonNull Object theUnsafe) {
@NonNull MethodHandle allocateInstance) {
return targetClass ->
() -> {
try {
var unsafe = (sun.misc.Unsafe) theUnsafe;
return unsafe.allocateInstance(targetClass);
return (Object) allocateInstance.invokeExact(targetClass);
} catch (InstantiationException exception) {
throw new IllegalStateException(
"unable to allocate instance class", exception);
} catch (RuntimeException | Error exception) {
throw exception;
} catch (Throwable throwable) {
throw new AssertionError("unexpected allocation failure", throwable);
}
};
}

View File

@ -89,7 +89,8 @@ public record RowedFormatter<T>(
* @return the prepared columns based on the given input data.
* @throws NullPointerException if the given input data is null.
*/
public @NonNull ColumnEntry[] convertToColumns(@NonNull T... input) {
@SafeVarargs
public final @NonNull ColumnEntry[] convertToColumns(@NonNull T... input) {
return this.convertToColumns(Arrays.asList(input));
}
@ -111,7 +112,8 @@ public record RowedFormatter<T>(
* @return the formatted table based on the given input data.
* @throws NullPointerException if the given input data is null.
*/
public @NonNull Collection<String> format(@NonNull T... input) {
@SafeVarargs
public final @NonNull Collection<String> format(@NonNull T... input) {
return this.defaultFormatter.formatLines(this.convertToColumns(input));
}