diff --git a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java index 5b3b9a06..6894079d 100644 --- a/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java +++ b/src/com/massivecraft/massivecore/command/type/combined/TypeCombined.java @@ -102,13 +102,13 @@ public abstract class TypeCombined extends TypeAbstract public abstract List split(T value); // -------------------------------------------- // - // METHODS + // SPLIT ENTRIES // -------------------------------------------- // public List, Object>> splitEntries(T value) { // Create - List, Object>> ret = new MassiveList, Object>>(); + List, Object>> ret = new MassiveList<>(); // Fill List parts = this.split(value); @@ -125,6 +125,64 @@ public abstract class TypeCombined extends TypeAbstract return ret; } + // -------------------------------------------- // + // SPLIT ENTRIES USER + // -------------------------------------------- // + // This entire section was made to handle the problem that the visual should contain what is nulled in user order. + // Just because we don't want it when we read arguments in commands does not mean we can omit it from the visual. + // The better and abstracted solution (that I skipped) would be to have multiple custom orders. + // One for command parameters. + // One for visuals. + // TODO: Implement such an abstraction. + // TODO: The current hack assumes we want all in the visuals. That may not be true. + + public List, Object>> splitEntriesUser(T value) + { + // Create + List, Object>> ret = new MassiveList<>(); + + // Fill + List, Object>> tech = this.splitEntries(value); + for (int i : this.getUserOrderAugmented()) + { + ret.add(tech.get(i)); + } + + // Return + return ret; + } + + public List getUserOrderAugmented() + { + // Create + List ret = new MassiveList<>(this.getUserOrder()); + + // Fill + for (int indexTech = 0; indexTech < this.getInnerTypes().size(); indexTech++) + { + if (ret.contains(indexTech)) continue; + addSorted(ret, indexTech); + } + + // Return + return ret; + } + + private static void addSorted(List list, Integer element) + { + for (int index = 0; index < list.size(); index++) + { + Integer current = list.get(index); + Integer next = (index + 1 < list.size() ? list.get(index + 1) : null); + if ((element <= current) && (next == null || element >= next)) + { + list.add(index, element); + return; + } + } + list.add(element); + } + // -------------------------------------------- // // META // -------------------------------------------- // @@ -157,10 +215,8 @@ public abstract class TypeCombined extends TypeAbstract List parts = new MassiveList<>(); // Fill - List, Object>> entries = this.splitEntries(value); - for (int i = 0; i < entries.size(); i++) + for (Entry, Object> entry : this.splitEntriesUser(value)) { - 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; @@ -183,10 +239,8 @@ public abstract class TypeCombined extends TypeAbstract List parts = new MassiveList<>(); // Fill - List, Object>> entries = this.splitEntries(value); - for (int i = 0; i < entries.size(); i++) + for (Entry, Object> entry : this.splitEntriesUser(value)) { - Entry, Object> entry = entries.get(this.getIndexTech(i)); Type type = (Type) entry.getKey(); String part = type.getVisual(entry.getValue(), sender); if ( ! this.isVisualNullIncluded() && part == null) continue;