Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Premium extends Plugin implements Listener {
- Random r = new Random();
- Configuration config = null;
- boolean interLobby = true;
- String messageFail = null;
- List<String> commands = new ArrayList();
- List<String> commandsdisabled = new ArrayList();
- HashMap<String, Integer> antibot = new HashMap();
- boolean antibotenabled = false;
- boolean delayjoin = false;
- int MaxTries = 30;
- int delayCount = 30;
- HashMap<String, String> namesock = new HashMap();
- HashMap<String, String> prev = new HashMap();
- HashSet<String> nopay = new HashSet();
- HashSet<String> paid = new HashSet();
- HashMap cd2 = new HashMap();
- int joined = 0;
- private List<String> lobbyPremium = new ArrayList();
- private List<String> defaultServer = new ArrayList();
- String dbtable = null;
- String dbcolumn = null;
- Connection data = null;
- private boolean mySQLEnabled = false;
- public void onEnable() {
- if (!getDataFolder().exists()) {
- getDataFolder().mkdir();
- }
- File localFile1 = new File(getDataFolder() + ".players");
- if (!localFile1.exists()) {
- localFile1.mkdir();
- }
- File localFile2 = new File(getDataFolder(), "config.yml");
- if (!localFile2.exists()) {
- try {
- Files.copy(getResourceAsStream("config.yml"), localFile2.toPath(), new CopyOption[0]);
- } catch (IOException localIOException1) {
- }
- }
- try {
- this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
- } catch (IOException localIOException2) {
- Logger.getLogger(Premium.class.getName()).log(Level.SEVERE, null, localIOException2);
- }
- getProxy().getPluginManager().registerListener(this, this);
- //Original hub
- this.lobbyPremium = this.config.getStringList("nologinLobby");
- //Warez hub
- this.defaultServer = this.config.getStringList("defaultServer");
- //Zda mohou originalky do warez hubu
- this.interLobby = this.config.getBoolean("interLobby");
- //Deaktivace prikazu
- if (this.config.getStringList("DisabledBungeeCommandsInCrakedLobbys") != null) {
- this.commands = this.config.getStringList("DisabledBungeeCommandsInCrakedLobbys");
- }
- if (this.config.getStringList("MessageIsCommandDisabledInCrackedLobby") != null) {
- this.commandsdisabled = this.config.getStringList("MessageIsCommandDisabledInCrackedLobby");
- }
- if (this.config.getString("VerifiedPremiumUserFailToLogin") != null) {
- this.messageFail = Colorizer.Color(this.config.getString("VerifiedPremiumUserFailToLogin"));
- }
- if (this.config.getBoolean("AntiBot.enabled")) {
- resetBot();
- this.antibotenabled = true;
- this.MaxTries = this.config.getInt("AntiBot.Max");
- }
- if (this.config.getBoolean("JoinDelay.enabled")) {
- resetDelay();
- this.delayjoin = true;
- this.delayCount = this.config.getInt("JoinDelay.canJoin");
- }
- this.mySQLEnabled = this.config.getBoolean("MySQL.enabled");
- this.dbtable = this.config.getString("MySQL.dbtable");
- this.dbcolumn = this.config.getString("MySQL.dbcolumn");
- if (this.mySQLEnabled == true) {
- try {
- openData();
- createTable();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- if (this.config.getBoolean("MySQL.ConvertYMLtoMYSQL") == true) {
- try {
- File localFile3 = new File(getDataFolder() + ".players");
- File[] arrayOfFile1 = localFile3.listFiles();
- int i = 0;
- int j = 0;
- int k = 0;
- System.out.println("Converting all files in folder Premium.players");
- System.out.println("this can take few minutes...");
- for (File localFile4 : arrayOfFile1) {
- try {
- if (localFile4.isFile()) {
- i += 1;
- RegPremium(String.valueOf(localFile4.getName()).replace(".yml", ""));
- j += 1;
- }
- } catch (Exception localException2) {
- k += 1;
- }
- }
- System.out.println("Done, sucessfully converted" + j + " of " + i + " only " + k + " errors");
- } catch (Exception localException1) {
- Logger.getLogger(Premium.class.getName()).log(Level.SEVERE, null, localException1);
- }
- }
- }
- public void resetBot() {
- getProxy().getScheduler().schedule(this, new Runnable() {
- public void run() {
- Premium.this.antibot.clear();
- }
- }, this.config.getInt("AntiBot.clearDelay"), this.config.getInt("AntiBot.clearDelay"), TimeUnit.SECONDS);
- }
- public void resetDelay() {
- getProxy().getScheduler().schedule(this, new Runnable() {
- public void run() {
- Premium.this.joined = 0;
- }
- }, this.config.getInt("JoinDelay.everyAmountOfSeconds"), this.config.getInt("JoinDelay.everyAmountOfSeconds"), TimeUnit.SECONDS);
- }
- private void createTable() throws SQLException {
- String str = "CREATE TABLE IF NOT EXISTS `" + this.dbtable + "` (\n" + " `" + this.dbcolumn + "` varchar(40) NOT NULL\n" + ")";
- Statement localStatement = this.data.createStatement();
- localStatement.execute(str);
- }
- public void RegPremium(String paramString) {
- Object localObject;
- if (this.mySQLEnabled == true) {
- if (isPremium(paramString)) {
- return;
- }
- localObject = null;
- try {
- localObject = this.data.createStatement();
- } catch (SQLException localSQLException1) {
- }
- if (localObject != null) {
- try {
- ((Statement) localObject).executeUpdate("INSERT INTO `" + this.dbtable + "`(" + this.dbcolumn + ") VALUE ('" + paramString.toLowerCase() + "')");
- } catch (SQLException localSQLException2) {
- Logger.getLogger(Premium.class.getName()).log(Level.SEVERE, null, localSQLException2);
- }
- }
- } else {
- localObject = new File(getDataFolder() + ".players", paramString.toLowerCase() + ".yml");
- if (!((File) localObject).exists()) {
- try {
- ((File) localObject).createNewFile();
- } catch (IOException localIOException) {
- }
- }
- }
- }
- public void openData() throws SQLException {
- 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"));
- this.data = localMySQL.openConnection();
- }
- public boolean isPremium(String paramString) {
- if (this.mySQLEnabled == true) {
- try {
- Statement localStatement = null;
- try {
- localStatement = this.data.createStatement();
- } catch (SQLException localSQLException2) {
- }
- ResultSet localResultSet = null;
- if (localStatement == null) {
- return false;
- }
- localResultSet = localStatement.executeQuery("SELECT * FROM " + this.dbtable + " WHERE " + this.dbcolumn + " = '" + paramString.toLowerCase() + "'");
- if (localResultSet.next()) {
- try {
- String str = localResultSet.getString(1);
- return true;
- } catch (Exception localException) {
- return false;
- }
- }
- return false;
- } catch (SQLException localSQLException1) {
- Logger.getLogger(Premium.class.getName()).log(Level.SEVERE, null, localSQLException1);
- }
- }
- File localFile = new File(getDataFolder() + ".players", paramString.toLowerCase() + ".yml");
- return localFile.exists();
- }
- public boolean checkPaid(String paramString) {
- boolean bool = false;
- HttpURLConnection localHttpURLConnection = null;
- Scanner localScanner = null;
- try {
- URL localURL = new URL("https://api.mojang.com/users/profiles/minecraft/" + paramString);
- System.out.println(localURL.toString());
- localHttpURLConnection = (HttpURLConnection) localURL.openConnection();
- System.out.println("Spojeni...");
- localHttpURLConnection.setConnectTimeout(3000);
- localHttpURLConnection.setReadTimeout(3000);
- localScanner = new Scanner(localHttpURLConnection.getInputStream());
- if (localScanner.hasNextLine()) {
- String str = localScanner.nextLine();
- System.out.println(str);
- if (!str.isEmpty()) {
- bool = true;
- System.out.println("true");
- } else {
- bool = false;
- System.out.println("false");
- }
- }
- } catch (MalformedURLException localMalformedURLException) {
- } catch (UnknownHostException e) {
- } catch (IOException e) {
- } finally {
- if (localScanner != null) {
- localScanner.close();
- }
- if (localHttpURLConnection != null) {
- localHttpURLConnection.disconnect();
- }
- }
- System.out.println("Verified: " + paramString + " as " + bool);
- return bool;
- }
- public boolean hasPaid(String paramString) {
- if (this.nopay.contains(paramString)) {
- return false;
- }
- if (this.paid.contains(paramString)) {
- return true;
- }
- if (checkPaid(paramString)) {
- this.paid.add(paramString);
- return true;
- }
- this.nopay.add(paramString);
- return false;
- }
- @EventHandler
- public void onJA5(ServerConnectEvent paramServerConnectEvent) {
- String str = paramServerConnectEvent.getPlayer().getName();
- ProxiedPlayer localProxiedPlayer = paramServerConnectEvent.getPlayer();
- try {
- if ((this.interLobby == true) && (localProxiedPlayer.getServer().getInfo().getName() != null)) {
- System.out.println("returning interlobby");
- return;
- }
- } catch (Exception localException) {
- }
- if (this.defaultServer.contains(paramServerConnectEvent.getTarget().getName())) {
- if (isPremium(str)) {
- if (this.lobbyPremium.size() > 1) {
- paramServerConnectEvent.setTarget(getProxy().getServerInfo((String) this.lobbyPremium.get(this.r.nextInt(this.lobbyPremium.size() - 1))));
- } else {
- paramServerConnectEvent.setTarget(getProxy().getServerInfo((String) this.lobbyPremium.get(0)));
- }
- }
- } else if (this.lobbyPremium.contains(paramServerConnectEvent.getTarget().getName())) {
- if (isPremium(str)) {
- if (this.defaultServer.size() > 1) {
- paramServerConnectEvent.setTarget(getProxy().getServerInfo((String) this.defaultServer.get(this.r.nextInt(this.defaultServer.size() - 1))));
- }
- } else {
- paramServerConnectEvent.setTarget(getProxy().getServerInfo((String) this.defaultServer.get(0)));
- }
- }
- }
- @EventHandler
- public void onChat(ChatEvent paramChatEvent) {
- ProxiedPlayer localProxiedPlayer = (ProxiedPlayer) paramChatEvent.getSender();
- if ((this.defaultServer.contains(localProxiedPlayer.getServer().getInfo().getName())) && (this.commands != null) && (!this.commands.isEmpty()) && (paramChatEvent.isCommand())) {
- Iterator localIterator1 = this.commands.iterator();
- while (localIterator1.hasNext()) {
- String str1 = (String) localIterator1.next();
- if (paramChatEvent.getMessage().toLowerCase().startsWith(str1.toLowerCase())) {
- if (this.commandsdisabled != null) {
- String str2;
- for (Iterator localIterator2 = this.commandsdisabled.iterator(); localIterator2.hasNext(); localProxiedPlayer.sendMessage(Colorizer.Color(str2))) {
- str2 = (String) localIterator2.next();
- }
- }
- paramChatEvent.setCancelled(true);
- return;
- }
- }
- }
- }
- @EventHandler
- public void onJA2(PreLoginEvent paramPreLoginEvent) {
- String str1 = paramPreLoginEvent.getConnection().getName();
- String str2 = paramPreLoginEvent.getConnection().getName().replaceAll("_", "").replace("_", "");
- Pattern localPattern = Pattern.compile("[^a-zA-Z0-9]");
- if (localPattern.matcher(str2).find()) {
- paramPreLoginEvent.setCancelReason("&c&lNeplatne znaky v nicku!");
- paramPreLoginEvent.setCancelled(true);
- }
- String str3 = paramPreLoginEvent.getConnection().getAddress().getAddress().getCanonicalHostName();
- if (this.delayjoin) {
- this.joined += 1;
- if (this.joined > this.delayCount) {
- paramPreLoginEvent.setCancelReason("&c&lMnoho hracu se snazi pripojit, cekej prosim...");
- paramPreLoginEvent.setCancelled(true);
- }
- }
- if (this.antibotenabled) {
- if (this.antibot.containsKey(str3)) {
- int i = ((Integer) this.antibot.get(str3)).intValue();
- if (i > this.MaxTries) {
- paramPreLoginEvent.setCancelReason("&c&lTvoje IP byla detekovana jako Bot IP! Cekej prosim...");
- paramPreLoginEvent.setCancelled(true);
- }
- this.antibot.put(str3, Integer.valueOf(i + 1));
- } else {
- this.antibot.put(str3, Integer.valueOf(1));
- }
- }
- if (isPremium(str1)) {
- System.out.println("setted to online mode, and returning");
- if (this.namesock.containsKey(str1)) {
- this.namesock.remove(str1);
- }
- if (this.prev.containsKey(str3)) {
- this.prev.remove(str3);
- }
- paramPreLoginEvent.getConnection().setOnlineMode(true);
- if (this.messageFail != null) {
- this.cd2.put(str1, str3);
- }
- return;
- }
- System.out.println("not setted to online mode");
- if ((this.messageFail != null) && (!this.cd2.isEmpty()) && (this.cd2.containsKey(str1)) && (((String) this.cd2.get(str1)).equalsIgnoreCase(str3))) {
- this.cd2.remove(str1);
- paramPreLoginEvent.setCancelReason(this.messageFail);
- paramPreLoginEvent.setCancelled(true);
- return;
- }
- paramPreLoginEvent.getConnection().setOnlineMode(true);
- if (!hasPaid(str1)) {
- paramPreLoginEvent.getConnection().setOnlineMode(false);
- return;
- }
- if ((this.namesock.containsKey(str1)) && (((String) this.namesock.get(str1)).equalsIgnoreCase(str3))) {
- paramPreLoginEvent.getConnection().setOnlineMode(false);
- return;
- }
- if ((this.prev.containsKey(str3)) && (((String) this.prev.get(str3)).equalsIgnoreCase(str1))) {
- this.namesock.put(str1, str3);
- paramPreLoginEvent.getConnection().setOnlineMode(false);
- }
- this.prev.put(str3, paramPreLoginEvent.getConnection().getName());
- }
- @EventHandler
- public void onJA3(LoginEvent paramLoginEvent) {
- String str1 = paramLoginEvent.getConnection().getName();
- String str2 = paramLoginEvent.getConnection().getAddress().getAddress().getCanonicalHostName();
- if ((this.messageFail != null) && (this.cd2.containsKey(str1))) {
- this.cd2.remove(str1);
- }
- if ((this.namesock.containsKey(str1)) && (((String) this.namesock.get(str1)).equalsIgnoreCase(str2))) {
- return;
- }
- if (!hasPaid(str1)) {
- return;
- }
- if (paramLoginEvent.getConnection().isOnlineMode()) {
- RegPremium(str1);
- this.namesock.remove(str1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement