Add landmine item recipe

This commit is contained in:
Gabriel Tofvesson 2021-09-15 23:15:20 +02:00
parent e42e97a8c4
commit 54a8ad9e03

View File

@ -1,19 +1,61 @@
package dev.w1zzrd.spigot.landmines2 package dev.w1zzrd.spigot.landmines2
import kr.entree.spigradle.annotations.SpigotPlugin import kr.entree.spigradle.annotations.SpigotPlugin
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
import org.bukkit.enchantments.EnchantmentWrapper
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.ShapelessRecipe
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
import java.io.File import java.io.File
private val field_acceptingNew = Enchantment::class.java.getDeclaredField("acceptingNew")
private var isAcceptingNewEnchantments: Boolean
get() {
field_acceptingNew.isAccessible = true
return field_acceptingNew.get(null) as Boolean
}
set(value) {
field_acceptingNew.isAccessible = true
field_acceptingNew.set(null, value)
}
@SpigotPlugin @SpigotPlugin
class LandminePlugin: JavaPlugin() { class LandminePlugin: JavaPlugin() {
private val recipeKey = NamespacedKey(this, "landmineRecipe")
private val enchantmentKey = NamespacedKey(this, "landmineEnchantment")
private lateinit var enchantment: Enchantment
private var landmineManager: LandmineManager? = null private var landmineManager: LandmineManager? = null
override fun onEnable() { override fun onEnable() {
super.onEnable() super.onEnable()
val ench = Enchantment.getByKey(enchantmentKey)
if (ench == null) {
enchantment = LandmineEnchantment(enchantmentKey)
isAcceptingNewEnchantments = true
Enchantment.registerEnchantment(enchantment)
isAcceptingNewEnchantments = false
} else {
enchantment = ench
}
val stack = ItemStack(Material.STONE_PRESSURE_PLATE)
val meta = stack.itemMeta!!
meta.addEnchant(enchantment, 1, true)
meta.itemFlags.add(ItemFlag.HIDE_ENCHANTS)
meta.setDisplayName("Landmine")
stack.itemMeta = meta
saveDefaultConfig() saveDefaultConfig()
landmineManager = LandmineManager(this, YamlFile(File(dataFolder, "data.yml"))) landmineManager = LandmineManager(this, YamlFile(File(dataFolder, "data.yml")))
landmineManager!!.onEnable() landmineManager!!.onEnable()
Bukkit.addRecipe(ShapelessRecipe(recipeKey, stack).addIngredient(Material.STONE_PRESSURE_PLATE).addIngredient(Material.TNT))
} }
override fun reloadConfig() { override fun reloadConfig() {
@ -23,6 +65,8 @@ class LandminePlugin: JavaPlugin() {
} }
override fun onDisable() { override fun onDisable() {
Bukkit.removeRecipe(recipeKey)
landmineManager!!.onDisable() landmineManager!!.onDisable()
saveConfig() saveConfig()