Search in sources :

Example 1 with Requirement

use of com.massivecraft.massivecore.command.requirement.Requirement 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;
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) Requirement(com.massivecraft.massivecore.command.requirement.Requirement) MassiveList(com.massivecraft.massivecore.collections.MassiveList) ChatColor(org.bukkit.ChatColor)

Aggregations

MassiveList (com.massivecraft.massivecore.collections.MassiveList)1 Requirement (com.massivecraft.massivecore.command.requirement.Requirement)1 Mson (com.massivecraft.massivecore.mson.Mson)1 ChatColor (org.bukkit.ChatColor)1