Skip to content
Open
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 @@ -7,12 +7,16 @@
public record TeamRole(int id, UUID teamId, String name, long permissions) {

public static final String OWNER_ROLE_NAME = "owner";
public static final String MEMBER_ROLE_NAME = "member";
public static final String DEFAULT_ROLE_NAME = "default";

public boolean isOwner() {
return OWNER_ROLE_NAME.equals(name);
}

public boolean isMemberRole() {
return MEMBER_ROLE_NAME.equals(name);
}
public boolean isDefaultRole() {
return DEFAULT_ROLE_NAME.equals(name);
}
Expand All @@ -34,7 +38,10 @@ public static long ownerPermissions() {
return Permission.of(Permission.values());
}

public static long memberPermissions() {
return 0b111111111111111111100000000L;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What in the unholy magic constant unreadable—

}
public static long defaultPermissions() {
return Permission.of();
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ public TeamRole getDefaultRole(Team team) {
return getRoleByName(team, TeamRole.DEFAULT_ROLE_NAME);
}

/**
* Convenience method that returns the "member" role for a team.
*
* @param team the team to query
* @return the default {@link TeamRole}, or {@code null} if not found
*/
public TeamRole getMemberRole(Team team) {
return getRoleByName(team, TeamRole.MEMBER_ROLE_NAME);
}

/**
* Updates the permission bitfield for a role identified by team and role name.
*
Expand Down Expand Up @@ -309,6 +319,7 @@ public void addTeam(Team team) {
}

addRole(team, TeamRole.OWNER_ROLE_NAME, TeamRole.ownerPermissions());
addRole(team, TeamRole.MEMBER_ROLE_NAME, TeamRole.memberPermissions());
addRole(team, TeamRole.DEFAULT_ROLE_NAME, TeamRole.defaultPermissions());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static int acceptInvite(CommandContext<CommandSourceStack> context) {
Team team = resolveInvitedTeam(context, player);
if (team == null) return 0;

TeamRole role = DatabaseManager.database.getDefaultRole(team);
TeamRole role = DatabaseManager.database.getMemberRole(team);
DatabaseManager.database.addPlayerToTeam(player, team, role);
InviteHandler.clearInvites(player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ private static int removeRole(CommandContext<CommandSourceStack> context) {
return failCommand(context, "commands.capitol.team.role.remove.default");
}

if (Objects.equals(roleName, TeamRole.MEMBER_ROLE_NAME)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do heavily applaud your use of Objects.equals for null safety.

A minor note would be that since we know that TeamRole.MEMBER_ROLE_NAME cannot (reasonably) be null, you could also use TeamRole.MEMBER_ROLE_NAME.equals(roleName).

This is purely stylistic, feel free to ignore this comment, either way you're doing good :)

return failCommand(context, "commands.capitol.team.role.remove.member");
}

TeamRole role = database.getRoleByName(team, roleName);

if (role == null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/capitol/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

"commands.capitol.team.role.remove.owner": "You cannot remove owner role.",
"commands.capitol.team.role.remove.default": "You cannot remove default role.",
"commands.capitol.team.role.remove.member": "You cannot remove member role.",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without quotation, this sounds like broken english / bad grammar.

I would suggest "You cannot remove the 'member' role."

"commands.capitol.team.role.remove.success": "Deleted role %s",

"commands.capitol.team.role.assign.no_permission": "You do not have permission to assign roles",
Expand Down