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


Java SlotTransaction.getSlot方法代码示例

本文整理汇总了Java中org.spongepowered.api.item.inventory.transaction.SlotTransaction.getSlot方法的典型用法代码示例。如果您正苦于以下问题:Java SlotTransaction.getSlot方法的具体用法?Java SlotTransaction.getSlot怎么用?Java SlotTransaction.getSlot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.item.inventory.transaction.SlotTransaction的用法示例。


在下文中一共展示了SlotTransaction.getSlot方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onClickInventory

import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入方法依赖的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

示例2: onItemPickup

import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入方法依赖的package包/类
@Listener
public void onItemPickup(ChangeInventoryEvent.Pickup event, @First(typeFilter = {Player.class}) Player player) {

	IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
	if (character.isStub()) {
		return;
	}
	if (player.get(Keys.GAME_MODE).get() != GameModes.SURVIVAL)
		return;

	for (SlotTransaction slotTransaction : event.getTransactions()) {
		Slot i = slotTransaction.getSlot();
		int index = ((SlotAdapter) i).getOrdinal();
		if (Utils.isHotbar(index)) {
			ItemStack a = slotTransaction.getFinal().createStack();
			if (inventoryService.canUse(a, character) != CannotUseItemReson.OK) {
				event.setCancelled(true);
				return;
			} else {
				inventoryService.initializeHotbar(character, index, a);
			}
		}
	}
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:25,代码来源:InventoryListener.java

示例3: fireClickEvent

import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入方法依赖的package包/类
private void fireClickEvent(ClickInventoryEvent e)
{
    Optional<Player> optional = Sponge.getServer().getPlayer(playerUniqueId);
    if (!optional.isPresent())
    {
        return;
    }
    Player player = optional.get();
    CompletableFuture<Boolean> future = CompletableFuture.completedFuture(Boolean.TRUE);
    for (SlotTransaction slotTransaction : e.getTransactions())
    {
        Slot slot = slotTransaction.getSlot();
        SlotIndex pos = SpongeUnimplemented.getSlotOrdinal(slot);
        if (SpongeUnimplemented.isSlotInInventory(slot, e.getTargetInventory()) && slotToListen.matches(pos))
        {
            e.setCancelled(true);
            boolean allowAction = actionIntervalManager.allowAction(player, acceptableActionIntervalTick);
            if (allowAction && itemsInSlots.containsKey(pos))
            {
                future = future.thenApplyAsync(p -> processClickEvent(e, player, pos) && p, executorService);
            }
        }
    }
    future.thenAccept(shouldKeepInventoryOpen ->
    {
        if (!shouldKeepInventoryOpen)
        {
            SpongeUnimplemented.closeInventory(player, plugin);
        }
    });
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:32,代码来源:VirtualChestInventory.java

示例4: onItemMove

import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入方法依赖的package包/类
public void onItemMove(ClickInventoryEvent event, @First(typeFilter = Player.class) Player pl) {
	IActiveCharacter character = characterService.getCharacter(pl.getUniqueId());
	if (character.isStub()) {
		return;
	}
	for (SlotTransaction slotTransaction : event.getTransactions()) {
		Slot i = slotTransaction.getSlot();
		int index = ((SlotAdapter) i).getOrdinal();
		character.getSlotsToReinitialize().add(index);
	}
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:12,代码来源:InventoryListener.java


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