Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. Skip to content
  2. Why GitHub?
  3. Business
  4. Explore
  5. Marketplace
  6. Pricing
  7.  
  8. Search
  9.  
  10. Sign in
  11. Sign up
  12. 1 1 2 funkemunky/Mojank
  13. Code Issues 0 Pull requests 0 Projects 0 Insights
  14. Join GitHub today
  15. GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
  16.  
  17. Mojank/src/cc/funkemunky/fixer/impl/fixes/AntiVPN.java
  18. 5f287e9 on Oct 12
  19. @funkemunky funkemunky changes
  20.  
  21. 111 lines (98 sloc) 4.62 KB
  22. package cc.funkemunky.fixer.impl.fixes;
  23.  
  24. import cc.funkemunky.fixer.Mojank;
  25. import cc.funkemunky.fixer.api.fixes.Fix;
  26. import cc.funkemunky.fixer.api.utils.Color;
  27. import org.bukkit.entity.Player;
  28. import org.bukkit.event.EventHandler;
  29. import org.bukkit.event.player.PlayerJoinEvent;
  30. import org.bukkit.scheduler.BukkitRunnable;
  31. import org.json.JSONException;
  32. import org.json.JSONObject;
  33.  
  34. import java.io.BufferedReader;
  35. import java.io.IOException;
  36. import java.io.InputStreamReader;
  37. import java.net.URL;
  38. import java.net.URLConnection;
  39. import java.util.HashMap;
  40. import java.util.Map;
  41.  
  42. public class AntiVPN extends Fix {
  43. public AntiVPN() {
  44. super("AntiVPN", true);
  45.  
  46. addConfigValue("kickMessage", "&6Mojank AntiVPN\n&7You have been detected using a VPN on the IP &c%ip% &7in &c%country%&7.");
  47. addConfigValue("allowPermBypass", true);
  48. }
  49.  
  50. @EventHandler
  51. public void onPlayerJoin(PlayerJoinEvent event) {
  52. if (!(boolean) getConfigValues().get("allowPermBypass") || (!event.getPlayer().hasPermission("mojank.antivpn.bypass") && !event.getPlayer().hasPermission("mojank.admin"))) {
  53. new BukkitRunnable() {
  54. public void run() {
  55. Map<String, String> result = getResponse(event.getPlayer());
  56.  
  57. if (result.get("status").equalsIgnoreCase("success")) {
  58. if (result.get("hostIP").equalsIgnoreCase("true")) {
  59. new BukkitRunnable() {
  60. public void run() {
  61. event.getPlayer().kickPlayer(Color.translate(((String) getConfigValues().get("kickMessage")).replaceAll("%ip%", result.get("ip")).replaceAll("%country%", result.get("countryName"))));
  62. AntiVPN.this.cancel(Mojank.getInstance().getDataManager().getPlayerData(event.getPlayer()), "Player " + event.getPlayer().getName() + " on the IP " + event.getPlayer().getAddress().getAddress().getHostAddress() + " is using a VPN.");
  63. }
  64. }.runTask(Mojank.getInstance());
  65. }
  66. }
  67. }
  68. }.runTaskAsynchronously(Mojank.getInstance());
  69. }
  70. }
  71.  
  72. public Map<String, String> getResponse(Player player) {
  73. Map<String, String> toReturn = new HashMap<>();
  74. try {
  75. StringBuilder response = new StringBuilder();
  76. String url = "http://api.vpnblocker.net/v2/json/" + player.getAddress().getAddress().getHostAddress() + "/gklH7N4NU5S8gpO6Tdk6UF68hrBTZ1";
  77. URLConnection connection = new URL(url).openConnection();
  78. connection.setRequestProperty("User-Agent", "Mojank v" + Mojank.getInstance().getDescription().getVersion());
  79. connection.setConnectTimeout(10000);
  80. BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  81. Throwable localThrowable3 = null;
  82. try {
  83. while ((url = in.readLine()) != null) {
  84. response.append(url);
  85. }
  86. in.close();
  87. } catch (Throwable localThrowable1) {
  88. localThrowable3 = localThrowable1;
  89. throw localThrowable1;
  90. } finally {
  91. if (localThrowable3 != null) {
  92. try {
  93. in.close();
  94. } catch (Throwable localThrowable2) {
  95. localThrowable3.addSuppressed(localThrowable2);
  96. }
  97. } else {
  98. in.close();
  99. }
  100. }
  101. String result = response.toString();
  102. JSONObject object = new JSONObject(result);
  103. String status = object.getString("status");
  104.  
  105. toReturn.put("status", status);
  106. if (status.equalsIgnoreCase("success")) {
  107. String ip = object.getString("ipaddress");
  108. String hostIP = object.getBoolean("host-ip") ? "true" : "false";
  109. JSONObject country = object.getJSONObject("country");
  110. String countryName = country.getString("name");
  111. String countryCode = country.getString("code");
  112.  
  113. toReturn.put("ip", ip);
  114. toReturn.put("hostIP", hostIP);
  115. toReturn.put("countryName", countryName);
  116. toReturn.put("countryCode", countryCode);
  117. }
  118.  
  119. return toReturn;
  120. } catch (IOException | JSONException e) {
  121. e.printStackTrace();
  122. }
  123. toReturn.put("status", "failure");
  124. return toReturn;
  125. }
  126.  
  127. @Override
  128. public void protocolLibListeners() {
  129.  
  130. }
  131. }
  132. © 2018 GitHub, Inc.
  133. Terms
  134. Privacy
  135. Security
  136. Status
  137. Help
  138. Contact GitHub
  139. Pricing
  140. API
  141. Training
  142. Blog
  143. About
  144. Press h to open a hovercard with more details.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement