use of org.spongepowered.api.command.CommandSource 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.command.CommandSource 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.command.CommandSource in project Nucleus by NucleusPowered.
the class AvailableBaseCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
MessageProvider mp = Nucleus.getNucleus().getMessageProvider();
List<Text> types = Sponge.getRegistry().getAllOf(this.catalogType).stream().map(x -> mp.getTextMessageWithFormat("command.world.presets.item", x.getId(), x.getName())).collect(Collectors.toList());
Util.getPaginationBuilder(src).title(mp.getTextMessageWithTextFormat(this.titleKey)).contents(types).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class SetupPermissionsCommand method setupPerms.
private void setupPerms(CommandSource src, Subject group, SuggestedLevel level, boolean reset, boolean inherit) throws Exception {
if (inherit && level.getLowerLevel() != null) {
setupPerms(src, group, level.getLowerLevel(), reset, inherit);
}
Set<Context> globalContext = Sets.newHashSet();
SubjectData data = group.getSubjectData();
Set<String> definedPermissions = data.getPermissions(ImmutableSet.of()).keySet();
Logger logger = Nucleus.getNucleus().getLogger();
MessageProvider messageProvider = Nucleus.getNucleus().getMessageProvider();
// Register all the permissions, but only those that have yet to be assigned.
permissionRegistry.getPermissions().entrySet().stream().filter(x -> x.getValue().level == level).filter(x -> reset || !definedPermissions.contains(x.getKey())).forEach(x -> {
logger.info(messageProvider.getMessageWithFormat("command.nucleus.permission.added", x.getKey(), group.getIdentifier()));
data.setPermission(globalContext, x.getKey(), Tristate.TRUE);
});
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.permission.complete", level.toString().toLowerCase(), group.getIdentifier()));
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class AFKCommandInterceptor method onPostCommand.
@Override
public void onPostCommand(Class<? extends AbstractCommand<?>> commandClass, CommandSource source, CommandContext context, CommandResult result) {
if (this.send && result.getSuccessCount().orElse(0) > 0 && commandClass.isAnnotationPresent(NotifyIfAFK.class)) {
NotifyIfAFK annotation = commandClass.getAnnotation(NotifyIfAFK.class);
Cause cause = CauseStackHelper.createCause(source);
for (String key : annotation.value()) {
context.getAll(key).stream().filter(x -> x instanceof User).map(x -> ((User) x).getPlayer().orElse(null)).filter(Objects::nonNull).filter(this.handler::isAFK).forEach(x -> {
Text messageToSend = this.message == null ? null : message.getForCommandSource(x);
AFKEvents.Notify event = new AFKEvents.Notify(x, messageToSend, cause);
Sponge.getEventManager().post(event);
event.getMessage().ifPresent(source::sendMessage);
});
}
}
}
Aggregations