Skip to content

Commit

Permalink
Fix spawning in wrong dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaCartes committed May 5, 2024
1 parent 28c5fa1 commit 6d5de20
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
### 3.0.24
##### Minecraft 1.20.5-1.20.6

1) Fix spawning in wrong dimension with `hide-player-coords` enabled

### 3.0.23
##### Minecraft 1.20.5-1.20.6

1) Fix `auth list`.


### 3.0.22-SNAPSHOT
##### Minecraft 1.20.3-1.20.4

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Mod
mod_name=EasyAuth
mod_id=easyauth
mod_version=3.0.23
mod_version=3.0.24

# Fabric
minecraft_version=1.20.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static int unregister(ServerCommandSource source, String pass) throws Co
DB.deleteUserData(uuid);
langConfig.accountDeleted.send(source);
((PlayerAuth) player).easyAuth$setAuthenticated(false);
((PlayerAuth) player).easyAuth$saveLastLocation();
((PlayerAuth) player).easyAuth$saveLastLocation(true);
player.networkHandler.disconnect(langConfig.accountDeleted.get());
playerCacheMap.remove(uuid);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static int logout(ServerCommandSource serverCommandSource) throws Comman
if (((PlayerAuth) player).easyAuth$isAuthenticated()) {
// player.getServer().getPlayerManager().sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.REMOVE_PLAYER, player));
((PlayerAuth) player).easyAuth$setAuthenticated(false);
((PlayerAuth) player).easyAuth$saveLastLocation();
((PlayerAuth) player).easyAuth$saveLastLocation(true);
langConfig.successfulLogout.send(serverCommandSource);
} else {
langConfig.cannotLogout.send(serverCommandSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private RegistryKey<World> onPlayerConnect(RegistryKey<World> world, ClientConne
playerCacheMap.put(uuid, cache);
}
if (config.hidePlayerCoords && !(hasValidSession(player, connection))) {
((PlayerAuth) player).easyAuth$saveLastDimension(world);
return RegistryKey.of(RegistryKeys.WORLD, new Identifier(config.worldSpawn.dimension));
}
return world;
Expand All @@ -78,7 +79,7 @@ private RegistryKey<World> onPlayerConnect(RegistryKey<World> world, ClientConne
private void onPlayerConnect(Args args, ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData) {
if (config.hidePlayerCoords && !(hasValidSession(player, connection))) {
PlayerCacheV0 cache = playerCacheMap.get(((PlayerAuth) player).easyAuth$getFakeUuid());
((PlayerAuth) player).easyAuth$saveLastLocation();
((PlayerAuth) player).easyAuth$saveLastLocation(false);

LogDebug(String.format("Teleporting player %s", ((PlayerAuth) player).easyAuth$getFakeUuid()));

Expand Down Expand Up @@ -154,9 +155,7 @@ private void onPlayerLeave(ServerPlayerEntity serverPlayerEntity, CallbackInfo c
@Inject(method = "checkCanJoin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/text/Text;", at = @At("HEAD"), cancellable = true)
private void checkCanJoin(SocketAddress socketAddress, GameProfile profile, CallbackInfoReturnable<Text> cir) {
// Getting the player that is trying to join the server
PlayerManager manager = (PlayerManager) (Object) this;

Text returnText = AuthEventHandler.checkCanPlayerJoinServer(profile, manager);
Text returnText = AuthEventHandler.checkCanPlayerJoinServer(profile, playerManager);

if (returnText != null) {
// Canceling player joining with the returnText message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.nikitacartes.easyauth.mixin;

import net.minecraft.entity.Entity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.scoreboard.ScoreboardCriterion;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -36,21 +37,36 @@ public abstract class ServerPlayerEntityMixin implements PlayerAuth {
private long kickTimer = config.kickTimeout * 20;

@Override
public void easyAuth$saveLastLocation() {
public void easyAuth$saveLastLocation(boolean saveDimension) {
PlayerCacheV0 cache = playerCacheMap.get(this.easyAuth$getFakeUuid());
if (cache == null) {
LogDebug("Player cache is null, not saving position.");
return;
}
// Saving position
cache.lastLocation.dimension = player.getServerWorld();
if (saveDimension) {
cache.lastLocation.dimension = player.getServerWorld();
}
cache.lastLocation.position = player.getPos();
cache.lastLocation.yaw = player.getYaw();
cache.lastLocation.pitch = player.getPitch();
cache.ridingEntityUUID = player.getVehicle() != null ? player.getVehicle().getUuid() : null;
cache.wasDead = player.isDead();
LogDebug(String.format("Saving position of player %s as %s", player.getName().getContent(), cache.lastLocation));
LogDebug(String.format("Saving vehicle of player %s as %s", player.getName().getContent(), cache.ridingEntityUUID));
if (cache.ridingEntityUUID != null) {
LogDebug(String.format("Saving vehicle of player %s as %s", player.getName().getContent(), cache.ridingEntityUUID));
}
}

@Override
public void easyAuth$saveLastDimension(RegistryKey<World> registryKey) {
PlayerCacheV0 cache = playerCacheMap.get(this.easyAuth$getFakeUuid());
if (cache == null) {
LogDebug("Player cache is null, not saving position.");
return;
}
// Saving position
cache.lastLocation.dimension = this.server.getWorld(registryKey);
}

@Override
Expand All @@ -70,7 +86,7 @@ public abstract class ServerPlayerEntityMixin implements PlayerAuth {
}
// Puts player to last cached position
player.teleport(
cache.lastLocation.dimension,
cache.lastLocation.dimension == null ? server.getWorld(World.OVERWORLD) : cache.lastLocation.dimension,
cache.lastLocation.position.getX(),
cache.lastLocation.position.getY(),
cache.lastLocation.position.getZ(),
Expand All @@ -80,6 +96,7 @@ public abstract class ServerPlayerEntityMixin implements PlayerAuth {

if (cache.ridingEntityUUID != null) {
LogDebug(String.format("Mounting player to vehicle %s", cache.ridingEntityUUID));
if (cache.lastLocation.dimension == null) return;
ServerWorld world = server.getWorld(cache.lastLocation.dimension.getRegistryKey());
if (world == null) return;
Entity entity = world.getEntity(cache.ridingEntityUUID);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/xyz/nikitacartes/easyauth/utils/PlayerAuth.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package xyz.nikitacartes.easyauth.utils;

import net.minecraft.text.Text;
import net.minecraft.registry.RegistryKey;
import net.minecraft.world.World;

/**
* PLayer authentication extension.
*/
public interface PlayerAuth {
void easyAuth$saveLastLocation();
void easyAuth$saveLastLocation(boolean saveDimension);

void easyAuth$saveLastDimension(RegistryKey<World> registryKey);

void easyAuth$restoreLastLocation();

Expand Down

0 comments on commit 6d5de20

Please sign in to comment.