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