Guest User

Untitled

a guest
Jun 23rd, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. Main class:
  2.  
  3. package me.samut8.AntiProxy;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. public class AntiProxy extends JavaPlugin
  11. {
  12. public static AntiProxy plugin;
  13. @Override
  14. public void onEnable()
  15. {
  16. Bukkit.getPluginManager().registerEvents(new Listeners(), this);
  17. getLogger().info("Anti-Proxy 1.2 by samut8 enabled!");
  18. saveDefaultConfig();
  19. }
  20. public void onDisable()
  21. {
  22. getLogger().info("Anti-Proxy 1.2 by samut8 disabled!");
  23. }
  24. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  25. if(cmd.getName().equalsIgnoreCase("antiproxy")) {
  26. onDisable();
  27. onEnable();
  28. reloadConfig();
  29. sender.sendMessage("§cAnti-Proxy 1.2 config reloaded!");
  30. }
  31. return false;
  32. }
  33. }
  34.  
  35.  
  36. Listeners:
  37.  
  38. package me.samut8.AntiProxy;
  39.  
  40. import java.io.IOException;
  41. import java.net.MalformedURLException;
  42. import java.net.URL;
  43. import java.util.Scanner;
  44.  
  45. import org.bukkit.Bukkit;
  46. import org.bukkit.ChatColor;
  47. import org.bukkit.entity.Player;
  48. import org.bukkit.event.EventHandler;
  49. import org.bukkit.event.EventPriority;
  50. import org.bukkit.event.Listener;
  51. import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
  52.  
  53. public class Listeners implements Listener {
  54.  
  55. private AntiProxy plugin;
  56.  
  57. @EventHandler(priority = EventPriority.HIGHEST)
  58. public void onAsyncPlayerLoginEvent(AsyncPlayerPreLoginEvent event)
  59. {
  60. try
  61. {
  62. String playerip = event.getAddress().getHostAddress();
  63. String player = event.getName();
  64. String url = "http://www.stopforumspam.com/api?ip=" + playerip;
  65. Scanner apiscanner = new Scanner(new URL(url).openStream());
  66.  
  67.  
  68. Bukkit.getLogger().info("Checking if " + player + " (" + playerip + ")" + " is trying to connect with a proxy...");
  69.  
  70. if(apiscanner.findInLine("ip yes") != null)
  71. {
  72. Bukkit.getLogger().info(player + " (" + playerip + ")" + " tried to connect using proxy!");
  73. event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, plugin.getConfig().getString("Kick_Message"));
  74. for(Player p : Bukkit.getOnlinePlayers()) {
  75. if(p.hasPermission("antiproxy.notify") && plugin.getConfig().getBoolean("Notify")) {
  76. p.sendMessage(ChatColor.GRAY + "[Anti-Proxy] " + player + " (" + playerip + ")" + " tried to connect using proxy!");
  77. }
  78. }
  79. }
  80. apiscanner.close();
  81. }
  82.  
  83. catch (MalformedURLException exception)
  84. {
  85. exception.printStackTrace();
  86. }
  87. catch (IOException exception)
  88. {
  89. exception.printStackTrace();
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment