Skip to content

Commit

Permalink
The Big Refactor (#22)
Browse files Browse the repository at this point in the history
* chore: switch to helper for creating identifiers

* chore: initial work on refactoring external providers

* chore: bump minecraft version to 1.21.4

* chore: finish off pronoun provider refactor

* fix: require player for /pronouns unset

* chore: reformat code

* feat: add pronoun length limit (closes #18) and update docs in README
  • Loading branch information
ashhhleyyy authored Jan 7, 2025
1 parent 46e949b commit bf5117d
Show file tree
Hide file tree
Showing 20 changed files with 626 additions and 408 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
name: Build
on: [pull_request, push]
on: [ pull_request, push ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup JDK 21
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Ensure gradlew is executable
run: chmod +x ./gradlew

- name: Build with gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build
run: ./gradlew build

- name: Upload build artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
32 changes: 13 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,30 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/cache@v2
with:
path: |
~/.gradle/loom-cache
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
- name: Checkout code
uses: actions/checkout@v4
- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup JDK 21
uses: actions/setup-java@v4
with:
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew
distribution: temurin
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Ensure gradlew is executable
run: chmod +x ./gradlew

- name: Build and publish with gradle
uses: gradle/gradle-build-action@v2
with:
arguments: modrinth publish
run: ./gradlew modrinth publish
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
MAVEN_URL: ${{ secrets.MAVEN_URL }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}

- name: Upload GitHub release
uses: AButler/upload-release-assets@v2.0
uses: AButler/upload-release-assets@v3.0
with:
files: 'build/libs/player-pronouns-*.jar'
repo-token: ${{ secrets.GITHUB_TOKEN }}
66 changes: 53 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
# Player Pronouns

Let players share their pronouns!

## For players

### 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.
### 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:

* `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.

```json
Expand All @@ -51,5 +49,47 @@ To configure pronouns to show up like this, you can set the `chat` style to the

![](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.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
`maven-publish`
}

version = "2.2.0+1.21"
version = "2.3.0+1.21.4"
group = "dev.ashhhleyyy"

repositories {
Expand Down
12 changes: 6 additions & 6 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[versions]
minecraft = "1.21"
yarn = "1.21+build.2"
minecraft = "1.21.4"
yarn = "1.21.4+build.8"

fabric-loader = "0.15.11"
fabric-api = "0.100.3+1.21"
fabric-loader = "0.16.9"
fabric-api = "0.114.1+1.21.4"

placeholder-api = "2.4.0+1.21"
placeholder-api = "2.5.1+1.21.3"

fabric-permissions = "0.3.1"
fabric-permissions = "0.3.3"

[libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
Expand Down
34 changes: 17 additions & 17 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
pluginManagement {
repositories {
maven {
name = "FabricMC"
url = uri("https://maven.fabricmc.net/")
}
maven {
name = "Cotton"
url = uri("https://server.bbkr.space/artifactory/libs-release")
}
gradlePluginPortal()
mavenCentral()
}
repositories {
maven {
name = "FabricMC"
url = uri("https://maven.fabricmc.net/")
}
maven {
name = "Cotton"
url = uri("https://server.bbkr.space/artifactory/libs-release")
}
gradlePluginPortal()
mavenCentral()
}
}

rootProject.name = "player-pronouns"

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("libs.versions.toml"))
}
}
versionCatalogs {
create("libs") {
from(files("libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.ashhhleyyy.playerpronouns.api;

import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

/**
* A provider that can add extra pronouns for a user based on remote data.
*/
public interface ExtraPronounProvider {
CompletableFuture<Optional<String>> provideExtras(UUID playerId);

Identifier getId();

Text getName();

boolean enabled();
}
60 changes: 32 additions & 28 deletions src/main/java/dev/ashhhleyyy/playerpronouns/api/Pronoun.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,28 @@
import com.mojang.serialization.DataResult;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import dev.ashhhleyyy.playerpronouns.impl.PlayerPronouns;
import net.minecraft.text.*;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
* A single pronoun, which consists of the word itself, along with an associated style.
*
* @param pronoun The text of this pronoun
* @param style An associated style that is used for display as {@link Text}
* @param style An associated style that is used for display as {@link Text}
*/
public record Pronoun(
String pronoun,
Style style
) {
public static final Codec<Pronoun> CODEC = new PronounCodec();

private static class PronounCodec implements Codec<Pronoun> {
private static final Codec<Pronoun> OBJECT_CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.fieldOf("pronoun").forGetter(Pronoun::pronoun),
Codec.STRING.listOf().xmap(Pronoun::styleFrom, Pronoun::fromStyle).fieldOf("style").forGetter(Pronoun::style)
).apply(instance, Pronoun::new));

private PronounCodec() { }

@Override
public <T> DataResult<Pair<Pronoun, T>> decode(DynamicOps<T> ops, T input) {
Optional<String> asString = ops.getStringValue(input).result();
return asString.map(s -> DataResult.success(new Pair<>(new Pronoun(s, Style.EMPTY), ops.empty())))
.orElseGet(() -> OBJECT_CODEC.decode(ops, input));
}

@Override
public <T> DataResult<T> encode(Pronoun input, DynamicOps<T> ops, T prefix) {
if (input.style.isEmpty()) {
return ops.mergeToPrimitive(prefix, ops.createString(input.pronoun));
} else {
return OBJECT_CODEC.encode(input, ops, prefix);
}
}
}

private static Style styleFrom(List<String> formatting) {
Style style = Style.EMPTY;

Expand Down Expand Up @@ -113,4 +91,30 @@ public String toString() {
public int hashCode() {
return this.pronoun.hashCode();
}

private static class PronounCodec implements Codec<Pronoun> {
private static final Codec<Pronoun> OBJECT_CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.fieldOf("pronoun").forGetter(Pronoun::pronoun),
Codec.STRING.listOf().xmap(Pronoun::styleFrom, Pronoun::fromStyle).fieldOf("style").forGetter(Pronoun::style)
).apply(instance, Pronoun::new));

private PronounCodec() {
}

@Override
public <T> DataResult<Pair<Pronoun, T>> decode(DynamicOps<T> ops, T input) {
Optional<String> asString = ops.getStringValue(input).result();
return asString.map(s -> DataResult.success(new Pair<>(new Pronoun(s, Style.EMPTY), ops.empty())))
.orElseGet(() -> OBJECT_CODEC.decode(ops, input));
}

@Override
public <T> DataResult<T> encode(Pronoun input, DynamicOps<T> ops, T prefix) {
if (input.style.isEmpty()) {
return ops.mergeToPrimitive(prefix, ops.createString(input.pronoun));
} else {
return OBJECT_CODEC.encode(input, ops, prefix);
}
}
}
}
Loading

0 comments on commit bf5117d

Please sign in to comment.