use of io.github.nucleuspowered.nucleus.modules.spawn.config.GlobalSpawnConfig in project Nucleus by NucleusPowered.
the class SpawnListener method onRespawn.
@Listener(order = Order.EARLY)
public void onRespawn(RespawnPlayerEvent event) {
if (event.isBedSpawn() && !this.spawnConfig.isRedirectBedSpawn()) {
// Nope, we don't care.
return;
}
GlobalSpawnConfig sc = spawnConfig.getGlobalSpawn();
World world = event.getToTransform().getExtent();
// Get the world.
if (sc.isOnRespawn()) {
Optional<WorldProperties> oworld = sc.getWorld();
if (oworld.isPresent()) {
world = Sponge.getServer().getWorld(oworld.get().getUniqueId()).orElse(world);
}
}
Location<World> spawn = world.getSpawnLocation().add(0.5, 0, 0.5);
Transform<World> to = new Transform<>(spawn);
// Compare current transform to spawn - set rotation.
Nucleus.getNucleus().getWorldDataManager().getWorld(world).ifPresent(x -> x.get(SpawnWorldDataModule.class).getSpawnRotation().ifPresent(y -> event.setToTransform(to.setRotation(y))));
}
use of io.github.nucleuspowered.nucleus.modules.spawn.config.GlobalSpawnConfig 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 io.github.nucleuspowered.nucleus.modules.spawn.config.GlobalSpawnConfig 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());
}
Aggregations