Cleaner quest accept prompt input

This commit is contained in:
PikaMug 2023-03-19 15:29:45 -04:00
parent 49392e5d1c
commit c5a753e19e
3 changed files with 13 additions and 29 deletions

View File

@ -172,8 +172,7 @@ public interface IQuester extends Comparable<IQuester> {
void smeltItem(final IQuest quest, final ItemStack itemStack);
void enchantBook(final IQuest quest, final ItemStack itemStack,
final Map<Enchantment, Integer> enchantsToAdd);
void enchantBook(final IQuest quest, final ItemStack itemStack, final Map<Enchantment, Integer> enchantsToAdd);
void enchantItem(final IQuest quest, final ItemStack itemStack);

View File

@ -492,12 +492,9 @@ public class Quests extends JavaPlugin implements QuestsAPI {
* Get Quester from player UUID
*
* @param id Player UUID
* @return Quester, or null if UUID is null
* @return new or existing Quester
*/
public Quester getQuester(final UUID id) {
if (id == null) {
return null;
}
public Quester getQuester(final @NotNull UUID id) {
final ConcurrentSkipListSet<IQuester> set = (ConcurrentSkipListSet<IQuester>) questers;
for (final IQuester q : set) {
if (q != null && q.getUUID().equals(id)) {
@ -738,28 +735,15 @@ public class Quests extends JavaPlugin implements QuestsAPI {
final Player player = (Player) context.getForWhom();
if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase("y")
|| input.equalsIgnoreCase(Lang.get(player, "yesWord"))) {
IQuester quester = getQuester(player.getUniqueId());
if (quester == null) {
// Must be new player
quester = new Quester(Quests.this, player.getUniqueId());
if (quester.saveData()) {
getLogger().info("Created new data for player " + player.getName());
} else {
Lang.send(player, ChatColor.RED + Lang.get(player, "questSaveError"));
}
}
final IQuester quester = getQuester(player.getUniqueId());
final String questIdToTake = quester.getQuestIdToTake();
try {
if (getQuestByIdTemp(questIdToTake) == null) {
getLogger().info(player.getName() + " attempted to take quest ID \"" + questIdToTake
+ "\" but something went wrong");
player.sendMessage(ChatColor.RED
+ "Something went wrong! Please report issue to an administrator.");
} else {
getQuester(player.getUniqueId()).takeQuest(getQuestByIdTemp(questIdToTake), false);
}
} catch (final Exception e) {
e.printStackTrace();
if (getQuestByIdTemp(questIdToTake) == null) {
getLogger().warning(player.getName() + " attempted to take quest ID \"" + questIdToTake
+ "\" but something went wrong");
player.sendMessage(ChatColor.RED
+ "Something went wrong! Please report issue to an administrator.");
} else {
quester.takeQuest(getQuestByIdTemp(questIdToTake), false);
}
return Prompt.END_OF_CONVERSATION;
} else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase("n")

View File

@ -27,6 +27,7 @@ import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.text.MessageFormat;
@ -132,7 +133,7 @@ public class NpcOfferQuestPrompt extends MiscStringPrompt {
@SuppressWarnings("unchecked")
@Override
public @Nonnull String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
this.context = context;
final LinkedList<Quest> quests = (LinkedList<Quest>) context.getSessionData("npcQuests");
final String npc = (String) context.getSessionData("npc");