feat: Add /pronouns unset command

This commit is contained in:
Ashhhleyyy 2022-01-22 11:21:14 +00:00
parent c860c116b6
commit 3909b53823
Signed by: ash
GPG key ID: 83B789081A0878FB
4 changed files with 20 additions and 4 deletions

View file

@ -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);

View file

@ -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;
})
)
);
}

View file

@ -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) {

View file

@ -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;