001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.util;
020
021import com.plotsquared.core.player.PlotPlayer;
022import com.plotsquared.core.plot.PlotInventory;
023import com.plotsquared.core.plot.PlotItemStack;
024
025/**
026 * This class is only used by internal functions, for most cases use the PlotInventory class
027 */
028public abstract class InventoryUtil {
029
030    public abstract void open(final PlotInventory inv);
031
032    public abstract void close(final PlotInventory inv);
033
034    /**
035     * Attempts to set an item into a {@link PlotInventory} while also checking the existence of the material
036     *
037     * @param plotInventory The inventory where the item should be placed
038     * @param index         The index where to place the item
039     * @param item          The item to place into the inventory
040     * @return {@code true} if the item could be placed, {@code false} otherwise (e.g. item not available in current version)
041     * @since 6.5.0
042     */
043    public abstract boolean setItemChecked(
044            final PlotInventory plotInventory, final int index,
045            final PlotItemStack item
046    );
047
048    /**
049     * Attempts to set an item into a {@link PlotInventory}
050     *
051     * @param plotInventory The inventory where the item should be placed
052     * @param index         The index where to place the item
053     * @param item          The item to place into the inventory
054     * @see #setItemChecked(PlotInventory, int, PlotItemStack)
055     */
056    public void setItem(
057            final PlotInventory plotInventory, final int index,
058            final PlotItemStack item
059    ) {
060        setItemChecked(plotInventory, index, item);
061    }
062
063    public abstract PlotItemStack[] getItems(final PlotPlayer<?> player);
064
065    public abstract boolean isOpen(final PlotInventory plotInventory);
066
067}