本文整理汇总了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);
}
}
}
}
示例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);
}
}
}
}
示例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);
}
});
}
示例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);
}
}