Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.97 KB | None | 0 0
  1. package de.burnico.dustsystem.clanapi;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.UUID;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.Location;
  12. import org.bukkit.OfflinePlayer;
  13. import org.bukkit.configuration.file.YamlConfiguration;
  14. import org.bukkit.entity.Player;
  15.  
  16. import de.burnico.dustsystem.main.Main;
  17. import de.burnico.dustsystem.mysql.ClanManager;
  18. import de.burnico.dustsystem.tablist.Tablist;
  19.  
  20. public class Clan {
  21.  
  22. String name;
  23. Player pl;
  24. String pr = "§bClan : §7";
  25. String tag;
  26.  
  27. public static ArrayList<Player> invite = new ArrayList<Player>();
  28. public static HashMap<Player, String> clan = new HashMap<Player, String>();
  29.  
  30.  
  31.  
  32. public Clan(String names){
  33. name = names;
  34.  
  35. }
  36. public static boolean existsClan(String name){
  37. File file = new File("plugins//DustSystem//Clans//" + name + ".yml");
  38.  
  39. if(file.exists()){
  40. return true;
  41. }
  42. return false;
  43. }
  44. public void sendMessage(String msg){
  45. for(Player all : Bukkit.getOnlinePlayers()){
  46. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  47. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  48. List<String> players = cfg.getStringList("Clan.players");
  49. if(players.contains(all.getUniqueId().toString())){
  50. all.sendMessage(Main.getInstance().pr + msg);
  51. }
  52. }
  53. }
  54. public static String getClan(Player p){
  55. File file1 = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
  56. YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
  57. return cfg1.getString("Clan");
  58. }
  59. public static String getClan(String name){
  60. @SuppressWarnings("deprecation")
  61. OfflinePlayer p = Bukkit.getOfflinePlayer(name);
  62. File file1 = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
  63. YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
  64. return cfg1.getString("Clan");
  65. }
  66.  
  67. public void create(Player p, String tags){
  68.  
  69. pl = p;
  70. tag = tags;
  71. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  72. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  73.  
  74. File file1 = new File("plugins//DustSystem//Clan.yml//" + pl.getUniqueId().toString() + ".yml");
  75. YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
  76. cfg1.set("Clan", this.name);
  77. try {
  78. cfg1.save(file1);
  79. } catch (IOException e1) {
  80. e1.printStackTrace();
  81. }
  82. List<String> owners = cfg.getStringList("Clan.owners");
  83. List<String> players = cfg.getStringList("Clan.players");
  84. owners.add(this.pl.getUniqueId().toString());
  85. players.add(this.pl.getUniqueId().toString());
  86.  
  87. if(!exist()){
  88. createFile();
  89. }
  90. cfg.set("Clan.name", this.name);
  91. cfg.set("Clan.tag", this.tag);
  92. cfg.set("Clan.owners", owners);
  93. cfg.set("Clan.moderatoren", "");
  94. cfg.set("Clan.players", players);
  95. cfg.set("Clan.level", 1);
  96. cfg.set("Clan.base", p.getLocation());
  97. try {
  98. cfg.save(file);
  99. } catch (IOException e) {
  100. e.printStackTrace();
  101. }
  102. for(Player all : Bukkit.getOnlinePlayers()){
  103. Tablist tab = new Tablist(all);
  104. tab.updatePrefixs();
  105. }
  106. }
  107. public boolean exist(){
  108. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  109. if(file.exists()){
  110. return true;
  111. }
  112. return false;
  113. }
  114. public void joinClan(Player p){
  115. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  116. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  117. File file1 = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
  118. YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
  119. cfg1.set("Clan", this.name);
  120. try {
  121. cfg1.save(file1);
  122. } catch (IOException e1) {
  123. e1.printStackTrace();
  124. }
  125.  
  126. List<String> players = cfg.getStringList("Clan.players");
  127. players.add(p.getUniqueId().toString());
  128. cfg.set("Clan.players", players);
  129. try {
  130. cfg.save(file);
  131. } catch (IOException e) {
  132. e.printStackTrace();
  133. }
  134. for(Player all : Bukkit.getOnlinePlayers()){
  135. Tablist tab = new Tablist(all);
  136. tab.updatePrefixs();
  137. }
  138. }
  139. public void createFile(){
  140. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  141. try {
  142. file.createNewFile();
  143. } catch (IOException e) {
  144. e.printStackTrace();
  145. }
  146. }
  147. public void saveFile(){
  148. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  149. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  150. try {
  151. cfg.save(file);
  152. } catch (IOException e) {
  153. e.printStackTrace();
  154. }
  155. }
  156. public void leaveClan(Player p){
  157. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  158. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  159. File file1 = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
  160. if(file1.exists()){
  161. file1.delete();
  162. }
  163.  
  164. List<String> mods = cfg.getStringList("Clan.moderatoren");
  165. List<String> players = cfg.getStringList("Clan.players");
  166.  
  167. String uuid = p.getUniqueId().toString();
  168.  
  169.  
  170. players.remove(uuid);
  171. cfg.set("Clan.players", players);
  172. try {
  173. cfg.save(file);
  174. } catch (IOException e) {
  175. e.printStackTrace();
  176. }
  177. if(mods.contains(uuid)){
  178. mods.remove(uuid);
  179. cfg.set("Clan.moderatoren", mods);
  180. try {
  181. cfg.save(file);
  182. } catch (IOException e) {
  183. e.printStackTrace();
  184. }
  185. }
  186. for(Player all : Bukkit.getOnlinePlayers()){
  187. Tablist tab = new Tablist(all);
  188. tab.updatePrefixs();
  189. }
  190.  
  191. }
  192. public String getRank(Player p){
  193. String rank = "";
  194. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  195. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  196. List<String> owners = cfg.getStringList("Clan.owners");
  197. List<String> mods = cfg.getStringList("Clan.moderatoren");
  198. List<String> players = cfg.getStringList("Clan.players");
  199. String uuid = p.getUniqueId().toString();
  200.  
  201. if(owners.contains(uuid)){
  202. rank = "Owner";
  203. } else if(mods.contains(uuid)){
  204. rank = "Moderator";
  205. } else if(players.contains(uuid)&&!(owners.contains(uuid))){
  206. rank = "Member";
  207. } else {
  208. rank = "null";
  209. }
  210. return rank;
  211. }
  212. public String getRank(String name){
  213. String rank = "";
  214. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  215. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  216. List<String> owners = cfg.getStringList("Clan.owners");
  217. List<String> mods = cfg.getStringList("Clan.moderatoren");
  218. List<String> players = cfg.getStringList("Clan.players");
  219. @SuppressWarnings("deprecation")
  220. OfflinePlayer p = Bukkit.getOfflinePlayer(name);
  221. String uuid = p.getUniqueId().toString();
  222.  
  223. if(owners.contains(uuid)){
  224. rank = "Owner";
  225. } else if(mods.contains(uuid)){
  226. rank = "Moderator";
  227. } else if(players.contains(uuid)&&!(owners.contains(uuid))){
  228. rank = "Member";
  229. } else {
  230. rank = "null";
  231. }
  232. return rank;
  233. }
  234. public void sendClanMessage(Player sender, String message){
  235. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  236. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  237. List<String> owners = cfg.getStringList("Clan.owners");
  238. List<String> mods = cfg.getStringList("Clan.moderatoren");
  239. List<String> players = cfg.getStringList("Clan.players");
  240.  
  241.  
  242.  
  243. for(Player all : Bukkit.getOnlinePlayers()){
  244. if(players.contains(all.getUniqueId().toString())){
  245. if(!all.getName().equalsIgnoreCase(sender.getName())){
  246. all.sendMessage("");
  247. }
  248. }
  249. }
  250. }
  251. public static boolean isInClan(Player p){
  252. File file = new File("plugins//DustSystem//Clan.yml//" + p.getUniqueId().toString() + ".yml");
  253. if(file.exists()){
  254. return true;
  255. }
  256. return false;
  257. }
  258. public String getName(){
  259. return this.name;
  260. }
  261. public String getTag(){
  262. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  263. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  264. return cfg.getString("Clan.tag");
  265. }
  266. public void invitePlayer(Player target){
  267. invite.add(target);
  268. clan.remove(target);
  269. clan.put(target, this.name);
  270. Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable(){
  271.  
  272. @Override
  273. public void run() {
  274. if(target != null){
  275. if(invite.contains(target)){
  276. invite.remove(target);
  277. }
  278. }
  279. }
  280.  
  281. }, 20*30L);
  282. }
  283.  
  284. public void acceptInvitation(Player p){
  285. invite.remove(p);
  286. joinClan(p);
  287. }
  288. public Integer getLevel(){
  289. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  290. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  291.  
  292. return cfg.getInt("Clan.level");
  293. }
  294. public void updateLevel(){
  295. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  296. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  297.  
  298. cfg.set("Clan.level", getLevel() +1);
  299. try {
  300. cfg.save(file);
  301. } catch (IOException e) {
  302. e.printStackTrace();
  303. }
  304. sendMessage("Der Clan ist zu Level §6§l" + getLevel() + "§7 aufgestiegen!");
  305. for(Player all : Bukkit.getOnlinePlayers()){
  306. Tablist tab = new Tablist(all);
  307. tab.updatePrefixs();
  308. tab.updateScores();
  309. }
  310. }
  311. public String getColor(){
  312. String color = "";
  313. if(getLevel()==1){
  314. color = "§e";
  315. } else if(getLevel()==2){
  316. color = "§6";
  317. } else if(getLevel()==3){
  318. color = "§b";
  319. } else if(getLevel()==4){
  320. color = "§9";
  321. } else if(getLevel()==5){
  322. color = "§1";
  323. } else if(getLevel()==6){
  324. color = "§d";
  325. } else if(getLevel()==7){
  326. color = "§5";
  327. } else if(getLevel()==8){
  328. color = "§c";
  329. } else if(getLevel()==9){
  330. color = "§4";
  331. } else if(getLevel()==10){
  332. color = "§f";
  333. }
  334.  
  335. return color;
  336. }
  337. public void kick(UUID uuid){
  338. File file1 = new File("plugins//DustSystem//Clan.yml//" + uuid + ".yml");
  339. if(file1.exists()){
  340. file1.delete();
  341. }
  342. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  343. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  344.  
  345. List<String> players = cfg.getStringList("Clan.players");
  346. if(players.contains(uuid.toString())){
  347. players.remove(uuid.toString());
  348. cfg.set("Clan.players", players);
  349. try {
  350. cfg.save(file);
  351. } catch (IOException e) {
  352. e.printStackTrace();
  353. }
  354. }
  355. for(Player all : Bukkit.getOnlinePlayers()){
  356. Tablist tab = new Tablist(all);
  357. tab.updatePrefixs();
  358. }
  359. }
  360. public void promotePlayer(Player p){
  361.  
  362. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  363. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  364.  
  365. List<String> mods = cfg.getStringList("Clan.moderatoren");
  366. mods.add(p.getUniqueId().toString());
  367. cfg.set("Clan.moderatoren", mods);
  368. try {
  369. cfg.save(file);
  370. } catch (IOException e) {
  371. e.printStackTrace();
  372. }
  373. }
  374. public void demotePlayer(Player p){
  375.  
  376. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  377. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  378.  
  379. List<String> mods = cfg.getStringList("Clan.moderatoren");
  380. mods.remove(p.getUniqueId().toString());
  381. cfg.set("Clan.moderatoren", mods);
  382. try {
  383. cfg.save(file);
  384. } catch (IOException e) {
  385. e.printStackTrace();
  386. }
  387. }
  388. public List<String> Owners(){
  389. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  390. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  391. List<String> owners = cfg.getStringList("Clan.owners");
  392. List<String> names = new ArrayList<>();
  393. owners.forEach(uuids ->{
  394. names.add(Main.getName(UUID.fromString(uuids)));
  395. });
  396. return names;
  397. }
  398. public List<String> Moderatoren(){
  399. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  400. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  401. List<String> owners = cfg.getStringList("Clan.moderatoren");
  402. List<String> names = new ArrayList<>();
  403. owners.forEach(uuids ->{
  404. names.add(Main.getName(UUID.fromString(uuids)));
  405. });
  406. return names;
  407. }
  408. public List<String> Players(){
  409. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  410. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  411. List<String> owners = cfg.getStringList("Clan.players");
  412. List<String> names = new ArrayList<>();
  413. owners.forEach(uuids ->{
  414. names.add(Main.getName(UUID.fromString(uuids)));
  415. });
  416. return names;
  417. }
  418. public void deomotePlayer(UUID uid){
  419.  
  420. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  421. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  422.  
  423. List<String> mods = cfg.getStringList("Clan.moderatoren");
  424. mods.remove(uid.toString());
  425. cfg.set("Clan.moderatoren", mods);
  426. try {
  427. cfg.save(file);
  428. } catch (IOException e) {
  429. e.printStackTrace();
  430. }
  431. }
  432. public void setBase(Location loc){
  433. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  434. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  435.  
  436. cfg.set("Clan.base", loc);
  437. try {
  438. cfg.save(file);
  439. } catch (IOException e) {
  440. e.printStackTrace();
  441. }
  442. }
  443. public void setTag(String tag){
  444. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  445. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  446. cfg.set("Clan.tag", tag);
  447. try {
  448. cfg.save(file);
  449. } catch (IOException e) {
  450. e.printStackTrace();
  451. }
  452. for(Player all : Bukkit.getOnlinePlayers()){
  453. Tablist tab = new Tablist(all);
  454. tab.updatePrefixs();
  455. }
  456. }
  457. public Location getBase(){
  458. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  459. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  460. return (Location) cfg.get("Clan.base");
  461. }
  462. public void delete(){
  463. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  464. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  465. List<String> players = cfg.getStringList("Clan.players");
  466. players.forEach(uid -> {
  467. File file1 = new File("plugins//DustSystem//Clan.yml//" + uid + ".yml");
  468. if(file1.exists()){
  469. file1.delete();
  470. }
  471. });
  472. if(file.exists()){
  473. file.delete();
  474. }
  475. for(Player all : Bukkit.getOnlinePlayers()){
  476. Tablist tab = new Tablist(all);
  477. tab.updatePrefixs();
  478. }
  479. ClanManager.setKills(getOwner(), 0);
  480. }
  481. public UUID getOwner(){
  482. File file = new File("plugins//DustSystem//Clans//" + this.name + ".yml");
  483. YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  484. List<String> owners = cfg.getStringList("Clan.owners");
  485.  
  486. int i = 0;
  487. for(String s : owners){
  488. i++;
  489. if(i < 2){
  490. return UUID.fromString(s);
  491. }
  492. }
  493.  
  494. return null;
  495. }
  496. public static String getClanName(UUID owner){
  497. File file1 = new File("plugins//DustSystem//Clan.yml//" + owner.toString() + ".yml");
  498. YamlConfiguration cfg1 = YamlConfiguration.loadConfiguration(file1);
  499. return cfg1.getString("Clan");
  500. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement