Added proxies

This commit is contained in:
Auxilor 2022-08-30 00:00:00 +01:00
parent a138aac13d
commit 924d42b96e
27 changed files with 330 additions and 13 deletions

View File

@ -0,0 +1,9 @@
group 'com.willfp'
version rootProject.version
subprojects {
dependencies {
compileOnly project(':eco-core:core-proxy')
compileOnly project(':eco-core:core-plugin')
}
}

View File

@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.17-R0.1-SNAPSHOT'
}

View File

@ -0,0 +1,27 @@
package com.willfp.ecoenchants.proxy.v1_17_R1
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import net.minecraft.world.item.enchantment.Enchantment
import org.bukkit.NamespacedKey
import org.bukkit.craftbukkit.v1_17_R1.enchantments.CraftEnchantment
class EcoCraftEnchantment(
target: Enchantment,
private val _maxLevel: Int,
private val conflicts: Collection<NamespacedKey>
) : CraftEnchantment(target) {
override fun getMaxLevel(): Int = _maxLevel
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
if (other is EcoEnchant) {
return other.conflictsWith(this)
}
return conflicts.contains(other.key)
}
fun register() {
EcoEnchants.register(this)
}
}

View File

@ -0,0 +1,20 @@
package com.willfp.ecoenchants.proxy.v1_17_R1
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
override fun registerNewCraftEnchantment(
enchantment: Enchantment,
maxLevel: Int,
conflicts: Collection<NamespacedKey>
) {
for (enchant in net.minecraft.core.IRegistry.X) {
val key = org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey.fromMinecraft(
net.minecraft.core.IRegistry.X.getKey(enchant)
)
EcoCraftEnchantment(enchant, maxLevel, conflicts).register()
}
}
}

View File

@ -0,0 +1,11 @@
package com.willfp.ecoenchants.proxy.v1_17_R1
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer
import org.bukkit.entity.Player
class OpenInventory : OpenInventoryProxy {
override fun getOpenInventory(player: Player): Any {
return (player as CraftPlayer).handle.bV
}
}

View File

@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.18-R0.1-SNAPSHOT'
}

View File

@ -0,0 +1,27 @@
package com.willfp.ecoenchants.proxy.v1_18_R1
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import net.minecraft.world.item.enchantment.Enchantment
import org.bukkit.NamespacedKey
import org.bukkit.craftbukkit.v1_18_R1.enchantments.CraftEnchantment
class EcoCraftEnchantment(
target: Enchantment,
private val _maxLevel: Int,
private val conflicts: Collection<NamespacedKey>
) : CraftEnchantment(target) {
override fun getMaxLevel(): Int = _maxLevel
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
if (other is EcoEnchant) {
return other.conflictsWith(this)
}
return conflicts.contains(other.key)
}
fun register() {
EcoEnchants.register(this)
}
}

View File

@ -0,0 +1,20 @@
package com.willfp.ecoenchants.proxy.v1_18_R1
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
override fun registerNewCraftEnchantment(
enchantment: Enchantment,
maxLevel: Int,
conflicts: Collection<NamespacedKey>
) {
for (enchant in net.minecraft.core.IRegistry.Y) {
val key = org.bukkit.craftbukkit.v1_18_R1.util.CraftNamespacedKey.fromMinecraft(
net.minecraft.core.IRegistry.Y.b(enchant)
)
EcoCraftEnchantment(enchant, maxLevel, conflicts).register()
}
}
}

View File

@ -0,0 +1,11 @@
package com.willfp.ecoenchants.proxy.v1_18_R1
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer
import org.bukkit.entity.Player
class OpenInventory : OpenInventoryProxy {
override fun getOpenInventory(player: Player): Any {
return (player as CraftPlayer).handle.bW
}
}

View File

@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT'
}

View File

@ -0,0 +1,27 @@
package com.willfp.ecoenchants.proxy.v1_18_R2
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import net.minecraft.world.item.enchantment.Enchantment
import org.bukkit.NamespacedKey
import org.bukkit.craftbukkit.v1_18_R2.enchantments.CraftEnchantment
class EcoCraftEnchantment(
target: Enchantment,
private val _maxLevel: Int,
private val conflicts: Collection<NamespacedKey>
) : CraftEnchantment(target) {
override fun getMaxLevel(): Int = _maxLevel
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
if (other is EcoEnchant) {
return other.conflictsWith(this)
}
return conflicts.contains(other.key)
}
fun register() {
EcoEnchants.register(this)
}
}

View File

@ -0,0 +1,20 @@
package com.willfp.ecoenchants.proxy.v1_18_R2
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
override fun registerNewCraftEnchantment(
enchantment: Enchantment,
maxLevel: Int,
conflicts: Collection<NamespacedKey>
) {
for (enchant in net.minecraft.core.IRegistry.V) {
val key = org.bukkit.craftbukkit.v1_18_R2.util.CraftNamespacedKey.fromMinecraft(
net.minecraft.core.IRegistry.V.b(enchant)
)
EcoCraftEnchantment(enchant, maxLevel, conflicts).register()
}
}
}

View File

@ -0,0 +1,11 @@
package com.willfp.ecoenchants.proxy.v1_18_R2
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer
import org.bukkit.entity.Player
class OpenInventory : OpenInventoryProxy {
override fun getOpenInventory(player: Player): Any {
return (player as CraftPlayer).handle.bV
}
}

View File

@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.19.1-R0.1-SNAPSHOT'
}

View File

@ -0,0 +1,27 @@
package com.willfp.ecoenchants.proxy.v1_19_R1
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.enchants.EcoEnchants
import net.minecraft.world.item.enchantment.Enchantment
import org.bukkit.NamespacedKey
import org.bukkit.craftbukkit.v1_17_R1.enchantments.CraftEnchantment
class EcoCraftEnchantment(
target: Enchantment,
private val _maxLevel: Int,
private val conflicts: Collection<NamespacedKey>
) : CraftEnchantment(target) {
override fun getMaxLevel(): Int = _maxLevel
override fun conflictsWith(other: org.bukkit.enchantments.Enchantment): Boolean {
if (other is EcoEnchant) {
return other.conflictsWith(this)
}
return conflicts.contains(other.key)
}
fun register() {
EcoEnchants.register(this)
}
}

View File

@ -0,0 +1,20 @@
package com.willfp.ecoenchants.proxy.v1_19_R1
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
class EcoCraftEnchantmentManager : EcoCraftEnchantmentManagerProxy {
override fun registerNewCraftEnchantment(
enchantment: Enchantment,
maxLevel: Int,
conflicts: Collection<NamespacedKey>
) {
for (enchant in net.minecraft.core.IRegistry.W) {
val key = org.bukkit.craftbukkit.v1_19_R1.util.CraftNamespacedKey.fromMinecraft(
net.minecraft.core.IRegistry.W.b(enchant)
)
EcoCraftEnchantment(enchant, maxLevel, conflicts).register()
}
}
}

View File

@ -0,0 +1,11 @@
package com.willfp.ecoenchants.proxy.v1_19_R1
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer
import org.bukkit.entity.Player
class OpenInventory : OpenInventoryProxy {
override fun getOpenInventory(player: Player): Any {
return (player as CraftPlayer).handle.bU
}
}

View File

@ -3,6 +3,7 @@ version rootProject.version
dependencies { dependencies {
compileOnly fileTree(dir: '../../lib', include: ['*.jar']) compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
compileOnly project(":eco-core:core-proxy")
compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT' compileOnly 'io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT'
compileOnly 'net.essentialsx:EssentialsX:2.19.0' compileOnly 'net.essentialsx:EssentialsX:2.19.0'
} }

View File

@ -12,6 +12,7 @@ import com.willfp.ecoenchants.config.VanillaEnchantsYml
import com.willfp.ecoenchants.display.EnchantDisplay import com.willfp.ecoenchants.display.EnchantDisplay
import com.willfp.ecoenchants.enchants.EcoEnchants import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.impl.EnchantmentTelekinesis import com.willfp.ecoenchants.enchants.impl.EnchantmentTelekinesis
import com.willfp.ecoenchants.enchants.registerVanillaEnchants
import com.willfp.ecoenchants.integrations.EnchantRegistrations import com.willfp.ecoenchants.integrations.EnchantRegistrations
import com.willfp.ecoenchants.integrations.plugins.CMIIntegration import com.willfp.ecoenchants.integrations.plugins.CMIIntegration
import com.willfp.ecoenchants.integrations.plugins.EssentialsIntegration import com.willfp.ecoenchants.integrations.plugins.EssentialsIntegration
@ -36,13 +37,13 @@ class EcoEnchantsPlugin : LibReforgePlugin() {
override fun handleEnableAdditional() { override fun handleEnableAdditional() {
copyConfigs("enchants") copyConfigs("enchants")
registerHolderProvider { it.heldEnchantLevels } registerHolderProvider { it.heldEnchantLevels }
} }
override fun handleReloadAdditional() { override fun handleReloadAdditional() {
// Load hardcoded enchantments // Load hardcoded enchantments
EnchantmentTelekinesis(this) EnchantmentTelekinesis(this)
registerVanillaEnchants(this)
logger.info(EcoEnchants.values().size.toString() + " Enchants Loaded") logger.info(EcoEnchants.values().size.toString() + " Enchants Loaded")
} }

View File

@ -2,6 +2,7 @@ package com.willfp.ecoenchants.enchants
import com.github.benmanes.caffeine.cache.Caffeine import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.ecoenchants.EcoEnchantsPlugin import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.rarity.EnchantmentRarities import com.willfp.ecoenchants.rarity.EnchantmentRarities
import com.willfp.ecoenchants.rarity.EnchantmentRarity import com.willfp.ecoenchants.rarity.EnchantmentRarity
import com.willfp.ecoenchants.type.EnchantmentType import com.willfp.ecoenchants.type.EnchantmentType
@ -67,3 +68,15 @@ class VanillaEcoEnchantLike(
return Objects.hash(this.enchant) return Objects.hash(this.enchant)
} }
} }
fun registerVanillaEnchants(plugin: EcoEnchantsPlugin) {
for (vanilla in plugin.vanillaEnchantsYml.getKeys(false)) {
if (plugin.vanillaEnchantsYml.has("$vanilla.max-level")) {
plugin.getProxy(EcoCraftEnchantmentManagerProxy::class.java).registerNewCraftEnchantment(
Enchantment.getByKey(NamespacedKey.minecraft(vanilla))!!,
plugin.vanillaEnchantsYml.getInt("$vanilla.max-level"),
plugin.vanillaEnchantsYml.getStrings("$vanilla.conflicts").map { NamespacedKey.minecraft(it) }
)
}
}
}

