Search in sources :

Example 16 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class KitEditCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    final Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
    if (KIT_HANDLER.isOpen(kitInfo.getName())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.current", kitInfo.getName()));
    }
    Inventory inventory = Util.getKitInventoryBuilder().property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.title", kitInfo.getName()))).build(plugin);
    kitInfo.getStacks().stream().filter(x -> !x.getType().equals(ItemTypes.NONE)).forEach(x -> inventory.offer(x.createStack()));
    Optional<Container> openedInventory = src.openInventory(inventory);
    if (openedInventory.isPresent()) {
        KIT_HANDLER.addKitInventoryToListener(Tuple.of(kitInfo, inventory), openedInventory.get());
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.kit.edit.cantopen", kitInfo.getName());
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) ItemTypes(org.spongepowered.api.item.ItemTypes) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) Since(io.github.nucleuspowered.nucleus.internal.annotations.Since) KitFallbackBase(io.github.nucleuspowered.nucleus.modules.kit.commands.KitFallbackBase) GenericArguments(org.spongepowered.api.command.args.GenericArguments) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) KitHandler(io.github.nucleuspowered.nucleus.modules.kit.handlers.KitHandler) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Tuple(org.spongepowered.api.util.Tuple) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) CommandElement(org.spongepowered.api.command.args.CommandElement) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) Container(org.spongepowered.api.item.inventory.Container) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) KitArgument(io.github.nucleuspowered.nucleus.argumentparsers.KitArgument) Container(org.spongepowered.api.item.inventory.Container) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 17 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class InvSeeCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    User target = args.<User>getOne(player).get();
    if (!target.isOnline() && !permissions.testSuffix(src, "offline")) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.invsee.nooffline"));
    }
    if (!this.self && target.getUniqueId().equals(src.getUniqueId())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.invsee.self"));
    }
    if (permissions.testSuffix(target, "exempt.target", src, false)) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.invsee.targetexempt", target.getName()));
    }
    // Just in case, get the subject inventory if they are online.
    try {
        Inventory targetInv = target.isOnline() ? target.getPlayer().get().getInventory() : target.getInventory();
        Optional<Container> oc = src.openInventory(targetInv);
        if (oc.isPresent()) {
            if (!permissions.testSuffix(src, "modify") || permissions.testSuffix(target, "exempt.interact")) {
                InvSeeListener.addEntry(src.getUniqueId(), oc.get());
            }
            return CommandResult.success();
        }
        throw ReturnMessageException.fromKey("command.invsee.failed");
    } catch (UnsupportedOperationException e) {
        throw ReturnMessageException.fromKey("command.invsee.offlinenotsupported");
    }
}
Also used : Container(org.spongepowered.api.item.inventory.Container) User(org.spongepowered.api.entity.living.player.User) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 18 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class SpawnMobCommand method executeWithPlayer.

@Override
public CommandResult executeWithPlayer(CommandSource src, Player pl, CommandContext args, boolean isSelf) throws Exception {
    // Get the amount
    int amount = args.<Integer>getOne(amountKey).get();
    EntityType et = args.<EntityType>getOne(mobTypeKey).get();
    if (!Living.class.isAssignableFrom(et.getEntityClass())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.livingonly", et.getTranslation().get()));
    }
    String id = et.getId().toLowerCase();
    if (this.mobConfig.isPerMobPermission() && !permissions.testSuffix(src, "mob." + id.replace(":", "."))) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.mobnoperm", et.getTranslation().get()));
    }
    Optional<BlockSpawnsConfig> config = this.mobConfig.getBlockSpawnsConfigForWorld(pl.getWorld());
    if (config.isPresent() && (config.get().isBlockVanillaMobs() && id.startsWith("minecraft:") || config.get().getIdsToBlock().contains(id))) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.blockedinconfig", et.getTranslation().get()));
    }
    Location<World> loc = pl.getLocation();
    World w = loc.getExtent();
    MessageProvider mp = plugin.getMessageProvider();
    // Count the number of entities spawned.
    int i = 0;
    Entity entityone = null;
    do {
        Entity e = w.createEntity(et, loc.getPosition());
        if (!w.spawnEntity(e)) {
            throw ReturnMessageException.fromKeyText("command.spawnmob.fail", Text.of(e));
        }
        if (entityone == null) {
            entityone = e;
        }
        i++;
    } while (i < Math.min(amount, this.mobConfig.getMaxMobsToSpawn()));
    if (amount > this.mobConfig.getMaxMobsToSpawn()) {
        src.sendMessage(mp.getTextMessageWithFormat("command.spawnmob.limit", String.valueOf(this.mobConfig.getMaxMobsToSpawn())));
    }
    if (i == 0) {
        throw ReturnMessageException.fromKey("command.spawnmob.fail", et.getTranslation().get());
    }
    if (i == 1) {
        src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.singular", Text.of(i), Text.of(entityone)));
    } else {
        src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.plural", Text.of(i), Text.of(entityone)));
    }
    return CommandResult.success();
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) Entity(org.spongepowered.api.entity.Entity) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Living(org.spongepowered.api.entity.living.Living) BlockSpawnsConfig(io.github.nucleuspowered.nucleus.modules.mob.config.BlockSpawnsConfig) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World)

