Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main extends JavaPlugin {
- public static ArrayList<Player> cmdcd = new ArrayList<>();
- static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- static SecureRandom rnd = new SecureRandom();
- Date now = new Date();
- SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
- static final String DB_NAME = "jdbc:mysql://127.0.0.1:3306/test";
- static final String USER = "root";
- static final String PASS = "";
- Connection conn;
- Statement s;
- public void onEnable(){
- try {
- Class.forName("com.mysql.jdbc.Driver"); //Gets the driver class
- getLogger().info("About to connect to database"); //These are just for debugging purposes.
- conn = (Connection) DriverManager.getConnection(DB_NAME, USER, PASS); //Gets a connection to the database using the details you provided.
- getLogger().info("Successfully connected.");
- getLogger().info("About to create a statement");
- s = (Statement) conn.createStatement(); //Creates a statement. You can execute queries on this.
- getLogger().info("Successfully created statement.");
- }
- catch(Exception ex) {
- ex.printStackTrace();
- }
- }
- public void onDisable(){
- }
- long startTime = System.currentTimeMillis();
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
- final Player player = (Player) sender;
- if(!(sender instanceof Player)){
- return true;
- }
- if(cmd.getName().equalsIgnoreCase("login")){
- if(!cmdcd.contains(player)){
- String playeruuid = player.getUniqueId().toString();
- String key = this.randomString(15);
- Calendar calendar = Calendar.getInstance();
- int dateandtime = (int) calendar.getTimeInMillis();
- String sql = "INSERT INTO weblogin (`UUID`, `Keyy`, `Tiempo`) VALUES ('playeruuid', 'key', 'dateandtime')";
- try {
- s.executeUpdate(sql);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- player.sendMessage(ChatColor.GRAY + "Key: " + ChatColor.AQUA + key);
- cmdcd.add(player);
- Bukkit.getScheduler().runTaskLater(this, new Runnable() {
- @Override
- public void run() {
- cmdcd.remove(player);
- }
- }, 20L * 60 * 5); // 5 minutos
- } else {
- player.sendMessage(ChatColor.RED + "You must wait to use this command again");
- }
- }
- return false;
- }
- String randomString( int len ){
- StringBuilder sb = new StringBuilder( len );
- for( int i = 0; i < len; i++ )
- sb.append( AB.charAt( rnd.nextInt(AB.length()) ) );
- return sb.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement