Fix backstringenumset to play nice with the editor.
This commit is contained in:
parent
7fd631bebe
commit
71436bb935
@ -67,5 +67,11 @@ public class BackstringEnumSet<T extends Enum<?>> extends BackstringSet<T>
|
||||
|
||||
return t.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, T> getStringToTypeMap()
|
||||
{
|
||||
return this.name2enum;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.massivecraft.massivecore.collections;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@Deprecated
|
||||
public class BackstringIterator<E> implements Iterator<E>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.massivecraft.massivecore.collections;
|
||||
|
||||
import java.util.AbstractSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
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 String convertToString(Object t);
|
||||
|
||||
public abstract Map<String, T> getStringToTypeMap();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
@ -55,7 +60,21 @@ public abstract class BackstringSet<T> extends AbstractSet<T>
|
||||
@Override
|
||||
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
|
||||
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.massivecore.collections.BackstringEnumSet;
|
||||
import com.massivecraft.massivecore.collections.ExceptionSet;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
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.TypePotionEffectWrap;
|
||||
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.TypeList;
|
||||
import com.massivecraft.massivecore.command.type.container.TypeMap;
|
||||
@ -129,6 +131,12 @@ public class RegistryType
|
||||
Class<?> fieldClass = field == null ? null : field.getType();
|
||||
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))
|
||||
{
|
||||
innerTypes = getInnerTypes(field, fieldType, 1);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user