Support Null User Order for Inner Types
This commit is contained in:
parent
3fb8268b2b
commit
305f3a4d2c
@ -5,6 +5,7 @@ import java.util.AbstractMap.SimpleImmutableEntry;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
@ -175,25 +176,28 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
|
||||
|
||||
public void addParametersElement(boolean strict)
|
||||
{
|
||||
Type<Object> innerType = this.getValueInnerType();
|
||||
Type<Object> elementType = this.getValueInnerType();
|
||||
|
||||
if (this.isCollection())
|
||||
{
|
||||
this.addParameter(innerType, true);
|
||||
this.addParameter(elementType, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type<Object> keyType = innerType.getInnerType(innerType.getIndexUser(0));
|
||||
Type<Object> valueType = innerType.getInnerType(innerType.getIndexUser(1));
|
||||
List<Integer> userOrder = elementType.getUserOrder();
|
||||
for (Iterator<Integer> iterator = userOrder.iterator(); iterator.hasNext();)
|
||||
{
|
||||
Integer indexTech = iterator.next();
|
||||
Type<?> innerType = elementType.getInnerType(indexTech);
|
||||
boolean concatFromHere = ! iterator.hasNext();
|
||||
if (strict)
|
||||
{
|
||||
this.addParameter(keyType);
|
||||
this.addParameter(valueType, true);
|
||||
this.addParameter(innerType, concatFromHere);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addParameter(null, TypeNullable.get(keyType, "any", "all"), keyType.getName(), "any");
|
||||
this.addParameter(null, TypeNullable.get(valueType, "any", "all"), valueType.getName(), "any", true);
|
||||
this.addParameter(null, TypeNullable.get(innerType, "any", "all"), innerType.getName(), "any", concatFromHere);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -206,12 +210,21 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
|
||||
}
|
||||
else
|
||||
{
|
||||
Object key = this.readArgAt(this.getValueInnerType().getIndexTech(0));
|
||||
Object value = this.readArgAt(this.getValueInnerType().getIndexTech(1));
|
||||
Object key = this.readElementInner(0);
|
||||
Object value = this.readElementInner(1);
|
||||
return new SimpleImmutableEntry<Object, Object>(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Object readElementInner(int indexTech) throws MassiveException
|
||||
{
|
||||
Type<Object> elementType = this.getValueInnerType();
|
||||
Integer indexUser = elementType.getIndexUser(indexTech);
|
||||
if (indexUser != null) return this.readArgAt(indexUser);
|
||||
Type<Object> innerType = elementType.getInnerType(indexTech);
|
||||
return innerType.read(sender);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ELEMENTS UTIL
|
||||
// -------------------------------------------- //
|
||||
|
@ -38,8 +38,9 @@ public interface Type<T> extends Named
|
||||
|
||||
public void setUserOrder(List<Integer> userOrder);
|
||||
public void setUserOrder(Integer... userOrder);
|
||||
public int getIndexUser(int indexTechy);
|
||||
public int getIndexTech(int indexUser);
|
||||
public List<Integer> getUserOrder();
|
||||
public Integer getIndexUser(int indexTechy);
|
||||
public Integer getIndexTech(int indexUser);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// WRITE VISUAL COLOR
|
||||
|
@ -87,17 +87,20 @@ public abstract class TypeAbstract<T> implements Type<T>
|
||||
private List<Integer> userOrder = null;
|
||||
@Override public void setUserOrder(List<Integer> userOrder) { this.userOrder = userOrder; }
|
||||
@Override public void setUserOrder(Integer... userOrder) { this.setUserOrder(Arrays.asList(userOrder)); }
|
||||
@Override public List<Integer> getUserOrder() { return this.userOrder; }
|
||||
@Override
|
||||
public int getIndexUser(int indexTechy)
|
||||
public Integer getIndexUser(int indexTechy)
|
||||
{
|
||||
if (this.userOrder == null) return indexTechy;
|
||||
return userOrder.get(indexTechy);
|
||||
Integer ret = this.userOrder.indexOf(indexTechy);
|
||||
if (ret.equals(-1)) return null;
|
||||
return ret;
|
||||
}
|
||||
@Override
|
||||
public int getIndexTech(int indexUser)
|
||||
public Integer getIndexTech(int indexUser)
|
||||
{
|
||||
if (this.userOrder == null) return indexUser;
|
||||
return userOrder.indexOf(indexUser);
|
||||
return this.userOrder.get(indexUser);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user