diff --git a/src/com/massivecraft/massivecore/command/HelpCommand.java b/src/com/massivecraft/massivecore/command/HelpCommand.java index 3cac4474..90fb3578 100644 --- a/src/com/massivecraft/massivecore/command/HelpCommand.java +++ b/src/com/massivecraft/massivecore/command/HelpCommand.java @@ -68,7 +68,9 @@ public class HelpCommand extends MassiveCommand if ( ! (this.hasParent() && visible)) return visible; 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) { diff --git a/src/com/massivecraft/massivecore/command/type/Type.java b/src/com/massivecraft/massivecore/command/type/Type.java index abb3deaa..dc2e36e9 100644 --- a/src/com/massivecraft/massivecore/command/type/Type.java +++ b/src/com/massivecraft/massivecore/command/type/Type.java @@ -54,7 +54,6 @@ public interface Type // A visual mson. public Mson getVisualMsonInner(T value, CommandSender sender); - public Mson getVisualMsonInner(T value); public Mson getVisualMson(T value, CommandSender sender); public Mson getVisualMson(T value); @@ -64,7 +63,6 @@ public interface Type // 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); public String getVisual(T value, CommandSender sender); public String getVisual(T value); diff --git a/src/com/massivecraft/massivecore/command/type/TypeAbstract.java b/src/com/massivecraft/massivecore/command/type/TypeAbstract.java index 144ae48b..8965ad87 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeAbstract.java +++ b/src/com/massivecraft/massivecore/command/type/TypeAbstract.java @@ -25,6 +25,7 @@ import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.store.SenderEntity; import com.massivecraft.massivecore.util.ContainerUtil; +import com.massivecraft.massivecore.util.ReflectionUtil; import com.massivecraft.massivecore.util.Txt; public abstract class TypeAbstract implements Type @@ -71,15 +72,15 @@ public abstract class TypeAbstract implements Type protected List> innerTypes = new MassiveList<>(); @SuppressWarnings("unchecked") - public > List getInnerTypes() { return (List) this.innerTypes; } + @Override public > List getInnerTypes() { return (List) this.innerTypes; } @SuppressWarnings("unchecked") - public > I getInnerType(int index) { return (I) this.getInnerTypes().get(index); } - public > I getInnerType() { return this.getInnerType(0); } + @Override public > I getInnerType(int index) { return (I) this.getInnerTypes().get(index); } + @Override public > I getInnerType() { return this.getInnerType(0); } @SuppressWarnings({ "unchecked", "rawtypes" }) - public void setInnerTypes(Collection> innerTypes) { this.innerTypes = new MassiveList(innerTypes); } - public void setInnerTypes(Type... innerTypes) { this.setInnerTypes(Arrays.asList(innerTypes)); }; - public void setInnerType(Type innerType) { this.setInnerTypes(innerType); } + @Override public void setInnerTypes(Collection> innerTypes) { this.innerTypes = new MassiveList(innerTypes); } + @Override public void setInnerTypes(Type... innerTypes) { this.setInnerTypes(Arrays.asList(innerTypes)); }; + @Override public void setInnerType(Type innerType) { this.setInnerTypes(innerType); } private List userOrder = null; @Override public void setUserOrder(List userOrder) { this.userOrder = userOrder; } @@ -102,14 +103,17 @@ public abstract class TypeAbstract implements Type // -------------------------------------------- // protected ChatColor visualColor = COLOR_DEFAULT; + @Override public void setVisualColor(ChatColor color) { this.visualColor = color; } + @Override public ChatColor getVisualColor(T value, CommandSender sender) { return this.visualColor; } + @Override public ChatColor getVisualColor(T value) { return this.getVisualColor(value, null); @@ -120,31 +124,37 @@ public abstract class TypeAbstract implements Type // -------------------------------------------- // // 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) { return Mson.fromParsedMessage(this.getVisualInner(value, sender)); } - public Mson getVisualMsonInner(T value) - { - return this.getVisualMson(value, null); - } - + @Override public Mson getVisualMson(T value, CommandSender sender) { if (value == null) return MSON_NULL; return this.getVisualMsonInner(value, sender); } + @Override public Mson getVisualMson(T value) { - if (value == null) return MSON_NULL; - return this.getVisualMsonInner(value); + return this.getVisualMson(value, null); } // -------------------------------------------- // // WRITE VISUAL // -------------------------------------------- // + @Override public String getVisualInner(T value, CommandSender sender) { if (value instanceof SenderEntity) @@ -153,19 +163,23 @@ public abstract class TypeAbstract implements Type String ret = senderEntity.getDisplayName(sender); return ret == null ? NULL : ret; } - - return this.getVisualColor(value, sender) + this.getNameInner(value); + if (this.isVisualMsonOverridden()) + { + return this.getVisualMsonInner(value, sender).toPlain(true); + } + else + { + return this.getVisualColor(value, sender) + this.getNameInner(value); + } } - public String getVisualInner(T value) - { - return this.getVisualInner(value, null); - } - + + @Override public String getVisual(T value, CommandSender sender) { if (value == null) return NULL; return this.getVisualInner(value, sender); } + @Override public String getVisual(T value) { return this.getVisual(value, null); @@ -175,6 +189,7 @@ public abstract class TypeAbstract implements Type // WRITE NAME // -------------------------------------------- // + @Override public String getNameInner(T value) { if (value instanceof Named) @@ -186,17 +201,20 @@ public abstract class TypeAbstract implements Type return this.getIdInner(value); } + @Override public String getName(T value) { if (value == null) return null; return this.getNameInner(value); } + @Override public Set getNamesInner(T value) { return Collections.singleton(this.getNameInner(value)); } + @Override public Set getNames(T value) { if (value == null) return Collections.emptySet(); @@ -207,6 +225,7 @@ public abstract class TypeAbstract implements Type // WRITE ID // -------------------------------------------- // + @Override public String getIdInner(T value) { if (value instanceof Entity) @@ -222,17 +241,20 @@ public abstract class TypeAbstract implements Type return null; } + @Override public String getId(T value) { if (value == null) return null; return this.getIdInner(value); } + @Override public Set getIdsInner(T value) { return Collections.singleton(this.getIdInner(value)); } + @Override public Set getIds(T value) { if (value == null) return Collections.emptySet(); @@ -243,16 +265,19 @@ public abstract class TypeAbstract implements Type // READ // -------------------------------------------- // + @Override public T read(CommandSender sender) throws MassiveException { return this.read(null, sender); } + @Override public T read(String arg) throws MassiveException { return this.read(arg, null); } + @Override public T read() throws MassiveException { return this.read(null, null); @@ -262,6 +287,7 @@ public abstract class TypeAbstract implements Type // VALID // -------------------------------------------- // + @Override public boolean isValid(String arg, CommandSender sender) { try @@ -279,11 +305,13 @@ public abstract class TypeAbstract implements Type // TAB LIST // -------------------------------------------- // + @Override public boolean allowSpaceAfterTab() { return true; } + @Override public List getTabListFiltered(CommandSender sender, String arg) { // Get the raw tab list. @@ -431,22 +459,22 @@ public abstract class TypeAbstract implements Type // -------------------------------------------- // 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; - public boolean isContainerMap() { this.calcContainer(); return this.containerMap; } + @Override public boolean isContainerMap() { this.calcContainer(); return this.containerMap; } 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; - public boolean isContainerIndexed() { this.calcContainer(); return this.containerIndexed; } + @Override public boolean isContainerIndexed() { this.calcContainer(); return this.containerIndexed; } 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; - public boolean isContainerSorted() { this.calcContainer(); return this.containerSorted; } + @Override public boolean isContainerSorted() { this.calcContainer(); return this.containerSorted; } private void calcContainer() { @@ -466,6 +494,7 @@ public abstract class TypeAbstract implements Type private Comparator elementComparator = null; @SuppressWarnings("unchecked") + @Override public Comparator getContainerComparator() { if (this.elementComparator != null) return (Comparator) this.elementComparator; @@ -473,8 +502,10 @@ public abstract class TypeAbstract implements Type return (Comparator) ComparatorHashCode.get().getLenient(); } @SuppressWarnings("unchecked") + @Override public void setContainerComparator(Comparator comparator) { this.elementComparator = (Comparator) comparator; } + @Override public List getContainerElementsOrdered(Iterable elements) { if (elements == null) return null; @@ -510,6 +541,7 @@ public abstract class TypeAbstract implements Type // EQUALS // -------------------------------------------- // + @Override public boolean equals(T type1, T type2) { if (type1 == null) return type2 == null; @@ -517,6 +549,7 @@ public abstract class TypeAbstract implements Type return this.equalsInner(type1, type2); } + @Override public boolean equalsInner(T type1, T type2) { return type1.equals(type2); @@ -526,11 +559,13 @@ public abstract class TypeAbstract implements Type // EDITOR // -------------------------------------------- // + @Override public CommandEditAbstract createEditCommand(EditSettings settings, Property property) { return new CommandEditSimple(settings, property); } + @Override public T createNewInstance() { return null; diff --git a/src/com/massivecraft/massivecore/command/type/TypeTransformer.java b/src/com/massivecraft/massivecore/command/type/TypeTransformer.java index e68b85c1..b922eafa 100644 --- a/src/com/massivecraft/massivecore/command/type/TypeTransformer.java +++ b/src/com/massivecraft/massivecore/command/type/TypeTransformer.java @@ -123,14 +123,6 @@ public abstract class TypeTransformer extends TypeAbstract 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 public Mson getVisualMson(O outer, CommandSender sender) { @@ -159,14 +151,6 @@ public abstract class TypeTransformer extends TypeAbstract 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 public String getVisual(O outer, CommandSender sender) { diff --git a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java index 44f95602..8c04bae4 100644 --- a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java +++ b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java @@ -1,12 +1,12 @@ package com.massivecraft.massivecore.command.type.combined; +import java.util.AbstractMap.SimpleEntry; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map.Entry; import java.util.regex.Pattern; -import java.util.AbstractMap.SimpleEntry; import org.bukkit.command.CommandSender; @@ -14,6 +14,7 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.TypeAbstract; +import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.util.Txt; public abstract class TypeCombined extends TypeAbstract @@ -46,6 +47,15 @@ public abstract class TypeCombined extends TypeAbstract public String getTypeNameSeparator() { return this.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 private boolean visualNullIncluded = true; public boolean isVisualNullIncluded() { return this.visualNullIncluded; } @@ -135,6 +145,32 @@ public abstract class TypeCombined extends TypeAbstract return Txt.implode(parts, this.getTypeNameSeparator()); } + // -------------------------------------------- // + // WRITE VISUAL MSON + // -------------------------------------------- // + + @SuppressWarnings("unchecked") + @Override + public Mson getVisualMsonInner(T value, CommandSender sender) + { + // Create + List parts = new MassiveList<>(); + + // Fill + List, Object>> entries = this.splitEntries(value); + for (int i = 0; i < entries.size(); i++) + { + Entry, Object> entry = entries.get(this.getIndexTech(i)); + Type type = (Type) 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 // -------------------------------------------- // @@ -144,7 +180,7 @@ public abstract class TypeCombined extends TypeAbstract public String getVisualInner(T value, CommandSender sender) { // Create - List parts = new MassiveList(); + List parts = new MassiveList<>(); // Fill List, Object>> entries = this.splitEntries(value); @@ -169,7 +205,7 @@ public abstract class TypeCombined extends TypeAbstract public String getNameInner(T value) { // Create - List parts = new MassiveList(); + List parts = new MassiveList<>(); // Fill for (Entry, Object> entry : this.splitEntries(value)) @@ -193,7 +229,7 @@ public abstract class TypeCombined extends TypeAbstract public String getIdInner(T value) { // Create - List parts = new MassiveList(); + List parts = new MassiveList<>(); // Fill for (Entry, Object> entry : this.splitEntries(value)) diff --git a/src/com/massivecraft/massivecore/mson/Mson.java b/src/com/massivecraft/massivecore/mson/Mson.java index 5c16cdb4..bcd18b15 100644 --- a/src/com/massivecraft/massivecore/mson/Mson.java +++ b/src/com/massivecraft/massivecore/mson/Mson.java @@ -48,6 +48,7 @@ public class Mson implements Serializable public static final Mson SPACE = mson(" "); public static final Mson EMPTY = mson(""); public static final Mson NEWLINE = mson("\n"); + public static final Mson DOT = mson("."); // -------------------------------------------- // // GSON