Done updating DIM stuff :)
This commit is contained in:
parent
4223536e49
commit
7dfe1ff5b3
|
@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||
|
||||
# Fabric properties
|
||||
minecraft_version=20w21a
|
||||
yarn_mappings=20w21a+build.16
|
||||
yarn_mappings=20w21a+build.19
|
||||
loader_version=0.8.4+build.198
|
||||
|
||||
#Fabric api
|
||||
|
|
|
@ -11,10 +11,11 @@ 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.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.iq80.leveldb.WriteBatch;
|
||||
|
@ -117,14 +118,14 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
private static void onStopServer() {
|
||||
LOGGER.info("[SimpleAuth] Shutting down SimpleAuth.");
|
||||
|
||||
WriteBatch batch = db.levelDBStore.createWriteBatch();
|
||||
WriteBatch batch = db.getLevelDBStore().createWriteBatch();
|
||||
// Writing coords of de-authenticated players to database
|
||||
deauthenticatedUsers.forEach((uuid, playerCache) -> {
|
||||
JsonObject data = new JsonObject();
|
||||
data.addProperty("password", playerCache.password);
|
||||
|
||||
JsonObject lastLocation = new JsonObject();
|
||||
lastLocation.addProperty("dim", playerCache.lastDim.toString());
|
||||
lastLocation.addProperty("dim", playerCache.lastDim);
|
||||
lastLocation.addProperty("x", playerCache.lastX);
|
||||
lastLocation.addProperty("y", playerCache.lastY);
|
||||
lastLocation.addProperty("z", playerCache.lastZ);
|
||||
|
@ -135,7 +136,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
});
|
||||
try {
|
||||
// Writing and closing batch
|
||||
db.levelDBStore.write(batch);
|
||||
db.getLevelDBStore().write(batch);
|
||||
batch.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("[SimpleAuth] Error saving player data! " + e.getMessage());
|
||||
|
@ -215,25 +216,25 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
// Teleports player to spawn or last location when authenticating
|
||||
public static void teleportPlayer(ServerPlayerEntity player, boolean toSpawn) {
|
||||
MinecraftServer server = player.getServer();
|
||||
if(server == null)
|
||||
if(server == null || config.worldSpawn.dimension == null)
|
||||
return;
|
||||
Registry<DimensionType> registry = server.method_29174().getRegistry();
|
||||
// registry for dimensions
|
||||
if (toSpawn) {
|
||||
// Teleports player to spawn
|
||||
player.teleport(
|
||||
server.getWorld(registry.getKey(config.worldSpawn.dimension)),
|
||||
server.getWorld(RegistryKey.of(Registry.DIMENSION_TYPE_KEY, new Identifier(config.worldSpawn.dimension))),
|
||||
config.worldSpawn.x,
|
||||
config.worldSpawn.y,
|
||||
config.worldSpawn.z,
|
||||
0,
|
||||
0
|
||||
90,
|
||||
90
|
||||
);
|
||||
return;
|
||||
}
|
||||
PlayerCache cache = deauthenticatedUsers.get(convertUuid(player));
|
||||
// Puts player to last cached position
|
||||
player.teleport(
|
||||
server.getWorld(registry.getKey(cache.lastDim)),
|
||||
server.getWorld(RegistryKey.of(Registry.DIMENSION_TYPE_KEY, new Identifier(cache.lastDim))),
|
||||
cache.lastX,
|
||||
cache.lastY,
|
||||
cache.lastZ,
|
||||
|
|
|
@ -19,6 +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.StringArgumentType.getString;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
||||
|
@ -58,10 +59,9 @@ public class AuthCommand {
|
|||
.executes(ctx -> {
|
||||
RegistryKey<DimensionType> registryKey = DimensionArgumentType.getDimensionArgument(ctx, "dimension");
|
||||
Registry<DimensionType> registry = ctx.getSource().getWorld().getServer().method_29174().getRegistry();
|
||||
//RegistryKey<DimensionType> registryKey = ctx.getSource().getEntityOrThrow().getEntityWorld().method_27983();
|
||||
return setSpawn(
|
||||
ctx.getSource(),
|
||||
registry.get(registryKey),
|
||||
Objects.requireNonNull(registry.get(registryKey)),
|
||||
//(ctx, "dimension id"),
|
||||
BlockPosArgumentType.getLoadedBlockPos(ctx, "position").getX(),
|
||||
// +1 to not spawn player in ground
|
||||
|
@ -136,10 +136,17 @@ public class AuthCommand {
|
|||
|
||||
//
|
||||
private static int setSpawn(ServerCommandSource source, DimensionType dimension, double x, double y, double z) {
|
||||
config.worldSpawn.dimension = dimension;
|
||||
// Getting dimension regitry
|
||||
Registry<DimensionType> registry = source.getWorld().getServer().method_29174().getRegistry();
|
||||
|
||||
// Setting config values and saving
|
||||
config.worldSpawn.dimension = String.valueOf(registry.getId(dimension));
|
||||
config.worldSpawn.x = x;
|
||||
config.worldSpawn.y = y;
|
||||
config.worldSpawn.z = z;
|
||||
config.save(new File("./mods/SimpleAuth/config.json"));
|
||||
|
||||
// Getting sender
|
||||
Entity sender = source.getEntity();
|
||||
if(sender != null)
|
||||
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.worldSpawnSet), false);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.samo_lego.simpleauth.event;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -111,14 +110,15 @@ public class AuthEventHandler {
|
|||
|
||||
// Faking portal blocks to be air
|
||||
BlockUpdateS2CPacket feetPacket = new BlockUpdateS2CPacket();
|
||||
((BlockUpdateS2CPacketAccessor) feetPacket).setState(new BlockState(Blocks.AIR, null, null));
|
||||
((BlockUpdateS2CPacketAccessor) feetPacket).setState(Blocks.AIR.getDefaultState());
|
||||
((BlockUpdateS2CPacketAccessor) feetPacket).setBlockPos(pos);
|
||||
player.networkHandler.sendPacket(feetPacket);
|
||||
|
||||
BlockUpdateS2CPacket headPacket = new BlockUpdateS2CPacket();
|
||||
((BlockUpdateS2CPacketAccessor) headPacket).setState(new BlockState(Blocks.AIR, null, null));
|
||||
((BlockUpdateS2CPacketAccessor) headPacket).setState(Blocks.AIR.getDefaultState());
|
||||
((BlockUpdateS2CPacketAccessor) headPacket).setBlockPos(pos.up());
|
||||
player.networkHandler.sendPacket(headPacket);
|
||||
System.out.println(headPacket);
|
||||
|
||||
// Teleporting player to the middle of the block
|
||||
player.teleport(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
|
||||
|
|
|
@ -19,7 +19,6 @@ 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;
|
||||
|
||||
|
@ -59,7 +58,7 @@ public class AuthConfig {
|
|||
// Whether to tp player to spawn when joining (to hide coordinates)
|
||||
public boolean spawnOnJoin = false;
|
||||
public static class WorldSpawn {
|
||||
public DimensionType dimension;
|
||||
public String dimension;
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
|
|
|
@ -5,7 +5,7 @@ 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.util.registry.Registry;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -21,7 +21,7 @@ public class PlayerCache {
|
|||
public String lastIp;
|
||||
public long validUntil;
|
||||
|
||||
public DimensionType lastDim;
|
||||
public String lastDim;
|
||||
public double lastX;
|
||||
public double lastY;
|
||||
public double lastZ;
|
||||
|
@ -37,20 +37,17 @@ public class PlayerCache {
|
|||
if(player != null) {
|
||||
this.lastIp = player.getIp();
|
||||
|
||||
// Setting last coordinates
|
||||
this.lastDim = player.getEntityWorld().getDimension();
|
||||
// Getting dimension registry
|
||||
Registry<DimensionType> registry = Objects.requireNonNull(player.getServer()).method_29174().getRegistry();
|
||||
|
||||
// Setting position cache
|
||||
this.lastDim = String.valueOf(registry.getId(player.getEntityWorld().getDimension()));
|
||||
this.lastX = player.getX();
|
||||
this.lastY = player.getY();
|
||||
this.lastZ = player.getZ();
|
||||
}
|
||||
else {
|
||||
this.lastIp = "";
|
||||
|
||||
// Setting last coordinates
|
||||
this.lastDim = config.worldSpawn.dimension;
|
||||
this.lastX = config.worldSpawn.x;
|
||||
this.lastY = config.worldSpawn.y;
|
||||
this.lastZ = config.worldSpawn.z;
|
||||
}
|
||||
|
||||
if(db.isUserRegistered(uuid)) {
|
||||
|
@ -59,24 +56,18 @@ public class PlayerCache {
|
|||
// Getting (hashed) password
|
||||
JsonObject json = gson.fromJson(data, JsonObject.class);
|
||||
this.password = json.get("password").getAsString();
|
||||
this.isRegistered = true;
|
||||
|
||||
// If coordinates are same as the one from world spawn
|
||||
// we should check the DB for saved coords
|
||||
// We should check the DB for saved coords
|
||||
if(config.main.spawnOnJoin) {
|
||||
try {
|
||||
JsonElement lastLoc = json.get("lastLocation");
|
||||
if (
|
||||
lastLoc != null &&
|
||||
this.lastDim == config.worldSpawn.dimension &&
|
||||
this.lastX == config.worldSpawn.x &&
|
||||
this.lastY == config.worldSpawn.y &&
|
||||
this.lastZ == config.worldSpawn.z
|
||||
) {
|
||||
if (lastLoc != null) {
|
||||
// Getting DB coords
|
||||
JsonObject lastLocation = gson.fromJson(lastLoc.getAsString(), JsonObject.class);
|
||||
String dim = lastLocation.get("dim").getAsString();
|
||||
//String dim = Objects.requireNonNull(Objects.requireNonNull(player).getServer()).method_29174().getRegistry().get(new Identifier(dim));
|
||||
// Extra long line to get dimension from string
|
||||
this.lastDim = Objects.requireNonNull(Objects.requireNonNull(player).getServer()).method_29174().getRegistry().get(new Identifier(dim));
|
||||
this.lastDim = lastLocation.get("dim").getAsString();
|
||||
this.lastX = lastLocation.get("x").getAsDouble();
|
||||
this.lastY = lastLocation.get("y").getAsDouble();
|
||||
this.lastZ = lastLocation.get("z").getAsDouble();
|
||||
|
@ -89,7 +80,6 @@ public class PlayerCache {
|
|||
// Player didn't have any coords in db to tp to
|
||||
}
|
||||
}
|
||||
this.isRegistered = true;
|
||||
}
|
||||
else {
|
||||
this.isRegistered = false;
|
||||
|
|
|
@ -15,7 +15,11 @@ import static org.iq80.leveldb.impl.Iq80DBFactory.factory;
|
|||
|
||||
public class SimpleAuthDatabase {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public DB levelDBStore;
|
||||
private DB levelDBStore;
|
||||
|
||||
public DB getLevelDBStore() {
|
||||
return this.levelDBStore;
|
||||
}
|
||||
|
||||
// Connects to the DB
|
||||
public void openConnection() {
|
||||
|
|
Loading…
Reference in New Issue