9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-27 02:49:22 +00:00

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	build.gradle
This commit is contained in:
Auxilor
2022-01-18 08:27:53 +00:00
5 changed files with 192 additions and 9 deletions

View File

@@ -61,8 +61,8 @@ allprojects {
}
dependencies {
compileOnly 'io.auxilor:eco:6.18.1'
implementation 'com.willfp:libreforge:3.3.0'
compileOnly 'com.willfp:eco:6.20.0'
implementation 'com.willfp:libreforge:3.4.1'
compileOnly 'org.jetbrains:annotations:23.0.0'

View File

@@ -16,6 +16,7 @@ import com.willfp.ecoarmor.sets.ArmorUtils.setAdvanced
import com.willfp.ecoarmor.sets.ArmorUtils.setTier
import com.willfp.ecoarmor.upgrades.Tier
import com.willfp.ecoarmor.upgrades.Tiers
import com.willfp.ecoarmor.util.PlayableSound
import com.willfp.ecoarmor.util.notNullMapOf
import com.willfp.libreforge.Holder
import com.willfp.libreforge.conditions.Conditions
@@ -23,13 +24,14 @@ import com.willfp.libreforge.conditions.ConfiguredCondition
import com.willfp.libreforge.effects.ConfiguredEffect
import com.willfp.libreforge.effects.Effects
import org.bukkit.Bukkit
import org.bukkit.Sound
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataType
import java.util.*
import java.util.stream.Collectors
class ArmorSet(
private val config: Config,
val config: Config,
private val plugin: EcoPlugin
) {
/**
@@ -62,6 +64,39 @@ class ArmorSet(
*/
val advancementShardItem: ItemStack
/*
* Equip Sound
*/
val equipSound = if (config.getBool("sounds.equip.enabled")) {
PlayableSound(
Sound.valueOf(config.getString("sounds.equip.sound").uppercase()),
config.getDouble("sounds.equip.volume"),
config.getDouble("sounds.equip.pitch")
)
} else null
/*
* Advanced equip Sound
*/
val advancedEquipSound = if (config.getBool("sounds.equip.enabled")) {
PlayableSound(
Sound.valueOf(config.getString("sounds.equip.sound").uppercase()),
config.getDouble("sounds.equip.volume"),
config.getDouble("sounds.equip.pitch")
)
} else null
/*
* Unequip Sound
*/
val unequipSound = if (config.getBool("sounds.equip.enabled")) {
PlayableSound(
Sound.valueOf(config.getString("sounds.equip.sound").uppercase()),
config.getDouble("sounds.equip.volume"),
config.getDouble("sounds.equip.pitch")
)
} else null
/**
* Create a new Armor Set.
*/
@@ -132,7 +167,11 @@ class ArmorSet(
advanced: Boolean
): ItemStack {
val builder: ItemBuilder = ItemStackBuilder(Items.lookup(slotConfig.getString("item")).item)
.setDisplayName(if (advanced) slotConfig.getFormattedString("advancedName") else slotConfig.getFormattedString("name"))
.setDisplayName(
if (advanced) slotConfig.getFormattedString("advancedName") else slotConfig.getFormattedString(
"name"
)
)
.addLoreLines(slotConfig.getFormattedStrings("lore").stream().map { s: String -> Display.PREFIX + s }
.collect(Collectors.toList()))
.addLoreLines {
@@ -144,7 +183,11 @@ class ArmorSet(
return@addLoreLines null
}
}
.setDisplayName { if (advanced) slotConfig.getFormattedString("advancedName") else slotConfig.getFormattedString("name") }
.setDisplayName {
if (advanced) slotConfig.getFormattedString("advancedName") else slotConfig.getFormattedString(
"name"
)
}
builder.writeMetaKey(
plugin.namespacedKeyFactory.create("set"),
PersistentDataType.STRING,

View File

@@ -1,15 +1,79 @@
package com.willfp.ecoarmor.util
import com.willfp.eco.core.events.ArmorChangeEvent
import com.willfp.ecoarmor.sets.ArmorSet
import com.willfp.ecoarmor.sets.ArmorUtils
import com.willfp.libreforge.updateEffects
import org.bukkit.Material
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.inventory.ItemStack
class EffectListener: Listener {
class EffectListener : Listener {
@EventHandler
fun armorEquipListener(event: ArmorChangeEvent) {
val player = event.player
player.updateEffects()
}
}
@EventHandler
fun handleSounds(event: ArmorChangeEvent) {
val player = event.player
val new = getSetOnItems(event.after) ?: return
val newAdvanced = isAdvanced(event.after)
val prev = getSetOnItems(event.before)
val prevAdvanced = isAdvanced(event.before)
if (new == prev && newAdvanced == prevAdvanced) {
return
}
if (new == prev) {
if (newAdvanced && !prevAdvanced) {
new.advancedEquipSound?.play(player)
}
} else {
prev?.unequipSound?.play(player)
if (newAdvanced) {
new.advancedEquipSound?.play(player)
} else {
new.equipSound?.play(player)
}
}
}
private fun getSetOnItems(items: List<ItemStack?>): ArmorSet? {
var set: ArmorSet? = null
for (item in items) {
if (item == null || item.type == Material.AIR) {
return null
}
val found = ArmorUtils.getSetOnItem(item) ?: return null
if (set != null && set != found) {
return null
}
set = found
}
return set
}
private fun isAdvanced(items: List<ItemStack?>): Boolean {
for (item in items) {
if (item == null) {
return false
}
if (!ArmorUtils.isAdvanced(item)) {
return false
}
}
return true
}
}

View File

@@ -0,0 +1,14 @@
package com.willfp.ecoarmor.util
import org.bukkit.Sound
import org.bukkit.entity.Player
class PlayableSound(
private val sound: Sound,
private val pitch: Double,
val volume: Double
) {
fun play(player: Player) {
player.playSound(player.location, sound, volume.toFloat(), pitch.toFloat())
}
}

View File

@@ -22,6 +22,22 @@ sets:
multiplier: 0.9
triggers:
- take_damage
sounds:
equip:
enabled: false
sound: ""
volume: 1
pitch: 1
advancedEquip:
enabled: false
sound: ""
volume: 1
pitch: 1
unequip:
enabled: false
sound: ""
volume: 1
pitch: 1
advancedLore:
- ''
- "<gradient:f12711>&lADVANCED BONUS</gradient:f5af19>"
@@ -196,6 +212,22 @@ sets:
- trident_attack
filters:
onlyBosses: true
sounds:
equip:
enabled: false
sound: ""
volume: 1
pitch: 1
advancedEquip:
enabled: false
sound: ""
volume: 1
pitch: 1
unequip:
enabled: false
sound: ""
volume: 1
pitch: 1
advancedLore:
- ''
- "<gradient:f12711>&lADVANCED BONUS</gradient:f5af19>"
@@ -371,6 +403,22 @@ sets:
args:
effect: regeneration
level: 1
sounds:
equip:
enabled: false
sound: ""
volume: 1
pitch: 1
advancedEquip:
enabled: false
sound: ""
volume: 1
pitch: 1
unequip:
enabled: false
sound: ""
volume: 1
pitch: 1
advancedLore:
- ''
- "<gradient:f12711>&lADVANCED BONUS</gradient:f5af19>"
@@ -553,8 +601,22 @@ sets:
multiplier: 1.75
triggers:
- bow_attack
potionEffects: []
advancedPotionEffects: []
sounds:
equip:
enabled: false
sound: ""
volume: 1
pitch: 1
advancedEquip:
enabled: false
sound: ""
volume: 1
pitch: 1
unequip:
enabled: false
sound: ""
volume: 1
pitch: 1
advancedLore:
- ''
- "<gradient:f12711>&lADVANCED BONUS</gradient:f5af19>"