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);
}
}
}
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));
}
}
}
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;
}
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;
}
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;
}
Aggregations