本文整理匯總了Java中org.bukkit.event.inventory.InventoryAction.PLACE_ALL屬性的典型用法代碼示例。如果您正苦於以下問題:Java InventoryAction.PLACE_ALL屬性的具體用法?Java InventoryAction.PLACE_ALL怎麽用?Java InventoryAction.PLACE_ALL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.bukkit.event.inventory.InventoryAction
的用法示例。
在下文中一共展示了InventoryAction.PLACE_ALL屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateShieldSlot
public static void updateShieldSlot(@NotNull Player player, @NotNull Inventory inventory, @NotNull Slot slot, int slotId,
InventoryType.SlotType slotType, InventoryAction action,
ItemStack currentItem, ItemStack cursor) {
ActionType actionType = ActionType.getTypeOfAction(action);
if (actionType == ActionType.GET) {
if (slot.isCup(currentItem)) {
return;
}
if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
inventory.setItem(slot.getSlotId(), slot.getCup());
} else {
player.getEquipment().setItemInOffHand(new ItemStack(Material.AIR));
}
} else if (actionType == ActionType.SET) {
if (slot.isCup(currentItem)) {
currentItem = null;
action = InventoryAction.PLACE_ALL;
}
if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
inventory.setItem(slot.getSlotId(), cursor);
} else {
player.getEquipment().setItemInOffHand(cursor);
}
}
InventoryManager.updateInventory(player, inventory, slotId, slotType, action, currentItem, cursor);
}
示例2: updateQuickSlot
public static void updateQuickSlot(@NotNull Player player, @NotNull Inventory inventory, @NotNull Slot slot, int slotId,
InventoryType.SlotType slotType, InventoryAction action,
ItemStack currentItem, ItemStack cursor) {
ActionType actionType = ActionType.getTypeOfAction(action);
if (actionType == ActionType.GET) {
if (slot.isCup(currentItem)) {
return;
}
if (player.getInventory().getHeldItemSlot() == slot.getQuickSlot()) {
InventoryUtils.heldFreeSlot(player, slot.getQuickSlot(), InventoryUtils.SearchType.NEXT);
}
if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
inventory.setItem(slot.getSlotId(), slot.getCup());
} else {
player.getInventory().setItem(slot.getQuickSlot(), slot.getCup());
}
action = InventoryAction.SWAP_WITH_CURSOR;
cursor = slot.getCup();
} else if (actionType == ActionType.SET) {
if (slot.isCup(currentItem)) {
currentItem = null;
action = InventoryAction.PLACE_ALL;
}
if (slotType == InventoryType.SlotType.QUICKBAR && InventoryAPI.isRPGInventory(inventory)) {
inventory.setItem(slot.getSlotId(), cursor);
} else {
player.getInventory().setItem(slot.getQuickSlot(), cursor);
}
}
InventoryManager.updateInventory(player, inventory, slotId, slotType, action, currentItem, cursor);
}
示例3: onClick
/**
* Handle a player click.
* @param evt
*/
public void onClick(InventoryClickEvent evt) {
InventoryAction action = evt.getAction();
if (IGNORE.contains(action)) {
evt.setCancelled(true);
return; // Don't allow these clicks.
}
Inventory top = evt.getView().getTopInventory();
boolean isTop = top.equals(evt.getClickedInventory());
boolean isBottom = evt.getView().getBottomInventory().equals(evt.getClickedInventory());
ItemStack add = null;
int slot = evt.getRawSlot();
if (slot >= 0 && isTop) {
GUIItem item = getItem(slot);
if (item != null) {
evt.setCancelled(true);
item.onClick(evt);
} else {
if (!isAllowStorage()) {
evt.setCancelled(true); // Don't allow depositing / withdrawing items.
return;
}
if (action == InventoryAction.HOTBAR_MOVE_AND_READD || action == InventoryAction.HOTBAR_SWAP) {
// Hotbar swap.
if (item != null || !isAllowStorage()) // Either they're not allowed or they're swapping with a DisplayItem.
add = evt.getWhoClicked().getInventory().getItem(evt.getHotbarButton());
} else if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_ONE) { //PLACE_SOME adds to an existing stack, we only want to fire when a new item is added.
add = evt.getCursor().clone();
if (action == InventoryAction.PLACE_ONE)
add.setAmount(1); // They're right clicking an item in.
}
}
} else if (isBottom && evt.isShiftClick()) { // They're trying to shift click an item in.
if (isAllowStorage() && top.firstEmpty() > -1) {
add = evt.getCurrentItem();
} else {
evt.setCancelled(true);
}
}
if (add != null) {
// We're depositing an item.
if (canDeposit(slot, add)) {
deposit(add);
} else {
evt.setCancelled(true);
}
}
}
示例4: 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();
}
示例5: 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());
}
示例6: 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();
}
});
}
}
}