Skip to content

Commit cadebf3

Browse files
authored
Registered default permissions (#42)
2 parents fcb2303 + 5bf9c59 commit cadebf3

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package pro.cloudnode.smp.enchantbookplus;
22

3+
import org.bukkit.Registry;
34
import org.bukkit.enchantments.Enchantment;
5+
import org.bukkit.permissions.Permission;
6+
import org.bukkit.permissions.PermissionDefault;
7+
import org.bukkit.plugin.PluginManager;
48
import org.jetbrains.annotations.NotNull;
59

610
public final class Permissions {
@@ -9,4 +13,21 @@ public final class Permissions {
913
}
1014

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

0 commit comments

Comments
 (0)