From 271e7f658eadae84c7a44ad7c35f023d5348f9e9 Mon Sep 17 00:00:00 2001 From: Jacob Gillespie Date: Sun, 15 Nov 2015 11:03:53 -0600 Subject: [PATCH] Add ability to buff exp --- README.md | 12 +++- pom.xml | 2 +- .../gg/obsidian/mobcontrol/Configuration.kt | 2 + .../obsidian/mobcontrol/MobControlListener.kt | 59 +++++++++++++++---- src/main/resources/config.yml | 1 + 5 files changed, 63 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 626476b..c60b53b 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ age-cap: buff: drops: 0 shear-drops: 0 + exp-multiplier: 1 disabled-items: - 329 @@ -85,7 +86,14 @@ settings: ## Features * Limits mobs per chunk +* Buffs drops and exp -## Upcoming Features +## Changelog -* Better mob XP drop adjustments +### 1.1.0 + +* Added ability to buff exp + +### 1.0.0 + +* Initial version diff --git a/pom.xml b/pom.xml index 453a846..24eabc1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ gg.obsidian MobControl - 1.0.0 + 1.1.0 Control mob spawing and chunk limits https://github.com/the-obsidian/MobControl diff --git a/src/main/kotlin/gg/obsidian/mobcontrol/Configuration.kt b/src/main/kotlin/gg/obsidian/mobcontrol/Configuration.kt index 84cfd7b..e94592a 100644 --- a/src/main/kotlin/gg/obsidian/mobcontrol/Configuration.kt +++ b/src/main/kotlin/gg/obsidian/mobcontrol/Configuration.kt @@ -16,6 +16,7 @@ class Configuration(val plugin: MobControl) { var LIMIT_SPAWNER_SPAWN: Boolean = false var BUFF_DROPS: Int = 0 var BUFF_SHEAR_DROPS: Int = 0 + var BUFF_EXP_MULTIPLIER: Int = 1 var BUFF_DISABLED_ITEMS: List = ArrayList() var DEBUG: Boolean = false @@ -55,6 +56,7 @@ class Configuration(val plugin: MobControl) { LIMIT_SPAWNER_SPAWN = plugin.getConfig().getBoolean("settings.limit-spawner-spawn") BUFF_DROPS = plugin.getConfig().getInt("buff.drops") BUFF_SHEAR_DROPS = plugin.getConfig().getInt("buff.shear-drops") + BUFF_EXP_MULTIPLIER = plugin.getConfig().getInt("buff.exp-multiplier", 1) BUFF_DISABLED_ITEMS = plugin.getConfig().getIntegerList("buff.disabled-items") DEBUG = plugin.getConfig().getBoolean("settings.debug") diff --git a/src/main/kotlin/gg/obsidian/mobcontrol/MobControlListener.kt b/src/main/kotlin/gg/obsidian/mobcontrol/MobControlListener.kt index 6f06668..aa7e3cb 100644 --- a/src/main/kotlin/gg/obsidian/mobcontrol/MobControlListener.kt +++ b/src/main/kotlin/gg/obsidian/mobcontrol/MobControlListener.kt @@ -2,12 +2,13 @@ package gg.obsidian.mobcontrol import org.bukkit.Material import org.bukkit.entity.Ageable +import org.bukkit.entity.Player +import org.bukkit.entity.Projectile import org.bukkit.entity.Sheep import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener -import org.bukkit.event.entity.CreatureSpawnEvent -import org.bukkit.event.entity.EntityDeathEvent +import org.bukkit.event.entity.* import org.bukkit.event.world.ChunkUnloadEvent import org.bukkit.inventory.ItemStack @@ -25,6 +26,24 @@ class MobControlListener(private val plugin: MobControl) : Listener { @EventHandler(priority = EventPriority.MONITOR) fun onEntityDeath(event: EntityDeathEvent) { + handleBuffDrops(event) + handleBuffExp(event) + } + + @EventHandler(priority = EventPriority.MONITOR) + fun onPlayerShearEvent(event: EntityDeathEvent) { + if (plugin.config.BUFF_SHEAR_DROPS <= 1 || event.entity !is Sheep) { + return + } + + val entity = event.entity as Sheep + val l = entity.location + + val count = (1 + (3 * Math.random()).toInt()) * (plugin.config.BUFF_SHEAR_DROPS - 1) + l.world.dropItemNaturally(l, ItemStack(Material.WOOL, count, entity.color.ordinal.toByte().toShort())) + } + + private fun handleBuffDrops(event: EntityDeathEvent) { if (plugin.config.BUFF_DROPS <= 1 || event.entity !is Ageable) { return } @@ -43,16 +62,36 @@ class MobControlListener(private val plugin: MobControl) : Listener { } } - @EventHandler(priority = EventPriority.MONITOR) - fun onPlayerShearEvent(event: EntityDeathEvent) { - if (plugin.config.BUFF_SHEAR_DROPS <= 1 || event.entity !is Sheep) { - return + private fun handleBuffExp(event: EntityDeathEvent) { + val target = event.entity + val attacker = getAttacker(target.lastDamageCause) + val xp = event.droppedExp + + if (event is PlayerDeathEvent) return + if (attacker == null) return + + handleMonsterDeath(event, xp) + } + + private fun handleMonsterDeath(event: EntityDeathEvent, exp: Int) { + if (plugin.config.BUFF_EXP_MULTIPLIER > 0) { + event.droppedExp = exp * plugin.config.BUFF_EXP_MULTIPLIER + } + } + + private fun getAttacker(attacker: EntityDamageEvent?): Player? { + if (attacker == null || attacker !is EntityDamageByEntityEvent) { + return null } - val entity = event.entity as Sheep - val l = entity.location + val damager = attacker.damager - val count = (1 + (3 * Math.random()).toInt()) * (plugin.config.BUFF_SHEAR_DROPS - 1) - l.world.dropItemNaturally(l, ItemStack(Material.WOOL, count, entity.color.ordinal.toByte().toShort())) + if (damager is Projectile && damager.shooter is Player) { + return damager.shooter as Player + } else if (damager is Player) { + return damager + } + + return null } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 660662a..b074eb0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -5,6 +5,7 @@ age-cap: buff: drops: 0 shear-drops: 0 + exp-multiplier: 1 disabled-items: - 329