use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class GameFreezeWhenOfflineOption method start.
@Override
public void start(Game game) {
new GameRunnable(game, true) {
@Override
public void run() {
boolean anyOffline = game.offlinePlayersWithoutSpectators().anyMatch(e -> !e.getKey().isOnline());
if (isFrozen) {
if (anyOffline) {
timer = 0;
} else if (timer >= UNFREEZE_TIME) {
game.removeFrozenCause(FROZEN_MESSAGE);
isFrozen = false;
timer = 0;
} else {
game.forEachOnlinePlayerWithoutSpectators((p, team) -> {
PacketUtils.sendTitle(p, ChatColor.BLUE + "Resuming in... " + ChatColor.GREEN + (UNFREEZE_TIME - timer), "", 0, 40, 0);
});
timer++;
}
} else {
if (!anyOffline) {
timer = 0;
} else if (timer >= FREEZE_TIME) {
game.addFrozenCause(FROZEN_MESSAGE);
isFrozen = true;
timer = 0;
} else {
timer++;
}
}
}
}.runTaskTimer(0, 20);
}
use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class ImposterModeOption method sendPoll.
public void sendPoll(Team team) {
poll = new GamePoll.Builder(game).setQuestion("Who is the most SUS on your team?").setTimeLeft(60).setOptions(game.offlinePlayersWithoutSpectators().filter(uuidTeamEntry -> uuidTeamEntry.getValue() == team).map(offlinePlayerTeamEntry -> offlinePlayerTeamEntry.getKey().getName()).collect(Collectors.toList())).setExcludedPlayers(game.offlinePlayersWithoutSpectators().filter(uuidTeamEntry -> uuidTeamEntry.getValue() != team).map(offlinePlayerTeamEntry -> offlinePlayerTeamEntry.getKey().getUniqueId()).collect(Collectors.toList())).setRunnableAfterPollEnded(p -> {
int mostVotes = Collections.max(p.getOptionsWithVotes().entrySet(), Comparator.comparingInt(Map.Entry::getValue)).getValue();
List<WarlordsPlayer> votedOut = p.getOptionsWithVotes().entrySet().stream().filter(stringIntegerEntry -> stringIntegerEntry.getValue() == mostVotes).map(Map.Entry::getKey).map(s -> game.warlordsPlayers().filter(warlordsPlayer -> warlordsPlayer.getName().equals(s)).findFirst().get()).collect(Collectors.toList());
// If multiple top votes and one is imposter then voted wrong
boolean votedCorrectly = votedOut.size() == 1 && imposters.get(team).stream().anyMatch(warlordsPlayer -> warlordsPlayer == votedOut.get(0));
new GameRunnable(game, true) {
int counter = 0;
@Override
public void run() {
String title = "";
String subtitle = "";
switch(counter) {
case 0:
case 1:
title = team.teamColor + team.name + " voted...";
break;
case 2:
case 3:
if (votedCorrectly) {
title = ChatColor.GREEN + "Correctly!";
} else {
title = ChatColor.RED + "Incorrectly!";
}
subtitle = team.teamColor + imposters.get(team).get(0).getName() + ChatColor.YELLOW + " was the imposter";
break;
}
counter++;
if (counter < 6) {
sendTitle(title, subtitle);
} else if (counter == 6) {
game.onlinePlayersWithoutSpectators().forEach(playerTeamEntry -> {
Player player = playerTeamEntry.getKey();
player.removePotionEffect(PotionEffectType.BLINDNESS);
showWinLossMessage(team, player, votedCorrectly, playerTeamEntry.getValue() == team);
});
} else if (counter == 9) {
game.removeFrozenCause(team.teamColor + team.name + ChatColor.GREEN + " is voting!");
int scoreNeededToEndGame = game.getOptions().stream().filter(e -> e instanceof WinByPointsOption).mapToInt(e -> ((WinByPointsOption) e).getPointLimit()).sorted().findFirst().orElse(Integer.MAX_VALUE);
if (votedCorrectly) {
game.setPoints(team, scoreNeededToEndGame);
} else {
// team with most points win, excluding voting team
game.setPoints(TeamMarker.getTeams(game).stream().filter(t -> t != team).min(Comparator.comparingInt(o -> game.getPoints(o))).get(), scoreNeededToEndGame);
}
((PlayingState) game.getState()).skipTimer();
game.onlinePlayers().forEach(playerTeamEntry -> {
Player player = playerTeamEntry.getKey();
sendImpostorResult(player);
});
this.cancel();
}
}
}.runTaskTimer(10, 20);
}).get();
}
use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class InterceptionPointOption method start.
@Override
public void start(Game game) {
Location clone = this.location.clone();
clone.add(0, -1.7, 0);
for (int i = middle.length - 1; i >= 0; i--) {
clone.add(0, this.captureProgress * 1 + 0.25, 0);
middle[i] = location.getWorld().spawn(clone, ArmorStand.class);
middle[i].setGravity(false);
middle[i].setBasePlate(false);
middle[i].setArms(false);
middle[i].setVisible(false);
}
updateArmorstandsAndEffect(null);
scoreboard.registerChangeHandler(this::updateArmorstandsAndEffect);
new GameRunnable(game) {
@Override
public void run() {
Stream<WarlordsPlayer> computePlayers = computePlayers();
double speed = updateTeamInCircle(computePlayers);
updateTeamHackProcess(speed);
if (effectPlayer != null) {
effectPlayer.playEffects();
}
}
}.runTaskTimer(1, 1);
}
use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class MercyWinOption method start.
@Override
public void start(Game game) {
EnumSet<Team> teams = TeamMarker.getTeams(game);
new GameRunnable(game) {
@Override
public void run() {
if (timer > 0) {
timer--;
return;
}
int higest = Integer.MIN_VALUE;
int secondHighest = Integer.MIN_VALUE;
Team winner = null;
for (Team team : teams) {
int points = game.getPoints(team);
if (points > higest) {
winner = team;
secondHighest = higest;
higest = points;
} else if (points > secondHighest) {
secondHighest = points;
}
}
if (higest - limit >= secondHighest) {
WarlordsGameTriggerWinEvent event = new WarlordsGameTriggerWinEvent(game, MercyWinOption.this, winner);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
cancel();
}
}
}
}.runTaskTimer(1 * SECOND, 1 * SECOND);
}
use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class WinAfterTimeoutOption method start.
@Override
public void start(Game game) {
this.runTaskTimer = new GameRunnable(game) {
@Override
public void run() {
timeRemaining--;
if (timeRemaining <= 0) {
Team leader;
if (winner == null) {
int higest = Integer.MIN_VALUE;
int secondHighest = Integer.MIN_VALUE;
leader = null;
for (Team team : TeamMarker.getTeams(game)) {
int points = game.getPoints(team);
if (points > higest) {
leader = team;
secondHighest = higest;
higest = points;
} else if (points > secondHighest) {
secondHighest = points;
}
}
if (higest <= secondHighest) {
leader = null;
}
} else {
leader = winner;
}
WarlordsGameTriggerWinEvent event = new WarlordsGameTriggerWinEvent(game, WinAfterTimeoutOption.this, leader);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
cancel();
}
}
scoreboard.markChanged();
}
}.runTaskTimer(1 * SECOND, 1 * SECOND);
}
Aggregations