🧫CompletionAsset

Generate content on demand

What is this?

The CompletionAssets allows you, to prived completion and execution content, which is able to adapt to the current situation, user, and input.

This allows you to generate organic content, adapt to changes inside the server, and give the player the possibility, to react to changing situations.

Immutability

CompletionAssets are deeply immutable, so you can't change the completion asset after the creation, but you can create modified copies of the assets, to 'modify' them.

Take a look!

The CompletionAssets do have multiple properties, which allows them to create their result, check the input and transform the input to its representing type.

A CompletionAsset always has a generic type T, which represents the object type, which will be represented by the CompletionAsset. For example, the onlinePlayer completion asset provides a list of online player names. The expected object, which should be returned, if the input is getting transformed, is a Player. So the T of the onlinePlayers CompletionAsset is Player

supportedInputType currently may not really affect the computational processing

To set these different properties, you can just pass them through the constructor, or you can choose to create a modified copy with these post-edit functions:

If you look at an example, you can really quickly learn, how you can use the CompletionAssets, to provide your own content:

The CompletionAsset, which is used inside the InterchangeStructure and StructuredInterchange, both supports the decision, if the input is case-sensitive or not. If you do not have to limit this due to a particiular reason, you should accept this and use the provided ignoreCase boolean, to allow this behavior, to match it at your Asset too.

@JvmStatic
val WORLD_NAME = CompletionAsset<World>(system, "WORLD_NAME", true) {
   worlds.withMap { name }
}.doCheck {
   worlds.any { it.name.equals(input, ignoreCase) }
}.transformer {
   Bukkit.getWorld(input)
}

Provided CompletionAssets

Sparkle itself provides some really helpful completion assets, which you can use in your own projects. These are all contained inside the companion object of the CompletionAsset class.

The example, used above, is also located inside this object, you can just use it, with the following example code:

addContent(CompletionAsset.WORLD_NAME)

Last updated