This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from TheWylot/dev/v2.0.0
DEV-2.0.9 // Lands Support
- Loading branch information
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/ir/wy/wycore/spigot/support/protection/Lands.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |