From 3909b53823d49a34b4fb9cb7e01c67de798ce230 Mon Sep 17 00:00:00 2001 From: Ashhhleyyy Date: Sat, 22 Jan 2022 11:21:14 +0000 Subject: [PATCH] feat: Add /pronouns unset command --- .../ashisbored/playerpronouns/PlayerPronouns.java | 3 ++- .../playerpronouns/command/PronounsCommand.java | 11 +++++++++++ .../playerpronouns/data/PalettePronounDatabase.java | 8 ++++++-- .../playerpronouns/data/PronounDatabase.java | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/ashisbored/playerpronouns/PlayerPronouns.java b/src/main/java/io/github/ashisbored/playerpronouns/PlayerPronouns.java index 4717fbe..6c965dd 100644 --- a/src/main/java/io/github/ashisbored/playerpronouns/PlayerPronouns.java +++ b/src/main/java/io/github/ashisbored/playerpronouns/PlayerPronouns.java @@ -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); diff --git a/src/main/java/io/github/ashisbored/playerpronouns/command/PronounsCommand.java b/src/main/java/io/github/ashisbored/playerpronouns/command/PronounsCommand.java index adca34a..c9b481f 100644 --- a/src/main/java/io/github/ashisbored/playerpronouns/command/PronounsCommand.java +++ b/src/main/java/io/github/ashisbored/playerpronouns/command/PronounsCommand.java @@ -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; + }) ) ); } diff --git a/src/main/java/io/github/ashisbored/playerpronouns/data/PalettePronounDatabase.java b/src/main/java/io/github/ashisbored/playerpronouns/data/PalettePronounDatabase.java index 154886f..15201fd 100644 --- a/src/main/java/io/github/ashisbored/playerpronouns/data/PalettePronounDatabase.java +++ b/src/main/java/io/github/ashisbored/playerpronouns/data/PalettePronounDatabase.java @@ -36,8 +36,12 @@ public class PalettePronounDatabase implements PronounDatabase { } @Override - public void put(UUID player, Pronouns pronouns) { - this.data.put(player, pronouns); + public void put(UUID player, @Nullable Pronouns pronouns) { + if (pronouns == null) { + this.data.remove(player); + } else { + this.data.put(player, pronouns); + } } @Override diff --git a/src/main/java/io/github/ashisbored/playerpronouns/data/PronounDatabase.java b/src/main/java/io/github/ashisbored/playerpronouns/data/PronounDatabase.java index 13b7fd3..685b410 100644 --- a/src/main/java/io/github/ashisbored/playerpronouns/data/PronounDatabase.java +++ b/src/main/java/io/github/ashisbored/playerpronouns/data/PronounDatabase.java @@ -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;