Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. public class Main extends JavaPlugin {
  2.    
  3.     public static ArrayList<Player> cmdcd = new ArrayList<>();
  4.    
  5.     static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  6.     static SecureRandom rnd = new SecureRandom();
  7.    
  8.     Date now = new Date();
  9.     SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
  10.    
  11.     static final String DB_NAME = "jdbc:mysql://127.0.0.1:3306/test";
  12.     static final String USER = "root";
  13.     static final String PASS = "";
  14.     Connection conn;
  15.     Statement s;
  16.    
  17.     public void onEnable(){
  18.        
  19.         try {
  20.             Class.forName("com.mysql.jdbc.Driver"); //Gets the driver class
  21.             getLogger().info("About to connect to database"); //These are just for debugging purposes.
  22.              
  23.             conn = (Connection) DriverManager.getConnection(DB_NAME, USER, PASS); //Gets a connection to the database using the details you provided.
  24.              
  25.             getLogger().info("Successfully connected.");
  26.              
  27.             getLogger().info("About to create a statement");
  28.              
  29.             s = (Statement) conn.createStatement(); //Creates a statement. You can execute queries on this.
  30.              
  31.             getLogger().info("Successfully created statement.");
  32.             }
  33.             catch(Exception ex) {
  34.             ex.printStackTrace();
  35.             }
  36.        
  37.  
  38.        
  39.     }
  40.    
  41.     public void onDisable(){
  42.        
  43.     }
  44.    
  45.     long startTime = System.currentTimeMillis();
  46.    
  47.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
  48.         final Player player = (Player) sender;
  49.        
  50.         if(!(sender instanceof Player)){
  51.             return true;
  52.         }
  53.        
  54.         if(cmd.getName().equalsIgnoreCase("login")){
  55.            
  56.             if(!cmdcd.contains(player)){
  57.            
  58.             String playeruuid = player.getUniqueId().toString();
  59.             String key = this.randomString(15);
  60.             Calendar calendar = Calendar.getInstance();
  61.             int dateandtime = (int) calendar.getTimeInMillis();
  62.            
  63.             String sql = "INSERT INTO weblogin (`UUID`, `Keyy`, `Tiempo`) VALUES ('playeruuid', 'key', 'dateandtime')";
  64.             try {
  65.                 s.executeUpdate(sql);
  66.             } catch (SQLException e) {
  67.                 // TODO Auto-generated catch block
  68.                 e.printStackTrace();
  69.             }
  70.            
  71.             player.sendMessage(ChatColor.GRAY + "Key: " + ChatColor.AQUA + key);
  72.             cmdcd.add(player);
  73.  
  74.                 Bukkit.getScheduler().runTaskLater(this, new Runnable() {                      
  75.                     @Override
  76.                     public void run() {
  77.                         cmdcd.remove(player);
  78.                     }
  79.                 }, 20L * 60 * 5); // 5 minutos
  80.  
  81.            
  82.             } else {
  83.                
  84.  
  85.                
  86.                 player.sendMessage(ChatColor.RED + "You must wait to use this command again");
  87.                
  88.             }
  89.            
  90.            
  91.             }
  92.             return false;
  93.         }
  94.    
  95.     String randomString( int len ){
  96.            StringBuilder sb = new StringBuilder( len );
  97.            for( int i = 0; i < len; i++ )
  98.               sb.append( AB.charAt( rnd.nextInt(AB.length()) ) );
  99.            return sb.toString();
  100.         }
  101.    
  102.  
  103.        
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement