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