Skip to content

Commit

Permalink
Add ability to buff exp
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie committed Nov 15, 2015
1 parent 746ad3f commit 271e7f6
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 13 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ age-cap:
buff:
drops: 0
shear-drops: 0
exp-multiplier: 1
disabled-items:
- 329

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>gg.obsidian</groupId>
<artifactId>MobControl</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<description>Control mob spawing and chunk limits</description>
<url>https://github.com/the-obsidian/MobControl</url>

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/gg/obsidian/mobcontrol/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int> = ArrayList<Int>()

var DEBUG: Boolean = false
Expand Down Expand Up @@ -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")
Expand Down
59 changes: 49 additions & 10 deletions src/main/kotlin/gg/obsidian/mobcontrol/MobControlListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand All @@ -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
}
}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ age-cap:
buff:
drops: 0
shear-drops: 0
exp-multiplier: 1
disabled-items:
- 329

Expand Down

0 comments on commit 271e7f6

Please sign in to comment.