Support Null User Order for Inner Types

This commit is contained in:
Olof Larsson 2016-03-15 18:58:15 +01:00
parent 3fb8268b2b
commit 305f3a4d2c
3 changed files with 37 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import java.util.AbstractMap.SimpleImmutableEntry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.List; import java.util.List;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
@ -175,25 +176,28 @@ public abstract class CommandEditContainerAbstract<O, V> extends CommandEditAbst
public void addParametersElement(boolean strict) public void addParametersElement(boolean strict)
{ {
Type<Object> innerType = this.getValueInnerType(); Type<Object> elementType = this.getValueInnerType();
if (this.isCollection()) if (this.isCollection())
{ {
this.addParameter(innerType, true); this.addParameter(elementType, true);
} }
else else
{ {
Type<Object> keyType = innerType.getInnerType(innerType.getIndexUser(0)); List<Integer> userOrder = elementType.getUserOrder();
Type<Object> valueType = innerType.getInnerType(innerType.getIndexUser(1)); for (Iterator<Integer> iterator = userOrder.iterator(); iterator.hasNext();)
if (strict)
{ {
this.addParameter(keyType); Integer indexTech = iterator.next();
this.addParameter(valueType, true); Type<?> innerType = elementType.getInnerType(indexTech);
} boolean concatFromHere = ! iterator.hasNext();
else if (strict)
{ {
this.addParameter(null, TypeNullable.get(keyType, "any", "all"), keyType.getName(), "any"); this.addParameter(innerType, concatFromHere);
this.addParameter(null, TypeNullable.get(valueType, "any", "all"), valueType.getName(), "any", true); }
else
{
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 else
{ {
Object key = this.readArgAt(this.getValueInnerType().getIndexTech(0)); Object key = this.readElementInner(0);
Object value = this.readArgAt(this.getValueInnerType().getIndexTech(1)); Object value = this.readElementInner(1);
return new SimpleImmutableEntry<Object, Object>(key, value); 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 // ELEMENTS UTIL
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -38,8 +38,9 @@ public interface Type<T> extends Named
public void setUserOrder(List<Integer> userOrder); public void setUserOrder(List<Integer> userOrder);
public void setUserOrder(Integer... userOrder); public void setUserOrder(Integer... userOrder);
public int getIndexUser(int indexTechy); public List<Integer> getUserOrder();
public int getIndexTech(int indexUser); public Integer getIndexUser(int indexTechy);
public Integer getIndexTech(int indexUser);
// -------------------------------------------- // // -------------------------------------------- //
// WRITE VISUAL COLOR // WRITE VISUAL COLOR

View File

@ -87,17 +87,20 @@ public abstract class TypeAbstract<T> implements Type<T>
private List<Integer> userOrder = null; private List<Integer> userOrder = null;
@Override public void setUserOrder(List<Integer> userOrder) { this.userOrder = userOrder; } @Override public void setUserOrder(List<Integer> userOrder) { this.userOrder = userOrder; }
@Override public void setUserOrder(Integer... userOrder) { this.setUserOrder(Arrays.asList(userOrder)); } @Override public void setUserOrder(Integer... userOrder) { this.setUserOrder(Arrays.asList(userOrder)); }
@Override public List<Integer> getUserOrder() { return this.userOrder; }
@Override @Override
public int getIndexUser(int indexTechy) public Integer getIndexUser(int indexTechy)
{ {
if (this.userOrder == null) return 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 @Override
public int getIndexTech(int indexUser) public Integer getIndexTech(int indexUser)
{ {
if (this.userOrder == null) return indexUser; if (this.userOrder == null) return indexUser;
return userOrder.indexOf(indexUser); return this.userOrder.get(indexUser);
} }
// -------------------------------------------- // // -------------------------------------------- //