mcUsers.java 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. package com.gmail.nossr50;
  2. import java.io.*;
  3. import java.util.ArrayList;
  4. import java.util.Properties;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. import org.bukkit.Location;
  8. import org.bukkit.entity.*;
  9. public class mcUsers {
  10. private static volatile mcUsers instance;
  11. protected static final Logger log = Logger.getLogger("Minecraft");
  12. String location = "mcmmo.users";
  13. public static PlayerList players = new PlayerList();
  14. private Properties properties = new Properties();
  15. //To load
  16. public void load() throws IOException {
  17. properties.load(new FileInputStream(location));
  18. }
  19. //To save
  20. public void save() {
  21. try {
  22. properties.store(new FileOutputStream(location), null);
  23. }catch(IOException ex) {
  24. }
  25. }
  26. public void loadUsers(){
  27. File theDir = new File(location);
  28. if(!theDir.exists()){
  29. //properties = new PropertiesFile(location);
  30. FileWriter writer = null;
  31. try {
  32. writer = new FileWriter(location);
  33. writer.write("#Storage place for user information\r\n");
  34. } catch (Exception e) {
  35. log.log(Level.SEVERE, "Exception while creating " + location, e);
  36. } finally {
  37. try {
  38. if (writer != null) {
  39. writer.close();
  40. }
  41. } catch (IOException e) {
  42. log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
  43. }
  44. }
  45. } else {
  46. //properties = new PropertiesFile(location);
  47. try {
  48. load();
  49. } catch (IOException e) {
  50. log.log(Level.SEVERE, "Exception while loading " + location, e);
  51. }
  52. }
  53. }
  54. //=====================================================================
  55. //Function: addUser
  56. //Input: Player player: The player to create a profile for
  57. //Output: none
  58. //Use: Loads the profile for the specified player
  59. //=====================================================================
  60. public static void addUser(Player player){
  61. players.addPlayer(player);
  62. }
  63. //=====================================================================
  64. //Function: removeUser
  65. //Input: Player player: The player to stop following
  66. //Output: none
  67. //Use: Creates the player profile
  68. //=====================================================================
  69. public static void removeUser(Player player){
  70. players.removePlayer(player);
  71. }
  72. //=====================================================================
  73. //Function: getProfile
  74. //Input: Player player: The player to find the profile for
  75. //Output: PlayerList.PlayerProfile: The profile
  76. //Use: Gets the player profile
  77. //=====================================================================
  78. public static PlayerList.PlayerProfile getProfile(Player player){
  79. return players.findProfile(player);
  80. }
  81. public static mcUsers getInstance() {
  82. if (instance == null) {
  83. instance = new mcUsers();
  84. }
  85. return instance;
  86. }
  87. public static void getRow(){
  88. }
  89. }
  90. class PlayerList
  91. {
  92. protected static final Logger log = Logger.getLogger("Minecraft");
  93. ArrayList<PlayerProfile> players;
  94. //=====================================================================
  95. //Function: PlayerList
  96. //Input: Player player: The player to create a profile object for
  97. //Output: none
  98. //Use: Initializes the ArrayList
  99. //=====================================================================
  100. public PlayerList() { players = new ArrayList<PlayerProfile>(); }
  101. //=====================================================================
  102. //Function: addPlayer
  103. //Input: Player player: The player to add
  104. //Output: None
  105. //Use: Add a profile of the specified player
  106. //=====================================================================
  107. public void addPlayer(Player player)
  108. {
  109. players.add(new PlayerProfile(player));
  110. }
  111. //=====================================================================
  112. //Function: removePlayer
  113. //Input: Player player: The player to remove
  114. //Output: None
  115. //Use: Remove the profile of the specified player
  116. //=====================================================================
  117. public void removePlayer(Player player)
  118. {
  119. players.remove(findProfile(player));
  120. }
  121. //=====================================================================
  122. //Function: findProfile
  123. //Input: Player player: The player to find's profile
  124. //Output: PlayerProfile: The profile of the specified player
  125. //Use: Get the profile for the specified player
  126. //=====================================================================
  127. public PlayerProfile findProfile(Player player)
  128. {
  129. for(PlayerProfile ply : players)
  130. {
  131. if(ply.isPlayer(player))
  132. return ply;
  133. }
  134. return null;
  135. }
  136. class PlayerProfile
  137. {
  138. protected final Logger log = Logger.getLogger("Minecraft");
  139. private String playerName, gather, wgather, woodcutting, repair, mining, party, myspawn, unarmed, herbalism, excavation,
  140. archery, swords, axes, invite, acrobatics, repairgather, unarmedgather, herbalismgather, excavationgather, archerygather, swordsgather, axesgather, acrobaticsgather;
  141. private boolean dead;
  142. char defaultColor;
  143. String location = "mcmmo.users";
  144. //=====================================================================
  145. //Function: PlayerProfile
  146. //Input: Player player: The player to create a profile object for
  147. //Output: none
  148. //Use: Loads settings for the player or creates them if they don't
  149. // exist.
  150. //=====================================================================
  151. public PlayerProfile(Player player)
  152. {
  153. //Declare things
  154. playerName = player.getName();
  155. party = new String();
  156. myspawn = new String();
  157. mining = new String();
  158. repair = new String();
  159. repairgather = new String();
  160. unarmed = new String();
  161. unarmedgather = new String();
  162. herbalism = new String();
  163. herbalismgather = new String();
  164. excavation = new String();
  165. excavationgather = new String();
  166. archery = new String();
  167. archerygather = new String();
  168. swords = new String();
  169. swordsgather = new String();
  170. axes = new String();
  171. axesgather = new String();
  172. acrobatics = new String();
  173. acrobaticsgather = new String();
  174. invite = new String();
  175. //mining = "0";
  176. wgather = new String();
  177. //wgather = "0";
  178. woodcutting = new String();
  179. //woodcutting = "0";
  180. gather = new String();
  181. //gather = "0";
  182. party = null;
  183. dead = false;
  184. //Try to load the player and if they aren't found, append them
  185. if(!load())
  186. addPlayer();
  187. }
  188. public boolean load()
  189. {
  190. try {
  191. //Open the user file
  192. FileReader file = new FileReader(location);
  193. BufferedReader in = new BufferedReader(file);
  194. String line = "";
  195. while((line = in.readLine()) != null)
  196. {
  197. //Find if the line contains the player we want.
  198. String[] character = line.split(":");
  199. if(!character[0].equals(playerName)){continue;}
  200. //Get Mining
  201. if(character.length > 1)
  202. mining = character[1];
  203. //Myspawn
  204. if(character.length > 2)
  205. myspawn = character[2];
  206. //Party
  207. if(character.length > 3)
  208. party = character[3];
  209. //Mining Gather
  210. if(character.length > 4)
  211. gather = character[4];
  212. if(character.length > 5)
  213. woodcutting = character[5];
  214. if(character.length > 6)
  215. wgather = character[6];
  216. if(character.length > 7)
  217. repair = character[7];
  218. if(character.length > 8)
  219. unarmed = character[8];
  220. if(character.length > 9)
  221. herbalism = character[9];
  222. if(character.length > 10)
  223. excavation = character[10];
  224. if(character.length > 11)
  225. archery = character[11];
  226. if(character.length > 12)
  227. swords = character[12];
  228. if(character.length > 13)
  229. axes = character[13];
  230. if(character.length > 14)
  231. acrobatics = character[14];
  232. if(character.length > 15)
  233. repairgather = character[15];
  234. if(character.length > 16)
  235. unarmedgather = character[16];
  236. if(character.length > 17)
  237. herbalismgather = character[17];
  238. if(character.length > 18)
  239. excavationgather = character[18];
  240. if(character.length > 19)
  241. archerygather = character[19];
  242. if(character.length > 20)
  243. swordsgather = character[20];
  244. if(character.length > 21)
  245. axesgather = character[21];
  246. if(character.length > 22)
  247. acrobaticsgather = character[22];
  248. in.close();
  249. return true;
  250. }
  251. in.close();
  252. } catch (Exception e) {
  253. log.log(Level.SEVERE, "Exception while reading "
  254. + location + " (Are you sure you formatted it correctly?)", e);
  255. }
  256. return false;
  257. }
  258. //=====================================================================
  259. // Function: save
  260. // Input: none
  261. // Output: None
  262. // Use: Writes current values of PlayerProfile to disk
  263. // Call this function to save current values
  264. //=====================================================================
  265. public void save()
  266. {
  267. try {
  268. //Open the file
  269. FileReader file = new FileReader(location);
  270. BufferedReader in = new BufferedReader(file);
  271. StringBuilder writer = new StringBuilder();
  272. String line = "";
  273. //While not at the end of the file
  274. while((line = in.readLine()) != null)
  275. {
  276. //Read the line in and copy it to the output it's not the player
  277. //we want to edit
  278. if(!line.split(":")[0].equalsIgnoreCase(playerName))
  279. {
  280. writer.append(line).append("\r\n");
  281. //Otherwise write the new player information
  282. } else {
  283. writer.append(playerName + ":");
  284. writer.append(mining + ":");
  285. writer.append(myspawn + ":");
  286. writer.append(party+":");
  287. writer.append(gather+":");
  288. writer.append(woodcutting+":");
  289. writer.append(wgather+":");
  290. writer.append(repair+":");
  291. writer.append(unarmed+":");
  292. writer.append(herbalism+":");
  293. writer.append(excavation+":");
  294. writer.append(archery+":");
  295. writer.append(swords+":");
  296. writer.append(axes+":");
  297. writer.append(acrobatics+":");
  298. writer.append(repairgather+":");
  299. writer.append(unarmedgather+":");
  300. writer.append(herbalismgather+":");
  301. writer.append(excavationgather+":");
  302. writer.append(archerygather+":");
  303. writer.append(swordsgather+":");
  304. writer.append(axesgather+":");
  305. writer.append(acrobaticsgather+":");
  306. writer.append("\r\n");
  307. }
  308. }
  309. in.close();
  310. //Write the new file
  311. FileWriter out = new FileWriter(location);
  312. out.write(writer.toString());
  313. out.close();
  314. } catch (Exception e) {
  315. log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e);
  316. }
  317. }
  318. public void addPlayer()
  319. {
  320. try {
  321. //Open the file to write the player
  322. FileWriter file = new FileWriter(location, true);
  323. BufferedWriter out = new BufferedWriter(file);
  324. //Add the player to the end
  325. out.append(playerName + ":");
  326. out.append(0 + ":"); //mining
  327. out.append(myspawn+":");
  328. out.append(party+":");
  329. out.append(0+":"); //gather
  330. out.append(0+":"); //woodcutting
  331. out.append(0+":"); //wgather
  332. out.append(0+":"); //repair
  333. out.append(0+":"); //unarmed
  334. out.append(0+":"); //herbalism
  335. out.append(0+":"); //excavation
  336. out.append(0+":"); //archery
  337. out.append(0+":"); //swords
  338. out.append(0+":"); //axes
  339. out.append(0+":"); //acrobatics
  340. out.append(0+":"); //repairgather
  341. out.append(0+":"); //unarmedgather
  342. out.append(0+":"); //herbalismgather
  343. out.append(0+":"); //excavationgather
  344. out.append(0+":"); //archerygather
  345. out.append(0+":"); //swordsgather
  346. out.append(0+":"); //axesgather
  347. out.append(0+":"); //acrobaticsgather
  348. //Add more in the same format as the line above
  349. out.newLine();
  350. out.close();
  351. } catch (Exception e) {
  352. log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e);
  353. }
  354. }
  355. //=====================================================================
  356. //Function: isPlayer
  357. //Input: None
  358. //Output: Player: The player this profile belongs to
  359. //Use: Finds if this profile belongs to a specified player
  360. //=====================================================================
  361. public boolean isPlayer(Player player)
  362. {
  363. return player.getName().equals(playerName);
  364. }
  365. public void skillUpAxes(int newskill){
  366. int x = 0;
  367. if(axes != null){
  368. if(isInt(axes)){
  369. x = Integer.parseInt(axes);
  370. }else {
  371. axes = "0";
  372. x = Integer.parseInt(axes);
  373. }
  374. }
  375. x += newskill;
  376. axes = Integer.toString(x);
  377. save();
  378. }
  379. public void skillUpAcrobatics(int newskill){
  380. int x = 0;
  381. if(acrobatics != null){
  382. if(isInt(acrobatics)){
  383. x = Integer.parseInt(acrobatics);
  384. }else {
  385. acrobatics = "0";
  386. x = Integer.parseInt(acrobatics);
  387. }
  388. }
  389. x += newskill;
  390. acrobatics = Integer.toString(x);
  391. save();
  392. }
  393. public void skillUpSwords(int newskill){
  394. int x = 0;
  395. if(swords != null){
  396. if(isInt(swords)){
  397. x = Integer.parseInt(swords);
  398. }else {
  399. swords = "0";
  400. x = Integer.parseInt(swords);
  401. }
  402. }
  403. x += newskill;
  404. swords = Integer.toString(x);
  405. save();
  406. }
  407. public void skillUpArchery(int newskill){
  408. int x = 0;
  409. if(archery != null){
  410. if(isInt(archery)){
  411. x = Integer.parseInt(archery);
  412. }else {
  413. archery = "0";
  414. x = Integer.parseInt(archery);
  415. }
  416. }
  417. x += newskill;
  418. archery = Integer.toString(x);
  419. save();
  420. }
  421. public void skillUpRepair(int newskill){
  422. int x = 0;
  423. if(repair != null){
  424. if(isInt(repair)){
  425. x = Integer.parseInt(repair);
  426. }else {
  427. repair = "0";
  428. x = Integer.parseInt(repair);
  429. }
  430. }
  431. x += newskill;
  432. repair = Integer.toString(x);
  433. save();
  434. }
  435. public void skillUpMining(int newmining){
  436. int x = 0;
  437. if(mining != null){
  438. if(isInt(mining)){
  439. x = Integer.parseInt(mining);
  440. }else {
  441. mining = "0";
  442. x = Integer.parseInt(mining);
  443. }
  444. }
  445. x += newmining;
  446. mining = Integer.toString(x);
  447. save();
  448. }
  449. public void skillUpUnarmed(int newskill){
  450. int x = 0;
  451. if(unarmed != null){
  452. if(isInt(unarmed)){
  453. x = Integer.parseInt(unarmed);
  454. }else {
  455. unarmed = "0";
  456. x = Integer.parseInt(unarmed);
  457. }
  458. }
  459. x += newskill;
  460. unarmed = Integer.toString(x);
  461. save();
  462. }
  463. public void skillUpHerbalism(int newskill){
  464. int x = 0;
  465. if(herbalism != null){
  466. if(isInt(herbalism)){
  467. x = Integer.parseInt(herbalism);
  468. }else {
  469. herbalism = "0";
  470. x = Integer.parseInt(herbalism);
  471. }
  472. }
  473. x += newskill;
  474. herbalism = Integer.toString(x);
  475. save();
  476. }
  477. public void skillUpExcavation(int newskill){
  478. int x = 0;
  479. if(excavation != null){
  480. if(isInt(excavation)){
  481. x = Integer.parseInt(excavation);
  482. }else {
  483. excavation = "0";
  484. x = Integer.parseInt(excavation);
  485. }
  486. }
  487. x += newskill;
  488. excavation = Integer.toString(x);
  489. save();
  490. }
  491. public void skillUpWoodCutting(int newskill){
  492. int x = 0;
  493. if(woodcutting != null){
  494. if(isInt(woodcutting)){
  495. x = Integer.parseInt(woodcutting);
  496. }else {
  497. woodcutting = "0";
  498. x = Integer.parseInt(woodcutting);
  499. }
  500. }
  501. x += newskill;
  502. woodcutting = Integer.toString(x);
  503. save();
  504. }
  505. public String getRepair(){
  506. if(repair != null && !repair.equals("") && !repair.equals("null")){
  507. return repair;
  508. } else {
  509. return "0";
  510. }
  511. }
  512. public String getMining(){
  513. if(mining != null && !mining.equals("") && !mining.equals("null")){
  514. return mining;
  515. } else {
  516. return "0";
  517. }
  518. }
  519. public String getUnarmed(){
  520. if(unarmed != null && !unarmed.equals("") && !unarmed.equals("null")){
  521. return unarmed;
  522. } else {
  523. return "0";
  524. }
  525. }
  526. public String getHerbalism(){
  527. if(herbalism != null && !herbalism.equals("") && !herbalism.equals("null")){
  528. return herbalism;
  529. } else {
  530. return "0";
  531. }
  532. }
  533. public String getExcavation(){
  534. if(excavation != null && !excavation.equals("") && !excavation.equals("null")){
  535. return excavation;
  536. } else {
  537. return "0";
  538. }
  539. }
  540. public String getArchery(){
  541. if(archery != null && !archery.equals("") && !archery.equals("null")){
  542. return archery;
  543. } else {
  544. return "0";
  545. }
  546. }
  547. public String getSwords(){
  548. if(swords != null && !swords.equals("") && !swords.equals("null")){
  549. return swords;
  550. } else {
  551. return "0";
  552. }
  553. }
  554. public String getAxes(){
  555. if(axes != null && !axes.equals("") && !axes.equals("null")){
  556. return axes;
  557. } else {
  558. return "0";
  559. }
  560. }
  561. public String getAcrobatics(){
  562. if(acrobatics != null && !acrobatics.equals("") && !acrobatics.equals("null")){
  563. return acrobatics;
  564. } else {
  565. return "0";
  566. }
  567. }
  568. public int getMiningInt(){
  569. if(isInt(mining)){
  570. int x = Integer.parseInt(mining);
  571. return x;
  572. } else{
  573. return 0;
  574. }
  575. }
  576. public int getUnarmedInt(){
  577. if(isInt(unarmed)){
  578. int x = Integer.parseInt(unarmed);
  579. return x;
  580. } else{
  581. return 0;
  582. }
  583. }
  584. public int getArcheryInt(){
  585. if(isInt(archery)){
  586. int x = Integer.parseInt(archery);
  587. return x;
  588. } else{
  589. return 0;
  590. }
  591. }
  592. public int getSwordsInt(){
  593. if(isInt(swords)){
  594. int x = Integer.parseInt(swords);
  595. return x;
  596. } else{
  597. return 0;
  598. }
  599. }
  600. public int getAxesInt(){
  601. if(isInt(axes)){
  602. int x = Integer.parseInt(axes);
  603. return x;
  604. } else{
  605. return 0;
  606. }
  607. }
  608. public int getAcrobaticsInt(){
  609. if(isInt(acrobatics)){
  610. int x = Integer.parseInt(acrobatics);
  611. return x;
  612. } else{
  613. return 0;
  614. }
  615. }
  616. public int getHerbalismInt(){
  617. if(isInt(herbalism)){
  618. int x = Integer.parseInt(herbalism);
  619. return x;
  620. } else{
  621. return 0;
  622. }
  623. }
  624. public int getExcavationInt(){
  625. if(isInt(excavation)){
  626. int x = Integer.parseInt(excavation);
  627. return x;
  628. } else{
  629. return 0;
  630. }
  631. }
  632. public int getRepairInt(){
  633. if(isInt(repair)){
  634. int x = Integer.parseInt(repair);
  635. return x;
  636. } else{
  637. return 0;
  638. }
  639. }
  640. public int getWoodCuttingInt(){
  641. if(isInt(woodcutting)){
  642. int x = Integer.parseInt(woodcutting);
  643. return x;
  644. } else{
  645. return 0;
  646. }
  647. }
  648. public String getWoodCutting(){
  649. if(woodcutting != null && !woodcutting.equals("") && !woodcutting.equals("null")){
  650. return woodcutting;
  651. } else {
  652. return "0";
  653. }
  654. }
  655. /*
  656. * EXPERIENCE STUFF
  657. */
  658. public void clearRepairGather(){
  659. repairgather = "0";
  660. }
  661. public void clearUnarmedGather(){
  662. unarmedgather = "0";
  663. }
  664. public void clearHerbalismGather(){
  665. herbalismgather = "0";
  666. }
  667. public void clearExcavationGather(){
  668. excavationgather = "0";
  669. }
  670. public void clearArcheryGather(){
  671. archerygather = "0";
  672. }
  673. public void clearSwordsGather(){
  674. swordsgather = "0";
  675. }
  676. public void clearAxesGather(){
  677. axesgather = "0";
  678. }
  679. public void clearAcrobaticsGather(){
  680. acrobaticsgather = "0";
  681. }
  682. public void addAcrobaticsGather(int newgather)
  683. {
  684. int x = 0;
  685. if(isInt(acrobaticsgather)){
  686. x = Integer.parseInt(acrobaticsgather);
  687. }
  688. x += newgather;
  689. acrobaticsgather = String.valueOf(x);
  690. save();
  691. }
  692. public void addAxesGather(int newgather)
  693. {
  694. int x = 0;
  695. if(isInt(axesgather)){
  696. x = Integer.parseInt(axesgather);
  697. }
  698. x += newgather;
  699. axesgather = String.valueOf(x);
  700. save();
  701. }
  702. public void addSwordsGather(int newgather)
  703. {
  704. int x = 0;
  705. if(isInt(swordsgather)){
  706. x = Integer.parseInt(swordsgather);
  707. }
  708. x += newgather;
  709. swordsgather = String.valueOf(x);
  710. save();
  711. }
  712. public void addArcheryGather(int newgather)
  713. {
  714. int x = 0;
  715. if(isInt(archerygather)){
  716. x = Integer.parseInt(archerygather);
  717. }
  718. x += newgather;
  719. archerygather = String.valueOf(x);
  720. save();
  721. }
  722. public void addExcavationGather(int newgather)
  723. {
  724. int x = 0;
  725. if(isInt(excavationgather)){
  726. x = Integer.parseInt(excavationgather);
  727. }
  728. x += newgather;
  729. excavationgather = String.valueOf(x);
  730. save();
  731. }
  732. public void addHerbalismGather(int newgather)
  733. {
  734. int x = 0;
  735. if(isInt(herbalismgather)){
  736. x = Integer.parseInt(herbalismgather);
  737. }
  738. x += newgather;
  739. herbalismgather = String.valueOf(x);
  740. save();
  741. }
  742. public void addRepairGather(int newgather)
  743. {
  744. int x = 0;
  745. if(isInt(repairgather)){
  746. x = Integer.parseInt(repairgather);
  747. }
  748. x += newgather;
  749. repairgather = String.valueOf(x);
  750. save();
  751. }
  752. public void addUnarmedGather(int newgather)
  753. {
  754. int x = 0;
  755. if(isInt(unarmedgather)){
  756. x = Integer.parseInt(unarmedgather);
  757. }
  758. x += newgather;
  759. unarmedgather = String.valueOf(x);
  760. save();
  761. }
  762. public void addWoodcuttingGather(int newgather)
  763. {
  764. int x = 0;
  765. if(isInt(wgather)){
  766. x = Integer.parseInt(wgather);
  767. }
  768. x += newgather;
  769. wgather = String.valueOf(x);
  770. save();
  771. }
  772. public void removeWoodCuttingGather(int newgather){
  773. int x = 0;
  774. if(isInt(wgather)){
  775. x = Integer.parseInt(wgather);
  776. }
  777. x -= newgather;
  778. wgather = String.valueOf(x);
  779. save();
  780. }
  781. public void addMiningGather(int newgather)
  782. {
  783. int x = 0;
  784. if(isInt(gather)){
  785. x = Integer.parseInt(gather);
  786. } else {
  787. x = 0;
  788. }
  789. x += newgather;
  790. gather = String.valueOf(x);
  791. save();
  792. }
  793. public void removeMiningGather(int newgather){
  794. int x = 0;
  795. if(isInt(gather)){
  796. x = Integer.parseInt(gather);
  797. }
  798. x -= newgather;
  799. gather = String.valueOf(x);
  800. save();
  801. }
  802. public void removeRepairGather(int newgather){
  803. int x = 0;
  804. if(isInt(repairgather)){
  805. x = Integer.parseInt(repairgather);
  806. }
  807. x -= newgather;
  808. repairgather = String.valueOf(x);
  809. save();
  810. }
  811. public void removeUnarmedGather(int newgather){
  812. int x = 0;
  813. if(isInt(unarmedgather)){
  814. x = Integer.parseInt(unarmedgather);
  815. }
  816. x -= newgather;
  817. unarmedgather = String.valueOf(x);
  818. save();
  819. }
  820. public void removeHerbalismGather(int newgather){
  821. int x = 0;
  822. if(isInt(herbalismgather)){
  823. x = Integer.parseInt(herbalismgather);
  824. }
  825. x -= newgather;
  826. herbalismgather = String.valueOf(x);
  827. save();
  828. }
  829. public void removeExcavationGather(int newgather){
  830. int x = 0;
  831. if(isInt(excavationgather)){
  832. x = Integer.parseInt(excavationgather);
  833. }
  834. x -= newgather;
  835. excavationgather = String.valueOf(x);
  836. save();
  837. }
  838. public void removeArcheryGather(int newgather){
  839. int x = 0;
  840. if(isInt(archerygather)){
  841. x = Integer.parseInt(archerygather);
  842. }
  843. x -= newgather;
  844. archerygather = String.valueOf(x);
  845. save();
  846. }
  847. public void removeSwordsGather(int newgather){
  848. int x = 0;
  849. if(isInt(swordsgather)){
  850. x = Integer.parseInt(swordsgather);
  851. }
  852. x -= newgather;
  853. swordsgather = String.valueOf(x);
  854. save();
  855. }
  856. public void removeAxesGather(int newgather){
  857. int x = 0;
  858. if(isInt(axesgather)){
  859. x = Integer.parseInt(axesgather);
  860. }
  861. x -= newgather;
  862. axesgather = String.valueOf(x);
  863. save();
  864. }
  865. public void removeAcrobaticsGather(int newgather){
  866. int x = 0;
  867. if(isInt(acrobaticsgather)){
  868. x = Integer.parseInt(acrobaticsgather);
  869. }
  870. x -= newgather;
  871. acrobaticsgather = String.valueOf(x);
  872. save();
  873. }
  874. public boolean isInt(String string){
  875. try {
  876. int x = Integer.parseInt(string);
  877. }
  878. catch(NumberFormatException nFE) {
  879. return false;
  880. }
  881. return true;
  882. }
  883. public boolean isDouble(String string){
  884. try {
  885. Double x = Double.valueOf(string);
  886. }
  887. catch(NumberFormatException nFE) {
  888. return false;
  889. }
  890. return true;
  891. }
  892. public void acceptInvite(){
  893. party = invite;
  894. invite = "";
  895. save();
  896. }
  897. public void modifyInvite(String invitename){
  898. invite = invitename;
  899. }
  900. //Returns player gather
  901. public String getMiningGather(){
  902. if(gather != null && !gather.equals("") && !gather.equals("null")){
  903. return gather;
  904. } else {
  905. return "0";
  906. }
  907. }
  908. public String getInvite() { return invite; }
  909. public String getWoodCuttingGather(){
  910. if(wgather != null && !wgather.equals("") && !wgather.equals("null")){
  911. return wgather;
  912. } else {
  913. return "0";
  914. }
  915. }
  916. public String getRepairGather(){
  917. if(repairgather != null && !repairgather.equals("") && !repairgather.equals("null")){
  918. return repairgather;
  919. } else {
  920. return "0";
  921. }
  922. }
  923. public String getHerbalismGather(){
  924. if(herbalismgather != null && !herbalismgather.equals("") && !herbalismgather.equals("null")){
  925. return herbalismgather;
  926. } else {
  927. return "0";
  928. }
  929. }
  930. public String getExcavationGather(){
  931. if(excavationgather != null && !excavationgather.equals("") && !excavationgather.equals("null")){
  932. return excavationgather;
  933. } else {
  934. return "0";
  935. }
  936. }
  937. public String getArcheryGather(){
  938. if(archerygather != null && !archerygather.equals("") && !archerygather.equals("null")){
  939. return archerygather;
  940. } else {
  941. return "0";
  942. }
  943. }
  944. public String getSwordsGather(){
  945. if(swordsgather != null && !swordsgather.equals("") && !swordsgather.equals("null")){
  946. return swordsgather;
  947. } else {
  948. return "0";
  949. }
  950. }
  951. public String getAxesGather(){
  952. if(axesgather != null && !axesgather.equals("") && !axesgather.equals("null")){
  953. return axesgather;
  954. } else {
  955. return "0";
  956. }
  957. }
  958. public String getAcrobaticsGather(){
  959. if(acrobaticsgather != null && !acrobaticsgather.equals("") && !acrobaticsgather.equals("null")){
  960. return acrobaticsgather;
  961. } else {
  962. return "0";
  963. }
  964. }
  965. public String getUnarmedGather(){
  966. if(unarmedgather != null && !unarmedgather.equals("") && !unarmedgather.equals("null")){
  967. return unarmedgather;
  968. } else {
  969. return "0";
  970. }
  971. }
  972. public int getWoodCuttingGatherInt() {
  973. if(isInt(wgather)){
  974. return Integer.parseInt(wgather);
  975. } else {
  976. wgather = "0";
  977. save();
  978. return 0;
  979. }
  980. }
  981. public int getRepairGatherInt() {
  982. if(isInt(repairgather)){
  983. return Integer.parseInt(repairgather);
  984. } else {
  985. repairgather = "0";
  986. save();
  987. return 0;
  988. }
  989. }
  990. public int getUnarmedGatherInt() {
  991. if(isInt(unarmedgather)){
  992. return Integer.parseInt(unarmedgather);
  993. } else {
  994. unarmedgather = "0";
  995. save();
  996. return 0;
  997. }
  998. }
  999. public int getHerbalismGatherInt() {
  1000. if(isInt(herbalismgather)){
  1001. return Integer.parseInt(herbalismgather);
  1002. } else {
  1003. herbalismgather = "0";
  1004. save();
  1005. return 0;
  1006. }
  1007. }
  1008. public int getExcavationGatherInt() {
  1009. if(isInt(excavationgather)){
  1010. return Integer.parseInt(excavationgather);
  1011. } else {
  1012. excavationgather = "0";
  1013. save();
  1014. return 0;
  1015. }
  1016. }
  1017. public int getArcheryGatherInt() {
  1018. if(isInt(archerygather)){
  1019. return Integer.parseInt(archerygather);
  1020. } else {
  1021. archerygather = "0";
  1022. save();
  1023. return 0;
  1024. }
  1025. }
  1026. public int getSwordsGatherInt() {
  1027. if(isInt(swordsgather)){
  1028. return Integer.parseInt(swordsgather);
  1029. } else {
  1030. swordsgather = "0";
  1031. save();
  1032. return 0;
  1033. }
  1034. }
  1035. public int getAxesGatherInt() {
  1036. if(isInt(axesgather)){
  1037. return Integer.parseInt(axesgather);
  1038. } else {
  1039. axesgather = "0";
  1040. save();
  1041. return 0;
  1042. }
  1043. }
  1044. public int getAcrobaticsGatherInt() {
  1045. if(isInt(acrobaticsgather)){
  1046. return Integer.parseInt(acrobaticsgather);
  1047. } else {
  1048. acrobaticsgather = "0";
  1049. save();
  1050. return 0;
  1051. }
  1052. }
  1053. public void modifyskill(int newvalue, String skillname){
  1054. if(skillname.equals("mining")){
  1055. mining = String.valueOf(newvalue);
  1056. }
  1057. if(skillname.equals("woodcutting")){
  1058. woodcutting = String.valueOf(newvalue);
  1059. }
  1060. if(skillname.equals("repair")){
  1061. repair = String.valueOf(newvalue);
  1062. }
  1063. if(skillname.equals("herbalism")){
  1064. herbalism = String.valueOf(newvalue);
  1065. }
  1066. if(skillname.equals("acrobatics")){
  1067. acrobatics = String.valueOf(newvalue);
  1068. }
  1069. if(skillname.equals("swords")){
  1070. swords = String.valueOf(newvalue);
  1071. }
  1072. if(skillname.equals("archery")){
  1073. archery = String.valueOf(newvalue);
  1074. }
  1075. if(skillname.equals("unarmed")){
  1076. unarmed = String.valueOf(newvalue);
  1077. }
  1078. if(skillname.equals("excavation")){
  1079. excavation = String.valueOf(newvalue);
  1080. }
  1081. if(skillname.equals("axes")){
  1082. axes = String.valueOf(newvalue);
  1083. }
  1084. save();
  1085. }
  1086. public int getMiningGatherInt() {
  1087. if(isInt(gather)){
  1088. return Integer.parseInt(gather);
  1089. } else {
  1090. gather = "0";
  1091. save();
  1092. return 0;
  1093. }
  1094. }
  1095. //Store the player's party
  1096. public void setParty(String newParty)
  1097. {
  1098. party = newParty;
  1099. save();
  1100. }
  1101. //Retrieve the player's party
  1102. public String getParty() {return party;}
  1103. //Remove party
  1104. public void removeParty() {
  1105. party = null;
  1106. save();
  1107. }
  1108. //Retrieve whether or not the player is in a party
  1109. public boolean inParty() {
  1110. if(party != null && !party.equals("") && !party.equals("null")){
  1111. return true;
  1112. } else {
  1113. return false;
  1114. }
  1115. }
  1116. //Retrieve whether or not the player has an invite
  1117. public boolean hasPartyInvite() {
  1118. if(invite != null && !invite.equals("") && !invite.equals("null")){
  1119. return true;
  1120. } else {
  1121. return false;
  1122. }
  1123. }
  1124. //Save a users spawn location
  1125. public void setMySpawn(double x, double y, double z){
  1126. myspawn = x+","+y+","+z;
  1127. save();
  1128. }
  1129. public String getX(){
  1130. String[] split = myspawn.split(",");
  1131. String x = split[0];
  1132. return x;
  1133. }
  1134. public String getY(){
  1135. String[] split = myspawn.split(",");
  1136. String y = split[1];
  1137. return y;
  1138. }
  1139. public String getZ(){
  1140. String[] split = myspawn.split(",");
  1141. String z = split[2];
  1142. return z;
  1143. }
  1144. public void setDead(boolean x){
  1145. dead = x;
  1146. save();
  1147. }
  1148. public boolean isDead(){
  1149. return dead;
  1150. }
  1151. public Location getMySpawn(Player player){
  1152. Location loc = player.getLocation();
  1153. if(isDouble(getX()) && isDouble(getY()) && isDouble(getX())){
  1154. loc.setX(Double.parseDouble(mcUsers.getProfile(player).getX()));
  1155. loc.setY(Double.parseDouble(mcUsers.getProfile(player).getY()));
  1156. loc.setZ(Double.parseDouble(mcUsers.getProfile(player).getZ()));
  1157. } else {
  1158. return null;
  1159. }
  1160. loc.setYaw(0);
  1161. loc.setPitch(0);
  1162. return loc;
  1163. }
  1164. }
  1165. }