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 dev.lone.itemsadder.api.CustomStack; 022import net.tnemc.item.AbstractItemStack; 023import net.tnemc.item.providers.ItemProvider; 024import org.bukkit.inventory.ItemStack; 025 026/** 027 * ItemAdderProvider 028 * 029 * @author creatorfromhell 030 * @since 0.2.0.0 031 */ 032public class ItemAdderProvider implements ItemProvider<ItemStack> { 033 034 /** 035 * Checks if the given serialized item stack applies to the specified item. 036 * 037 * @param serialized The serialized item stack to check against the item. 038 * @param item The item to check against. 039 * 040 * @return True if the serialized item stack applies to the item, false otherwise. 041 */ 042 @Override 043 public boolean appliesTo(final AbstractItemStack<? extends ItemStack> serialized, final ItemStack item) { 044 045 final CustomStack customStack = CustomStack.byItemStack(item); 046 if(customStack == null) { 047 return false; 048 } 049 050 serialized.setItemProvider(identifier()); 051 serialized.setProviderItemID(customStack.getId()); 052 053 return true; 054 } 055 056 /** 057 * Checks if the provided item stack is similar to the original item stack. 058 * 059 * @param original The original item stack to compare against. 060 * @param compare The item stack to compare. 061 * 062 * @return True if the two item stacks are similar, otherwise false. 063 */ 064 @Override 065 public boolean similar(final AbstractItemStack<? extends ItemStack> original, final ItemStack compare) { 066 final CustomStack originalStack = CustomStack.getInstance(original.providerItemID()); 067 if(originalStack == null) { 068 return false; 069 } 070 071 final CustomStack compareStack = CustomStack.byItemStack(compare); 072 if(compareStack == null) { 073 return false; 074 } 075 076 return originalStack.matchNamespacedID(compareStack); 077 } 078 079 /** 080 * Creates a copy of the original item stack with a specified amount. 081 * 082 * @param original The original item stack to copy. 083 * @param amount The amount for the new item stack. 084 * 085 * @return A new item stack with the specified amount. 086 */ 087 @Override 088 public ItemStack locale(final AbstractItemStack<? extends ItemStack> original, final int amount) { 089 090 final CustomStack customStack = CustomStack.getInstance(original.providerItemID()); 091 if(customStack == null) { 092 return null; 093 } 094 095 final ItemStack stack = customStack.getItemStack(); 096 stack.setAmount(amount); 097 098 return stack; 099 } 100 101 /** 102 * @return the identifier for this check. 103 */ 104 @Override 105 public String identifier() { 106 107 return "itemsadder"; 108 } 109}