Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gmail.bloodywampire.old.listeners;
- import java.util.Properties;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerJoinEvent;
- import com.gmail.bloodywampire.old.Main.Main;
- import com.gmail.bloodywampire.old.commands.Token;
- import com.gmail.bloodywampire.old.libs.Time;
- public class PlayerJoin implements Listener
- {
- public static String pass = randomString( 6 );
- public void Event( PlayerJoinEvent event )
- {
- Player p = event.getPlayer();
- String name = p.getName();
- event.setJoinMessage((Object) ChatColor.BLUE + name + "dolaczy." );
- }
- public static void playerJoinMethod( Player player ) throws MessagingException
- {
- String where = "nick = '" + player.getName() + "'";
- if (player.hasPermission("oldcraft.adm")){
- long time = Time.getTime();
- long t1 = (long) Main.mysql.getRecord("token", "czas", where);
- if (t1 == time) {
- player.kickPlayer(Main.prefix + ChatColor.RED + " Wygenerowano nowy token. Sprawdz skrzynke mailowa.");
- long t2 = time + Time.addToTime(0, 0, 0, 1, 0);
- Main.mysql.updateRecord("token", "czas", t2, where);
- Main.mysql.updateRecord("token", "token", pass, where);
- PlayerJoin.send();
- return;
- }
- else {
- while (Token.tokenw = false){
- }
- do {
- player.sendMessage(Main.prefix + ChatColor.RED + " Podaj token.");
- Location teleportLocation = new Location(player.getWorld(), 0, 66, 0);
- player.teleport(teleportLocation);
- }while (Token.tokenw = true);
- return;
- }
- }
- }
- static void send() throws MessagingException {
- final String username = "oldcraftmail@gmail.com";
- final String password = "1QA2ws3ed";
- Properties props = new Properties();
- props.put("mail.smtp.starttls.enable", "true");
- props.put("mail.smtp.auth", "true");
- props.put("mail.smtp.host", "smtp.gmail.com");
- props.put("mail.smtp.port", "587");
- Session session = Session.getInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- try {
- Message message = new MimeMessage(session);
- message.setFrom(new InternetAddress("oldcraftmail@gmail.com"));
- message.setRecipients(Message.RecipientType.TO,
- InternetAddress.parse("admoldcraft@gmail.com"));
- message.setSubject("Nowy Token");
- message.setText("Twój nowy token to: " + pass
- + "Proszę nie odpisywać na tego maila.");
- Transport.send(message);
- System.out.println(Main.prefix + ChatColor.GOLD + " Wyslano maila z tokenem.");
- } catch (MessagingException e) {
- throw new RuntimeException(e);
- }
- }
- public static String randomString(int len)
- {
- char[] str = new char[100];
- for (int i = 0; i < len; i++)
- {
- str[i] = (char) (((int)(Math.random() * 26)) + (int)'A');
- }
- return (new String(str, 0, len));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement