SHARE
TWEET

Untitled

a guest Jun 18th, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.myzickzack;
  2.  
  3. import java.io.File;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.configuration.file.YamlConfiguration;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14.  
  15. public class Main extends JavaPlugin implements Listener {
  16.     private static Main plugin;
  17.     public static MySQL mysql;
  18.     public void onEnable() {
  19.         plugin = this;
  20.         getCommand("coins").setExecutor(new Coins());
  21.         Bukkit.getPluginManager().registerEvents(this, this);
  22.         loadConfig();
  23.     //  ConnectMySQL();
  24.     }
  25.  
  26.     public void loadConfig() {
  27.         File file = new File("plugins//CoinsAPI//config.yml");
  28.         FileConfiguration cfg = this.getConfig();
  29.         if (!file.exists()) {
  30.  
  31.             cfg.addDefault("mysql.host", "HOST");
  32.             cfg.addDefault("mysql.port", Integer.valueOf(3306));
  33.             cfg.addDefault("mysql.user", "USER");
  34.             cfg.addDefault("mysql.password", "PASSWORD");
  35.             cfg.addDefault("mysql.database", "Coins");
  36.             cfg.options().copyDefaults(true);
  37.             saveConfig();
  38.         }
  39.     }
  40.  
  41.     public void onDisable() {
  42.     }
  43.  
  44.     public void ConnectMySQL() {
  45.        
  46.         File file = new File("plugins//CoinsAPI//config.yml");
  47.         FileConfiguration mcfg = YamlConfiguration.loadConfiguration(file);
  48.         if (file.exists()) {
  49.             String host = mcfg.getString("mysql.host");
  50.             String database = mcfg.getString("mysql.database");
  51.             String user = mcfg.getString("mysql.user");
  52.             String password = mcfg.getString("mysql.password");
  53.             mysql = new MySQL(host, database, user, password);
  54.             mysql.connect();
  55.             mysql.update("CREATE TABLE IF NOT EXISTS coins(name varchar(100) UNIQUE, coins int)");
  56.             Bukkit.broadcastMessage("VERBINDUNG IZ DA");
  57.         } else {
  58.             loadConfig();
  59.             System.out.println("Verbindung konnte nicht hergestellt werden!");
  60.         }
  61.     }
  62.  
  63.     public static int getCoins(String name) {
  64.  
  65.         ResultSet rs = Main.mysql.query("SELECT coins FROM coins WHERE name = '" + name + "' LIMIT 1");
  66.  
  67.         try {
  68.             while (rs.next()) {
  69.                 return rs.getInt("coins");
  70.             }
  71.         } catch (SQLException e) {
  72.         }
  73.         return -1;
  74.     }
  75.  
  76.     public static void setCoins(String name, int amount) {
  77.         Main.mysql.update("UPDATE coins SET coins = " + amount + " WHERE name = '" + name + "'");
  78.     }
  79.  
  80.     public static boolean isRegistered(String name) {
  81.  
  82.         ResultSet rs = Main.mysql.query("SELECT * FROM coins WHERE name = '" + name + "' LIMIT 1");
  83.         System.out.println(rs == null);
  84.         try {
  85.             return rs.next();
  86.         } catch (SQLException e) {
  87.         }
  88.         return false;
  89.     }
  90.  
  91.     public static void register(String name) {
  92.         Main.mysql.update("INSERT INTO coins (name, coins) VALUES ('" + name + "', 0)");
  93.  
  94.     }
  95.  
  96.     public static Main getPlugin() {
  97.         return plugin;
  98.     }
  99. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top