Skip to content

Commit c815ff9

Browse files
committed
Register defaults for permissions
1 parent 1552d58 commit c815ff9

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ You can set the max level for each enchantment, and add XP cost in levels.
2626
>
2727
> Example: `enchantbookplus.enchant.*` or `enchantbookplus.enchant.unbreaking`
2828
29-
| Permission | Description |
30-
|-----------------------------------------|----------------------------------------------------------------------------------------|
31-
| `enchantbookplus.enchant.<enchantment>` | Allow enchanting `<enchantment>` above the vanilla level, as configured in the plugin. |
32-
| `enchantbookplus.reload` | Reload plugin config using `/enchantbookplus reload` |
29+
| Permission | Description | Default |
30+
|-----------------------------------------|----------------------------------------------------------------------------------------|----------|
31+
| `enchantbookplus.enchant.<enchantment>` | Allow enchanting `<enchantment>` above the vanilla level, as configured in the plugin. | Everyone |
32+
| `enchantbookplus.reload` | Reload plugin config using `/enchantbookplus reload` | OP |
3333

3434
## Reporting issues
3535
Fixing bugs is the utmost priority for this project.

src/main/java/pro/cloudnode/smp/enchantbookplus/EnchantBookPlus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void reload() {
8383

8484
@Override
8585
public void onEnable() {
86+
Permissions.init();
8687
Objects.requireNonNull(getCommand("enchantbookplus")).setExecutor(new MainCommand());
8788

8889
registerEvents();

src/main/java/pro/cloudnode/smp/enchantbookplus/Permissions.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package pro.cloudnode.smp.enchantbookplus;
22

3+
import org.bukkit.Registry;
4+
import org.bukkit.Server;
35
import org.bukkit.enchantments.Enchantment;
6+
import org.bukkit.permissions.Permission;
7+
import org.bukkit.permissions.PermissionDefault;
8+
import org.bukkit.plugin.PluginManager;
49
import org.jetbrains.annotations.NotNull;
510

611
public final class Permissions {
@@ -9,4 +14,22 @@ public final class Permissions {
914
}
1015

1116
public static @NotNull String RELOAD = "enchantbookplus.reload";
17+
18+
public static void init() {
19+
final @NotNull Server server = EnchantBookPlus.getInstance().getServer();
20+
final @NotNull PluginManager pm = server.getPluginManager();
21+
pm.addPermission(new Permission(
22+
RELOAD,
23+
"Reload plugin config using `/enchantbookplus reload`",
24+
PermissionDefault.OP
25+
));
26+
for (Enchantment enchantment : Registry.ENCHANTMENT) {
27+
EnchantBookPlus.getInstance().getLogger().info("Registering permission for " + enchantment.getKey());
28+
pm.addPermission(new Permission(
29+
enchant(enchantment),
30+
"Allow enchanting " + enchantment.getKey() + "above the vanilla level, as configured in the plugin",
31+
PermissionDefault.TRUE
32+
));
33+
}
34+
}
1235
}

0 commit comments

Comments
 (0)