-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mattmx.ktgui.papi | ||
|
||
import com.mattmx.ktgui.commands.declarative.ChainCommandBuilder | ||
|
||
class Placeholder( | ||
val match: ChainCommandBuilder, | ||
val supplier: (PlaceholderParseContext) -> Any? | ||
) { | ||
var priority = 0 | ||
|
||
fun parse(context: PlaceholderParseContext) = supplier.invoke(context) | ||
} |
54 changes: 54 additions & 0 deletions
54
api/src/main/kotlin/com/mattmx/ktgui/papi/PlaceholderExpansionWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.mattmx.ktgui.papi | ||
|
||
import me.clip.placeholderapi.expansion.PlaceholderExpansion | ||
import org.bukkit.entity.Player | ||
import org.bukkit.plugin.java.JavaPlugin | ||
|
||
class PlaceholderExpansionWrapper( | ||
private val owner: JavaPlugin | ||
) : PlaceholderExpansion() { | ||
private val placeholders = arrayListOf<Placeholder>() | ||
var id = owner.name | ||
private set | ||
var author = owner.pluginMeta.authors.joinToString(", ") | ||
private set | ||
var version = owner.pluginMeta.version | ||
private set | ||
var splitArgs = { params: String -> params.split("_") } | ||
private set | ||
|
||
override fun getIdentifier() = id | ||
override fun getAuthor() = author | ||
override fun getVersion() = version | ||
override fun getPlaceholders() = placeholders.map { it.toString() }.toMutableList() | ||
|
||
infix fun id(id: String) = apply { | ||
this.id = id | ||
} | ||
|
||
infix fun author(author: String) = apply { | ||
this.author = author | ||
} | ||
|
||
infix fun version(version: String) = apply { | ||
this.version = version | ||
} | ||
|
||
infix fun splitArgs(splitArgs: (String) -> List<String>) = apply { | ||
this.splitArgs = splitArgs | ||
} | ||
|
||
infix fun registerPlaceholder(placeholder: Placeholder) = placeholders.add(placeholder) | ||
|
||
override fun onPlaceholderRequest(player: Player?, params: String): String? { | ||
val context = PlaceholderParseContext(player, splitArgs(params)) | ||
for (placeholder in placeholders.sortedByDescending { it.priority }) { | ||
val content = placeholder.parse(context) | ||
|
||
if (content != null) { | ||
return content.toString() | ||
} | ||
} | ||
return null | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/kotlin/com/mattmx/ktgui/papi/PlaceholderParseContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mattmx.ktgui.papi | ||
|
||
import com.mattmx.ktgui.commands.declarative.arg.Argument | ||
import org.bukkit.entity.Player | ||
|
||
class PlaceholderParseContext( | ||
val requestedBy: Player?, | ||
val params: List<String> | ||
) { | ||
|
||
operator fun <T : Any> Argument<T>.invoke(): T = TODO() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mattmx.ktgui.papi | ||
|
||
import com.mattmx.ktgui.commands.declarative.ChainCommandBuilder | ||
import org.bukkit.plugin.java.JavaPlugin | ||
|
||
inline fun JavaPlugin.placeholderExpansion(builder: PlaceholderExpansionWrapper.() -> Unit) = | ||
PlaceholderExpansionWrapper(this).apply(builder).apply { register() } | ||
|
||
fun placeholder(string: String, supplier: PlaceholderParseContext.() -> Any?) = | ||
Placeholder(ChainCommandBuilder(string), supplier) | ||
|
||
fun placeholder(chain: ChainCommandBuilder, supplier: PlaceholderParseContext.() -> Any?) = | ||
Placeholder(chain, supplier) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters