use of org.spongepowered.api.command.CommandResult 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.CommandResult in project Nucleus by NucleusPowered.
the class LightningCommand method executeCommand.
@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
Collection<Living> playerCollection = args.getAll(player);
// No argument, let's not smite the subject.
if (playerCollection.isEmpty()) {
if (!(src instanceof Player)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.playeronly"));
return CommandResult.empty();
}
Player pl = (Player) src;
// 100 is a good limit here.
BlockRay<World> playerBlockRay = BlockRay.from(pl).distanceLimit(100).stopFilter(BlockRay.continueAfterFilter(BlockRay.onlyAirFilter(), 1)).build();
Optional<BlockRayHit<World>> obh = playerBlockRay.end();
Location<World> lightningLocation;
// Smite above, but not on.
lightningLocation = obh.map(BlockRayHit::getLocation).orElseGet(() -> pl.getLocation().add(0, 3, 0));
return this.spawnLightning(lightningLocation, src, null);
}
int successCount = 0;
for (Living pl : playerCollection) {
CommandResult cr = this.spawnLightning(pl.getLocation(), src, pl instanceof Player ? (Player) pl : null);
successCount += cr.getSuccessCount().orElse(0);
}
return CommandResult.builder().successCount(successCount).build();
}
use of org.spongepowered.api.command.CommandResult 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);
});
}
}
}
use of org.spongepowered.api.command.CommandResult in project Nucleus by NucleusPowered.
the class AbstractCommand method startExecute.
@SuppressWarnings({ "unchecked" })
private CommandResult startExecute(T src, CommandContext args) throws Exception {
CommandResult cr;
boolean isSuccess = false;
try {
// Any pre-processing steps
commandInterceptors.forEach(x -> x.onPreCommand((Class<? extends AbstractCommand<?>>) getClass(), src, args));
// Execute the command in the specific executor.
cr = executeCommand(src, args);
isSuccess = cr.getSuccessCount().orElse(0) > 0;
} catch (ReturnMessageException e) {
Text t = e.getText();
src.sendMessage((t == null) ? NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("command.error") : t);
cr = CommandResult.empty();
} finally {
if (src instanceof Player) {
// If the subject is subject to cooling down, apply the cooldown.
@SuppressWarnings("unchecked") final Player p = (Player) src;
if (isSuccess) {
setCooldown(p, args);
} else {
// For the tests, keep this here so we can skip the hard to test
// code below.
final double cost = getCost(p, args);
if (cost > 0) {
Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> plugin.getEconHelper().depositInPlayer(p, cost));
}
}
}
}
for (ICommandInterceptor x : commandInterceptors) {
x.onPostCommand((Class<? extends AbstractCommand<?>>) getClass(), src, args, cr);
}
return cr;
}
use of org.spongepowered.api.command.CommandResult in project Nucleus by NucleusPowered.
the class BroadcastCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
String m = args.<String>getOne(message).get();
NucleusTextTemplate textTemplate = NucleusTextTemplateFactory.createFromAmpersandString(m);
Text p = bc.getPrefix().getForCommandSource(src);
Text s = bc.getSuffix().getForCommandSource(src);
new NucleusTextTemplateMessageSender(textTemplate, src, t -> TextParsingUtils.joinTextsWithColoursFlowing(p, t, s)).send();
return CommandResult.success();
}
Aggregations