Skip to content
Jaimss edited this page Jul 20, 2020 · 6 revisions

Package Breakdown

mcutils is broken down into 3 different packages: bukkit, bungee, and common.

The two packages you will use are bukkit and bungee. common is bundled into both bukkit and bungee so you don't need to add an extra dependency.

To include mcutils, please follow the guide in the readme.

Examples:

Here are a few usage examples of the different features of mcutils.

Bukkit Examples
    override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
        // send a colored message to someone
        sender.send("Sending a CommandSender a &3colored &fmessage.")
        val player = sender as Player
        // send a player a message and translate all placeholderapi placeholders
        player.send("&aHey %player_name%, your uuid is %player_uuid%!", player)

        // check if a player is in a certain radius of a location
        if (player.inRadiusOfLocation(Location(Bukkit.getWorld("name"), 1.0, 2.0, 3.0), 5)) {
            player.send("&bYou are within 5 blocks of the coordinates &3(1,2,3) &bin world &3\"name\"")
        }

        return true
    }
class MyPlugin : JavaPlugin() {

    override fun onEnable() {
        log("This is a message to console!")
        log("This is a warning in console", Severity.WARNING)
        log("This is an error in console", Severity.ERROR)
    }

}
        ItemBuilder(Material.DIAMOND_BLOCK)
                .setGlow()
                .setAmount(16)
                .setUnbreakable()
                .setName("&3&lEnchanted &bDiamond Block")
                .addLore(" &3- This is a nice diamond block!")
                .addLore(
                        listOf(
                                " &3 - Lore 2",
                                " &3 - Lore 3"
                        )
                ).get() // returns an itemstack with the above configuration
Bungee Examples

This is very similar to the bukkit features.

    override fun execute(sender: CommandSender, args: Array<out String>) {
        sender.send("&3This &ais &9a &5colored &6message!")
        val player = sender as ProxiedPlayer
        player.send("&3This &ais &9a &5colored &6message!")
    }
class MyBungeePlugin: Plugin() {

    override fun onEnable() {
        log("This is a message to console!")
        log("This is a warning in console", Severity.WARNING)
        log("This is an error in console", Severity.ERROR)
    }

}
Common Examples

These are available in both packages

println(10.toRomanNumeral()) // prints X
println(50.toRomanNumeral()) // prints L
println(60.toTimeFormatted()) // prints {years=0, months=0, weeks=0, days=0, hours=0, minutes=1, seconds=0}
println(1029323421.toTimeFormatted()) // prints {years=32, months=7, weeks=3, days=2, hours=11, minutes=10, seconds=21}
println(1029323421.toTimeFormatted()[Times.MINUTES]) // prints 10

For getting the Times, it is an enum to make it easy and eliminate potential bugs that could occur with strings for example. The enum can be found here.

This will let you turn seconds into a formatted time string really easily, or convert a number to a roman numeral for levels or something. Just a few things I have found useful over my time making plugins so I added them.

Clone this wiki locally