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(final UUID id, final PluginContainer container) {
040
041    super(id, container);
042  }
043
044  /**
045   * Used to get an inventory object.
046   *
047   * @param ender True if the ender chest object should be returned, otherwise false.
048   *
049   * @return The inventory object.
050   */
051  @Override
052  public Inventory getInventory(final boolean ender) {
053
054    final Optional<ServerPlayer> player = Sponge.server().player(this.id);
055    if(player.isPresent()) {
056
057      if(ender) {
058        return player.get().enderChestInventory();
059      }
060      return player.get().inventory();
061    }
062    return null;
063  }
064}