Smarter default visual implementation
This commit is contained in:
parent
d1aacefdec
commit
5d868d5081
@ -68,7 +68,9 @@ public class HelpCommand extends MassiveCommand
|
|||||||
if ( ! (this.hasParent() && visible)) return visible;
|
if ( ! (this.hasParent() && visible)) return visible;
|
||||||
|
|
||||||
int pageHeight = (sender instanceof Player) ? Txt.PAGEHEIGHT_PLAYER : Txt.PAGEHEIGHT_CONSOLE;
|
int pageHeight = (sender instanceof Player) ? Txt.PAGEHEIGHT_PLAYER : Txt.PAGEHEIGHT_CONSOLE;
|
||||||
int size = this.getParent().getChildren().size();
|
|
||||||
|
// Minues one, don't count ourself.
|
||||||
|
int size = this.getParent().getChildren().size()-1;
|
||||||
|
|
||||||
if (size <= pageHeight)
|
if (size <= pageHeight)
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,6 @@ public interface Type<T>
|
|||||||
// A visual mson.
|
// A visual mson.
|
||||||
|
|
||||||
public Mson getVisualMsonInner(T value, CommandSender sender);
|
public Mson getVisualMsonInner(T value, CommandSender sender);
|
||||||
public Mson getVisualMsonInner(T value);
|
|
||||||
public Mson getVisualMson(T value, CommandSender sender);
|
public Mson getVisualMson(T value, CommandSender sender);
|
||||||
public Mson getVisualMson(T value);
|
public Mson getVisualMson(T value);
|
||||||
|
|
||||||
@ -64,7 +63,6 @@ public interface Type<T>
|
|||||||
// A visual and colorful representation. Possibly with added detail such as simple ASCII art.
|
// A visual and colorful representation. Possibly with added detail such as simple ASCII art.
|
||||||
|
|
||||||
public String getVisualInner(T value, CommandSender sender);
|
public String getVisualInner(T value, CommandSender sender);
|
||||||
public String getVisualInner(T value);
|
|
||||||
public String getVisual(T value, CommandSender sender);
|
public String getVisual(T value, CommandSender sender);
|
||||||
public String getVisual(T value);
|
public String getVisual(T value);
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import com.massivecraft.massivecore.mson.Mson;
|
|||||||
import com.massivecraft.massivecore.store.Entity;
|
import com.massivecraft.massivecore.store.Entity;
|
||||||
import com.massivecraft.massivecore.store.SenderEntity;
|
import com.massivecraft.massivecore.store.SenderEntity;
|
||||||
import com.massivecraft.massivecore.util.ContainerUtil;
|
import com.massivecraft.massivecore.util.ContainerUtil;
|
||||||
|
import com.massivecraft.massivecore.util.ReflectionUtil;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
public abstract class TypeAbstract<T> implements Type<T>
|
public abstract class TypeAbstract<T> implements Type<T>
|
||||||
@ -71,15 +72,15 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
protected List<Type<?>> innerTypes = new MassiveList<>();
|
protected List<Type<?>> innerTypes = new MassiveList<>();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <I extends Type<?>> List<I> getInnerTypes() { return (List<I>) this.innerTypes; }
|
@Override public <I extends Type<?>> List<I> getInnerTypes() { return (List<I>) this.innerTypes; }
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <I extends Type<?>> I getInnerType(int index) { return (I) this.getInnerTypes().get(index); }
|
@Override public <I extends Type<?>> I getInnerType(int index) { return (I) this.getInnerTypes().get(index); }
|
||||||
public <I extends Type<?>> I getInnerType() { return this.getInnerType(0); }
|
@Override public <I extends Type<?>> I getInnerType() { return this.getInnerType(0); }
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public void setInnerTypes(Collection<Type<?>> innerTypes) { this.innerTypes = new MassiveList(innerTypes); }
|
@Override public void setInnerTypes(Collection<Type<?>> innerTypes) { this.innerTypes = new MassiveList(innerTypes); }
|
||||||
public void setInnerTypes(Type<?>... innerTypes) { this.setInnerTypes(Arrays.asList(innerTypes)); };
|
@Override public void setInnerTypes(Type<?>... innerTypes) { this.setInnerTypes(Arrays.asList(innerTypes)); };
|
||||||
public void setInnerType(Type<?> innerType) { this.setInnerTypes(innerType); }
|
@Override public void setInnerType(Type<?> innerType) { this.setInnerTypes(innerType); }
|
||||||
|
|
||||||
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; }
|
||||||
@ -102,14 +103,17 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
protected ChatColor visualColor = COLOR_DEFAULT;
|
protected ChatColor visualColor = COLOR_DEFAULT;
|
||||||
|
@Override
|
||||||
public void setVisualColor(ChatColor color)
|
public void setVisualColor(ChatColor color)
|
||||||
{
|
{
|
||||||
this.visualColor = color;
|
this.visualColor = color;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public ChatColor getVisualColor(T value, CommandSender sender)
|
public ChatColor getVisualColor(T value, CommandSender sender)
|
||||||
{
|
{
|
||||||
return this.visualColor;
|
return this.visualColor;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public ChatColor getVisualColor(T value)
|
public ChatColor getVisualColor(T value)
|
||||||
{
|
{
|
||||||
return this.getVisualColor(value, null);
|
return this.getVisualColor(value, null);
|
||||||
@ -120,31 +124,37 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// A visual mson.
|
// A visual mson.
|
||||||
|
|
||||||
|
protected boolean visualMsonOverridden = calcVisualMsonOverridden();
|
||||||
|
public boolean isVisualMsonOverridden() { return this.visualMsonOverridden; }
|
||||||
|
public void setVisualMsonOverridden(boolean visualMsonOverridden) { this.visualMsonOverridden = visualMsonOverridden; }
|
||||||
|
public boolean calcVisualMsonOverridden()
|
||||||
|
{
|
||||||
|
return ! TypeAbstract.class.equals(ReflectionUtil.getSuperclassDeclaringMethod(this.getClass(), true, "getVisualMsonInner"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Mson getVisualMsonInner(T value, CommandSender sender)
|
public Mson getVisualMsonInner(T value, CommandSender sender)
|
||||||
{
|
{
|
||||||
return Mson.fromParsedMessage(this.getVisualInner(value, sender));
|
return Mson.fromParsedMessage(this.getVisualInner(value, sender));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mson getVisualMsonInner(T value)
|
@Override
|
||||||
{
|
|
||||||
return this.getVisualMson(value, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mson getVisualMson(T value, CommandSender sender)
|
public Mson getVisualMson(T value, CommandSender sender)
|
||||||
{
|
{
|
||||||
if (value == null) return MSON_NULL;
|
if (value == null) return MSON_NULL;
|
||||||
return this.getVisualMsonInner(value, sender);
|
return this.getVisualMsonInner(value, sender);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public Mson getVisualMson(T value)
|
public Mson getVisualMson(T value)
|
||||||
{
|
{
|
||||||
if (value == null) return MSON_NULL;
|
return this.getVisualMson(value, null);
|
||||||
return this.getVisualMsonInner(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// WRITE VISUAL
|
// WRITE VISUAL
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getVisualInner(T value, CommandSender sender)
|
public String getVisualInner(T value, CommandSender sender)
|
||||||
{
|
{
|
||||||
if (value instanceof SenderEntity<?>)
|
if (value instanceof SenderEntity<?>)
|
||||||
@ -153,19 +163,23 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
String ret = senderEntity.getDisplayName(sender);
|
String ret = senderEntity.getDisplayName(sender);
|
||||||
return ret == null ? NULL : ret;
|
return ret == null ? NULL : ret;
|
||||||
}
|
}
|
||||||
|
if (this.isVisualMsonOverridden())
|
||||||
return this.getVisualColor(value, sender) + this.getNameInner(value);
|
{
|
||||||
}
|
return this.getVisualMsonInner(value, sender).toPlain(true);
|
||||||
public String getVisualInner(T value)
|
}
|
||||||
{
|
else
|
||||||
return this.getVisualInner(value, null);
|
{
|
||||||
|
return this.getVisualColor(value, sender) + this.getNameInner(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getVisual(T value, CommandSender sender)
|
public String getVisual(T value, CommandSender sender)
|
||||||
{
|
{
|
||||||
if (value == null) return NULL;
|
if (value == null) return NULL;
|
||||||
return this.getVisualInner(value, sender);
|
return this.getVisualInner(value, sender);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String getVisual(T value)
|
public String getVisual(T value)
|
||||||
{
|
{
|
||||||
return this.getVisual(value, null);
|
return this.getVisual(value, null);
|
||||||
@ -175,6 +189,7 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// WRITE NAME
|
// WRITE NAME
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getNameInner(T value)
|
public String getNameInner(T value)
|
||||||
{
|
{
|
||||||
if (value instanceof Named)
|
if (value instanceof Named)
|
||||||
@ -186,17 +201,20 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
return this.getIdInner(value);
|
return this.getIdInner(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName(T value)
|
public String getName(T value)
|
||||||
{
|
{
|
||||||
if (value == null) return null;
|
if (value == null) return null;
|
||||||
return this.getNameInner(value);
|
return this.getNameInner(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Set<String> getNamesInner(T value)
|
public Set<String> getNamesInner(T value)
|
||||||
{
|
{
|
||||||
return Collections.singleton(this.getNameInner(value));
|
return Collections.singleton(this.getNameInner(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Set<String> getNames(T value)
|
public Set<String> getNames(T value)
|
||||||
{
|
{
|
||||||
if (value == null) return Collections.emptySet();
|
if (value == null) return Collections.emptySet();
|
||||||
@ -207,6 +225,7 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// WRITE ID
|
// WRITE ID
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getIdInner(T value)
|
public String getIdInner(T value)
|
||||||
{
|
{
|
||||||
if (value instanceof Entity)
|
if (value instanceof Entity)
|
||||||
@ -222,17 +241,20 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getId(T value)
|
public String getId(T value)
|
||||||
{
|
{
|
||||||
if (value == null) return null;
|
if (value == null) return null;
|
||||||
return this.getIdInner(value);
|
return this.getIdInner(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Set<String> getIdsInner(T value)
|
public Set<String> getIdsInner(T value)
|
||||||
{
|
{
|
||||||
return Collections.singleton(this.getIdInner(value));
|
return Collections.singleton(this.getIdInner(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Set<String> getIds(T value)
|
public Set<String> getIds(T value)
|
||||||
{
|
{
|
||||||
if (value == null) return Collections.emptySet();
|
if (value == null) return Collections.emptySet();
|
||||||
@ -243,16 +265,19 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// READ
|
// READ
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
public T read(CommandSender sender) throws MassiveException
|
public T read(CommandSender sender) throws MassiveException
|
||||||
{
|
{
|
||||||
return this.read(null, sender);
|
return this.read(null, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public T read(String arg) throws MassiveException
|
public T read(String arg) throws MassiveException
|
||||||
{
|
{
|
||||||
return this.read(arg, null);
|
return this.read(arg, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public T read() throws MassiveException
|
public T read() throws MassiveException
|
||||||
{
|
{
|
||||||
return this.read(null, null);
|
return this.read(null, null);
|
||||||
@ -262,6 +287,7 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// VALID
|
// VALID
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isValid(String arg, CommandSender sender)
|
public boolean isValid(String arg, CommandSender sender)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -279,11 +305,13 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// TAB LIST
|
// TAB LIST
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean allowSpaceAfterTab()
|
public boolean allowSpaceAfterTab()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<String> getTabListFiltered(CommandSender sender, String arg)
|
public List<String> getTabListFiltered(CommandSender sender, String arg)
|
||||||
{
|
{
|
||||||
// Get the raw tab list.
|
// Get the raw tab list.
|
||||||
@ -431,22 +459,22 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private Boolean container = null;
|
private Boolean container = null;
|
||||||
public boolean isContainer() { this.calcContainer(); return this.container; }
|
@Override public boolean isContainer() { this.calcContainer(); return this.container; }
|
||||||
|
|
||||||
private Boolean containerMap = null;
|
private Boolean containerMap = null;
|
||||||
public boolean isContainerMap() { this.calcContainer(); return this.containerMap; }
|
@Override public boolean isContainerMap() { this.calcContainer(); return this.containerMap; }
|
||||||
|
|
||||||
private Boolean containerCollection = null;
|
private Boolean containerCollection = null;
|
||||||
public boolean isContainerCollection() { this.calcContainer(); return this.containerCollection; }
|
@Override public boolean isContainerCollection() { this.calcContainer(); return this.containerCollection; }
|
||||||
|
|
||||||
private Boolean containerIndexed = null;
|
private Boolean containerIndexed = null;
|
||||||
public boolean isContainerIndexed() { this.calcContainer(); return this.containerIndexed; }
|
@Override public boolean isContainerIndexed() { this.calcContainer(); return this.containerIndexed; }
|
||||||
|
|
||||||
private Boolean containerOrdered = null;
|
private Boolean containerOrdered = null;
|
||||||
public boolean isContainerOrdered() { this.calcContainer(); return this.containerOrdered; }
|
@Override public boolean isContainerOrdered() { this.calcContainer(); return this.containerOrdered; }
|
||||||
|
|
||||||
private Boolean containerSorted = null;
|
private Boolean containerSorted = null;
|
||||||
public boolean isContainerSorted() { this.calcContainer(); return this.containerSorted; }
|
@Override public boolean isContainerSorted() { this.calcContainer(); return this.containerSorted; }
|
||||||
|
|
||||||
private void calcContainer()
|
private void calcContainer()
|
||||||
{
|
{
|
||||||
@ -466,6 +494,7 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
|
|
||||||
private Comparator<Object> elementComparator = null;
|
private Comparator<Object> elementComparator = null;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public <E> Comparator<E> getContainerComparator()
|
public <E> Comparator<E> getContainerComparator()
|
||||||
{
|
{
|
||||||
if (this.elementComparator != null) return (Comparator<E>) this.elementComparator;
|
if (this.elementComparator != null) return (Comparator<E>) this.elementComparator;
|
||||||
@ -473,8 +502,10 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
return (Comparator<E>) ComparatorHashCode.get().getLenient();
|
return (Comparator<E>) ComparatorHashCode.get().getLenient();
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public void setContainerComparator(Comparator<?> comparator) { this.elementComparator = (Comparator<Object>) comparator; }
|
public void setContainerComparator(Comparator<?> comparator) { this.elementComparator = (Comparator<Object>) comparator; }
|
||||||
|
|
||||||
|
@Override
|
||||||
public <E> List<E> getContainerElementsOrdered(Iterable<E> elements)
|
public <E> List<E> getContainerElementsOrdered(Iterable<E> elements)
|
||||||
{
|
{
|
||||||
if (elements == null) return null;
|
if (elements == null) return null;
|
||||||
@ -510,6 +541,7 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// EQUALS
|
// EQUALS
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(T type1, T type2)
|
public boolean equals(T type1, T type2)
|
||||||
{
|
{
|
||||||
if (type1 == null) return type2 == null;
|
if (type1 == null) return type2 == null;
|
||||||
@ -517,6 +549,7 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
return this.equalsInner(type1, type2);
|
return this.equalsInner(type1, type2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equalsInner(T type1, T type2)
|
public boolean equalsInner(T type1, T type2)
|
||||||
{
|
{
|
||||||
return type1.equals(type2);
|
return type1.equals(type2);
|
||||||
@ -526,11 +559,13 @@ public abstract class TypeAbstract<T> implements Type<T>
|
|||||||
// EDITOR
|
// EDITOR
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
public <O> CommandEditAbstract<O, T> createEditCommand(EditSettings<O> settings, Property<O, T> property)
|
public <O> CommandEditAbstract<O, T> createEditCommand(EditSettings<O> settings, Property<O, T> property)
|
||||||
{
|
{
|
||||||
return new CommandEditSimple<O, T>(settings, property);
|
return new CommandEditSimple<O, T>(settings, property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public T createNewInstance()
|
public T createNewInstance()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -123,14 +123,6 @@ public abstract class TypeTransformer<I, O> extends TypeAbstract<O>
|
|||||||
return INNER.getVisualMsonInner(inner, sender);
|
return INNER.getVisualMsonInner(inner, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Mson getVisualMsonInner(O outer)
|
|
||||||
{
|
|
||||||
I inner = outerToInner(outer);
|
|
||||||
if (outer != null && inner == null) return prefix(OUTER.getVisualMsonInner(outer));
|
|
||||||
return INNER.getVisualMsonInner(inner);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mson getVisualMson(O outer, CommandSender sender)
|
public Mson getVisualMson(O outer, CommandSender sender)
|
||||||
{
|
{
|
||||||
@ -159,14 +151,6 @@ public abstract class TypeTransformer<I, O> extends TypeAbstract<O>
|
|||||||
return INNER.getVisualInner(inner, sender);
|
return INNER.getVisualInner(inner, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getVisualInner(O outer)
|
|
||||||
{
|
|
||||||
I inner = outerToInner(outer);
|
|
||||||
if (outer != null && inner == null) return prefix(OUTER.getVisualInner(outer));
|
|
||||||
return INNER.getVisualInner(inner);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVisual(O outer, CommandSender sender)
|
public String getVisual(O outer, CommandSender sender)
|
||||||
{
|
{
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.massivecraft.massivecore.command.type.combined;
|
package com.massivecraft.massivecore.command.type.combined;
|
||||||
|
|
||||||
|
import java.util.AbstractMap.SimpleEntry;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@ -14,6 +14,7 @@ import com.massivecraft.massivecore.MassiveException;
|
|||||||
import com.massivecraft.massivecore.collections.MassiveList;
|
import com.massivecraft.massivecore.collections.MassiveList;
|
||||||
import com.massivecraft.massivecore.command.type.Type;
|
import com.massivecraft.massivecore.command.type.Type;
|
||||||
import com.massivecraft.massivecore.command.type.TypeAbstract;
|
import com.massivecraft.massivecore.command.type.TypeAbstract;
|
||||||
|
import com.massivecraft.massivecore.mson.Mson;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
public abstract class TypeCombined<T> extends TypeAbstract<T>
|
public abstract class TypeCombined<T> extends TypeAbstract<T>
|
||||||
@ -46,6 +47,15 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
|
|||||||
public String getTypeNameSeparator() { return this.typeNameSeparator; }
|
public String getTypeNameSeparator() { return this.typeNameSeparator; }
|
||||||
public void setTypeNameSeparator(String typeNameSeparator) { this.typeNameSeparator = typeNameSeparator; }
|
public void setTypeNameSeparator(String typeNameSeparator) { this.typeNameSeparator = typeNameSeparator; }
|
||||||
|
|
||||||
|
// Visual Mson
|
||||||
|
private boolean visualMsonNullIncluded = true;
|
||||||
|
public boolean isVisualMsonNullIncluded() { return this.visualMsonNullIncluded; }
|
||||||
|
public void setVisualMsonNullIncluded(boolean visualMsonNullIncluded) { this.visualMsonNullIncluded = visualMsonNullIncluded; }
|
||||||
|
|
||||||
|
private Mson visualMsonSeparator = Mson.SPACE;
|
||||||
|
public Mson getVisualMsonSeparator() { return this.visualMsonSeparator; }
|
||||||
|
public void setVisualMsonSeparator(Mson visualMsonSeparator) { this.visualMsonSeparator = visualMsonSeparator; }
|
||||||
|
|
||||||
// Visual
|
// Visual
|
||||||
private boolean visualNullIncluded = true;
|
private boolean visualNullIncluded = true;
|
||||||
public boolean isVisualNullIncluded() { return this.visualNullIncluded; }
|
public boolean isVisualNullIncluded() { return this.visualNullIncluded; }
|
||||||
@ -135,6 +145,32 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
|
|||||||
return Txt.implode(parts, this.getTypeNameSeparator());
|
return Txt.implode(parts, this.getTypeNameSeparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// WRITE VISUAL MSON
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Mson getVisualMsonInner(T value, CommandSender sender)
|
||||||
|
{
|
||||||
|
// Create
|
||||||
|
List<Mson> parts = new MassiveList<>();
|
||||||
|
|
||||||
|
// Fill
|
||||||
|
List<Entry<Type<?>, Object>> entries = this.splitEntries(value);
|
||||||
|
for (int i = 0; i < entries.size(); i++)
|
||||||
|
{
|
||||||
|
Entry<Type<?>, Object> entry = entries.get(this.getIndexTech(i));
|
||||||
|
Type<Object> type = (Type<Object>) entry.getKey();
|
||||||
|
Mson part = type.getVisualMson(entry.getValue(), sender);
|
||||||
|
if ( ! this.isVisualMsonNullIncluded() && part == null) continue;
|
||||||
|
parts.add(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return Mson.implode(parts, this.getVisualMsonSeparator());
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// WRITE VISUAL
|
// WRITE VISUAL
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -144,7 +180,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
|
|||||||
public String getVisualInner(T value, CommandSender sender)
|
public String getVisualInner(T value, CommandSender sender)
|
||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
List<String> parts = new MassiveList<String>();
|
List<String> parts = new MassiveList<>();
|
||||||
|
|
||||||
// Fill
|
// Fill
|
||||||
List<Entry<Type<?>, Object>> entries = this.splitEntries(value);
|
List<Entry<Type<?>, Object>> entries = this.splitEntries(value);
|
||||||
@ -169,7 +205,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
|
|||||||
public String getNameInner(T value)
|
public String getNameInner(T value)
|
||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
List<String> parts = new MassiveList<String>();
|
List<String> parts = new MassiveList<>();
|
||||||
|
|
||||||
// Fill
|
// Fill
|
||||||
for (Entry<Type<?>, Object> entry : this.splitEntries(value))
|
for (Entry<Type<?>, Object> entry : this.splitEntries(value))
|
||||||
@ -193,7 +229,7 @@ public abstract class TypeCombined<T> extends TypeAbstract<T>
|
|||||||
public String getIdInner(T value)
|
public String getIdInner(T value)
|
||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
List<String> parts = new MassiveList<String>();
|
List<String> parts = new MassiveList<>();
|
||||||
|
|
||||||
// Fill
|
// Fill
|
||||||
for (Entry<Type<?>, Object> entry : this.splitEntries(value))
|
for (Entry<Type<?>, Object> entry : this.splitEntries(value))
|
||||||
|
@ -48,6 +48,7 @@ public class Mson implements Serializable
|
|||||||
public static final Mson SPACE = mson(" ");
|
public static final Mson SPACE = mson(" ");
|
||||||
public static final Mson EMPTY = mson("");
|
public static final Mson EMPTY = mson("");
|
||||||
public static final Mson NEWLINE = mson("\n");
|
public static final Mson NEWLINE = mson("\n");
|
||||||
|
public static final Mson DOT = mson(".");
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// GSON
|
// GSON
|
||||||
|
Loading…
Reference in New Issue
Block a user