KarmaAPI 1.3.0

Create commented yaml files, custom files, log files and much more, using this free API

  1. KarmaConfigs
    Native Minecraft Version:
    1.16
    Tested Minecraft Versions:
    • 1.7
    • 1.8
    • 1.9
    • 1.10
    • 1.11
    • 1.12
    • 1.13
    • 1.14
    • 1.15
    • 1.16
    Source Code:
    https://github.com/KarmaConfigs/KarmaAPI
    Bungee-Spigot compatible

    THIS API IS UNDER GSA GENERAL PLUGIN LICENSE


    POV: You are a developer searching for easy ways to manage your files or an easy way to get NMS classes or who knows... a directly method to send a title to a player in a really easy way, this API allows you for that and much more!

    Last implemented feature:
    Temporal and persistent holograms with item support

    [​IMG]


    Code (Text):

    <dependency>
        <groupId>ml.karmaconfigs</groupId>
        <artifactId>KarmaAPI-{Bukkit/Bungee/Common/Bundle}</artifactId>
        <version>1.3.0-SNAPSHOT</version>
        <scope>compile</scope>
    </dependency>
     
    HELP ME, I DON'T KNOW HOW TO MAKE MAVEN BUILD THE PLUGIN WITH DEPENDENCIES SCOPED WITH "compile"!

    Add this to your pom.xml
    Code (Text):

    <build>
        <finalName>MyAwesomePlugin</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <configuration>
                    <relocations>
                        <relocation>
                            <pattern>ml.karmaconfigs.api</pattern>
                            <shadedPattern>change.this</shadedPattern>
                        </relocation>
                    </relocations>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
     

    For extra help, read JavaDocs

    This api helps you to store inventories or items in a simple file, this using bukkit itemstack API ( itemstack serialization ). So it's completely compatible with bukkit.

    Code (Java):

    /**
    Inventory serialization
    */


    InventorySerializer inventory = new InventorySerializer(plugin, player.getInventory());

    inventory.save("InventoryOne");
    //or
    inventory.save(player.getUniqueId());

    /**
    Inventory deserialization
    */


    InventoryDeserializer deserializer = new InventoryDeserializer(plugin);

    Inventory stored = deserializer.getInventory("InventoryOne");

    //or

    deserializer.getInventory(player.getUniqueId());
     
    Code (Java):
    /**
    ItemStack serialization
    */


    ItemStackSerializer stacks = new ItemStackSerializer(plugin, ItemStack...);

    stacks.save("StacksOne");
    //or
    stacks.save(player.getUniqueId));

    /**
    ItemStack deserialization
    */


    ItemStackDeserializer deserializer = new ItemStackDeserializer(plugin);

    ItemStack[] contents = deserializer.getItems("StacksOne");
    //or
    contents = deserializer.getItems(player.getUniqueId());

    KarmaServer utilities allows you to get server version, build and more server information easily, it also allows you to check if the server is over or under an specified version in a really easy way!

    Code (Java):
    ServerVersion server = new ServerVersion(plugin);

    VersionUtils utils = server.utils();

    if (utils == null)
        return;

    String realVersion = utils.getRealVersion();
    /* Get the server real version, for example: 1.12.2 */

    String fullVersion = utils.getFullVersion();
    /* Get the server full version, for example git-Spigot-dcd1643-e60fc34 (MC: 1.12.2) */

    String package = utils.getPackageType();
    /* Get the server version build, for example: SNAPSHOT */

    float mainVersion = utils.getVersion();
    /* Get the server native version, for example 1.12 */

    int update = utils.getVersionUpdate();
    /* Get the server update version, for example 5 ( 1.16.5 ) */

    Version version = utils.getV();
    /* Returns the version as an enum type, for example v1_12_2 */

    boolean overOneNine = utils.isOver(Version.v1_9);
    /* Returns if the version is over the specified version */

    boolean underOneSevenThen = utils.isUnder(Version.v1_7_10);
    /* Returns if the version is under the specified version */

    Class<?> mcReflection = utils.getMinecraftClass("EntityPlayer");
    /* Returns a minecraft server class instance */

    Class<?> bukkitReflection = utils.getBukkitClass("CraftPlayer");
    /* Returns a craftbukkit class instance */

    Code (Java):
    //To create a temporal hologram ( it won't be stored anywhere )
    KarmaHologram tempHolo = KarmaHologram.createHologram(player.getLocation());
    tempHolo = KarmaHologram.createHologram(player.getLocation(), "Line 1", "&bLine 2");

    //It's equivalent to:
    tempHolo = new TempHologram(player.getLocation());
    tempHolo = new TempHologram(player.getLocation(), "Line 1", "&bLine 2");

    //To create a persistent hologram ( it will be stored so you can create a new KarmaHologram object with
    //the same name to load it )
    KarmaHologram persistent = KarmaHologram.createHologram(Main.getInstance(), "Hologram1");
    persistent = KarmaHologram.createHologram(Main.getInstance(), "Hologram1", player.getLocation());
    persistent = KarmaHologram.createHologram(Main.getInstance(), "Hologram1", player.getLocation(), "Line 1", "&bLine 2");

    //It's equivalent to:
    persistent = new PersistentHologram(Main.getInstance(), "Hologram1");
    persistent.add("Line 1");
    persistent.add("&bLine 2");
    //IF YOU SPAWN IT WITHOUT A PREVIOUSLY SPAWN LOCATION, IT WILL THROW AN ERROR
    persistent.spawn(player.getLocation());

    //You can also add items to the holograms
    persistent.add(new ItemStack(Material.DIAMOND_SWORD, 1));

    //To update the hologram lines, use
    persistent.updateLines();

    //You can toggle global visibility by using setVisible
    persistent.setVisible(true);

    //Or you can hide this hologram for specified players
    persistent.hide(player1, player2, player3);
    //The same applies for showing
    persistent.show(player1, player2, player3);

    For this, the original .yml file must be inside your jar file, otherwise it won't work...

    Code (Java):
    /**
    Creating the commented file
    */

    FileCopy configuration = new FileCopy(plugin, "config.yml");
    /* That config.yml file must be inside the jar file! */

    File configFile = new File(plugin.getDataFolder(), "config.yml");
    YamlConfiguration cfg = YamlConfiguration.loadConfiguration(configFile);

    try {
        configuration.copy(configFile);
    } catch (Throwable anyException) {
        System.out.println("Couldn't create config.yml");
    }

    /**
    Reloading a commented file
    */

    YamlReloader reloader = new YamlReloader(plugin, configFile, "config.yml");

    try {
        if (reloader.reloadAndCopy()) {
            cfg.loadFromString(reloader.getYamlString());
        }
    } catch (Throwable anyException) {
        System.out.println("Failed to reload configuration file");
    }
    In bungeecord, is a bit different
    Code (Java):
    /**
    Creating the commented file
    */

    FileCopy configuration = new FileCopy(plugin, "config.yml");
    //or
    FileCopy configuration = new FileCopy(MainClass.class, "config.yml");

    /* That config.yml file must be inside the jar file! */

    File configFile = new File(plugin.getDataFolder(), "config.yml");
    FileConfiguration cfg = YamlConfiguration.getProvider(YamlConfiguration.class).load(configFile);

    try {
        configuration.copy(configFile);
    } catch (Throwable anyException) {
        System.out.println("Couldn't create config.yml");
    }

    /**
    Reloading a commented file
    */

    YamlReloader reloader = new YamlReloader(plugin, configFile, "config.yml");

    try {
        if (reloader.reloadAndCopy()) {
            System.out.println("Reloaded config file");
        }
    } catch (Throwable anyException) {
        System.out.println("Failed to reload configuration file");
    }

    With the KarmaAPI you can send titles, actionbars and boss bars in a really easy way!

    Code (Java):
    /**
    Sendint a title
    */


    TitleMessage title = new TitleMessage(player, "&aThis is title", "&aThis is subtitle");
    title.send();
    //or
    title.send(int.class, int.class, int.class);

    /**
    Sending an actionbar
    */


    BarMessage bar = new BarMessage(player, "Message #1");

    bar.send(true);
    /* With bar.send(boolean.class) you can specify if the bar message is persistent or not, cancel the message with bar.stop() ( MUST BE THE SAME BarMessage INSTANCE ) */

    bar.send(5);
    /* Send the bar 5 times every 2'5 seconds, creating a "temporally persistent" bar */

    bar.stop()
    /* Stop the bar message if persistent */

    bar.setMessage("Message #2");
    /* Change the bar message */

    if (!bar.isSent()) {
        System.out.println("Bar is not sent!");
    }

    /**
    Sending a boss bar
    */

    int showTime = 10;
    /* In seconds */

    BossMessage boss = new BossMessage(plugin, "&cThis is the boss bar message", showTime).color(BossColor.PURPLE).style(BossType.SOLID);
    /* color and style are optional, and won't work on legacy minecraft */

    boss.scheduleBar(Bukkit.getOnlinePlayers());
    /* Can be used on a collection of players */
    boss.scheduleBar(player);
    /* Or on a single player */

    System.out.println("Bars amount: " + boss.getBarsAmount());
     

    Bungeecord has native support for titles, but to be honnest, is a bit lazy to setup a title using its API...

    Code (Java):
    TitleMessage title = new TitleMessage(proxiedPlayer, "&aThis is the title", "&aThis is the subtitle");

    title.send();
    // or
    title.send(int.class, int.class, int.class);

    Some developers don't know that some sounds ( specefically from 1.13 ) are not the same. KarmaAPI helps you to make compatible these sounds, in a easy way

    Code (Java):
    SoundPlayer sound = new SoundPlayer(plugin, ml.karmaconfigs.api.bukkit.soundutil.Sound.<SOUND>);

    /**
    For usage, read javadocs, as this class has a lot of methods, I can't explain all

    https://karmaconfigs.ml/javadocs/karmaapi/ml/karmaconfigs/api/bukkit/soundutil/SoundPlayer.html
    */

    We all know about bukkit schedule API, but KarmaAPI tries to improve this.

    Code (Java):
    SimpleTimer timer = new SourceSimpleTimer(plugin, 1 /* 1 second */, false /* restart timer when it ends */
    //or
    SourceSimpleTimer(timer.getId());

    /**
    A bad thing about SourceSimpleTimer is that requires a lot of resouces when you want to use it only as "per second timer". If you want a "per second timer" you should user SourceSecondsTimer
    */


    SimpleTimer timer = new SourceSecondsTimer(plugin, 1, false);

    /**
    As sound utilities, this class is a bit complex and big to explain in here, please take a look to java docs

    https://karmaconfigs.ml/javadocs/karmaapi/ml/karmaconfigs/api/bukkit/timer/AdvancedPluginTimer.html
    */

    KarmaAPI helps you to send messages to the console in a easy way, as all in this API.

    Code (Java):
    /**
    Console method is an interface, so it can't be initialized, but can be called as Console#method or implemented in the class
    */


    Console.setOkPrefix(plugin, "&aMyPlugin &7> &f");
    /* Set console message prefix when sending a message with OK level */

    Console.setInfoPrefix(plugin, "&7MyPlugin > &f");
    /* Set console message prefix when sending a message with INFO level */

    Console.setWarningPrefix(plugin, "&eMyPlugin > &f");
    /* Set console message prefix when sending a message with WARNING level */

    Console.setGravePrefix(plugin, "&cMyPlugin > &f");
    /* Set console message prefix when sending a message with GRAVE level */

    Console.send("&bThis is a message!");
    Console.send("&b{0} + {1} is {2}, operation by {3}", 2, 3, 5, "Math teacher");
    /*
    This method sends a message replacing the {<number>} with the replace object in the same order...

    {0} is being replaced with 2
    {1} is being replaced with 3
    {2} is being replaced with 5
    {3} is being replaced with "Math teacher"
    */


    Console.send(plugin, "This message is a level message", Level.OK);
    /* This sends a message to the console, with the message level, so will use level prefix */

    Console.send(plugin, "{0} + {1} is not {2}, student is: {3}". Level.GRAVE, 2, 3, 1, "KarmaDev");
    /*
    This is the most complex method of the Console utility

    This message has a level, GRAVE level, so it will use GRAVE prefix. It also contains replaces...

    {0} is being replaced with 2
    {1} is being replaced with 3
    {2} is being replaced with 1
    {3} is being replaced with "KarmaDev"

    */


    /**
    Other way to use this is...
    */


    public final class ExtendedConsole implements Console {
     
        public static void close() {
            plugin.onDisable();
        }
    }

    ExtendedConsole.setOkPrefix....

    ExtendedConsole.close();

     

    KarmaFile is the own API file format, it supports any value, and comments.

    Code (Java):
    KarmaFile kf = new KarmaFile(plugin, "myFile.file");
    /* File path: plugins/PluginName/myFile.file */

    KarmaFile kf = new KarmaFile(plugin, "myFile.file", "subFolderOne", "subFolderTwo");
    /* File path: plugins/PluginName/subFolderOne/subFolderTwo/myFile.file */

    File justANewFile = new File(FileUtilities.getServerFolder(), "test.test");
    KarmaFile kf = new KarmaFile(justANewFile);
    /* File path: <your server.jar folder location>/test.test */

    /**
    In the last method, I used a KarmaAPI-Common api method, to read more about KarmaAPI-Common, check the java docs ( https://karmaconfigs.ml/javadocs/karmaapi/ml/karmaconfigs/api/common/package-summary.html )

    If you want to know more about KarmaFile, take a look at
    ( Bukkit ) https://karmaconfigs.ml/javadocs/karmaapi/ml/karmaconfigs/api/bukkit/KarmaFile.html

    ( Bungee )
    https://karmaconfigs.ml/javadocs/karmaapi/ml/karmaconfigs/api/bungee/KarmaFile.html

    ( No platform )
    https://karmaconfigs.ml/javadocs/karmaapi/ml/karmaconfigs/api/common/GlobalKarmaFile.html
    */
    This is an example of KarmaFile format
    Code (Text):
    Something: "Hello"
    SomethingAgain: 32

    [LIST=JustAList]
    This is a list in a
    KarmaFile.

    It supports empty lines
    [/LIST=JustAList]

    /// And this, is a comment in a -->
    // KarmaFile -->

    KarmaFileSupportKeysWithNoValue

    Some plugins need to create logs with info on them, like if something went wrong or usage statistics, that can help in a bug report.

    Code (Java):
    Logger logger = new Logger(plugin);

    logger.scheduleLog(Level.<Level>, "This is a log message");

    try {
        // Try to do something dangerous
    } catch (Throwable anyException) {
        logger.scheduleLog(Level.GRAVE, anyException);
        logger.scheduleLog(Level.INFO, "Something went wrong");
    }
    If you need help go to our discord here or open an issue in github (We highly recommend to open a ticket in discord since we bring support faster)

    yml
    yml comment
    comment yml
    yml comments
    comments yml
    commented yml files
    yaml
    yaml comment
    comment yaml
    yaml comments
    comments yaml
    commented yaml files
    inventory to string
    item to string
    stack to string
    itemstack to string
    string from inventory
    string to inventory
    string to item
    string to stack
    string to itemstack
    get server version
    get bukkit server version
    get spigot server version
    get minecraft server version
    view server version
    view bukkit server version
    view spigot server version
    view minecraft server version
    retrieve server version
    retrieve bukkit server version
    retrieve spigot server version
    retrieve minecraft server version
    hologram bukkit
    holograms bukkit
    hologram spigot
    holograms spigot
    hologram api
    hologram api bukkit
    holograms api bukkit
    hologram api spigot
    holograms api spigot
    spigot reflection
    bukkit reflection
    send title
    send titles
    send subtitle
    send subtitles
    title bukkit
    titles bukkit
    title spigot
    titles spigot
    subtitle bukkit
    subtitles bukkit
    subtitle spigot
    subtitles spigot
    sound reflection
    sounds reflection
    sound reflection bukkit
    sounds reflection bukkit
    sound reflection spigot
    sounds reflection spigot
    timer bukkit
    timers bukkit
    timer spigot
    timers spigot
    message color bukkit
    message color spigot
    color message bukkit
    color message spigot
    colored message bukkit
    colored messages bukkit
    colored message spigot
    colored messages spigot
    custom file
    create custom file
    create custom file extension
    create file extension
    create extension
    edit custom file
    open custom file
    log exception
    log to file

    Images

    1. Captura de pantalla 2021-03-27 225037.png

Recent Updates

  1. Timer optimizations
  2. Timer fixes and improvements
  3. Fixes

Recent Reviews

  1. shmezi
    shmezi
    5/5,
    Version: 1.1.7
    Looks great, update your Discord link.

    Well I still need to fill a few chars to post this review.
    1. KarmaConfigs
      Author's Response