Search in sources :

Example 1 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Skree by Skelril.

the class DropClearCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<DropClearService> optService = Sponge.getServiceManager().provide(DropClearService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The drop clear service is not currently running."));
        return CommandResult.empty();
    }
    DropClearService service = optService.get();
    // World resolution
    Optional<WorldProperties> optWorldProps = args.getOne("world");
    Optional<World> optWorld;
    if (!optWorldProps.isPresent()) {
        if (!(src instanceof Player)) {
            src.sendMessage(Text.of(TextColors.RED, "You are not a player and need to specify a world!"));
            return CommandResult.empty();
        }
        optWorld = Optional.of(((Player) src).getWorld());
    } else {
        optWorld = Sponge.getServer().getWorld(optWorldProps.get().getUniqueId());
    }
    // Handled by command spec, so always provided
    int seconds = args.<Integer>getOne("seconds").get();
    World world = optWorld.get();
    if (!world.isLoaded()) {
        src.sendMessage(Text.of(TextColors.RED, "The specified world was not loaded!"));
        return CommandResult.empty();
    }
    service.cleanup(world, Math.max(0, Math.min(seconds, maxDelay)));
    return CommandResult.success();
}
Also used : DropClearService(com.skelril.skree.service.DropClearService) Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 2 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project SpongeCommon by SpongePowered.

the class SpongeCommonEventFactory method callChangeBlockEventModifyLiquidMix.

public static ChangeBlockEvent.Modify callChangeBlockEventModifyLiquidMix(net.minecraft.world.World worldIn, BlockPos pos, IBlockState state, @Nullable Object source) {
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final PhaseData data = phaseTracker.getCurrentPhaseData();
    BlockState fromState = BlockUtil.fromNative(worldIn.getBlockState(pos));
    BlockState toState = BlockUtil.fromNative(state);
    User owner = data.context.getOwner().orElse(null);
    User notifier = data.context.getNotifier().orElse(null);
    if (source == null) {
        // If source is null the source is the block itself
        source = LocatableBlock.builder().state(fromState).world(((World) worldIn)).position(pos.getX(), pos.getY(), pos.getZ()).build();
    }
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(source);
        Sponge.getCauseStackManager().addContext(EventContextKeys.LIQUID_MIX, (World) worldIn);
        if (owner != null) {
            Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, owner);
        }
        if (notifier != null) {
            Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier);
        }
        WorldProperties world = ((World) worldIn).getProperties();
        Vector3i position = new Vector3i(pos.getX(), pos.getY(), pos.getZ());
        Transaction<BlockSnapshot> transaction = new Transaction<>(BlockSnapshot.builder().blockState(fromState).world(world).position(position).build(), BlockSnapshot.builder().blockState(toState).world(world).position(position).build());
        ChangeBlockEvent.Modify event = SpongeEventFactory.createChangeBlockEventModify(Sponge.getCauseStackManager().getCurrentCause(), Collections.singletonList(transaction));
        SpongeImpl.postEvent(event);
        return event;
    }
}
Also used : PhaseData(org.spongepowered.common.event.tracking.PhaseData) User(org.spongepowered.api.entity.living.player.User) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Transaction(org.spongepowered.api.data.Transaction) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Vector3i(com.flowpowered.math.vector.Vector3i) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 3 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties 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 WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method setLocation.

@Override
public boolean setLocation(Vector3d position, UUID world) {
    WorldProperties prop = Sponge.getServer().getWorldProperties(world).orElseThrow(() -> new IllegalArgumentException("Invalid World: No world found for UUID"));
    World loaded = Sponge.getServer().loadWorld(prop).orElseThrow(() -> new IllegalArgumentException("Invalid World: Could not load world for UUID"));
    return this.setLocation(new Location<>(loaded, position));
}
Also used : World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 5 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties 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)

Aggregations

WorldProperties (org.spongepowered.api.world.storage.WorldProperties)109 World (org.spongepowered.api.world.World)37 CommandException (org.spongepowered.api.command.CommandException)27 ArrayList (java.util.ArrayList)26 Player (org.spongepowered.api.entity.living.player.Player)19 Text (org.spongepowered.api.text.Text)16 Vector3d (com.flowpowered.math.vector.Vector3d)9 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)9 Listener (org.spongepowered.api.event.Listener)9 WorldGeneratorModifier (org.spongepowered.api.world.gen.WorldGeneratorModifier)9 List (java.util.List)8 Optional (java.util.Optional)8 CommandResult (org.spongepowered.api.command.CommandResult)8 Vector3i (com.flowpowered.math.vector.Vector3i)7 IOException (java.io.IOException)7 Sponge (org.spongepowered.api.Sponge)7 CommandSource (org.spongepowered.api.command.CommandSource)7 IMixinWorldInfo (org.spongepowered.common.interfaces.world.IMixinWorldInfo)7 GenericArguments (org.spongepowered.api.command.args.GenericArguments)6 Location (org.spongepowered.api.world.Location)6