Search in sources :

Example 1 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class PlayerData method quitMinigame.

public void quitMinigame(MinigamePlayer player, boolean forced) {
    Minigame minigame = player.getMinigame();
    boolean isWinner = false;
    if (GameOverModule.getMinigameModule(minigame).getWinners().contains(player))
        isWinner = true;
    QuitMinigameEvent event = new QuitMinigameEvent(player, minigame, forced, isWinner);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        if (!minigame.isSpectator(player)) {
            if (player.getEndTime() == 0)
                player.setEndTime(System.currentTimeMillis());
            if (isWinner)
                GameOverModule.getMinigameModule(minigame).getWinners().remove(player);
            else
                GameOverModule.getMinigameModule(minigame).getLosers().remove(player);
            if (!isWinner) {
                if (!minigame.canSaveCheckpoint() && minigame.isEnabled()) {
                    StoredGameStats saveData = new StoredGameStats(minigame, player);
                    saveData.addStat(MinigameStats.Attempts, 1);
                    for (DynamicMinigameStat stat : MinigameStats.getDynamicStats()) {
                        if (stat.doesApply(minigame, player, false)) {
                            saveData.addStat(stat, stat.getValue(minigame, player, false));
                        }
                    }
                    saveData.applySettings(minigame.getStatSettings(saveData));
                    plugin.queueStatSave(saveData, false);
                }
            }
            //Call Types quit.
            mdata.minigameType(minigame.getType()).quitMinigame(player, minigame, forced);
            //Call Mechanic quit.
            minigame.getMechanic().quitMinigame(minigame, player, forced);
            //Prepare player for quit
            if (player.getPlayer().getVehicle() != null) {
                Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle();
                vehicle.eject();
            }
            player.getPlayer().closeInventory();
            if (player.getLoadout() != null) {
                player.getLoadout().removeLoadout(player);
            }
            player.removeMinigame();
            minigame.removePlayer(player);
            for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
                player.getPlayer().removePotionEffect(potion.getType());
            }
            player.getPlayer().setFallDistance(0);
            player.getPlayer().setNoDamageTicks(60);
            final MinigamePlayer fplayer = player;
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                @Override
                public void run() {
                    fplayer.getPlayer().setFireTicks(0);
                }
            });
            player.resetAllStats();
            if (!player.isDead()) {
                player.restorePlayerData();
                if (!isWinner)
                    player.teleport(minigame.getQuitPosition());
                else
                    player.teleport(minigame.getEndPosition());
            } else {
                if (!isWinner)
                    player.setQuitPos(minigame.getQuitPosition());
                else
                    player.setQuitPos(minigame.getEndPosition());
                player.setRequiredQuit(true);
            }
            //Reward Player
            if (isWinner) {
                player.claimTempRewardItems();
            }
            player.claimRewards();
            //Reset Minigame
            if (minigame.getPlayers().size() == 0) {
                if (minigame.getMinigameTimer() != null) {
                    minigame.getMinigameTimer().stopTimer();
                    minigame.setMinigameTimer(null);
                }
                if (minigame.getFloorDegenerator() != null) {
                    minigame.getFloorDegenerator().stopDegenerator();
                }
                minigame.setState(MinigameState.IDLE);
                if (minigame.getBlockRecorder().hasData()) {
                    minigame.getBlockRecorder().restoreBlocks();
                    minigame.getBlockRecorder().restoreEntities();
                    minigame.getBlockRecorder().setCreatedRegenBlocks(false);
                }
                if (minigame.getMpTimer() != null) {
                    minigame.getMpTimer().pauseTimer();
                    minigame.getMpTimer().removeTimer();
                    minigame.setMpTimer(null);
                }
                if (minigame.getMpBets() != null) {
                    minigame.setMpBets(null);
                }
                mdata.clearClaimedScore(minigame);
                WeatherTimeModule.getMinigameModule(minigame).stopTimeLoop();
                GameOverModule.getMinigameModule(minigame).stopEndGameTimer();
                for (Team team : TeamsModule.getMinigameModule(minigame).getTeams()) {
                    team.setScore(0);
                }
            }
            minigame.getScoreboardManager().resetScores(player.getName());
            for (MinigamePlayer pl : minigame.getSpectators()) {
                player.getPlayer().showPlayer(pl.getPlayer());
            }
            if (minigame.getPlayers().size() == 0 && !minigame.isRegenerating()) {
                HandlerList.unregisterAll(minigame.getBlockRecorder());
            }
            //Send out messages
            if (!forced) {
                mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.quit.plyMsg", player.getName(), minigame.getName(true)), "error", player);
            }
            plugin.getLogger().info(player.getName() + " quit " + minigame);
            player.updateInventory();
        } else {
            if (player.getPlayer().getVehicle() != null) {
                Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle();
                vehicle.eject();
            }
            player.getPlayer().setFallDistance(0);
            player.getPlayer().setNoDamageTicks(60);
            final Player fplayer = player.getPlayer();
            for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
                player.getPlayer().removePotionEffect(potion.getType());
            }
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                @Override
                public void run() {
                    fplayer.setFireTicks(0);
                }
            });
            player.getPlayer().closeInventory();
            if (!player.isDead()) {
                player.restorePlayerData();
            }
            player.teleport(minigame.getQuitPosition());
            player.removeMinigame();
            minigame.removeSpectator(player);
            for (MinigamePlayer pl : minigame.getPlayers()) {
                pl.getPlayer().showPlayer(player.getPlayer());
            }
            player.sendMessage(MinigameUtils.formStr("player.spectate.quit.plyMsg", minigame.getName(true)), "error");
            mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.spectate.quit.minigameMsg", player.getName(), minigame.getName(true)), "error", player);
        }
        if (player.getPlayer().getGameMode() != GameMode.CREATIVE)
            player.setCanFly(false);
        if (!forced) {
            minigame.getScoreboardData().reload();
        }
    }
}
Also used : Vehicle(org.bukkit.entity.Vehicle) QuitMinigameEvent(au.com.mineauz.minigames.events.QuitMinigameEvent) Player(org.bukkit.entity.Player) StoredGameStats(au.com.mineauz.minigames.stats.StoredGameStats) PotionEffect(org.bukkit.potion.PotionEffect) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame) DynamicMinigameStat(au.com.mineauz.minigames.stats.DynamicMinigameStat)

Example 2 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class MultiplayerType method joinMinigame.

@Override
public boolean joinMinigame(MinigamePlayer player, Minigame mgm) {
    if (!LobbySettingsModule.getMinigameModule(mgm).canInteractPlayerWait())
        player.setCanInteract(false);
    if (!LobbySettingsModule.getMinigameModule(mgm).canMovePlayerWait())
        player.setFrozen(true);
    if (!mgm.isWaitingForPlayers() && !mgm.hasStarted()) {
        if (mgm.getMpTimer() == null && mgm.getPlayers().size() == mgm.getMinPlayers()) {
            mgm.setMpTimer(new MultiplayerTimer(mgm));
            mgm.getMpTimer().startTimer();
            if (mgm.getPlayers().size() == mgm.getMaxPlayers()) {
                mgm.getMpTimer().setPlayerWaitTime(0);
                mdata.sendMinigameMessage(mgm, MinigameUtils.getLang("minigame.skipWaitTime"), "info", null);
            }
        } else if (mgm.getMpTimer() != null && mgm.getPlayers().size() == mgm.getMaxPlayers()) {
            mgm.getMpTimer().setPlayerWaitTime(0);
            mdata.sendMinigameMessage(mgm, MinigameUtils.getLang("minigame.skipWaitTime"), "info", null);
        } else if (mgm.getMpTimer() == null) {
            int neededPlayers = mgm.getMinPlayers() - mgm.getPlayers().size();
            mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("minigame.waitingForPlayers", neededPlayers), null, null);
        }
    } else if (mgm.hasStarted()) {
        player.setLatejoining(true);
        //TODO: Late join delay variable
        player.sendMessage(MinigameUtils.formStr("minigame.lateJoin", 5));
        final MinigamePlayer fply = player;
        final Minigame fmgm = mgm;
        if (mgm.isTeamGame()) {
            Team smTeam = null;
            for (Team team : TeamsModule.getMinigameModule(mgm).getTeams()) {
                if (smTeam == null || team.getPlayers().size() < smTeam.getPlayers().size()) {
                    smTeam = team;
                }
            }
            smTeam.addPlayer(player);
            player.sendMessage(String.format(smTeam.getAssignMessage(), smTeam.getChatColor() + smTeam.getDisplayName()), null);
            final Team fteam = smTeam;
            player.setLateJoinTimer(Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                @Override
                public void run() {
                    if (fply.isInMinigame()) {
                        List<Location> locs = new ArrayList<Location>();
                        if (TeamsModule.getMinigameModule(fmgm).hasTeamStartLocations()) {
                            locs.addAll(fteam.getStartLocations());
                        } else {
                            locs.addAll(fmgm.getStartLocations());
                        }
                        Collections.shuffle(locs);
                        fply.teleport(locs.get(0));
                        fply.getLoadout().equiptLoadout(fply);
                        fply.setLatejoining(false);
                        fply.setFrozen(false);
                        fply.setCanInteract(true);
                        fply.setLateJoinTimer(-1);
                    }
                }
            }, //TODO: Latejoin variable
            5 * 20));
        } else {
            player.setLateJoinTimer(Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                @Override
                public void run() {
                    if (fply.isInMinigame()) {
                        List<Location> locs = new ArrayList<Location>(fmgm.getStartLocations());
                        Collections.shuffle(locs);
                        fply.teleport(locs.get(0));
                        fply.getLoadout().equiptLoadout(fply);
                        fply.setLatejoining(false);
                        fply.setFrozen(false);
                        fply.setCanInteract(true);
                        fply.setLateJoinTimer(-1);
                    }
                }
            }, //TODO: Latejoin variable
            5 * 20));
        }
        player.getPlayer().setScoreboard(mgm.getScoreboardManager());
        mgm.setScore(player, 1);
        mgm.setScore(player, 0);
    }
    return true;
}
Also used : MultiplayerTimer(au.com.mineauz.minigames.MultiplayerTimer) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) Team(au.com.mineauz.minigames.minigame.Team) ArrayList(java.util.ArrayList) List(java.util.List) Minigame(au.com.mineauz.minigames.minigame.Minigame) Location(org.bukkit.Location)

