Skip to content

Commit

Permalink
Fix incompatibility with LuckPerms with enabled forcedOfflineUuids
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaCartes committed Jul 25, 2023
1 parent 0dc8a73 commit 4fbda21
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- `skipAllAuthChecks`
2) Player will be re-mounted on entity if they were dismounted on login with `spawnOnJoin` enabled
3) Changed behavior of `premiumAutologin`. Now it only allows online players not to authorize when logging in
4) Fix incompatibility with LuckPerms with enabled forcedOfflineUuids

----
### 3.0.18
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/xyz/nikitacartes/easyauth/EasyAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.player.*;
import net.fabricmc.fabric.api.networking.v1.ServerLoginConnectionEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Identifier;
import xyz.nikitacartes.easyauth.commands.*;
import xyz.nikitacartes.easyauth.event.AuthEventHandler;
import xyz.nikitacartes.easyauth.storage.AuthConfig;
Expand Down Expand Up @@ -129,6 +132,10 @@ public void onInitialize() {
ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> AuthCommand.reloadConfig(null));
ServerLifecycleEvents.SERVER_STARTED.register(this::onStartServer);
ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer);

Identifier earlyPhase = new Identifier(MOD_ID, "early");
ServerLoginConnectionEvents.QUERY_START.addPhaseOrdering(earlyPhase, Event.DEFAULT_PHASE);
ServerLoginConnectionEvents.QUERY_START.register(earlyPhase, AuthEventHandler::onPreLogin);
}

private void onStartServer(MinecraftServer server) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package xyz.nikitacartes.easyauth.event;

import com.mojang.authlib.GameProfile;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.ServerLoginNetworking;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerLoginNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
Expand Down Expand Up @@ -281,4 +285,10 @@ public static ActionResult onUseEntity(PlayerEntity player) {
return ActionResult.PASS;
}

public static void onPreLogin(ServerLoginNetworkHandler netHandler, MinecraftServer server, PacketSender packetSender, ServerLoginNetworking.LoginSynchronizer sync) {
if (config.experimental.forcedOfflineUuids) {
netHandler.profile = netHandler.toOfflineProfile(netHandler.profile);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Shadow;
import xyz.nikitacartes.easyauth.event.AuthEventHandler;
import xyz.nikitacartes.easyauth.mixin.accessor.ServerStatHandlerAccessor;
import xyz.nikitacartes.easyauth.utils.PlayerAuth;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,13 @@ public abstract class ServerLoginNetworkHandlerMixin {
@Shadow
GameProfile profile;

@Shadow
protected abstract GameProfile toOfflineProfile(GameProfile profile);

@Shadow
ServerLoginNetworkHandler.State state;

@Final
@Shadow
MinecraftServer server;

@Inject(method = "acceptPlayer()V", at = @At("HEAD"))
private void acceptPlayer(CallbackInfo ci) {
if (config.experimental.forcedOfflineUuids) {
this.profile = this.toOfflineProfile(this.profile);
}
}

/**
* Checks whether the player has purchased an account.
* If so, server is presented as online, and continues as in normal-online mode.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.nikitacartes.easyauth.mixin;
package xyz.nikitacartes.easyauth.mixin.accessor;

import net.minecraft.stat.ServerStatHandler;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/easyauth.accesswidener
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
accessWidener v1 named

accessible class net/minecraft/server/network/ServerLoginNetworkHandler$State
accessible class net/minecraft/server/network/ServerLoginNetworkHandler$State
accessible method net/minecraft/server/network/ServerLoginNetworkHandler toOfflineProfile (Lcom/mojang/authlib/GameProfile;)Lcom/mojang/authlib/GameProfile;
accessible field net/minecraft/server/network/ServerLoginNetworkHandler profile Lcom/mojang/authlib/GameProfile;
6 changes: 3 additions & 3 deletions src/main/resources/easyauth.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"mixins": [
"CommandManagerMixin",
"MinecraftServerMixin",
"SaveAllCommandMixin",
"PlayerAdvancementTrackerMixin",
"PlayerListS2CPacketMixin",
"PlayerManagerMixin",
"SaveAllCommandMixin",
"ServerLoginNetworkHandlerMixin",
"ServerPlayerEntityMixin",
"ServerPlayNetworkHandlerMixin",
"ServerStatHandlerAccessor",
"SlotMixin",
"WorldSaveHandlerMixin"
"WorldSaveHandlerMixin",
"accessor.ServerStatHandlerAccessor"
],
"minVersion": "0.8",
"injectors": {
Expand Down

0 comments on commit 4fbda21

Please sign in to comment.