Search in sources :

Example 21 with Minigame

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

the class CTFMechanic method takeFlag.

@EventHandler
private void takeFlag(PlayerInteractEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame() && !ply.getPlayer().isDead() && ply.getMinigame().hasStarted()) {
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK && (event.getClickedBlock().getType() == Material.SIGN_POST || event.getClickedBlock().getType() == Material.WALL_SIGN) && ply.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR) {
            Minigame mgm = ply.getMinigame();
            Sign sign = (Sign) event.getClickedBlock().getState();
            if (mgm.getMechanicName().equals("ctf") && sign.getLine(1).equals(ChatColor.GREEN + "Flag")) {
                Team team = ply.getTeam();
                String sloc = MinigameUtils.createLocationID(event.getClickedBlock().getLocation());
                if ((!sign.getLine(2).equalsIgnoreCase(team.getChatColor() + team.getColor().toString()) && !sign.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "Capture")) || sign.getLine(2).equalsIgnoreCase(ChatColor.GRAY + "Neutral")) {
                    if (mgm.getFlagCarrier(ply) == null) {
                        TakeFlagEvent ev = null;
                        if (!mgm.hasDroppedFlag(sloc) && (TeamsModule.getMinigameModule(mgm).hasTeam(TeamColor.matchColor(ChatColor.stripColor(sign.getLine(2)))) || sign.getLine(2).equalsIgnoreCase(ChatColor.GRAY + "Neutral"))) {
                            Team oTeam = TeamsModule.getMinigameModule(mgm).getTeam(TeamColor.matchColor(ChatColor.stripColor(sign.getLine(2))));
                            CTFFlag flag = new CTFFlag(event.getClickedBlock().getLocation(), oTeam, event.getPlayer(), mgm);
                            ev = new TakeFlagEvent(mgm, ply, flag);
                            Bukkit.getPluginManager().callEvent(ev);
                            if (!ev.isCancelled()) {
                                mgm.addFlagCarrier(ply, flag);
                                flag.removeFlag();
                            }
                        } else if (mgm.hasDroppedFlag(sloc)) {
                            CTFFlag flag = mgm.getDroppedFlag(sloc);
                            ev = new TakeFlagEvent(mgm, ply, flag);
                            Bukkit.getPluginManager().callEvent(ev);
                            if (!ev.isCancelled()) {
                                mgm.addFlagCarrier(ply, flag);
                                if (!flag.isAtHome()) {
                                    flag.stopTimer();
                                }
                                flag.removeFlag();
                            }
                        }
                        if (mgm.getFlagCarrier(ply) != null && !ev.isCancelled()) {
                            if (mgm.getFlagCarrier(ply).getTeam() != null) {
                                Team fteam = mgm.getFlagCarrier(ply).getTeam();
                                String message = ply.getName() + " stole " + fteam.getChatColor() + fteam.getDisplayName() + ChatColor.WHITE + "'s flag!";
                                mdata.sendMinigameMessage(mgm, message, null, null);
                                mgm.getFlagCarrier(ply).startCarrierParticleEffect(ply.getPlayer());
                            } else {
                                String message = ply.getName() + " stole the " + ChatColor.GRAY + "neutral" + ChatColor.WHITE + " flag!";
                                mdata.sendMinigameMessage(mgm, message, null, null);
                                mgm.getFlagCarrier(ply).startCarrierParticleEffect(ply.getPlayer());
                            }
                        }
                    }
                } else if (team == TeamsModule.getMinigameModule(mgm).getTeam(TeamColor.matchColor(ChatColor.stripColor(sign.getLine(2)))) && CTFModule.getMinigameModule(mgm).getUseFlagAsCapturePoint() || (team == TeamsModule.getMinigameModule(mgm).getTeam(TeamColor.matchColor(ChatColor.stripColor(sign.getLine(3)))) && sign.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "Capture")) || (sign.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "Capture") && sign.getLine(3).equalsIgnoreCase(ChatColor.GRAY + "Neutral"))) {
                    String clickID = MinigameUtils.createLocationID(event.getClickedBlock().getLocation());
                    if (mgm.getFlagCarrier(ply) != null && (!mgm.hasDroppedFlag(clickID) || mgm.getDroppedFlag(clickID).isAtHome())) {
                        CTFFlag flag = mgm.getFlagCarrier(ply);
                        FlagCaptureEvent ev = new FlagCaptureEvent(mgm, ply, flag);
                        Bukkit.getPluginManager().callEvent(ev);
                        if (!ev.isCancelled()) {
                            flag.respawnFlag();
                            String id = MinigameUtils.createLocationID(flag.getSpawnLocation());
                            mgm.addDroppedFlag(id, flag);
                            mgm.removeFlagCarrier(ply);
                            boolean end = false;
                            if (mgm.isTeamGame()) {
                                ply.getTeam().addScore();
                                if (mgm.getMaxScore() != 0 && ply.getTeam().getScore() >= mgm.getMaxScorePerPlayer())
                                    end = true;
                                if (!end) {
                                    String message = MinigameUtils.formStr("player.ctf.capture", ply.getName(), ply.getTeam().getChatColor() + ply.getTeam().getDisplayName());
                                    mdata.sendMinigameMessage(mgm, message, null, null);
                                }
                                flag.stopCarrierParticleEffect();
                                ply.addScore();
                                mgm.setScore(ply, ply.getScore());
                                if (end) {
                                    mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.ctf.captureFinal", ply.getName(), ply.getTeam().getChatColor() + ply.getTeam().getDisplayName()), null, null);
                                    List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(ply.getTeam().getPlayers());
                                    List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mgm.getPlayers().size() - ply.getTeam().getPlayers().size());
                                    for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                                        if (t != ply.getTeam())
                                            l.addAll(t.getPlayers());
                                    }
                                    plugin.pdata.endMinigame(mgm, w, l);
                                    mgm.resetFlags();
                                }
                            } else {
                                ply.addScore();
                                mgm.setScore(ply, ply.getScore());
                                if (mgm.getMaxScore() != 0 && ply.getScore() >= mgm.getMaxScorePerPlayer()) {
                                    end = true;
                                }
                                mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.ctf.captureNeutral", ply.getName()), null, null);
                                flag.stopCarrierParticleEffect();
                                if (end) {
                                    mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.ctf.captureNeutralFinal", ply.getName()), null, null);
                                    pdata.endMinigame(ply);
                                    mgm.resetFlags();
                                }
                            }
                        }
                    } else if (mgm.getFlagCarrier(ply) == null && mgm.hasDroppedFlag(clickID) && !mgm.getDroppedFlag(clickID).isAtHome()) {
                        CTFFlag flag = mgm.getDroppedFlag(sloc);
                        if (mgm.hasDroppedFlag(sloc)) {
                            mgm.removeDroppedFlag(sloc);
                            String newID = MinigameUtils.createLocationID(flag.getSpawnLocation());
                            mgm.addDroppedFlag(newID, flag);
                        }
                        flag.respawnFlag();
                        mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.ctf.returned", ply.getName(), ply.getTeam().getChatColor() + ply.getTeam().getDisplayName() + ChatColor.WHITE), null, null);
                    } else if (mgm.getFlagCarrier(ply) != null && mgm.hasDroppedFlag(clickID) && !mgm.getDroppedFlag(clickID).isAtHome()) {
                        ply.sendMessage(MinigameUtils.getLang("player.ctf.returnFail"), null);
                    }
                }
            }
        }
    }
}
Also used : TakeFlagEvent(au.com.mineauz.minigames.events.TakeFlagEvent) MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) CTFFlag(au.com.mineauz.minigames.CTFFlag) Sign(org.bukkit.block.Sign) Team(au.com.mineauz.minigames.minigame.Team) ArrayList(java.util.ArrayList) List(java.util.List) FlagCaptureEvent(au.com.mineauz.minigames.events.FlagCaptureEvent) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 22 with Minigame

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

