Implement landmine-specific tracking for manager
This commit is contained in:
parent
54a8ad9e03
commit
74d99b6c3d
@ -4,6 +4,7 @@ import org.bukkit.Location
|
|||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.OfflinePlayer
|
import org.bukkit.OfflinePlayer
|
||||||
import org.bukkit.configuration.file.FileConfiguration
|
import org.bukkit.configuration.file.FileConfiguration
|
||||||
|
import org.bukkit.enchantments.Enchantment
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
import org.bukkit.event.EventPriority
|
import org.bukkit.event.EventPriority
|
||||||
import org.bukkit.event.HandlerList
|
import org.bukkit.event.HandlerList
|
||||||
@ -31,6 +32,7 @@ private val threadLocalBuffer = ThreadLocal.withInitial { ByteBuffer.allocate(16
|
|||||||
|
|
||||||
class LandmineManager(
|
class LandmineManager(
|
||||||
private val plugin: Plugin,
|
private val plugin: Plugin,
|
||||||
|
private val enchantment: Enchantment,
|
||||||
private val landmineData: YamlFile
|
private val landmineData: YamlFile
|
||||||
): Listener {
|
): Listener {
|
||||||
private var landmines: SortedList<LandmineData> = SortedList.create(comparator = LANDMINE_COMPARATOR)
|
private var landmines: SortedList<LandmineData> = SortedList.create(comparator = LANDMINE_COMPARATOR)
|
||||||
@ -174,10 +176,11 @@ class LandmineManager(
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
fun onPlayerPlaceMine(placeEvent: BlockPlaceEvent) {
|
fun onPlayerPlaceMine(placeEvent: BlockPlaceEvent) {
|
||||||
if (placeEvent.blockPlaced.type == Material.STONE_PRESSURE_PLATE && !placeEvent.isCancelled) {
|
if (placeEvent.blockPlaced.type == Material.STONE_PRESSURE_PLATE &&
|
||||||
if (placeMine(placeEvent.player, placeEvent.blockPlaced.location)) {
|
placeEvent.itemInHand.itemMeta?.enchants?.contains(enchantment) == true &&
|
||||||
|
!placeEvent.isCancelled) {
|
||||||
|
if (placeMine(placeEvent.player, placeEvent.blockPlaced.location))
|
||||||
--placeEvent.player.inventory.getItem(placeEvent.hand).amount
|
--placeEvent.player.inventory.getItem(placeEvent.hand).amount
|
||||||
}
|
|
||||||
|
|
||||||
placeEvent.isCancelled = true
|
placeEvent.isCancelled = true
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,11 @@ class LandminePlugin: JavaPlugin() {
|
|||||||
stack.itemMeta = meta
|
stack.itemMeta = meta
|
||||||
|
|
||||||
saveDefaultConfig()
|
saveDefaultConfig()
|
||||||
landmineManager = LandmineManager(this, YamlFile(File(dataFolder, "data.yml")))
|
landmineManager = LandmineManager(
|
||||||
|
this,
|
||||||
|
enchantment,
|
||||||
|
YamlFile(File(dataFolder, "data.yml"))
|
||||||
|
)
|
||||||
landmineManager!!.onEnable()
|
landmineManager!!.onEnable()
|
||||||
|
|
||||||
Bukkit.addRecipe(ShapelessRecipe(recipeKey, stack).addIngredient(Material.STONE_PRESSURE_PLATE).addIngredient(Material.TNT))
|
Bukkit.addRecipe(ShapelessRecipe(recipeKey, stack).addIngredient(Material.STONE_PRESSURE_PLATE).addIngredient(Material.TNT))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user