View File

@ -121,18 +121,26 @@ object EcoEnchants {
*/ */
@Suppress("UNCHECKED_CAST", "DEPRECATION") @Suppress("UNCHECKED_CAST", "DEPRECATION")
internal fun addNewEnchant(enchant: EcoEnchant) { internal fun addNewEnchant(enchant: EcoEnchant) {
removeEnchant(enchant) BY_KEY[enchant.id] = enchant
BY_NAME[ChatColor.stripColor(enchant.displayName)] = enchant
register(enchant)
}
/**
* Register a new [Enchantment] with the server.
*
* @param enchantment The [Enchantment] to add.
*/
@JvmStatic
fun register(enchantment: Enchantment) {
Enchantment::class.java.getDeclaredField("acceptingNew") Enchantment::class.java.getDeclaredField("acceptingNew")
.apply { .apply {
isAccessible = true isAccessible = true
set(null, true) set(null, true)
} }
BY_KEY[enchant.id] = enchant Enchantment.registerEnchantment(enchantment)
BY_NAME[ChatColor.stripColor(enchant.displayName)] = enchant
Enchantment.registerEnchantment(enchant)
EnchantRegistrations.registerEnchantments() EnchantRegistrations.registerEnchantments()
} }
} }

View File

@ -4,6 +4,7 @@ import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.fast.fast import com.willfp.eco.core.fast.fast
import com.willfp.eco.core.proxy.ProxyConstants import com.willfp.eco.core.proxy.ProxyConstants
import com.willfp.eco.util.StringUtils import com.willfp.eco.util.StringUtils
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy
import org.bukkit.ChatColor import org.bukkit.ChatColor
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.entity.Player import org.bukkit.entity.Player
@ -56,14 +57,9 @@ class AnvilSupport(
fun onAnvilPrepare(@NotNull event: PrepareAnvilEvent) { fun onAnvilPrepare(@NotNull event: PrepareAnvilEvent) {
val player = event.viewers.getOrNull(0) as? Player ?: return val player = event.viewers.getOrNull(0) as? Player ?: return
// TODO: Implement proxies if (this.plugin.getProxy(OpenInventoryProxy::class.java).getOpenInventory(player)::class.java.toString() == anvilGuiClass) {
/*
if (this.getPlugin().getProxy(OpenInventoryProxy::class.java).getOpenInventory(player).getClass().toString()
.equals(ANVIL_GUI_CLASS)
) {
return return
} }
*/
if (antiRepeat.contains(player.uniqueId)) { if (antiRepeat.contains(player.uniqueId)) {
return return

View File

@ -1,11 +1,17 @@
# Rarity option does not affect vanilla enchantments. # Rarity option does not affect vanilla enchantments.
# The option is there for the display option to sort by rarity. # The option is there for the display option to sort by rarity.
# If you enable custom max levels for a vanilla enchant you have to also specify conflicts,
# if you don't the enchantment will have no conflicts at all, and vice-versa; changing conflicts
# will require you to specify the max level.
protection: protection:
name: "Protection" name: "Protection"
description: Reduces most types of damage. description: Reduces most types of damage.
type: normal type: normal
rarity: common rarity: common
#max-level: 6 # Custom max level to override for the enchantment. Raise it, but lowering it may cause bugs.
#conflicts: [] # Custom conflicts to override for the enchantment. Add or remove conflicts as you please.
fire_protection: fire_protection:
name: "Fire Protection" name: "Fire Protection"

View File

@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
}

View File

@ -0,0 +1,8 @@
package com.willfp.ecoenchants.proxy.proxies
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
interface EcoCraftEnchantmentManagerProxy {
fun registerNewCraftEnchantment(enchantment: Enchantment, maxLevel: Int, conflicts: Collection<NamespacedKey>)
}

View File

@ -0,0 +1,7 @@
package com.willfp.ecoenchants.proxy.proxies
import org.bukkit.entity.Player
interface OpenInventoryProxy {
fun getOpenInventory(player: Player): Any
}

View File

@ -3,3 +3,9 @@ rootProject.name = 'EcoEnchants'
// Core // Core
include ':eco-core' include ':eco-core'
include ':eco-core:core-plugin' include ':eco-core:core-plugin'
include ':eco-core:core-proxy'
include ':eco-core:core-nms'
include ':eco-core:core-nms:v1_17_R1'
include ':eco-core:core-nms:v1_18_R1'
include ':eco-core:core-nms:v1_18_R2'
include ':eco-core:core-nms:v1_19_R1'