001package net.tnemc.plugincore.sponge.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.sponge8.SpongeInventory;
022import net.tnemc.plugincore.core.compatibility.InventoryProvider;
023import org.spongepowered.api.Sponge;
024import org.spongepowered.api.entity.living.player.server.ServerPlayer;
025import org.spongepowered.api.item.inventory.Inventory;
026import org.spongepowered.plugin.PluginContainer;
027
028import java.util.Optional;
029import java.util.UUID;
030
031/**
032 * SpongeInventoryProvider
033 *
034 * @author creatorfromhell
035 * @since 0.1.2.0
036 */
037public class SpongeInventoryProvider extends SpongeInventory implements InventoryProvider<Inventory> {
038
039  public SpongeInventoryProvider(UUID id, PluginContainer container) {
040    super(id, container);
041  }
042
043  /**
044   * Used to get an inventory object.
045   *
046   * @param ender True if the ender chest object should be returned, otherwise false.
047   *
048   * @return The inventory object.
049   */
050  @Override
051  public Inventory getInventory(boolean ender) {
052    final Optional<ServerPlayer> player = Sponge.server().player(this.id);
053    if(player.isPresent()) {
054
055      if(ender) {
056        return player.get().enderChestInventory();
057      }
058      return player.get().inventory();
059    }
060    return null;
061  }
062}