Advertisement
Guest User

Arena

a guest
Dec 8th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. package me.whatapigdoes.craftsg;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6.  
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Location;
  9. import org.bukkit.entity.Player;
  10.  
  11. public class Arena {
  12.  
  13. public HashMap<Location, Boolean> spawns = new HashMap<Location, Boolean>();
  14. public Location lobby = null;
  15. public List<PlayerData> players = new ArrayList<PlayerData>();
  16. public String name = "Unknown";
  17. public State state = State.UNKNOWN;
  18. public boolean enabled = false;
  19.  
  20. public Arena(String name, Location lobby, boolean enabled) {
  21. this.name = name;
  22. this.lobby = lobby;
  23. this.enabled = enabled;
  24. if (enabled == false){
  25. state = State.DISABLED;
  26. }else{
  27. state = State.WAITING;
  28. }
  29. }
  30.  
  31. public String addPlayer(Player p) {
  32. if (state != State.WAITING || enabled == false) {
  33. return ChatColor.RED + " This arena is not joinable";
  34. } else {
  35. if ((spawns.size() + 1) > spawns.size()) {
  36. players.add(new PlayerData(p, this));
  37. p.teleport(lobby);
  38. return ChatColor.GREEN + " Successfully joined arena";
  39. } else {
  40. return ChatColor.RED + "This arena is full!";
  41. }
  42. }
  43. }
  44.  
  45. public void removePlayer(Player p) {
  46. for (PlayerData pd : players) {
  47. if (pd.getPlayer().equals(p)) {
  48. pd.reset();
  49. players.remove(pd);
  50. }
  51. }
  52. }
  53.  
  54. public void disable() {
  55. for (PlayerData pd : players) {
  56. pd.getPlayer().sendMessage(
  57. ChatColor.GRAY + "[TurtleSG]" + ChatColor.RED
  58. + " This arena has been disabled!");
  59. pd.reset();
  60. players.remove(pd);
  61. }
  62. state = State.DISABLED;
  63. enabled = false;
  64. ArenaManager.getManager().plugin.getLogger().info(
  65. "Disabled arena " + name);
  66. }
  67.  
  68. public void enable() {
  69. state = State.WAITING;
  70. enabled = true;
  71. ArenaManager.getManager().plugin.getLogger().info(
  72. "Enabled arena" + name);
  73. }
  74.  
  75. public void addSpawn(Location spawn) {
  76. spawns.put(spawn, false);
  77.  
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement