Util *BROKEN* *PLEASE READ* Create a Minigame!

Discussion in 'Resources' started by JPG2000, Nov 11, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    JPG2000

    I am going to say this upfront; this tutorial is broken. It was made a while back when I did not understand code well. Do NOT follow this tutorial anymore.


    Sorry to those who have issues with this tutorial.


    Pre-Note:
    Before you cause me of copying other peoples tutorials, I didn't. This one IS different. The other tutorials manage there Arenas a little diffirently, but most of all use arena ID's. This tutorial use's Arena names (Strings).

    Our Arena.class (Our Arena Objects)
    1) We are now going to create our Arena class, which will store all of the data for our separate Arena Objects. Fell free to remove/add more fields to your needs.
    Code:java
    1. package me.JPG.Tester;
    2.  
    3. import java.util.ArrayList;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.Location;
    6.  
    7. /**
    8. *
    9. * @Author Jake
    10. */
    11. public class Arena {
    12.  
    13. //A list of all the Arena Objects
    14. public static ArrayList<Arena> arenaObjects = new ArrayList<Arena>();
    15.  
    16. //Some fields we want each Arena object to store:
    17. private Location joinLocation, startLocation, endLocation; //Some general arena locations
    18.  
    19. private String name; //Arena name
    20. private ArrayList<String> players = new ArrayList<String>(); //And arraylist of players name
    21.  
    22. private int maxPlayers;
    23.  
    24. private boolean inGame = false; //Boolean to determine if an Arena is ingame or not, automaticly make it false
    25.  
    26.  
    27. //Now for a Constructor:
    28. public Arena (String arenaName, Location joinLocation, Location startLocation, Location endLocation, int maxPlayers) { //So basicly: Arena myArena = new Arena("My Arena", joinLocation, startLocation, endLocation, 17)
    29. //Lets initalize it all:
    30. this.name = arenaName;
    31. this.joinLocation = joinLocation;
    32. this.startLocation = startLocation;
    33. this.endLocation = endLocation;
    34. this.maxPlayers = maxPlayers;
    35.  
    36. //Now lets add this object to the list of objects:
    37. arenaObjects.add(this);
    38.  
    39. }
    40.  
    41. //Now for some Getters and Setters, so with our arena object, we can use special methods:
    42. public Location getJoinLocation() {
    43. return this.joinLocation;
    44. }
    45.  
    46. public void setJoinLocation(Location joinLocation) {
    47. this.joinLocation = joinLocation;
    48. }
    49.  
    50. public Location getStartLocation() {
    51. return this.startLocation;
    52. }
    53.  
    54. public void setStartLocation(Location startLocation) {
    55. this.startLocation = startLocation;
    56. }
    57.  
    58. public Location getEndLocation() {
    59. return this.endLocation;
    60. }
    61.  
    62. public void setEndLocation(Location endLocation) {
    63. this.endLocation = endLocation;
    64. }
    65.  
    66. public String getName() {
    67. return this.name;
    68. }
    69.  
    70. public void setName(String name) {
    71. this.name = name;
    72. }
    73.  
    74. public int getMaxPlayers() {
    75. return this.maxPlayers;
    76. }
    77.  
    78. public void setMaxPlayers(int maxPlayers) {
    79. this.maxPlayers = maxPlayers;
    80. }
    81.  
    82. public ArrayList<String> getPlayers() {
    83. return this.players;
    84. }
    85.  
    86.  
    87.  
    88. //And finally, some booleans:
    89. public boolean isFull() { //Returns weather the arena is full or not
    90. if (players.size() >= maxPlayers) {
    91. return true;
    92. } else {
    93. return false;
    94. }
    95. }
    96.  
    97.  
    98. public boolean isInGame() {
    99. return inGame;
    100. }
    101.  
    102. public void setInGame(boolean inGame) {
    103. this.inGame = inGame;
    104. }
    105.  
    106. //To send each player in the arena a message
    107. public void sendMessage(String message) {
    108. for (String s: players) {
    109. Bukkit.getPlayer(s).sendMessage(message);
    110. }
    111. }
    112.  
    113.  
    114. }
    115.  

    Pastebin version: http://pastebin.com/bhm3pdG8


    Our ArenaManager (The class that will manager our arenas)





    2) Lets create our Arena Manager. This will be responsible for adding players to an arena, ending/starting an arena, and a method to get every arena method. This will also be responsible for loading arenas from a configuration file. Make sure to read every comment, especially near the loadArenas method. This is a VERY big class, so read all of it!
    Code:java
    1. package me.JPG.Tester;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.World;
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.entity.Player;
    9.  
    10. /**
    11. *
    12. * @Author Jake
    13. */
    14. public class ArenaManager {
    15.  
    16. private static ArenaManager am = new ArenaManager();
    17.  
    18. //Usefull for getting the ArenaManager, like so: ArenaManager.getManager()
    19. public static ArenaManager getManager() {
    20. return am;
    21. }
    22.  
    23.  
    24. //A method for getting one of the Arenas out of the list by name:
    25. public Arena getArena(String name) {
    26. for (Arena a: Arena.arenaObjects) { //For all of the arenas in the list of objects
    27. if (a.getName().equals(name)) { //If the name of an arena object in the list is equal to the one in the parameter...
    28. return a; //Return that object
    29. }
    30. }
    31. return null; //No objects were found, return null
    32. }
    33.  
    34.  
    35. //A method for adding players
    36. public void addPlayers(Player player, String arenaName) {
    37.  
    38. if (getArena(arenaName) != null) { //If the arena exsists
    39.  
    40. Arena arena = getArena(arenaName); //Create an arena for using in this method
    41.  
    42. if (!arena.isFull()) { //If the arena is not full
    43.  
    44. if (!arena.isInGame()) {
    45.  
    46. //Every check is complete, arena is joinable
    47. player.getInventory().clear(); //Clear the players inventory
    48. player.setHealth(player.getMaxHealth()); //Heal the player
    49. player.setFireTicks(0); //Heal the player even more ^ ^ ^
    50.  
    51. //Teleport to the arena's join location
    52. player.teleport(arena.getJoinLocation());
    53.  
    54. //Add the player to the arena list
    55. arena.getPlayers().add(player.getName()); //Add the players name to the arena
    56.  
    57. int playersLeft = arena.getMaxPlayers() - arena.getPlayers().size(); //How many players needed to start
    58. //Send the arena's players a message
    59. arena.sendMessage(ChatColor.BLUE + player.getName() + " has joined the arena! We only need " + playersLeft + " to start the game!");
    60.  
    61.  
    62. if (playersLeft == 0) { //IF there are 0 players needed to start the game
    63. startArena(arenaName); //Start the arena, see the method way below :)
    64. }
    65.  
    66.  
    67. } else { //Specifiend arena is in game, send the player an error message
    68. player.sendMessage(ChatColor.RED + "The arena you are looking for is currently full!");
    69.  
    70. }
    71. } else { //Specified arena is full, send the player an error message
    72. player.sendMessage(ChatColor.RED + "The arena you are looking for is currently full!");
    73. }
    74.  
    75. } else { //The arena doesn't exsist, send the player an error message
    76. player.sendMessage(ChatColor.RED + "The arena you are looking for could not be found!");
    77. }
    78.  
    79. }
    80.  
    81.  
    82. //A method for removing players
    83. public void removePlayer(Player player, String arenaName) {
    84.  
    85. if (getArena(arenaName) != null) { //If the arena exsists
    86.  
    87. Arena arena = getArena(arenaName); //Create an arena for using in this method
    88.  
    89. if (arena.getPlayers().contains(player.getName())) { //If the arena has the player already
    90.  
    91. //Every check is complete, arena is leavable
    92. player.getInventory().clear(); //Clear the players inventory
    93. player.setHealth(player.getMaxHealth()); //Heal the player
    94. player.setFireTicks(0); //Heal the player even more ^ ^ ^
    95.  
    96. //Teleport to the arena's join location
    97. player.teleport(arena.getEndLocation());
    98.  
    99. //remove the player to the arena list
    100. arena.getPlayers().remove(player.getName()); //Removes the players name to the arena
    101.  
    102. //Send the arena's players a message
    103. arena.sendMessage(ChatColor.BLUE + player.getName() + " has left the Arena! There are " + arena.getPlayers().size() + "players currently left!");
    104.  
    105.  
    106.  
    107.  
    108. } else { //Specified arena doesn't have the player, send the player an error message
    109. player.sendMessage(ChatColor.RED + "Your not in the arena your looking for!");
    110.  
    111. }
    112.  
    113.  
    114. } else { //The arena doesn't exsist, send the player an error message
    115. player.sendMessage(ChatColor.RED + "The arena you are looking for could not be found!");
    116. }
    117. }
    118.  
    119.  
    120. //A method for starting an Arena:
    121. public void startArena(String arenaName) {
    122.  
    123. if (getArena(arenaName) != null) { //If the arena exsists
    124.  
    125. Arena arena = getArena(arenaName); //Create an arena for using in this method
    126.  
    127. arena.sendMessage(ChatColor.GOLD + "The arena has BEGUN!");
    128.  
    129. //Set ingame
    130. arena.setInGame(true);
    131.  
    132. for (String s: arena.getPlayers()) {//Loop through every player in the arena
    133.  
    134. Bukkit.getPlayer(s).teleport(arena.getStartLocation()); //Teleports the player to the arena start location
    135.  
    136. //Do custom stuff here, like give weapons etc, but for the purpose of this tutorial, i'll do nothing
    137.  
    138. //Set inGa
    139.  
    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(player.getMaxHealth()); //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 = null; //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 = null; //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.  
    261. }
    262. }
    263.  

    Pastebin version: http://pastebin.com/wE5N9W7B


    A quick example of some commands
    Code:java
    1. //Lets assume my onCommand method is above here and is working properly
    2.  
    3. if (alias.equalsIgnoreCase("join")) {
    4. //We would have to check the arguments first, but lets just be lazy! :p
    5. ArenaManager.getManager().addPlayer(player, args[0]); //Would use our method made in our ArenaManager class, args[0] is the first argument they typed
    6. }
    7.  
    8. if (alias.equalsIgnoreCase("leave")) {
    9. ArenaManager.getManager().removePlayer(player, args[0]); //Would use our method made in our ArenaManager class, args[0] is the first argument they typed
    10. }
    11.  
    12. if (alias.equalsIgnoreCase("ForceStartArena")) {
    13. ArenaManager.getManager().startArena(args[0]); //Starts an arena
    14. }
    15.  
    16. if (alias.equalsIgnoreCase("ForceEndArena")) {
    17. ArenaManager.getManager.endArena(args[0]); //Ends an arena
    18. }
    19. }


    Now proceed to making an awesome game. For events, loop through every arena (Line 26, Arena Manager) and see if the arenas contain the player.

    Jake!
     
    Last edited by a moderator: May 6, 2015
  2. Offline

    PieMan456

    JPG2000
    Very useful I am going to use this to create a custom paintball Minigame!
     
    GrandmaJam and JPG2000 like this.
  3. Offline

    xTrollxDudex

    FadedMystery and JPG2000 like this.
  4. Offline

    JPG2000

    PieMan456 Thanks!

    xTrollxDudex Not really, since I took a different approach then yours, and I used strings instead of names. And the idea isn't yours, since lots of people ask for tutorials.
     
  5. Offline

    xTrollxDudex

    JPG2000
    Same implementation.

    I'm going to have to bump mine a lot.
     
  6. Offline

    JPG2000

    xTrollxDudex Funny joke. The aim of our tutorials are to help people, not to have yours become number one. Bumping yours all the time is a little rude to me, and it shows that you aren't in it for helping people.
     
    ark9026, BDKing88, fearleas and 11 others like this.
  7. Offline

    Ultimate_n00b

    There's like two guides out there. Mine uses strings. So yours actually isn't different..
     
  8. Offline

    JPG2000

    Ultimate_n00b I mean I use different methods and obviously different code. There may be different tutorials but there all here to help people.
     
  9. Offline

    Ultimate_n00b


     
  10. Offline

    xTrollxDudex

    Sorry if you took it the wrong way... It was a joke ;P
     
    Wizardo367 likes this.
  11. Offline

    BungeeTheCookie

    xTrollxDudex is a troll, he didn't mean it. He is always being helpful. Also, I like your tutorial, I will also use yours when I start making minigames. Keep up the good work :D
     
    MadMaxCookie and DogeDev like this.
  12. Offline

    bennie3211

    Nice, I always had problems with finding good tutorials! But since I have seen 3 tutorials I now finaly understand how to create (good) multiple arena's! Thank to you all guys! :D
     
    JPG2000 likes this.
  13. Offline

    JPG2000

    @BungeeTheCookien thanks!

    bennie3211 Awesome. Just ask if you have questions :)
     
  14. Offline

    PieMan456

    JPG2000
    How would you add multiple spawn points because I want a red spawn and a blue spawn for my paintball plugin?
     
  15. Offline

    JPG2000

    PieMan456 Add fields to the Arena class. All the information is stored in your arena class, so add another Location field, and another methods that returns that location. Or if your really lazy, just add a location object and don't make it private.
     
  16. Offline

    mattrick

  17. Offline

    Ultimate_n00b

    Lol. Mine is obviously the best, I get paid the big bucks to make these plugins for Minecade <3

    And DANGIT! My words keep moving weirdly thanks to your signature >_>
     
  18. Offline

    mattrick

    Lol you need your eyes checked, I've been staring at my own sig after I post and....wait hold on the room is spinning.
     
  19. Offline

    xTrollxDudex

    JPG2000
    With all this discussion, I think your thread is receiving the max amount of visibility due to the amount of bumping going on here :p
     
    JPG2000 likes this.
  20. Offline

    JPG2000

    xTrollxDudex likes this.
  21. Offline

    PieMan456

    JPG2000 xTrollxDudex Ultimate_n00b
    Since all of you guys have made tutorials on how to make minigames you should all make tutorials on how to add commands and listeners too. For people that are newer to bukkit.
     
  22. Offline

    Ultimate_n00b

    There is a wiki, and many guides on this. There is no need to explain it further.
     
  23. Offline

    JPG2000

  24. Offline

    PieMan456

    JPG2000
    I mean like to teach people how to add like BlockListeners or pvplisteners and how to add commands that add people to the game and remove people. And also like how to use put lobby signs and make those.

    Edit: I see that you already showed how to put commands in my bad:p

    JPG2000
    So are you gonna do that because I think it would be very helpful to people who are new to bukkit as well as people who want to make custom minigames.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    JPG2000 likes this.
  25. Offline

    xTrollxDudex

  26. Offline

    PieMan456

    xTrollxDudex
    I wasn't saying I didn't know it was saying that it would be helpful to people who are new.
     
  27. Offline

    xTrollxDudex

    PieMan456
    Let's have a link hub resource then?
     
  28. Offline

    PieMan456

  29. Offline

    xTrollxDudex

    PieMan456
    A resource that is a hub with links in it. Like a server hub except for links, a place to find a directory to where you need to go but with links.
     
    cruz2000 and JPG2000 like this.
  30. Offline

    PieMan456

    xTrollxDudex likes this.
Thread Status:
Not open for further replies.

Share This Page