mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-22 02:25:42 +01:00
Separate method to prepare GUI items
This commit is contained in:
parent
70615b30c9
commit
565bfe02e0
@ -65,6 +65,7 @@ import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@ -590,6 +591,42 @@ public class Quest implements IQuest {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format GUI display item with applicable display name, lore, and item flags
|
||||
*
|
||||
* @param quester The quester to prepare for
|
||||
* @return formatted item
|
||||
*/
|
||||
public ItemStack prepareDisplay(final Quester quester) {
|
||||
final ItemStack display = getGUIDisplay().clone();
|
||||
final ItemMeta meta = display.getItemMeta();
|
||||
if (meta != null) {
|
||||
final Player player = quester.getPlayer();
|
||||
if (quester.getCompletedQuests().contains(this)) {
|
||||
meta.setDisplayName(ChatColor.DARK_PURPLE + ConfigUtil.parseString(getName()
|
||||
+ " " + ChatColor.GREEN + Lang.get(player, "redoCompleted"), getNpcStart()));
|
||||
} else {
|
||||
meta.setDisplayName(ChatColor.DARK_PURPLE + ConfigUtil.parseString(getName(), getNpcStart()));
|
||||
}
|
||||
if (!meta.hasLore()) {
|
||||
final LinkedList<String> lines;
|
||||
String desc = getDescription();
|
||||
if (plugin.getDependencies().getPlaceholderApi() != null) {
|
||||
desc = PlaceholderAPI.setPlaceholders(player, desc);
|
||||
}
|
||||
if (desc.equals(ChatColor.stripColor(desc))) {
|
||||
lines = MiscUtil.makeLines(desc, " ", 40, ChatColor.DARK_GREEN);
|
||||
} else {
|
||||
lines = MiscUtil.makeLines(desc, " ", 40, null);
|
||||
}
|
||||
meta.setLore(lines);
|
||||
}
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
display.setItemMeta(meta);
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a quester has met all Requirements to accept this quest<p>
|
||||
|
@ -4561,37 +4561,13 @@ public class Quester implements IQuester {
|
||||
Lang.get(player, "quests") + " | " + name);
|
||||
int i = 0;
|
||||
for (final IQuest quest : quests) {
|
||||
if (quest.getGUIDisplay() != null) {
|
||||
final Quest bukkitQuest = (Quest)quest;
|
||||
if (bukkitQuest.getGUIDisplay() != null) {
|
||||
if (i > 53) {
|
||||
// Protocol-enforced size limit has been exceeded
|
||||
break;
|
||||
}
|
||||
final ItemStack display = quest.getGUIDisplay().clone();
|
||||
final ItemMeta meta = display.getItemMeta();
|
||||
if (meta != null) {
|
||||
if (completedQuests.contains(quest)) {
|
||||
meta.setDisplayName(ChatColor.DARK_PURPLE + ConfigUtil.parseString(quest.getName()
|
||||
+ " " + ChatColor.GREEN + Lang.get(player, "redoCompleted"), npc));
|
||||
} else {
|
||||
meta.setDisplayName(ChatColor.DARK_PURPLE + ConfigUtil.parseString(quest.getName(), npc));
|
||||
}
|
||||
if (!meta.hasLore()) {
|
||||
final LinkedList<String> lines;
|
||||
String desc = quest.getDescription();
|
||||
if (plugin.getDependencies().getPlaceholderApi() != null) {
|
||||
desc = PlaceholderAPI.setPlaceholders(player, desc);
|
||||
}
|
||||
if (desc.equals(ChatColor.stripColor(desc))) {
|
||||
lines = MiscUtil.makeLines(desc, " ", 40, ChatColor.DARK_GREEN);
|
||||
} else {
|
||||
lines = MiscUtil.makeLines(desc, " ", 40, null);
|
||||
}
|
||||
meta.setLore(lines);
|
||||
}
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
display.setItemMeta(meta);
|
||||
}
|
||||
inv.setItem(i, display);
|
||||
inv.setItem(i, bukkitQuest.prepareDisplay(this));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
package me.blackvein.quests.listeners;
|
||||
|
||||
import me.blackvein.quests.Quest;
|
||||
import me.blackvein.quests.Quester;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.enums.ObjectiveType;
|
||||
@ -120,14 +121,15 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final IQuester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId());
|
||||
final Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId());
|
||||
final Player player = (Player) evt.getWhoClicked();
|
||||
if (evt.getView().getTitle().contains(Lang.get(player, "quests"))) {
|
||||
final ItemStack clicked = evt.getCurrentItem();
|
||||
if (ItemUtil.isItem(clicked)) {
|
||||
for (final IQuest quest : plugin.getLoadedQuests()) {
|
||||
final Quest bukkitQuest = (Quest)quest;
|
||||
if (quest.getGUIDisplay() != null) {
|
||||
if (ItemUtil.compareItems(clicked, quest.getGUIDisplay(), false) == 0) {
|
||||
if (ItemUtil.compareItems(clicked, bukkitQuest.prepareDisplay(quester), false) == 0) {
|
||||
if (quester.canAcceptOffer(quest, true)) {
|
||||
try {
|
||||
quester.takeQuest(quest, false);
|
||||
|
Loading…
Reference in New Issue
Block a user