Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Connection con;
- public static String ip = "185.230.161.168";
- public static String port = "3306";
- public static String dbname = "Smash";
- public static String user = "Smash";
- public static String password = "hdgdl#1234";
- public static String cointable = "Coins";
- public static String statstable = "Stats";
- public static HashMap<Integer, String> rang = new HashMap<Integer, String>();
- public static void connect(){
- if(!isConnected()){
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + ip +":" + port +"/" + dbname + "?autoReconnect=true", user, password);
- if(isConnected()){
- Bukkit.getConsoleSender().sendMessage("§aMySQL Verbindung hergestellt.");
- createTable();
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public static boolean isConnected(){
- return (con != null);
- }
- public static void disconnect() {
- if(isConnected()){
- try {
- con.close();
- Bukkit.getConsoleSender().sendMessage("§cDie MySQL Verbindung wurde getrennt!");
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public static void createTable(){
- try {
- PreparedStatement ps = con.prepareStatement("CREATE TABLE IF NOT EXISTS Coins (UUID VARCHAR(64), Playername VARCHAR(32), Coins int(15));");
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- try {
- PreparedStatement ps = con.prepareStatement("CREATE TABLE IF NOT EXISTS Stats (UUID VARCHAR(64),Playername VARCHAR(32), Kills int(11), Deaths int(11), Rounds int(11));");
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static boolean UserExists(String UUID){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("SELECT Coins FROM " + cointable + " WHERE UUID = ?");
- ps.setString(1, UUID);
- ResultSet rs = ps.executeQuery();
- return rs.next();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static boolean UUIDExists(String UUID){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("SELECT UUID FROM " + statstable + " WHERE UUID = ?");
- ps.setString(1, UUID);
- ResultSet rs = ps.executeQuery();
- return rs.next();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static void createUser(String uuid, Player p){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO " + statstable + " (UUID,Playername,Kills,Deaths,Rounds) VALUES (?,?,?,?,?)");
- ps.setString(1, uuid);
- ps.setString(2, p.getName());
- ps.setInt(3, 0);
- ps.setInt(4, 0);
- ps.setInt(5, 0);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void addTode(String UUID, int amount, String playername){
- int tode = getTode(UUID);
- amount+=tode;
- if(UUIDExists(UUID)){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("UPDATE " + statstable + " SET Deaths = ? WHERE UUID = ?");
- ps.setInt(1, amount);
- ps.setString(2, UUID);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void addKIlls(String UUID, int amount, String playername){
- int kills = getKills(UUID);
- amount+=kills;
- if(UUIDExists(UUID)){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("UPDATE " + statstable + " SET Kills = ? WHERE UUID = ?");
- ps.setInt(1, amount);
- ps.setString(2, UUID);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void removeTode(String uuid, int amount,String playername){
- int tode = getTode(uuid);
- if(UUIDExists(uuid)){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("UPDATE " + statstable + " SET Deaths = ? WHERE UUID = ?");
- ps.setInt(1, tode-=amount);
- ps.setString(2, uuid);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void removeKills(String uuid, int amount,String playername){
- int kills = getKills(uuid);
- if(UUIDExists(uuid)){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("UPDATE " + statstable + " SET Kills = ? WHERE UUID = ?");
- ps.setInt(1, kills-=amount);
- ps.setString(2, uuid);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static Integer getTode(String uuid){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("Select Deaths From " + statstable + " Where UUID = ?");
- ps.setString(1, uuid);
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getInt("Deaths");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return 0;
- }
- public static Integer getKills(String uuid){
- int it = 0;
- if(UUIDExists(uuid)){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("Select * From " + statstable + " Where UUID = ?");
- ps.setString(1, uuid);
- ResultSet rs = ps.executeQuery();
- if(rs.next()){
- it = rs.getInt("Kills");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return it;
- }
- return 0;
- }
- public static String getPlayername(String UUID){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("Select Playername From " + statstable + " Where UUID = ?");
- ps.setString(1, UUID);
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getString("Playername");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static Integer getCoins(String uuid){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("Select Coins From " + cointable + " Where UUID = ?");
- ps.setString(1, uuid);
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getInt("Coins");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return 0;
- }
- public static void addCoins(String uuid, int amount, Player p ){
- int coins = getCoins(uuid);
- amount+=coins;
- if(UserExists(uuid)){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("UPDATE " + cointable + " SET Coins = ? WHERE UUID = ?");
- ps.setInt(1, amount);
- ps.setString(2, uuid);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }else{
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO " + cointable + " (UUID,Playername,Coins) VALUES (?,?,?)");
- ps.setString(1, uuid);
- ps.setString(2, p.getName());
- ps.setInt(3, amount);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void removeCoins(String uuid, int amount,String playername){
- int coins = getCoins(uuid);
- if(UserExists(uuid)){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("UPDATE " + cointable + " SET Coins = ? WHERE UUID = ?");
- ps.setInt(1, coins-=amount);
- ps.setString(2, uuid);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }else{
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("Insert INTO " + cointable + " (UUID,Coins) VALUES (?,?)");
- ps.setString(1, uuid);
- ps.setInt(2, amount);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void set(){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("SELECT UUID FROM " + statstable + " ORDER BY KILLS DESC LIMIT 10");
- ResultSet rs = ps.executeQuery();
- int i = 0;
- while(rs.next()){
- i++;
- rang.put(i, rs.getString("UUID"));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if(InteractListener.cfg.getString("Kopf-1") != null && InteractListener.cfg.getString("Kopf-2") != null && InteractListener.cfg.getString("Kopf-3") != null && InteractListener.cfg.getString("Kopf-4") != null && InteractListener.cfg.getString("Kopf-5") != null && InteractListener.cfg.getString("Kopf-6") != null && InteractListener.cfg.getString("Kopf-7") != null && InteractListener.cfg.getString("Kopf-8") != null && InteractListener.cfg.getString("Kopf-9") != null && InteractListener.cfg.getString("Kopf-10") != null){
- Location loc = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-1" + ".World")), InteractListener.cfg.getInt("Kopf-1" + ".X"), InteractListener.cfg.getInt("Kopf-1" + ".Y"), InteractListener.cfg.getInt("Kopf-1" + ".Z"));
- Location loc2 = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-2" + ".World")), InteractListener.cfg.getInt("Kopf-2" + ".X"), InteractListener.cfg.getInt("Kopf-2" + ".Y"), InteractListener.cfg.getInt("Kopf-2" + ".Z"));
- Location loc3 = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-3" + ".World")), InteractListener.cfg.getInt("Kopf-3" + ".X"), InteractListener.cfg.getInt("Kopf-3" + ".Y"), InteractListener.cfg.getInt("Kopf-3" + ".Z"));
- Location loc4 = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-4" + ".World")), InteractListener.cfg.getInt("Kopf-4" + ".X"), InteractListener.cfg.getInt("Kopf-4" + ".Y"), InteractListener.cfg.getInt("Kopf-4" + ".Z"));
- Location loc5 = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-5" + ".World")), InteractListener.cfg.getInt("Kopf-5" + ".X"), InteractListener.cfg.getInt("Kopf-5" + ".Y"), InteractListener.cfg.getInt("Kopf-5" + ".Z"));
- Location loc6 = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-6" + ".World")), InteractListener.cfg.getInt("Kopf-6" + ".X"), InteractListener.cfg.getInt("Kopf-6" + ".Y"), InteractListener.cfg.getInt("Kopf-6" + ".Z"));
- Location loc7 = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-7" + ".World")), InteractListener.cfg.getInt("Kopf-7" + ".X"), InteractListener.cfg.getInt("Kopf-7" + ".Y"), InteractListener.cfg.getInt("Kopf-7" + ".Z"));
- Location loc8 = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-8" + ".World")), InteractListener.cfg.getInt("Kopf-8" + ".X"), InteractListener.cfg.getInt("Kopf-8" + ".Y"), InteractListener.cfg.getInt("Kopf-8" + ".Z"));
- Location loc9 = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-9" + ".World")), InteractListener.cfg.getInt("Kopf-9" + ".X"), InteractListener.cfg.getInt("Kopf-9" + ".Y"), InteractListener.cfg.getInt("Kopf-9" + ".Z"));
- Location loc10 = new Location(Bukkit.getWorld(InteractListener.cfg.getString("Kopf-10" + ".World")), InteractListener.cfg.getInt("Kopf-10" + ".X"), InteractListener.cfg.getInt("Kopf-10" + ".Y"), InteractListener.cfg.getInt("Kopf-10" + ".Z"));
- String face = InteractListener.cfg.getString("Kopf-1" + ".Richtung");
- List<Location> locs = new ArrayList<>();
- locs.add(loc);
- locs.add(loc2);
- locs.add(loc3);
- locs.add(loc4);
- locs.add(loc5);
- locs.add(loc6);
- locs.add(loc7);
- locs.add(loc8);
- locs.add(loc9);
- locs.add(loc10);
- for(int in = 0; in < locs.size(); in++){
- int id = in+1;
- if(getKills(rang.get(id)) > 0){
- locs.get(in).getBlock().setType(Material.SKULL);
- Skull s = (Skull) locs.get(in).getBlock().getState();
- s.setSkullType(SkullType.PLAYER);
- s.setRotation(BlockFace.WEST);
- String name = getPlayername(rang.get(id));
- s.setOwner(name);
- s.update();
- Location ort = new Location(locs.get(id).getWorld(), locs.get(id).getX(), locs.get(id).getY() -1, locs.get(id).getZ());
- if(ort.getBlock().getState() instanceof Sign){
- BlockState b = ort.getBlock().getState();
- Sign si = (Sign) b;
- si.setLine(0, "Platz #" + id);
- si.setLine(1, name);
- si.setLine(2, "");
- if(getKills(rang.get(id)) == 1){
- si.setLine(3, getKills(rang.get(id)) + " Kill");
- }else if(getKills(rang.get(id)) > 1){
- si.setLine(3, getKills(rang.get(id)) + " Kills");
- }else{
- si.setLine(3, getKills(rang.get(id)) + " Kills");
- }
- si.update();
- }
- }
- }
- }else{
- Bukkit.getConsoleSender().sendMessage("Bitte Stats Köpfe setzen!");
- }
- }
- public static void delete(String uuid){
- if(UserExists(uuid)){
- try {
- PreparedStatement ps = MySQL.con.prepareStatement("DELETE FROM " + cointable + " WHERE UUID = ?");
- ps.setString(1, uuid);
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement