Fixing dimension mess from previous snapshot.

This commit is contained in:
samo_lego 2020-05-27 12:03:23 +02:00
parent 4c01a1a6ab
commit 782f6fbabe
5 changed files with 48 additions and 30 deletions

View File

@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx1G
# Fabric properties # Fabric properties
minecraft_version=20w21a minecraft_version=20w21a
yarn_mappings=20w21a+build.2 yarn_mappings=20w21a+build.16
loader_version=0.8.4+build.198 loader_version=0.8.4+build.198
#Fabric api #Fabric api
fabric_version=0.10.9+build.346-1.16 fabric_version=0.10.10+build.347-1.16
# Mod Properties # Mod Properties
mod_version = 1.4.3 mod_version = 1.4.3

View File

@ -12,6 +12,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -123,7 +124,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
data.addProperty("password", playerCache.password); data.addProperty("password", playerCache.password);
JsonObject lastLocation = new JsonObject(); JsonObject lastLocation = new JsonObject();
lastLocation.addProperty("dimId", playerCache.lastDimId); lastLocation.addProperty("dim", playerCache.lastDim.toString());
lastLocation.addProperty("x", playerCache.lastX); lastLocation.addProperty("x", playerCache.lastX);
lastLocation.addProperty("y", playerCache.lastY); lastLocation.addProperty("y", playerCache.lastY);
lastLocation.addProperty("z", playerCache.lastZ); lastLocation.addProperty("z", playerCache.lastZ);
@ -216,10 +217,11 @@ public class SimpleAuth implements DedicatedServerModInitializer {
MinecraftServer server = player.getServer(); MinecraftServer server = player.getServer();
if(server == null) if(server == null)
return; return;
Registry<DimensionType> registry = server.method_29174().getRegistry();
if (toSpawn) { if (toSpawn) {
// Teleports player to spawn // Teleports player to spawn
player.teleport( player.teleport(
server.getWorld(DimensionType.byRawId(config.worldSpawn.dimensionId)), server.getWorld(registry.getKey(config.worldSpawn.dimension)),
config.worldSpawn.x, config.worldSpawn.x,
config.worldSpawn.y, config.worldSpawn.y,
config.worldSpawn.z, config.worldSpawn.z,
@ -231,7 +233,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
PlayerCache cache = deauthenticatedUsers.get(convertUuid(player)); PlayerCache cache = deauthenticatedUsers.get(convertUuid(player));
// Puts player to last cached position // Puts player to last cached position
player.teleport( player.teleport(
server.getWorld(DimensionType.byRawId(cache.lastDimId)), server.getWorld(registry.getKey(cache.lastDim)),
cache.lastX, cache.lastX,
cache.lastY, cache.lastY,
cache.lastZ, cache.lastZ,

View File

@ -3,10 +3,14 @@ package org.samo_lego.simpleauth.commands;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.arguments.BlockPosArgumentType; import net.minecraft.command.arguments.BlockPosArgumentType;
import net.minecraft.command.arguments.DimensionArgumentType;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.dimension.DimensionType;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.samo_lego.simpleauth.SimpleAuth; import org.samo_lego.simpleauth.SimpleAuth;
@ -15,10 +19,7 @@ import org.samo_lego.simpleauth.storage.PlayerCache;
import org.samo_lego.simpleauth.utils.AuthHelper; import org.samo_lego.simpleauth.utils.AuthHelper;
import java.io.File; import java.io.File;
import java.util.Objects;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static com.mojang.brigadier.arguments.StringArgumentType.getString; import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.word; import static com.mojang.brigadier.arguments.StringArgumentType.word;
import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.argument;
@ -47,22 +48,29 @@ public class AuthCommand {
.then(literal("setSpawn") .then(literal("setSpawn")
.executes( ctx -> setSpawn( .executes( ctx -> setSpawn(
ctx.getSource(), ctx.getSource(),
Objects.requireNonNull(ctx.getSource().getEntity()).dimension.getRawId(), ctx.getSource().getWorld().getDimension(),
ctx.getSource().getEntity().getX(), ctx.getSource().getEntityOrThrow().getX(),
ctx.getSource().getEntity().getY(), ctx.getSource().getEntityOrThrow().getY(),
ctx.getSource().getEntity().getZ() ctx.getSource().getEntityOrThrow().getZ()
)) ))
.then(argument("dimension id", integer()) .then(argument("dimension", DimensionArgumentType.dimension())
.then(argument("position", BlockPosArgumentType.blockPos()) .then(argument("position", BlockPosArgumentType.blockPos())
.executes(ctx -> setSpawn( .executes(ctx -> {
ctx.getSource(), RegistryKey<DimensionType> registryKey = DimensionArgumentType.getDimensionArgument(ctx, "dimension");
getInteger(ctx, "dimension id"), Registry<DimensionType> registry = ctx.getSource().getWorld().getServer().method_29174().getRegistry();
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getX(), //RegistryKey<DimensionType> registryKey = ctx.getSource().getEntityOrThrow().getEntityWorld().method_27983();
// +1 to not spawn player in ground return setSpawn(
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getY() + 1, ctx.getSource(),
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getZ() registry.get(registryKey),
)) //(ctx, "dimension id"),
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getX(),
// +1 to not spawn player in ground
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getY() + 1,
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getZ()
);
}
) )
)
) )
) )
.then(literal("remove") .then(literal("remove")
@ -127,14 +135,14 @@ public class AuthCommand {
} }
// //
private static int setSpawn(ServerCommandSource source, int dimensionId, double x, double y, double z) { private static int setSpawn(ServerCommandSource source, DimensionType dimension, double x, double y, double z) {
config.worldSpawn.dimensionId = dimensionId; config.worldSpawn.dimension = dimension;
config.worldSpawn.x = x; config.worldSpawn.x = x;
config.worldSpawn.y = y; config.worldSpawn.y = y;
config.worldSpawn.z = z; config.worldSpawn.z = z;
Entity sender = source.getEntity(); Entity sender = source.getEntity();
if(sender != null) if(sender != null)
sender.sendSystemMessage(new LiteralText(config.lang.worldSpawnSet)); ((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.worldSpawnSet), false);
else else
LOGGER.info(config.lang.worldSpawnSet); LOGGER.info(config.lang.worldSpawnSet);
return 1; return 1;

View File

@ -19,6 +19,7 @@ package org.samo_lego.simpleauth.storage;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import net.minecraft.world.dimension.DimensionType;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -55,9 +56,10 @@ public class AuthConfig {
// Visit https://github.com/samolego/SimpleAuth/wiki/Sessions for more info // Visit https://github.com/samolego/SimpleAuth/wiki/Sessions for more info
public int sessionTimeoutTime = 60; public int sessionTimeoutTime = 60;
// Whether to tp player to spawn when joining (to hide coordinates)
public boolean spawnOnJoin = false; public boolean spawnOnJoin = false;
public static class WorldSpawn { public static class WorldSpawn {
public int dimensionId; public DimensionType dimension;
public double x; public double x;
public double y; public double y;
public double z; public double z;

View File

@ -5,6 +5,10 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.world.dimension.DimensionType;
import java.util.Objects;
import static org.samo_lego.simpleauth.SimpleAuth.config; import static org.samo_lego.simpleauth.SimpleAuth.config;
import static org.samo_lego.simpleauth.SimpleAuth.db; import static org.samo_lego.simpleauth.SimpleAuth.db;
@ -17,7 +21,7 @@ public class PlayerCache {
public String lastIp; public String lastIp;
public long validUntil; public long validUntil;
public int lastDimId; public DimensionType lastDim;
public double lastX; public double lastX;
public double lastY; public double lastY;
public double lastZ; public double lastZ;
@ -43,7 +47,7 @@ public class PlayerCache {
this.lastIp = ""; this.lastIp = "";
// Setting last coordinates // Setting last coordinates
this.lastDimId = config.worldSpawn.dimensionId; this.lastDim = config.worldSpawn.dimension;
this.lastX = config.worldSpawn.x; this.lastX = config.worldSpawn.x;
this.lastY = config.worldSpawn.y; this.lastY = config.worldSpawn.y;
this.lastZ = config.worldSpawn.z; this.lastZ = config.worldSpawn.z;
@ -63,14 +67,16 @@ public class PlayerCache {
JsonElement lastLoc = json.get("lastLocation"); JsonElement lastLoc = json.get("lastLocation");
if ( if (
lastLoc != null && lastLoc != null &&
this.lastDimId == config.worldSpawn.dimensionId && this.lastDim == config.worldSpawn.dimension &&
this.lastX == config.worldSpawn.x && this.lastX == config.worldSpawn.x &&
this.lastY == config.worldSpawn.y && this.lastY == config.worldSpawn.y &&
this.lastZ == config.worldSpawn.z this.lastZ == config.worldSpawn.z
) { ) {
// Getting DB coords // Getting DB coords
JsonObject lastLocation = gson.fromJson(lastLoc.getAsString(), JsonObject.class); JsonObject lastLocation = gson.fromJson(lastLoc.getAsString(), JsonObject.class);
this.lastDimId = lastLocation.get("dimId").getAsInt(); String dim = lastLocation.get("dim").getAsString();
// Extra long line to get dimension from string
this.lastDim = Objects.requireNonNull(Objects.requireNonNull(player).getServer()).method_29174().getRegistry().get(new Identifier(dim));
this.lastX = lastLocation.get("x").getAsDouble(); this.lastX = lastLocation.get("x").getAsDouble();
this.lastY = lastLocation.get("y").getAsDouble(); this.lastY = lastLocation.get("y").getAsDouble();
this.lastZ = lastLocation.get("z").getAsDouble(); this.lastZ = lastLocation.get("z").getAsDouble();