当前位置: 首页>>代码示例>>Java>>正文


Java ClickInventoryEvent类代码示例

本文整理汇总了Java中org.spongepowered.api.event.item.inventory.ClickInventoryEvent的典型用法代码示例。如果您正苦于以下问题:Java ClickInventoryEvent类的具体用法?Java ClickInventoryEvent怎么用?Java ClickInventoryEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClickInventoryEvent类属于org.spongepowered.api.event.item.inventory包,在下文中一共展示了ClickInventoryEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAddTrailCommand

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
private static CommandSpec getAddTrailCommand() {
    return CommandSpec.builder()
        .permission("happytrails.command.add")
        .description(Text.of("Adds a new trail"))
        .executor((src, args) -> {
            if (!(src instanceof Player)) {
                return CommandResult.empty();
            }
            final Inventory creator = Inventory.builder()
                .of(InventoryArchetypes.CHEST)
                .property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(Text.of(TextColors.AQUA, "Create a Trail")))
                .listener(ClickInventoryEvent.Primary.class, (event) -> {

                })
                .build(HappyTrails.getInstance());
            creator.offer(ItemStack.of(ItemTypes.FIREWORKS, 1));
            creator.offer(ItemStack.builder().fromBlockState(BlockTypes.REDSTONE_BLOCK.getDefaultState()).build());
            ((Player) src).openInventory(creator);
            return CommandResult.success();
        })
        .build();

}
 
开发者ID:gabizou,项目名称:HappyTrails,代码行数:24,代码来源:TrailCommands.java

示例2: createInventory

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
public Inventory createInventory(Player player)
{
    UUID uuid = player.getUniqueId();
    if (!inventories.containsKey(uuid))
    {
        VirtualChestEventListener listener = new VirtualChestEventListener(player);
        Inventory chestInventory = Inventory.builder().of(InventoryArchetypes.CHEST).withCarrier(player)
                .property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(this.title))
                .property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, this.height))
                .listener(ClickInventoryEvent.class, listener::fireClickEvent)
                .listener(InteractInventoryEvent.Open.class, listener::fireOpenEvent)
                .listener(InteractInventoryEvent.Close.class, listener::fireCloseEvent)
                .build(this.plugin);
        inventories.put(uuid, chestInventory);
        return chestInventory;
    }
    return inventories.get(uuid);
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:19,代码来源:VirtualChestInventory.java

示例3: onItemForge

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Listener
public void onItemForge(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {

    /*if (inventory.getArchetype() == InventoryArchetypes.ANVIL) {

        Inventory forgingInputs = inventory.query(InputSlot.class);

        PermHandler ph = PermHandler.getInstance();
        
        forgingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
            String itemId = itemStack.getItem().getType().getId();
            if (!ph.checkPerm(player, "protectionperms.item.forge." + itemId)) {
                event.setCancelled(true);
                player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to forge " + itemId + '!'));
            }
        }));
    }*/
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:19,代码来源:ForgeItemListener.java

示例4: onItemEnchant

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Listener
public void onItemEnchant(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {

    /*if (inventory.getArchetype() == InventoryArchetypes.ENCHANTING_TABLE) {

        Inventory enchantingInputs = inventory.query(InputSlot.class);

        enchantingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
            String itemId = itemStack.getItem().getType().getId();

            itemStack.getValue(Keys.ITEM_ENCHANTMENTS).ifPresent(itemEnchantments -> itemEnchantments.forEach(enchantment -> {
                String enchantmentId = enchantment.getEnchantment().getId();
                if (!player.hasPermission("protectionperms.item.enchant." + itemId + ".with." + enchantmentId)) {
                    event.setCancelled(true);
                    player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to enchant " + itemId + " with " + enchantmentId + '!'));
                }
            }));
        }));
    }*/
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:21,代码来源:EnchantItemListener.java

示例5: onItemEquip

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Listener
public void onItemEquip(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {

    if (inventory.getArchetype() == InventoryArchetypes.PLAYER) {

        Inventory equipmentSlots = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(EquipmentSlot.class));

        equipmentSlots.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {

            ItemType itemType = itemStack.getType();
            String itemId = itemType.getId();

            PermHandler ph = PermHandler.getInstance();

            if (!ph.checkPerm(player, "protectionperms.item.equip." + itemId + ".on.self")) {
                event.setCancelled(true);
                player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to equip " + itemType.getName() + '!'));
            }
        }));
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:22,代码来源:EquipItemListener.java

示例6: onItemCraft

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Listener
public void onItemCraft(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {

    if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {

        Inventory craftingOutputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingOutput.class));

        craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {

            ItemType itemType = itemStack.getType();
            String itemId = itemType.getId();

            PermHandler ph = PermHandler.getInstance();

            if (!ph.checkPerm(player, "protectionperms.item.craft." + itemId)) {
                event.setCancelled(true);
                player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemType.getName() + '!'));
            }
        }));
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:22,代码来源:CraftItemListener.java

示例7: onItemSmelt

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Listener
public void onItemSmelt(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {

    /*if (inventory.getArchetype() == InventoryArchetypes.BREWING_STAND) {

        Inventory brewingInputs = inventory.query(InputSlot.class);

        brewingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
            String itemId = itemStack.getItem().getType().getId();

            PermHandler ph = PermHandler.getInstance();
            
            if (slot instanceof FuelSlot) {
                if (!ph.checkPerm(player, "protectionperms.item.fuel." + itemId)) {
                    event.setCancelled(true);
                    player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemId + " as fuel!"));
                }
            } else {
                if (!ph.checkPerm(player, "protectionperms.item.brew." + itemId)) {
                    event.setCancelled(true);
                    player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to brew " + itemId + '!'));
                }
            }
        }));
    }*/
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:27,代码来源:BrewItemListener.java

示例8: onClickInventory

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Listener
public void onClickInventory(final ClickInventoryEvent event, @First Player player) {
    //Make sure we have a transaction to validate
    if (event.getTransactions().size() <= 0) {
        return;
    }
    //Get the first transaction of this event
    final SlotTransaction slotTransaction = event.getTransactions().get(0);

    final Slot slot = slotTransaction.getSlot();

    //If the player is interacting with a TileEntityCarrier
    if (slot.parent() instanceof TileEntityCarrier) {
        //If the final item is NONE (or amount is less) person is trying to withdraw (so we care about it)
        if (slotTransaction.getFinal().getType() == ItemTypes.NONE || slotTransaction.getFinal().getCount() < slotTransaction.getOriginal().getCount()) {
            //Then check to see if there's a lock
            final Optional<Lock> lock = Latch.getLockManager().getLock(((TileEntityCarrier) slot.parent()).getLocation());

            //If there's a donation lock the player CANNOT access
            if (lock.isPresent() && lock.get().getLockType() == LockType.DONATION && !lock.get().canAccess(player.getUniqueId())) {
                event.setCancelled(true);
            }
        }
    }
}
 
开发者ID:ichorpowered,项目名称:latch,代码行数:26,代码来源:InteractBlockListener.java

示例9: handleCreativeClick

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Override
public void handleCreativeClick(ClientContainer clientContainer, @Nullable ClientSlot clientSlot, @Nullable ItemStack itemStack) {
    final LanternPlayer player = clientContainer.getPlayer();

    final CauseStack causeStack = CauseStack.current();
    if (clientSlot == null) {
        if (itemStack != null) {
            causeStack.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
            LanternEventHelper.handleDroppedItemSpawning(player.getTransform(), itemStack.createSnapshot());
        }
    } else if (clientSlot instanceof ClientSlot.Slot) {
        final AbstractSlot slot = ((ClientSlot.Slot) clientSlot).getSlot();
        final PeekedSetTransactionResult result = slot.peekSet(itemStack);

        // We do not know the remaining stack in the cursor,
        // so just use none as new item
        final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(
                LanternItemStack.toSnapshot(itemStack), ItemStackSnapshot.NONE);

        final ClickInventoryEvent.Creative event = SpongeEventFactory.createClickInventoryEventCreative(
                causeStack.getCurrentCause(), cursorTransaction, this.container,
                this.container.transformSlots(result.getTransactions()));
        finishInventoryEvent(event);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:26,代码来源:VanillaContainerInteractionBehavior.java

示例10: finishInventoryEvent

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
private void finishInventoryEvent(ChangeInventoryEvent event) {
    final List<SlotTransaction> slotTransactions = event.getTransactions();
    Sponge.getEventManager().post(event);
    if (!event.isCancelled()) {
        if (!(event instanceof ClickInventoryEvent.Creative) && event instanceof ClickInventoryEvent) {
            final Transaction<ItemStackSnapshot> cursorTransaction = ((ClickInventoryEvent) event).getCursorTransaction();
            if (cursorTransaction.isValid()) {
                setCursorItem(cursorTransaction.getFinal().createStack());
            }
        }
        slotTransactions.stream().filter(Transaction::isValid).forEach(
                transaction -> transaction.getSlot().set(transaction.getFinal().createStack()));
        if (event instanceof SpawnEntityEvent) {
            LanternWorld.finishSpawnEntityEvent((SpawnEntityEvent) event);
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:VanillaContainerInteractionBehavior.java

示例11: createFilter

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Override
protected ActionFilterTemplate createFilter() {
    return ActionFilterTemplate.builder()
            .addOption(new ActionFilterOption<ItemStack, ClickInventoryEvent>("result",
                    MatcherType.ITEM_STACK, e -> {
                        if (e instanceof Shift.Primary || e instanceof Shift.Secondary) {
                            Set<ItemStack> consumed = getConsumedItemStacks(e.getTransactions());
                            Entry<ItemStack, Integer> result = getResult(e.getTransactions());
                            int ingredientsQuantity = getIngredientsQuantity(consumed, result.getKey());
                            int resultQuantity = result.getValue();
                            int craftedQuantity = resultQuantity / ingredientsQuantity;
                            ItemStack craftedStack = createStackWithCustomQuantity(result.getKey(),
                                    craftedQuantity);
                            return craftedStack;
                        } else if (e instanceof Primary || e instanceof Secondary) {
                            return e.getCursorTransaction().getFinal().createStack();
                        }
                        throw new AssertionError();
                    }))
            .build();
}
 
开发者ID:Monospark,项目名称:ActionControl,代码行数:22,代码来源:CraftRule.java

示例12: onInteract

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Listener
@Exclude({ClickInventoryEvent.Close.class, ClickInventoryEvent.Open.class})
public void onInteract(ClickInventoryEvent event, @Root Player p) {
    try {
        //Get target inventory owner
        Inventory inv = event.getTargetInventory();
        if (!(inv instanceof CarriedInventory)) return;
        CarriedInventory cinv = (CarriedInventory) inv;
        if (!cinv.getCarrier().isPresent() || !(cinv.getCarrier().get() instanceof User)) return;
        User t = (User) cinv.getCarrier().get();

        //Check if player is in invsee & Cancel event if player doesn't have permission
        UltimateUser up = UltimateCore.get().getUserService().getUser(p);
        if (up.get(InventoryKeys.INVSEE_TARGET).isPresent() && up.get(InventoryKeys.INVSEE_TARGET).get().equals(t.getUniqueId())) {
            if (!p.hasPermission("uc.inventory.invsee.modify")) {
                event.getCursorTransaction().setValid(false);
                event.setCancelled(true);
            }
        }
    } catch (Exception ignore) {
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:23,代码来源:InventoryListener.java

示例13: cancelClick

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void cancelClick(ClickInventoryEvent event) {
    Container container = event.getTargetInventory();
    if (FirstGuiPreview.FIRST_GUI_CONTAINERS.containsKey(container) ||
            SecondGuiPreview.SECOND_GUI_CONTAINERS.containsKey(container)) {
        event.setCancelled(true);
    }
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:9,代码来源:PreviewListener.java

示例14: cancelClick

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
@Listener(order = Order.LATE)
public void cancelClick(ClickInventoryEvent event) {
    Container container = event.getTargetInventory();
    if (FirstOpenManager.FIRST_GUI_CONTAINERS.containsKey(container)) {
        event.setCancelled(true);
    }
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:8,代码来源:FirstGuiOpenManagerListener.java

示例15: RouletteCrateView

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入依赖的package包/类
public RouletteCrateView(HuskyCrates plugin, Player runner, VirtualCrate virtualCrate){
    this.plugin = plugin;
    vc = virtualCrate;
    ourplr = runner;
    items = vc.getItemSet();
    if(virtualCrate.scrambleRewards){
        scrambleRewards();
    }
    disp = Inventory.builder()
            .of(InventoryArchetypes.DISPENSER)
            .listener(InteractInventoryEvent.class, evt ->{
                if(!(evt instanceof InteractInventoryEvent.Open) && !(evt instanceof  InteractInventoryEvent.Close)){
                    evt.setCancelled(true);
                    if(!stopped && evt instanceof ClickInventoryEvent){
                        ourplr.playSound(SoundTypes.ENTITY_FIREWORK_LAUNCH,ourplr.getLocation().getPosition(),1);
                    }
                    stopped = true;
                }

            })
            .property(InventoryTitle.PROPERTY_NAME,InventoryTitle.of(TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName)))
            .build(plugin);
    updateInv(0);
    Scheduler scheduler = Sponge.getScheduler();
    Task.Builder taskBuilder = scheduler.createTaskBuilder();
    updater = taskBuilder.execute(this::updateTick).intervalTicks(1).submit(plugin);
}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:28,代码来源:RouletteCrateView.java


注:本文中的org.spongepowered.api.event.item.inventory.ClickInventoryEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。