Added 2 new Faction Mission types!

This commit is contained in:
DroppingAnvil 2019-09-15 23:01:34 -05:00
parent 1e7bd8ff35
commit b3eca15839
2 changed files with 61 additions and 2 deletions

View File

@ -1,19 +1,23 @@
package com.massivecraft.factions.missions;
import com.earth2me.essentials.Enchantments;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
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 +121,37 @@ public class MissionHandler implements Listener {
}
}
@EventHandler
public void onPlayerEnchant(EnchantItemEvent e) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(e.getEnchanter());
if (fPlayer == null) {
return;
}
List<Mission> 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<Mission> 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;

View File

@ -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"]
############################################################
# +------------------------------------------------------+ #