From 5a2d24c37e56b6af07bf38eb543002337be57eb8 Mon Sep 17 00:00:00 2001 From: nickreesdev Date: Fri, 19 Feb 2021 20:17:33 -0600 Subject: [PATCH] Added a notification for when a player joins letting them know if they have unclaimed rewards. --- .../core/deliveryMan/DeliveryManManager.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/src/main/java/zone/themcgamer/core/deliveryMan/DeliveryManManager.java b/core/src/main/java/zone/themcgamer/core/deliveryMan/DeliveryManManager.java index 7ba5320..1bda050 100644 --- a/core/src/main/java/zone/themcgamer/core/deliveryMan/DeliveryManManager.java +++ b/core/src/main/java/zone/themcgamer/core/deliveryMan/DeliveryManManager.java @@ -1,6 +1,9 @@ package zone.themcgamer.core.deliveryMan; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.java.JavaPlugin; import zone.themcgamer.core.account.Account; import zone.themcgamer.core.account.AccountManager; @@ -53,6 +56,23 @@ public class DeliveryManManager extends MiniAccount { } } + @EventHandler(priority = EventPriority.HIGHEST) + private void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + Optional optionalAccount = AccountManager.fromCache(player.getUniqueId()); + if (optionalAccount.isEmpty()) + return; + Optional optionalClient = lookup(player.getUniqueId()); + if (optionalClient.isEmpty()) + return; + for (DeliveryManReward reward : DeliveryManReward.values()) { + if ((canClaim(player, reward) && optionalAccount.get().hasRank(reward.getRequiredRank()))) { + player.sendMessage(Style.main(DELIVERY_MAN_NAME, "You have unclaimed rewards! Visit §b" + DELIVERY_MAN_NAME + " §7to claim them!")); + return; + } + } + } + /** * Claims a {@link Player}'s {@link DeliveryManReward} *