mirror of
https://github.com/ashhhleyyy/player-pronouns.git
synced 2024-11-01 07:07:38 +00:00
feat: Add /pronouns unset command
This commit is contained in:
parent
c860c116b6
commit
3909b53823
4 changed files with 20 additions and 4 deletions
|
@ -16,6 +16,7 @@ import net.minecraft.util.Identifier;
|
|||
import net.minecraft.util.WorldSavePath;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -103,7 +104,7 @@ public class PlayerPronouns implements ModInitializer {
|
|||
pronounDatabase.save(playerData.resolve("pronouns.dat"));
|
||||
}
|
||||
|
||||
public static boolean setPronouns(ServerPlayerEntity player, Pronouns pronouns) {
|
||||
public static boolean setPronouns(ServerPlayerEntity player, @Nullable Pronouns pronouns) {
|
||||
if (pronounDatabase == null) return false;
|
||||
|
||||
pronounDatabase.put(player.getUuid(), pronouns);
|
||||
|
|
|
@ -56,6 +56,17 @@ public class PronounsCommand {
|
|||
ctx.getSource().sendFeedback(new LiteralText("Reloaded the config!").formatted(Formatting.GREEN), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
).then(literal("unset")
|
||||
.executes(ctx -> {
|
||||
ServerPlayerEntity player = ctx.getSource().getPlayer();
|
||||
if (!PlayerPronouns.setPronouns(player, null)) {
|
||||
ctx.getSource().sendError(new LiteralText("Failed to update pronouns, sorry"));
|
||||
} else {
|
||||
ctx.getSource().sendFeedback(new LiteralText("Cleared your pronouns!")
|
||||
.formatted(Formatting.GREEN), false);
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -36,9 +36,13 @@ public class PalettePronounDatabase implements PronounDatabase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void put(UUID player, Pronouns pronouns) {
|
||||
public void put(UUID player, @Nullable Pronouns pronouns) {
|
||||
if (pronouns == null) {
|
||||
this.data.remove(player);
|
||||
} else {
|
||||
this.data.put(player, pronouns);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Pronouns get(UUID player) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.nio.file.Path;
|
|||
import java.util.UUID;
|
||||
|
||||
public interface PronounDatabase {
|
||||
void put(UUID player, Pronouns pronouns);
|
||||
void put(UUID player, @Nullable Pronouns pronouns);
|
||||
@Nullable Pronouns get(UUID player);
|
||||
void save(Path path) throws IOException;
|
||||
|
||||
|
|
Loading…
Reference in a new issue