From 5172dcd059fef892565b9ea1db276487e08c98da Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Tue, 7 Apr 2020 14:28:23 +0200 Subject: [PATCH] Starting portal rescue feature. --- .../simpleauth/mixin/MixinPlayerManager.java | 24 +++++++++++++++++-- .../simpleauth/utils/AuthConfig.java | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java index 9f336ad..db2da0e 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java @@ -1,19 +1,39 @@ package org.samo_lego.simpleauth.mixin; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.network.ClientConnection; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; +import org.samo_lego.simpleauth.SimpleAuth; import org.samo_lego.simpleauth.event.entity.player.PlayerJoinServerCallback; 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; +import static net.minecraft.block.NetherPortalBlock.AXIS; +import static net.minecraft.util.math.Direction.Axis.Z; + @Mixin(PlayerManager.class) public abstract class MixinPlayerManager { @Inject(method = "onPlayerConnect", at = @At("RETURN")) - private void onPlayerConnect(ClientConnection clientConnection_1, ServerPlayerEntity serverPlayerEntity_1, CallbackInfo ci) { - PlayerJoinServerCallback.EVENT.invoker().onPlayerJoin(serverPlayerEntity_1); + private void onPlayerConnect(ClientConnection clientConnection, ServerPlayerEntity serverPlayerEntity, CallbackInfo ci) { + PlayerJoinServerCallback.EVENT.invoker().onPlayerJoin(serverPlayerEntity); + if(SimpleAuth.config.main.tryPortalRescue && serverPlayerEntity.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL)) { //((MixinEntity) serverPlayerEntity).inNetherPortal() + // Tries to rescue player from nether portal + // Teleport - serverPlayerEntity.getBlockState().isOpaque(); + BlockState portalState = serverPlayerEntity.getBlockState(); + if(portalState.get(AXIS) == Z) { + // Player should be put to northern or southern block + System.out.println("(N/S is ok) Position %s" + serverPlayerEntity.getBlockPos().toString()); + } + else { + // Player should be put to eastern or western block + System.out.println("(W/E is ok) Position %s" + serverPlayerEntity.getBlockPos().toString()); + } + + } } } diff --git a/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java b/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java index 7465acd..9525f4c 100644 --- a/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java +++ b/src/main/java/org/samo_lego/simpleauth/utils/AuthConfig.java @@ -64,6 +64,8 @@ public class AuthConfig { Password will be hashed and saved. */ public String globalPassword = null; + // Tries to rescue players if they are stuck inside a portal on logging in + public boolean tryPortalRescue = true; } public static class LangConfig { public String enterPassword = "ยง6You need to enter your password!";