Add Towny support, some minor optimizations

This commit is contained in:
TomTom 2024-03-09 16:25:36 +01:00
parent e11506e945
commit 6d25baa210
6 changed files with 84 additions and 14 deletions

View File

@ -100,6 +100,10 @@ allprojects {
maven {
url = uri("https://repo.artillex-studios.com/releases")
}
maven {
url = uri("https://repo.glaremasters.me/repository/towny")
}
}
dependencies {
@ -122,8 +126,9 @@ allprojects {
compileOnly 'com.intellectualsites.plotsquared:plotsquared-core:7.0.0-rc.4'
compileOnly 'com.intellectualsites.plotsquared:plotsquared-bukkit:7.0.0-rc.4'
compileOnly 'com.github.LoneDev6:api-itemsadder:3.6.1'
compileOnly 'com.palmergames.bukkit.towny:towny:0.100.1.0'
implementation platform('com.intellectualsites.bom:bom-newest:1.35')
implementation("com.artillexstudios.axapi:axapi:1.4.75")
implementation("com.artillexstudios.axapi:axapi:1.4.87")
implementation("net.byteflux:libby-bukkit:1.3.0")
implementation("com.zaxxer:HikariCP:5.1.0")
implementation("org.bstats:bstats-bukkit:3.0.2")

View File

@ -22,6 +22,7 @@ import com.artillexstudios.axminions.integrations.protection.IridiumSkyBlockInte
import com.artillexstudios.axminions.integrations.protection.KingdomsXIntegration
import com.artillexstudios.axminions.integrations.protection.LandsIntegration
import com.artillexstudios.axminions.integrations.protection.SuperiorSkyBlock2Integration
import com.artillexstudios.axminions.integrations.protection.TownyIntegration
import com.artillexstudios.axminions.integrations.protection.WorldGuardIntegration
import com.artillexstudios.axminions.integrations.stacker.DefaultStackerIntegration
import com.artillexstudios.axminions.integrations.stacker.RoseStackerIntegration
@ -96,9 +97,10 @@ class Integrations : Integrations {
}
"economyshopgui" -> {
if (isPluginLoaded("EconomyShopGUI") || isPluginLoaded("EconomyShopGUI-Premium")) {
if (Bukkit.getPluginManager().getPlugin("EconomyShopGUI") != null || Bukkit.getPluginManager().getPlugin("EconomyShopGUI-Premium") != null) {
register(EconomyShopGUIIntegration())
}
Bukkit.getConsoleSender()
.sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into EconomyShopGUI!"))}
}
}
@ -171,6 +173,16 @@ class Integrations : Integrations {
Bukkit.getConsoleSender()
.sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into ItemsAdder!"))
}
if (Bukkit.getPluginManager().getPlugin("ItemsAdder") != null) {
itemsAdderIntegration = true
Bukkit.getConsoleSender()
.sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into ItemsAdder!"))
}
if (Bukkit.getPluginManager().getPlugin("Towny") != null) {
register(TownyIntegration())
}
}
override fun register(integration: Integration) {

View File

@ -0,0 +1,19 @@
package com.artillexstudios.axminions.integrations.protection
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegration
import com.palmergames.bukkit.towny.`object`.TownyPermission
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.entity.Player
class TownyIntegration : ProtectionIntegration {
override fun canBuildAt(player: Player, location: Location): Boolean {
return PlayerCacheUtil.getCachePermission(player, location, Material.STONE, TownyPermission.ActionType.BUILD);
}
override fun register() {
}
}

View File

@ -27,15 +27,13 @@ class MinionPlaceListener : Listener {
fun onPlayerInteractEvent(event: PlayerInteractEvent) {
if (event.action != Action.RIGHT_CLICK_BLOCK && event.action != Action.RIGHT_CLICK_AIR) return
if (event.clickedBlock == null) return
if (event.item == null) return
if (!event.item!!.hasItemMeta()) return
val item = event.item ?: return
var meta = item.itemMeta ?: return
val type = event.item!!.itemMeta!!.persistentDataContainer.get(Keys.MINION_TYPE, PersistentDataType.STRING) ?: return
val minionType = MinionTypes.valueOf(type) ?: return
event.isCancelled = true
val item = event.item ?: return
var meta = item.itemMeta ?: return
if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) {
if (Config.DEBUG()) {
event.player.sendMessage(
@ -44,8 +42,10 @@ class MinionPlaceListener : Listener {
}
return
}
val level = meta.persistentDataContainer.get(Keys.LEVEL, PersistentDataType.INTEGER) ?: 0
val stats = meta.persistentDataContainer.get(Keys.STATISTICS, PersistentDataType.LONG) ?: 0
if (Config.PLACE_PERMISSION() && !event.player.hasPermission("axminions.place.${minionType.getName()}")) {
event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.PLACE_MISSING_PERMISSION()))
return
@ -59,6 +59,11 @@ class MinionPlaceListener : Listener {
val maxMinions = AxMinionsAPI.INSTANCE.getMinionLimit(event.player)
if (Minions.getMinionAt(location) != null) {
event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.PLACE_MINION_AT_LOCATION()))
return
}
val chunk = location.chunk
AxMinionsPlugin.dataQueue.submit {
val placed = AxMinionsPlugin.dataHandler.getMinionAmount(event.player.uniqueId)
@ -74,11 +79,6 @@ class MinionPlaceListener : Listener {
return@submit
}
if (AxMinionsPlugin.dataHandler.isMinion(location)) {
event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.PLACE_MINION_AT_LOCATION()))
return@submit
}
val locationId = AxMinionsPlugin.dataHandler.getLocationID(location)
val minion = Minion(
location,
@ -126,10 +126,12 @@ class MinionPlaceListener : Listener {
)
}
}
@EventHandler
fun onBlockPlace(event: BlockPlaceEvent) {
val blockLocation = event.block.location
if (AxMinionsPlugin.dataHandler.isMinion(blockLocation)) {
if (Minions.getMinionAt(blockLocation) != null) {
event.isCancelled = true
}
}

View File

@ -9,6 +9,7 @@ import kotlin.concurrent.write
import org.bukkit.Chunk
import org.bukkit.Location
object Minions {
internal val lock = ReentrantReadWriteLock()
internal val minions = arrayListOf<ChunkPos>()
@ -120,6 +121,36 @@ object Minions {
}
}
fun getMinionAt(location: Location): Minion? {
val world = location.world ?: return null
val worldUUID = world.uid
val x = Math.round(location.x).toInt() shr 4
val z = Math.round(location.z).toInt() shr 4
lock.read {
for (pos in minions) {
if (!pos.ticking) continue
if (pos.x == x && pos.z == z && pos.worldUUID == worldUUID) {
val minions: ArrayList<Minion> = pos.minions
val minionSize = minions.size
for (j in 0..<minionSize) {
val minion = minions[j]
if (minion.getLocation() != location) continue
return minion
}
return null
}
}
}
return null
}
internal inline fun get(minions: (ArrayList<ChunkPos>) -> Unit) {
lock.read {
minions(this.minions)

View File

@ -19,4 +19,5 @@ softdepend:
- SuperiorSkyBlock2
- WorldGuard
- PlotSquared
- KGenerators
- KGenerators
- Towny