Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.conditions.Condition
import org.bukkit.Material
import org.bukkit.block.BlockFace

object ConditionInAir : Condition<NoCompileData>("in_air") {
override fun isMet(
Expand All @@ -14,6 +16,6 @@ object ConditionInAir : Condition<NoCompileData>("in_air") {
compileData: NoCompileData
): Boolean {
val location = dispatcher.location ?: return false
return location.block.isEmpty
return location.block.getRelative(BlockFace.DOWN).type == Material.AIR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ object ConditionOnGround : Condition<NoCompileData>("on_ground") {
compileData: NoCompileData
): Boolean {
val location = dispatcher.location ?: return false
return location.block.getRelative(BlockFace.SOUTH).isSolid
return location.block.getRelative(BlockFace.DOWN).isSolid
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,39 @@ object EffectPermanentPotionEffect : Effect<NoCompileData>("permanent_potion_eff
val icon: Boolean
)

private fun getHolderData(player: Player): MutableMap<UUID, PotionEffectData> {
return player.getMetadata(metaKey).firstOrNull()?.value()
as? MutableMap<UUID, PotionEffectData>
?: mutableMapOf()
}

private fun refreshEffectsOfType(player: Player, type: PotionEffectType) {
player.removePotionEffect(type)
val active = getHolderData(player)
.values
.filter { it.effectType == type }
if (active.isEmpty()) return
val best = active.maxByOrNull { it.level }!!
val effect = PotionEffect(
type,
DURATION,
best.level,
false,
active.any { it.particles },
active.any { it.icon }
)
player.addPotionEffect(effect)
}

@EventHandler
fun onRespawn(event: PlayerRespawnEvent) {
val player = event.player
val types = getHolderData(player)
.values
.map { it.effectType }
.toSet()

val meta = player.getMetadata(metaKey).firstOrNull()?.value()
as? MutableMap<UUID, PotionEffectData> ?: mutableMapOf()

for ((_, data) in meta) {
val effect = PotionEffect(
data.effectType,
DURATION,
data.level,
false,
data.particles,
data.icon
)

player.addPotionEffect(effect)
}
types.forEach { refreshEffectsOfType(player, it) }
}

override fun onEnable(
Expand All @@ -82,42 +96,20 @@ object EffectPermanentPotionEffect : Effect<NoCompileData>("permanent_potion_eff
val icon = config.getBoolOrNull("icon") ?: true
val particles = config.getBoolOrNull("particles") ?: true

val effect = PotionEffect(
effectType,
DURATION,
level,
false,
particles,
icon
)

player.addPotionEffect(effect)

val meta = player.getMetadata(metaKey).firstOrNull()?.value()
as? MutableMap<UUID, PotionEffectData> ?: mutableMapOf()
val holderData = getHolderData(player)
holderData[identifiers.uuid] = PotionEffectData(effectType, level, particles, icon)
player.setMetadata(metaKey, plugin.metadataValueFactory.create(holderData))

meta[identifiers.uuid] = PotionEffectData(effectType, level, particles, icon)

player.setMetadata(metaKey, plugin.metadataValueFactory.create(meta))
refreshEffectsOfType(player, effectType)
}

override fun onDisable(dispatcher: Dispatcher<*>, identifiers: Identifiers, holder: ProvidedHolder) {
val player = dispatcher.get<Player>() ?: return

val meta = player.getMetadata(metaKey).firstOrNull()?.value()
as? MutableMap<UUID, PotionEffectData> ?: mutableMapOf()

val data = meta[identifiers.uuid] ?: return

val active = player.getPotionEffect(data.effectType) ?: return

if (active.duration < 0) {
return
}

meta.remove(identifiers.uuid)
player.setMetadata(metaKey, plugin.metadataValueFactory.create(meta))
val holderData = getHolderData(player)
val removed = holderData.remove(identifiers.uuid) ?: return
player.setMetadata(metaKey, plugin.metadataValueFactory.create(holderData))

player.removePotionEffect(data.effectType)
refreshEffectsOfType(player, removed.effectType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ object EffectSpawnPotionCloud : Effect<NoCompileData>("spawn_potion_cloud") {
)

cloud.source = data.player
cloud.duration = duration

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ object TriggerTakeDamage : Trigger("take_damage") {
if (Bukkit.getPluginManager().isPluginEnabled("MythicMobs")) {
if (event is EntityDamageByEntityEvent) {
val attacker = event.damager.tryAsLivingEntity()
if (MythicBukkit.inst().mobManager.isMythicMob(attacker)) {
return
if (attacker != null) {
if (MythicBukkit.inst().mobManager.isMythicMob(attacker)) {
return
}
}
}
}
Expand Down