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;