Skip to content

Commit

Permalink
Fix: afk status isn't updated after disconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
iceBear67 committed Jan 4, 2025
1 parent a733806 commit d1747f5
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
import io.ib67.sfcraft.callback.SFCallbacks;
import io.ib67.sfcraft.mixin.common.bridge.ServerPlayerBridge;
import io.ib67.sfcraft.registry.chat.SimpleMessageDecorator;
import net.minecraft.network.DisconnectionInfo;
import net.minecraft.network.message.MessageDecorator;
import net.minecraft.server.MinecraftServer;
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.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ServerPlayNetworkHandler.class)
public abstract class ServerPlayNetworkHandlerMixin {
@Shadow
public ServerPlayerEntity player;

/**
* @author icybear
* @reason small method, overwrite to reduce overhead
Expand All @@ -25,6 +32,11 @@ public MessageDecorator getMessageDecorator(MinecraftServer instance) {
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;disconnect(Lnet/minecraft/text/Text;)V", ordinal = 2))
public void onPlayerIdling(ServerPlayNetworkHandler instance, Text text) {
((ServerPlayerBridge) instance.player).setLastActionTime(Long.MAX_VALUE);
SFCallbacks.PLAYER_IDLE.invoker().onSwitchIdle(instance.player,true);
SFCallbacks.PLAYER_IDLE.invoker().onSwitchIdle(instance.player, true);
}

@Inject(method = "onDisconnected", at = @At("HEAD"))
public void onDisconnected(DisconnectionInfo instance, CallbackInfo ci) {
player.updateLastActionTime();
}
}

0 comments on commit d1747f5

Please sign in to comment.