diff --git a/gradle.properties b/gradle.properties index b0c3eeb..5452531 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx1G # Fabric properties minecraft_version=20w21a -yarn_mappings=20w21a+build.2 +yarn_mappings=20w21a+build.16 loader_version=0.8.4+build.198 #Fabric api -fabric_version=0.10.9+build.346-1.16 +fabric_version=0.10.10+build.347-1.16 # Mod Properties mod_version = 1.4.3 diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java index 54c102c..7409b54 100644 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java @@ -12,6 +12,7 @@ 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.util.registry.Registry; import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType; import org.apache.logging.log4j.LogManager; @@ -123,7 +124,7 @@ public class SimpleAuth implements DedicatedServerModInitializer { data.addProperty("password", playerCache.password); JsonObject lastLocation = new JsonObject(); - lastLocation.addProperty("dimId", playerCache.lastDimId); + lastLocation.addProperty("dim", playerCache.lastDim.toString()); lastLocation.addProperty("x", playerCache.lastX); lastLocation.addProperty("y", playerCache.lastY); lastLocation.addProperty("z", playerCache.lastZ); @@ -216,10 +217,11 @@ public class SimpleAuth implements DedicatedServerModInitializer { MinecraftServer server = player.getServer(); if(server == null) return; + Registry registry = server.method_29174().getRegistry(); if (toSpawn) { // Teleports player to spawn player.teleport( - server.getWorld(DimensionType.byRawId(config.worldSpawn.dimensionId)), + server.getWorld(registry.getKey(config.worldSpawn.dimension)), config.worldSpawn.x, config.worldSpawn.y, config.worldSpawn.z, @@ -231,7 +233,7 @@ public class SimpleAuth implements DedicatedServerModInitializer { PlayerCache cache = deauthenticatedUsers.get(convertUuid(player)); // Puts player to last cached position player.teleport( - server.getWorld(DimensionType.byRawId(cache.lastDimId)), + server.getWorld(registry.getKey(cache.lastDim)), cache.lastX, cache.lastY, cache.lastZ, diff --git a/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java index 7a6b3f5..1b2310c 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/AuthCommand.java @@ -3,10 +3,14 @@ package org.samo_lego.simpleauth.commands; import com.google.gson.JsonObject; import com.mojang.brigadier.CommandDispatcher; import net.minecraft.command.arguments.BlockPosArgumentType; +import net.minecraft.command.arguments.DimensionArgumentType; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.ServerCommandSource; 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.Logger; 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 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.word; import static net.minecraft.server.command.CommandManager.argument; @@ -28,7 +29,7 @@ import static org.samo_lego.simpleauth.SimpleAuth.db; public class AuthCommand { private static final Logger LOGGER = LogManager.getLogger(); - + public static void registerCommand(CommandDispatcher dispatcher) { // Registering the "/auth" command dispatcher.register(literal("auth") @@ -47,22 +48,29 @@ public class AuthCommand { .then(literal("setSpawn") .executes( ctx -> setSpawn( ctx.getSource(), - Objects.requireNonNull(ctx.getSource().getEntity()).dimension.getRawId(), - ctx.getSource().getEntity().getX(), - ctx.getSource().getEntity().getY(), - ctx.getSource().getEntity().getZ() + ctx.getSource().getWorld().getDimension(), + ctx.getSource().getEntityOrThrow().getX(), + ctx.getSource().getEntityOrThrow().getY(), + ctx.getSource().getEntityOrThrow().getZ() )) - .then(argument("dimension id", integer()) + .then(argument("dimension", DimensionArgumentType.dimension()) .then(argument("position", BlockPosArgumentType.blockPos()) - .executes(ctx -> setSpawn( - ctx.getSource(), - getInteger(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() - )) + .executes(ctx -> { + RegistryKey registryKey = DimensionArgumentType.getDimensionArgument(ctx, "dimension"); + Registry registry = ctx.getSource().getWorld().getServer().method_29174().getRegistry(); + //RegistryKey registryKey = ctx.getSource().getEntityOrThrow().getEntityWorld().method_27983(); + return setSpawn( + ctx.getSource(), + 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") @@ -127,14 +135,14 @@ public class AuthCommand { } // - private static int setSpawn(ServerCommandSource source, int dimensionId, double x, double y, double z) { - config.worldSpawn.dimensionId = dimensionId; + private static int setSpawn(ServerCommandSource source, DimensionType dimension, double x, double y, double z) { + config.worldSpawn.dimension = dimension; config.worldSpawn.x = x; config.worldSpawn.y = y; config.worldSpawn.z = z; Entity sender = source.getEntity(); if(sender != null) - sender.sendSystemMessage(new LiteralText(config.lang.worldSpawnSet)); + ((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.worldSpawnSet), false); else LOGGER.info(config.lang.worldSpawnSet); return 1; diff --git a/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java b/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java index dc07531..f8c2f13 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java @@ -19,6 +19,7 @@ package org.samo_lego.simpleauth.storage; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import net.minecraft.world.dimension.DimensionType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -55,9 +56,10 @@ public class AuthConfig { // Visit https://github.com/samolego/SimpleAuth/wiki/Sessions for more info public int sessionTimeoutTime = 60; + // Whether to tp player to spawn when joining (to hide coordinates) public boolean spawnOnJoin = false; public static class WorldSpawn { - public int dimensionId; + public DimensionType dimension; public double x; public double y; public double z; diff --git a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java b/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java index f7d43bf..74261d6 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java @@ -5,6 +5,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; 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.db; @@ -17,7 +21,7 @@ public class PlayerCache { public String lastIp; public long validUntil; - public int lastDimId; + public DimensionType lastDim; public double lastX; public double lastY; public double lastZ; @@ -43,7 +47,7 @@ public class PlayerCache { this.lastIp = ""; // Setting last coordinates - this.lastDimId = config.worldSpawn.dimensionId; + this.lastDim = config.worldSpawn.dimension; this.lastX = config.worldSpawn.x; this.lastY = config.worldSpawn.y; this.lastZ = config.worldSpawn.z; @@ -63,14 +67,16 @@ public class PlayerCache { JsonElement lastLoc = json.get("lastLocation"); if ( lastLoc != null && - this.lastDimId == config.worldSpawn.dimensionId && + this.lastDim == config.worldSpawn.dimension && this.lastX == config.worldSpawn.x && this.lastY == config.worldSpawn.y && this.lastZ == config.worldSpawn.z ) { // Getting DB coords 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.lastY = lastLocation.get("y").getAsDouble(); this.lastZ = lastLocation.get("z").getAsDouble();