diff --git a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java index edc6b999..ac400195 100644 --- a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java +++ b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java @@ -24,17 +24,7 @@ public abstract class TypeCombined extends TypeAbstract private Pattern separatorsPattern = null; public Pattern getSeparatorsPattern() { return this.separatorsPattern; } - private void buildSeparatorsPattern() - { - StringBuilder regex = new StringBuilder(); - regex.append("["); - for (char c : this.separators.toCharArray()) - { - regex.append(Pattern.quote(String.valueOf(c))); - } - regex.append("]+"); - separatorsPattern = Pattern.compile(regex.toString()); - } + private void buildSeparatorsPattern() { this.separatorsPattern = buildSeparatorsPattern(this.separators); } private String separators = null; public String getSeparators() { return this.separators; } @@ -44,6 +34,37 @@ public abstract class TypeCombined extends TypeAbstract this.buildSeparatorsPattern(); } + private String separatorTypeName = " "; + public String getSeparatorTypeName() { return this.separatorTypeName; } + public void setSeparatorTypeName(String separatorTypeName) { this.separatorTypeName = separatorTypeName; } + + // Visual + private boolean includeNullVisual = true; + public boolean doesIncludeNullVisual() { return this.includeNullVisual; } + public void setIncludeNullVisual(boolean includeNullVisual) { this.includeNullVisual = includeNullVisual; } + + private String separatorVisual = " "; + public String getSeparatorVisual() { return this.separatorVisual; } + public void setSeparatorVisual(String separatorVisual) { this.separatorVisual = separatorVisual; } + + // Name + private boolean includeNullName = true; + public boolean doesIncludeNullName() { return this.includeNullName; } + public void setIncludeNullName(boolean includeNullName) { this.includeNullName = includeNullName; } + + private String separatorName = " "; + public String getSeparatorName() { return this.separatorName; } + public void setSeparatorName(String separatorName) { this.separatorName = separatorName; } + + // Id + private boolean includeNullId = true; + public boolean doesIncludeNullId() { return this.includeNullId; } + public void setIncludeNullId(boolean includeNullId) { this.includeNullId = includeNullId; } + + private String separatorId = " "; + public String getSeparatorId() { return this.separatorId; } + public void setSeparatorId(String separatorId) { this.separatorId = separatorId; } + // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // @@ -103,7 +124,7 @@ public abstract class TypeCombined extends TypeAbstract } // Return - return Txt.implode(parts, " "); + return Txt.implode(parts, this.getSeparatorTypeName()); } // -------------------------------------------- // @@ -122,11 +143,12 @@ public abstract class TypeCombined extends TypeAbstract @SuppressWarnings("unchecked") Type type = (Type) entry.getKey(); String part = type.getVisual(entry.getValue(), sender); + if ( ! this.doesIncludeNullVisual() && part == null) continue; parts.add(part); } // Return - return Txt.implode(parts, " "); + return Txt.implode(parts, this.getSeparatorVisual()); } // -------------------------------------------- // @@ -145,11 +167,12 @@ public abstract class TypeCombined extends TypeAbstract @SuppressWarnings("unchecked") Type type = (Type) entry.getKey(); String part = type.getName(entry.getValue()); + if ( ! this.doesIncludeNullName() && part == null) continue; parts.add(part); } // Return - return Txt.implode(parts, " "); + return Txt.implode(parts, this.getSeparatorName()); } // -------------------------------------------- // @@ -168,11 +191,12 @@ public abstract class TypeCombined extends TypeAbstract @SuppressWarnings("unchecked") Type type = (Type) entry.getKey(); String part = type.getId(entry.getValue()); + if ( ! this.doesIncludeNullId() && part == null) continue; parts.add(part); } // Return - return Txt.implode(parts, " "); + return Txt.implode(parts, this.getSeparatorId()); } // -------------------------------------------- // @@ -257,5 +281,21 @@ public abstract class TypeCombined extends TypeAbstract if (args.size() > this.getInnerTypes().size()) return null; return this.getInnerType(args.size() - 1); } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static Pattern buildSeparatorsPattern(String separators) + { + StringBuilder regex = new StringBuilder(); + regex.append("["); + for (char c : separators.toCharArray()) + { + regex.append(Pattern.quote(String.valueOf(c))); + } + regex.append("]+"); + return Pattern.compile(regex.toString()); + } } diff --git a/src/com/massivecraft/massivecore/command/type/combined/TypeEntry.java b/src/com/massivecraft/massivecore/command/type/combined/TypeEntry.java index b9cedbaf..0b2081b4 100644 --- a/src/com/massivecraft/massivecore/command/type/combined/TypeEntry.java +++ b/src/com/massivecraft/massivecore/command/type/combined/TypeEntry.java @@ -24,6 +24,7 @@ public class TypeEntry extends TypeCombined> public TypeEntry(Type keyType, Type valueType) { super(keyType, valueType); + this.setSeparatorTypeName(" and "); } // -------------------------------------------- // @@ -36,13 +37,7 @@ public class TypeEntry extends TypeCombined> // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // - - @Override - public String getTypeName() - { - return this.getKeyType().getTypeName() + " and " + this.getValueType().getTypeName(); - } - + @SuppressWarnings("unchecked") @Override public Entry combine(List parts)