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;
}
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());
}
}
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);
}
}
}
}
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;
}
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;
}
Aggregations