Merging changes

This commit is contained in:
samo_lego 2020-10-16 22:54:18 +02:00
parent ae8cdd38fd
commit 653823e2ee
4 changed files with 12 additions and 46 deletions

View File

@ -6,14 +6,6 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.player.*; import net.fabricmc.fabric.api.event.player.*;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.MinecraftServer; 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.commands.*;
import org.samo_lego.simpleauth.event.AuthEventHandler; import org.samo_lego.simpleauth.event.AuthEventHandler;
import org.samo_lego.simpleauth.event.entity.player.*; 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.Executors;
import java.util.concurrent.TimeUnit; 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.commands.AuthCommand.reloadConfig;
import static org.samo_lego.simpleauth.event.AuthEventHandler.*; import static org.samo_lego.simpleauth.event.AuthEventHandler.*;
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError; import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
@ -104,12 +94,12 @@ public class SimpleAuth implements DedicatedServerModInitializer {
PlayerMoveCallback.EVENT.register(AuthEventHandler::onPlayerMove); PlayerMoveCallback.EVENT.register(AuthEventHandler::onPlayerMove);
// From Fabric API // From Fabric API
AttackBlockCallback.EVENT.register((playerEntity, world, hand, blockPos, direction) -> AuthEventHandler.onAttackBlock(playerEntity)); PlayerBlockBreakEvents.BEFORE.register((world, player, blockPos, blockState, blockEntity) -> onBreakBlock(player));
UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> AuthEventHandler.onUseBlock(player)); UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> onUseBlock(player));
UseItemCallback.EVENT.register((player, world, hand) -> AuthEventHandler.onUseItem(player)); UseItemCallback.EVENT.register((player, world, hand) -> onUseItem(player));
AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onAttackEntity(player)); AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onAttackEntity(player));
UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onUseEntity(player)); UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onUseEntity(player));
ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> AuthCommand.reloadConfig(null)); ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> reloadConfig(null));
ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer); ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer);
} }

View File

@ -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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import static org.samo_lego.simpleauth.SimpleAuth.config; import static org.samo_lego.simpleauth.SimpleAuth.*;
import static org.samo_lego.simpleauth.SimpleAuth.playerCacheMap;
import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake; import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake;
@Mixin(PlayerEntity.class) @Mixin(PlayerEntity.class)
@ -114,7 +113,7 @@ public abstract class MixinPlayerEntity implements PlayerAuth {
if(!playerCacheMap.containsKey(this.getFakeUuid())) { if(!playerCacheMap.containsKey(this.getFakeUuid())) {
// First join // First join
playerCache = new PlayerCache(this.getFakeUuid(), player); playerCache = PlayerCache.fromJson(player, DB.getUserData(this.getFakeUuid()));
playerCacheMap.put(this.getFakeUuid(), playerCache); playerCacheMap.put(this.getFakeUuid(), playerCache);
} }
else { else {

View File

@ -5,13 +5,7 @@ import com.google.gson.JsonObject;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; 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.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import java.util.Objects;
import java.util.Objects; import java.util.Objects;
@ -133,12 +127,10 @@ public class PlayerCache {
playerCache.wasOnFire = player.isOnFire(); playerCache.wasOnFire = player.isOnFire();
// Setting position cache // Setting position cache
playerCache.lastLocation.lastDim = String.valueOf(player.getEntityWorld().getRegistryKey().getValue()); playerCache.lastLocation.dimension = player.getServerWorld();
playerCache.lastLocation.lastX = player.getX(); playerCache.lastLocation.position = player.getPos();
playerCache.lastLocation.lastY = player.getY(); playerCache.lastLocation.yaw = player.yaw;
playerCache.lastLocation.lastZ = player.getZ(); playerCache.lastLocation.pitch = player.pitch;
playerCache.lastLocation.lastYaw = player.yaw;
playerCache.lastLocation.lastPitch = player.pitch;
} }
else { else {
playerCache.wasInPortal = false; playerCache.wasInPortal = false;
@ -153,14 +145,6 @@ public class PlayerCache {
JsonObject cacheJson = new JsonObject(); JsonObject cacheJson = new JsonObject();
cacheJson.addProperty("password", this.password); 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; return cacheJson;
} }
} }

View File

@ -59,16 +59,10 @@ public class MongoDB {
List<ReplaceOneModel<Document>> updateList = new ArrayList<>(); List<ReplaceOneModel<Document>> updateList = new ArrayList<>();
playerCacheMap.forEach((uuid, playerCache) -> { playerCacheMap.forEach((uuid, playerCache) -> {
// Save as BSON not JSON stringified // 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)) { if(!isUserRegistered(uuid)) {
writeList.add(new InsertOneModel<>( writeList.add(new InsertOneModel<>(
new Document("UUID", uuid) new Document("UUID", uuid)
.append("password", playerCache.password) .append("password", playerCache.password)
.append("lastLocation", lastLocation)
) )
); );
} }
@ -76,7 +70,6 @@ public class MongoDB {
updateList.add(new ReplaceOneModel<>(eq("UUID", uuid), updateList.add(new ReplaceOneModel<>(eq("UUID", uuid),
new Document("UUID", uuid) new Document("UUID", uuid)
.append("password", playerCache.password) .append("password", playerCache.password)
.append("lastLocation", lastLocation)
) )
); );
} }