Fix backstringenumset to play nice with the editor.

This commit is contained in:
TheComputerGeek2 2017-02-25 18:57:40 -08:00
parent 7fd631bebe
commit 71436bb935
5 changed files with 76 additions and 1 deletions

View File

@ -67,5 +67,11 @@ public class BackstringEnumSet<T extends Enum<?>> extends BackstringSet<T>
return t.toString(); return t.toString();
} }
@Override
public Map<String, T> getStringToTypeMap()
{
return this.name2enum;
}
} }

View File

@ -2,6 +2,7 @@ package com.massivecraft.massivecore.collections;
import java.util.Iterator; import java.util.Iterator;
@Deprecated
public class BackstringIterator<E> implements Iterator<E> public class BackstringIterator<E> implements Iterator<E>
{ {
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -1,10 +1,13 @@
package com.massivecraft.massivecore.collections; package com.massivecraft.massivecore.collections;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
public abstract class BackstringSet<T> extends AbstractSet<T> public abstract class BackstringSet<T> extends AbstractSet<T>
@ -23,6 +26,8 @@ public abstract class BackstringSet<T> extends AbstractSet<T>
public abstract T convertFromString(String string); public abstract T convertFromString(String string);
public abstract String convertToString(Object t); public abstract String convertToString(Object t);
public abstract Map<String, T> getStringToTypeMap();
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
@ -55,7 +60,21 @@ public abstract class BackstringSet<T> extends AbstractSet<T>
@Override @Override
public Iterator<T> iterator() public Iterator<T> iterator()
{ {
return new BackstringIterator<T>(this.stringSet.iterator(), this); // Create
List<T> ret = new ArrayList<>();
// Get our conversion map
Map<String, T> typeMap = this.getStringToTypeMap();
// Fill
for (String key: this.getStringSet())
{
T value = typeMap.get(key);
if (value != null) ret.add(value);
}
// Return
return ret.iterator();
} }
@Override @Override

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.massivecraft.massivecore.collections.BackstringEnumSet;
import com.massivecraft.massivecore.collections.ExceptionSet; import com.massivecraft.massivecore.collections.ExceptionSet;
import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.collections.MassiveMap; import com.massivecraft.massivecore.collections.MassiveMap;
@ -17,6 +18,7 @@ import com.massivecraft.massivecore.command.type.combined.TypeDataPotionEffect;
import com.massivecraft.massivecore.command.type.combined.TypeEntry; import com.massivecraft.massivecore.command.type.combined.TypeEntry;
import com.massivecraft.massivecore.command.type.combined.TypePotionEffectWrap; import com.massivecraft.massivecore.command.type.combined.TypePotionEffectWrap;
import com.massivecraft.massivecore.command.type.combined.TypeSoundEffect; import com.massivecraft.massivecore.command.type.combined.TypeSoundEffect;
import com.massivecraft.massivecore.command.type.container.TypeBackStringEnumSet;
import com.massivecraft.massivecore.command.type.container.TypeExceptionSet; import com.massivecraft.massivecore.command.type.container.TypeExceptionSet;
import com.massivecraft.massivecore.command.type.container.TypeList; import com.massivecraft.massivecore.command.type.container.TypeList;
import com.massivecraft.massivecore.command.type.container.TypeMap; import com.massivecraft.massivecore.command.type.container.TypeMap;
@ -129,6 +131,12 @@ public class RegistryType
Class<?> fieldClass = field == null ? null : field.getType(); Class<?> fieldClass = field == null ? null : field.getType();
List<Type<?>> innerTypes; List<Type<?>> innerTypes;
if (ReflectionUtil.isRawTypeAssignableFromAny(BackstringEnumSet.class, fieldType, fieldClass))
{
innerTypes = getInnerTypes(field, fieldType, 1);
return TypeBackStringEnumSet.get((Type<? extends Enum>)innerTypes.get(0));
}
if (ReflectionUtil.isRawTypeAssignableFromAny(List.class, fieldType, fieldClass)) if (ReflectionUtil.isRawTypeAssignableFromAny(List.class, fieldType, fieldClass))
{ {
innerTypes = getInnerTypes(field, fieldType, 1); innerTypes = getInnerTypes(field, fieldType, 1);

View File

@ -0,0 +1,41 @@
package com.massivecraft.massivecore.command.type.container;
import com.massivecraft.massivecore.collections.BackstringEnumSet;
import com.massivecraft.massivecore.command.type.Type;
import java.util.Set;
public class TypeBackStringEnumSet<E extends Enum<E>> extends TypeContainer<Set<E>, E>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private Class<? extends Enum> innerTypeClass;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public static <E extends Enum<E>> TypeBackStringEnumSet<E> get(Type<E> innerType)
{
return new TypeBackStringEnumSet<E>(innerType);
}
public TypeBackStringEnumSet(Type<E> innerType)
{
super(BackstringEnumSet.class, innerType);
this.innerTypeClass = innerType.getClazz();
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public BackstringEnumSet<E> createNewInstance()
{
return new BackstringEnumSet<E>((Class<E>) innerTypeClass);
}
}