Solved Auto start and playpaint ball game sytem fail

Discussion in 'Plugin Development' started by ian_x1995, Aug 19, 2013.

?

AN Auto start and play paint ball game sytem :solution

  1. Better code

    75.0%
  2. sugestions

    50.0%
Multiple votes are allowed.
Thread Status:
Not open for further replies.
  1. Offline

    ian_x1995

    [SOLVED]
    [cake] [cake] [cake]

    Code:java
    1. package Test.Plugin1;
    2. import java.util.ArrayList;
    3. import java.util.Iterator;
    4. import java.util.Random;
    5. import java.util.logging.Logger;
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Location;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.configuration.file.FileConfiguration;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.plugin.PluginDescriptionFile;
    14. import org.bukkit.plugin.PluginManager;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16. public final class Main extends JavaPlugin{
    17. public final Logger logger = Logger.getLogger("Minecraft");
    18. public final BukkitListener bl = new BukkitListener(this);
    19. //public final BukkitLogger blo = new BukkitLogger(this);
    20. public static Main plugin;
    21. ArrayList<Player> InGame = new ArrayList<Player>();
    22. ArrayList<Player> Zoom = new ArrayList<Player>();
    23. ArrayList<Player> t1 = new ArrayList<Player>();
    24. ArrayList<Player> t2 = new ArrayList<Player>();
    25. Random random = new Random();
    26. int teamI = random.nextInt(2);
    27. @Override
    28. public void onDisable(){
    29. //blo.enabled(false);
    30. PluginDescriptionFile pdfFile = this.getDescription();
    31. this.logger.info(pdfFile.getName() + " Is OFF!");
    32. }
    33. @Override
    34. public void onEnable(){
    35. //blo.enabled(true);
    36. PluginManager pm = this.getServer().getPluginManager();
    37. pm.registerEvents(bl, this);
    38. PluginDescriptionFile pdfFile = this.getDescription();
    39. this.logger.info(pdfFile.getName() + " Is ON!");
    40. /////////////////////////////
    41. /////// CRACH HERE //////////
    42. /////////////////////////////
    43. StartGame();
    44. }
    45. public void StartGame() {
    46. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    47. FileConfiguration cfg = plugin.getConfig();
    48. public Double s1 = cfg.getDouble("game.Lobbytime");
    49. public Double s2 = cfg.getDouble("game.time");
    50. public int start = (int)(s1 + s2) * 60 ;
    51. Iterator<Player> iterator1 = t1.iterator();
    52. Iterator<Player> iterator2 = t2.iterator();
    53. Iterator<Player> iteratorIG = InGame.iterator();
    54. // 0.017 = +-1second
    55. public void run(){
    56. if (start != -1){
    57. if (start != 0){
    58. if (start == (int)((s1 - 0.017) + s2) *60 ){
    59. Bukkit.getServer().broadcastMessage(ChatColor.GREEN +" - Paint Ball: "+s1+" minutes before the game start !");
    60. Bukkit.getServer().broadcastMessage(ChatColor.GREEN +" - Paint Ball: "+ (cfg.getInt("Maxp") - InGame.size() )+" Spots left !");
    61. Bukkit.getServer().broadcastMessage(ChatColor.GREEN +" - Paint Ball: "+ChatColor.GRAY+"/join"+ChatColor.GREEN+" to Join the game !");
    62.  
    63. while (iterator1.hasNext()) {
    64. Player player = (Player) iterator1.next();
    65. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + s1 + ChatColor.BLUE +" minutes left before the game starts !");
    66. player.sendMessage(ChatColor.BLUE + " - you will play in team 1 !");
    67. }
    68. while (iterator2.hasNext()) {
    69. Player player = (Player) iterator2.next();
    70. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + s1 + ChatColor.BLUE +" minutes left before the game starts !");
    71. player.sendMessage(ChatColor.BLUE + " - you will play in team 2 !");
    72. }
    73. while (iteratorIG.hasNext()) {
    74. Player player = (Player) iteratorIG.next();
    75. if (!(t1.contains(player) || t2.contains(player))) {
    76. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + s1 + ChatColor.BLUE +" minutes left before the game starts !");
    77. player.sendMessage(ChatColor.BLUE + " - you will play in a random team or type /join <t1> OR <t2> !");
    78. }
    79. }
    80. }
    81. if (start == (int)((s1 / 2) + s2) *60 ) {
    82. while (iterator1.hasNext()) {
    83. Player player = (Player) iterator1.next();
    84. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + (s1 / 2) + ChatColor.BLUE +" minutes left before the game starts !");
    85. player.sendMessage(ChatColor.BLUE + " - you will play in team 1 !");
    86. }
    87. while (iterator2.hasNext()) {
    88. Player player = (Player) iterator2.next();
    89. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + (s1 / 2) + ChatColor.BLUE +" minutes left before the game starts !");
    90. player.sendMessage(ChatColor.BLUE + " - you will play in team 2 !");
    91. }
    92. while (iteratorIG.hasNext()) {
    93. Player player = (Player) iteratorIG.next();
    94. if (!(t1.contains(player) || t2.contains(player))) {
    95. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + (s1 / 2) + ChatColor.BLUE +" minutes left before the game starts !");
    96. player.sendMessage(ChatColor.BLUE + " - you will play in a random team or type /join <t1> OR <t2> !");
    97. }
    98. }
    99. }
    100. if (start == (int)((0.017 * 30) + s2) *60) {
    101. Bukkit.getServer().broadcastMessage(ChatColor.GREEN +" - Paint Ball: 30 secondes before the game start !");
    102. Bukkit.getServer().broadcastMessage(ChatColor.GREEN +" - Paint Ball: "+ (cfg.getInt("Maxp") - InGame.size() )+" Spots left !");
    103. Bukkit.getServer().broadcastMessage(ChatColor.GREEN +" - Paint Ball: "+ChatColor.GRAY+"/join"+ChatColor.GREEN+" to Join the game !");
    104. while (iterator1.hasNext()) {
    105. Player player = (Player) iterator1.next();
    106. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + (0.017 * 30) + ChatColor.BLUE +" minutes left before the game starts !");
    107. player.sendMessage(ChatColor.BLUE + " - you will play in team 1 !");
    108. }
    109. while (iterator2.hasNext()) {
    110. Player player = (Player) iterator2.next();
    111. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + (0.017 * 30) + ChatColor.BLUE +" minutes left before the game starts !");
    112. player.sendMessage(ChatColor.BLUE + " - you will play in team 2 !");
    113. }
    114. while (iteratorIG.hasNext()) {
    115. Player player = (Player) iteratorIG.next();
    116. if (!(t1.contains(player) || t2.contains(player))) {
    117. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + (0.017 * 30) + ChatColor.BLUE +" minutes left before the game starts !");
    118. player.sendMessage(ChatColor.BLUE + " - you will play in a random team or type /join <t1> OR <t2> !");
    119. }
    120. }
    121. }
    122. if (start == (int)((0.017 * 5) + s2) *60) {
    123. while (iteratorIG.hasNext()) {
    124. Player player = (Player) iteratorIG.next();
    125. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + "5" + ChatColor.BLUE +" seconds left before the game starts !");
    126. }
    127. }
    128. if (start == (int)((0.017 * 4) + s2) *60) {
    129. while (iteratorIG.hasNext()) {
    130. Player player = (Player) iteratorIG.next();
    131. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + "4" + ChatColor.BLUE +" seconds left before the game starts !");
    132. }
    133. }
    134. if (start == (int)((0.017 * 3) + s2) *60) {
    135. while (iteratorIG.hasNext()) {
    136. Player player = (Player) iteratorIG.next();
    137. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + "3" + ChatColor.BLUE +" seconds left before the game starts !");
    138. }
    139. }
    140. if (start == (int)((0.017 * 2) + s2) *60) {
    141. while (iteratorIG.hasNext()) {
    142. Player player = (Player) iteratorIG.next();
    143. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + "2" + ChatColor.BLUE +" seconds left before the game starts !");
    144. }
    145. }
    146. if (start == (int)(0.017 + s2) *60) {
    147. while (iteratorIG.hasNext()) {
    148. Player player = (Player) iteratorIG.next();
    149. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + "1" + ChatColor.BLUE +" second left before the game starts !");
    150. }
    151. }
    152. if (start == (int)(s2 *60)) {
    153. Bukkit.getServer().broadcastMessage(ChatColor.GREEN +" - Paint Ball: has been started !");
    154. while (iteratorIG.hasNext()) {
    155. Player player = (Player) iteratorIG.next();
    156. if (!(t1.contains(player) || t2.contains(player))) {
    157. int teamI = random.nextInt(2);
    158. if (teamI == 0){
    159. t1.add(player);
    160. t2.remove(player);
    161. boolean t1 = true;
    162. cfg.set(".t1." + player, t1);
    163. boolean t2 = false;
    164. cfg.set(".t2." + player, t2);
    165. saveConfig();
    166. player.sendMessage(ChatColor.BLUE + " - You have Joined Team 1 !");
    167. }
    168. if (teamI == 1){
    169. t2.add(player);
    170. t1.remove(player);
    171. boolean t1 = false;
    172. cfg.set(".t1." + player, t1);
    173. boolean t2 =true;
    174. cfg.set(".t2." + player, t2);
    175. saveConfig();
    176. player.sendMessage(ChatColor.BLUE + " - You have Joined Team 2 !");
    177. }
    178. player.sendMessage(ChatColor.GREEN +" "+ ChatColor.BOLD + "- GO !");
    179. }
    180. while (iterator1.hasNext()) {
    181. Player player2 = (Player) iterator1.next();
    182. String w = cfg.getString("team1.W");
    183. Double x = cfg.getDouble("team1.x");
    184. Double y = cfg.getDouble("team1.y");
    185. Double z = cfg.getDouble("team1.z");
    186. Location Loc = new Location(Bukkit.getWorld(w), x, y, z);
    187. player2.teleport(Loc);
    188. player2.sendMessage(ChatColor.GREEN +" "+ ChatColor.BOLD + "- GO !");
    189. }
    190. while (iterator2.hasNext()) {
    191. Player player2 = (Player) iterator2.next();
    192. String w = cfg.getString("team2.W");
    193. Double x = cfg.getDouble("team2.x");
    194. Double y = cfg.getDouble("team2.y");
    195. Double z = cfg.getDouble("team2.z");
    196. Location Loc = new Location(Bukkit.getWorld(w), x, y, z);
    197. player2.teleport(Loc);
    198. player2.sendMessage(ChatColor.GREEN +" "+ ChatColor.BOLD + "- GO !");
    199. }
    200. }
    201. }
    202. if (start == (int)(s2 / 2) *60) {
    203. while (iteratorIG.hasNext()) {
    204. Player player = (Player) iteratorIG.next();
    205. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + (s2 / 2) + ChatColor.BLUE +" minutes left before the game ends !");
    206. }
    207. }
    208. if (start == (int)(0.017 * 30) *60) {
    209. while (iteratorIG.hasNext()) {
    210. Player player = (Player) iteratorIG.next();
    211. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + "30" + ChatColor.BLUE +" seconds left before the game ends !");
    212. }
    213. }
    214. if (start == (int)(0.017 * 3) *60) {
    215. while (iteratorIG.hasNext()) {
    216. Player player = (Player) iteratorIG.next();
    217. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + "3" + ChatColor.BLUE +" seconds left before the game ends !");
    218. }
    219. }
    220. if (start == (int)(0.017 * 2) *60) {
    221. while (iteratorIG.hasNext()) {
    222. Player player = (Player) iteratorIG.next();
    223. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + "2" + ChatColor.BLUE +" seconds left before the game ends !");
    224. }
    225. }
    226. if (start == (int)(0.017) *60) {
    227. while (iteratorIG.hasNext()) {
    228. Player player = (Player) iteratorIG.next();
    229. player.sendMessage(ChatColor.BLUE + " - "+ ChatColor.GRAY + "1" + ChatColor.BLUE +" seconds left before the game ends !");
    230. }
    231. }
    232. start--;
    233. }else if (start == 0){
    234. while (iteratorIG.hasNext()) {
    235. Player player = (Player) iteratorIG.next();
    236. String Lw = cfg.getString(".L");
    237. double Lx = cfg.getDouble(".LX");
    238. double Ly = cfg.getDouble(".LY");
    239. double Lz = cfg.getDouble(".LZ");
    240. Location Loc = new Location(Bukkit.getWorld(Lw), Lx, Ly, Lz);
    241. player.teleport(Loc);
    242. player.sendMessage(ChatColor.BLUE + " - you are in the Lobby now !");
    243. player.sendMessage(ChatColor.BLUE + " - The game have ended !");
    244. }
    245. start--;
    246. }
    247. }
    248. if (start <= -1) {
    249. StartGame();
    250. return;
    251. }
    252. }
    253. }, 0L, 20L);
    254. }
    255. /////////////////////////////
    256. //// CRACH stops HERE ///////
    257. /////////////////////////////
    258. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    259. if(cmd.getName().equalsIgnoreCase("set") && sender instanceof Player && sender.isOp()) {
    260. Player player = (Player) sender;
    261. FileConfiguration cfg = this.getConfig();
    262. if (!(args.length == 1)){
    263. if (args.length == 0){
    264. player.sendMessage(ChatColor.RED + " - You have to tell wat to set !");
    265. }
    266. if (args.length > 1){
    267. player.sendMessage(ChatColor.RED + " - To many arguments !");
    268. }
    269. player.sendMessage(ChatColor.GRAY + " - /set <SZ OR SafeZone>");
    270. player.sendMessage(ChatColor.GRAY + " - /set <RCP OR ReConnectionPoint>");
    271. player.sendMessage(ChatColor.GRAY + " - /set <L OR Lobby>");
    272. player.sendMessage(ChatColor.GRAY + " - /set <t1>");
    273. player.sendMessage(ChatColor.GRAY + " - /set <t2>");
    274. return true;
    275. }
    276. if (args.length == 1){
    277. if (args[0].equalsIgnoreCase("SZ") || args[0].equalsIgnoreCase("SafeZone")){
    278. String SZw = player.getWorld().getName();
    279. double SZx = player.getLocation().getX();
    280. double SZy = player.getLocation().getY();
    281. double SZz = player.getLocation().getZ();
    282. cfg.set(".SZ", SZw);
    283. cfg.set(".SZX", SZx);
    284. cfg.set(".SZY", SZy);
    285. cfg.set(".SZZ", SZz);
    286. this.saveConfig();
    287. player.sendMessage(ChatColor.BLUE + " - The Safe Zone location is set to: " + SZx + ", " + SZy + ", " + SZz);
    288. return true;
    289. }
    290. if (args[0].equalsIgnoreCase("RCP") || args[0].equalsIgnoreCase("ReConnectionPoint")){
    291. String RCPw = player.getWorld().getName();
    292. double RCPx = player.getLocation().getX();
    293. double RCPy = player.getLocation().getY();
    294. double RCPz = player.getLocation().getZ();
    295. cfg.set(".RCP", RCPw);
    296. cfg.set(".RCPX", RCPx);
    297. cfg.set(".RCPY", RCPy);
    298. cfg.set(".RCPZ", RCPz);
    299. this.saveConfig();
    300. player.sendMessage(ChatColor.BLUE + " - The ReConnect Point is set to: " + RCPx + ", " + RCPy + ", " + RCPz);
    301. return true;
    302. }
    303. if (args[0].equalsIgnoreCase("L") || args[0].equalsIgnoreCase("Lobby")){
    304. String Lw = player.getWorld().getName();
    305. double Lx = player.getLocation().getX();
    306. double Ly = player.getLocation().getY();
    307. double Lz = player.getLocation().getZ();
    308. cfg.set(".L", Lw);
    309. cfg.set(".LX", Lx);
    310. cfg.set(".LY", Ly);
    311. cfg.set(".LZ", Lz);
    312. this.saveConfig();
    313. player.sendMessage(ChatColor.BLUE + " - The Lobby is set to: " + Lx + ", " + Ly + ", " + Lz);
    314. return true;
    315. }
    316. if (!(args[0].equalsIgnoreCase("RCP") || args[0].equalsIgnoreCase("ReConnectionPoint") || args[0].equalsIgnoreCase("L") || args[0].equalsIgnoreCase("Lobby") || args[0].equalsIgnoreCase("SZ") || args[0].equalsIgnoreCase("SafeZone") || args[0].equalsIgnoreCase("t1") || args[0].equalsIgnoreCase("t2"))) {
    317. player.sendMessage(ChatColor.RED + " - You Can't Set " + ChatColor.DARK_PURPLE + args[0] + ChatColor.RED + " !");
    318. player.sendMessage(ChatColor.GRAY + " - /set <SZ OR SafeZone>");
    319. player.sendMessage(ChatColor.GRAY + " - /set <RCP OR ReConnectionPoint>");
    320. player.sendMessage(ChatColor.GRAY + " - /set <L OR Lobby>");
    321. player.sendMessage(ChatColor.GRAY + " - /set <t1>");
    322. player.sendMessage(ChatColor.GRAY + " - /set <t2>");
    323. return true;
    324. }
    325. if (args[0].equalsIgnoreCase("t1")){
    326. String w = player.getWorld().getName();
    327. Double x = player.getLocation().getX();
    328. Double y = player.getLocation().getY();
    329. Double z = player.getLocation().getZ();
    330. cfg.set("team1.W", w);
    331. cfg.set("team1.x", x);
    332. cfg.set("team1.y", y);
    333. cfg.set("team1.z", z);
    334. this.saveConfig();
    335. player.sendMessage(ChatColor.BLUE + " - Team1's spawn is set to " + x + ", " + y + ", " + z + " !!!");
    336. return true;
    337. }
    338. if (args[0].equalsIgnoreCase("t2")){
    339. String w = player.getWorld().getName();
    340. Double x = player.getLocation().getX();
    341. Double y = player.getLocation().getY();
    342. Double z = player.getLocation().getZ();
    343. cfg.set("team2.W", w);
    344. cfg.set("team2.x", x);
    345. cfg.set("team2.y", y);
    346. cfg.set("team2.z", z);
    347. this.saveConfig();
    348. player.sendMessage(ChatColor.BLUE + " - Team2's spawn is set to " + x + ", " + y + ", " + z + " !!!");
    349. return true;
    350. }
    351. }
    352. return true;
    353. } else if(cmd.getName().equalsIgnoreCase("GoTo") && sender instanceof Player && sender.isOp()) {
    354. Player player = (Player) sender;
    355. FileConfiguration cfg = this.getConfig();
    356. if (!(args.length == 1)){
    357. if (args.length == 0){
    358. player.sendMessage(ChatColor.RED + " - You have to tell were to goto !");
    359. }
    360. if (args.length > 1){
    361. player.sendMessage(ChatColor.RED + " - To many arguments !");
    362. }
    363. player.sendMessage(ChatColor.GRAY + " - /Goto <SZ OR SafeZone>");
    364. player.sendMessage(ChatColor.GRAY + " - /Goto <RCP OR ReConnectionPoint>");
    365. player.sendMessage(ChatColor.GRAY + " - /Goto <L OR Lobby>");
    366. player.sendMessage(ChatColor.GRAY + " - /Goto <t1>");
    367. player.sendMessage(ChatColor.GRAY + " - /Goto <t2>");
    368. return true;
    369. }
    370. if (args.length == 1){
    371. if (args[0].equalsIgnoreCase("SZ") || args[0].equalsIgnoreCase("SafeZone")){
    372. try {
    373. String SZw = cfg.getString(".SZ");
    374. double SZx = cfg.getDouble(".SZX");
    375. double SZy = cfg.getDouble(".SZY");
    376. double SZz = cfg.getDouble(".SZZ");
    377. Location Loc = new Location(Bukkit.getWorld(SZw), SZx, SZy, SZz);
    378. player.teleport(Loc);
    379. player.sendMessage(ChatColor.BLUE + " - you are in the Save Zone !");
    380. return true;
    381. } catch (Exception ex1) {
    382. player.sendMessage(ChatColor.RED + " - the Save Zone isn't set yet !");
    383. }
    384. }
    385. if (args[0].equalsIgnoreCase("RCP") || args[0].equalsIgnoreCase("ReConnectionPoint")){
    386. try {
    387. String RCPw = cfg.getString(".RCP");
    388. double RCPx = cfg.getDouble(".RCPX");
    389. double RCPy = cfg.getDouble(".RCPY");
    390. double RCPz = cfg.getDouble(".RCPZ");
    391. Location Loc = new Location(Bukkit.getWorld(RCPw), RCPx, RCPy, RCPz);
    392. player.teleport(Loc);
    393. player.sendMessage(ChatColor.GRAY + " - You are ReConnected !");
    394. return true;
    395. } catch (Exception ex1) {
    396. player.sendMessage(ChatColor.RED + " - the ReConnectionPoint isn't set yet !");
    397. }
    398. }
    399. if (args[0].equalsIgnoreCase("L") || args[0].equalsIgnoreCase("Lobby")){
    400. try {
    401. String Lw = cfg.getString(".L");
    402. double Lx = cfg.getDouble(".LX");
    403. double Ly = cfg.getDouble(".LY");
    404. double Lz = cfg.getDouble(".LZ");
    405. Location Loc = new Location(Bukkit.getWorld(Lw), Lx, Ly, Lz);
    406. player.teleport(Loc);
    407. player.sendMessage(ChatColor.BLUE + " - you are in the Lobby now !");
    408. return true;
    409. } catch (Exception ex1) {
    410. player.sendMessage(ChatColor.RED + " - the Lobby isn't set yet !");
    411. }
    412. }
    413. if (!(args[0].equalsIgnoreCase("RCP") || args[0].equalsIgnoreCase("ReConnectionPoint") || args[0].equalsIgnoreCase("L") || args[0].equalsIgnoreCase("Lobby") || args[0].equalsIgnoreCase("SZ") || args[0].equalsIgnoreCase("SafeZone") || args[0].equalsIgnoreCase("t1") || args[0].equalsIgnoreCase("t2"))) {
    414. player.sendMessage(ChatColor.RED + " - You Can't goto " + ChatColor.DARK_PURPLE + args[0] + ChatColor.RED + " !");
    415. player.sendMessage(ChatColor.GRAY + " - /Goto <SZ OR SafeZone>");
    416. player.sendMessage(ChatColor.GRAY + " - /Goto <RCP OR ReConnectionPoint>");
    417. player.sendMessage(ChatColor.GRAY + " - /Goto <L OR Lobby>");
    418. player.sendMessage(ChatColor.GRAY + " - /Goto <t1>");
    419. player.sendMessage(ChatColor.GRAY + " - /Goto <t2>");
    420. return true;
    421. }
    422. if (args[0].equalsIgnoreCase("t1")){
    423. try {
    424. String w = cfg.getString("team1.W");
    425. Double x = cfg.getDouble("team1.x");
    426. Double y = cfg.getDouble("team1.y");
    427. Double z = cfg.getDouble("team1.z");
    428. Location Loc = new Location(Bukkit.getWorld(w), x, y, z);
    429. player.teleport(Loc);
    430. player.sendMessage(ChatColor.BLUE + " - You are in team1's spawn !");
    431. } catch (Exception e) {
    432. player.sendMessage(ChatColor.BLUE + " - Team1's spawn isn't set yet !");
    433. }
    434. return true;
    435. }
    436. if (args[0].equalsIgnoreCase("t2")){
    437. try {
    438. String w = cfg.getString("team2.W");
    439. Double x = cfg.getDouble("team2.x");
    440. Double y = cfg.getDouble("team2.y");
    441. Double z = cfg.getDouble("team2.z");
    442. Location Loc = new Location(Bukkit.getWorld(w), x, y, z);
    443. player.teleport(Loc);
    444. player.sendMessage(ChatColor.BLUE + " - You are in team2's spawn !");
    445. } catch (Exception e) {
    446. player.sendMessage(ChatColor.BLUE + " - Team2's spawn isn't set yet !");
    447. }
    448. return true;
    449. }
    450. }
    451. return true;
    452. } else if ((cmd.getName().equalsIgnoreCase("Join")) && ((sender instanceof Player))) {
    453. Player player = (Player)sender;
    454. FileConfiguration cfg = getConfig();
    455. if (args.length == 1) {
    456. if (args[0].equalsIgnoreCase("t1") && this.InGame.contains(player)) {
    457. t1.add(player);
    458. t2.remove(player);
    459. boolean t1 = true;
    460. cfg.set(".t1." + player, t1);
    461. boolean t2 = false;
    462. cfg.set(".t2." + player, t2);
    463. saveConfig();
    464. player.sendMessage(ChatColor.GREEN + " - You have Joined Team 1 !");
    465. return true;
    466. }
    467. if (args[0].equalsIgnoreCase("t2") && this.InGame.contains(player)) {
    468. t2.add(player);
    469. t1.remove(player);
    470. boolean t2 = true;
    471. cfg.set(".t2." + player, t2);
    472. boolean t1 = false;
    473. cfg.set(".t1." + player, t1);
    474. saveConfig();
    475. player.sendMessage(ChatColor.GREEN + " - You have Joined Team 2 !");
    476. return true;
    477. }
    478. if (!(args[0].equalsIgnoreCase("t1") || args[0].equalsIgnoreCase("t2"))) {
    479. player.sendMessage(ChatColor.RED + " - You Can't join " + ChatColor.DARK_PURPLE + args[0] + ChatColor.RED + " !");
    480. player.sendMessage(ChatColor.GRAY + " - /join");
    481. player.sendMessage(ChatColor.GRAY + " - /join <t1> OR <t2>");
    482. return true;
    483. }
    484. if (! this.InGame.contains(player)) {
    485. player.sendMessage(ChatColor.RED + " - You Can't join " + ChatColor.DARK_PURPLE + args[0] + ChatColor.RED + " !");
    486. player.sendMessage(ChatColor.GRAY + " - first you have to Join the game ! type /join");
    487. return true;
    488. }
    489. return true;
    490. }
    491. if (args.length == 0) {
    492. InGame.add(player);
    493.  
    494. boolean ingame = true;
    495. cfg.set(".InGame." + player, ingame);
    496. this.saveConfig();
    497. String Lw = cfg.getString(".L");
    498. double Lx = cfg.getDouble(".LX");
    499. double Ly = cfg.getDouble(".LY");
    500. double Lz = cfg.getDouble(".LZ");
    501. Location Loc = new Location(Bukkit.getWorld(Lw), Lx, Ly, Lz);
    502. player.teleport(Loc);
    503. player.sendMessage(ChatColor.BLUE + " - you are in the Lobby now !");
    504. player.sendMessage(ChatColor.GREEN + " - You have Joined Paint ball !");
    505. return true;
    506. }
    507. if (args.length > 1) {
    508. player.sendMessage(ChatColor.RED + " - To many arguments !");
    509. player.sendMessage(ChatColor.GRAY + " - /join OR /join < 't1' OR 't2' > !");
    510. return true;
    511. }
    512. return true;
    513. } else if ((cmd.getName().equalsIgnoreCase("leave")) && ((sender instanceof Player))) {
    514. Player player = (Player)sender;
    515. FileConfiguration cfg = getConfig();
    516. if (args.length == 1) {
    517. if (args[0].equalsIgnoreCase("team") || args[0].equalsIgnoreCase("t")) {
    518. if (this.InGame.contains(player)) {
    519. t1.remove(player);
    520. t2.remove(player);
    521. boolean t1 = false;
    522. boolean t2 = false;
    523. cfg.set(".t1." + player, t1);
    524. cfg.set(".t2." + player, t2);
    525. this.saveConfig();
    526.  
    527. player.sendMessage(ChatColor.GREEN + " - You have Left the Team !");
    528. return true;
    529. }
    530. }
    531. if (!(args[0].equalsIgnoreCase("t") || args[0].equalsIgnoreCase("team"))) {
    532. player.sendMessage(ChatColor.RED + " - You Can't leave " + ChatColor.DARK_PURPLE + args[0] + ChatColor.RED + " !");
    533. player.sendMessage(ChatColor.GRAY + " - /leave");
    534. player.sendMessage(ChatColor.GRAY + " - /leave <t> OR <team>");
    535. return true;
    536. }
    537. }
    538. if (args.length == 0) {
    539. InGame.remove(player);
    540. t2.remove(player);
    541. t1.remove(player);
    542. boolean t2 = false;
    543. boolean t1 = false;
    544. cfg.set(".t2." + player, t2);
    545. cfg.set(".t1." + player, t1);
    546. boolean ingame = false;
    547. cfg.set(".InGame." + player, ingame);
    548. this.saveConfig();
    549. player.sendMessage(ChatColor.GREEN + " - You have Left Paint ball !");
    550. return true;
    551. }
    552. if (args.length > 1) {
    553. player.sendMessage(ChatColor.RED + " - To many arguments !");
    554. player.sendMessage(ChatColor.GRAY + " - /leave OR /leave < 'team' OR 't' > !");
    555. return true;
    556. }
    557. return true;
    558. } else if(cmd.getName().equalsIgnoreCase("AMMO") && sender instanceof Player && sender.isOp()){
    559. Player player = (Player) sender;
    560. FileConfiguration cfg = this.getConfig();
    561. if (args.length == 0) {
    562. int snow = 20;
    563. cfg.set(".snow." + player, snow);
    564. this.saveConfig();
    565. player.sendMessage(ChatColor.GREEN + " - Your have Reloaded !");
    566. return true;
    567. } else if (args.length == 1 ) {
    568. if (args[0].equalsIgnoreCase("BAR")) {
    569. int AmmoBar = 2;
    570. cfg.set(".AmmoBar", AmmoBar);
    571. this.saveConfig();
    572. player.sendMessage(ChatColor.GREEN + " - You have set the Ammo display to A Bar !");
    573. return true;
    574. }
    575. if (args[0].equalsIgnoreCase("nr") || args[0].equalsIgnoreCase("number")) {
    576. int AmmoBar = 1;
    577. cfg.set(".AmmoBar", AmmoBar);
    578. this.saveConfig();
    579. player.sendMessage(ChatColor.GREEN + " - You have set the Ammo display to A Number !");
    580. return true;
    581. }
    582. if (!(args[0].equalsIgnoreCase("nr") || args[0].equalsIgnoreCase("number") || args[0].equalsIgnoreCase("BAR"))){
    583. player.sendMessage(ChatColor.RED + " - you can't use " + ChatColor.DARK_PURPLE + args[0] + ChatColor.RED + " as an argument !");
    584. player.sendMessage(ChatColor.GRAY + " - /Ammo , /Ammo Bar , /Ammo nr OR /Ammo number !");
    585. return true;
    586. }
    587. return true;
    588. }
    589. return true;
    590. } else if(cmd.getName().equalsIgnoreCase("UseAmmo") && sender instanceof Player){
    591. Player player = (Player) sender;
    592. FileConfiguration cfg = this.getConfig();
    593. if (args.length == 1){
    594. if (args[0].equalsIgnoreCase("true") || args[0].equalsIgnoreCase("t")){
    595. cfg.set(".UseAmmo", true);
    596. this.saveConfig();
    597. player.sendMessage(ChatColor.GREEN + " - You have set the game to Use Ammo !");
    598. return true;
    599. }
    600. else if (args[0].equalsIgnoreCase("false") || args[0].equalsIgnoreCase("f")){
    601. cfg.set(".UseAmmo", false);
    602. this.saveConfig();
    603. player.sendMessage(ChatColor.GREEN + " - You have set the game to NOT Use Ammo !");
    604. return true;
    605. }
    606. if (!(args[0].equalsIgnoreCase("false") || args[0].equalsIgnoreCase("f") || args[0].equalsIgnoreCase("true") || args[0].equalsIgnoreCase("t"))){
    607. player.sendMessage(ChatColor.RED + " - you can't use " + ChatColor.DARK_PURPLE + args[0] + ChatColor.RED + " as an argument !");
    608. player.sendMessage(ChatColor.GRAY + " - /UseAmmo true , /UseAmmo t , /UseAmmo false OR /UseAmmo f !");
    609. return true;
    610. }
    611. return true;
    612. }
    613. if (args.length == 0 || args.length > 1){
    614. player.sendMessage(ChatColor.RED + " - In order to set the Ammo Use , You have to type 'true' / 't' OR 'false' / 'f' !");
    615. player.sendMessage(ChatColor.GRAY + " - /UseAmmo true , /UseAmmo t , /UseAmmo false OR /UseAmmo f !");
    616. return true;
    617. }
    618. return true;
    619. } else if(cmd.getName().equalsIgnoreCase("Game") && sender instanceof Player && sender.isOp()){
    620. Player player = (Player) sender;
    621. FileConfiguration cfg = this.getConfig();
    622. if (args.length == 2) {
    623. if (args[0].equalsIgnoreCase("t") || args[0].equalsIgnoreCase("time")) {
    624. if (args[1].equalsIgnoreCase("1")) {
    625. Double time = 1.000;
    626. cfg.set("game.time", time);
    627. this.saveConfig();
    628. player.sendMessage(ChatColor.GREEN + " - The game will last 1 minute MAX. !");
    629. }
    630. else if (args[1].equalsIgnoreCase("2")) {
    631. Double time = 2.000;
    632. cfg.set("game.time", time);
    633. this.saveConfig();
    634. player.sendMessage(ChatColor.GREEN + " - The game will last 2 minute MAX. !");
    635. }
    636. else if (args[1].equalsIgnoreCase("3")) {
    637. Double time = 3.000;
    638. cfg.set("game.time", time);
    639. this.saveConfig();
    640. player.sendMessage(ChatColor.GREEN + " - The game will last 3 minute MAX. !");
    641. }
    642. else if (args[1].equalsIgnoreCase("4")) {
    643. Double time = 4.000;
    644. cfg.set("game.time", time);
    645. this.saveConfig();
    646. player.sendMessage(ChatColor.GREEN + " - The game will last 4 minute MAX. !");
    647. }
    648. else if (args[1].equalsIgnoreCase("5")) {
    649. Double time = 5.000;
    650. cfg.set("game.time", time);
    651. this.saveConfig();
    652. player.sendMessage(ChatColor.GREEN + " - The game will last 5 minute MAX. !");
    653. }
    654. else {
    655. player.sendMessage(ChatColor.RED + " - /game <t> OR <time>: <1-5 minutes> OR <Off> (1,2,3,4,5 OR Off) !");
    656. }
    657. return true;
    658. }
    659. if (args[0].equalsIgnoreCase("Lt") || args[0].equalsIgnoreCase("Lobbytime")) {
    660. if (args[1].equalsIgnoreCase("1")) {
    661. Double time = 1.000;
    662. cfg.set("game.Lobbytime", time);
    663. this.saveConfig();
    664. player.sendMessage(ChatColor.GREEN + " - The Join time will last 1 minute MAX. !");
    665. }
    666. else if (args[1].equalsIgnoreCase("2")) {
    667. Double time = 2.000;
    668. cfg.set("game.Lobbytime", time);
    669. this.saveConfig();
    670. player.sendMessage(ChatColor.GREEN + " - The Join time will last 2 minute MAX. !");
    671. }
    672. else if (args[1].equalsIgnoreCase("3")) {
    673. Double time = 3.000;
    674. cfg.set("game.Lobbytime", time);
    675. this.saveConfig();
    676. player.sendMessage(ChatColor.GREEN + " - The Join time will last 3 minute MAX. !");
    677. }
    678. else if (args[1].equalsIgnoreCase("4")) {
    679. Double time = 4.000;
    680. cfg.set("game.Lobbytime", time);
    681. this.saveConfig();
    682. player.sendMessage(ChatColor.GREEN + " - The Join time will last 4 minute MAX. !");
    683. }
    684. else if (args[1].equalsIgnoreCase("5")) {
    685. Double time = 5.000;
    686. cfg.set("game.Lobbytime", time);
    687. this.saveConfig();
    688. player.sendMessage(ChatColor.GREEN + " - The Join time will last 5 minute MAX. !");
    689. }
    690. else {
    691. player.sendMessage(ChatColor.RED + " - /game <Lt> OR <Lobbytime>: <1-5 minutes> (1,2,3,4 OR 5) !");
    692. }
    693. return true;
    694. }
    695. return true;
    696. }
    697. if (! (args.length == 2)) {
    698. player.sendMessage(ChatColor.RED + " - /game '<t> or <time>' OR '<Lt> or <Lobbytime>': <1-5 minutes> OR <Off> (1,2,3,4,5 OR Off) !");
    699. player.sendMessage(ChatColor.RED + " - /game '<lives>': <1-5 lives> (1,2,3,4,5) !");
    700. }
    701. return true;
    702. }
    703. }
    704.  

    [Plugin Noob][coal]
    I am a plugin noob and i need help !
    when I try to automaticly start and repeat a game, my code craches pls I need help !

    I know this is a mess but pls help me!



    I would be happy if You can help me whit in 4 days.

    19/08/13
     

    Attached Files:

  2. Offline

    ian_x1995

    IMG_19082013_230013.png If tis helps here are the files + a picture of the crach report !
     

    Attached Files:

  3. Offline

    Mattredsox

    We need the crash report (I think you tried to post them but it didn't show up)
     
  4. Offline

    ian_x1995

    Done ; see prev poste + I updatet the code all you need is in there now !
    The problem lays in:
    Code:java
    1. public void StartGame() {
    2. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    3.  
    4. // this is the problem I think but I need the config //
    5.  
    6. FileConfiguration cfg = plugin.getConfig();
    7. // .....
    8. public void run(){
    9. // .....
    10. }
    11.  
    12. }, 0, 20);
    13. }
     
  5. Offline

    blablubbabc



    • public static Main plugin;
    is null. You are never assigning a value to it in your on Enable, but you are using it in your task in the StartGame method:
    FileConfiguration cfg = plugin.getConfig();
     
  6. Offline

    ian_x1995

    thats NOT the problem because my 2nd class use this and it Always have worked (like: plugin.saveConfig(); and stuff This works so....)
    but when I added the StartGame() the plugin still does but StartGame() it gives an error !
     
  7. Offline

    blablubbabc

    Show me the place where you are assigning plugin a value then ...
     
  8. The problem is caused by the 53rd, 58th and 59th line.
     
  9. Offline

    ian_x1995

    I know that is:
    Code:java
    1. @Overridepublic
    2. void onEnable(){
    3. ////////////////////////////
    4. ////// CRACH HERE //////////
    5. ////////////////////////////
    6. StartGame();
    7. }


    AND

    Code:java
    1. public void StartGame() {
    2. ///// THIS
    3. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    4. /////////////////
    5. FileConfiguration cfg = plugin.getConfig();
    6. },0 ,20);
    7. }


    AND

    Code:java
    1. public void StartGame() {
    2. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    3. ///// AND THIS
    4. FileConfiguration cfg = plugin.getConfig();
    5. /////////////////
    6.  
    7. },0 ,20);
    8. }




    I know that is:

    Do you mean this: ?

    Code:java
    1. public static ClassName main;
    2.  
    3. @Override
    4. public void onEnable() {
    5. main = this;
    6. }



    In my case it is:
    Code:java
    1. public static Main plugin;
    2.  
    3. @Override
    4. public void onEnable() {
    5. plugin = this;
    6. }

    (I have added this and going to Test it later (I have to do Other important stuff) Thanks if this helps)

    Do I have to do this or ...?
    can you tell me some thing !

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  10. Offline

    blablubbabc

    Yes, that's what you are missing in the code above.
     
    ian_x1995 likes this.
  11. Offline

    ian_x1995

    (I have added this and going to Test it later (I have to do Other important stuff) Thanks if this helps)
    1 more question: How do I put this on solved IF this works ?

    THANKS this works. I still have to pull some buggs out but this works.

    [SOLVED]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  12. Offline

    ian_x1995

  13. ian_x1995
    In the future, it'd be a good idea to put things in different classes so your main class doesn't get too cluttered. It will make it more organized and professional :)
     
Thread Status:
Not open for further replies.

Share This Page