From 1068dffb8eaa01b5ecc8fb75e3855659a6cbc087 Mon Sep 17 00:00:00 2001 From: makeevrserg Date: Wed, 12 Apr 2023 09:59:58 +0300 Subject: [PATCH] added restrictions on tnt, lava, fire --- gradle/libs.versions.toml | 2 +- .../aspekt/events/EventHandler.kt | 2 + .../events/restrictions/RestrictionsEvent.kt | 98 +++++++++++++++++++ .../aspekt/events/sort/SortEvent.kt | 2 + .../aspekt/plugin/PluginConfiguration.kt | 10 ++ plugin/src/main/resources/config.yml | 12 ++- 6 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/restrictions/RestrictionsEvent.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f557ded..2b39480 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] # Plugin/Mod core -plugin = "2.1.3" +plugin = "2.1.4" name = "AspeKt" group = "com.astrainteractive" description = "Essentials plugin for EmpireProjekt" diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/EventHandler.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/EventHandler.kt index 34323f4..af07712 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/EventHandler.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/EventHandler.kt @@ -1,6 +1,7 @@ package ru.astrainteractive.aspekt.events import ru.astrainteractive.aspekt.events.crop.AutoCrop +import ru.astrainteractive.aspekt.events.restrictions.RestrictionsEvent import ru.astrainteractive.aspekt.events.sit.SitController import ru.astrainteractive.aspekt.events.sit.SitEvent import ru.astrainteractive.aspekt.events.sort.SortController @@ -24,5 +25,6 @@ class EventHandler( SortEvent(sortControllerDependency) AutoCrop(pluginConfigDep) TCEvent(pluginConfigDep) + RestrictionsEvent(pluginConfigDep) } } diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/restrictions/RestrictionsEvent.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/restrictions/RestrictionsEvent.kt new file mode 100644 index 0000000..0ab9259 --- /dev/null +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/restrictions/RestrictionsEvent.kt @@ -0,0 +1,98 @@ +package ru.astrainteractive.aspekt.events.restrictions + +import org.bukkit.Material +import org.bukkit.event.block.BlockBurnEvent +import org.bukkit.event.block.BlockExplodeEvent +import org.bukkit.event.block.BlockFromToEvent +import org.bukkit.event.block.BlockIgniteEvent +import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.block.BlockSpreadEvent +import org.bukkit.event.entity.ExplosionPrimeEvent +import org.bukkit.event.player.PlayerBucketEmptyEvent +import ru.astrainteractive.aspekt.plugin.PluginConfiguration +import ru.astrainteractive.astralibs.di.Dependency +import ru.astrainteractive.astralibs.di.Module +import ru.astrainteractive.astralibs.di.getValue +import ru.astrainteractive.astralibs.events.DSLEvent + +class RestrictionsEvent( + pluginConfigurationModule: Dependency +) { + private val pluginConfiguration by pluginConfigurationModule + private val restrictions: PluginConfiguration.Restrictions + get() = pluginConfiguration.restrictions + + // Explosions + val onBlockExplode = DSLEvent.event { + if (restrictions.explode) it.isCancelled = true + } + val onEntityExplode = DSLEvent.event { + if (!restrictions.explode) it.isCancelled = true + } + val onPrimeExplosion = DSLEvent.event { + if (!restrictions.explode) it.isCancelled = true + } + + // Placing + val bucketEmptyEvent = DSLEvent.event { + when (it.bucket) { + Material.LAVA_BUCKET -> { + if (!restrictions.placeLava) it.isCancelled = true + } + + else -> Unit + } + } + val blockPlace = DSLEvent.event { + when (it.blockPlaced.type) { + Material.TNT -> { + if (!restrictions.placeTnt) it.isCancelled = true + } + + Material.LAVA -> { + if (!restrictions.placeLava) it.isCancelled = true + } + + Material.LAVA_BUCKET -> { + if (!restrictions.placeLava) it.isCancelled = true + } + + else -> Unit + } + } + val blockFromTo = DSLEvent.event { + + when (it.block.type){ + Material.LAVA -> { + if (!restrictions.spreadLava) it.isCancelled = true + } + + Material.FIRE -> { + if (!restrictions.spreadFire) it.isCancelled = true + } + + else -> Unit + } + } + val blockIgniteEvent = DSLEvent.event { + if (it.cause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) return@event + if (!restrictions.spreadFire) it.isCancelled = true + } + val blockBurnEvent = DSLEvent.event { + if (!restrictions.spreadFire) it.isCancelled = true + } + val blockSpread = DSLEvent.event { + + when (it.source.type) { + Material.LAVA -> { + if (!restrictions.spreadLava) it.isCancelled = true + } + + Material.FIRE -> { + if (!restrictions.spreadFire) it.isCancelled = true + } + + else -> Unit + } + } +} \ No newline at end of file diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/sort/SortEvent.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/sort/SortEvent.kt index 35a3193..86fe902 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/sort/SortEvent.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/events/sort/SortEvent.kt @@ -1,6 +1,8 @@ package ru.astrainteractive.aspekt.events.sort +import org.bukkit.Material import org.bukkit.entity.Player +import org.bukkit.event.block.BlockPlaceEvent import org.bukkit.event.inventory.ClickType import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.player.PlayerJoinEvent diff --git a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginConfiguration.kt b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginConfiguration.kt index e70e4d5..25bede3 100644 --- a/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginConfiguration.kt +++ b/plugin/src/main/kotlin/ru/astrainteractive/aspekt/plugin/PluginConfiguration.kt @@ -13,6 +13,16 @@ class PluginConfiguration(private val fc: FileConfiguration) { val announcements = Announcements() val autoCrop = AutoCrop() val tc = TC() + val restrictions = Restrictions() + + inner class Restrictions { + private val PATH: String = "core.restrictions" + val placeTnt by fc.cBoolean("$PATH.place.tnt", false) + val explode by fc.cBoolean("$PATH.explode", false) + val placeLava by fc.cBoolean("$PATH.place.lava", false) + val spreadLava by fc.cBoolean("$PATH.spread.lava", false) + val spreadFire by fc.cBoolean("$PATH.spread.fire", false) + } inner class TC { private val PATH: String = "core.tree_capitator" diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index e70eba7..3f24c88 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -1,12 +1,20 @@ core: sit: true + restrictions: + explode: false + place: + tnt: false + lava: false + spread: + lava: false + fire: false tree_capitator: enabled: true - destroy_limit: 16 + destroy_limit: 32 damage_axe: true break_axe: true replant: true - replant_max_iterations: 10 + replant_max_iterations: 32 destroy_leaves: true auto_crop: enabled: true