use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class MassiveCommand method getTemplate.
public Mson getTemplate(boolean addDesc, boolean onlyFirstAlias, CommandSender sender) {
// Create Ret
Mson ret = TEMPLATE_CORE;
// Get commands
List<MassiveCommand> commands = this.getChain(true);
// Add commands
boolean first = true;
for (MassiveCommand command : commands) {
Mson mson = null;
if (first && onlyFirstAlias) {
mson = mson(command.getAliases().get(0));
} else {
mson = mson(Txt.implode(command.getAliases(), ","));
}
if (sender != null && !command.isRequirementsMet(sender, false)) {
mson = mson.color(ChatColor.RED);
} else {
mson = mson.color(ChatColor.AQUA);
}
if (!first)
ret = ret.add(Mson.SPACE);
ret = ret.add(mson);
first = false;
}
// Check if last command is parentCommand and make command suggestable/clickable
if (commands.get(commands.size() - 1).isParent()) {
ret = ret.command(this);
} else {
ret = ret.suggest(this);
}
// Add args
for (Mson parameter : this.getTemplateParameters(sender)) {
ret = ret.add(Mson.SPACE);
ret = ret.add(parameter.color(ChatColor.DARK_AQUA));
}
// Add desc
if (addDesc) {
ret = ret.add(Mson.SPACE);
ret = ret.add(mson(this.getDesc()).color(ChatColor.YELLOW));
}
// Return Ret
return ret;
}
use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class MassiveCommand method execute.
// -------------------------------------------- //
// EXECUTOR
// -------------------------------------------- //
public void execute(CommandSender sender, List<String> args) {
try {
// Sender Field - Setup
this.senderFieldsOuter(sender);
// Apply Puzzler
args = this.applyPuzzler(args, sender);
this.setArgs(args);
// Requirements
if (!this.isRequirementsMet(sender, true))
return;
// Child Execution
if (this.isParent() && args.size() > 0) {
// Get matches
String token = args.get(0);
Set<MassiveCommand> matches = this.getChildren(token, false, null, true);
// Score!
if (matches.size() == 1) {
MassiveCommand child = matches.iterator().next();
args.remove(0);
child.execute(sender, args);
} else // Crap!
{
Mson base = null;
Collection<MassiveCommand> suggestions = null;
if (matches.isEmpty()) {
base = Lang.COMMAND_CHILD_NONE;
suggestions = this.getChildren(token, true, sender, false);
} else {
base = Lang.COMMAND_CHILD_AMBIGUOUS;
suggestions = this.getChildren(token, false, sender, false);
}
// Message: "The sub command X couldn't be found."
// OR
// Message: "The sub command X is ambiguous."
Mson bluetoken = mson(token).color(ChatColor.AQUA);
MixinMessage.get().messageOne(sender, base.replaceAll(Lang.COMMAND_REPLACEMENT, bluetoken).command(this));
// Message: "/f ally ..."
for (MassiveCommand suggestion : suggestions) {
MixinMessage.get().messageOne(sender, suggestion.getTemplate(false, false, sender));
}
// Message: "Use /Y to see all commands."
MixinMessage.get().messageOne(sender, Lang.COMMAND_CHILD_HELP.replaceAll(Lang.COMMAND_REPLACEMENT, this.getTemplate(false, false, sender)).command(this));
}
// NOTE: This return statement will jump to the finally block.
return;
}
// Self Execution > Arguments Valid
if (!this.isArgsValid(this.getArgs(), this.sender))
return;
// Self Execution > Perform
this.perform();
} catch (MassiveException ex) {
// Sometimes Types (or commands themselves) throw exceptions, to stop executing and notify the user.
if (ex.hasMessages()) {
MixinMessage.get().messageOne(sender, ex.getMessages());
}
} finally {
// Sender Sender - Cleanup
this.senderFieldsOuter(null);
}
}
use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class Property method getShowLines.
public List<Mson> getShowLines(O object, CommandSender sender) {
Mson prefix = Mson.mson(this.getDisplayNameMson(), Mson.mson(":").color(ChatColor.GRAY));
List<Mson> ret = Mson.prepondfix(prefix, this.getValueType().getShow(this.getInheritedValue(object), sender), this.getInheritanceSuffix(object));
for (ListIterator<Mson> it = ret.listIterator(1); it.hasNext(); ) {
Mson mson = it.next();
it.set(mson.text(SHOW_INDENT + mson.getText()));
}
return ret;
}
use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class TypeContainer method getVisualMsonInner.
// -------------------------------------------- //
// WRITE VISUAL
// -------------------------------------------- //
@Override
public Mson getVisualMsonInner(C container, CommandSender sender) {
// Empty
if (ContainerUtil.isEmpty(container))
return MSON_EMPTY;
// Create
List<Mson> parts = new MassiveList<>();
// Fill
List<E> elements = this.getContainerElementsOrdered(container);
Type<E> innerType = this.getInnerType();
int index = this.getIndexStart();
for (E element : elements) {
Mson part = innerType.getVisualMson(element, sender);
if (this.isIndexVisible()) {
part = Mson.mson(Mson.mson(String.valueOf(index)).color(ChatColor.WHITE), Mson.SPACE, part);
}
parts.add(part);
index++;
}
// Return
return Mson.implode(parts, Mson.mson("\n"));
}
use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.
the class EngineMassiveCoreSponsor method informInner.
public void informInner(CommandSender sender) {
// Enabled
if (!this.isEnabled(sender))
return;
// Messages
List<String> msgs = (IdUtil.isConsole(sender) ? MassiveCoreMSponsorInfo.get().consoleMsgs : MassiveCoreMSponsorInfo.get().ingameMsgs);
String senderVisual = MixinDisplayName.get().getDisplayName(sender, sender);
for (String msg : msgs) {
String message = Txt.parse(msg);
message = message.replace("{p}", senderVisual);
Mson mson = Mson.fromParsedMessage(message).link(MassiveCoreMSponsorInfo.get().ingameLink);
MixinMessage.get().messageOne(sender, mson);
}
// Sound
if (sender instanceof Player) {
Player player = (Player) sender;
SoundEffect.runAll(MassiveCoreMSponsorInfo.get().ingameSoundEffects, player);
}
}
Aggregations