KarmaAPI 2.2 - SNAPSHOT

An API (doesn't need to be loaded by Bukkit/Bungee) that will help you in a lot of things

  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://www.patreon.com/posts/my-patreon-page-34215088
    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!

    Code (Text):

    <repository>
        <id>Repos-KarmaAPI</id>
        <url>https://github.com/KarmaConfigs/Repos/raw/KarmaAPI/</url>
     </repository>

    <dependency>
        <groupId>ml.karmaconfigs</groupId>
        <artifactId>KarmaAPI</artifactId>
        <version>2.2-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>
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <archive>
              <manifest>
                <mainClass>com.myclass.myplugin.Main</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
        </plugin>
      </plugins>
    </build>
     

    KarmaYAML is a module from KarmaAPI (included) designed to the developers who just want to copy the internal <file>.yml file to his plugins folder and checking for the same file to refill the not-found sets, checking for correct sets and yes, it supports comments

    (Example)

    Code (Java):
    FileCopy copy = new FileCopy(plugin, "internal_file.yml");

    File dest = new File(plugin.getDataFolder(), "messages.yml");
    YamlConfiguration msg = YamlConfiguration.loadConfiguration(dest);

    if (copy.copy(dest)) {
        // YOUR CODE HERE
    }

    YamlReloader reloader = new YamlReloader(plugin, dest, "internal_file.yml");

    if (reloader.reloadAndCopy()) {
      msg.loadFromString(reloader.getYamlString()); // BungeeCord skips this step
    }
    Code (Text):
    [Internal config.yml]
    #Welcome to my
    #config file

    #Please, don't touch this
    Ver: 1.0

    #This manages something
    Hello: "World!"

    #And this is just a boolean
    NotABoolean: false

    [User's config.yml]
    Ver: 34
    Hello: false

    //
    My API will re-set the values to the default ones for the paths that have an incorrect value object, and yes, it would regenerate comments and "NotABoolean"
     

    KarmaFile allows you to create any kind of file, like a .player file with player information, and easily readable by anyone

    Example:
    Code (Java):

    String uuid = player.getUniqueId().toString();

    KarmaFile playerFile = new KarmaFile(plugin, uuid + ".player",
    /*Sub-directories (starting from "plugin.getDataFolder()"*/ "players", "data");
    //This will create the file <uuid>.player at plugins/<plugin>/players/data

    playerFile.set("Health", player.getHealthScale());
    List<String> playerDesc = new ArrayList<>();
    playerDesc.add("This is a");
    playerDesc.add("simple description");

    playerFile.set("Desc", playerDesc);

    System.out.printIn("Description of " + player.getName() + playerFile.getStringList("Desc"));
    System.out.printIn("Saved health" + playerFile.getDouble("Health"));

     

    My API also helps you when sending messages to the console, by using

    ml.karmaconfigs.api.spigot//bungee.Console.send(); method, it has 4 methods, 2 for normal messages, 2 for alert messages

    (Example)
    Code (Java):
    ml.karmaconfigs.spigot.api.Console.send("Hello world!");

    ml.karmaconfigs.spigot.api.Console.send("{0} {1}", "Hello!", 1);

    ml.karmaconfigs.spigot.api.Console.send(plugin, "OH NO!", Level.INFO-Level.WARNING-Level.GRAVE);

    ml.karmaconfigs.spigot.api.Console.send(plugin, "OH NO! {0} is not a player", Level.INFO-Level.WARNING-Level.GRAVE, player.getName());
    Why does the alert message method requires a plugin (Main) instance?

    It's due the alert message prefixes

    (Example)
    Code (Java):
    Console.setInfoPrefix(plugin, "&b[INFO] &7");

    Console.send(plugin, "I'm an info message", Level.INFO);

    Output:
    //Previsualize the color codes :)
    "&b[INFO] &7I'm an info message"
    And the same for Console.setWarningPrefix and Console.setGravePrefix

    This API will also help you when creating logs, so your users can save errors and they can keep them safe when asking for help. the logs are saved Async so it won't fload server memory since they use some "while ()"

    Code (Java):
    Logger logger = new Logger(plugin);
    logger.scheduleLog(Level.INFO | Level.WARNING | Level.GRAVE, "This will be a string message");

    try {
      //Your code here
    } catch (IOException e) {
      logger.scheduleLog(Level.INFO | Level.WARNING | Level.GRAVE, e);
      Console.send(plugin, "Something went wrong", Level.GRAVE);
    }

    This API includes StringUtils which will allow you to use color codes without that long method ChatColor.translateAlternatoColorCodes();

    Code (Java):
    String colored = StringUtils.toColor("&aHello");
    String noColor = StringUtils.stripColor(colored);
    It also includes TitleAPI, ActionBar and ServerVersion
    Code (Java):
    //Title example
    TitleMessage title_example = new TitleMessage(player, "Title", "Subtitle"); // You don't have to specify a Subtitle

    title_example.send();
    //Will send a title with
    /*
    FadeIn: 2
    Display: 5
    FadeOut: 2
    */


    title_example.send(2, 5, 4);
    /*
    2 - FadeIn time
    5 - Display time
    4 - FadeOut time
    */


    //ActionBar example
    BarMessage bar_example = new BarMessage(player, "Message");
    bar_example.send();
     
    ServerVersion will allow you to get server full version (Example: 1.16.3), server short version (1.16) version build type (SNAPSHOT), build number (R0.1), update identifier (3), and a Version instance (v1_16_3)

    Code (Java):
    ServerVersion version = new ServerVersion(plugin.getServer());
     
            System.out.println("Full: " + version.getFullVersion());
            System.out.println("Real: " + version.getRealVersion());
            System.out.println("Version (float): " + version.getVersion());
            System.out.println("Update number: " + version.getVersionUpdate());
            System.out.println("Package: " + version.getPackageType());
            System.out.println("Build: " + version.getPackageBuild());
            System.out.println("Version: " + version.getV());

    //Will return:
    Full: 1.16.3
    Real: 1.16.3-R0.1-SNAPSHOT
    Version (float): 1.16
    Update number: 3
    Package: SNAPSHOT
    Build: R0.1
    Version: v1_16_3

    But ServerVersion also lets you to find a NMS or OBC class just by using

    version.getNMSClass("AnyMinecraftClass");
    version.getObcClass("AnyCraftBukkitClass");
    //DON'T FORGET TO CHECK IF IT'S NULL
     

    KarmaAPI version checker recommends the usage of github pages for an easy work

    Step 1:
    Settup @KarmaPlugin annotation in your Main class
    Code (Java):

    @KarmaPlugin{plugin_name = "Hi", plugin_version = "1.0", plugin_update_url = "https://myhost.com/latest.txt"
    public final class Main extends JavaPlugin {

       @Override
       //I THINK THE REST OBVIOUS
     
       // TO GET AN ANNOTATION VALUE JUST USE
       KarmaPlugin.getters.getName(Main.class);
    }
     
    Step 2:
    Creating the latest.txt
    It needs to be that format (either the plugin could return a null exception)
    Code (Text):
    1.0.0 // Latest version (It supports strings like "Beta 1.0"
    https://spigotmc.org/resources/... // This is the url where the user should go to download the plugin, read below to see how to get that URL in-code
    - ChangeLog line
      1
    - ChangeLog line
      2
    - I'm just adding a
      lot of changelog
      lines
     
    Step 3:
    Upload the latest.txt file to your
    https://yourhost.com/latest.txt
    ( In case you have github and you
    uploaded to your master branch, you should
    be able to locate the file in
    https://yourprofile.github.io/YourRepo/latest.txt
    or if you have in a sub-folder
    https://yourprofile.github.io/YourRepo/subRepoFolder/latest.txt )
    Don't forget to wait a bit before trying to request that URL, sometimes it can take a way long

    Setp 4:
    Making everything to work
    Code (Java):
    VersionChecker checker = new VersionChecker(plugin);

    if (cheker.isUpdated()) {
        Console.send(plugin, "Plugin is up-to-date ({0} - {1})", Level.INFO, checker.getLatest(), checker.getCurrent());
    } else {
        Console.send(plugin, "Plugin is ready to update, update from {0}", Level.WARNING, checker.getUpdateURL());

        //Way one to get changelog (recommended)
        Console.send(checker.toString());

       //Second way to it
       List<String> changelog = checker.getChangelog();
       for (String str : changelog) {
           Console.send(str);
       }
    }
     

    This API will allow you to inject a .jar into your plugin, this will allow your plugin to be a really lightweight plugin that downloads their dependencies separately and loads them at runtime ( DO NOT INJECT OTHER PLUGIN .JAR )

    Code (Java):
    File dependency = new File(plugin.getDataFolder() + "/libs", "Dependency.jar");

    JarInjector injector = new JarInjector(dependency);

    // THIS WILL CHECK IF THE DEPENDENCY FILE EXISTS
    // OR IS IN A DOWNLOADED LIST
    if (!injector.isDownloaded()) {
        injector.download("https://someurl.com/files/dependency.jar");
    }

    if (injector.inject(plugin)) {
        // YOUR CODE HERE...
    } else {
        plugin.getServer().getPluginManager().disablePlugin(plugin);
    }

    Since version 1.4 you can serialize player inventories and deserialize them in a easy way, you can also play a sound to a player ignoring version sound restrictions

    Example (Inventory serialization):
    Code (Java):
    InventorySerializer serializer = new InventorySerializer(player.getInventory());

    try {
        serializer.save(plugin, player.getUniqueId());
        /*
            Will be saved in cache server folder
        */

    } catch (Throwable e) {
        e.printStackTrace();
    }

    InventoryDeserializer deserializer = new InventoryDeserializer(player.getUniqueId());

    Inventory inv = deserializer.getInventory(plugin);

    if (inv != null) {
        // DO WHATEVER YOU WANT
    }
    Example (sound):
    Code (Java):
    /*
    SoundPlayer has a lot of methods, I'll show only the basic ones
    */


    SoundPlayer s_player = new SoundPlayer(plugin, ml.karmaconfigs.api.spigot.soundutil.Sound.<AnySound>);

    s_player.playTo(player...);
    s_player.playTo(Bukkit.getOnlinePlayers()...);
    s_player.playProgressivelyNote(player...);
    s_player.playProgressivelyNote(Bukkit.getOnlinePlayers()...);
    s_player.playProgressivelyVolume(player...);
    s_player.playProgressivelyVolume(Bukkit.getOnlinePlayers()...);

    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)

Recent Updates

  1. Fixed configuration sections
  2. File system improvements
  3. Fixed