Prepare ItemStackAdapter for 1.9 Potions Step1

This commit is contained in:
Olof Larsson 2016-03-10 16:09:04 +01:00
parent a1652849ea
commit 3681b189f6
5 changed files with 155 additions and 66 deletions

View File

@ -29,7 +29,7 @@ public class ItemStackAdapter implements JsonDeserializer<ItemStack>, JsonSerial
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
protected ItemStackAdapterInner inner; private ItemStackAdapterInner inner;
public ItemStackAdapterInner getInner() { return this.inner; } public ItemStackAdapterInner getInner() { return this.inner; }
public void setInner(ItemStackAdapterInner inner) { this.inner = inner; } public void setInner(ItemStackAdapterInner inner) { this.inner = inner; }
@ -39,18 +39,30 @@ public class ItemStackAdapter implements JsonDeserializer<ItemStack>, JsonSerial
public ItemStackAdapter() public ItemStackAdapter()
{ {
// 1.7 // 1.9
this.inner = ItemStackAdapterInnerV1_7.get(); try
{
this.inner = ItemStackAdapterInner19.get();
return;
}
catch (Throwable t)
{
}
// 1.8 // 1.8
try try
{ {
this.inner = ItemStackAdapterInnerV1_8.get(); this.inner = ItemStackAdapterInner18.get();
return;
} }
catch (Throwable t) catch (Throwable t)
{ {
return;
} }
// 1.7
this.inner = ItemStackAdapterInner17.get();
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -7,6 +7,9 @@ import com.massivecraft.massivecore.xlib.gson.JsonObject;
public interface ItemStackAdapterInner public interface ItemStackAdapterInner
{ {
public Object provoke();
public JsonObject erialize(ItemStack stack); public JsonObject erialize(ItemStack stack);
public ItemStack erialize(JsonElement jsonElement); public ItemStack erialize(JsonElement jsonElement);
} }

View File

@ -32,7 +32,7 @@ import com.massivecraft.massivecore.xlib.gson.JsonObject;
import com.massivecraft.massivecore.xlib.gson.JsonPrimitive; import com.massivecraft.massivecore.xlib.gson.JsonPrimitive;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner public class ItemStackAdapterInner17 implements ItemStackAdapterInner
{ {
// -------------------------------------------- // // -------------------------------------------- //
// CONSTANTS: NAMES // CONSTANTS: NAMES
@ -73,9 +73,23 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public static ItemStackAdapterInnerV1_7 i = new ItemStackAdapterInnerV1_7(); public static ItemStackAdapterInner17 i = new ItemStackAdapterInner17();
public static ItemStackAdapterInnerV1_7 get() { return i; } public static ItemStackAdapterInner17 get() { return i; }
public ItemStackAdapterInner17()
{
this.provoke();
}
// -------------------------------------------- //
// PROVOKE
// -------------------------------------------- //
@Override
public Object provoke()
{
return null;
}
// -------------------------------------------- // // -------------------------------------------- //
// WRITE // WRITE
// -------------------------------------------- // // -------------------------------------------- //
@ -137,7 +151,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
this.transferBasic(stack, json, stack2json); this.transferBasic(stack, json, stack2json);
ItemMeta meta = stack.getItemMeta(); ItemMeta meta = stack.getItemMeta();
this.transferMeta(meta, json, stack2json); this.transferMeta(stack, json, stack2json, meta);
if (stack2json == false) if (stack2json == false)
{ {
@ -221,29 +235,29 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// META // META
// -------------------------------------------- // // -------------------------------------------- //
public void transferMeta(ItemMeta meta, JsonObject json, boolean meta2json) public void transferMeta(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
this.transferMetaUnspecific(meta, json, meta2json); this.transferMetaUnspecific(stack, json, meta2json, meta);
this.transferMetaSpecific(meta, json, meta2json); this.transferMetaSpecific(stack, json, meta2json, meta);
} }
// -------------------------------------------- // // -------------------------------------------- //
// UNSPECIFIC META // UNSPECIFIC META
// -------------------------------------------- // // -------------------------------------------- //
public void transferMetaUnspecific(ItemMeta meta, JsonObject json, boolean meta2json) public void transferMetaUnspecific(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
this.transferName(meta, json, meta2json); this.transferName(stack, json, meta2json, meta);
this.transferLore(meta, json, meta2json); this.transferLore(stack, json, meta2json, meta);
this.transferEnchants(meta, json, meta2json); this.transferEnchants(stack, json, meta2json, meta);
this.transferRepaircost(meta, json, meta2json); this.transferRepaircost(stack, json, meta2json, meta);
} }
// -------------------------------------------- // // -------------------------------------------- //
// UNSPECIFIC META: NAME // UNSPECIFIC META: NAME
// -------------------------------------------- // // -------------------------------------------- //
public void transferName(ItemMeta meta, JsonObject json, boolean meta2json) public void transferName(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -262,7 +276,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// UNSPECIFIC META: LORE // UNSPECIFIC META: LORE
// -------------------------------------------- // // -------------------------------------------- //
public void transferLore(ItemMeta meta, JsonObject json, boolean meta2json) public void transferLore(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -281,7 +295,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// UNSPECIFIC META: ENCHANTS // UNSPECIFIC META: ENCHANTS
// -------------------------------------------- // // -------------------------------------------- //
public void transferEnchants(ItemMeta meta, JsonObject json, boolean meta2json) public void transferEnchants(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -303,7 +317,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// UNSPECIFIC META: REPAIRCOST // UNSPECIFIC META: REPAIRCOST
// -------------------------------------------- // // -------------------------------------------- //
public void transferRepaircost(ItemMeta meta, JsonObject json, boolean meta2json) public void transferRepaircost(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
if ( ! (meta instanceof Repairable)) return; if ( ! (meta instanceof Repairable)) return;
Repairable repairable = (Repairable) meta; Repairable repairable = (Repairable) meta;
@ -326,39 +340,39 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// SPECIFIC META // SPECIFIC META
// -------------------------------------------- // // -------------------------------------------- //
public void transferMetaSpecific(ItemMeta meta, JsonObject json, boolean meta2json) public void transferMetaSpecific(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
if (meta instanceof BookMeta) if (meta instanceof BookMeta)
{ {
this.transferBook((BookMeta) meta, json, meta2json); this.transferBook(stack, json, meta2json, (BookMeta)meta);
} }
else if (meta instanceof LeatherArmorMeta) else if (meta instanceof LeatherArmorMeta)
{ {
this.transferLeatherArmor((LeatherArmorMeta) meta, json, meta2json); this.transferLeatherArmor(stack, json, meta2json, (LeatherArmorMeta)meta);
} }
else if (meta instanceof MapMeta) else if (meta instanceof MapMeta)
{ {
this.transferMap((MapMeta) meta, json, meta2json); this.transferMap(stack, json, meta2json, (MapMeta)meta);
} }
else if (meta instanceof PotionMeta) else if (meta instanceof PotionMeta)
{ {
this.transferPotion((PotionMeta) meta, json, meta2json); this.transferPotion(stack, json, meta2json, (PotionMeta)meta);
} }
else if (meta instanceof SkullMeta) else if (meta instanceof SkullMeta)
{ {
this.transferSkull((SkullMeta) meta, json, meta2json); this.transferSkull(stack, json, meta2json, (SkullMeta)meta);
} }
else if (meta instanceof FireworkEffectMeta) else if (meta instanceof FireworkEffectMeta)
{ {
this.transferFireworkEffect((FireworkEffectMeta) meta, json, meta2json); this.transferFireworkEffect(stack, json, meta2json, (FireworkEffectMeta)meta);
} }
else if (meta instanceof FireworkMeta) else if (meta instanceof FireworkMeta)
{ {
this.transferFirework((FireworkMeta) meta, json, meta2json); this.transferFirework(stack, json, meta2json, (FireworkMeta)meta);
} }
else if (meta instanceof EnchantmentStorageMeta) else if (meta instanceof EnchantmentStorageMeta)
{ {
this.transferEnchantmentStorage((EnchantmentStorageMeta) meta, json, meta2json); this.transferEnchantmentStorage(stack, json, meta2json, (EnchantmentStorageMeta)meta);
} }
} }
@ -366,14 +380,14 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// SPECIFIC META: BOOK // SPECIFIC META: BOOK
// -------------------------------------------- // // -------------------------------------------- //
public void transferBook(BookMeta meta, JsonObject json, boolean meta2json) public void transferBook(ItemStack stack, JsonObject json, boolean meta2json, BookMeta meta)
{ {
this.transferTitle(meta, json, meta2json); this.transferTitle(stack, json, meta2json, meta);
this.transferAuthor(meta, json, meta2json); this.transferAuthor(stack, json, meta2json, meta);
this.transferPages(meta, json, meta2json); this.transferPages(stack, json, meta2json, meta);
} }
public void transferTitle(BookMeta meta, JsonObject json, boolean meta2json) public void transferTitle(ItemStack stack, JsonObject json, boolean meta2json, BookMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -388,7 +402,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
} }
} }
public void transferAuthor(BookMeta meta, JsonObject json, boolean meta2json) public void transferAuthor(ItemStack stack, JsonObject json, boolean meta2json, BookMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -403,7 +417,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
} }
} }
public void transferPages(BookMeta meta, JsonObject json, boolean meta2json) public void transferPages(ItemStack stack, JsonObject json, boolean meta2json, BookMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -430,7 +444,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// SPECIFIC META: LEATHER ARMOR // SPECIFIC META: LEATHER ARMOR
// -------------------------------------------- // // -------------------------------------------- //
public void transferLeatherArmor(LeatherArmorMeta meta, JsonObject json, boolean meta2json) public void transferLeatherArmor(ItemStack stack, JsonObject json, boolean meta2json, LeatherArmorMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -452,7 +466,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// SPECIFIC META: MAP // SPECIFIC META: MAP
// -------------------------------------------- // // -------------------------------------------- //
public void transferMap(MapMeta meta, JsonObject json, boolean meta2json) public void transferMap(ItemStack stack, JsonObject json, boolean meta2json, MapMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -472,7 +486,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// SPECIFIC META: POTION // SPECIFIC META: POTION
// -------------------------------------------- // // -------------------------------------------- //
public void transferPotion(PotionMeta meta, JsonObject json, boolean meta2json) public void transferPotion(ItemStack stack, JsonObject json, boolean meta2json, PotionMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -497,7 +511,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// SPECIFIC META: SKULL // SPECIFIC META: SKULL
// -------------------------------------------- // // -------------------------------------------- //
public void transferSkull(SkullMeta meta, JsonObject json, boolean meta2json) public void transferSkull(ItemStack stack, JsonObject json, boolean meta2json, SkullMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -516,7 +530,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// SPECIFIC META: FIREWORK EFFECT // SPECIFIC META: FIREWORK EFFECT
// -------------------------------------------- // // -------------------------------------------- //
public void transferFireworkEffect(FireworkEffectMeta meta, JsonObject json, boolean meta2json) public void transferFireworkEffect(ItemStack stack, JsonObject json, boolean meta2json, FireworkEffectMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -535,13 +549,13 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// SPECIFIC META: FIREWORK // SPECIFIC META: FIREWORK
// -------------------------------------------- // // -------------------------------------------- //
public void transferFirework(FireworkMeta meta, JsonObject json, boolean meta2json) public void transferFirework(ItemStack stack, JsonObject json, boolean meta2json, FireworkMeta meta)
{ {
this.transferFireworkEffects(meta, json, meta2json); this.transferFireworkEffects(stack, json, meta2json, meta);
this.transferFireworkPower(meta, json, meta2json); this.transferFireworkPower(stack, json, meta2json, meta);
} }
public void transferFireworkEffects(FireworkMeta meta, JsonObject json, boolean meta2json) public void transferFireworkEffects(ItemStack stack, JsonObject json, boolean meta2json, FireworkMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -557,7 +571,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
} }
} }
public void transferFireworkPower(FireworkMeta meta, JsonObject json, boolean meta2json) public void transferFireworkPower(ItemStack stack, JsonObject json, boolean meta2json, FireworkMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -575,7 +589,7 @@ public class ItemStackAdapterInnerV1_7 implements ItemStackAdapterInner
// SPECIFIC META: ENCHANTMENT STORAGE // SPECIFIC META: ENCHANTMENT STORAGE
// -------------------------------------------- // // -------------------------------------------- //
public void transferEnchantmentStorage(EnchantmentStorageMeta meta, JsonObject json, boolean meta2json) public void transferEnchantmentStorage(ItemStack stack, JsonObject json, boolean meta2json, EnchantmentStorageMeta meta)
{ {
if (meta2json) if (meta2json)
{ {

View File

@ -8,9 +8,11 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType; import org.bukkit.block.banner.PatternType;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
@ -23,7 +25,7 @@ import com.massivecraft.massivecore.xlib.gson.JsonObject;
import com.massivecraft.massivecore.xlib.gson.JsonPrimitive; import com.massivecraft.massivecore.xlib.gson.JsonPrimitive;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7 public class ItemStackAdapterInner18 extends ItemStackAdapterInner17
{ {
// -------------------------------------------- // // -------------------------------------------- //
// CONSTANTS: NAMES // CONSTANTS: NAMES
@ -40,26 +42,38 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public static ItemStackAdapterInnerV1_8 i = new ItemStackAdapterInnerV1_8(); public static ItemStackAdapterInner18 i = new ItemStackAdapterInner18();
public static ItemStackAdapterInnerV1_8 get() { return i; } public static ItemStackAdapterInner18 get() { return i; }
// -------------------------------------------- //
// PROVOKE
// -------------------------------------------- //
@Override
public Object provoke()
{
ItemStack stack = new ItemStack(Material.STONE);
ItemMeta meta = stack.getItemMeta();
return meta.spigot().isUnbreakable();
}
// -------------------------------------------- // // -------------------------------------------- //
// UNSPECIFIC META // UNSPECIFIC META
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void transferMetaUnspecific(ItemMeta meta, JsonObject json, boolean meta2json) public void transferMetaUnspecific(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
super.transferMetaUnspecific(meta, json, meta2json); super.transferMetaUnspecific(stack, json, meta2json, meta);
this.transferUnbreakable(meta, json, meta2json); this.transferUnbreakable(stack, json, meta2json, meta);
this.transferItemFlags(meta, json, meta2json); this.transferItemFlags(stack, json, meta2json, meta);
} }
// -------------------------------------------- // // -------------------------------------------- //
// UNSPECIFIC META: UNBREAKABLE // UNSPECIFIC META: UNBREAKABLE
// -------------------------------------------- // // -------------------------------------------- //
public void transferUnbreakable(ItemMeta meta, JsonObject json, boolean meta2json) public void transferUnbreakable(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -79,7 +93,7 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7
// UNSPECIFIC META: ITEM FLAGS // UNSPECIFIC META: ITEM FLAGS
// -------------------------------------------- // // -------------------------------------------- //
public void transferItemFlags(ItemMeta meta, JsonObject json, boolean meta2json) public void transferItemFlags(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -144,15 +158,15 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void transferMetaSpecific(ItemMeta meta, JsonObject json, boolean meta2json) public void transferMetaSpecific(ItemStack stack, JsonObject json, boolean meta2json, ItemMeta meta)
{ {
if (meta instanceof BannerMeta) if (meta instanceof BannerMeta)
{ {
this.transferBanner((BannerMeta) meta, json, meta2json); this.transferBanner(stack, json, meta2json, (BannerMeta)meta);
} }
else else
{ {
super.transferMetaSpecific(meta, json, meta2json); super.transferMetaSpecific(stack, json, meta2json, meta);
} }
} }
@ -165,7 +179,7 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7
// Different servers might serialize different heads differently. // Different servers might serialize different heads differently.
@Override @Override
public void transferSkull(SkullMeta meta, JsonObject json, boolean meta2json) public void transferSkull(ItemStack stack, JsonObject json, boolean meta2json, SkullMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -198,17 +212,17 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7
// SPECIFIC META: BANNER // SPECIFIC META: BANNER
// -------------------------------------------- // // -------------------------------------------- //
public void transferBanner(BannerMeta meta, JsonObject json, boolean meta2json) public void transferBanner(ItemStack stack, JsonObject json, boolean meta2json, BannerMeta meta)
{ {
this.transferBannerBase(meta, json, meta2json); this.transferBannerBase(stack, json, meta2json, meta);
this.transferBannerPatterns(meta, json, meta2json); this.transferBannerPatterns(stack, json, meta2json, meta);
} }
// -------------------------------------------- // // -------------------------------------------- //
// SPECIFIC META: BANNER BASE // SPECIFIC META: BANNER BASE
// -------------------------------------------- // // -------------------------------------------- //
public void transferBannerBase(BannerMeta meta, JsonObject json, boolean meta2json) public void transferBannerBase(ItemStack stack, JsonObject json, boolean meta2json, BannerMeta meta)
{ {
if (meta2json) if (meta2json)
{ {
@ -235,7 +249,7 @@ public class ItemStackAdapterInnerV1_8 extends ItemStackAdapterInnerV1_7
// SPECIFIC META: BANNER PATTERNS // SPECIFIC META: BANNER PATTERNS
// -------------------------------------------- // // -------------------------------------------- //
public void transferBannerPatterns(BannerMeta meta, JsonObject json, boolean meta2json) public void transferBannerPatterns(ItemStack stack, JsonObject json, boolean meta2json, BannerMeta meta)
{ {
if (meta2json) if (meta2json)
{ {

View File

@ -0,0 +1,46 @@
package com.massivecraft.massivecore.adapter;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import com.massivecraft.massivecore.xlib.gson.JsonObject;
public class ItemStackAdapterInner19 extends ItemStackAdapterInner18
{
// -------------------------------------------- //
// CONSTANTS: NAMES
// -------------------------------------------- //
public static final String POTION = "potion";
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public static ItemStackAdapterInner19 i = new ItemStackAdapterInner19();
public static ItemStackAdapterInner19 get() { return i; }
// -------------------------------------------- //
// PROVOKE
// -------------------------------------------- //
@Override
public Object provoke()
{
return PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT;
}
// -------------------------------------------- //
// SPECIFIC META: POTION
// -------------------------------------------- //
@Override
public void transferPotion(ItemStack stack, JsonObject json, boolean meta2json, PotionMeta meta)
{
super.transferPotion(stack, json, meta2json, meta);
// TODO: Handle new potions here.
// TODO: Awaiting the pull request by t00thp1ck.
}
}