Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.block.BlockState;
- import org.bukkit.block.Sign;
- import org.bukkit.configuration.file.YamlConfiguration;
- import de.DasGunter.SP.Main.main;
- public class TopTen {
- public static File f = new File("plugins/SP/sign.yml");
- @SuppressWarnings("static-access")
- public static YamlConfiguration cfg = new YamlConfiguration().loadConfiguration(f);
- public static int s;
- static HashMap<Integer, String> rang = new HashMap<>();
- static HashMap<Integer, String> name = new HashMap<>();
- public static void setStats(){
- s = Bukkit.getScheduler().scheduleSyncRepeatingTask(main.ins, new Runnable()
- {
- @Override
- public void run() {
- if(MySQL.isConnected()){
- try {
- ResultSet rs = MySQL.query("SELECT * FROM Stats ORDER BY Kills DESC LIMIT 10");
- int i = 0;
- while(rs.next()) {
- i++;
- rang.put(i, rs.getString("UUID"));
- name.put(i, rs.getString("Name"));
- }
- System.out.println(rang.toString());
- } catch (Exception e) {
- System.out.println(e);
- }
- set();
- }else{
- Bukkit.getScheduler().cancelTask(s);
- }
- }
- },20L,60*20);
- }
- public static Integer getkills(String uuid){
- Integer i = -1;
- ResultSet rs = MySQL.query("SELECT * FROM Stats WHERE UUID= '"+uuid+"'");
- try {
- if((!rs.next()) || (Integer.valueOf(rs.getInt("Kills")) == null));
- i = rs.getInt("Kills");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return i;
- }
- public static Integer getTode(String uuid){
- Integer i = -1;
- ResultSet rs = MySQL.query("SELECT * FROM Stats WHERE UUID= '"+uuid+"'");
- try {
- if((!rs.next()) || (Integer.valueOf(rs.getInt("Tode")) == null));
- i = rs.getInt("Tode");
- } catch (SQLException e) {
- }
- return i;
- }
- public static Integer getCoins(String uuid){
- Integer i = -1;
- ResultSet rs = MySQL.query("SELECT * FROM Stats WHERE UUID= '"+uuid+"'");
- try {
- if((!rs.next()) || (Integer.valueOf(rs.getInt("Tokens")) == null));
- i = rs.getInt("Tokens");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return i;
- }
- public static void set(){
- double x1 = cfg.getDouble("Sign.eins.X");
- double y1 = cfg.getDouble("Sign.eins.Y");
- double z1 = cfg.getDouble("Sign.eins.Z");
- double x2 = cfg.getDouble("Sign.zwei.X");
- double y2 = cfg.getDouble("Sign.zwei.Y");
- double z2 = cfg.getDouble("Sign.zwei.Z");
- double x3 = cfg.getDouble("Sign.drei.X");
- double y3 = cfg.getDouble("Sign.drei.Y");
- double z3 = cfg.getDouble("Sign.drei.Z");
- double x4 = cfg.getDouble("Sign.vier.X");
- double y4 = cfg.getDouble("Sign.vier.Y");
- double z4 = cfg.getDouble("Sign.vier.Z");
- double x5 = cfg.getDouble("Sign.funf.X");
- double y5 = cfg.getDouble("Sign.funf.Y");
- double z5 = cfg.getDouble("Sign.funf.Z");
- double x6 = cfg.getDouble("Sign.sech.X");
- double y6 = cfg.getDouble("Sign.sech.Y");
- double z6 = cfg.getDouble("Sign.sech.Z");
- double x7 = cfg.getDouble("Sign.seven.X");
- double y7 = cfg.getDouble("Sign.seven.Y");
- double z7 = cfg.getDouble("Sign.seven.Z");
- double x8 = cfg.getDouble("Sign.acht.X");
- double y8 = cfg.getDouble("Sign.acht.Y");
- double z8 = cfg.getDouble("Sign.acht.Z");
- double x9 = cfg.getDouble("Sign.neun.X");
- double y9 = cfg.getDouble("Sign.neun.Y");
- double z9 = cfg.getDouble("Sign.neun.Z");
- double x10 = cfg.getDouble("Sign.zehn.X");
- double y10 = cfg.getDouble("Sign.zehn.Y");
- double z10 = cfg.getDouble("Sign.zehn.Z");
- Location loc = new Location(Bukkit.getWorld("world"), x1, y1, z1);
- Location loc2 = new Location(Bukkit.getWorld("world"), x2, y2, z2);
- Location loc3 = new Location(Bukkit.getWorld("world"), x3, y3, z3);
- Location loc4 = new Location(Bukkit.getWorld("world"), x4, y4, z4);
- Location loc5 = new Location(Bukkit.getWorld("world"), x5, y5, z5);
- Location loc6 = new Location(Bukkit.getWorld("world"), x6, y6, z6);
- Location loc7 = new Location(Bukkit.getWorld("world"), x7, y7, z7);
- Location loc8 = new Location(Bukkit.getWorld("world"), x8, y8, z8);
- Location loc9 = new Location(Bukkit.getWorld("world"), x9, y9, z9);
- Location loc10 = new Location(Bukkit.getWorld("world"), x10, y10, z10);
- List<Location> LOC = new ArrayList<Location>();
- LOC.add(loc);
- LOC.add(loc2);
- LOC.add(loc3);
- LOC.add(loc4);
- LOC.add(loc5);
- LOC.add(loc6);
- LOC.add(loc7);
- LOC.add(loc8);
- LOC.add(loc9);
- LOC.add(loc10);
- for(int i = 0; i < LOC.size(); i++){
- final int id = i+1;
- PreparedStatement st;
- try {
- st = MySQL.connection.prepareStatement("SELECT * FROM Stats WHERE UUID='"+rang.get(id)+"'");
- final ResultSet rs = st.executeQuery();
- final Location newlock = new Location(LOC.get(i).getWorld(), LOC.get(i).getX(), LOC.get(i).getY(), LOC.get(i).getZ());
- Bukkit.getScheduler().scheduleSyncDelayedTask(main.ins, new Runnable() {
- @Override
- public void run() {
- if(newlock.getBlock().getState() instanceof Sign){
- BlockState b = newlock.getBlock().getState();
- Sign S = (Sign) b;
- S.setLine(0, "§6Platz §c#"+id);
- S.setLine(1, name.get(id));
- S.setLine(2, "§cKills§8: §9"+getkills(rang.get(id)));
- S.setLine(3, "§9Punkte§8: §9"+getCoins(rang.get(id)));
- S.update();
- }
- }
- }, 20L);
- } catch (SQLException e1) {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement