Search in sources :

Example 11 with Mson

use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.

the class TypeCombined method getVisualMsonInner.

// -------------------------------------------- //
// WRITE VISUAL MSON
// -------------------------------------------- //
@SuppressWarnings("unchecked")
@Override
public Mson getVisualMsonInner(T value, CommandSender sender) {
    // Create
    List<Mson> parts = new MassiveList<>();
    // Fill
    for (Entry<Type<?>, Object> entry : this.splitEntriesUser(value)) {
        Type<Object> type = (Type<Object>) entry.getKey();
        Mson part = type.getVisualMson(entry.getValue(), sender);
        if (!this.isVisualMsonNullIncluded() && part == null)
            continue;
        parts.add(part);
    }
    // Return
    return Mson.implode(parts, this.getVisualMsonSeparator());
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) MassiveList(com.massivecraft.massivecore.collections.MassiveList) Type(com.massivecraft.massivecore.command.type.Type)

Example 12 with Mson

use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.

the class Parameter method getTemplate.

public Mson getTemplate(CommandSender sender) {
    Mson ret;
    if (this.isRequiredFor(sender)) {
        ret = mson("<" + this.getName() + ">");
    } else {
        String def = this.getDefaultDesc();
        def = (def != null ? "=" + def : "");
        ret = mson("[" + this.getName() + def + "]");
    }
    return ret;
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson)

Example 13 with Mson

use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.

the class CommandEditAbstract method attemptSetPerform.

protected void attemptSetPerform(V after) {
    String descProperty = this.getProperty().getDisplayName();
    Mson descObject = this.getObjectVisual();
    Mson descValue = this.getInheritedVisual();
    // Create messages
    List<Mson> messages = new MassiveList<>();
    // Before
    // We inform what the value was before.
    messages.add(mson(mson("Before: ").color(ChatColor.AQUA), descValue));
    // Apply
    // We set the new property value.
    this.setValue(after);
    // After
    // We inform what the value is after.
    descValue = this.getInheritedVisual();
    messages.add(mson(mson("After: ").color(ChatColor.AQUA), descValue));
    // Startup
    // We inform what property and object the edit is taking place on.
    // The visual might change after modification, so this should be added after we have made the change.
    descObject = this.getObjectVisual();
    messages.add(0, mson(descProperty, " for ", descObject, " edited:").color(ChatColor.GRAY));
    message(messages);
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) MassiveList(com.massivecraft.massivecore.collections.MassiveList)

Example 14 with Mson

use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.

the class CommandEditAbstract method show.

public void show(int page) {
    List<Mson> show = this.getValueType().getShow(this.getValue(), sender);
    Property<O, V> property = this.getProperty();
    Mson descProperty = property.getDisplayNameMson();
    Mson descObject = this.getObjectVisual();
    Mson title;
    if (property instanceof PropertyThis) {
        title = descObject;
    } else {
        title = mson(descProperty, " for ", descObject);
    }
    // For things with line breaks.
    if (show.size() > 1) {
        message(Txt.getPage(show, page, title, this));
    } else // Others
    {
        message(Mson.prepondfix(title.add(mson(":").color(ChatColor.GRAY)), show, null));
    }
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson)

Example 15 with Mson

use of com.massivecraft.massivecore.mson.Mson in project MassiveCore by MassiveCraft.

the class CommandEditContainerAbstract method attemptSetPerform.

@SuppressWarnings("unchecked")
@Override
public void attemptSetPerform(V after) {
    V before = this.getInheritedValue();
    Mson descProperty = this.getProperty().getDisplayNameMson();
    // Apply
    // We set the new property value.
    this.setValue(after);
    // Create messages
    List<Mson> messages = new MassiveList<>();
    messages.add(mson(descProperty, mson(" for ").color(ChatColor.GRAY), this.getObjectVisual(), mson(" edited:").color(ChatColor.GRAY)));
    // Note: The result of getAdditions is not actually V, but the implementation doesn't care.
    Collection<Object> additions = ContainerUtil.getAdditions(before, after);
    if (!additions.isEmpty()) {
        messages.add(Mson.prepondfix(mson("Additions:").color(ChatColor.AQUA), this.getValueType().getVisualMson((V) additions, sender), null));
    }
    // Note: The result of getDeletions is not actually V, but the implementation doesn't care.
    Collection<Object> deletions = ContainerUtil.getDeletions(before, after);
    if (!deletions.isEmpty()) {
        messages.add(Mson.prepondfix(mson("Deletions:").color(ChatColor.AQUA), this.getValueType().getVisualMson((V) deletions, sender), null));
    }
    message(messages);
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) MassiveList(com.massivecraft.massivecore.collections.MassiveList)

Aggregations

Mson (com.massivecraft.massivecore.mson.Mson)20 MassiveList (com.massivecraft.massivecore.collections.MassiveList)7 MassiveException (com.massivecraft.massivecore.MassiveException)2 Requirement (com.massivecraft.massivecore.command.requirement.Requirement)1 Type (com.massivecraft.massivecore.command.type.Type)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 ChatColor (org.bukkit.ChatColor)1 CommandSender (org.bukkit.command.CommandSender)1 Player (org.bukkit.entity.Player)1