Example 19 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class SellCommand method executeCommand.

@Override
public CommandResult executeCommand(final Player src, CommandContext args) throws Exception {
    // Get the item in the hand.
    ItemStack is = src.getItemInHand(HandTypes.MAIN_HAND).orElseThrow(() -> new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.generalerror.handempty")));
    String id;
    Optional<BlockState> blockState = is.get(Keys.ITEM_BLOCKSTATE);
    id = blockState.map(blockState1 -> blockState1.getId().toLowerCase()).orElseGet(() -> is.getType().getId());
    ItemDataNode node = itemDataService.getDataForItem(id);
    final double sellPrice = node.getServerSellPrice();
    if (sellPrice < 0) {
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.itemsell.notforselling"));
        return CommandResult.empty();
    }
    // Get the cost.
    final int amt = is.getQuantity();
    final double overallCost = sellPrice * amt;
    if (econHelper.depositInPlayer(src, overallCost, false)) {
        src.setItemInHand(HandTypes.MAIN_HAND, null);
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsell.summary", Text.of(amt), Text.of(is), Text.of(econHelper.getCurrencySymbol(overallCost))));
        return CommandResult.success();
    }
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsell.error", Text.of(is)));
    return CommandResult.empty();
}
Also used : BlockState(org.spongepowered.api.block.BlockState) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemDataNode(io.github.nucleuspowered.nucleus.configurate.datatypes.ItemDataNode)

Example 20 with ReturnMessageException

use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.

the class TeleportAskCommand 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.CauseToPlayer event = new RequestEvent.CauseToPlayer(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(src).setTo(target).setSafe(!args.<Boolean>getOne("f").orElse(false));
    int warmup = getWarmup(src);
    if (warmup > 0) {
        tb.setWarmupTime(warmup);
    }
    double cost = getCost(src, args);
    if (cost > 0.) {
        tb.setCharge(src).setCost(cost);
    }
    tpHandler.addAskQuestion(target.getUniqueId(), new TeleportHandler.TeleportPrep(Instant.now().plus(30, ChronoUnit.SECONDS), src, cost, tb));
    target.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tpa.question", src.getName()));
    target.sendMessage(tpHandler.getAcceptDenyMessage());
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.tpask.sent", target.getName()));
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) RequestEvent(io.github.nucleuspowered.nucleus.modules.teleport.events.RequestEvent) TeleportHandler(io.github.nucleuspowered.nucleus.modules.teleport.handlers.TeleportHandler) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Aggregations

ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)45 Player (org.spongepowered.api.entity.living.player.Player)14 World (org.spongepowered.api.world.World)14 Text (org.spongepowered.api.text.Text)11 User (org.spongepowered.api.entity.living.player.User)9 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)9 CommandResult (org.spongepowered.api.command.CommandResult)7 Inventory (org.spongepowered.api.item.inventory.Inventory)6 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)5 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)5 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)5 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)5 Optional (java.util.Optional)5 CommandContext (org.spongepowered.api.command.args.CommandContext)5 CommandElement (org.spongepowered.api.command.args.CommandElement)5 GenericArguments (org.spongepowered.api.command.args.GenericArguments)5 Home (io.github.nucleuspowered.nucleus.api.nucleusdata.Home)4 Warp (io.github.nucleuspowered.nucleus.api.nucleusdata.Warp)4 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)4 NucleusTeleportHandler (io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler)4