use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class TeleportWorldCommand method executeCommand.
@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
Player player = getUserFromArgs(Player.class, src, playerKey, args, "command.world.player");
WorldProperties worldProperties = args.<WorldProperties>getOne(world).get();
if (!worldProperties.isEnabled()) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.world.teleport.notenabled", worldProperties.getWorldName()));
}
World world = Sponge.getServer().loadWorld(worldProperties.getUniqueId()).orElseThrow(() -> ReturnMessageException.fromKey("command.world.teleport.failed", worldProperties.getWorldName()));
Vector3d pos = worldProperties.getSpawnPosition().toDouble();
if (!player.transferToWorld(world, pos)) {
throw ReturnMessageException.fromKey("command.world.teleport.failed", worldProperties.getWorldName());
}
// Rotate.
Nucleus.getNucleus().getWorldDataManager().getWorld(worldProperties.getUniqueId()).ifPresent(x -> x.get(SpawnWorldDataModule.class).getSpawnRotation().ifPresent(y -> new Transform<World>(world, pos, y)));
if (src instanceof Player && ((Player) src).getUniqueId().equals(player.getUniqueId())) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.teleport.success", worldProperties.getWorldName()));
} else {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.teleport.successplayer", plugin.getNameUtil().getSerialisedName(player), worldProperties.getWorldName()));
player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.teleport.success", worldProperties.getWorldName()));
}
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class UnloadWorldCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
WorldProperties worldProperties = args.<WorldProperties>getOne(worldKey).get();
Optional<WorldProperties> transferWorld = args.getOne(transferWorldKey);
boolean disable = args.hasAny("d");
Optional<World> worldOptional = Sponge.getServer().getWorld(worldProperties.getUniqueId());
if (!worldOptional.isPresent()) {
// Not loaded.
if (disable) {
disable(worldProperties, src, plugin.getMessageProvider(), false);
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.world.unload.alreadyunloaded", worldProperties.getWorldName()));
}
World world = worldOptional.get();
List<Player> playerCollection = Sponge.getServer().getOnlinePlayers().stream().filter(x -> x.getWorld().equals(world)).collect(Collectors.toList());
if (playerCollection.isEmpty() || (transferWorld.isPresent() && transferWorld.get().isEnabled())) {
if (!playerCollection.isEmpty()) {
// Transfer World is present and enabled.
playerCollection.forEach(x -> x.transferToWorld(transferWorld.get().getUniqueId(), transferWorld.get().getSpawnPosition().toDouble()));
Sponge.getScheduler().createSyncExecutor(plugin).schedule(() -> unloadWorld(src, world, plugin.getMessageProvider(), disable), 40, TimeUnit.MILLISECONDS);
// Well, this bit succeeded, at least.
return CommandResult.success();
} else if (unloadWorld(src, world, plugin.getMessageProvider(), disable)) {
return CommandResult.success();
} else {
return CommandResult.empty();
}
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.world.unload.players", worldProperties.getWorldName()));
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class GenerateChunksCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
WorldProperties wp = getWorldFromUserOrArgs(src, worldKey, args);
if (worldHelper.isPregenRunningForWorld(wp.getUniqueId())) {
throw ReturnMessageException.fromKey("command.world.gen.alreadyrunning", wp.getWorldName());
}
World w = Sponge.getServer().getWorld(wp.getUniqueId()).orElseThrow(() -> ReturnMessageException.fromKey("command.world.gen.notloaded", wp.getWorldName()));
this.worldHelper.startPregenningForWorld(w, args.hasAny("a"), args.<Long>getOne(Text.of(GenerateChunksCommand.saveTimeKey)).orElse(20L) * 1000L, args.<Integer>getOne(ticksKey).orElse(null), args.<Integer>getOne(tickFrequency).orElse(null));
src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("command.world.gen.started", wp.getWorldName()));
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class ResetBorderCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
WorldProperties wp = getWorldFromUserOrArgs(src, worldKey, args);
wp.setWorldBorderCenter(0, 0);
Optional<World> world = Sponge.getServer().getWorld(wp.getUniqueId());
// A world to get defaults from.
World toDiameter = world.orElseGet(() -> Sponge.getServer().getWorld(Sponge.getServer().getDefaultWorld().orElseThrow(IllegalStateException::new).getUniqueId()).orElseThrow(IllegalStateException::new));
// +1 includes the final block (1 -> -1 would otherwise give 2, not 3).
final long diameter = Math.abs(toDiameter.getBiomeMax().getX() - toDiameter.getBiomeMin().getX()) + 1;
wp.setWorldBorderDiameter(diameter);
world.ifPresent(w -> {
w.getWorldBorder().setCenter(0, 0);
w.getWorldBorder().setDiameter(diameter);
});
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.setborder.set", wp.getWorldName(), "0", "0", String.valueOf(diameter)));
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class WorldHelper method startPregenningForWorld.
public boolean startPregenningForWorld(World world, boolean aggressive, long saveTime, @Nullable Integer tickPercent, @Nullable Integer tickFrequency) {
cleanup();
if (!isPregenRunningForWorld(world.getUniqueId())) {
WorldProperties wp = world.getProperties();
ChunkPreGenerate.Builder wbcp = world.newChunkPreGenerate(wp.getWorldBorderCenter(), wp.getWorldBorderDiameter()).owner(plugin).addListener(new Listener(aggressive, saveTime));
if (aggressive) {
wbcp.tickPercentLimit(0.9f).tickInterval(3);
}
if (tickPercent != null) {
wbcp.tickPercentLimit(Math.max(0f, Math.min(tickPercent / 100.0f, 1f)));
}
if (tickFrequency != null) {
wbcp.tickInterval(Math.max(1, tickFrequency));
}
pregen.put(world.getUniqueId(), wbcp.start());
return true;
}
return false;
}
Aggregations