001package net.tnemc.item.bukkitbase.platform.providers;
002/*
003 * The New Item Library
004 * Copyright (C) 2022 - 2025 Daniel "creatorfromhell" Vidmar
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (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 GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020
021import io.th0rgal.oraxen.api.OraxenItems;
022import io.th0rgal.oraxen.items.ItemBuilder;
023import net.tnemc.item.AbstractItemStack;
024import net.tnemc.item.providers.ItemProvider;
025import org.bukkit.inventory.ItemStack;
026
027/**
028 * OraxenAddon
029 *
030 * @author creatorfromhell
031 * @since 0.2.0.0
032 */
033public class OraxenProvider implements ItemProvider<ItemStack> {
034
035  /**
036   * Checks if the given serialized item stack applies to the specified item.
037   *
038   * @param serialized The serialized item stack to check against the item.
039   * @param item       The item to check against.
040   *
041   * @return True if the serialized item stack applies to the item, false otherwise.
042   */
043  @Override
044  public boolean appliesTo(final AbstractItemStack<? extends ItemStack> serialized, final ItemStack item) {
045
046    final String id = OraxenItems.getIdByItem(item);
047    if(id == null) {
048      return false;
049    }
050
051    serialized.setItemProvider(identifier());
052    serialized.setProviderItemID(id);
053
054    return true;
055  }
056
057  /**
058   * Checks if the provided item stack is similar to the original item stack.
059   *
060   * @param original The original item stack to compare against.
061   * @param compare  The item stack to compare.
062   *
063   * @return True if the two item stacks are similar, otherwise false.
064   */
065  @Override
066  public boolean similar(final AbstractItemStack<? extends ItemStack> original, final ItemStack compare) {
067
068    final String compareID = OraxenItems.getIdByItem(compare);
069    if(compareID == null) {
070      return false;
071    }
072
073    return original.providerItemID().equals(compareID);
074  }
075
076  /**
077   * Creates a copy of the original item stack with a specified amount.
078   *
079   * @param original The original item stack to copy.
080   * @param amount   The amount for the new item stack.
081   *
082   * @return A new item stack with the specified amount.
083   */
084  @Override
085  public ItemStack locale(final AbstractItemStack<? extends ItemStack> original, final int amount) {
086
087    final ItemBuilder originalStack = OraxenItems.getItemById(original.providerItemID());
088    if(originalStack == null) {
089
090      return null;
091    }
092
093    final ItemStack stack = originalStack.build();
094    stack.setAmount(amount);
095
096    return stack;
097  }
098
099  /**
100   * @return the identifier for this check.
101   */
102  @Override
103  public String identifier() {
104
105    return "oraxen";
106  }
107}