Theme

Creating a Theme

A Theme in SefiLib is a way to pre-define a style and reuse it in multi locations.

It supports basic chat messages and strings, Themed ItemStack and Themed SlimefunItemStack also.

To create a new Theme, first add the import:

import io.github.sefiraat.sefilib.string.Theme;

Then you need to choose your ChatColor for the theme.

ChatColor chatColor = ChatColor.of("#3295a8");
ChatColor chatColor = ChatColor.RED;
Color color = new Color(255, 150, 20);
ChatColor chatColor = ChatColor.of(color);

Be sure you use ChatColor from net.md_5.bungee.api.ChatColor not org.bukkit.ChatColor

Then you need a String that will be the name, lore line and tag for this Theme. This string is used in the following ways:

  • Added to the final line in the lore of an ItemStack

  • Prepends any logging message sent via the Theme

Then create a new Theme using these two arguments.

Theme TRAIT = new Theme(ChatColor.of("#3295a8"), "Trait");

I would suggest creating themes as static elements of a utility class, as per the below example:

package dev.sefiraat.slimetinker2.implementation;

import io.github.sefiraat.sefilib.string.Theme;
import net.md_5.bungee.api.ChatColor;

public final class TinkerThemes {

    private TinkerThemes() {
        throw new IllegalStateException("Utility class");
    }

    public static final Theme MAIN = new Theme(ChatColor.of("#8a0e0e"), "SlimeTinker2");
    public static final Theme RESEARCH = new Theme(ChatColor.of("#a60e03"), "Research");
    public static final Theme CRAFTING = new Theme(ChatColor.of("#dbcea9"), "Crafting Material");
    public static final Theme RECIPE_TYPE = new Theme(ChatColor.of("#ffe89c"), "Recipe Type");
    public static final Theme MACHINE = new Theme(ChatColor.of("#3295a8"), "Machine");
    public static final Theme TOOL = new Theme(ChatColor.of("#3295a8"), "Tool");
    public static final Theme PART = new Theme(ChatColor.of("#dbcea9"), "Part");
    public static final Theme TRAIT = new Theme(ChatColor.of("#3295a8"), "Trait");
    public static final Theme MATERIAL = new Theme(ChatColor.of("#dbcea9"), "Material");
    public static final Theme ENCHANTMENT = new Theme(ChatColor.of("#ffe89c"), "Enchantment");
    public static final Theme UPGRADE = new Theme(ChatColor.of("#ea201a"), "Upgrade");
    public static final Theme ADDON = new Theme(ChatColor.of("#8a0e0e"), "Addon");
}

The Theme class comes with some default themes that can be used for common purposes (and used by Theme for item generation and certain strings).

ItemStacks

To create an ItemStack with the Theme applied. Simply use the static method Theme#themedItemStack() providing the Material, the Theme to be applied, the Item's name and a List<String> for the lore.

The resulting ItemStack will have the name you provided using the Theme's color. The lore lines will follow after a single line gap using a the default Theme#PASSIVE. After all of the lore lines, there will be one last gap followed by the Theme's lore line using Theme#CLICK_INFO

An ItemStack created using Theme

SlimefunItemStack

A SlimefunItemStack is created in almost the same way, requiring an additional argument for the SlimefunItem ID as well as the List<String> being replaced with a String Array/String var-args

A SlimefunItemStack created using a Theme

Themed Strings

The Theme class overrides .toString() to provide the theme's base color. This means at the most basic level, you can use your theme field directly within a string concatenation or other message formatter

You can use the .apply(Object) method which will directly return a String that is colored to match the theme. The static method Theme#applyThemeToString(Theme, String) does the same as .apply() but in a static context.

You can use the .asTitle(Object, Object) method which will directly return a String that has the first object (as a string) in the themes color followed immedietly by a colon, a space then the second object as a string using the default Theme.PASSIVE. The static method Theme#applyThemeAsTitle(Theme, String, Object) does the same as .asTitle() but in a static context.

asTitle() example

Last updated

Was this helpful?