Advertisement
Guest User

PlayerJoin

a guest
Jun 18th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.47 KB | None | 0 0
  1. package com.gmail.bloodywampire.old.listeners;
  2.  
  3. import java.util.Properties;
  4. import javax.mail.Message;
  5. import javax.mail.MessagingException;
  6. import javax.mail.PasswordAuthentication;
  7. import javax.mail.Session;
  8. import javax.mail.Transport;
  9. import javax.mail.internet.InternetAddress;
  10. import javax.mail.internet.MimeMessage;
  11. import org.bukkit.ChatColor;
  12. import org.bukkit.Location;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.event.player.PlayerJoinEvent;
  16. import com.gmail.bloodywampire.old.Main.Main;
  17. import com.gmail.bloodywampire.old.commands.Token;
  18. import com.gmail.bloodywampire.old.libs.Time;
  19.  
  20. public class PlayerJoin implements Listener
  21. {
  22.     public static String pass = randomString( 6 );
  23.    
  24.     public void Event( PlayerJoinEvent event )
  25.     {
  26.         Player p = event.getPlayer();
  27.         String name = p.getName();
  28.          event.setJoinMessage((Object) ChatColor.BLUE + name + "dolaczy."   );
  29.     }
  30.    
  31.     public static void playerJoinMethod( Player player ) throws MessagingException
  32.     {
  33.         String where = "nick = '" + player.getName() + "'";
  34.         if (player.hasPermission("oldcraft.adm")){
  35.             long time = Time.getTime();
  36.             long t1 =   (long) Main.mysql.getRecord("token", "czas",  where);
  37.             if (t1 == time) {
  38.                 player.kickPlayer(Main.prefix + ChatColor.RED + " Wygenerowano nowy token. Sprawdz skrzynke mailowa.");
  39.                 long t2 = time + Time.addToTime(0, 0, 0, 1, 0);
  40.                 Main.mysql.updateRecord("token", "czas", t2, where);
  41.                 Main.mysql.updateRecord("token", "token", pass, where);
  42.                 PlayerJoin.send();
  43.                 return;
  44.             }
  45.             else {
  46.                 while (Token.tokenw = false){
  47.                 }
  48.                 do {
  49.                     player.sendMessage(Main.prefix + ChatColor.RED + " Podaj token.");
  50.                     Location teleportLocation = new Location(player.getWorld(), 0, 66, 0);
  51.                     player.teleport(teleportLocation);
  52.                 }while (Token.tokenw = true);
  53.              return;
  54.             }
  55.         }
  56.        
  57.        
  58.     }
  59.    
  60.     static void send() throws MessagingException {
  61.         final String username = "oldcraftmail@gmail.com";
  62.         final String password = "1QA2ws3ed";
  63.  
  64.         Properties props = new Properties();
  65.         props.put("mail.smtp.starttls.enable", "true");
  66.         props.put("mail.smtp.auth", "true");
  67.         props.put("mail.smtp.host", "smtp.gmail.com");
  68.         props.put("mail.smtp.port", "587");
  69.  
  70.         Session session = Session.getInstance(props,
  71.           new javax.mail.Authenticator() {
  72.             protected PasswordAuthentication getPasswordAuthentication() {
  73.                 return new PasswordAuthentication(username, password);
  74.             }
  75.           });
  76.  
  77.         try {
  78.  
  79.             Message message = new MimeMessage(session);
  80.             message.setFrom(new InternetAddress("oldcraftmail@gmail.com"));
  81.             message.setRecipients(Message.RecipientType.TO,
  82.                 InternetAddress.parse("admoldcraft@gmail.com"));
  83.             message.setSubject("Nowy Token");
  84.             message.setText("Twój nowy token to: " + pass  
  85.                 + "Proszę nie odpisywać na tego maila.");
  86.  
  87.             Transport.send(message);
  88.  
  89.             System.out.println(Main.prefix + ChatColor.GOLD + " Wyslano maila z tokenem.");
  90.  
  91.         } catch (MessagingException e) {
  92.             throw new RuntimeException(e);
  93.         }
  94.     }
  95.    
  96.     public static String randomString(int len)
  97.     {
  98.         char[] str = new char[100];
  99.  
  100.         for (int i = 0; i < len; i++)
  101.         {
  102.           str[i] = (char) (((int)(Math.random() * 26)) + (int)'A');
  103.         }
  104.  
  105.         return (new String(str, 0, len));
  106.     }
  107.    
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement