Possibly Fully Functional :O

This commit is contained in:
Olof Larsson 2016-04-25 14:50:57 +02:00
parent a0bcc5ae8d
commit 4c1907ba07
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474
65 changed files with 591 additions and 1874 deletions

View File

@ -153,6 +153,18 @@ public class MassiveCore extends MassivePlugin
// Enumeration Annotation Dodge // Enumeration Annotation Dodge
ret.registerTypeAdapterFactory(AdapterModdedEnumType.ENUM_FACTORY); 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?) // Entries (Is this still needed?)
ret.registerTypeAdapter(Entry.class, AdapterEntry.get()); ret.registerTypeAdapter(Entry.class, AdapterEntry.get());
@ -166,6 +178,11 @@ public class MassiveCore extends MassivePlugin
ret.registerTypeAdapter(Mson.class, AdapterMson.get()); ret.registerTypeAdapter(Mson.class, AdapterMson.get());
ret.registerTypeAdapter(MsonEvent.class, AdapterMsonEvent.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 // ItemStack
ret.registerTypeAdapter(ItemStack.class, AdapterItemStack.get()); ret.registerTypeAdapter(ItemStack.class, AdapterItemStack.get());
Class<?> classCraftItemStack = NmsItemStack.get().classCraftItemStack; Class<?> classCraftItemStack = NmsItemStack.get().classCraftItemStack;
@ -175,22 +192,6 @@ public class MassiveCore extends MassivePlugin
ret.registerTypeAdapter(Inventory.class, AdapterInventory.get()); ret.registerTypeAdapter(Inventory.class, AdapterInventory.get());
ret.registerTypeAdapter(PlayerInventory.class, AdapterPlayerInventory.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
return ret; return ret;
} }

View File

@ -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;
}
}

View File

