Repository navigation
KotlinPlugin
Wittawat Manha edited this page Sep 8, 2020
·
2 revisions
public abstract class KotlinPlugin extends JavaPluginthis plugin is based on kotlin so tutorial will be kotlin
-
Logging without getting
Logger- you can use
KotlinPlugin.<log-level>(message)
- you can use
-
Commands registered by
KotlinPlugincan-
disableandenableat runtime - register at runtime (can register when not provide in plugin.yml)
-
-
get file inside config folder
-
KotlinPlugin.getFile(path)getFile("test.txt") == new File("<ServerFolder>/plugins/<PluginName>/test.txt")
-
-
can call
BukkitRunnabledirectly- run task later is easy as
KotlinPlugin.runTask(delay, Runnable)
- run task later is easy as
// kotlin
// old
class PluginName : JavaPlugin(){}
// new
class PluginName : com.wireless4024.mc.bukcore.api.KotlinPlugin(){}// old
val plugin:JavaPlugin = ... // or somehow
plugin.logger.fine(String.valueOf(plugin))
plugin.logger.info(String.valueOf(1234))
plugin.logger.warning(String.valueOf(5678))
plugin.logger.warning(arrayOf(1,2,3,4).joinToString()) // yea need to join into a string
// new
val plugin:KotlinPlugin = ... // or somehow
plugin.log(plugin)
plugin.info(1234)
plugin.warning(5678)
plugin.warning(arrayOf(1,2,3,4)) // it's will print [1, 2, 3, 4]if you didn't use CommandBase you will need to register command to KotlinPlugin
plugin:KotlinPlugin = ...
plugin.registerCommand("command-name", plugin.getCommand("command-name"))via CommandBase is easy as
CommandName(plugin).register()
// just single line 👍 if command is registered into kotlin plugin here are what you can do
plugin:KotlinPlugin = ...
// plugin.enableCommand(name:String)
// plugin.disableCommand(name:String)
// plugin.registerCommand(name:String, command:Command)
// plugin.unregisterCommand(name:String, purge:Boolean)
plugin.disableCommand("command-name")
// if you use /command-name in game it's will unknown command
plugin.enableCommand("command-name")
// if you use /command-name in game it's will be back 💯
plugin.unregisterCommand("command-name")
// if you use /command-name in game it's will unknown command
plugin.enableCommand("command-name")
// if you use /command-name in game it's will be back lol?
plugin.enableAllCommand()
// to enable all disabled command// old
File("plugin/${plugin.name}/file-name.whatever")
// new
plugin:KotlinPlugin = ...
plugin.getFile("file-name.whatever")arguments are moved to front of a task because you'll able to use closure with it
val plugin:KotlinPlugin = ...
val runnable = object :BukkitRunnable(){ // you can't use closure with abstract class
override fun run() {
// do whatever
}
}
val closure = {
// do whatever
}
/* to run a task as soon as possible */
// old
runnable.runTask(plugin)
// new
plugin.runTask(closure)
// or
plugin.runTask { /* do whatever */ }
// or
plugin { /* do whatever */ }
/* --------------------------------- */
/* to run a task as soon as possible asynchronously */
// old
runnable.runTaskAsynchronously(plugin)
// new
plugin.runAsync(closure)
// or
plugin.runAsync { /* do whatever */ }
/* ------------------------------------------------ */
/* to run a task later */
val delay = 10 // tick
// old
runnable.runTaskLater(plugin, delay)
// new
plugin.runTask(delay, closure)
// or
plugin.runTask(delay){ /* do whatever */ }
// or
plugin(delay) { /* do whatever */ }
/* ------------------- */
/* to run a task later asynchronously */
// old
runnable.runTaskLaterAsynchronously(plugin, delay)
// new
plugin.runAsync(delay, closure)
// or
plugin.runAsync(delay){ /* do whatever */ }
/* ---------------------------------- */
/* to run a task timer */
val period = 10 // 10 tick
// old
runnable.runTaskTimer(plugin, delay, period)
// new
plugin.runTimer(delay, period, closure)
// or
plugin.runTimer(delay, period){ /* do whatever */ }
/* ------------------- */
/* to run a task timer asynchronously */
runnable.runTaskTimerAsynchronously(plugin, delay, period) // very long
// new
plugin.runTimerAsync(delay, period, closure)
// or
plugin.runTimerAsync(delay, period){ /* do whatever */ }
/* ---------------------------------- */
// only with kotlin plugin
// if this is running in async thread
val location:Location = ...
val higestBlock:Block = plugin.call {
// a task that needed to call in main thread
// eg get block
location.world.getHighestBlockAt(location)
}