Skip to content

Commit

Permalink
Ajout d'un anti vpn (#91)
Browse files Browse the repository at this point in the history
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
Margouta authored Jul 7, 2024
2 parents 1424e1c + 090233e commit d9843a2
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/fr/communaywen/core/AywenCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new ChatListener(this, discordWebhook), this);
getServer().getPluginManager().registerEvents(new FreezeListener(this), this);
getServer().getPluginManager().registerEvents(new WelcomeMessage(loadWelcomeMessageConfig()), this);
getServer().getPluginManager().registerEvents(new VpnListener(this), this);
/* --------- */

saveDefaultConfig();
Expand Down
74 changes: 74 additions & 0 deletions src/main/java/fr/communaywen/core/listeners/VpnListener.java
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

plugin.getFrozenPlayers().add(target.getUniqueId());
target.sendTitle(ChatColor.RED + "Vous êtes freeze !", ChatColor.YELLOW + "Regardez votre chat", 10, 70, 20);
target.sendTitle(ChatColor.RED + "Vous êtes freeze !", ChatColor.YELLOW + "Regardez votre chat", 10, 1000, 20);
target.sendMessage(ChatColor.RED + "Vous êtes Freeze, si vous déconnectez, vous serez banni !");
player.sendMessage(ChatColor.GREEN + target.getName() + " a bien été freeze.");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
if (plugin.getFrozenPlayers().contains(playerUUID)) {
int banDurationDays = plugin.getBanDuration();
Date banDuration = new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(banDurationDays));
Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), "Vous avez été banni pour déconnexion en étant freeze pandant ", banDuration, "Anti Déco Freeze");
Bukkit.getBanList(BanList.Type.NAME).addBan(player.getName(), "Déconnexion en étant freeze !", banDuration, "Anti Déco Freeze");
plugin.getFrozenPlayers().remove(playerUUID);

}
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ permissions:
default: true
ayw.command.rtp:
description: 'rtp'
default: false
default: true
ayw.command.feed:
description: 'feed'
default: true
Expand All @@ -86,6 +86,12 @@ permissions:
openmc.staff.freeze:
description: 'Ensemble de commandes pour freeze un joueur'
default: false
aywencraft.antivpn.notification:
description: 'Permission to receive VPN connection notifications'
default: op
aywencraft.antivpn.bypass:
description: 'Permission to bypass VPN check'
default: false
ayw.command.spawn:
description: 'spawn'
default: true

0 comments on commit d9843a2

Please sign in to comment.