use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.
the class PotionEffectEditorMenu method init.
@Override
public void init(Player player, InventoryContents contents) {
addBackItem(contents, e -> menus.getTeamMenus().openPotionEffectsMenu(player, arena, team));
contents.set(0, 3, ClickableItem.from(nameItem(Material.REDSTONE, "&eDuration", "||&eCurrent value: &3" + potionEffect.getDuration()), e -> openAnvilMenu(player, arena, team, potionEffect, String.valueOf(potionEffect.getDuration()), (p, text) -> {
if (Utils.isInt(text)) {
team.getLoadout().getEffects().remove(potionEffect);
potionEffect = new PotionEffectBuilder(potionEffect).duration(Integer.parseInt(text)).build();
team.getLoadout().getEffects().add(potionEffect);
arena.write();
Tasks.wait(1, () -> {
// Since potion effects don't have setters, pass-by-reference is broken, so we
// have to do some hacky waits to get the menu to open with the correct object
player.closeInventory();
Tasks.wait(1, () -> menus.getTeamMenus().openPotionEffectEditorMenu(player, arena, team, potionEffect));
});
return AnvilGUI.Response.text(text);
} else {
PlayerUtils.send(player, PREFIX + "You must use an integer for the duration.");
return AnvilGUI.Response.close();
}
})));
contents.set(0, 5, ClickableItem.from(nameItem(Material.GLOWSTONE_DUST, "&eAmplifier", "||&eCurrent value: &3" + (potionEffect.getAmplifier() + 1)), e -> openAnvilMenu(player, arena, team, potionEffect, String.valueOf(potionEffect.getAmplifier()), (p, text) -> {
if (Utils.isInt(text)) {
team.getLoadout().getEffects().remove(potionEffect);
potionEffect = new PotionEffectBuilder(potionEffect).amplifier(Integer.parseInt(text) - 1).build();
team.getLoadout().getEffects().add(potionEffect);
arena.write();
Tasks.wait(1, () -> {
player.closeInventory();
Tasks.wait(1, () -> menus.getTeamMenus().openPotionEffectEditorMenu(player, arena, team, potionEffect));
});
return AnvilGUI.Response.text(text);
} else {
PlayerUtils.send(player, PREFIX + "You must use an integer for the amplifier.");
return AnvilGUI.Response.close();
}
})));
contents.set(0, 8, ClickableItem.from(nameItem(Material.END_CRYSTAL, "&eSave"), e -> arena.write()));
int row = 2;
int column = 0;
for (PotionEffectType effect : PotionEffectType.values()) {
if (effect == null)
continue;
ItemStack potionItem = new ItemBuilder(Material.POTION).name("&e" + StringUtils.camelCase(effect.getName().replace("_", " "))).potionEffect(new PotionEffectBuilder(effect).duration(5).amplifier(0)).potionEffectColor(effect.getColor()).build();
if (effect == potionEffect.getType())
potionItem.setType(Material.SPLASH_POTION);
contents.set(row, column, ClickableItem.from(potionItem, e -> {
team.getLoadout().getEffects().remove(potionEffect);
potionEffect = new PotionEffectBuilder(potionEffect).type(effect).build();
team.getLoadout().getEffects().add(potionEffect);
arena.write();
Tasks.wait(1, () -> {
player.closeInventory();
Tasks.wait(1, () -> menus.getTeamMenus().openPotionEffectEditorMenu(player, arena, team, potionEffect));
});
}));
if (column == 8) {
column = 0;
row++;
} else {
column++;
}
}
}
use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.
the class TeamMechanic method nextTurn.
public void nextTurn(@NotNull Match match) {
Arena arena = match.getArena();
MatchData matchData = match.getMatchData();
MatchTasks tasks = match.getTasks();
if (match.isEnded() || matchData == null)
return;
if (matchData.getTurnTeam() != null) {
onTurnEnd(match, matchData.getTurnTeam());
matchData.setTurnTeam(null);
}
if (shouldBeOver(match)) {
end(match);
return;
}
if (matchData.getTurns() >= match.getArena().getMaxTurns()) {
match.broadcast("Max turns reached, ending game");
match.end();
return;
}
if (matchData.getTurnTeamList().isEmpty()) {
matchData.setTurnTeamList(new ArrayList<>(match.getAliveTeams()));
if (shuffleTurnList())
Collections.shuffle(matchData.getTurnTeamList());
}
tasks.cancel(MatchTaskType.TURN);
Team team = matchData.getTurnTeamList().get(0);
matchData.getTurnTeamList().remove(team);
matchData.setTurnTeam(team);
match.getScoreboard().update();
onTurnStart(match, team);
tasks.register(MatchTaskType.TURN, tasks.wait(arena.getTurnTime() * TickTime.SECOND.get(), () -> nextTurn(match)));
}
use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.
the class TeamMechanic method announceWinners.
@Override
public void announceWinners(@NotNull Match match) {
Arena arena = match.getArena();
Map<Team, Integer> scores = match.getScores();
int winningScore = getWinningScore(scores.values());
List<Team> winners = getWinningTeams(winningScore, scores);
String announcement = null;
if (winningScore == 0)
announcement = "No teams scored in ";
else if (arena.getTeams().size() == winners.size())
announcement = "All teams tied in ";
JsonBuilder builder = new JsonBuilder();
builder.next(announcement == null ? getWinnersComponent(winners) : Component.text(announcement));
builder.next(arena);
if (winningScore != 0)
builder.next(" (" + winningScore + ")");
Minigames.broadcast(builder);
}
use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.
the class TeamMechanic method getBalanceWrappers.
@NotNull
protected List<BalanceWrapper> getBalanceWrappers(@NotNull Match match) {
// ALL PERCENTAGES HERE RANGE FROM 0 to 1 !!
List<Team> teams = match.getArena().getTeams();
List<BalanceWrapper> wrappers = new ArrayList<>();
// sum of all balance percentages
double percentageSum = 0;
// count of teams w/o balance percentages
int noPercentage = 0;
for (Team team : teams) {
BalanceWrapper wrapper = new BalanceWrapper(team, match);
wrappers.add(wrapper);
if (wrapper.getPercentage() != null)
percentageSum += wrapper.getPercentage();
else
noPercentage++;
}
if (noPercentage > 0 && percentageSum < 1) {
// evenly split the balance of teams that don't have a balance percentage (if there is any unassigned %)
double percentage = (1d / noPercentage) * (1d - percentageSum);
wrappers.stream().filter(wrapper -> wrapper.getPercentage() == null).forEach(wrapper -> wrapper.setPercentage(percentage));
}
// ensure percentages add up to 100
double totalPercentage = wrappers.stream().mapToDouble(BalanceWrapper::getPercentage).sum();
wrappers.forEach(wrapper -> wrapper.setPercentage(wrapper.getPercentage() / totalPercentage));
return wrappers;
}
use of gg.projecteden.nexus.features.minigames.models.Team in project Nexus by ProjectEdenGG.
the class TeamMechanic method basicBalanceCheck.
public final boolean basicBalanceCheck(@NotNull List<Minigamer> minigamers) {
if (minigamers.isEmpty())
return false;
Match match = minigamers.get(0).getMatch();
Arena arena = match.getArena();
List<Team> teams = new ArrayList<>(arena.getTeams());
int required = 0;
for (Team team : teams) required += team.getMinPlayers();
if (match.getMinigamers().size() < required) {
error("Not enough players to meet team requirements!", match);
return false;
}
return true;
}
Aggregations