diff --git a/src/com/massivecraft/massivecore/item/ConverterListImmutable.java b/src/com/massivecraft/massivecore/item/ConverterListImmutable.java new file mode 100644 index 00000000..a88cf4c1 --- /dev/null +++ b/src/com/massivecraft/massivecore/item/ConverterListImmutable.java @@ -0,0 +1,58 @@ +package com.massivecraft.massivecore.item; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; + +public class ConverterListImmutable extends Converter, ImmutableList> +{ + // -------------------------------------------- // + // FIELD + // -------------------------------------------- // + + private final Converter converterElement; + public Converter getConverterElement() { return this.converterElement; } + + // -------------------------------------------- // + // CREATE + // -------------------------------------------- // + + public ConverterListImmutable(Converter converterElement) + { + this.converterElement = converterElement; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public ImmutableList convert(Iterable exs) + { + // Null + if (exs == null) return null; + + // Create + Builder eys = ImmutableList.builder(); + + // Fill + for (EX ex : exs) + { + EY ey = null; + try + { + ey = this.getConverterElement().convert(ex); + } + catch (Throwable t) + { + t.printStackTrace(); + continue; + } + + eys.add(ey); + } + + // Return + return eys.build(); + } + +} diff --git a/src/com/massivecraft/massivecore/item/ConverterToColors.java b/src/com/massivecraft/massivecore/item/ConverterToColors.java index 5eecaad7..d5de6c54 100644 --- a/src/com/massivecraft/massivecore/item/ConverterToColors.java +++ b/src/com/massivecraft/massivecore/item/ConverterToColors.java @@ -2,7 +2,7 @@ package com.massivecraft.massivecore.item; import org.bukkit.Color; -public class ConverterToColors extends ConverterList +public class ConverterToColors extends ConverterListImmutable { // -------------------------------------------- // // INSTANCE & CONSTRUCT diff --git a/src/com/massivecraft/massivecore/item/WriterFireworkEffectColors.java b/src/com/massivecraft/massivecore/item/WriterFireworkEffectColors.java index 5099c94f..bc6dbd79 100644 --- a/src/com/massivecraft/massivecore/item/WriterFireworkEffectColors.java +++ b/src/com/massivecraft/massivecore/item/WriterFireworkEffectColors.java @@ -1,11 +1,12 @@ package com.massivecraft.massivecore.item; +import com.google.common.collect.ImmutableList; import org.bukkit.Color; import org.bukkit.FireworkEffect; import java.util.List; -public class WriterFireworkEffectColors extends WriterAbstractFireworkEffect, List> +public class WriterFireworkEffectColors extends WriterAbstractFireworkEffect, ImmutableList> { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -37,9 +38,9 @@ public class WriterFireworkEffectColors extends WriterAbstractFireworkEffect getB(FireworkEffect cb, Object d) + public ImmutableList getB(FireworkEffect cb, Object d) { - return cb.getColors(); + return (ImmutableList) cb.getColors(); } } diff --git a/src/com/massivecraft/massivecore/item/WriterFireworkEffectFadeColors.java b/src/com/massivecraft/massivecore/item/WriterFireworkEffectFadeColors.java index 22e853f7..cd33a7b9 100644 --- a/src/com/massivecraft/massivecore/item/WriterFireworkEffectFadeColors.java +++ b/src/com/massivecraft/massivecore/item/WriterFireworkEffectFadeColors.java @@ -1,11 +1,12 @@ package com.massivecraft.massivecore.item; +import com.google.common.collect.ImmutableList; import org.bukkit.Color; import org.bukkit.FireworkEffect; import java.util.List; -public class WriterFireworkEffectFadeColors extends WriterAbstractFireworkEffect, List> +public class WriterFireworkEffectFadeColors extends WriterAbstractFireworkEffect, ImmutableList> { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -37,9 +38,9 @@ public class WriterFireworkEffectFadeColors extends WriterAbstractFireworkEffect } @Override - public List getB(FireworkEffect cb, Object d) + public ImmutableList getB(FireworkEffect cb, Object d) { - return cb.getFadeColors(); + return (ImmutableList) cb.getFadeColors(); } }