-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HuskTowns antigrief support Added ItemBridge lookup support (`itembridge:key__id)
- Loading branch information
Showing
7 changed files
with
323 additions
and
0 deletions.
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
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
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
135 changes: 135 additions & 0 deletions
135
.../main/kotlin/com/willfp/eco/internal/spigot/integrations/antigrief/AntigriefHuskClaims.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,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() | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
...c/main/kotlin/com/willfp/eco/internal/spigot/integrations/antigrief/AntigriefHuskTowns.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,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() | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...n/kotlin/com/willfp/eco/internal/spigot/integrations/customitems/CustomItemsItemBridge.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,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 | ||
) | ||
} | ||
} | ||
} |
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