當前位置: 首頁>>代碼示例>>Java>>正文


Java InventoryAction.MOVE_TO_OTHER_INVENTORY屬性代碼示例

本文整理匯總了Java中org.bukkit.event.inventory.InventoryAction.MOVE_TO_OTHER_INVENTORY屬性的典型用法代碼示例。如果您正苦於以下問題:Java InventoryAction.MOVE_TO_OTHER_INVENTORY屬性的具體用法?Java InventoryAction.MOVE_TO_OTHER_INVENTORY怎麽用?Java InventoryAction.MOVE_TO_OTHER_INVENTORY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.bukkit.event.inventory.InventoryAction的用法示例。


在下文中一共展示了InventoryAction.MOVE_TO_OTHER_INVENTORY屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onAnvil

@EventHandler
public void onAnvil(InventoryClickEvent event) {
    // The whole Anvil system is horribly broken right now, so we're just going to disallow
    // any kind of anvil activity for STB items.
    if (event.getWhoClicked() instanceof Player && event.getInventory().getType() == InventoryType.ANVIL) {
        if (event.getSlotType() == InventoryType.SlotType.CRAFTING) {
            if (SensibleToolbox.getItemRegistry().isSTBItem(event.getCursor())) {
                event.setCancelled(true);
                MiscUtil.errorMessage((Player) event.getWhoClicked(), "Sensible Toolbox items don't fit in a vanilla anvil.");
            }
        } else if (event.getRawSlot() > 2 && event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
            if (SensibleToolbox.getItemRegistry().isSTBItem(event.getCurrentItem())) {
                event.setCancelled(true);
                MiscUtil.errorMessage((Player) event.getWhoClicked(), "Sensible Toolbox items don't fit in a vanilla anvil.");
            }
        }
    }
}
 
開發者ID:desht,項目名稱:sensibletoolbox,代碼行數:18,代碼來源:AnvilListener.java

示例2: getRelevantStack

private ItemStackSource getRelevantStack(InventoryItemAction action, InventoryClickEvent event) {
    switch (action) {
        case PLACED_TOP:
            // fall through
        case PLACED_BOTTOM:
            // fall through
        case DROPPED:
            if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
                return ItemStackSource.SLOT;
            }

            return ItemStackSource.CURSOR;
        default:
            return ItemStackSource.SLOT;
    }
}
 
開發者ID:JCThePants,項目名稱:NucleusFramework,代碼行數:16,代碼來源:ChestEventListener.java

示例3: onInventoryClick

@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    if (e.getClickedInventory() == e.getInventory())
        onClick(e);
    if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        if (getHistory((Player) e.getWhoClicked()) != null)
            e.setCancelled(true);
    }
}
 
開發者ID:upperlevel,項目名稱:uppercore,代碼行數:9,代碼來源:GuiManager.java

示例4: onInventoryClick

@EventHandler(priority = EventPriority.LOW)
public void onInventoryClick(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();

    if(!inventories.containsKey(p))
        return;

    if(e.getAction() == InventoryAction.COLLECT_TO_CURSOR ||
            e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        e.setCancelled(true);
        return;
    }

    if(e.getClickedInventory() == p.getOpenInventory().getTopInventory()) {
        e.setCancelled(true);

        int row = e.getSlot() / 9;
        int column = e.getSlot() % 9;

        if(row < 0 || column < 0)
            return;

        SmartInventory inv = inventories.get(p);

        if(row >= inv.getRows() || column >= inv.getColumns())
            return;

        inv.getListeners().stream()
                .filter(listener -> listener.getType() == InventoryClickEvent.class)
                .forEach(listener -> ((InventoryListener<InventoryClickEvent>) listener).accept(e));

        contents.get(p).get(row, column).ifPresent(item -> item.run(e));
    }
}
 
開發者ID:MinusKube,項目名稱:SmartInvs,代碼行數:34,代碼來源:InventoryManager.java

示例5: onInventoryClick

@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
	if(controller.isPlaying()) {
		boolean move = e.getRawSlot() >= e.getInventory().getSize()
				&& e.getCurrentItem().getType() == Material.EYE_OF_ENDER
				&& e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY;
		boolean inventory = e.getRawSlot() < e.getInventory().getSize()
				&& e.getCursor().getType() == Material.EYE_OF_ENDER
				&& e.getAction() != InventoryAction.PICKUP_ALL;

		if(move || inventory)
			e.setResult(Result.DENY);
	}
}
 
開發者ID:kyriog,項目名稱:rftd,代碼行數:14,代碼來源:InventoryListener.java

示例6: updateInventory

private static void updateInventory(
        @NotNull Player player,
        @NotNull Inventory inventory,
        int slot,
        InventoryType.SlotType slotType,
        InventoryAction action,
        ItemStack currentItem,
        ItemStack cursorItem
) {
    if (ActionType.getTypeOfAction(action) == ActionType.DROP) {
        return;
    }

    if (action == InventoryAction.PLACE_ALL) {
        if (ItemUtils.isEmpty(currentItem)) {
            currentItem = cursorItem.clone();
        } else {
            currentItem.setAmount(currentItem.getAmount() + cursorItem.getAmount());
        }

        cursorItem = null;
    } else if (action == InventoryAction.PLACE_ONE) {
        if (ItemUtils.isEmpty(currentItem)) {
            currentItem = cursorItem.clone();
            currentItem.setAmount(1);
            cursorItem.setAmount(cursorItem.getAmount() - 1);
        } else if (currentItem.getMaxStackSize() < currentItem.getAmount() + 1) {
            currentItem.setAmount(currentItem.getAmount() + 1);
            cursorItem.setAmount(cursorItem.getAmount() - 1);
        }
    } else if (action == InventoryAction.PLACE_SOME) {
        cursorItem.setAmount(currentItem.getMaxStackSize() - currentItem.getAmount());
        currentItem.setAmount(currentItem.getMaxStackSize());
    } else if (action == InventoryAction.SWAP_WITH_CURSOR) {
        ItemStack tempItem = cursorItem.clone();
        cursorItem = currentItem.clone();
        currentItem = tempItem;
    } else if (action == InventoryAction.PICKUP_ALL) {
        cursorItem = currentItem.clone();
        currentItem = null;
    } else if (action == InventoryAction.PICKUP_HALF) {
        ItemStack item = currentItem.clone();
        if (currentItem.getAmount() % 2 == 0) {
            item.setAmount(item.getAmount() / 2);
            currentItem = item.clone();
            cursorItem = item.clone();
        } else {
            currentItem = item.clone();
            currentItem.setAmount(item.getAmount() / 2);
            cursorItem = item.clone();
            cursorItem.setAmount(item.getAmount() / 2 + 1);
        }
    } else if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        player.getInventory().addItem(currentItem);
        currentItem = null;
    }

    if (slotType == InventoryType.SlotType.QUICKBAR) {
        if (slot < 9) { // Exclude shield
            player.getInventory().setItem(slot, currentItem);
        }
    } else {
        inventory.setItem(slot, currentItem);
    }

    player.setItemOnCursor(cursorItem);
    player.updateInventory();
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:68,代碼來源:InventoryManager.java

示例7: testOnInventoryMoveTnt

@Test
public void testOnInventoryMoveTnt() {
	when(player.getGameMode()).thenReturn(GameMode.SURVIVAL);
	ItemStack item = new ItemStack(Material.TNT, 1);
	
	
	Inventory top = mock(Inventory.class);
	when(top.getHolder()).thenReturn(mock(Dropper.class));
	when(top.getSize()).thenReturn(9);
	
	Inventory bottom = mock(Inventory.class);
	when(bottom.getHolder()).thenReturn(mock(Player.class));
	when(bottom.getSize()).thenReturn(45);
	
	InventoryView view = mock(InventoryView.class);
	when(view.getPlayer()).thenReturn(player);
	when(view.getTopInventory()).thenReturn(top);
	when(view.getBottomInventory()).thenReturn(bottom);
	when(view.getCursor()).thenReturn(item);
	when(view.getItem(eq(5))).thenReturn(item);
	when(view.getItem(eq(40))).thenReturn(item);
	
	InventoryClickEvent e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
	when(config.canPerform(ExileRule.PLACE_TNT)).thenReturn(true);
	dut.onInventoryClick(e);
	assertFalse(e.isCancelled());
	
	e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
	when(config.canPerform(ExileRule.PLACE_TNT)).thenReturn(false);
	dut.onInventoryClick(e);
	assertFalse(e.isCancelled());
	
	e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
	when(config.canPerform(ExileRule.PLACE_TNT)).thenReturn(true);
	when(pearlApi.isPlayerExiled(uid)).thenReturn(true);
	dut.onInventoryClick(e);
	assertFalse(e.isCancelled());
	
	e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
	when(config.canPerform(ExileRule.PLACE_TNT)).thenReturn(false);
	dut.onInventoryClick(e);
	assertTrue(e.isCancelled());

	e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
	when(top.getHolder()).thenReturn(mock(Chest.class));
	dut.onInventoryClick(e);
	assertFalse(e.isCancelled());
	
	e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_ALL);
	when(top.getHolder()).thenReturn(mock(Hopper.class));
	dut.onInventoryClick(e);
	assertTrue(e.isCancelled());
	
	e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_ONE);
	when(top.getHolder()).thenReturn(mock(Dispenser.class));
	dut.onInventoryClick(e);
	assertTrue(e.isCancelled());
	
	e = new InventoryClickEvent(view, null, 5, ClickType.SHIFT_LEFT, InventoryAction.MOVE_TO_OTHER_INVENTORY);
	dut.onInventoryClick(e);
	assertFalse(e.isCancelled());

	e = new InventoryClickEvent(view, null, 40, ClickType.LEFT, InventoryAction.PLACE_SOME);
	dut.onInventoryClick(e);
	assertFalse(e.isCancelled());
	
	e = new InventoryClickEvent(view, null, 40, ClickType.SHIFT_LEFT, InventoryAction.MOVE_TO_OTHER_INVENTORY);
	when(view.getType()).thenReturn(InventoryType.DISPENSER);
	assertEquals(e.getCurrentItem(), item);
	dut.onInventoryClick(e);
	assertTrue(e.isCancelled());

}
 
開發者ID:DevotedMC,項目名稱:ExilePearl,代碼行數:73,代碼來源:ExileListenerTest.java


注:本文中的org.bukkit.event.inventory.InventoryAction.MOVE_TO_OTHER_INVENTORY屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。