Fix TypeTransformer bad read override. Manually set classes in ItemStack system.
This commit is contained in:
parent
1a20951ef6
commit
792c379542
@ -2,7 +2,6 @@ package com.massivecraft.massivecore.command.type;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeObject;
|
||||
import com.massivecraft.massivecore.item.DataItemStack;
|
||||
|
||||
@ -36,25 +35,13 @@ public class TypeDataItemStack extends TypeTransformer<ItemStack, DataItemStack>
|
||||
@Override
|
||||
public DataItemStack innerToOuter(ItemStack inner)
|
||||
{
|
||||
// TODO: Why on earth doesn't this line work.
|
||||
DataItemStack outer = DataItemStack.fromBukkit(inner);
|
||||
|
||||
System.out.println("1 from inner: " + inner);
|
||||
System.out.println("2 to outer: " + outer.getId());
|
||||
System.out.println("3 to outer: " + MassiveCore.get().getGson().toJson(outer, DataItemStack.class));
|
||||
|
||||
return outer;
|
||||
return DataItemStack.fromBukkit(inner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack outerToInner(DataItemStack outer)
|
||||
{
|
||||
ItemStack inner = DataItemStack.toBukkit(outer);
|
||||
|
||||
System.out.println("from outer: " + MassiveCore.get().getGson().toJson(outer, DataItemStack.class));
|
||||
System.out.println("to inner: " + inner);
|
||||
|
||||
return inner;
|
||||
return DataItemStack.toBukkit(outer);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -255,30 +255,6 @@ public abstract class TypeTransformer<I, O> extends TypeAbstract<O>
|
||||
return outer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public O read(CommandSender sender) throws MassiveException
|
||||
{
|
||||
I inner = INNER.read(sender);
|
||||
O outer = innerToOuter(inner);
|
||||
return outer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public O read(String arg) throws MassiveException
|
||||
{
|
||||
I inner = INNER.read(arg);
|
||||
O outer = innerToOuter(inner);
|
||||
return outer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public O read() throws MassiveException
|
||||
{
|
||||
I inner = INNER.read();
|
||||
O outer = innerToOuter(inner);
|
||||
return outer;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// VALID
|
||||
// -------------------------------------------- //
|
||||
|
@ -24,6 +24,16 @@ import com.massivecraft.massivecore.util.Txt;
|
||||
//
|
||||
public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB, D> extends Engine
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstract(Class<CA> classCA, Class<CB> classCB)
|
||||
{
|
||||
this.classCA = classCA;
|
||||
this.classCB = classCB;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITERS
|
||||
// -------------------------------------------- //
|
||||
@ -169,22 +179,12 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB, D> extends Engine
|
||||
// -------------------------------------------- //
|
||||
// CLASSES
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Class<?> classOA = null;
|
||||
public Class<?> getClassOA() { return this.classOA; }
|
||||
public void setClassOA(Class<?> classOA) { this.classOA = classOA; }
|
||||
|
||||
private Class<?> classOB = null;
|
||||
public Class<?> getClassOB() { return this.classOB; }
|
||||
public void setClassOB(Class<?> classOB) { this.classOB = classOB; }
|
||||
|
||||
private Class<?> classCA = null;
|
||||
public Class<?> getClassCA() { return this.classCA; }
|
||||
public void setClassCA(Class<?> classCA) { this.classCA = classCA; }
|
||||
private final Class<CA> classCA;
|
||||
public Class<CA> getClassCA() { return this.classCA; }
|
||||
|
||||
private Class<?> classCB = null;
|
||||
public Class<?> getClassCB() { return this.classCB; }
|
||||
public void setClassCB(Class<?> classCB) { this.classCB = classCB; }
|
||||
private final Class<CB> classCB;
|
||||
public Class<CB> getClassCB() { return this.classCB; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MORPH
|
||||
@ -222,10 +222,6 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB, D> extends Engine
|
||||
if (oa == null) throw new NullPointerException("Couldn't Create OA");
|
||||
if (ob == null) throw new NullPointerException("Couldn't Create OB");
|
||||
|
||||
// Class O
|
||||
this.setClassOA(oa.getClass());
|
||||
this.setClassOB(ob.getClass());
|
||||
|
||||
// Morph
|
||||
CA ca = this.morphA(oa);
|
||||
CB cb = this.morphB(ob);
|
||||
@ -234,10 +230,6 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB, D> extends Engine
|
||||
if (ca == null) throw new NullPointerException("Couldn't Create CA");
|
||||
if (cb == null) throw new NullPointerException("Couldn't Create CB");
|
||||
|
||||
// Class C
|
||||
this.setClassCA(ca.getClass());
|
||||
this.setClassCB(cb.getClass());
|
||||
|
||||
// Write (to provoke extra much)
|
||||
this.write(oa, ob, true);
|
||||
this.write(oa, ob, false);
|
||||
|
@ -7,6 +7,15 @@ import com.massivecraft.massivecore.nms.NmsItemStack;
|
||||
|
||||
public abstract class WriterAbstractItemStack<OB, CB, FA, FB> extends WriterAbstract<DataItemStack, OB, DataItemStack, CB, FA, FB, ItemStack>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStack(Class<CB> classCB)
|
||||
{
|
||||
super(DataItemStack.class, classCB);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
@ -6,5 +6,13 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public abstract class WriterAbstractItemStackField<FA, FB> extends WriterAbstractItemStack<ItemStack, ItemStack, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackField()
|
||||
{
|
||||
super(ItemStack.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,15 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMeta<OB, CB, FA, FB> extends WriterAbstractItemStack<OB, CB, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackMeta(Class<CB> classCB)
|
||||
{
|
||||
super(classCB);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE INNER
|
||||
// -------------------------------------------- //
|
||||
|
@ -4,6 +4,15 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaField<CB, FA, FB> extends WriterAbstractItemStackMeta<ItemMeta, CB, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackMetaField(Class<CB> classCB)
|
||||
{
|
||||
super(classCB);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
@ -4,7 +4,16 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaMorph<FA, FB> extends WriterAbstractItemStackMeta<ItemStack, ItemMeta, FA, FB>
|
||||
{
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackMetaMorph()
|
||||
{
|
||||
super(ItemMeta.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MORPH
|
||||
// -------------------------------------------- //
|
||||
|
@ -11,8 +11,10 @@ public abstract class WriterAbstractItemStackMetaState<OB, CB, FA, FB> extends W
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackMetaState()
|
||||
public WriterAbstractItemStackMetaState(Class<CB> classCB)
|
||||
{
|
||||
super(classCB);
|
||||
|
||||
// For the setup to pass we must set a Material with a BlockStateMeta.
|
||||
this.setMaterial(Material.SHIELD);
|
||||
}
|
||||
|
@ -2,8 +2,17 @@ package com.massivecraft.massivecore.item;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaStateField<S, FA, FB> extends WriterAbstractItemStackMetaState<BlockState, S, FA, FB>
|
||||
public abstract class WriterAbstractItemStackMetaStateField<CB, FA, FB> extends WriterAbstractItemStackMetaState<BlockState, CB, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackMetaStateField(Class<CB> classCB)
|
||||
{
|
||||
super(classCB);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
@ -7,6 +7,15 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class WriterAbstractItemStackMetaStateMorph<FA, FB> extends WriterAbstractItemStackMetaState<ItemMeta, BlockState, FA, FB>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public WriterAbstractItemStackMetaStateMorph()
|
||||
{
|
||||
super(BlockState.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CREATE
|
||||
// -------------------------------------------- //
|
||||
|
@ -18,6 +18,7 @@ public abstract class WriterAbstractReflect<OA, OB, CA, CB, FA, FB> extends Writ
|
||||
|
||||
public WriterAbstractReflect(Class<?> clazz, String fieldName)
|
||||
{
|
||||
super(null, null);
|
||||
this.field = (fieldName == null ? null : ReflectionUtil.getField(clazz, fieldName));
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,10 @@ public class WriterItemStackMetaAuthor extends WriterAbstractItemStackMetaField<
|
||||
|
||||
private static final WriterItemStackMetaAuthor i = new WriterItemStackMetaAuthor();
|
||||
public static WriterItemStackMetaAuthor get() { return i; }
|
||||
|
||||
public WriterItemStackMetaAuthor()
|
||||
{
|
||||
super(BookMeta.class);
|
||||
this.setMaterial(Material.WRITTEN_BOOK);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ public class WriterItemStackMetaBannerBase extends WriterAbstractItemStackMetaFi
|
||||
public static WriterItemStackMetaBannerBase get() { return i; }
|
||||
public WriterItemStackMetaBannerBase()
|
||||
{
|
||||
super(BannerMeta.class);
|
||||
this.setMaterial(Material.BANNER);
|
||||
this.setConverterTo(ConverterToDyeColor.get());
|
||||
this.setConverterFrom(ConverterFromDyeColor.get());
|
||||
|
@ -15,7 +15,9 @@ public class WriterItemStackMetaBannerPatterns extends WriterAbstractItemStackMe
|
||||
|
||||
private static final WriterItemStackMetaBannerPatterns i = new WriterItemStackMetaBannerPatterns();
|
||||
public static WriterItemStackMetaBannerPatterns get() { return i; }
|
||||
public WriterItemStackMetaBannerPatterns()
|
||||
{
|
||||
super(BannerMeta.class);
|
||||
this.setMaterial(Material.BANNER);
|
||||
this.setConverterTo(ConverterToBannerPatterns.get());
|
||||
this.setConverterFrom(ConverterFromBannerPatterns.get());
|
||||
|
@ -13,7 +13,10 @@ public class WriterItemStackMetaColor extends WriterAbstractItemStackMetaField<L
|
||||
|
||||
private static final WriterItemStackMetaColor i = new WriterItemStackMetaColor();
|
||||
public static WriterItemStackMetaColor get() { return i; }
|
||||
|
||||
public WriterItemStackMetaColor()
|
||||
{
|
||||
super(LeatherArmorMeta.class);
|
||||
this.setMaterial(Material.LEATHER_HELMET);
|
||||
this.setConverterTo(ConverterToColor.get());
|
||||
this.setConverterFrom(ConverterFromColor.get());
|
||||
|
@ -17,6 +17,7 @@ public class WriterItemStackMetaEnchants extends WriterAbstractItemStackMetaFiel
|
||||
public static WriterItemStackMetaEnchants get() { return i; }
|
||||
public WriterItemStackMetaEnchants()
|
||||
{
|
||||
super(ItemMeta.class);
|
||||
this.setConverterTo(ConverterToEnchants.get());
|
||||
this.setConverterFrom(ConverterFromEnchants.get());
|
||||
}
|
||||
|
@ -13,7 +13,9 @@ public class WriterItemStackMetaFireworkEffect extends WriterAbstractItemStackMe
|
||||
|
||||
private static final WriterItemStackMetaFireworkEffect i = new WriterItemStackMetaFireworkEffect();
|
||||
public static WriterItemStackMetaFireworkEffect get() { return i; }
|
||||
public WriterItemStackMetaFireworkEffect()
|
||||
{
|
||||
super(FireworkEffectMeta.class);
|
||||
this.setMaterial(Material.FIREWORK_CHARGE);
|
||||
this.setConverterTo(ConverterToFireworkEffect.get());
|
||||
this.setConverterFrom(ConverterFromFireworkEffect.get());
|
||||
|
@ -15,7 +15,9 @@ public class WriterItemStackMetaFireworkEffects extends WriterAbstractItemStackM
|
||||
|
||||
private static final WriterItemStackMetaFireworkEffects i = new WriterItemStackMetaFireworkEffects();
|
||||
public static WriterItemStackMetaFireworkEffects get() { return i; }
|
||||
public WriterItemStackMetaFireworkEffects()
|
||||
{
|
||||
super(FireworkMeta.class);
|
||||
this.setMaterial(Material.FIREWORK);
|
||||
this.setConverterTo(ConverterToFireworkEffects.get());
|
||||
this.setConverterFrom(ConverterFromFireworkEffects.get());
|
||||
|
@ -12,7 +12,9 @@ public class WriterItemStackMetaFireworkFlight extends WriterAbstractItemStackMe
|
||||
|
||||
private static final WriterItemStackMetaFireworkFlight i = new WriterItemStackMetaFireworkFlight();
|
||||
public static WriterItemStackMetaFireworkFlight get() { return i; }
|
||||
public WriterItemStackMetaFireworkFlight()
|
||||
{
|
||||
super(FireworkMeta.class);
|
||||
this.setMaterial(Material.FIREWORK);
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ public class WriterItemStackMetaFlags extends WriterAbstractItemStackMetaField<I
|
||||
public static WriterItemStackMetaFlags get() { return i; }
|
||||
public WriterItemStackMetaFlags()
|
||||
{
|
||||
super(ItemMeta.class);
|
||||
this.setConverterTo(ConverterToItemFlags.get());
|
||||
this.setConverterFrom(ConverterFromItemFlags.get());
|
||||
}
|
||||
|
@ -13,6 +13,10 @@ public class WriterItemStackMetaLore extends WriterAbstractItemStackMetaField<It
|
||||
|
||||
private static final WriterItemStackMetaLore i = new WriterItemStackMetaLore();
|
||||
public static WriterItemStackMetaLore get() { return i; }
|
||||
public WriterItemStackMetaLore()
|
||||
{
|
||||
super(ItemMeta.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
|
@ -11,6 +11,10 @@ public class WriterItemStackMetaName extends WriterAbstractItemStackMetaField<It
|
||||
|
||||
private static final WriterItemStackMetaName i = new WriterItemStackMetaName();
|
||||
public static WriterItemStackMetaName get() { return i; }
|
||||
public WriterItemStackMetaName()
|
||||
{
|
||||
super(ItemMeta.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
|
@ -14,7 +14,9 @@ public class WriterItemStackMetaPages extends WriterAbstractItemStackMetaField<B
|
||||
|
||||
private static final WriterItemStackMetaPages i = new WriterItemStackMetaPages();
|
||||
public static WriterItemStackMetaPages get() { return i; }
|
||||
public WriterItemStackMetaPages()
|
||||
{
|
||||
super(BookMeta.class);
|
||||
this.setMaterial(Material.WRITTEN_BOOK);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,9 @@ public class WriterItemStackMetaPotion extends WriterAbstractItemStackMetaField<
|
||||
|
||||
private static final WriterItemStackMetaPotion i = new WriterItemStackMetaPotion();
|
||||
public static WriterItemStackMetaPotion get() { return i; }
|
||||
public WriterItemStackMetaPotion()
|
||||
{
|
||||
super(PotionMeta.class);
|
||||
this.setMaterial(Material.POTION);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,10 @@ public class WriterItemStackMetaPotionEffects extends WriterAbstractItemStackMet
|
||||
|
||||
private static final WriterItemStackMetaPotionEffects i = new WriterItemStackMetaPotionEffects();
|
||||
public static WriterItemStackMetaPotionEffects get() { return i; }
|
||||
|
||||
public WriterItemStackMetaPotionEffects()
|
||||
{
|
||||
super(PotionMeta.class);
|
||||
this.setMaterial(Material.POTION);
|
||||
this.setConverterTo(ConverterToPotionEffects.get());
|
||||
this.setConverterFrom(ConverterFromPotionEffects.get());
|
||||
|
@ -12,7 +12,9 @@ public class WriterItemStackMetaRepaircost extends WriterAbstractItemStackMetaFi
|
||||
|
||||
private static final WriterItemStackMetaRepaircost i = new WriterItemStackMetaRepaircost();
|
||||
public static WriterItemStackMetaRepaircost get() { return i; }
|
||||
public WriterItemStackMetaRepaircost()
|
||||
{
|
||||
super(Repairable.class);
|
||||
this.setMaterial(Material.IRON_CHESTPLATE);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,9 @@ public class WriterItemStackMetaScaling extends WriterAbstractItemStackMetaField
|
||||
|
||||
private static final WriterItemStackMetaScaling i = new WriterItemStackMetaScaling();
|
||||
public static WriterItemStackMetaScaling get() { return i; }
|
||||
public WriterItemStackMetaScaling()
|
||||
{
|
||||
super(MapMeta.class);
|
||||
this.setMaterial(Material.MAP);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ public class WriterItemStackMetaSkull17 extends WriterAbstractItemStackMetaField
|
||||
public static WriterItemStackMetaSkull17 get() { return i; }
|
||||
public WriterItemStackMetaSkull17()
|
||||
{
|
||||
super(SkullMeta.class);
|
||||
this.setMaterial(Material.SKULL_ITEM);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ public class WriterItemStackMetaSkull18 extends WriterAbstractItemStackMetaField
|
||||
public static WriterItemStackMetaSkull18 get() { return i; }
|
||||
public WriterItemStackMetaSkull18()
|
||||
{
|
||||
super(SkullMeta.class);
|
||||
this.setMaterial(Material.SKULL_ITEM);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ public class WriterItemStackMetaStateShieldBase extends WriterAbstractItemStackM
|
||||
public static WriterItemStackMetaStateShieldBase get() { return i; }
|
||||
public WriterItemStackMetaStateShieldBase()
|
||||
{
|
||||
super(Banner.class);
|
||||
this.setMaterial(Material.SHIELD);
|
||||
this.setConverterTo(ConverterToDyeColor.get());
|
||||
this.setConverterFrom(ConverterFromDyeColor.get());
|
||||
|
@ -15,7 +15,10 @@ public class WriterItemStackMetaStateShieldPatterns extends WriterAbstractItemSt
|
||||
|
||||
private static final WriterItemStackMetaStateShieldPatterns i = new WriterItemStackMetaStateShieldPatterns();
|
||||
public static WriterItemStackMetaStateShieldPatterns get() { return i; }
|
||||
|
||||
public WriterItemStackMetaStateShieldPatterns()
|
||||
{
|
||||
super(Banner.class);
|
||||
this.setMaterial(Material.SHIELD);
|
||||
this.setConverterTo(ConverterToBannerPatterns.get());
|
||||
this.setConverterFrom(ConverterFromBannerPatterns.get());
|
||||
|
@ -18,6 +18,7 @@ public class WriterItemStackMetaStoredEnchants extends WriterAbstractItemStackMe
|
||||
public static WriterItemStackMetaStoredEnchants get() { return i; }
|
||||
public WriterItemStackMetaStoredEnchants()
|
||||
{
|
||||
super(EnchantmentStorageMeta.class);
|
||||
this.setMaterial(Material.ENCHANTED_BOOK);
|
||||
this.setConverterTo(ConverterToEnchants.get());
|
||||
this.setConverterFrom(ConverterFromEnchants.get());
|
||||
|
@ -12,7 +12,9 @@ public class WriterItemStackMetaTitle extends WriterAbstractItemStackMetaField<B
|
||||
|
||||
private static final WriterItemStackMetaTitle i = new WriterItemStackMetaTitle();
|
||||
public static WriterItemStackMetaTitle get() { return i; }
|
||||
public WriterItemStackMetaTitle()
|
||||
{
|
||||
super(BookMeta.class);
|
||||
this.setMaterial(Material.WRITTEN_BOOK);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,10 @@ public class WriterItemStackMetaUnbreakable extends WriterAbstractItemStackMetaF
|
||||
|
||||
private static final WriterItemStackMetaUnbreakable i = new WriterItemStackMetaUnbreakable();
|
||||
public static WriterItemStackMetaUnbreakable get() { return i; }
|
||||
public WriterItemStackMetaUnbreakable()
|
||||
{
|
||||
super(ItemMeta.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ACCESS
|
||||
|
Loading…
Reference in New Issue
Block a user