Search in sources :

Example 1 with OfflineMinigamePlayer

use of au.com.mineauz.minigames.objects.OfflineMinigamePlayer in project Minigames by AddstarMC.

the class Events method onPlayerConnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerConnect(PlayerJoinEvent event) {
    pdata.addMinigamePlayer(event.getPlayer());
    File pldata = new File(plugin.getDataFolder() + "/playerdata/inventories/" + event.getPlayer().getUniqueId().toString() + ".yml");
    final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (pldata.exists()) {
        ply.setOfflineMinigamePlayer(new OfflineMinigamePlayer(event.getPlayer().getUniqueId()));
        Location floc = ply.getOfflineMinigamePlayer().getLoginLocation();
        ply.setRequiredQuit(true);
        ply.setQuitPos(floc);
        if (!ply.getPlayer().isDead() && ply.isRequiredQuit()) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, ply::restorePlayerData);
            ply.teleport(ply.getQuitPos());
            ply.setRequiredQuit(false);
            ply.setQuitPos(null);
        }
        plugin.getLogger().info(ply.getName() + "'s data has been restored from file.");
    }
    ply.loadClaimedRewards();
    if (Bukkit.getServer().getOnlinePlayers().size() == 1) {
        for (Minigame mgm : mdata.getAllMinigames().values()) {
            if (mgm != null && mgm.getType() == MinigameType.GLOBAL) {
                if (mgm.getMinigameTimer() != null)
                    mgm.getMinigameTimer().startTimer();
            }
        }
    // for(String mgm : mdata.getAllMinigames().keySet()){
    // if(mdata.getMinigame(mgm).getType() == MinigameType.GLOBAL){
    // if(minigameManager.getMinigame(mgm).getThTimer() != null){
    // minigameManager.getMinigame(mgm).getThTimer().pauseTimer(false);
    // }
    // if(mdata.getMinigame(mgm).getMinigameTimer() != null)
    // mdata.getMinigame(mgm).getMinigameTimer().startTimer();
    // }
    // }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) File(java.io.File) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Minigame (au.com.mineauz.minigames.minigame.Minigame)1 MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)1 OfflineMinigamePlayer (au.com.mineauz.minigames.objects.OfflineMinigamePlayer)1 File (java.io.File)1 Location (org.bukkit.Location)1 EventHandler (org.bukkit.event.EventHandler)1