Compare commits

...

3 Commits

Author SHA1 Message Date
20dc34714e Merge pull request '5.1.0: add player life cycle events' (#33) from dev into master
All checks were successful
Test and Deploy / build (17, ubuntu-latest) (push) Successful in 2m53s
Test and Deploy / deploy (17, ubuntu-latest) (push) Successful in 4m4s
Reviewed-on: #33
2024-08-20 18:52:18 +02:00
267bd3644c ci: add cache
All checks were successful
Test and Deploy / build (17, ubuntu-latest) (push) Successful in 6m12s
Test and Deploy / deploy (17, ubuntu-latest) (push) Has been skipped
Test and Deploy / build (17, ubuntu-latest) (pull_request) Successful in 2m26s
Test and Deploy / deploy (17, ubuntu-latest) (pull_request) Has been skipped
2024-08-20 18:42:39 +02:00
d6515d9cbb feat: add player join and leave events
Some checks failed
Test and Deploy / deploy (17, ubuntu-latest) (push) Blocked by required conditions
Test and Deploy / build (17, ubuntu-latest) (push) Has been cancelled
2024-08-20 18:39:30 +02:00
9 changed files with 109 additions and 5 deletions

View File

@ -33,6 +33,14 @@ jobs:
with:
java-version: ${{ matrix.java }}
distribution: 'oracle'
- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: make gradle wrapper executable
if: ${{ runner.os != 'Windows' }}
run: |

View File

@ -0,0 +1,37 @@
package fr.altarik.toolbox.core.event;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
public interface PlayerLifecycleCallback {
Event<PlayerJoin> PLAYER_JOIN = EventFactory.createArrayBacked(PlayerJoin.class, listeners -> player -> {
for(PlayerJoin listener : listeners) {
ActionResult result = listener.onPlayerJoin(player);
if (result != ActionResult.PASS)
return result;
}
return ActionResult.PASS;
});
Event<PlayerLeave> PLAYER_LEAVE = EventFactory.createArrayBacked(PlayerLeave.class, listeners -> player -> {
for(PlayerLeave listener : listeners) {
ActionResult result = listener.onPlayerLeave(player);
if (result != ActionResult.PASS)
return result;
}
return ActionResult.PASS;
});
@FunctionalInterface
interface PlayerJoin {
ActionResult onPlayerJoin(ServerPlayerEntity player);
}
@FunctionalInterface
interface PlayerLeave {
ActionResult onPlayerLeave(ServerPlayerEntity player);
}
}

View File

@ -0,0 +1,20 @@
package fr.altarik.toolbox.core.mixin;
import fr.altarik.toolbox.core.event.PlayerLifecycleCallback;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ConnectedClientData;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(PlayerManager.class)
public class PlayerJoinEvent {
@Inject(method = "onPlayerConnect", at = @At(value = "RETURN"))
private void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
PlayerLifecycleCallback.PLAYER_JOIN.invoker().onPlayerJoin(player);
}
}

View File

@ -0,0 +1,23 @@
package fr.altarik.toolbox.core.mixin;
import fr.altarik.toolbox.core.event.PlayerLifecycleCallback;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ServerPlayNetworkHandler.class)
public class PlayerLeaveEvent {
@Shadow
public ServerPlayerEntity player;
@Inject(at = @At(value = "HEAD"), method = "onDisconnected")
private void onPlayerQuit(Text reason, CallbackInfo ci) {
PlayerLifecycleCallback.PLAYER_LEAVE.invoker().onPlayerLeave(player);
}
}

View File

@ -0,0 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "fr.altarik.toolbox.core.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"PlayerJoinEvent",
"PlayerLeaveEvent"
],
"verbose": false,
"injectors": {
"defaultRequire": 1
}
}

View File

@ -19,7 +19,9 @@
"entrypoints": {
"main": []
},
"mixins": [],
"mixins": [
"Core.mixins.json"
],
"depends": {
"fabricloader": "^${loaderVersion}",
"fabric-api": "*",

View File

@ -2,7 +2,7 @@ import fr.altarik.CreateTag
import fr.altarik.ReportDiscord
plugins {
id 'fabric-loom' version '1.5-SNAPSHOT' apply false
id 'fabric-loom' version '1.6-SNAPSHOT' apply false
}
Properties local = new Properties()

View File

@ -5,10 +5,10 @@ junit_version=5.9.0
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.6
fabric_version=0.95.4+1.20.4
fabric_version=0.97.1+1.20.4
maven_group=fr.altarik.toolbox
maven_version=5.0.0
maven_version=5.1.0
git_owner=quentinlegot
git_repo=Toolbox

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists