111 lines
3.4 KiB
Java
111 lines
3.4 KiB
Java
package runnables;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Sound;
|
|
|
|
import main.SpleggOG;
|
|
import managers.Game;
|
|
import managers.LobbyScoreboard;
|
|
import utils.SpleggPlayer;
|
|
|
|
public class LobbyCountdown implements Runnable {
|
|
|
|
int lobbycount;
|
|
Game game;
|
|
// Set by /spforcestart so the countdown ignores Options.AutoStartPlayers.
|
|
boolean ignorePlayerCount;
|
|
|
|
public LobbyCountdown(SpleggOG splegg, Game game, int lobbycount) {
|
|
|
|
this(splegg, game, lobbycount, false);
|
|
|
|
}
|
|
|
|
public LobbyCountdown(SpleggOG splegg, Game game, int lobbycount, boolean ignorePlayerCount) {
|
|
|
|
this.game = game;
|
|
this.lobbycount = lobbycount;
|
|
this.ignorePlayerCount = ignorePlayerCount;
|
|
|
|
}
|
|
|
|
public void run() {
|
|
|
|
if (this.lobbycount >= 1) {
|
|
|
|
this.lobbycount--;
|
|
this.game.setLobbyCount(this.lobbycount);
|
|
this.game.selectMapFromVoteIfDue(this.lobbycount);
|
|
|
|
SpleggPlayer sp;
|
|
Iterator<?> playersInGameIterator = this.game.getPlayers().values().iterator();
|
|
while (playersInGameIterator.hasNext()) {
|
|
|
|
sp = (SpleggPlayer) playersInGameIterator.next();
|
|
sp.getPlayer().setLevel(this.lobbycount);
|
|
sp.getPlayer().setExp((float) ((double) this.game.getLobbyCount() * 0.008D));
|
|
|
|
}
|
|
|
|
this.game.getSign().update(this.game.getMap(), false);
|
|
LobbyScoreboard.refreshGame(this.game);
|
|
|
|
if (this.lobbycount % 25 == 0) {
|
|
|
|
SpleggOG.getPlugin().chat.bc(SpleggOG.getPlugin().getConfig().getString("Messages.LobbyTimer")
|
|
.replaceAll("%timer%", String.valueOf(this.lobbycount)), this.game);
|
|
|
|
}
|
|
|
|
if (this.lobbycount <= 10 && this.lobbycount >= 1) {
|
|
|
|
SpleggOG.getPlugin().chat.bc(SpleggOG.getPlugin().getConfig().getString("Messages.LobbyTimer")
|
|
.replaceAll("%timer%", String.valueOf(this.lobbycount)), this.game);
|
|
|
|
playersInGameIterator = this.game.getPlayers().values().iterator();
|
|
while (playersInGameIterator.hasNext()) {
|
|
|
|
sp = (SpleggPlayer) playersInGameIterator.next();
|
|
sp.getPlayer().playSound(sp.getPlayer().getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1.0F,
|
|
1.0F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.lobbycount <= 0) {
|
|
|
|
playersInGameIterator = this.game.getPlayers().values().iterator();
|
|
while (playersInGameIterator.hasNext()) {
|
|
|
|
sp = (SpleggPlayer) playersInGameIterator.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ((this.game.getPlayers().size()) >= (this.ignorePlayerCount ? 1 : 2)) {
|
|
|
|
Bukkit.getScheduler().cancelTask(this.game.getCounterID());
|
|
SpleggOG.getPlugin().game.startGame(this.game);
|
|
|
|
} else {
|
|
|
|
SpleggOG.getPlugin().chat.bc(SpleggOG.getPlugin().getConfig().getString("Messages.NoEnoughPlayers"),
|
|
this.game);
|
|
Bukkit.getScheduler().cancelTask(this.game.getCounterID());
|
|
|
|
this.game.setStarting(false);
|
|
this.game.setLobbyCount(SpleggOG.getPlugin().getConfig().getInt("Options.Timer"));
|
|
this.game.resetVoting();
|
|
this.game.getSign().update(this.game.getMap(), false);
|
|
LobbyScoreboard.refreshGame(this.game);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|