/DeveloperKit

A library to aid in creating Minecraft plugins

Primary LanguageJavaApache License 2.0Apache-2.0

DeveloperKit

The ultimate kit for making Minecraft plugins efficiently

This will explain everything you need to know for this kit.

Overview

The Developer Kit comes with multiple classes to aid in making the creation of Minecraft plugins easier, including:

  • KBase, which is a class that it meant to hold a bunch of util classes. Note: it is recommended that classes that aren't extending anything extend this
  • KListener, which is a class meant to be used instead of Listener. This extends KBase, so all KBase functions are present in KListener as well
  • KCommand, which is a class meant to be used instead of CommandExecutor. This extends KBase, so all KBase functions are present in KCommand as well
  • GUIClickableItem, which is a class meant for running an action in the run function upon clicking the item specified in the GUIClickableItem. This is meant to replace the need for making listeners for clicking items in a GUI.
  • KRunnable, which is a class meant to be used instead of BukkitRunnable. This functions as a normal BukkitRunnable, but includes the following new features
    • The ability to cancel it after a certain amount of time
    • The ability to run a function upon the runnable cancellation
    • Uses lambda functions, making it look a lot neater and easier to read
      • task -> {} instead of @Override public void run() {}
  • NBTItem, which is a version of tr7zw's NBTItem that adds get or default functions, and puts everything by default onto another compound (ExtraAttributes) to remove the excessive amount of nbt tags when looked at with advanced tooltips

Known Issues

  • Good for now!

Future Things

  • Auto register listeners (with toggle for it)
  • Auto register commands (with toggle for it)

Download

To add it to your plugin, use the maven import and add "KojiDevKit" to the dependencies part of your plugin.yml

Maven maven

<dependency>
  <groupId>io.github.kojiv</groupId>
  <artifactId>developerkit</artifactId>
  <version>version</version>
  <scope>provided</scope>
</dependency>

Gradle

repositories {
  mavenCentral()
}
dependencies {
  implementation("io.github.kojiv:developerkit:version") { isTransitive = false }
}

Examples

Example 1: KRunnable

In this example, the runnable will check if the entity is dead, and cancel the runnable if it is, but no matter what it will be canceled in 10 seconds.

final int[] i = {10};

World world = Bukkit.getWorlds().get(0);
Zombie zomb = world.spawn(world.getPlayers().get(0).getLocation(), Zombie.class);

new KRunnable(task -> {

  //If the zombie isn't dead
  if(!zomb.isDead()) {
  
    for(Player player : world.getPlayers()) {
      //Say to every player in the world that the zombie is still alive
      player.sendMessage(ChatColor.RED + "Zombie is still alive! You have " + i[0] + " seconds!");
    }
    
  } else {
    //Cancel it (this will cancel with the type of "Premature")
    task.cancel();
  }
  i[0]--;
}, 10 * 20L //If this time hits, then time ran out, canceling withe the type of "Time"

//Specify a task that runs on cancel
).cancelTask(task -> 
  
  world.getPlayers().forEach(p -> 
    p.sendMessage(ChatColor.GREEN + "Good job!")
  )
), KRunnable.CancellationActivationType.PREMATURE //The above function runs if the canceled type is "Premature"
  
//Specify a task that runs on cancel
).cancelTask(task -> 
  
  world.getPlayers().forEach(p ->
    p.sendMessage(ChatColor.RED + "Failed to kill the zombie!" )
  )
), KRunnable.CancellationActivationType.TIME //The above function runs if the canceled type is "Time"

//Specify a task that runs on cancel
).cancelTask(task -> 
  
  world.getPlayers().forEach(p ->
    p.sendMessage(ChatColor.GREEN + "Challenge Ended.")
  )
), KRunnable.CancellationActivationType.BOTH //The above function runs if it's canceled no matter what
  
//Actually schedule the thing
).runTaskTimer(KBase.getPlugin(), 0L, 20L); 

Credits

This dev kit includes libraries from other people, specifically:

  • NBT API by tr7zw on Github & Spigot
  • XSeries by CryptoMorin on Github & Spigot