Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'

- name: validate gradle wrapper
- name: wrapper validation
uses: gradle/actions/wrapper-validation@v4

- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew

- name: build
run: ./gradlew build --stacktrace

10 changes: 7 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ name: Release
on: [workflow_dispatch] # Manual trigger
jobs:
build:
runs-on: ${{ matrix.os }}
runs-on: ubuntu-24.04
steps:
- name: checkout repository
uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'

- name: validate gradle wrapper
- name: wrapper validation
uses: gradle/actions/wrapper-validation@v4

- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: chmod +x ./gradlew

- name: build
run: ./gradlew build publish --stacktrace
env:
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'fabric-loom' version '1.10-SNAPSHOT' apply false
id 'ploceus' version '1.10-SNAPSHOT' apply false
id 'fabric-loom' version '1.12-SNAPSHOT' apply false
id 'ploceus' version '1.12-SNAPSHOT' apply false
}

setUpJar(project)
Expand Down Expand Up @@ -49,7 +49,7 @@ def setUpJar(project) {
project.group = "${project.rootProject.root_maven_group}"

project.ploceus {
setGeneration(2)
setIntermediaryGeneration(2)
}

project.repositories {
Expand Down Expand Up @@ -194,7 +194,7 @@ def setUpModule(project, String... dependencies) {
}
}
project.ploceus {
setGeneration(2)
setIntermediaryGeneration(2)
}

def libraries = getLibraryDependencies(project, dependencies)
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
9 changes: 4 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -115,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
CLASSPATH="\\\"\\\""


# Determine the Java command to use to start the JVM.
Expand Down Expand Up @@ -206,15 +205,15 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

# Stop when "xargs" is not available.
Expand Down
4 changes: 2 additions & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ goto fail
:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
set CLASSPATH=


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.ornithemc.osl.lifecycle.api.server;

import net.minecraft.server.MinecraftServer;

import net.ornithemc.osl.lifecycle.impl.server.MinecraftServerAccess;

/**
* A wrapper class for getting the {@linkplain MinecraftServer} instance.
*/
public class MinecraftServerInstance {

/**
* Retrieves the current Minecraft server instance,
* or throws an exception.
*
* @return the current Minecraft server instance
*/
public static MinecraftServer get() {
return MinecraftServerAccess.getInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import net.minecraft.server.MinecraftServer;

import net.ornithemc.osl.lifecycle.api.server.MinecraftServerEvents;
import net.ornithemc.osl.lifecycle.impl.server.MinecraftServerAccess;

@Mixin(MinecraftServer.class)
public class MinecraftServerMixin {

@Unique private boolean osl$lifecycle$stopped;
@Unique private int osl$lifecycle$shutdownDepth;

@Inject(
method = "run",
Expand All @@ -23,7 +24,8 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$start(CallbackInfo ci) {
MinecraftServerEvents.START.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerAccess.INSTANCE = (MinecraftServer)(Object)this;
MinecraftServerEvents.START.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -35,7 +37,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$ready(CallbackInfo ci) {
MinecraftServerEvents.READY.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.READY.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -45,9 +47,20 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$stop(CallbackInfo ci) {
if (!osl$lifecycle$stopped) {
osl$lifecycle$stopped = true;
MinecraftServerEvents.STOP.invoker().accept((MinecraftServer)(Object)this);
if (osl$lifecycle$shutdownDepth++ == 0) {
MinecraftServerEvents.STOP.invoker().accept(MinecraftServerAccess.INSTANCE);
}
}

@Inject(
method = "shutdown",
at = @At(
value = "HEAD"
)
)
private void osl$lifecycle$stopped(CallbackInfo ci) {
if (--osl$lifecycle$shutdownDepth == 0) {
MinecraftServerAccess.INSTANCE = null;
}
}

Expand All @@ -58,7 +71,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$startTick(CallbackInfo ci) {
MinecraftServerEvents.TICK_START.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.TICK_START.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -68,7 +81,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$endTick(CallbackInfo ci) {
MinecraftServerEvents.TICK_END.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.TICK_END.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -78,7 +91,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$loadWorld(CallbackInfo ci) {
MinecraftServerEvents.LOAD_WORLD.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.LOAD_WORLD.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -91,7 +104,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$prepareWorld(CallbackInfo ci) {
MinecraftServerEvents.PREPARE_WORLD.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.PREPARE_WORLD.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -101,6 +114,6 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$readyWorld(CallbackInfo ci) {
MinecraftServerEvents.READY_WORLD.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.READY_WORLD.invoker().accept(MinecraftServerAccess.INSTANCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.ornithemc.osl.lifecycle.impl.server;

import net.minecraft.server.MinecraftServer;

public class MinecraftServerAccess {

public static MinecraftServer INSTANCE;

public static MinecraftServer getInstance() {
if (INSTANCE == null) {
throw new IllegalStateException("no MinecraftServer instance available right now");
}

return INSTANCE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.ornithemc.osl.lifecycle.api.server;

import net.minecraft.server.MinecraftServer;

import net.ornithemc.osl.lifecycle.impl.server.MinecraftServerAccess;

/**
* A wrapper class for getting the {@linkplain MinecraftServer} instance.
*/
public class MinecraftServerInstance {

/**
* Retrieves the current Minecraft server instance,
* or throws an exception.
*
* @return the current Minecraft server instance
*/
public static MinecraftServer get() {
return MinecraftServerAccess.getInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import net.minecraft.server.MinecraftServer;

import net.ornithemc.osl.lifecycle.api.server.MinecraftServerEvents;
import net.ornithemc.osl.lifecycle.impl.server.MinecraftServerAccess;

@Mixin(MinecraftServer.class)
public class MinecraftServerMixin {

@Unique private boolean osl$lifecycle$stopped;
@Unique private int osl$lifecycle$shutdownDepth;

@Inject(
method = "run",
Expand All @@ -23,7 +24,8 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$start(CallbackInfo ci) {
MinecraftServerEvents.START.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerAccess.INSTANCE = (MinecraftServer)(Object)this;
MinecraftServerEvents.START.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -35,7 +37,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$ready(CallbackInfo ci) {
MinecraftServerEvents.READY.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.READY.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -45,9 +47,20 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$stop(CallbackInfo ci) {
if (!osl$lifecycle$stopped) {
osl$lifecycle$stopped = true;
MinecraftServerEvents.STOP.invoker().accept((MinecraftServer)(Object)this);
if (osl$lifecycle$shutdownDepth++ == 0) {
MinecraftServerEvents.STOP.invoker().accept(MinecraftServerAccess.INSTANCE);
}
}

@Inject(
method = "shutdown",
at = @At(
value = "HEAD"
)
)
private void osl$lifecycle$stopped(CallbackInfo ci) {
if (--osl$lifecycle$shutdownDepth == 0) {
MinecraftServerAccess.INSTANCE = null;
}
}

Expand All @@ -58,7 +71,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$startTick(CallbackInfo ci) {
MinecraftServerEvents.TICK_START.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.TICK_START.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -68,7 +81,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$endTick(CallbackInfo ci) {
MinecraftServerEvents.TICK_END.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.TICK_END.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -78,7 +91,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$loadWorld(CallbackInfo ci) {
MinecraftServerEvents.LOAD_WORLD.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.LOAD_WORLD.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -91,7 +104,7 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$prepareWorld(CallbackInfo ci) {
MinecraftServerEvents.PREPARE_WORLD.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.PREPARE_WORLD.invoker().accept(MinecraftServerAccess.INSTANCE);
}

@Inject(
Expand All @@ -101,6 +114,6 @@ public class MinecraftServerMixin {
)
)
private void osl$lifecycle$readyWorld(CallbackInfo ci) {
MinecraftServerEvents.READY_WORLD.invoker().accept((MinecraftServer)(Object)this);
MinecraftServerEvents.READY_WORLD.invoker().accept(MinecraftServerAccess.INSTANCE);
}
}
Loading
Loading