Skip to content

Commit

Permalink
added restrictions on tnt, lava, fire
Browse files Browse the repository at this point in the history
  • Loading branch information
makeevrserg committed Apr 12, 2023
1 parent e31e9cb commit 1068dff
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,5 +25,6 @@ class EventHandler(
SortEvent(sortControllerDependency)
AutoCrop(pluginConfigDep)
TCEvent(pluginConfigDep)
RestrictionsEvent(pluginConfigDep)
}
}
Original file line number Diff line number Diff line change
@@ -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<PluginConfiguration>
) {
private val pluginConfiguration by pluginConfigurationModule
private val restrictions: PluginConfiguration.Restrictions
get() = pluginConfiguration.restrictions

// Explosions
val onBlockExplode = DSLEvent.event<BlockExplodeEvent> {
if (restrictions.explode) it.isCancelled = true
}
val onEntityExplode = DSLEvent.event<BlockExplodeEvent> {
if (!restrictions.explode) it.isCancelled = true
}
val onPrimeExplosion = DSLEvent.event<ExplosionPrimeEvent> {
if (!restrictions.explode) it.isCancelled = true
}

// Placing
val bucketEmptyEvent = DSLEvent.event<PlayerBucketEmptyEvent> {
when (it.bucket) {
Material.LAVA_BUCKET -> {
if (!restrictions.placeLava) it.isCancelled = true
}

else -> Unit
}
}
val blockPlace = DSLEvent.event<BlockPlaceEvent> {
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<BlockFromToEvent> {

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<BlockIgniteEvent> {
if (it.cause == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) return@event
if (!restrictions.spreadFire) it.isCancelled = true
}
val blockBurnEvent = DSLEvent.event<BlockBurnEvent> {
if (!restrictions.spreadFire) it.isCancelled = true
}
val blockSpread = DSLEvent.event<BlockSpreadEvent> {

when (it.source.type) {
Material.LAVA -> {
if (!restrictions.spreadLava) it.isCancelled = true
}

Material.FIRE -> {
if (!restrictions.spreadFire) it.isCancelled = true
}

else -> Unit
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 1068dff

Please sign in to comment.