From 8ad08aceb276a641989e33df85d8b099e97dceff Mon Sep 17 00:00:00 2001 From: Will FP Date: Mon, 11 Dec 2023 17:43:59 +0000 Subject: [PATCH] Fixed permissions --- .../enchant/impl/EcoEnchantBase.kt | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt index 78188ffc..9ced2865 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchant/impl/EcoEnchantBase.kt @@ -1,8 +1,13 @@ package com.willfp.ecoenchants.enchant.impl import com.willfp.eco.core.config.interfaces.Config +import com.willfp.eco.core.fast.fast +import com.willfp.eco.core.placeholder.PlayerlessPlaceholder +import com.willfp.eco.core.placeholder.context.PlaceholderContext +import com.willfp.eco.core.placeholder.templates.SimpleInjectablePlaceholder import com.willfp.eco.util.containsIgnoreCase import com.willfp.ecoenchants.EcoEnchantsPlugin +import com.willfp.ecoenchants.display.getFormattedName import com.willfp.ecoenchants.enchant.EcoEnchant import com.willfp.ecoenchants.enchant.EcoEnchantLevel import com.willfp.ecoenchants.rarity.EnchantmentRarities @@ -12,8 +17,11 @@ import com.willfp.ecoenchants.type.EnchantmentType import com.willfp.ecoenchants.type.EnchantmentTypes import com.willfp.libreforge.ViolationContext import com.willfp.libreforge.conditions.Conditions +import org.bukkit.Bukkit import org.bukkit.NamespacedKey import org.bukkit.enchantments.Enchantment +import org.bukkit.permissions.Permission +import org.bukkit.permissions.PermissionDefault import org.jetbrains.annotations.ApiStatus.Internal abstract class EcoEnchantBase( @@ -69,6 +77,39 @@ abstract class EcoEnchantBase( override val isObtainableThroughDiscovery = config.getBool("discoverable") + init { + // Placeholders + PlayerlessPlaceholder(plugin, "${id}_name") { + this.getFormattedName(0, false) + }.register() + + // Setup permissions + if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.$id") == null) { + val permission = Permission( + "ecoenchants.fromtable.$id", + "Allows getting $id from an Enchanting Table", + PermissionDefault.TRUE + ) + + if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.*") == null) { + Bukkit.getPluginManager().addPermission( + Permission( + "ecoenchants.fromtable.*", + "Allows getting all enchantments from an Enchanting Table", + PermissionDefault.TRUE + ) + ) + } + + permission.addParent( + Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.*")!!, + true + ) + + Bukkit.getPluginManager().addPermission(permission) + } + } + /** * Load the config for this enchant. */