Search in sources :

Example 56 with MinigamePlayer

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

the class MinigamePlayerManager method balanceGame.

public List<MinigamePlayer> balanceGame(Minigame game) {
    List<MinigamePlayer> result = null;
    if (game.isTeamGame()) {
        GameMechanicBase mech = GameMechanics.getGameMechanic(game.getMechanicName());
        if (mech != null) {
            List<MinigamePlayer> players = new ArrayList<>(game.getPlayers());
            result = mech.balanceTeam(players, game);
        }
    }
    return result;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) GameMechanicBase(au.com.mineauz.minigames.mechanics.GameMechanicBase)

Example 57 with MinigamePlayer

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

the class MenuItemAddTeam method onClick.

@Override
public ItemStack onClick() {
    MinigamePlayer ply = getContainer().getViewer();
    ply.setNoClose(true);
    ply.getPlayer().closeInventory();
    ply.sendMessage("Enter the color of the team you wish to add. All colors available below:", MinigameMessageType.INFO);
    List<String> teams = new ArrayList<>();
    for (TeamColor col : TeamColor.values()) teams.add(col.getColor() + MinigameUtils.capitalize(col.toString().replace("_", " ")));
    ply.sendInfoMessage(MinigameUtils.listToString(teams));
    ply.setManualEntry(this);
    getContainer().startReopenTimer(30);
    return null;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ArrayList(java.util.ArrayList) TeamColor(au.com.mineauz.minigames.minigame.TeamColor)

Example 58 with MinigamePlayer

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

the class MenuItemDecimal method onDoubleClick.

@Override
public ItemStack onDoubleClick() {
    MinigamePlayer ply = getContainer().getViewer();
    ply.setNoClose(true);
    ply.getPlayer().closeInventory();
    ply.sendMessage("Enter decimal value into chat for " + getName() + ", the menu will automatically reopen in 15s if nothing is entered.", MinigameMessageType.INFO);
    String min = "N/A";
    String max = "N/A";
    if (this.min != null) {
        min = this.min.toString();
    }
    if (this.max != null) {
        max = this.max.toString();
    }
    ply.setManualEntry(this);
    ply.sendInfoMessage("Min: " + min + ", Max: " + max);
    getContainer().startReopenTimer(15);
    return null;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer)

Example 59 with MinigamePlayer

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

the class CTFMechanic method endMinigame.

@Override
public void endMinigame(Minigame minigame, List<MinigamePlayer> winners, List<MinigamePlayer> losers) {
    for (MinigamePlayer pl : winners) {
        if (minigame.isFlagCarrier(pl)) {
            minigame.getFlagCarrier(pl).stopCarrierParticleEffect();
            minigame.getFlagCarrier(pl).respawnFlag();
            minigame.removeFlagCarrier(pl);
        }
    }
    if (minigame.getPlayers().size() == 1) {
        minigame.resetFlags();
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer)

Example 60 with MinigamePlayer

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

the class CTFMechanic method takeFlag.

@EventHandler
public 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.OAK_SIGN || event.getClickedBlock().getType() == Material.OAK_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);
                                mgm.getFlagCarrier(ply).startCarrierParticleEffect(ply.getPlayer());
                            } else {
                                String message = ply.getName() + " stole the " + ChatColor.GRAY + "neutral" + ChatColor.WHITE + " flag!";
                                mdata.sendMinigameMessage(mgm, message);
                                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);
                                }
                                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()));
                                    List<MinigamePlayer> w = new ArrayList<>(ply.getTeam().getPlayers());
                                    List<MinigamePlayer> l = new ArrayList<>(mgm.getPlayers().size() - ply.getTeam().getPlayers().size());
                                    for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
                                        if (t != ply.getTeam())
                                            l.addAll(t.getPlayers());
                                    }
                                    plugin.getPlayerManager().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()));
                                flag.stopCarrierParticleEffect();
                                if (end) {
                                    mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.ctf.captureNeutralFinal", ply.getName()));
                                    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));
                    } else if (mgm.getFlagCarrier(ply) != null && mgm.hasDroppedFlag(clickID) && !mgm.getDroppedFlag(clickID).isAtHome()) {
                        ply.sendMessage(MinigameUtils.getLang("player.ctf.returnFail"), MinigameMessageType.LOSS);
                    }
                }
            }
        }
    }
}
Also used : TakeFlagEvent(au.com.mineauz.minigames.events.TakeFlagEvent) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) CTFFlag(au.com.mineauz.minigames.objects.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)

Aggregations

MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)134 EventHandler (org.bukkit.event.EventHandler)46 Minigame (au.com.mineauz.minigames.minigame.Minigame)40 ArrayList (java.util.ArrayList)25 Team (au.com.mineauz.minigames.minigame.Team)24 OfflineMinigamePlayer (au.com.mineauz.minigames.objects.OfflineMinigamePlayer)15 Player (org.bukkit.entity.Player)15 Location (org.bukkit.Location)11 ItemStack (org.bukkit.inventory.ItemStack)8 MinigameTool (au.com.mineauz.minigames.tool.MinigameTool)7 Menu (au.com.mineauz.minigames.menu.Menu)5 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)5 List (java.util.List)5 PotionEffect (org.bukkit.potion.PotionEffect)5 ResourcePack (au.com.mineauz.minigames.objects.ResourcePack)4 Material (org.bukkit.Material)4 Sign (org.bukkit.block.Sign)4 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)3 MenuItem (au.com.mineauz.minigames.menu.MenuItem)2 MenuItemBoolean (au.com.mineauz.minigames.menu.MenuItemBoolean)2