From c6c1c39a9860bb69057c4dcf087e24bc71f8182d Mon Sep 17 00:00:00 2001 From: Shrek5InTheatres2019 Date: Fri, 6 Sep 2019 16:44:58 -0700 Subject: [PATCH 1/4] 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 From 478d542981b0617b7d17aad79e5f3c103f089a46 Mon Sep 17 00:00:00 2001 From: Shrek5InTheatres2019 Date: Fri, 6 Sep 2019 16:46:38 -0700 Subject: [PATCH 2/4] removing this task that i once thought i needed and now realize that it is completely unnecessary --- .../ExecutePlayerProfileLoadEventTask.java | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/runnables/player/ExecutePlayerProfileLoadEventTask.java diff --git a/src/main/java/com/gmail/nossr50/runnables/player/ExecutePlayerProfileLoadEventTask.java b/src/main/java/com/gmail/nossr50/runnables/player/ExecutePlayerProfileLoadEventTask.java deleted file mode 100644 index 93bd9d8ba..000000000 --- a/src/main/java/com/gmail/nossr50/runnables/player/ExecutePlayerProfileLoadEventTask.java +++ /dev/null @@ -1,20 +0,0 @@ -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); - } -} From 67bfb40dd51b8ecaea5076575ac28380694c9779 Mon Sep 17 00:00:00 2001 From: Shrek5InTheatres2019 Date: Mon, 9 Sep 2019 16:50:05 -0700 Subject: [PATCH 3/4] fixing the things --- .../players/McMMOPlayerProfileLoadEvent.java | 14 +++++++++----- .../gmail/nossr50/listeners/PlayerListener.java | 1 - .../runnables/player/PlayerProfileLoadingTask.java | 4 +--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/events/players/McMMOPlayerProfileLoadEvent.java b/src/main/java/com/gmail/nossr50/events/players/McMMOPlayerProfileLoadEvent.java index 508a9886c..3fa9407b1 100644 --- a/src/main/java/com/gmail/nossr50/events/players/McMMOPlayerProfileLoadEvent.java +++ b/src/main/java/com/gmail/nossr50/events/players/McMMOPlayerProfileLoadEvent.java @@ -1,17 +1,19 @@ package com.gmail.nossr50.events.players; import com.gmail.nossr50.datatypes.player.PlayerProfile; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerEvent; -public class McMMOPlayerProfileLoadEvent extends PlayerEvent implements Cancellable { +public class McMMOPlayerProfileLoadEvent extends Event implements Cancellable { private boolean cancelled; private PlayerProfile profile; private Player player; public McMMOPlayerProfileLoadEvent(Player player, PlayerProfile profile){ - super(player); + super(!Bukkit.isPrimaryThread()); this.cancelled = false; this.profile = profile; @@ -19,12 +21,12 @@ public class McMMOPlayerProfileLoadEvent extends PlayerEvent implements Cancella } @Override public boolean isCancelled() { - return cancelled; + return this.cancelled; } @Override - public void setCancelled(boolean b) { - this.cancelled = b; + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; } public PlayerProfile getProfile(){return this.profile;} @@ -38,4 +40,6 @@ public class McMMOPlayerProfileLoadEvent extends PlayerEvent implements Cancella public static HandlerList getHandlerList() { return handlers; } + + public Player getPlayer() {return player;} } diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 8a33ba4f0..ede4468b1 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -68,7 +68,6 @@ 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 */ 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 77cd19373..a005e39c7 100644 --- a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java @@ -50,9 +50,7 @@ public class PlayerProfileLoadingTask extends BukkitRunnable { // 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); - }); + EventUtils.callPlayerProfileLoadEvent(player, profile); return; } From c3548be380295cc86e707741bfd88f4ee6b981bf Mon Sep 17 00:00:00 2001 From: Shrek5InTheatres2019 Date: Mon, 9 Sep 2019 17:56:06 -0700 Subject: [PATCH 4/4] deleting one character variables for good --- src/main/java/com/gmail/nossr50/util/EventUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index 7a483627e..2793a446e 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -152,10 +152,10 @@ public class EventUtils { } public static McMMOPlayerProfileLoadEvent callPlayerProfileLoadEvent(Player player, PlayerProfile profile){ - McMMOPlayerProfileLoadEvent e = new McMMOPlayerProfileLoadEvent(player, profile); - mcMMO.p.getServer().getPluginManager().callEvent(e); + McMMOPlayerProfileLoadEvent event = new McMMOPlayerProfileLoadEvent(player, profile); + mcMMO.p.getServer().getPluginManager().callEvent(event); - return e; + return event; } /**