use of io.github.nucleuspowered.nucleus.modules.spawn.events.SendToSpawnEvent 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 io.github.nucleuspowered.nucleus.modules.spawn.events.SendToSpawnEvent 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());
}
Aggregations