Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2015
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. package me.stefvanschie;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Location;
  9. import org.bukkit.World;
  10. import org.bukkit.entity.Player;
  11.  
  12. public class Join
  13. {
  14. BuildingGame main = new BuildingGame();
  15. public void joinGame (Player player, String arena)
  16. {
  17. if (player.hasPermission("join"))
  18. {
  19. if (main.arenas.contains(arena))
  20. {
  21. if (!main.playersInArena.containsKey(arena))
  22. {
  23. main.playersInArena.put(arena, 0);
  24. }
  25. if (main.playersInArena.get(arena) < main.arenas.getInt(arena + ".maxplayers"))
  26. {
  27. player.sendMessage(ChatColor.GOLD + "You have joined the game");
  28. for (Player pl : main.players.keySet())
  29. {
  30. if (main.players.get(pl).equals(arena))
  31. {
  32. pl.sendMessage(ChatColor.GOLD + "" + player.getName() + " joined the game!");
  33. }
  34. }
  35. main.playersInArena.put(arena, main.playersInArena.get(arena) + 1);
  36. main.players.put(player, arena);
  37. main.votes.put(player, 0);
  38. if (main.playersInArena.get(arena) == main.arenas.getInt(arena + ".maxplayers"))
  39. {
  40. String subject = "";
  41. if (main.config.contains("subjects"))
  42. {
  43. List<String> subjects = new ArrayList<String>();
  44. subjects = main.config.getStringList("subjects");
  45. Random rndm = new Random();
  46. int subjectint = rndm.nextInt(subjects.size());
  47. subject = subjects.get(subjectint);
  48. }
  49. int places = 1;
  50. for (Player pl : main.players.keySet())
  51. {
  52. if (main.players.get(pl).equals(arena))
  53. {
  54. String worldstr = main.arenas.getString(arena + "." + places + ".world");
  55. World world = main.getServer().getWorld(worldstr);
  56. int x = main.arenas.getInt(arena + "." + places + ".x");
  57. int y = main.arenas.getInt(arena + "." + places + ".y");
  58. int z = main.arenas.getInt(arena + "." + places + ".z");
  59. Location location = new Location(world, x, y, z);
  60. pl.teleport(location);
  61. pl.sendMessage(ChatColor.GOLD + "The game has started!");
  62. if (main.config.contains("subjects"))
  63. {
  64. pl.sendMessage(ChatColor.GOLD + "The subject is " + subject);
  65. }
  66. main.playernumbers.put(places, player);
  67. places++;
  68. }
  69. }
  70. main.timer(arena);
  71. }
  72. }
  73. else if (main.playersInArena.get(arena) >= main.config.getInt(arena + ".maxplayers"))
  74. {
  75. player.sendMessage(ChatColor.RED + "This arena is currently full");
  76. }
  77. else
  78. {
  79. player.sendMessage(ChatColor.RED + "An unexpected error occured: Error: bg.join.playersingame");
  80. }
  81. }
  82. else if (!main.config.contains(arena))
  83. {
  84. player.sendMessage(ChatColor.RED + "This arena does not exists!");
  85. }
  86. else
  87. {
  88. player.sendMessage(ChatColor.RED + "An unexpected error occured. Error: bg.join.config.contains");
  89. }
  90. }
  91. else if (!player.hasPermission("join"))
  92. {
  93. player.sendMessage(ChatColor.RED + "You don't have the required permission for that!");
  94. }
  95. else
  96. {
  97. player.sendMessage(ChatColor.RED + "An unexpected error occured: Error: bg.join.permission");
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement