001package net.tnemc.plugincore.paper.impl;
002
003/*
004 * The New Plugin Core
005 * Copyright (C) 2022 - 2024 Daniel "creatorfromhell" Vidmar
006 *
007 * This program is free software: you can redistribute it and/or modify
008 * it under the terms of the GNU Affero General Public License as published by
009 * the Free Software Foundation, either version 3 of the License, or
010 * (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015 * GNU Affero General Public License for more details.
016 *
017 * You should have received a copy of the GNU Affero General Public License
018 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
019 */
020
021import net.tnemc.menu.paper.PaperInventory;
022import net.tnemc.plugincore.core.compatibility.InventoryProvider;
023import org.bukkit.Bukkit;
024import org.bukkit.OfflinePlayer;
025import org.bukkit.inventory.Inventory;
026import org.bukkit.plugin.java.JavaPlugin;
027
028import java.util.UUID;
029
030/**
031 * BukkitInventoryProvider
032 *
033 * @author creatorfromhell
034 * @since 0.1.2.0
035 */
036public class PaperInventoryProvider extends PaperInventory implements InventoryProvider<Inventory> {
037
038  public PaperInventoryProvider(UUID id, JavaPlugin plugin) {
039    super(id, plugin);
040  }
041
042  /**
043   * Used to get an inventory object.
044   *
045   * @param ender True if the ender chest object should be returned, otherwise false.
046   *
047   * @return The inventory object.
048   */
049  @Override
050  public Inventory getInventory(boolean ender) {
051    final OfflinePlayer player = Bukkit.getOfflinePlayer(player());
052    if(player.getPlayer() == null) return null;
053
054    if(ender) {
055      return player.getPlayer().getEnderChest();
056    }
057    return player.getPlayer().getInventory();
058  }
059}