Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.projectinferno.games.api;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.entity.Player;
- import net.projectinferno.games.Main;
- import net.projectinferno.games.other.ConfigAccessor;
- public class TeamAPI {
- MapAPI mAPI = null;
- GameAPI gAPI = null;
- ConfigAccessor customConfig = null;
- private Main plugin;
- public TeamAPI(Main plugin) {
- this.plugin = plugin;
- mAPI = new MapAPI(plugin);
- gAPI = new GameAPI(plugin);
- customConfig = new ConfigAccessor(plugin);
- }
- public boolean joinBlue(Player player) {
- String name = player.getName();
- int blue = customConfig.getConfig("match").getInt("Teams.blue");
- int newBlue = blue + 1;
- customConfig.getConfig("match").set("Teams.blue", newBlue);
- customConfig.getConfig("players").set(name + ".team", "blue");
- if (gAPI.hasStarted() == true) {
- mAPI.spawnPlayer(player, "blue");
- }
- customConfig.getConfig("players").set(name + "inGame", true);
- customConfig.saveConfig("players");
- customConfig.saveConfig("match");
- player.sendMessage(ChatColor.GRAY + "You have joined the " + ChatColor.DARK_AQUA + "Blue Team");
- player.teleport(player.getLocation());
- return false;
- }
- public boolean joinRed(Player player) {
- String name = player.getName();
- int red = customConfig.getConfig("match").getInt("Teams.red");
- int newRed = red + 1;
- customConfig.getConfig("match").set("Teams.red", newRed);
- customConfig.getConfig("players").set(name + ".team", "red");
- if (gAPI.hasStarted() == true) {
- mAPI.spawnPlayer(player, "red");
- }
- customConfig.getConfig("players").set(name + "inGame", true);
- customConfig.saveConfig("players");
- customConfig.saveConfig("match");
- player.sendMessage(ChatColor.GRAY + "You have joined the " + ChatColor.DARK_RED + "Red Team");
- player.teleport(player.getLocation());
- return false;
- }
- public boolean startSpectating(Player player) {
- String name = player.getName();
- customConfig.getConfig("players").set(name + ".team", "spec");
- customConfig.getConfig("players").set(name + "inGame", false);
- customConfig.saveConfig("players");
- player.sendMessage(ChatColor.GRAY + "You are currently " + ChatColor.AQUA + "Spectating");
- player.teleport(player.getLocation());
- return true;
- }
- public boolean leaveTeam(Player player) {
- String name = player.getName();
- String team = customConfig.getConfig("players").getString(name + ".team");
- if (team != "spec") {
- int teamSize = customConfig.getConfig("match").getInt("Teams." + team);
- int newTeamSize = teamSize - 1;
- customConfig.getConfig("match").set("Teams." + team, newTeamSize);
- this.startSpectating(player);
- customConfig.saveConfig("players");
- customConfig.saveConfig("match");
- }
- return false;
- }
- public Location playerTeamSpawn(Player player) {
- String name = player.getName();
- Location l = null;
- String team = plugin.getConfig().getString("Users." + name + ".team");
- l = mAPI.getTeamSpawn(team);
- return l;
- }
- public String getTeam(Player player) {
- String name = player.getName();
- String team = plugin.getConfig().getString("Users." + name + ".team");
- return team;
- }
- public boolean reloadTeams() {
- Player[] players = Bukkit.getOnlinePlayers();
- for (Player player : players) {
- this.leaveTeam(player);
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement