Skip to content

Commit

Permalink
feat: add pronoun length limit (closes #18) and update docs in README
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhhleyyy committed Jan 7, 2025
1 parent ad44f40 commit 20953a4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 44 deletions.
84 changes: 50 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,37 @@ Let players share their pronouns!

### Commands

To change your displayed pronouns, you can use the command `/pronouns`.
It will suggest pronouns that are configured by the server admins, along with the default set. By default, you do not
have to pick one of the suggestions at all, however server owners may disable setting custom pronouns in case of abuse,
although it is not recommended to do so permanently.
To change your displayed pronouns, you can use the command `/pronouns set` or `/pronouns unset`. You can also view other player's pronouns with `/pronouns show`.

`/pronouns set` will suggest pronouns that are configured by the server admins, along with the default set. By default, you do not have to pick one of the suggestions at all, however server owners may disable setting custom pronouns in case of abuse, though it is not recommended to do so permanently. Server admins may also limit the length of custom pronouns, to prevent overflow when displayed, although this is also not the default.

## For server owners

> [!NOTE]
> Player Pronouns needs another mod configured to actually display pronouns, otherwise users will be able to set
> pronouns, but will not see them anywhere.
> Player Pronouns needs another mod configured to actually display pronouns, otherwise users will be able to set pronouns, but will not see them anywhere.
### Configuration

The mod should work out of the box without any configuration, however if you want player's pronouns to be visible, you
probably want to use the placeholder somewhere.

#### Reloading the config

You can reload the config file using the command `/pronouns reload-config`. This requires either OP level 4 or the
permission `playerpronouns.reload_config`.

#### Adding custom pronouns (eg. neo-pronouns)

To add custom pronoun sets, you can use the `single` and `pairs` options in the config file. `single` is for singular
options such as `any` or `ask` while `pairs` is for pronouns that come in pairs and are used in the form `a/b`, for
example `they` and `them`.

#### Setting the default placeholder

You can configure the default text returned by the placeholder when a player does not have pronouns set by changing the
`default_placeholder` config value. You can also override the default in particular cases by passing an argument to the
placeholder like this: `%playerpronouns:pronouns/ask%` (or `%playerpronouns:raw_pronouns/ask%`) where `ask` is the
default text.
The mod should work out of the box without any configuration, however if you want player's pronouns to be visible, you probably want to use the placeholder somewhere.

#### Displaying pronouns

You can display the pronouns in any [TextPlaceholderAPI](https://github.com/Patbox/TextPlaceholderAPI) compatible mods
using the following placeholders:
You can display the pronouns in any [TextPlaceholderAPI](https://github.com/Patbox/TextPlaceholderAPI) compatible mods using the following placeholders:

* `playerpronouns:pronouns`: Returns a player's pronouns with any styling that is configured.
* `playerpronouns:raw_pronouns`: Returns a player's pronouns without any styling even if configured.

##### In chat with Styled Chat

[Styled Chat](https://modrinth.com/mod/styled-chat) allows you to customise the formatting of chat messages.
To configure pronouns to show up like this, you can set the `chat` style to the following:
[Styled Chat](https://modrinth.com/mod/styled-chat) allows you to customise the formatting of chat messages. To configure pronouns to show up like this, you can set the `chat` style to the following:

`<${player} [%playerpronouns:pronouns%]> ${message}`

![](https://cdn.discordapp.com/attachments/859419898962116642/870732808367267881/in-chat.png)

##### On the tab list with Styled Player List

[Styled Player List](https://modrinth.com/mod/styledplayerlist) allows you to customise the look and feel of the
tab/player list, as well as customise the formatting used for players in the list.
[Styled Player List](https://modrinth.com/mod/styledplayerlist) allows you to customise the look and feel of the tab/player list, as well as customise the formatting used for players in the list.

```json
{
Expand All @@ -73,7 +49,47 @@ tab/player list, as well as customise the formatting used for players in the lis

![](https://cdn.discordapp.com/attachments/859419898962116642/870739744286453820/2021-07-30_19.45.49.png)

#### Config structure

The default configuration file looks something like this, and is located in `config/player-pronouns.json`:

```json
{
"pairs": [],
"single": [],
"integrations": {
"pronoun_db": false
},
"allow_custom": true,
"default_placeholder": "Unknown",
"max_pronoun_length": -1
}
```

#### Reloading the config

You can reload the config file using the command `/pronouns reload-config`. This requires either OP level 4 or the permission `playerpronouns.reload_config`.

#### Integrations

Player Pronouns supports fetching pronouns from external services, such as PronounDB. These integrations are disabled by default, and can be enabled in the configuration file under the `integrations` section.

#### Custom pronouns and max length

By default, players can set their pronouns to anything they like, however you can limit this selection to only the default set and any extras defined in your configuration by setting `allow_custom` to `false`, however this is not recommended.

You can also limit the allowed length of custom pronouns, for example if you are displaying them in locations where space is limited. This can be done by setting `max_pronoun_length` to a value >0.

#### Adding custom pronouns (eg. neo-pronouns)

Custom pronouns allow expanding the autocomplete options on the `/pronouns set` command.

To add custom pronoun sets, you can use the `single` and `pairs` options in the config file. `single` is for singular options such as `any` or `ask` while `pairs` is for pronouns that come in pairs and are used in the form `a/b`, for example `they` and `them`.

#### Setting the default placeholder

You can configure the default text returned by the placeholder when a player does not have pronouns set by changing the`default_placeholder` config value. You can also override the default in particular cases by passing an argument to the placeholder like this: `%playerpronouns:pronouns/ask%` (or `%playerpronouns:raw_pronouns/ask%`) where `ask` is the default text.

### Backing up the database

The mod stores the mapping of players -> pronouns inside the world save file at `world/playerdata/pronouns.dat`. Note
that the file is a custom binary format, NOT NBT, and so cannot be edited using normal tools.
The mod stores the mapping of players -> pronouns inside the world save file at `world/playerdata/pronouns.dat`. Note that the file is a custom binary format, NOT NBT, and so cannot be edited using normal tools.
18 changes: 10 additions & 8 deletions src/main/java/dev/ashhhleyyy/playerpronouns/impl/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ public record Config(
List<Pronoun> single,
List<Pronoun> pairs,
String defaultPlaceholder,
Integrations integrations
Integrations integrations,
int maxPronounLength
) {
private static final Codec<Config> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.BOOL.fieldOf("allow_custom").forGetter(Config::allowCustom),
Pronoun.CODEC.listOf().fieldOf("single").forGetter(Config::single),
Pronoun.CODEC.listOf().fieldOf("pairs").forGetter(Config::pairs),
Codec.STRING.optionalFieldOf("default_placeholder", "Unknown").forGetter(Config::defaultPlaceholder),
Integrations.CODEC.fieldOf("integrations").forGetter(Config::integrations)
Integrations.CODEC.optionalFieldOf("integrations", new Integrations()).forGetter(Config::integrations),
Codec.INT.optionalFieldOf("max_pronoun_length", -1).forGetter(Config::maxPronounLength)
).apply(instance, Config::new));

private Config() {
this(true, Collections.emptyList(), Collections.emptyList(), "Unknown", new Integrations());
this(true, Collections.emptyList(), Collections.emptyList(), "Unknown", new Integrations(), -1);
}

public static Config load() {
Expand All @@ -61,11 +63,11 @@ public static Config load() {
err.ifPresent(e -> PlayerPronouns.LOGGER.warn("Failed to load config: {}", e.message()));
Config config = result.result().orElseGet(Config::new);
if (err.isEmpty() && ele.getAsJsonObject().has("enable_pronoundb_sync")) {
if (!ele.getAsJsonObject().get("enable_pronoundb_sync").getAsBoolean()) {
PlayerPronouns.LOGGER.warn("Config option `enable_pronoundb_sync` is legacy and will be removed in the next release. Please set `integrations.pronoundb` to `false` instead.");
if (ele.getAsJsonObject().get("enable_pronoundb_sync").getAsBoolean()) {
PlayerPronouns.LOGGER.warn("Config option `enable_pronoundb_sync` is legacy and will be removed in the next release. Please set `integrations.pronoundb` to `true` instead.");
config = new Config(config.allowCustom, config.single, config.pairs, config.defaultPlaceholder, new Integrations(
false
));
true
), config.maxPronounLength);
}
}
return config;
Expand Down Expand Up @@ -100,7 +102,7 @@ public record Integrations(
).apply(instance, Integrations::new));

private Integrations() {
this(true);
this(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class PlayerPronouns implements ModInitializer, PronounsApi.PronounReader
public static final Logger LOGGER = LoggerFactory.getLogger(PlayerPronouns.class);
public static final String MOD_ID = "playerpronouns";
public static final String USER_AGENT = "player-pronouns/1.0 (+https://ashhhleyyy.dev/projects/2021/player-pronouns)";
public static final byte[][] OWOS = new byte[][]{new byte[]{73, 110, 106, 101, 99, 116, 105, 110, 103, 32, 119, 111, 107, 101, 46, 46, 46}, new byte[]{85, 112, 103, 114, 97, 100, 105, 110, 103, 32, 97, 109, 97, 116, 101, 117, 114, 32, 110, 111, 117, 110, 115, 46, 46, 46}, new byte[]{80, 114, 101, 112, 97, 114, 105, 110, 103, 32, 65, 98, 115, 116, 114, 97, 99, 116, 80, 114, 111, 110, 111, 117, 110, 80, 114, 111, 118, 105, 100, 101, 114, 70, 97, 99, 116, 111, 114, 121, 46, 46, 46}, new byte[]{84, 114, 97, 110, 115, 105, 110, 103, 32, 103, 101, 110, 100, 101, 114, 115, 46, 46, 46}, new byte[]{77, 97, 107, 105, 110, 103, 32, 116, 104, 101, 32, 102, 114, 111, 103, 115, 32, 103, 97, 121, 46, 46, 46}, new byte[]{70, 108, 121, 105, 110, 103, 32, 102, 108, 97, 103, 115, 46, 46, 46}, new byte[]{72, 97, 112, 112, 121, 32, 112, 114, 105, 100, 101, 32, 109, 111, 110, 116, 104, 33, 33}};
public static final byte[][] OWOS = new byte[][]{new byte[]{73,110,106,101,99,116,105,110,103,32,119,111,107,101,46,46,46},new byte[]{85,112,103,114,97,100,105,110,103,32,97,109,97,116,101,117,114,32,110,111,117,110,115,46,46,46},new byte[]{80,114,101,112,97,114,105,110,103,32,65,98,115,116,114,97,99,116,80,114,111,110,111,117,110,80,114,111,118,105,100,101,114,70,97,99,116,111,114,121,46,46,46},new byte[]{84,114,97,110,115,105,110,103,32,103,101,110,100,101,114,115,46,46,46},new byte[]{77,97,107,105,110,103,32,116,104,101,32,102,114,111,103,115,32,103,97,121,46,46,46},new byte[]{70,108,121,105,110,103,32,102,108,97,103,115,46,46,46},new byte[]{76,111,99,97,116,105,110,103,32,66,108,97,104,97,106,46,46,46},new byte[]{72,97,112,112,121,32,112,114,105,100,101,32,109,111,110,116,104,33,33}};
public static Config config;
private PronounDatabase pronounDatabase;
private PronounDbClient pronounDbClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
String pronounsString = getString(ctx, "pronouns");

Map<String, Text> pronounTexts = PronounList.get().getCalculatedPronounStrings();
if (!PlayerPronouns.config.allowCustom() && !pronounTexts.containsKey(pronounsString)) {
boolean isCustom = !pronounTexts.containsKey(pronounsString);
if (isCustom && !PlayerPronouns.config.allowCustom()) {
ctx.getSource().sendError(Text.literal("Custom pronouns have been disabled by the server administrator."));
return 0;
}

int maxLength = PlayerPronouns.config.maxPronounLength();
if (isCustom && maxLength > 0 && pronounsString.length() > maxLength) {
ctx.getSource().sendError(Text.literal("The server administrator has limited the length of custom pronouns to " + maxLength + "."));
return 0;
}

Pronouns pronouns = Pronouns.fromString(pronounsString);

if (!PronounsApi.getSetter().setPronouns(player, pronouns)) {
Expand Down

0 comments on commit 20953a4

Please sign in to comment.