Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.35 KB | None | 0 0
  1. package me.xxx;
  2.  
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.UUID;
  7.  
  8. import org.bukkit.entity.Player;
  9.  
  10. import net.milkbowl.vault.permission.Permission;
  11.  
  12. public class L2 {
  13.  DiscordBot plugin = DiscordBot.getPlugin(DiscordBot.class);
  14.          
  15.  public boolean playerExists(UUID uuid){
  16.      
  17.      try {
  18.      PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM " + plugin.table + "WHERE UUID =?");
  19.      statement.setString(1, uuid.toString());
  20.      
  21.      ResultSet results = statement.executeQuery();
  22.      if(results.next()) {
  23.          
  24.      }
  25.      
  26.  } catch (SQLException e) {
  27.      e.printStackTrace();
  28.  }
  29.  return false;
  30. }
  31. public void createPlayer(final UUID uuid, Player player) {
  32.     try {
  33.         PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM " + plugin.table + "WHERE UUID =?");
  34.          statement.setString(1, uuid.toString());
  35.          statement.setString(1, uuid.toString());
  36.          ResultSet results = statement.executeQuery();
  37.          results.next();
  38.          if(!(playerExists(uuid) != true)) {
  39.              PreparedStatement insert = plugin.getConnection().prepareStatement("INSERT INTO " + plugin.table + "(UUID, NAME, RANK) VALUE (?,?,?)");
  40.              insert.setString(1, uuid.toString());
  41.              insert.setString(2, player.getName());
  42.              insert.setString(3, Permission.getPrimaryGroup(player));
  43.          }
  44.     } catch (SQLException e) {
  45.         e.printStackTrace();
  46.     }
  47. }
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. package me.xxx;
  58.  
  59. import java.sql.PreparedStatement;
  60. import java.sql.ResultSet;
  61. import java.sql.SQLException;
  62. import java.util.UUID;
  63.  
  64. import org.bukkit.entity.Player;
  65.  
  66. import net.milkbowl.vault.permission.Permission;
  67.  
  68. public class L2 {
  69.  DiscordBot plugin = DiscordBot.getPlugin(DiscordBot.class);
  70.          
  71.  public boolean playerExists(UUID uuid){
  72.      
  73.      try {
  74.      PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM " + plugin.table + "WHERE UUID =?");
  75.      statement.setString(1, uuid.toString());
  76.      
  77.      ResultSet results = statement.executeQuery();
  78.      if(results.next()) {
  79.          
  80.      }
  81.      
  82.  } catch (SQLException e) {
  83.      e.printStackTrace();
  84.  }
  85.  return false;
  86. }
  87. public void createPlayer(final UUID uuid, Player player) {
  88.     try {
  89.         PreparedStatement statement = plugin.getConnection().prepareStatement("SELECT * FROM " + plugin.table + "WHERE UUID =?");
  90.          statement.setString(1, uuid.toString());
  91.          statement.setString(1, uuid.toString());
  92.          ResultSet results = statement.executeQuery();
  93.          results.next();
  94.          if(!(playerExists(uuid) != true)) {
  95.              PreparedStatement insert = plugin.getConnection().prepareStatement("INSERT INTO " + plugin.table + "(UUID, NAME, RANK) VALUE (?,?,?)");
  96.              insert.setString(1, uuid.toString());
  97.              insert.setString(2, player.getName());
  98.              insert.setString(3, Permission.getPrimaryGroup(player));
  99.          }
  100.     } catch (SQLException e) {
  101.         e.printStackTrace();
  102.     }
  103. }
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. package me.xxx;
  112.  
  113.  
  114. import java.sql.Connection;
  115. import java.sql.DriverManager;
  116. import java.sql.SQLException;
  117.  
  118. import org.bukkit.Bukkit;
  119. import org.bukkit.ChatColor;
  120. import org.bukkit.command.Command;
  121. import org.bukkit.command.CommandSender;
  122. import org.bukkit.entity.Player;
  123. import org.bukkit.plugin.RegisteredServiceProvider;
  124. import org.bukkit.plugin.java.JavaPlugin;
  125.  
  126. import net.milkbowl.vault.permission.Permission;
  127.  
  128.  
  129.  
  130. public class DiscordBot extends JavaPlugin {
  131.     public static Permission permission = null;
  132.     private Connection connection;
  133.     public String host, database, username, password, table;
  134.     public int port;
  135.     public Connection getConnection() {
  136.         return connection;
  137.     }
  138.    
  139.     public void onEnable() {
  140.      registerConfig();
  141.     mysqlSetup();
  142.      setupPermissions();
  143.      
  144.  }
  145.  
  146.  
  147.  
  148. private void registerConfig() {
  149.     getConfig().options().copyDefaults(true);
  150.     saveConfig();
  151. }
  152. public void setConnection(Connection connection) {
  153.     this.connection = connection;
  154. }
  155. public void mysqlSetup() {
  156.     host = getConfig().getString("Dbhost");
  157.     database = getConfig().getString("Db");
  158.     username = getConfig().getString("Dbname");
  159.     password = getConfig().getString("Dbpass");
  160.     port = getConfig().getInt("Dbport");
  161.     table = getConfig().getString("Table");
  162.    
  163.     try{
  164.        
  165.         synchronized (this){
  166.             if(getConnection() != null && !getConnection().isClosed()){
  167.                 return;
  168.             }
  169.            
  170.             Class.forName("com.mysql.jdbc.Driver");
  171.            
  172.             setConnection( DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password));
  173.            
  174.             Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "MYSQL CONNECTED");
  175.         }
  176.     }catch(SQLException e){
  177.         e.printStackTrace();
  178.     }catch(ClassNotFoundException e){
  179.         e.printStackTrace();
  180.     }
  181. }
  182.  
  183.  
  184.  
  185.  
  186.  
  187. public void onDisable() {
  188.      
  189. saveConfig();
  190.  
  191.      
  192.  }
  193.  
  194.  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  195.      
  196.      
  197.      if (cmd.getName().equalsIgnoreCase("rank") && sender instanceof Player) {
  198.          
  199.          Player player = (Player) sender;
  200.          
  201.          
  202.          
  203.      }
  204.      
  205.      return false;
  206.  }
  207.  private boolean setupPermissions()
  208.  {
  209.      RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
  210.      if (permissionProvider != null) {
  211.          permission = permissionProvider.getProvider();
  212.      }
  213.      return (permission != null);
  214.  }
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement