From ca1dc7c0b1b4bb0123bae474aeb531b820ed2b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Sat, 22 Oct 2022 16:11:37 +0200 Subject: [PATCH] Implement "set" subcommand --- .../nounspicker/commands/NounsCommand.java | 7 ++++ .../subcommands/NounsSetSubCommand.java | 38 +++++++++++++++++++ .../beatrice/nounspicker/objects/Cache.java | 28 ++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsSetSubCommand.java create mode 100644 src/main/java/wtf/beatrice/nounspicker/objects/Cache.java diff --git a/src/main/java/wtf/beatrice/nounspicker/commands/NounsCommand.java b/src/main/java/wtf/beatrice/nounspicker/commands/NounsCommand.java index 718980b..578b2af 100644 --- a/src/main/java/wtf/beatrice/nounspicker/commands/NounsCommand.java +++ b/src/main/java/wtf/beatrice/nounspicker/commands/NounsCommand.java @@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import wtf.beatrice.nounspicker.NounsPicker; +import wtf.beatrice.nounspicker.commands.subcommands.NounsSetSubCommand; public class NounsCommand implements CommandExecutor { @@ -28,6 +29,12 @@ public class NounsCommand implements CommandExecutor return true; } + switch(args[0].toLowerCase()) + { + case "set": + return NounsSetSubCommand.run(sender, args); + } + return false; } diff --git a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsSetSubCommand.java b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsSetSubCommand.java new file mode 100644 index 0000000..bbc6f75 --- /dev/null +++ b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsSetSubCommand.java @@ -0,0 +1,38 @@ +package wtf.beatrice.nounspicker.commands.subcommands; + +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import wtf.beatrice.nounspicker.objects.Cache; + +public class NounsSetSubCommand +{ + public static boolean run(@NotNull CommandSender sender, + @NotNull String[] args) + { + + if(args.length < 3) + { + sender.sendMessage("usage: /nouns set
"); + return true; + } + + String mainPronoun = args[1].toLowerCase(); + String secondaryPronoun = args[2].toLowerCase(); + + if(!Cache.isPronounValid(mainPronoun)) + { + sender.sendMessage("Invalid main pronoun!"); + return true; + } + + if(!Cache.isPronounValid(secondaryPronoun)) + { + sender.sendMessage("Invalid secondary pronoun!"); + return true; + } + + // todo: add to sqlite + + return true; + } +} diff --git a/src/main/java/wtf/beatrice/nounspicker/objects/Cache.java b/src/main/java/wtf/beatrice/nounspicker/objects/Cache.java new file mode 100644 index 0000000..60d64d7 --- /dev/null +++ b/src/main/java/wtf/beatrice/nounspicker/objects/Cache.java @@ -0,0 +1,28 @@ +package wtf.beatrice.nounspicker.objects; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; + +public class Cache +{ + + // map to store pronouns' "raw" names and how they appear in game. + private static final HashMap pronouns = new HashMap<>(); + + public static @Nullable String getPronoun(String pronoun) + { + return pronouns.get(pronoun); + } + + public static void addPronoun(@NotNull String pronoun, @NotNull String appearance) + { + pronouns.put(pronoun, appearance); + } + + public static boolean isPronounValid(String pronoun) + { + return getPronoun(pronoun) != null; + } +}