Search in sources :

Example 1 with IMixinWorldInfo

use of org.spongepowered.common.interfaces.world.IMixinWorldInfo in project SpongeCommon by SpongePowered.

the class MixinSaveHandler method loadSpongeDatData.

@Override
public void loadSpongeDatData(WorldInfo info) throws IOException {
    final File spongeFile = new File(this.worldDirectory, "level_sponge.dat");
    final File spongeOldFile = new File(this.worldDirectory, "level_sponge.dat_old");
    if (spongeFile.exists() || spongeOldFile.exists()) {
        final NBTTagCompound compound = CompressedStreamTools.readCompressed(new FileInputStream(spongeFile.exists() ? spongeFile : spongeOldFile));
        ((IMixinWorldInfo) info).setSpongeRootLevelNBT(compound);
        if (compound.hasKey(NbtDataUtil.SPONGE_DATA)) {
            final NBTTagCompound spongeCompound = compound.getCompoundTag(NbtDataUtil.SPONGE_DATA);
            DataUtil.spongeDataFixer.process(FixTypes.LEVEL, spongeCompound);
            ((IMixinWorldInfo) info).readSpongeNbt(spongeCompound);
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with IMixinWorldInfo

use of org.spongepowered.common.interfaces.world.IMixinWorldInfo in project SpongeCommon by SpongePowered.

the class MixinChunk_Tracker method addTrackedBlockPosition.

@Override
public void addTrackedBlockPosition(Block block, BlockPos pos, User user, PlayerTracker.Type trackerType) {
    if (this.world.isRemote) {
        return;
    }
    if (PhaseTracker.getInstance().getCurrentState().ignoresBlockTracking()) {
        // Don't track chunk gen
        return;
    }
    // Don't track fake players
    if (user instanceof EntityPlayerMP && SpongeImplHooks.isFakePlayer((EntityPlayerMP) user)) {
        return;
    }
    if (!SpongeHooks.getActiveConfig((WorldServer) this.world).getConfig().getBlockTracking().getBlockBlacklist().contains(((BlockType) block).getId())) {
        SpongeHooks.logBlockTrack(this.world, block, pos, user, true);
    } else {
        SpongeHooks.logBlockTrack(this.world, block, pos, user, false);
    }
    final IMixinWorldInfo worldInfo = (IMixinWorldInfo) this.world.getWorldInfo();
    final int indexForUniqueId = worldInfo.getIndexForUniqueId(user.getUniqueId());
    if (pos.getY() <= 255) {
        short blockPos = blockPosToShort(pos);
        final PlayerTracker playerTracker = this.trackedShortBlockPositions.get(blockPos);
        if (playerTracker != null) {
            if (trackerType == PlayerTracker.Type.OWNER) {
                playerTracker.ownerIndex = indexForUniqueId;
                playerTracker.notifierIndex = indexForUniqueId;
            } else {
                playerTracker.notifierIndex = indexForUniqueId;
            }
        } else {
            this.trackedShortBlockPositions.put(blockPos, new PlayerTracker(indexForUniqueId, trackerType));
        }
    } else {
        int blockPos = blockPosToInt(pos);
        final PlayerTracker playerTracker = this.trackedIntBlockPositions.get(blockPos);
        if (playerTracker != null) {
            if (trackerType == PlayerTracker.Type.OWNER) {
                playerTracker.ownerIndex = indexForUniqueId;
            } else {
                playerTracker.notifierIndex = indexForUniqueId;
            }
        } else {
            this.trackedIntBlockPositions.put(blockPos, new PlayerTracker(indexForUniqueId, trackerType));
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) PlayerTracker(org.spongepowered.common.entity.PlayerTracker) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer)

Example 3 with IMixinWorldInfo

use of org.spongepowered.common.interfaces.world.IMixinWorldInfo in project SpongeCommon by SpongePowered.

the class MixinWorld method getUniqueId.

/**
 * Specifically verify the {@link UUID} for this world is going to be valid, in
 * certain cases, there are mod worlds that are extending {@link net.minecraft.world.World}
 * and have custom {@link WorldInfo}s, which ends up causing issues with
 * plugins expecting a valid uuid for each world.
 *
 * <p>TODO There may be some issues with plugins somehow picking up these "fake"
 * worlds with regards to their block changes, and therefor cause issues when
 * those plugins are finding those worlds, instead of traditional
 * {@link WorldServer} instances.</p>
 *
 * @return The world id, verified from the properties
 */
@Override
public UUID getUniqueId() {
    final WorldProperties properties = this.getProperties();
    final UUID worldId = properties.getUniqueId();
    if (worldId == null) {
        // Some mod worlds make their own WorldInfos for "fake" worlds.
        // Specifically fixes https://github.com/SpongePowered/SpongeForge/issues/1527
        // and https://github.com/BuildCraft/BuildCraft/issues/3594
        final IMixinWorldInfo mixinWorldInfo = (IMixinWorldInfo) properties;
        mixinWorldInfo.setUniqueId(UUID.randomUUID());
        return properties.getUniqueId();
    }
    return worldId;
}
Also used : IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) UUID(java.util.UUID) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 4 with IMixinWorldInfo

use of org.spongepowered.common.interfaces.world.IMixinWorldInfo in project SpongeCommon by SpongePowered.

the class MixinSpongeUser method setLocation.

@Override
public boolean setLocation(Vector3d position, UUID world) {
    WorldProperties prop = WorldManager.getWorldProperties(world).orElseThrow(() -> new IllegalArgumentException("Invalid World: No world found for UUID"));
    Integer dimensionId = ((IMixinWorldInfo) prop).getDimensionId();
    if (dimensionId == null) {
        throw new IllegalArgumentException("Invalid World: missing dimensionID)");
    }
    this.dimension = dimensionId;
    this.posX = position.getX();
    this.posY = position.getY();
    this.posZ = position.getZ();
    this.markDirty();
    return true;
}
Also used : IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 5 with IMixinWorldInfo

use of org.spongepowered.common.interfaces.world.IMixinWorldInfo in project SpongeCommon by SpongePowered.

the class WorldManager method setUuidOnProperties.

/**
 * Parses a {@link UUID} from disk from other known plugin platforms and sets it on the
 * {@link WorldProperties}. Currently only Bukkit is supported.
 */
private static UUID setUuidOnProperties(Path savesRoot, WorldProperties properties) {
    checkNotNull(properties);
    UUID uuid;
    if (properties.getUniqueId() == null || properties.getUniqueId().equals(UUID.fromString("00000000-0000-0000-0000-000000000000"))) {
        // Check if Bukkit's uid.dat file is here and use it
        final Path uidPath = savesRoot.resolve(properties.getWorldName()).resolve("uid.dat");
        if (Files.notExists(uidPath)) {
            uuid = UUID.randomUUID();
        } else {
            try (final DataInputStream dis = new DataInputStream(Files.newInputStream(uidPath))) {
                uuid = new UUID(dis.readLong(), dis.readLong());
            } catch (IOException e) {
                SpongeImpl.getLogger().error("World folder [{}] has an existing Bukkit unique identifier for it but we encountered issues parsing " + "the file. We will have to use a new unique id. Please report this to Sponge ASAP.", properties.getWorldName(), e);
                uuid = UUID.randomUUID();
            }
        }
    } else {
        uuid = properties.getUniqueId();
    }
    ((IMixinWorldInfo) properties).setUniqueId(uuid);
    return uuid;
}
Also used : Path(java.nio.file.Path) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) IOException(java.io.IOException) UUID(java.util.UUID) DataInputStream(java.io.DataInputStream)

Aggregations

IMixinWorldInfo (org.spongepowered.common.interfaces.world.IMixinWorldInfo)13 WorldServer (net.minecraft.world.WorldServer)6 WorldInfo (net.minecraft.world.storage.WorldInfo)6 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)6 Path (java.nio.file.Path)5 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)5 IMixinWorldSettings (org.spongepowered.common.interfaces.world.IMixinWorldSettings)5 AnvilSaveHandler (net.minecraft.world.chunk.storage.AnvilSaveHandler)4 IMixinMinecraftServer (org.spongepowered.common.interfaces.IMixinMinecraftServer)4 IOException (java.io.IOException)3 MinecraftServer (net.minecraft.server.MinecraftServer)3 WorldSettings (net.minecraft.world.WorldSettings)3 WorldArchetype (org.spongepowered.api.world.WorldArchetype)3 UUID (java.util.UUID)2 DimensionType (net.minecraft.world.DimensionType)2 ISaveHandler (net.minecraft.world.storage.ISaveHandler)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1