Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public final boolean getMultiplyCostByLevel() {
* Get enchantment
*/
public final Enchantment getEnchantment() {
return Objects.requireNonNull(Registry.ENCHANTMENT.get(NamespacedKey.minecraft(name)));
return Objects.requireNonNull(Registry.ENCHANTMENT.get(Objects.requireNonNull(NamespacedKey.fromString(name))));
}

/**
Expand All @@ -228,7 +228,12 @@ public final Enchantment getEnchantment() {
* @param enchantment The enchantment
*/
public final boolean isEnchantment(final Enchantment enchantment) {
return name.equalsIgnoreCase(enchantment.getKey().getKey());
if (!enchantment.getKey().getNamespace().equals(NamespacedKey.MINECRAFT)) {
return name.equalsIgnoreCase(enchantment.getKey().getNamespace() + ":" + enchantment.getKey().getKey());
}

return name.equalsIgnoreCase(enchantment.getKey().getKey())
|| name.equalsIgnoreCase(enchantment.getKey().getNamespace() + ":" + enchantment.getKey().getKey());
}

public static final class AllConfigEnchantmentEntry extends ConfigEnchantmentEntry {
Expand All @@ -252,7 +257,7 @@ public static AllConfigEnchantmentEntry from(final ConfigEnchantmentEntry config

public ConfigEnchantmentEntry enchant(final Enchantment enchantment) {
return new ConfigEnchantmentEntry(
enchantment.getKey().getKey(),
enchantment.getKey().getNamespace() + ":" + enchantment.getKey().getKey(),
this.maxLevel,
maxLevelRelative,
cost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void reload() {

@Override
public void onEnable() {
Permissions.init(this);
Permissions.register(this);
Objects.requireNonNull(getCommand("enchantbookplus")).setExecutor(new MainCommand(this));

registerEvents();
Expand All @@ -99,5 +99,6 @@ public void onEnable() {
public void onDisable() {
allConfigEnchantment = null;
configEnchantments.clear();
Permissions.unregister(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
package pro.cloudnode.smp.enchantbookplus;

import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
import org.jspecify.annotations.NullMarked;

import java.util.function.Consumer;

@NullMarked
public final class Permissions {
public final static String RELOAD = "enchantbookplus.reload";
public static final String RELOAD = "enchantbookplus.reload";

public static String enchant(final Enchantment enchantment) {
return "enchantbookplus.enchant." + enchantment.getKey().getKey();
if (enchantment.getKey().getNamespace().equals(NamespacedKey.MINECRAFT)) {
return "enchantbookplus.enchant." + enchantment.getKey().getKey();
}

return "enchantbookplus.enchant." + enchantment.getKey().getNamespace() + "." + enchantment.getKey().getKey();
}

public static void init(final EnchantBookPlus plugin) {
public static void register(final EnchantBookPlus plugin) {
final PluginManager pm = plugin.getServer().getPluginManager();
forEach(pm::addPermission);
}

public static void unregister(final EnchantBookPlus plugin) {
final PluginManager pm = plugin.getServer().getPluginManager();
forEach(pm::removePermission);
}

pm.addPermission(new Permission(
private static void forEach(final Consumer<Permission> consumer) {
consumer.accept(new Permission(
RELOAD,
"Reload plugin config using ‘/enchantbookplus reload’",
PermissionDefault.OP
));

for (Enchantment enchantment : Registry.ENCHANTMENT) {
pm.addPermission(new Permission(
for (final Enchantment enchantment : Registry.ENCHANTMENT) {
consumer.accept(new Permission(
enchant(enchantment),
"Allow enchanting " + enchantment.getKey() + "above the vanilla level, as configured in the plugin",
"Allow enchanting " + enchantment.getKey()
+ " above the vanilla level, as configured in the plugin",
PermissionDefault.TRUE
));
}
Expand Down
Loading