Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52c1b52f6d | ||
|
|
f321296227 | ||
|
|
ddd12db420 | ||
|
|
bd09791b5b | ||
|
|
ce9549f03d | ||
|
|
52367dbb95 | ||
|
|
0080c32c23 | ||
|
|
581094a930 | ||
|
|
5d9c8775e8 | ||
|
|
9ab51d2c87 | ||
|
|
b0de341d7f | ||
|
|
1bada835ea |
@@ -22,6 +22,7 @@ dependencies {
|
||||
implementation(project(path = ":eco-core:core-plugin", configuration = "shadow"))
|
||||
implementation(project(":eco-core:core-proxy"))
|
||||
implementation(project(":eco-core:core-backend"))
|
||||
implementation(project(":eco-core:core-backend-modern"))
|
||||
implementation(project(path = ":eco-core:core-nms:v1_17_R1", configuration = "reobf"))
|
||||
implementation(project(path = ":eco-core:core-nms:v1_18_R1", configuration = "reobf"))
|
||||
implementation(project(path = ":eco-core:core-nms:v1_18_R2", configuration = "reobf"))
|
||||
|
||||
@@ -158,11 +158,8 @@ public final class DurabilityUtils {
|
||||
}
|
||||
|
||||
if (item.getItemMeta() instanceof Damageable meta) {
|
||||
meta.setDamage(meta.getDamage() - repair);
|
||||
meta.setDamage(Math.max(0, meta.getDamage() - repair));
|
||||
|
||||
if (meta.getDamage() < 0) {
|
||||
meta.setDamage(0);
|
||||
}
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
}
|
||||
}
|
||||
|
||||
19
eco-core/core-backend-modern/build.gradle.kts
Normal file
19
eco-core/core-backend-modern/build.gradle.kts
Normal file
@@ -0,0 +1,19 @@
|
||||
group = "com.willfp"
|
||||
version = rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":eco-core:core-backend"))
|
||||
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks {
|
||||
compileJava {
|
||||
options.release = 21
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "21"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.willfp.eco.internal.compat.modern.entities
|
||||
|
||||
import com.willfp.eco.core.entities.Entities
|
||||
import com.willfp.eco.internal.compat.modern.entities.parsers.EntityArgParserJumpStrength
|
||||
import com.willfp.eco.internal.compat.modern.entities.parsers.EntityArgParserScale
|
||||
import com.willfp.eco.internal.entities.ModernEntityArgParsers
|
||||
|
||||
class ModernEntityArgParsersImpl: ModernEntityArgParsers {
|
||||
override fun registerAll() {
|
||||
Entities.registerArgParser(EntityArgParserScale)
|
||||
Entities.registerArgParser(EntityArgParserJumpStrength)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.internal.entities
|
||||
package com.willfp.eco.internal.compat.modern.entities.parsers
|
||||
|
||||
import com.willfp.eco.core.entities.args.EntityArgParseResult
|
||||
import com.willfp.eco.core.entities.args.EntityArgParser
|
||||
@@ -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,8 +36,8 @@ object EntityArgParserJumpStrength : EntityArgParser {
|
||||
return@EntityArgParseResult
|
||||
}
|
||||
|
||||
it.getAttribute(Attribute.HORSE_JUMP_STRENGTH)?.baseValue = attributeValue
|
||||
it.getAttribute(Attribute.GENERIC_JUMP_STRENGTH)?.baseValue = attributeValue
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.willfp.eco.internal.compat.modern.entities.parsers
|
||||
|
||||
import com.willfp.eco.core.entities.args.EntityArgParseResult
|
||||
import com.willfp.eco.core.entities.args.EntityArgParser
|
||||
import org.bukkit.attribute.Attribute
|
||||
import org.bukkit.entity.LivingEntity
|
||||
import org.bukkit.entity.Phantom
|
||||
import org.bukkit.entity.Slime
|
||||
|
||||
object EntityArgParserScale : EntityArgParser {
|
||||
override fun parseArguments(args: Array<out String>): EntityArgParseResult? {
|
||||
var attributeValue: Double? = null
|
||||
|
||||
for (arg in args) {
|
||||
val argSplit = arg.split(":")
|
||||
if (!argSplit[0].equals("scale", ignoreCase = true)) {
|
||||
continue
|
||||
}
|
||||
if (argSplit.size < 2) {
|
||||
continue
|
||||
}
|
||||
attributeValue = argSplit[1].toDoubleOrNull()
|
||||
}
|
||||
|
||||
attributeValue ?: return null
|
||||
|
||||
return EntityArgParseResult(
|
||||
{
|
||||
if (it !is LivingEntity) {
|
||||
return@EntityArgParseResult false
|
||||
}
|
||||
|
||||
val inst = it.getAttribute(Attribute.GENERIC_SCALE) ?: return@EntityArgParseResult false
|
||||
inst.value >= attributeValue
|
||||
},
|
||||
{
|
||||
if (it !is LivingEntity) {
|
||||
return@EntityArgParseResult
|
||||
}
|
||||
|
||||
it.getAttribute(Attribute.GENERIC_SCALE)?.baseValue = attributeValue
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.eco.internal.compat.modern.items
|
||||
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.internal.compat.modern.items.parsers.ArgParserFireResistant
|
||||
import com.willfp.eco.internal.compat.modern.items.parsers.ArgParserGlint
|
||||
import com.willfp.eco.internal.compat.modern.items.parsers.ArgParserItemName
|
||||
import com.willfp.eco.internal.compat.modern.items.parsers.ArgParserMaxDamage
|
||||
import com.willfp.eco.internal.compat.modern.items.parsers.ArgParserMaxStackSize
|
||||
import com.willfp.eco.internal.compat.modern.items.parsers.ArgParserTrim
|
||||
import com.willfp.eco.internal.items.ModernItemArgParsers
|
||||
|
||||
class ModernItemArgParsersImpl : ModernItemArgParsers {
|
||||
override fun registerAll() {
|
||||
Items.registerArgParser(ArgParserTrim)
|
||||
Items.registerArgParser(ArgParserFireResistant)
|
||||
Items.registerArgParser(ArgParserGlint)
|
||||
Items.registerArgParser(ArgParserItemName)
|
||||
Items.registerArgParser(ArgParserMaxDamage)
|
||||
Items.registerArgParser(ArgParserMaxStackSize)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.willfp.eco.internal.compat.modern.items.parsers
|
||||
|
||||
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.compat.modern.items.parsers
|
||||
|
||||
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.compat.modern.items.parsers
|
||||
|
||||
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,31 @@
|
||||
package com.willfp.eco.internal.compat.modern.items.parsers
|
||||
|
||||
import com.willfp.eco.internal.items.templates.ValueArgParser
|
||||
import org.bukkit.inventory.meta.Damageable
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
|
||||
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,22 @@
|
||||
package com.willfp.eco.internal.compat.modern.items.parsers
|
||||
|
||||
import com.willfp.eco.internal.items.templates.ValueArgParser
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
|
||||
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.compat.modern.items.parsers
|
||||
|
||||
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()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,3 +13,15 @@ dependencies {
|
||||
compileOnly("org.yaml:snakeyaml:1.33")
|
||||
compileOnly("com.moandjiezana.toml:toml4j:0.7.2")
|
||||
}
|
||||
|
||||
tasks {
|
||||
compileJava {
|
||||
options.release = 17
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,14 +126,19 @@ abstract class HandledCommand(
|
||||
* @return The tab completion results.
|
||||
*/
|
||||
private fun CommandBase.handleTabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||
if (!sender.hasPermission(permission)) return emptyList()
|
||||
if (!sender.hasPermission(permission)) {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
if (args.size == 1) {
|
||||
val completions = subcommands.filter { sender.hasPermission(it.permission) }.map { it.name }
|
||||
val completions = mutableListOf<String>()
|
||||
|
||||
val list = mutableListOf<String>()
|
||||
StringUtil.copyPartialMatches(
|
||||
args[0],
|
||||
subcommands.filter { sender.hasPermission(it.permission) }.map { it.name },
|
||||
completions
|
||||
)
|
||||
|
||||
StringUtil.copyPartialMatches(args[0], completions, list)
|
||||
if (completions.isNotEmpty()) {
|
||||
return completions
|
||||
}
|
||||
@@ -156,9 +161,11 @@ abstract class HandledCommand(
|
||||
}
|
||||
|
||||
val completions = tabComplete(sender, args).toMutableList()
|
||||
|
||||
if (sender is Player) {
|
||||
completions.addAll(tabComplete(sender, args))
|
||||
}
|
||||
|
||||
return completions.sorted()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.willfp.eco.internal.compat
|
||||
|
||||
import com.willfp.eco.core.Prerequisite
|
||||
import com.willfp.eco.core.proxy.exceptions.ProxyError
|
||||
|
||||
private const val BASE_PACKAGE = "com.willfp.eco.internal.compat.modern"
|
||||
private val isModern = Prerequisite.HAS_PAPER.isMet && Prerequisite.HAS_1_21.isMet
|
||||
|
||||
internal annotation class ModernCompatibilityProxy(
|
||||
val location: String
|
||||
)
|
||||
|
||||
private val cache = mutableMapOf<Class<*>, Any>()
|
||||
|
||||
object ModernCompatibilityScope {
|
||||
inline fun <reified T> loadProxy(): T {
|
||||
return loadCompatibilityProxy(T::class.java)
|
||||
}
|
||||
|
||||
inline fun <reified T> useProxy(block: T.() -> Any?) {
|
||||
val proxy = loadProxy<T>()
|
||||
|
||||
with(proxy) {
|
||||
block()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <R> ifModern(block: ModernCompatibilityScope.() -> R) {
|
||||
if (!isModern) {
|
||||
return
|
||||
}
|
||||
|
||||
block(ModernCompatibilityScope)
|
||||
}
|
||||
|
||||
fun <T> loadCompatibilityProxy(clazz: Class<T>): T {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return cache.getOrPut(clazz) {
|
||||
loadProxyUncached(clazz)
|
||||
} as T
|
||||
}
|
||||
|
||||
private fun loadProxyUncached(clazz: Class<*>): Any {
|
||||
val proxy = clazz.getAnnotation(ModernCompatibilityProxy::class.java)
|
||||
val location = proxy?.location ?: throw IllegalArgumentException("Class ${clazz.name} is not a proxy")
|
||||
val className = "$BASE_PACKAGE.$location"
|
||||
|
||||
try {
|
||||
val found = Class.forName(className)
|
||||
|
||||
val constructor = found.getConstructor()
|
||||
val instance = constructor.newInstance()
|
||||
|
||||
if (!clazz.isInstance(instance)) {
|
||||
throw ProxyError(
|
||||
"Modern compatibility proxy class $className does not implement ${clazz.name}",
|
||||
ClassCastException()
|
||||
)
|
||||
}
|
||||
|
||||
return instance
|
||||
} catch (e: ClassNotFoundException) {
|
||||
throw ProxyError("Could not find modern compatibility proxy class $className", e)
|
||||
} catch (e: NoSuchMethodException) {
|
||||
throw ProxyError("Could not find no-args constructor for modern compatibility proxy class $className", e)
|
||||
}
|
||||
}
|
||||
@@ -40,4 +40,4 @@ object EntityArgParserFlySpeed : EntityArgParser {
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.willfp.eco.internal.entities
|
||||
|
||||
import com.willfp.eco.internal.compat.ModernCompatibilityProxy
|
||||
|
||||
@ModernCompatibilityProxy("entities.ModernEntityArgParsersImpl")
|
||||
interface ModernEntityArgParsers {
|
||||
fun registerAll()
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.willfp.eco.internal.gui.menu
|
||||
|
||||
import com.willfp.eco.core.Eco
|
||||
import com.willfp.eco.core.Prerequisite
|
||||
import com.willfp.eco.core.gui.menu.events.CaptiveItemChangeEvent
|
||||
import com.willfp.eco.core.items.isEcoEmpty
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
|
||||
@@ -20,9 +22,23 @@ fun Player.forceRenderedInventory(menu: RenderedInventory) {
|
||||
trackedForceRendered[this.uniqueId] = menu
|
||||
}
|
||||
|
||||
// Workaround because 1.21 has OpenInventory as an interface instead of an abstract class like in previous versions
|
||||
interface TopInventoryProxy {
|
||||
fun getTopInventory(player: Player): Inventory
|
||||
}
|
||||
|
||||
private val Player.topInventory: Inventory
|
||||
get() {
|
||||
return if (!Prerequisite.HAS_1_21.isMet) {
|
||||
Eco.get().ecoPlugin.getProxy(TopInventoryProxy::class.java).getTopInventory(this)
|
||||
} else {
|
||||
this.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
|
||||
val Player.renderedInventory: RenderedInventory?
|
||||
get() = trackedForceRendered[this.uniqueId]
|
||||
?: this.openInventory.topInventory.asRenderedInventory()
|
||||
?: this.topInventory.asRenderedInventory()
|
||||
|
||||
class RenderedInventory(
|
||||
val menu: EcoMenu,
|
||||
|
||||
@@ -49,4 +49,4 @@ object ArgParserColor : LookupArgParser {
|
||||
|
||||
return "color:#${Integer.toHexString(meta.color.asRGB())}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ object ArgParserEnchantment : LookupArgParser {
|
||||
continue
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
val enchant = Enchantment.getByKey(NamespacedKeyUtils.create("minecraft", argSplit[0]))
|
||||
val level = argSplit[1].toIntOrNull()
|
||||
|
||||
|
||||
@@ -61,4 +61,4 @@ object ArgParserEntity : LookupArgParser {
|
||||
|
||||
return state.spawnedType?.let { "entity:${state.spawnedType!!.name}" } ?: return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,4 +44,4 @@ object ArgParserTexture : LookupArgParser {
|
||||
|
||||
return "texture:${SkullUtils.getSkullTexture(meta)}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,8 @@
|
||||
package com.willfp.eco.internal.items
|
||||
|
||||
import com.willfp.eco.internal.compat.ModernCompatibilityProxy
|
||||
|
||||
@ModernCompatibilityProxy("items.ModernItemArgParsersImpl")
|
||||
interface ModernItemArgParsers {
|
||||
fun registerAll()
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_17_R1
|
||||
|
||||
import com.willfp.eco.internal.gui.menu.TopInventoryProxy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
class TopInventory: TopInventoryProxy {
|
||||
override fun getTopInventory(player: Player): Inventory {
|
||||
return player.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_18_R1
|
||||
|
||||
import com.willfp.eco.internal.gui.menu.TopInventoryProxy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
class TopInventory: TopInventoryProxy {
|
||||
override fun getTopInventory(player: Player): Inventory {
|
||||
return player.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_18_R2
|
||||
|
||||
import com.willfp.eco.internal.gui.menu.TopInventoryProxy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
class TopInventory: TopInventoryProxy {
|
||||
override fun getTopInventory(player: Player): Inventory {
|
||||
return player.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.internal.gui.menu.TopInventoryProxy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
class TopInventory: TopInventoryProxy {
|
||||
override fun getTopInventory(player: Player): Inventory {
|
||||
return player.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R2
|
||||
|
||||
import com.willfp.eco.internal.gui.menu.TopInventoryProxy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
class TopInventory: TopInventoryProxy {
|
||||
override fun getTopInventory(player: Player): Inventory {
|
||||
return player.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R3
|
||||
|
||||
import com.willfp.eco.internal.gui.menu.TopInventoryProxy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
class TopInventory: TopInventoryProxy {
|
||||
override fun getTopInventory(player: Player): Inventory {
|
||||
return player.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_20_R1
|
||||
|
||||
import com.willfp.eco.internal.gui.menu.TopInventoryProxy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
class TopInventory: TopInventoryProxy {
|
||||
override fun getTopInventory(player: Player): Inventory {
|
||||
return player.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_20_R2
|
||||
|
||||
import com.willfp.eco.internal.gui.menu.TopInventoryProxy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
class TopInventory: TopInventoryProxy {
|
||||
override fun getTopInventory(player: Player): Inventory {
|
||||
return player.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_20_R3
|
||||
|
||||
import com.willfp.eco.internal.gui.menu.TopInventoryProxy
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
|
||||
class TopInventory: TopInventoryProxy {
|
||||
override fun getTopInventory(player: Player): Inventory {
|
||||
return player.openInventory.topInventory
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import java.lang.reflect.Field
|
||||
|
||||
class ExtendedPersistentDataContainerFactory : ExtendedPersistentDataContainerFactoryProxy {
|
||||
private val registry: CraftPersistentDataTypeRegistry
|
||||
@@ -21,7 +22,15 @@ class ExtendedPersistentDataContainerFactory : ExtendedPersistentDataContainerFa
|
||||
*/
|
||||
val item = CraftItemStack.asCraftCopy(ItemStack(Material.STONE))
|
||||
val pdc = item.itemMeta!!.persistentDataContainer
|
||||
this.registry = CraftPersistentDataContainer::class.java.getDeclaredField("registry")
|
||||
|
||||
// Cross-version compatibility:
|
||||
val registryField: Field = try {
|
||||
CraftPersistentDataContainer::class.java.getDeclaredField("registry")
|
||||
} catch (e: NoSuchFieldException) {
|
||||
CraftPersistentDataContainer::class.java.superclass.getDeclaredField("registry")
|
||||
}
|
||||
|
||||
this.registry = registryField
|
||||
.apply { isAccessible = true }.get(pdc) as CraftPersistentDataTypeRegistry
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,38 @@ import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.core.packet.PacketListener
|
||||
import com.willfp.eco.core.particle.Particles
|
||||
import com.willfp.eco.core.price.Prices
|
||||
import com.willfp.eco.internal.compat.ifModern
|
||||
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.entities.EntityArgParserAdult
|
||||
import com.willfp.eco.internal.entities.EntityArgParserAttackDamage
|
||||
import com.willfp.eco.internal.entities.EntityArgParserAttackSpeed
|
||||
import com.willfp.eco.internal.entities.EntityArgParserBaby
|
||||
import com.willfp.eco.internal.entities.EntityArgParserCharged
|
||||
import com.willfp.eco.internal.entities.EntityArgParserEquipment
|
||||
import com.willfp.eco.internal.entities.EntityArgParserExplosionRadius
|
||||
import com.willfp.eco.internal.entities.EntityArgParserFlySpeed
|
||||
import com.willfp.eco.internal.entities.EntityArgParserFollowRange
|
||||
import com.willfp.eco.internal.entities.EntityArgParserHealth
|
||||
import com.willfp.eco.internal.entities.EntityArgParserKnockback
|
||||
import com.willfp.eco.internal.entities.EntityArgParserKnockbackResistance
|
||||
import com.willfp.eco.internal.entities.EntityArgParserName
|
||||
import com.willfp.eco.internal.entities.EntityArgParserNoAI
|
||||
import com.willfp.eco.internal.entities.EntityArgParserSilent
|
||||
import com.willfp.eco.internal.entities.EntityArgParserSize
|
||||
import com.willfp.eco.internal.entities.EntityArgParserSpawnReinforcements
|
||||
import com.willfp.eco.internal.entities.EntityArgParserSpeed
|
||||
import com.willfp.eco.internal.entities.ModernEntityArgParsers
|
||||
import com.willfp.eco.internal.items.ArgParserColor
|
||||
import com.willfp.eco.internal.items.ArgParserCustomModelData
|
||||
import com.willfp.eco.internal.items.ArgParserEnchantment
|
||||
import com.willfp.eco.internal.items.ArgParserEntity
|
||||
import com.willfp.eco.internal.items.ArgParserFlag
|
||||
import com.willfp.eco.internal.items.ArgParserHead
|
||||
import com.willfp.eco.internal.items.ArgParserName
|
||||
import com.willfp.eco.internal.items.ArgParserTexture
|
||||
import com.willfp.eco.internal.items.ArgParserUnbreakable
|
||||
import com.willfp.eco.internal.items.ModernItemArgParsers
|
||||
import com.willfp.eco.internal.lookup.SegmentParserGroup
|
||||
import com.willfp.eco.internal.lookup.SegmentParserUseIfPresent
|
||||
import com.willfp.eco.internal.particle.ParticleFactoryRGB
|
||||
@@ -37,16 +65,50 @@ import com.willfp.eco.internal.spigot.data.PlayerBlockListener
|
||||
import com.willfp.eco.internal.spigot.data.ProfileHandler
|
||||
import com.willfp.eco.internal.spigot.data.storage.ProfileSaver
|
||||
import com.willfp.eco.internal.spigot.drops.CollatedRunnable
|
||||
import com.willfp.eco.internal.spigot.eventlisteners.*
|
||||
import com.willfp.eco.internal.spigot.eventlisteners.EntityDeathByEntityListeners
|
||||
import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListenersPaper
|
||||
import com.willfp.eco.internal.spigot.eventlisteners.NaturalExpGainListenersSpigot
|
||||
import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersPaper
|
||||
import com.willfp.eco.internal.spigot.eventlisteners.PlayerJumpListenersSpigot
|
||||
import com.willfp.eco.internal.spigot.eventlisteners.armor.ArmorChangeEventListeners
|
||||
import com.willfp.eco.internal.spigot.eventlisteners.armor.ArmorListener
|
||||
import com.willfp.eco.internal.spigot.gui.GUIListener
|
||||
import com.willfp.eco.internal.spigot.integrations.afk.AFKIntegrationCMI
|
||||
import com.willfp.eco.internal.spigot.integrations.afk.AFKIntegrationEssentials
|
||||
import com.willfp.eco.internal.spigot.integrations.anticheat.*
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.*
|
||||
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatAAC
|
||||
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatAlice
|
||||
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatMatrix
|
||||
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatNCP
|
||||
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatSpartan
|
||||
import com.willfp.eco.internal.spigot.integrations.anticheat.AnticheatVulcan
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefBentoBox
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCombatLogXV10
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCombatLogXV11
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCrashClaim
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefDeluxeCombat
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefFabledSkyBlock
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefFactionsUUID
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefGriefPrevention
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefHuskClaims
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefHuskTowns
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefIridiumSkyblock
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefKingdoms
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefLands
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefPvPManager
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefRPGHorses
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefSuperiorSkyblock2
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefTowny
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefWorldGuard
|
||||
import com.willfp.eco.internal.spigot.integrations.customentities.CustomEntitiesMythicMobs
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.*
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsCustomCrafting
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsDenizen
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsExecutableItems
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsHeadDatabase
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsItemBridge
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsItemsAdder
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsMythicMobs
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsOraxen
|
||||
import com.willfp.eco.internal.spigot.integrations.customitems.CustomItemsScyther
|
||||
import com.willfp.eco.internal.spigot.integrations.customrecipes.CustomRecipeCustomCrafting
|
||||
import com.willfp.eco.internal.spigot.integrations.economy.EconomyVault
|
||||
import com.willfp.eco.internal.spigot.integrations.entitylookup.EntityLookupModelEngine
|
||||
@@ -97,8 +159,11 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
Items.registerArgParser(ArgParserName)
|
||||
Items.registerArgParser(ArgParserHead)
|
||||
Items.registerArgParser(ArgParserEntity)
|
||||
if (Prerequisite.HAS_1_20.isMet) {
|
||||
Items.registerArgParser(ArgParserTrim)
|
||||
|
||||
ifModern {
|
||||
useProxy<ModernItemArgParsers> {
|
||||
registerAll()
|
||||
}
|
||||
}
|
||||
|
||||
Entities.registerArgParser(EntityArgParserName)
|
||||
@@ -108,7 +173,6 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
Entities.registerArgParser(EntityArgParserFlySpeed)
|
||||
Entities.registerArgParser(EntityArgParserFollowRange)
|
||||
Entities.registerArgParser(EntityArgParserHealth)
|
||||
Entities.registerArgParser(EntityArgParserJumpStrength)
|
||||
Entities.registerArgParser(EntityArgParserKnockback)
|
||||
Entities.registerArgParser(EntityArgParserKnockbackResistance)
|
||||
Entities.registerArgParser(EntityArgParserSize)
|
||||
@@ -121,6 +185,12 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
Entities.registerArgParser(EntityArgParserSilent)
|
||||
Entities.registerArgParser(EntityArgParserEquipment)
|
||||
|
||||
ifModern {
|
||||
useProxy<ModernEntityArgParsers> {
|
||||
registerAll()
|
||||
}
|
||||
}
|
||||
|
||||
Prices.registerPriceFactory(PriceFactoryEconomy)
|
||||
Prices.registerPriceFactory(PriceFactoryXPLevels)
|
||||
Prices.registerPriceFactory(PriceFactoryXP)
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
version = 6.71.0
|
||||
version = 6.71.5
|
||||
kotlin.incremental.useClasspathSnapshot=false
|
||||
@@ -29,4 +29,5 @@ include(":eco-core:core-nms:v1_20_R3")
|
||||
include(":eco-core:core-nms:v1_21")
|
||||
include(":eco-core:core-proxy")
|
||||
include(":eco-core:core-plugin")
|
||||
include(":eco-core:core-backend")
|
||||
include(":eco-core:core-backend")
|
||||
include(":eco-core:core-backend-modern")
|
||||
Reference in New Issue
Block a user