Search in sources :

Example 31 with Minigame

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

the class StartCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
    if (args != null) {
        Minigame mgm = plugin.mdata.getMinigame(args[0]);
        if (mgm != null) {
            if (!mgm.isEnabled() && mgm.getType() == MinigameType.GLOBAL) {
                MinigamePlayer caller = null;
                if (sender instanceof Player)
                    caller = plugin.pdata.getMinigamePlayer((Player) sender);
                plugin.mdata.startGlobalMinigame(mgm, caller);
            } else if (mgm.getType() != MinigameType.GLOBAL && mgm.getType() != MinigameType.SINGLEPLAYER && mgm.hasPlayers()) {
                if (mgm.getMpTimer() == null || mgm.getMpTimer().getPlayerWaitTimeLeft() != 0) {
                    if (mgm.getMpTimer() == null) {
                        mgm.setMpTimer(new MultiplayerTimer(mgm));
                    }
                    mgm.getMpTimer().setPlayerWaitTime(0);
                    mgm.getMpTimer().startTimer();
                } else
                    sender.sendMessage(ChatColor.RED + mgm.getName(false) + " has already started.");
            } else if (mgm.isEnabled() && mgm.getType() == MinigameType.GLOBAL) {
                sender.sendMessage(ChatColor.RED + mgm.getName(false) + " is already running!");
            }
        } else {
            sender.sendMessage(ChatColor.RED + "No Global or Multiplayer Minigame found by the name " + args[0]);
        }
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) MultiplayerTimer(au.com.mineauz.minigames.MultiplayerTimer) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 32 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 33 with Minigame

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

the class RegionEvents method playerMove.

@EventHandler(ignoreCancelled = true)
private void playerMove(PlayerMoveEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame()) {
        Minigame mg = ply.getMinigame();
        executeRegionChanges(mg, ply);
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 34 with Minigame

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

the class RegionEvents method playerQuit.

@EventHandler(ignoreCancelled = true)
private void playerQuit(QuitMinigameEvent event) {
    MinigamePlayer ply = event.getMinigamePlayer();
    if (ply == null)
        return;
    Minigame mg = ply.getMinigame();
    for (Region r : RegionModule.getMinigameModule(mg).getRegions()) {
        if (r.hasPlayer(ply))
            r.removePlayer(ply);
    }
    for (Node node : RegionModule.getMinigameModule(event.getMinigame()).getNodes()) {
        node.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
        if (event.getMinigame().getPlayers().size() > 1) {
            for (NodeExecutor exec : node.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
        } else {
            for (NodeExecutor exec : node.getExecutors()) exec.clearTriggers();
            node.setEnabled(true);
        }
    }
    for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
        if (region.playerInRegion(ply))
            region.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
        if (event.getMinigame().getPlayers().size() > 1) {
            for (RegionExecutor exec : region.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
        } else {
            for (RegionExecutor exec : region.getExecutors()) {
                exec.clearTriggers();
            }
            region.removeTickTask();
            region.setEnabled(true);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) RegionExecutor(au.com.mineauz.minigamesregions.executors.RegionExecutor) Minigame(au.com.mineauz.minigames.minigame.Minigame) NodeExecutor(au.com.mineauz.minigamesregions.executors.NodeExecutor) EventHandler(org.bukkit.event.EventHandler)

Example 35 with Minigame

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

the class RegionEvents method playerJoin.

@EventHandler(ignoreCancelled = true)
private void playerJoin(JoinMinigameEvent event) {
    final MinigamePlayer ply = event.getMinigamePlayer();
    if (ply == null)
        return;
    final Minigame mg = event.getMinigame();
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

        @Override
        public void run() {
            executeRegionChanges(mg, ply);
            for (Node node : RegionModule.getMinigameModule(mg).getNodes()) {
                node.execute(Triggers.getTrigger("GAME_JOIN"), ply);
            }
            for (Region region : RegionModule.getMinigameModule(mg).getRegions()) {
                if (region.hasPlayer(ply))
                    region.execute(Triggers.getTrigger("GAME_JOIN"), ply);
            }
        }
    });
    if (event.getMinigame().getPlayers().size() == 0) {
        for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
            for (RegionExecutor ex : region.getExecutors()) {
                if (ex.getTrigger().getName().equalsIgnoreCase("TICK")) {
                    region.startTickTask();
                    break;
                }
            }
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) RegionExecutor(au.com.mineauz.minigamesregions.executors.RegionExecutor) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Minigame (au.com.mineauz.minigames.minigame.Minigame)64 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)33 EventHandler (org.bukkit.event.EventHandler)29 ArrayList (java.util.ArrayList)19 Player (org.bukkit.entity.Player)16 Team (au.com.mineauz.minigames.minigame.Team)15 List (java.util.List)7 Location (org.bukkit.Location)7 TreasureHuntModule (au.com.mineauz.minigames.minigame.modules.TreasureHuntModule)4 Sign (org.bukkit.block.Sign)4 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)3 Block (org.bukkit.block.Block)3 ItemStack (org.bukkit.inventory.ItemStack)3 PotionEffect (org.bukkit.potion.PotionEffect)3 CTFFlag (au.com.mineauz.minigames.CTFFlag)2 MinigameData (au.com.mineauz.minigames.MinigameData)2 MultiplayerTimer (au.com.mineauz.minigames.MultiplayerTimer)2 ICommand (au.com.mineauz.minigames.commands.ICommand)2 TakeFlagEvent (au.com.mineauz.minigames.events.TakeFlagEvent)2 ScoreboardDisplay (au.com.mineauz.minigames.minigame.ScoreboardDisplay)2