1.0h Mson titles

This commit is contained in:
BuildTools 2016-03-15 19:46:40 +01:00 committed by Olof Larsson
parent 04c059dc8b
commit e7a397668b
7 changed files with 56 additions and 24 deletions

View File

@ -54,7 +54,7 @@ public class CmdMassiveCoreStoreListcolls extends MassiveCommand
collnames.addAll(db.getCollnames()); collnames.addAll(db.getCollnames());
// Do it! // Do it!
msg(Txt.titleize("Collections in "+db.getDbName())); message(Txt.titleize("Collections in "+db.getDbName()));
for (String collname : collnames) for (String collname : collnames)
{ {
String message = Txt.parse("<h>") + collname; String message = Txt.parse("<h>") + collname;

View File

@ -49,7 +49,7 @@ public class CmdMassiveCoreStoreStats extends MassiveCommand
public void performTotal() public void performTotal()
{ {
msg(Txt.titleize("MStore Total Statistics")); message(Txt.titleize("MStore Total Statistics"));
//msg("<k>Last Examine Duration: <v>%d<i>ms", ExamineThread.get().getLastDurationMillis()); //msg("<k>Last Examine Duration: <v>%d<i>ms", ExamineThread.get().getLastDurationMillis());
msg("<a>== <k>Coll <a>| <k>Sync Count In <a>| <k>Sync Count Out <a>=="); msg("<a>== <k>Coll <a>| <k>Sync Count In <a>| <k>Sync Count Out <a>==");
for (Entry<String, Coll<?>> entry : Coll.getMap().entrySet()) for (Entry<String, Coll<?>> entry : Coll.getMap().entrySet())
@ -65,7 +65,7 @@ public class CmdMassiveCoreStoreStats extends MassiveCommand
public void performColl(Coll<?> coll) public void performColl(Coll<?> coll)
{ {
msg(Txt.titleize("MStore "+coll.getName()+" Statistics")); message(Txt.titleize("MStore "+coll.getName()+" Statistics"));
msg("<k>Basename: <v>%s", coll.getBasename()); msg("<k>Basename: <v>%s", coll.getBasename());
msg("<k>Universe: <v>%s", coll.getUniverse()); msg("<k>Universe: <v>%s", coll.getUniverse());
msg("<k>Entity Count: <v>%d", coll.getIds().size()); msg("<k>Entity Count: <v>%d", coll.getIds().size());

View File

@ -35,7 +35,7 @@ public class CmdMassiveCoreUsysAspectShow extends MassiveCommand
{ {
Aspect aspect = this.readArg(); Aspect aspect = this.readArg();
msg(Txt.titleize("Aspect: "+aspect.getId())); message(Txt.titleize("Aspect: "+aspect.getId()));
msg("<k>using multiverse: <v>%s",aspect.getMultiverse().getId()); msg("<k>using multiverse: <v>%s",aspect.getMultiverse().getId());
for (String descLine : aspect.getDesc()) for (String descLine : aspect.getDesc())

View File

@ -40,7 +40,7 @@ public class CmdMassiveCoreUsysMultiverseShow extends MassiveCommand
{ {
Multiverse multiverse = this.readArg(); Multiverse multiverse = this.readArg();
msg(Txt.titleize("Multiverse: "+multiverse.getId())); message(Txt.titleize("Multiverse: "+multiverse.getId()));
for (String universe : multiverse.getUniverses()) for (String universe : multiverse.getUniverses())
{ {

View File

@ -741,6 +741,20 @@ public class Mson implements Serializable
return ret; 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 // Contains
public boolean contains(CharSequence sequence) public boolean contains(CharSequence sequence)
{ {

View File

@ -534,7 +534,7 @@ public class MUtil
List<String> messages = new MassiveList<>(); List<String> messages = new MassiveList<>();
// Fill // Fill
messages.add(Txt.titleize(title)); messages.add(Txt.titleize(title).toPlain(true));
messages.addAll(MUtil.getStackTraceStrings(1, true)); messages.addAll(MUtil.getStackTraceStrings(1, true));
// Message // Message

View File

@ -466,18 +466,30 @@ public class Txt
private final static String titleizeLine = repeat("_", 52); private final static String titleizeLine = repeat("_", 52);
private final static int titleizeBalance = -1; private final static int titleizeBalance = -1;
public static String titleize(String str) public static Mson titleize(Object obj)
{ {
String center = ".[ "+ parse("<l>") + str + parse("<a>") + " ]."; Mson title = mson(obj);
int centerlen = ChatColor.stripColor(center).length(); 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 pivot = titleizeLine.length() / 2;
int eatLeft = (centerlen / 2) - titleizeBalance; int eatLeft = (centerlen / 2) - titleizeBalance;
int eatRight = (centerlen - eatLeft) + titleizeBalance; int eatRight = (centerlen - eatLeft) + titleizeBalance;
if (eatLeft < pivot) if (eatLeft < pivot)
return parse("<a>")+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 else
return parse("<a>")+center; return center;
} }
public static Mson getMessageEmpty() public static Mson getMessageEmpty()
@ -501,14 +513,20 @@ public class Txt
} }
} }
public static Mson titleizeMson(String str, int pagecount, int pageHumanBased, MassiveCommand command, List<String> args) public static Mson titleizeMson(Object obj, int pagecount, int pageHumanBased, MassiveCommand command, List<String> args)
{ {
if (command == null) return mson(titleize(str + parse("<a>") + " " + pageHumanBased + "/" + pagecount)); if (command == null)
{
return titleize(mson(
obj,
Mson.SPACE,
mson(pageHumanBased + "/" + pagecount).color(ChatColor.GOLD)
));
}
// Math // Math
String title = str + " " + "[<]" + pageHumanBased + "/" + pagecount + "[>]"; Mson title = mson(obj, Mson.SPACE, "[<]", String.valueOf(pageHumanBased), "/", String.valueOf(pagecount), "[>]");
String center = ".[ " + title + " ]."; int centerlen = ".[ ".length() + title.length() + " ].".length();
int centerlen = center.length();
int pivot = titleizeLine.length() / 2; int pivot = titleizeLine.length() / 2;
int eatLeft = (centerlen / 2) - titleizeBalance; int eatLeft = (centerlen / 2) - titleizeBalance;
int eatRight = (centerlen - eatLeft) + titleizeBalance; int eatRight = (centerlen - eatLeft) + titleizeBalance;
@ -516,7 +534,7 @@ public class Txt
// Mson // Mson
Mson centerMson = mson( Mson centerMson = mson(
mson(".[ ").color(ChatColor.GOLD), mson(".[ ").color(ChatColor.GOLD),
mson(str + " ").color(ChatColor.DARK_GREEN), mson(obj, Mson.SPACE).color(ChatColor.DARK_GREEN),
getFlipSection(pagecount, pageHumanBased, args, command), getFlipSection(pagecount, pageHumanBased, args, command),
mson(" ].").color(ChatColor.GOLD) mson(" ].").color(ChatColor.GOLD)
); );
@ -537,36 +555,36 @@ public class Txt
} }
} }
public static List<Mson> getPage(List<?> lines, int pageHumanBased, String title) public static List<Mson> getPage(List<?> lines, int pageHumanBased, Object title)
{ {
return getPage(lines, pageHumanBased, title, null, null, null); return getPage(lines, pageHumanBased, title, null, null, null);
} }
public static List<Mson> getPage(List<?> lines, int pageHumanBased, String title, CommandSender sender) public static List<Mson> getPage(List<?> lines, int pageHumanBased, Object title, CommandSender sender)
{ {
return getPage(lines, pageHumanBased, title, sender, null, null); return getPage(lines, pageHumanBased, title, sender, null, null);
} }
public static List<Mson> getPage(List<?> lines, int pageHumanBased, String title, MassiveCommand command) public static List<Mson> getPage(List<?> lines, int pageHumanBased, Object title, MassiveCommand command)
{ {
return getPage(lines, pageHumanBased, title, command, command.getArgs()); return getPage(lines, pageHumanBased, title, command, command.getArgs());
} }
public static List<Mson> getPage(List<?> lines, int pageHumanBased, String title, MassiveCommand command, List<String> args) public static List<Mson> getPage(List<?> lines, int pageHumanBased, Object title, MassiveCommand command, List<String> args)
{ {
return getPage(lines, pageHumanBased, title, command.sender, command, args); return getPage(lines, pageHumanBased, title, command.sender, command, args);
} }
public static List<Mson> getPage(List<?> lines, int pageHumanBased, String title, CommandSender sender, MassiveCommand command, List<String> args) public static List<Mson> getPage(List<?> lines, int pageHumanBased, Object title, CommandSender sender, MassiveCommand command, List<String> args)
{ {
return getPage(lines, pageHumanBased, title, (sender == null || sender instanceof Player) ? Txt.PAGEHEIGHT_PLAYER : Txt.PAGEHEIGHT_CONSOLE, command, args); return getPage(lines, pageHumanBased, title, (sender == null || sender instanceof Player) ? Txt.PAGEHEIGHT_PLAYER : Txt.PAGEHEIGHT_CONSOLE, command, args);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static List<Mson> getPage(List<?> lines, int pageHumanBased, String title, int pageheight, MassiveCommand command, List<String> args) public static List<Mson> getPage(List<?> lines, int pageHumanBased, Object title, int pageheight, MassiveCommand command, List<String> args)
{ {
// Create Ret // Create Ret
List<Mson> ret = new ArrayList<Mson>(); List<Mson> ret = new MassiveList<>();
int pageZeroBased = pageHumanBased - 1; int pageZeroBased = pageHumanBased - 1;
int pagecount = (int)Math.ceil(((double)lines.size()) / pageheight); int pagecount = (int)Math.ceil(((double)lines.size()) / pageheight);