Merging changes
This commit is contained in:
parent
ae8cdd38fd
commit
653823e2ee
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,16 +59,10 @@ public class MongoDB {
|
|||
List<ReplaceOneModel<Document>> 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)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue