Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
DEV-2.0.8 // Added Lands Support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWylot committed Feb 16, 2023
1 parent 72efb96 commit b1a046c
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/main/java/ir/wy/wycore/spigot/support/protection/Lands.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ir.wy.wycore.spigot.support.protection

import ir.wy.wycore.WyCore
import ir.wy.wycore.behind.support.protection.ProtectionSupport
import me.angeschossen.lands.api.LandsIntegration
import me.angeschossen.lands.api.flags.type.Flags
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.block.Block
import org.bukkit.entity.Animals
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Monster
import org.bukkit.entity.Player


class Lands(private val plugin: WyCore) : ProtectionSupport {
private val landsIntegration = LandsIntegration.of(this.plugin)
override fun canBreakBlock(player: Player, block: Block): Boolean {
val area = landsIntegration.getArea(block.location) ?: return true
return area.hasRoleFlag(player, Flags.BLOCK_BREAK, block.type, false)
}

override fun canCreateExplosion(player: Player, location: Location): Boolean {
val area = landsIntegration.getArea(location) ?: return true
return area.hasRoleFlag(player, Flags.ATTACK_PLAYER, Material.AIR, false)
&& area.hasRoleFlag(player, Flags.ATTACK_ANIMAL, Material.AIR, false)
}

override fun canPlaceBlock(player: Player, block: Block): Boolean {
val area = landsIntegration.getArea(block.location) ?: return true
return area.hasRoleFlag(player, Flags.BLOCK_PLACE, Material.AIR, false)
}

override fun canInjure(player: Player, victim: LivingEntity): Boolean {
val area = landsIntegration.getArea(victim.location) ?: return true

return when(victim) {
is Player -> area.hasRoleFlag(player, Flags.ATTACK_PLAYER, Material.AIR, false)
is Monster -> area.hasRoleFlag(player, Flags.ATTACK_MONSTER, Material.AIR, false)
is Animals -> area.hasRoleFlag(player, Flags.ATTACK_ANIMAL, Material.AIR, false)
else -> area.isTrusted(player.uniqueId)
}
}

override fun getPluginName(): String {
return "Lands"
}

override fun canPickupItem(player: Player, location: Location): Boolean {
val area = landsIntegration.getArea(location) ?: return true
return area.hasRoleFlag(player, Flags.ITEM_PICKUP, Material.AIR, false)
}

override fun equals(other: Any?): Boolean {
if (other !is ProtectionSupport) {
return false
}

return other.pluginName == this.pluginName
}

override fun hashCode(): Int {
return this.pluginName.hashCode()
}
}

0 comments on commit b1a046c

Please sign in to comment.