@ -2,6 +2,8 @@ package com.massivecraft.massivecore.adapter;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.massivecraft.massivecore.item.DataItemStack;
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext; import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer; import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
import com.massivecraft.massivecore.xlib.gson.JsonElement; import com.massivecraft.massivecore.xlib.gson.JsonElement;
@ -26,59 +28,21 @@ public class AdapterItemStack implements JsonDeserializer<ItemStack>, JsonSerial
public static AdapterItemStack get() { return i; } public static AdapterItemStack get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // OVERRIDE
// -------------------------------------------- //
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) public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context)
{ {
return this.getInner().erialize(src); DataItemStack dataItemStack = new DataItemStack(src);
return context.serialize(dataItemStack);
} }
@Override @Override
public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException 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();
} }
} }

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -60,7 +60,7 @@ public class DataBannerPattern implements Comparable<DataBannerPattern>
public Pattern toBukkit() public Pattern toBukkit()
{ {
// Create // Create
Pattern ret = WriterBannerPattern.get().createB(); Pattern ret = WriterBannerPattern.get().createOB();
// Fill // Fill
this.write(ret, true); this.write(ret, true);

View File

@ -84,7 +84,7 @@ public class DataFireworkEffect implements Comparable<DataFireworkEffect>
public FireworkEffect toBukkit() public FireworkEffect toBukkit()
{ {
// Create // Create
FireworkEffect ret = WriterFireworkEffect.get().createB(); FireworkEffect ret = WriterFireworkEffect.get().createOB();
// Fill // Fill
this.write(ret, true); this.write(ret, true);

View File

@ -271,7 +271,7 @@ public class DataItemStack implements Comparable<DataItemStack>
public ItemStack toBukkit() public ItemStack toBukkit()
{ {
// Create // Create
ItemStack ret = WriterItemStack.get().createB(); ItemStack ret = WriterItemStack.get().createOB();
// Fill // Fill
this.write(ret, true); this.write(ret, true);

View File

@ -83,7 +83,7 @@ public class DataPotionEffect implements Comparable<DataPotionEffect>
public PotionEffect toBukkit() public PotionEffect toBukkit()
{ {
// Create // Create
PotionEffect ret = WriterPotionEffect.get().createB(); PotionEffect ret = WriterPotionEffect.get().createOB();
// Fill // Fill
this.write(ret, true); this.write(ret, true);

View 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();
}

View File

@ -11,7 +11,18 @@ import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.ReflectionUtil; import com.massivecraft.massivecore.util.ReflectionUtil;
import com.massivecraft.massivecore.util.Txt; 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 // WRITERS
@ -19,10 +30,9 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
// Writer have dependencies and child writers. // Writer have dependencies and child writers.
// A dependency is another writer that must be successfully activated for this writer to function. // 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. // Examples would be WriterPotionEffect and WriterFireworkEffect.
// They are implicitly required for some ItemStack field writers. // They are implicitly required for some ItemStack field writers.
private List<Class<?>> dependencyClasses = new MassiveList<>(); private List<Class<?>> dependencyClasses = new MassiveList<>();
public List<Class<?>> getDependencyClasses() { return this.dependencyClasses; } public List<Class<?>> getDependencyClasses() { return this.dependencyClasses; }
public void addDependencyClasses(Class<?>... dependencyClasses) { this.getDependencyClasses().addAll(Arrays.asList(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)); } public void addWriterClasses(Class<?>... writerClasses) { this.getWriterClasses().addAll(Arrays.asList(writerClasses)); }
// These are the actually functional child writers. // These are the actually functional child writers.
// This list should only contain writers that passed the provoke routine. // This list should only contain writers that passed the setup routine.
private List<WriterAbstract<CA, CB, ?, ?, ?, ?>> writers = new MassiveList<>(); private List<WriterAbstract<CA, CB, ?, ?, ?, ?, D>> writers = new MassiveList<>();
public List<WriterAbstract<CA, CB, ?, ?, ?, ?>> getWriters() { return this.writers; } public List<WriterAbstract<CA, CB, ?, ?, ?, ?, D>> getWriters() { return this.writers; }
// Here is the logic to perform the dependency and child writer setup. // Here is the logic to perform the dependency and child writer setup.
public void setupDependencies() public void setupDependencies()
@ -61,12 +71,12 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
{ {
try try
{ {
Class<WriterAbstract<?, ?, ?, ?, ?, ?>> writerClassInner = (Class<WriterAbstract<?, ?, ?, ?, ?, ?>>) writerClass; Class<WriterAbstract<?, ?, ?, ?, ?, ?, ?>> writerClassInner = (Class<WriterAbstract<?, ?, ?, ?, ?, ?, ?>>) writerClass;
WriterAbstract<?, ?, ?, ?, ?, ?> writer = ReflectionUtil.getSingletonInstance(writerClassInner); WriterAbstract<?, ?, ?, ?, ?, ?, ?> writer = ReflectionUtil.getSingletonInstance(writerClassInner);
if ( ! writer.isActive()) writer.setActive(this.getActivePlugin()); 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) catch (Throwable t)
{ {
@ -120,17 +130,14 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
// -------------------------------------------- // // -------------------------------------------- //
// ACTIVE // 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 @Override
public void setActive(boolean active) public void setActive(boolean active)
{ {
if (active) if (active)
{ {
// Provoke // Setup Self
this.provoke(); this.setupSelf();
// Setup Dependencies // Setup Dependencies
this.setupDependencies(); this.setupDependencies();
@ -141,6 +148,7 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
// Setup Writers // Setup Writers
this.setupWriters(); this.setupWriters();
} }
super.setActive(active); super.setActive(active);
} }
@ -148,87 +156,91 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB> extends Engine
// CREATE // CREATE
// -------------------------------------------- // // -------------------------------------------- //
public abstract CA createA(); public OA createOA()
{
public abstract CB createB(); return null;
}
public OB createOB()
{
return null;
}
// -------------------------------------------- // // -------------------------------------------- //
// CLASSES // 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() private Class<?> classOB = null;
{ public Class<?> getClassOB() { return this.classOB; }
return this.classA; 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) private Class<?> classCB = null;
{ public Class<?> getClassCB() { return this.classCB; }
this.classA = classA; public void setClassCB(Class<?> classCB) { this.classCB = classCB; }
}
private Class<CB> classB = null;
public Class<CB> getClassB()
{
return this.classB;
}
public void setClassB(Class<CB> classB)
{
this.classB = classB;
}
// -------------------------------------------- // // -------------------------------------------- //
// MORPH // 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") @SuppressWarnings("unchecked")
public CA morphA(OA oa) public CA morphA(OA oa)
{ {
Class<CA> classA = this.getClassA(); if (this.getClassCA() != null && ! this.getClassCA().isAssignableFrom(oa.getClass())) return null;
if (classA != null && !classA.isAssignableFrom(oa.getClass())) return null; return (CA)oa;
CA ca = (CA) oa;
return ca;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CB morphB(OB ob) public CB morphB(OB ob)
{ {
Class<CB> classB = this.getClassB(); if (this.getClassCB() != null && ! this.getClassCB().isAssignableFrom(ob.getClass())) return null;
if (classB != null && !classB.isAssignableFrom(ob.getClass())) return null; return (CB)ob;
CB cb = (CB) ob;
return cb;
} }
// -------------------------------------------- // // -------------------------------------------- //
// PROVOKE // SETUP
// -------------------------------------------- // // -------------------------------------------- //
public Object provoke() public void setupSelf()
{ {
// Create Instances // Create O
CA ia = this.createA(); OA oa = this.createOA();
CB ib = this.createB(); OB ob = this.createOB();
// Demand Set // Demand O
if (ia == null) throw new NullPointerException("Couldn't Create A"); if (oa == null) throw new NullPointerException("Couldn't Create OA");
if (ib == null) throw new NullPointerException("Couldn't Create B"); if (ob == null) throw new NullPointerException("Couldn't Create OB");
// Use Access // Class O
FA fa = this.getA(ia); this.setClassOA(oa.getClass());
this.setA(ia, fa); this.setClassOB(ob.getClass());
FB fb = this.getB(ib); // Morph
this.setB(ib, fb); CA ca = this.morphA(oa);
CB cb = this.morphB(ob);
// Use To
this.toA(fb); // Demand C
this.toB(fa); if (ca == null) throw new NullPointerException("Couldn't Create CA");
if (cb == null) throw new NullPointerException("Couldn't Create CB");
// Return
return null; // 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) 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 (oa == null) throw new NullPointerException("oa");
if (ob == null) throw new NullPointerException("ob"); if (ob == null) throw new NullPointerException("ob");
CA ca = this.morphA(oa); CA ca = this.morphA(oa);
if (ca == null) return; if (ca == null) return;
CB cb = this.morphB(ob); CB cb = this.morphB(ob);
if (cb == null) return; 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) if (a2b)
{ {
FA fa = getA(ca); FA fa = getA(ca, d);
FB fb = toB(fa); FB fb = toB(fa);
setB(cb, fb); setB(cb, fb, d);
} }
else else
{ {
FB fb = getB(cb); FB fb = getB(cb, d);
FA fa = toA(fb); 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 // ACCESS
// -------------------------------------------- // // -------------------------------------------- //
public FA getA(CA ca) public FA getA(CA ca, D d)
{ {
return null; 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; return null;
} }
public void setB(CB cb, FB fb) public void setB(CB cb, FB fb, D d)
{ {
} }

View File

@ -26,13 +26,13 @@ public abstract class WriterAbstractBannerPattern<FA, FB> extends WriterAbstract
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public DataBannerPattern createA() public DataBannerPattern createOA()
{ {
return new DataBannerPattern(); return new DataBannerPattern();
} }
@Override @Override
public Pattern createB() public Pattern createOB()
{ {
return new Pattern(DyeColor.WHITE, PatternType.BASE); return new Pattern(DyeColor.WHITE, PatternType.BASE);
} }

View File

@ -25,13 +25,13 @@ public abstract class WriterAbstractFireworkEffect<FA, FB> extends WriterAbstrac
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public DataFireworkEffect createA() public DataFireworkEffect createOA()
{ {
return new DataFireworkEffect(); return new DataFireworkEffect();
} }
@Override @Override
public FireworkEffect createB() public FireworkEffect createOB()
{ {
return FireworkEffect.builder().withColor(Color.GREEN).build(); return FireworkEffect.builder().withColor(Color.GREEN).build();
} }

View File

@ -1,24 +1,60 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import com.massivecraft.massivecore.nms.NmsItemStack; 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 // CREATE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public DataItemStack createA() public DataItemStack createOA()
{ {
return new DataItemStack(); return new DataItemStack();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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);
} }
} }

View File

@ -1,35 +1,22 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; 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> public abstract class WriterAbstractItemStackMeta<OB, CB, FA, FB> extends WriterAbstractItemStack<OB, CB, FA, FB>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // CREATE INNER
// -------------------------------------------- // // -------------------------------------------- //
private Material material = Material.STONE; public ItemMeta createItemMeta()
public Material getMaterial() { return this.material; }
@SuppressWarnings("unchecked")
public void setMaterial(Material material)
{ {
this.material = material; return createItemMeta(this.createItemStack());
CB cb = this.createB();
this.setClassB((Class<CB>) cb.getClass());
} }
// -------------------------------------------- // public static ItemMeta createItemMeta(ItemStack itemStack)
// CREATE
// -------------------------------------------- //
@SuppressWarnings("unchecked")
@Override
public CB createB()
{ {
ItemStack itemStack = (ItemStack) super.createB(); return itemStack.getItemMeta();
itemStack.setType(this.getMaterial());
return (CB) itemStack.getItemMeta();
} }
} }

View File

@ -2,7 +2,16 @@ package com.massivecraft.massivecore.item;
import org.bukkit.inventory.meta.ItemMeta; 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();
}
} }

View File

@ -12,7 +12,7 @@ public abstract class WriterAbstractItemStackMetaMorph<FA, FB> extends WriterAbs
@Override @Override
public ItemMeta morphB(ItemStack ob) public ItemMeta morphB(ItemStack ob)
{ {
return ob.getItemMeta(); return createItemMeta(ob);
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -20,9 +20,9 @@ public abstract class WriterAbstractItemStackMetaMorph<FA, FB> extends WriterAbs
// -------------------------------------------- // // -------------------------------------------- //
@Override @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 // Write Back
if (a2b) ob.setItemMeta(cb); if (a2b) ob.setItemMeta(cb);

View File

@ -1,7 +1,9 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.meta.BlockStateMeta; 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> 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() 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); this.setMaterial(Material.SHIELD);
} }
// -------------------------------------------- // // -------------------------------------------- //
// CREATE // CREATE INNER
// -------------------------------------------- // // -------------------------------------------- //
@SuppressWarnings("unchecked") public BlockState createItemMetaState()
@Override
public CB createB()
{ {
BlockStateMeta blockStateMeta = (BlockStateMeta) super.createB(); return createItemMetaState(this.createItemMeta());
return (CB) blockStateMeta.getBlockState(); }
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;
}
} }
} }

View File

@ -4,5 +4,14 @@ import org.bukkit.block.BlockState;
public abstract class WriterAbstractItemStackMetaStateField<S, FA, FB> extends WriterAbstractItemStackMetaState<BlockState, S, FA, FB> public abstract class WriterAbstractItemStackMetaStateField<S, FA, FB> extends WriterAbstractItemStackMetaState<BlockState, S, FA, FB>
{ {
// -------------------------------------------- //
// CREATE
// -------------------------------------------- //
@Override
public BlockState createOB()
{
return this.createItemMetaState();
}
} }

View File

@ -1,11 +1,22 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
public abstract class WriterAbstractItemStackMetaStateMorph<FA, FB> extends WriterAbstractItemStackMetaState<ItemMeta, BlockState, FA, FB> public abstract class WriterAbstractItemStackMetaStateMorph<FA, FB> extends WriterAbstractItemStackMetaState<ItemMeta, BlockState, FA, FB>
{ {
// -------------------------------------------- //
// CREATE
// -------------------------------------------- //
@Override
public ItemMeta createOB()
{
return this.createItemMeta();
}
// -------------------------------------------- // // -------------------------------------------- //
// MORPH // MORPH
// -------------------------------------------- // // -------------------------------------------- //
@ -13,18 +24,17 @@ public abstract class WriterAbstractItemStackMetaStateMorph<FA, FB> extends Writ
@Override @Override
public BlockState morphB(ItemMeta ob) public BlockState morphB(ItemMeta ob)
{ {
BlockStateMeta state = (BlockStateMeta)ob; return createItemMetaState(ob);
return state.getBlockState();
} }
// -------------------------------------------- // // -------------------------------------------- //
// WRITE // WRITE
// -------------------------------------------- // // -------------------------------------------- //
@Override @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 // Write Back
if (a2b) if (a2b)

View File

@ -24,13 +24,13 @@ public abstract class WriterAbstractPotionEffect<FA, FB> extends WriterAbstractR
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public DataPotionEffect createA() public DataPotionEffect createOA()
{ {
return new DataPotionEffect(); return new DataPotionEffect();
} }
@Override @Override
public PotionEffect createB() public PotionEffect createOB()
{ {
return new PotionEffect(PotionEffectType.SPEED, 1, 1); return new PotionEffect(PotionEffectType.SPEED, 1, 1);
} }

View File

@ -4,7 +4,7 @@ import java.lang.reflect.Field;
import com.massivecraft.massivecore.util.ReflectionUtil; 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 // FIELDS
@ -26,7 +26,7 @@ public abstract class WriterAbstractReflect<OA, OB, CA, CB, FA, FB> extends Writ
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void setB(CB cb, FB fb) public void setB(CB cb, FB fb, Object d)
{ {
if (this.field == null) return; if (this.field == null) return;
ReflectionUtil.setField(this.field, cb, fb); ReflectionUtil.setField(this.field, cb, fb);

View File

@ -23,19 +23,19 @@ public class WriterBannerPatternColor extends WriterAbstractBannerPattern<Intege
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataBannerPattern ca) public Integer getA(DataBannerPattern ca, Object d)
{ {
return ca.getColor(); return ca.getColor();
} }
@Override @Override
public void setA(DataBannerPattern ca, Integer fa) public void setA(DataBannerPattern ca, Integer fa, Object d)
{ {
ca.setColor(fa); ca.setColor(fa);
} }
@Override @Override
public DyeColor getB(Pattern cb) public DyeColor getB(Pattern cb, Object d)
{ {
return cb.getColor(); return cb.getColor();
} }

View File

@ -23,19 +23,19 @@ public class WriterBannerPatternId extends WriterAbstractBannerPattern<String, P
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getA(DataBannerPattern ca) public String getA(DataBannerPattern ca, Object d)
{ {
return ca.getId(); return ca.getId();
} }
@Override @Override
public void setA(DataBannerPattern ca, String fa) public void setA(DataBannerPattern ca, String fa, Object d)
{ {
ca.setId(fa); ca.setId(fa);
} }
@Override @Override
public PatternType getB(Pattern cb) public PatternType getB(Pattern cb, Object d)
{ {
return cb.getPattern(); return cb.getPattern();
} }

View File

@ -27,19 +27,19 @@ public class WriterFireworkEffectColors extends WriterAbstractFireworkEffect<Lis
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public List<Integer> getA(DataFireworkEffect ca) public List<Integer> getA(DataFireworkEffect ca, Object d)
{ {
return ca.getColors(); return ca.getColors();
} }
@Override @Override
public void setA(DataFireworkEffect ca, List<Integer> fa) public void setA(DataFireworkEffect ca, List<Integer> fa, Object d)
{ {
ca.setColors(fa); ca.setColors(fa);
} }
@Override @Override
public ImmutableList<Color> getB(FireworkEffect cb) public ImmutableList<Color> getB(FireworkEffect cb, Object d)
{ {
return (ImmutableList<Color>) cb.getColors(); return (ImmutableList<Color>) cb.getColors();
} }

View File

@ -27,19 +27,19 @@ public class WriterFireworkEffectFadeColors extends WriterAbstractFireworkEffect
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public List<Integer> getA(DataFireworkEffect ca) public List<Integer> getA(DataFireworkEffect ca, Object d)
{ {
return ca.getFadeColors(); return ca.getFadeColors();
} }
@Override @Override
public void setA(DataFireworkEffect ca, List<Integer> fa) public void setA(DataFireworkEffect ca, List<Integer> fa, Object d)
{ {
ca.setFadeColors(fa); ca.setFadeColors(fa);
} }
@Override @Override
public ImmutableList<Color> getB(FireworkEffect cb) public ImmutableList<Color> getB(FireworkEffect cb, Object d)
{ {
return (ImmutableList<Color>) cb.getFadeColors(); return (ImmutableList<Color>) cb.getFadeColors();
} }

View File

@ -20,19 +20,19 @@ public class WriterFireworkEffectFlicker extends WriterAbstractFireworkEffect<Bo
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Boolean getA(DataFireworkEffect ca) public Boolean getA(DataFireworkEffect ca, Object d)
{ {
return ca.hasFlicker(); return ca.hasFlicker();
} }
@Override @Override
public void setA(DataFireworkEffect ca, Boolean fa) public void setA(DataFireworkEffect ca, Boolean fa, Object d)
{ {
ca.setFlicker(fa); ca.setFlicker(fa);
} }
@Override @Override
public Boolean getB(FireworkEffect cb) public Boolean getB(FireworkEffect cb, Object d)
{ {
return cb.hasFlicker(); return cb.hasFlicker();
} }

View File

@ -20,19 +20,19 @@ public class WriterFireworkEffectTrail extends WriterAbstractFireworkEffect<Bool
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Boolean getA(DataFireworkEffect ca) public Boolean getA(DataFireworkEffect ca, Object d)
{ {
return ca.hasTrail(); return ca.hasTrail();
} }
@Override @Override
public void setA(DataFireworkEffect ca, Boolean fa) public void setA(DataFireworkEffect ca, Boolean fa, Object d)
{ {
ca.setTrail(fa); ca.setTrail(fa);
} }
@Override @Override
public Boolean getB(FireworkEffect cb) public Boolean getB(FireworkEffect cb, Object d)
{ {
return cb.hasTrail(); return cb.hasTrail();
} }

View File

@ -23,19 +23,19 @@ public class WriterFireworkEffectType extends WriterAbstractFireworkEffect<Strin
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getA(DataFireworkEffect ca) public String getA(DataFireworkEffect ca, Object d)
{ {
return ca.getType(); return ca.getType();
} }
@Override @Override
public void setA(DataFireworkEffect ca, String fa) public void setA(DataFireworkEffect ca, String fa, Object d)
{ {
ca.setType(fa); ca.setType(fa);
} }
@Override @Override
public Type getB(FireworkEffect cb) public Type getB(FireworkEffect cb, Object d)
{ {
return cb.getType(); return cb.getType();
} }

View File

@ -16,25 +16,25 @@ public class WriterItemStackCount extends WriterAbstractItemStackField<Integer,
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataItemStack ca) public Integer getA(DataItemStack ca, ItemStack d)
{ {
return ca.getCount(); return ca.getCount();
} }
@Override @Override
public void setA(DataItemStack ca, Integer fa) public void setA(DataItemStack ca, Integer fa, ItemStack d)
{ {
ca.setCount(fa); ca.setCount(fa);
} }
@Override @Override
public Integer getB(ItemStack cb) public Integer getB(ItemStack cb, ItemStack d)
{ {
return cb.getAmount(); return cb.getAmount();
} }
@Override @Override
public void setB(ItemStack cb, Integer fb) public void setB(ItemStack cb, Integer fb, ItemStack d)
{ {
cb.setAmount(fb); cb.setAmount(fb);
} }

View File

@ -16,25 +16,25 @@ public class WriterItemStackDamage extends WriterAbstractItemStackField<Integer,
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataItemStack ca) public Integer getA(DataItemStack ca, ItemStack d)
{ {
return ca.getDamage(); return ca.getDamage();
} }
@Override @Override
public void setA(DataItemStack ca, Integer fa) public void setA(DataItemStack ca, Integer fa, ItemStack d)
{ {
ca.setDamage(fa); ca.setDamage(fa);
} }
@Override @Override
public Integer getB(ItemStack cb) public Integer getB(ItemStack cb, ItemStack d)
{ {
return Integer.valueOf(cb.getDurability()); return Integer.valueOf(cb.getDurability());
} }
@Override @Override
public void setB(ItemStack cb, Integer fb) public void setB(ItemStack cb, Integer fb, ItemStack d)
{ {
cb.setDurability(fb.shortValue()); cb.setDurability(fb.shortValue());
} }

View File

@ -16,27 +16,27 @@ public class WriterItemStackId extends WriterAbstractItemStackField<Integer, Int
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataItemStack ca) public Integer getA(DataItemStack ca, ItemStack d)
{ {
return ca.getId(); return ca.getId();
} }
@Override @Override
public void setA(DataItemStack ca, Integer fa) public void setA(DataItemStack ca, Integer fa, ItemStack d)
{ {
ca.setId(fa); ca.setId(fa);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public Integer getB(ItemStack cb) public Integer getB(ItemStack cb, ItemStack d)
{ {
return cb.getTypeId(); return cb.getTypeId();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void setB(ItemStack cb, Integer fb) public void setB(ItemStack cb, Integer fb, ItemStack d)
{ {
cb.setTypeId(fb); cb.setTypeId(fb);
} }

View File

@ -56,10 +56,10 @@ public class WriterItemStackMeta extends WriterAbstractItemStackMetaMorph<Object
WriterItemStackMetaBannerPatterns.class, WriterItemStackMetaBannerPatterns.class,
// STATE // STATE
WriterItemStackMetaState.class WriterItemStackMetaState.class,
// POTION // POTION
// TODO Merge with potion above? WriterItemStackMetaPotion.class
); );
} }

View File

@ -1,6 +1,7 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
public class WriterItemStackMetaAuthor extends WriterAbstractItemStackMetaField<BookMeta, String, String> public class WriterItemStackMetaAuthor extends WriterAbstractItemStackMetaField<BookMeta, String, String>
@ -20,25 +21,25 @@ public class WriterItemStackMetaAuthor extends WriterAbstractItemStackMetaField<
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getA(DataItemStack ca) public String getA(DataItemStack ca, ItemStack d)
{ {
return ca.getAuthor(); return ca.getAuthor();
} }
@Override @Override
public void setA(DataItemStack ca, String fa) public void setA(DataItemStack ca, String fa, ItemStack d)
{ {
ca.setAuthor(fa); ca.setAuthor(fa);
} }
@Override @Override
public String getB(BookMeta cb) public String getB(BookMeta cb, ItemStack d)
{ {
return cb.getAuthor(); return cb.getAuthor();
} }
@Override @Override
public void setB(BookMeta cb, String fb) public void setB(BookMeta cb, String fb, ItemStack d)
{ {
cb.setAuthor(fb); cb.setAuthor(fb);
} }

View File

@ -2,6 +2,7 @@ package com.massivecraft.massivecore.item;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.BannerMeta;
public class WriterItemStackMetaBannerBase extends WriterAbstractItemStackMetaField<BannerMeta, Integer, DyeColor> public class WriterItemStackMetaBannerBase extends WriterAbstractItemStackMetaField<BannerMeta, Integer, DyeColor>
@ -24,25 +25,25 @@ public class WriterItemStackMetaBannerBase extends WriterAbstractItemStackMetaFi
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataItemStack ca) public Integer getA(DataItemStack ca, ItemStack d)
{ {
return ca.getBannerBase(); return ca.getBannerBase();
} }
@Override @Override
public void setA(DataItemStack ca, Integer fa) public void setA(DataItemStack ca, Integer fa, ItemStack d)
{ {
ca.setBannerBase(fa); ca.setBannerBase(fa);
} }
@Override @Override
public DyeColor getB(BannerMeta cb) public DyeColor getB(BannerMeta cb, ItemStack d)
{ {
return cb.getBaseColor(); return cb.getBaseColor();
} }
@Override @Override
public void setB(BannerMeta cb, DyeColor fb) public void setB(BannerMeta cb, DyeColor fb, ItemStack d)
{ {
cb.setBaseColor(fb); cb.setBaseColor(fb);
} }

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.BannerMeta;
public class WriterItemStackMetaBannerPatterns extends WriterAbstractItemStackMetaField<BannerMeta, List<DataBannerPattern>, List<Pattern>> public class WriterItemStackMetaBannerPatterns extends WriterAbstractItemStackMetaField<BannerMeta, List<DataBannerPattern>, List<Pattern>>
@ -28,25 +29,25 @@ public class WriterItemStackMetaBannerPatterns extends WriterAbstractItemStackMe
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public List<DataBannerPattern> getA(DataItemStack ca) public List<DataBannerPattern> getA(DataItemStack ca, ItemStack d)
{ {
return ca.getBannerPatterns(); return ca.getBannerPatterns();
} }
@Override @Override
public void setA(DataItemStack ca, List<DataBannerPattern> fa) public void setA(DataItemStack ca, List<DataBannerPattern> fa, ItemStack d)
{ {
ca.setBannerPatterns(fa); ca.setBannerPatterns(fa);
} }
@Override @Override
public List<Pattern> getB(BannerMeta cb) public List<Pattern> getB(BannerMeta cb, ItemStack d)
{ {
return cb.getPatterns(); return cb.getPatterns();
} }
@Override @Override
public void setB(BannerMeta cb, List<Pattern> fb) public void setB(BannerMeta cb, List<Pattern> fb, ItemStack d)
{ {
cb.setPatterns(fb); cb.setPatterns(fb);
} }

View File

@ -2,6 +2,7 @@ package com.massivecraft.massivecore.item;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.LeatherArmorMeta;
public class WriterItemStackMetaColor extends WriterAbstractItemStackMetaField<LeatherArmorMeta, Integer, Color> public class WriterItemStackMetaColor extends WriterAbstractItemStackMetaField<LeatherArmorMeta, Integer, Color>
@ -23,25 +24,25 @@ public class WriterItemStackMetaColor extends WriterAbstractItemStackMetaField<L
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataItemStack ca) public Integer getA(DataItemStack ca, ItemStack d)
{ {
return ca.getColor(); return ca.getColor();
} }
@Override @Override
public void setA(DataItemStack ca, Integer fa) public void setA(DataItemStack ca, Integer fa, ItemStack d)
{ {
ca.setColor(fa); ca.setColor(fa);
} }
@Override @Override
public Color getB(LeatherArmorMeta cb) public Color getB(LeatherArmorMeta cb, ItemStack d)
{ {
return cb.getColor(); return cb.getColor();
} }
@Override @Override
public void setB(LeatherArmorMeta cb, Color fb) public void setB(LeatherArmorMeta cb, Color fb, ItemStack d)
{ {
cb.setColor(fb); cb.setColor(fb);
} }

View File

@ -4,6 +4,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
public class WriterItemStackMetaEnchants extends WriterAbstractItemStackMetaField<ItemMeta, Map<Integer, Integer>, Map<Enchantment, Integer>> public class WriterItemStackMetaEnchants extends WriterAbstractItemStackMetaField<ItemMeta, Map<Integer, Integer>, Map<Enchantment, Integer>>
@ -25,25 +26,25 @@ public class WriterItemStackMetaEnchants extends WriterAbstractItemStackMetaFiel
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Map<Integer, Integer> getA(DataItemStack ca) public Map<Integer, Integer> getA(DataItemStack ca, ItemStack d)
{ {
return ca.getEnchants(); return ca.getEnchants();
} }
@Override @Override
public void setA(DataItemStack ca, Map<Integer, Integer> fa) public void setA(DataItemStack ca, Map<Integer, Integer> fa, ItemStack d)
{ {
ca.setEnchants(fa); ca.setEnchants(fa);
} }
@Override @Override
public Map<Enchantment, Integer> getB(ItemMeta cb) public Map<Enchantment, Integer> getB(ItemMeta cb, ItemStack d)
{ {
return cb.getEnchants(); return cb.getEnchants();
} }
@Override @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()) for (Entry<Enchantment, Integer> entry : fb.entrySet())
{ {

View File

@ -2,6 +2,7 @@ package com.massivecraft.massivecore.item;
import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkEffectMeta; import org.bukkit.inventory.meta.FireworkEffectMeta;
public class WriterItemStackMetaFireworkEffect extends WriterAbstractItemStackMetaField<FireworkEffectMeta, DataFireworkEffect, FireworkEffect> public class WriterItemStackMetaFireworkEffect extends WriterAbstractItemStackMetaField<FireworkEffectMeta, DataFireworkEffect, FireworkEffect>
@ -26,25 +27,25 @@ public class WriterItemStackMetaFireworkEffect extends WriterAbstractItemStackMe
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public DataFireworkEffect getA(DataItemStack ca) public DataFireworkEffect getA(DataItemStack ca, ItemStack d)
{ {
return ca.getFireworkEffect(); return ca.getFireworkEffect();
} }
@Override @Override
public void setA(DataItemStack ca, DataFireworkEffect fa) public void setA(DataItemStack ca, DataFireworkEffect fa, ItemStack d)
{ {
ca.setFireworkEffect(fa); ca.setFireworkEffect(fa);
} }
@Override @Override
public FireworkEffect getB(FireworkEffectMeta cb) public FireworkEffect getB(FireworkEffectMeta cb, ItemStack d)
{ {
return cb.getEffect(); return cb.getEffect();
} }
@Override @Override
public void setB(FireworkEffectMeta cb, FireworkEffect fb) public void setB(FireworkEffectMeta cb, FireworkEffect fb, ItemStack d)
{ {
cb.setEffect(fb); cb.setEffect(fb);
} }

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.FireworkMeta;
public class WriterItemStackMetaFireworkEffects extends WriterAbstractItemStackMetaField<FireworkMeta, List<DataFireworkEffect>, List<FireworkEffect>> public class WriterItemStackMetaFireworkEffects extends WriterAbstractItemStackMetaField<FireworkMeta, List<DataFireworkEffect>, List<FireworkEffect>>
@ -28,25 +29,25 @@ public class WriterItemStackMetaFireworkEffects extends WriterAbstractItemStackM
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public List<DataFireworkEffect> getA(DataItemStack ca) public List<DataFireworkEffect> getA(DataItemStack ca, ItemStack d)
{ {
return ca.getFireworkEffects(); return ca.getFireworkEffects();
} }
@Override @Override
public void setA(DataItemStack ca, List<DataFireworkEffect> fa) public void setA(DataItemStack ca, List<DataFireworkEffect> fa, ItemStack d)
{ {
ca.setFireworkEffects(fa); ca.setFireworkEffects(fa);
} }
@Override @Override
public List<FireworkEffect> getB(FireworkMeta cb) public List<FireworkEffect> getB(FireworkMeta cb, ItemStack d)
{ {
return cb.getEffects(); return cb.getEffects();
} }
@Override @Override
public void setB(FireworkMeta cb, List<FireworkEffect> fb) public void setB(FireworkMeta cb, List<FireworkEffect> fb, ItemStack d)
{ {
cb.addEffects(fb); cb.addEffects(fb);
} }

View File

@ -1,6 +1,7 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.FireworkMeta;
public class WriterItemStackMetaFireworkFlight extends WriterAbstractItemStackMetaField<FireworkMeta, Integer, Integer> public class WriterItemStackMetaFireworkFlight extends WriterAbstractItemStackMetaField<FireworkMeta, Integer, Integer>
@ -20,25 +21,25 @@ public class WriterItemStackMetaFireworkFlight extends WriterAbstractItemStackMe
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataItemStack ca) public Integer getA(DataItemStack ca, ItemStack d)
{ {
return ca.getFireworkFlight(); return ca.getFireworkFlight();
} }
@Override @Override
public void setA(DataItemStack ca, Integer fa) public void setA(DataItemStack ca, Integer fa, ItemStack d)
{ {
ca.setFireworkFlight(fa); ca.setFireworkFlight(fa);
} }
@Override @Override
public Integer getB(FireworkMeta cb) public Integer getB(FireworkMeta cb, ItemStack d)
{ {
return cb.getPower(); return cb.getPower();
} }
@Override @Override
public void setB(FireworkMeta cb, Integer fb) public void setB(FireworkMeta cb, Integer fb, ItemStack d)
{ {
cb.setPower(fb); cb.setPower(fb);
} }

View File

@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
import java.util.Set; import java.util.Set;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
public class WriterItemStackMetaFlags extends WriterAbstractItemStackMetaField<ItemMeta, Set<String>, Set<ItemFlag>> public class WriterItemStackMetaFlags extends WriterAbstractItemStackMetaField<ItemMeta, Set<String>, Set<ItemFlag>>
@ -24,25 +25,25 @@ public class WriterItemStackMetaFlags extends WriterAbstractItemStackMetaField<I
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Set<String> getA(DataItemStack ca) public Set<String> getA(DataItemStack ca, ItemStack d)
{ {
return ca.getFlags(); return ca.getFlags();
} }
@Override @Override
public void setA(DataItemStack ca, Set<String> fa) public void setA(DataItemStack ca, Set<String> fa, ItemStack d)
{ {
ca.setFlags(fa); ca.setFlags(fa);
} }
@Override @Override
public Set<ItemFlag> getB(ItemMeta cb) public Set<ItemFlag> getB(ItemMeta cb, ItemStack d)
{ {
return cb.getItemFlags(); return cb.getItemFlags();
} }
@Override @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])); cb.addItemFlags(fb.toArray(new ItemFlag[0]));
} }

