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.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; 022import net.tnemc.item.AbstractItemStack; 023import net.tnemc.item.providers.ItemProvider; 024import org.bukkit.inventory.ItemStack; 025 026/** 027 * SlimefunProvider 028 * 029 * @author creatorfromhell 030 * @since 0.2.0.0 031 */ 032public class SlimefunProvider 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 SlimefunItem stack = SlimefunItem.getByItem(item); 046 if(stack == null) { 047 return false; 048 } 049 050 serialized.setItemProvider(identifier()); 051 serialized.setProviderItemID(stack.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 067 final SlimefunItem compareStack = SlimefunItem.getByItem(compare); 068 if(compareStack == null) { 069 070 return false; 071 } 072 073 return original.providerItemID().equals(compareStack.getId()); 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 SlimefunItem originalStack = SlimefunItem.getById(original.providerItemID()); 088 if(originalStack == null) { 089 090 return null; 091 } 092 093 final ItemStack stack = originalStack.getItem(); 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 "slimefun"; 106 } 107}