Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.00 KB | None | 0 0
  1. package Security;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.UUID;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.Material;
  10. import org.bukkit.Sound;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.inventory.InventoryClickEvent;
  15. import org.bukkit.event.player.PlayerLoginEvent;
  16. import org.bukkit.inventory.Inventory;
  17.  
  18. import Configs.PlayerC;
  19. import Main.PrisonAddon;
  20. import Utilitys.Utils;
  21.  
  22. public class PinLogin implements Listener {
  23.  
  24.     public static Map<UUID, Boolean> PlayersLoggedIN = new HashMap<UUID, Boolean>();
  25.     public static Map<UUID, Integer> PinTracker = new HashMap<UUID, Integer>();
  26.  
  27.     @EventHandler
  28.     public static void Login(PlayerLoginEvent e) {
  29.  
  30.         Player p = e.getPlayer();
  31.  
  32.         if (p.isOp() || p.hasPermission("maxbans.tempmute") || p.hasPermission("maxbans.mute")) {
  33.  
  34.             if (PlayerC.PinCode.HasData(p.getUniqueId())) {
  35.                 PlayersLoggedIN.put(p.getUniqueId(), false);
  36.                 Bukkit.getScheduler().scheduleSyncDelayedTask(PrisonAddon.plugin, new Runnable() {
  37.                     @Override
  38.                     public void run() {
  39.                         OpenPinInput(p);
  40.                     }
  41.                 }, 20);
  42.  
  43.             } else {
  44.                 SetNewPIN(p);
  45.             }
  46.         }
  47.  
  48.     }
  49.  
  50.     @EventHandler
  51.     public static void InventoryClick(InventoryClickEvent e) {
  52.         if (ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("⇭ Enter Your Pin ⇭")) {
  53.             if (e.getCurrentItem().getType() == Material.STAINED_GLASS_PANE) {
  54.                 int number = Integer.parseInt(e.getCurrentItem().getItemMeta().getLore().get(0));
  55.                 UpdatePinTracker((Player) e.getWhoClicked(), number);
  56.                 e.setCancelled(true);
  57.             }
  58.         }
  59.     }
  60.  
  61.     public static void ForceInventory() {
  62.  
  63.         Bukkit.getScheduler().scheduleSyncRepeatingTask(PrisonAddon.plugin, new Runnable() {
  64.             @Override
  65.             public void run() {
  66.  
  67.                 for (UUID uuid : PlayersLoggedIN.keySet()) {
  68.  
  69.                     if (Bukkit.getPlayer(uuid) == null || Bukkit.getPlayer(uuid).isOnline() == false) {
  70.                         continue;
  71.                     }
  72.  
  73.                     Player p = Bukkit.getPlayer(uuid);
  74.  
  75.                     if (PlayersLoggedIN.get(uuid) == false) {
  76.  
  77.                         if (PinInv != null) {
  78.                             if (p.getOpenInventory().getTopInventory().equals(PinInv) == false) {
  79.                                 OpenPinInput(p);
  80.                             }
  81.                         } else {
  82.                             OpenPinInput(p);
  83.                         }
  84.  
  85.                     }
  86.  
  87.                 }
  88.  
  89.             }
  90.         }, 2, 2);
  91.  
  92.     }
  93.  
  94.     public static Inventory PinInv = null;
  95.  
  96.     public static void OpenPinInput(Player p) {
  97.  
  98.         if (PinInv != null) {
  99.             p.openInventory(PinInv);
  100.         }
  101.  
  102.         Inventory inv = Bukkit.getServer().createInventory(null, 36, ChatColor.translateAlternateColorCodes('&', "&4⇭ &3Enter Your Pin &4⇭"));
  103.  
  104.         inv.setItem(3, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &61 &c-", 1, new String[] { "1" }, (byte) 4, null));
  105.         inv.setItem(4, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &62 &c-", 1, new String[] { "2" }, (byte) 11, null));
  106.         inv.setItem(5, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &63 &c-", 1, new String[] { "3" }, (byte) 6, null));
  107.         inv.setItem(12, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &64 &c-", 1, new String[] { "4" }, (byte) 2, null));
  108.         inv.setItem(13, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &65 &c-", 1, new String[] { "5" }, (byte) 12, null));
  109.         inv.setItem(14, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &66 &c-", 1, new String[] { "6" }, (byte) 14, null));
  110.         inv.setItem(21, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &67 &c-", 1, new String[] { "7" }, (byte) 3, null));
  111.         inv.setItem(22, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &68 &c-", 1, new String[] { "8" }, (byte) 1, null));
  112.         inv.setItem(23, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &69 &c-", 1, new String[] { "9" }, (byte) 15, null));
  113.         inv.setItem(31, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &60 &c-", 1, new String[] { "0" }, (byte) 0, null));
  114.  
  115.         PinInv = inv;
  116.         p.openInventory(PinInv);
  117.  
  118.     }
  119.  
  120.     public static void UpdatePinTracker(Player p, int Update) {
  121.         UUID PU = p.getUniqueId();
  122.         if (PinTracker.containsKey(PU)) {
  123.             int New = Integer.parseInt(PinTracker.get(PU) + "" + Update);
  124.             PinTracker.put(PU, New);
  125.         } else {
  126.             PinTracker.put(PU, Update);
  127.         }
  128.  
  129.         if (PinTracker.get(PU).toString().length() == 6) {
  130.             Validate(PinTracker.get(PU), p);
  131.             PinTracker.remove(PU);
  132.             return;
  133.         }
  134.        
  135.         p.playSound(p.getLocation(), Sound.NOTE_PLING, 1, 1);
  136.  
  137.     }
  138.  
  139.     public static void Validate(int InputPin, Player p) {
  140.         if (GetLoginPin(p) == InputPin) {
  141.             p.closeInventory();
  142.             Utils.SendTitles(p, "", "&2Successfully logged in");
  143.             PlayersLoggedIN.put(p.getUniqueId(), true);
  144.         } else {
  145.             Utils.SendActionBar(p, "&4-----> &cIncorrect PIN &4<-----");
  146.             Utils.SendMessage(p, "&4-----> &cIncorrect PIN &4<-----");
  147.             Utils.SendMessage(p, "&4-----> &cIncorrect PIN &4<-----");
  148.             Utils.SendMessage(p, "&4-----> &cIncorrect PIN &4<-----");
  149.         }
  150.     }
  151.  
  152.     public static long GetLoginPin(Player p) {
  153.  
  154.         if (PlayerC.PinCode.HasData(p.getUniqueId())) {
  155.             return PlayerC.PinCode.GetLong(p.getUniqueId(), 499392l);
  156.         } else {
  157.             return PlayerC.PinCode.GetLong(p.getUniqueId(), SetNewPIN(p));
  158.         }
  159.  
  160.     }
  161.  
  162.     public static int SetNewPIN(Player p) {
  163.  
  164.         int Pin = Utils.randInt(100000, 999999);
  165.  
  166.         PlayerC.PinCode.SetLong((long) Pin, true, p.getUniqueId());
  167.  
  168.         Bukkit.getScheduler().scheduleSyncDelayedTask(PrisonAddon.plugin, new Runnable() {
  169.             @Override
  170.             public void run() {
  171.                 Utils.SendTitles(p, "&4Save this PIN", "&6Your login pin is: &5" + Pin);
  172.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  173.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  174.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  175.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  176.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  177.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  178.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  179.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  180.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  181.                 Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
  182.  
  183.             }
  184.         }, 20);
  185.  
  186.         return Pin;
  187.     }
  188.  
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement