Commit 0fe8d2ee authored by Linus K.'s avatar Linus K.
Browse files

Make cat anger everyone to get killed

parent 16ff40ff
Pipeline #129 passed with stage
in 54 seconds
......@@ -52,10 +52,12 @@ class Plugin: JavaPlugin() {
val pm = Bukkit.getPluginManager()
pm.registerEvents(AutoFarmerListener(), this)
pm.registerEvents(ColoredSignsListener(), this)
pm.registerEvents(KillCatsListener(), this)
}
fun registerSchedulers() {
AutoFarmerListener.initScheduler(this)
KillCatsListener.initializeScheduler(this)
}
override fun onDisable() {
......
package me.linuscde.mcplugins.autosyston.listeners
import me.linuscde.mcplugins.autosyston.Plugin
import org.bukkit.Bukkit
import org.bukkit.entity.*
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageByEntityEvent
class KillCatsListener: Listener {
companion object {
val CAT_KILLERS = arrayOf(
EntityType.ZOMBIE,
EntityType.ZOMBIE_VILLAGER,
EntityType.SKELETON,
EntityType.IRON_GOLEM,
EntityType.WOLF,
EntityType.BEE,
EntityType.CAVE_SPIDER,
EntityType.SPIDER,
EntityType.ENDERMAN,
EntityType.HUSK
)
private fun isTargeted(cat: Cat) = cat.world.entities.any { it is Creature && it.target == cat }
fun initializeScheduler(plugin: org.bukkit.plugin.Plugin) {
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, {
Bukkit.getWorlds()
.flatMap { it.entities }
.filterIsInstance<Cat>()
.filter { ! it.isTamed }
.filter { ! isTargeted(it) }
.forEach { cat ->
Bukkit.broadcastMessage("POSSIBLE CAT")
val newKiller = cat.world.entities
.asSequence()
.filterIsInstance<Creature>()
.filter { it.type in CAT_KILLERS }
.filter { it.location.distance(cat.location) < 25.0 }
.minBy { it.location.distance(cat.location) }
if(newKiller != null) {
Bukkit.broadcastMessage("ATTACK CAT")
val oldHealth = newKiller.health
cat.attack(newKiller)
newKiller.health = oldHealth
}
}
}, 40, 40)
}
}
@EventHandler
fun onDamage(e: EntityDamageByEntityEvent) {
val damager = e.damager
if(damager is Bee && e.entity is Cat) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Plugin.instance, {
if(!damager.isDead) damager.setHasStung(false)
}, 20*3)
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte Frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close