2016-04-14 16:24:03 +00:00
|
|
|
package me.mrCookieSlime.Slimefun.Setup;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2019-12-08 11:58:05 +00:00
|
|
|
import java.util.Optional;
|
2016-04-14 16:24:03 +00:00
|
|
|
|
2019-09-03 17:30:58 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
2019-09-21 11:04:36 +00:00
|
|
|
import org.bukkit.inventory.Inventory;
|
2017-04-09 07:59:45 +00:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2019-09-03 17:30:58 +00:00
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2017-04-09 07:59:45 +00:00
|
|
|
import org.bukkit.potion.PotionEffect;
|
|
|
|
|
2019-12-08 11:58:05 +00:00
|
|
|
import io.github.thebusybiscuit.cscorelib2.item.ImmutableItemMeta;
|
2019-09-03 17:30:58 +00:00
|
|
|
import me.mrCookieSlime.EmeraldEnchants.EmeraldEnchants;
|
|
|
|
import me.mrCookieSlime.EmeraldEnchants.ItemEnchantment;
|
2019-10-03 16:06:14 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Lists.Categories;
|
|
|
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
2019-09-03 17:30:58 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
|
2016-04-14 16:24:03 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunArmorPiece;
|
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
2017-04-09 07:59:45 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.VanillaItem;
|
2019-10-03 16:06:14 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.Soulbound;
|
2019-12-08 11:58:05 +00:00
|
|
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
2016-04-14 16:24:03 +00:00
|
|
|
|
2019-08-27 21:08:13 +00:00
|
|
|
public final class SlimefunManager {
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2019-08-27 21:08:13 +00:00
|
|
|
private SlimefunManager() {}
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
public static void registerArmorSet(ItemStack baseComponent, ItemStack[] items, String idSyntax, PotionEffect[][] effects, boolean special, boolean slimefun) {
|
|
|
|
String[] components = new String[] {"_HELMET", "_CHESTPLATE", "_LEGGINGS", "_BOOTS"};
|
|
|
|
Category cat = special ? Categories.MAGIC_ARMOR: Categories.ARMOR;
|
2019-08-27 21:08:13 +00:00
|
|
|
List<ItemStack[]> recipes = new ArrayList<>();
|
2016-04-14 16:24:03 +00:00
|
|
|
recipes.add(new ItemStack[] {baseComponent, baseComponent, baseComponent, baseComponent, null, baseComponent, null, null, null});
|
|
|
|
recipes.add(new ItemStack[] {baseComponent, null, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent});
|
|
|
|
recipes.add(new ItemStack[] {baseComponent, baseComponent, baseComponent, baseComponent, null, baseComponent, baseComponent, null, baseComponent});
|
|
|
|
recipes.add(new ItemStack[] {null, null, null, baseComponent, null, baseComponent, baseComponent, null, baseComponent});
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2019-08-29 23:11:33 +00:00
|
|
|
if (i < effects.length && effects[i].length > 0) {
|
2019-08-29 21:18:04 +00:00
|
|
|
new SlimefunArmorPiece(cat, items[i], idSyntax + components[i], RecipeType.ARMOR_FORGE, recipes.get(i), effects[i]).register(slimefun);
|
2019-10-03 22:37:13 +00:00
|
|
|
}
|
2019-08-29 23:11:33 +00:00
|
|
|
else {
|
2019-08-29 21:18:04 +00:00
|
|
|
new SlimefunItem(cat, items[i], idSyntax + components[i], RecipeType.ARMOR_FORGE, recipes.get(i)).register(slimefun);
|
|
|
|
}
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2017-04-09 07:59:45 +00:00
|
|
|
public static void registerArmorSet(ItemStack baseComponent, ItemStack[] items, String idSyntax, boolean slimefun, boolean vanilla) {
|
2016-04-14 16:24:03 +00:00
|
|
|
String[] components = new String[] {"_HELMET", "_CHESTPLATE", "_LEGGINGS", "_BOOTS"};
|
|
|
|
Category cat = Categories.ARMOR;
|
2019-08-27 21:08:13 +00:00
|
|
|
List<ItemStack[]> recipes = new ArrayList<>();
|
2016-04-14 16:24:03 +00:00
|
|
|
recipes.add(new ItemStack[] {baseComponent, baseComponent, baseComponent, baseComponent, null, baseComponent, null, null, null});
|
|
|
|
recipes.add(new ItemStack[] {baseComponent, null, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent, baseComponent});
|
|
|
|
recipes.add(new ItemStack[] {baseComponent, baseComponent, baseComponent, baseComponent, null, baseComponent, baseComponent, null, baseComponent});
|
|
|
|
recipes.add(new ItemStack[] {null, null, null, baseComponent, null, baseComponent, baseComponent, null, baseComponent});
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-04-09 07:59:45 +00:00
|
|
|
if (vanilla) {
|
|
|
|
new VanillaItem(cat, items[i], idSyntax + components[i], RecipeType.ARMOR_FORGE, recipes.get(i)).register(slimefun);
|
2019-10-03 22:37:13 +00:00
|
|
|
}
|
2019-08-29 23:11:33 +00:00
|
|
|
else {
|
2017-04-09 07:59:45 +00:00
|
|
|
new SlimefunItem(cat, items[i], idSyntax + components[i], RecipeType.ARMOR_FORGE, recipes.get(i)).register(slimefun);
|
|
|
|
}
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2019-09-21 11:04:36 +00:00
|
|
|
@Deprecated
|
|
|
|
public static enum DataType {
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2019-09-21 11:04:36 +00:00
|
|
|
ALWAYS,
|
|
|
|
NEVER,
|
|
|
|
IF_COLORED;
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2019-09-21 11:04:36 +00:00
|
|
|
}
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2019-12-08 11:58:05 +00:00
|
|
|
@Deprecated
|
2019-08-30 20:49:18 +00:00
|
|
|
public static boolean isItemSimiliar(ItemStack item, ItemStack sfitem, boolean lore) {
|
2019-12-08 11:58:05 +00:00
|
|
|
return isItemSimilar(item, sfitem, lore);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isItemSimilar(ItemStack item, ItemStack sfitem, boolean checkLore) {
|
2019-08-30 20:49:18 +00:00
|
|
|
if (item == null) return sfitem == null;
|
|
|
|
if (sfitem == null) return false;
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2019-08-30 20:49:18 +00:00
|
|
|
if (item.getType() == sfitem.getType() && item.getAmount() >= sfitem.getAmount()) {
|
|
|
|
if (item.hasItemMeta() && sfitem.hasItemMeta()) {
|
2019-12-08 11:58:05 +00:00
|
|
|
ItemMeta itemMeta = item.getItemMeta();
|
|
|
|
ItemMeta sfitemMeta = sfitem.getItemMeta();
|
|
|
|
|
|
|
|
if (sfitem instanceof SlimefunItemStack) {
|
|
|
|
System.out.println(sfitem.clone().getClass().getName());
|
|
|
|
|
|
|
|
Optional<String> id = SlimefunPlugin.getItemDataService().getItemData(itemMeta);
|
|
|
|
|
|
|
|
if (id.isPresent()) {
|
|
|
|
return id.equals(((SlimefunItemStack) sfitem).getItemID());
|
|
|
|
}
|
|
|
|
|
|
|
|
ImmutableItemMeta meta = ((SlimefunItemStack) sfitem).getImmutableMeta();
|
|
|
|
|
|
|
|
Optional<String> displayName = meta.getDisplayName();
|
|
|
|
|
|
|
|
if (itemMeta.hasDisplayName() && displayName.isPresent()) {
|
|
|
|
if (itemMeta.getDisplayName().equals(displayName.get())) {
|
|
|
|
Optional<List<String>> itemLore = meta.getLore();
|
|
|
|
|
|
|
|
if (checkLore) {
|
|
|
|
if (itemMeta.hasLore() && itemLore.isPresent()) {
|
|
|
|
return equalsLore(itemMeta.getLore(), itemLore.get());
|
|
|
|
}
|
|
|
|
else return !itemMeta.hasLore() && !itemLore.isPresent();
|
|
|
|
}
|
|
|
|
else return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
else if (!itemMeta.hasDisplayName() && !displayName.isPresent()) {
|
|
|
|
Optional<List<String>> itemLore = meta.getLore();
|
|
|
|
|
|
|
|
if (checkLore) {
|
|
|
|
if (itemMeta.hasLore() && itemLore.isPresent()) {
|
|
|
|
return equalsLore(itemMeta.getLore(), itemLore.get());
|
|
|
|
}
|
|
|
|
else return !itemMeta.hasLore() && !itemLore.isPresent();
|
|
|
|
}
|
|
|
|
else return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
else if (itemMeta.hasDisplayName() && sfitemMeta.hasDisplayName()) {
|
|
|
|
if (itemMeta.getDisplayName().equals(sfitemMeta.getDisplayName())) {
|
|
|
|
if (checkLore) {
|
|
|
|
if (itemMeta.hasLore() && sfitemMeta.hasLore()) {
|
|
|
|
return equalsLore(itemMeta.getLore(), sfitemMeta.getLore());
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2019-12-08 11:58:05 +00:00
|
|
|
else return !itemMeta.hasLore() && !sfitemMeta.hasLore();
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
else return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
2019-12-08 11:58:05 +00:00
|
|
|
else if (!itemMeta.hasDisplayName() && !sfitemMeta.hasDisplayName()) {
|
|
|
|
if (checkLore) {
|
|
|
|
if (itemMeta.hasLore() && sfitemMeta.hasLore()) {
|
|
|
|
return equalsLore(itemMeta.getLore(), sfitemMeta.getLore());
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2019-12-08 11:58:05 +00:00
|
|
|
else return !itemMeta.hasLore() && !sfitemMeta.hasLore();
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
else return true;
|
|
|
|
}
|
|
|
|
else return false;
|
2019-10-03 22:37:13 +00:00
|
|
|
}
|
2019-08-30 20:49:18 +00:00
|
|
|
else return !item.hasItemMeta() && !sfitem.hasItemMeta();
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
2019-08-29 14:19:23 +00:00
|
|
|
|
|
|
|
@Deprecated
|
2019-08-30 20:49:18 +00:00
|
|
|
public static boolean isItemSimiliar(ItemStack item, ItemStack sfitem, boolean lore, DataType data) {
|
|
|
|
return isItemSimiliar(item, sfitem, lore);
|
2019-08-29 14:19:23 +00:00
|
|
|
}
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2019-09-21 11:04:36 +00:00
|
|
|
public static boolean containsSimilarItem(Inventory inventory, ItemStack itemStack, boolean checkLore) {
|
|
|
|
if (inventory == null || itemStack == null) return false;
|
|
|
|
|
|
|
|
for (ItemStack is : inventory.getStorageContents()) {
|
|
|
|
if (is == null || is.getType() == Material.AIR) continue;
|
|
|
|
if (isItemSimiliar(is, itemStack, checkLore)) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2016-04-14 16:24:03 +00:00
|
|
|
private static boolean equalsLore(List<String> lore, List<String> lore2) {
|
2019-09-03 17:30:58 +00:00
|
|
|
StringBuilder string1 = new StringBuilder();
|
|
|
|
StringBuilder string2 = new StringBuilder();
|
2019-09-05 12:08:19 +00:00
|
|
|
|
2019-09-03 17:30:58 +00:00
|
|
|
String colors = ChatColor.YELLOW.toString() + ChatColor.YELLOW.toString() + ChatColor.GRAY.toString();
|
2019-12-08 11:58:05 +00:00
|
|
|
|
|
|
|
for (String string : lore) {
|
2019-09-05 12:02:26 +00:00
|
|
|
if (!string.equals(ChatColor.GRAY + "Soulbound") && !string.startsWith(colors)) string1.append("-NEW LINE-").append(string);
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
2019-10-03 22:37:13 +00:00
|
|
|
|
2019-12-08 11:58:05 +00:00
|
|
|
for (String string : lore2) {
|
2019-09-05 12:02:26 +00:00
|
|
|
if (!string.equals(ChatColor.GRAY + "Soulbound") && !string.startsWith(colors)) string2.append("-NEW LINE-").append(string);
|
2019-09-03 17:30:58 +00:00
|
|
|
}
|
2019-12-08 11:58:05 +00:00
|
|
|
|
2019-09-03 17:30:58 +00:00
|
|
|
return string1.toString().equals(string2.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isItemSoulbound(ItemStack item) {
|
|
|
|
if (item == null || item.getType() == Material.AIR) return false;
|
2019-10-03 16:06:14 +00:00
|
|
|
else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BOUND_BACKPACK, false)) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-03 17:30:58 +00:00
|
|
|
else {
|
|
|
|
ItemStack strippedItem = item.clone();
|
|
|
|
|
|
|
|
if (SlimefunPlugin.getHooks().isEmeraldEnchantsInstalled()) {
|
|
|
|
for (ItemEnchantment enchantment : EmeraldEnchants.getInstance().getRegistry().getEnchantments(item)){
|
|
|
|
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(strippedItem, enchantment.getEnchantment(), 0);
|
|
|
|
}
|
|
|
|
}
|
2019-10-06 15:04:34 +00:00
|
|
|
|
2019-10-03 16:06:14 +00:00
|
|
|
if (SlimefunItem.getByItem(strippedItem) instanceof Soulbound) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-03 17:30:58 +00:00
|
|
|
else if (item.hasItemMeta()) {
|
|
|
|
ItemMeta im = item.getItemMeta();
|
|
|
|
return (im.hasLore() && im.getLore().contains(ChatColor.GRAY + "Soulbound"));
|
|
|
|
}
|
|
|
|
return false;
|
2016-04-14 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|