Advertisement
Guest User

Team API Class

a guest
Dec 3rd, 2012
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. package net.projectinferno.games.api;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.entity.Player;
  7.  
  8. import net.projectinferno.games.Main;
  9. import net.projectinferno.games.other.ConfigAccessor;
  10.  
  11. public class TeamAPI {
  12.    
  13.     MapAPI mAPI = null;
  14.     GameAPI gAPI = null;
  15.     ConfigAccessor customConfig = null;
  16.     private Main plugin;
  17.  
  18.     public TeamAPI(Main plugin) {
  19.         this.plugin = plugin;
  20.         mAPI = new MapAPI(plugin);
  21.         gAPI = new GameAPI(plugin);
  22.         customConfig = new ConfigAccessor(plugin);
  23.     }
  24.    
  25.     public boolean joinBlue(Player player) {
  26.         String name = player.getName();
  27.         int blue = customConfig.getConfig("match").getInt("Teams.blue");
  28.         int newBlue = blue + 1;
  29.         customConfig.getConfig("match").set("Teams.blue", newBlue);
  30.         customConfig.getConfig("players").set(name + ".team", "blue");
  31.        
  32.         if (gAPI.hasStarted() == true) {
  33.             mAPI.spawnPlayer(player, "blue");
  34.         }
  35.  
  36.         customConfig.getConfig("players").set(name + "inGame", true);
  37.         customConfig.saveConfig("players");
  38.         customConfig.saveConfig("match");
  39.        
  40.         player.sendMessage(ChatColor.GRAY + "You have joined the " + ChatColor.DARK_AQUA + "Blue Team");
  41.        
  42.         player.teleport(player.getLocation());
  43.         return false;
  44.     }
  45.    
  46.     public boolean joinRed(Player player) {
  47.         String name = player.getName();
  48.         int red = customConfig.getConfig("match").getInt("Teams.red");
  49.         int newRed = red + 1;
  50.         customConfig.getConfig("match").set("Teams.red", newRed);
  51.         customConfig.getConfig("players").set(name + ".team", "red");
  52.        
  53.         if (gAPI.hasStarted() == true) {
  54.             mAPI.spawnPlayer(player, "red");
  55.         }
  56.  
  57.         customConfig.getConfig("players").set(name + "inGame", true);
  58.         customConfig.saveConfig("players");
  59.         customConfig.saveConfig("match");
  60.        
  61.         player.sendMessage(ChatColor.GRAY + "You have joined the " + ChatColor.DARK_RED + "Red Team");
  62.        
  63.         player.teleport(player.getLocation());
  64.         return false;
  65.     }
  66.    
  67.     public boolean startSpectating(Player player) {
  68.         String name = player.getName();
  69.        
  70.  
  71.         customConfig.getConfig("players").set(name + ".team", "spec");
  72.         customConfig.getConfig("players").set(name + "inGame", false);
  73.         customConfig.saveConfig("players");
  74.  
  75.         player.sendMessage(ChatColor.GRAY + "You are currently " + ChatColor.AQUA + "Spectating");
  76.        
  77.         player.teleport(player.getLocation());
  78.         return true;
  79.     }
  80.    
  81.     public boolean leaveTeam(Player player) {
  82.         String name = player.getName();
  83.         String team = customConfig.getConfig("players").getString(name + ".team");
  84.        
  85.         if (team != "spec") {
  86.             int teamSize = customConfig.getConfig("match").getInt("Teams." + team);
  87.             int newTeamSize = teamSize - 1;
  88.             customConfig.getConfig("match").set("Teams." + team, newTeamSize);
  89.             this.startSpectating(player);
  90.             customConfig.saveConfig("players");
  91.             customConfig.saveConfig("match");
  92.         }
  93.        
  94.         return false;
  95.     }
  96.    
  97.     public Location playerTeamSpawn(Player player) {
  98.         String name = player.getName();
  99.         Location l = null;
  100.         String team = plugin.getConfig().getString("Users." + name + ".team");
  101.         l = mAPI.getTeamSpawn(team);
  102.         return l;
  103.     }
  104.    
  105.     public String getTeam(Player player) {
  106.         String name = player.getName();
  107.         String team = plugin.getConfig().getString("Users." + name + ".team");
  108.         return team;
  109.     }
  110.    
  111.     public boolean reloadTeams() {
  112.         Player[] players = Bukkit.getOnlinePlayers();
  113.         for (Player player : players) {
  114.             this.leaveTeam(player);
  115.         }
  116.         return true;
  117.     }
  118.    
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement