diff --git a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java index c38a9571..f301dfab 100644 --- a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java +++ b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java @@ -11,9 +11,11 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.enchantment.EnchantItemEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityTameEvent; import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.event.player.PlayerItemConsumeEvent; import java.util.List; import java.util.stream.Collectors; @@ -117,6 +119,37 @@ public class MissionHandler implements Listener { } } + @EventHandler + public void onPlayerEnchant(EnchantItemEvent e) { + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(e.getEnchanter()); + if (fPlayer == null) { + return; + } + List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("enchant")).collect(Collectors.toList()); + for (Mission mission2 : missions) { + ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); + mission2.incrementProgress(); + checkIfDone(fPlayer, mission2, section); + } + } + + @EventHandler + public void onPlayerConsume(PlayerItemConsumeEvent e) { + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(e.getPlayer()); + if (fPlayer == null) { + return; + } + List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("consume")).collect(Collectors.toList()); + for (Mission mission2 : missions) { + ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); + if (!e.getItem().toString().contains(section.getConfigurationSection("Mission").getString("Item")) && !section.getConfigurationSection("Mission").getString("Item").equalsIgnoreCase("ALL")) { + continue; + } + mission2.incrementProgress(); + checkIfDone(fPlayer, mission2, section); + } + } + private void checkIfDone(FPlayer fPlayer, Mission mission, ConfigurationSection section) { if (mission.getProgress() < section.getConfigurationSection("Mission").getLong("Amount")) { return; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 41c8a6bf..fe9ab408 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -741,7 +741,7 @@ Missions-GUI-Title: '&bFaction Missions' MaximumMissionsAllowedAtOnce: 1 Mission-Progress-Format: '&b&lProgression: &f{progress}&7/&e{total}' -#Mission Types: KILL, MINE, PLACE, FISH, TAME +#Mission Types: KILL, MINE, PLACE, FISH, TAME, ENCHANT, CONSUME Missions: sugarcane: Slot: 11 @@ -779,7 +779,7 @@ Missions: Reward: Commands: ["f points add %faction% 100"] animaltaming: - Slot: 21 + Slot: 20 Material: "BONE" Name: "&f100 &cTamed Animals" Lore: @@ -790,6 +790,30 @@ Missions: Amount: 100 Reward: Commands: ["f points add %faction% 100"] + enchant: + Slot: 22 + Material: "BOOK" + Name: "&f100 &dEnchants" + Lore: + - "&b&lEnchant &n100&r &d&litems" + Mission: + Type: "ENCHANT" + Amount: 100 + Reward: + Commands: ["f points add %faction% 100"] + consume: + Slot: 24 + Material: "COOKED_BEEF" + Name: "&f100 &dSteak" + Lore: + - "&b&lConsume &n100&r &d&lsteak" + Mission: + Type: "CONSUME" + # "ALL" can also be used for item + Item: "COOKED_BEEF" + Amount: 100 + Reward: + Commands: ["f points add %faction% 100"] ############################################################ # +------------------------------------------------------+ #