-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
eco-api/src/main/kotlin/com/willfp/libreforge/effects/effects/EffectPermanentPotionEffect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.willfp.libreforge.effects.effects | ||
|
||
import com.willfp.eco.core.config.interfaces.JSONConfig | ||
import com.willfp.libreforge.ConfigViolation | ||
import com.willfp.libreforge.LibReforge | ||
import com.willfp.libreforge.effects.Effect | ||
import com.willfp.libreforge.effects.getEffectAmount | ||
import org.bukkit.entity.Player | ||
import org.bukkit.potion.PotionEffect | ||
import org.bukkit.potion.PotionEffectType | ||
import java.util.* | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
class EffectPermanentPotionEffect : Effect("permanent_potion_effect") { | ||
private val metaKey = "${LibReforge.plugin.name}_${this.id}" | ||
|
||
override fun handleEnable(player: Player, config: JSONConfig) { | ||
val effectType = PotionEffectType.getByName(config.getString("effect")) | ||
?: PotionEffectType.INCREASE_DAMAGE | ||
|
||
val effect = PotionEffect( | ||
effectType, | ||
1_500_000_000, | ||
config.getInt("level") - 1, | ||
false, | ||
false, | ||
true | ||
) | ||
|
||
player.addPotionEffect(effect) | ||
|
||
val meta = player.getMetadata(metaKey).firstOrNull()?.value() | ||
as? MutableMap<UUID, PotionEffectType> ?: mutableMapOf() | ||
|
||
meta[this.getUUID(player.getEffectAmount(this))] = effectType | ||
} | ||
|
||
override fun handleDisable(player: Player) { | ||
val meta = player.getMetadata(metaKey).firstOrNull()?.value() | ||
as? MutableMap<UUID, PotionEffectType> ?: mutableMapOf() | ||
|
||
val toRemove = meta[this.getUUID(player.getEffectAmount(this))] ?: return | ||
|
||
val active = player.getPotionEffect(toRemove) ?: return | ||
|
||
if (active.duration < 1_000_000_000) { | ||
return | ||
} | ||
|
||
player.removePotionEffect(toRemove) | ||
} | ||
|
||
override fun validateConfig(config: JSONConfig): List<ConfigViolation> { | ||
val violations = mutableListOf<ConfigViolation>() | ||
|
||
config.getStringOrNull("effect") | ||
?: violations.add( | ||
ConfigViolation( | ||
"effect", | ||
"You must specify the potion effect!" | ||
) | ||
) | ||
|
||
config.getIntOrNull("level") | ||
?: violations.add( | ||
ConfigViolation( | ||
"level", | ||
"You must specify the effect level!" | ||
) | ||
) | ||
|
||
return violations | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
eco-api/src/main/kotlin/com/willfp/libreforge/effects/effects/EffectPotionEffect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.willfp.libreforge.effects.effects | ||
|
||
import com.willfp.eco.core.config.interfaces.JSONConfig | ||
import com.willfp.libreforge.ConfigViolation | ||
import com.willfp.libreforge.effects.Effect | ||
import com.willfp.libreforge.triggers.TriggerData | ||
import com.willfp.libreforge.triggers.TriggerParameter | ||
import com.willfp.libreforge.triggers.Triggers | ||
import org.bukkit.potion.PotionEffect | ||
import org.bukkit.potion.PotionEffectType | ||
|
||
class EffectPotionEffect : Effect( | ||
"potion_effect", | ||
applicableTriggers = Triggers.withParameters( | ||
TriggerParameter.PLAYER, | ||
TriggerParameter.VICTIM | ||
) | ||
) { | ||
override fun handle(data: TriggerData, config: JSONConfig) { | ||
val toApply = if (config.getBool("apply_to_player")) { | ||
data.player ?: return | ||
} else { | ||
data.victim ?: return | ||
} | ||
|
||
toApply.addPotionEffect( | ||
PotionEffect( | ||
PotionEffectType.getByName(config.getString("effect")) | ||
?: PotionEffectType.INCREASE_DAMAGE, | ||
1_500_000_000, | ||
config.getInt("level") - 1, | ||
false, | ||
true, | ||
true | ||
) | ||
) | ||
} | ||
|
||
override fun validateConfig(config: JSONConfig): List<ConfigViolation> { | ||
val violations = mutableListOf<ConfigViolation>() | ||
|
||
config.getStringOrNull("effect") | ||
?: violations.add( | ||
ConfigViolation( | ||
"effect", | ||
"You must specify the potion effect!" | ||
) | ||
) | ||
|
||
config.getIntOrNull("level") | ||
?: violations.add( | ||
ConfigViolation( | ||
"level", | ||
"You must specify the effect level!" | ||
) | ||
) | ||
|
||
config.getIntOrNull("duration") | ||
?: violations.add( | ||
ConfigViolation( | ||
"duration", | ||
"You must specify the duration!" | ||
) | ||
) | ||
|
||
config.getBoolOrNull("apply_to_player") | ||
?: violations.add( | ||
ConfigViolation( | ||
"apply_to_player", | ||
"You must specify whether the player or victim gets the effect!" | ||
) | ||
) | ||
|
||
return violations | ||
} | ||
} |