use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class SpawnListener method onJoin.
@Listener
public void onJoin(ClientConnectionEvent.Login loginEvent) {
UUID pl = loginEvent.getProfile().getUniqueId();
boolean first = Nucleus.getNucleus().getUserDataManager().getUnchecked(pl).get(CoreUserDataModule.class).isStartedFirstJoin();
try {
if (first) {
// first spawn.
Optional<Transform<World>> ofs = Nucleus.getNucleus().getGeneralService().get(SpawnGeneralDataModule.class).getFirstSpawn();
// setting the location the player safely. If this cannot be done in either case, send them to world spawn.
if (ofs.isPresent()) {
NucleusTeleportHandler.StandardTeleportMode mode = spawnConfig.isSafeTeleport() ? NucleusTeleportHandler.StandardTeleportMode.SAFE_TELEPORT : NucleusTeleportHandler.StandardTeleportMode.WALL_CHECK;
Optional<Location<World>> location = plugin.getTeleportHandler().getSafeLocation(null, ofs.get().getLocation(), mode);
if (location.isPresent()) {
loginEvent.setToTransform(new Transform<>(location.get().getExtent(), process(location.get().getPosition()), ofs.get().getRotation()));
return;
}
WorldProperties w = Sponge.getServer().getDefaultWorld().get();
loginEvent.setToTransform(new Transform<>(Sponge.getServer().getWorld(w.getUniqueId()).get(), w.getSpawnPosition().toDouble().add(0.5, 0, 0.5)));
// We don't want to boot them elsewhere.
return;
}
}
} catch (Exception e) {
if (Nucleus.getNucleus().isDebugMode()) {
e.printStackTrace();
}
}
// Throw them to the default world spawn if the config suggests so.
User user = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).getOrCreate(loginEvent.getProfile());
if (spawnConfig.isSpawnOnLogin() && !user.hasPermission(spawnExempt)) {
GlobalSpawnConfig sc = spawnConfig.getGlobalSpawn();
World world = loginEvent.getFromTransform().getExtent();
if (sc.isOnLogin() && sc.getWorld().isPresent()) {
world = Sponge.getServer().getWorld(sc.getWorld().get().getUniqueId()).orElse(world);
}
Location<World> lw = world.getSpawnLocation().add(0.5, 0, 0.5);
Optional<Location<World>> safe = plugin.getTeleportHandler().getSafeLocation(null, lw, spawnConfig.isSafeTeleport() ? NucleusTeleportHandler.StandardTeleportMode.SAFE_TELEPORT_ASCENDING : NucleusTeleportHandler.StandardTeleportMode.NO_CHECK);
if (safe.isPresent()) {
try {
Optional<Vector3d> ov = Nucleus.getNucleus().getWorldDataManager().getWorld(world.getUniqueId()).get().get(SpawnWorldDataModule.class).getSpawnRotation();
if (ov.isPresent()) {
loginEvent.setToTransform(new Transform<>(safe.get().getExtent(), process(safe.get().getPosition()), ov.get()));
return;
}
} catch (Exception e) {
//
}
loginEvent.setToTransform(new Transform<>(process(safe.get())));
}
}
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class TeleportPositionCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Player pl = this.getUserFromArgs(Player.class, src, key, args);
WorldProperties wp = args.<WorldProperties>getOne(location).orElse(pl.getWorld().getProperties());
World world = Sponge.getServer().loadWorld(wp.getUniqueId()).get();
int xx = args.<Integer>getOne(x).get();
int zz = args.<Integer>getOne(z).get();
int yy = args.<Integer>getOne(y).get();
if (yy < 0) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.ysmall"));
return CommandResult.empty();
}
// Chunks are 16 in size, chunk 0 is from 0 - 15, -1 from -1 to -16.
if (args.hasAny("c")) {
xx = xx * 16 + 8;
yy = yy * 16 + 8;
zz = zz * 16 + 8;
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.fromchunk", String.valueOf(xx), String.valueOf(yy), String.valueOf(zz)));
}
Vector3i max = world.getBlockMax();
Vector3i min = world.getBlockMin();
if (!(isBetween(xx, max.getX(), min.getX()) && isBetween(yy, max.getY(), min.getY()) && isBetween(zz, max.getZ(), min.getZ()))) {
throw ReturnMessageException.fromKey("command.tppos.invalid");
}
// Create the location
Location<World> loc = new Location<>(world, xx, yy, zz);
if (!args.hasAny("b") && !Util.isLocationInWorldBorder(loc)) {
throw ReturnMessageException.fromKey("command.tppos.worldborder");
}
NucleusTeleportHandler teleportHandler = Nucleus.getNucleus().getTeleportHandler();
Cause cause = CauseStackHelper.createCause(src);
// Don't bother with the safety if the flag is set.
if (args.<Boolean>getOne("f").orElse(false)) {
if (teleportHandler.teleportPlayer(pl, loc, NucleusTeleportHandler.StandardTeleportMode.NO_CHECK, cause).isSuccess()) {
pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.self"));
if (!src.equals(pl)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.other", pl.getName()));
}
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.tppos.cancelledevent");
}
// If we have a chunk, scan the whole chunk.
NucleusTeleportHandler.StandardTeleportMode mode = teleportHandler.getTeleportModeForPlayer(pl);
if (args.hasAny("c") && mode == NucleusTeleportHandler.StandardTeleportMode.FLYING_THEN_SAFE) {
mode = NucleusTeleportHandler.StandardTeleportMode.FLYING_THEN_SAFE_CHUNK;
}
NucleusTeleportHandler.TeleportResult result = teleportHandler.teleportPlayer(pl, loc, mode, cause, true);
if (result.isSuccess()) {
pl.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.self"));
if (!src.equals(pl)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tppos.success.other", pl.getName()));
}
return CommandResult.success();
} else if (result == NucleusTeleportHandler.TeleportResult.FAILED_NO_LOCATION) {
throw ReturnMessageException.fromKey("command.tppos.nosafe");
}
throw ReturnMessageException.fromKey("command.tppos.cancelledevent");
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class SpawnCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
boolean force = args.hasAny("f");
GlobalSpawnConfig gsc = sc.getGlobalSpawn();
WorldProperties wp = args.<WorldProperties>getOne(key).orElseGet(() -> gsc.isOnSpawnCommand() ? gsc.getWorld().orElse(src.getWorld().getProperties()) : src.getWorld().getProperties());
Optional<World> ow = Sponge.getServer().loadWorld(wp.getUniqueId());
if (!ow.isPresent()) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawn.noworld"));
} else if (sc.isPerWorldPerms() && !permissions.testSuffix(src, "worlds." + ow.get().getName().toLowerCase())) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawn.nopermsworld", ow.get().getName()));
}
Transform<World> worldTransform = SpawnHelper.getSpawn(wp, plugin, src);
SendToSpawnEvent event = new SendToSpawnEvent(worldTransform, src, CauseStackHelper.createCause(src));
if (Sponge.getEventManager().post(event)) {
if (event.getCancelReason().isPresent()) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.self.failed.reason", event.getCancelReason().get()));
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.self.failed.noreason"));
}
// If we don't have a rotation, then use the current rotation
NucleusTeleportHandler.TeleportResult result = this.plugin.getTeleportHandler().teleportPlayer(src, SpawnHelper.getSpawn(ow.get().getProperties(), this.plugin, src), !force && this.sc.isSafeTeleport());
if (result.isSuccess()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.spawn.success", wp.getWorldName()));
return CommandResult.success();
}
if (result == NucleusTeleportHandler.TeleportResult.FAILED_NO_LOCATION) {
throw ReturnMessageException.fromKey("command.spawn.fail", wp.getWorldName());
}
throw ReturnMessageException.fromKey("command.spawn.cancelled", wp.getWorldName());
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class SpawnOtherCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User target = args.<User>getOne(otherKey).get();
WorldProperties world = this.getWorldProperties(src, worldKey, args).orElseGet(() -> gsc.isOnSpawnCommand() ? gsc.getWorld().get() : Sponge.getServer().getDefaultWorld().get());
Transform<World> worldTransform = SpawnHelper.getSpawn(world, plugin, target.getPlayer().orElse(null));
SendToSpawnEvent event = new SendToSpawnEvent(worldTransform, target, CauseStackHelper.createCause(src));
if (Sponge.getEventManager().post(event)) {
if (event.getCancelReason().isPresent()) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.other.failed.reason", target.getName(), event.getCancelReason().get()));
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.other.failed.noreason", target.getName()));
}
if (!target.isOnline()) {
return isOffline(src, target, worldTransform);
}
// If we don't have a rotation, then use the current rotation
Player player = target.getPlayer().get();
NucleusTeleportHandler.TeleportResult result = plugin.getTeleportHandler().teleportPlayer(player, worldTransform, this.safeTeleport);
if (result.isSuccess()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.success.source", target.getName(), world.getWorldName()));
player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnother.success.target", world.getWorldName()));
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.spawnother.fail", target.getName(), world.getWorldName());
}
use of org.spongepowered.api.world.storage.WorldProperties in project Nucleus by NucleusPowered.
the class RandomTeleportCommand method executeWithPlayer.
@Override
protected CommandResult executeWithPlayer(CommandSource src, Player player, CommandContext args, boolean self) throws Exception {
// Get the current world.
final WorldProperties wp;
if (this.rc.getDefaultWorld().isPresent()) {
wp = args.<WorldProperties>getOne(worldKey).orElseGet(() -> this.rc.getDefaultWorld().get());
} else {
wp = this.getWorldFromUserOrArgs(src, worldKey, args);
}
if (rc.isPerWorldPermissions()) {
String name = wp.getWorldName();
permissions.checkSuffix(src, "worlds." + name.toLowerCase(), () -> ReturnMessageException.fromKey("command.rtp.worldnoperm", name));
}
World currentWorld = Sponge.getServer().loadWorld(wp.getUniqueId()).orElse(null);
if (currentWorld == null) {
currentWorld = Sponge.getServer().loadWorld(wp).orElseThrow(() -> ReturnMessageException.fromKey("command.rtp.worldnoload", wp.getWorldName()));
}
// World border
WorldBorder wb = currentWorld.getWorldBorder();
int diameter = Math.min(Math.abs(rc.getRadius(currentWorld.getName()) * 2), (int) wb.getDiameter());
int minDiameter = Math.max(Math.abs(rc.getMinRadius(currentWorld.getName()) * 2), 0);
Vector3d centre = wb.getCenter();
src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("command.rtp.searching"));
if (self) {
Sponge.getScheduler().createTaskBuilder().execute(new RTPTask(plugin, centre, minDiameter, diameter, getCost(src, args), player, currentWorld, rc)).submit(plugin);
} else {
Sponge.getScheduler().createTaskBuilder().execute(new RTPTask(plugin, centre, minDiameter, diameter, getCost(src, args), player, currentWorld, src, rc)).submit(plugin);
}
return CommandResult.success();
}
Aggregations