Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. import java.io.File;
  2. import java.sql.PreparedStatement;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.Location;
  10. import org.bukkit.block.BlockState;
  11. import org.bukkit.block.Sign;
  12. import org.bukkit.configuration.file.YamlConfiguration;
  13. import de.DasGunter.SP.Main.main;
  14. public class TopTen {
  15.  
  16.  
  17. public static File f = new File("plugins/SP/sign.yml");
  18. @SuppressWarnings("static-access")
  19. public static YamlConfiguration cfg = new YamlConfiguration().loadConfiguration(f);
  20.  
  21. public static int s;
  22. static HashMap<Integer, String> rang = new HashMap<>();
  23. static HashMap<Integer, String> name = new HashMap<>();
  24. public static void setStats(){
  25.  
  26. s = Bukkit.getScheduler().scheduleSyncRepeatingTask(main.ins, new Runnable()
  27. {
  28.  
  29. @Override
  30. public void run() {
  31. if(MySQL.isConnected()){
  32.  
  33. try {
  34.  
  35. ResultSet rs = MySQL.query("SELECT * FROM Stats ORDER BY Kills DESC LIMIT 10");
  36. int i = 0;
  37. while(rs.next()) {
  38. i++;
  39.  
  40. rang.put(i, rs.getString("UUID"));
  41. name.put(i, rs.getString("Name"));
  42. }
  43. System.out.println(rang.toString());
  44.  
  45.  
  46.  
  47. } catch (Exception e) {
  48. System.out.println(e);
  49.  
  50. }
  51. set();
  52. }else{
  53. Bukkit.getScheduler().cancelTask(s);
  54.  
  55. }
  56.  
  57. }
  58.  
  59. },20L,60*20);
  60. }
  61.  
  62.  
  63. public static Integer getkills(String uuid){
  64. Integer i = -1;
  65. ResultSet rs = MySQL.query("SELECT * FROM Stats WHERE UUID= '"+uuid+"'");
  66. try {
  67. if((!rs.next()) || (Integer.valueOf(rs.getInt("Kills")) == null));
  68.  
  69. i = rs.getInt("Kills");
  70. } catch (SQLException e) {
  71.  
  72. e.printStackTrace();
  73. }
  74.  
  75. return i;
  76. }
  77.  
  78. public static Integer getTode(String uuid){
  79. Integer i = -1;
  80. ResultSet rs = MySQL.query("SELECT * FROM Stats WHERE UUID= '"+uuid+"'");
  81. try {
  82. if((!rs.next()) || (Integer.valueOf(rs.getInt("Tode")) == null));
  83.  
  84. i = rs.getInt("Tode");
  85. } catch (SQLException e) {
  86.  
  87. }
  88.  
  89. return i;
  90. }
  91.  
  92. public static Integer getCoins(String uuid){
  93. Integer i = -1;
  94. ResultSet rs = MySQL.query("SELECT * FROM Stats WHERE UUID= '"+uuid+"'");
  95. try {
  96. if((!rs.next()) || (Integer.valueOf(rs.getInt("Tokens")) == null));
  97.  
  98. i = rs.getInt("Tokens");
  99. } catch (SQLException e) {
  100. e.printStackTrace();
  101. }
  102.  
  103. return i;
  104. }
  105. public static void set(){
  106.  
  107.  
  108. double x1 = cfg.getDouble("Sign.eins.X");
  109. double y1 = cfg.getDouble("Sign.eins.Y");
  110. double z1 = cfg.getDouble("Sign.eins.Z");
  111.  
  112. double x2 = cfg.getDouble("Sign.zwei.X");
  113. double y2 = cfg.getDouble("Sign.zwei.Y");
  114. double z2 = cfg.getDouble("Sign.zwei.Z");
  115.  
  116. double x3 = cfg.getDouble("Sign.drei.X");
  117. double y3 = cfg.getDouble("Sign.drei.Y");
  118. double z3 = cfg.getDouble("Sign.drei.Z");
  119.  
  120. double x4 = cfg.getDouble("Sign.vier.X");
  121. double y4 = cfg.getDouble("Sign.vier.Y");
  122. double z4 = cfg.getDouble("Sign.vier.Z");
  123.  
  124. double x5 = cfg.getDouble("Sign.funf.X");
  125. double y5 = cfg.getDouble("Sign.funf.Y");
  126. double z5 = cfg.getDouble("Sign.funf.Z");
  127.  
  128. double x6 = cfg.getDouble("Sign.sech.X");
  129. double y6 = cfg.getDouble("Sign.sech.Y");
  130. double z6 = cfg.getDouble("Sign.sech.Z");
  131.  
  132. double x7 = cfg.getDouble("Sign.seven.X");
  133. double y7 = cfg.getDouble("Sign.seven.Y");
  134. double z7 = cfg.getDouble("Sign.seven.Z");
  135.  
  136. double x8 = cfg.getDouble("Sign.acht.X");
  137. double y8 = cfg.getDouble("Sign.acht.Y");
  138. double z8 = cfg.getDouble("Sign.acht.Z");
  139.  
  140. double x9 = cfg.getDouble("Sign.neun.X");
  141. double y9 = cfg.getDouble("Sign.neun.Y");
  142. double z9 = cfg.getDouble("Sign.neun.Z");
  143.  
  144. double x10 = cfg.getDouble("Sign.zehn.X");
  145. double y10 = cfg.getDouble("Sign.zehn.Y");
  146. double z10 = cfg.getDouble("Sign.zehn.Z");
  147.  
  148. Location loc = new Location(Bukkit.getWorld("world"), x1, y1, z1);
  149. Location loc2 = new Location(Bukkit.getWorld("world"), x2, y2, z2);
  150. Location loc3 = new Location(Bukkit.getWorld("world"), x3, y3, z3);
  151. Location loc4 = new Location(Bukkit.getWorld("world"), x4, y4, z4);
  152. Location loc5 = new Location(Bukkit.getWorld("world"), x5, y5, z5);
  153. Location loc6 = new Location(Bukkit.getWorld("world"), x6, y6, z6);
  154. Location loc7 = new Location(Bukkit.getWorld("world"), x7, y7, z7);
  155. Location loc8 = new Location(Bukkit.getWorld("world"), x8, y8, z8);
  156. Location loc9 = new Location(Bukkit.getWorld("world"), x9, y9, z9);
  157. Location loc10 = new Location(Bukkit.getWorld("world"), x10, y10, z10);
  158. List<Location> LOC = new ArrayList<Location>();
  159. LOC.add(loc);
  160. LOC.add(loc2);
  161. LOC.add(loc3);
  162. LOC.add(loc4);
  163. LOC.add(loc5);
  164. LOC.add(loc6);
  165. LOC.add(loc7);
  166. LOC.add(loc8);
  167. LOC.add(loc9);
  168. LOC.add(loc10);
  169.  
  170. for(int i = 0; i < LOC.size(); i++){
  171. final int id = i+1;
  172. PreparedStatement st;
  173.  
  174.  
  175.  
  176. try {
  177. st = MySQL.connection.prepareStatement("SELECT * FROM Stats WHERE UUID='"+rang.get(id)+"'");
  178.  
  179. final ResultSet rs = st.executeQuery();
  180.  
  181.  
  182. final Location newlock = new Location(LOC.get(i).getWorld(), LOC.get(i).getX(), LOC.get(i).getY(), LOC.get(i).getZ());
  183. Bukkit.getScheduler().scheduleSyncDelayedTask(main.ins, new Runnable() {
  184. @Override
  185. public void run() {
  186. if(newlock.getBlock().getState() instanceof Sign){
  187.  
  188. BlockState b = newlock.getBlock().getState();
  189. Sign S = (Sign) b;
  190.  
  191.  
  192.  
  193. S.setLine(0, "§6Platz §c#"+id);
  194. S.setLine(1, name.get(id));
  195. S.setLine(2, "§cKills§8: §9"+getkills(rang.get(id)));
  196. S.setLine(3, "§9Punkte§8: §9"+getCoins(rang.get(id)));
  197. S.update();
  198.  
  199. }
  200. }
  201. }, 20L);
  202. } catch (SQLException e1) {
  203.  
  204. }
  205.  
  206. }
  207. }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement