summaryrefslogtreecommitdiff
path: root/src/main/java/com/encrox/zombie/Lobby.java
blob: c33c3c36295c735de096423b7d1d16ff2291b78f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.encrox.zombie;

import java.util.ArrayList;

import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

public class Lobby {
	
	private ArrayList<Player> players;
	private Player creator;
	private String identifier;
	private Map map;
	
	public Lobby(Player creator, String identifier, Map map) {
		this.creator = creator;
		this.identifier = identifier;
		this.map = map;
		players = new ArrayList<Player>();
		players.add(creator);
	}
	
	public String getIdentifier() {
		return identifier;
	}
	
	public Player getCreator() {
		return creator;
	}
	
	public boolean containsPlayer(Player player) {
		if(creator.equals(player)) return true;
		return players.contains(player);
	}
	
	public void removePlayer(Player player) {
		if(creator.equals(player)) {
			for(int i = 0, size = players.size(); i<size; i++) {
				players.get(i).sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("lobby_disbanded"));
			}
			Zombie.lobbies.remove(this);
			return;
		}
		if(players.contains(player)) {
			for(int i = 0, size = players.size(); i<size; i++) {
				players.get(i).sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("lobby_left").replace("%player%", player.getName()));
			}
			players.remove(player);
		}
	}
	
	public void addPlayer(Player player) {
		players.add(player);
		for(int i = 0, size = players.size(); i<size; i++) {
			players.get(i).sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("lobby_joined").replace("%player%", player.getName()));
		}
	}
	
	public int getMax() {
		return map.getPlayers();
	}
	
	public int getCurrent() {
		return players.size();
	}
	
	public void start() {
		Zombie.games.add(new Game(players, map));
		Zombie.lobbies.remove(this);
	}
	
}