Example 3 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class Minigames method hookPlaceHolderApi.

private void hookPlaceHolderApi() {
    if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
        hasPAPI = true;
        log.info("--------------------");
        log.info("Hooking PlaceHolder API");
        placeHolderManager = new PlaceHolderManager(this);
        placeHolderManager.register();
        log.info("Adding Placeholders for " + getMinigameManager().getAllMinigames().size() + " games");
        for (Map.Entry<String, Minigame> game : getMinigameManager().getAllMinigames().entrySet()) {
            log.fine("Adding Placeholders for " + game.getKey());
            placeHolderManager.addGameIdentifiers(game.getValue());
        }
        log.info("PlaceHolders: " + placeHolderManager.getRegisteredPlaceHolders().toString());
        log.info("--------------------");
    }
}
Also used : PlaceHolderManager(au.com.mineauz.minigames.managers.PlaceHolderManager) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 4 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class Minigames method onDisable.

public void onDisable() {
    if (getPlugin() == null) {
        log().info("Minigames is disabled");
        return;
    }
    final PluginDescriptionFile desc = this.getDescription();
    for (final Player p : this.getServer().getOnlinePlayers()) {
        if (this.playerManager.getMinigamePlayer(p).isInMinigame()) {
            this.playerManager.quitMinigame(this.playerManager.getMinigamePlayer(p), true);
        }
    }
    for (final Minigame minigame : this.minigameManager.getAllMinigames().values()) {
        if (minigame.getType() == MinigameType.GLOBAL && "treasure_hunt".equals(minigame.getMechanicName()) && minigame.isEnabled()) {
            if (minigame.getMinigameTimer() != null) {
                minigame.getMinigameTimer().stopTimer();
            }
            TreasureHuntMechanic.removeTreasure(minigame);
        }
    }
    for (final Minigame mg : this.minigameManager.getAllMinigames().values()) {
        mg.saveMinigame();
    }
    this.backend.shutdown();
    this.playerManager.saveDeniedCommands();
    final MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
    if (this.minigameManager.hasLoadouts()) {
        for (final String loadout : this.minigameManager.getLoadouts()) {
            for (final Integer slot : this.minigameManager.getLoadout(loadout).getItems()) {
                globalLoadouts.getConfig().set(loadout + '.' + slot, this.minigameManager.getLoadout(loadout).getItem(slot));
            }
            if (!this.minigameManager.getLoadout(loadout).getAllPotionEffects().isEmpty()) {
                for (final PotionEffect eff : this.minigameManager.getLoadout(loadout).getAllPotionEffects()) {
                    globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".amp", eff.getAmplifier());
                    globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".dur", eff.getDuration());
                }
            } else {
                globalLoadouts.getConfig().set(loadout + ".potions", null);
            }
            if (this.minigameManager.getLoadout(loadout).getUsePermissions()) {
                globalLoadouts.getConfig().set(loadout + ".usepermissions", true);
            } else {
                globalLoadouts.getConfig().set(loadout + ".usepermissions", null);
            }
        }
    } else {
        globalLoadouts.getConfig().set("globalloadouts", null);
    }
    globalLoadouts.saveConfig();
    this.minigameManager.saveRewardSigns();
    resourceManager.saveResources();
    log().info(desc.getName() + " successfully disabled.");
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) PotionEffect(org.bukkit.potion.PotionEffect) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) Minigame(au.com.mineauz.minigames.minigame.Minigame) MinigameSave(au.com.mineauz.minigames.config.MinigameSave)

