From 1838c9c2ab33c7f20f78341f2ff97594708b025a Mon Sep 17 00:00:00 2001 From: ulumulu1510 Date: Mon, 30 Jan 2017 19:26:13 +0100 Subject: [PATCH] Add potion & map color fields to DataItemStack. --- itemstackformat.txt | 2 + .../massivecore/item/DataItemStack.java | 38 +++++++++++-- .../massivecore/item/WriterItemStackMeta.java | 2 + .../item/WriterItemStackMetaMapColor.java | 53 +++++++++++++++++++ .../item/WriterItemStackMetaPotionColor.java | 53 +++++++++++++++++++ 5 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 src/com/massivecraft/massivecore/item/WriterItemStackMetaMapColor.java create mode 100644 src/com/massivecraft/massivecore/item/WriterItemStackMetaPotionColor.java diff --git a/itemstackformat.txt b/itemstackformat.txt index 567fc079..412b6efd 100644 --- a/itemstackformat.txt +++ b/itemstackformat.txt @@ -42,6 +42,8 @@ author: str pages: [str] map_is_scaling: byte + potionColor: int + mapColor: int SkullOwner: str CustomPotionEffects: [ diff --git a/src/com/massivecraft/massivecore/item/DataItemStack.java b/src/com/massivecraft/massivecore/item/DataItemStack.java index 20324b19..3ea7d6f4 100644 --- a/src/com/massivecraft/massivecore/item/DataItemStack.java +++ b/src/com/massivecraft/massivecore/item/DataItemStack.java @@ -81,6 +81,8 @@ public class DataItemStack implements Comparable public static final transient List DEFAULT_BANNER_PATTERNS = Collections.emptyList(); public static final transient String DEFAULT_POTION = "water"; public static final transient Map DEFAULT_INVENTORY = Collections.emptyMap(); + public static final transient Integer DEFAULT_POTION_COLOR = null; + public static final transient Integer DEFAULT_MAP_COLOR = null; // -------------------------------------------- // // FIELDS > BASIC @@ -276,6 +278,26 @@ public class DataItemStack implements Comparable public Map getInventory() { return get(this.inventory, DEFAULT_INVENTORY); } public DataItemStack setInventory(Map inventory) { this.inventory = set(inventory, DEFAULT_INVENTORY); return this; } + // -------------------------------------------- // + // FIELDS > POTION COLOR + // -------------------------------------------- // + // SINCE: 1.11 + + @EditorType(TypeConverterColor.class) + private Integer potionColor = null; + public Integer getPotionColor() { return get(this.potionColor, DEFAULT_POTION_COLOR); } + public DataItemStack setPotionColor(Integer potionColor) { this.potionColor = set(potionColor, DEFAULT_POTION_COLOR); return this; } + + // -------------------------------------------- // + // FIELDS > MAP COLOR + // -------------------------------------------- // + // Since 1.11 + + @EditorType(TypeConverterColor.class) + private Integer mapColor = null; + public Integer getMapColor() { return get(this.mapColor, DEFAULT_MAP_COLOR); } + public DataItemStack setMapColor(Integer mapColor) { this.mapColor = set(mapColor, DEFAULT_MAP_COLOR); return this; } + // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // @@ -481,7 +503,9 @@ public class DataItemStack implements Comparable this.getBannerBase(), that.getBannerBase(), this.getBannerPatterns(), that.getBannerPatterns(), this.getPotion(), that.getPotion(), - this.getInventory(), that.getInventory() + this.getInventory(), that.getInventory(), + this.getPotionColor(), that.getPotionColor(), + this.getMapColor(), that.getMapColor() ); } @@ -514,7 +538,9 @@ public class DataItemStack implements Comparable this.getBannerBase(), that.getBannerBase(), this.getBannerPatterns(), that.getBannerPatterns(), this.getPotion(), that.getPotion(), - this.getInventory(), that.getInventory() + this.getInventory(), that.getInventory(), + this.getPotionColor(), that.getPotionColor(), + this.getMapColor(), that.getMapColor() ); } @@ -554,7 +580,9 @@ public class DataItemStack implements Comparable this.getBannerBase(), that.getBannerBase(), this.getBannerPatterns(), that.getBannerPatterns(), this.getPotion(), that.getPotion(), - this.getInventory(), that.getInventory() + this.getInventory(), that.getInventory(), + this.getPotionColor(), that.getPotionColor(), + this.getMapColor(), that.getMapColor() ); } @@ -592,7 +620,9 @@ public class DataItemStack implements Comparable this.getBannerBase(), this.getBannerPatterns(), this.getPotion(), - this.getInventory() + this.getInventory(), + this.getPotionColor(), + this.getMapColor() ); } diff --git a/src/com/massivecraft/massivecore/item/WriterItemStackMeta.java b/src/com/massivecraft/massivecore/item/WriterItemStackMeta.java index 9191c88a..c6f4be05 100644 --- a/src/com/massivecraft/massivecore/item/WriterItemStackMeta.java +++ b/src/com/massivecraft/massivecore/item/WriterItemStackMeta.java @@ -27,6 +27,7 @@ public class WriterItemStackMeta extends WriterAbstractItemStackMetaMorph +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static final WriterItemStackMetaMapColor i = new WriterItemStackMetaMapColor(); + public static WriterItemStackMetaMapColor get() { return i; } + + public WriterItemStackMetaMapColor() + { + super(MapMeta.class); + this.setMaterial(Material.MAP); + this.setConverterTo(ConverterToColor.get()); + this.setConverterFrom(ConverterFromColor.get()); + } + + // -------------------------------------------- // + // ACCESS + // -------------------------------------------- // + + @Override + public Integer getA(DataItemStack ca, ItemStack d) + { + return ca.getMapColor(); + } + + @Override + public void setA(DataItemStack ca, Integer fa, ItemStack d) + { + ca.setMapColor(fa); + } + + @Override + public Color getB(MapMeta cb, ItemStack d) + { + return cb.getColor(); + } + + @Override + public void setB(MapMeta cb, Color fb, ItemStack d) + { + cb.setColor(fb); + } + +} diff --git a/src/com/massivecraft/massivecore/item/WriterItemStackMetaPotionColor.java b/src/com/massivecraft/massivecore/item/WriterItemStackMetaPotionColor.java new file mode 100644 index 00000000..b37ab53a --- /dev/null +++ b/src/com/massivecraft/massivecore/item/WriterItemStackMetaPotionColor.java @@ -0,0 +1,53 @@ +package com.massivecraft.massivecore.item; + +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; + +public class WriterItemStackMetaPotionColor extends WriterAbstractItemStackMetaField +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static final WriterItemStackMetaPotionColor i = new WriterItemStackMetaPotionColor(); + public static WriterItemStackMetaPotionColor get() { return i; } + + public WriterItemStackMetaPotionColor() + { + super(PotionMeta.class); + this.setMaterial(Material.POTION); + this.setConverterTo(ConverterToColor.get()); + this.setConverterFrom(ConverterFromColor.get()); + } + + // -------------------------------------------- // + // ACCESS + // -------------------------------------------- // + + @Override + public Integer getA(DataItemStack ca, ItemStack d) + { + return ca.getPotionColor(); + } + + @Override + public void setA(DataItemStack ca, Integer fa, ItemStack d) + { + ca.setPotionColor(fa); + } + + @Override + public Color getB(PotionMeta cb, ItemStack d) + { + return cb.getColor(); + } + + @Override + public void setB(PotionMeta cb, Color fb, ItemStack d) + { + cb.setColor(fb); + } + +}