Merge pull request #15 from DroppingAnvil/1.6.x

Added 2 new Faction Mission types!
This commit is contained in:
Driftay 2019-09-16 07:37:45 -04:00 committed by GitHub
commit 17378f7c3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 2 deletions

View File

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