From c6c1c39a9860bb69057c4dcf087e24bc71f8182d Mon Sep 17 00:00:00 2001 From: Shrek5InTheatres2019 Date: Fri, 6 Sep 2019 16:44:58 -0700 Subject: [PATCH] player profile load event from issue request #4045 --- .../players/McMMOPlayerProfileLoadEvent.java | 41 +++++++++++++++++++ .../nossr50/listeners/PlayerListener.java | 3 +- src/main/java/com/gmail/nossr50/mcMMO.java | 2 + .../ExecutePlayerProfileLoadEventTask.java | 20 +++++++++ .../player/PlayerProfileLoadingTask.java | 8 ++++ .../com/gmail/nossr50/util/EventUtils.java | 8 ++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/gmail/nossr50/events/players/McMMOPlayerProfileLoadEvent.java create mode 100644 src/main/java/com/gmail/nossr50/runnables/player/ExecutePlayerProfileLoadEventTask.java diff --git a/src/main/java/com/gmail/nossr50/events/players/McMMOPlayerProfileLoadEvent.java b/src/main/java/com/gmail/nossr50/events/players/McMMOPlayerProfileLoadEvent.java new file mode 100644 index 000000000..508a9886c --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/players/McMMOPlayerProfileLoadEvent.java @@ -0,0 +1,41 @@ +package com.gmail.nossr50.events.players; + +import com.gmail.nossr50.datatypes.player.PlayerProfile; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class McMMOPlayerProfileLoadEvent extends PlayerEvent implements Cancellable { + private boolean cancelled; + private PlayerProfile profile; + private Player player; + public McMMOPlayerProfileLoadEvent(Player player, PlayerProfile profile){ + super(player); + + this.cancelled = false; + this.profile = profile; + this.player = player; + } + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean b) { + this.cancelled = b; + } + + public PlayerProfile getProfile(){return this.profile;} + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index bd1c3ddfa..8a33ba4f0 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -13,6 +13,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; +import com.gmail.nossr50.events.players.McMMOPlayerProfileLoadEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.party.ShareHandler; @@ -67,6 +68,7 @@ public class PlayerListener implements Listener { * * @param event The event to monitor */ + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerTeleport(PlayerTeleportEvent event) { /* WORLD BLACKLIST CHECK */ @@ -102,7 +104,6 @@ public class PlayerListener implements Listener { UserManager.getPlayer(player).actualizeTeleportATS(); } - /** * Handle PlayerDeathEvents at the lowest priority. *

diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 79c0e689e..301df2ca9 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -14,6 +14,7 @@ import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManagerFactory; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.subskills.acrobatics.Roll; +import com.gmail.nossr50.events.players.McMMOPlayerProfileLoadEvent; import com.gmail.nossr50.listeners.*; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.runnables.CheckDateTask; @@ -50,6 +51,7 @@ import net.shatteredlands.shatt.backup.ZipLibrary; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.PluginManager; diff --git a/src/main/java/com/gmail/nossr50/runnables/player/ExecutePlayerProfileLoadEventTask.java b/src/main/java/com/gmail/nossr50/runnables/player/ExecutePlayerProfileLoadEventTask.java new file mode 100644 index 000000000..93bd9d8ba --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/player/ExecutePlayerProfileLoadEventTask.java @@ -0,0 +1,20 @@ +package com.gmail.nossr50.runnables.player; + +import com.gmail.nossr50.datatypes.player.PlayerProfile; +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.EventUtils; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +public class ExecutePlayerProfileLoadEventTask extends BukkitRunnable { + private Player player; + private PlayerProfile profile; + public ExecutePlayerProfileLoadEventTask(Player player, PlayerProfile profile){ + this.player = player; + this.profile = profile; + } + @Override + public void run() { + EventUtils.callPlayerProfileLoadEvent(this.player, this.profile); + } +} diff --git a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java index 50f960b95..77cd19373 100644 --- a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java @@ -3,14 +3,18 @@ package com.gmail.nossr50.runnables.player; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; +import com.gmail.nossr50.events.players.McMMOPlayerProfileLoadEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.runnables.commands.McScoreboardKeepTask; +import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager; +import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.entity.Player; +import org.bukkit.event.Event; import org.bukkit.scheduler.BukkitRunnable; public class PlayerProfileLoadingTask extends BukkitRunnable { @@ -42,9 +46,13 @@ public class PlayerProfileLoadingTask extends BukkitRunnable { } PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(player.getName(), player.getUniqueId(), true); + // If successful, schedule the apply if (profile.isLoaded()) { new ApplySuccessfulProfile(new McMMOPlayer(player, profile)).runTask(mcMMO.p); + Bukkit.getScheduler().runTask(mcMMO.p, () -> { + EventUtils.callPlayerProfileLoadEvent(player, profile); + }); return; } diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index 6c9317185..7a483627e 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -20,6 +20,7 @@ import com.gmail.nossr50.events.hardcore.McMMOPlayerVampirismEvent; import com.gmail.nossr50.events.party.McMMOPartyLevelUpEvent; import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent; import com.gmail.nossr50.events.party.McMMOPartyXpGainEvent; +import com.gmail.nossr50.events.players.McMMOPlayerProfileLoadEvent; import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent; import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent; import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent; @@ -150,6 +151,13 @@ public class EventUtils { return event; } + public static McMMOPlayerProfileLoadEvent callPlayerProfileLoadEvent(Player player, PlayerProfile profile){ + McMMOPlayerProfileLoadEvent e = new McMMOPlayerProfileLoadEvent(player, profile); + mcMMO.p.getServer().getPluginManager().callEvent(e); + + return e; + } + /** * Calls a new SubSkillEvent for this SubSkill and then returns it * @param player target player