Skip to content

Commit

Permalink
feat: customizable permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Misat11 committed Feb 25, 2024
1 parent e5379b6 commit 54b4763
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,32 @@
import org.screamingsandals.lib.sender.permissions.Permission;
import org.screamingsandals.lib.sender.permissions.SimplePermission;

import java.util.List;

@RequiredArgsConstructor
public enum BedWarsPermission {
ADMIN_PERMISSION("bw.admin", List.of()),
OTHER_STATS_PERMISSION("bw.otherstats", List.of()),
JOIN_PERMISSION("bw.cmd.join", List.of("default-permissions", "join")),
JOIN_GROUP_PERMISSION("bw.cmd.join-group", List.of("default-permissions", "join-group")),
LEAVE_PERMISSION("bw.cmd.leave", List.of("default-permissions", "leave")),
GAMES_INVENTORY_PERMISSION("bw.cmd.gamesinv", List.of("default-permissions", "gamesinv")),
AUTOJOIN_PERMISSION("bw.cmd.autojoin", List.of("default-permissions", "autojoin")),
LIST_PERMISSION("bw.cmd.list", List.of("default-permissions", "list")),
REJOIN_PERMISSION("bw.cmd.rejoin", List.of("default-permissions", "rejoin")),
STATS_PERMISSION("bw.cmd.stats", List.of("default-permissions", "stats")),
LEADERBOARD_PERMISSION("bw.cmd.leaderboard", List.of("default-permissions", "leaderboard")),
PARTY_PERMISSION("bw.cmd.party", List.of("default-permissions", "party")),
ALL_JOIN_PERMISSION("bw.admin.alljoin", List.of()),
DISABLE_ALL_JOIN_PERMISSION("bw.disable.joinall", List.of()),
START_ITEM_PERMISSION("bw.vip.startitem", List.of()),
FORCE_JOIN_PERMISSION("bw.vip.forcejoin", List.of()),
BYPASS_FLIGHT_PERMISSION("bw.bypass.flight", List.of());
ADMIN_PERMISSION("admin"),
OTHER_STATS_PERMISSION("other-stats"),
JOIN_PERMISSION("join"),
JOIN_GROUP_PERMISSION("join-group"),
LEAVE_PERMISSION("leave"),
GAMES_INVENTORY_PERMISSION("gamesinv"),
AUTOJOIN_PERMISSION("autojoin"),
LIST_PERMISSION("list"),
REJOIN_PERMISSION("rejoin"),
STATS_PERMISSION("stats"),
LEADERBOARD_PERMISSION("leaderboard"),
PARTY_PERMISSION("party"),
ALL_JOIN_PERMISSION("all-join"),
DISABLE_ALL_JOIN_PERMISSION("disable-all-join"),
START_ITEM_PERMISSION("start-item"),
FORCE_JOIN_PERMISSION("force-join"),
BYPASS_FLIGHT_PERMISSION("bypass-flight");

private final String permission;
private final List<String> defaultAllowedConfigurationKeys;
private final String permissionNodeKey;

public Permission asPermission() {
var defaultAllowed = false;
if (!defaultAllowedConfigurationKeys.isEmpty()) {
defaultAllowed = MainConfig.getInstance().node(defaultAllowedConfigurationKeys.toArray()).getBoolean();
}
var node = MainConfig.getInstance().node("permissions", permissionNodeKey);
var permission = node.node("key").getString("bw.unknown-permission");
var defaultAllowed = node.node("default").getBoolean(false);

return SimplePermission.of(permission, defaultAllowed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,17 +798,95 @@ public void load() {
.key("hide-spectators").defValue(true)
.key("hide-foreign-players").defValue(false)
.back()
.section("default-permissions")
.key("join").defValue(true)
.key("join-group").defValue(true)
.key("leave").defValue(true)
.key("stats").defValue(true)
.key("list").defValue(true)
.key("rejoin").defValue(true)
.key("autojoin").defValue(true)
.key("leaderboard").defValue(true)
.key("party").defValue(true)
.key("gamesinv").defValue(true)
.section("permissions")
.section("join")
.key("key").defValue("bw.cmd.join")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "join")
.defValue(true)
.back()
.section("join-group")
.key("key").defValue("bw.cmd.join-group")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "join-group")
.defValue(true)
.back()
.section("leave")
.key("key").defValue("bw.cmd.leave")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "leave")
.defValue(true)
.back()
.section("autojoin")
.key("key").defValue("bw.cmd.autojoin")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "autojoin")
.defValue(true)
.back()
.section("list")
.key("key").defValue("bw.cmd.list")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "list")
.defValue(true)
.back()
.section("rejoin")
.key("key").defValue("bw.cmd.rejoin")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "rejoin")
.defValue(true)
.back()
.section("stats")
.key("key").defValue("bw.cmd.stats")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "stats")
.defValue(true)
.back()
.section("leaderboard")
.key("key").defValue("bw.cmd.leaderboard")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "leaderboard")
.defValue(true)
.back()
.section("party")
.key("key").defValue("bw.cmd.party")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "party")
.defValue(true)
.back()
.section("gamesinv")
.key("key").defValue("bw.cmd.gamesinv")
.key("default")
.migrateOldAbsoluteKey("default-permissions", "gamesinv")
.defValue(true)
.back()
.section("admin")
.key("key").defValue("bw.admin")
.key("default").defValue(false)
.back()
.section("other-stats")
.key("key").defValue("bw.otherstats")
.key("default").defValue(false)
.back()
.section("all-join")
.key("key").defValue("bw.admin.alljoin")
.key("default").defValue(false)
.back()
.section("disable-all-join")
.key("key").defValue("bw.disable.joinall")
.key("default").defValue(false)
.back()
.section("start-item")
.key("key").defValue("bw.vip.startitem")
.key("default").defValue(false)
.back()
.section("force-join")
.key("key").defValue("bw.vip.forcejoin")
.key("default").defValue(false)
.back()
.section("bypass-flight")
.key("key").defValue("bw.bypass.flight")
.key("default").defValue(false)
.back()
.back()
.section("party")
.key("enabled").defValue(false)
Expand Down

0 comments on commit 54b4763

Please sign in to comment.