Example 5 with Minigame

use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.

the class Events method itemPickup.

@EventHandler(ignoreCancelled = true)
public void itemPickup(EntityPickupItemEvent event) {
    if (event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        MinigamePlayer ply = pdata.getMinigamePlayer(player);
        if (ply.isInMinigame()) {
            Minigame mgm = ply.getMinigame();
            if (!mgm.hasItemPickup() || mgm.isSpectator(ply)) {
                event.setCancelled(true);
            }
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) OfflineMinigamePlayer(au.com.mineauz.minigames.objects.OfflineMinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Minigame (au.com.mineauz.minigames.minigame.Minigame)75 MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)42 EventHandler (org.bukkit.event.EventHandler)32 ArrayList (java.util.ArrayList)18 Team (au.com.mineauz.minigames.minigame.Team)16 Player (org.bukkit.entity.Player)14 Location (org.bukkit.Location)7 OfflineMinigamePlayer (au.com.mineauz.minigames.objects.OfflineMinigamePlayer)6 List (java.util.List)6 TreasureHuntModule (au.com.mineauz.minigames.minigame.modules.TreasureHuntModule)4 MinigameTool (au.com.mineauz.minigames.tool.MinigameTool)4 RegionModule (au.com.mineauz.minigamesregions.RegionModule)4 Sign (org.bukkit.block.Sign)4 ItemStack (org.bukkit.inventory.ItemStack)4 MinigameManager (au.com.mineauz.minigames.managers.MinigameManager)3 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)3 Block (org.bukkit.block.Block)3 PotionEffect (org.bukkit.potion.PotionEffect)3 MultiplayerTimer (au.com.mineauz.minigames.MultiplayerTimer)2 ICommand (au.com.mineauz.minigames.commands.ICommand)2