Java Code Examples for org.bukkit.event.inventory.InventoryType#PLAYER

The following examples show how to use org.bukkit.event.inventory.InventoryType#PLAYER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (event.getClickedInventory() == null) {
        return;
    }

    if (event.getClickedInventory().getType() == InventoryType.PLAYER) {
        Player p = (Player) event.getWhoClicked();
        if (Main.isPlayerInGame(p)) {
            GamePlayer gPlayer = Main.getPlayerGameProfile(p);
            Game game = gPlayer.getGame();
            if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 2
Source File: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (event.getClickedInventory() == null) {
        return;
    }

    if (event.getClickedInventory().getType() == InventoryType.PLAYER) {
        Player p = (Player) event.getWhoClicked();
        if (Main.isPlayerInGame(p)) {
            GamePlayer gPlayer = Main.getPlayerGameProfile(p);
            Game game = gPlayer.getGame();
            if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 3
Source File: EnhancedItemListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Prevents enhanced item from storing.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent e) {
    if ((e.getInventory().getType() != InventoryType.CRAFTING) && (e.getInventory().getType() != InventoryType.PLAYER)) {
        if ((e.getClick().equals(ClickType.NUMBER_KEY)) && (e.getWhoClicked().getInventory().getItem(e.getHotbarButton()) != null)) {
            ItemStack itemMoved = e.getWhoClicked().getInventory().getItem(e.getHotbarButton());
            if ((itemMoved.hasItemMeta()) && (itemMoved.getItemMeta().hasLore())) {
                if (itemMoved.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) {
                    e.setCancelled(true);
                    Util.sendMessage(SettingsManager.lang.getString("messages.noStorage"), e.getWhoClicked());
                }
            }
        }
        if (e.getCurrentItem() != null) {
            if ((e.getCurrentItem().hasItemMeta()) && (e.getCurrentItem().getItemMeta().hasLore())) {
                if (e.getCurrentItem().getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) {
                    e.setCancelled(true);
                    Util.sendMessage(SettingsManager.lang.getString("messages.noStorage"), e.getWhoClicked());
                }
            }
        }
    }
}
 
Example 4
Source File: KitLoading.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void StopClicking(InventoryClickEvent event)
{
    HumanEntity entity = event.getWhoClicked();
    ItemStack stack = event.getCurrentItem();
    InventoryType top = event.getView().getTopInventory().getType();
    
    if (stack != null && (entity instanceof Player)) 
    {
    	if (top == InventoryType.PLAYER || top == InventoryType.WORKBENCH || top == InventoryType.CRAFTING) 
    		return;

    	if(KitUtils.isSoulbound(stack))
          event.setCancelled(true); 
    }
 }
 
Example 5
Source File: BackpackListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onClick(InventoryClickEvent e) {
    ItemStack item = backpacks.get(e.getWhoClicked().getUniqueId());

    if (item != null) {
        SlimefunItem backpack = SlimefunItem.getByItem(item);

        if (backpack instanceof SlimefunBackpack) {
            if (e.getClick() == ClickType.NUMBER_KEY) {
                if (e.getClickedInventory().getType() != InventoryType.PLAYER) {
                    ItemStack hotbarItem = e.getWhoClicked().getInventory().getItem(e.getHotbarButton());

                    if (!isAllowed((SlimefunBackpack) backpack, hotbarItem)) {
                        e.setCancelled(true);
                    }
                }
            }
            else if (!isAllowed((SlimefunBackpack) backpack, e.getCurrentItem())) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example 6
Source File: StoreListener.java    From skRayFall with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Remove the store/unstore event possibility when an inventory is closed.
 *
 * @param evt The InventoryCloseEvent used to remove the possibility of a store/unstore
 *            event
 */
@EventHandler
public void onClose(InventoryCloseEvent evt) {
    if (evt.getView().getBottomInventory().getType() == InventoryType.PLAYER
            && (evt.getView().getTopInventory().getType() == InventoryType.CHEST
            || evt.getView().getTopInventory().getType() == InventoryType.ENDER_CHEST
            || evt.getView().getTopInventory().getType() == InventoryType.HOPPER
            || evt.getView().getTopInventory().getType() == InventoryType.DISPENSER
            || evt.getView().getTopInventory().getType() == InventoryType.DROPPER)) {
        if (storePossible.contains(evt.getPlayer())) {
            storePossible.remove(evt.getPlayer());
        } else if (unstorePossible.contains(evt.getPlayer())) {
            unstorePossible.remove(evt.getPlayer());
        }
    }
}
 
Example 7
Source File: CraftInventory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public InventoryType getType() {
    // Thanks to Droppers extending Dispensers, order is important.
    if (inventory instanceof InventoryCrafting) {
        return inventory.getSizeInventory() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING;
    } else if (inventory instanceof InventoryPlayer) {
        return InventoryType.PLAYER;
    } else if (inventory instanceof TileEntityDropper) {
        return InventoryType.DROPPER;
    } else if (inventory instanceof TileEntityDispenser) {
        return InventoryType.DISPENSER;
    } else if (inventory instanceof TileEntityFurnace) {
        return InventoryType.FURNACE;
    } else if (this instanceof CraftInventoryEnchanting) {
        return InventoryType.ENCHANTING;
    } else if (inventory instanceof TileEntityBrewingStand) {
        return InventoryType.BREWING;
    } else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) {
        return ((CraftInventoryCustom.MinecraftInventory) inventory).getType();
    } else if (inventory instanceof InventoryEnderChest) {
        return InventoryType.ENDER_CHEST;
    } else if (inventory instanceof InventoryMerchant) {
        return InventoryType.MERCHANT;
    } else if (inventory instanceof TileEntityBeacon) {
        return InventoryType.BEACON;
    } else if (this instanceof CraftInventoryAnvil) {
        return InventoryType.ANVIL;
    } else if (inventory instanceof IHopper) {
        return InventoryType.HOPPER;
    } else if (inventory instanceof TileEntityShulkerBox) {
        return InventoryType.SHULKER_BOX;
    } else {
        return InventoryType.CHEST;
    }
}
 
Example 8
Source File: GUIListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prevents item glitched into menu.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent e) {
    if ((e.getInventory().getType() != InventoryType.CRAFTING) && (e.getInventory().getType() != InventoryType.PLAYER)) {
        if ((e.getClick().equals(ClickType.NUMBER_KEY)) && (e.getWhoClicked().getInventory().getItem(e.getHotbarButton()) != null)) {
            Player player = (Player) e.getWhoClicked();
            String playerName = player.getName();
            GUIAbstract gui = GUIManager.getMap().get(playerName);
            if (gui != null && gui.getInventory().equals(e.getInventory())) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example 9
Source File: CraftInventory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public InventoryType getType() {
    // Thanks to Droppers extending Dispensers, order is important.
    if (inventory instanceof net.minecraft.inventory.InventoryCrafting) {
        return inventory.getSizeInventory() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING;
    } else if (inventory instanceof net.minecraft.entity.player.InventoryPlayer) {
        return InventoryType.PLAYER;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityDropper) {
        return InventoryType.DROPPER;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityDispenser) {
        return InventoryType.DISPENSER;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityFurnace) {
        return InventoryType.FURNACE;
    } else if (inventory instanceof net.minecraft.inventory.ContainerEnchantTableInventory) {
        return InventoryType.ENCHANTING;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityBrewingStand) {
        return InventoryType.BREWING;
    } else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) {
        return ((CraftInventoryCustom.MinecraftInventory) inventory).getType();
    } else if (inventory instanceof net.minecraft.inventory.InventoryEnderChest) {
        return InventoryType.ENDER_CHEST;
    } else if (inventory instanceof net.minecraft.inventory.InventoryMerchant) {
        return InventoryType.MERCHANT;
    } else if (inventory instanceof net.minecraft.tileentity.TileEntityBeacon) {
        return InventoryType.BEACON;
    } else if (inventory instanceof net.minecraft.inventory.ContainerRepairInventory) {
        return InventoryType.ANVIL;
    } else if (inventory instanceof net.minecraft.tileentity.IHopper) {
        return InventoryType.HOPPER;
    } else {
        return InventoryType.CHEST;
    }
}
 
Example 10
Source File: QuestItemHandler.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onItemMove(final InventoryClickEvent event) {
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }
    if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) {
        return;
    }
    final String playerID = PlayerConverter.getID((Player) event.getWhoClicked());
    ItemStack item;
    switch (event.getAction()) {
    case MOVE_TO_OTHER_INVENTORY:
        item = event.getCurrentItem();
        break;
    case PLACE_ALL:
    case PLACE_ONE:
    case PLACE_SOME:
    case SWAP_WITH_CURSOR:
        if (event.getClickedInventory().getType() != InventoryType.PLAYER) {
            item = event.getCursor();
        } else {
            item = null;
        }
        break;
    case HOTBAR_MOVE_AND_READD:
    case HOTBAR_SWAP:
        if (event.getClickedInventory().getType() != InventoryType.PLAYER) {
            item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
        } else {
            item = null;
        }
        break;
    default:
        item = null;
        break;
    }
    if (item != null && (Journal.isJournal(playerID, item) || Utils.isQuestItem(item))) {
        event.setCancelled(true);
    }
}
 
Example 11
Source File: InventoryForItemStorage.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void inventoryClick(InventoryClickEvent event) {
	Inventory inventory = event.getClickedInventory();
	if (inventory != null) {
		InventoryAction action = event.getAction();
		if (action == InventoryAction.COLLECT_TO_CURSOR) {
			event.setCancelled(true);
		} else if (inventory.getType() == InventoryType.PLAYER) {
			if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
				event.setCancelled(true);
			}
		} else {
			event.setCancelled(true);
			int slot = event.getSlot();
			if (slot < ITEMS_PER_PAGE) {
				if (event.getCursor().getType() == Material.AIR && _originaItems[slot] != null) {
					event.getView().setCursor(_originaItems[slot]);
				}
			} else if (slot == 52) {
				// previous page
				changePage(-1);
			} else if (slot == 53) {
				// next page
				changePage(1);
			}
		}
	}
	
}
 
Example 12
Source File: InventoryForItemStorage.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void inventoryDrag(InventoryDragEvent event) {
	InventoryView view = event.getView();
	for (int slot : event.getRawSlots()) {
		if (view.getInventory(slot).getType() != InventoryType.PLAYER) {
			event.setCancelled(true);
			return;
		}
	}
}
 
Example 13
Source File: PotionFuelsListener.java    From UHC with MIT License 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void on(InventoryClickEvent event) {
    if (event.getInventory().getType() != InventoryType.BREWING) return;

    // quick exit
    if (disabled.size() == 0) return;

    // clicked outside of the window
    if (event.getClickedInventory() == null) return;

    final InventoryType clicked = event.getClickedInventory().getType();

    // get any relevant stack to check the type of based on the action took
    Optional<ItemStack> relevant = Optional.absent();
    switch (event.getAction()) {
        case MOVE_TO_OTHER_INVENTORY:
            // only worry about player -> stand
            if (clicked == InventoryType.PLAYER) {
                relevant = Optional.fromNullable(event.getCurrentItem());
            }
            break;
        case PLACE_ALL:
        case PLACE_SOME:
        case PLACE_ONE:
        case SWAP_WITH_CURSOR:
            // only worry about within a stand
            if (clicked == InventoryType.BREWING) {
                relevant = Optional.fromNullable(event.getCursor());
            }
            break;
        case HOTBAR_SWAP:
            // only worry about within a stand
            if (clicked == InventoryType.BREWING) {
                relevant = Optional.fromNullable(
                        event.getWhoClicked().getInventory().getItem(event.getHotbarButton())
                );
            }
            break;
        default:
    }

    if (relevant.isPresent() && disabled.contains(relevant.get().getType())) {
        event.getWhoClicked().sendMessage(messages.get(relevant.get().getType()));
        event.setCancelled(true);
    }
}
 
Example 14
Source File: HorseArmourModule.java    From UHC with MIT License 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void on(InventoryClickEvent event) {
    if (isEnabled()) return;

    if (!(event.getView().getTopInventory() instanceof HorseInventory)) return;

    // clicked outside of the window
    if (event.getClickedInventory() == null) return;

    final InventoryType clicked = event.getClickedInventory().getType();

    // get any relevant stack to check the type of based on the action took
    Optional<ItemStack> relevant = Optional.absent();
    switch (event.getAction()) {
        case MOVE_TO_OTHER_INVENTORY:
            // only worry about player -> horse
            if (clicked == InventoryType.PLAYER) {
                relevant = Optional.fromNullable(event.getCurrentItem());
            }
            break;
        case PLACE_ALL:
        case PLACE_SOME:
        case PLACE_ONE:
        case SWAP_WITH_CURSOR:
            // only worry about within the horse
            if (clicked != InventoryType.PLAYER) {
                relevant = Optional.fromNullable(event.getCursor());
            }
            break;
        case HOTBAR_SWAP:
            // only worry about within a horse
            if (clicked != InventoryType.PLAYER) {
                relevant = Optional.fromNullable(
                        event.getWhoClicked().getInventory().getItem(event.getHotbarButton())
                );
            }
            break;
        default:
    }

    if (relevant.isPresent() && DISABLED.contains(relevant.get().getType())) {
        event.getWhoClicked().sendMessage(messages.getRaw("disabled message"));
        event.setCancelled(true);
    }
}
 
Example 15
Source File: StoreListener.java    From skRayFall with GNU General Public License v3.0 4 votes vote down vote up
/**
 * See if a store/unstore event is possible through items being moved into an inventory. Then
 * Storing the value in a array list while the inventory is open.
 *
 * @param evt The InventoryClickEvent used to check item movement
 */
@EventHandler
public void onStoringFilter(InventoryClickEvent evt) {
    if (evt.getAction() == InventoryAction.SWAP_WITH_CURSOR
            || evt.getAction() == InventoryAction.COLLECT_TO_CURSOR
            || evt.getAction() == InventoryAction.PICKUP_SOME
            || evt.getAction() == InventoryAction.PICKUP_HALF
            || evt.getAction() == InventoryAction.PICKUP_ALL
            || evt.getAction() == InventoryAction.PICKUP_ONE) {
        if (evt.getClickedInventory().getType() != null
                && evt.getView().getBottomInventory().getType() == InventoryType.PLAYER
                && (evt.getView().getTopInventory().getType() == InventoryType.CHEST
                || evt.getView().getTopInventory().getType() == InventoryType.ENDER_CHEST
                || evt.getView().getTopInventory().getType() == InventoryType.HOPPER
                || evt.getView().getTopInventory().getType() == InventoryType.DISPENSER
                || evt.getView().getTopInventory().getType() == InventoryType.DROPPER)
                && evt.getClickedInventory().getType() == InventoryType.PLAYER
                && (!(storePossible.contains(evt.getWhoClicked())))) {
            storePossible.add((Player) evt.getWhoClicked());
            if (unstorePossible.contains(evt.getWhoClicked())) {
                unstorePossible.remove(evt.getWhoClicked());
            }
        }
        if (evt.getClickedInventory().getType() != null
                && evt.getView().getBottomInventory().getType() == InventoryType.PLAYER
                && (evt.getView().getTopInventory().getType() == InventoryType.CHEST
                || evt.getView().getTopInventory().getType() == InventoryType.ENDER_CHEST
                || evt.getView().getTopInventory().getType() == InventoryType.HOPPER
                || evt.getView().getTopInventory().getType() == InventoryType.DISPENSER
                || evt.getView().getTopInventory().getType() == InventoryType.DROPPER)
                && (evt.getClickedInventory().getType() == InventoryType.CHEST
                || evt.getClickedInventory().getType() == InventoryType.ENDER_CHEST
                || evt.getClickedInventory().getType() == InventoryType.HOPPER
                || evt.getClickedInventory().getType() == InventoryType.DISPENSER
                || evt.getClickedInventory().getType() == InventoryType.DROPPER)
                && (!(unstorePossible.contains(evt.getWhoClicked())))) {
            unstorePossible.add((Player) evt.getWhoClicked());
            if (storePossible.contains(evt.getWhoClicked())) {
                storePossible.remove(evt.getWhoClicked());
            }
        }
    }
}