Reflection actually demanded ImmutableList so revert to that

This commit is contained in:
Olof Larsson 2017-12-17 14:22:00 +01:00
parent 04f6ae211f
commit 05b632e8d5
4 changed files with 67 additions and 7 deletions

View File

@ -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<EX, EY> extends Converter<Iterable<EX>, ImmutableList<EY>>
{
// -------------------------------------------- //
// FIELD
// -------------------------------------------- //
private final Converter<EX, EY> converterElement;
public Converter<EX, EY> getConverterElement() { return this.converterElement; }
// -------------------------------------------- //
// CREATE
// -------------------------------------------- //
public ConverterListImmutable(Converter<EX, EY> converterElement)
{
this.converterElement = converterElement;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public ImmutableList<EY> convert(Iterable<EX> exs)
{
// Null
if (exs == null) return null;
// Create
Builder<EY> 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();
}
}

View File

@ -2,7 +2,7 @@ package com.massivecraft.massivecore.item;
import org.bukkit.Color; import org.bukkit.Color;
public class ConverterToColors extends ConverterList<Integer, Color> public class ConverterToColors extends ConverterListImmutable<Integer, Color>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT

View File

@ -1,11 +1,12 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import com.google.common.collect.ImmutableList;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect;
import java.util.List; import java.util.List;
public class WriterFireworkEffectColors extends WriterAbstractFireworkEffect<List<Integer>, List<Color>> public class WriterFireworkEffectColors extends WriterAbstractFireworkEffect<List<Integer>, ImmutableList<Color>>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
@ -37,9 +38,9 @@ public class WriterFireworkEffectColors extends WriterAbstractFireworkEffect<Lis
} }
@Override @Override
public List<Color> getB(FireworkEffect cb, Object d) public ImmutableList<Color> getB(FireworkEffect cb, Object d)
{ {
return cb.getColors(); return (ImmutableList<Color>) cb.getColors();
} }
} }

View File

@ -1,11 +1,12 @@
package com.massivecraft.massivecore.item; package com.massivecraft.massivecore.item;
import com.google.common.collect.ImmutableList;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect;
import java.util.List; import java.util.List;
public class WriterFireworkEffectFadeColors extends WriterAbstractFireworkEffect<List<Integer>, List<Color>> public class WriterFireworkEffectFadeColors extends WriterAbstractFireworkEffect<List<Integer>, ImmutableList<Color>>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
@ -37,9 +38,9 @@ public class WriterFireworkEffectFadeColors extends WriterAbstractFireworkEffect
} }
@Override @Override
public List<Color> getB(FireworkEffect cb, Object d) public ImmutableList<Color> getB(FireworkEffect cb, Object d)
{ {
return cb.getFadeColors(); return (ImmutableList<Color>) cb.getFadeColors();
} }
} }