1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-21 12:15:50 +00:00
Slimefun4/src/me/mrCookieSlime/Slimefun/Setup/SlimefunManager.java

164 lines
7.0 KiB
Java
Raw Normal View History

2016-04-14 16:24:03 +00:00
package me.mrCookieSlime.Slimefun.Setup;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
2017-04-09 07:59:45 +00:00
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
2017-04-09 07:59:45 +00:00
import org.bukkit.potion.PotionEffect;
import me.mrCookieSlime.EmeraldEnchants.EmeraldEnchants;
import me.mrCookieSlime.EmeraldEnchants.ItemEnchantment;
2016-04-14 16:24:03 +00:00
import me.mrCookieSlime.Slimefun.Lists.Categories;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
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;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SoulboundItem;
2017-04-09 07:59:45 +00:00
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.VanillaItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
2016-04-14 16:24:03 +00:00
2019-08-27 21:08:13 +00:00
public final class SlimefunManager {
private SlimefunManager() {}
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-08-29 23:11:33 +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-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
}
}
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-08-29 23:11:33 +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-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
}
}
//ToDO: ALl all
//Charcoal=coal?
// public static List<Material> data_safe = Arrays.asList(Material.WHITE_WOOL,
// Material.WHITE_CARPET,
// Material.WHITE_TERRACOTTA,
// Material.WHITE_STAINED_GLASS,
// Material.WHITE_STAINED_GLASS_PANE,
// Material.INK_SAC,
// Material.STONE,
// Material.COAL, Material.SKULL_ITEM, Material.RAW_FISH, Material.COOKED_FISH);
2016-04-14 16:24:03 +00:00
public static boolean isItemSimiliar(ItemStack item, ItemStack sfitem, boolean lore) {
if (item == null) return sfitem == null;
if (sfitem == null) return false;
2016-04-14 16:24:03 +00:00
if (item.getType() == sfitem.getType() && item.getAmount() >= sfitem.getAmount()) {
if (item.hasItemMeta() && sfitem.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName() && sfitem.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(sfitem.getItemMeta().getDisplayName())) {
2016-04-14 16:24:03 +00:00
if (lore) {
if (item.getItemMeta().hasLore() && sfitem.getItemMeta().hasLore()) {
return equalsLore(item.getItemMeta().getLore(), sfitem.getItemMeta().getLore());
2016-04-14 16:24:03 +00:00
}
else return !item.getItemMeta().hasLore() && !sfitem.getItemMeta().hasLore();
2016-04-14 16:24:03 +00:00
}
else return true;
}
else return false;
}
else if (!item.getItemMeta().hasDisplayName() && !sfitem.getItemMeta().hasDisplayName()) {
2016-04-14 16:24:03 +00:00
if (lore) {
if (item.getItemMeta().hasLore() && sfitem.getItemMeta().hasLore()) {
return equalsLore(item.getItemMeta().getLore(), sfitem.getItemMeta().getLore());
2016-04-14 16:24:03 +00:00
}
else return !item.getItemMeta().hasLore() && !sfitem.getItemMeta().hasLore();
2016-04-14 16:24:03 +00:00
}
else return true;
}
else return false;
}
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
public static enum DataType {
ALWAYS,
NEVER,
IF_COLORED;
}
@Deprecated
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
}
2016-04-14 16:24:03 +00:00
private static boolean equalsLore(List<String> lore, List<String> lore2) {
StringBuilder string1 = new StringBuilder();
StringBuilder string2 = new StringBuilder();
String colors = ChatColor.YELLOW.toString() + ChatColor.YELLOW.toString() + ChatColor.GRAY.toString();
2016-04-14 16:24:03 +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
}
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);
}
return string1.toString().equals(string2.toString());
}
public static boolean isItemSoulbound(ItemStack item) {
if (item == null || item.getType() == Material.AIR) return false;
else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BOUND_BACKPACK, false)) return true;
else {
ItemStack strippedItem = item.clone();
for (Enchantment enchantment : item.getEnchantments().keySet()) {
strippedItem.removeEnchantment(enchantment);
}
if (SlimefunPlugin.getHooks().isEmeraldEnchantsInstalled()) {
for (ItemEnchantment enchantment : EmeraldEnchants.getInstance().getRegistry().getEnchantments(item)){
EmeraldEnchants.getInstance().getRegistry().applyEnchantment(strippedItem, enchantment.getEnchantment(), 0);
}
}
if (SlimefunItem.getByItem(strippedItem) instanceof SoulboundItem) return true;
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
}
}
}