Search in sources :

Example 36 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.

the class CloneWorldCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    WorldProperties worldToCopy = args.<WorldProperties>getOne(this.worldKey).get();
    final String oldName = worldToCopy.getWorldName();
    final String newName = args.<String>getOne(this.newKey).get();
    if (Sponge.getServer().getWorldProperties(newName).isPresent()) {
        throw ReturnMessageException.fromKey("command.world.clone.alreadyexists", newName);
    }
    Text message = Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.world.clone.starting", oldName, newName);
    src.sendMessage(message);
    if (!(src instanceof ConsoleSource)) {
        Sponge.getServer().getConsole().sendMessage(message);
    }
    // Well, you never know, the player might die or disconnect - we have to be vigilant.
    final Supplier<MessageReceiver> mr;
    if (src instanceof Player) {
        UUID uuid = ((Player) src).getUniqueId();
        mr = () -> Sponge.getServer().getPlayer(uuid).map(x -> (MessageReceiver) x).orElseGet(() -> new MessageReceiver() {

            @Override
            public void sendMessage(Text message) {
            }

            @Override
            public MessageChannel getMessageChannel() {
                return MessageChannel.TO_NONE;
            }

            @Override
            public void setMessageChannel(MessageChannel channel) {
            }
        });
    } else {
        mr = () -> src;
    }
    Sponge.getServer().copyWorld(worldToCopy, newName).handle((result, ex) -> {
        MessageReceiver m = mr.get();
        Text msg;
        if (ex == null && result.isPresent()) {
            msg = Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.world.clone.success", oldName, newName);
        } else {
            msg = Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.world.clone.failed", oldName, newName);
        }
        m.sendMessage(msg);
        if (!(m instanceof ConsoleSource)) {
            Sponge.getServer().getConsole().sendMessage(msg);
        }
        return result;
    });
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) MessageReceiver(org.spongepowered.api.text.channel.MessageReceiver) Text(org.spongepowered.api.text.Text) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) UUID(java.util.UUID) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 37 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.

the class EnableWorldCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    WorldProperties worldProperties = args.<WorldProperties>getOne(worldKey).get();
    if (worldProperties.isEnabled()) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.world.enable.alreadyenabled", worldProperties.getWorldName()));
    }
    worldProperties.setEnabled(true);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.enable.success", worldProperties.getWorldName()));
    return CommandResult.success();
}
Also used : ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 38 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.

the class InfoWorldCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    WorldProperties wp = getWorldFromUserOrArgs(src, worldKey, args);
    final List<Text> listContent = Lists.newArrayList();
    final boolean canSeeSeeds = permissions.testSuffix(src, "seed");
    ListWorldCommand.getWorldInfo(listContent, wp, canSeeSeeds);
    Util.getPaginationBuilder(src).contents(listContent).title(plugin.getMessageProvider().getTextMessageWithFormat("command.world.info.title", wp.getWorldName())).sendTo(src);
    return CommandResult.success();
}
Also used : Text(org.spongepowered.api.text.Text) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 39 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.

the class LoadWorldCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    WorldProperties worldProperties = args.<WorldProperties>getOne(worldKey).get();
    if (!worldProperties.isEnabled() && !args.hasAny("e")) {
        // Not enabled, cannot load.
        if (plugin.getPermissionRegistry().getPermissionsForNucleusCommand(EnableWorldCommand.class).testBase(src)) {
            throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.world.load.notenabled.enable", worldProperties.getWorldName()));
        }
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.world.load.notenabled.noenable", worldProperties.getWorldName()));
    }
    if (Sponge.getServer().getWorld(worldProperties.getUniqueId()).isPresent()) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.world.load.alreadyloaded", worldProperties.getWorldName()));
    }
    worldProperties.setEnabled(true);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.load.start", worldProperties.getWorldName()));
    Optional<World> optional = Sponge.getServer().loadWorld(worldProperties);
    if (optional.isPresent()) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.load.loaded", worldProperties.getWorldName()));
        return CommandResult.success();
    }
    throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.world.load.fail", worldProperties.getWorldName()));
}
Also used : ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 40 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.

the class SetSpawnWorldCommand method executeCommand.

@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    WorldProperties world = this.getWorldFromUserOrArgs(src, this.worldKey, args);
    Vector3i loc;
    if (args.hasAny(this.xKey)) {
        loc = new Vector3i(args.<Integer>getOne(this.xKey).get(), args.<Integer>getOne(this.yKey).get(), args.<Integer>getOne(this.zKey).get());
    } else {
        loc = ((Locatable) src).getLocation().getBlockPosition();
    }
    world.setSpawnPosition(loc);
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.setspawn.success"));
    return CommandResult.success();
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Locatable(org.spongepowered.api.world.Locatable)

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