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 com.nexomc.nexo.api.NexoItems; 022import com.nexomc.nexo.items.ItemBuilder; 023import net.tnemc.item.AbstractItemStack; 024import net.tnemc.item.providers.ItemProvider; 025import org.bukkit.inventory.ItemStack; 026 027/** 028 * NexoProvider 029 * 030 * @author creatorfromhell 031 * @since 0.2.0.0 032 */ 033public class NexoProvider 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 = NexoItems.idFromItem(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 ItemBuilder originalStack = NexoItems.itemFromId(original.providerItemID()); 069 if(originalStack == null) { 070 return false; 071 } 072 073 return originalStack.build().isSimilar(compare); 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 = NexoItems.itemFromId(original.providerItemID()); 088 System.out.println("Nexo locale"); 089 if(originalStack == null) { 090 System.out.println("Nexo locale null"); 091 092 return null; 093 } 094 095 final ItemStack stack = originalStack.build(); 096 stack.setAmount(amount); 097 System.out.println("Nexo locale returning"); 098 099 return stack; 100 } 101 102 /** 103 * @return the identifier for this check. 104 */ 105 @Override 106 public String identifier() { 107 108 return "nexo"; 109 } 110}