From aacea63b0c20fcc6c9650f6e48a185e0f09eb987 Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Sat, 31 May 2025 18:37:10 +0200 Subject: [PATCH 01/19] Progress --- .../listeners/PlayerListener.java | 4 +- .../managers/QuestCompassGui.java | 205 ++++++++++++++++++ .../managers/QuestCompassManager.java | 60 +++-- .../scriptedquests/utils/CustomInventory.java | 2 +- 4 files changed, 248 insertions(+), 23 deletions(-) create mode 100644 plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java index 4c39392d..b6072fba 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java @@ -2,6 +2,8 @@ import com.playmonumenta.scriptedquests.Constants; import com.playmonumenta.scriptedquests.Plugin; +import com.playmonumenta.scriptedquests.managers.QuestCompassGui; +import com.playmonumenta.scriptedquests.managers.QuestCompassManager; import com.playmonumenta.scriptedquests.managers.SongManager; import com.playmonumenta.scriptedquests.point.Point; import com.playmonumenta.scriptedquests.quests.QuestDeath.DeathActions; @@ -70,7 +72,7 @@ public void playerInteractEvent(PlayerInteractEvent event) { if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) { mPlugin.mQuestCompassManager.showCurrentQuest(player); } else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { - mPlugin.mQuestCompassManager.cycleQuestTracker(player); + new QuestCompassGui(player, mPlugin.mQuestCompassManager).openInventory(player, mPlugin); } } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java new file mode 100644 index 00000000..302fe9d3 --- /dev/null +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -0,0 +1,205 @@ +package com.playmonumenta.scriptedquests.managers; + +import com.playmonumenta.scriptedquests.utils.CustomInventory; +import com.playmonumenta.scriptedquests.utils.InventoryUtils; +import com.playmonumenta.scriptedquests.managers.QuestCompassManager.ValidCompassEntry; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; +import org.apache.commons.lang3.StringUtils; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class QuestCompassGui extends CustomInventory { + private final Player mPlayer; + private final QuestCompassManager mManager; + + public QuestCompassGui(Player player, QuestCompassManager manager) { + super(player, 36, "Quest Compass"); + mPlayer = player; + mManager = manager; + } + + @Override + public void openInventory(Player player, org.bukkit.plugin.Plugin owner) { + super.openInventory(player, owner); + setupInventory(); + } + + private void setupInventory() { + mInventory.clear(); + mPlayer.playSound(mPlayer.getLocation(), Sound.UI_LOOM_SELECT_PATTERN, SoundCategory.PLAYERS, 1f, 1f); + + ItemStack info = new ItemStack(Material.COMPASS); + ItemMeta infoMeta = info.getItemMeta(); + infoMeta.displayName(Component.text("Quest Compass", NamedTextColor.RED).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + infoMeta.lore(List.of(Component.text("Left click on a quest to track it.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), + Component.text("More instructions later", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); + info.setItemMeta(infoMeta); + mInventory.setItem(4, info); + + ItemStack guides = new ItemStack(Material.SCUTE); + ItemMeta guidesMeta = guides.getItemMeta(); + guidesMeta.displayName(Component.text("Quest Guides", NamedTextColor.GOLD).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + guidesMeta.lore(List.of(Component.text("Click to see available quests", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), + Component.text("across Monumenta by region and", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), + Component.text("town.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); + guides.setItemMeta(guidesMeta); + mInventory.setItem(3, guides); + + ItemStack hidden = new ItemStack(Material.CAULDRON); + ItemMeta hiddenMeta = guides.getItemMeta(); + hiddenMeta.displayName(Component.text("Hidden Quests", NamedTextColor.DARK_GREEN).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + hiddenMeta.lore(List.of(Component.text("Instructions", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); + hidden.setItemMeta(hiddenMeta); + mInventory.setItem(5, hidden); + + List quests = mManager.getCurrentMarkerTitles(mPlayer); + + for (int i = 0; i < quests.size(); i++) { + if (i > 20) { + return; + } + + ValidCompassEntry quest = quests.get(i); + + ItemStack displayItem; + + NamedTextColor titleColor; + NamedTextColor selectedColor = NamedTextColor.DARK_AQUA; + if (quest.mType == QuestCompassManager.CompassEntryType.Death) { + titleColor = NamedTextColor.RED; + } else if (quest.mType == QuestCompassManager.CompassEntryType.Waypoint) { + titleColor = NamedTextColor.GREEN; + } else { + titleColor = NamedTextColor.AQUA; + } + + String title = StringUtils.remove(quest.mTitle, "&a&l"); + + Component itemName = Component.text(title, titleColor).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false); + + int slot = i + 10; + Material material; + if (mManager.mCurrentIndex.getOrDefault(mPlayer, 0) == i) { + switch (quest.mType) { + default -> material = Material.ENCHANTED_BOOK; + case Death -> material = Material.ARMOR_STAND; + case Waypoint -> material = Material.KNOWLEDGE_BOOK; + } + itemName = itemName.append(Component.text(" [Currently Tracking]", selectedColor).decoration(TextDecoration.BOLD, false).decoration(TextDecoration.ITALIC, false)); + } else { + switch (quest.mType) { + default -> material = Material.BOOK; + case Death -> material = Material.ARMOR_STAND; + case Waypoint -> material = Material.KNOWLEDGE_BOOK; + } + } + + slot += (int) (2 * Math.floor((double) (slot - 8) / 9)); + + displayItem = new ItemStack(material); + ItemMeta meta = displayItem.getItemMeta(); + meta.displayName(itemName); + + // Add quest index tag + meta.setCustomModelData(i); + + List lore2 = new ArrayList<>(); + + + for (int j = i + 1 - quest.mMarkersIndex[0]; j < quest.mMarkersIndex[1]; j++) { + int splitIndex = 0; + ValidCompassEntry q = quests.get(j); + String lore = StringUtils.remove(q.mLocation.getMessage(), "&a"); + while (splitIndex < lore.length() && !(j != i && splitIndex > 0)) { + lore2.add(Component.text(StringUtils.substring(lore, splitIndex, lore.indexOf(" ", splitIndex + 45) < 0 ? 1000 : lore.indexOf(" ", splitIndex + 45)) + (j != i && lore.indexOf(" ", splitIndex + 45) > 0 ? " {...}" : ""), j == i ? NamedTextColor.WHITE : NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); + if (lore.indexOf(" ", splitIndex + 45) < 0) { + splitIndex += 1000; + } else { + splitIndex = 1 + lore.indexOf(" ", splitIndex + 45); + } + } + lore2.add(Component.text((int) q.mLocation.getLocation().getX() + ", " + (int) q.mLocation.getLocation().getY() + ", " + (int) q.mLocation.getLocation().getZ() + " (" + (int) mPlayer.getLocation().distance(q.mLocation.getLocation()) + "m away)", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false)); + if (j + 1 != q.mMarkersIndex[1]) { + lore2.add(Component.text("")); + } + } + + // Find out if this quest has multiple markers. If it does, removing the last 6 characters of mTitle will match the QuestCompass title +// for (QuestCompass q : mManager.mQuests) { +// if (q.getQuestName().equals(StringUtils.substringBefore(title, title.length() - 6))) { +// for (CompassLocation cLoc : q.getMarkers(mPlayer)) { +// int splitIndex = 0; +// while (splitIndex < lore.length()) { +// lore2.add(Component.text(StringUtils.substring(lore, splitIndex, lore.indexOf(" ", splitIndex + 45) < 0 ? 1000 : lore.indexOf(" ", splitIndex + 45)), cLoc.getLocation().equals(quest.mLocation.getLocation()) ? NamedTextColor.WHITE : NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); +// if (lore.indexOf(" ", splitIndex + 45) < 0) { +// splitIndex += 1000; +// } else { +// splitIndex = 1 + lore.indexOf(" ", splitIndex + 45); +// } +// } +// lore2.add(Component.text((int) cLoc.getLocation().getX() + ", " + (int) cLoc.getLocation().getY() + ", " + (int) cLoc.getLocation().getZ() + " (" + (int) mPlayer.getLocation().distance(cLoc.getLocation()) + "m away)", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false)); +// lore2.add(Component.text("")); +// } +// } else if (q.getQuestName().equals(title)) { +// int splitIndex = 0; +// while (splitIndex < lore.length()) { +// lore2.add(Component.text(StringUtils.substring(lore, splitIndex, lore.indexOf(" ", splitIndex + 45) < 0 ? 1000 : lore.indexOf(" ", splitIndex + 45)), NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); +// if (lore.indexOf(" ", splitIndex + 45) < 0) { +// splitIndex += 1000; +// } else { +// splitIndex = 1 + lore.indexOf(" ", splitIndex + 45); +// } +// } +// lore2.add(Component.text((int) quest.mLocation.getLocation().getX() + ", " + (int) quest.mLocation.getLocation().getY() + ", " + (int) quest.mLocation.getLocation().getZ() + " (" + (int) mPlayer.getLocation().distance(quest.mLocation.getLocation()) + "m away)", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false)); +// lore2.add(Component.text("")); +// } +// } + + meta.lore(lore2); + displayItem.setItemMeta(meta); + + mInventory.setItem(slot, displayItem); + } + } + + @Override + protected void inventoryClick(InventoryClickEvent event) { + event.setCancelled(true); + InventoryUtils.refreshOffhand(event); + if ((event.getClick() != ClickType.LEFT && event.getClick() != ClickType.RIGHT) + || !(event.getWhoClicked() instanceof Player player) + || event.getClickedInventory() != mInventory + || event.getInventory().getItem(event.getSlot()) == null) { + return; + } + if (event.getSlot() == 3) { + mPlayer.performCommand("sqgui show regionqg @s"); + return; + } + + mPlayer.playSound(mPlayer.getLocation(), Sound.UI_LOOM_TAKE_RESULT, SoundCategory.PLAYERS, 1f, 1f); + + int index = Objects.requireNonNull(event.getInventory().getItem(event.getSlot())).getItemMeta().getCustomModelData(); + mManager.mCurrentIndex.put(mPlayer, mManager.showCurrentQuest(player, index)); + close(); + } + + @Override + protected void inventoryClose(InventoryCloseEvent event) { + // Something later + } +} + diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index 5de435da..0ddbe454 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -24,26 +24,38 @@ public class QuestCompassManager { - private final List mQuests = new ArrayList(); - private final Map mCompassCache = new HashMap(); - private final Map mCurrentIndex = new WeakHashMap<>(); - private final Plugin mPlugin; + public final List mQuests = new ArrayList(); + public final Map mCompassCache = new HashMap(); + public final Map mCurrentIndex = new WeakHashMap<>(); + public final Plugin mPlugin; /* One command-specified waypoint per player */ public final Map mCommandWaypoints = new HashMap(); - private static class ValidCompassEntry { - private final QuestLocation mLocation; - private final String mTitle; - private final boolean mAllowTranslations; + public static class ValidCompassEntry { + public final QuestLocation mLocation; + public final String mTitle; + public final boolean mAllowTranslations; + public final CompassEntryType mType; + public final int[] mMarkersIndex; - private ValidCompassEntry(QuestLocation loc, String title, boolean allowTranslations) { + public ValidCompassEntry(QuestLocation loc, String title, boolean allowTranslations, CompassEntryType type) { mLocation = loc; mTitle = title; mAllowTranslations = allowTranslations; + mType = type; + mMarkersIndex = new int[]{1, 1}; } - private void directPlayer(WaypointManager mgr, Player player, boolean isRemovable) { + public ValidCompassEntry(QuestLocation loc, String title, boolean allowTranslations, CompassEntryType type, int[] markersIndex) { + mLocation = loc; + mTitle = title; + mAllowTranslations = allowTranslations; + mType = type; + mMarkersIndex = markersIndex; + } + + public void directPlayer(WaypointManager mgr, Player player, boolean isRemovable) { if (isRemovable) { MessagingUtils.sendClickableMessage(player, mTitle + ": " + mLocation.getMessage(), mAllowTranslations, "/waypoint remove @s", HoverEvent.showText(Component.text("Click to remove this waypoint."))); } else { @@ -53,16 +65,22 @@ private void directPlayer(WaypointManager mgr, Player player, boolean isRemovabl } } - private static class CompassCacheEntry { - private final int mLastRefresh; - private final List mEntries; + public enum CompassEntryType { + Quest(), + Death(), + Waypoint() + } + + public static class CompassCacheEntry { + public final int mLastRefresh; + public final List mEntries; - private CompassCacheEntry(Player player, List entries) { + public CompassCacheEntry(Player player, List entries) { mLastRefresh = player.getTicksLived(); mEntries = entries; } - private boolean isStillValid(Player player) { + public boolean isStillValid(Player player) { return Math.abs(player.getTicksLived() - mLastRefresh) < 200; } } @@ -85,7 +103,7 @@ public void reload(Plugin plugin, @Nullable CommandSender sender) { } @SuppressWarnings("unchecked") - private List getCurrentMarkerTitles(Player player) { + public List getCurrentMarkerTitles(Player player) { /* * First check the cache - if it is still valid, returned the cached data * This dramatically improves performance when there are many compass entries @@ -112,7 +130,7 @@ private List getCurrentMarkerTitles(Player player) { title += " [" + (i + 1) + "/" + questMarkers.size() + "]"; } - entries.add(new ValidCompassEntry(questMarkers.get(i), title, true)); + entries.add(new ValidCompassEntry(questMarkers.get(i), title, true, CompassEntryType.Quest, new int[]{i + 1, questMarkers.size()})); } } @@ -128,7 +146,7 @@ private List getCurrentMarkerTitles(Player player) { title += " [" + (i + 1) + "/" + deathEntries.size() + "]"; } - entries.add(new ValidCompassEntry(deathEntries.get(i), title, false)); + entries.add(new ValidCompassEntry(deathEntries.get(i), title, false, CompassEntryType.Death)); } } @@ -144,7 +162,7 @@ private List getCurrentMarkerTitles(Player player) { return entries; } - private int showCurrentQuest(Player player, int index) { + public int showCurrentQuest(Player player, int index) { List entries = getCurrentMarkerTitles(player); if (index >= entries.size()) { @@ -178,9 +196,9 @@ public void cycleQuestTracker(Player player) { /* One command-specified waypoint per player */ public void setCommandWaypoint(Player player, List steps, String title, String message) { - ValidCompassEntry entry = new ValidCompassEntry(new CompassLocation(null, message, steps), title, false); + ValidCompassEntry entry = new ValidCompassEntry(new CompassLocation(null, message, steps), title, false, CompassEntryType.Waypoint); mCommandWaypoints.put(player.getUniqueId(), entry); - getCurrentMarkerTitles(player); + mCurrentIndex.put(player, getCurrentMarkerTitles(player).indexOf(mCommandWaypoints.get(player.getUniqueId()))); entry.directPlayer(mPlugin.mWaypointManager, player, true); } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/CustomInventory.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/CustomInventory.java index cc07dd80..8e211935 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/CustomInventory.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/CustomInventory.java @@ -108,7 +108,7 @@ public CustomInventory(Player owner, int size, Component title) { mInventory = Bukkit.createInventory(owner, size, title); } - public final void openInventory(Player player, Plugin owner) { + public void openInventory(Player player, Plugin owner) { if (mOwner == null) { player.openInventory(mInventory); mOpenedInvsByPlayer.put(player, this); From 8371df2da4dbe42962c8d1126a296428fc6e4082 Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Sun, 1 Jun 2025 00:23:01 +0200 Subject: [PATCH 02/19] more progress --- .../managers/QuestCompassGui.java | 115 +++++++++--------- .../managers/QuestCompassManager.java | 6 +- 2 files changed, 62 insertions(+), 59 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 302fe9d3..77ff621c 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; - import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; @@ -15,7 +14,6 @@ import org.bukkit.Sound; import org.bukkit.SoundCategory; import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.ItemStack; @@ -26,7 +24,9 @@ public class QuestCompassGui extends CustomInventory { private final QuestCompassManager mManager; public QuestCompassGui(Player player, QuestCompassManager manager) { - super(player, 36, "Quest Compass"); + super(player, Math.min(36 + 9 * (manager.getCurrentMarkerTitles(player).stream().filter( + q -> q.mType != QuestCompassManager.CompassEntryType.Death && q.mType != QuestCompassManager.CompassEntryType.Waypoint).toList().size() / 7), 54), + "Quest Compass"); mPlayer = player; mManager = manager; } @@ -34,12 +34,13 @@ public QuestCompassGui(Player player, QuestCompassManager manager) { @Override public void openInventory(Player player, org.bukkit.plugin.Plugin owner) { super.openInventory(player, owner); + player.playSound(player.getLocation(), Sound.UI_LOOM_SELECT_PATTERN, SoundCategory.PLAYERS, 1f, 1f); setupInventory(); } private void setupInventory() { mInventory.clear(); - mPlayer.playSound(mPlayer.getLocation(), Sound.UI_LOOM_SELECT_PATTERN, SoundCategory.PLAYERS, 1f, 1f); + int rows = mInventory.getSize() / 9; ItemStack info = new ItemStack(Material.COMPASS); ItemMeta infoMeta = info.getItemMeta(); @@ -60,11 +61,28 @@ private void setupInventory() { ItemStack hidden = new ItemStack(Material.CAULDRON); ItemMeta hiddenMeta = guides.getItemMeta(); - hiddenMeta.displayName(Component.text("Hidden Quests", NamedTextColor.DARK_GREEN).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + hiddenMeta.displayName(Component.text("Hidden Quests", NamedTextColor.DARK_PURPLE).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); hiddenMeta.lore(List.of(Component.text("Instructions", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); hidden.setItemMeta(hiddenMeta); mInventory.setItem(5, hidden); + ItemStack death = new ItemStack(Material.SKULL_POTTERY_SHERD); + ItemMeta deathMeta = death.getItemMeta(); + deathMeta.displayName(Component.text("Death Waypoints", NamedTextColor.DARK_RED).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + deathMeta.lore(List.of(Component.text("No recent death to show here.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); + death.setItemMeta(deathMeta); + mInventory.setItem(32 + 9 * (rows - 4), death); + mInventory.setItem(33 + 9 * (rows - 4), death); + mInventory.setItem(34 + 9 * (rows - 4), death); + + ItemStack custom = new ItemStack(Material.LODESTONE); + ItemMeta customMeta = custom.getItemMeta(); + customMeta.displayName(Component.text("Custom Waypoint", NamedTextColor.DARK_GREEN).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + customMeta.lore(List.of(Component.text("No custom waypoint set. Waypoints can be set through", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), + Component.text("Quest Guides, /waypoint, or by other special means.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); + custom.setItemMeta(customMeta); + mInventory.setItem(29 + 9 * (rows - 4), custom); + List quests = mManager.getCurrentMarkerTitles(mPlayer); for (int i = 0; i < quests.size(); i++) { @@ -108,67 +126,43 @@ private void setupInventory() { } slot += (int) (2 * Math.floor((double) (slot - 8) / 9)); + if (quest.mType == QuestCompassManager.CompassEntryType.Death) { + slot = 31 + quest.mMarkersIndex[0] + 9 * (rows - 4); + } else if (quest.mType == QuestCompassManager.CompassEntryType.Waypoint) { + slot = 29 + 9 * (rows - 4); + } displayItem = new ItemStack(material); ItemMeta meta = displayItem.getItemMeta(); meta.displayName(itemName); - // Add quest index tag + // Use this as a quest index tag for inventoryClick to easily identify quest index meta.setCustomModelData(i); - List lore2 = new ArrayList<>(); - - - for (int j = i + 1 - quest.mMarkersIndex[0]; j < quest.mMarkersIndex[1]; j++) { + // Compile all steps and highlight the one that matches this quest index (j == i) + List lore = new ArrayList<>(); + for (int j = i + 1 - quest.mMarkersIndex[0]; j < i + 1 - quest.mMarkersIndex[0] + quest.mMarkersIndex[1]; j++) { int splitIndex = 0; ValidCompassEntry q = quests.get(j); - String lore = StringUtils.remove(q.mLocation.getMessage(), "&a"); - while (splitIndex < lore.length() && !(j != i && splitIndex > 0)) { - lore2.add(Component.text(StringUtils.substring(lore, splitIndex, lore.indexOf(" ", splitIndex + 45) < 0 ? 1000 : lore.indexOf(" ", splitIndex + 45)) + (j != i && lore.indexOf(" ", splitIndex + 45) > 0 ? " {...}" : ""), j == i ? NamedTextColor.WHITE : NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); - if (lore.indexOf(" ", splitIndex + 45) < 0) { + String qLore = StringUtils.remove(q.mLocation.getMessage(), "&a"); + while (splitIndex < qLore.length() && !(j != i && splitIndex > 0)) { + lore.add(Component.text(StringUtils.substring(qLore, splitIndex, qLore.indexOf(" ", splitIndex + 45) < 0 ? 1000 : qLore.indexOf(" ", splitIndex + 45)) + (j != i && qLore.indexOf(" ", splitIndex + 45) > 0 ? " {...}" : ""), j == i ? NamedTextColor.WHITE : NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); + if (qLore.indexOf(" ", splitIndex + 45) < 0) { splitIndex += 1000; } else { - splitIndex = 1 + lore.indexOf(" ", splitIndex + 45); + splitIndex = 1 + qLore.indexOf(" ", splitIndex + 45); } } - lore2.add(Component.text((int) q.mLocation.getLocation().getX() + ", " + (int) q.mLocation.getLocation().getY() + ", " + (int) q.mLocation.getLocation().getZ() + " (" + (int) mPlayer.getLocation().distance(q.mLocation.getLocation()) + "m away)", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false)); - if (j + 1 != q.mMarkersIndex[1]) { - lore2.add(Component.text("")); + lore.add(Component.text((int) q.mLocation.getLocation().getX() + ", " + (int) q.mLocation.getLocation().getY() + ", " + (int) q.mLocation.getLocation().getZ() + " (" + (int) mPlayer.getLocation().distance(q.mLocation.getLocation()) + "m away)", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false)); + if (q.mType == QuestCompassManager.CompassEntryType.Waypoint) { + lore.add(Component.text("(Shift Click to remove this waypoint.)", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); + } + if (j != i - quest.mMarkersIndex[0] + quest.mMarkersIndex[1]) { + lore.add(Component.text("")); } } - // Find out if this quest has multiple markers. If it does, removing the last 6 characters of mTitle will match the QuestCompass title -// for (QuestCompass q : mManager.mQuests) { -// if (q.getQuestName().equals(StringUtils.substringBefore(title, title.length() - 6))) { -// for (CompassLocation cLoc : q.getMarkers(mPlayer)) { -// int splitIndex = 0; -// while (splitIndex < lore.length()) { -// lore2.add(Component.text(StringUtils.substring(lore, splitIndex, lore.indexOf(" ", splitIndex + 45) < 0 ? 1000 : lore.indexOf(" ", splitIndex + 45)), cLoc.getLocation().equals(quest.mLocation.getLocation()) ? NamedTextColor.WHITE : NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); -// if (lore.indexOf(" ", splitIndex + 45) < 0) { -// splitIndex += 1000; -// } else { -// splitIndex = 1 + lore.indexOf(" ", splitIndex + 45); -// } -// } -// lore2.add(Component.text((int) cLoc.getLocation().getX() + ", " + (int) cLoc.getLocation().getY() + ", " + (int) cLoc.getLocation().getZ() + " (" + (int) mPlayer.getLocation().distance(cLoc.getLocation()) + "m away)", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false)); -// lore2.add(Component.text("")); -// } -// } else if (q.getQuestName().equals(title)) { -// int splitIndex = 0; -// while (splitIndex < lore.length()) { -// lore2.add(Component.text(StringUtils.substring(lore, splitIndex, lore.indexOf(" ", splitIndex + 45) < 0 ? 1000 : lore.indexOf(" ", splitIndex + 45)), NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); -// if (lore.indexOf(" ", splitIndex + 45) < 0) { -// splitIndex += 1000; -// } else { -// splitIndex = 1 + lore.indexOf(" ", splitIndex + 45); -// } -// } -// lore2.add(Component.text((int) quest.mLocation.getLocation().getX() + ", " + (int) quest.mLocation.getLocation().getY() + ", " + (int) quest.mLocation.getLocation().getZ() + " (" + (int) mPlayer.getLocation().distance(quest.mLocation.getLocation()) + "m away)", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false)); -// lore2.add(Component.text("")); -// } -// } - - meta.lore(lore2); + meta.lore(lore); displayItem.setItemMeta(meta); mInventory.setItem(slot, displayItem); @@ -179,21 +173,28 @@ private void setupInventory() { protected void inventoryClick(InventoryClickEvent event) { event.setCancelled(true); InventoryUtils.refreshOffhand(event); - if ((event.getClick() != ClickType.LEFT && event.getClick() != ClickType.RIGHT) - || !(event.getWhoClicked() instanceof Player player) + if (!(event.getWhoClicked() instanceof Player player) || event.getClickedInventory() != mInventory || event.getInventory().getItem(event.getSlot()) == null) { return; } if (event.getSlot() == 3) { - mPlayer.performCommand("sqgui show regionqg @s"); + player.performCommand("sqgui show regionqg @s"); + return; + } else if (event.getSlot() == 4 || event.getSlot() == 5) { + // Not implemented return; } - - mPlayer.playSound(mPlayer.getLocation(), Sound.UI_LOOM_TAKE_RESULT, SoundCategory.PLAYERS, 1f, 1f); - + // This is throwing a Lot of NullPointerExceptions - find a way to make it Not do that int index = Objects.requireNonNull(event.getInventory().getItem(event.getSlot())).getItemMeta().getCustomModelData(); - mManager.mCurrentIndex.put(mPlayer, mManager.showCurrentQuest(player, index)); + if (mManager.getCurrentMarkerTitles(player).get(index).mType == QuestCompassManager.CompassEntryType.Waypoint && event.isShiftClick()) { + mManager.removeCommandWaypoint(player); + player.playSound(player.getLocation(), "minecraft:entity.armadillo.scute_drop", SoundCategory.PLAYERS, 1f, 1f); + setupInventory(); + return; + } + mManager.mCurrentIndex.put(player, mManager.showCurrentQuest(player, index)); + player.playSound(player.getLocation(), Sound.UI_LOOM_TAKE_RESULT, SoundCategory.PLAYERS, 1f, 1f); close(); } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index 0ddbe454..be8fe541 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -14,6 +14,8 @@ import java.util.Map; import java.util.UUID; import java.util.WeakHashMap; + +import dev.jorel.commandapi.arguments.ChatColorArgument; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; import org.bukkit.ChatColor; @@ -146,7 +148,7 @@ public List getCurrentMarkerTitles(Player player) { title += " [" + (i + 1) + "/" + deathEntries.size() + "]"; } - entries.add(new ValidCompassEntry(deathEntries.get(i), title, false, CompassEntryType.Death)); + entries.add(new ValidCompassEntry(deathEntries.get(i), title, false, CompassEntryType.Death, new int[]{i + 1, deathEntries.size()})); } } @@ -206,8 +208,8 @@ public void setCommandWaypoint(Player player, List steps, String title public void removeCommandWaypoint(Player player) { if (mCommandWaypoints.containsKey(player.getUniqueId())) { mCommandWaypoints.remove(player.getUniqueId()); + invalidateCache(player); getCurrentMarkerTitles(player); - mPlugin.mWaypointManager.setWaypoint(player, null); } } From d4c1429358ad30942bbe66889b3ae9dc63a38e71 Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Tue, 3 Jun 2025 15:17:43 +0200 Subject: [PATCH 03/19] Nearly done --- .../listeners/PlayerListener.java | 8 +- .../managers/QuestCompassGui.java | 78 ++++++++++++------- .../managers/QuestCompassManager.java | 22 ++++-- 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java index b6072fba..394ec0a1 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java @@ -68,11 +68,13 @@ public void playerInteractEvent(PlayerInteractEvent event) { // compass if (useItem != Event.Result.DENY && item != null - && item.getType() == Material.COMPASS && !player.isSneaking()) { - if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) { + && item.getType() == Material.COMPASS) { + if ((action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) && !player.isSneaking()) { mPlugin.mQuestCompassManager.showCurrentQuest(player); - } else if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { + } else if ((action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) && !player.isSneaking()) { new QuestCompassGui(player, mPlugin.mQuestCompassManager).openInventory(player, mPlugin); + } else if ((action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) && player.isSneaking()) { + mPlugin.mQuestCompassManager.cycleQuestTracker(player); } } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 77ff621c..5a1448de 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -5,7 +5,6 @@ import com.playmonumenta.scriptedquests.managers.QuestCompassManager.ValidCompassEntry; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; @@ -22,6 +21,13 @@ public class QuestCompassGui extends CustomInventory { private final Player mPlayer; private final QuestCompassManager mManager; + private final int mRows = mInventory.getSize() / 9; + private final int mGuidesSlot = 3; + private final int mInfoSlot = 4; + private final int mHiddenSlot = 5; + private final List mDeathSlots = List.of(32 + 9 * (mRows - 4), 33 + 9 * (mRows - 4), 34 + 9 * (mRows - 4)); + private final int mCustomSlot = 30 + 9 * (mRows - 4); + private final int mDeselectSlot = 28 + 9 * (mRows - 4); public QuestCompassGui(Player player, QuestCompassManager manager) { super(player, Math.min(36 + 9 * (manager.getCurrentMarkerTitles(player).stream().filter( @@ -40,7 +46,6 @@ public void openInventory(Player player, org.bukkit.plugin.Plugin owner) { private void setupInventory() { mInventory.clear(); - int rows = mInventory.getSize() / 9; ItemStack info = new ItemStack(Material.COMPASS); ItemMeta infoMeta = info.getItemMeta(); @@ -48,7 +53,7 @@ private void setupInventory() { infoMeta.lore(List.of(Component.text("Left click on a quest to track it.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), Component.text("More instructions later", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); info.setItemMeta(infoMeta); - mInventory.setItem(4, info); + mInventory.setItem(mInfoSlot, info); ItemStack guides = new ItemStack(Material.SCUTE); ItemMeta guidesMeta = guides.getItemMeta(); @@ -57,31 +62,38 @@ private void setupInventory() { Component.text("across Monumenta by region and", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), Component.text("town.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); guides.setItemMeta(guidesMeta); - mInventory.setItem(3, guides); + mInventory.setItem(mGuidesSlot, guides); ItemStack hidden = new ItemStack(Material.CAULDRON); ItemMeta hiddenMeta = guides.getItemMeta(); hiddenMeta.displayName(Component.text("Hidden Quests", NamedTextColor.DARK_PURPLE).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); hiddenMeta.lore(List.of(Component.text("Instructions", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); hidden.setItemMeta(hiddenMeta); - mInventory.setItem(5, hidden); + mInventory.setItem(mHiddenSlot, hidden); ItemStack death = new ItemStack(Material.SKULL_POTTERY_SHERD); ItemMeta deathMeta = death.getItemMeta(); - deathMeta.displayName(Component.text("Death Waypoints", NamedTextColor.DARK_RED).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + deathMeta.displayName(Component.text("Death Waypoints", NamedTextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); deathMeta.lore(List.of(Component.text("No recent death to show here.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); death.setItemMeta(deathMeta); - mInventory.setItem(32 + 9 * (rows - 4), death); - mInventory.setItem(33 + 9 * (rows - 4), death); - mInventory.setItem(34 + 9 * (rows - 4), death); + mInventory.setItem(mDeathSlots.get(0), death); + mInventory.setItem(mDeathSlots.get(1), death); + mInventory.setItem(mDeathSlots.get(2), death); - ItemStack custom = new ItemStack(Material.LODESTONE); + ItemStack custom = new ItemStack(Material.HOPPER); ItemMeta customMeta = custom.getItemMeta(); customMeta.displayName(Component.text("Custom Waypoint", NamedTextColor.DARK_GREEN).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); - customMeta.lore(List.of(Component.text("No custom waypoint set. Waypoints can be set through", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), - Component.text("Quest Guides, /waypoint, or by other special means.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); + customMeta.lore(List.of(Component.text("No custom waypoint set. Waypoints can be set by", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), + Component.text("Quest Guides, /waypoint, or other special means.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); custom.setItemMeta(customMeta); - mInventory.setItem(29 + 9 * (rows - 4), custom); + mInventory.setItem(mCustomSlot, custom); + + ItemStack deselect = new ItemStack(Material.TNT_MINECART); + ItemMeta deselectMeta = deselect.getItemMeta(); + deselectMeta.displayName(Component.text("Deselect Active Quest", NamedTextColor.DARK_RED).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + deselectMeta.lore(List.of(Component.text("Click to deselect your currently tracked quest.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); + deselect.setItemMeta(deselectMeta); + mInventory.setItem(mDeselectSlot, deselect); List quests = mManager.getCurrentMarkerTitles(mPlayer); @@ -104,7 +116,7 @@ private void setupInventory() { titleColor = NamedTextColor.AQUA; } - String title = StringUtils.remove(quest.mTitle, "&a&l"); + String title = quest.mTitle.replaceAll("&.", ""); Component itemName = Component.text(title, titleColor).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false); @@ -127,9 +139,9 @@ private void setupInventory() { slot += (int) (2 * Math.floor((double) (slot - 8) / 9)); if (quest.mType == QuestCompassManager.CompassEntryType.Death) { - slot = 31 + quest.mMarkersIndex[0] + 9 * (rows - 4); + slot = 31 + quest.mMarkersIndex[0] + 9 * (mRows - 4); } else if (quest.mType == QuestCompassManager.CompassEntryType.Waypoint) { - slot = 29 + 9 * (rows - 4); + slot = 30 + 9 * (mRows - 4); } displayItem = new ItemStack(material); @@ -144,7 +156,7 @@ private void setupInventory() { for (int j = i + 1 - quest.mMarkersIndex[0]; j < i + 1 - quest.mMarkersIndex[0] + quest.mMarkersIndex[1]; j++) { int splitIndex = 0; ValidCompassEntry q = quests.get(j); - String qLore = StringUtils.remove(q.mLocation.getMessage(), "&a"); + String qLore = q.mLocation.getMessage().replaceAll("&.", ""); while (splitIndex < qLore.length() && !(j != i && splitIndex > 0)) { lore.add(Component.text(StringUtils.substring(qLore, splitIndex, qLore.indexOf(" ", splitIndex + 45) < 0 ? 1000 : qLore.indexOf(" ", splitIndex + 45)) + (j != i && qLore.indexOf(" ", splitIndex + 45) > 0 ? " {...}" : ""), j == i ? NamedTextColor.WHITE : NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); if (qLore.indexOf(" ", splitIndex + 45) < 0) { @@ -173,34 +185,42 @@ private void setupInventory() { protected void inventoryClick(InventoryClickEvent event) { event.setCancelled(true); InventoryUtils.refreshOffhand(event); + int slot = event.getSlot(); + ItemStack item = event.getInventory().getItem(slot); if (!(event.getWhoClicked() instanceof Player player) || event.getClickedInventory() != mInventory - || event.getInventory().getItem(event.getSlot()) == null) { + || item == null) { return; } - if (event.getSlot() == 3) { + if (slot == mGuidesSlot) { player.performCommand("sqgui show regionqg @s"); return; - } else if (event.getSlot() == 4 || event.getSlot() == 5) { + } else if (slot == mInfoSlot || slot == mHiddenSlot) { // Not implemented return; - } - // This is throwing a Lot of NullPointerExceptions - find a way to make it Not do that - int index = Objects.requireNonNull(event.getInventory().getItem(event.getSlot())).getItemMeta().getCustomModelData(); - if (mManager.getCurrentMarkerTitles(player).get(index).mType == QuestCompassManager.CompassEntryType.Waypoint && event.isShiftClick()) { + } else if (slot == mDeselectSlot) { + mManager.mCurrentIndex.put(player, mManager.showCurrentQuest(player, -1)); + player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_CLOSE, SoundCategory.PLAYERS, 1f, 0.8f); + close(); + return; + } else if (slot == mCustomSlot && event.isShiftClick() && item.getType() == Material.KNOWLEDGE_BOOK) { mManager.removeCommandWaypoint(player); player.playSound(player.getLocation(), "minecraft:entity.armadillo.scute_drop", SoundCategory.PLAYERS, 1f, 1f); setupInventory(); return; + } else if (mDeathSlots.contains(slot) && item.getType() == Material.SKULL_POTTERY_SHERD) { + return; + } else if (slot == mCustomSlot && item.getType() == Material.HOPPER) { + return; } + + int index = item.getItemMeta().getCustomModelData(); mManager.mCurrentIndex.put(player, mManager.showCurrentQuest(player, index)); player.playSound(player.getLocation(), Sound.UI_LOOM_TAKE_RESULT, SoundCategory.PLAYERS, 1f, 1f); + if (slot == mCustomSlot) { + player.playSound(player.getLocation(), "minecraft:block.trial_spawner.eject_item", SoundCategory.PLAYERS, 1f, 2f); + } close(); } - - @Override - protected void inventoryClose(InventoryCloseEvent event) { - // Something later - } } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index be8fe541..72ce40eb 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -14,12 +14,12 @@ import java.util.Map; import java.util.UUID; import java.util.WeakHashMap; - -import dev.jorel.commandapi.arguments.ChatColorArgument; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; @@ -171,7 +171,7 @@ public int showCurrentQuest(Player player, int index) { index = 0; } - if (entries.isEmpty()) { + if (entries.isEmpty() || index == -1) { MessagingUtils.sendActionBarMessage(player, "You have no active quest."); mPlugin.mWaypointManager.setWaypoint(player, null); } else { @@ -189,11 +189,20 @@ public void showCurrentQuest(Player player) { public void cycleQuestTracker(Player player) { Integer index = mCurrentIndex.getOrDefault(player, 0); - index += 1; + if (index < 0) { + showCurrentQuest(player, index); + return; + } - index = showCurrentQuest(player, index); + ValidCompassEntry quest = mCompassCache.get(player.getUniqueId()).mEntries.get(index); + if (quest.mMarkersIndex[0] == quest.mMarkersIndex[1]) { + index += 1 - quest.mMarkersIndex[1]; + } else { + index += 1; + } - mCurrentIndex.put(player, index); + mCurrentIndex.put(player, showCurrentQuest(player, index)); + player.playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, SoundCategory.PLAYERS, 1f, 1.5f); } /* One command-specified waypoint per player */ @@ -201,6 +210,7 @@ public void setCommandWaypoint(Player player, List steps, String title ValidCompassEntry entry = new ValidCompassEntry(new CompassLocation(null, message, steps), title, false, CompassEntryType.Waypoint); mCommandWaypoints.put(player.getUniqueId(), entry); mCurrentIndex.put(player, getCurrentMarkerTitles(player).indexOf(mCommandWaypoints.get(player.getUniqueId()))); + invalidateCache(player); entry.directPlayer(mPlugin.mWaypointManager, player, true); } From ab141e462da82496ea65be50feb5925dfbb51b21 Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Tue, 3 Jun 2025 15:20:15 +0200 Subject: [PATCH 04/19] Update QuestCompassGui.java --- .../playmonumenta/scriptedquests/managers/QuestCompassGui.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 5a1448de..4b7f0347 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -217,9 +217,6 @@ protected void inventoryClick(InventoryClickEvent event) { int index = item.getItemMeta().getCustomModelData(); mManager.mCurrentIndex.put(player, mManager.showCurrentQuest(player, index)); player.playSound(player.getLocation(), Sound.UI_LOOM_TAKE_RESULT, SoundCategory.PLAYERS, 1f, 1f); - if (slot == mCustomSlot) { - player.playSound(player.getLocation(), "minecraft:block.trial_spawner.eject_item", SoundCategory.PLAYERS, 1f, 2f); - } close(); } } From c316844a3a44e8089f60566e5dace2875af27fe2 Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Sun, 8 Jun 2025 14:43:17 +0200 Subject: [PATCH 05/19] Removed hide item --- .../scriptedquests/managers/QuestCompassGui.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 4b7f0347..66c96581 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -22,9 +22,8 @@ public class QuestCompassGui extends CustomInventory { private final Player mPlayer; private final QuestCompassManager mManager; private final int mRows = mInventory.getSize() / 9; - private final int mGuidesSlot = 3; + private final int mGuidesSlot = 6; private final int mInfoSlot = 4; - private final int mHiddenSlot = 5; private final List mDeathSlots = List.of(32 + 9 * (mRows - 4), 33 + 9 * (mRows - 4), 34 + 9 * (mRows - 4)); private final int mCustomSlot = 30 + 9 * (mRows - 4); private final int mDeselectSlot = 28 + 9 * (mRows - 4); @@ -64,13 +63,6 @@ private void setupInventory() { guides.setItemMeta(guidesMeta); mInventory.setItem(mGuidesSlot, guides); - ItemStack hidden = new ItemStack(Material.CAULDRON); - ItemMeta hiddenMeta = guides.getItemMeta(); - hiddenMeta.displayName(Component.text("Hidden Quests", NamedTextColor.DARK_PURPLE).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); - hiddenMeta.lore(List.of(Component.text("Instructions", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); - hidden.setItemMeta(hiddenMeta); - mInventory.setItem(mHiddenSlot, hidden); - ItemStack death = new ItemStack(Material.SKULL_POTTERY_SHERD); ItemMeta deathMeta = death.getItemMeta(); deathMeta.displayName(Component.text("Death Waypoints", NamedTextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); @@ -195,8 +187,7 @@ protected void inventoryClick(InventoryClickEvent event) { if (slot == mGuidesSlot) { player.performCommand("sqgui show regionqg @s"); return; - } else if (slot == mInfoSlot || slot == mHiddenSlot) { - // Not implemented + } else if (slot == mInfoSlot) { return; } else if (slot == mDeselectSlot) { mManager.mCurrentIndex.put(player, mManager.showCurrentQuest(player, -1)); From 10d4c1c33fab0bb2bee60c415f8b763a247cd09f Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Tue, 17 Jun 2025 16:04:32 +0200 Subject: [PATCH 06/19] worlds --- .../scriptedquests/listeners/PlayerListener.java | 2 +- .../scriptedquests/managers/QuestCompassGui.java | 13 +++++++++++-- .../quests/components/CompassLocation.java | 10 ++++++++++ .../quests/components/DeathLocation.java | 10 +++++++++- .../quests/components/QuestLocation.java | 2 ++ tools/schema/quest_location.json | 14 +++++++++++--- 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java index 394ec0a1..8c9c62dc 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java @@ -174,7 +174,7 @@ public void playerDeathEvent(PlayerDeathEvent event) { } // Add this death location to the beginning of the list - deathEntries.add(0, new DeathLocation(event.getEntity().getLocation(), System.currentTimeMillis())); + deathEntries.add(0, new DeathLocation(event.getEntity().getLocation(), System.currentTimeMillis(), event.getEntity().getWorld())); if (deathEntries.size() > 3) { deathEntries.remove(3); } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 66c96581..c74de879 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -5,16 +5,17 @@ import com.playmonumenta.scriptedquests.managers.QuestCompassManager.ValidCompassEntry; import java.util.ArrayList; import java.util.List; + import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; import org.apache.commons.lang3.StringUtils; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.SoundCategory; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -157,7 +158,12 @@ private void setupInventory() { splitIndex = 1 + qLore.indexOf(" ", splitIndex + 45); } } - lore.add(Component.text((int) q.mLocation.getLocation().getX() + ", " + (int) q.mLocation.getLocation().getY() + ", " + (int) q.mLocation.getLocation().getZ() + " (" + (int) mPlayer.getLocation().distance(q.mLocation.getLocation()) + "m away)", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false)); + + boolean differentWorld = !com.playmonumenta.scriptedquests.Plugin.getInstance().mZoneManager.getWorldRegexMatcher().matches(mPlayer.getWorld().getName(), q.mLocation.getWorldRegex()); + Location qLoc = q.mLocation.getLocation(); + lore.add(Component.text((int) qLoc.getX() + ", " + (int) qLoc.getY() + ", " + (int) qLoc.getZ() + " ", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false) + .append(differentWorld ? Component.text("[Different World!]", NamedTextColor.DARK_RED) : Component.text(("("+ (int) mPlayer.getLocation().distance(new Location(mPlayer.getWorld(), qLoc.getX(), qLoc.getY(), qLoc.getZ())) + "m away)")))); + if (q.mType == QuestCompassManager.CompassEntryType.Waypoint) { lore.add(Component.text("(Shift Click to remove this waypoint.)", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); } @@ -208,6 +214,9 @@ protected void inventoryClick(InventoryClickEvent event) { int index = item.getItemMeta().getCustomModelData(); mManager.mCurrentIndex.put(player, mManager.showCurrentQuest(player, index)); player.playSound(player.getLocation(), Sound.UI_LOOM_TAKE_RESULT, SoundCategory.PLAYERS, 1f, 1f); + if (slot == mCustomSlot) { + player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.5f, 0.8f); + } close(); } } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/CompassLocation.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/CompassLocation.java index 0dfb975d..b50bd948 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/CompassLocation.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/CompassLocation.java @@ -17,6 +17,7 @@ public class CompassLocation implements QuestLocation { private final @Nullable QuestPrerequisites mPrerequisites; private final String mMessage; private final List mWaypoints = new ArrayList(); + private final String mWorldRegex; public CompassLocation(World world, JsonElement element) throws Exception { JsonObject object = element.getAsJsonObject(); @@ -29,6 +30,9 @@ public CompassLocation(World world, JsonElement element) throws Exception { if (prereq == null) { throw new Exception("Failed to parse location prerequisites!"); } + + mWorldRegex = object.has("world_name") ? object.get("world_name").toString() : ".*"; + mPrerequisites = new QuestPrerequisites(prereq); if (object.has("waypoints")) { @@ -105,6 +109,7 @@ public CompassLocation(@Nullable QuestPrerequisites questPrereq, String message, mPrerequisites = questPrereq; mMessage = message; mWaypoints.addAll(waypoints); + mWorldRegex = ".*"; } @Override @@ -122,6 +127,11 @@ public String getMessage() { return mMessage; } + @Override + public String getWorldRegex() { + return mWorldRegex; + } + @Override public boolean prerequisiteMet(Player player) { return mPrerequisites == null || mPrerequisites.prerequisiteMet(new QuestContext(Plugin.getInstance(), player, null)); diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java index 07be73c6..9179558b 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java @@ -3,14 +3,17 @@ import java.util.ArrayList; import java.util.List; import org.bukkit.Location; +import org.bukkit.World; public class DeathLocation implements QuestLocation { private final long mDeathTime; private final List mWaypoints = new ArrayList<>(1); + private final String mWorld; - public DeathLocation(Location loc, long deathTime) { + public DeathLocation(Location loc, long deathTime, World world) { mDeathTime = deathTime; mWaypoints.add(loc); + mWorld = world.getName(); } public String getTimeDifference(long compareTime) { @@ -79,4 +82,9 @@ public Location getLocation() { public String getMessage() { return getTimeDifference(System.currentTimeMillis()) + " ago"; } + + @Override + public String getWorldRegex() { + return mWorld; + } } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/QuestLocation.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/QuestLocation.java index 1bc4ea8d..025675ba 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/QuestLocation.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/QuestLocation.java @@ -19,6 +19,8 @@ public interface QuestLocation { String getMessage(); + String getWorldRegex(); + default boolean prerequisiteMet(Player player) { return true; } diff --git a/tools/schema/quest_location.json b/tools/schema/quest_location.json index 1a24de5e..c285e052 100644 --- a/tools/schema/quest_location.json +++ b/tools/schema/quest_location.json @@ -5,7 +5,7 @@ "waypoints", "message" ], - "additionalProperties": false, + "additionalProperties": true, "properties": { "prerequisites": { "required": true, @@ -27,10 +27,18 @@ }, "message": { "required": true, - "propertyOrder": 4, + "propertyOrder": 3, "title": "message", "description": "Text to display in chat when checking a quest", "type": "string" - } + }, + "world_name": { + "required": false, + "propertyOrder": 4, + "title": "world_name", + "description": "A regular expression (regex) that matches one or more world names completely. Inherits from the file containing it. If not set at all, it defaults to \".*\". See regex101.com for help.", + "type": "string", + "default": ".*" + } } } From c7cc29f21f527a3088364a7adecc1a4cef6b17e7 Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Mon, 7 Jul 2025 01:14:31 +0200 Subject: [PATCH 07/19] world regex stuff (does not work) --- .../listeners/WorldListener.java | 2 ++ .../managers/QuestCompassGui.java | 4 ++-- .../managers/QuestCompassManager.java | 20 +++++++++++++++++++ .../{zones => utils}/WorldRegexMatcher.java | 12 +++++------ .../scriptedquests/zones/ZoneManager.java | 1 + 5 files changed, 31 insertions(+), 8 deletions(-) rename plugin/src/main/java/com/playmonumenta/scriptedquests/{zones => utils}/WorldRegexMatcher.java (79%) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/WorldListener.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/WorldListener.java index 5c0b05da..322c20c8 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/WorldListener.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/WorldListener.java @@ -35,10 +35,12 @@ public void entityAddToWorldEvent(EntityAddToWorldEvent event) { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void worldLoadEvent(WorldLoadEvent event) { mPlugin.mZoneManager.onLoadWorld(event.getWorld()); + mPlugin.mQuestCompassManager.getWorldRegexMatcher().onLoadWorld(event.getWorld()); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void worldUnloadEvent(WorldUnloadEvent event) { mPlugin.mZoneManager.onUnloadWorld(event.getWorld()); + mPlugin.mQuestCompassManager.getWorldRegexMatcher().onUnloadWorld(event.getWorld()); } } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index c74de879..8354a780 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -1,5 +1,6 @@ package com.playmonumenta.scriptedquests.managers; +import com.playmonumenta.scriptedquests.Plugin; import com.playmonumenta.scriptedquests.utils.CustomInventory; import com.playmonumenta.scriptedquests.utils.InventoryUtils; import com.playmonumenta.scriptedquests.managers.QuestCompassManager.ValidCompassEntry; @@ -159,11 +160,10 @@ private void setupInventory() { } } - boolean differentWorld = !com.playmonumenta.scriptedquests.Plugin.getInstance().mZoneManager.getWorldRegexMatcher().matches(mPlayer.getWorld().getName(), q.mLocation.getWorldRegex()); + boolean differentWorld = !Plugin.getInstance().mQuestCompassManager.getWorldRegexMatcher().matches(mPlayer.getWorld().getName(), q.mLocation.getWorldRegex()); Location qLoc = q.mLocation.getLocation(); lore.add(Component.text((int) qLoc.getX() + ", " + (int) qLoc.getY() + ", " + (int) qLoc.getZ() + " ", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false) .append(differentWorld ? Component.text("[Different World!]", NamedTextColor.DARK_RED) : Component.text(("("+ (int) mPlayer.getLocation().distance(new Location(mPlayer.getWorld(), qLoc.getX(), qLoc.getY(), qLoc.getZ())) + "m away)")))); - if (q.mType == QuestCompassManager.CompassEntryType.Waypoint) { lore.add(Component.text("(Shift Click to remove this waypoint.)", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index 72ce40eb..9dbad19d 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -10,10 +10,14 @@ import com.playmonumenta.scriptedquests.utils.QuestUtils; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.WeakHashMap; + +import com.playmonumenta.scriptedquests.utils.WorldRegexMatcher; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; import org.bukkit.ChatColor; @@ -30,6 +34,7 @@ public class QuestCompassManager { public final Map mCompassCache = new HashMap(); public final Map mCurrentIndex = new WeakHashMap<>(); public final Plugin mPlugin; + public static WorldRegexMatcher mWorldRegexMatcher = null; /* One command-specified waypoint per player */ public final Map mCommandWaypoints = new HashMap(); @@ -102,6 +107,13 @@ public void reload(Plugin plugin, @Nullable CommandSender sender) { mQuests.add(quest); return quest.getQuestName() + ":" + Integer.toString(quest.getMarkers().size()); }); + final Set worldRegexes = new HashSet<>(); + for (QuestCompass qc : mQuests) { + for (CompassLocation cl : qc.getMarkers()) { + worldRegexes.add(cl.getWorldRegex()); + } + } + mWorldRegexMatcher = new WorldRegexMatcher(worldRegexes); } @SuppressWarnings("unchecked") @@ -226,4 +238,12 @@ public void removeCommandWaypoint(Player player) { public void invalidateCache(Player player) { mCompassCache.remove(player.getUniqueId()); } + + public WorldRegexMatcher getWorldRegexMatcher() { + WorldRegexMatcher matcher = mWorldRegexMatcher; + if (matcher == null) { + throw new RuntimeException("WorldRegexMatcher unavailable before ScriptedQuests finishes loading"); + } + return matcher; + } } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/zones/WorldRegexMatcher.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java similarity index 79% rename from plugin/src/main/java/com/playmonumenta/scriptedquests/zones/WorldRegexMatcher.java rename to plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java index 3acf5e49..0e730f7e 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/zones/WorldRegexMatcher.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java @@ -1,4 +1,4 @@ -package com.playmonumenta.scriptedquests.zones; +package com.playmonumenta.scriptedquests.utils; import java.util.HashMap; import java.util.HashSet; @@ -10,10 +10,10 @@ import org.bukkit.World; public class WorldRegexMatcher { - private static final Map mPatterns = new HashMap<>(); - private static final Map> mWorldPatternMatches = new HashMap<>(); + private final Map mPatterns = new HashMap<>(); + private final Map> mWorldPatternMatches = new HashMap<>(); - protected WorldRegexMatcher(Set worldRegexes) throws PatternSyntaxException { + public WorldRegexMatcher(Set worldRegexes) throws PatternSyntaxException { for (String worldRegexStr : worldRegexes) { mPatterns.put(worldRegexStr, Pattern.compile(worldRegexStr)); } @@ -23,7 +23,7 @@ protected WorldRegexMatcher(Set worldRegexes) throws PatternSyntaxExcept } } - protected void onLoadWorld(World world) { + public void onLoadWorld(World world) { Set matchingPatterns = new HashSet<>(); mWorldPatternMatches.put(world, matchingPatterns); @@ -41,7 +41,7 @@ protected void onLoadWorld(World world) { } } - protected void onUnloadWorld(World world) { + public void onUnloadWorld(World world) { mWorldPatternMatches.remove(world); } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/zones/ZoneManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/zones/ZoneManager.java index dfa31dab..85ccaa5d 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/zones/ZoneManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/zones/ZoneManager.java @@ -4,6 +4,7 @@ import com.playmonumenta.scriptedquests.utils.ArgUtils; import com.playmonumenta.scriptedquests.utils.MMLog; import com.playmonumenta.scriptedquests.utils.MessagingUtils; +import com.playmonumenta.scriptedquests.utils.WorldRegexMatcher; import dev.jorel.commandapi.arguments.Argument; import dev.jorel.commandapi.arguments.ArgumentSuggestions; import dev.jorel.commandapi.arguments.TextArgument; From 3eab3c128a903d074e22ce763e559560928b1ec1 Mon Sep 17 00:00:00 2001 From: Timothy Southwick Date: Sun, 6 Jul 2025 19:44:44 -0400 Subject: [PATCH 08/19] Always mark world name and regex as matching if they're equal, even if it's not cached --- .../scriptedquests/utils/WorldRegexMatcher.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java index 0e730f7e..60557244 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java @@ -55,7 +55,12 @@ public boolean matches(World world, String worldRegex) { } public boolean matches(String worldName, String worldRegex) { - if (worldRegex == null || worldRegex.isEmpty() || worldRegex.equals(".*")) { + if ( + worldRegex == null + || worldRegex.isEmpty() + || worldRegex.equals(".*") + || worldRegex.equals(worldName) + ) { return true; } From 1a415bd65503860eb0fe85cbc1bd8a00170ee43f Mon Sep 17 00:00:00 2001 From: Timothy Southwick Date: Sun, 6 Jul 2025 19:45:23 -0400 Subject: [PATCH 09/19] Fix import order --- .../scriptedquests/managers/QuestCompassManager.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index 9dbad19d..811e9e12 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -8,6 +8,7 @@ import com.playmonumenta.scriptedquests.quests.components.QuestLocation; import com.playmonumenta.scriptedquests.utils.MessagingUtils; import com.playmonumenta.scriptedquests.utils.QuestUtils; +import com.playmonumenta.scriptedquests.utils.WorldRegexMatcher; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -16,8 +17,6 @@ import java.util.Set; import java.util.UUID; import java.util.WeakHashMap; - -import com.playmonumenta.scriptedquests.utils.WorldRegexMatcher; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; import org.bukkit.ChatColor; From e44ec922bc2693bd896366691ae0b01456394d9b Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Mon, 21 Jul 2025 22:37:15 +0200 Subject: [PATCH 10/19] finished perhaps --- .../playmonumenta/scriptedquests/Plugin.java | 3 + .../scriptedquests/commands/Waypoint.java | 8 +- .../listeners/WorldListener.java | 2 - .../managers/QuestCompassGui.java | 147 +++++++++++++----- .../managers/QuestCompassManager.java | 30 +--- .../quests/components/CompassLocation.java | 7 +- .../quests/components/DeathLocation.java | 2 +- .../utils/WorldRegexMatcher.java | 3 +- tools/schema/quest_location.json | 5 +- 9 files changed, 129 insertions(+), 78 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/Plugin.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/Plugin.java index f3073e6e..335f127b 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/Plugin.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/Plugin.java @@ -52,6 +52,7 @@ public class Plugin extends JavaPlugin { public @Nullable Boolean mShowTimerNames = null; public boolean mShowZonesDynmap = false; public boolean mFallbackZoneLookup = false; + public ConfigurationSection mQuestCompassGUIItems; public QuestCompassManager mQuestCompassManager; public QuestNpcManager mNpcManager; @@ -289,6 +290,8 @@ private void reloadConfigYaml(CommandSender sender) { sender.sendMessage("default_music_category: " + Constants.SOUND_CATEGORY_NAMES.get(mDefaultMusicSoundCategory)); } + + mQuestCompassGUIItems = mConfig.getConfigurationSection("quest_compass_gui_items"); } public static Plugin getInstance() { diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java index 6e5c72aa..c340bf27 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java @@ -20,8 +20,9 @@ public static void register(Plugin plugin) { EntitySelectorArgument.OnePlayer playerArg = new EntitySelectorArgument.OnePlayer("player"); TextArgument titleArg = new TextArgument("title"); - TextArgument labelArg = new TextArgument("label"); + TextArgument messageArg = new TextArgument("message"); LocationArgument locationArg = new LocationArgument("location", LocationType.PRECISE_POSITION); + TextArgument regexArg = new TextArgument("world name regex"); //Sets command waypoint new CommandAPICommand("waypoint") @@ -29,8 +30,9 @@ public static void register(Plugin plugin) { .withSubcommand(new CommandAPICommand("set") .withArguments(playerArg) .withArguments(titleArg) - .withArguments(labelArg) + .withArguments(messageArg) .withArguments(locationArg) + .withOptionalArguments(regexArg) .executes((sender, args) -> { Player targetPlayer = args.getByArgument(playerArg); if (sender instanceof Player player @@ -41,7 +43,7 @@ public static void register(Plugin plugin) { if (plugin.mQuestCompassManager != null) { List waypoint = new ArrayList<>(); waypoint.add(args.getByArgument(locationArg)); - plugin.mQuestCompassManager.setCommandWaypoint(targetPlayer, waypoint, args.getByArgument(titleArg) + ChatColor.RESET, args.getByArgument(labelArg)); + plugin.mQuestCompassManager.setCommandWaypoint(targetPlayer, waypoint, args.getByArgument(titleArg) + ChatColor.RESET, args.getByArgument(messageArg), args.getByArgumentOrDefault(regexArg, targetPlayer != null ? targetPlayer.getWorld().getName() : ".*")); } else { throw CommandAPI.failWithString("Quest Compass Manager does not exist!"); } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/WorldListener.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/WorldListener.java index 322c20c8..5c0b05da 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/WorldListener.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/WorldListener.java @@ -35,12 +35,10 @@ public void entityAddToWorldEvent(EntityAddToWorldEvent event) { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void worldLoadEvent(WorldLoadEvent event) { mPlugin.mZoneManager.onLoadWorld(event.getWorld()); - mPlugin.mQuestCompassManager.getWorldRegexMatcher().onLoadWorld(event.getWorld()); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void worldUnloadEvent(WorldUnloadEvent event) { mPlugin.mZoneManager.onUnloadWorld(event.getWorld()); - mPlugin.mQuestCompassManager.getWorldRegexMatcher().onUnloadWorld(event.getWorld()); } } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 8354a780..6537ae03 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -5,16 +5,20 @@ import com.playmonumenta.scriptedquests.utils.InventoryUtils; import com.playmonumenta.scriptedquests.managers.QuestCompassManager.ValidCompassEntry; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; - +import java.util.Map; +import java.util.Objects; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextDecoration; import org.apache.commons.lang3.StringUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.SoundCategory; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; @@ -22,13 +26,16 @@ public class QuestCompassGui extends CustomInventory { private final Player mPlayer; + private final Plugin mPlugin = Plugin.getInstance(); private final QuestCompassManager mManager; private final int mRows = mInventory.getSize() / 9; - private final int mGuidesSlot = 6; - private final int mInfoSlot = 4; private final List mDeathSlots = List.of(32 + 9 * (mRows - 4), 33 + 9 * (mRows - 4), 34 + 9 * (mRows - 4)); private final int mCustomSlot = 30 + 9 * (mRows - 4); private final int mDeselectSlot = 28 + 9 * (mRows - 4); + private final int mNextSlot = 44; + private final int mPrevSlot = 36; + private int mPage; + private final Map mItemToActions = new HashMap<>(); public QuestCompassGui(Player player, QuestCompassManager manager) { super(player, Math.min(36 + 9 * (manager.getCurrentMarkerTitles(player).stream().filter( @@ -36,34 +43,62 @@ public QuestCompassGui(Player player, QuestCompassManager manager) { "Quest Compass"); mPlayer = player; mManager = manager; + mPage = 0; } @Override public void openInventory(Player player, org.bukkit.plugin.Plugin owner) { super.openInventory(player, owner); player.playSound(player.getLocation(), Sound.UI_LOOM_SELECT_PATTERN, SoundCategory.PLAYERS, 1f, 1f); - setupInventory(); + setupInventory(mPage); } - private void setupInventory() { + private void setupInventory(int page) { mInventory.clear(); + mPage = page; + + for (String key : mPlugin.mQuestCompassGUIItems.getKeys(false)) { + ConfigurationSection itemConfig = mPlugin.mQuestCompassGUIItems.getConfigurationSection(key); + if (itemConfig != null) { + String name = itemConfig.getString("name"); + Material material = Material.getMaterial(Objects.requireNonNull(itemConfig.getString("material"))); + TextColor nameColor = TextColor.fromHexString(Objects.requireNonNull(itemConfig.getString("name_color"))); + TextColor loreColor = TextColor.fromHexString(Objects.requireNonNull(itemConfig.getString("lore_color"))); + + name = name != null ? name : "Name Unset"; + material = material != null ? material : Material.BARRIER; + nameColor = nameColor != null ? nameColor : NamedTextColor.LIGHT_PURPLE; + loreColor = loreColor != null ? loreColor : NamedTextColor.DARK_PURPLE; + + List lores = new ArrayList<>(); + ConfigurationSection loresConfig = itemConfig.getConfigurationSection("lore"); + if (loresConfig != null) { + for (String line : loresConfig.getKeys(false)) { + String text = loresConfig.getString(line); + if (text == null) { + text = "Lore unset"; + } + lores.add(Component.text(text, loreColor).decoration(TextDecoration.ITALIC, false)); + } + } - ItemStack info = new ItemStack(Material.COMPASS); - ItemMeta infoMeta = info.getItemMeta(); - infoMeta.displayName(Component.text("Quest Compass", NamedTextColor.RED).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); - infoMeta.lore(List.of(Component.text("Left click on a quest to track it.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), - Component.text("More instructions later", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); - info.setItemMeta(infoMeta); - mInventory.setItem(mInfoSlot, info); - - ItemStack guides = new ItemStack(Material.SCUTE); - ItemMeta guidesMeta = guides.getItemMeta(); - guidesMeta.displayName(Component.text("Quest Guides", NamedTextColor.GOLD).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); - guidesMeta.lore(List.of(Component.text("Click to see available quests", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), - Component.text("across Monumenta by region and", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), - Component.text("town.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); - guides.setItemMeta(guidesMeta); - mInventory.setItem(mGuidesSlot, guides); + int slot = itemConfig.getInt("slot"); + if (itemConfig.getBoolean("slot_scale_with_rows", false)) { + slot += 9 * (mRows - 4); + } + + ItemStack item = new ItemStack(material); + ItemMeta itemMeta = item.getItemMeta(); + itemMeta.displayName(Component.text(name, nameColor).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + itemMeta.lore(lores); + item.setItemMeta(itemMeta); + mInventory.setItem(slot, item); + + if (itemConfig.isConfigurationSection("actions")) { + mItemToActions.put(item, itemConfig.getConfigurationSection("actions")); + } + } + } ItemStack death = new ItemStack(Material.SKULL_POTTERY_SHERD); ItemMeta deathMeta = death.getItemMeta(); @@ -78,25 +113,40 @@ private void setupInventory() { ItemMeta customMeta = custom.getItemMeta(); customMeta.displayName(Component.text("Custom Waypoint", NamedTextColor.DARK_GREEN).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); customMeta.lore(List.of(Component.text("No custom waypoint set. Waypoints can be set by", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false), - Component.text("Quest Guides, /waypoint, or other special means.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); + Component.text("the /waypoint command or other special means.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); custom.setItemMeta(customMeta); mInventory.setItem(mCustomSlot, custom); ItemStack deselect = new ItemStack(Material.TNT_MINECART); ItemMeta deselectMeta = deselect.getItemMeta(); - deselectMeta.displayName(Component.text("Deselect Active Quest", NamedTextColor.DARK_RED).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); - deselectMeta.lore(List.of(Component.text("Click to deselect your currently tracked quest.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); + deselectMeta.displayName(Component.text("Stop Tracking", NamedTextColor.DARK_RED).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + deselectMeta.lore(List.of(Component.text("Click to stop tracking the selected quest.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))); deselect.setItemMeta(deselectMeta); mInventory.setItem(mDeselectSlot, deselect); List quests = mManager.getCurrentMarkerTitles(mPlayer); - for (int i = 0; i < quests.size(); i++) { - if (i > 20) { - return; - } + if (quests.stream().filter(q -> q.mType == QuestCompassManager.CompassEntryType.Quest).toList().size() > 21 * (1 + mPage)) { + ItemStack next = new ItemStack(Material.ARROW); + ItemMeta nextMeta = next.getItemMeta(); + nextMeta.displayName(Component.text("Next Page", NamedTextColor.WHITE).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + next.setItemMeta(nextMeta); + mInventory.setItem(mNextSlot, next); + } + if (mPage > 0) { + ItemStack prev = new ItemStack(Material.ARROW); + ItemMeta prevMeta = prev.getItemMeta(); + prevMeta.displayName(Component.text("Previous Page", NamedTextColor.WHITE).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false)); + prev.setItemMeta(prevMeta); + mInventory.setItem(mPrevSlot, prev); + } + for (int i = 21 * mPage; i < quests.size(); i++) { ValidCompassEntry quest = quests.get(i); + if (i >= 21 * (1 + mPage) && quest.mType == QuestCompassManager.CompassEntryType.Quest) { + // Death and waypoint quests are sorted last - don't skip these, so they stay on every page + continue; + } ItemStack displayItem; @@ -114,7 +164,7 @@ private void setupInventory() { Component itemName = Component.text(title, titleColor).decoration(TextDecoration.BOLD, true).decoration(TextDecoration.ITALIC, false); - int slot = i + 10; + int slot = i + 10 - 21 * mPage; Material material; if (mManager.mCurrentIndex.getOrDefault(mPlayer, 0) == i) { switch (quest.mType) { @@ -122,7 +172,7 @@ private void setupInventory() { case Death -> material = Material.ARMOR_STAND; case Waypoint -> material = Material.KNOWLEDGE_BOOK; } - itemName = itemName.append(Component.text(" [Currently Tracking]", selectedColor).decoration(TextDecoration.BOLD, false).decoration(TextDecoration.ITALIC, false)); + itemName = itemName.append(Component.text(" (Currently Tracking)", selectedColor).decoration(TextDecoration.BOLD, false).decoration(TextDecoration.ITALIC, false)); } else { switch (quest.mType) { default -> material = Material.BOOK; @@ -131,7 +181,7 @@ private void setupInventory() { } } - slot += (int) (2 * Math.floor((double) (slot - 8) / 9)); + slot += (int) (2 * Math.floor((double) (slot - 10) / 7)); if (quest.mType == QuestCompassManager.CompassEntryType.Death) { slot = 31 + quest.mMarkersIndex[0] + 9 * (mRows - 4); } else if (quest.mType == QuestCompassManager.CompassEntryType.Waypoint) { @@ -142,7 +192,7 @@ private void setupInventory() { ItemMeta meta = displayItem.getItemMeta(); meta.displayName(itemName); - // Use this as a quest index tag for inventoryClick to easily identify quest index + // Use this as a quest index tag for inventoryClick to easily identify quest index. The resource pack will not be using this so there is no overlap. meta.setCustomModelData(i); // Compile all steps and highlight the one that matches this quest index (j == i) @@ -159,11 +209,10 @@ private void setupInventory() { splitIndex = 1 + qLore.indexOf(" ", splitIndex + 45); } } - - boolean differentWorld = !Plugin.getInstance().mQuestCompassManager.getWorldRegexMatcher().matches(mPlayer.getWorld().getName(), q.mLocation.getWorldRegex()); + boolean differentWorld = !mPlayer.getWorld().getName().matches(q.mLocation.getWorldRegex()); Location qLoc = q.mLocation.getLocation(); lore.add(Component.text((int) qLoc.getX() + ", " + (int) qLoc.getY() + ", " + (int) qLoc.getZ() + " ", NamedTextColor.DARK_GRAY).decoration(TextDecoration.ITALIC, false) - .append(differentWorld ? Component.text("[Different World!]", NamedTextColor.DARK_RED) : Component.text(("("+ (int) mPlayer.getLocation().distance(new Location(mPlayer.getWorld(), qLoc.getX(), qLoc.getY(), qLoc.getZ())) + "m away)")))); + .append(differentWorld ? Component.text("(Different World!)", NamedTextColor.RED) : Component.text(("("+ (int) mPlayer.getLocation().distance(new Location(mPlayer.getWorld(), qLoc.getX(), qLoc.getY(), qLoc.getZ())) + "m away)")))); if (q.mType == QuestCompassManager.CompassEntryType.Waypoint) { lore.add(Component.text("(Shift Click to remove this waypoint.)", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); } @@ -184,16 +233,23 @@ protected void inventoryClick(InventoryClickEvent event) { event.setCancelled(true); InventoryUtils.refreshOffhand(event); int slot = event.getSlot(); + if (slot < 0) { + return; + } ItemStack item = event.getInventory().getItem(slot); if (!(event.getWhoClicked() instanceof Player player) || event.getClickedInventory() != mInventory || item == null) { return; } - if (slot == mGuidesSlot) { - player.performCommand("sqgui show regionqg @s"); - return; - } else if (slot == mInfoSlot) { + if (mItemToActions.containsKey(item)) { + String command = mItemToActions.get(item).getString("command"); + if (command != null) { + player.performCommand(command); + } + if (mItemToActions.get(item).getBoolean("close_gui", false)) { + close(); + } return; } else if (slot == mDeselectSlot) { mManager.mCurrentIndex.put(player, mManager.showCurrentQuest(player, -1)); @@ -203,11 +259,18 @@ protected void inventoryClick(InventoryClickEvent event) { } else if (slot == mCustomSlot && event.isShiftClick() && item.getType() == Material.KNOWLEDGE_BOOK) { mManager.removeCommandWaypoint(player); player.playSound(player.getLocation(), "minecraft:entity.armadillo.scute_drop", SoundCategory.PLAYERS, 1f, 1f); - setupInventory(); + setupInventory(mPage); + return; + } else if (slot == mNextSlot) { + setupInventory(mPage + 1); + player.playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, SoundCategory.PLAYERS, 1f, 1.5f); return; - } else if (mDeathSlots.contains(slot) && item.getType() == Material.SKULL_POTTERY_SHERD) { + } else if (slot == mPrevSlot) { + setupInventory(mPage - 1); + player.playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, SoundCategory.PLAYERS, 1f, 1.5f); return; - } else if (slot == mCustomSlot && item.getType() == Material.HOPPER) { + } else if (!item.getItemMeta().hasCustomModelData()) { + // Item has no function return; } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index 811e9e12..c64fa92b 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -8,13 +8,10 @@ import com.playmonumenta.scriptedquests.quests.components.QuestLocation; import com.playmonumenta.scriptedquests.utils.MessagingUtils; import com.playmonumenta.scriptedquests.utils.QuestUtils; -import com.playmonumenta.scriptedquests.utils.WorldRegexMatcher; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.UUID; import java.util.WeakHashMap; import net.kyori.adventure.text.Component; @@ -33,7 +30,6 @@ public class QuestCompassManager { public final Map mCompassCache = new HashMap(); public final Map mCurrentIndex = new WeakHashMap<>(); public final Plugin mPlugin; - public static WorldRegexMatcher mWorldRegexMatcher = null; /* One command-specified waypoint per player */ public final Map mCommandWaypoints = new HashMap(); @@ -67,6 +63,11 @@ public void directPlayer(WaypointManager mgr, Player player, boolean isRemovable } else { MessagingUtils.sendRawMessage(player, mTitle + ": " + mLocation.getMessage(), mAllowTranslations); } + if (!player.getWorld().getName().matches(mLocation.getWorldRegex())) { + MessagingUtils.sendRawMessage(player, "&7(This location is on a &cdifferent world!&7 Find a way to the correct world before following the compass.)", mAllowTranslations); + + } + mgr.setWaypoint(player, mLocation); } } @@ -106,13 +107,6 @@ public void reload(Plugin plugin, @Nullable CommandSender sender) { mQuests.add(quest); return quest.getQuestName() + ":" + Integer.toString(quest.getMarkers().size()); }); - final Set worldRegexes = new HashSet<>(); - for (QuestCompass qc : mQuests) { - for (CompassLocation cl : qc.getMarkers()) { - worldRegexes.add(cl.getWorldRegex()); - } - } - mWorldRegexMatcher = new WorldRegexMatcher(worldRegexes); } @SuppressWarnings("unchecked") @@ -217,11 +211,11 @@ public void cycleQuestTracker(Player player) { } /* One command-specified waypoint per player */ - public void setCommandWaypoint(Player player, List steps, String title, String message) { - ValidCompassEntry entry = new ValidCompassEntry(new CompassLocation(null, message, steps), title, false, CompassEntryType.Waypoint); + public void setCommandWaypoint(Player player, List steps, String title, String message, String worldRegex) { + invalidateCache(player); + ValidCompassEntry entry = new ValidCompassEntry(new CompassLocation(null, message, steps, worldRegex), title, false, CompassEntryType.Waypoint); mCommandWaypoints.put(player.getUniqueId(), entry); mCurrentIndex.put(player, getCurrentMarkerTitles(player).indexOf(mCommandWaypoints.get(player.getUniqueId()))); - invalidateCache(player); entry.directPlayer(mPlugin.mWaypointManager, player, true); } @@ -237,12 +231,4 @@ public void removeCommandWaypoint(Player player) { public void invalidateCache(Player player) { mCompassCache.remove(player.getUniqueId()); } - - public WorldRegexMatcher getWorldRegexMatcher() { - WorldRegexMatcher matcher = mWorldRegexMatcher; - if (matcher == null) { - throw new RuntimeException("WorldRegexMatcher unavailable before ScriptedQuests finishes loading"); - } - return matcher; - } } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/CompassLocation.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/CompassLocation.java index b50bd948..9a1e40e6 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/CompassLocation.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/CompassLocation.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -31,7 +32,7 @@ public CompassLocation(World world, JsonElement element) throws Exception { throw new Exception("Failed to parse location prerequisites!"); } - mWorldRegex = object.has("world_name") ? object.get("world_name").toString() : ".*"; + mWorldRegex = object.has("world_name") ? object.get("world_name").toString().replaceAll("\"", "") : Bukkit.getWorlds().get(0).getName(); mPrerequisites = new QuestPrerequisites(prereq); @@ -105,11 +106,11 @@ public CompassLocation(World world, JsonElement element) throws Exception { } //If QuestPrerequisites is null, prerequisites always met - public CompassLocation(@Nullable QuestPrerequisites questPrereq, String message, List waypoints) { + public CompassLocation(@Nullable QuestPrerequisites questPrereq, String message, List waypoints, String worldRegex) { mPrerequisites = questPrereq; mMessage = message; mWaypoints.addAll(waypoints); - mWorldRegex = ".*"; + mWorldRegex = worldRegex; } @Override diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java index 9179558b..b1bc2f54 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java @@ -13,7 +13,7 @@ public class DeathLocation implements QuestLocation { public DeathLocation(Location loc, long deathTime, World world) { mDeathTime = deathTime; mWaypoints.add(loc); - mWorld = world.getName(); + mWorld = world.getName().replaceAll("\\d+", ".+"); } public String getTimeDifference(long compareTime) { diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java index 60557244..cdb9af10 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/utils/WorldRegexMatcher.java @@ -55,8 +55,7 @@ public boolean matches(World world, String worldRegex) { } public boolean matches(String worldName, String worldRegex) { - if ( - worldRegex == null + if (worldRegex == null || worldRegex.isEmpty() || worldRegex.equals(".*") || worldRegex.equals(worldName) diff --git a/tools/schema/quest_location.json b/tools/schema/quest_location.json index c285e052..2bc7010d 100644 --- a/tools/schema/quest_location.json +++ b/tools/schema/quest_location.json @@ -36,9 +36,8 @@ "required": false, "propertyOrder": 4, "title": "world_name", - "description": "A regular expression (regex) that matches one or more world names completely. Inherits from the file containing it. If not set at all, it defaults to \".*\". See regex101.com for help.", - "type": "string", - "default": ".*" + "description": "A regular expression (regex) that matches one or more world names. Using /worlds in game will tell you the name of your current world if you are unsure. If not set at all, this defaults to using Bukkit.getWorlds().get(0).getName(). See regex101.com for help.", + "type": "string" } } } From bba00f0ad7e1615b47860552d32ec164cc61275f Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Mon, 21 Jul 2025 22:41:08 +0200 Subject: [PATCH 11/19] Unpublicified --- .../managers/QuestCompassManager.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index c64fa92b..36bd10b3 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -26,13 +26,13 @@ public class QuestCompassManager { - public final List mQuests = new ArrayList(); - public final Map mCompassCache = new HashMap(); + private final List mQuests = new ArrayList(); + private final Map mCompassCache = new HashMap(); public final Map mCurrentIndex = new WeakHashMap<>(); - public final Plugin mPlugin; + private final Plugin mPlugin; /* One command-specified waypoint per player */ - public final Map mCommandWaypoints = new HashMap(); + private final Map mCommandWaypoints = new HashMap(); public static class ValidCompassEntry { public final QuestLocation mLocation; @@ -41,7 +41,7 @@ public static class ValidCompassEntry { public final CompassEntryType mType; public final int[] mMarkersIndex; - public ValidCompassEntry(QuestLocation loc, String title, boolean allowTranslations, CompassEntryType type) { + private ValidCompassEntry(QuestLocation loc, String title, boolean allowTranslations, CompassEntryType type) { mLocation = loc; mTitle = title; mAllowTranslations = allowTranslations; @@ -49,7 +49,7 @@ public ValidCompassEntry(QuestLocation loc, String title, boolean allowTranslati mMarkersIndex = new int[]{1, 1}; } - public ValidCompassEntry(QuestLocation loc, String title, boolean allowTranslations, CompassEntryType type, int[] markersIndex) { + private ValidCompassEntry(QuestLocation loc, String title, boolean allowTranslations, CompassEntryType type, int[] markersIndex) { mLocation = loc; mTitle = title; mAllowTranslations = allowTranslations; @@ -57,7 +57,7 @@ public ValidCompassEntry(QuestLocation loc, String title, boolean allowTranslati mMarkersIndex = markersIndex; } - public void directPlayer(WaypointManager mgr, Player player, boolean isRemovable) { + private void directPlayer(WaypointManager mgr, Player player, boolean isRemovable) { if (isRemovable) { MessagingUtils.sendClickableMessage(player, mTitle + ": " + mLocation.getMessage(), mAllowTranslations, "/waypoint remove @s", HoverEvent.showText(Component.text("Click to remove this waypoint."))); } else { @@ -78,16 +78,16 @@ public enum CompassEntryType { Waypoint() } - public static class CompassCacheEntry { + private static class CompassCacheEntry { public final int mLastRefresh; public final List mEntries; - public CompassCacheEntry(Player player, List entries) { + private CompassCacheEntry(Player player, List entries) { mLastRefresh = player.getTicksLived(); mEntries = entries; } - public boolean isStillValid(Player player) { + private boolean isStillValid(Player player) { return Math.abs(player.getTicksLived() - mLastRefresh) < 200; } } From 2db620032197f57ecb0b3740c1414b5a071246c2 Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Mon, 21 Jul 2025 22:43:28 +0200 Subject: [PATCH 12/19] Update quest_location.json --- tools/schema/quest_location.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/schema/quest_location.json b/tools/schema/quest_location.json index 2bc7010d..817f550f 100644 --- a/tools/schema/quest_location.json +++ b/tools/schema/quest_location.json @@ -5,7 +5,7 @@ "waypoints", "message" ], - "additionalProperties": true, + "additionalProperties": false, "properties": { "prerequisites": { "required": true, From 2c49a35ab6981264b67beb67384870fb7a0f3e82 Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Mon, 21 Jul 2025 23:19:51 +0200 Subject: [PATCH 13/19] Distinct base items --- .../scriptedquests/managers/QuestCompassGui.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 6537ae03..89332ab0 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -169,8 +169,8 @@ private void setupInventory(int page) { if (mManager.mCurrentIndex.getOrDefault(mPlayer, 0) == i) { switch (quest.mType) { default -> material = Material.ENCHANTED_BOOK; - case Death -> material = Material.ARMOR_STAND; - case Waypoint -> material = Material.KNOWLEDGE_BOOK; + case Death -> material = Material.TOTEM_OF_UNDYING; + case Waypoint -> material = Material.BAMBOO_RAFT; } itemName = itemName.append(Component.text(" (Currently Tracking)", selectedColor).decoration(TextDecoration.BOLD, false).decoration(TextDecoration.ITALIC, false)); } else { From 35f206fa669cdaff338196051de50b8227f4722c Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Mon, 21 Jul 2025 23:37:47 +0200 Subject: [PATCH 14/19] Review dog --- .../managers/QuestCompassManager.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index 36bd10b3..0baa3e27 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -199,11 +199,14 @@ public void cycleQuestTracker(Player player) { return; } - ValidCompassEntry quest = mCompassCache.get(player.getUniqueId()).mEntries.get(index); - if (quest.mMarkersIndex[0] == quest.mMarkersIndex[1]) { - index += 1 - quest.mMarkersIndex[1]; - } else { - index += 1; + QuestCompassManager.CompassCacheEntry cacheEntryMap = mCompassCache.get(player.getUniqueId()); + if (cacheEntryMap != null) { + ValidCompassEntry quest = cacheEntryMap.mEntries.get(index); + if (quest.mMarkersIndex[0] == quest.mMarkersIndex[1]) { + index += 1 - quest.mMarkersIndex[1]; + } else { + index += 1; + } } mCurrentIndex.put(player, showCurrentQuest(player, index)); From 35fea1d66c8fc939a70a8a0291d89d5ae569a00e Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Tue, 22 Jul 2025 00:01:27 +0200 Subject: [PATCH 15/19] Fix for non ops and removing custom waypoint --- .../scriptedquests/managers/QuestCompassGui.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 89332ab0..869aacd4 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -4,6 +4,7 @@ import com.playmonumenta.scriptedquests.utils.CustomInventory; import com.playmonumenta.scriptedquests.utils.InventoryUtils; import com.playmonumenta.scriptedquests.managers.QuestCompassManager.ValidCompassEntry; +import com.playmonumenta.scriptedquests.utils.NmsUtils; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -245,7 +246,7 @@ protected void inventoryClick(InventoryClickEvent event) { if (mItemToActions.containsKey(item)) { String command = mItemToActions.get(item).getString("command"); if (command != null) { - player.performCommand(command); + NmsUtils.getVersionAdapter().runConsoleCommandSilently(command.replace("@S", mPlayer.getName())); } if (mItemToActions.get(item).getBoolean("close_gui", false)) { close(); @@ -256,7 +257,7 @@ protected void inventoryClick(InventoryClickEvent event) { player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_CLOSE, SoundCategory.PLAYERS, 1f, 0.8f); close(); return; - } else if (slot == mCustomSlot && event.isShiftClick() && item.getType() == Material.KNOWLEDGE_BOOK) { + } else if (slot == mCustomSlot && event.isShiftClick() && item.getItemMeta().hasCustomModelData()) { mManager.removeCommandWaypoint(player); player.playSound(player.getLocation(), "minecraft:entity.armadillo.scute_drop", SoundCategory.PLAYERS, 1f, 1f); setupInventory(mPage); From 50941378908fb425deaecc0f1b4b72306e9b40ed Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Wed, 23 Jul 2025 21:16:37 +0200 Subject: [PATCH 16/19] NBTified --- .../managers/QuestCompassGui.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 869aacd4..5c929ee5 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -1,10 +1,15 @@ package com.playmonumenta.scriptedquests.managers; +import com.google.gson.JsonElement; import com.playmonumenta.scriptedquests.Plugin; +import com.playmonumenta.scriptedquests.quests.components.GuiItem; +import com.playmonumenta.scriptedquests.quests.components.NbtTags; import com.playmonumenta.scriptedquests.utils.CustomInventory; import com.playmonumenta.scriptedquests.utils.InventoryUtils; import com.playmonumenta.scriptedquests.managers.QuestCompassManager.ValidCompassEntry; +import com.playmonumenta.scriptedquests.utils.JsonUtils; import com.playmonumenta.scriptedquests.utils.NmsUtils; +import de.tr7zw.nbtapi.NBTItem; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -35,8 +40,9 @@ public class QuestCompassGui extends CustomInventory { private final int mDeselectSlot = 28 + 9 * (mRows - 4); private final int mNextSlot = 44; private final int mPrevSlot = 36; - private int mPage; + private int mPage = 0; private final Map mItemToActions = new HashMap<>(); + private final String mNBTTag = "quest_index"; public QuestCompassGui(Player player, QuestCompassManager manager) { super(player, Math.min(36 + 9 * (manager.getCurrentMarkerTitles(player).stream().filter( @@ -44,7 +50,6 @@ public QuestCompassGui(Player player, QuestCompassManager manager) { "Quest Compass"); mPlayer = player; mManager = manager; - mPage = 0; } @Override @@ -149,8 +154,6 @@ private void setupInventory(int page) { continue; } - ItemStack displayItem; - NamedTextColor titleColor; NamedTextColor selectedColor = NamedTextColor.DARK_AQUA; if (quest.mType == QuestCompassManager.CompassEntryType.Death) { @@ -189,13 +192,10 @@ private void setupInventory(int page) { slot = 30 + 9 * (mRows - 4); } - displayItem = new ItemStack(material); + ItemStack displayItem = new ItemStack(material); ItemMeta meta = displayItem.getItemMeta(); meta.displayName(itemName); - // Use this as a quest index tag for inventoryClick to easily identify quest index. The resource pack will not be using this so there is no overlap. - meta.setCustomModelData(i); - // Compile all steps and highlight the one that matches this quest index (j == i) List lore = new ArrayList<>(); for (int j = i + 1 - quest.mMarkersIndex[0]; j < i + 1 - quest.mMarkersIndex[0] + quest.mMarkersIndex[1]; j++) { @@ -224,6 +224,10 @@ private void setupInventory(int page) { meta.lore(lore); displayItem.setItemMeta(meta); + // Use NBT as a quest index tag for inventoryClick to easily identify quest index + NBTItem nbtItem = new NBTItem(displayItem); + nbtItem.setInteger(mNBTTag, i); + displayItem = nbtItem.getItem(); mInventory.setItem(slot, displayItem); } @@ -243,6 +247,7 @@ protected void inventoryClick(InventoryClickEvent event) { || item == null) { return; } + NBTItem nbtItem = new NBTItem(item); if (mItemToActions.containsKey(item)) { String command = mItemToActions.get(item).getString("command"); if (command != null) { @@ -257,7 +262,7 @@ protected void inventoryClick(InventoryClickEvent event) { player.playSound(player.getLocation(), Sound.BLOCK_WOODEN_TRAPDOOR_CLOSE, SoundCategory.PLAYERS, 1f, 0.8f); close(); return; - } else if (slot == mCustomSlot && event.isShiftClick() && item.getItemMeta().hasCustomModelData()) { + } else if (slot == mCustomSlot && event.isShiftClick() && nbtItem.getInteger(mNBTTag) > 0) { mManager.removeCommandWaypoint(player); player.playSound(player.getLocation(), "minecraft:entity.armadillo.scute_drop", SoundCategory.PLAYERS, 1f, 1f); setupInventory(mPage); @@ -270,12 +275,12 @@ protected void inventoryClick(InventoryClickEvent event) { setupInventory(mPage - 1); player.playSound(player.getLocation(), Sound.ITEM_BOOK_PAGE_TURN, SoundCategory.PLAYERS, 1f, 1.5f); return; - } else if (!item.getItemMeta().hasCustomModelData()) { - // Item has no function + } else if (!nbtItem.hasTag(mNBTTag)) { + // Item has no function and is not a quest return; } - int index = item.getItemMeta().getCustomModelData(); + int index = nbtItem.getInteger(mNBTTag); mManager.mCurrentIndex.put(player, mManager.showCurrentQuest(player, index)); player.playSound(player.getLocation(), Sound.UI_LOOM_TAKE_RESULT, SoundCategory.PLAYERS, 1f, 1f); if (slot == mCustomSlot) { From 0d3972f93851c7dcbb0ffd8d0222036c70c2963d Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Wed, 23 Jul 2025 21:26:00 +0200 Subject: [PATCH 17/19] Fine reviewdog --- .../playmonumenta/scriptedquests/commands/Waypoint.java | 2 +- .../scriptedquests/managers/QuestCompassManager.java | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java index c340bf27..715f5b55 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java @@ -43,7 +43,7 @@ public static void register(Plugin plugin) { if (plugin.mQuestCompassManager != null) { List waypoint = new ArrayList<>(); waypoint.add(args.getByArgument(locationArg)); - plugin.mQuestCompassManager.setCommandWaypoint(targetPlayer, waypoint, args.getByArgument(titleArg) + ChatColor.RESET, args.getByArgument(messageArg), args.getByArgumentOrDefault(regexArg, targetPlayer != null ? targetPlayer.getWorld().getName() : ".*")); + plugin.mQuestCompassManager.setCommandWaypoint(targetPlayer, waypoint, args.getByArgument(titleArg) + "§r", args.getByArgument(messageArg), args.getByArgumentOrDefault(regexArg, targetPlayer != null ? targetPlayer.getWorld().getName() : ".*")); } else { throw CommandAPI.failWithString("Quest Compass Manager does not exist!"); } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index 0baa3e27..3c03e3af 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -16,7 +16,6 @@ import java.util.WeakHashMap; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.SoundCategory; @@ -130,8 +129,7 @@ public List getCurrentMarkerTitles(Player player) { // Add all the valid markers/titles to the list for (int i = 0; i < questMarkers.size(); i++) { - String title = ChatColor.AQUA + "" + ChatColor.BOLD + quest.getQuestName() - + ChatColor.RESET + "" + ChatColor.AQUA; + String title = "§b§l" + quest.getQuestName() + "§r§b"; if (questMarkers.size() > 1) { title += " [" + (i + 1) + "/" + questMarkers.size() + "]"; @@ -146,8 +144,7 @@ public List getCurrentMarkerTitles(Player player) { List deathEntries = (List)player.getMetadata(Constants.PLAYER_DEATH_LOCATION_METAKEY).get(0).value(); for (int i = 0; i < deathEntries.size(); i++) { - String title = ChatColor.RED + "" + ChatColor.BOLD + "Death" - + ChatColor.RESET + "" + ChatColor.AQUA; + String title = "§c§lDeath§r§b"; if (deathEntries.size() > 1) { title += " [" + (i + 1) + "/" + deathEntries.size() + "]"; From faeef4ca643f63c8d51a560e5b73d23d7bfb6b99 Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Wed, 23 Jul 2025 21:28:53 +0200 Subject: [PATCH 18/19] Unused imports --- .../com/playmonumenta/scriptedquests/commands/Waypoint.java | 1 - .../scriptedquests/listeners/PlayerListener.java | 1 - .../scriptedquests/managers/QuestCompassGui.java | 4 ---- 3 files changed, 6 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java index 715f5b55..cdbafa03 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/commands/Waypoint.java @@ -10,7 +10,6 @@ import dev.jorel.commandapi.arguments.TextArgument; import java.util.ArrayList; import java.util.List; -import net.md_5.bungee.api.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java index 8c9c62dc..29969176 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java @@ -3,7 +3,6 @@ import com.playmonumenta.scriptedquests.Constants; import com.playmonumenta.scriptedquests.Plugin; import com.playmonumenta.scriptedquests.managers.QuestCompassGui; -import com.playmonumenta.scriptedquests.managers.QuestCompassManager; import com.playmonumenta.scriptedquests.managers.SongManager; import com.playmonumenta.scriptedquests.point.Point; import com.playmonumenta.scriptedquests.quests.QuestDeath.DeathActions; diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 5c929ee5..53d1835c 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -1,13 +1,9 @@ package com.playmonumenta.scriptedquests.managers; -import com.google.gson.JsonElement; import com.playmonumenta.scriptedquests.Plugin; -import com.playmonumenta.scriptedquests.quests.components.GuiItem; -import com.playmonumenta.scriptedquests.quests.components.NbtTags; import com.playmonumenta.scriptedquests.utils.CustomInventory; import com.playmonumenta.scriptedquests.utils.InventoryUtils; import com.playmonumenta.scriptedquests.managers.QuestCompassManager.ValidCompassEntry; -import com.playmonumenta.scriptedquests.utils.JsonUtils; import com.playmonumenta.scriptedquests.utils.NmsUtils; import de.tr7zw.nbtapi.NBTItem; import java.util.ArrayList; From e487a8ec381beaf8e080bfda7c1b358a26b4c0ec Mon Sep 17 00:00:00 2001 From: xernial <148793048+xerniale@users.noreply.github.com> Date: Wed, 23 Jul 2025 23:41:44 +0200 Subject: [PATCH 19/19] Comments plus bug fix --- .../scriptedquests/listeners/PlayerListener.java | 2 +- .../scriptedquests/managers/QuestCompassGui.java | 16 +++++++++------- .../managers/QuestCompassManager.java | 2 +- .../quests/components/DeathLocation.java | 5 ++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java index 29969176..77fd432a 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/listeners/PlayerListener.java @@ -173,7 +173,7 @@ public void playerDeathEvent(PlayerDeathEvent event) { } // Add this death location to the beginning of the list - deathEntries.add(0, new DeathLocation(event.getEntity().getLocation(), System.currentTimeMillis(), event.getEntity().getWorld())); + deathEntries.add(0, new DeathLocation(event.getEntity().getLocation(), System.currentTimeMillis())); if (deathEntries.size() > 3) { deathEntries.remove(3); } diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java index 53d1835c..794744bc 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassGui.java @@ -10,7 +10,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; @@ -63,14 +62,17 @@ private void setupInventory(int page) { ConfigurationSection itemConfig = mPlugin.mQuestCompassGUIItems.getConfigurationSection(key); if (itemConfig != null) { String name = itemConfig.getString("name"); - Material material = Material.getMaterial(Objects.requireNonNull(itemConfig.getString("material"))); - TextColor nameColor = TextColor.fromHexString(Objects.requireNonNull(itemConfig.getString("name_color"))); - TextColor loreColor = TextColor.fromHexString(Objects.requireNonNull(itemConfig.getString("lore_color"))); + String materialName = itemConfig.getString("material"); + String nameColorHex = itemConfig.getString("name_color"); + String loreColorHex = itemConfig.getString("lore_color"); name = name != null ? name : "Name Unset"; - material = material != null ? material : Material.BARRIER; - nameColor = nameColor != null ? nameColor : NamedTextColor.LIGHT_PURPLE; - loreColor = loreColor != null ? loreColor : NamedTextColor.DARK_PURPLE; + Material material = materialName != null ? Material.getMaterial(materialName) : Material.BARRIER; + if (material == null) { + material = Material.BARRIER; + } + TextColor nameColor = nameColorHex != null ? TextColor.fromHexString(nameColorHex) : NamedTextColor.LIGHT_PURPLE; + TextColor loreColor = loreColorHex != null ? TextColor.fromHexString(loreColorHex) : NamedTextColor.DARK_PURPLE; List lores = new ArrayList<>(); ConfigurationSection loresConfig = itemConfig.getConfigurationSection("lore"); diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java index 3c03e3af..f8589057 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/managers/QuestCompassManager.java @@ -64,7 +64,6 @@ private void directPlayer(WaypointManager mgr, Player player, boolean isRemovabl } if (!player.getWorld().getName().matches(mLocation.getWorldRegex())) { MessagingUtils.sendRawMessage(player, "&7(This location is on a &cdifferent world!&7 Find a way to the correct world before following the compass.)", mAllowTranslations); - } mgr.setWaypoint(player, mLocation); @@ -171,6 +170,7 @@ public int showCurrentQuest(Player player, int index) { if (index >= entries.size()) { index = 0; + mCurrentIndex.put(player, index); } if (entries.isEmpty() || index == -1) { diff --git a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java index b1bc2f54..817994b7 100644 --- a/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java +++ b/plugin/src/main/java/com/playmonumenta/scriptedquests/quests/components/DeathLocation.java @@ -3,17 +3,16 @@ import java.util.ArrayList; import java.util.List; import org.bukkit.Location; -import org.bukkit.World; public class DeathLocation implements QuestLocation { private final long mDeathTime; private final List mWaypoints = new ArrayList<>(1); private final String mWorld; - public DeathLocation(Location loc, long deathTime, World world) { + public DeathLocation(Location loc, long deathTime) { mDeathTime = deathTime; mWaypoints.add(loc); - mWorld = world.getName().replaceAll("\\d+", ".+"); + mWorld = loc.getWorld().getName().replaceAll("\\d+", ".+"); } public String getTimeDifference(long compareTime) {