Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,11 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) {
boolean hidden = config.getBoolean("options.hidden", false);
int cooldownTime = config.getInt("options.cooldown.time", 10);
int timeLimtTime = config.getInt("options.time-limit.time", 10);

// Modifica: Lettura slot manuale (default -1) e ordinamento
int displaySlot = config.getInt("options.display-slot", -1);
int sortOrder = config.getInt("options.sort-order", 1);

String category = config.getString("options.category");
Map<String, String> placeholders = new HashMap<>();
Map<String, String> progressPlaceholders = new HashMap<>();
Expand Down Expand Up @@ -320,6 +324,8 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) {
.withProgressPlaceholders(progressPlaceholders)
.withCooldown(cooldownTime)
.withTimeLimit(timeLimtTime)
// Modifica: Passiamo al builder il displaySlot
.withDisplaySlot(displaySlot)
.withSortOrder(sortOrder)
.withCooldownEnabled(cooldown)
.withTimeLimitEnabled(timeLimit)
Expand Down Expand Up @@ -600,4 +606,4 @@ private QItemStack getQItemStack(String path, FileConfiguration config) {
return new QItemStack(plugin, name, loreNormal, loreStarted, is);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
import com.leonardobishop.quests.bukkit.menu.element.PageDescMenuElement;
import com.leonardobishop.quests.bukkit.menu.element.PageNextMenuElement;
import com.leonardobishop.quests.bukkit.menu.element.PagePrevMenuElement;
import com.leonardobishop.quests.bukkit.menu.element.QuestMenuElement;
import com.leonardobishop.quests.bukkit.menu.element.SpacerMenuElement;
import com.leonardobishop.quests.bukkit.util.MenuUtils;
import com.leonardobishop.quests.bukkit.util.lang3.StringUtils;
import com.leonardobishop.quests.common.player.QPlayer;
import com.leonardobishop.quests.common.quest.Quest; // Import necessario per accedere al metodo getDisplaySlot
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.Iterator;
import java.util.List;

public abstract class PaginatedQMenu extends QMenu {
Expand Down Expand Up @@ -75,6 +78,10 @@ public void setMaxPage(int maxPage) {
}

public void populate(String customElementsPath, List<MenuElement> menuElementsToFill, BackMenuElement backMenuElement) {
populate(customElementsPath, menuElementsToFill, backMenuElement, null, null);
}

protected void populate(String customElementsPath, List<MenuElement> menuElementsToFill, BackMenuElement backMenuElement, BukkitQuestsPlugin questPlugin, QMenu questMenu) {
Player player = Bukkit.getPlayer(owner.getPlayerUUID());
if (player == null) {
return;
Expand All @@ -95,15 +102,22 @@ public void populate(String customElementsPath, List<MenuElement> menuElementsTo
int repeat = plugin.getConfig().getInt(customElementsPath + "." + s + ".repeat");
boolean staticElement = plugin.getConfig().getBoolean(customElementsPath + "." + s + ".static", false);

MenuElement menuElement;
MenuElement menuElement = null;
if (plugin.getConfig().contains(customElementsPath + "." + s + ".display")) {
ItemStack is = plugin.getConfiguredItemStack(customElementsPath + "." + s + ".display", plugin.getConfig());
List<String> commands = plugin.getQuestsConfig().getStringList(customElementsPath + "." + s + ".commands");
menuElement = new CustomMenuElement(plugin, owner.getPlayerUUID(), is, commands);
} else if (plugin.getConfig().getBoolean(customElementsPath + "." + s + ".spacer", false)) {
menuElement = spacer;
} else {
continue; // user = idiot
} else if (plugin.getConfig().contains(customElementsPath + "." + s + ".quest-id")) {
String questId = plugin.getConfig().getString(customElementsPath + "." + s + ".quest-id");
if (questPlugin != null && questId != null) {
menuElement = createQuestMenuElement(questPlugin, questId, menuElementsToFill, questMenu);
}
}

if (menuElement == null) {
continue;
}

for (int i = 0; i <= repeat; i++) {
Expand Down Expand Up @@ -147,8 +161,8 @@ public void populate(String customElementsPath, List<MenuElement> menuElementsTo

// else find a place for the back button if needed
} else if (backMenuElement != null && backMenuElement.isEnabled()) {
int slot = trim ? MenuUtils.getHigherOrEqualMultiple(menuElements.size() + menuElementsToFill.size() + customStaticElements, 9)
: backMenuElement.getSlot(); // place the back button at the defined slot
int slot = trim ? MenuUtils.getHigherOrEqualMultiple(menuElements.size() + menuElementsToFill.size() + customStaticElements, 9)
: backMenuElement.getSlot(); // place the back button at the defined slot
staticMenuElements[slot] = backMenuElement;
}

Expand All @@ -164,16 +178,39 @@ public void populate(String customElementsPath, List<MenuElement> menuElementsTo
return;
}

// fill in the remaining menu elements into empty slots
// --- INIZIO MODIFICA: Logica Slot Manuali ---
// 1. Prima inseriamo gli elementi che hanno uno slot specifico (displaySlot)
// Usiamo un iteratore per poter rimuovere gli elementi dalla lista "da riempire"
Iterator<MenuElement> iterator = menuElementsToFill.iterator();
while (iterator.hasNext()) {
MenuElement element = iterator.next();
if (element instanceof QuestMenuElement) {
QuestMenuElement qElement = (QuestMenuElement) element;
// Metodo getQuest() è presente in QuestMenuElement (verifica ok)
Quest quest = qElement.getQuest();
if (quest != null) {
int manualSlot = quest.getDisplaySlot();
// Se lo slot è valido (es. 22), lo inseriamo direttamente
if (manualSlot >= 0) {
menuElements.put(manualSlot, element);
iterator.remove(); // Rimuoviamo dalla lista così non viene reinserito dopo
}
}
}
}

// 2. Riempiamo gli spazi vuoti con gli elementi rimanenti (senza slot specifico)
int slot = 0;
for (MenuElement element : menuElementsToFill) {
fillStaticMenuElements(slot, staticMenuElements);
// Cerca il prossimo slot libero (salta quelli occupati da elementi statici o quest manuali)
while (menuElements.containsKey(slot)) {
slot++;
fillStaticMenuElements(slot, staticMenuElements);
}
menuElements.put(slot, element);
}
// --- FINE MODIFICA ---

this.minPage = 1;
this.maxPage = (menuElements.isEmpty() ? 0 : Ints.max(menuElements.keys)) / pageSize + 1;
Expand Down Expand Up @@ -237,4 +274,18 @@ public Inventory draw() {
int pageOffset = (currentPage - 1) * pageSize;
return super.getMenuElementAt(slot + pageOffset);
}
}

private MenuElement createQuestMenuElement(BukkitQuestsPlugin questPlugin, String questId, List<MenuElement> menuElementsToFill, QMenu questMenu) {
Iterator<MenuElement> iterator = menuElementsToFill.iterator();
while (iterator.hasNext()) {
MenuElement element = iterator.next();
if (element instanceof QuestMenuElement questMenuElement) {
if (questMenuElement.getQuestId().equals(questId)) {
iterator.remove();
return element;
}
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.leonardobishop.quests.common.player.questprogressfile.QuestProgress;
import com.leonardobishop.quests.common.quest.Category;
import com.leonardobishop.quests.common.quest.Quest;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Bukkit;
import org.jspecify.annotations.Nullable;

Expand All @@ -25,7 +27,7 @@ public class QuestQMenu extends PaginatedQMenu {
private final String categoryName;

public QuestQMenu(BukkitQuestsPlugin plugin, QPlayer owner, List<Quest> quests, @Nullable Category category, CategoryQMenu categoryQMenu) {
super(owner, Chat.legacyColor(guiName(plugin, category)),
super(owner, Chat.legacyColor(PlaceholderAPI.setPlaceholders(Bukkit.getPlayer(owner.getPlayerUUID()) ,(guiName(plugin, category)))),
plugin.getQuestsConfig().getBoolean("options.trim-gui-size.quests-menu"), 54, plugin);

BukkitQuestsConfig config = (BukkitQuestsConfig) plugin.getQuestsConfig();
Expand Down Expand Up @@ -58,22 +60,22 @@ public QuestQMenu(BukkitQuestsPlugin plugin, QPlayer owner, List<Quest> quests,
} else {
path = "custom-elements.quests";
}
super.populate(path, filteredQuests, backMenuElement);
super.populate(path, filteredQuests, backMenuElement, plugin, this);
}

public String getCategoryName() {
return categoryName;
}

private static String guiName(final BukkitQuestsPlugin plugin, final @Nullable Category category) {

if (category != null) {
final String guiName = category.getGUIName();

if (guiName != null) {
return guiName;
}
}

return plugin.getQuestsConfig().getString("options.guinames.quests-menu");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ public class Quest implements Comparable<Quest> {
private int cooldown;
private boolean timeLimitEnabled;
private int timeLimit;

// Manteniamo sortOrder per compatibilità ma useremo displaySlot per l'ordinamento
private int sortOrder;

// NUOVO CAMPO
private int displaySlot;

private boolean permissionRequired;
private boolean autoStartEnabled;
private boolean cancellable;
Expand Down Expand Up @@ -311,6 +317,14 @@ public int getSortOrder() {
return sortOrder;
}

/**
* Get the specific display slot for this quest.
* * @return the slot index (0-53) or -1 if not set
*/
public int getDisplaySlot() {
return displaySlot;
}

/**
* Get if quest-specific autostart is enabled for this quest.
*
Expand Down Expand Up @@ -357,15 +371,17 @@ public boolean isHidden() {
}

/**
* Compare the sort orders for this quest with another quest.
* Compare the quests.
* Modified to prioritise displaySlot over sortOrder.
*
* @see Comparable#compareTo(Object)
* @param quest the quest to compare with
* @return a negative integer, zero, or a positive integer
*/
@Override
public int compareTo(@NotNull Quest quest) {
return (sortOrder - quest.sortOrder);
// MODIFICA: Utilizza displaySlot per il confronto
return Integer.compare(this.displaySlot, quest.displaySlot);
}

public static class Builder {
Expand All @@ -387,6 +403,8 @@ public static class Builder {
private boolean timeLimitEnabled = false;
private int timeLimit = 0;
private int sortOrder = 1;
// NUOVO CAMPO NEL BUILDER
private int displaySlot = -1;
private boolean permissionRequired = false;
private boolean autoStartEnabled = false;
private boolean cancellable = true;
Expand Down Expand Up @@ -456,6 +474,12 @@ public Builder withSortOrder(int sortOrder) {
return this;
}

// NUOVO METODO NEL BUILDER
public Builder withDisplaySlot(int displaySlot) {
this.displaySlot = displaySlot;
return this;
}

public Builder withCooldown(int cooldown) {
this.cooldown = cooldown;
return this;
Expand Down Expand Up @@ -545,6 +569,8 @@ public Quest build() {
quest.timeLimitEnabled = this.timeLimitEnabled;
quest.timeLimit = this.timeLimit;
quest.sortOrder = this.sortOrder;
// ASSEGNAZIONE NUOVO CAMPO
quest.displaySlot = this.displaySlot;
quest.permissionRequired = this.permissionRequired;
quest.autoStartEnabled = this.autoStartEnabled;
quest.countsTowardsLimit = this.countsTowardsLimit;
Expand Down