Added many more enchantments and default plugin hook enchant system

This commit is contained in:
Auxilor
2022-10-03 16:59:33 +01:00
parent 9735a825d2
commit 676bd0ee0b
19 changed files with 458 additions and 13 deletions

View File

@@ -12,12 +12,6 @@ import com.willfp.ecoenchants.config.VanillaEnchantsYml
import com.willfp.ecoenchants.display.EnchantDisplay
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.LoreConversion
import com.willfp.ecoenchants.enchants.impl.EnchantmentPermanenceCurse
import com.willfp.ecoenchants.enchants.impl.EnchantmentRapid
import com.willfp.ecoenchants.enchants.impl.EnchantmentRepairing
import com.willfp.ecoenchants.enchants.impl.EnchantmentReplenish
import com.willfp.ecoenchants.enchants.impl.EnchantmentSoulbound
import com.willfp.ecoenchants.enchants.impl.EnchantmentTelekinesis
import com.willfp.ecoenchants.enchants.registerVanillaEnchants
import com.willfp.ecoenchants.integrations.EnchantRegistrations
import com.willfp.ecoenchants.integrations.plugins.CMIIntegration
@@ -37,6 +31,8 @@ class EcoEnchantsPlugin : LibReforgePlugin() {
val rarityYml = RarityYml(this)
val typesYml = TypesYml(this)
val vanillaEnchantsYml = VanillaEnchantsYml(this)
var isLoaded = false
private set
init {
instance = this
@@ -48,6 +44,10 @@ class EcoEnchantsPlugin : LibReforgePlugin() {
registerHolderProvider { it.heldEnchantLevels }
}
override fun handleAfterLoad() {
isLoaded = true
}
override fun handleReloadAdditional() {
registerVanillaEnchants(this)

View File

@@ -108,6 +108,8 @@ abstract class EcoEnchant(
)
init {
checkDependencies()
config.injectPlaceholders(
PlayerStaticPlaceholder(
"level"
@@ -116,9 +118,9 @@ abstract class EcoEnchant(
}
)
conditions = config.getSubsections("conditions").mapNotNull {
conditions = if (plugin.isLoaded) config.getSubsections("conditions").mapNotNull {
Conditions.compile(it, "Enchantment $id")
}.toSet()
}.toSet() else emptySet()
if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.$id") == null) {
val permission = Permission(
@@ -155,6 +157,21 @@ abstract class EcoEnchant(
}
}
private fun checkDependencies() {
val missingPlugins = mutableListOf<String>()
for (dependency in config.getStrings("dependencies")) {
if (!Bukkit.getPluginManager().plugins.map { it.name }.containsIgnoreCase(dependency)) {
missingPlugins += dependency
}
}
if (missingPlugins.isNotEmpty()) {
config.set("dont-register", true) // Just in case.
throw MissingDependencyException(missingPlugins)
}
}
private fun doOnInit() {
onInit()
}

View File

@@ -100,7 +100,15 @@ object EcoEnchants {
for ((id, config) in plugin.fetchConfigs("enchants")) {
if (config.has("effects")) {
LibReforgeEcoEnchant(id, config, plugin)
try {
LibReforgeEcoEnchant(
id,
config,
plugin
)
} catch (e: MissingDependencyException) {
promptPluginInstall(plugin, id, e.plugins.toMutableList())
}
}
}
@@ -170,7 +178,9 @@ object EcoEnchants {
}
/** Register the hardcoded enchantments. */
private fun registerHardcodedEnchantments(plugin: EcoEnchantsPlugin) {
private fun registerHardcodedEnchantments(
plugin: EcoEnchantsPlugin
) {
EnchantmentTelekinesis(plugin)
EnchantmentPermanenceCurse(plugin)
EnchantmentRepairing(plugin)

View File

@@ -6,7 +6,7 @@ import com.willfp.libreforge.Holder
import com.willfp.libreforge.conditions.ConfiguredCondition
import com.willfp.libreforge.effects.ConfiguredEffect
import com.willfp.libreforge.effects.Effects
import java.util.*
import java.util.Objects
class LibReforgeEcoEnchant(
id: String,
@@ -20,9 +20,9 @@ class LibReforgeEcoEnchant(
private val effects: Set<ConfiguredEffect>
init {
effects = config.getSubsections("effects").mapNotNull {
effects = if (plugin.isLoaded) config.getSubsections("effects").mapNotNull {
Effects.compile(it, "Enchantment $id")
}.toSet()
}.toSet() else emptySet()
}
override fun createLevel(level: Int): EcoEnchantLevel =

View File

@@ -0,0 +1,35 @@
package com.willfp.ecoenchants.enchants
import com.willfp.ecoenchants.EcoEnchantsPlugin
class MissingDependencyException(
val plugins: List<String>
) : Exception() {
override val message = "Missing the following plugins: ${plugins.joinToString(", ")}"
}
fun promptPluginInstall(plugin: EcoEnchantsPlugin, enchant: String, plugins: MutableList<String>) {
if (!plugin.isLoaded) {
return
}
val formatted = StringBuilder()
when (plugins.size) {
1 -> formatted.append(plugins.first())
2 -> formatted.append(plugins[0])
.append(" and ")
.append(plugins[1])
else -> {
val last = plugins.removeLast()
formatted.append(plugins.joinToString(", "))
.append(", and ")
.append(last)
}
}
plugin.logger.apply {
warning("Can't load the $enchant enchantment because you need $formatted installed")
warning("Either download $formatted or delete the folders with their names (/plugins/EcoEnchants/enchants/) to remove this message!")
}
}

View File

@@ -0,0 +1,27 @@
display-name: "Adrenaline"
description: "Gain strength for &a%placeholder%&r seconds when blocking hits"
placeholder: "1 + %level% / 2"
type: normal
targets:
- shield
conflicts: [ ]
rarity: epic
max-level: 3
tradeable: true
discoverable: true
enchantable: true
effects:
- id: potion_effect
args:
effect: increase_damage
level: 2
duration: "20 + 10 * %level%"
apply-to-player: true
cooldown: 10
triggers:
- shield_block
conditions: [ ]

View File

@@ -0,0 +1,23 @@
display-name: "Caffeinated"
description: "Gives a &a%placeholder%%&r bonus to attack speed while sprinting"
placeholder: "5 * %level%"
type: normal
targets:
- sword
conflicts: [ ]
rarity: rare
max-level: 3
tradeable: true
discoverable: true
enchantable: true
effects:
- id: attack_speed_multiplier
args:
multiplier: "1 + %level% * 0.05"
triggers: [ ]
conditions:
- id: is_sprinting

View File

@@ -0,0 +1,33 @@
display-name: "Contagion"
description: "Gives a &a%placeholder%%&r chance to spawn a cloud of poison around where your trident lands"
placeholder: "5 * %level%"
type: special
targets:
- trident
conflicts: [ ]
rarity: legendary
max-level: 2
tradeable: true
discoverable: true
enchantable: true
effects:
- id: spawn_potion_cloud
args:
effect: poison
level: 1
duration: 60
triggers:
- projectile_hit
- id: play_sound
args:
sound: entity_splash_potion_break
pitch: 0.7
volume: 1
triggers:
- projectile_hit
conditions: [ ]

View File

@@ -0,0 +1,44 @@
display-name: "Stimulating"
description: "Gives a &a%bonus%%&r to all stats for &a%seconds%%&r seconds"
placeholders:
bonus: "10 * %level%"
seconds: "3 * %level%"
type: spell
targets:
- sword
conflicts: [ ]
rarity: legendary
max-level: 2
tradeable: true
discoverable: true
enchantable: true
effects:
- effects:
- id: add_holder
args:
effects:
- id: multiply_all_stats
args:
multiplier: "1 + 0.1 * %level%"
conditions: [ ]
duration: "3 * %level% * 20"
- id: play_sound
args:
sound: entity_allay_death
pitch: 1.2
volume: 1
args:
cooldown: 180
send_cooldown_message: true
triggers:
- alt_click
conditions: [ ]
dependencies:
- EcoSkills

View File

@@ -0,0 +1,27 @@
display-name: "Vicious"
description: "Gives &a+%placeholder%&r %ecoskills_ferocity_name%"
placeholder: "5 + 5 * %level%"
type: spell
targets:
- sword
conflicts: [ ]
rarity: epic
max-level: 3
tradeable: true
discoverable: true
enchantable: true
effects:
- id: add_stat
args:
stat: ferocity
amount: "5 + 5 * %level%"
triggers:
- alt_click
conditions: [ ]
dependencies:
- EcoSkills

View File

@@ -0,0 +1,27 @@
display-name: "Escape"
description: "Gain a short burst of speed &a%placeholder%%&r after taking damage"
placeholder: "%level%"
type: normal
targets:
- boots
conflicts:
- streamlining
rarity: epic
max-level: 2
tradeable: true
discoverable: true
enchantable: true
effects:
- id: potion_effect
args:
effect: speed
level: "%level%"
duration: 30
apply_to_player: true
triggers:
- take_entity_damage
conditions: [ ]

View File

@@ -0,0 +1,25 @@
display-name: "Getaway"
description: "Gain a &a%placeholder%%&r bonus to movement speed below &a20%&r health"
placeholder: "%level%"
type: normal
targets:
- boots
conflicts: [ ]
rarity: rare
max-level: 2
tradeable: true
discoverable: true
enchantable: true
effects:
- id: movement_speed_multiplier
args:
multiplier: "1 + 0.1 * %level%"
triggers: [ ]
conditions:
- id: below_health_percent
args:
percent: 20

View File

@@ -0,0 +1,25 @@
display-name: "Haunting"
description: "Dying spawns a harming cloud for &a%placeholder%&r seconds"
placeholder: "1 + %level%"
type: normal
targets:
- helmet
conflicts: [ ]
rarity: epic
max-level: 2
tradeable: true
discoverable: true
enchantable: true
effects:
- id: spawn_potion_cloud
args:
effect: harm
level: 1
duration: "20 + %level% * 20"
triggers:
- death
conditions: [ ]

View File

@@ -0,0 +1,26 @@
display-name: "Ninja"
description: "Deal &a+%placeholder%&r damage while sneaking"
placeholder: "0.5 + %level% * 0.5"
type: normal
targets:
- sword
conflicts: [ ]
rarity: rare
max-level: 5
tradeable: true
discoverable: true
enchantable: true
effects:
- id: add_damage
args:
damage: "0.5 + %level% * 0.5"
triggers:
- melee_attack
conditions:
- id: is_sneaking
args:
is_sneaking: true

View File

@@ -0,0 +1,30 @@
display-name: "Poison Ivy"
description: "Poisons attackers for &a%seconds%&r seconds for each heart of damage dealt, up to &a%limit%&r seconds"
placeholders:
seconds: "0.5 * %level%"
limit: "4 + %level%"
type: normal
targets:
- leggings
conflicts:
- thorns
rarity: epic
max-level: 2
tradeable: true
discoverable: true
enchantable: true
effects:
- id: potion_effect
args:
effect: poison
level: 1
duration: "min(10 * %level% * %v% / 2, 80 + %level% * 20 * %v% / 2)"
apply_to_player: false
triggers:
- take_entity_damage
conditions: [ ]

View File

@@ -0,0 +1,23 @@
display-name: "Rebounding"
description: "Rebounds &a%placeholder%%&r of incoming damage back at your attacker"
placeholder: "20 + %level% * 10"
type: normal
targets:
- shield
conflicts: [ ]
rarity: epic
max-level: 3
tradeable: true
discoverable: true
enchantable: true
effects:
- id: damage_victim
args:
damage: "%v% * (0.2 + %level% * 0.1)"
triggers:
- shield_block
conditions: [ ]

View File

@@ -0,0 +1,26 @@
display-name: "Shura"
description: "Gives a &a%placeholder%x&r bonus to critical damage when under half health"
placeholder: "1 + 0.25 * %level%"
type: normal
targets:
- axe
conflicts: [ ]
rarity: rare
max-level: 2
tradeable: true
discoverable: true
enchantable: true
effects:
- id: crit_multiplier
args:
multiplier: "1 + 0.25 * %level%"
triggers:
- melee_attack
conditions:
- id: below_health_percent
args:
percent: 51

View File

@@ -0,0 +1,24 @@
display-name: "Warp Drive"
description: "Hitting your opponent with an arrow teleports you to them"
placeholder: "%level%"
type: special
targets:
- bow
conflicts: [ ]
rarity: veryspecial
max-level: 1
tradeable: true
discoverable: true
enchantable: true
effects:
- id: teleport
triggers:
- bow_attack
conditions: [ ]
mutators:
- id: location_to_victim

View File

@@ -0,0 +1,23 @@
display-name: "Wyvern"
description: "Gives a &a%placeholder%%&r bonus to melee damage"
placeholder: "10 * %level%"
type: normal
targets:
- elytra
conflicts: [ ]
rarity: epic
max-level: 2
tradeable: true
discoverable: true
enchantable: true
effects:
- id: damage_multiplier
args:
multiplier: "1 + (0.15 * %level%)"
triggers:
- melee_attack
conditions: [ ]