Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Main class:
- package me.samut8.AntiProxy;
- import org.bukkit.Bukkit;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.plugin.java.JavaPlugin;
- public class AntiProxy extends JavaPlugin
- {
- public static AntiProxy plugin;
- @Override
- public void onEnable()
- {
- Bukkit.getPluginManager().registerEvents(new Listeners(), this);
- getLogger().info("Anti-Proxy 1.2 by samut8 enabled!");
- saveDefaultConfig();
- }
- public void onDisable()
- {
- getLogger().info("Anti-Proxy 1.2 by samut8 disabled!");
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if(cmd.getName().equalsIgnoreCase("antiproxy")) {
- onDisable();
- onEnable();
- reloadConfig();
- sender.sendMessage("§cAnti-Proxy 1.2 config reloaded!");
- }
- return false;
- }
- }
- Listeners:
- package me.samut8.AntiProxy;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Scanner;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
- public class Listeners implements Listener {
- private AntiProxy plugin;
- @EventHandler(priority = EventPriority.HIGHEST)
- public void onAsyncPlayerLoginEvent(AsyncPlayerPreLoginEvent event)
- {
- try
- {
- String playerip = event.getAddress().getHostAddress();
- String player = event.getName();
- String url = "http://www.stopforumspam.com/api?ip=" + playerip;
- Scanner apiscanner = new Scanner(new URL(url).openStream());
- Bukkit.getLogger().info("Checking if " + player + " (" + playerip + ")" + " is trying to connect with a proxy...");
- if(apiscanner.findInLine("ip yes") != null)
- {
- Bukkit.getLogger().info(player + " (" + playerip + ")" + " tried to connect using proxy!");
- event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, plugin.getConfig().getString("Kick_Message"));
- for(Player p : Bukkit.getOnlinePlayers()) {
- if(p.hasPermission("antiproxy.notify") && plugin.getConfig().getBoolean("Notify")) {
- p.sendMessage(ChatColor.GRAY + "[Anti-Proxy] " + player + " (" + playerip + ")" + " tried to connect using proxy!");
- }
- }
- }
- apiscanner.close();
- }
- catch (MalformedURLException exception)
- {
- exception.printStackTrace();
- }
- catch (IOException exception)
- {
- exception.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment