Advertisement
Guest User

Untitled

a guest
Apr 26th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 65.92 KB | None | 0 0
  1. public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args)
  2. {
  3. if(cmd.getName().equalsIgnoreCase("guildadmin"))
  4. {
  5. if(theSender instanceof Player)
  6. {
  7. Player thePlayer = (Player) theSender;
  8. if(thePlayer.hasPermission("guilds.admin"))
  9. {
  10. if(args.length == 0)
  11. {
  12. thePlayer.performCommand("/guildadmin help");
  13. }
  14. if(args.length > 0)
  15. {
  16. if(args[0].equalsIgnoreCase("help"))
  17. {
  18. thePlayer.sendMessage("§b- - - - - §6[§3GAdmin §b- §3Page 1/1§6] §b- - - - -");
  19. thePlayer.sendMessage("§6/ga help - §3Displays information on guild admin commands.");
  20. thePlayer.sendMessage("§6/ga disband [GuildName] - §bDisbands the specified guild.");
  21. thePlayer.sendMessage("§6/ga join [GuildName] - §3Forcefully joins the specified guild.");
  22. thePlayer.sendMessage("§6/ga home [GuildName] - §bVisits the home of the specified guild.");
  23. }
  24. else if(args[0].equalsIgnoreCase("disband"))
  25. {
  26. if(args.length == 2)
  27. {
  28. String gn = args[1];
  29. if(config.isSet("guilds."+gn))
  30. {
  31. if(config.isSet("guilds."+gn+".members"))
  32. {
  33. @SuppressWarnings("unchecked")
  34. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  35. for(int i = 0; i < members.size(); i++)
  36. {
  37. Player member = Bukkit.getPlayer(members.get(i));
  38. member.sendMessage("§6[§a"+gn+"§6] §aYour guild has been disbanded.");
  39. config.set("players."+member.getUniqueId()+".guild", null);
  40. }
  41. }
  42. if(config.isSet("guilds."+gn+".claims"))
  43. {
  44. @SuppressWarnings("unchecked")
  45. ArrayList<String> claims = (ArrayList<String>) config.getList("guilds."+gn+".claims");
  46. for(int i = 0; i < claims.size(); i++)
  47. {
  48. config.set("claims."+claims.get(i), null);
  49. }
  50. }
  51. config.set("guilds."+gn, null);
  52. @SuppressWarnings("unchecked")
  53. ArrayList<String> guilds = (ArrayList<String>) config.getList("guildlist");
  54. guilds.remove(gn);
  55. config.set("guildlist", guilds);
  56. saveConfig();
  57. Bukkit.getServer().broadcastMessage("§6[§3Guilds§6] §a"+gn+" has been disbanded by "+theSender.getName());
  58. return true;
  59. }
  60. else theSender.sendMessage("§cGuild not found.");
  61. }
  62. else theSender.sendMessage("§cIncorrect format, use §4/ga disband [GuildName]");
  63. }
  64. else if(args[0].equalsIgnoreCase("home"))
  65. {
  66. if(args.length == 2)
  67. {
  68. String gn = args[1];
  69. if(config.isSet("guilds."+gn))
  70. {
  71. if(config.isSet("guilds."+gn+".homeblock"))
  72. {
  73. World w = (World) Bukkit.getServer().getWorld((String) config.get(("guilds."+gn+".sethome.w")));
  74. double x = config.getDouble(("guilds."+gn+".sethome.x"));
  75. double y = config.getDouble(("guilds."+gn+".sethome.y"));
  76. double z = config.getDouble(("guilds."+gn+".sethome.z"));
  77. Location loc = new Location(w, x, y, z);
  78. thePlayer.sendMessage("§aTeleporting. . .");
  79. thePlayer.teleport(loc);
  80. }
  81. thePlayer.sendMessage("§cGuild home not found.");
  82. }
  83. thePlayer.sendMessage("§cGuild not found.");
  84. }
  85. else
  86. {
  87. thePlayer.sendMessage("§cIncorrect format, use §4/ga home [GuildName]");
  88. return false;
  89. }
  90. }
  91. else if(args[0].equalsIgnoreCase("join"))
  92. {
  93. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  94. {
  95. thePlayer.sendMessage("§cYou must leave or disband your current guild before joining a new one.");
  96. return false;
  97. }
  98. if(args.length != 2)
  99. {
  100. thePlayer.sendMessage("§cIncorrect format, use §4/ga join [GuildName]");
  101. return false;
  102. }
  103. String gn = args[1];
  104. if(config.isSet("guilds."+gn))
  105. {
  106. @SuppressWarnings("unchecked")
  107. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  108. if (members.size() == 20)
  109. {
  110. thePlayer.sendMessage("§cI'm sorry, that guild has reached it's maximum player limit.");
  111. return false;
  112. }
  113. for(int i = 0; i < members.size(); i++)
  114. {
  115. Player member = Bukkit.getPlayer(members.get(i));
  116. member.sendMessage("§6[§a"+gn+"§6] §a"+thePlayer.getName()+" has forcefully joined your guild.");
  117. }
  118. members.add(thePlayer.getName());
  119. config.set("guilds."+gn+".members", members);
  120. config.set("guilds."+gn+".landcount", config.getInt("guilds."+gn+".landcount")+1);
  121. config.set("guilds."+gn+".power", guildPower(gn));
  122. config.set("players."+thePlayer.getUniqueId()+".guild", gn);
  123. saveConfig();
  124. thePlayer.sendMessage("§aYou have successfully joined "+gn+".");
  125. return true;
  126. }
  127. else thePlayer.sendMessage("§cGuild not found.");
  128. }
  129. else
  130. {
  131. thePlayer.performCommand("/guildadmin help");
  132. }
  133. }
  134. }
  135. else theSender.sendMessage("§4You do not have permission to use guild admin commands.");
  136. }
  137. else theSender.sendMessage("§4This command can only be used in game.");
  138. }
  139. if(commandLabel.equalsIgnoreCase("rank"))
  140. {
  141. if(theSender instanceof Player)
  142. {
  143. theSender.sendMessage("§4This command can only be used by the console.");
  144. return false;
  145. }
  146. if(args.length == 2)
  147. {
  148. if(Bukkit.getPlayer(args[0]) != null)
  149. {
  150. Player rankPlayer = Bukkit.getPlayer(args[0]);
  151. if(args[1].equalsIgnoreCase("default"))
  152. {
  153. config.set("players."+rankPlayer.getUniqueId()+".rank", null);
  154. return true;
  155. }
  156. if(args[1].equalsIgnoreCase("chatmod"))
  157. {
  158. config.set("players."+rankPlayer.getUniqueId()+".rank", "§eChatMod");
  159. return true;
  160. }
  161. if(args[1].equalsIgnoreCase("mod"))
  162. {
  163. config.set("players."+rankPlayer.getUniqueId()+".rank", "§6Mod");
  164. return true;
  165. }
  166. if(args[1].equalsIgnoreCase("builder"))
  167. {
  168. config.set("players."+rankPlayer.getUniqueId()+".rank", "§6Builder");
  169. return true;
  170. }
  171. if(args[1].equalsIgnoreCase("admin"))
  172. {
  173. config.set("players."+rankPlayer.getUniqueId()+".rank", "§cAdmin");
  174. return true;
  175. }
  176. if(args[1].equalsIgnoreCase("owner"))
  177. {
  178. config.set("players."+rankPlayer.getUniqueId()+".rank", "§4Owner");
  179. return true;
  180. }
  181. }
  182. else
  183. {
  184. theSender.sendMessage("§cPlayer not found.");
  185. return false;
  186. }
  187. }
  188. else
  189. {
  190. theSender.sendMessage("§cIncorrect format, use /rank [PlayerName] [RankName]");
  191. return false;
  192. }
  193. }
  194. if(cmd.getName().equalsIgnoreCase("guild"))
  195. {
  196. if(theSender instanceof Player)
  197. {
  198. final Player thePlayer = (Player) theSender;
  199. if(args.length == 0)
  200. {
  201. thePlayer.performCommand("/g help 1");
  202. return false;
  203. }
  204. else if (args.length >= 1)
  205. {
  206. if(args[0].equalsIgnoreCase("help"))
  207. {
  208. if(args.length == 1)
  209. {
  210. thePlayer.performCommand("/g help 1");
  211. return false;
  212. }
  213. if(args.length == 2)
  214. {
  215. if(args[1].equalsIgnoreCase("1"))
  216. {
  217. thePlayer.sendMessage("§b- - - - - §6[§3Guilds §b- §3Page 1/3§6] §b- - - - -");
  218. thePlayer.sendMessage("§6/g help [1/2/3] - §3Displays information on guild commands.");
  219. thePlayer.sendMessage("§6/g create [GuildName] - §bCreates a new guild.");
  220. thePlayer.sendMessage("§6/g p <PlayerName> - §3Finds guild related information on a player.");
  221. thePlayer.sendMessage("§6/g g <GuildName> - §bFinds information on a guild.");
  222. thePlayer.sendMessage("§6/g invite [PlayerName] - §3Invites a player to your guild.");
  223. thePlayer.sendMessage("§6/g join [GuildName] - §bAccepts an invite to a guild.");
  224. thePlayer.sendMessage("§6/g leave - §3Leaves your guild.");
  225. thePlayer.sendMessage("§6/g claim - §bClaims the chunk you're in for your guild.");
  226. thePlayer.sendMessage("§6/g unclaim <all> - §3Unclaims the chunk you're in, or unclaims all of your guild claims.");
  227. return true;
  228. }
  229. if(args[1].equalsIgnoreCase("2"))
  230. {
  231. thePlayer.sendMessage("§b- - - - - §6[§3Guilds §b- §3Page 2/3§6] §b- - - - -");
  232. thePlayer.sendMessage("§6/g sethome - §3Sets a home for your guild.");
  233. thePlayer.sendMessage("§6/g home - §bTeleports you to your guild home, if set.");
  234. thePlayer.sendMessage("§6/g balance - §3Shows information about your guild's bank.");
  235. thePlayer.sendMessage("§6/g deposit [Amount] - §bDeposits money into your guild's bank.");
  236. thePlayer.sendMessage("§6/g c [Message] - §3Sends a message to your guild members.");
  237. thePlayer.sendMessage("§6/g invites - §bShows any pending guild invites.");
  238. thePlayer.sendMessage("§6/g revoke [PlayerName] - §3Revokes an invite to your guild.");
  239. thePlayer.sendMessage("§6/g kick [PlayerName] - §bKicks a player from your guild.");
  240. thePlayer.sendMessage("§6/g disband [GuildName] - §3Disbands your guild.");
  241. return true;
  242. }
  243. if(args[1].equalsIgnoreCase("3"))
  244. {
  245. thePlayer.sendMessage("§b- - - - - §6[§3Guilds §b- §3Page 3/3§6] §b- - - - -");
  246. thePlayer.sendMessage("§6/g rename [New GuildName] - §3Renames your guild.");
  247. thePlayer.sendMessage("§6/g promote [PlayerName] - §bPromotes a player in your guild.");
  248. thePlayer.sendMessage("§6/g demote [PlayerName] - §3Demotes a player in your guild.");
  249. thePlayer.sendMessage("§6/g leader [PlayerName] [GuildName] - §bTransfers leadership of your guild to another player.");
  250. return true;
  251. }
  252. else
  253. {
  254. thePlayer.sendMessage("§cUse /g help <1/2/3>");
  255. return false;
  256. }
  257. }
  258. else
  259. {
  260. thePlayer.sendMessage("§cUse /g help <1/2/3>");
  261. return false;
  262. }
  263. }
  264. if(args[0].equalsIgnoreCase("create") || (args[0].equalsIgnoreCase("new")))
  265. {
  266. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  267. {
  268. thePlayer.sendMessage("§cYou must leave or disband your current guild before you can create a new one.");
  269. return false;
  270. }
  271. if(args.length == 2)
  272. {
  273. String gn = args[1];
  274. if(!isAlphanumeric(gn))
  275. {
  276. thePlayer.sendMessage("§cYour guild name must be alphanumeric, please choose a new name and try again.");
  277. return false;
  278. }
  279. if(illegalNames.contains(gn))
  280. {
  281. thePlayer.sendMessage("§cInnappropriate guild name, please choose a new name and try again.");
  282. return false;
  283. }
  284. ArrayList<String> guilds = new ArrayList<String>();
  285. if(config.isSet("guildlist"))
  286. {
  287. @SuppressWarnings("unchecked")
  288. ArrayList<String> guilds2 = (ArrayList<String>) config.getList("guildlist");
  289. for(int i = 0; i < guilds2.size(); i++)
  290. {
  291. guilds.add(guilds2.get(i));
  292. if(guilds2.get(i).equalsIgnoreCase(gn))
  293. {
  294. thePlayer.sendMessage("§cThat guild already exists, please choose a new name and try again.");
  295. return false;
  296. }
  297. }
  298. }
  299. if(gn.length() > 10)
  300. {
  301. thePlayer.sendMessage("§cGuild names cannot be longer than 10 characters, please choose a new name and try again.");
  302. return false;
  303. }
  304. if(ecoConfig.getDouble("economy."+thePlayer.getUniqueId()+".balance") < 500.00)
  305. {
  306. thePlayer.sendMessage("§cYou do not have enough money to start a guild, you need $500, you can check your balance with §4/balance");
  307. return false;
  308. }
  309. if(config.getInt("players."+thePlayer.getUniqueId()+".power") != 10)
  310. {
  311. thePlayer.sendMessage("§cYou do not have enough power to start a guild, you need 10 power, you have "+config.getDouble("players."+thePlayer.getUniqueId()+".power"));
  312. return false;
  313. }
  314. config.createSection("guilds."+gn);
  315. Double bal = ecoConfig.getDouble("economy."+thePlayer.getUniqueId()+".balance");
  316. ecoConfig.set("economy."+thePlayer.getUniqueId()+".balance", bal-500.0);
  317. config.set("players."+thePlayer.getUniqueId()+".guild", gn);
  318. config.set("guilds."+gn+".leader", thePlayer.getUniqueId().toString());
  319. config.set("guilds."+gn+".leadername", thePlayer.getName());
  320. ArrayList<String> members = new ArrayList<String>();
  321. members.add(thePlayer.getName());
  322. config.set("guilds."+gn+".members", members);
  323. config.set("guilds."+gn+".bal", 250.0);
  324. config.set("guilds."+gn+".landcount", 1);
  325. config.set("guilds."+gn+".landclaimed", 0);
  326. config.set("guilds."+gn+".power", 10);
  327. guilds.add(gn);
  328. config.set("guildlist", guilds);
  329. saveConfig();
  330. Bukkit.getServer().broadcastMessage("§6[§3Guilds§6] §a"+thePlayer.getName()+" has created a new guild by the name of "+gn+"!");
  331. return true;
  332. }
  333. else
  334. {
  335. thePlayer.sendMessage("§cIncorrect format, use §4/g create [GuildName]");
  336. return false;
  337. }
  338. }
  339. if(args[0].equalsIgnoreCase("g") || (args[0].equalsIgnoreCase("guild")))
  340. {
  341. if(args.length == 2)
  342. {
  343. String gn = args[1];
  344. thePlayer.sendMessage("§6Searching for guild or player, information will be returned if found.");
  345. if(config.isSet("guildlist"))
  346. {
  347. @SuppressWarnings("unchecked")
  348. ArrayList<String> guilds = (ArrayList<String>) config.getList("guildlist");
  349. for(int i = 0; i < guilds.size(); i++)
  350. {
  351. if(guilds.get(i).equalsIgnoreCase(gn))
  352. {
  353. gn = guilds.get(i);
  354. thePlayer.sendMessage("§2- - - - - §6[§a"+gn+" - "+config.getString("guilds."+gn+".leadername")+"§6] §2- - - - -");
  355. thePlayer.sendMessage("§aLand Claimed/Land Count: §2"+config.getInt("guilds."+gn+".landclaimed")+"/"+config.getInt("guilds."+gn+".landcount"));
  356. thePlayer.sendMessage("§aPower: §2"+guildPower(gn));
  357. thePlayer.sendMessage("§aBank: §2$"+config.getInt("guilds."+gn+".bal"));
  358. if(config.isSet("guilds."+gn+".officers"))
  359. {
  360. thePlayer.sendMessage("§aOfficers: §2"+config.getList("guilds."+gn+".officers"));
  361. }
  362. thePlayer.sendMessage("§aMembers: §2"+config.getList("guilds."+gn+".members"));
  363. return true;
  364. }
  365. }
  366. }
  367. else
  368. {
  369. thePlayer.sendMessage("§cNo guilds found.");
  370. return false;
  371. }
  372. }
  373. else
  374. {
  375. thePlayer.sendMessage("§cIncorrect format, use §4/g g [GuildName]");
  376. return false;
  377. }
  378. }
  379. if(args[0].equalsIgnoreCase("p") || (args[0].equalsIgnoreCase("player")))
  380. {
  381. if(args.length == 2)
  382. {
  383. Player player = Bukkit.getPlayer(args[1]);
  384. if(config.isSet("players."+player.getUniqueId()+".guild"))
  385. {
  386. String gn = config.getString("players."+player.getUniqueId()+".guild");
  387. thePlayer.performCommand("g g "+gn);
  388. return true;
  389. }
  390. else
  391. {
  392. thePlayer.sendMessage("§cThat player is not a part of a guild.");
  393. return false;
  394. }
  395. }
  396. else
  397. {
  398. thePlayer.sendMessage("§cIncorrect format, use §4/g p [PlayerName]");
  399. return false;
  400. }
  401. }
  402. if(args[0].equalsIgnoreCase("balance") || (args[0].equalsIgnoreCase("bal")))
  403. {
  404. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  405. {
  406. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  407. thePlayer.sendMessage("§6[§a"+gn+"§6] §aGuild Bank Balance: §2$"+config.getInt("guilds."+gn+".bal"));
  408. thePlayer.sendMessage("§aGuild Pricing: New Guild - §2$500§a, Rename - §2$250§a, Claim Wilderness - §2$100§a, Claim Over - §2$200§a, Unclaim + §2$25");
  409. return true;
  410. }
  411. else
  412. {
  413. thePlayer.sendMessage("§cYou are not a part of a guild.");
  414. return false;
  415. }
  416. }
  417. if(args[0].equalsIgnoreCase("deposit"))
  418. {
  419. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  420. {
  421. if(args.length == 2)
  422. {
  423. if(isInt(args[1]))
  424. {
  425. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  426. int amount = Integer.parseInt(args[1]);
  427. if(amount > 0)
  428. {
  429. if(amount <= ecoConfig.getDouble("economy."+thePlayer.getUniqueId()+".balance"))
  430. {
  431. ecoConfig.set("economy."+thePlayer.getUniqueId()+".balance", ecoConfig.getDouble("economy."+thePlayer.getUniqueId()+".balance")-amount);
  432. config.set("guilds."+gn+".bal", config.getDouble("guilds."+gn+".bal")+amount);
  433. thePlayer.sendMessage("§6[§a"+gn+"§6] §aDeposit successful, new guild bank balance is §2$"+config.getDouble("guilds."+gn+".bal"));
  434. saveConfig();
  435. return true;
  436. }
  437. else
  438. {
  439. thePlayer.sendMessage("§cCould not deposit, please ensure you have money in your EcoAccount using §4/balance");
  440. return false;
  441. }
  442. }
  443. else
  444. {
  445. thePlayer.sendMessage("§cCould not deposit, use §4/g deposit [amount] §cand ensure amount is greater than zero.");
  446. return false;
  447. }
  448. }
  449. else
  450. {
  451. thePlayer.sendMessage("§cCould not deposit, use §4/g deposit [amount] §cand ensure amount is a number.");
  452. return false;
  453. }
  454. }
  455. else
  456. {
  457. thePlayer.sendMessage("§cIncorrect format, use §4/g deposit [amount]");
  458. return false;
  459. }
  460. }
  461. else
  462. {
  463. thePlayer.sendMessage("§cYou are not a part of a guild.");
  464. return false;
  465. }
  466. }
  467. if(args[0].equalsIgnoreCase("promote"))
  468. {
  469. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  470. {
  471. if(args.length == 2)
  472. {
  473. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  474. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()))
  475. {
  476. if(Bukkit.getPlayer(args[1]) != null)
  477. {
  478. Player promotePlayer = Bukkit.getPlayer(args[1]);
  479. if(config.isSet("players."+promotePlayer.getUniqueId()+".guild") && config.getString("players."+promotePlayer.getUniqueId()+".guild").equals(gn))
  480. {
  481. if(thePlayer.getName().equals(promotePlayer.getName()))
  482. {
  483. thePlayer.sendMessage("§cYou cannot promote yourself to an Officer.");
  484. return false;
  485. }
  486. if(config.isSet("guilds."+gn+".officers"))
  487. {
  488. @SuppressWarnings("unchecked")
  489. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  490. if(officers.contains(promotePlayer.getName()))
  491. {
  492. thePlayer.sendMessage("§cThat player is already an Officer of your guild.");
  493. return false;
  494. }
  495. officers.add(promotePlayer.getName());
  496. config.set("guilds."+gn+".officers", officers);
  497. saveConfig();
  498. @SuppressWarnings("unchecked")
  499. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  500. for(int i = 0; i < members.size(); i++)
  501. {
  502. Player member = Bukkit.getPlayer(members.get(i));
  503. member.sendMessage("§6[§a"+gn+"§6] §a"+promotePlayer.getName()+" has been promoted to an Officer of your guild.");
  504. }
  505. return true;
  506. }
  507. else
  508. {
  509. ArrayList<String> officers = new ArrayList<String>();
  510. officers.add(promotePlayer.getName());
  511. promotePlayer.sendMessage("§6[§a"+gn+"§6] §aYou've been promoted to an Officer of your guild, you can now invite players and claim land.");
  512. config.set("guilds."+gn+".officers", officers);
  513. saveConfig();
  514. @SuppressWarnings("unchecked")
  515. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  516. for(int i = 0; i < members.size(); i++)
  517. {
  518. Player member = Bukkit.getPlayer(members.get(i));
  519. member.sendMessage("§6[§a"+gn+"§6] §a"+promotePlayer.getName()+" has been promoted to an Officer of your guild.");
  520. }
  521. return true;
  522. }
  523. }
  524. else
  525. {
  526. thePlayer.sendMessage("§cThat player is not in your guild.");
  527. return false;
  528. }
  529. }
  530. else
  531. {
  532. thePlayer.sendMessage("§cPlayer not found.");
  533. return false;
  534. }
  535. }
  536. else
  537. {
  538. thePlayer.sendMessage("§cOnly guild leaders can choose guild Officers.");
  539. return false;
  540. }
  541. }
  542. else
  543. {
  544. thePlayer.sendMessage("§cIncorrect format, use §4/g promote [PlayerName]");
  545. return false;
  546. }
  547. }
  548. else
  549. {
  550. thePlayer.sendMessage("§cYou are not a part of a guild.");
  551. return false;
  552. }
  553. }
  554. if(args[0].equalsIgnoreCase("demote"))
  555. {
  556. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  557. {
  558. if(args.length == 2)
  559. {
  560. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  561. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()))
  562. {
  563. if(Bukkit.getPlayer(args[1]) != null)
  564. {
  565. Player demotePlayer = Bukkit.getPlayer(args[1]);
  566. if(config.isSet("players."+demotePlayer.getUniqueId()+".guild") && config.getString("players."+demotePlayer.getUniqueId()+".guild").equals(gn))
  567. {
  568. if(thePlayer.getName().equals(demotePlayer.getName()))
  569. {
  570. thePlayer.sendMessage("§cYou cannot demote yourself.");
  571. return false;
  572. }
  573. if(config.isSet("guilds."+gn+".officers"))
  574. {
  575. @SuppressWarnings("unchecked")
  576. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  577. if(officers.contains(demotePlayer.getName()))
  578. {
  579. officers.remove(demotePlayer.getName());
  580. config.set("guilds."+gn+".officers", officers);
  581. saveConfig();
  582. @SuppressWarnings("unchecked")
  583. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  584. for(int i = 0; i < members.size(); i++)
  585. {
  586. Player member = Bukkit.getPlayer(members.get(i));
  587. member.sendMessage("§6[§a"+gn+"§6] §a"+demotePlayer.getName()+" is no longer an Officer for your guild.");
  588. }
  589. return true;
  590. }
  591. thePlayer.sendMessage("§cThat player is not an Officer of your guild.");
  592. return false;
  593. }
  594. else
  595. {
  596. thePlayer.sendMessage("§cThat player is not an Officer of your guild.");
  597. return false;
  598. }
  599. }
  600. else
  601. {
  602. thePlayer.sendMessage("§cThat player is not in your guild.");
  603. return false;
  604. }
  605. }
  606. else
  607. {
  608. thePlayer.sendMessage("§cPlayer not found.");
  609. return false;
  610. }
  611. }
  612. else
  613. {
  614. thePlayer.sendMessage("§cOnly guild leaders can choose guild Officers.");
  615. return false;
  616. }
  617. }
  618. else
  619. {
  620. thePlayer.sendMessage("§cIncorrect format, use §4/g demote [PlayerName]");
  621. return false;
  622. }
  623. }
  624. else
  625. {
  626. thePlayer.sendMessage("§cYou are not a part of a guild.");
  627. return false;
  628. }
  629. }
  630. if(args[0].equalsIgnoreCase("leader"))
  631. {
  632. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  633. {
  634. if(args.length == 2)
  635. {
  636. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  637. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()))
  638. {
  639. if(Bukkit.getPlayer(args[1]) != null)
  640. {
  641. Player promotePlayer = Bukkit.getPlayer(args[1]);
  642. if(config.isSet("players."+promotePlayer.getUniqueId()+".guild") && config.getString("players."+promotePlayer.getUniqueId()+".guild").equals(gn))
  643. {
  644. if(thePlayer.getName().equals(promotePlayer.getName()))
  645. {
  646. thePlayer.sendMessage("§cYou are already the leader of your guild.");
  647. return false;
  648. }
  649. config.set("guilds."+gn+".leader", promotePlayer.getUniqueId().toString());
  650. config.set("guilds."+gn+".leadername", promotePlayer.getName());
  651. saveConfig();
  652. @SuppressWarnings("unchecked")
  653. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  654. for(int i = 0; i < members.size(); i++)
  655. {
  656. Player member = Bukkit.getPlayer(members.get(i));
  657. member.sendMessage("§6[§a"+gn+"§6] §a"+promotePlayer.getName()+" is now the leader of your guild.");
  658. }
  659. return true;
  660. }
  661. else
  662. {
  663. thePlayer.sendMessage("§cThat player is not in your guild.");
  664. return false;
  665. }
  666. }
  667. else
  668. {
  669. thePlayer.sendMessage("§cPlayer not found.");
  670. return false;
  671. }
  672. }
  673. else
  674. {
  675. thePlayer.sendMessage("§cOnly guild leaders can choose new guild leaders.");
  676. return false;
  677. }
  678. }
  679. else
  680. {
  681. thePlayer.sendMessage("§cIncorrect format, use §4/g leader [PlayerName]");
  682. return false;
  683. }
  684. }
  685. else
  686. {
  687. thePlayer.sendMessage("§cYou are not a part of a guild.");
  688. return false;
  689. }
  690. }
  691. if(args[0].equalsIgnoreCase("invite") || args[0].equalsIgnoreCase("inv") || args[0].equalsIgnoreCase("add"))
  692. {
  693. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  694. {
  695. if(args.length == 2)
  696. {
  697. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  698. @SuppressWarnings("unchecked")
  699. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  700. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()) || (officers.contains(thePlayer.getName())))
  701. {
  702. if(Bukkit.getPlayer(args[1]) != null)
  703. {
  704. Player invPlayer = Bukkit.getPlayer(args[1]);
  705. if(thePlayer.getName().equals(invPlayer.getName()))
  706. {
  707. thePlayer.sendMessage("§cYou cannot invite yourself to your guild.");
  708. return false;
  709. }
  710. if(config.getString("players."+invPlayer.getUniqueId()+".guild").equals(gn))
  711. {
  712. thePlayer.sendMessage("§cThat player is already a part of your guild.");
  713. return false;
  714. }
  715. else
  716. {
  717. if(config.isSet("players."+invPlayer.getUniqueId()+".invites"))
  718. {
  719. @SuppressWarnings("unchecked")
  720. ArrayList<String> invs = (ArrayList<String>) config.getList("players."+invPlayer.getUniqueId()+".invites");
  721. if(invs.contains(gn))
  722. {
  723. thePlayer.sendMessage("§cThat player already has an invitation to your guild.");
  724. return false;
  725. }
  726. else
  727. {
  728. invs.add(gn);
  729. config.set("players."+invPlayer.getUniqueId()+".invites", invs);
  730. saveConfig();
  731. invPlayer.sendMessage("§aThe guild "+gn+" has extended you an invitation. Use §2/invites §ato see all of your invitations or §2/g join "+gn+" §to accept the invite.");
  732. @SuppressWarnings("unchecked")
  733. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  734. for(int i = 0; i < members.size(); i++)
  735. {
  736. Player member = Bukkit.getPlayer(members.get(i));
  737. member.sendMessage("§6[§a"+gn+"§6] §a"+invPlayer.getName()+" has been invited to your guild by "+thePlayer.getName()+".");
  738. }
  739. return true;
  740. }
  741. }
  742. else
  743. {
  744. ArrayList<String> invites = new ArrayList<String>();
  745. invites.add(gn);
  746. config.set("players."+invPlayer.getUniqueId()+".invites", invites);
  747. saveConfig();
  748. invPlayer.sendMessage("§aThe guild "+gn+" has extended you an invitation. Use §2/invites §ato see all of your invitations or §2/g join "+gn+" §to accept the invite.");
  749. @SuppressWarnings("unchecked")
  750. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  751. for(int i = 0; i < members.size(); i++)
  752. {
  753. Player member = Bukkit.getPlayer(members.get(i));
  754. member.sendMessage("§6[§a"+gn+"§6] §a"+invPlayer.getName()+" has been invited to your guild by "+thePlayer.getName()+".");
  755. }
  756. return true;
  757. }
  758. }
  759. }
  760. else
  761. {
  762. thePlayer.sendMessage("§cPlayer not found.");
  763. return false;
  764. }
  765. }
  766. else
  767. {
  768. thePlayer.sendMessage("§cOnly guild leaders and officers can invite players to the guild.");
  769. return false;
  770. }
  771. }
  772. else
  773. {
  774. thePlayer.sendMessage("§cIncorrect format, use §4/g invite [PlayerName]");
  775. return false;
  776. }
  777. }
  778. else
  779. {
  780. thePlayer.sendMessage("§cYou are not a part of a guild.");
  781. return false;
  782. }
  783. }
  784. if(args[0].equalsIgnoreCase("revoke") || args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("deinvite"))
  785. {
  786. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  787. {
  788. if(args.length == 2)
  789. {
  790. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  791. @SuppressWarnings("unchecked")
  792. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  793. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()) || (officers.contains(thePlayer.getName())))
  794. {
  795. if(Bukkit.getPlayer(args[1]) != null)
  796. {
  797. Player invPlayer = Bukkit.getPlayer(args[1]);
  798. if(config.isSet("players."+invPlayer.getUniqueId()+".invites"))
  799. {
  800. @SuppressWarnings("unchecked")
  801. ArrayList<String> invs = (ArrayList<String>) config.getList("players."+invPlayer.getUniqueId()+".invites");
  802. if(invs.contains(gn))
  803. {
  804. invs.remove(gn);
  805. config.set("players."+invPlayer.getUniqueId()+".invites", invs);
  806. saveConfig();
  807. invPlayer.sendMessage("§a"+gn+" has revoked their invitation for you to join their guild. Use §2/invites §ato see any other pending invitations.");
  808. @SuppressWarnings("unchecked")
  809. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  810. for(int i = 0; i < members.size(); i++)
  811. {
  812. Player member = Bukkit.getPlayer(members.get(i));
  813. member.sendMessage("§6[§a"+gn+"§6] §a"+invPlayer.getName()+"'s invitation to join your guild has been revoked by "+thePlayer.getName()+".");
  814. }
  815. return true;
  816. }
  817. else
  818. {
  819. thePlayer.sendMessage("§cThat player does not have an invitation to your guild.");
  820. return false;
  821. }
  822. }
  823. else
  824. {
  825. thePlayer.sendMessage("§cThat player does not have an invitation to your guild.");
  826. return false;
  827. }
  828. }
  829. else
  830. {
  831. thePlayer.sendMessage("§cPlayer not found.");
  832. return false;
  833. }
  834. }
  835. else
  836. {
  837. thePlayer.sendMessage("§cOnly guild leaders and officers can revoke invitations.");
  838. return false;
  839. }
  840. }
  841. else
  842. {
  843. thePlayer.sendMessage("§cIncorrect format, use §4/g revoke [PlayerName]");
  844. return false;
  845. }
  846. }
  847. else
  848. {
  849. thePlayer.sendMessage("§cYou are not a part of a guild.");
  850. return false;
  851. }
  852. }
  853. if(args[0].equalsIgnoreCase("invs") || args[0].equalsIgnoreCase("invites") || args[0].equalsIgnoreCase("invitations"))
  854. {
  855. if(args.length == 1)
  856. {
  857. if(config.isSet("players."+thePlayer.getUniqueId()+".invites"))
  858. {
  859. @SuppressWarnings("unchecked")
  860. ArrayList<String> invs = (ArrayList<String>) config.getList("players."+thePlayer.getUniqueId()+".invites");
  861. thePlayer.sendMessage("§aTo accept a pending invitation you must not be a part of a guild currently and use §2/g join [GuildName]");
  862. thePlayer.sendMessage("§aInvitations: "+invs);
  863. return true;
  864. }
  865. else
  866. {
  867. thePlayer.sendMessage("§aYou currently have no pending guild invitations.");
  868. return true;
  869. }
  870. }
  871. else
  872. {
  873. thePlayer.sendMessage("§cIncorrect format, use §4/g invites");
  874. return false;
  875. }
  876. }
  877. if(args[0].equalsIgnoreCase("join"))
  878. {
  879. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  880. {
  881. thePlayer.sendMessage("§cYou must leave or disband your current guild before joining a new one.");
  882. return false;
  883. }
  884. if(args.length != 2)
  885. {
  886. thePlayer.sendMessage("§cIncorrect format, use §4/g join [GuildName]");
  887. return false;
  888. }
  889. String gn = args[1];
  890. if(config.isSet("guilds."+gn))
  891. {
  892. @SuppressWarnings("unchecked")
  893. ArrayList<String> invs = (ArrayList<String>) config.getList("players."+thePlayer.getUniqueId()+".invites");
  894. if(invs.contains(gn))
  895. {
  896. invs.remove(gn);
  897. config.set("players."+thePlayer.getUniqueId()+".invites", invs);
  898. @SuppressWarnings("unchecked")
  899. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  900. if (members.size() == 20)
  901. {
  902. thePlayer.sendMessage("§cI'm sorry, that guild has reached it's maximum player limit.");
  903. return false;
  904. }
  905. for(int i = 0; i < members.size(); i++)
  906. {
  907. Player member = Bukkit.getPlayer(members.get(i));
  908. member.sendMessage("§6[§a"+gn+"§6] §a"+thePlayer.getName()+" has joined your guild.");
  909. }
  910. members.add(thePlayer.getName());
  911. config.set("guilds."+gn+".members", members);
  912. config.set("guilds."+gn+".landcount", config.getInt("guilds."+gn+".landcount")+1);
  913. config.set("guilds."+gn+".power", guildPower(gn));
  914. config.set("players."+thePlayer.getUniqueId()+".guild", gn);
  915. saveConfig();
  916. thePlayer.sendMessage("§aYou have successfully joined "+gn+"!");
  917. return true;
  918. }
  919. else
  920. {
  921. thePlayer.sendMessage("§cYou do not have an invitation from that guild, use §4/invites §cto see your guild invitations.");
  922. return false;
  923. }
  924. }
  925. else
  926. {
  927. thePlayer.sendMessage("§cGuild not found.");
  928. return false;
  929. }
  930. }
  931. if(args[0].equalsIgnoreCase("leave"))
  932. {
  933. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  934. {
  935. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  936. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()))
  937. {
  938. thePlayer.sendMessage("§cYou cannot leave your guild, consider §4/g leader [PlayerName] §cor §4/g disband");
  939. return false;
  940. }
  941. @SuppressWarnings("unchecked")
  942. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  943. if(officers.contains(thePlayer.getName()))
  944. {
  945. officers.remove(thePlayer.getName());
  946. config.set("guilds."+gn+".officers", officers);
  947. }
  948. @SuppressWarnings("unchecked")
  949. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  950. if(members.contains(thePlayer.getName()))
  951. {
  952. members.remove(thePlayer.getName());
  953. config.set("players."+thePlayer.getUniqueId()+".guild", null);
  954. config.set("guilds."+gn+".members", members);
  955. config.set("guilds."+gn+".landcount", config.getInt("guilds."+gn+".landcount")-1);
  956. config.set("guilds."+gn+".power", guildPower(gn));
  957. saveConfig();
  958. for(int i = 0; i < members.size(); i++)
  959. {
  960. Player member = Bukkit.getPlayer(members.get(i));
  961. member.sendMessage("§6[§a"+gn+"§6] §a"+thePlayer.getName()+" has left your guild.");
  962. }
  963. return true;
  964. }
  965. }
  966. else
  967. {
  968. thePlayer.sendMessage("§cYou are not a part of a guild.");
  969. return false;
  970. }
  971. }
  972. if(args[0].equalsIgnoreCase("kick"))
  973. {
  974. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  975. {
  976. if(args.length == 2)
  977. {
  978. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  979. @SuppressWarnings("unchecked")
  980. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  981. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()) || (officers.contains(thePlayer.getName())))
  982. {
  983. if(Bukkit.getPlayer(args[1]) != null)
  984. {
  985. Player kickPlayer = Bukkit.getPlayer(args[1]);
  986. @SuppressWarnings("unchecked")
  987. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  988. if(members.contains(kickPlayer.getName()))
  989. {
  990. if(config.getString("guilds."+gn+".leader").equals(kickPlayer.getUniqueId().toString()))
  991. {
  992. thePlayer.sendMessage("§cYou cannot do that.");
  993. return false;
  994. }
  995. if(officers.contains(kickPlayer.getName()))
  996. {
  997. if(officers.contains(thePlayer.getName()))
  998. {
  999. thePlayer.sendMessage("§cOnly the guild leader can kick guild officers.");
  1000. return false;
  1001. }
  1002. officers.remove(thePlayer.getName());
  1003. config.set("guilds."+gn+".officers", officers);
  1004. }
  1005. members.remove(kickPlayer.getName());
  1006. config.set("players."+kickPlayer.getUniqueId()+".guild", null);
  1007. config.set("guilds."+gn+".members", members);
  1008. config.set("guilds."+gn+".landcount", config.getInt("guilds."+gn+".landcount")-1);
  1009. config.set("guilds."+gn+".power", guildPower(gn));
  1010. saveConfig();
  1011. for(int i = 0; i < members.size(); i++)
  1012. {
  1013. Player member = Bukkit.getPlayer(members.get(i));
  1014. member.sendMessage("§6[§a"+gn+"§6] §a"+thePlayer.getName()+" has been kicked from your guild by "+thePlayer.getName()+".");
  1015. }
  1016. return true;
  1017. }
  1018. else
  1019. {
  1020. thePlayer.sendMessage("§cThat player is not a part of your guild.");
  1021. return false;
  1022. }
  1023. }
  1024. else
  1025. {
  1026. thePlayer.sendMessage("§cPlayer not found.");
  1027. return false;
  1028. }
  1029. }
  1030. else
  1031. {
  1032. thePlayer.sendMessage("§cOnly the guild leader and guild officers can kick players from the guild.");
  1033. return false;
  1034. }
  1035. }
  1036. else
  1037. {
  1038. thePlayer.sendMessage("§cIncorrect format, use §4/g kick [PlayerName]");
  1039. return false;
  1040. }
  1041. }
  1042. else
  1043. {
  1044. thePlayer.sendMessage("§cYou are not a part of a guild.");
  1045. return false;
  1046. }
  1047. }
  1048. if(args[0].equalsIgnoreCase("chat") || (args[0].equalsIgnoreCase("c")))
  1049. {
  1050. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  1051. {
  1052. if(args.length > 1)
  1053. {
  1054. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  1055. @SuppressWarnings("unchecked")
  1056. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  1057. @SuppressWarnings("unchecked")
  1058. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  1059. StringBuilder sb = new StringBuilder();
  1060. for(int i=0;i<args.length;i++)
  1061. {
  1062. sb.append(args[i] + " ");
  1063. }
  1064. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()))
  1065. {
  1066. for(int i = 0; i < members.size(); i++)
  1067. {
  1068. Player member = Bukkit.getPlayer(members.get(i));
  1069. member.sendMessage("§6[§a"+gn+"§6] §a**"+thePlayer.getName()+": "+sb);
  1070. }
  1071. return true;
  1072. }
  1073. else if(officers.contains(thePlayer.getName()))
  1074. {
  1075. for(int i = 0; i < members.size(); i++)
  1076. {
  1077. Player member = Bukkit.getPlayer(members.get(i));
  1078. member.sendMessage("§6[§a"+gn+"§6] §a*"+thePlayer.getName()+": "+sb);
  1079. }
  1080. return true;
  1081. }
  1082. else
  1083. {
  1084. for(int i = 0; i < members.size(); i++)
  1085. {
  1086. Player member = Bukkit.getPlayer(members.get(i));
  1087. member.sendMessage("§6[§a"+gn+"§6] §a"+thePlayer.getName()+": "+sb);
  1088. }
  1089. return true;
  1090. }
  1091. }
  1092. else
  1093. {
  1094. thePlayer.sendMessage("§cIncorrect format, use §4/g c [Message]");
  1095. return false;
  1096. }
  1097. }
  1098. else
  1099. {
  1100. thePlayer.sendMessage("§cYou are not a part of a guild.");
  1101. return false;
  1102. }
  1103. }
  1104. if(args[0].equalsIgnoreCase("check"))
  1105. {
  1106. if(args.length == 1)
  1107. {
  1108. Chunk chunk = thePlayer.getLocation().getChunk();
  1109. if(config.isSet("claims."+chunk.toString()))
  1110. {
  1111. String guild = config.getString("claims."+chunk.toString());
  1112. thePlayer.sendMessage("§aThis chunk belongs to "+guild+".");
  1113. }
  1114. else thePlayer.sendMessage("§aThis chunk does not belong to a guild.");
  1115. }
  1116. else thePlayer.sendMessage("§cUse this command while standing in a chunk you wish to know the owner of, correct format is §4/g check");
  1117. }
  1118. if(args[0].equalsIgnoreCase("claim"))
  1119. {
  1120. if(args.length == 1)
  1121. {
  1122. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  1123. {
  1124. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  1125. @SuppressWarnings("unchecked")
  1126. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  1127. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()) || (officers.contains(thePlayer.getName())))
  1128. {
  1129. Chunk chunk = thePlayer.getLocation().getChunk();
  1130. if(config.isSet("claims."+chunk.toString()))
  1131. {
  1132. if(config.getString("claims."+chunk.toString()).equals(gn))
  1133. {
  1134. thePlayer.sendMessage("§aYour guild already owns this chunk.");
  1135. return false;
  1136. }
  1137. else
  1138. {
  1139. thePlayer.sendMessage("§aAnalyzing attempt to claim. . .");
  1140. int landcount = config.getInt("guilds."+gn+".landcount");
  1141. int landclaimed = config.getInt("guilds."+gn+".landclaimed");
  1142. if(landclaimed >= landcount)
  1143. {
  1144. thePlayer.sendMessage("§cYour guild cannot claim anymore land.");
  1145. return false;
  1146. }
  1147. if(config.getDouble("guilds."+gn+".bal") < 200.0)
  1148. {
  1149. thePlayer.sendMessage("§cYour guild cannot afford $200.00 to claim this land.");
  1150. return false;
  1151. }
  1152. String ogn = config.getString("claims."+chunk.toString());
  1153. if(config.isSet("guilds."+ogn+".homeblock"))
  1154. {
  1155. if(config.getString("guilds."+ogn+".homeblock").equals(chunk.toString()))
  1156. {
  1157. thePlayer.sendMessage("§cYour guild cannot claim over the home block of "+ogn);
  1158. return false;
  1159. }
  1160. }
  1161. int olandcount = config.getInt("guilds."+ogn+".landcount");
  1162. int olandclaimed = config.getInt("guilds."+ogn+".landclaimed");
  1163. if(olandclaimed > olandcount)
  1164. {
  1165. thePlayer.sendMessage("§a"+ogn+" has claimed more land than they can support, approving your claim. . .");
  1166. @SuppressWarnings("unchecked")
  1167. ArrayList<String> oclaims = (ArrayList<String>) config.getList("guilds."+ogn+".claims");
  1168. oclaims.remove(chunk.toString());
  1169. config.set("guilds."+ogn+".claims", oclaims);
  1170. config.set("guilds."+ogn+".landclaimed", config.getInt("guilds."+ogn+".landclaimed")-1);
  1171. config.set("guilds."+gn+".landclaimed", config.getInt("guilds."+gn+".landclaimed")+1);
  1172. config.set("guilds."+gn+".bal", config.getDouble("guilds."+gn+".bal")-200.0);
  1173. config.set("claims."+chunk.toString(), gn);
  1174. if(config.isSet("guilds."+gn+".claims"))
  1175. {
  1176. @SuppressWarnings("unchecked")
  1177. ArrayList<String> claims = (ArrayList<String>) config.getList("guilds."+gn+".claims");
  1178. claims.add(chunk.toString());
  1179. config.set("guilds."+gn+".claims", claims);
  1180. }
  1181. else
  1182. {
  1183. ArrayList<String> claims = new ArrayList<String>();
  1184. claims.add(chunk.toString());
  1185. config.set("guilds."+gn+".claims", claims);
  1186. }
  1187. landclaimed = config.getInt("guilds."+gn+".landclaimed");
  1188. saveConfig();
  1189. thePlayer.sendMessage("§aLand claimed! You have claimed "+landclaimed+"/"+landcount+" possible claims.");
  1190. return true;
  1191. }
  1192. else
  1193. {
  1194. int opower = Integer.parseInt(guildPower(ogn));
  1195. int oneeded = olandclaimed*10/2;
  1196. if(oneeded >= opower)
  1197. {
  1198. thePlayer.sendMessage("§cCould not claim over the land of "+ogn+". They have not exceeded their claim limit, or fallen below needed power levels.");
  1199. return false;
  1200. }
  1201. else
  1202. {
  1203. thePlayer.sendMessage("§a"+ogn+" does not have enough power to protect this land, approving your claim. . .");
  1204. @SuppressWarnings("unchecked")
  1205. ArrayList<String> oclaims = (ArrayList<String>) config.getList("guilds."+ogn+".claims");
  1206. oclaims.remove(chunk.toString());
  1207. config.set("guilds."+ogn+".claims", oclaims);
  1208. config.set("guilds."+ogn+".landclaimed", config.getInt("guilds."+ogn+".landclaimed")-1);
  1209. config.set("guilds."+gn+".landclaimed", config.getInt("guilds."+gn+".landclaimed")+1);
  1210. config.set("guilds."+gn+".bal", config.getDouble("guilds."+gn+".bal")-200.0);
  1211. config.set("claims."+chunk.toString(), gn);
  1212. if(config.isSet("guilds."+gn+".claims"))
  1213. {
  1214. @SuppressWarnings("unchecked")
  1215. ArrayList<String> claims = (ArrayList<String>) config.getList("guilds."+gn+".claims");
  1216. claims.add(chunk.toString());
  1217. config.set("guilds."+gn+".claims", claims);
  1218. }
  1219. else
  1220. {
  1221. ArrayList<String> claims = new ArrayList<String>();
  1222. claims.add(chunk.toString());
  1223. config.set("guilds."+gn+".claims", claims);
  1224. }
  1225. landclaimed = config.getInt("guilds."+gn+".landclaimed");
  1226. saveConfig();
  1227. thePlayer.sendMessage("§aLand claimed! You have claimed "+landclaimed+"/"+landcount+" possible claims.");
  1228. return true;
  1229. }
  1230. }
  1231. }
  1232. }
  1233. else
  1234. {
  1235. int landcount = config.getInt("guilds."+gn+".landcount");
  1236. int landclaimed = config.getInt("guilds."+gn+".landclaimed");
  1237. if(landclaimed >= landcount)
  1238. {
  1239. thePlayer.sendMessage("§cYour guild cannot claim anymore land.");
  1240. return false;
  1241. }
  1242. if(config.getDouble("guilds."+gn+".bal") < 100.0)
  1243. {
  1244. thePlayer.sendMessage("§cYour guild cannot afford $100.00 to claim this land.");
  1245. return false;
  1246. }
  1247. else
  1248. {
  1249. config.set("guilds."+gn+".landclaimed", config.getInt("guilds."+gn+".landclaimed")+1);
  1250. config.set("guilds."+gn+".bal", config.getDouble("guilds."+gn+".bal")-100.0);
  1251. config.set("claims."+chunk.toString(), gn);
  1252. if(config.isSet("guilds."+gn+".claims"))
  1253. {
  1254. @SuppressWarnings("unchecked")
  1255. ArrayList<String> claims = (ArrayList<String>) config.getList("guilds."+gn+".claims");
  1256. claims.add(chunk.toString());
  1257. config.set("guilds."+gn+".claims", claims);
  1258. }
  1259. else
  1260. {
  1261. ArrayList<String> claims = new ArrayList<String>();
  1262. claims.add(chunk.toString());
  1263. config.set("guilds."+gn+".claims", claims);
  1264. }
  1265. landclaimed = config.getInt("guilds."+gn+".landclaimed");
  1266. saveConfig();
  1267. thePlayer.sendMessage("§aLand claimed! You have claimed "+landclaimed+"/"+landcount+" possible claims.");
  1268. return true;
  1269. }
  1270. }
  1271. }
  1272. else
  1273. {
  1274. thePlayer.sendMessage("§cOnly guild leaders and guild officers can claim land.");
  1275. return false;
  1276. }
  1277. }
  1278. else
  1279. {
  1280. thePlayer.sendMessage("§cYou are not a part of a guild.");
  1281. return false;
  1282. }
  1283. }
  1284. else
  1285. {
  1286. thePlayer.sendMessage("§cIncorrect format, use §4/g claim");
  1287. return false;
  1288. }
  1289. }
  1290. if(args[0].equalsIgnoreCase("unclaim"))
  1291. {
  1292. if(args.length == 1)
  1293. {
  1294. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  1295. {
  1296. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  1297. @SuppressWarnings("unchecked")
  1298. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  1299. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()) || (officers.contains(thePlayer.getName())))
  1300. {
  1301. Chunk chunk = thePlayer.getLocation().getChunk();
  1302. if(config.isSet("claims."+chunk.toString()))
  1303. {
  1304. if(config.getString("claims."+chunk.toString()).equals(gn))
  1305. {
  1306. int landcount = config.getInt("guilds."+gn+".landcount");
  1307. int landclaimed = config.getInt("guilds."+gn+".landclaimed");
  1308. config.set("guilds."+gn+".landclaimed", config.getInt("guilds."+gn+".landclaimed")-1);
  1309. config.set("guilds."+gn+".bal", config.getDouble("guilds."+gn+".bal")+25.0);
  1310. config.set("claims."+chunk.toString(), null);
  1311. if(config.isSet("guilds."+gn+".homeblock"))
  1312. {
  1313. if(config.getString("guilds."+gn+".homeblock").equals(chunk.toString()))
  1314. {
  1315. config.set("guilds."+gn+".homeblock", null);
  1316. config.set("guilds."+gn+".sethome", null);
  1317. }
  1318. }
  1319. @SuppressWarnings("unchecked")
  1320. ArrayList<String> claims = (ArrayList<String>) config.getList("guilds."+gn+".claims");
  1321. claims.remove(chunk.toString());
  1322. config.set("guilds."+gn+".claims", claims);
  1323. landclaimed = config.getInt("guilds."+gn+".landclaimed");
  1324. saveConfig();
  1325. thePlayer.sendMessage("§aUnclaimed. Your guild has now claimed "+landclaimed+"/"+landcount+" claims.");
  1326. return true;
  1327. }
  1328. else
  1329. {
  1330. thePlayer.sendMessage("§cThis claim does not belong to your guild.");
  1331. return false;
  1332. }
  1333. }
  1334. else
  1335. {
  1336. thePlayer.sendMessage("§cThis chunk is not claimed.");
  1337. return false;
  1338. }
  1339. }
  1340. else
  1341. {
  1342. thePlayer.sendMessage("§cOnly guild leaders and guild officers can unclaim land.");
  1343. return false;
  1344. }
  1345. }
  1346. else
  1347. {
  1348. thePlayer.sendMessage("§cYou are not a part of a guild.");
  1349. return false;
  1350. }
  1351. }
  1352. if(args.length == 2)
  1353. {
  1354. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  1355. {
  1356. if(args[1].equalsIgnoreCase("all"))
  1357. {
  1358. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  1359. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()))
  1360. {
  1361. if(config.isSet("guilds."+gn+".claims"))
  1362. {
  1363. @SuppressWarnings("unchecked")
  1364. ArrayList<String> claims = (ArrayList<String>) config.getList("guilds."+gn+".claims");
  1365. for(int i = 0; i < claims.size(); i++)
  1366. {
  1367. String chunk = claims.get(i);
  1368. config.set("claims."+chunk, null);
  1369. config.set("guilds."+gn+".bal", config.getDouble("guilds."+gn+".bal")+25.0);
  1370. claims.remove(i);
  1371. }
  1372. if(config.isSet("guilds."+gn+".homeblock"))
  1373. {
  1374. config.set("guilds."+gn+".homeblock", null);
  1375. config.set("guilds."+gn+".sethome", null);
  1376. }
  1377. config.set("guilds."+gn+".claims", null);
  1378. config.set("guilds."+gn+".landclaimed", 0);
  1379. saveConfig();
  1380. thePlayer.sendMessage("§aLand unclaimed.");
  1381. return true;
  1382. }
  1383. else
  1384. {
  1385. thePlayer.sendMessage("§cYour guild does not have any claimed land.");
  1386. return false;
  1387. }
  1388. }
  1389. else
  1390. {
  1391. thePlayer.sendMessage("§cOnly the guild leader can use that command.");
  1392. return false;
  1393. }
  1394. }
  1395. else
  1396. {
  1397. thePlayer.sendMessage("§cIncorrect format, use §4/g unclaim §cor §4/g unclaim all");
  1398. return false;
  1399. }
  1400. }
  1401. else
  1402. {
  1403. thePlayer.sendMessage("§cYou are not a part of a guild.");
  1404. return false;
  1405. }
  1406.  
  1407. }
  1408. else
  1409. {
  1410. thePlayer.sendMessage("§cIncorrect format, use §4/g unclaim §cor §4/g unclaim all");
  1411. return false;
  1412. }
  1413. }
  1414. if(args[0].equalsIgnoreCase("sethome"))
  1415. {
  1416. if(args.length == 1)
  1417. {
  1418. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  1419. {
  1420. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  1421. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()))
  1422. {
  1423. Chunk chunk = thePlayer.getLocation().getChunk();
  1424. if(config.isSet("claims."+chunk.toString()))
  1425. {
  1426. if(config.getString("claims."+chunk.toString()).equals(gn))
  1427. {
  1428. config.set("guilds."+gn+".homeblock", chunk.toString());
  1429. String w = thePlayer.getWorld().getName();
  1430. double x = thePlayer.getLocation().getX();
  1431. double y = thePlayer.getLocation().getY();
  1432. double z = thePlayer.getLocation().getZ();
  1433. config.set("guilds."+gn+".sethome.x", x);
  1434. config.set("guilds."+gn+".sethome.y", y);
  1435. config.set("guilds."+gn+".sethome.z", z);
  1436. config.set("guilds."+gn+".sethome.w", w);
  1437. saveConfig();
  1438. thePlayer.sendMessage("§aGuild home set to your location.");
  1439. return true;
  1440. }
  1441. else
  1442. {
  1443. thePlayer.sendMessage("§cYour guild does not own this chunk.");
  1444. return false;
  1445. }
  1446. }
  1447. else
  1448. {
  1449. thePlayer.sendMessage("§cThis chunk does not belong to a guild.");
  1450. return false;
  1451. }
  1452. }
  1453. else
  1454. {
  1455. thePlayer.sendMessage("§cOnly guilds leaders can set the guild home.");
  1456. return false;
  1457. }
  1458. }
  1459. else
  1460. {
  1461. thePlayer.sendMessage("§cYou are not a part of a guild.");
  1462. return false;
  1463. }
  1464. }
  1465. else
  1466. {
  1467. thePlayer.sendMessage("§cIncorrect format, use §4/g sethome");
  1468. return false;
  1469. }
  1470. }
  1471. if(args[0].equalsIgnoreCase("home"))
  1472. {
  1473. if(args.length == 1)
  1474. {
  1475. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  1476. {
  1477. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  1478. if(config.isSet("guilds."+gn+".homeblock"))
  1479. {
  1480. World w = (World) Bukkit.getServer().getWorld((String) config.get(("guilds."+gn+".sethome.w")));
  1481. double x = config.getDouble(("guilds."+gn+".sethome.x"));
  1482. double y = config.getDouble(("guilds."+gn+".sethome.y"));
  1483. double z = config.getDouble(("guilds."+gn+".sethome.z"));
  1484. Location loc = new Location(w, x, y, z);
  1485. thePlayer.sendMessage("§aTeleporting in 3 seconds. . .");
  1486. ghome.put(thePlayer.getUniqueId(), loc);
  1487. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
  1488. @Override
  1489. public void run()
  1490. {
  1491. if (ghome.containsKey(thePlayer.getUniqueId()))
  1492. {
  1493. thePlayer.sendMessage("§aTeleporting. . .");
  1494. thePlayer.teleport(ghome.get(thePlayer.getUniqueId()));
  1495. ghome.remove(thePlayer.getUniqueId());
  1496. }
  1497. }
  1498. }, 80);
  1499. }
  1500. }
  1501. else
  1502. {
  1503. thePlayer.sendMessage("§cYou are not a part of a guild.");
  1504. return false;
  1505. }
  1506. }
  1507. else
  1508. {
  1509. thePlayer.sendMessage("§cIncorrect format, use §4/g home");
  1510. return false;
  1511. }
  1512. }
  1513. if(args[0].equalsIgnoreCase("rename"))
  1514. {
  1515. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  1516. {
  1517. if(args.length == 2)
  1518. {
  1519. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  1520. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()))
  1521. {
  1522. String ngn = args[1];
  1523. if(gn.equalsIgnoreCase(ngn))
  1524. {
  1525. thePlayer.sendMessage("§cThat is already the name of your guild.");
  1526. return false;
  1527. }
  1528. if(!isAlphanumeric(ngn))
  1529. {
  1530. thePlayer.sendMessage("§cYour guild name must be alphanumeric, please choose a new name and try again.");
  1531. return false;
  1532. }
  1533. if(illegalNames.contains(ngn))
  1534. {
  1535. thePlayer.sendMessage("§cInnappropriate guild name, please choose a new name and try again.");
  1536. return false;
  1537. }
  1538. @SuppressWarnings("unchecked")
  1539. ArrayList<String> guilds = (ArrayList<String>) config.getList("guildlist");
  1540. for(int i = 0; i < guilds.size(); i++)
  1541. {
  1542. if(guilds.get(i).equalsIgnoreCase(ngn))
  1543. {
  1544. thePlayer.sendMessage("§cThat guild already exists, please choose a new name and try again.");
  1545. return false;
  1546. }
  1547. }
  1548. if(ngn.length() > 10)
  1549. {
  1550. thePlayer.sendMessage("§cGuild names cannot be longer than 10 characters, please choose a new name and try again.");
  1551. return false;
  1552. }
  1553. if(config.getDouble("guilds."+gn+".bal") < 250.00)
  1554. {
  1555. thePlayer.sendMessage("§cYou do not have enough money in your guild bank to rename your guild, you need $250.00, use §4/g balance");
  1556. return false;
  1557. }
  1558. config.createSection("guilds."+ngn);
  1559. if(config.isSet("guilds."+gn+".officers"))
  1560. {
  1561. @SuppressWarnings("unchecked")
  1562. ArrayList<String> officers = (ArrayList<String>) config.getList("guilds."+gn+".officers");
  1563. ArrayList<String> nofficers = new ArrayList<String>();
  1564. for(int i = 0; i < officers.size(); i++)
  1565. {
  1566. nofficers.add(officers.get(i));
  1567. }
  1568. config.set("guilds."+ngn+".officers", nofficers);
  1569. }
  1570. if(config.isSet("guilds."+gn+".members"))
  1571. {
  1572. @SuppressWarnings("unchecked")
  1573. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  1574. ArrayList<String> nmembers = new ArrayList<String>();
  1575. for(int i = 0; i < members.size(); i++)
  1576. {
  1577. Player member = Bukkit.getPlayer(members.get(i));
  1578. member.sendMessage("§aYour guild has been renamed to "+ngn);
  1579. nmembers.add(members.get(i));
  1580. config.set("players."+member.getUniqueId()+".guild", ngn);
  1581. }
  1582. config.set("guilds."+ngn+".members", nmembers);
  1583. }
  1584. if(config.isSet("guilds."+gn+".claims"))
  1585. {
  1586. @SuppressWarnings("unchecked")
  1587. ArrayList<String> claims = (ArrayList<String>) config.getList("guilds."+gn+".claims");
  1588. ArrayList<String> nclaims = new ArrayList<String>();
  1589. for(int i = 0; i < claims.size(); i++)
  1590. {
  1591. nclaims.add(claims.get(i));
  1592. config.set("claims."+claims.get(i), ngn);
  1593. }
  1594. config.set("guilds."+ngn+".claims", nclaims);
  1595. }
  1596. config.set("guilds."+ngn+".bal", config.getDouble("guilds."+gn+".bal"));
  1597. if(config.isSet("guilds."+gn+".sethome.w"))
  1598. {
  1599. config.set("guilds."+ngn+".sethome.w", config.get("guilds."+gn+".sethome.w"));
  1600. config.set("guilds."+ngn+".sethome.x", config.get("guilds."+gn+".sethome.x"));
  1601. config.set("guilds."+ngn+".sethome.y", config.get("guilds."+gn+".sethome.y"));
  1602. config.set("guilds."+ngn+".sethome.z", config.get("guilds."+gn+".sethome.z"));
  1603. config.set("guilds."+ngn+".homeblock", config.get("guilds."+gn+".homeblock"));
  1604. }
  1605. config.set("guilds."+ngn+".leader", config.get("guilds."+gn+".leader"));
  1606. config.set("guilds."+ngn+".leadername", config.get("guilds."+gn+".leadername"));
  1607. config.set("guilds."+ngn+".landcount", config.get("guilds."+gn+".landcount"));
  1608. config.set("guilds."+ngn+".landclaimed", config.get("guilds."+gn+".landclaimed"));
  1609. config.set("guilds."+ngn+".power", guildPower(gn));
  1610. config.set("guilds."+gn, null);
  1611. guilds.remove(gn);
  1612. guilds.add(ngn);
  1613. config.set("guildlist", guilds);
  1614. saveConfig();
  1615. Bukkit.getServer().broadcastMessage("§6[§3Guilds§6] §a"+gn+" has been renamed to "+ngn+"!");
  1616. return true;
  1617. }
  1618. else
  1619. {
  1620. thePlayer.sendMessage("§cOnly guild leaders can rename guilds.");
  1621. return false;
  1622. }
  1623. }
  1624. else
  1625. {
  1626. thePlayer.sendMessage("§cIncorrect format, use §4/g rename [NewGuildName]");
  1627. return false;
  1628. }
  1629. }
  1630. else
  1631. {
  1632. thePlayer.sendMessage("§cYou are not a part of a guild.");
  1633. return false;
  1634. }
  1635. }
  1636. if(args[0].equalsIgnoreCase("disband"))
  1637. {
  1638. if(args.length == 1)
  1639. {
  1640. if(config.isSet("players."+thePlayer.getUniqueId()+".guild"))
  1641. {
  1642. String gn = config.getString("players."+thePlayer.getUniqueId()+".guild");
  1643. if(config.getString("guilds."+gn+".leader").equals(thePlayer.getUniqueId().toString()))
  1644. {
  1645. if(config.isSet("guilds."+gn+".members"))
  1646. {
  1647. @SuppressWarnings("unchecked")
  1648. ArrayList<String> members = (ArrayList<String>) config.getList("guilds."+gn+".members");
  1649. for(int i = 0; i < members.size(); i++)
  1650. {
  1651. Player member = Bukkit.getPlayer(members.get(i));
  1652. member.sendMessage("§6[§a"+gn+"§6] §aYour guild has been disbanded.");
  1653. config.set("players."+member.getUniqueId()+".guild", null);
  1654. }
  1655. }
  1656. if(config.isSet("guilds."+gn+".claims"))
  1657. {
  1658. @SuppressWarnings("unchecked")
  1659. ArrayList<String> claims = (ArrayList<String>) config.getList("guilds."+gn+".claims");
  1660. for(int i = 0; i < claims.size(); i++)
  1661. {
  1662. config.set("claims."+claims.get(i), null);
  1663. }
  1664. }
  1665. config.set("guilds."+gn, null);
  1666. @SuppressWarnings("unchecked")
  1667. ArrayList<String> guilds = (ArrayList<String>) config.getList("guildlist");
  1668. guilds.remove(gn);
  1669. config.set("guildlist", guilds);
  1670. saveConfig();
  1671. Bukkit.getServer().broadcastMessage("§6[§3Guilds§6] §a"+gn+" has been disbanded!");
  1672. return true;
  1673. }
  1674. else
  1675. {
  1676. thePlayer.sendMessage("§cOnly guild leaders can disband guilds.");
  1677. return false;
  1678. }
  1679. }
  1680. else
  1681. {
  1682. thePlayer.sendMessage("§cYou are not a part of a guild.");
  1683. return false;
  1684. }
  1685. }
  1686. else
  1687. {
  1688. thePlayer.sendMessage("§cIncorrect format, use §4/g rename [NewGuildName]");
  1689. return false;
  1690. }
  1691. }
  1692. }
  1693. }
  1694. else theSender.sendMessage("§cGuild commands can only be used in game.");
  1695. }
  1696. return false;
  1697. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement