use of com.ebicep.warlords.events.WarlordsGameTriggerWinEvent 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.events.WarlordsGameTriggerWinEvent 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);
}
use of com.ebicep.warlords.events.WarlordsGameTriggerWinEvent in project Warlords by ebicep.
the class PlayingState method begin.
@Override
@SuppressWarnings("null")
public void begin() {
this.game.setAcceptsSpectators(true);
this.game.setAcceptsPlayers(false);
this.resetTimer();
RemoveEntities.doRemove(this.game);
for (Option option : game.getOptions()) {
option.start(game);
}
this.game.forEachOfflinePlayer((player, team) -> {
if (team != null) {
PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
Warlords.addPlayer(new WarlordsPlayer(player, this, team, playerSettings));
}
});
this.game.forEachOfflineWarlordsPlayer(wp -> {
CustomScoreboard customScoreboard = Warlords.playerScoreboards.get(wp.getUuid());
updateBasedOnGameState(customScoreboard, wp);
if (wp.getEntity() instanceof Player) {
wp.applySkillBoost((Player) wp.getEntity());
}
});
if (DatabaseManager.playerService != null) {
Warlords.newChain().async(() -> game.forEachOfflinePlayer((player, team) -> {
DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
DatabaseManager.updatePlayerAsync(databasePlayer);
DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.SEASON_5, () -> {
});
DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.WEEKLY, () -> {
});
DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.DAILY, () -> {
});
})).execute();
} else {
System.out.println("ATTENTION - playerService is null");
}
game.registerEvents(new Listener() {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onWin(WarlordsGameTriggerWinEvent event) {
game.setNextState(new EndState(game, event));
winEvent = event;
}
});
GameRunnable.create(game, this::updateScoreboard).runTaskTimer(0, 10);
new GameRunnable(game) {
@Override
public void run() {
counter++;
timer += GameRunnable.SECOND;
if (counter >= 60) {
counter -= 60;
PlayerFilter.playingGame(game).forEach(wp -> wp.getMinuteStats().advanceMinute());
}
PlayerFilter.playingGame(game).forEach(wp -> wp.getSecondStats().advanceSecond());
}
}.runTaskTimer(0, GameRunnable.SECOND);
game.registerGameMarker(TimerSkipAbleMarker.class, (delay) -> {
counter += delay / GameRunnable.SECOND;
timer += delay;
});
Warlords.getInstance().hideAndUnhidePeople();
}
use of com.ebicep.warlords.events.WarlordsGameTriggerWinEvent in project Warlords by ebicep.
the class WinByPointsOption method onEvent.
@EventHandler
public void onEvent(WarlordsPointsChangedEvent event) {
if (!hasActivated && event.getNewPoints() >= pointLimit) {
WarlordsGameTriggerWinEvent e = new WarlordsGameTriggerWinEvent(event.getGame(), this, event.getTeam());
Bukkit.getPluginManager().callEvent(e);
if (!e.isCancelled()) {
hasActivated = true;
}
}
}
Aggregations