Skip to content

Commit

Permalink
Damage animals & monster spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxLlN authored Aug 14, 2024
1 parent cb13a14 commit a08c41e
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 68 deletions.
69 changes: 69 additions & 0 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermDamageAnimals.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.mcstarrysky.land.flag

import com.mcstarrysky.land.data.Land
import com.mcstarrysky.land.manager.LandManager
import com.mcstarrysky.land.util.display
import com.mcstarrysky.land.util.prettyInfo
import com.mcstarrysky.land.util.registerPermission
import org.bukkit.entity.Animals
import org.bukkit.entity.Player
import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.ItemStack
import taboolib.internal.xseries.XMaterial
import taboolib.util.item.ItemBuilder

/**
* Land
* com.mcstarrysky.land.flag.PermDamageAnimals
*
* @author HXS
* @since 2024/8/14 13:57
*/
object PermDamageAnimals : Permission {

@Awake(LifeCycle.ENABLE)
private fun init() {
registerPermission()
}

override val id: String
get() = "damage_animals"

override val default: Boolean
get() = false

override val worldSide: Boolean
get() = true

override val playerSide: Boolean
get() = true

override fun generateMenuItem(land: Land): ItemStack {
return ItemBuilder(XMaterial.IRON_SWORD){
name = "&f攻击动物 ${land.getFlagOrNull(id).display}"
lore += listOf(
"&7允许行为:",
"&8对动物 (Animals) 造成伤害"
"",
"&e左键修改值, 右键取消设置"
)
flags += ItemFlag.values().toList()
if (land.getFlagOrNull(id) == true) shiny()
colored()
}
}

@SubscribeEvent(ignoreCancelled = true)
fun e(e: EntityDamageByEntityEvent) {
if (e.entity is Animals) {
val player = e.damager as? Player ?: return
LandManager.getLand(e.inventory.location ?: return)?.run {
if (!hasPermission(e.player) && !getFlag(this@PermDamageAnimals.id)) {
e.isCancelled = true
e.player.prettyInfo("没有权限, 禁止攻击动物&7\\(标记: ${this@PermDamageAnimals.id}\\)")
}
}
}
}
}
136 changes: 68 additions & 68 deletions src/main/kotlin/com/mcstarrysky/land/flag/PermMobSpawn.kt
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
package com.mcstarrysky.land.flag

import com.mcstarrysky.land.data.Land
import com.mcstarrysky.land.manager.LandManager
import com.mcstarrysky.land.util.display
import com.mcstarrysky.land.util.registerPermission
import org.bukkit.entity.Mob
import org.bukkit.event.entity.EntitySpawnEvent
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.ItemStack
import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.xseries.XMaterial
import taboolib.platform.util.buildItem

/**
* Land
* com.mcstarrysky.land.flag.PermMobSpawn
*
* @author mical
* @since 2024/8/3 17:23
*/
object PermMobSpawn : Permission {

@Awake(LifeCycle.ENABLE)
private fun init() {
registerPermission()
}

override val id: String
get() = "mob_spawn"

override val default: Boolean
get() = true

override val worldSide: Boolean
get() = true

override val playerSide: Boolean
get() = true

override fun generateMenuItem(land: Land): ItemStack {
return buildItem(XMaterial.ZOMBIE_SPAWN_EGG) {
name = "&f怪物产生 ${land.getFlagOrNull(id).display}"
lore += listOf(
"&7允许行为:",
"&8生成怪物",
"",
"&e左键修改值, 右键取消设置"
)
flags += ItemFlag.values().toList()
if (land.getFlagOrNull(id) == true) shiny()
colored()
}
}

@SubscribeEvent(ignoreCancelled = true)
fun e(e: EntitySpawnEvent) {
if (e.entity !is Mob){
return
}
LandManager.getLand(e.entity.location)?.run {
if (!getFlag(this@PermMobSpawn.id)) {
e.isCancelled = true
}
}
}
package com.mcstarrysky.land.flag

import com.mcstarrysky.land.data.Land
import com.mcstarrysky.land.manager.LandManager
import com.mcstarrysky.land.util.display
import com.mcstarrysky.land.util.registerPermission
import org.bukkit.entity.Mob
import org.bukkit.entity.Monster
import org.bukkit.event.entity.EntitySpawnEvent
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.ItemStack
import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.xseries.XMaterial
import taboolib.platform.util.buildItem

/**
* Land
* com.mcstarrysky.land.flag.PermMobSpawn
*
* @author mical
* @since 2024/8/3 17:23
*/
object PermMobSpawn : Permission {

@Awake(LifeCycle.ENABLE)
private fun init() {
registerPermission()
}

override val id: String
get() = "mob_spawn"

override val default: Boolean
get() = true

override val worldSide: Boolean
get() = true

override val playerSide: Boolean
get() = true

override fun generateMenuItem(land: Land): ItemStack {
return buildItem(XMaterial.ZOMBIE_SPAWN_EGG) {
name = "&f怪物产生 ${land.getFlagOrNull(id).display}"
lore += listOf(
"&7允许行为:",
"&8生成怪物",
"",
"&e左键修改值, 右键取消设置"
)
flags += ItemFlag.values().toList()
if (land.getFlagOrNull(id) == true) shiny()
colored()
}
}

@SubscribeEvent(ignoreCancelled = true)
fun e(e: EntitySpawnEvent) {
if (e.entity is Monster) {
LandManager.getLand(e.entity.location)?.run {
if (!getFlag(this@PermMobSpawn.id)) {
e.isCancelled = true
}
}
}
}
}

0 comments on commit a08c41e

Please sign in to comment.