Skip to content

Commit

Permalink
Added HuskClaims antigrief support
Browse files Browse the repository at this point in the history
Added HuskTowns antigrief support
Added ItemBridge lookup support (`itembridge:key__id)
  • Loading branch information
0ft3n committed Jan 27, 2024
1 parent 6b46ea7 commit db41e11
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ allprojects {

// IridiumSkyblock
maven("https://nexus.iridiumdevelopment.net/repository/maven-releases/")

// HuskPlugins
maven("https://repo.william278.net/releases")
}

dependencies {
Expand Down
3 changes: 3 additions & 0 deletions eco-core/core-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ dependencies {
exclude(group = "*", module = "*")
}
compileOnly("com.iridium:IridiumSkyblock:4.0.8")
compileOnly("net.william278.huskclaims:huskclaims-bukkit:1.0.1")
compileOnly("net.william278:husktowns:2.6.1")
compileOnly("com.github.jojodmo:ItemBridge:b0054538c1")

compileOnly(fileTree("../../lib") {
include("*.jar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
IntegrationLoader("Kingdoms") { AntigriefManager.register(AntigriefKingdoms()) },
IntegrationLoader("RPGHorses") { AntigriefManager.register(AntigriefRPGHorses()) },
IntegrationLoader("CrashClaim") { AntigriefManager.register(AntigriefCrashClaim()) },
IntegrationLoader("HuskTowns") { AntigriefManager.register(AntigriefHuskTowns()) },
IntegrationLoader("HuskClaims") { AntigriefManager.register(AntigriefHuskClaims()) },
IntegrationLoader("CombatLogX") {
val pluginManager = Bukkit.getPluginManager()
val combatLogXPlugin = pluginManager.getPlugin("CombatLogX") ?: return@IntegrationLoader
Expand Down Expand Up @@ -283,6 +285,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
IntegrationLoader("MythicMobs") { CustomItemsManager.register(CustomItemsMythicMobs(this)) },
IntegrationLoader("Scyther") { CustomItemsManager.register(CustomItemsScyther()) },
IntegrationLoader("Denizen") { CustomItemsManager.register(CustomItemsDenizen()) },
IntegrationLoader("ItemBridge") { CustomItemsManager.register(CustomItemsItemBridge()) },

// Shop
IntegrationLoader("ShopGUIPlus") { ShopManager.register(ShopShopGuiPlus()) },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.willfp.eco.internal.spigot.integrations.antigrief

import com.willfp.eco.core.integrations.antigrief.AntigriefIntegration
import net.crashcraft.crashclaim.CrashClaim
import net.crashcraft.crashclaim.permissions.PermissionRoute
import net.william278.huskclaims.api.HuskClaimsAPI
import net.william278.huskclaims.libraries.cloplib.operation.Operation
import net.william278.huskclaims.libraries.cloplib.operation.OperationPosition
import net.william278.huskclaims.libraries.cloplib.operation.OperationType
import net.william278.huskclaims.position.Position
import net.william278.huskclaims.position.World
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Monster
import org.bukkit.entity.Player
import kotlin.jvm.optionals.getOrElse

class AntigriefHuskClaims : AntigriefIntegration {
override fun canBreakBlock(
player: Player,
block: Block
): Boolean {
val api = HuskClaimsAPI.getInstance() ?: return true

val user = api.getOnlineUser(player.uniqueId) ?: return true

return api.isOperationAllowed(
Operation.of(
user,
OperationType.BLOCK_BREAK,
Position.at(
block.x.toDouble(),
block.y.toDouble(),
block.z.toDouble(),
api.getWorld(block.location.world.name)
),
true
)
)
}

override fun canCreateExplosion(
player: Player,
location: Location
): Boolean {
val api = HuskClaimsAPI.getInstance() ?: return true

val user = api.getOnlineUser(player.uniqueId) ?: return true

return api.isOperationAllowed(
Operation.of(
user,
OperationType.EXPLOSION_DAMAGE_ENTITY,
Position.at(
location.x,
location.y,
location.z,
api.getWorld(location.world.name)
),
true
)
)
}

override fun canPlaceBlock(
player: Player,
block: Block
): Boolean {
val api = HuskClaimsAPI.getInstance() ?: return true

val user = api.getOnlineUser(player.uniqueId) ?: return true

return api.isOperationAllowed(
Operation.of(
user,
OperationType.BLOCK_PLACE,
Position.at(
block.x.toDouble(),
block.y.toDouble(),
block.z.toDouble(),
api.getWorld(block.location.world.name)
),
true
)
)
}

override fun canInjure(
player: Player,
victim: LivingEntity
): Boolean {
val api = HuskClaimsAPI.getInstance() ?: return true

val user = api.getOnlineUser(player.uniqueId) ?: return true

return api.isOperationAllowed(
Operation.of(
user,
when (victim) {
is Monster -> OperationType.PLAYER_DAMAGE_MONSTER
is Player -> OperationType.PLAYER_DAMAGE_PLAYER
else -> OperationType.PLAYER_DAMAGE_ENTITY
},
Position.at(
victim.x,
victim.y,
victim.z,
api.getWorld(victim.location.world.name)
),
true
)
)
}

override fun canPickupItem(player: Player, location: Location): Boolean {
return true
}

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

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

return other.pluginName == this.pluginName
}

override fun hashCode(): Int {
return this.pluginName.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.willfp.eco.internal.spigot.integrations.antigrief

import com.willfp.eco.core.integrations.antigrief.AntigriefIntegration
import net.william278.husktowns.api.HuskTownsAPI
import net.william278.husktowns.claim.Position
import net.william278.husktowns.listener.Operation
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Monster
import org.bukkit.entity.Player

class AntigriefHuskTowns : AntigriefIntegration {
override fun canBreakBlock(
player: Player,
block: Block
): Boolean {
val api = HuskTownsAPI.getInstance() ?: return true

val user = api.getOnlineUser(player) ?: return true

return api.isOperationAllowed(
Operation.of(
user,
Operation.Type.BLOCK_BREAK,
Position.at(
block.location.x,
block.location.y,
block.location.z,
api.getWorld(block.world)
),
true
)
)
}

override fun canCreateExplosion(
player: Player,
location: Location
): Boolean {
val api = HuskTownsAPI.getInstance() ?: return true

val user = api.getOnlineUser(player) ?: return true

return api.isOperationAllowed(
Operation.of(
user,
Operation.Type.EXPLOSION_DAMAGE_ENTITY,
Position.at(
location.x,
location.y,
location.z,
api.getWorld(location.world)
),
true
)
)
}

override fun canPlaceBlock(
player: Player,
block: Block
): Boolean {
val api = HuskTownsAPI.getInstance() ?: return true

val user = api.getOnlineUser(player) ?: return true

return api.isOperationAllowed(
Operation.of(
user,
Operation.Type.BLOCK_PLACE,
Position.at(
block.location.x,
block.location.y,
block.location.z,
api.getWorld(block.world)
),
true
)
)
}

override fun canInjure(
player: Player,
victim: LivingEntity
): Boolean {
val api = HuskTownsAPI.getInstance() ?: return true

val user = api.getOnlineUser(player) ?: return true

return api.isOperationAllowed(
Operation.of(
user,
when(victim) {
is Monster -> Operation.Type.PLAYER_DAMAGE_MONSTER
is Player -> Operation.Type.PLAYER_DAMAGE_PLAYER
else -> Operation.Type.PLACE_HANGING_ENTITY
},
Position.at(
player.location.x,
player.location.y,
player.location.z,
api.getWorld(player.world)
),
true
)
)
}

override fun canPickupItem(player: Player, location: Location): Boolean {
return true
}

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

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

return other.pluginName == this.pluginName
}

override fun hashCode(): Int {
return this.pluginName.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.willfp.eco.internal.spigot.integrations.customitems

import com.jojodmo.itembridge.ItemBridge
import com.willfp.eco.core.integrations.customitems.CustomItemsIntegration
import com.willfp.eco.core.items.CustomItem
import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.TestableItem
import com.willfp.eco.core.items.provider.ItemProvider
import com.willfp.eco.util.namespacedKeyOf
import org.bukkit.inventory.ItemStack

class CustomItemsItemBridge : CustomItemsIntegration {
override fun registerProvider() {
Items.registerItemProvider(ItemBridgeProvider())
}

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

private class ItemBridgeProvider : ItemProvider("itembridge") {
override fun provideForKey(key: String): TestableItem? {

val split = key.split(":").toMutableList()

if (split.size < 2) {
return null
}

val itemKey = split[0]

val item = split[1]

val stack = ItemBridge.getItemStack(itemKey, item) ?: kotlin.run {
return null
}

return CustomItem(
namespacedKeyOf("eco:${key.lowercase().replace(":", "__")}"),
{ test: ItemStack ->
ItemBridge.isItemStack(test, itemKey, item)
},
stack
)
}
}
}
3 changes: 3 additions & 0 deletions eco-core/core-plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ loadbefore:
- SCore
- ExecutableItems
softdepend:
- ItemBridge
- HuskClaims
- HuskTowns
- Terra
- ProtocolLib
- WorldGuard
Expand Down

0 comments on commit db41e11

Please sign in to comment.