the class MultiplayerType method playerRespawn.

/*----------------*/
/*-----EVENTS-----*/
/*----------------*/
@EventHandler(priority = EventPriority.HIGHEST)
public void playerRespawn(PlayerRespawnEvent event) {
    final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply.isInMinigame() && ply.getMinigame().getType() == MinigameType.MULTIPLAYER) {
        Minigame mg = ply.getMinigame();
        Location respawnPos;
        if (ply.getMinigame().isTeamGame()) {
            Team team = ply.getTeam();
            if (mg.hasStarted() && !ply.isLatejoining()) {
                if (mg.isAllowedMPCheckpoints() && ply.hasCheckpoint()) {
                    respawnPos = ply.getCheckpoint();
                } else {
                    List<Location> starts = new ArrayList<Location>();
                    if (TeamsModule.getMinigameModule(mg).hasTeamStartLocations()) {
                        starts.addAll(team.getStartLocations());
                        ply.getLoadout().equiptLoadout(ply);
                    } else {
                        starts.addAll(mg.getStartLocations());
                    }
                    Collections.shuffle(starts);
                    respawnPos = starts.get(0);
                }
                ply.getLoadout().equiptLoadout(ply);
            } else {
                respawnPos = mg.getLobbyPosition();
            }
        } else {
            if (mg.hasStarted() && !ply.isLatejoining()) {
                if (mg.isAllowedMPCheckpoints() && ply.hasCheckpoint()) {
                    respawnPos = ply.getCheckpoint();
                } else {
                    List<Location> starts = new ArrayList<Location>();
                    starts.addAll(mg.getStartLocations());
                    Collections.shuffle(starts);
                    respawnPos = starts.get(0);
                }
                ply.getLoadout().equiptLoadout(ply);
            } else {
                respawnPos = mg.getLobbyPosition();
            }
        }
        event.setRespawnLocation(respawnPos);
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

            @Override
            public void run() {
                ply.getPlayer().setNoDamageTicks(60);
            }
        });
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) ArrayList(java.util.ArrayList) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 23 with Minigame

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

the class SingleplayerType method onPlayerRespawn.

/*----------------*/
/*-----EVENTS-----*/
/*----------------*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
    if (pdata.getMinigamePlayer(event.getPlayer()).isInMinigame()) {
        MinigamePlayer player = pdata.getMinigamePlayer(event.getPlayer());
        Minigame mgm = player.getMinigame();
        if (mgm.getType() == MinigameType.SINGLEPLAYER) {
            event.setRespawnLocation(player.getCheckpoint());
            player.sendMessage(MinigameUtils.getLang("player.checkpoint.deathRevert"), "error");
            player.getLoadout().equiptLoadout(player);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 24 with Minigame

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

the class JuggernautMechanic method minigameStart.

@EventHandler
private void minigameStart(StartMinigameEvent event) {
    if (event.getMinigame().getMechanic() == this) {
        Minigame mgm = event.getMinigame();
        mgm.getScoreboardManager().registerNewTeam("juggernaut");
        mgm.getScoreboardManager().getTeam("juggernaut").setPrefix(ChatColor.RED.toString());
        MinigamePlayer j = assignNewJuggernaut(event.getPlayers(), null);
        JuggernautModule.getMinigameModule(event.getMinigame()).setJuggernaut(j);
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 25 with Minigame

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

the class LivesMechanic method minigameStart.

@EventHandler
private void minigameStart(StartMinigameEvent event) {
    if (event.getMinigame().getMechanicName().equals(getMechanic())) {
        final List<MinigamePlayer> players = event.getPlayers();
        final Minigame minigame = event.getMinigame();
        for (MinigamePlayer player : players) {
            player.setScore(minigame.getLives());
            minigame.setScore(player, minigame.getLives());
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) 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