Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
Add permission format override for join/quit messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Oct 17, 2023
1 parent 7e04a37 commit 1380c7b
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public Optional<String> getPlayerGroupDisplayName(@NotNull Player player) {
}
}

@Override
public Optional<String> getTextFromNode(@NotNull Player player, @NotNull String nodePrefix) {
final String prefix = nodePrefix.endsWith(".") ? nodePrefix : nodePrefix + ".";
return getUser(player).getPerms().stream().filter(node -> node.startsWith(prefix)).findFirst()
.map(node -> node.length() > prefix.length() ? node.substring(prefix.length()) : "");
}

private User getUser(Player player) {
return permissionsManager.getUser(player.getUuid());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,16 @@ public void sendFormattedBroadcastMessage(@NotNull Player player, @NotNull Strin
}

public void sendJoinMessage(@NotNull Player player) {
plugin.replacePlaceholders(player, plugin.getSettings().getJoinMessageFormat())
plugin.replacePlaceholders(player,
plugin.getDataGetter().getTextFromNode(player, "huskchat.join_message")
.orElse(plugin.getSettings().getJoinMessageFormat()))
.thenAccept(replaced -> sendJoinQuitMessage(player, new MineDown(replaced).toComponent()));
}

public void sendQuitMessage(@NotNull Player player) {
plugin.replacePlaceholders(player, plugin.getSettings().getQuitMessageFormat())
plugin.replacePlaceholders(player,
plugin.getDataGetter().getTextFromNode(player, "huskchat.quit_message")
.orElse(plugin.getSettings().getQuitMessageFormat()))
.thenAccept(replaced -> sendJoinQuitMessage(player, new MineDown(replaced).toComponent()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ public abstract class DataGetter {

public abstract Optional<String> getPlayerGroupDisplayName(@NotNull Player player);

public abstract Optional<String> getTextFromNode(@NotNull Player player, @NotNull String nodePrefix);

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ public Optional<String> getPlayerGroupDisplayName(@NotNull Player player) {
return Optional.empty();
}

@Override
public Optional<String> getTextFromNode(@NotNull Player player, @NotNull String nodePrefix) {
return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ public Optional<String> getPlayerGroupDisplayName(@NotNull Player player) {
}
return Optional.of(group.getDisplayName());
});
}


@Override
public Optional<String> getTextFromNode(@NotNull Player player, @NotNull String nodePrefix) {
return getUser(player.getUuid()).flatMap(user -> Optional.ofNullable(
user.getCachedData().getMetaData().getMetaValue(nodePrefix)
));
}

private Optional<User> getUser(@NotNull UUID uuid) {
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ message_replacers:
join_and_quit_messages:
join:
enabled: false
# Use the huskchat.join.[text] permission to override this per-group if needed
# Use the huskchat.join_message.[text] permission to override this per-group if needed
format: '&e%name% joined the network'
quit:
enabled: false
# Use the huskchat.quit.[text] permission to override this per-group if needed
# Use the huskchat.quit_message.[text] permission to override this per-group if needed
format: '&e%name% left the network'
broadcast_scope: GLOBAL # Note that on Velocity/Bungee, PASSTHROUGH modes won't cancel local join/quit messages

Expand Down
4 changes: 2 additions & 2 deletions docs/Config-Files.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ message_replacers:
join_and_quit_messages:
join:
enabled: false
# Use the huskchat.join.[text] permission to override this per-group if needed
# Use the huskchat.join_message.[text] permission to override this per-group if needed
format: '&e%name% joined the network'
quit:
enabled: false
# Use the huskchat.quit.[text] permission to override this per-group if needed
# Use the huskchat.quit_message.[text] permission to override this per-group if needed
format: '&e%name% left the network'
broadcast_scope: GLOBAL # Note that on Velocity/Bungee, PASSTHROUGH modes won't cancel local join/quit messages

Expand Down
9 changes: 6 additions & 3 deletions docs/Join-and-Quit-Messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ Note that global, local and regular PASSTHROUGH scopes are only effective when r
join_and_quit_messages:
join:
enabled: false
# Use the huskchat.join.[text] permission to override this per-group if needed
# Use the huskchat.join_message.[text] permission to override this per-group if needed
format: '&e%name% joined the network'
quit:
enabled: false
# Use the huskchat.quit.[text] permission to override this per-group if needed
# Use the huskchat.quit_message.[text] permission to override this per-group if needed
format: '&e%name% left the network'
broadcast_scope: GLOBAL # Note that on Velocity/Bungee, PASSTHROUGH modes won't cancel local join/quit messages
```
</details>
</details>
## Permission-based formats
You can set specific join/quit messages for specific groups by using the `huskchat.join_message.[text]` and `huskchat.quit_message.[text]` permissions. For example, if you wanted to set a special join message for players with the `vip` group, you could give them the `huskchat.join_message.&a%name% has arrived with style!` permission node to display a different join message.

0 comments on commit 1380c7b

Please sign in to comment.