Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Security;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.player.PlayerLoginEvent;
- import org.bukkit.inventory.Inventory;
- import Configs.PlayerC;
- import Main.PrisonAddon;
- import Utilitys.Utils;
- public class PinLogin implements Listener {
- public static Map<UUID, Boolean> PlayersLoggedIN = new HashMap<UUID, Boolean>();
- public static Map<UUID, Integer> PinTracker = new HashMap<UUID, Integer>();
- @EventHandler
- public static void Login(PlayerLoginEvent e) {
- Player p = e.getPlayer();
- if (p.isOp() || p.hasPermission("maxbans.tempmute") || p.hasPermission("maxbans.mute")) {
- if (PlayerC.PinCode.HasData(p.getUniqueId())) {
- PlayersLoggedIN.put(p.getUniqueId(), false);
- Bukkit.getScheduler().scheduleSyncDelayedTask(PrisonAddon.plugin, new Runnable() {
- @Override
- public void run() {
- OpenPinInput(p);
- }
- }, 20);
- } else {
- SetNewPIN(p);
- }
- }
- }
- @EventHandler
- public static void InventoryClick(InventoryClickEvent e) {
- if (ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("⇭ Enter Your Pin ⇭")) {
- if (e.getCurrentItem().getType() == Material.STAINED_GLASS_PANE) {
- int number = Integer.parseInt(e.getCurrentItem().getItemMeta().getLore().get(0));
- UpdatePinTracker((Player) e.getWhoClicked(), number);
- e.setCancelled(true);
- }
- }
- }
- public static void ForceInventory() {
- Bukkit.getScheduler().scheduleSyncRepeatingTask(PrisonAddon.plugin, new Runnable() {
- @Override
- public void run() {
- for (UUID uuid : PlayersLoggedIN.keySet()) {
- if (Bukkit.getPlayer(uuid) == null || Bukkit.getPlayer(uuid).isOnline() == false) {
- continue;
- }
- Player p = Bukkit.getPlayer(uuid);
- if (PlayersLoggedIN.get(uuid) == false) {
- if (PinInv != null) {
- if (p.getOpenInventory().getTopInventory().equals(PinInv) == false) {
- OpenPinInput(p);
- }
- } else {
- OpenPinInput(p);
- }
- }
- }
- }
- }, 2, 2);
- }
- public static Inventory PinInv = null;
- public static void OpenPinInput(Player p) {
- if (PinInv != null) {
- p.openInventory(PinInv);
- }
- Inventory inv = Bukkit.getServer().createInventory(null, 36, ChatColor.translateAlternateColorCodes('&', "&4⇭ &3Enter Your Pin &4⇭"));
- inv.setItem(3, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &61 &c-", 1, new String[] { "1" }, (byte) 4, null));
- inv.setItem(4, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &62 &c-", 1, new String[] { "2" }, (byte) 11, null));
- inv.setItem(5, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &63 &c-", 1, new String[] { "3" }, (byte) 6, null));
- inv.setItem(12, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &64 &c-", 1, new String[] { "4" }, (byte) 2, null));
- inv.setItem(13, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &65 &c-", 1, new String[] { "5" }, (byte) 12, null));
- inv.setItem(14, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &66 &c-", 1, new String[] { "6" }, (byte) 14, null));
- inv.setItem(21, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &67 &c-", 1, new String[] { "7" }, (byte) 3, null));
- inv.setItem(22, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &68 &c-", 1, new String[] { "8" }, (byte) 1, null));
- inv.setItem(23, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &69 &c-", 1, new String[] { "9" }, (byte) 15, null));
- inv.setItem(31, Utils.CIFI(Material.STAINED_GLASS_PANE, "&c- &60 &c-", 1, new String[] { "0" }, (byte) 0, null));
- PinInv = inv;
- p.openInventory(PinInv);
- }
- public static void UpdatePinTracker(Player p, int Update) {
- UUID PU = p.getUniqueId();
- if (PinTracker.containsKey(PU)) {
- int New = Integer.parseInt(PinTracker.get(PU) + "" + Update);
- PinTracker.put(PU, New);
- } else {
- PinTracker.put(PU, Update);
- }
- if (PinTracker.get(PU).toString().length() == 6) {
- Validate(PinTracker.get(PU), p);
- PinTracker.remove(PU);
- return;
- }
- p.playSound(p.getLocation(), Sound.NOTE_PLING, 1, 1);
- }
- public static void Validate(int InputPin, Player p) {
- if (GetLoginPin(p) == InputPin) {
- p.closeInventory();
- Utils.SendTitles(p, "", "&2Successfully logged in");
- PlayersLoggedIN.put(p.getUniqueId(), true);
- } else {
- Utils.SendActionBar(p, "&4-----> &cIncorrect PIN &4<-----");
- Utils.SendMessage(p, "&4-----> &cIncorrect PIN &4<-----");
- Utils.SendMessage(p, "&4-----> &cIncorrect PIN &4<-----");
- Utils.SendMessage(p, "&4-----> &cIncorrect PIN &4<-----");
- }
- }
- public static long GetLoginPin(Player p) {
- if (PlayerC.PinCode.HasData(p.getUniqueId())) {
- return PlayerC.PinCode.GetLong(p.getUniqueId(), 499392l);
- } else {
- return PlayerC.PinCode.GetLong(p.getUniqueId(), SetNewPIN(p));
- }
- }
- public static int SetNewPIN(Player p) {
- int Pin = Utils.randInt(100000, 999999);
- PlayerC.PinCode.SetLong((long) Pin, true, p.getUniqueId());
- Bukkit.getScheduler().scheduleSyncDelayedTask(PrisonAddon.plugin, new Runnable() {
- @Override
- public void run() {
- Utils.SendTitles(p, "&4Save this PIN", "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- Utils.SendMessage(p, "&6Your login pin is: &5" + Pin);
- }
- }, 20);
- return Pin;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement