Implement "set" subcommand
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2022-10-22 16:11:37 +02:00
parent 6789c757e1
commit ca1dc7c0b1
3 changed files with 73 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import wtf.beatrice.nounspicker.NounsPicker; import wtf.beatrice.nounspicker.NounsPicker;
import wtf.beatrice.nounspicker.commands.subcommands.NounsSetSubCommand;
public class NounsCommand implements CommandExecutor public class NounsCommand implements CommandExecutor
{ {
@ -28,6 +29,12 @@ public class NounsCommand implements CommandExecutor
return true; return true;
} }
switch(args[0].toLowerCase())
{
case "set":
return NounsSetSubCommand.run(sender, args);
}
return false; return false;
} }

View File

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

View File

@ -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<String, String> 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;
}
}