Implement landmine-specific tracking for manager

This commit is contained in:
Gabriel Tofvesson 2021-09-15 23:15:58 +02:00
parent 54a8ad9e03
commit 74d99b6c3d
2 changed files with 11 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.OfflinePlayer
import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.enchantments.Enchantment
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.HandlerList
@ -31,6 +32,7 @@ private val threadLocalBuffer = ThreadLocal.withInitial { ByteBuffer.allocate(16
class LandmineManager(
private val plugin: Plugin,
private val enchantment: Enchantment,
private val landmineData: YamlFile
): Listener {
private var landmines: SortedList<LandmineData> = SortedList.create(comparator = LANDMINE_COMPARATOR)
@ -174,10 +176,11 @@ class LandmineManager(
@EventHandler(priority = EventPriority.HIGHEST)
fun onPlayerPlaceMine(placeEvent: BlockPlaceEvent) {
if (placeEvent.blockPlaced.type == Material.STONE_PRESSURE_PLATE && !placeEvent.isCancelled) {
if (placeMine(placeEvent.player, placeEvent.blockPlaced.location)) {
if (placeEvent.blockPlaced.type == Material.STONE_PRESSURE_PLATE &&
placeEvent.itemInHand.itemMeta?.enchants?.contains(enchantment) == true &&
!placeEvent.isCancelled) {
if (placeMine(placeEvent.player, placeEvent.blockPlaced.location))
--placeEvent.player.inventory.getItem(placeEvent.hand).amount
}
placeEvent.isCancelled = true
}

View File

@ -52,7 +52,11 @@ class LandminePlugin: JavaPlugin() {
stack.itemMeta = meta
saveDefaultConfig()
landmineManager = LandmineManager(this, YamlFile(File(dataFolder, "data.yml")))
landmineManager = LandmineManager(
this,
enchantment,
YamlFile(File(dataFolder, "data.yml"))
)
landmineManager!!.onEnable()
Bukkit.addRecipe(ShapelessRecipe(recipeKey, stack).addIngredient(Material.STONE_PRESSURE_PLATE).addIngredient(Material.TNT))