Guest User

Untitled

a guest
Nov 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.89 KB | None | 0 0
  1. package fr.thedarven.statistiques;
  2.  
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.text.DateFormat;
  9. import java.text.SimpleDateFormat;
  10. import java.util.Date;
  11.  
  12. import org.bukkit.ChatColor;
  13. import org.bukkit.Material;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16. import org.bukkit.potion.PotionEffect;
  17. import org.bukkit.potion.PotionEffectType;
  18. import fr.thedarven.events.Commandes;
  19. import fr.thedarven.events.EventsManager;
  20.  
  21. public class Statistiques extends JavaPlugin{
  22.  
  23. public SqlConnection sql;
  24. public static Statistiques instance;
  25. public static Statistiques getInstance(){
  26. return instance;
  27. }
  28.  
  29. // je propose que lorsqu'on tombe dans le vide, on est téléporté au spawn MAIS on perd 50% de notre stuff
  30. // COLLISION OFF
  31. public static float strength[] = {100,500,1000,5000,10000};
  32. public static float agility[] = {1000,10000,50000,100000,500000};
  33. public static float haste[] = {3456,17280,43200,86400,172800};
  34. public static float poison_resistance[] = {100,200,500,1000,5000};
  35. public static float fire_resistance[] = {100,200,500,1000,5000};
  36. public static float all_resistance[] = {500,1000,2000,5000,10000};
  37. public static float falling_resistance[] = {100,500,1000,2000,5000};
  38.  
  39. public static Material hasteExp[] = {Material.STONE, Material.COBBLESTONE, Material.SMOOTH_BRICK};
  40.  
  41. public void onEnable(){
  42. instance = this;
  43.  
  44. EventsManager.registerEvents(this);
  45. sql = new SqlConnection("jdbc:mysql://","localhost","semi-rp","root","");
  46. sql.connection();
  47.  
  48. try{
  49. File ff = new File("plugins//Statistiques//logs.txt");
  50. ff.createNewFile();
  51. FileWriter ffw=new FileWriter(ff, true);
  52. DateFormat dateFormat = new SimpleDateFormat("[dd/MM/yyyy][HH:mm:ss]");
  53. Date date = new Date();
  54. ffw.write(dateFormat.format(date)+" ==================== SERVEUR OUVERT ====================");
  55. ffw.write("\r\n");
  56. ffw.close();
  57. } catch (Exception ee) {}
  58.  
  59. getCommand("stats").setExecutor(new Commandes());
  60. }
  61.  
  62. public void onDisable(){
  63. sql.disconnect();
  64. try{
  65. File ff = new File("plugins//Statistiques//logs.txt");
  66. ff.createNewFile();
  67. FileWriter ffw=new FileWriter(ff, true);
  68. DateFormat dateFormat = new SimpleDateFormat("[dd/MM/yyyy][HH:mm:ss]");
  69. Date date = new Date();
  70. ffw.write(dateFormat.format(date)+" ==================== SERVEUR FERME ====================");
  71. ffw.write("\r\n");
  72. ffw.close();
  73. } catch (Exception ee) {}
  74. }
  75.  
  76. public static boolean changeLevel(float[] str, int level, int valor, Player player, String stats){
  77. for(int i = 0; i < str.length; i++){
  78. if(str[i] <= valor && i+1 > level){
  79. switch (stats){
  80. case "strength":
  81. try {
  82. PreparedStatement q = SqlConnection.connection.prepareStatement("UPDATE players SET strength = ? WHERE uuid = ?");
  83. q.setInt(1, i+1);
  84. q.setString(2, player.getUniqueId().toString());
  85. q.execute();
  86. q.close();
  87. } catch (SQLException error) {
  88. error.printStackTrace();
  89. }
  90.  
  91. level++;
  92. player.sendMessage(ChatColor.GREEN+"Félicitations, vous avez débloqué "+ChatColor.RED+"✽Force "+level);
  93.  
  94. setEffet(player);
  95. return true;
  96. case "agility":
  97. try {
  98. PreparedStatement q = SqlConnection.connection.prepareStatement("UPDATE players SET agility = ? WHERE uuid = ?");
  99. q.setInt(1, i+1);
  100. q.setString(2, player.getUniqueId().toString());
  101. q.execute();
  102. q.close();
  103. } catch (SQLException error) {
  104. error.printStackTrace();
  105. }
  106.  
  107. level++;
  108. player.sendMessage(ChatColor.GREEN+"Félicitations, vous avez débloqué "+ChatColor.AQUA+"❄Agilité "+level);
  109.  
  110. setEffet(player);
  111. return true;
  112. case "haste":
  113. try {
  114. PreparedStatement q = SqlConnection.connection.prepareStatement("UPDATE players SET haste = ? WHERE uuid = ?");
  115. q.setInt(1, i+1);
  116. q.setString(2, player.getUniqueId().toString());
  117. q.execute();
  118. q.close();
  119. } catch (SQLException error) {
  120. error.printStackTrace();
  121. }
  122.  
  123. level++;
  124. player.sendMessage(ChatColor.GREEN+"Félicitations, vous avez débloqué "+ChatColor.AQUA+"❃Haste "+level);
  125.  
  126. setEffet(player);
  127. return true;
  128. case "poison_resistance":
  129. try {
  130. PreparedStatement q = SqlConnection.connection.prepareStatement("UPDATE players SET poison_resistance = ? WHERE uuid = ?");
  131. q.setInt(1, i+1);
  132. q.setString(2, player.getUniqueId().toString());
  133. q.execute();
  134. q.close();
  135. } catch (SQLException error) {
  136. error.printStackTrace();
  137. }
  138.  
  139. level++;
  140. player.sendMessage(ChatColor.GREEN+"Félicitations, vous avez débloqué "+ChatColor.AQUA+"❃Résistance au poison "+level);
  141.  
  142. setEffet(player);
  143. return true;
  144. case "fire_resistance":
  145. try {
  146. PreparedStatement q = SqlConnection.connection.prepareStatement("UPDATE players SET fire_resistance = ? WHERE uuid = ?");
  147. q.setInt(1, i+1);
  148. q.setString(2, player.getUniqueId().toString());
  149. q.execute();
  150. q.close();
  151. } catch (SQLException error) {
  152. error.printStackTrace();
  153. }
  154.  
  155. level++;
  156. player.sendMessage(ChatColor.GREEN+"Félicitations, vous avez débloqué "+ChatColor.AQUA+"❃Résistance au feu "+level);
  157.  
  158. setEffet(player);
  159. return true;
  160. case "falling_resistance":
  161. try {
  162. PreparedStatement q = SqlConnection.connection.prepareStatement("UPDATE players SET falling_resistance = ? WHERE uuid = ?");
  163. q.setInt(1, i+1);
  164. q.setString(2, player.getUniqueId().toString());
  165. q.execute();
  166. q.close();
  167. } catch (SQLException error) {
  168. error.printStackTrace();
  169. }
  170.  
  171. level++;
  172. player.sendMessage(ChatColor.GREEN+"Félicitations, vous avez débloqué "+ChatColor.AQUA+"❃Résistance à la chute "+level);
  173.  
  174. setEffet(player);
  175. return true;
  176. case "all_resistance":
  177. try {
  178. PreparedStatement q = SqlConnection.connection.prepareStatement("UPDATE players SET all_resistance = ? WHERE uuid = ?");
  179. q.setInt(1, i+1);
  180. q.setString(2, player.getUniqueId().toString());
  181. q.execute();
  182. q.close();
  183. } catch (SQLException error) {
  184. error.printStackTrace();
  185. }
  186.  
  187. level++;
  188. player.sendMessage(ChatColor.GREEN+"Félicitations, vous avez débloqué "+ChatColor.AQUA+"❃Résistance au front "+level);
  189.  
  190. setEffet(player);
  191. return true;
  192. default:
  193. /*Action*/;
  194. }
  195. }
  196. }
  197. return false;
  198. }
  199.  
  200. public static void setEffet(Player player){
  201. int agilityLevel = 0;
  202. boolean agilityActive = true;
  203. int hasteLevel = 0;
  204. boolean hasteActive = true;
  205.  
  206. try {
  207. PreparedStatement q = SqlConnection.connection.prepareStatement("SELECT agility,agility_active FROM players WHERE uuid = ?");
  208. q.setString(1, player.getUniqueId().toString());
  209. ResultSet resultat = q.executeQuery();
  210. while(resultat.next()){
  211. agilityLevel = resultat.getInt("agility");
  212. agilityActive = resultat.getBoolean("agility_active");
  213. }
  214. q.close();
  215.  
  216. if(agilityActive == true){
  217. switch(agilityLevel){
  218. case 1:
  219. player.setWalkSpeed(0.215F);
  220. break;
  221. case 2:
  222. player.setWalkSpeed(0.23F);
  223. break;
  224. case 3:
  225. player.setWalkSpeed(0.245F);
  226. break;
  227. case 4:
  228. player.setWalkSpeed(0.26F);
  229. break;
  230. case 5:
  231. player.setWalkSpeed(0.275F);
  232. break;
  233. default:
  234. player.setWalkSpeed(0.2F);
  235. }
  236. }else{
  237. player.setWalkSpeed(0.2F);
  238. }
  239.  
  240. } catch (SQLException error) {
  241. error.printStackTrace();
  242. }
  243.  
  244. try {
  245. PreparedStatement q = SqlConnection.connection.prepareStatement("SELECT haste,haste_active FROM players WHERE uuid = ?");
  246. q.setString(1, player.getUniqueId().toString());
  247. ResultSet resultat = q.executeQuery();
  248. while(resultat.next()){
  249. hasteLevel = resultat.getInt("haste");
  250. }
  251. q.close();
  252.  
  253. if(hasteActive == true){
  254. switch(hasteLevel){
  255. case 1:
  256. player.removePotionEffect(PotionEffectType.FAST_DIGGING);
  257. player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 100000, 0));
  258. break;
  259. case 2:
  260. player.removePotionEffect(PotionEffectType.FAST_DIGGING);
  261. player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 100000, 0));
  262. break;
  263. case 3:
  264. player.removePotionEffect(PotionEffectType.FAST_DIGGING);
  265. player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 100000, 0));
  266. break;
  267. case 4:
  268. player.removePotionEffect(PotionEffectType.FAST_DIGGING);
  269. player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 100000, 0));
  270. break;
  271. case 5:
  272. player.removePotionEffect(PotionEffectType.FAST_DIGGING);
  273. player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 100000, 1));
  274. break;
  275. }
  276. }else{
  277. player.removePotionEffect(PotionEffectType.FAST_DIGGING);
  278. }
  279.  
  280. } catch (SQLException error) {
  281. error.printStackTrace();
  282. }
  283. }
  284. }
Add Comment
Please, Sign In to add comment