Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.91 KB | None | 0 0
  1. public class Premium extends Plugin implements Listener {
  2.     Random r = new Random();
  3.     Configuration config = null;
  4.     boolean interLobby = true;
  5.     String messageFail = null;
  6.     List<String> commands = new ArrayList();
  7.     List<String> commandsdisabled = new ArrayList();
  8.     HashMap<String, Integer> antibot = new HashMap();
  9.     boolean antibotenabled = false;
  10.     boolean delayjoin = false;
  11.     int MaxTries = 30;
  12.     int delayCount = 30;
  13.     HashMap<String, String> namesock = new HashMap();
  14.     HashMap<String, String> prev = new HashMap();
  15.     HashSet<String> nopay = new HashSet();
  16.     HashSet<String> paid = new HashSet();
  17.     HashMap cd2 = new HashMap();
  18.     int joined = 0;
  19.     private List<String> lobbyPremium = new ArrayList();
  20.     private List<String> defaultServer = new ArrayList();
  21.     String dbtable = null;
  22.     String dbcolumn = null;
  23.     Connection data = null;
  24.     private boolean mySQLEnabled = false;
  25.     public void onEnable() {
  26.         if (!getDataFolder().exists()) {
  27.             getDataFolder().mkdir();
  28.         }
  29.         File localFile1 = new File(getDataFolder() + ".players");
  30.         if (!localFile1.exists()) {
  31.             localFile1.mkdir();
  32.         }
  33.         File localFile2 = new File(getDataFolder(), "config.yml");
  34.         if (!localFile2.exists()) {
  35.             try {
  36.                 Files.copy(getResourceAsStream("config.yml"), localFile2.toPath(), new CopyOption[0]);
  37.             } catch (IOException localIOException1) {
  38.             }
  39.         }
  40.         try {
  41.             this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
  42.         } catch (IOException localIOException2) {
  43.             Logger.getLogger(Premium.class.getName()).log(Level.SEVERE, null, localIOException2);
  44.         }
  45.         getProxy().getPluginManager().registerListener(this, this);
  46.         //Original hub
  47.         this.lobbyPremium = this.config.getStringList("nologinLobby");
  48.         //Warez hub
  49.         this.defaultServer = this.config.getStringList("defaultServer");
  50.         //Zda mohou originalky do warez hubu
  51.         this.interLobby = this.config.getBoolean("interLobby");
  52.         //Deaktivace prikazu
  53.         if (this.config.getStringList("DisabledBungeeCommandsInCrakedLobbys") != null) {
  54.             this.commands = this.config.getStringList("DisabledBungeeCommandsInCrakedLobbys");
  55.         }
  56.         if (this.config.getStringList("MessageIsCommandDisabledInCrackedLobby") != null) {
  57.             this.commandsdisabled = this.config.getStringList("MessageIsCommandDisabledInCrackedLobby");
  58.         }
  59.         if (this.config.getString("VerifiedPremiumUserFailToLogin") != null) {
  60.             this.messageFail = Colorizer.Color(this.config.getString("VerifiedPremiumUserFailToLogin"));
  61.         }
  62.         if (this.config.getBoolean("AntiBot.enabled")) {
  63.             resetBot();
  64.             this.antibotenabled = true;
  65.             this.MaxTries = this.config.getInt("AntiBot.Max");
  66.         }
  67.         if (this.config.getBoolean("JoinDelay.enabled")) {
  68.             resetDelay();
  69.             this.delayjoin = true;
  70.             this.delayCount = this.config.getInt("JoinDelay.canJoin");
  71.         }
  72.         this.mySQLEnabled = this.config.getBoolean("MySQL.enabled");
  73.         this.dbtable = this.config.getString("MySQL.dbtable");
  74.         this.dbcolumn = this.config.getString("MySQL.dbcolumn");
  75.         if (this.mySQLEnabled == true) {
  76.             try {
  77.                 openData();
  78.                 createTable();
  79.             } catch (SQLException e) {
  80.                 e.printStackTrace();
  81.             }
  82.         }
  83.         if (this.config.getBoolean("MySQL.ConvertYMLtoMYSQL") == true) {
  84.             try {
  85.                 File localFile3 = new File(getDataFolder() + ".players");
  86.                 File[] arrayOfFile1 = localFile3.listFiles();
  87.                 int i = 0;
  88.                 int j = 0;
  89.                 int k = 0;
  90.                 System.out.println("Converting all files in folder Premium.players");
  91.                 System.out.println("this can take few minutes...");
  92.                 for (File localFile4 : arrayOfFile1) {
  93.                     try {
  94.                         if (localFile4.isFile()) {
  95.                             i += 1;
  96.                             RegPremium(String.valueOf(localFile4.getName()).replace(".yml", ""));
  97.                             j += 1;
  98.                         }
  99.                     } catch (Exception localException2) {
  100.                         k += 1;
  101.                     }
  102.                 }
  103.                 System.out.println("Done, sucessfully converted" + j + " of " + i + " only " + k + " errors");
  104.             } catch (Exception localException1) {
  105.                 Logger.getLogger(Premium.class.getName()).log(Level.SEVERE, null, localException1);
  106.             }
  107.         }
  108.     }
  109.     public void resetBot() {
  110.         getProxy().getScheduler().schedule(this, new Runnable() {
  111.             public void run() {
  112.                 Premium.this.antibot.clear();
  113.             }
  114.         }, this.config.getInt("AntiBot.clearDelay"), this.config.getInt("AntiBot.clearDelay"), TimeUnit.SECONDS);
  115.     }
  116.     public void resetDelay() {
  117.         getProxy().getScheduler().schedule(this, new Runnable() {
  118.             public void run() {
  119.                 Premium.this.joined = 0;
  120.             }
  121.         }, this.config.getInt("JoinDelay.everyAmountOfSeconds"), this.config.getInt("JoinDelay.everyAmountOfSeconds"), TimeUnit.SECONDS);
  122.     }
  123.     private void createTable() throws SQLException {
  124.         String str = "CREATE TABLE IF NOT EXISTS `" + this.dbtable + "` (\n" + "  `" + this.dbcolumn + "` varchar(40) NOT NULL\n" + ")";
  125.         Statement localStatement = this.data.createStatement();
  126.         localStatement.execute(str);
  127.     }
  128.     public void RegPremium(String paramString) {
  129.         Object localObject;
  130.         if (this.mySQLEnabled == true) {
  131.             if (isPremium(paramString)) {
  132.                 return;
  133.             }
  134.             localObject = null;
  135.             try {
  136.                 localObject = this.data.createStatement();
  137.             } catch (SQLException localSQLException1) {
  138.             }
  139.             if (localObject != null) {
  140.                 try {
  141.                     ((Statement) localObject).executeUpdate("INSERT INTO `" + this.dbtable + "`(" + this.dbcolumn + ") VALUE ('" + paramString.toLowerCase() + "')");
  142.                 } catch (SQLException localSQLException2) {
  143.                     Logger.getLogger(Premium.class.getName()).log(Level.SEVERE, null, localSQLException2);
  144.                 }
  145.             }
  146.         } else {
  147.             localObject = new File(getDataFolder() + ".players", paramString.toLowerCase() + ".yml");
  148.             if (!((File) localObject).exists()) {
  149.                 try {
  150.                     ((File) localObject).createNewFile();
  151.                 } catch (IOException localIOException) {
  152.                 }
  153.             }
  154.         }
  155.     }
  156.     public void openData() throws SQLException {
  157.         MySQL localMySQL = new MySQL(this, this.config.getString("MySQL.host"), this.config.getString("MySQL.port"), this.config.getString("MySQL.dbname"), this.config.getString("MySQL.dbuser"), this.config.getString("MySQL.password"));
  158.         this.data = localMySQL.openConnection();
  159.     }
  160.     public boolean isPremium(String paramString) {
  161.         if (this.mySQLEnabled == true) {
  162.             try {
  163.                 Statement localStatement = null;
  164.                 try {
  165.                     localStatement = this.data.createStatement();
  166.                 } catch (SQLException localSQLException2) {
  167.                 }
  168.                 ResultSet localResultSet = null;
  169.                 if (localStatement == null) {
  170.                     return false;
  171.                 }
  172.                 localResultSet = localStatement.executeQuery("SELECT * FROM " + this.dbtable + " WHERE " + this.dbcolumn + " = '" + paramString.toLowerCase() + "'");
  173.                 if (localResultSet.next()) {
  174.                     try {
  175.                         String str = localResultSet.getString(1);
  176.                         return true;
  177.                     } catch (Exception localException) {
  178.                         return false;
  179.                     }
  180.                 }
  181.                 return false;
  182.             } catch (SQLException localSQLException1) {
  183.                 Logger.getLogger(Premium.class.getName()).log(Level.SEVERE, null, localSQLException1);
  184.             }
  185.         }
  186.         File localFile = new File(getDataFolder() + ".players", paramString.toLowerCase() + ".yml");
  187.         return localFile.exists();
  188.     }
  189.     public boolean checkPaid(String paramString) {
  190.         boolean bool = false;
  191.         HttpURLConnection localHttpURLConnection = null;
  192.         Scanner localScanner = null;
  193.         try {
  194.             URL localURL = new URL("https://api.mojang.com/users/profiles/minecraft/" + paramString);
  195.             System.out.println(localURL.toString());
  196.             localHttpURLConnection = (HttpURLConnection) localURL.openConnection();
  197.             System.out.println("Spojeni...");
  198.             localHttpURLConnection.setConnectTimeout(3000);
  199.             localHttpURLConnection.setReadTimeout(3000);
  200.             localScanner = new Scanner(localHttpURLConnection.getInputStream());
  201.             if (localScanner.hasNextLine()) {
  202.                 String str = localScanner.nextLine();
  203.                 System.out.println(str);
  204.                 if (!str.isEmpty()) {
  205.                     bool = true;
  206.                     System.out.println("true");
  207.                 } else {
  208.                     bool = false;
  209.                     System.out.println("false");
  210.                 }
  211.             }
  212.         } catch (MalformedURLException localMalformedURLException) {
  213.         } catch (UnknownHostException e) {
  214.         } catch (IOException e) {
  215.         } finally {
  216.             if (localScanner != null) {
  217.                 localScanner.close();
  218.             }
  219.             if (localHttpURLConnection != null) {
  220.                 localHttpURLConnection.disconnect();
  221.             }
  222.         }
  223.         System.out.println("Verified: " + paramString + " as " + bool);
  224.         return bool;
  225.     }
  226.     public boolean hasPaid(String paramString) {
  227.         if (this.nopay.contains(paramString)) {
  228.             return false;
  229.         }
  230.         if (this.paid.contains(paramString)) {
  231.             return true;
  232.         }
  233.         if (checkPaid(paramString)) {
  234.             this.paid.add(paramString);
  235.             return true;
  236.         }
  237.         this.nopay.add(paramString);
  238.         return false;
  239.     }
  240.     @EventHandler
  241.     public void onJA5(ServerConnectEvent paramServerConnectEvent) {
  242.         String str = paramServerConnectEvent.getPlayer().getName();
  243.         ProxiedPlayer localProxiedPlayer = paramServerConnectEvent.getPlayer();
  244.         try {
  245.             if ((this.interLobby == true) && (localProxiedPlayer.getServer().getInfo().getName() != null)) {
  246.                 System.out.println("returning interlobby");
  247.                 return;
  248.             }
  249.         } catch (Exception localException) {
  250.         }
  251.         if (this.defaultServer.contains(paramServerConnectEvent.getTarget().getName())) {
  252.             if (isPremium(str)) {
  253.                 if (this.lobbyPremium.size() > 1) {
  254.                     paramServerConnectEvent.setTarget(getProxy().getServerInfo((String) this.lobbyPremium.get(this.r.nextInt(this.lobbyPremium.size() - 1))));
  255.                 } else {
  256.                     paramServerConnectEvent.setTarget(getProxy().getServerInfo((String) this.lobbyPremium.get(0)));
  257.                 }
  258.             }
  259.         } else if (this.lobbyPremium.contains(paramServerConnectEvent.getTarget().getName())) {
  260.             if (isPremium(str)) {
  261.                 if (this.defaultServer.size() > 1) {
  262.                     paramServerConnectEvent.setTarget(getProxy().getServerInfo((String) this.defaultServer.get(this.r.nextInt(this.defaultServer.size() - 1))));
  263.                 }
  264.             } else {
  265.                 paramServerConnectEvent.setTarget(getProxy().getServerInfo((String) this.defaultServer.get(0)));
  266.             }
  267.         }
  268.     }
  269.     @EventHandler
  270.     public void onChat(ChatEvent paramChatEvent) {
  271.         ProxiedPlayer localProxiedPlayer = (ProxiedPlayer) paramChatEvent.getSender();
  272.         if ((this.defaultServer.contains(localProxiedPlayer.getServer().getInfo().getName())) && (this.commands != null) && (!this.commands.isEmpty()) && (paramChatEvent.isCommand())) {
  273.             Iterator localIterator1 = this.commands.iterator();
  274.             while (localIterator1.hasNext()) {
  275.                 String str1 = (String) localIterator1.next();
  276.                 if (paramChatEvent.getMessage().toLowerCase().startsWith(str1.toLowerCase())) {
  277.                     if (this.commandsdisabled != null) {
  278.                         String str2;
  279.                         for (Iterator localIterator2 = this.commandsdisabled.iterator(); localIterator2.hasNext(); localProxiedPlayer.sendMessage(Colorizer.Color(str2))) {
  280.                             str2 = (String) localIterator2.next();
  281.                         }
  282.                     }
  283.                     paramChatEvent.setCancelled(true);
  284.                     return;
  285.                 }
  286.             }
  287.         }
  288.     }
  289.     @EventHandler
  290.     public void onJA2(PreLoginEvent paramPreLoginEvent) {
  291.         String str1 = paramPreLoginEvent.getConnection().getName();
  292.         String str2 = paramPreLoginEvent.getConnection().getName().replaceAll("_", "").replace("_", "");
  293.         Pattern localPattern = Pattern.compile("[^a-zA-Z0-9]");
  294.         if (localPattern.matcher(str2).find()) {
  295.             paramPreLoginEvent.setCancelReason("&c&lNeplatne znaky v nicku!");
  296.             paramPreLoginEvent.setCancelled(true);
  297.         }
  298.         String str3 = paramPreLoginEvent.getConnection().getAddress().getAddress().getCanonicalHostName();
  299.         if (this.delayjoin) {
  300.             this.joined += 1;
  301.             if (this.joined > this.delayCount) {
  302.                 paramPreLoginEvent.setCancelReason("&c&lMnoho hracu se snazi pripojit, cekej prosim...");
  303.                 paramPreLoginEvent.setCancelled(true);
  304.             }
  305.         }
  306.         if (this.antibotenabled) {
  307.             if (this.antibot.containsKey(str3)) {
  308.                 int i = ((Integer) this.antibot.get(str3)).intValue();
  309.                 if (i > this.MaxTries) {
  310.                     paramPreLoginEvent.setCancelReason("&c&lTvoje IP byla detekovana jako Bot IP! Cekej prosim...");
  311.                     paramPreLoginEvent.setCancelled(true);
  312.                 }
  313.                 this.antibot.put(str3, Integer.valueOf(i + 1));
  314.             } else {
  315.                 this.antibot.put(str3, Integer.valueOf(1));
  316.             }
  317.         }
  318.         if (isPremium(str1)) {
  319.             System.out.println("setted to online mode, and returning");
  320.             if (this.namesock.containsKey(str1)) {
  321.                 this.namesock.remove(str1);
  322.             }
  323.             if (this.prev.containsKey(str3)) {
  324.                 this.prev.remove(str3);
  325.             }
  326.             paramPreLoginEvent.getConnection().setOnlineMode(true);
  327.             if (this.messageFail != null) {
  328.                 this.cd2.put(str1, str3);
  329.             }
  330.             return;
  331.         }
  332.         System.out.println("not setted to online mode");
  333.         if ((this.messageFail != null) && (!this.cd2.isEmpty()) && (this.cd2.containsKey(str1)) && (((String) this.cd2.get(str1)).equalsIgnoreCase(str3))) {
  334.             this.cd2.remove(str1);
  335.             paramPreLoginEvent.setCancelReason(this.messageFail);
  336.             paramPreLoginEvent.setCancelled(true);
  337.             return;
  338.         }
  339.         paramPreLoginEvent.getConnection().setOnlineMode(true);
  340.         if (!hasPaid(str1)) {
  341.             paramPreLoginEvent.getConnection().setOnlineMode(false);
  342.             return;
  343.         }
  344.         if ((this.namesock.containsKey(str1)) && (((String) this.namesock.get(str1)).equalsIgnoreCase(str3))) {
  345.             paramPreLoginEvent.getConnection().setOnlineMode(false);
  346.             return;
  347.         }
  348.         if ((this.prev.containsKey(str3)) && (((String) this.prev.get(str3)).equalsIgnoreCase(str1))) {
  349.             this.namesock.put(str1, str3);
  350.             paramPreLoginEvent.getConnection().setOnlineMode(false);
  351.         }
  352.         this.prev.put(str3, paramPreLoginEvent.getConnection().getName());
  353.     }
  354.     @EventHandler
  355.     public void onJA3(LoginEvent paramLoginEvent) {
  356.         String str1 = paramLoginEvent.getConnection().getName();
  357.         String str2 = paramLoginEvent.getConnection().getAddress().getAddress().getCanonicalHostName();
  358.         if ((this.messageFail != null) && (this.cd2.containsKey(str1))) {
  359.             this.cd2.remove(str1);
  360.         }
  361.         if ((this.namesock.containsKey(str1)) && (((String) this.namesock.get(str1)).equalsIgnoreCase(str2))) {
  362.             return;
  363.         }
  364.         if (!hasPaid(str1)) {
  365.             return;
  366.         }
  367.         if (paramLoginEvent.getConnection().isOnlineMode()) {
  368.             RegPremium(str1);
  369.             this.namesock.remove(str1);
  370.         }
  371.     }
  372. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement