-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
J'ai fait un anti vpn. J'utilise l'api ip-api qui est une superbe api très fiable pour savoir si une ip est vpn ou non. Ptet ajouter une commande pour whitelist une ip ou un pseudo au futur ?
- Loading branch information
Showing
5 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/fr/communaywen/core/listeners/VpnListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package fr.communaywen.core.listeners; | ||
|
||
import fr.communaywen.core.AywenCraftPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerLoginEvent; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
public class VpnListener implements Listener { | ||
|
||
private final AywenCraftPlugin plugin; | ||
|
||
public VpnListener(AywenCraftPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerLogin(PlayerLoginEvent event) { | ||
|
||
Player player = event.getPlayer(); | ||
|
||
if (player.hasPermission("aywencraft.antivpn.bypass")) { | ||
return; | ||
} | ||
|
||
String ip = event.getAddress().getHostAddress(); | ||
new BukkitRunnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
URL url = new URL("http://ip-api.com/json/" + ip + "?fields=proxy"); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.setRequestMethod("GET"); | ||
|
||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
String inputLine; | ||
StringBuilder content = new StringBuilder(); | ||
while ((inputLine = in.readLine()) != null) { | ||
content.append(inputLine); | ||
} | ||
|
||
in.close(); | ||
connection.disconnect(); | ||
|
||
String response = content.toString(); | ||
if (response.contains("\"proxy\":true")) { | ||
Bukkit.getScheduler().runTask(plugin, () -> { | ||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, | ||
"§l§cOpenMc - Sécuritée\n" + | ||
"§l§eConnexion Non Permise !§r\n" + | ||
"§6Vous essayez actuellement de vous connecter au serveur\n" + | ||
"§6avec un vpn ou un proxy.\n" + | ||
"§3Merci de le désactiver et de réessayer\n" + | ||
"§cSi vous pensez qu'il s'agit d'une erreur, vous pouvez\n" + | ||
"§cavoir de l'assistance sur discord.gg/aywen"); | ||
Bukkit.broadcast(ChatColor.YELLOW + event.getPlayer().getName() + " a essayé de se connecter mais il avait un vpn.", | ||
"aywencraft.antivpn.notification"); | ||
}); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}.runTaskAsynchronously(plugin); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters