diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreListcolls.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreListcolls.java index 11c72486..29bfc5cc 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreListcolls.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreListcolls.java @@ -54,7 +54,7 @@ public class CmdMassiveCoreStoreListcolls extends MassiveCommand collnames.addAll(db.getCollnames()); // Do it! - msg(Txt.titleize("Collections in "+db.getDbName())); + message(Txt.titleize("Collections in "+db.getDbName())); for (String collname : collnames) { String message = Txt.parse("") + collname; diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreStats.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreStats.java index 5f9de615..d1d53c2c 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreStats.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreStoreStats.java @@ -49,7 +49,7 @@ public class CmdMassiveCoreStoreStats extends MassiveCommand public void performTotal() { - msg(Txt.titleize("MStore Total Statistics")); + message(Txt.titleize("MStore Total Statistics")); //msg("Last Examine Duration: %dms", ExamineThread.get().getLastDurationMillis()); msg("== Coll | Sync Count In | Sync Count Out =="); for (Entry> entry : Coll.getMap().entrySet()) @@ -65,7 +65,7 @@ public class CmdMassiveCoreStoreStats extends MassiveCommand public void performColl(Coll coll) { - msg(Txt.titleize("MStore "+coll.getName()+" Statistics")); + message(Txt.titleize("MStore "+coll.getName()+" Statistics")); msg("Basename: %s", coll.getBasename()); msg("Universe: %s", coll.getUniverse()); msg("Entity Count: %d", coll.getIds().size()); diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsysAspectShow.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsysAspectShow.java index 25cb4a79..d96a10a6 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsysAspectShow.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsysAspectShow.java @@ -35,7 +35,7 @@ public class CmdMassiveCoreUsysAspectShow extends MassiveCommand { Aspect aspect = this.readArg(); - msg(Txt.titleize("Aspect: "+aspect.getId())); + message(Txt.titleize("Aspect: "+aspect.getId())); msg("using multiverse: %s",aspect.getMultiverse().getId()); for (String descLine : aspect.getDesc()) diff --git a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsysMultiverseShow.java b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsysMultiverseShow.java index 7ce14680..31741c67 100644 --- a/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsysMultiverseShow.java +++ b/src/com/massivecraft/massivecore/command/massivecore/CmdMassiveCoreUsysMultiverseShow.java @@ -40,7 +40,7 @@ public class CmdMassiveCoreUsysMultiverseShow extends MassiveCommand { Multiverse multiverse = this.readArg(); - msg(Txt.titleize("Multiverse: "+multiverse.getId())); + message(Txt.titleize("Multiverse: "+multiverse.getId())); for (String universe : multiverse.getUniverses()) { diff --git a/src/com/massivecraft/massivecore/mson/Mson.java b/src/com/massivecraft/massivecore/mson/Mson.java index 35e481a0..6cef8655 100644 --- a/src/com/massivecraft/massivecore/mson/Mson.java +++ b/src/com/massivecraft/massivecore/mson/Mson.java @@ -741,6 +741,20 @@ public class Mson implements Serializable return ret; } + // Length + public int length() + { + int ret = this.getText().length(); + if (this.hasExtra()) + { + for (Mson part : this.getExtra()) + { + ret += part.length(); + } + } + return ret; + } + // Contains public boolean contains(CharSequence sequence) { diff --git a/src/com/massivecraft/massivecore/util/MUtil.java b/src/com/massivecraft/massivecore/util/MUtil.java index f2e1a91f..589dc679 100644 --- a/src/com/massivecraft/massivecore/util/MUtil.java +++ b/src/com/massivecraft/massivecore/util/MUtil.java @@ -534,7 +534,7 @@ public class MUtil List messages = new MassiveList<>(); // Fill - messages.add(Txt.titleize(title)); + messages.add(Txt.titleize(title).toPlain(true)); messages.addAll(MUtil.getStackTraceStrings(1, true)); // Message diff --git a/src/com/massivecraft/massivecore/util/Txt.java b/src/com/massivecraft/massivecore/util/Txt.java index b50edac9..68e01b49 100644 --- a/src/com/massivecraft/massivecore/util/Txt.java +++ b/src/com/massivecraft/massivecore/util/Txt.java @@ -466,18 +466,30 @@ public class Txt private final static String titleizeLine = repeat("_", 52); private final static int titleizeBalance = -1; - public static String titleize(String str) + public static Mson titleize(Object obj) { - String center = ".[ "+ parse("") + str + parse("") + " ]."; - int centerlen = ChatColor.stripColor(center).length(); + Mson title = mson(obj); + if (title.getColor() == null) title = title.color(ChatColor.DARK_GREEN); + + Mson center = mson( + mson(".[ ").color(ChatColor.GOLD), + title, + mson(" ].").color(ChatColor.GOLD) + ); + + int centerlen = center.length(); int pivot = titleizeLine.length() / 2; int eatLeft = (centerlen / 2) - titleizeBalance; int eatRight = (centerlen - eatLeft) + titleizeBalance; if (eatLeft < pivot) - return parse("")+titleizeLine.substring(0, pivot - eatLeft) + center + titleizeLine.substring(pivot + eatRight); + return mson( + mson(titleizeLine.substring(0, pivot - eatLeft)).color(ChatColor.GOLD), + center, + mson(titleizeLine.substring(pivot + eatRight)).color(ChatColor.GOLD) + ); else - return parse("")+center; + return center; } public static Mson getMessageEmpty() @@ -501,14 +513,20 @@ public class Txt } } - public static Mson titleizeMson(String str, int pagecount, int pageHumanBased, MassiveCommand command, List args) + public static Mson titleizeMson(Object obj, int pagecount, int pageHumanBased, MassiveCommand command, List args) { - if (command == null) return mson(titleize(str + parse("") + " " + pageHumanBased + "/" + pagecount)); + if (command == null) + { + return titleize(mson( + obj, + Mson.SPACE, + mson(pageHumanBased + "/" + pagecount).color(ChatColor.GOLD) + )); + } // Math - String title = str + " " + "[<]" + pageHumanBased + "/" + pagecount + "[>]"; - String center = ".[ " + title + " ]."; - int centerlen = center.length(); + Mson title = mson(obj, Mson.SPACE, "[<]", String.valueOf(pageHumanBased), "/", String.valueOf(pagecount), "[>]"); + int centerlen = ".[ ".length() + title.length() + " ].".length(); int pivot = titleizeLine.length() / 2; int eatLeft = (centerlen / 2) - titleizeBalance; int eatRight = (centerlen - eatLeft) + titleizeBalance; @@ -516,7 +534,7 @@ public class Txt // Mson Mson centerMson = mson( mson(".[ ").color(ChatColor.GOLD), - mson(str + " ").color(ChatColor.DARK_GREEN), + mson(obj, Mson.SPACE).color(ChatColor.DARK_GREEN), getFlipSection(pagecount, pageHumanBased, args, command), mson(" ].").color(ChatColor.GOLD) ); @@ -537,36 +555,36 @@ public class Txt } } - public static List getPage(List lines, int pageHumanBased, String title) + public static List getPage(List lines, int pageHumanBased, Object title) { return getPage(lines, pageHumanBased, title, null, null, null); } - public static List getPage(List lines, int pageHumanBased, String title, CommandSender sender) + public static List getPage(List lines, int pageHumanBased, Object title, CommandSender sender) { return getPage(lines, pageHumanBased, title, sender, null, null); } - public static List getPage(List lines, int pageHumanBased, String title, MassiveCommand command) + public static List getPage(List lines, int pageHumanBased, Object title, MassiveCommand command) { return getPage(lines, pageHumanBased, title, command, command.getArgs()); } - public static List getPage(List lines, int pageHumanBased, String title, MassiveCommand command, List args) + public static List getPage(List lines, int pageHumanBased, Object title, MassiveCommand command, List args) { return getPage(lines, pageHumanBased, title, command.sender, command, args); } - public static List getPage(List lines, int pageHumanBased, String title, CommandSender sender, MassiveCommand command, List args) + public static List getPage(List lines, int pageHumanBased, Object title, CommandSender sender, MassiveCommand command, List args) { return getPage(lines, pageHumanBased, title, (sender == null || sender instanceof Player) ? Txt.PAGEHEIGHT_PLAYER : Txt.PAGEHEIGHT_CONSOLE, command, args); } @SuppressWarnings("unchecked") - public static List getPage(List lines, int pageHumanBased, String title, int pageheight, MassiveCommand command, List args) + public static List getPage(List lines, int pageHumanBased, Object title, int pageheight, MassiveCommand command, List args) { // Create Ret - List ret = new ArrayList(); + List ret = new MassiveList<>(); int pageZeroBased = pageHumanBased - 1; int pagecount = (int)Math.ceil(((double)lines.size()) / pageheight);