mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
player profile load event from issue request #4045
This commit is contained in:
parent
e27d299132
commit
c6c1c39a98
@ -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;
|
||||
}
|
||||
}
|
@ -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.
|
||||
* <p>
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user