diff --git a/build.gradle b/build.gradle index 85457c0..55d3fb3 100644 --- a/build.gradle +++ b/build.gradle @@ -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") diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt index d825a16..3c8accd 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt @@ -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) { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/protection/TownyIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/protection/TownyIntegration.kt new file mode 100644 index 0000000..d0154b4 --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/protection/TownyIntegration.kt @@ -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() { + + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt index 2f26747..a29c671 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionPlaceListener.kt @@ -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 } } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt index 667b9b5..0008c18 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minions.kt @@ -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() @@ -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 = pos.minions + val minionSize = minions.size + + for (j in 0..) -> Unit) { lock.read { minions(this.minions) diff --git a/common/src/main/resources/plugin.yml b/common/src/main/resources/plugin.yml index d9fca32..128bdcb 100644 --- a/common/src/main/resources/plugin.yml +++ b/common/src/main/resources/plugin.yml @@ -19,4 +19,5 @@ softdepend: - SuperiorSkyBlock2 - WorldGuard - PlotSquared - - KGenerators \ No newline at end of file + - KGenerators + - Towny \ No newline at end of file