diff options
Diffstat (limited to 'src/me/fatpigsarefat/quests/player')
5 files changed, 0 insertions, 602 deletions
diff --git a/src/me/fatpigsarefat/quests/player/QPlayer.java b/src/me/fatpigsarefat/quests/player/QPlayer.java deleted file mode 100644 index e797d7bb..00000000 --- a/src/me/fatpigsarefat/quests/player/QPlayer.java +++ /dev/null @@ -1,123 +0,0 @@ -package me.fatpigsarefat.quests.player; - -import me.fatpigsarefat.quests.Quests; -import me.fatpigsarefat.quests.events.EventInventory; -import me.fatpigsarefat.quests.obj.Options; -import me.fatpigsarefat.quests.obj.misc.QMenu; -import me.fatpigsarefat.quests.obj.misc.QMenuCategory; -import me.fatpigsarefat.quests.obj.misc.QMenuQuest; -import me.fatpigsarefat.quests.player.questprogressfile.QuestProgressFile; -import me.fatpigsarefat.quests.quests.Category; -import me.fatpigsarefat.quests.quests.Quest; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public class QPlayer { - - private UUID uuid; - private QuestProgressFile questProgressFile; - private boolean onlyDataLoaded; - - public QPlayer(UUID uuid, QuestProgressFile questProgressFile) { - this(uuid, questProgressFile, false); - } - - public QPlayer(UUID uuid, QuestProgressFile questProgressFile, boolean onlyDataLoaded) { - this.uuid = uuid; - this.questProgressFile = questProgressFile; - this.onlyDataLoaded = onlyDataLoaded; - } - - public UUID getUuid() { - return uuid; - } - - public void openCategory(Category category) { - if (onlyDataLoaded) { - return; - } - - Player player = Bukkit.getPlayer(uuid); - if (player == null) { - return; - } - - QMenuQuest qMenuQuest = new QMenuQuest(Quests.getPlayerManager().getPlayer(player.getUniqueId()), category.getId(), null); - List<Quest> quests = new ArrayList<>(); - for (String questid : category.getRegisteredQuestIds()) { - Quest quest = Quests.getQuestManager().getQuestById(questid); - if (quest != null) { - quests.add(quest); - } - } - qMenuQuest.populate(quests); - qMenuQuest.setBackButtonEnabled(false); - - player.openInventory(qMenuQuest.toInventory(1)); - EventInventory.track(player.getUniqueId(), qMenuQuest); - } - - public void openQuests() { - if (onlyDataLoaded) { - return; - } - - Player player = Bukkit.getPlayer(uuid); - if (player == null) { - return; - } - - if (Options.CATEGORIES_ENABLED.getBooleanValue()) { - QMenuCategory qMenuCategory = new QMenuCategory(Quests.getPlayerManager().getPlayer(player.getUniqueId())); - List<QMenuQuest> questMenus = new ArrayList<>(); - for (Category category : Quests.getQuestManager().getCategories()) { - QMenuQuest qMenuQuest = new QMenuQuest(Quests.getPlayerManager().getPlayer(player.getUniqueId()), category.getId(), qMenuCategory); - List<Quest> quests = new ArrayList<>(); - for (String questid : category.getRegisteredQuestIds()) { - Quest quest = Quests.getQuestManager().getQuestById(questid); - if (quest != null) { - quests.add(quest); - } - } - qMenuQuest.populate(quests); - questMenus.add(qMenuQuest); - } - qMenuCategory.populate(questMenus); - - player.openInventory(qMenuCategory.toInventory(1)); - EventInventory.track(player.getUniqueId(), qMenuCategory); - } else { - QMenuQuest qMenuQuest = new QMenuQuest(Quests.getPlayerManager().getPlayer(player.getUniqueId()), "", null); - List<Quest> quests = new ArrayList<>(); - for (Map.Entry<String, Quest> entry : Quests.getQuestManager().getQuests().entrySet()) { - quests.add(entry.getValue()); - } - qMenuQuest.populate(quests); - qMenuQuest.setBackButtonEnabled(false); - - player.openInventory(qMenuQuest.toInventory(1)); - EventInventory.track(player.getUniqueId(), qMenuQuest); - } - } - - public boolean isOnlyDataLoaded() { - return onlyDataLoaded; - } - - public void setOnlyDataLoaded(boolean onlyDataLoaded) { - this.onlyDataLoaded = onlyDataLoaded; - } - - public QuestProgressFile getQuestProgressFile() { - return questProgressFile; - } - - public QuestProgressFile setQuestProgressFile() { - return questProgressFile; - } -} diff --git a/src/me/fatpigsarefat/quests/player/QPlayerManager.java b/src/me/fatpigsarefat/quests/player/QPlayerManager.java deleted file mode 100644 index 29c6f01a..00000000 --- a/src/me/fatpigsarefat/quests/player/QPlayerManager.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.fatpigsarefat.quests.player; - -import me.fatpigsarefat.quests.Quests; -import me.fatpigsarefat.quests.player.questprogressfile.QuestProgress; -import me.fatpigsarefat.quests.player.questprogressfile.QuestProgressFile; -import me.fatpigsarefat.quests.player.questprogressfile.TaskProgress; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.util.*; - -public class QPlayerManager { - - private Map<UUID, QPlayer> qPlayers = new HashMap<>(); - - public void addPlayer(QPlayer qPlayer) { - qPlayers.put(qPlayer.getUuid(), qPlayer); - } - - public QPlayer getPlayer(UUID uuid) { - return qPlayers.getOrDefault(uuid, null); - } - - public void removePlayer(UUID uuid) { - qPlayers.remove(uuid); - } - - public Collection<QPlayer> getQPlayers() { - return qPlayers.values(); - } - - public void loadPlayer(UUID uuid) { - loadPlayer(uuid, false); - } - - public void loadPlayer(UUID uuid, boolean onlyData) { - if (getPlayer(uuid) == null || getPlayer(uuid).isOnlyDataLoaded()) { - QuestProgressFile questProgressFile = new QuestProgressFile(uuid); - - try { - File directory = new File(Quests.getInstance().getDataFolder() + File.separator + "playerdata"); - if (directory.exists() && directory.isDirectory()) { - File file = new File(Quests.getInstance().getDataFolder() + File.separator + "playerdata" + File.separator + uuid.toString() + ".yml"); - if (file.exists()) { - YamlConfiguration data = YamlConfiguration.loadConfiguration(file); - if (data.contains("quest-progress")) { - for (String id : data.getConfigurationSection("quest-progress").getKeys(false)) { - boolean started = data.getBoolean("quest-progress." + id + ".started"); - boolean completed = data.getBoolean("quest-progress." + id + ".completed"); - boolean completedBefore = data.getBoolean("quest-progress." + id + ".completed-before"); - long completionDate = data.getLong("quest-progress." + id + ".completion-date"); - - QuestProgress questProgress = new QuestProgress(id, completed, completedBefore, completionDate, uuid, started, true); - - for (String taskid : data.getConfigurationSection("quest-progress." + id + ".task-progress").getKeys(false)) { - boolean taskCompleted = data.getBoolean("quest-progress." + id + ".task-progress." + taskid + ".completed"); - Object taskProgression = data.get("quest-progress." + id + ".task-progress." + taskid + ".progress"); - - TaskProgress taskProgress = new TaskProgress(taskid, taskProgression, uuid, taskCompleted); - questProgress.addTaskProgress(taskProgress); - } - - questProgressFile.addQuestProgress(questProgress); - } - } - } - } - } catch (Exception ignored) { - // fuck - } - - QPlayer qPlayer = new QPlayer(uuid, questProgressFile, onlyData); - - addPlayer(qPlayer); - } - } - -} diff --git a/src/me/fatpigsarefat/quests/player/questprogressfile/QuestProgress.java b/src/me/fatpigsarefat/quests/player/questprogressfile/QuestProgress.java deleted file mode 100644 index 97e0b517..00000000 --- a/src/me/fatpigsarefat/quests/player/questprogressfile/QuestProgress.java +++ /dev/null @@ -1,106 +0,0 @@ -package me.fatpigsarefat.quests.player.questprogressfile; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class QuestProgress { - - private Map<String, TaskProgress> taskProgress = new HashMap<>(); - private String questid; - private boolean started; - private boolean completed; - private boolean completedBefore; - private long completionDate; - private UUID player; - private boolean modified; - - public QuestProgress(String questid, boolean completed, boolean completedBefore, long completionDate, UUID player, boolean started) { - this.questid = questid; - this.completed = completed; - this.completedBefore = completedBefore; - this.completionDate = completionDate; - this.player = player; - this.started = started; - } - - public QuestProgress(String questid, boolean completed, boolean completedBefore, long completionDate, UUID player, boolean started, boolean modified) { - this(questid, completed, completedBefore, completionDate, player, started); - this.modified = modified; - } - - public String getQuestId() { - return questid; - } - - public boolean isCompleted() { - return completed; - } - - public void setCompleted(boolean completed) { - this.completed = completed; - this.modified = true; - } - - public boolean isStarted() { - return started; - } - - public void setStarted(boolean started) { - this.started = started; - this.modified = true; - } - - public long getCompletionDate() { - return completionDate; - } - - public void setCompletionDate(long completionDate) { - this.completionDate = completionDate; - this.modified = true; - } - - public UUID getPlayer() { - return player; - } - - public boolean isCompletedBefore() { - return completedBefore; - } - - public void setCompletedBefore(boolean completedBefore) { - this.completedBefore = completedBefore; - this.modified = true; - } - - public void addTaskProgress(TaskProgress taskProgress) { - this.taskProgress.put(taskProgress.getTaskId(), taskProgress); - } - - public Collection<TaskProgress> getTaskProgress() { - return taskProgress.values(); - } - - public TaskProgress getTaskProgress(String taskId) { - TaskProgress tP = taskProgress.getOrDefault(taskId, null); - if (tP == null) { - repairTaskProgress(taskId); - tP = taskProgress.getOrDefault(taskId, null); - } - return tP; - } - - public void repairTaskProgress(String taskid) { - TaskProgress taskProgress = new TaskProgress(taskid, null, player, false); - this.addTaskProgress(taskProgress); - } - - public boolean isWorthSaving() { - return modified; - } - - public void setWorthSaving(boolean modified) { - this.modified = modified; - } -} diff --git a/src/me/fatpigsarefat/quests/player/questprogressfile/QuestProgressFile.java b/src/me/fatpigsarefat/quests/player/questprogressfile/QuestProgressFile.java deleted file mode 100644 index 144093e6..00000000 --- a/src/me/fatpigsarefat/quests/player/questprogressfile/QuestProgressFile.java +++ /dev/null @@ -1,254 +0,0 @@ -package me.fatpigsarefat.quests.player.questprogressfile; - -import me.fatpigsarefat.quests.Quests; -import me.fatpigsarefat.quests.obj.Messages; -import me.fatpigsarefat.quests.obj.Options; -import me.fatpigsarefat.quests.quests.Quest; -import me.fatpigsarefat.quests.quests.Task; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.TimeUnit; - -public class QuestProgressFile { - - private Map<String, QuestProgress> questProgress = new HashMap<>(); - private UUID player; - - public QuestProgressFile(UUID player) { - this.player = player; - } - - //TODO change back to quest id to save performance - - public boolean completeQuest(Quest quest) { - QuestProgress questProgress = getQuestProgress(quest); - questProgress.setStarted(false); - questProgress.setCompleted(true); - questProgress.setCompletedBefore(true); - questProgress.setCompletionDate(System.currentTimeMillis()); - if (Bukkit.getPlayer(player) != null) { - Player player = Bukkit.getPlayer(this.player); - Bukkit.getServer().getScheduler().runTask(Quests.getInstance(), () -> { - for (String s : quest.getRewards()) { - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), s.replace("{player}", player.getName())); - } - }); - player.sendMessage(Messages.QUEST_COMPLETE.getMessage().replace("{quest}", quest.getDisplayNameStripped())); - if (Options.TITLES_ENABLED.getBooleanValue()) { - Quests.getTitle().sendTitle(player, Messages.TITLE_QUEST_COMPLETE_TITLE.getMessage().replace("{quest}", quest - .getDisplayNameStripped()), Messages.TITLE_QUEST_COMPLETE_SUBTITLE.getMessage().replace("{quest}", quest - .getDisplayNameStripped())); - } - for (String s : quest.getRewardString()) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', s)); - } - } - return true; - } - - /** - * Start a quest for the player. - * - * @param quest the quest to check - * @return 0 if successful, 1 if limit reached, 2 if quest is already completed, 3 if quest has cooldown, 4 if still locked - */ - public int startQuest(Quest quest) { - if (getStartedQuests().size() >= Options.QUESTS_START_LIMIT.getIntValue()) { - if (Bukkit.getPlayer(player) != null) { - Player player = Bukkit.getPlayer(getPlayer()); - player.sendMessage(Messages.QUEST_START_LIMIT.getMessage().replace("{limit}", String.valueOf(Options.QUESTS_START_LIMIT.getIntValue()))); - } - return 1; - } - QuestProgress questProgress = getQuestProgress(quest); - if (!quest.isRepeatable() && questProgress.isCompletedBefore()) { - if (Bukkit.getPlayer(player) != null) { - Player player = Bukkit.getPlayer(getPlayer()); - player.sendMessage(Messages.QUEST_START_DISABLED.getMessage()); - } - return 2; - } - long cooldown = getCooldownFor(quest); - if (cooldown > 0) { - if (Bukkit.getPlayer(player) != null) { - Player player = Bukkit.getPlayer(getPlayer()); - player.sendMessage(Messages.QUEST_START_COOLDOWN.getMessage().replace("{time}", String.valueOf(Quests.convertToFormat(TimeUnit.MINUTES.convert(cooldown, TimeUnit.MILLISECONDS))))); - } - return 3; - } - if (!hasMetRequirements(quest)) { - if (Bukkit.getPlayer(player) != null) { - Player player = Bukkit.getPlayer(getPlayer()); - player.sendMessage(Messages.QUEST_START_LOCKED.getMessage()); - } - return 4; - } - questProgress.setStarted(true); - for (TaskProgress taskProgress : questProgress.getTaskProgress()) { - taskProgress.setCompleted(false); - taskProgress.setProgress(null); - } - questProgress.setCompleted(false); - if (Bukkit.getPlayer(player) != null) { - Player player = Bukkit.getPlayer(getPlayer()); - player.sendMessage(Messages.QUEST_START.getMessage().replace("{quest}", quest.getDisplayNameStripped())); - if (Options.TITLES_ENABLED.getBooleanValue()) { - Quests.getTitle().sendTitle(player, Messages.TITLE_QUEST_START_TITLE.getMessage().replace("{quest}", quest - .getDisplayNameStripped()), Messages.TITLE_QUEST_START_SUBTITLE.getMessage().replace("{quest}", quest - .getDisplayNameStripped())); - } - } - return 0; - } - - public boolean cancelQuest(Quest quest) { - QuestProgress questProgress = getQuestProgress(quest); - if (!questProgress.isStarted()) { - if (Bukkit.getPlayer(player) != null) { - Bukkit.getPlayer(getPlayer()).sendMessage(Messages.QUEST_CANCEL_NOTSTARTED.getMessage()); - } - return false; - } - questProgress.setStarted(false); - for (TaskProgress taskProgress : questProgress.getTaskProgress()) { - taskProgress.setProgress(null); - } - if (Bukkit.getPlayer(player) != null) { - Bukkit.getPlayer(getPlayer()).sendMessage(Messages.QUEST_CANCEL.getMessage().replace("{quest}", quest.getDisplayNameStripped())); - } - return true; - } - - public void addQuestProgress(QuestProgress questProgress) { - this.questProgress.put(questProgress.getQuestId(), questProgress); - } - - public List<Quest> getStartedQuests() { - List<Quest> startedQuests = new ArrayList<>(); - for (QuestProgress questProgress : questProgress.values()) { - if (questProgress.isStarted()) { - startedQuests.add(Quests.getQuestManager().getQuestById(questProgress.getQuestId())); - } - } - return startedQuests; - } - - public boolean hasQuestProgress(Quest quest) { - return questProgress.containsKey(quest.getId()); - } - - public boolean hasStartedQuest(Quest quest) { - //TODO always return true if the need for starting quests is disabled & requirements are met - if (hasQuestProgress(quest)) { - if (getQuestProgress(quest).isStarted()) { - return true; - } - } - return false; - } - - public long getCooldownFor(Quest quest) { - QuestProgress questProgress = getQuestProgress(quest); - if (quest.isCooldownEnabled() && questProgress.isCompleted()) { - if (questProgress.getCompletionDate() > 0) { - long date = questProgress.getCompletionDate(); - return (date + TimeUnit.MILLISECONDS.convert(quest.getCooldown(), TimeUnit.MINUTES)) - System.currentTimeMillis(); - } - } - return 0; - } - - public boolean hasMetRequirements(Quest quest) { - for (String id : quest.getRequirements()) { - Quest q = Quests.getQuestManager().getQuestById(id); - if (q == null) { - continue; - } - if (hasQuestProgress(q) && !getQuestProgress(q).isCompletedBefore()) { - return false; - } else if (!hasQuestProgress(q)) { - return false; - } - } - return true; - } - - public UUID getPlayer() { - return player; - } - - public QuestProgress getQuestProgress(Quest quest) { - if (questProgress.containsKey(quest.getId())) { - return questProgress.get(quest.getId()); - } else if (generateBlankQuestProgress(quest.getId())) { - return getQuestProgress(quest); - } - return null; - } - - public boolean generateBlankQuestProgress(String questid) { - if (Quests.getQuestManager().getQuestById(questid) != null) { - Quest quest = Quests.getQuestManager().getQuestById(questid); - QuestProgress questProgress = new QuestProgress(quest.getId(), false, false, 0, player, false, false); - for (Task task : quest.getTasks()) { - TaskProgress taskProgress = new TaskProgress(task.getId(), null, player, false); - questProgress.addTaskProgress(taskProgress); - } - - addQuestProgress(questProgress); - return true; - } - return false; - } - - public void saveToDisk() { - File directory = new File(Quests.getInstance().getDataFolder() + File.separator + "playerdata"); - if (!directory.exists() && !directory.isDirectory()) { - directory.mkdirs(); - } - File file = new File(Quests.getInstance().getDataFolder() + File.separator + "playerdata" + File.separator + player.toString() + ".yml"); - if (!file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - YamlConfiguration data = YamlConfiguration.loadConfiguration(file); - data.set("quest-progress", null); - for (QuestProgress questProgress : questProgress.values()) { - if (!questProgress.isWorthSaving()) { - continue; - } - data.set("quest-progress." + questProgress.getQuestId() + ".started", questProgress.isStarted()); - data.set("quest-progress." + questProgress.getQuestId() + ".completed", questProgress.isCompleted()); - data.set("quest-progress." + questProgress.getQuestId() + ".completed-before", questProgress.isCompletedBefore()); - data.set("quest-progress." + questProgress.getQuestId() + ".completion-date", questProgress.getCompletionDate()); - for (TaskProgress taskProgress : questProgress.getTaskProgress()) { - data.set("quest-progress." + questProgress.getQuestId() + ".task-progress." + taskProgress.getTaskId() + ".completed", taskProgress - .isCompleted()); - data.set("quest-progress." + questProgress.getQuestId() + ".task-progress." + taskProgress.getTaskId() + ".progress", taskProgress - .getProgress()); - } - } - - try { - data.save(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void clear() { - questProgress.clear(); - } - -} - diff --git a/src/me/fatpigsarefat/quests/player/questprogressfile/TaskProgress.java b/src/me/fatpigsarefat/quests/player/questprogressfile/TaskProgress.java deleted file mode 100644 index 3b896334..00000000 --- a/src/me/fatpigsarefat/quests/player/questprogressfile/TaskProgress.java +++ /dev/null @@ -1,41 +0,0 @@ -package me.fatpigsarefat.quests.player.questprogressfile; - -import java.util.UUID; - -public class TaskProgress { - - private String taskid; - private Object progress; - private UUID player; - private boolean completed; - - public TaskProgress(String taskid, Object progress, UUID player, boolean completed) { - this.taskid = taskid; - this.progress = progress; - this.completed = completed; - } - - public String getTaskId() { - return taskid; - } - - public Object getProgress() { - return progress; - } - - public void setProgress(Object progress) { - this.progress = progress; - } - - public UUID getPlayer() { - return player; - } - - public boolean isCompleted() { - return completed; - } - - public void setCompleted(boolean complete) { - this.completed = complete; - } -} |
