Possibly Fully Functional :O
This commit is contained in:
parent
a0bcc5ae8d
commit
4c1907ba07
@ -153,6 +153,18 @@ public class MassiveCore extends MassivePlugin
|
||||
// Enumeration Annotation Dodge
|
||||
ret.registerTypeAdapterFactory(AdapterModdedEnumType.ENUM_FACTORY);
|
||||
|
||||
// Massive Containers
|
||||
ret.registerTypeAdapter(MassiveList.class, AdapterMassiveList.get());
|
||||
ret.registerTypeAdapter(MassiveListDef.class, AdapterMassiveList.get());
|
||||
ret.registerTypeAdapter(MassiveMap.class, AdapterMassiveMap.get());
|
||||
ret.registerTypeAdapter(MassiveMapDef.class, AdapterMassiveMap.get());
|
||||
ret.registerTypeAdapter(MassiveSet.class, AdapterMassiveSet.get());
|
||||
ret.registerTypeAdapter(MassiveSetDef.class, AdapterMassiveSet.get());
|
||||
ret.registerTypeAdapter(MassiveTreeMap.class, AdapterMassiveTreeMap.get());
|
||||
ret.registerTypeAdapter(MassiveTreeMapDef.class, AdapterMassiveTreeMap.get());
|
||||
ret.registerTypeAdapter(MassiveTreeSet.class, AdapterMassiveTreeSet.get());
|
||||
ret.registerTypeAdapter(MassiveTreeSetDef.class, AdapterMassiveTreeSet.get());
|
||||
|
||||
// Entries (Is this still needed?)
|
||||
ret.registerTypeAdapter(Entry.class, AdapterEntry.get());
|
||||
|
||||
@ -166,6 +178,11 @@ public class MassiveCore extends MassivePlugin
|
||||
ret.registerTypeAdapter(Mson.class, AdapterMson.get());
|
||||
ret.registerTypeAdapter(MsonEvent.class, AdapterMsonEvent.get());
|
||||
|
||||
// Banner Patterns Upgrade Adapter
|
||||
// NOTE: Must come after the "MassiveContainers" section for priority.
|
||||
Type typeBannerPatterns = new TypeToken<MassiveListDef<DataBannerPattern>>(){}.getType();
|
||||
ret.registerTypeAdapter(typeBannerPatterns, AdapterBannerPatterns.get());
|
||||
|
||||
// ItemStack
|
||||
ret.registerTypeAdapter(ItemStack.class, AdapterItemStack.get());
|
||||
Class<?> classCraftItemStack = NmsItemStack.get().classCraftItemStack;
|
||||
@ -175,22 +192,6 @@ public class MassiveCore extends MassivePlugin
|
||||
ret.registerTypeAdapter(Inventory.class, AdapterInventory.get());
|
||||
ret.registerTypeAdapter(PlayerInventory.class, AdapterPlayerInventory.get());
|
||||
|
||||
// Banner Patterns Upgrade Adapter
|
||||
Type typeBannerPatterns = new TypeToken<MassiveListDef<DataBannerPattern>>(){}.getType();
|
||||
ret.registerTypeAdapter(typeBannerPatterns, AdapterBannerPatterns.get());
|
||||
|
||||
// Massive Containers
|
||||
ret.registerTypeAdapter(MassiveList.class, AdapterMassiveList.get());
|
||||
ret.registerTypeAdapter(MassiveListDef.class, AdapterMassiveList.get());
|
||||
ret.registerTypeAdapter(MassiveMap.class, AdapterMassiveMap.get());
|
||||
ret.registerTypeAdapter(MassiveMapDef.class, AdapterMassiveMap.get());
|
||||
ret.registerTypeAdapter(MassiveSet.class, AdapterMassiveSet.get());
|
||||
ret.registerTypeAdapter(MassiveSetDef.class, AdapterMassiveSet.get());
|
||||
ret.registerTypeAdapter(MassiveTreeMap.class, AdapterMassiveTreeMap.get());
|
||||
ret.registerTypeAdapter(MassiveTreeMapDef.class, AdapterMassiveTreeMap.get());
|
||||
ret.registerTypeAdapter(MassiveTreeSet.class, AdapterMassiveTreeSet.get());
|
||||
ret.registerTypeAdapter(MassiveTreeSetDef.class, AdapterMassiveTreeSet.get());
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
@ -1,145 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.FireworkEffect.Type;
|
||||
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonArray;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonPrimitive;
|
||||
|
||||
public class AdapterFireworkEffect
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELD CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final String FLICKER = "flicker";
|
||||
public static final String TRAIL = "trail";
|
||||
public static final String COLORS = "colors";
|
||||
public static final String FADE_COLORS = "fade-colors";
|
||||
public static final String TYPE = "type";
|
||||
|
||||
public static final boolean FLICKER_DEFAULT = false;
|
||||
public static final boolean TRAIL_DEFAULT = false;
|
||||
public static final List<Color> COLORS_DEFAULT = Collections.unmodifiableList(MUtil.list(Color.GREEN));
|
||||
public static final List<Color> FADE_COLORS_DEFAULT = Collections.unmodifiableList(new ArrayList<Color>());
|
||||
public static final Type TYPE_DEFAULT = Type.BALL_LARGE;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TO JSON
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static JsonObject toJson(FireworkEffect fireworkEffect)
|
||||
{
|
||||
if (fireworkEffect == null) return null;
|
||||
|
||||
JsonObject ret = new JsonObject();
|
||||
|
||||
ret.addProperty(FLICKER, fireworkEffect.hasFlicker());
|
||||
ret.addProperty(TRAIL, fireworkEffect.hasTrail());
|
||||
ret.add(COLORS, fromColorCollection(fireworkEffect.getColors()));
|
||||
ret.add(FADE_COLORS, fromColorCollection(fireworkEffect.getFadeColors()));
|
||||
ret.addProperty(TYPE, fireworkEffect.getType().name());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FROM JSON
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static FireworkEffect fromJson(JsonElement jsonElement)
|
||||
{
|
||||
if (jsonElement == null) return null;
|
||||
if ( ! jsonElement.isJsonObject()) return null;
|
||||
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
|
||||
boolean flicker = FLICKER_DEFAULT;
|
||||
boolean trail = TRAIL_DEFAULT;
|
||||
List<Color> colors = COLORS_DEFAULT;
|
||||
List<Color> fadeColors = FADE_COLORS_DEFAULT;
|
||||
Type type = TYPE_DEFAULT;
|
||||
|
||||
JsonElement element;
|
||||
|
||||
element = json.get(FLICKER);
|
||||
if (element != null)
|
||||
{
|
||||
flicker = element.getAsBoolean();
|
||||
}
|
||||
|
||||
element = json.get(TRAIL);
|
||||
if (element != null)
|
||||
{
|
||||
trail = element.getAsBoolean();
|
||||
}
|
||||
|
||||
element = json.get(COLORS);
|
||||
if (element != null)
|
||||
{
|
||||
colors = toColorCollection(element);
|
||||
}
|
||||
|
||||
element = json.get(FADE_COLORS);
|
||||
if (element != null)
|
||||
{
|
||||
fadeColors = toColorCollection(element);
|
||||
}
|
||||
|
||||
element = json.get(TYPE);
|
||||
if (element != null)
|
||||
{
|
||||
type = Type.valueOf(element.getAsString());
|
||||
}
|
||||
|
||||
FireworkEffect ret = FireworkEffect.builder()
|
||||
.flicker(flicker)
|
||||
.trail(trail)
|
||||
.withColor(colors)
|
||||
.withFade(fadeColors)
|
||||
.with(type)
|
||||
.build();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MINI UTILS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static JsonArray fromColorCollection(Collection<Color> colors)
|
||||
{
|
||||
JsonArray ret = new JsonArray();
|
||||
for (Color color : colors)
|
||||
{
|
||||
ret.add(new JsonPrimitive(color.asRGB()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<Color> toColorCollection(JsonElement json)
|
||||
{
|
||||
JsonArray array = json.getAsJsonArray();
|
||||
List<Color> ret = new ArrayList<Color>();
|
||||
|
||||
Iterator<JsonElement> iter = array.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
JsonElement element = iter.next();
|
||||
ret.add(Color.fromRGB(element.getAsInt()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,8 @@ package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.massivecraft.massivecore.item.DataItemStack;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
@ -26,59 +28,21 @@ public class AdapterItemStack implements JsonDeserializer<ItemStack>, JsonSerial
|
||||
public static AdapterItemStack get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private AdapterItemStackInner inner;
|
||||
public AdapterItemStackInner getInner() { return this.inner; }
|
||||
public void setInner(AdapterItemStackInner inner) { this.inner = inner; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public AdapterItemStack()
|
||||
{
|
||||
// 1.9
|
||||
try
|
||||
{
|
||||
this.inner = AdapterItemStackInner19.get();
|
||||
return;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 1.8
|
||||
try
|
||||
{
|
||||
this.inner = AdapterItemStackInner18.get();
|
||||
return;
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 1.7
|
||||
this.inner = AdapterItemStackInner17.get();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// GSON INTERFACE IMPLEMENTATION
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
return this.getInner().erialize(src);
|
||||
DataItemStack dataItemStack = new DataItemStack(src);
|
||||
return context.serialize(dataItemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
|
||||
{
|
||||
return this.getInner().erialize(json);
|
||||
DataItemStack dataItemStack = context.deserialize(json, DataItemStack.class);
|
||||
return dataItemStack.toBukkit();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
|
||||
public interface AdapterItemStackInner
|
||||
{
|
||||
public Object provoke();
|
||||
|
||||
public JsonObject erialize(ItemStack stack);
|
||||
public ItemStack erialize(JsonElement jsonElement);
|
||||
|
||||
}
|
@ -1,725 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.FireworkEffectMeta;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.MapMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.inventory.meta.Repairable;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonArray;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonPrimitive;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class AdapterItemStackInner17 implements AdapterItemStackInner
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS: NAMES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final String ID = "id";
|
||||
public static final String COUNT = "count";
|
||||
public static final String DAMAGE = "damage";
|
||||
|
||||
public static final String NAME = "name";
|
||||
public static final String LORE = "lore";
|
||||
|
||||
public static final String ENCHANTS = "enchants";
|
||||
|
||||
public static final String REPAIRCOST = "repaircost";
|
||||
|
||||
public static final String BOOK_TITLE = "title";
|
||||
public static final String BOOK_AUTHOR = "author";
|
||||
public static final String BOOK_PAGES = "pages";
|
||||
|
||||
public static final String LEATHER_ARMOR_COLOR = "color";
|
||||
|
||||
public static final String MAP_SCALING = "scaling";
|
||||
|
||||
public static final String SKULL_OWNER = "skull";
|
||||
|
||||
// We renamed "effects" to "potion-effects".
|
||||
public static final String POTION_EFFECTS_OLD = "effects";
|
||||
public static final String POTION_EFFECTS = "potion-effects";
|
||||
|
||||
public static final String FIREWORK_EFFECT = "firework-effect";
|
||||
public static final String FIREWORK_EFFECTS = "firework-effects";
|
||||
public static final String FIREWORK_FLIGHT = "firework-flight";
|
||||
|
||||
public static final String STORED_ENCHANTS = "stored-enchants";
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final AdapterItemStackInner17 i = new AdapterItemStackInner17();
|
||||
public static AdapterItemStackInner17 get() { return i; }
|
||||
public AdapterItemStackInner17()
|
||||
{
|
||||
this.provoke();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PROVOKE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object provoke()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public JsonObject erialize(ItemStack stack)
|
||||
{
|
||||
// Check for "nothing"
|
||||
if (stack == null) return null;
|
||||
if (stack.getType() == Material.AIR) return null;
|
||||
if (stack.getAmount() == 0) return null;
|
||||
|
||||
// Create a new JsonObject
|
||||
JsonObject json = new JsonObject();
|
||||
|
||||
// Transfer data from stack to json
|
||||
this.transferAll(stack, json, true);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack erialize(JsonElement jsonElement)
|
||||
{
|
||||
// Check for "nothing"
|
||||
if (jsonElement == null) return null;
|
||||
|
||||
// Must be a JsonObject
|
||||
if (jsonElement.isJsonObject() == false) return null;
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
|
||||
// Create a new ItemStack
|
||||
ItemStack stack = createItemStack();
|
||||
|
||||
// Transfer data from json to stack
|
||||
this.transferAll(stack, json, false);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// NOARG STACK CONSTRUCTOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final int DEFAULT_ID = 0;
|
||||
public static final int DEFAULT_COUNT = 1;
|
||||
public static final int DEFAULT_DAMAGE = 0;
|
||||
public ItemStack createItemStack()
|
||||
{
|
||||
return new ItemStack(DEFAULT_ID, DEFAULT_COUNT, (short)DEFAULT_DAMAGE);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ALL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferAll(ItemStack stack, JsonObject json, boolean stack2json)
|
||||
{
|
||||
this.transferBasic(stack, json, stack2json);
|
||||
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
this.transferMeta(stack, json, stack2json, meta);
|
||||
|
||||
if (stack2json == false)
|
||||
{
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// BASIC
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferBasic(ItemStack stack, JsonObject json, boolean stack2json)
|
||||
{
|
||||
this.transferId(stack, json, stack2json);
|
||||
this.transferCount(stack, json, stack2json);
|
||||
this.transferDamage(stack, json, stack2json);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// BASIC: ID
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferId(ItemStack stack, JsonObject json, boolean stack2json)
|
||||
{
|
||||
if (stack2json)
|
||||
{
|
||||
int id = stack.getTypeId();
|
||||
if (id == DEFAULT_ID) return;
|
||||
json.addProperty(ID, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(ID);
|
||||
if (element == null) return;
|
||||
stack.setTypeId(element.getAsInt());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// BASIC: COUNT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferCount(ItemStack stack, JsonObject json, boolean stack2json)
|
||||
{
|
||||
if (stack2json)
|
||||
{
|
||||
int count = stack.getAmount();
|
||||
if (count == DEFAULT_COUNT) return;
|
||||
json.addProperty(COUNT, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(COUNT);
|
||||
if (element == null) return;
|
||||
stack.setAmount(element.getAsInt());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// BASIC: DAMAGE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferDamage(ItemStack stack, JsonObject json, boolean stack2json)
|
||||
{
|
||||
// Durability is a weird name since it is the amount of damage.
|
||||
if (stack2json)
|
||||
{
|
||||
int damage = stack.getDurability();
|
||||
if (damage == DEFAULT_DAMAGE) return;
|
||||
json.addProperty(DAMAGE, damage);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(DAMAGE);
|
||||
if (element == null) return;
|
||||
stack.setDurability(element.getAsShort());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// META
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferMeta(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
this.transferMetaUnspecific(stack, json, meta2json, meta);
|
||||
this.transferMetaSpecific(stack, json, meta2json, meta);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNSPECIFIC META
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferMetaUnspecific(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
this.transferName(stack, json, meta2json, meta);
|
||||
this.transferLore(stack, json, meta2json, meta);
|
||||
this.transferEnchants(stack, json, meta2json, meta);
|
||||
this.transferRepaircost(stack, json, meta2json, meta);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNSPECIFIC META: NAME
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferName(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasDisplayName()) return;
|
||||
json.addProperty(NAME, meta.getDisplayName());
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(NAME);
|
||||
if (element == null) return;
|
||||
meta.setDisplayName(element.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNSPECIFIC META: LORE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferLore(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasLore()) return;
|
||||
json.add(LORE, convertStringList(meta.getLore()));
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(LORE);
|
||||
if (element == null) return;
|
||||
meta.setLore(convertStringList(element));
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNSPECIFIC META: ENCHANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferEnchants(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasEnchants()) return;
|
||||
json.add(ENCHANTS, convertEnchantLevelMap(meta.getEnchants()));
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(ENCHANTS);
|
||||
if (element == null) return;
|
||||
for (Entry<Enchantment, Integer> entry : convertEnchantLevelMap(element).entrySet())
|
||||
{
|
||||
meta.addEnchant(entry.getKey(), entry.getValue(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNSPECIFIC META: REPAIRCOST
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferRepaircost(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
if ( ! (meta instanceof Repairable)) return;
|
||||
Repairable repairable = (Repairable) meta;
|
||||
|
||||
if (meta2json)
|
||||
{
|
||||
if (!repairable.hasRepairCost()) return;
|
||||
json.addProperty(REPAIRCOST, repairable.getRepairCost());
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(REPAIRCOST);
|
||||
if (element == null) return;
|
||||
|
||||
repairable.setRepairCost(element.getAsInt());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferMetaSpecific(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
if (meta instanceof BookMeta)
|
||||
{
|
||||
this.transferBook(stack, json, meta2json, (BookMeta)meta);
|
||||
}
|
||||
else if (meta instanceof LeatherArmorMeta)
|
||||
{
|
||||
this.transferLeatherArmor(stack, json, meta2json, (LeatherArmorMeta)meta);
|
||||
}
|
||||
else if (meta instanceof MapMeta)
|
||||
{
|
||||
this.transferMap(stack, json, meta2json, (MapMeta)meta);
|
||||
}
|
||||
else if (meta instanceof PotionMeta)
|
||||
{
|
||||
this.transferPotion(stack, json, meta2json, (PotionMeta)meta);
|
||||
}
|
||||
else if (meta instanceof SkullMeta)
|
||||
{
|
||||
this.transferSkull(stack, json, meta2json, (SkullMeta)meta);
|
||||
}
|
||||
else if (meta instanceof FireworkEffectMeta)
|
||||
{
|
||||
this.transferFireworkEffect(stack, json, meta2json, (FireworkEffectMeta)meta);
|
||||
}
|
||||
else if (meta instanceof FireworkMeta)
|
||||
{
|
||||
this.transferFirework(stack, json, meta2json, (FireworkMeta)meta);
|
||||
}
|
||||
else if (meta instanceof EnchantmentStorageMeta)
|
||||
{
|
||||
this.transferEnchantmentStorage(stack, json, meta2json, (EnchantmentStorageMeta)meta);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: BOOK
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferBook(ItemStack stack, JsonObject json, boolean meta2json, BookMeta meta)
|
||||
{
|
||||
this.transferTitle(stack, json, meta2json, meta);
|
||||
this.transferAuthor(stack, json, meta2json, meta);
|
||||
this.transferPages(stack, json, meta2json, meta);
|
||||
}
|
||||
|
||||
public void transferTitle(ItemStack stack, JsonObject json, boolean meta2json, BookMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasTitle()) return;
|
||||
json.addProperty(BOOK_TITLE, meta.getTitle());
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(BOOK_TITLE);
|
||||
if (element == null) return;
|
||||
meta.setTitle(element.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
public void transferAuthor(ItemStack stack, JsonObject json, boolean meta2json, BookMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasTitle()) return;
|
||||
json.addProperty(BOOK_AUTHOR, meta.getAuthor());
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(BOOK_AUTHOR);
|
||||
if (element == null) return;
|
||||
meta.setAuthor(element.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
public void transferPages(ItemStack stack, JsonObject json, boolean meta2json, BookMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasTitle()) return;
|
||||
try
|
||||
{
|
||||
json.add(BOOK_PAGES, convertStringList(meta.getPages()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
// It seems CraftMetaBook#getPages some times throw an NPE.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(BOOK_PAGES);
|
||||
if (element == null) return;
|
||||
meta.setPages(convertStringList(element));
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: LEATHER ARMOR
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferLeatherArmor(ItemStack stack, JsonObject json, boolean meta2json, LeatherArmorMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
Color color = meta.getColor();
|
||||
|
||||
if (Bukkit.getItemFactory().getDefaultLeatherColor().equals(color)) return;
|
||||
|
||||
json.addProperty(LEATHER_ARMOR_COLOR, color.asRGB());
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(LEATHER_ARMOR_COLOR);
|
||||
if (element == null) return;
|
||||
meta.setColor(Color.fromRGB(element.getAsInt()));
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: MAP
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferMap(ItemStack stack, JsonObject json, boolean meta2json, MapMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.isScaling()) return;
|
||||
json.addProperty(MAP_SCALING, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(MAP_SCALING);
|
||||
if (element == null) return;
|
||||
|
||||
meta.setScaling(element.getAsBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: POTION
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferPotion(ItemStack stack, JsonObject json, boolean meta2json, PotionMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasCustomEffects()) return;
|
||||
json.add(POTION_EFFECTS, convertPotionEffectList(meta.getCustomEffects()));
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(POTION_EFFECTS);
|
||||
if (element == null) element = json.get(POTION_EFFECTS_OLD);
|
||||
if (element == null) return;
|
||||
|
||||
meta.clearCustomEffects();
|
||||
for (PotionEffect pe : convertPotionEffectList(element))
|
||||
{
|
||||
meta.addCustomEffect(pe, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: SKULL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferSkull(ItemStack stack, JsonObject json, boolean meta2json, SkullMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasOwner()) return;
|
||||
json.addProperty(SKULL_OWNER, meta.getOwner());
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(SKULL_OWNER);
|
||||
if (element == null) return;
|
||||
meta.setOwner(element.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: FIREWORK EFFECT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferFireworkEffect(ItemStack stack, JsonObject json, boolean meta2json, FireworkEffectMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasEffect()) return;
|
||||
json.add(FIREWORK_EFFECT, AdapterFireworkEffect.toJson(meta.getEffect()));
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(FIREWORK_EFFECT);
|
||||
if (element == null) return;
|
||||
meta.setEffect(AdapterFireworkEffect.fromJson(element));
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: FIREWORK
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferFirework(ItemStack stack, JsonObject json, boolean meta2json, FireworkMeta meta)
|
||||
{
|
||||
this.transferFireworkEffects(stack, json, meta2json, meta);
|
||||
this.transferFireworkPower(stack, json, meta2json, meta);
|
||||
}
|
||||
|
||||
public void transferFireworkEffects(ItemStack stack, JsonObject json, boolean meta2json, FireworkMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasEffects()) return;
|
||||
json.add(FIREWORK_EFFECTS, convertFireworkEffectList(meta.getEffects()));
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(FIREWORK_EFFECTS);
|
||||
if (element == null) return;
|
||||
meta.clearEffects();
|
||||
meta.addEffects(convertFireworkEffectList(element));
|
||||
}
|
||||
}
|
||||
|
||||
public void transferFireworkPower(ItemStack stack, JsonObject json, boolean meta2json, FireworkMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
json.addProperty(FIREWORK_FLIGHT, meta.getPower());
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(FIREWORK_FLIGHT);
|
||||
if (element == null) return;
|
||||
meta.setPower(element.getAsInt());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: ENCHANTMENT STORAGE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferEnchantmentStorage(ItemStack stack, JsonObject json, boolean meta2json, EnchantmentStorageMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if (!meta.hasStoredEnchants()) return;
|
||||
json.add(STORED_ENCHANTS, convertEnchantLevelMap(meta.getStoredEnchants()));
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(STORED_ENCHANTS);
|
||||
if (element == null) return;
|
||||
for (Entry<Enchantment, Integer> entry : convertEnchantLevelMap(element).entrySet())
|
||||
{
|
||||
meta.addStoredEnchant(entry.getKey(), entry.getValue(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MINI UTILS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// String List
|
||||
public static JsonArray convertStringList(Collection<String> strings)
|
||||
{
|
||||
JsonArray ret = new JsonArray();
|
||||
for (String string : strings)
|
||||
{
|
||||
ret.add(new JsonPrimitive(string));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<String> convertStringList(JsonElement jsonElement)
|
||||
{
|
||||
JsonArray array = jsonElement.getAsJsonArray();
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
Iterator<JsonElement> iter = array.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
JsonElement element = iter.next();
|
||||
ret.add(element.getAsString());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// PotionEffect List
|
||||
public static JsonArray convertPotionEffectList(Collection<PotionEffect> potionEffects)
|
||||
{
|
||||
JsonArray ret = new JsonArray();
|
||||
for (PotionEffect e : potionEffects)
|
||||
{
|
||||
ret.add(AdapterPotionEffect.toJson(e));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<PotionEffect> convertPotionEffectList(JsonElement jsonElement)
|
||||
{
|
||||
if (jsonElement == null) return null;
|
||||
if ( ! jsonElement.isJsonArray()) return null;
|
||||
JsonArray array = jsonElement.getAsJsonArray();
|
||||
|
||||
List<PotionEffect> ret = new ArrayList<PotionEffect>();
|
||||
|
||||
Iterator<JsonElement> iter = array.iterator();
|
||||
while(iter.hasNext())
|
||||
{
|
||||
PotionEffect e = AdapterPotionEffect.fromJson(iter.next());
|
||||
if (e == null) continue;
|
||||
ret.add(e);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// FireworkEffect List
|
||||
public static JsonArray convertFireworkEffectList(Collection<FireworkEffect> fireworkEffects)
|
||||
{
|
||||
JsonArray ret = new JsonArray();
|
||||
for (FireworkEffect fe : fireworkEffects)
|
||||
{
|
||||
ret.add(AdapterFireworkEffect.toJson(fe));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<FireworkEffect> convertFireworkEffectList(JsonElement jsonElement)
|
||||
{
|
||||
if (jsonElement == null) return null;
|
||||
if ( ! jsonElement.isJsonArray()) return null;
|
||||
JsonArray array = jsonElement.getAsJsonArray();
|
||||
|
||||
List<FireworkEffect> ret = new ArrayList<FireworkEffect>();
|
||||
|
||||
Iterator<JsonElement> iter = array.iterator();
|
||||
while(iter.hasNext())
|
||||
{
|
||||
FireworkEffect fe = AdapterFireworkEffect.fromJson(iter.next());
|
||||
if (fe == null) continue;
|
||||
ret.add(fe);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// EnchantLevelMap
|
||||
public static JsonObject convertEnchantLevelMap(Map<Enchantment, Integer> enchantLevelMap)
|
||||
{
|
||||
JsonObject ret = new JsonObject();
|
||||
for (Entry<Enchantment, Integer> entry : enchantLevelMap.entrySet())
|
||||
{
|
||||
ret.addProperty(String.valueOf(entry.getKey().getId()), entry.getValue());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Map<Enchantment, Integer> convertEnchantLevelMap(JsonElement jsonElement)
|
||||
{
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
Map<Enchantment, Integer> ret = new HashMap<Enchantment, Integer>();
|
||||
for (Entry<String, JsonElement> entry : json.entrySet())
|
||||
{
|
||||
int id = Integer.valueOf(entry.getKey());
|
||||
Enchantment ench = Enchantment.getById(id);
|
||||
int lvl = entry.getValue().getAsInt();
|
||||
ret.put(ench, lvl);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,326 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import com.massivecraft.massivecore.Couple;
|
||||
import com.massivecraft.massivecore.nms.NmsHead;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonArray;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonPrimitive;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class AdapterItemStackInner18 extends AdapterItemStackInner17
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS: NAMES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final String UNBREAKABLE = "unbreakable";
|
||||
|
||||
public static final String ITEM_FLAGS = "flags";
|
||||
|
||||
public static final String BANNER_BASE = "banner-base";
|
||||
public static final String BANNER_PATTERNS = "banner";
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final AdapterItemStackInner18 i = new AdapterItemStackInner18();
|
||||
public static AdapterItemStackInner18 get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PROVOKE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object provoke()
|
||||
{
|
||||
ItemStack stack = new ItemStack(Material.STONE);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
return meta.spigot().isUnbreakable();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNSPECIFIC META
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void transferMetaUnspecific(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
super.transferMetaUnspecific(stack, json, meta2json, meta);
|
||||
this.transferUnbreakable(stack, json, meta2json, meta);
|
||||
this.transferItemFlags(stack, json, meta2json, meta);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNSPECIFIC META: UNBREAKABLE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferUnbreakable(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
boolean unbreakable = meta.spigot().isUnbreakable();
|
||||
if ( ! unbreakable) return;
|
||||
json.addProperty(UNBREAKABLE, unbreakable);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(UNBREAKABLE);
|
||||
if (element == null) return;
|
||||
meta.spigot().setUnbreakable(element.getAsBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UNSPECIFIC META: ITEM FLAGS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferItemFlags(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
JsonArray value = convertItemFlags(meta.getItemFlags());
|
||||
if (value == null) return;
|
||||
json.add(ITEM_FLAGS, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(ITEM_FLAGS);
|
||||
if (element == null) return;
|
||||
Set<ItemFlag> flags = convertItemFlags(element);
|
||||
meta.addItemFlags(flags.toArray(new ItemFlag[0]));
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonArray convertItemFlags(Set<ItemFlag> flags)
|
||||
{
|
||||
// Null
|
||||
if (flags == null) return null;
|
||||
if (flags.isEmpty()) return null;
|
||||
|
||||
// Create Ret
|
||||
JsonArray ret = new JsonArray();
|
||||
|
||||
// Fill Ret
|
||||
for (ItemFlag flag : flags)
|
||||
{
|
||||
ret.add(new JsonPrimitive(flag.name()));
|
||||
}
|
||||
|
||||
// Return Ret
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Set<ItemFlag> convertItemFlags(JsonElement jsonElement)
|
||||
{
|
||||
// Create Ret
|
||||
Set<ItemFlag> ret = new HashSet<ItemFlag>();
|
||||
|
||||
// Fill Ret
|
||||
JsonArray json = jsonElement.getAsJsonArray();
|
||||
for (JsonElement element : json)
|
||||
{
|
||||
try
|
||||
{
|
||||
ItemFlag flag = ItemFlag.valueOf(element.getAsString());
|
||||
ret.add(flag);
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
// Ignore when we got a old String which does not map to a Enum value anymore.
|
||||
}
|
||||
}
|
||||
|
||||
// Return Ret
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void transferMetaSpecific(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
if (meta instanceof BannerMeta)
|
||||
{
|
||||
this.transferBanner(stack, json, meta2json, (BannerMeta)meta);
|
||||
}
|
||||
else
|
||||
{
|
||||
super.transferMetaSpecific(stack, json, meta2json, meta);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: SKULL
|
||||
// -------------------------------------------- //
|
||||
// When we serialize we store the minimal information possible.
|
||||
// We then deserialize using cached information.
|
||||
// This is done to avoid sync bouncing.
|
||||
// Different servers might serialize different heads differently.
|
||||
|
||||
@Override
|
||||
public void transferSkull(ItemStack stack, JsonObject json, boolean meta2json, SkullMeta meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
if ( ! meta.hasOwner()) return;
|
||||
String name = meta.getOwner();
|
||||
if (name == null) return;
|
||||
name = name.toLowerCase();
|
||||
json.addProperty(SKULL_OWNER, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(SKULL_OWNER);
|
||||
if (element == null) return;
|
||||
|
||||
String name = element.getAsString();
|
||||
UUID id = null;
|
||||
|
||||
Couple<String, UUID> resolved = NmsHead.resolve(name, id);
|
||||
name = resolved.getFirst();
|
||||
id = resolved.getSecond();
|
||||
|
||||
if (name != null || id != null)
|
||||
{
|
||||
NmsHead.set(meta, name, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: BANNER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferBanner(ItemStack stack, JsonObject json, boolean meta2json, Object meta)
|
||||
{
|
||||
this.transferBannerBase(stack, json, meta2json, meta);
|
||||
this.transferBannerPatterns(stack, json, meta2json, meta);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: BANNER BASE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferBannerBase(ItemStack stack, JsonObject json, boolean meta2json, Object meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
DyeColor baseColor = null;
|
||||
if (meta instanceof BannerMeta) baseColor = ((BannerMeta)meta).getBaseColor();
|
||||
if (meta instanceof Banner) baseColor = ((Banner)meta).getBaseColor();
|
||||
|
||||
// The default base color is null.
|
||||
// This occurs when no patterns are set.
|
||||
// In those cases the damage value of the item is used to denote color.
|
||||
if (baseColor == null) return;
|
||||
|
||||
byte data = baseColor.getDyeData();
|
||||
json.addProperty(BANNER_BASE, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(BANNER_BASE);
|
||||
if (element == null) return;
|
||||
DyeColor baseColor = DyeColor.getByDyeData(element.getAsByte());
|
||||
|
||||
if (meta instanceof BannerMeta) ((BannerMeta)meta).setBaseColor(baseColor);
|
||||
if (meta instanceof Banner) ((Banner)meta).setBaseColor(baseColor);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: BANNER PATTERNS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void transferBannerPatterns(ItemStack stack, JsonObject json, boolean meta2json, Object meta)
|
||||
{
|
||||
if (meta2json)
|
||||
{
|
||||
List<Pattern> patterns = null;
|
||||
if (meta instanceof BannerMeta) patterns = ((BannerMeta)meta).getPatterns();
|
||||
if (meta instanceof Banner) patterns = ((Banner)meta).getPatterns();
|
||||
|
||||
JsonArray data = convertBannerPatterns(patterns);
|
||||
if (data == null) return;
|
||||
json.add(BANNER_PATTERNS, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
JsonElement element = json.get(BANNER_PATTERNS);
|
||||
if (element == null) return;
|
||||
List<Pattern> patterns = convertBannerPatterns(element);
|
||||
|
||||
if (meta instanceof BannerMeta) ((BannerMeta)meta).setPatterns(patterns);
|
||||
if (meta instanceof Banner) ((Banner)meta).setPatterns(patterns);
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonArray convertBannerPatterns(List<Pattern> patterns)
|
||||
{
|
||||
// Null
|
||||
if (patterns == null) return null;
|
||||
if (patterns.isEmpty()) return null;
|
||||
|
||||
// Create Ret
|
||||
JsonArray ret = new JsonArray();
|
||||
|
||||
// Fill Ret
|
||||
for (Pattern pattern : patterns)
|
||||
{
|
||||
String i = pattern.getPattern().getIdentifier();
|
||||
Byte c = pattern.getColor().getDyeData();
|
||||
|
||||
ret.add(new JsonPrimitive(i));
|
||||
ret.add(new JsonPrimitive(c));
|
||||
}
|
||||
|
||||
// Return Ret
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static List<Pattern> convertBannerPatterns(JsonElement jsonElement)
|
||||
{
|
||||
// Create Ret
|
||||
List<Pattern> ret = new ArrayList<Pattern>();
|
||||
|
||||
// Fill Ret
|
||||
JsonArray json = jsonElement.getAsJsonArray();
|
||||
Iterator<JsonElement> iter = json.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
JsonElement ie = iter.next();
|
||||
if ( ! iter.hasNext()) break;
|
||||
JsonElement ce = iter.next();
|
||||
|
||||
PatternType type = PatternType.getByIdentifier(ie.getAsString());
|
||||
DyeColor color = DyeColor.getByDyeData(ce.getAsByte());
|
||||
ret.add(new Pattern(color, type));
|
||||
}
|
||||
|
||||
// Return Ret
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,247 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class AdapterItemStackInner19 extends AdapterItemStackInner18
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS: POTION
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final String POTION = "potion";
|
||||
public static final PotionData POTION_DEFAULT = new PotionData(PotionType.WATER, false, false);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final AdapterItemStackInner19 i = new AdapterItemStackInner19();
|
||||
public static AdapterItemStackInner19 get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PROVOKE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Object provoke()
|
||||
{
|
||||
return PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META (SHIELD)
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void transferMetaSpecific(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
|
||||
{
|
||||
if (stack.getType() == Material.SHIELD)
|
||||
{
|
||||
this.transferShield(stack, json, meta2json, (BlockStateMeta)meta);
|
||||
}
|
||||
else
|
||||
{
|
||||
super.transferMetaSpecific(stack, json, meta2json, meta);
|
||||
}
|
||||
}
|
||||
|
||||
public void transferShield(ItemStack stack, JsonObject json, boolean meta2json, BlockStateMeta meta)
|
||||
{
|
||||
BlockState state = (Banner) meta.getBlockState();
|
||||
this.transferBanner(stack, json, meta2json, state);
|
||||
|
||||
if (meta2json)
|
||||
{
|
||||
// TODO: This direction seems to work fine.
|
||||
// TODO: Serialization seems to work fine.
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: This does not seem to work.
|
||||
// TODO: Is it because an inferior ItemStack vs CraftItemStack implementation?
|
||||
meta.setBlockState(state);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SPECIFIC META: POTION
|
||||
// -------------------------------------------- //
|
||||
// In Minecraft 1.8 the damage value was used to store the potion effects.
|
||||
// In Minecraft 1.9 the damage value is no longer used and the potion effect is stored by string instead.
|
||||
//
|
||||
// Sticking to the damage value for serialization is not feasible.
|
||||
// Minecraft 1.9 adds new potion effects that did not exist in Minecraft 1.9 such as LUCK.
|
||||
//
|
||||
// Thus we upgrade the database from damage values to the new potion string where possible.
|
||||
// Invalid old damage values that does not make any sense are left as is.
|
||||
|
||||
@Override
|
||||
public void transferPotion(ItemStack stack, JsonObject json, boolean meta2json, PotionMeta meta)
|
||||
{
|
||||
super.transferPotion(stack, json, meta2json, meta);
|
||||
|
||||
if (meta2json)
|
||||
{
|
||||
// Check Null and Default
|
||||
PotionData potionData = meta.getBasePotionData();
|
||||
if (potionData != null && ! potionData.equals(POTION_DEFAULT))
|
||||
{
|
||||
// Check Null (silent on failure)
|
||||
String potionString = toPotionString(potionData);
|
||||
if (potionString != null)
|
||||
{
|
||||
json.addProperty(POTION, potionString);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create
|
||||
PotionData target = null;
|
||||
|
||||
// Get by "potion"
|
||||
JsonElement potionElement = json.get(POTION);
|
||||
if (potionElement != null)
|
||||
{
|
||||
String potionString = potionElement.getAsString();
|
||||
PotionData potionData = toPotionData(potionString);
|
||||
if (potionData != null)
|
||||
{
|
||||
target = potionData;
|
||||
}
|
||||
}
|
||||
|
||||
// Get by "damage"
|
||||
if (target == null)
|
||||
{
|
||||
JsonElement damageElement = json.get(DAMAGE);
|
||||
if (damageElement != null)
|
||||
{
|
||||
int damage = damageElement.getAsInt();
|
||||
PotionData potionData = toPotionData(damage);
|
||||
if (potionData != null)
|
||||
{
|
||||
stack.setDurability((short) 0);
|
||||
target = potionData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get by POTION_DEFAULT
|
||||
if (target == null)
|
||||
{
|
||||
target = POTION_DEFAULT;
|
||||
}
|
||||
|
||||
// Set
|
||||
meta.setBasePotionData(target);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// POTION UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static PotionData toPotionData(int damage)
|
||||
{
|
||||
try
|
||||
{
|
||||
Potion potion = Potion.fromDamage(damage);
|
||||
PotionType type = potion.getType();
|
||||
boolean extended = potion.hasExtendedDuration();
|
||||
boolean upgraded = (potion.getLevel() >= 2);
|
||||
|
||||
// This section serves two purposes:
|
||||
// 1. Avoid slow exceptions over for invalid damage values.
|
||||
// 2. Lenient upgrade to Minecraft 1.9. Keep what we can.
|
||||
// If a potion was both upgraded and extended we keep the upgraded and remove the extended.
|
||||
if (type == null) return null;
|
||||
if (extended && ! type.isExtendable()) return null;
|
||||
if (upgraded && ! type.isUpgradeable()) return null;
|
||||
if (upgraded && extended) extended = false;
|
||||
|
||||
return new PotionData(type, extended, upgraded);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static PotionData toPotionData(String potionString)
|
||||
{
|
||||
if (potionString == null) return null;
|
||||
return POTION_ID_TO_DATA.get(potionString);
|
||||
}
|
||||
|
||||
public static String toPotionString(PotionData potionData)
|
||||
{
|
||||
if (potionData == null) return null;
|
||||
return POTION_ID_TO_DATA.inverse().get(potionData);
|
||||
}
|
||||
|
||||
private static final BiMap<String, PotionData> POTION_ID_TO_DATA = ImmutableBiMap.<String, PotionData>builder()
|
||||
// REGULAR
|
||||
.put("empty", new PotionData(PotionType.UNCRAFTABLE, false, false))
|
||||
.put("water", new PotionData(PotionType.WATER, false, false))
|
||||
.put("mundane", new PotionData(PotionType.MUNDANE, false, false))
|
||||
.put("thick", new PotionData(PotionType.THICK, false, false))
|
||||
.put("awkward", new PotionData(PotionType.AWKWARD, false, false))
|
||||
.put("night_vision", new PotionData(PotionType.NIGHT_VISION, false, false))
|
||||
.put("invisibility", new PotionData(PotionType.INVISIBILITY, false, false))
|
||||
.put("leaping", new PotionData(PotionType.JUMP, false, false))
|
||||
.put("fire_resistance", new PotionData(PotionType.FIRE_RESISTANCE, false, false))
|
||||
.put("swiftness", new PotionData(PotionType.SPEED, false, false))
|
||||
.put("slowness", new PotionData(PotionType.SLOWNESS, false, false))
|
||||
.put("water_breathing", new PotionData(PotionType.WATER_BREATHING, false, false))
|
||||
.put("healing", new PotionData(PotionType.INSTANT_HEAL, false, false))
|
||||
.put("harming", new PotionData(PotionType.INSTANT_DAMAGE, false, false))
|
||||
.put("poison", new PotionData(PotionType.POISON, false, false))
|
||||
.put("regeneration", new PotionData(PotionType.REGEN, false, false))
|
||||
.put("strength", new PotionData(PotionType.STRENGTH, false, false))
|
||||
.put("weakness", new PotionData(PotionType.WEAKNESS, false, false))
|
||||
.put("luck", new PotionData(PotionType.LUCK, false, false))
|
||||
|
||||
// UPGRADABLE
|
||||
.put("strong_leaping", new PotionData(PotionType.JUMP, false, true))
|
||||
.put("strong_swiftness", new PotionData(PotionType.SPEED, false, true))
|
||||
.put("strong_healing", new PotionData(PotionType.INSTANT_HEAL, false, true))
|
||||
.put("strong_harming", new PotionData(PotionType.INSTANT_DAMAGE, false, true))
|
||||
.put("strong_poison", new PotionData(PotionType.POISON, false, true))
|
||||
.put("strong_regeneration", new PotionData(PotionType.REGEN, false, true))
|
||||
.put("strong_strength", new PotionData(PotionType.STRENGTH, false, true))
|
||||
|
||||
// EXTENDABLE
|
||||
.put("long_night_vision", new PotionData(PotionType.NIGHT_VISION, true, false))
|
||||
.put("long_invisibility", new PotionData(PotionType.INVISIBILITY, true, false))
|
||||
.put("long_leaping", new PotionData(PotionType.JUMP, true, false))
|
||||
.put("long_fire_resistance", new PotionData(PotionType.FIRE_RESISTANCE, true, false))
|
||||
.put("long_swiftness", new PotionData(PotionType.SPEED, true, false))
|
||||
.put("long_slowness", new PotionData(PotionType.SLOWNESS, true, false))
|
||||
.put("long_water_breathing", new PotionData(PotionType.WATER_BREATHING, true, false))
|
||||
.put("long_poison", new PotionData(PotionType.POISON, true, false))
|
||||
.put("long_regeneration", new PotionData(PotionType.REGEN, true, false))
|
||||
.put("long_strength", new PotionData(PotionType.STRENGTH, true, false))
|
||||
.put("long_weakness", new PotionData(PotionType.WEAKNESS, true, false))
|
||||
|
||||
// BUILD
|
||||
.build();
|
||||
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
package com.massivecraft.massivecore.adapter;
|
||||
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class AdapterPotionEffect
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELD CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final String POTION_EFFECT_ID = "id";
|
||||
public static final String POTION_DURATION = "duration";
|
||||
public static final String POTION_AMPLIFIER = "amplifier";
|
||||
public static final String POTION_AMBIENT = "ambient";
|
||||
|
||||
public static final int POTION_DURATION_DEFAULT = 20*3*60;
|
||||
public static final int POTION_AMPLIFIER_DEFAULT = 0;
|
||||
public static final boolean POTION_AMBIENT_DEFAULT = false;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TO JSON
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static JsonObject toJson(PotionEffect potionEffect)
|
||||
{
|
||||
if (potionEffect == null) return null;
|
||||
|
||||
JsonObject ret = new JsonObject();
|
||||
|
||||
ret.addProperty(POTION_EFFECT_ID, potionEffect.getType().getId());
|
||||
ret.addProperty(POTION_DURATION, potionEffect.getDuration());
|
||||
ret.addProperty(POTION_AMPLIFIER, potionEffect.getAmplifier());
|
||||
ret.addProperty(POTION_AMBIENT, potionEffect.isAmbient());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FROM JSON
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static PotionEffect fromJson(JsonElement jsonElement)
|
||||
{
|
||||
if (jsonElement == null) return null;
|
||||
if ( ! jsonElement.isJsonObject()) return null;
|
||||
|
||||
JsonObject json = jsonElement.getAsJsonObject();
|
||||
|
||||
PotionEffectType pet = PotionEffectType.getById(json.get(POTION_EFFECT_ID).getAsInt());
|
||||
|
||||
int duration = POTION_DURATION_DEFAULT;
|
||||
JsonElement durationElement = json.get(POTION_DURATION);
|
||||
if (durationElement != null)
|
||||
{
|
||||
duration = durationElement.getAsInt();
|
||||
}
|
||||
|
||||
int amplifier = POTION_AMPLIFIER_DEFAULT;
|
||||
JsonElement amplifierElement = json.get(POTION_AMPLIFIER);
|
||||
if (amplifierElement != null)
|
||||
{
|
||||
amplifier = amplifierElement.getAsInt();
|
||||
}
|
||||
|
||||
boolean ambient = POTION_AMBIENT_DEFAULT;
|
||||
JsonElement ambientElement = json.get(POTION_AMBIENT);
|
||||
if (ambientElement != null)
|
||||
{
|
||||
ambient = ambientElement.getAsBoolean();
|
||||
}
|
||||
|
||||
return new PotionEffect(pet, duration, amplifier, ambient);
|
||||
}
|
||||
|
||||
}
|
@ -60,7 +60,7 @@ public class DataBannerPattern implements Comparable<DataBannerPattern>
|
||||
public Pattern toBukkit()
|
||||
{
|
||||
// Create
|
||||
Pattern ret = WriterBannerPattern.get().createB();
|
||||
Pattern ret = WriterBannerPattern.get().createOB();
|
||||
|
||||
// Fill
|
||||
this.write(ret, true);
|
||||
|
@ -84,7 +84,7 @@ public class DataFireworkEffect implements Comparable<DataFireworkEffect>
|
||||
public FireworkEffect toBukkit()
|
||||
{
|
||||
// Create
|
||||
FireworkEffect ret = WriterFireworkEffect.get().createB();
|
||||
FireworkEffect ret = WriterFireworkEffect.get().createOB();
|
||||
|
||||
// Fill
|
||||
this.write(ret, true);
|
||||
|
@ -271,7 +271,7 @@ public class DataItemStack implements Comparable<DataItemStack>
|
||||
public ItemStack toBukkit()
|
||||
{
|
||||
// Create
|
||||
ItemStack ret = WriterItemStack.get().createB();
|
||||
ItemStack ret = WriterItemStack.get().createOB();
|
||||
|
||||
// Fill
|
||||
this.write(ret, true);
|
||||
|
@ -83,7 +83,7 @@ public class DataPotionEffect implements Comparable<DataPotionEffect>
|
||||
public PotionEffect toBukkit()
|
||||
{
|
||||
// Create
|
||||
PotionEffect ret = WriterPotionEffect.get().createB();
|
||||
PotionEffect ret = WriterPotionEffect.get().createOB();
|
||||
|
||||
// Fill
|
||||
this.write(ret, true);
|
||||
|
98
src/com/massivecraft/massivecore/item/PotionUtil.java
Normal file
98
src/com/massivecraft/massivecore/item/PotionUtil.java
Normal file
@ -0,0 +1,98 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PotionUtil
|
||||
{
|
||||
public static PotionData toPotionData(int damage)
|
||||
{
|
||||
try
|
||||
{
|
||||
Potion potion = Potion.fromDamage(damage);
|
||||
PotionType type = potion.getType();
|
||||
boolean extended = potion.hasExtendedDuration();
|
||||
boolean upgraded = (potion.getLevel() >= 2);
|
||||
|
||||
// This section serves two purposes:
|
||||
// 1. Avoid slow exceptions over for invalid damage values.
|
||||
// 2. Lenient upgrade to Minecraft 1.9. Keep what we can.
|
||||
// If a potion was both upgraded and extended we keep the upgraded and remove the extended.
|
||||
if (type == null) return null;
|
||||
if (extended && ! type.isExtendable()) return null;
|
||||
if (upgraded && ! type.isUpgradeable()) return null;
|
||||
if (upgraded && extended) extended = false;
|
||||
|
||||
return new PotionData(type, extended, upgraded);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static PotionData toPotionData(String potionString)
|
||||
{
|
||||
if (potionString == null) return null;
|
||||
return POTION_ID_TO_DATA.get(potionString);
|
||||
}
|
||||
|
||||
public static String toPotionString(PotionData potionData)
|
||||
{
|
||||
if (potionData == null) return null;
|
||||
return POTION_ID_TO_DATA.inverse().get(potionData);
|
||||
}
|
||||
|
||||
private static final BiMap<String, PotionData> POTION_ID_TO_DATA = ImmutableBiMap.<String, PotionData>builder()
|
||||
// REGULAR
|
||||
.put("empty", new PotionData(PotionType.UNCRAFTABLE, false, false))
|
||||
.put("water", new PotionData(PotionType.WATER, false, false))
|
||||
.put("mundane", new PotionData(PotionType.MUNDANE, false, false))
|
||||
.put("thick", new PotionData(PotionType.THICK, false, false))
|
||||
.put("awkward", new PotionData(PotionType.AWKWARD, false, false))
|
||||
.put("night_vision", new PotionData(PotionType.NIGHT_VISION, false, false))
|
||||
.put("invisibility", new PotionData(PotionType.INVISIBILITY, false, false))
|
||||
.put("leaping", new PotionData(PotionType.JUMP, false, false))
|
||||
.put("fire_resistance", new PotionData(PotionType.FIRE_RESISTANCE, false, false))
|
||||
.put("swiftness", new PotionData(PotionType.SPEED, false, false))
|
||||
.put("slowness", new PotionData(PotionType.SLOWNESS, false, false))
|
||||
.put("water_breathing", new PotionData(PotionType.WATER_BREATHING, false, false))
|
||||
.put("healing", new PotionData(PotionType.INSTANT_HEAL, false, false))
|
||||
.put("harming", new PotionData(PotionType.INSTANT_DAMAGE, false, false))
|
||||
.put("poison", new PotionData(PotionType.POISON, false, false))
|
||||
.put("regeneration", new PotionData(PotionType.REGEN, false, false))
|
||||
.put("strength", new PotionData(PotionType.STRENGTH, false, false))
|
||||
.put("weakness", new PotionData(PotionType.WEAKNESS, false, false))
|
||||
.put("luck", new PotionData(PotionType.LUCK, false, false))
|
||||
|
||||
// UPGRADABLE
|
||||
.put("strong_leaping", new PotionData(PotionType.JUMP, false, true))
|
||||
.put("strong_swiftness", new PotionData(PotionType.SPEED, false, true))
|
||||
.put("strong_healing", new PotionData(PotionType.INSTANT_HEAL, false, true))
|
||||
.put("strong_harming", new PotionData(PotionType.INSTANT_DAMAGE, false, true))
|
||||
.put("strong_poison", new PotionData(PotionType.POISON, false, true))
|
||||
.put("strong_regeneration", new PotionData(PotionType.REGEN, false, true))
|
||||
.put("strong_strength", new PotionData(PotionType.STRENGTH, false, true))
|
||||
|
||||
// EXTENDABLE
|
||||
.put("long_night_vision", new PotionData(PotionType.NIGHT_VISION, true, false))
|
||||
.put("long_invisibility", new PotionData(PotionType.INVISIBILITY, true, false))
|
||||
.put("long_leaping", new PotionData(PotionType.JUMP, true, false))
|
||||
.put("long_fire_resistance", new PotionData(PotionType.FIRE_RESISTANCE, true, false))
|
||||
.put("long_swiftness", new PotionData(PotionType.SPEED, true, false))
|
||||
.put("long_slowness", new PotionData(PotionType.SLOWNESS, true, false))
|
||||
.put("long_water_breathing", new PotionData(PotionType.WATER_BREATHING, true, false))
|
||||
.put("long_poison", new PotionData(PotionType.POISON, true, false))
|
||||
.put("long_regeneration", new PotionData(PotionType.REGEN, true, false))
|
||||
.put("long_strength", new PotionData(PotionType.STRENGTH, true, false))
|
||||
.put("long_weakness", new PotionData(PotionType.WEAKNESS, true, false))
|
||||
|
||||
// BUILD
|
||||
.build();
|
||||
|
||||
}
|
@ -11,7 +11,18 @@ import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.ReflectionUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
|
||||
// A = What we are writing from.
|
||||
// B = What we are writing to.
|
||||
//
|
||||
// O = The base object. Not yet morphed into specific class.
|
||||
// C = The specific class object. Often the same as O but at times very different.
|
||||
// F = The field class. Used for field writing.
|
||||
//
|
||||
// D = The data class. Used for sending arbitrary data along.
|
||||
//
|
||||
// TIP: Simply set to Object if you are not using a certain generic.
|
||||
//
|
||||
public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB, D> extends Engine
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// WRITERS
|
||||
@ -19,10 +30,9 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
|
||||
// Writer have dependencies and child writers.
|
||||
|
||||
// A dependency is another writer that must be successfully activated for this writer to function.
|
||||
// For that reason the dependencies are activated just after the provoke logic.
|
||||
// For that reason the dependencies are activated just after the setup logic.
|
||||
// Examples would be WriterPotionEffect and WriterFireworkEffect.
|
||||
// They are implicitly required for some ItemStack field writers.
|
||||
|
||||
private List<Class<?>> dependencyClasses = new MassiveList<>();
|
||||
public List<Class<?>> getDependencyClasses() { return this.dependencyClasses; }
|
||||
public void addDependencyClasses(Class<?>... dependencyClasses) { this.getDependencyClasses().addAll(Arrays.asList(dependencyClasses)); }
|
||||
@ -35,9 +45,9 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
|
||||
public void addWriterClasses(Class<?>... writerClasses) { this.getWriterClasses().addAll(Arrays.asList(writerClasses)); }
|
||||
|
||||
// These are the actually functional child writers.
|
||||
// This list should only contain writers that passed the provoke routine.
|
||||
private List<WriterAbstract<CA, CB, ?, ?, ?, ?>> writers = new MassiveList<>();
|
||||
public List<WriterAbstract<CA, CB, ?, ?, ?, ?>> getWriters() { return this.writers; }
|
||||
// This list should only contain writers that passed the setup routine.
|
||||
private List<WriterAbstract<CA, CB, ?, ?, ?, ?, D>> writers = new MassiveList<>();
|
||||
public List<WriterAbstract<CA, CB, ?, ?, ?, ?, D>> getWriters() { return this.writers; }
|
||||
|
||||
// Here is the logic to perform the dependency and child writer setup.
|
||||
public void setupDependencies()
|
||||
@ -61,12 +71,12 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<WriterAbstract<?, ?, ?, ?, ?, ?>> writerClassInner = (Class<WriterAbstract<?, ?, ?, ?, ?, ?>>) writerClass;
|
||||
WriterAbstract<?, ?, ?, ?, ?, ?> writer = ReflectionUtil.getSingletonInstance(writerClassInner);
|
||||
Class<WriterAbstract<?, ?, ?, ?, ?, ?, ?>> writerClassInner = (Class<WriterAbstract<?, ?, ?, ?, ?, ?, ?>>) writerClass;
|
||||
WriterAbstract<?, ?, ?, ?, ?, ?, ?> writer = ReflectionUtil.getSingletonInstance(writerClassInner);
|
||||
|
||||
if ( ! writer.isActive()) writer.setActive(this.getActivePlugin());
|
||||
|
||||
if (add) this.getWriters().add((WriterAbstract<CA, CB, ?, ?, ?, ?>)writer);
|
||||
if (add) this.getWriters().add((WriterAbstract<CA, CB, ?, ?, ?, ?, D>)writer);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
@ -120,17 +130,14 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
|
||||
// -------------------------------------------- //
|
||||
// ACTIVE
|
||||
// -------------------------------------------- //
|
||||
// The setActive method starts out with the provoke.
|
||||
// This means it can fail immediately with a runtime exception.
|
||||
// If this happens it will not have been activated in any way.
|
||||
|
||||
@Override
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
// Provoke
|
||||
this.provoke();
|
||||
// Setup Self
|
||||
this.setupSelf();
|
||||
|
||||
// Setup Dependencies
|
||||
this.setupDependencies();
|
||||
@ -141,6 +148,7 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
|
||||
// Setup Writers
|
||||
this.setupWriters();
|
||||
}
|
||||
|
||||
super.setActive(active);
|
||||
}
|
||||
|
||||
@ -148,87 +156,91 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public abstract CA createA();
|
||||
|
||||
public abstract CB createB();
|
||||
public OA createOA()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public OB createOB()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CLASSES
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Class<CA> classA = null;
|
||||
private Class<?> classOA = null;
|
||||
public Class<?> getClassOA() { return this.classOA; }
|
||||
public void setClassOA(Class<?> classOA) { this.classOA = classOA; }
|
||||
|
||||
public Class<CA> getClassA()
|
||||
{
|
||||
return this.classA;
|
||||
}
|
||||
private Class<?> classOB = null;
|
||||
public Class<?> getClassOB() { return this.classOB; }
|
||||
public void setClassOB(Class<?> classOB) { this.classOB = classOB; }
|
||||
|
||||
private Class<?> classCA = null;
|
||||
public Class<?> getClassCA() { return this.classCA; }
|
||||
public void setClassCA(Class<?> classCA) { this.classCA = classCA; }
|
||||
|
||||
public void setClassA(Class<CA> classA)
|
||||
{
|
||||
this.classA = classA;
|
||||
}
|
||||
|
||||
private Class<CB> classB = null;
|
||||
|
||||
public Class<CB> getClassB()
|
||||
{
|
||||
return this.classB;
|
||||
}
|
||||
|
||||
public void setClassB(Class<CB> classB)
|
||||
{
|
||||
this.classB = classB;
|
||||
}
|
||||
private Class<?> classCB = null;
|
||||
public Class<?> getClassCB() { return this.classCB; }
|
||||
public void setClassCB(Class<?> classCB) { this.classCB = classCB; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MORPH
|
||||
// -------------------------------------------- //
|
||||
// Per default the morph is just a secure cast.
|
||||
// If the morph fails it means the writer was not applicable.
|
||||
// In those cases we don't want a crash.
|
||||
// We rather silently continue.
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CA morphA(OA oa)
|
||||
{
|
||||
Class<CA> classA = this.getClassA();
|
||||
if (classA != null && !classA.isAssignableFrom(oa.getClass())) return null;
|
||||
CA ca = (CA) oa;
|
||||
return ca;
|
||||
if (this.getClassCA() != null && ! this.getClassCA().isAssignableFrom(oa.getClass())) return null;
|
||||
return (CA)oa;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public CB morphB(OB ob)
|
||||
{
|
||||
Class<CB> classB = this.getClassB();
|
||||
if (classB != null && !classB.isAssignableFrom(ob.getClass())) return null;
|
||||
CB cb = (CB) ob;
|
||||
return cb;
|
||||
if (this.getClassCB() != null && ! this.getClassCB().isAssignableFrom(ob.getClass())) return null;
|
||||
return (CB)ob;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PROVOKE
|
||||
// SETUP
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Object provoke()
|
||||
|
||||
public void setupSelf()
|
||||
{
|
||||
// Create Instances
|
||||
CA ia = this.createA();
|
||||
CB ib = this.createB();
|
||||
// Create O
|
||||
OA oa = this.createOA();
|
||||
OB ob = this.createOB();
|
||||
|
||||
// Demand Set
|
||||
if (ia == null) throw new NullPointerException("Couldn't Create A");
|
||||
if (ib == null) throw new NullPointerException("Couldn't Create B");
|
||||
|
||||
// Use Access
|
||||
FA fa = this.getA(ia);
|
||||
this.setA(ia, fa);
|
||||
|
||||
FB fb = this.getB(ib);
|
||||
this.setB(ib, fb);
|
||||
|
||||
// Use To
|
||||
this.toA(fb);
|
||||
this.toB(fa);
|
||||
|
||||
// Return
|
||||
return null;
|
||||
// Demand O
|
||||
if (oa == null) throw new NullPointerException("Couldn't Create OA");
|
||||
if (ob == null) throw new NullPointerException("Couldn't Create OB");
|
||||
|
||||
// Class O
|
||||
this.setClassOA(oa.getClass());
|
||||
this.setClassOB(ob.getClass());
|
||||
|
||||
// Morph
|
||||
CA ca = this.morphA(oa);
|
||||
CB cb = this.morphB(ob);
|
||||
|
||||
// Demand C
|
||||
if (ca == null) throw new NullPointerException("Couldn't Create CA");
|
||||
if (cb == null) throw new NullPointerException("Couldn't Create CB");
|
||||
|
||||
// Class C
|
||||
this.setClassCA(ca.getClass());
|
||||
this.setClassCB(cb.getClass());
|
||||
|
||||
// Write (to provoke extra much)
|
||||
this.write(oa, ob, true);
|
||||
this.write(oa, ob, false);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -237,38 +249,43 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
|
||||
|
||||
public void write(OA oa, OB ob, boolean a2b)
|
||||
{
|
||||
if ( ! this.isActive()) throw new IllegalStateException("not active " + this.getClass().getName());
|
||||
this.write(oa, ob, null, a2b);
|
||||
}
|
||||
|
||||
public void write(OA oa, OB ob, D d, boolean a2b)
|
||||
{
|
||||
// if ( ! this.isActive()) throw new IllegalStateException("not active " + this.getClass().getName());
|
||||
|
||||
if (oa == null) throw new NullPointerException("oa");
|
||||
if (ob == null) throw new NullPointerException("ob");
|
||||
|
||||
|
||||
CA ca = this.morphA(oa);
|
||||
if (ca == null) return;
|
||||
|
||||
CB cb = this.morphB(ob);
|
||||
if (cb == null) return;
|
||||
|
||||
this.writeInner(oa, ob, ca, cb, a2b);
|
||||
this.writeInner(oa, ob, ca, cb, d, a2b);
|
||||
}
|
||||
|
||||
public void writeInner(OA oa, OB ob, CA ca, CB cb, boolean a2b)
|
||||
public void writeInner(OA oa, OB ob, CA ca, CB cb, D d, boolean a2b)
|
||||
{
|
||||
for (WriterAbstract<CA, CB, ?, ?, ?, ?> writer : this.getWriters())
|
||||
for (WriterAbstract<CA, CB, ?, ?, ?, ?, D> writer : this.getWriters())
|
||||
{
|
||||
writer.write(ca, cb, a2b);
|
||||
writer.write(ca, cb, d, a2b);
|
||||
}
|
||||
|
||||
if (a2b)
|
||||
{
|
||||
FA fa = getA(ca);
|
||||
FA fa = getA(ca, d);
|
||||
FB fb = toB(fa);
|
||||
setB(cb, fb);
|
||||
setB(cb, fb, d);
|
||||
}
|
||||
else
|
||||
{
|
||||
FB fb = getB(cb);
|
||||
FB fb = getB(cb, d);
|
||||
FA fa = toA(fb);
|
||||
setA(ca, fa);
|
||||
setA(ca, fa, d);
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,22 +293,22 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
|
||||
// ACCESS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public FA getA(CA ca)
|
||||
public FA getA(CA ca, D d)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setA(CA ca, FA fa)
|
||||
public void setA(CA ca, FA fa, D d)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public FB getB(CB cb)
|
||||
public FB getB(CB cb, D d)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setB(CB cb, FB fb)
|
||||
public void setB(CB cb, FB fb, D d)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ public abstract class WriterAbstractBannerPattern<FA, FB> extends WriterAbstract
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataBannerPattern createA()
|
||||
public DataBannerPattern createOA()
|
||||
{
|
||||
return new DataBannerPattern();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern createB()
|
||||
public Pattern createOB()
|
||||
{
|
||||
return new Pattern(DyeColor.WHITE, PatternType.BASE);
|
||||
}
|
||||
|
@ -25,13 +25,13 @@ public abstract class WriterAbstractFireworkEffect<FA, FB> extends WriterAbstrac
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataFireworkEffect createA()
|
||||
public DataFireworkEffect createOA()
|
||||
{
|
||||
return new DataFireworkEffect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FireworkEffect createB()
|
||||
public FireworkEffect createOB()
|
||||
{
|
||||
return FireworkEffect.builder().withColor(Color.GREEN).build();
|
||||
}
|
||||
|
@ -1,24 +1,60 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.massivecraft.massivecore.nms.NmsItemStack;
|
||||
|
||||
public abstract class WriterAbstractItemStack<OB, CB, FA, FB> extends WriterAbstract<DataItemStack, OB, DataItemStack, CB, FA, FB>
|
||||
public abstract class WriterAbstractItemStack<OB, CB, FA, FB> extends WriterAbstract<DataItemStack, OB, DataItemStack, CB, FA, FB, ItemStack>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Material material = Material.STONE;
|
||||
public Material getMaterial() { return this.material; }
|
||||
public void setMaterial(Material material) { this.material = material; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataItemStack createA()
|
||||
public DataItemStack createOA()
|
||||
{
|
||||
return new DataItemStack();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public CB createB()
|
||||
public OB createOB()
|
||||
{
|
||||
return (CB) NmsItemStack.get().createItemStack();
|
||||
return (OB) this.createItemStack();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE INNER
|
||||
// -------------------------------------------- //
|
||||
|
||||
public ItemStack createItemStack()
|
||||
{
|
||||
ItemStack ret = NmsItemStack.get().createItemStack();
|
||||
ret.setType(this.getMaterial());
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE & WRITE
|
||||
// -------------------------------------------- //
|
||||
// We some times need to access the ItemStack even at deeper levels of writing.
|
||||
// With that in mind we pass it along in the data generic.
|
||||
|
||||
@Override
|
||||
public void writeInner(DataItemStack oa, OB ob, DataItemStack ca, CB cb, ItemStack d, boolean a2b)
|
||||
{
|
||||
// Ensure there is an ItemStack data. Create if necessary (used by setup method).
|
||||
if (d == null) d = (ItemStack)((ob instanceof ItemStack) ? ob : this.createItemStack());
|
||||
super.writeInner(oa, ob, ca, cb, d, a2b);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,35 +1,22 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMeta<OB, CB, FA, FB> extends WriterAbstractItemStack<OB, CB, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// CREATE INNER
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Material material = Material.STONE;
|
||||
public Material getMaterial() { return this.material; }
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setMaterial(Material material)
|
||||
public ItemMeta createItemMeta()
|
||||
{
|
||||
this.material = material;
|
||||
CB cb = this.createB();
|
||||
this.setClassB((Class<CB>) cb.getClass());
|
||||
return createItemMeta(this.createItemStack());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public CB createB()
|
||||
public static ItemMeta createItemMeta(ItemStack itemStack)
|
||||
{
|
||||
ItemStack itemStack = (ItemStack) super.createB();
|
||||
itemStack.setType(this.getMaterial());
|
||||
return (CB) itemStack.getItemMeta();
|
||||
return itemStack.getItemMeta();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,16 @@ package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaField<M, FA, FB> extends WriterAbstractItemStackMeta<ItemMeta, M, FA, FB>
|
||||
public abstract class WriterAbstractItemStackMetaField<CB, FA, FB> extends WriterAbstractItemStackMeta<ItemMeta, CB, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public ItemMeta createOB()
|
||||
{
|
||||
return this.createItemMeta();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public abstract class WriterAbstractItemStackMetaMorph<FA, FB> extends WriterAbs
|
||||
@Override
|
||||
public ItemMeta morphB(ItemStack ob)
|
||||
{
|
||||
return ob.getItemMeta();
|
||||
return createItemMeta(ob);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -20,9 +20,9 @@ public abstract class WriterAbstractItemStackMetaMorph<FA, FB> extends WriterAbs
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void writeInner(DataItemStack oa, ItemStack ob, DataItemStack ca, ItemMeta cb, boolean a2b)
|
||||
public void writeInner(DataItemStack oa, ItemStack ob, DataItemStack ca, ItemMeta cb, ItemStack d, boolean a2b)
|
||||
{
|
||||
super.writeInner(oa, ob, ca, cb, a2b);
|
||||
super.writeInner(oa, ob, ca, cb, d, a2b);
|
||||
|
||||
// Write Back
|
||||
if (a2b) ob.setItemMeta(cb);
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaState<OB, CB, FA, FB> extends WriterAbstractItemStackMeta<OB, CB, FA, FB>
|
||||
{
|
||||
@ -11,20 +13,32 @@ public abstract class WriterAbstractItemStackMetaState<OB, CB, FA, FB> extends W
|
||||
|
||||
public WriterAbstractItemStackMetaState()
|
||||
{
|
||||
// For the initial provoke to pass we must set a Material with a BlockStateMeta.
|
||||
// For the setup to pass we must set a Material with a BlockStateMeta.
|
||||
this.setMaterial(Material.SHIELD);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// CREATE INNER
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public CB createB()
|
||||
public BlockState createItemMetaState()
|
||||
{
|
||||
BlockStateMeta blockStateMeta = (BlockStateMeta) super.createB();
|
||||
return (CB) blockStateMeta.getBlockState();
|
||||
return createItemMetaState(this.createItemMeta());
|
||||
}
|
||||
|
||||
public static BlockState createItemMetaState(ItemMeta itemMeta)
|
||||
{
|
||||
if ( ! (itemMeta instanceof BlockStateMeta)) return null;
|
||||
BlockStateMeta blockStateMeta = (BlockStateMeta)itemMeta;
|
||||
try
|
||||
{
|
||||
return blockStateMeta.getBlockState();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Catch errors such as: throw new IllegalStateException("Missing blockState for " + material);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,5 +4,14 @@ import org.bukkit.block.BlockState;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaStateField<S, FA, FB> extends WriterAbstractItemStackMetaState<BlockState, S, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public BlockState createOB()
|
||||
{
|
||||
return this.createItemMetaState();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,22 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaStateMorph<FA, FB> extends WriterAbstractItemStackMetaState<ItemMeta, BlockState, FA, FB>
|
||||
{
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public ItemMeta createOB()
|
||||
{
|
||||
return this.createItemMeta();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MORPH
|
||||
// -------------------------------------------- //
|
||||
@ -13,18 +24,17 @@ public abstract class WriterAbstractItemStackMetaStateMorph<FA, FB> extends Writ
|
||||
@Override
|
||||
public BlockState morphB(ItemMeta ob)
|
||||
{
|
||||
BlockStateMeta state = (BlockStateMeta)ob;
|
||||
return state.getBlockState();
|
||||
return createItemMetaState(ob);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE
|
||||
// -------------------------------------------- //
|
||||
|
||||
|
||||
@Override
|
||||
public void writeInner(DataItemStack oa, ItemMeta ob, DataItemStack ca, BlockState cb, boolean a2b)
|
||||
public void writeInner(DataItemStack oa, ItemMeta ob, DataItemStack ca, BlockState cb, ItemStack d, boolean a2b)
|
||||
{
|
||||
super.writeInner(oa, ob, ca, cb, a2b);
|
||||
super.writeInner(oa, ob, ca, cb, d, a2b);
|
||||
|
||||
// Write Back
|
||||
if (a2b)
|
||||
|
@ -24,13 +24,13 @@ public abstract class WriterAbstractPotionEffect<FA, FB> extends WriterAbstractR
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataPotionEffect createA()
|
||||
public DataPotionEffect createOA()
|
||||
{
|
||||
return new DataPotionEffect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionEffect createB()
|
||||
public PotionEffect createOB()
|
||||
{
|
||||
return new PotionEffect(PotionEffectType.SPEED, 1, 1);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import java.lang.reflect.Field;
|
||||
|
||||
import com.massivecraft.massivecore.util.ReflectionUtil;
|
||||
|
||||
public abstract class WriterAbstractReflect<OA, OB, CA, CB, FA, FB> extends WriterAbstract<OA, OB, CA, CB, FA, FB>
|
||||
public abstract class WriterAbstractReflect<OA, OB, CA, CB, FA, FB> extends WriterAbstract<OA, OB, CA, CB, FA, FB, Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
@ -26,7 +26,7 @@ public abstract class WriterAbstractReflect<OA, OB, CA, CB, FA, FB> extends Writ
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setB(CB cb, FB fb)
|
||||
public void setB(CB cb, FB fb, Object d)
|
||||
{
|
||||
if (this.field == null) return;
|
||||
ReflectionUtil.setField(this.field, cb, fb);
|
||||
|
@ -23,19 +23,19 @@ public class WriterBannerPatternColor extends WriterAbstractBannerPattern<Intege
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataBannerPattern ca)
|
||||
public Integer getA(DataBannerPattern ca, Object d)
|
||||
{
|
||||
return ca.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataBannerPattern ca, Integer fa)
|
||||
public void setA(DataBannerPattern ca, Integer fa, Object d)
|
||||
{
|
||||
ca.setColor(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeColor getB(Pattern cb)
|
||||
public DyeColor getB(Pattern cb, Object d)
|
||||
{
|
||||
return cb.getColor();
|
||||
}
|
||||
|
@ -23,19 +23,19 @@ public class WriterBannerPatternId extends WriterAbstractBannerPattern<String, P
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataBannerPattern ca)
|
||||
public String getA(DataBannerPattern ca, Object d)
|
||||
{
|
||||
return ca.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataBannerPattern ca, String fa)
|
||||
public void setA(DataBannerPattern ca, String fa, Object d)
|
||||
{
|
||||
ca.setId(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PatternType getB(Pattern cb)
|
||||
public PatternType getB(Pattern cb, Object d)
|
||||
{
|
||||
return cb.getPattern();
|
||||
}
|
||||
|
@ -27,19 +27,19 @@ public class WriterFireworkEffectColors extends WriterAbstractFireworkEffect<Lis
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<Integer> getA(DataFireworkEffect ca)
|
||||
public List<Integer> getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.getColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, List<Integer> fa)
|
||||
public void setA(DataFireworkEffect ca, List<Integer> fa, Object d)
|
||||
{
|
||||
ca.setColors(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Color> getB(FireworkEffect cb)
|
||||
public ImmutableList<Color> getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return (ImmutableList<Color>) cb.getColors();
|
||||
}
|
||||
|
@ -27,19 +27,19 @@ public class WriterFireworkEffectFadeColors extends WriterAbstractFireworkEffect
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<Integer> getA(DataFireworkEffect ca)
|
||||
public List<Integer> getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.getFadeColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, List<Integer> fa)
|
||||
public void setA(DataFireworkEffect ca, List<Integer> fa, Object d)
|
||||
{
|
||||
ca.setFadeColors(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Color> getB(FireworkEffect cb)
|
||||
public ImmutableList<Color> getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return (ImmutableList<Color>) cb.getFadeColors();
|
||||
}
|
||||
|
@ -20,19 +20,19 @@ public class WriterFireworkEffectFlicker extends WriterAbstractFireworkEffect<Bo
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Boolean getA(DataFireworkEffect ca)
|
||||
public Boolean getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.hasFlicker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, Boolean fa)
|
||||
public void setA(DataFireworkEffect ca, Boolean fa, Object d)
|
||||
{
|
||||
ca.setFlicker(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getB(FireworkEffect cb)
|
||||
public Boolean getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return cb.hasFlicker();
|
||||
}
|
||||
|
@ -20,19 +20,19 @@ public class WriterFireworkEffectTrail extends WriterAbstractFireworkEffect<Bool
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Boolean getA(DataFireworkEffect ca)
|
||||
public Boolean getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.hasTrail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, Boolean fa)
|
||||
public void setA(DataFireworkEffect ca, Boolean fa, Object d)
|
||||
{
|
||||
ca.setTrail(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getB(FireworkEffect cb)
|
||||
public Boolean getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return cb.hasTrail();
|
||||
}
|
||||
|
@ -23,19 +23,19 @@ public class WriterFireworkEffectType extends WriterAbstractFireworkEffect<Strin
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataFireworkEffect ca)
|
||||
public String getA(DataFireworkEffect ca, Object d)
|
||||
{
|
||||
return ca.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataFireworkEffect ca, String fa)
|
||||
public void setA(DataFireworkEffect ca, String fa, Object d)
|
||||
{
|
||||
ca.setType(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getB(FireworkEffect cb)
|
||||
public Type getB(FireworkEffect cb, Object d)
|
||||
{
|
||||
return cb.getType();
|
||||
}
|
||||
|
@ -16,25 +16,25 @@ public class WriterItemStackCount extends WriterAbstractItemStackField<Integer,
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca)
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa)
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setCount(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getB(ItemStack cb)
|
||||
public Integer getB(ItemStack cb, ItemStack d)
|
||||
{
|
||||
return cb.getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemStack cb, Integer fb)
|
||||
public void setB(ItemStack cb, Integer fb, ItemStack d)
|
||||
{
|
||||
cb.setAmount(fb);
|
||||
}
|
||||
|
@ -16,25 +16,25 @@ public class WriterItemStackDamage extends WriterAbstractItemStackField<Integer,
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca)
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa)
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setDamage(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getB(ItemStack cb)
|
||||
public Integer getB(ItemStack cb, ItemStack d)
|
||||
{
|
||||
return Integer.valueOf(cb.getDurability());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemStack cb, Integer fb)
|
||||
public void setB(ItemStack cb, Integer fb, ItemStack d)
|
||||
{
|
||||
cb.setDurability(fb.shortValue());
|
||||
}
|
||||
|
@ -16,27 +16,27 @@ public class WriterItemStackId extends WriterAbstractItemStackField<Integer, Int
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca)
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa)
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setId(fa);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Integer getB(ItemStack cb)
|
||||
public Integer getB(ItemStack cb, ItemStack d)
|
||||
{
|
||||
return cb.getTypeId();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void setB(ItemStack cb, Integer fb)
|
||||
public void setB(ItemStack cb, Integer fb, ItemStack d)
|
||||
{
|
||||
cb.setTypeId(fb);
|
||||
}
|
||||
|
@ -56,10 +56,10 @@ public class WriterItemStackMeta extends WriterAbstractItemStackMetaMorph<Object
|
||||
WriterItemStackMetaBannerPatterns.class,
|
||||
|
||||
// STATE
|
||||
WriterItemStackMetaState.class
|
||||
WriterItemStackMetaState.class,
|
||||
|
||||
// POTION
|
||||
// TODO Merge with potion above?
|
||||
WriterItemStackMetaPotion.class
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
public class WriterItemStackMetaAuthor extends WriterAbstractItemStackMetaField<BookMeta, String, String>
|
||||
@ -20,25 +21,25 @@ public class WriterItemStackMetaAuthor extends WriterAbstractItemStackMetaField<
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataItemStack ca)
|
||||
public String getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getAuthor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, String fa)
|
||||
public void setA(DataItemStack ca, String fa, ItemStack d)
|
||||
{
|
||||
ca.setAuthor(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getB(BookMeta cb)
|
||||
public String getB(BookMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getAuthor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(BookMeta cb, String fb)
|
||||
public void setB(BookMeta cb, String fb, ItemStack d)
|
||||
{
|
||||
cb.setAuthor(fb);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
|
||||
public class WriterItemStackMetaBannerBase extends WriterAbstractItemStackMetaField<BannerMeta, Integer, DyeColor>
|
||||
@ -24,25 +25,25 @@ public class WriterItemStackMetaBannerBase extends WriterAbstractItemStackMetaFi
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca)
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getBannerBase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa)
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setBannerBase(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeColor getB(BannerMeta cb)
|
||||
public DyeColor getB(BannerMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getBaseColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(BannerMeta cb, DyeColor fb)
|
||||
public void setB(BannerMeta cb, DyeColor fb, ItemStack d)
|
||||
{
|
||||
cb.setBaseColor(fb);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
|
||||
public class WriterItemStackMetaBannerPatterns extends WriterAbstractItemStackMetaField<BannerMeta, List<DataBannerPattern>, List<Pattern>>
|
||||
@ -28,25 +29,25 @@ public class WriterItemStackMetaBannerPatterns extends WriterAbstractItemStackMe
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<DataBannerPattern> getA(DataItemStack ca)
|
||||
public List<DataBannerPattern> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getBannerPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, List<DataBannerPattern> fa)
|
||||
public void setA(DataItemStack ca, List<DataBannerPattern> fa, ItemStack d)
|
||||
{
|
||||
ca.setBannerPatterns(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pattern> getB(BannerMeta cb)
|
||||
public List<Pattern> getB(BannerMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(BannerMeta cb, List<Pattern> fb)
|
||||
public void setB(BannerMeta cb, List<Pattern> fb, ItemStack d)
|
||||
{
|
||||
cb.setPatterns(fb);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
public class WriterItemStackMetaColor extends WriterAbstractItemStackMetaField<LeatherArmorMeta, Integer, Color>
|
||||
@ -23,25 +24,25 @@ public class WriterItemStackMetaColor extends WriterAbstractItemStackMetaField<L
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca)
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa)
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setColor(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getB(LeatherArmorMeta cb)
|
||||
public Color getB(LeatherArmorMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(LeatherArmorMeta cb, Color fb)
|
||||
public void setB(LeatherArmorMeta cb, Color fb, ItemStack d)
|
||||
{
|
||||
cb.setColor(fb);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class WriterItemStackMetaEnchants extends WriterAbstractItemStackMetaField<ItemMeta, Map<Integer, Integer>, Map<Enchantment, Integer>>
|
||||
@ -25,25 +26,25 @@ public class WriterItemStackMetaEnchants extends WriterAbstractItemStackMetaFiel
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Map<Integer, Integer> getA(DataItemStack ca)
|
||||
public Map<Integer, Integer> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getEnchants();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Map<Integer, Integer> fa)
|
||||
public void setA(DataItemStack ca, Map<Integer, Integer> fa, ItemStack d)
|
||||
{
|
||||
ca.setEnchants(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getB(ItemMeta cb)
|
||||
public Map<Enchantment, Integer> getB(ItemMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getEnchants();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemMeta cb, Map<Enchantment, Integer> fb)
|
||||
public void setB(ItemMeta cb, Map<Enchantment, Integer> fb, ItemStack d)
|
||||
{
|
||||
for (Entry<Enchantment, Integer> entry : fb.entrySet())
|
||||
{
|
||||
|
@ -2,6 +2,7 @@ package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.FireworkEffectMeta;
|
||||
|
||||
public class WriterItemStackMetaFireworkEffect extends WriterAbstractItemStackMetaField<FireworkEffectMeta, DataFireworkEffect, FireworkEffect>
|
||||
@ -26,25 +27,25 @@ public class WriterItemStackMetaFireworkEffect extends WriterAbstractItemStackMe
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public DataFireworkEffect getA(DataItemStack ca)
|
||||
public DataFireworkEffect getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getFireworkEffect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, DataFireworkEffect fa)
|
||||
public void setA(DataItemStack ca, DataFireworkEffect fa, ItemStack d)
|
||||
{
|
||||
ca.setFireworkEffect(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FireworkEffect getB(FireworkEffectMeta cb)
|
||||
public FireworkEffect getB(FireworkEffectMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getEffect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(FireworkEffectMeta cb, FireworkEffect fb)
|
||||
public void setB(FireworkEffectMeta cb, FireworkEffect fb, ItemStack d)
|
||||
{
|
||||
cb.setEffect(fb);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
|
||||
public class WriterItemStackMetaFireworkEffects extends WriterAbstractItemStackMetaField<FireworkMeta, List<DataFireworkEffect>, List<FireworkEffect>>
|
||||
@ -28,25 +29,25 @@ public class WriterItemStackMetaFireworkEffects extends WriterAbstractItemStackM
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<DataFireworkEffect> getA(DataItemStack ca)
|
||||
public List<DataFireworkEffect> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getFireworkEffects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, List<DataFireworkEffect> fa)
|
||||
public void setA(DataItemStack ca, List<DataFireworkEffect> fa, ItemStack d)
|
||||
{
|
||||
ca.setFireworkEffects(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FireworkEffect> getB(FireworkMeta cb)
|
||||
public List<FireworkEffect> getB(FireworkMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getEffects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(FireworkMeta cb, List<FireworkEffect> fb)
|
||||
public void setB(FireworkMeta cb, List<FireworkEffect> fb, ItemStack d)
|
||||
{
|
||||
cb.addEffects(fb);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
|
||||
public class WriterItemStackMetaFireworkFlight extends WriterAbstractItemStackMetaField<FireworkMeta, Integer, Integer>
|
||||
@ -20,25 +21,25 @@ public class WriterItemStackMetaFireworkFlight extends WriterAbstractItemStackMe
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca)
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getFireworkFlight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa)
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setFireworkFlight(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getB(FireworkMeta cb)
|
||||
public Integer getB(FireworkMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getPower();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(FireworkMeta cb, Integer fb)
|
||||
public void setB(FireworkMeta cb, Integer fb, ItemStack d)
|
||||
{
|
||||
cb.setPower(fb);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class WriterItemStackMetaFlags extends WriterAbstractItemStackMetaField<ItemMeta, Set<String>, Set<ItemFlag>>
|
||||
@ -24,25 +25,25 @@ public class WriterItemStackMetaFlags extends WriterAbstractItemStackMetaField<I
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Set<String> getA(DataItemStack ca)
|
||||
public Set<String> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Set<String> fa)
|
||||
public void setA(DataItemStack ca, Set<String> fa, ItemStack d)
|
||||
{
|
||||
ca.setFlags(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ItemFlag> getB(ItemMeta cb)
|
||||
public Set<ItemFlag> getB(ItemMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getItemFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemMeta cb, Set<ItemFlag> fb)
|
||||
public void setB(ItemMeta cb, Set<ItemFlag> fb, ItemStack d)
|
||||
{
|
||||
cb.addItemFlags(fb.toArray(new ItemFlag[0]));
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.massivecraft.massivecore.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class WriterItemStackMetaLore extends WriterAbstractItemStackMetaField<ItemMeta, List<String>, List<String>>
|
||||
@ -18,25 +19,25 @@ public class WriterItemStackMetaLore extends WriterAbstractItemStackMetaField<It
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<String> getA(DataItemStack ca)
|
||||
public List<String> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getLore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, List<String> fa)
|
||||
public void setA(DataItemStack ca, List<String> fa, ItemStack d)
|
||||
{
|
||||
ca.setLore(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getB(ItemMeta cb)
|
||||
public List<String> getB(ItemMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getLore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemMeta cb, List<String> fb)
|
||||
public void setB(ItemMeta cb, List<String> fb, ItemStack d)
|
||||
{
|
||||
cb.setLore(fb);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class WriterItemStackMetaName extends WriterAbstractItemStackMetaField<ItemMeta, String, String>
|
||||
@ -16,25 +17,25 @@ public class WriterItemStackMetaName extends WriterAbstractItemStackMetaField<It
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataItemStack ca)
|
||||
public String getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, String fa)
|
||||
public void setA(DataItemStack ca, String fa, ItemStack d)
|
||||
{
|
||||
ca.setName(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getB(ItemMeta cb)
|
||||
public String getB(ItemMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemMeta cb, String fb)
|
||||
public void setB(ItemMeta cb, String fb, ItemStack d)
|
||||
{
|
||||
cb.setDisplayName(fb);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
public class WriterItemStackMetaPages extends WriterAbstractItemStackMetaField<BookMeta, List<String>, List<String>>
|
||||
@ -22,25 +23,25 @@ public class WriterItemStackMetaPages extends WriterAbstractItemStackMetaField<B
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<String> getA(DataItemStack ca)
|
||||
public List<String> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getPages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, List<String> fa)
|
||||
public void setA(DataItemStack ca, List<String> fa, ItemStack d)
|
||||
{
|
||||
ca.setPages(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getB(BookMeta cb)
|
||||
public List<String> getB(BookMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getPages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(BookMeta cb, List<String> fb)
|
||||
public void setB(BookMeta cb, List<String> fb, ItemStack d)
|
||||
{
|
||||
cb.setPages(fb);
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionData;
|
||||
|
||||
public class WriterItemStackMetaPotion extends WriterAbstractItemStackMetaField<PotionMeta, Object, Object>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final WriterItemStackMetaPotion i = new WriterItemStackMetaPotion();
|
||||
public static WriterItemStackMetaPotion get() { return i; }
|
||||
{
|
||||
this.setMaterial(Material.POTION);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE
|
||||
// -------------------------------------------- //
|
||||
// Due to the complexity of the upgrade mechanic we override writeInner.
|
||||
//
|
||||
// There are two interesting data points.
|
||||
// 1. The old item damage.
|
||||
// 2. The new item potion.
|
||||
// These two data points exists in both our implementation and in Bukkit.
|
||||
//
|
||||
// Serialization is simple.
|
||||
// We just assume everything is properly upgraded and save accordingly.
|
||||
//
|
||||
// The hard part is deserialization (writing to Bukkit).
|
||||
//
|
||||
// In Minecraft 1.8 the damage value was used to store the potion effects.
|
||||
// In Minecraft 1.9 the damage value is no longer used and the potion effect is stored by string instead.
|
||||
//
|
||||
// Sticking to the damage value for serialization is not feasible.
|
||||
// Minecraft 1.9 adds new potion effects that did not exist in Minecraft 1.8 such as LUCK.
|
||||
//
|
||||
// Thus we upgrade the database from damage values to the new potion string where possible.
|
||||
// Invalid old damage values that does not make any sense are left as is.
|
||||
//
|
||||
// TODO: As Ulumulu1510 indicated the material must be changed for throwable/splash potions.
|
||||
// TODO: That must be implemented for a 100% proper upgrading experience.
|
||||
|
||||
@Override
|
||||
public void writeInner(DataItemStack oa, ItemMeta ob, DataItemStack ca, PotionMeta cb, ItemStack d, boolean a2b)
|
||||
{
|
||||
if (a2b)
|
||||
{
|
||||
// DESERIALIZE
|
||||
|
||||
// Create
|
||||
PotionData potionData = null;
|
||||
|
||||
// Fill > Old
|
||||
int damage = ca.getDamage();
|
||||
if (damage != DataItemStack.DEFAULT_DAMAGE)
|
||||
{
|
||||
potionData = PotionUtil.toPotionData(damage);
|
||||
if (potionData != null)
|
||||
{
|
||||
d.setDurability((short)0);
|
||||
}
|
||||
}
|
||||
|
||||
// Fill > New / Default
|
||||
if (potionData == null)
|
||||
{
|
||||
String potionString = ca.getPotion();
|
||||
potionData = PotionUtil.toPotionData(potionString);
|
||||
}
|
||||
|
||||
// Set
|
||||
cb.setBasePotionData(potionData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// SERIALIZE
|
||||
PotionData potionData = cb.getBasePotionData();
|
||||
String potionString = PotionUtil.toPotionString(potionData);
|
||||
ca.setPotion(potionString);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
@ -28,25 +29,25 @@ public class WriterItemStackMetaPotionEffects extends WriterAbstractItemStackMet
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<DataPotionEffect> getA(DataItemStack ca)
|
||||
public List<DataPotionEffect> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getPotionEffects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, List<DataPotionEffect> fa)
|
||||
public void setA(DataItemStack ca, List<DataPotionEffect> fa, ItemStack d)
|
||||
{
|
||||
ca.setPotionEffects(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PotionEffect> getB(PotionMeta cb)
|
||||
public List<PotionEffect> getB(PotionMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getCustomEffects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(PotionMeta cb, List<PotionEffect> fb)
|
||||
public void setB(PotionMeta cb, List<PotionEffect> fb, ItemStack d)
|
||||
{
|
||||
for (PotionEffect potionEffect : fb)
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Repairable;
|
||||
|
||||
public class WriterItemStackMetaRepaircost extends WriterAbstractItemStackMetaField<Repairable, Integer, Integer>
|
||||
@ -20,25 +21,25 @@ public class WriterItemStackMetaRepaircost extends WriterAbstractItemStackMetaFi
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca)
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getRepaircost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa)
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setRepaircost(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getB(Repairable cb)
|
||||
public Integer getB(Repairable cb, ItemStack d)
|
||||
{
|
||||
return cb.getRepairCost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(Repairable cb, Integer fb)
|
||||
public void setB(Repairable cb, Integer fb, ItemStack d)
|
||||
{
|
||||
cb.setRepairCost(fb);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.MapMeta;
|
||||
|
||||
public class WriterItemStackMetaScaling extends WriterAbstractItemStackMetaField<MapMeta, Boolean, Boolean>
|
||||
@ -20,25 +21,25 @@ public class WriterItemStackMetaScaling extends WriterAbstractItemStackMetaField
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Boolean getA(DataItemStack ca)
|
||||
public Boolean getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.isScaling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Boolean fa)
|
||||
public void setA(DataItemStack ca, Boolean fa, ItemStack d)
|
||||
{
|
||||
ca.setScaling(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getB(MapMeta cb)
|
||||
public Boolean getB(MapMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.isScaling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(MapMeta cb, Boolean fb)
|
||||
public void setB(MapMeta cb, Boolean fb, ItemStack d)
|
||||
{
|
||||
cb.setScaling(fb);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class WriterItemStackMetaSkull17 extends WriterAbstractItemStackMetaField<SkullMeta, String, String>
|
||||
@ -21,25 +22,25 @@ public class WriterItemStackMetaSkull17 extends WriterAbstractItemStackMetaField
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataItemStack ca)
|
||||
public String getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getSkull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, String fa)
|
||||
public void setA(DataItemStack ca, String fa, ItemStack d)
|
||||
{
|
||||
ca.setSkull(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getB(SkullMeta cb)
|
||||
public String getB(SkullMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(SkullMeta cb, String fb)
|
||||
public void setB(SkullMeta cb, String fb, ItemStack d)
|
||||
{
|
||||
cb.setOwner(fb);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import com.massivecraft.massivecore.Couple;
|
||||
@ -26,26 +27,26 @@ public class WriterItemStackMetaSkull18 extends WriterAbstractItemStackMetaField
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataItemStack ca)
|
||||
public String getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getSkull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, String fa)
|
||||
public void setA(DataItemStack ca, String fa, ItemStack d)
|
||||
{
|
||||
if (fa != null) fa = fa.toLowerCase();
|
||||
ca.setSkull(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getB(SkullMeta cb)
|
||||
public String getB(SkullMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(SkullMeta cb, String fb)
|
||||
public void setB(SkullMeta cb, String fb, ItemStack d)
|
||||
{
|
||||
String name = fb;
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class WriterItemStackMetaStateShieldBase extends WriterAbstractItemStackMetaStateField<Banner, Integer, DyeColor>
|
||||
{
|
||||
@ -24,25 +25,25 @@ public class WriterItemStackMetaStateShieldBase extends WriterAbstractItemStackM
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataItemStack ca)
|
||||
public Integer getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getBannerBase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Integer fa)
|
||||
public void setA(DataItemStack ca, Integer fa, ItemStack d)
|
||||
{
|
||||
ca.setBannerBase(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeColor getB(Banner cb)
|
||||
public DyeColor getB(Banner cb, ItemStack d)
|
||||
{
|
||||
return cb.getBaseColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(Banner cb, DyeColor fb)
|
||||
public void setB(Banner cb, DyeColor fb, ItemStack d)
|
||||
{
|
||||
cb.setBaseColor(fb);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class WriterItemStackMetaStateShieldPatterns extends WriterAbstractItemStackMetaStateField<Banner, List<DataBannerPattern>, List<Pattern>>
|
||||
{
|
||||
@ -28,25 +29,25 @@ public class WriterItemStackMetaStateShieldPatterns extends WriterAbstractItemSt
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public List<DataBannerPattern> getA(DataItemStack ca)
|
||||
public List<DataBannerPattern> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getBannerPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, List<DataBannerPattern> fa)
|
||||
public void setA(DataItemStack ca, List<DataBannerPattern> fa, ItemStack d)
|
||||
{
|
||||
ca.setBannerPatterns(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pattern> getB(Banner cb)
|
||||
public List<Pattern> getB(Banner cb, ItemStack d)
|
||||
{
|
||||
return cb.getPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(Banner cb, List<Pattern> fb)
|
||||
public void setB(Banner cb, List<Pattern> fb, ItemStack d)
|
||||
{
|
||||
cb.setPatterns(fb);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
|
||||
public class WriterItemStackMetaStoredEnchants extends WriterAbstractItemStackMetaField<EnchantmentStorageMeta, Map<Integer, Integer>, Map<Enchantment, Integer>>
|
||||
@ -27,25 +28,25 @@ public class WriterItemStackMetaStoredEnchants extends WriterAbstractItemStackMe
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Map<Integer, Integer> getA(DataItemStack ca)
|
||||
public Map<Integer, Integer> getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getStoredEnchants();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Map<Integer, Integer> fa)
|
||||
public void setA(DataItemStack ca, Map<Integer, Integer> fa, ItemStack d)
|
||||
{
|
||||
ca.setStoredEnchants(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getB(EnchantmentStorageMeta cb)
|
||||
public Map<Enchantment, Integer> getB(EnchantmentStorageMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getStoredEnchants();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(EnchantmentStorageMeta cb, Map<Enchantment, Integer> fb)
|
||||
public void setB(EnchantmentStorageMeta cb, Map<Enchantment, Integer> fb, ItemStack d)
|
||||
{
|
||||
for (Entry<Enchantment, Integer> entry : fb.entrySet())
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
public class WriterItemStackMetaTitle extends WriterAbstractItemStackMetaField<BookMeta, String, String>
|
||||
@ -20,25 +21,25 @@ public class WriterItemStackMetaTitle extends WriterAbstractItemStackMetaField<B
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String getA(DataItemStack ca)
|
||||
public String getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.getTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, String fa)
|
||||
public void setA(DataItemStack ca, String fa, ItemStack d)
|
||||
{
|
||||
ca.setTitle(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getB(BookMeta cb)
|
||||
public String getB(BookMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.getTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(BookMeta cb, String fb)
|
||||
public void setB(BookMeta cb, String fb, ItemStack d)
|
||||
{
|
||||
cb.setTitle(fb);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class WriterItemStackMetaUnbreakable extends WriterAbstractItemStackMetaField<ItemMeta, Boolean, Boolean>
|
||||
@ -16,25 +17,25 @@ public class WriterItemStackMetaUnbreakable extends WriterAbstractItemStackMetaF
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Boolean getA(DataItemStack ca)
|
||||
public Boolean getA(DataItemStack ca, ItemStack d)
|
||||
{
|
||||
return ca.isUnbreakable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataItemStack ca, Boolean fa)
|
||||
public void setA(DataItemStack ca, Boolean fa, ItemStack d)
|
||||
{
|
||||
ca.setUnbreakable(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getB(ItemMeta cb)
|
||||
public Boolean getB(ItemMeta cb, ItemStack d)
|
||||
{
|
||||
return cb.spigot().isUnbreakable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setB(ItemMeta cb, Boolean fb)
|
||||
public void setB(ItemMeta cb, Boolean fb, ItemStack d)
|
||||
{
|
||||
cb.spigot().setUnbreakable(fb);
|
||||
}
|
||||
|
@ -20,19 +20,19 @@ public class WriterPotionEffectAmbient extends WriterAbstractPotionEffect<Boolea
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Boolean getA(DataPotionEffect ca)
|
||||
public Boolean getA(DataPotionEffect ca, Object d)
|
||||
{
|
||||
return ca.isAmbient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataPotionEffect ca, Boolean fa)
|
||||
public void setA(DataPotionEffect ca, Boolean fa, Object d)
|
||||
{
|
||||
ca.setAmbient(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getB(PotionEffect cb)
|
||||
public Boolean getB(PotionEffect cb, Object d)
|
||||
{
|
||||
return cb.isAmbient();
|
||||
}
|
||||
|
@ -20,19 +20,19 @@ public class WriterPotionEffectAmplifier extends WriterAbstractPotionEffect<Inte
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataPotionEffect ca)
|
||||
public Integer getA(DataPotionEffect ca, Object d)
|
||||
{
|
||||
return ca.getAmplifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataPotionEffect ca, Integer fa)
|
||||
public void setA(DataPotionEffect ca, Integer fa, Object d)
|
||||
{
|
||||
ca.setAmplifier(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getB(PotionEffect cb)
|
||||
public Integer getB(PotionEffect cb, Object d)
|
||||
{
|
||||
return cb.getAmplifier();
|
||||
}
|
||||
|
@ -23,19 +23,19 @@ public class WriterPotionEffectColor extends WriterAbstractPotionEffect<Integer,
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataPotionEffect ca)
|
||||
public Integer getA(DataPotionEffect ca, Object d)
|
||||
{
|
||||
return ca.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataPotionEffect ca, Integer fa)
|
||||
public void setA(DataPotionEffect ca, Integer fa, Object d)
|
||||
{
|
||||
ca.setColor(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getB(PotionEffect cb)
|
||||
public Color getB(PotionEffect cb, Object d)
|
||||
{
|
||||
return cb.getColor();
|
||||
}
|
||||
|
@ -20,19 +20,19 @@ public class WriterPotionEffectDuraction extends WriterAbstractPotionEffect<Inte
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataPotionEffect ca)
|
||||
public Integer getA(DataPotionEffect ca, Object d)
|
||||
{
|
||||
return ca.getDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataPotionEffect ca, Integer fa)
|
||||
public void setA(DataPotionEffect ca, Integer fa, Object d)
|
||||
{
|
||||
ca.setDuration(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getB(PotionEffect cb)
|
||||
public Integer getB(PotionEffect cb, Object d)
|
||||
{
|
||||
return cb.getDuration();
|
||||
}
|
||||
|
@ -23,19 +23,19 @@ public class WriterPotionEffectId extends WriterAbstractPotionEffect<Integer, Po
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Integer getA(DataPotionEffect ca)
|
||||
public Integer getA(DataPotionEffect ca, Object d)
|
||||
{
|
||||
return ca.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataPotionEffect ca, Integer fa)
|
||||
public void setA(DataPotionEffect ca, Integer fa, Object d)
|
||||
{
|
||||
ca.setId(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionEffectType getB(PotionEffect cb)
|
||||
public PotionEffectType getB(PotionEffect cb, Object d)
|
||||
{
|
||||
return cb.getType();
|
||||
}
|
||||
|
@ -20,19 +20,19 @@ public class WriterPotionEffectParticles extends WriterAbstractPotionEffect<Bool
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Boolean getA(DataPotionEffect ca)
|
||||
public Boolean getA(DataPotionEffect ca, Object d)
|
||||
{
|
||||
return ca.isParticles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setA(DataPotionEffect ca, Boolean fa)
|
||||
public void setA(DataPotionEffect ca, Boolean fa, Object d)
|
||||
{
|
||||
ca.setParticles(fa);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getB(PotionEffect cb)
|
||||
public Boolean getB(PotionEffect cb, Object d)
|
||||
{
|
||||
return cb.hasParticles();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user