Search in sources :

Example 61 with MinigamePlayer

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

the class GameMechanicBase method balanceTeam.

/**
 * In the case of a Minigame having teams, this should be used to balance players
 * to a specific team, usual games is evenly distributed, in the case of Infection,
 * only a specific percentage is assigned to one team by default. The default function
 * will assign teams automatically unless overridden.
 * Additionally teams that are flagged as autoBalance false will not have players removed or added through a team switch...
 *
 * @param players  The players to be balanced to a team
 * @param minigame The minigame in which the balancing occours
 * @return List of {@link MinigamePlayer} that have been moved to a different or new team.
 */
public List<MinigamePlayer> balanceTeam(List<MinigamePlayer> players, Minigame minigame) {
    List<MinigamePlayer> result = new ArrayList<>();
    if (minigame.isTeamGame()) {
        boolean sorted = false;
        for (MinigamePlayer ply : players) {
            if (ply.getTeam() == null) {
                Team smt = null;
                for (Team t : TeamsModule.getMinigameModule(minigame).getTeams()) {
                    if (smt == null || (t.getPlayers().size() < smt.getPlayers().size() && (t.getMaxPlayers() == 0 || t.getPlayers().size() != t.getMaxPlayers())))
                        smt = t;
                }
                if (smt == null) {
                    pdata.quitMinigame(ply, false);
                    ply.sendMessage(MinigameUtils.getLang("minigame.full"), MinigameMessageType.ERROR);
                } else {
                    smt.addPlayer(ply);
                    ply.sendInfoMessage(String.format(smt.getAutobalanceMessage(), smt.getChatColor() + smt.getDisplayName()));
                    mdata.sendMinigameMessage(minigame, String.format(smt.getGameAutobalanceMessage(), ply.getName(), smt.getChatColor() + smt.getDisplayName()), null, ply);
                }
            }
        }
        while (!sorted) {
            Team smt = null;
            Team lgt = null;
            for (Team t : TeamsModule.getMinigameModule(minigame).getTeams()) {
                if (smt == null || (t.getPlayers().size() < smt.getPlayers().size() - 1 && !t.isFull() && t.getAutoBalanceTeam()))
                    smt = t;
                if ((lgt == null || (t.getPlayers().size() > lgt.getPlayers().size() && !t.isFull())) && t != smt && t.getAutoBalanceTeam())
                    lgt = t;
            }
            if (smt != null && lgt != null && lgt.getPlayers().size() - smt.getPlayers().size() > 1) {
                MinigamePlayer pl = lgt.getPlayers().get(0);
                MultiplayerType.switchTeam(minigame, pl, smt);
                result.add(pl);
                pl.sendInfoMessage(String.format(smt.getAutobalanceMessage(), smt.getChatColor() + smt.getDisplayName()));
                mdata.sendMinigameMessage(minigame, String.format(smt.getGameAutobalanceMessage(), pl.getDisplayName(minigame.usePlayerDisplayNames()), smt.getChatColor() + smt.getDisplayName()), null, pl);
            } else {
                sorted = true;
            }
        }
    }
    return result;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ArrayList(java.util.ArrayList) Team(au.com.mineauz.minigames.minigame.Team)

Example 62 with MinigamePlayer

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

the class LivesMechanic method playerDeath.

@EventHandler
private void playerDeath(PlayerDeathEvent event) {
    MinigamePlayer ply = Minigames.getPlugin().getPlayerManager().getMinigamePlayer(event.getEntity());
    if (ply == null)
        return;
    if (ply.isInMinigame() && ply.getMinigame().getMechanicName().equals(getMechanic())) {
        ply.addScore(-1);
        ply.getMinigame().setScore(ply, ply.getScore());
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) EventHandler(org.bukkit.event.EventHandler)

Example 63 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer 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) {
            if (!Float.isFinite(minigame.getLives())) {
                player.setScore(Integer.MAX_VALUE);
                minigame.setScore(player, Integer.MAX_VALUE);
            } else {
                int lives = Float.floatToIntBits(minigame.getLives());
                player.setScore(lives);
                minigame.setScore(player, lives);
            }
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 64 with MinigamePlayer

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

the class MenuItemAddFlag method onClick.

@Override
public ItemStack onClick() {
    MinigamePlayer ply = getContainer().getViewer();
    ply.setNoClose(true);
    ply.getPlayer().closeInventory();
    ply.sendMessage("Enter a flag name into chat for " + getName() + ", the menu will automatically reopen in 20s if nothing is entered.", MinigameMessageType.INFO);
    ply.setManualEntry(this);
    getContainer().startReopenTimer(20);
    return null;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer)

Example 65 with MinigamePlayer

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

the class MenuItemAddWhitelistBlock method onClick.

@Override
public ItemStack onClick() {
    MinigamePlayer ply = getContainer().getViewer();
    ply.setNoClose(true);
    ply.getPlayer().closeInventory();
    ply.sendMessage("Enter material name into chat to add to the whitelist/blacklist, the menu will automatically reopen in 30s if nothing is entered.", MinigameMessageType.INFO);
    ply.setManualEntry(this);
    getContainer().startReopenTimer(30);
    return null;
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer)

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