From 454445c356e745fac1779bb1b8a4b4b0ccafc5a6 Mon Sep 17 00:00:00 2001 From: fatpigsarefat Date: Sat, 20 Oct 2018 23:19:36 +0100 Subject: Added Citizens task type - "citizens_deliver" and "citizens_interact" added - Fixed a stupid bug with the startQuest response codes - Removed "beta" tag - Added Citizens to softdepend & pom.xml --- .../java/com/leonardobishop/quests/Quests.java | 15 +-- .../quests/player/QPlayerManager.java | 4 +- .../questprogressfile/QuestProgressFile.java | 2 +- .../tasktypes/types/CitizensDeliverTaskType.java | 114 +++++++++++++++++++++ .../tasktypes/types/CitizensInteractTaskType.java | 69 +++++++++++++ 5 files changed, 195 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensDeliverTaskType.java create mode 100644 src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensInteractTaskType.java (limited to 'src/main/java/com') diff --git a/src/main/java/com/leonardobishop/quests/Quests.java b/src/main/java/com/leonardobishop/quests/Quests.java index c5b46ff6..f1ef5085 100644 --- a/src/main/java/com/leonardobishop/quests/Quests.java +++ b/src/main/java/com/leonardobishop/quests/Quests.java @@ -1,6 +1,9 @@ package com.leonardobishop.quests; +import com.google.common.io.ByteStreams; +import com.leonardobishop.quests.blocktype.SimilarBlocks; import com.leonardobishop.quests.bstats.Metrics; +import com.leonardobishop.quests.commands.CommandQuests; import com.leonardobishop.quests.events.EventInventory; import com.leonardobishop.quests.events.EventPlayerJoin; import com.leonardobishop.quests.events.EventPlayerLeave; @@ -15,17 +18,11 @@ import com.leonardobishop.quests.quests.Quest; import com.leonardobishop.quests.quests.QuestManager; import com.leonardobishop.quests.quests.Task; import com.leonardobishop.quests.quests.tasktypes.TaskTypeManager; -import com.fatpigsarefat.quests.quests.tasktypes.types.*; +import com.leonardobishop.quests.quests.tasktypes.types.*; import com.leonardobishop.quests.title.Title; import com.leonardobishop.quests.title.Title_Bukkit; import com.leonardobishop.quests.title.Title_BukkitNoTimings; import com.leonardobishop.quests.title.Title_Other; -import com.google.common.io.ByteStreams; -import com.leonardobishop.quests.blocktype.SimilarBlocks; -import com.leonardobishop.quests.commands.CommandQuests; -import com.leonardobishop.quests.quests.tasktypes.types.*; -import me.fatpigsarefat.quests.quests.tasktypes.types.*; -import me.fatpigsarefat.quests.title.*; import com.leonardobishop.quests.updater.Updater; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -135,6 +132,10 @@ public class Quests extends JavaPlugin { if (Bukkit.getPluginManager().isPluginEnabled("uSkyBlock")) { taskTypeManager.registerTaskType(new uSkyBlockLevelType()); } + if (Bukkit.getPluginManager().isPluginEnabled("Citizens")) { + taskTypeManager.registerTaskType(new CitizensDeliverTaskType()); + taskTypeManager.registerTaskType(new CitizensInteractTaskType()); + } Bukkit.getPluginCommand("quests").setExecutor(new CommandQuests()); Bukkit.getPluginManager().registerEvents(new EventPlayerJoin(), this); diff --git a/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java b/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java index 295f3c5b..45d1eff6 100644 --- a/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java +++ b/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java @@ -65,7 +65,9 @@ public class QPlayerManager { } } } - } catch (Exception ignored) { + } catch (Exception ex) { + Quests.getInstance().getLogger().severe("Failed to load player: " + uuid + "! This WILL cause errors."); + ex.printStackTrace(); // fuck } diff --git a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java index bba02878..8554bb58 100644 --- a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java +++ b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java @@ -86,7 +86,7 @@ public class QuestProgressFile { } return 4; } - if (!questProgress.isStarted()) { + if (questProgress.isStarted()) { if (player != null) { p.sendMessage(Messages.QUEST_START_STARTED.getMessage()); } diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensDeliverTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensDeliverTaskType.java new file mode 100644 index 00000000..c2b2621f --- /dev/null +++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensDeliverTaskType.java @@ -0,0 +1,114 @@ +package com.leonardobishop.quests.quests.tasktypes.types; + +import com.leonardobishop.quests.Quests; +import com.leonardobishop.quests.player.QPlayer; +import com.leonardobishop.quests.player.questprogressfile.QuestProgress; +import com.leonardobishop.quests.player.questprogressfile.QuestProgressFile; +import com.leonardobishop.quests.player.questprogressfile.TaskProgress; +import com.leonardobishop.quests.quests.Quest; +import com.leonardobishop.quests.quests.Task; +import com.leonardobishop.quests.quests.tasktypes.ConfigValue; +import com.leonardobishop.quests.quests.tasktypes.TaskType; +import net.citizensnpcs.api.event.NPCLeftClickEvent; +import net.citizensnpcs.api.event.NPCRightClickEvent; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryInteractEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.ArrayList; +import java.util.List; + +public final class CitizensDeliverTaskType extends TaskType { + + private List creatorConfigValues = new ArrayList<>(); + + public CitizensDeliverTaskType() { + super("citizens_deliver", "lmbishop", "Deliver a set of items to a NPC."); + this.creatorConfigValues.add(new ConfigValue("amount", true, "Amount of item to retrieve.")); + this.creatorConfigValues.add(new ConfigValue("item", true, "Name or ID of item.")); + this.creatorConfigValues.add(new ConfigValue("npc-name", true, "Name of the NPC.")); + this.creatorConfigValues.add(new ConfigValue("remove-items-when-complete", false, "Take the items away from the player on completion (true/false, " + + "default = false).")); + } + + @Override + public List getCreatorConfigValues() { + return creatorConfigValues; + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onNPCClick(NPCRightClickEvent event) { + new BukkitRunnable() { + @Override + public void run() { + checkInventory(event.getClicker(), event.getNPC().getName()); + } + }.runTaskLater(Quests.getInstance(), 1L); + } + + private void checkInventory(Player player, String citizenName) { + QPlayer qPlayer = Quests.getPlayerManager().getPlayer(player.getUniqueId()); + if (qPlayer == null) { + return; + } + + QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile(); + + for (Quest quest : super.getRegisteredQuests()) { + if (questProgressFile.hasStartedQuest(quest)) { + QuestProgress questProgress = questProgressFile.getQuestProgress(quest); + + for (Task task : quest.getTasksOfType(super.getType())) { + if (!ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', String.valueOf(task.getConfigValue("npc-name")))).equals(ChatColor + .stripColor(ChatColor.translateAlternateColorCodes('&', citizenName)))) { + return; + } + TaskProgress taskProgress = questProgress.getTaskProgress(task.getId()); + + if (taskProgress.isCompleted()) { + continue; + } + + Material material; + int amount = (int) task.getConfigValue("amount"); + Object configBlock = task.getConfigValue("item"); + Object configData = task.getConfigValue("data"); + Object remove = task.getConfigValue("remove-items-when-complete"); + + if (StringUtils.isNumeric(String.valueOf(configBlock))) { + material = Material.getMaterial((int) configBlock); + } else { + material = Material.getMaterial(String.valueOf(configBlock)); + } + + if (material == null) { + continue; + } + ItemStack is; + if (configData != null) { + is = new ItemStack(material, 1, ((Integer) configData).shortValue()); + } else { + is = new ItemStack(material, 1); + } + + if (player.getInventory().containsAtLeast(is, amount)) { + is.setAmount(amount); + taskProgress.setCompleted(true); + + if (remove != null && ((Boolean) remove)) { + player.getInventory().removeItem(is); + } + } + } + } + } + } + +} diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensInteractTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensInteractTaskType.java new file mode 100644 index 00000000..aea19b72 --- /dev/null +++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/CitizensInteractTaskType.java @@ -0,0 +1,69 @@ +package com.leonardobishop.quests.quests.tasktypes.types; + +import com.leonardobishop.quests.Quests; +import com.leonardobishop.quests.player.QPlayer; +import com.leonardobishop.quests.player.questprogressfile.QuestProgress; +import com.leonardobishop.quests.player.questprogressfile.QuestProgressFile; +import com.leonardobishop.quests.player.questprogressfile.TaskProgress; +import com.leonardobishop.quests.quests.Quest; +import com.leonardobishop.quests.quests.Task; +import com.leonardobishop.quests.quests.tasktypes.ConfigValue; +import com.leonardobishop.quests.quests.tasktypes.TaskType; +import net.citizensnpcs.api.event.NPCRightClickEvent; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.ArrayList; +import java.util.List; + +public final class CitizensInteractTaskType extends TaskType { + + private List creatorConfigValues = new ArrayList<>(); + + public CitizensInteractTaskType() { + super("citizens_interact", "lmbishop", "Interact with an NPC to complete the quest."); + this.creatorConfigValues.add(new ConfigValue("npc-name", true, "Name of the NPC.")); + } + + @Override + public List getCreatorConfigValues() { + return creatorConfigValues; + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onNPCClick(NPCRightClickEvent event) { + QPlayer qPlayer = Quests.getPlayerManager().getPlayer(event.getClicker().getUniqueId()); + if (qPlayer == null) { + return; + } + + QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile(); + + for (Quest quest : super.getRegisteredQuests()) { + if (questProgressFile.hasStartedQuest(quest)) { + QuestProgress questProgress = questProgressFile.getQuestProgress(quest); + + for (Task task : quest.getTasksOfType(super.getType())) { + if (!ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', String.valueOf(task.getConfigValue("npc-name")))).equals(ChatColor + .stripColor(ChatColor.translateAlternateColorCodes('&', event.getNPC().getName())))) { + return; + } + TaskProgress taskProgress = questProgress.getTaskProgress(task.getId()); + + if (taskProgress.isCompleted()) { + continue; + } + + taskProgress.setCompleted(true); + } + } + } + } + +} -- cgit v1.2.3-70-g09d2