forked from sorceress/EasyAuth
Merge branch 'portalRescue-overhaul'
This commit is contained in:
commit
3e0f9777d6
|
@ -11,6 +11,8 @@ import net.minecraft.server.MinecraftServer;
|
|||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
@ -156,6 +158,17 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
if(config.main.spawnOnJoin)
|
||||
teleportPlayer(player, false);
|
||||
|
||||
// Updating blocks if needed (if portal rescue action happened)
|
||||
if(deauthenticatedUsers.get(convertUuid(player)).wasInPortal) {
|
||||
World world = player.getEntityWorld();
|
||||
BlockPos pos = player.getBlockPos();
|
||||
|
||||
// Sending updates to portal blocks
|
||||
// This is technically not needed, but it cleans the "messed portal" on the client
|
||||
world.updateListeners(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
|
||||
world.updateListeners(pos.up(), world.getBlockState(pos.up()), world.getBlockState(pos.up()), 3);
|
||||
}
|
||||
|
||||
deauthenticatedUsers.remove(convertUuid(player));
|
||||
|
||||
// Player no longer needs to be invisible and invulnerable
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.block.Blocks;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
|
||||
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
|
||||
import net.minecraft.server.PlayerManager;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
@ -13,15 +14,13 @@ import net.minecraft.text.Text;
|
|||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.samo_lego.simpleauth.mixin.BlockUpdateS2CPacketAccessor;
|
||||
import org.samo_lego.simpleauth.storage.PlayerCache;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static net.minecraft.block.NetherPortalBlock.AXIS;
|
||||
import static net.minecraft.util.math.Direction.Axis.Z;
|
||||
import static org.samo_lego.simpleauth.SimpleAuth.*;
|
||||
import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
|
||||
|
||||
|
@ -92,80 +91,38 @@ public class AuthEventHandler {
|
|||
}
|
||||
// Invalidating session
|
||||
playerCache.wasAuthenticated = false;
|
||||
if(playerCache.isRegistered)
|
||||
player.sendMessage(new LiteralText(config.lang.loginRequired), false);
|
||||
else
|
||||
player.sendMessage(new LiteralText(config.lang.notRegistered), false);
|
||||
}
|
||||
else
|
||||
else {
|
||||
deauthenticatePlayer(player);
|
||||
playerCache = deauthenticatedUsers.get(uuid);
|
||||
}
|
||||
|
||||
if(config.main.spawnOnJoin)
|
||||
teleportPlayer(player, true);
|
||||
|
||||
|
||||
// Tries to rescue player from nether portal
|
||||
if(config.main.tryPortalRescue && player.getBlockState().getBlock().equals(Blocks.NETHER_PORTAL)) {
|
||||
boolean wasSuccessful = false;
|
||||
BlockPos pos = player.getBlockPos();
|
||||
|
||||
BlockState portalState = player.getBlockState();
|
||||
World world = player.getEntityWorld();
|
||||
// Faking portal blocks to be air
|
||||
BlockUpdateS2CPacket feetPacket = new BlockUpdateS2CPacket();
|
||||
((BlockUpdateS2CPacketAccessor) feetPacket).setState(new BlockState(Blocks.AIR, null));
|
||||
((BlockUpdateS2CPacketAccessor) feetPacket).setBlockPos(pos);
|
||||
player.networkHandler.sendPacket(feetPacket);
|
||||
|
||||
double x = player.getX();
|
||||
double y = player.getY();
|
||||
double z = player.getZ();
|
||||
BlockUpdateS2CPacket headPacket = new BlockUpdateS2CPacket();
|
||||
((BlockUpdateS2CPacketAccessor) headPacket).setState(new BlockState(Blocks.AIR, null));
|
||||
((BlockUpdateS2CPacketAccessor) headPacket).setBlockPos(pos.up());
|
||||
player.networkHandler.sendPacket(headPacket);
|
||||
|
||||
if(portalState.get(AXIS) == Z) {
|
||||
// Player should be put to eastern or western block
|
||||
if( // Checking towards east
|
||||
world.getBlockState(new BlockPos(x + 1, y, z)).isAir() &&
|
||||
world.getBlockState(new BlockPos(x + 1, y + 1, z)).isAir() &&
|
||||
(
|
||||
world.getBlockState(new BlockPos(x + 1, y - 1, z)).isOpaque() ||
|
||||
world.getBlockState(new BlockPos(x + 1, y - 1, z)).hasSolidTopSurface(world, new BlockPos(x + 1, y - 1, z), player)
|
||||
)
|
||||
) {
|
||||
x++; // Towards east
|
||||
wasSuccessful = true;
|
||||
}
|
||||
|
||||
else if( // Checking towards south
|
||||
world.getBlockState(new BlockPos(x - 1, y, z)).isAir() &&
|
||||
world.getBlockState(new BlockPos(x - 1, y + 1, z)).isAir() &&
|
||||
(
|
||||
world.getBlockState(new BlockPos(x - 1, y - 1, z)).isOpaque() ||
|
||||
world.getBlockState(new BlockPos(x - 1, y - 1, z)).hasSolidTopSurface(world, new BlockPos(x - 1, y - 1, z), player)
|
||||
)
|
||||
) {
|
||||
x--; // Towards south
|
||||
wasSuccessful = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Player should be put to northern or southern block
|
||||
if( // Checking towards south
|
||||
world.getBlockState(new BlockPos(x, y, z + 1)).isAir() &&
|
||||
world.getBlockState(new BlockPos(x, y + 1, z + 1)).isAir() &&
|
||||
(
|
||||
world.getBlockState(new BlockPos(x, y - 1, z + 1)).isOpaque() ||
|
||||
world.getBlockState(new BlockPos(x, y - 1, z + 1)).hasSolidTopSurface(world, new BlockPos(x, y - 1, z + 1), player)
|
||||
)
|
||||
) {
|
||||
z++; // Towards south
|
||||
wasSuccessful = true;
|
||||
}
|
||||
|
||||
else if( // Checking towards north
|
||||
world.getBlockState(new BlockPos(x, y, z - 1)).isAir() &&
|
||||
world.getBlockState(new BlockPos(x, y + 1, z - 1)).isAir() &&
|
||||
(
|
||||
world.getBlockState(new BlockPos(x, y - 1, z - 1)).isOpaque() ||
|
||||
world.getBlockState(new BlockPos(x, y - 1, z - 1)).hasSolidTopSurface(world, new BlockPos(x, y - 1, z - 1), player)
|
||||
)
|
||||
) {
|
||||
z--; // Towards north
|
||||
wasSuccessful = true;
|
||||
}
|
||||
}
|
||||
if(wasSuccessful) {
|
||||
player.teleport(x, y, z);
|
||||
player.sendMessage(successfulPortalRescue, false);
|
||||
}
|
||||
// Teleporting player to the middle of the block
|
||||
player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
|
||||
playerCache.wasInPortal = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.samo_lego.simpleauth.mixin;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(BlockUpdateS2CPacket.class)
|
||||
public interface BlockUpdateS2CPacketAccessor {
|
||||
@Accessor("state")
|
||||
void setState(BlockState state);
|
||||
|
||||
@Accessor("pos")
|
||||
void setBlockPos(BlockPos pos);
|
||||
}
|
|
@ -23,6 +23,7 @@ public class PlayerCache {
|
|||
public double lastZ;
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
public boolean wasInPortal;
|
||||
|
||||
|
||||
public PlayerCache(String uuid, ServerPlayerEntity player) {
|
||||
|
@ -90,5 +91,6 @@ public class PlayerCache {
|
|||
}
|
||||
this.wasAuthenticated = false;
|
||||
this.loginTries = 0;
|
||||
this.wasInPortal = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
"required": true,
|
||||
"package": "org.samo_lego.simpleauth.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
],
|
||||
"mixins": [],
|
||||
"server": [
|
||||
"BlockUpdateS2CPacketAccessor",
|
||||
"MixinPlayerEntity",
|
||||
"MixinPlayerManager",
|
||||
"MixinServerPlayNetworkHandler",
|
||||
|
|
Loading…
Reference in New Issue