##Kosp
I am developing all of my plugins in Kotlin. It brings some nice features like cool constructors and extensions. In the end, I feel like I can work more efficient using Kotlin.
###Source
###Usage
Please read the README.md
####Name
Kotlin + Sponge = Kosp; maybe not that creative but I just needed a name
###Extensions
A good example of using an extension is formatting a Text
:
fun Text.aqua(): Text = toBuilder().color(TextColors.AQUA).build()
Generalizing this:
fun Text.format(format : TextFormat): Text = toBuilder().format(format).build()
fun Text.color(color : TextColor): Text = format(format.color(color))
fun Text.aqua(): Text = color(TextColors.AQUA)
Note that format.color
is format.getColor()
and this
is the receiver of the function, in this case Text
.
###Config
Features: automatic hyphen separated key names, simple Text
and TextTemplate
serializer.
Example config:
@ConfigSerializable
class Config(
@Setting val ticketCosts: Int = 100
)
Plugin main class
@Plugin(...)
class PluginMainClass @Inject constructor(
@DefaultConfig(sharedRoot = true) configLoader: ConfigurationLoader<CommentedConfigurationNode>
) {
val configManager = ConfigManager(
configLoader = configLoader,
clazz = Config::class)
}
And then simply: configManager.get()
to get the Config
object. .save()
to save a modified one(modifying is really easy in Kotlin with data classes)
The .conf would be:
ticket-costs = 100
###BStats
A client for BStats.
###Other extensions
For example:
- text concatenation:
"red text".red() + " green text".green()
or simply"text".toText() + "a string"
- text actions:
"click text".action(TextActions.runCommand("/time set day"))
- text template formatting:
"arg_name".toArg().green().bold()
- UUID to
Player
,User
,World
:uuid.toPlayer()
,uuid.toUser()
,uuid.toWorld()
####Explore it
I will integrate Kosp in my older plugins in th future, so there will be many examples of how to use this lib.
This lib was meant just for my own use but as always I do it opensource, so feel free to use it
Using it in Java is possible but not recommended, the extensions become static methods which are not so nice to use.
If you use it, please send me a message, I would like to see how you use it
RandomByte