Tried to add a progress book which only shows the quest progress upon using a command.
This commit is contained in:
parent
e85e79c801
commit
0a0c4ffb98
|
|
@ -35,7 +35,8 @@ public class CommandManager implements CommandExecutor, TabExecutor {
|
|||
new CommandChangeQuest(),
|
||||
new CommandTurnIn(),
|
||||
new CommandSetQuest(),
|
||||
new CommandGetReward());
|
||||
new CommandGetReward(),
|
||||
new CommandProgress());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,15 +1,55 @@
|
|||
package com.alttd.altitudequests.commands.subcommands;
|
||||
|
||||
import com.alttd.altitudequests.AQuest;
|
||||
import com.alttd.altitudequests.commands.SubCommand;
|
||||
import com.alttd.altitudequests.config.MessagesConfig;
|
||||
import com.alttd.altitudequests.objects.Quest;
|
||||
import com.alttd.altitudequests.util.ProgressBookOpener;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandProgress extends SubCommand {
|
||||
//TODO show player current quest progress
|
||||
|
||||
private static final Set<UUID> inProcess = new HashSet<>();
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
return false;
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMiniMessage(MessagesConfig.NO_CONSOLE, null);
|
||||
return true;
|
||||
}
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
commandSender.sendMiniMessage(getHelpMessage(), null);
|
||||
return true;
|
||||
}
|
||||
Quest dailyQuest = Quest.getDailyQuest(player.getUniqueId());
|
||||
if (dailyQuest == null) {
|
||||
player.sendMiniMessage("<red>You have no active quests.</red>", null);
|
||||
return true;
|
||||
}
|
||||
if (dailyQuest.isDone()) {
|
||||
player.sendMiniMessage("<green>You already completed the daily quest.</green>", null);
|
||||
return true;
|
||||
}
|
||||
final UUID uniqueId = player.getUniqueId();
|
||||
if (inProcess.contains(uniqueId)) {
|
||||
return true;
|
||||
}
|
||||
inProcess.add(uniqueId);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ProgressBookOpener.openProgressBook(player);
|
||||
inProcess.remove(uniqueId);
|
||||
}
|
||||
}.runTaskAsynchronously(AQuest.getInstance());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ public final class Config extends AbstractConfig {
|
|||
|
||||
public static String QUEST_BOOK_AUTHOR = "<magenta>Scruff</magenta>";
|
||||
public static String QUEST_BOOK_TITLE = "<green>Quest Title</green>";
|
||||
public static String PRGORESS_BOOK_AUTHOR = "<magenta>Scruff</magenta>";
|
||||
public static String PROGRESS_BOOK_TITLE = "<green>Quest Title</green>";
|
||||
public static List<String> QUEST_PAGES = List.of("""
|
||||
<bold><gold>Hey <player></gold></bold>
|
||||
|
||||
|
|
@ -31,6 +33,16 @@ public final class Config extends AbstractConfig {
|
|||
* <step_2>: <step_2_progress>/<step_2_total>
|
||||
|
||||
<click:run_command:/aquest turnin><turn_in_text></click>
|
||||
""");
|
||||
public static List<String> PROGRESS_PAGES = List.of("""
|
||||
<bold><gold>Hey <player></gold></bold>
|
||||
|
||||
Your quest progress:
|
||||
* Quest: <quest>
|
||||
* Type: <variant>
|
||||
* <step_1>: <step_1_progress>/<step_1_total>
|
||||
* <step_2>: <step_2_progress>/<step_2_total>
|
||||
|
||||
""");
|
||||
private static void loadBook() {
|
||||
QUEST_BOOK_AUTHOR = config.getString("book.author", QUEST_BOOK_AUTHOR);
|
||||
|
|
@ -38,6 +50,12 @@ public final class Config extends AbstractConfig {
|
|||
QUEST_PAGES = config.getStringList("book.pages", QUEST_PAGES);
|
||||
}
|
||||
|
||||
private static void loadProgressBook() {
|
||||
QUEST_BOOK_AUTHOR = config.getString("progressBook.author", PRGORESS_BOOK_AUTHOR);
|
||||
QUEST_BOOK_TITLE = config.getString("progressBook.title", PROGRESS_BOOK_TITLE);
|
||||
QUEST_PAGES = config.getStringList("progressBook.pages", PROGRESS_PAGES);
|
||||
}
|
||||
|
||||
public static String NPC_NAME = "<light_purple>Scruff</light_purple>";
|
||||
public static boolean DEBUG = false;
|
||||
private static void loadSettings() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
package com.alttd.altitudequests.util;
|
||||
|
||||
import com.alttd.altitudequests.config.Config;
|
||||
import com.alttd.altitudequests.objects.Quest;
|
||||
import net.kyori.adventure.inventory.Book;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ProgressBookOpener {
|
||||
|
||||
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
public static void openProgressBook(Player player) {
|
||||
player.openBook(getProgressBook(player));
|
||||
}
|
||||
|
||||
private static Book getProgressBook (Player player) {
|
||||
return Book.builder()
|
||||
.author(miniMessage.deserialize(Config.PRGORESS_BOOK_AUTHOR))
|
||||
.title(miniMessage.deserialize(Config.PROGRESS_BOOK_TITLE))
|
||||
.pages(getPages(player))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static final Component error = MiniMessage.miniMessage().deserialize("<red>Error retrieving quest data</red>");
|
||||
private static List<Component> getPages(Player player) {
|
||||
Quest dailyQuest = Quest.getDailyQuest(player.getUniqueId());
|
||||
if (dailyQuest == null)
|
||||
return List.of(error);
|
||||
TagResolver tagResolver = TagResolver.resolver(
|
||||
TagResolver.resolver(Placeholder.component("player", player.name())),
|
||||
TagResolver.resolver(Placeholder.component("quest", dailyQuest.getDisplayName())),
|
||||
TagResolver.resolver(Placeholder.component("variant", dailyQuest.getVariant().getName())),
|
||||
dailyQuest.getTagResolvers()
|
||||
);
|
||||
List<String> pages = new ArrayList<>();
|
||||
if (dailyQuest.isDone())
|
||||
pages.addAll(dailyQuest.getDonePages());
|
||||
else
|
||||
pages.addAll(dailyQuest.getQuestPages());
|
||||
pages.addAll(Config.PROGRESS_PAGES);
|
||||
return (pages.stream()
|
||||
.map(page -> miniMessage.deserialize(page, tagResolver))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user