Advertisement
Guest User

Untitled

a guest
Nov 19th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. package me.rw_craft.elitemctntwars;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5.  
  6. import me.rw_craft.elitemctntwars.ArenaManager.Team;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.DyeColor;
  11. import org.bukkit.Location;
  12. import org.bukkit.Material;
  13. import org.bukkit.configuration.ConfigurationSection;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.inventory.ItemStack;
  16. import org.bukkit.inventory.meta.ItemMeta;
  17. import org.bukkit.material.Wool;
  18. import org.bukkit.scoreboard.Objective;
  19. import org.bukkit.scoreboard.Score;
  20. import org.bukkit.scoreboard.Scoreboard;
  21.  
  22. public class Arena {
  23.  
  24. private int ID;
  25. private boolean started = false;
  26. private Location redspawn, bluespawn;
  27. private ArrayList<PlayerData> players = new ArrayList<PlayerData>();
  28.  
  29. private Scoreboard sb;
  30. private Objective o;
  31. private Score red, blue;
  32.  
  33. @SuppressWarnings("deprecation")
  34. public Arena (int ID) {
  35. this.ID = ID;
  36. ConfigurationSection conf = SettingsManager.getInstance().get(ID + "");
  37.  
  38. this.redspawn = getLocation(conf.getConfigurationSection("redspawn"));
  39. this.bluespawn = getLocation(conf.getConfigurationSection("bluespawn"));
  40.  
  41. sb = Bukkit.getServer().getScoreboardManager().getNewScoreboard();
  42. o = sb.registerNewObjective("Team Scores", "dummy");
  43. red = o.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.RED + "Red"));
  44. blue = o.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.BLUE + "Blue"));
  45. }
  46.  
  47. public boolean isStarted() {
  48. return started;
  49. }
  50.  
  51. public void setStarter(boolean started) {
  52. this.started = started;
  53. }
  54.  
  55. private Location getLocation(ConfigurationSection path) {
  56. return new Location(
  57. Bukkit.getServer().getWorld(path.getString("world")),
  58. path.getDouble("x"),
  59. path.getDouble("y"),
  60. path.getDouble("z")
  61. );
  62. }
  63.  
  64. public int getID() {
  65. return ID;
  66. }
  67.  
  68. public Location getSpawn(Team team) {
  69. switch(team) {
  70. case RED: return redspawn;
  71. case BLUE: return bluespawn;
  72. default: return null;
  73. }
  74. }
  75.  
  76. public Team getTeam(Player p) {
  77. return getData(p).getTeam();
  78. }
  79.  
  80. public void addPlayer(Player p) {
  81. players.add(new PlayerData(p.getName(), getTeamWithLessPlayers(), p.getInventory(), p.getLocation()));
  82. p.getInventory().clear();
  83. ItemStack chest = new ItemStack(Material.CHEST, 1);
  84. ItemMeta chestmeta = chest.getItemMeta();
  85. chestmeta.setDisplayName(ChatColor.GREEN+"Items");
  86. chestmeta.setLore(Arrays.asList(ChatColor.WHITE+"Click To Open The Items GUI"));
  87. chest.setItemMeta(chestmeta);
  88.  
  89. p.getInventory().setHelmet(new Wool(DyeColor.valueOf(getData(p).getTeam().toString())).toItemStack(1));
  90. p.getInventory().setItem(8, chest);
  91.  
  92. p.teleport(getSpawn(getData(p).getTeam()));
  93.  
  94. p.setScoreboard(sb);
  95.  
  96. if (players.size() >= 2) start();
  97. }
  98.  
  99. public void removePlayer(Player p) {
  100. PlayerData pd = getData(p);
  101. p.getInventory().clear();
  102. p.teleport(pd.getLocation());
  103. p.getInventory().setArmorContents(pd.getInventory().getArmorContents());
  104. p.getInventory().addItem(pd.getInventory().getContents());
  105. p.setScoreboard(null);
  106. players.remove(p);
  107. MessageManager.getInstance().info(p, "Unlucky! You Died.");
  108. msg(p.getName()+" Died.");
  109. }
  110.  
  111. public void start() {
  112. msg("Game Starting In 30 Seconds...");
  113. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SettingsManager.getInstance().getPlugin(), new Runnable() {
  114. public void run() {
  115. Arena.this.started = true;
  116. }
  117. }, 30 * 20);
  118. }
  119.  
  120. public void stop() {
  121. for (PlayerData pd: players) {
  122. Player p = Bukkit.getServer().getPlayer(pd.getPlayerName());
  123. p.getInventory().clear();
  124. p.teleport(pd.getLocation());
  125. p.getInventory().setArmorContents(pd.getInventory().getArmorContents());
  126. p.getInventory().addItem(pd.getInventory().getContents());
  127. }
  128. }
  129.  
  130. public void addDeath(Player p) {
  131. Team t = getTeam(p);
  132. if (t == Team.RED) blue.setScore(blue.getScore() + 1);
  133. else red.setScore(red.getScore() + 1);
  134. }
  135.  
  136. private void msg(String msg) {
  137. for (PlayerData pd : players) {
  138. Player p = Bukkit.getServer().getPlayer(pd.getPlayerName());
  139. MessageManager.getInstance().publicarena(p, msg);
  140. }
  141. }
  142.  
  143. private Team getTeamWithLessPlayers() {
  144. int red = 0, blue = 0;
  145. for (PlayerData pd : players) {
  146. if (pd.getTeam() == Team.RED) red++;
  147. else blue++;
  148. }
  149. if (red > blue) return Team.BLUE;
  150. else return Team.RED;
  151. }
  152.  
  153. public boolean containsPlayer(Player p) {
  154. return getData(p) != null;
  155. }
  156.  
  157. private PlayerData getData(Player p) {
  158. for (PlayerData pd : players) {
  159. if (pd.getPlayerName().equalsIgnoreCase(p.getName())) return pd;
  160. }
  161. return null;
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement