use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class TeleportAskHereCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
Player target = args.<Player>getOne(PLAYER_KEY).get();
if (src.equals(target)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.teleport.self"));
return CommandResult.empty();
}
// Before we do all this, check the event.
RequestEvent.PlayerToCause event = new RequestEvent.PlayerToCause(CauseStackHelper.createCause(src), target);
if (Sponge.getEventManager().post(event)) {
throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("command.tpa.eventfailed")));
}
TeleportHandler.TeleportBuilder tb = tpHandler.getBuilder().setFrom(target).setTo(src).setSafe(!args.<Boolean>getOne("f").orElse(false));
int warmup = getWarmup(target);
if (warmup > 0) {
tb.setWarmupTime(warmup);
}
double cost = getCost(src, args);
if (cost > 0.) {
tb.setCharge(src).setCost(cost);
}
// The question needs to be asked of the target
tpHandler.addAskQuestion(target.getUniqueId(), new TeleportHandler.TeleportPrep(Instant.now().plus(30, ChronoUnit.SECONDS), src, cost, tb));
target.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tpahere.question", src.getName()));
target.sendMessage(tpHandler.getAcceptDenyMessage());
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tpask.sent", target.getName()));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class SellAllCommand method executeCommand.
@Override
public CommandResult executeCommand(final Player src, CommandContext args) throws Exception {
boolean accepted = args.hasAny("a");
CatalogType ct = getCatalogTypeFromHandOrArgs(src, itemKey, args);
String id = ct.getId();
ItemStack query;
if (ct instanceof BlockState) {
query = ItemStack.builder().fromBlockState((BlockState) ct).quantity(1).build();
// Yeah...
query.setQuantity(-1);
} else {
// Having a quantity of -1 causes an IllegalArgumentException here...
query = ItemStack.of((ItemType) ct, 1);
// and doesn't care here...
query.setQuantity(-1);
}
ItemDataNode node = itemDataService.getDataForItem(id);
final double sellPrice = node.getServerSellPrice();
if (sellPrice < 0) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.itemsell.notforselling"));
}
Iterable<Slot> slots = Util.getStandardInventory(src).query(query).slots();
List<ItemStack> itemsToSell = StreamSupport.stream(Util.getStandardInventory(src).query(query).slots().spliterator(), false).map(Inventory::peek).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
// Get the cost.
final int amt = itemsToSell.stream().mapToInt(ItemStack::getQuantity).sum();
if (amt <= 0) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsellall.none", Text.of(query)));
}
final double overallCost = sellPrice * amt;
if (accepted) {
if (econHelper.depositInPlayer(src, overallCost, false)) {
slots.forEach(Inventory::clear);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsell.summary", Text.of(amt), Text.of(query), Text.of(econHelper.getCurrencySymbol(overallCost))));
return CommandResult.success();
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsell.error", Text.of(query)));
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsellall.summary", Text.of(amt), Text.of(query), Text.of(econHelper.getCurrencySymbol(overallCost)), Text.of(id)).toBuilder().onClick(TextActions.runCommand("/nucleus:itemsellall -a " + id)).build());
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException 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.internal.command.ReturnMessageException 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 io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class DeleteWarpCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Warp warp = args.<Warp>getOne(WarpCommand.warpNameArg).get();
NucleusWarpService qs = Sponge.getServiceManager().provideUnchecked(NucleusWarpService.class);
DeleteWarpEvent event = new DeleteWarpEvent(CauseStackHelper.createCause(src), warp);
if (Sponge.getEventManager().post(event)) {
throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("nucleus.eventcancelled")));
}
if (qs.removeWarp(warp.getName())) {
// Worked. Tell them.
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.del", warp.getName()));
return CommandResult.success();
}
// Didn't work. Tell them.
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.delerror"));
return CommandResult.empty();
}
Aggregations