use of com.leomelonseeds.missilewars.teams.MissileWarsPlayer in project MissileWars by Leomelonseeds.
the class Arena method enqueueBlue.
/**
* Enqueue a player with a given UUID to the blue team.
*
* @param uuid the Player's UUID
*/
public void enqueueBlue(UUID uuid) {
for (MissileWarsPlayer player : players) {
if (player.getMCPlayerId().equals(uuid)) {
// Make sure people can't break the game
if (startTime != null) {
int time = (int) Duration.between(LocalDateTime.now(), startTime).toSeconds();
if (time <= 2 && time >= -2) {
ConfigUtils.sendConfigMessage("messages.queue-join-time", player.getMCPlayer(), this, null);
return;
}
}
if (!running) {
if (!blueQueue.contains(player)) {
redQueue.remove(player);
blueQueue.add(player);
ConfigUtils.sendConfigMessage("messages.queue-waiting-blue", player.getMCPlayer(), this, null);
removeSpectator(player);
}
} else {
if (!player.getMCPlayer().isOp() && blueTeam.getSize() - redTeam.getSize() >= 1) {
ConfigUtils.sendConfigMessage("messages.queue-join-error", player.getMCPlayer(), this, null);
} else if (!player.getMCPlayer().hasPermission("umw.joinfull") && blueTeam.getSize() >= getCapacity() / 2) {
ConfigUtils.sendConfigMessage("messages.queue-join-full", player.getMCPlayer(), this, null);
} else {
redTeam.removePlayer(player);
blueTeam.addPlayer(player);
blueTeam.giveItems(player);
player.giveDeckGear();
removeSpectator(player);
announceMessage("messages.queue-join-blue", player);
}
}
break;
}
}
}
use of com.leomelonseeds.missilewars.teams.MissileWarsPlayer 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.MissileWarsPlayer in project MissileWars by Leomelonseeds.
the class Arena method enqueueRed.
/**
* Enqueue a player with a given UUID to the red team.
*
* @param uuid the Player's UUID
*/
public void enqueueRed(UUID uuid) {
for (MissileWarsPlayer player : players) {
if (player.getMCPlayerId().equals(uuid)) {
// Make sure people can't break the game
if (startTime != null) {
int time = (int) Duration.between(LocalDateTime.now(), startTime).toSeconds();
if (time <= 2 && time >= -2) {
ConfigUtils.sendConfigMessage("messages.queue-join-time", player.getMCPlayer(), this, null);
return;
}
}
if (!running) {
if (!redQueue.contains(player)) {
blueQueue.remove(player);
redQueue.add(player);
ConfigUtils.sendConfigMessage("messages.queue-waiting-red", player.getMCPlayer(), this, null);
removeSpectator(player);
}
} else {
if (!player.getMCPlayer().isOp() && redTeam.getSize() - blueTeam.getSize() >= 1) {
ConfigUtils.sendConfigMessage("messages.queue-join-error", player.getMCPlayer(), this, null);
} else if (!player.getMCPlayer().hasPermission("umw.joinfull") && redTeam.getSize() >= getCapacity() / 2) {
ConfigUtils.sendConfigMessage("messages.queue-join-full", player.getMCPlayer(), this, null);
} else {
blueTeam.removePlayer(player);
redTeam.addPlayer(player);
redTeam.giveItems(player);
player.giveDeckGear();
removeSpectator(player);
announceMessage("messages.queue-join-red", player);
}
}
break;
}
}
}
use of com.leomelonseeds.missilewars.teams.MissileWarsPlayer in project MissileWars by Leomelonseeds.
the class Arena method joinPlayer.
/**
* Attempt to add a player to the Arena.
*
* @param player the player
* @return true if the player joined the Arena, otherwise false
*/
public boolean joinPlayer(Player player) {
// Ensure world isn't resetting
if (resetting) {
return false;
}
player.teleport(getPlayerSpawn(player));
// Make sure another plugin hasn't cancelled the event
if (player.getWorld().getName().equals("world")) {
return false;
}
InventoryUtils.saveInventory(player, true);
InventoryUtils.clearInventory(player);
ConfigUtils.sendConfigMessage("messages.join-arena", player, this, null);
for (MissileWarsPlayer mwPlayer : players) {
ConfigUtils.sendConfigMessage("messages.joined-arena-others", mwPlayer.getMCPlayer(), null, player);
}
ConfigUtils.sendConfigMessage("messages.joined-arena", player, this, null);
TextChannel discordChannel = DiscordSRV.getPlugin().getMainTextChannel();
discordChannel.sendMessage(":arrow_backward: " + player.getName() + " left and joined arena " + this.getName()).queue();
player.setHealth(20);
player.setFoodLevel(20);
players.add(new MissileWarsPlayer(player.getUniqueId()));
player.setBedSpawnLocation(getPlayerSpawn(player), true);
player.setGameMode(GameMode.ADVENTURE);
for (Player worldPlayer : Bukkit.getWorld("world").getPlayers()) {
ConfigUtils.sendConfigMessage("messages.joined-arena-lobby", worldPlayer, this, player);
}
// Check for game start
int minPlayers = MissileWarsPlugin.getPlugin().getConfig().getInt("minimum-players");
if (getNumPlayers() >= minPlayers) {
scheduleStart();
}
return true;
}
use of com.leomelonseeds.missilewars.teams.MissileWarsPlayer in project MissileWars by Leomelonseeds.
the class Arena method addSpectator.
/**
* Add the player with a given UUID to the spectators.
*
* @param uuid the UUID of the player
*/
public void addSpectator(UUID uuid) {
for (MissileWarsPlayer player : players) {
if (player.getMCPlayerId().equals(uuid)) {
if (running && !blueTeam.containsPlayer(uuid) && !redTeam.containsPlayer(uuid)) {
announceMessage("messages.spectate-join-others", player);
spectators.add(player);
redQueue.remove(player);
blueQueue.remove(player);
Player mcPlayer = player.getMCPlayer();
mcPlayer.setGameMode(GameMode.SPECTATOR);
mcPlayer.sendActionBar("Type /spectate to stop spectating");
} else {
player.getMCPlayer().sendMessage(ConfigUtils.getConfigText("messages.spectate-join-fail", player.getMCPlayer(), null, null));
}
break;
}
}
}
Aggregations