use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class Txt method createItemMson.
public static Mson createItemMson(ItemStack item) {
String name = Txt.getItemName(item);
String colors = Txt.getStartColors(name);
name = colors + "[" + ChatColor.stripColor(name) + "]";
Mson ret = Mson.fromParsedMessage(name);
if (InventoryUtil.isSomething(item))
ret = ret.item(item);
return ret;
}
use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class MassiveException method addMessage.
// Add single
public MassiveException addMessage(Object part) {
// Only add a newline if not empty.
Mson mson = this.messages.isEmpty() ? Mson.mson(part) : Mson.mson("\n", part);
this.messages = this.messages.add(mson);
return this;
}
use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class Button method render.
// -------------------------------------------- //
// RENDER
// -------------------------------------------- //
public Mson render() {
// Create
Mson ret = mson("[", Mson.parse(this.getName()), "]");
// Error and Enabled
String error = this.getError();
if (error == null) {
// Get Requirements
List<Requirement> requirements = new MassiveList<>();
requirements.add(RequirementIsPlayer.get());
requirements.addAll(this.getRequirements());
if (this.getCommand() != null)
requirements.addAll(this.getCommand().getRequirements());
// Check Requirements
error = RequirementAbstract.getRequirementsError(requirements, this.getSender(), this.getCommand(), true);
}
boolean enabled = (error == null);
// Check Verbose
if (!enabled && !this.isVerbose())
return null;
// Colorize
ChatColor color = (enabled ? COLOR_ENABLED : COLOR_DISABLED);
ret = ret.color(color);
// Empower
if (enabled) {
if (this.getCommand() != null) {
// Create the command line
String commandLine = this.getCommand().getCommandLine(this.getArgs());
// Render the corresponding tooltip
String tooltip = MsonEvent.command(commandLine).createTooltip();
// Possibly make command line clicking
if (this.isClicking())
commandLine = CmdMassiveCore.get().cmdMassiveCoreClick.getCommandLine(commandLine);
// Apply command
ret = ret.command(commandLine);
// Possibly set tooltip to hide the clicking clutter
if (this.isClicking())
ret = ret.tooltip(tooltip);
} else if (this.getLink() != null) {
ret = ret.link(this.getLink());
} else {
throw new RuntimeException();
}
} else {
ret = ret.tooltip(error);
}
// Pad
if (Boolean.TRUE.equals(this.isPaddingRight()))
return mson(ret, " ");
if (Boolean.FALSE.equals(this.isPaddingRight()))
return mson(" ", ret);
// Return
return ret;
}
use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class TypeAbstract method getVisualMsonInner.
@Override
public Mson getVisualMsonInner(T value, CommandSender sender) {
String visualInner = this.getVisualInner(value, sender);
Mson ret = Mson.fromParsedMessage(visualInner);
if (this.hasInnerProperties())
ret.tooltip(Mson.toPlain(this.getShow(value, sender), true));
return ret;
}
use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class TypeAbstractChoice method read.
@Override
public T read(String arg, CommandSender sender) throws MassiveException {
// NPE Evade
if (arg == null)
return null;
// Exact
T exact = this.getExactMatch(arg);
if (exact != null)
return exact;
// Get All
Collection<T> all = this.getAll(sender);
// Get Options
Map<String, T> options = this.getOptions();
if (options == null)
options = this.createOptions(all);
// Get Matches
List<T> matches = this.getMatches(options, arg, false);
// Exact
if (matches.size() == 1)
return matches.get(0);
// Exception
MassiveException exception = new MassiveException();
// Suggestions
boolean suggestNone = false;
boolean suggestAmbiguous = false;
boolean suggestAll = false;
boolean suggestLevenshtein = false;
// Nothing Found
String message;
if (matches.isEmpty()) {
message = String.format(MESSAGE_MATCH_NOTHING, this.getName(), arg);
exception.addMessage(message);
suggestLevenshtein = true;
} else // Ambiguous
{
message = String.format(MESSAGE_MATCH_AMBIGUOUS, matches.size(), this.getName(), arg);
exception.addMessage(message);
suggestAmbiguous = true;
}
// Suggest
if (all.isEmpty())
suggestNone = true;
if (all.size() <= this.getListCountMax())
suggestAll = true;
if (!this.canList(sender)) {
} else if (suggestNone) {
message = String.format(MESSAGE_AVAILABLE_EMPTY, this.getName());
exception.addMessage(message);
} else {
Collection<T> suggestions = null;
Mson format = SUGGEST_FORMAT;
Mson comma = SUGGEST_COMMMA;
Mson and = SUGGEST_AND;
Mson dot = SUGGEST_DOT;
if (suggestAmbiguous) {
suggestions = matches;
message = MESSAGE_COLON_AMBIGUOUS;
} else if (suggestAll) {
suggestions = all;
message = MESSAGE_COLON_ALL;
} else if (suggestLevenshtein) {
suggestions = this.getMatches(options, arg, true);
message = MESSAGE_COLON_SIMILAR;
}
if (suggestions.isEmpty()) {
exception.addMessage(MESSAGE_SUGGESTIONS_EMPTY);
} else if (suggestions.size() > this.getListCountMax()) {
message = String.format(MESSAGE_SUGGESTIONS_MUCH, this.getListCountMax());
exception.addMessage(message);
} else {
List<Mson> visuals = new MassiveList<>();
for (T value : suggestions) {
visuals.add(this.getVisualMson(value, sender));
}
exception.addMessage(Mson.mson(message, Mson.implodeCommaAndDot(visuals, format, comma, and, dot)));
}
}
// Help
String help = this.getHelp();
if (help != null)
exception.addMessage(help);
throw exception;
}
Aggregations