Added 1.21 item arg parsers
This commit is contained in:
@@ -6,10 +6,22 @@ dependencies {
|
||||
implementation("org.reflections:reflections:0.9.12")
|
||||
implementation("org.objenesis:objenesis:3.2")
|
||||
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT")
|
||||
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
|
||||
compileOnly("me.clip:placeholderapi:2.11.4")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.10.0")
|
||||
compileOnly("net.kyori:adventure-platform-bukkit:4.1.0")
|
||||
compileOnly("org.yaml:snakeyaml:1.33")
|
||||
compileOnly("com.moandjiezana.toml:toml4j:0.7.2")
|
||||
}
|
||||
|
||||
tasks {
|
||||
compileJava {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "21"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ object EntityArgParserJumpStrength : EntityArgParser {
|
||||
return@EntityArgParseResult false
|
||||
}
|
||||
|
||||
val inst = it.getAttribute(Attribute.HORSE_JUMP_STRENGTH) ?: return@EntityArgParseResult false
|
||||
val inst = it.getAttribute(Attribute.GENERIC_JUMP_STRENGTH) ?: return@EntityArgParseResult false
|
||||
inst.value >= attributeValue
|
||||
},
|
||||
{
|
||||
@@ -36,7 +36,7 @@ object EntityArgParserJumpStrength : EntityArgParser {
|
||||
return@EntityArgParseResult
|
||||
}
|
||||
|
||||
it.getAttribute(Attribute.HORSE_JUMP_STRENGTH)?.baseValue = attributeValue
|
||||
it.getAttribute(Attribute.GENERIC_JUMP_STRENGTH)?.baseValue = attributeValue
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ object ArgParserEnchantment : LookupArgParser {
|
||||
continue
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
val enchant = Enchantment.getByKey(NamespacedKeyUtils.create("minecraft", argSplit[0]))
|
||||
val level = argSplit[1].toIntOrNull()
|
||||
|
||||
|
||||
@@ -1,44 +1,30 @@
|
||||
package com.willfp.eco.internal.items
|
||||
|
||||
import com.willfp.eco.core.items.args.LookupArgParser
|
||||
import com.willfp.eco.internal.items.templates.ValueArgParser
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import java.util.function.Predicate
|
||||
|
||||
object ArgParserName : LookupArgParser {
|
||||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? {
|
||||
var name: String? = null
|
||||
object ArgParserName : ValueArgParser<String>("name") {
|
||||
override fun parse(arg: String): String {
|
||||
return arg
|
||||
}
|
||||
|
||||
for (arg in args) {
|
||||
if (!arg.lowercase().startsWith("name:")) {
|
||||
continue
|
||||
}
|
||||
name = arg.substring(5, arg.length)
|
||||
}
|
||||
|
||||
name ?: return null
|
||||
|
||||
val formatted = StringUtils.format(name)
|
||||
override fun apply(meta: ItemMeta, value: String) {
|
||||
val formatted = StringUtils.format(value)
|
||||
|
||||
// I don't know why it says it's redundant, the compiler yells at me
|
||||
@Suppress("UsePropertyAccessSyntax", "RedundantSuppression", "DEPRECATION")
|
||||
meta.setDisplayName(formatted)
|
||||
|
||||
return Predicate {
|
||||
val testMeta = it.itemMeta ?: return@Predicate false
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
testMeta.displayName == formatted
|
||||
}
|
||||
}
|
||||
|
||||
override fun serializeBack(meta: ItemMeta): String? {
|
||||
override fun test(meta: ItemMeta): String? {
|
||||
if (!meta.hasDisplayName()) {
|
||||
return null
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
return "name:\"${meta.displayName}\""
|
||||
return meta.displayName
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,14 @@
|
||||
package com.willfp.eco.internal.items
|
||||
|
||||
import com.willfp.eco.core.items.args.LookupArgParser
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import com.willfp.eco.internal.items.templates.FlagArgParser
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import java.util.function.Predicate
|
||||
|
||||
object ArgParserUnbreakable : LookupArgParser {
|
||||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? {
|
||||
var unbreakable = false
|
||||
|
||||
for (arg in args) {
|
||||
if (arg.equals("unbreakable", true)) {
|
||||
unbreakable = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!unbreakable) {
|
||||
return null
|
||||
}
|
||||
|
||||
object ArgParserUnbreakable : FlagArgParser("unbreakable") {
|
||||
override fun apply(meta: ItemMeta) {
|
||||
meta.isUnbreakable = true
|
||||
|
||||
return Predicate {
|
||||
val testMeta = it.itemMeta ?: return@Predicate false
|
||||
|
||||
testMeta.isUnbreakable
|
||||
}
|
||||
}
|
||||
|
||||
override fun serializeBack(meta: ItemMeta): String? {
|
||||
if (!meta.isUnbreakable) {
|
||||
return null
|
||||
}
|
||||
|
||||
return "unbreakable"
|
||||
override fun test(meta: ItemMeta): Boolean {
|
||||
return meta.isUnbreakable
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.willfp.eco.internal.items.modern
|
||||
|
||||
import com.willfp.eco.internal.items.templates.FlagArgParser
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
|
||||
object ArgParserFireResistant : FlagArgParser("fire_resistant") {
|
||||
override fun apply(meta: ItemMeta) {
|
||||
meta.isFireResistant = true
|
||||
}
|
||||
|
||||
override fun test(meta: ItemMeta): Boolean {
|
||||
return meta.isFireResistant
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.willfp.eco.internal.items.modern
|
||||
|
||||
import com.willfp.eco.internal.items.templates.FlagArgParser
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
|
||||
object ArgParserGlint : FlagArgParser("glint") {
|
||||
override fun apply(meta: ItemMeta) {
|
||||
meta.setEnchantmentGlintOverride(true)
|
||||
}
|
||||
|
||||
override fun test(meta: ItemMeta): Boolean {
|
||||
return meta.hasEnchantmentGlintOverride()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.willfp.eco.internal.items.modern
|
||||
|
||||
import com.willfp.eco.internal.items.templates.ValueArgParser
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
|
||||
object ArgParserItemName : ValueArgParser<Component>("item_name") {
|
||||
override fun parse(arg: String): Component {
|
||||
return StringUtils.formatToComponent(arg)
|
||||
}
|
||||
|
||||
override fun apply(meta: ItemMeta, value: Component) {
|
||||
meta.itemName(value)
|
||||
}
|
||||
|
||||
override fun test(meta: ItemMeta): String? {
|
||||
if (!meta.hasItemName()) {
|
||||
return null
|
||||
}
|
||||
|
||||
val name = MiniMessage.miniMessage().serialize(meta.itemName())
|
||||
|
||||
return name
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.willfp.eco.internal.items.modern
|
||||
|
||||
import com.willfp.eco.internal.items.templates.ValueArgParser
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
||||
import org.bukkit.inventory.meta.Damageable
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import org.checkerframework.checker.units.qual.m
|
||||
|
||||
object ArgParserMaxDamage : ValueArgParser<Int>("max_damage") {
|
||||
override fun parse(arg: String): Int? {
|
||||
return arg.toIntOrNull()
|
||||
}
|
||||
|
||||
override fun apply(meta: ItemMeta, value: Int) {
|
||||
if (meta !is Damageable) {
|
||||
return
|
||||
}
|
||||
|
||||
meta.setMaxDamage(value)
|
||||
}
|
||||
|
||||
override fun test(meta: ItemMeta): String? {
|
||||
if (meta !is Damageable) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (!meta.hasMaxDamage()) {
|
||||
return null
|
||||
}
|
||||
|
||||
return meta.maxDamage.toString()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.willfp.eco.internal.items.modern
|
||||
|
||||
import com.willfp.eco.internal.items.templates.ValueArgParser
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
||||
import org.bukkit.inventory.meta.Damageable
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import org.checkerframework.checker.units.qual.m
|
||||
|
||||
object ArgParserMaxStackSize : ValueArgParser<Int>("max_stack_size") {
|
||||
override fun parse(arg: String): Int? {
|
||||
return arg.toIntOrNull()
|
||||
}
|
||||
|
||||
override fun apply(meta: ItemMeta, value: Int) {
|
||||
meta.setMaxStackSize(value)
|
||||
}
|
||||
|
||||
override fun test(meta: ItemMeta): String? {
|
||||
if (!meta.hasMaxStackSize()) {
|
||||
return null
|
||||
}
|
||||
|
||||
return meta.maxStackSize.toString()
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.internal.items
|
||||
package com.willfp.eco.internal.items.modern
|
||||
|
||||
import com.willfp.eco.core.items.args.LookupArgParser
|
||||
import org.bukkit.NamespacedKey
|
||||
@@ -23,7 +23,11 @@ object ArgParserTrim : LookupArgParser {
|
||||
if (!argSplit[0].equals("trim", ignoreCase = true)) {
|
||||
continue
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
material = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft(argSplit.getOrElse(1) {""}))
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
pattern = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft(argSplit.getOrElse(2) {""}))
|
||||
}
|
||||
|
||||
@@ -43,6 +47,11 @@ object ArgParserTrim : LookupArgParser {
|
||||
override fun serializeBack(meta: ItemMeta): String? {
|
||||
val trim = (meta as? ArmorMeta)?.trim ?: return null
|
||||
|
||||
return "trim:${trim.material.key.key.lowercase()}:${trim.pattern.key.key.lowercase()}"
|
||||
@Suppress("DEPRECATION")
|
||||
val materialKey = Registry.TRIM_MATERIAL.getKey(trim.material) ?: return null
|
||||
@Suppress("DEPRECATION")
|
||||
val patternKey = Registry.TRIM_PATTERN.getKey(trim.pattern) ?: return null
|
||||
|
||||
return "trim:${materialKey.key.lowercase()}:${patternKey.key.lowercase()}"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.willfp.eco.internal.items.templates
|
||||
|
||||
import com.willfp.eco.core.items.args.LookupArgParser
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import java.util.function.Predicate
|
||||
|
||||
abstract class FlagArgParser(
|
||||
protected val flag: String
|
||||
) : LookupArgParser {
|
||||
abstract fun apply(meta: ItemMeta)
|
||||
|
||||
abstract fun test(meta: ItemMeta): Boolean
|
||||
|
||||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? {
|
||||
var has = false
|
||||
|
||||
for (arg in args) {
|
||||
if (arg.equals(flag, true)) {
|
||||
has = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!has) {
|
||||
return null
|
||||
}
|
||||
|
||||
apply(meta)
|
||||
|
||||
return Predicate {
|
||||
val testMeta = it.itemMeta ?: return@Predicate false
|
||||
|
||||
test(testMeta)
|
||||
}
|
||||
}
|
||||
|
||||
override fun serializeBack(meta: ItemMeta): String? {
|
||||
if (!test(meta)) {
|
||||
return null
|
||||
}
|
||||
|
||||
return flag
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.willfp.eco.internal.items.templates
|
||||
|
||||
import com.willfp.eco.core.items.args.LookupArgParser
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import java.util.function.Predicate
|
||||
|
||||
abstract class ValueArgParser<T: Any>(
|
||||
protected val flag: String
|
||||
) : LookupArgParser {
|
||||
abstract fun parse(arg: String): T?
|
||||
|
||||
abstract fun apply(meta: ItemMeta, value: T)
|
||||
|
||||
abstract fun test(meta: ItemMeta): String?
|
||||
|
||||
override fun parseArguments(args: Array<out String>, meta: ItemMeta): Predicate<ItemStack>? {
|
||||
var argument: String? = null
|
||||
|
||||
for (arg in args) {
|
||||
if (!arg.lowercase().startsWith("${flag}:")) {
|
||||
continue
|
||||
}
|
||||
argument = arg.substring(flag.length + 1, arg.length)
|
||||
}
|
||||
|
||||
argument ?: return null
|
||||
|
||||
val parsed = parse(argument) ?: return null
|
||||
|
||||
apply(meta, parsed)
|
||||
|
||||
return Predicate {
|
||||
val testMeta = it.itemMeta ?: return@Predicate false
|
||||
|
||||
test(testMeta) == parsed
|
||||
}
|
||||
}
|
||||
|
||||
override fun serializeBack(meta: ItemMeta): String? {
|
||||
val test = test(meta)
|
||||
|
||||
if (test.isNullOrBlank()) {
|
||||
return null
|
||||
}
|
||||
|
||||
return "${flag}:\"$test\""
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.internal.particle
|
||||
|
||||
import com.willfp.eco.core.Prerequisite
|
||||
import com.willfp.eco.core.particle.ParticleFactory
|
||||
import com.willfp.eco.core.particle.SpawnableParticle
|
||||
import org.bukkit.Color
|
||||
@@ -7,6 +8,14 @@ import org.bukkit.Location
|
||||
import org.bukkit.Particle
|
||||
|
||||
object ParticleFactoryRGB : ParticleFactory {
|
||||
private val dustParticle = runCatching {
|
||||
if (Prerequisite.HAS_1_20_5.isMet) {
|
||||
Particle.valueOf("DUST")
|
||||
} else {
|
||||
Particle.valueOf("REDSTONE_DUST")
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
override fun getNames() = listOf(
|
||||
"color",
|
||||
"rgb",
|
||||
@@ -30,7 +39,9 @@ object ParticleFactoryRGB : ParticleFactory {
|
||||
override fun spawn(location: Location, amount: Int) {
|
||||
val world = location.world ?: return
|
||||
|
||||
world.spawnParticle(Particle.REDSTONE, location, amount, 0.0, 0.0, 0.0, 0.0, options)
|
||||
val particle = dustParticle ?: return
|
||||
|
||||
world.spawnParticle(particle, location, amount, 0.0, 0.0, 0.0, 0.0, options)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,12 @@ import com.willfp.eco.internal.data.MavenVersionToStringAdapter
|
||||
import com.willfp.eco.internal.data.VersionToStringAdapter
|
||||
import com.willfp.eco.internal.entities.*
|
||||
import com.willfp.eco.internal.items.*
|
||||
import com.willfp.eco.internal.items.modern.ArgParserFireResistant
|
||||
import com.willfp.eco.internal.items.modern.ArgParserGlint
|
||||
import com.willfp.eco.internal.items.modern.ArgParserItemName
|
||||
import com.willfp.eco.internal.items.modern.ArgParserMaxDamage
|
||||
import com.willfp.eco.internal.items.modern.ArgParserMaxStackSize
|
||||
import com.willfp.eco.internal.items.modern.ArgParserTrim
|
||||
import com.willfp.eco.internal.lookup.SegmentParserGroup
|
||||
import com.willfp.eco.internal.lookup.SegmentParserUseIfPresent
|
||||
import com.willfp.eco.internal.particle.ParticleFactoryRGB
|
||||
@@ -97,8 +103,14 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
Items.registerArgParser(ArgParserName)
|
||||
Items.registerArgParser(ArgParserHead)
|
||||
Items.registerArgParser(ArgParserEntity)
|
||||
if (Prerequisite.HAS_1_20.isMet) {
|
||||
|
||||
if (Prerequisite.HAS_PAPER.isMet && Prerequisite.HAS_1_21.isMet) {
|
||||
Items.registerArgParser(ArgParserTrim)
|
||||
Items.registerArgParser(ArgParserFireResistant)
|
||||
Items.registerArgParser(ArgParserGlint)
|
||||
Items.registerArgParser(ArgParserItemName)
|
||||
Items.registerArgParser(ArgParserMaxDamage)
|
||||
Items.registerArgParser(ArgParserMaxStackSize)
|
||||
}
|
||||
|
||||
Entities.registerArgParser(EntityArgParserName)
|
||||
|
||||
Reference in New Issue
Block a user