View File

@ -2,6 +2,7 @@ package com.massivecraft.massivecore.item;
import java.util.List; import java.util.List;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
public class WriterItemStackMetaLore extends WriterAbstractItemStackMetaField<ItemMeta, List<String>, List<String>> public class WriterItemStackMetaLore extends WriterAbstractItemStackMetaField<ItemMeta, List<String>, List<String>>
@ -18,25 +19,25 @@ public class WriterItemStackMetaLore extends WriterAbstractItemStackMetaField<It
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public List<String> getA(DataItemStack ca) public List<String> getA(DataItemStack ca, ItemStack d)
{ {
return ca.getLore(); return ca.getLore();
} }
@Override @Override
public void setA(DataItemStack ca, List<String> fa) public void setA(DataItemStack ca, List<String> fa, ItemStack d)
{ {
ca.setLore(fa); ca.setLore(fa);
} }
@Override @Override
public List<String> getB(ItemMeta cb) public List<String> getB(ItemMeta cb, ItemStack d)
{ {
return cb.getLore(); return cb.getLore();
} }
@Override @Override
public void setB(ItemMeta cb, List<String> fb) public void setB(ItemMeta cb, List<String> fb, ItemStack d)
{ {
cb.setLore(fb); cb.setLore(fb);
} }

View File

@ -1,5 +1,6 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
public class WriterItemStackMetaName extends WriterAbstractItemStackMetaField<ItemMeta, String, String> public class WriterItemStackMetaName extends WriterAbstractItemStackMetaField<ItemMeta, String, String>
@ -16,25 +17,25 @@ public class WriterItemStackMetaName extends WriterAbstractItemStackMetaField<It
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getA(DataItemStack ca) public String getA(DataItemStack ca, ItemStack d)
{ {
return ca.getName(); return ca.getName();
} }
@Override @Override
public void setA(DataItemStack ca, String fa) public void setA(DataItemStack ca, String fa, ItemStack d)
{ {
ca.setName(fa); ca.setName(fa);
} }
@Override @Override
public String getB(ItemMeta cb) public String getB(ItemMeta cb, ItemStack d)
{ {
return cb.getDisplayName(); return cb.getDisplayName();
} }
@Override @Override
public void setB(ItemMeta cb, String fb) public void setB(ItemMeta cb, String fb, ItemStack d)
{ {
cb.setDisplayName(fb); cb.setDisplayName(fb);
} }

View File

@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
import java.util.List; import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
public class WriterItemStackMetaPages extends WriterAbstractItemStackMetaField<BookMeta, List<String>, List<String>> public class WriterItemStackMetaPages extends WriterAbstractItemStackMetaField<BookMeta, List<String>, List<String>>
@ -22,25 +23,25 @@ public class WriterItemStackMetaPages extends WriterAbstractItemStackMetaField<B
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public List<String> getA(DataItemStack ca) public List<String> getA(DataItemStack ca, ItemStack d)
{ {
return ca.getPages(); return ca.getPages();
} }
@Override @Override
public void setA(DataItemStack ca, List<String> fa) public void setA(DataItemStack ca, List<String> fa, ItemStack d)
{ {
ca.setPages(fa); ca.setPages(fa);
} }
@Override @Override
public List<String> getB(BookMeta cb) public List<String> getB(BookMeta cb, ItemStack d)
{ {
return cb.getPages(); return cb.getPages();
} }
@Override @Override
public void setB(BookMeta cb, List<String> fb) public void setB(BookMeta cb, List<String> fb, ItemStack d)
{ {
cb.setPages(fb); cb.setPages(fb);
} }

