Starting portal rescue feature.

This commit is contained in:
samo_lego 2020-04-07 14:28:23 +02:00
parent c9a99dbec7
commit 5172dcd059
2 changed files with 24 additions and 2 deletions

View File

@ -1,19 +1,39 @@
package org.samo_lego.simpleauth.mixin; package org.samo_lego.simpleauth.mixin;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.network.ClientConnection; import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager; import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import org.samo_lego.simpleauth.SimpleAuth;
import org.samo_lego.simpleauth.event.entity.player.PlayerJoinServerCallback; import org.samo_lego.simpleauth.event.entity.player.PlayerJoinServerCallback;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 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) @Mixin(PlayerManager.class)
public abstract class MixinPlayerManager { public abstract class MixinPlayerManager {
@Inject(method = "onPlayerConnect", at = @At("RETURN")) @Inject(method = "onPlayerConnect", at = @At("RETURN"))
private void onPlayerConnect(ClientConnection clientConnection_1, ServerPlayerEntity serverPlayerEntity_1, CallbackInfo ci) { private void onPlayerConnect(ClientConnection clientConnection, ServerPlayerEntity serverPlayerEntity, CallbackInfo ci) {
PlayerJoinServerCallback.EVENT.invoker().onPlayerJoin(serverPlayerEntity_1); 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());
}
}
} }
} }

View File

@ -64,6 +64,8 @@ public class AuthConfig {
Password will be hashed and saved. Password will be hashed and saved.
*/ */
public String globalPassword = null; 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 static class LangConfig {
public String enterPassword = "§6You need to enter your password!"; public String enterPassword = "§6You need to enter your password!";