Advertisement
Guest User

Untitled

a guest
Nov 15th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.52 KB | None | 0 0
  1. package me.COOKIE_EATER_13.COMFFA;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.World;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.inventory.ItemStack;
  11.  
  12. /**
  13. *
  14. * @Author Jake
  15. */
  16. public class ArenaManager {
  17.  
  18. private static ArenaManager am = new ArenaManager();
  19.  
  20. //Usefull for getting the ArenaManager, like so: ArenaManager.getManager()
  21. public static ArenaManager getManager() {
  22. return am;
  23. }
  24.  
  25.  
  26. //A method for getting one of the Arenas out of the list by name:
  27. public Arena getArena(String name) {
  28. for (Arena a: Arena.arenaObjects) { //For all of the arenas in the list of objects
  29. if (a.getName().equals(name)) { //If the name of an arena object in the list is equal to the one in the parameter...
  30. return a; //Return that object
  31. }
  32. }
  33. return null; //No objects were found, return null
  34. }
  35.  
  36.  
  37. //A method for adding players
  38. public void addPlayers(Player player, String arenaName) {
  39.  
  40. if (getArena(arenaName) != null) { //If the arena exsists
  41.  
  42. Arena arena = getArena(arenaName); //Create an arena for using in this method
  43.  
  44. if (!arena.isFull()) { //If the arena is not full
  45.  
  46. if (!arena.isInGame()) {
  47.  
  48. //Every check is complete, arena is joinable
  49. player.getInventory().clear(); //Clear the players inventory
  50. player.setHealth(20); //Heal the player
  51. player.setFireTicks(0); //Heal the player even more ^ ^ ^
  52.  
  53. //Teleport to the arena's join location
  54. player.teleport(arena.getJoinLocation());
  55.  
  56. //Add the player to the arena list
  57. arena.getPlayers().add(player.getName()); //Add the players name to the arena
  58.  
  59. int playersLeft = arena.getMaxPlayers() - arena.getPlayers().size(); //How many players needed to start
  60. //Send the arena's players a message
  61. arena.sendMessage(ChatColor.BLUE + player.getName() + " has joined the arena! We only need " + playersLeft + " to start the game!");
  62.  
  63.  
  64. if (playersLeft == 0) { //IF there are 0 players needed to start the game
  65. startArena(arenaName); //Start the arena, see the method way below :)
  66. }
  67.  
  68.  
  69. } else { //Specifiend arena is in game, send the player an error message
  70. player.sendMessage(ChatColor.RED + "The arena you are looking for is currently full!");
  71.  
  72. }
  73. } else { //Specified arena is full, send the player an error message
  74. player.sendMessage(ChatColor.RED + "The arena you are looking for is currently full!");
  75. }
  76.  
  77. } else { //The arena doesn't exsist, send the player an error message
  78. player.sendMessage(ChatColor.RED + "The arena you are looking for could not be found!");
  79. }
  80.  
  81. }
  82.  
  83.  
  84. //A method for removing players
  85. public void removePlayer(Player player, String arenaName) {
  86.  
  87. if (getArena(arenaName) != null) { //If the arena exsists
  88.  
  89. Arena arena = getArena(arenaName); //Create an arena for using in this method
  90.  
  91. if (arena.getPlayers().contains(player.getName())) { //If the arena has the player already
  92.  
  93. //Every check is complete, arena is leavable
  94. player.getInventory().clear(); //Clear the players inventory
  95. player.setHealth(20); //Heal the player
  96. player.setFireTicks(0); //Heal the player even more ^ ^ ^
  97.  
  98. //Teleport to the arena's join location
  99. player.teleport(arena.getEndLocation());
  100.  
  101. //remove the player to the arena list
  102. arena.getPlayers().remove(player.getName()); //Removes the players name to the arena
  103.  
  104. //Send the arena's players a message
  105. arena.sendMessage(ChatColor.BLUE + player.getName() + " has left the Arena! There are " + arena.getPlayers().size() + " players currently left!");
  106.  
  107.  
  108.  
  109.  
  110. } else { //Specified arena doesn't have the player, send the player an error message
  111. player.sendMessage(ChatColor.RED + "Your not in the arena your looking for!");
  112.  
  113. }
  114.  
  115.  
  116. } else { //The arena doesn't exsist, send the player an error message
  117. player.sendMessage(ChatColor.RED + "The arena you are looking for could not be found!");
  118. }
  119. }
  120.  
  121.  
  122. //A method for starting an Arena:
  123. public void startArena(String arenaName) {
  124.  
  125. if (getArena(arenaName) != null) { //If the arena exsists
  126.  
  127. Arena arena = getArena(arenaName); //Create an arena for using in this method
  128.  
  129. arena.sendMessage(ChatColor.GOLD + "The arena has BEGUN!");
  130.  
  131. //Set ingame
  132. arena.setInGame(true);
  133.  
  134. for (String s: arena.getPlayers()) {//Loop through every player in the arena
  135.  
  136. Bukkit.getPlayer(s).teleport(arena.getStartLocation()); //Teleports the player to the arena start location
  137. Player p = Bukkit.getPlayer(s);
  138. //Do custom stuff here, like give weapons etc, but for the purpose of this tutorial, i'll do nothing
  139. //Set inGa
  140.  
  141. }
  142.  
  143.  
  144. }
  145.  
  146. }
  147.  
  148.  
  149. //A method for ending an Arena:
  150. public void endArena(String arenaName) {
  151.  
  152. if (getArena(arenaName) != null) { //If the arena exsists
  153.  
  154. Arena arena = getArena(arenaName); //Create an arena for using in this method
  155.  
  156. //Send them a message
  157. arena.sendMessage(ChatColor.GOLD + "The arena has ended :(");
  158.  
  159. //Set ingame
  160. arena.setInGame(false);
  161.  
  162. for (String s: arena.getPlayers()) {//Loop through every player in the arena
  163.  
  164. //Teleport them:
  165.  
  166. Player player = Bukkit.getPlayer(s); //Create a player by the name
  167. player.teleport(arena.getEndLocation());
  168.  
  169. player.getInventory().clear(); //Clear the players inventory
  170. player.setHealth(20); //Heal the player
  171. player.setFireTicks(0); //Heal the player even more ^ ^ ^
  172.  
  173. //Remove them all from the list
  174. arena.getPlayers().remove(player.getName());
  175.  
  176. }
  177.  
  178.  
  179. }
  180. }
  181.  
  182.  
  183. //And our final method, loading each arena
  184. //This will be resonsible for creating each arena from the config, and creating an object to represent it
  185. //Call this method in your main class, onEnable
  186.  
  187.  
  188. public void loadArenas() {
  189.  
  190. //I just create a quick Config Variable, obviously don't do this.
  191. //Use your own config file
  192. FileConfiguration fc = Bukkit.getPluginManager().getPlugin("COMFFA").getConfig(); //If you just use this code, it will erorr, its null. Read the notes above, USE YOUR OWN CONFIGURATION FILE
  193.  
  194. //Youll get an error here, FOR THE LOVE OF GAWD READ THE NOTES ABOVE!!!
  195. for (String keys: fc.getConfigurationSection("arenas").getKeys(false)) { //For each arena name in the arena file
  196.  
  197. //Now lets get all of the values, and make an Arena object for each:
  198. //Just to help me remember: Arena myArena = new Arena("My Arena", joinLocation, startLocation, endLocation, 17)
  199.  
  200. World world = Bukkit.getWorld("arenas." + keys + ".world");
  201.  
  202. //Arena's name is keys
  203.  
  204. double joinX = fc.getDouble("arenas." + "keys." + "joinX");
  205. double joinY = fc.getDouble("arenas." + "keys." + "joinY");
  206. double joinZ = fc.getDouble("arenas." + "keys." + "joinZ");
  207. Location joinLocation = new Location(world, joinX, joinY, joinZ);
  208.  
  209. double startX = fc.getDouble("arenas." + "keys." + "startX");
  210. double startY = fc.getDouble("arenas." + "keys." + "startY");
  211. double startZ = fc.getDouble("arenas." + "keys." + "startZ");
  212.  
  213. Location startLocation = new Location(world, startX, startY, startZ);
  214.  
  215. double endX = fc.getDouble("arenas." + "keys." + "endX");
  216. double endY = fc.getDouble("arenas." + "keys." + "endX");
  217. double endZ = fc.getDouble("arenas." + "keys." + "endX");
  218.  
  219. Location endLocation = new Location(world, endX, endY, endZ);
  220.  
  221. int maxPlayers = fc.getInt("arenas." + keys + ".maxPlayers");
  222.  
  223. //Now lets create an object to represent it:
  224. Arena arena = new Arena(keys, joinLocation, startLocation, endLocation, 17);
  225.  
  226. }
  227.  
  228.  
  229. }
  230.  
  231. //Our final method, create arena!
  232. public void createArena(String arenaName, Location joinLocation, Location startLocation, Location endLocation, int maxPlayers) {
  233.  
  234. //Now, lets create an arena object to represent it:
  235. Arena arena = new Arena(arenaName, joinLocation, startLocation, endLocation, maxPlayers);
  236.  
  237. //Now here is where you would save it all to a file, again, im going to create a null FileConfiguration, USE YOUR OWN!!!
  238. FileConfiguration fc = Bukkit.getPluginManager().getPlugin("COMFFA").getConfig(); //USE YOUR OWN PUNK
  239.  
  240. fc.set("arenas." + arenaName, null); //Set its name
  241. //Now sets the other values
  242.  
  243. String path = "arenas." + arenaName + "."; //Shortcut
  244. //Sets the paths
  245. fc.set(path + "joinX", joinLocation.getX());
  246. fc.set(path + "joinY", joinLocation.getY());
  247. fc.set(path + "joinZ", joinLocation.getZ());
  248.  
  249. fc.set(path + "startX", startLocation.getX());
  250. fc.set(path + "startY", startLocation.getY());
  251. fc.set(path + "startZ", startLocation.getZ());
  252.  
  253. fc.set(path + "endX", endLocation.getX());
  254. fc.set(path + "endY", endLocation.getY());
  255. fc.set(path + "endZ", endLocation.getZ());
  256.  
  257. fc.set(path + "maxPlayers", maxPlayers);
  258.  
  259. //Now save it up down here
  260. Bukkit.getPluginManager().getPlugin("COMFFA").saveConfig();
  261. }
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement