Skip to content

Commit

Permalink
chore: reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhhleyyy committed Jan 7, 2025
1 parent e473316 commit ad44f40
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 313 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 }}
42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
# 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.
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.

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

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

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

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.

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.

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

Expand All @@ -38,7 +58,9 @@ To configure pronouns to show up like this, you can set the `chat` style to the
![](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 @@ -52,4 +74,6 @@ 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)

### 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.
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
Expand Up @@ -12,7 +12,10 @@
*/
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);
}
}
}
}
7 changes: 4 additions & 3 deletions src/main/java/dev/ashhhleyyy/playerpronouns/api/Pronouns.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

/**
* A combined set of {@link Pronoun}s
* @param raw The plain text version of this pronoun set
*
* @param raw The plain text version of this pronoun set
* @param formatted The styled version of this pronoun set
* @param remote Whether the pronouns were fetched from a remote API
* @param provider The ID of the external provider that these pronouns were fetched from
* @param remote Whether the pronouns were fetched from a remote API
* @param provider The ID of the external provider that these pronouns were fetched from
*/
public record Pronouns(
String raw,
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/dev/ashhhleyyy/playerpronouns/api/PronounsApi.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package dev.ashhhleyyy.playerpronouns.api;

import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

import org.jetbrains.annotations.Nullable;

import net.minecraft.server.network.ServerPlayerEntity;

/**
* Entrypoint to the API, and provides access to a {@link PronounReader} and {@link PronounSetter}
*/
public final class PronounsApi {
private static final List<ExtraPronounProvider> PROVIDERS = new ArrayList<>();
private static @Nullable PronounReader READER = null;
private static @Nullable PronounSetter SETTER = null;
private static final List<ExtraPronounProvider> PROVIDERS = new ArrayList<>();

/**
* @return The currently initialised {@link PronounReader}
Expand All @@ -41,7 +40,7 @@ public static PronounSetter getSetter() {
* Makes the passed reader be set as the default.
* <p>
* This should not be called by most mods, unless they are implementing a custom backend.
*
*
* @param reader The reader to configure
*/
public static void initReader(PronounReader reader) {
Expand All @@ -55,7 +54,7 @@ public static void initReader(PronounReader reader) {
* Makes the passed setter be set as the default.
* <p.
* This should not be called by most mods, unless they are implementing a custom backend.
*
*
* @param setter The setter to configure
*/
public static void initSetter(PronounSetter setter) {
Expand All @@ -82,6 +81,7 @@ public interface PronounSetter {
default boolean setPronouns(ServerPlayerEntity player, @Nullable Pronouns pronouns) {
return this.setPronouns(player.getUuid(), pronouns);
}

boolean setPronouns(UUID playerId, @Nullable Pronouns pronouns);
}

Expand All @@ -92,6 +92,7 @@ public interface PronounReader {
default @Nullable Pronouns getPronouns(ServerPlayerEntity player) {
return this.getPronouns(player.getUuid());
}

@Nullable Pronouns getPronouns(UUID playerId);
}
}
Loading

0 comments on commit ad44f40

Please sign in to comment.