Skip to content
Merged
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
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ See the [default config](https://github.com/cloudnode-pro/EnchantBookPlus/blob/m
> [!NOTE]
> `<echantment>` is the enchantment ID, e.g. `swift_sneak`, `efficiency`, etc. Replace with `*` for all enchantments.
>
> Example: `enchantbookplus.enchant.*` or `enchantbookplus.enchant.unbreaking`

| Permission | Description | Default |
|-----------------------------------------|----------------------------------------------------------------------------------------|----------|
| `enchantbookplus.enchant.<enchantment>` | Allow enchanting `<enchantment>` above the vanilla level, as configured in the plugin. | Everyone |
| `enchantbookplus.reload` | Reload plugin config using `/enchantbookplus reload` | OP |
> For custom enchantments, the `<namespace>` prefix is required and must specify the namespace of the plugin or datapack
> which registered the enchantment.
>
> Example: `enchantbookplus.enchant.*`, `enchantbookplus.enchant.unbreaking`, or
> `enchantbookplus.enchant.someplugin.enchantname`.

| Permission | Description | Default |
|-----------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|----------|
| `enchantbookplus.enchant.<enchantment>` | Allow enchanting `<enchantment>` above the vanilla level, as configured in the plugin. | Everyone |
| `enchantbookplus.enchant.<namespace>.<enchantment>` | Allow enchanting the custom enchantment `<enchantment>` from the `<namespace>` plugin/datapack above its maximum level, as configured in this plugin. | Everyone |
| `enchantbookplus.reload` | Reload plugin config using `/enchantbookplus reload` | OP |

## Reporting issues
Fixing bugs is the utmost priority for this project.
Expand Down
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
5 changes: 3 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# List of enchantments for which to enable upgrading above the vanilla max levels using an anvil.
enchantments:
# Enchantment name (same as in the /enchant command).
# Set this to "ALL" to enable upgrading for all other enchantments not listed here.
# NOTE: Enchantments that on Vanilla have a max level of 1 (e.g. Silk Touch, Mending, Curse of Vanishing, Infinity) etc. are always ignored by this plugin.
# Vanilla enchantments can be written with or without the namespace, e.g. "efficiency" or "minecraft:efficiency".
# Custom enchantments must include their plugin or datapack namespace, in the form "namespace:key".
- name: efficiency
# Maximum level to which the enchantment can be upgraded.
# For relative levels above the vanilla max level, use e.g. "+1". E.g. +1 for Protection will allow upgrading to Protection V. For Efficiency, +1 will allow upgrading to Efficiency VI.
Expand All @@ -16,6 +16,7 @@ enchantments:
# You can also just provide a flat value for all levels, e.g. "10" will cost 10 XP levels regardless of the enchantment level
cost: "*150"

# "ALL" affects all other enchantments not listed above.
- name: ALL
max-level: "+1"
cost: 100
Loading