SQLConversionTask.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. package com.gmail.nossr50.database.runnables;
  2. import java.io.BufferedReader;
  3. import java.io.FileReader;
  4. import com.gmail.nossr50.mcMMO;
  5. import com.gmail.nossr50.config.Config;
  6. import com.gmail.nossr50.database.Database;
  7. import com.gmail.nossr50.util.Misc;
  8. import com.gmail.nossr50.util.StringUtils;
  9. public class SQLConversionTask implements Runnable {
  10. private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
  11. @Override
  12. public void run() {
  13. String location = mcMMO.getUsersFilePath();
  14. try {
  15. FileReader file = new FileReader(location);
  16. BufferedReader in = new BufferedReader(file);
  17. String line = "";
  18. String playerName = null;
  19. //String party = null;
  20. String mining = null;
  21. String woodcutting = null;
  22. String repair = null;
  23. String unarmed = null;
  24. String herbalism = null;
  25. String excavation = null;
  26. String archery = null;
  27. String swords = null;
  28. String axes = null;
  29. String acrobatics = null;
  30. String taming = null;
  31. String fishing = null;
  32. String miningXP = null;
  33. String woodCuttingXP = null;
  34. String repairXP = null;
  35. String unarmedXP = null;
  36. String herbalismXP = null;
  37. String excavationXP = null;
  38. String archeryXP = null;
  39. String swordsXP = null;
  40. String axesXP = null;
  41. String acrobaticsXP = null;
  42. String tamingXP = null;
  43. String fishingXP = null;
  44. int id = 0;
  45. int theCount = 0;
  46. while ((line = in.readLine()) != null) {
  47. //Find if the line contains the player we want.
  48. String[] character = line.split(":");
  49. playerName = character[0];
  50. //Check for things we don't want put in the DB
  51. if (playerName == null || playerName.equals("null") || playerName.equals("#Storage place for user information")) {
  52. continue;
  53. }
  54. if (character.length > 1) {
  55. mining = character[1];
  56. }
  57. /*
  58. * Looks like we still have party as the 4th string in the array but we don't use it anymore
  59. if (character.length > 3) {
  60. party = character[3];
  61. }
  62. */
  63. if (character.length > 4) {
  64. miningXP = character[4];
  65. }
  66. if (character.length > 5) {
  67. woodcutting = character[5];
  68. }
  69. if (character.length > 6) {
  70. woodCuttingXP = character[6];
  71. }
  72. if (character.length > 7) {
  73. repair = character[7];
  74. }
  75. if (character.length > 8) {
  76. unarmed = character[8];
  77. }
  78. if (character.length > 9) {
  79. herbalism = character[9];
  80. }
  81. if (character.length > 10) {
  82. excavation = character[10];
  83. }
  84. if (character.length > 11) {
  85. archery = character[11];
  86. }
  87. if (character.length > 12) {
  88. swords = character[12];
  89. }
  90. if (character.length > 13) {
  91. axes = character[13];
  92. }
  93. if (character.length > 14) {
  94. acrobatics = character[14];
  95. }
  96. if (character.length > 15) {
  97. repairXP = character[15];
  98. }
  99. if (character.length > 16) {
  100. unarmedXP = character[16];
  101. }
  102. if (character.length > 17) {
  103. herbalismXP = character[17];
  104. }
  105. if (character.length > 18) {
  106. excavationXP = character[18];
  107. }
  108. if (character.length > 19) {
  109. archeryXP = character[19];
  110. }
  111. if (character.length > 20) {
  112. swordsXP = character[20];
  113. }
  114. if (character.length > 21) {
  115. axesXP = character[21];
  116. }
  117. if (character.length > 22) {
  118. acrobaticsXP = character[22];
  119. }
  120. if (character.length > 24) {
  121. taming = character[24];
  122. }
  123. if (character.length > 25) {
  124. tamingXP = character[25];
  125. }
  126. if (character.length > 34) {
  127. fishing = character[34];
  128. }
  129. if (character.length > 35) {
  130. fishingXP = character[35];
  131. }
  132. //Check to see if the user is in the DB
  133. id = Database.getInt("SELECT id FROM "
  134. + tablePrefix
  135. + "users WHERE user = '" + playerName + "'");
  136. if (id > 0) {
  137. theCount++;
  138. //Update the skill values
  139. Database.write("UPDATE "
  140. + tablePrefix
  141. + "users SET lastlogin = " + 0
  142. + " WHERE id = " + id);
  143. Database.write("UPDATE "
  144. + tablePrefix
  145. + "skills SET "
  146. + " taming = taming+" + StringUtils.getInt(taming)
  147. + ", mining = mining+" + StringUtils.getInt(mining)
  148. + ", repair = repair+" + StringUtils.getInt(repair)
  149. + ", woodcutting = woodcutting+" + StringUtils.getInt(woodcutting)
  150. + ", unarmed = unarmed+" + StringUtils.getInt(unarmed)
  151. + ", herbalism = herbalism+" + StringUtils.getInt(herbalism)
  152. + ", excavation = excavation+" + StringUtils.getInt(excavation)
  153. + ", archery = archery+" + StringUtils.getInt(archery)
  154. + ", swords = swords+" + StringUtils.getInt(swords)
  155. + ", axes = axes+" + StringUtils.getInt(axes)
  156. + ", acrobatics = acrobatics+" + StringUtils.getInt(acrobatics)
  157. + ", fishing = fishing+" + StringUtils.getInt(fishing)
  158. + " WHERE user_id = " + id);
  159. Database.write("UPDATE "
  160. + tablePrefix
  161. + "experience SET "
  162. + " taming = " + StringUtils.getInt(tamingXP)
  163. + ", mining = " + StringUtils.getInt(miningXP)
  164. + ", repair = " + StringUtils.getInt(repairXP)
  165. + ", woodcutting = " + StringUtils.getInt(woodCuttingXP)
  166. + ", unarmed = " + StringUtils.getInt(unarmedXP)
  167. + ", herbalism = " + StringUtils.getInt(herbalismXP)
  168. + ", excavation = " + StringUtils.getInt(excavationXP)
  169. + ", archery = " + StringUtils.getInt(archeryXP)
  170. + ", swords = " + StringUtils.getInt(swordsXP)
  171. + ", axes = " + StringUtils.getInt(axesXP)
  172. + ", acrobatics = " + StringUtils.getInt(acrobaticsXP)
  173. + ", fishing = " + StringUtils.getInt(fishingXP)
  174. + " WHERE user_id = " + id);
  175. }
  176. else {
  177. theCount++;
  178. //Create the user in the DB
  179. Database.write("INSERT INTO "
  180. + tablePrefix
  181. + "users (user, lastlogin) VALUES ('"
  182. + playerName + "',"
  183. + System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR + ")");
  184. id = Database.getInt("SELECT id FROM "
  185. + tablePrefix
  186. + "users WHERE user = '"
  187. + playerName + "'");
  188. Database.write("INSERT INTO "
  189. + tablePrefix
  190. + "skills (user_id) VALUES (" + id + ")");
  191. Database.write("INSERT INTO "
  192. + tablePrefix
  193. + "experience (user_id) VALUES (" + id
  194. + ")");
  195. //Update the skill values
  196. Database.write("UPDATE "
  197. + tablePrefix
  198. + "users SET lastlogin = " + 0
  199. + " WHERE id = " + id);
  200. /*
  201. Database.write("UPDATE "
  202. + tablePrefix
  203. + "users SET party = '" + party
  204. + "' WHERE id = " + id);
  205. */
  206. Database.write("UPDATE "
  207. + tablePrefix
  208. + "skills SET "
  209. + " taming = taming+" + StringUtils.getInt(taming)
  210. + ", mining = mining+" + StringUtils.getInt(mining)
  211. + ", repair = repair+" + StringUtils.getInt(repair)
  212. + ", woodcutting = woodcutting+" + StringUtils.getInt(woodcutting)
  213. + ", unarmed = unarmed+" + StringUtils.getInt(unarmed)
  214. + ", herbalism = herbalism+" + StringUtils.getInt(herbalism)
  215. + ", excavation = excavation+" + StringUtils.getInt(excavation)
  216. + ", archery = archery+" + StringUtils.getInt(archery)
  217. + ", swords = swords+" + StringUtils.getInt(swords)
  218. + ", axes = axes+" + StringUtils.getInt(axes)
  219. + ", acrobatics = acrobatics+" + StringUtils.getInt(acrobatics)
  220. + ", fishing = fishing+" + StringUtils.getInt(fishing)
  221. + " WHERE user_id = " + id);
  222. Database.write("UPDATE "
  223. + tablePrefix
  224. + "experience SET "
  225. + " taming = " + StringUtils.getInt(tamingXP)
  226. + ", mining = " + StringUtils.getInt(miningXP)
  227. + ", repair = " + StringUtils.getInt(repairXP)
  228. + ", woodcutting = " + StringUtils.getInt(woodCuttingXP)
  229. + ", unarmed = " + StringUtils.getInt(unarmedXP)
  230. + ", herbalism = " + StringUtils.getInt(herbalismXP)
  231. + ", excavation = " + StringUtils.getInt(excavationXP)
  232. + ", archery = " + StringUtils.getInt(archeryXP)
  233. + ", swords = " + StringUtils.getInt(swordsXP)
  234. + ", axes = " + StringUtils.getInt(axesXP)
  235. + ", acrobatics = " + StringUtils.getInt(acrobaticsXP)
  236. + ", fishing = " + StringUtils.getInt(fishingXP)
  237. + " WHERE user_id = " + id);
  238. }
  239. }
  240. mcMMO.p.getLogger().info("[mcMMO] MySQL Updated from users file, " + theCount + " items added/updated to MySQL DB");
  241. in.close();
  242. }
  243. catch (Exception e) {
  244. mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
  245. }
  246. }
  247. }