From 653823e2ee639531bd532954ed5b77636a6b0dfe Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:54:18 +0200 Subject: [PATCH] Merging changes --- .../org/samo_lego/simpleauth/SimpleAuth.java | 22 +++++------------ .../simpleauth/mixin/MixinPlayerEntity.java | 5 ++-- .../simpleauth/storage/PlayerCache.java | 24 ++++--------------- .../simpleauth/storage/database/MongoDB.java | 7 ------ 4 files changed, 12 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java index e3cfb70..4b8f910 100644 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java @@ -6,14 +6,6 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.player.*; import net.fabricmc.loader.api.FabricLoader; 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 org.samo_lego.simpleauth.commands.*; import org.samo_lego.simpleauth.event.AuthEventHandler; import org.samo_lego.simpleauth.event.entity.player.*; @@ -33,8 +25,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import static org.iq80.leveldb.impl.Iq80DBFactory.bytes; -import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake; import static org.samo_lego.simpleauth.commands.AuthCommand.reloadConfig; import static org.samo_lego.simpleauth.event.AuthEventHandler.*; import static org.samo_lego.simpleauth.utils.SimpleLogger.logError; @@ -104,12 +94,12 @@ public class SimpleAuth implements DedicatedServerModInitializer { PlayerMoveCallback.EVENT.register(AuthEventHandler::onPlayerMove); // From Fabric API - AttackBlockCallback.EVENT.register((playerEntity, world, hand, blockPos, direction) -> AuthEventHandler.onAttackBlock(playerEntity)); - UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> AuthEventHandler.onUseBlock(player)); - UseItemCallback.EVENT.register((player, world, hand) -> AuthEventHandler.onUseItem(player)); - AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onAttackEntity(player)); - UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onUseEntity(player)); - ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> AuthCommand.reloadConfig(null)); + PlayerBlockBreakEvents.BEFORE.register((world, player, blockPos, blockState, blockEntity) -> onBreakBlock(player)); + UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> onUseBlock(player)); + UseItemCallback.EVENT.register((player, world, hand) -> onUseItem(player)); + AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onAttackEntity(player)); + UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onUseEntity(player)); + ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> reloadConfig(null)); ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer); } diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java index 674c9a3..0b430c6 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerEntity.java @@ -23,8 +23,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import static org.samo_lego.simpleauth.SimpleAuth.config; -import static org.samo_lego.simpleauth.SimpleAuth.playerCacheMap; +import static org.samo_lego.simpleauth.SimpleAuth.*; import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake; @Mixin(PlayerEntity.class) @@ -114,7 +113,7 @@ public abstract class MixinPlayerEntity implements PlayerAuth { if(!playerCacheMap.containsKey(this.getFakeUuid())) { // First join - playerCache = new PlayerCache(this.getFakeUuid(), player); + playerCache = PlayerCache.fromJson(player, DB.getUserData(this.getFakeUuid())); playerCacheMap.put(this.getFakeUuid(), playerCache); } else { 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 523039a..fe1a79b 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java @@ -5,13 +5,7 @@ import com.google.gson.JsonObject; import net.minecraft.block.Blocks; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.registry.Registry; -import net.minecraft.util.registry.RegistryKey; - -import java.util.Objects; import java.util.Objects; @@ -133,12 +127,10 @@ public class PlayerCache { playerCache.wasOnFire = player.isOnFire(); // Setting position cache - playerCache.lastLocation.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue()); - playerCache.lastLocation.lastX = player.getX(); - playerCache.lastLocation.lastY = player.getY(); - playerCache.lastLocation.lastZ = player.getZ(); - playerCache.lastLocation.lastYaw = player.yaw; - playerCache.lastLocation.lastPitch = player.pitch; + playerCache.lastLocation.dimension = player.getServerWorld(); + playerCache.lastLocation.position = player.getPos(); + playerCache.lastLocation.yaw = player.yaw; + playerCache.lastLocation.pitch = player.pitch; } else { playerCache.wasInPortal = false; @@ -153,14 +145,6 @@ public class PlayerCache { JsonObject cacheJson = new JsonObject(); cacheJson.addProperty("password", this.password); - JsonObject lastLocation = new JsonObject(); - lastLocation.addProperty("dim", this.lastLocation.lastDim); - lastLocation.addProperty("x", this.lastLocation.lastX); - lastLocation.addProperty("y", this.lastLocation.lastY); - lastLocation.addProperty("z", this.lastLocation.lastZ); - - cacheJson.addProperty("lastLocation", lastLocation.toString()); - return cacheJson; } } diff --git a/src/main/java/org/samo_lego/simpleauth/storage/database/MongoDB.java b/src/main/java/org/samo_lego/simpleauth/storage/database/MongoDB.java index c53af10..0d58bf0 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/database/MongoDB.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/database/MongoDB.java @@ -59,16 +59,10 @@ public class MongoDB { List> updateList = new ArrayList<>(); playerCacheMap.forEach((uuid, playerCache) -> { // Save as BSON not JSON stringified - Document lastLocation = new Document("x", playerCache.lastX) - .append("y", playerCache.lastY) - .append("z", playerCache.lastZ) - .append("dimension", playerCache.lastDim); - if(!isUserRegistered(uuid)) { writeList.add(new InsertOneModel<>( new Document("UUID", uuid) .append("password", playerCache.password) - .append("lastLocation", lastLocation) ) ); } @@ -76,7 +70,6 @@ public class MongoDB { updateList.add(new ReplaceOneModel<>(eq("UUID", uuid), new Document("UUID", uuid) .append("password", playerCache.password) - .append("lastLocation", lastLocation) ) ); }