use of com.leomelonseeds.missilewars.teams.MissileWarsTeam in project MissileWars by Leomelonseeds.
the class Arena method start.
/**
* Starts a game in the arena with the classic arena. Different gamemodes and maps coming soon.
*
* @return true if the game started. Otherwise false
*/
public boolean start() {
if (running) {
return false;
}
MissileWarsPlugin plugin = MissileWarsPlugin.getPlugin();
// Select Map
mapName = "default-map";
List<String> mapsWithTopVotes = new LinkedList<>();
for (String map : mapVotes.keySet()) {
if (mapsWithTopVotes.isEmpty()) {
mapsWithTopVotes.add(map);
} else {
String previousTop = mapsWithTopVotes.get(0);
if (mapVotes.get(previousTop) == mapVotes.get(map)) {
mapsWithTopVotes.add(map);
} else if (mapVotes.get(previousTop) < mapVotes.get(map)) {
mapsWithTopVotes.clear();
mapsWithTopVotes.add(map);
}
}
}
if (!mapsWithTopVotes.isEmpty()) {
// Set map to random map with top votes
mapName = mapsWithTopVotes.get(new Random().nextInt(mapsWithTopVotes.size()));
}
// Generate map.
if (!generateMap(mapName)) {
announceMessage("messages.map-failed", null);
return false;
} else {
announceMessage("messages.starting", null);
}
// Acquire red and blue spawns
FileConfiguration mapConfig = ConfigUtils.getConfigFile(plugin.getDataFolder().toString(), "maps.yml");
Vector blueSpawnVec = SchematicManager.getVector(mapConfig, "blue-spawn", mapType, mapName);
Location blueSpawn = new Location(getWorld(), blueSpawnVec.getX(), blueSpawnVec.getY(), blueSpawnVec.getZ());
Vector redSpawnVec = SchematicManager.getVector(mapConfig, "red-spawn", mapType, mapName);
Location redSpawn = new Location(getWorld(), redSpawnVec.getX(), redSpawnVec.getY(), redSpawnVec.getZ());
redSpawn.setYaw(180);
blueSpawn.setWorld(getWorld());
redSpawn.setWorld(getWorld());
// Setup scoreboard and teams
blueTeam = new MissileWarsTeam(ChatColor.BLUE + "" + ChatColor.BOLD + "Blue", this, blueSpawn);
redTeam = new MissileWarsTeam(ChatColor.RED + "" + ChatColor.BOLD + "Red", this, redSpawn);
// Assign players to teams based on queue (which removes their items)
Set<MissileWarsPlayer> toAssign = new HashSet<>(players);
double maxSize = getCapacity() / 2;
double maxQueue = Math.ceil((double) players.size() / 2);
// Teleport all players to center to remove lobby minigame items/dismount
tasks.add(new BukkitRunnable() {
@Override
public void run() {
for (MissileWarsPlayer player : players) {
player.getMCPlayer().teleport(getPlayerSpawn(player.getMCPlayer()));
}
}
}.runTaskLater(plugin, 15));
// Teleport teams slightly later to wait for map generation
tasks.add(new BukkitRunnable() {
@Override
public void run() {
// Assign queued players
while (!blueQueue.isEmpty() || !redQueue.isEmpty()) {
if (!redQueue.isEmpty()) {
MissileWarsPlayer toAdd = redQueue.remove();
if (redTeam.getSize() < maxQueue) {
redTeam.addPlayer(toAdd);
toAssign.remove(toAdd);
}
}
if (!blueQueue.isEmpty()) {
MissileWarsPlayer toAdd = blueQueue.remove();
if (blueTeam.getSize() < maxQueue) {
blueTeam.addPlayer(toAdd);
toAssign.remove(toAdd);
}
}
}
// Assign remaining players
for (MissileWarsPlayer player : toAssign) {
// Ignore if player is a spectator
if (spectators.contains(player)) {
continue;
}
if (blueTeam.getSize() <= redTeam.getSize()) {
if (blueTeam.getSize() >= maxSize) {
ConfigUtils.sendConfigMessage("messages.queue-join-full", player.getMCPlayer(), null, null);
} else {
blueTeam.addPlayer(player);
}
} else {
if (redTeam.getSize() >= maxSize) {
ConfigUtils.sendConfigMessage("messages.queue-join-full", player.getMCPlayer(), null, null);
} else {
redTeam.addPlayer(player);
}
}
}
// Start deck distribution for each team and send messages
redTeam.scheduleDeckItems();
redTeam.distributeGear();
redTeam.sendTitle("classic-start");
redTeam.sendSound("game-start");
blueTeam.scheduleDeckItems();
blueTeam.distributeGear();
blueTeam.sendTitle("classic-start");
blueTeam.sendSound("game-start");
}
}.runTaskLater(plugin, 20));
// Setup game timers
// Game start
startTime = LocalDateTime.now();
long gameLength = getSecondsRemaining();
tasks.add(new BukkitRunnable() {
@Override
public void run() {
if (!(blueTeam.getFirstPortalStatus() || blueTeam.getSecondPortalStatus()) && (redTeam.getFirstPortalStatus() || redTeam.getSecondPortalStatus())) {
endGame(blueTeam);
} else if ((blueTeam.getFirstPortalStatus() || blueTeam.getSecondPortalStatus()) && !(redTeam.getFirstPortalStatus() || redTeam.getSecondPortalStatus())) {
endGame(redTeam);
} else {
endGame(null);
}
}
}.runTaskLater(plugin, gameLength * 20));
// Chaos time start
int chaosStart = getChaosTime();
tasks.add(new BukkitRunnable() {
@Override
public void run() {
blueTeam.setChaosMode(true);
redTeam.setChaosMode(true);
redTeam.broadcastConfigMsg("messages.chaos-mode", null);
blueTeam.broadcastConfigMsg("messages.chaos-mode", null);
}
}.runTaskLater(plugin, (gameLength - chaosStart) * 20));
// Game is 1800 seconds long.
int[] reminderTimes = { 600, 1500, 1740, 1770, 1790, 1795, 1796, 1797, 1798, 1799 };
for (int i : reminderTimes) {
tasks.add(new BukkitRunnable() {
@Override
public void run() {
announceMessage("messages.game-end-reminder", null);
}
}.runTaskLater(plugin, i * 20));
}
// Despawn leaves after a while
leaves = new HashMap<>();
tasks.add(new BukkitRunnable() {
@Override
public void run() {
Map<Location, Integer> temp = new HashMap<>(leaves);
for (Entry<Location, Integer> e : temp.entrySet()) {
int i = e.getValue();
Location loc = e.getKey();
if (i <= 0) {
if (loc.getBlock().getType().toString().contains("LEAVES")) {
loc.getBlock().setType(Material.AIR);
}
leaves.remove(loc);
} else {
leaves.put(loc, i - 5);
}
}
}
}.runTaskTimer(plugin, 100, 100));
running = true;
return true;
}
use of com.leomelonseeds.missilewars.teams.MissileWarsTeam in project MissileWars by Leomelonseeds.
the class MissileWarsPlaceholder method onRequest.
@Override
public String onRequest(OfflinePlayer player, String params) {
// Stop trying to fetch placeholders if the plugin is disabled
if (!MissileWarsPlugin.getPlugin().isEnabled()) {
return null;
}
ArenaManager manager = MissileWarsPlugin.getPlugin().getArenaManager();
Arena playerArena = manager.getArena(player.getUniqueId());
DecimalFormat df = new DecimalFormat("##.##");
// General purpose placeholders
if (params.equalsIgnoreCase("focus")) {
return ConfigUtils.getFocusName(player);
}
if (params.equalsIgnoreCase("team")) {
return playerArena == null ? "no team" : ChatColor.stripColor(playerArena.getTeam(player.getUniqueId()));
}
if (params.equalsIgnoreCase("deck")) {
JSONObject json = MissileWarsPlugin.getPlugin().getJSON().getPlayer(player.getUniqueId());
String deck = json.getString("Deck");
ChatColor chatcolor = ChatColor.WHITE;
switch(deck) {
case "Vanguard":
chatcolor = ChatColor.GOLD;
break;
case "Sentinel":
chatcolor = ChatColor.AQUA;
break;
case "Berserker":
chatcolor = ChatColor.RED;
}
return chatcolor + json.getString("Deck");
}
// Rank placeholders
if (params.contains("rank_")) {
int exp = MissileWarsPlugin.getPlugin().getSQL().getExpSync(player.getUniqueId());
int level = RankUtils.getRankLevel(exp);
int max = 10;
if (params.equalsIgnoreCase("rank_exp_total")) {
return Integer.toString(exp);
}
if (params.equalsIgnoreCase("rank_name")) {
return RankUtils.getRankName(exp);
}
if (params.equalsIgnoreCase("rank_symbol")) {
return RankUtils.getRankSymbol(exp);
}
if (params.equalsIgnoreCase("rank_exp")) {
if (level >= max) {
return "0";
}
return Integer.toString(RankUtils.getCurrentExp(exp));
}
if (params.equalsIgnoreCase("rank_exp_next")) {
if (level >= max) {
return "N/A";
}
return Integer.toString(RankUtils.getNextExp(exp));
}
if (params.equalsIgnoreCase("rank_progress_percentage")) {
if (level >= max) {
return "0%";
}
return df.format(RankUtils.getExpProgress(exp) * 100) + "%";
}
if (params.contains("rank_progress_bar")) {
String[] args = params.split("_");
int size = Integer.parseInt(args[3]);
if (level >= max) {
String result = "";
for (int i = 0; i < size; i++) {
result = result + "|";
}
return ChatColor.GRAY + result;
}
return RankUtils.getProgressBar(exp, size);
}
return null;
}
// Stats placeholders. Includes top 10 placeholders, which includes top 10 exp values.
if (params.contains("stats")) {
SQLManager sql = MissileWarsPlugin.getPlugin().getSQL();
String[] args = params.split("_");
String gamemode = args[1];
String stat = args[2];
// stats_[gamemode/overall]_[stat]
if (args.length == 3) {
return Integer.toString(sql.getStatSync(player.getUniqueId(), stat, gamemode));
}
// # can be 1-10, nothing more or error
if (args[3].equals("top")) {
List<ArrayList<Object>> list = sql.getTopTenStat(stat, gamemode);
int index = Integer.parseInt(args[4]) - 1;
String playerName = RankUtils.getLeaderboardPlayer((OfflinePlayer) list.get(index).get(0));
String playerStat = Integer.toString((int) list.get(index).get(1));
return ChatColor.translateAlternateColorCodes('&', playerName + " &7- &f" + playerStat);
}
// Gets the player position in for that stat
if (args[3].equals("rank")) {
return Integer.toString(sql.getStatRank(player.getUniqueId(), stat, gamemode));
}
return null;
}
if (playerArena == null) {
return null;
}
if (params.equalsIgnoreCase("arena")) {
return playerArena.getName();
}
if (params.equalsIgnoreCase("gamemode")) {
return ChatColor.GREEN + "Classic";
}
boolean inGame = playerArena.isRunning() || playerArena.isResetting();
if (params.equalsIgnoreCase("ingame")) {
return inGame ? "true" : "false";
}
if (params.equalsIgnoreCase("red_queue")) {
return Integer.toString(playerArena.getRedQueue());
}
if (params.equalsIgnoreCase("blue_queue")) {
return Integer.toString(playerArena.getBlueQueue());
}
if (!inGame) {
return null;
}
// In-Game placeholders
MissileWarsTeam redTeam = playerArena.getRedTeam();
MissileWarsTeam blueTeam = playerArena.getBlueTeam();
if (params.equalsIgnoreCase("map")) {
return ConfigUtils.getMapText(playerArena.getMapType(), playerArena.getMapName(), "name");
}
if (params.equalsIgnoreCase("time_remaining")) {
return playerArena.getTimeRemaining();
}
if (params.equalsIgnoreCase("red_shield_health")) {
double health = Math.max(0, redTeam.getShieldHealth());
ChatColor chatcolor;
if (health >= 90) {
chatcolor = ChatColor.DARK_GREEN;
} else if (health >= 80) {
chatcolor = ChatColor.GREEN;
} else if (health >= 70) {
chatcolor = ChatColor.YELLOW;
} else if (health >= 60) {
chatcolor = ChatColor.GOLD;
} else if (health >= 50) {
chatcolor = ChatColor.RED;
} else {
chatcolor = ChatColor.DARK_RED;
}
return chatcolor + df.format(health) + "%";
}
if (params.equalsIgnoreCase("blue_shield_health")) {
double health = Math.max(0, blueTeam.getShieldHealth());
ChatColor chatcolor;
if (health >= 90) {
chatcolor = ChatColor.DARK_GREEN;
} else if (health >= 80) {
chatcolor = ChatColor.GREEN;
} else if (health >= 70) {
chatcolor = ChatColor.YELLOW;
} else if (health >= 60) {
chatcolor = ChatColor.GOLD;
} else if (health >= 50) {
chatcolor = ChatColor.RED;
} else {
chatcolor = ChatColor.DARK_RED;
}
return chatcolor + df.format(health) + "%";
}
if (params.equalsIgnoreCase("red_team")) {
return Integer.toString(redTeam.getSize());
}
if (params.equalsIgnoreCase("blue_team")) {
return Integer.toString(blueTeam.getSize());
}
if (params.equalsIgnoreCase("red_portals")) {
String firstPortal = redTeam.getFirstPortalStatus() ? ChatColor.WHITE + "⬛" : ChatColor.DARK_PURPLE + "⬛";
String secondPortal = redTeam.getSecondPortalStatus() ? ChatColor.WHITE + "⬛" : ChatColor.DARK_PURPLE + "⬛";
if (playerArena.getTeam(player.getUniqueId()).equalsIgnoreCase(ChatColor.RED + "red" + ChatColor.RESET)) {
return firstPortal + secondPortal;
}
return secondPortal + firstPortal;
}
if (params.equalsIgnoreCase("blue_portals")) {
String firstPortal = blueTeam.getFirstPortalStatus() ? ChatColor.WHITE + "⬛" : ChatColor.DARK_PURPLE + "⬛";
String secondPortal = blueTeam.getSecondPortalStatus() ? ChatColor.WHITE + "⬛" : ChatColor.DARK_PURPLE + "⬛";
if (playerArena.getTeam(player.getUniqueId()).equalsIgnoreCase(ChatColor.BLUE + "blue" + ChatColor.RESET)) {
return secondPortal + firstPortal;
}
return firstPortal + secondPortal;
}
// Placeholder is unknown by the Expansion
return null;
}
Aggregations