mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add material groups and prepare additional permissions.
This commit is contained in:
parent
e2aa0509f0
commit
e18e5b224e
8 changed files with 256 additions and 2 deletions
|
|
@ -34,6 +34,9 @@ class AnvilEventListener : Listener {
|
|||
// Permission node required for the plugin to take over enchantment combination
|
||||
private val requirePermission: Permission
|
||||
get() = Permission(UnsafeEnchants.unsafePermission)
|
||||
// Permission node to bypass illegal group check
|
||||
private val bypassPermission: Permission
|
||||
get() = Permission(UnsafeEnchants.unsafeBypassPermission)
|
||||
|
||||
/**
|
||||
* Event handler logic for when an anvil contains items to be combined
|
||||
|
|
@ -85,7 +88,10 @@ class AnvilEventListener : Listener {
|
|||
val player = event.whoClicked as? Player ?: return
|
||||
val inventory = event.inventory as? AnvilInventory ?: return
|
||||
val output = inventory.getItem(ANVIL_OUTPUT_SLOT) ?: return
|
||||
if (output.findEnchantments().hasConflicts() && !player.hasPermission(requirePermission)) { return }
|
||||
if(!player.hasPermission(bypassPermission)){
|
||||
if (output.findEnchantments().hasConflicts() && !player.hasPermission(requirePermission)) { return }
|
||||
|
||||
}
|
||||
if (event.rawSlot != ANVIL_OUTPUT_SLOT) { return }
|
||||
event.result = Event.Result.ALLOW
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package io.delilaheve
|
||||
|
||||
import io.delilaheve.util.ConfigOptions
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import xyz.alexcrea.group.ItemGroupManager
|
||||
|
||||
/**
|
||||
* Bukkit/Spigot/Paper plugin to alter enchantment max
|
||||
|
|
@ -12,8 +14,15 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
companion object {
|
||||
// Permission string required to use the plugin's features
|
||||
const val unsafePermission = "ue.unsafe"
|
||||
// Permission string required to bypass illegal enchantment group
|
||||
const val unsafeBypassPermission = "ue.unsafe_all"
|
||||
// Item Grouping Configuration file name
|
||||
const val itemGroupingConfigName = "item_groups.yml"
|
||||
|
||||
// Current plugin instance
|
||||
lateinit var instance: UnsafeEnchants
|
||||
// Current item grouping configuration instance
|
||||
lateinit var itemGroups: ItemGroupManager
|
||||
|
||||
/**
|
||||
* Logging handler
|
||||
|
|
@ -31,6 +40,21 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
override fun onEnable() {
|
||||
instance = this
|
||||
saveDefaultConfig()
|
||||
|
||||
// Save default material grouping config
|
||||
saveResource(itemGroupingConfigName,false)
|
||||
// Load material grouping config
|
||||
val itemGroupConfig = YamlConfiguration()
|
||||
val configReader = this.getTextResource(itemGroupingConfigName)
|
||||
if(configReader == null){
|
||||
logger.severe("could no load item grouping configuration")
|
||||
}else{
|
||||
itemGroupConfig.load(configReader)
|
||||
}
|
||||
// Read material groups from config
|
||||
itemGroups = ItemGroupManager()
|
||||
itemGroups.prepareGroups(itemGroupConfig)
|
||||
|
||||
server.pluginManager.registerEvents(
|
||||
AnvilEventListener(),
|
||||
this
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue