diff options
8 files changed, 277 insertions, 11 deletions
@@ -10,7 +10,7 @@ <name>Quests</name> <properties> - <release.version>${version}-beta</release.version> + <release.version>${version}</release.version> </properties> <repositories> @@ -36,6 +36,12 @@ <updatePolicy>always</updatePolicy> </snapshots> </repository> + + <!-- Citizens --> + <repository> + <id>everything</id> + <url>http://repo.citizensnpcs.co/</url> + </repository> </repositories> <dependencies> @@ -61,6 +67,15 @@ <artifactId>uSkyBlock-API</artifactId> <version>2.6.4</version> </dependency> + + <!-- Citizens --> + <dependency> + <groupId>net.citizensnpcs</groupId> + <artifactId>citizens</artifactId> + <version>2.0.24-SNAPSHOT</version> + <type>jar</type> + <scope>provided</scope> + </dependency> </dependencies> <build> 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<ConfigValue> 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<ConfigValue> 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<ConfigValue> 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<ConfigValue> 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); + } + } + } + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 79bcadfd..84aff28f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -812,6 +812,71 @@ quests: enabled: true time: 1440 + citizensdeliver: + tasks: + deliver: + type: "citizens_deliver" + item: IRON_BLOCK + amount: 1 + npc-name: "Gerald" + remove-items-when-complete: true + display: + name: "&cDeliverer (Citizens)" + lore-normal: + - "&7This quest requires you to:" + - "&7 - Deliver 1 iron block to a NPC named Gerald" + - "" + - "&7Rewards:" + - "&7 - $30 added to your in-game balance." + - "" + - "&cRequires plugin Citizens!" + lore-started: + - "" + - "&7Your current progression:" + - "&7 - Iron block delivered: {deliver:complete}." + type: "MILK_BUCKET" + rewards: + - "eco give {player} 30" + options: + category: "dependent" + requires: + - "" + repeatable: false + cooldown: + enabled: true + time: 1440 + + citizensinteract: + tasks: + talker: + type: "citizens_interact" + npc-name: "Krystina" + display: + name: "&cTalker (Citizens)" + lore-normal: + - "&7This quest requires you to:" + - "&7 - Deliver 1 iron block to a NPC named Krystina" + - "" + - "&7Rewards:" + - "&7 - $30 added to your in-game balance." + - "" + - "&cRequires plugin Citizens!" + lore-started: + - "" + - "&7Your current progression:" + - "&7 - Citizen talked to: {deliver:complete}." + type: "PAPER" + rewards: + - "eco give {player} 30" + options: + category: "dependent" + requires: + - "" + repeatable: false + cooldown: + enabled: true + time: 1440 + # Categories are a way of grouping up quests. # When a player uses /quests, a menu of categories will be presented to them. # When a player clicks ona category, a list of quests under that category will show. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 691112a8..460c5122 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ version: %PLUGIN_VERSION% main: com.leonardobishop.quests.Quests author: lmbishop -softdepend: [ASkyBlock, uSkyBlock] +softdepend: [ASkyBlock, uSkyBlock, Citizens] prefix: Quests commands: |
