// Path: api/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java
// @Deprecated
// public interface IInventoryAccess {
// 
//     /**
//      * Gets an ISpecialEnderChest from an Inventory or null if the Inventory is not backed by an
//      * ISpecialEnderChest.
//      *
//      * @param inventory the Inventory
//      * @return the ISpecialEnderChest or null
//      */
//     @Deprecated
//     @Nullable ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory);
// 
//     /**
//      * Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by
//      * an ISpecialPlayerInventory.
//      *
//      * @param inventory the Inventory
//      * @return the ISpecialPlayerInventory or null
//      */
//     @Deprecated
//     @Nullable ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory);
// 
//     /**
//      * Check if an Inventory is an ISpecialEnderChest implementation.
//      *
//      * @param inventory the Inventory
//      * @return true if the Inventory is backed by an ISpecialEnderChest
//      */
//     @Deprecated
//     boolean isSpecialEnderChest(@NotNull Inventory inventory);
// 
//     /**
//      * Check if an Inventory is an ISpecialPlayerInventory implementation.
//      *
//      * @param inventory the Inventory
//      * @return true if the Inventory is backed by an ISpecialPlayerInventory
//      */
//     @Deprecated
//     boolean isSpecialPlayerInventory(@NotNull Inventory inventory);
// 
// }
// 
// Path: api/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java
// public interface ISpecialEnderChest extends ISpecialInventory {
// 
// }
// 
// Path: api/src/main/java/com/lishid/openinv/internal/ISpecialInventory.java
// public interface ISpecialInventory {
// 
//     /**
//      * Gets the Inventory associated with this ISpecialInventory.
//      *
//      * @return the Inventory
//      */
//     @NotNull Inventory getBukkitInventory();
// 
//     /**
//      * Sets the Player associated with this ISpecialInventory online.
//      *
//      * @param player the Player coming online
//      */
//     void setPlayerOnline(@NotNull Player player);
// 
//     /**
//      * Sets the Player associated with this ISpecialInventory offline.
//      */
//     void setPlayerOffline();
// 
//     /**
//      * Gets whether or not this ISpecialInventory is in use.
//      *
//      * @return true if the ISpecialInventory is in use
//      */
//     boolean isInUse();
// 
// }
// 
// Path: api/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java
// public interface ISpecialPlayerInventory extends ISpecialInventory {
// 
// }


import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialInventory;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/*
 * Copyright (C) 2011-2020 lishid. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package com.lishid.openinv.util;


public class InventoryAccess implements IInventoryAccess {

    private static Class<?> craftInventory = null;
    private static Method getInventory = null;

    static {
        String packageName = Bukkit.getServer().getClass().getPackage().getName();
        try {
            craftInventory = Class.forName(packageName + ".inventory.CraftInventory");
        } catch (ClassNotFoundException ignored) {}
        try {
            getInventory = craftInventory.getDeclaredMethod("getInventory");
        } catch (NoSuchMethodException ignored) {}
    }

    /**
     * @deprecated use {@link #isUsable()}
     */
    @Deprecated
    public static boolean isUseable() {
        return isUsable();
    }

    public static boolean isUsable() {
        return craftInventory != null && getInventory != null;
    }

    public static boolean isPlayerInventory(@NotNull Inventory inventory) {
        return getPlayerInventory(inventory) != null;
    }

// Path: api/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java
// @Deprecated
// public interface IInventoryAccess {
// 
//     /**
//      * Gets an ISpecialEnderChest from an Inventory or null if the Inventory is not backed by an
//      * ISpecialEnderChest.
//      *
//      * @param inventory the Inventory
//      * @return the ISpecialEnderChest or null
//      */
//     @Deprecated
//     @Nullable ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory);
// 
//     /**
//      * Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by
//      * an ISpecialPlayerInventory.
//      *
//      * @param inventory the Inventory
//      * @return the ISpecialPlayerInventory or null
//      */
//     @Deprecated
//     @Nullable ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory);
// 
//     /**
//      * Check if an Inventory is an ISpecialEnderChest implementation.
//      *
//      * @param inventory the Inventory
//      * @return true if the Inventory is backed by an ISpecialEnderChest
//      */
//     @Deprecated
//     boolean isSpecialEnderChest(@NotNull Inventory inventory);
// 
//     /**
//      * Check if an Inventory is an ISpecialPlayerInventory implementation.
//      *
//      * @param inventory the Inventory
//      * @return true if the Inventory is backed by an ISpecialPlayerInventory
//      */
//     @Deprecated
//     boolean isSpecialPlayerInventory(@NotNull Inventory inventory);
// 
// }
// 
// Path: api/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java
// public interface ISpecialEnderChest extends ISpecialInventory {
// 
// }
// 
// Path: api/src/main/java/com/lishid/openinv/internal/ISpecialInventory.java
// public interface ISpecialInventory {
// 
//     /**
//      * Gets the Inventory associated with this ISpecialInventory.
//      *
//      * @return the Inventory
//      */
//     @NotNull Inventory getBukkitInventory();
// 
//     /**
//      * Sets the Player associated with this ISpecialInventory online.
//      *
//      * @param player the Player coming online
//      */
//     void setPlayerOnline(@NotNull Player player);
// 
//     /**
//      * Sets the Player associated with this ISpecialInventory offline.
//      */
//     void setPlayerOffline();
// 
//     /**
//      * Gets whether or not this ISpecialInventory is in use.
//      *
//      * @return true if the ISpecialInventory is in use
//      */
//     boolean isInUse();
// 
// }
// 
// Path: api/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java
// public interface ISpecialPlayerInventory extends ISpecialInventory {
// 
// }


// Path: api/src/main/java/com/lishid/openinv/util/InventoryAccess.java
import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialInventory;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/*
 * Copyright (C) 2011-2020 lishid. All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package com.lishid.openinv.util;


public class InventoryAccess implements IInventoryAccess {

    private static Class<?> craftInventory = null;
    private static Method getInventory = null;

    static {
        String packageName = Bukkit.getServer().getClass().getPackage().getName();
        try {
            craftInventory = Class.forName(packageName + ".inventory.CraftInventory");
        } catch (ClassNotFoundException ignored) {}
        try {
            getInventory = craftInventory.getDeclaredMethod("getInventory");
        } catch (NoSuchMethodException ignored) {}
    }

    /**
     * @deprecated use {@link #isUsable()}
     */
    @Deprecated
    public static boolean isUseable() {
        return isUsable();
    }

    public static boolean isUsable() {
        return craftInventory != null && getInventory != null;
    }

    public static boolean isPlayerInventory(@NotNull Inventory inventory) {
        return getPlayerInventory(inventory) != null;
    }

    public static @Nullable ISpecialPlayerInventory getPlayerInventory(@NotNull Inventory inventory) {