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


Java InventoryAction.PLACE_SOME屬性代碼示例

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


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

示例1: 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

示例2: 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

示例3: onInventorySharing

@EventHandler(priority= EventPriority.HIGHEST)
private void onInventorySharing(InventoryClickEvent event) {
    HumanEntity humanEntity = event.getWhoClicked();
    if (humanEntity == null)
        return;

    if (!(humanEntity instanceof Player))
        return;

    final Player p = (Player)humanEntity;
    IArenaPlayer player = ArenaPlayer.get(p);
    if (player == null)
        return;

    IArena arena = player.getArena();

    if (arena == null)
        return;

    IContextSettings settings = player.getContextSettings();
    if (settings == null)
        return;

    if (settings.isSharingEnabled())
        return;

    // prevent sharing
    if ((event.getAction() == InventoryAction.PLACE_ALL ||
            event.getAction() == InventoryAction.PLACE_ONE ||
            event.getAction() == InventoryAction.PLACE_SOME)) {

        if (event.getInventory().getHolder() instanceof Chest ||
                event.getInventory().getHolder() instanceof DoubleChest) {

            if (event.getRawSlot() >= event.getInventory().getContents().length)
                return;

            event.setCancelled(true);
            event.setResult(Result.DENY);

            // close chest to prevent sharing bug
            // i.e. If you try enough, eventually the event wont fire but the item
            // will make it into chest.
            Bukkit.getScheduler().runTask(PVStarAPI.getPlugin(), new Runnable() {

                @Override
                public void run() {
                    p.closeInventory();
                }

            });
        }
    }
}
 
開發者ID:JCThePants,項目名稱:PV-Star,代碼行數:54,代碼來源:SharingListener.java


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