View File

@ -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);
}
}
}

View File

@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
import java.util.List; import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@ -28,25 +29,25 @@ public class WriterItemStackMetaPotionEffects extends WriterAbstractItemStackMet
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public List<DataPotionEffect> getA(DataItemStack ca) public List<DataPotionEffect> getA(DataItemStack ca, ItemStack d)
{ {
return ca.getPotionEffects(); return ca.getPotionEffects();
} }
@Override @Override
public void setA(DataItemStack ca, List<DataPotionEffect> fa) public void setA(DataItemStack ca, List<DataPotionEffect> fa, ItemStack d)
{ {
ca.setPotionEffects(fa); ca.setPotionEffects(fa);
} }
@Override @Override
public List<PotionEffect> getB(PotionMeta cb) public List<PotionEffect> getB(PotionMeta cb, ItemStack d)
{ {
return cb.getCustomEffects(); return cb.getCustomEffects();
} }
@Override @Override
public void setB(PotionMeta cb, List<PotionEffect> fb) public void setB(PotionMeta cb, List<PotionEffect> fb, ItemStack d)
{ {
for (PotionEffect potionEffect : fb) for (PotionEffect potionEffect : fb)
{ {

View File

@ -1,6 +1,7 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Repairable; import org.bukkit.inventory.meta.Repairable;
public class WriterItemStackMetaRepaircost extends WriterAbstractItemStackMetaField<Repairable, Integer, Integer> public class WriterItemStackMetaRepaircost extends WriterAbstractItemStackMetaField<Repairable, Integer, Integer>
@ -20,25 +21,25 @@ public class WriterItemStackMetaRepaircost extends WriterAbstractItemStackMetaFi
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataItemStack ca) public Integer getA(DataItemStack ca, ItemStack d)
{ {
return ca.getRepaircost(); return ca.getRepaircost();
} }
@Override @Override
public void setA(DataItemStack ca, Integer fa) public void setA(DataItemStack ca, Integer fa, ItemStack d)
{ {
ca.setRepaircost(fa); ca.setRepaircost(fa);
} }
@Override @Override
public Integer getB(Repairable cb) public Integer getB(Repairable cb, ItemStack d)
{ {
return cb.getRepairCost(); return cb.getRepairCost();
} }
@Override @Override
public void setB(Repairable cb, Integer fb) public void setB(Repairable cb, Integer fb, ItemStack d)
{ {
cb.setRepairCost(fb); cb.setRepairCost(fb);
} }

View File

@ -1,6 +1,7 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta; import org.bukkit.inventory.meta.MapMeta;
public class WriterItemStackMetaScaling extends WriterAbstractItemStackMetaField<MapMeta, Boolean, Boolean> public class WriterItemStackMetaScaling extends WriterAbstractItemStackMetaField<MapMeta, Boolean, Boolean>
@ -20,25 +21,25 @@ public class WriterItemStackMetaScaling extends WriterAbstractItemStackMetaField
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Boolean getA(DataItemStack ca) public Boolean getA(DataItemStack ca, ItemStack d)
{ {
return ca.isScaling(); return ca.isScaling();
} }
@Override @Override
public void setA(DataItemStack ca, Boolean fa) public void setA(DataItemStack ca, Boolean fa, ItemStack d)
{ {
ca.setScaling(fa); ca.setScaling(fa);
} }
@Override @Override
public Boolean getB(MapMeta cb) public Boolean getB(MapMeta cb, ItemStack d)
{ {
return cb.isScaling(); return cb.isScaling();
} }
@Override @Override
public void setB(MapMeta cb, Boolean fb) public void setB(MapMeta cb, Boolean fb, ItemStack d)
{ {
cb.setScaling(fb); cb.setScaling(fb);
} }

View File

@ -1,6 +1,7 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
public class WriterItemStackMetaSkull17 extends WriterAbstractItemStackMetaField<SkullMeta, String, String> public class WriterItemStackMetaSkull17 extends WriterAbstractItemStackMetaField<SkullMeta, String, String>
@ -21,25 +22,25 @@ public class WriterItemStackMetaSkull17 extends WriterAbstractItemStackMetaField
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getA(DataItemStack ca) public String getA(DataItemStack ca, ItemStack d)
{ {
return ca.getSkull(); return ca.getSkull();
} }
@Override @Override
public void setA(DataItemStack ca, String fa) public void setA(DataItemStack ca, String fa, ItemStack d)
{ {
ca.setSkull(fa); ca.setSkull(fa);
} }
@Override @Override
public String getB(SkullMeta cb) public String getB(SkullMeta cb, ItemStack d)
{ {
return cb.getOwner(); return cb.getOwner();
} }
@Override @Override
public void setB(SkullMeta cb, String fb) public void setB(SkullMeta cb, String fb, ItemStack d)
{ {
cb.setOwner(fb); cb.setOwner(fb);
} }

View File

@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import com.massivecraft.massivecore.Couple; import com.massivecraft.massivecore.Couple;
@ -26,26 +27,26 @@ public class WriterItemStackMetaSkull18 extends WriterAbstractItemStackMetaField
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getA(DataItemStack ca) public String getA(DataItemStack ca, ItemStack d)
{ {
return ca.getSkull(); return ca.getSkull();
} }
@Override @Override
public void setA(DataItemStack ca, String fa) public void setA(DataItemStack ca, String fa, ItemStack d)
{ {
if (fa != null) fa = fa.toLowerCase(); if (fa != null) fa = fa.toLowerCase();
ca.setSkull(fa); ca.setSkull(fa);
} }
@Override @Override
public String getB(SkullMeta cb) public String getB(SkullMeta cb, ItemStack d)
{ {
return cb.getOwner(); return cb.getOwner();
} }
@Override @Override
public void setB(SkullMeta cb, String fb) public void setB(SkullMeta cb, String fb, ItemStack d)
{ {
String name = fb; String name = fb;

View File

@ -3,6 +3,7 @@ package com.massivecraft.massivecore.item;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Banner; import org.bukkit.block.Banner;
import org.bukkit.inventory.ItemStack;
public class WriterItemStackMetaStateShieldBase extends WriterAbstractItemStackMetaStateField<Banner, Integer, DyeColor> public class WriterItemStackMetaStateShieldBase extends WriterAbstractItemStackMetaStateField<Banner, Integer, DyeColor>
{ {
@ -24,25 +25,25 @@ public class WriterItemStackMetaStateShieldBase extends WriterAbstractItemStackM
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataItemStack ca) public Integer getA(DataItemStack ca, ItemStack d)
{ {
return ca.getBannerBase(); return ca.getBannerBase();
} }
@Override @Override
public void setA(DataItemStack ca, Integer fa) public void setA(DataItemStack ca, Integer fa, ItemStack d)
{ {
ca.setBannerBase(fa); ca.setBannerBase(fa);
} }
@Override @Override
public DyeColor getB(Banner cb) public DyeColor getB(Banner cb, ItemStack d)
{ {
return cb.getBaseColor(); return cb.getBaseColor();
} }
@Override @Override
public void setB(Banner cb, DyeColor fb) public void setB(Banner cb, DyeColor fb, ItemStack d)
{ {
cb.setBaseColor(fb); cb.setBaseColor(fb);
} }

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Banner; import org.bukkit.block.Banner;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
import org.bukkit.inventory.ItemStack;
public class WriterItemStackMetaStateShieldPatterns extends WriterAbstractItemStackMetaStateField<Banner, List<DataBannerPattern>, List<Pattern>> public class WriterItemStackMetaStateShieldPatterns extends WriterAbstractItemStackMetaStateField<Banner, List<DataBannerPattern>, List<Pattern>>
{ {
@ -28,25 +29,25 @@ public class WriterItemStackMetaStateShieldPatterns extends WriterAbstractItemSt
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public List<DataBannerPattern> getA(DataItemStack ca) public List<DataBannerPattern> getA(DataItemStack ca, ItemStack d)
{ {
return ca.getBannerPatterns(); return ca.getBannerPatterns();
} }
@Override @Override
public void setA(DataItemStack ca, List<DataBannerPattern> fa) public void setA(DataItemStack ca, List<DataBannerPattern> fa, ItemStack d)
{ {
ca.setBannerPatterns(fa); ca.setBannerPatterns(fa);
} }
@Override @Override
public List<Pattern> getB(Banner cb) public List<Pattern> getB(Banner cb, ItemStack d)
{ {
return cb.getPatterns(); return cb.getPatterns();
} }
@Override @Override
public void setB(Banner cb, List<Pattern> fb) public void setB(Banner cb, List<Pattern> fb, ItemStack d)
{ {
cb.setPatterns(fb); cb.setPatterns(fb);
} }

View File

@ -5,6 +5,7 @@ import java.util.Map.Entry;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
public class WriterItemStackMetaStoredEnchants extends WriterAbstractItemStackMetaField<EnchantmentStorageMeta, Map<Integer, Integer>, Map<Enchantment, Integer>> public class WriterItemStackMetaStoredEnchants extends WriterAbstractItemStackMetaField<EnchantmentStorageMeta, Map<Integer, Integer>, Map<Enchantment, Integer>>
@ -27,25 +28,25 @@ public class WriterItemStackMetaStoredEnchants extends WriterAbstractItemStackMe
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Map<Integer, Integer> getA(DataItemStack ca) public Map<Integer, Integer> getA(DataItemStack ca, ItemStack d)
{ {
return ca.getStoredEnchants(); return ca.getStoredEnchants();
} }
@Override @Override
public void setA(DataItemStack ca, Map<Integer, Integer> fa) public void setA(DataItemStack ca, Map<Integer, Integer> fa, ItemStack d)
{ {
ca.setStoredEnchants(fa); ca.setStoredEnchants(fa);
} }
@Override @Override
public Map<Enchantment, Integer> getB(EnchantmentStorageMeta cb) public Map<Enchantment, Integer> getB(EnchantmentStorageMeta cb, ItemStack d)
{ {
return cb.getStoredEnchants(); return cb.getStoredEnchants();
} }
@Override @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()) for (Entry<Enchantment, Integer> entry : fb.entrySet())
{ {

View File

@ -1,6 +1,7 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
public class WriterItemStackMetaTitle extends WriterAbstractItemStackMetaField<BookMeta, String, String> public class WriterItemStackMetaTitle extends WriterAbstractItemStackMetaField<BookMeta, String, String>
@ -20,25 +21,25 @@ public class WriterItemStackMetaTitle extends WriterAbstractItemStackMetaField<B
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getA(DataItemStack ca) public String getA(DataItemStack ca, ItemStack d)
{ {
return ca.getTitle(); return ca.getTitle();
} }
@Override @Override
public void setA(DataItemStack ca, String fa) public void setA(DataItemStack ca, String fa, ItemStack d)
{ {
ca.setTitle(fa); ca.setTitle(fa);
} }
@Override @Override
public String getB(BookMeta cb) public String getB(BookMeta cb, ItemStack d)
{ {
return cb.getTitle(); return cb.getTitle();
} }
@Override @Override
public void setB(BookMeta cb, String fb) public void setB(BookMeta cb, String fb, ItemStack d)
{ {
cb.setTitle(fb); cb.setTitle(fb);
} }

View File

@ -1,5 +1,6 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
public class WriterItemStackMetaUnbreakable extends WriterAbstractItemStackMetaField<ItemMeta, Boolean, Boolean> public class WriterItemStackMetaUnbreakable extends WriterAbstractItemStackMetaField<ItemMeta, Boolean, Boolean>
@ -16,25 +17,25 @@ public class WriterItemStackMetaUnbreakable extends WriterAbstractItemStackMetaF
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Boolean getA(DataItemStack ca) public Boolean getA(DataItemStack ca, ItemStack d)
{ {
return ca.isUnbreakable(); return ca.isUnbreakable();
} }
@Override @Override
public void setA(DataItemStack ca, Boolean fa) public void setA(DataItemStack ca, Boolean fa, ItemStack d)
{ {
ca.setUnbreakable(fa); ca.setUnbreakable(fa);
} }
@Override @Override
public Boolean getB(ItemMeta cb) public Boolean getB(ItemMeta cb, ItemStack d)
{ {
return cb.spigot().isUnbreakable(); return cb.spigot().isUnbreakable();
} }
@Override @Override
public void setB(ItemMeta cb, Boolean fb) public void setB(ItemMeta cb, Boolean fb, ItemStack d)
{ {
cb.spigot().setUnbreakable(fb); cb.spigot().setUnbreakable(fb);
} }

View File

@ -20,19 +20,19 @@ public class WriterPotionEffectAmbient extends WriterAbstractPotionEffect<Boolea
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Boolean getA(DataPotionEffect ca) public Boolean getA(DataPotionEffect ca, Object d)
{ {
return ca.isAmbient(); return ca.isAmbient();
} }
@Override @Override
public void setA(DataPotionEffect ca, Boolean fa) public void setA(DataPotionEffect ca, Boolean fa, Object d)
{ {
ca.setAmbient(fa); ca.setAmbient(fa);
} }
@Override @Override
public Boolean getB(PotionEffect cb) public Boolean getB(PotionEffect cb, Object d)
{ {
return cb.isAmbient(); return cb.isAmbient();
} }

View File

@ -20,19 +20,19 @@ public class WriterPotionEffectAmplifier extends WriterAbstractPotionEffect<Inte
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataPotionEffect ca) public Integer getA(DataPotionEffect ca, Object d)
{ {
return ca.getAmplifier(); return ca.getAmplifier();
} }
@Override @Override
public void setA(DataPotionEffect ca, Integer fa) public void setA(DataPotionEffect ca, Integer fa, Object d)
{ {
ca.setAmplifier(fa); ca.setAmplifier(fa);
} }
@Override @Override
public Integer getB(PotionEffect cb) public Integer getB(PotionEffect cb, Object d)
{ {
return cb.getAmplifier(); return cb.getAmplifier();
} }

View File

@ -23,19 +23,19 @@ public class WriterPotionEffectColor extends WriterAbstractPotionEffect<Integer,
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataPotionEffect ca) public Integer getA(DataPotionEffect ca, Object d)
{ {
return ca.getColor(); return ca.getColor();
} }
@Override @Override
public void setA(DataPotionEffect ca, Integer fa) public void setA(DataPotionEffect ca, Integer fa, Object d)
{ {
ca.setColor(fa); ca.setColor(fa);
} }
@Override @Override
public Color getB(PotionEffect cb) public Color getB(PotionEffect cb, Object d)
{ {
return cb.getColor(); return cb.getColor();
} }

View File

@ -20,19 +20,19 @@ public class WriterPotionEffectDuraction extends WriterAbstractPotionEffect<Inte
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataPotionEffect ca) public Integer getA(DataPotionEffect ca, Object d)
{ {
return ca.getDuration(); return ca.getDuration();
} }
@Override @Override
public void setA(DataPotionEffect ca, Integer fa) public void setA(DataPotionEffect ca, Integer fa, Object d)
{ {
ca.setDuration(fa); ca.setDuration(fa);
} }
@Override @Override
public Integer getB(PotionEffect cb) public Integer getB(PotionEffect cb, Object d)
{ {
return cb.getDuration(); return cb.getDuration();
} }

View File

@ -23,19 +23,19 @@ public class WriterPotionEffectId extends WriterAbstractPotionEffect<Integer, Po
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Integer getA(DataPotionEffect ca) public Integer getA(DataPotionEffect ca, Object d)
{ {
return ca.getId(); return ca.getId();
} }
@Override @Override
public void setA(DataPotionEffect ca, Integer fa) public void setA(DataPotionEffect ca, Integer fa, Object d)
{ {
ca.setId(fa); ca.setId(fa);
} }
@Override @Override
public PotionEffectType getB(PotionEffect cb) public PotionEffectType getB(PotionEffect cb, Object d)
{ {
return cb.getType(); return cb.getType();
} }

View File

@ -20,19 +20,19 @@ public class WriterPotionEffectParticles extends WriterAbstractPotionEffect<Bool
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Boolean getA(DataPotionEffect ca) public Boolean getA(DataPotionEffect ca, Object d)
{ {
return ca.isParticles(); return ca.isParticles();
} }
@Override @Override
public void setA(DataPotionEffect ca, Boolean fa) public void setA(DataPotionEffect ca, Boolean fa, Object d)
{ {
ca.setParticles(fa); ca.setParticles(fa);
} }
@Override @Override
public Boolean getB(PotionEffect cb) public Boolean getB(PotionEffect cb, Object d)
{ {
return cb.hasParticles(); return cb.hasParticles();
} }