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..3fa9407b1 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/players/McMMOPlayerProfileLoadEvent.java @@ -0,0 +1,45 @@ +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 Event implements Cancellable { + private boolean cancelled; + private PlayerProfile profile; + private Player player; + public McMMOPlayerProfileLoadEvent(Player player, PlayerProfile profile){ + super(!Bukkit.isPrimaryThread()); + + this.cancelled = false; + this.profile = profile; + this.player = player; + } + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + 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; + } + + 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 bd1c3ddfa..ede4468b1 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; @@ -102,7 +103,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/PlayerProfileLoadingTask.java b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java index 50f960b95..a005e39c7 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,11 @@ 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); + 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..2793a446e 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 event = new McMMOPlayerProfileLoadEvent(player, profile); + mcMMO.p.getServer().getPluginManager().callEvent(event); + + return event; + } + /** * Calls a new SubSkillEvent for this SubSkill and then returns it * @param player target player