-
-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
Jaimss edited this page Jul 23, 2020
·
3 revisions
Here are a few usage examples of the different features of mcutils.
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.")
sender.send(listOf("a", "b")) // send a list to a player
// like bungeecord can be mixed with list of players, list of messages, adding a player parameter for placeholderapi, etc.
// like bungeecord read the docs :)
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
This is very similar to the bukkit features.
override fun execute(sender: CommandSender, args: Array<out String>) {
sender.send("&3This &ais &9a &5colored &6message!")
sender.send(listOf("a", "b")) // send a list of messages
// you can also mix things like send a list of proxiedplayers a list of messages, etc etc.
// see the docs for more info
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)
register(ListenerClass()) // easily register a listener
register(CommandClass()) // easily register a command
}
}
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
"someUserInputString".getInputType() // returns whether it is a UUID, SHORTUUID, or NAME so you can easily check against a databse or something
Date().getSecondsDifference(oldCachedDate) // will return the seconds it has been since the old date
UUID.fromString("40468bbd-8afd-4e5f-b777-becde0554094").getName() // returns a players username
"username".getUUID() // returns a players uuid
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.
Come chat with us at discord.jaims.dev! You can receive support in my discord above or in the issues tab!