From b4b03c60e8fa7621fa7450cda66d106d03680bdc Mon Sep 17 00:00:00 2001 From: Thatsmusic99 Date: Mon, 19 Nov 2018 17:06:36 +0000 Subject: [PATCH] Fixed mask issue --- .../config/headsx/HeadInventory.java | 2 +- .../headsplus/events/MaskEvent.java | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/main/java/io/github/thatsmusic99/headsplus/config/headsx/HeadInventory.java b/main/java/io/github/thatsmusic99/headsplus/config/headsx/HeadInventory.java index 6e3fa85..1175dc8 100644 --- a/main/java/io/github/thatsmusic99/headsplus/config/headsx/HeadInventory.java +++ b/main/java/io/github/thatsmusic99/headsplus/config/headsx/HeadInventory.java @@ -150,7 +150,7 @@ public Inventory build(PagedLists list, Player sender) { } if (getIconArray()[o].getLore().get(z).contains("{completed}")) { if (c.isComplete(sender)) { - lore.add(ChatColor.GOLD + "Complete!"); + lore.add(HeadsPlus.getInstance().getMessagesConfig().getString("challenge-completed")); } } if (getIconArray()[o].getLore().get(z).contains("{challenge-xp}")) { diff --git a/main/java/io/github/thatsmusic99/headsplus/events/MaskEvent.java b/main/java/io/github/thatsmusic99/headsplus/events/MaskEvent.java index 2db65f0..1285c2f 100644 --- a/main/java/io/github/thatsmusic99/headsplus/events/MaskEvent.java +++ b/main/java/io/github/thatsmusic99/headsplus/events/MaskEvent.java @@ -4,14 +4,22 @@ import io.github.thatsmusic99.headsplus.api.HPPlayer; import io.github.thatsmusic99.headsplus.config.HeadsPlusConfigHeads; import io.github.thatsmusic99.headsplus.nms.NMSManager; +import org.bukkit.Material; import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.HashMap; +import java.util.List; public class MaskEvent implements Listener { + private static HashMap maskMonitors = new HashMap<>(); + @EventHandler public void onMaskPutOn(InventoryClickEvent e) { HeadsPlus hp = HeadsPlus.getInstance(); @@ -26,11 +34,18 @@ public void onMaskPutOn(InventoryClickEvent e) { if (hpch.mHeads.contains(s) || hpch.uHeads.contains(s) || s.equalsIgnoreCase("player")) { HPPlayer pl = HPPlayer.getHPPlayer((OfflinePlayer) e.getWhoClicked()); pl.addMask(s); - } - } else { - if (e.getWhoClicked().getActivePotionEffects().size() > 0) { - HPPlayer pl = HPPlayer.getHPPlayer((OfflinePlayer) e.getWhoClicked()); - pl.clearMask(); + maskMonitors.put((Player) e.getWhoClicked(), new BukkitRunnable() { + @Override + public void run() { + if (e.getWhoClicked().getInventory().getItem(39) == null) { + HPPlayer pl = HPPlayer.getHPPlayer((OfflinePlayer) e.getWhoClicked()); + pl.clearMask(); + maskMonitors.remove(e.getWhoClicked()); + cancel(); + } + } + }); + maskMonitors.get(e.getWhoClicked()).runTaskTimer(HeadsPlus.getInstance(), 20, 40); } } }