本文整理匯總了Java中org.bukkit.event.inventory.InventoryAction類的典型用法代碼示例。如果您正苦於以下問題:Java InventoryAction類的具體用法?Java InventoryAction怎麽用?Java InventoryAction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
InventoryAction類屬於org.bukkit.event.inventory包,在下文中一共展示了InventoryAction類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onClick
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
@EventHandler
public void onClick(InventoryClickEvent e) {
guiMap.getOptional(e.getWhoClicked()).ifPresent(gui -> {
InventoryAction action = e.getAction();
Inventory inv = e.getInventory();
if (action == InventoryAction.COLLECT_TO_CURSOR) {
for (ItemStack item : inv) {
if (e.getCursor().isSimilar(item)) {
e.setCancelled(true);
break;
}
}
}
gui.getHandlers().notify(e);
});
}
示例2: onPlayerClick
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerClick(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
HotbarView h = view(player);
if (e.getAction() == InventoryAction.HOTBAR_SWAP || e.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD) {
//isIconSlot is really fast but it only works with the main player inventory where the first 9 indexes are
//for the hotbar. this isn't exactly the main inventory but it works as well
if (h != null && h.isIconSlot(e.getHotbarButton())) {
e.setCancelled(true);
return;
}
}
if (h != null && (h.isIcon(e.getCurrentItem()) || h.isIcon((e.getCursor())))) {//TODO use normal slots
e.setCancelled(true);
player.updateInventory();
}
}
示例3: onQuickEquip
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onQuickEquip(PlayerInteractEvent event) {
final Player player = event.getPlayer();
if (!InventoryManager.playerIsLoaded(player) || event.getAction() != Action.RIGHT_CLICK_AIR &&
event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK &&
!event.getClickedBlock().getState().getClass().getSimpleName().contains("BlockState")) {
return;
}
ItemStack item = event.getItem();
if (ItemUtils.isEmpty(item)) {
return;
}
ArmorType armorType = ArmorType.matchType(item);
if (InventoryUtils.playerNeedArmor(player, armorType)) {
Slot armorSlot = SlotManager.instance().getSlot(armorType.name());
if (armorSlot == null) {
return;
}
event.setCancelled(!InventoryManager.validateArmor(player, InventoryAction.PLACE_ONE, armorSlot, item));
PlayerUtils.updateInventory(player);
}
}
示例4: getItem
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
@Override
public InventoryItem getItem(int pos, InventoryAction action) {
//real logic is here
/*
* Check slot. If in player's inventory, try to take. If in top inventory, try and put back.
*/
if (pos >= slots) {
//in player's inventory
doContribute(pos);
} else if (pos == slots - 1) {
doSubmit();
} else {
doReturn(pos);
}
return null; //tell it to do nothing
}
示例5: onInventoryClick
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
if (event.isCancelled() || !(event.getWhoClicked() instanceof Player)) return;
final Player p = (Player) event.getWhoClicked();
ItemStack item = event.getCurrentItem();
if(event.getInventory().getHolder() != p && ArmorStandTool.isTool(item)) {
event.setCancelled(true);
//noinspection deprecation
p.updateInventory();
return;
}
if(event.getAction() == InventoryAction.HOTBAR_SWAP || event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD) {
if(Utils.hasItems(p)) {
event.setCancelled(true);
//noinspection deprecation
p.updateInventory();
}
}
}
示例6: onAnvil
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
@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.");
}
}
}
}
示例7: getRelevantStack
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
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;
}
}
示例8: testOnItemsPickup
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
/**
* Make sure the "onItemsPickup" method is invoked when
* items are picked up in the inventory view.
*/
@Test
public void testOnItemsPickup() {
MockChestView view = new MockChestView(plugin, null);
_session.next(view);
BukkitTester.pause(2);
BukkitTester.viewClick(player,
SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.PICKUP_ALL);
BukkitTester.pause(2);
// check "onItemsPickup" is invoked
assertTrue(view.itemsPickup != null);
}
示例9: testOnItemsPlaced
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
/**
* Make sure the "onItemsPlaced" method is invoked when
* items are placed in the inventory view.
*/
@Test
public void testOnItemsPlaced() {
MockChestView view = new MockChestView(plugin, null);
_session.next(view);
BukkitTester.pause(2);
BukkitTester.viewClick(player,
SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.PLACE_ALL);
BukkitTester.pause(2);
// check "onItemsPlaced" is invoked
assertTrue(view.itemsPlaced != null);
}
示例10: testOnItemsDropped
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
/**
* Make sure the "onItemsDropped" method is invoked when
* items are dropped from the inventory view.
*/
@Test
public void testOnItemsDropped() {
MockChestView view = new MockChestView(plugin, null);
_session.next(view);
BukkitTester.pause(2);
BukkitTester.viewClick(player,
SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.DROP_ALL_CURSOR);
BukkitTester.pause(2);
// check "onItemsDropped" is invoked
assertTrue(view.itemsDropped != null);
}
示例11: testOnItemSelected
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
/**
* Make sure {@link #onItemSelect} is invoked when a menu item is clicked
* and that the correct {@link MenuItem} is passed into the invoked method.
*/
@Test
public void testOnItemSelected() {
MockMenuView view = new MockMenuView(plugin, null);
_session.next(view);
BukkitTester.pause(2);
MenuItem menuItem = new MenuItemBuilder(Material.WOOD).build(0);
menuItem.setVisible(view, true);
// select/click the menu item
BukkitTester.viewClick(player,
SlotType.CONTAINER, 0, ClickType.LEFT, InventoryAction.PICKUP_ALL);
BukkitTester.pause(2);
// check "onItemSelected" is invoked with correct menu item
assertEquals(menuItem, view.selected);
}
示例12: onInventoryClick
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
@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);
}
}
示例13: ExampleMenu
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
public ExampleMenu()
{
super("Test Menu", 4);
setItem(0, 0, new MenuItem()
{
public ItemStack getItem()
{
return new ItemBuilder(Material.PAPER).colorName("&a0,0").enchantEffect().build();
}
public boolean shouldUpdateItem()
{
return false;
}
public boolean onClick(Player player, ClickType clickType, InventoryAction action)
{
Bukkit.broadcastMessage(player.getName()+" clicked");
return false;
}
});
setItem(1,1, new BasicItem(
new ItemBuilder(Material.PAPER).colorName("&a1,1").enchantEffect().build(),
(player, clickType, action) ->
{
Bukkit.broadcastMessage(player.getName() + " clicked BasicItem");
return false;
})
);
}
示例14: collectToCursor
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void collectToCursor(InventoryClickEvent event) {
// If this hasn't been cancelled yet, cancel it so our implementation can take over
if(event.getAction() == InventoryAction.COLLECT_TO_CURSOR) {
event.setCancelled(true);
this.collectToCursor = true;
}
}
示例15: onInventoryClick
import org.bukkit.event.inventory.InventoryAction; //導入依賴的package包/類
@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));
}
}