generated from AitorAstorga/Best-README-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e419c50
commit 25cfe34
Showing
7 changed files
with
183 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>eus.aichan</groupId> | ||
<artifactId>BotBlocker</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.17.1-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<defaultGoal>clean package</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.2.0</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<classpathPrefix>lib/</classpathPrefix> | ||
<mainClass>com.tuDominio.BotBlocker</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,100 @@ | ||
package eus.aichan.Blocker; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.BanList.Type; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
public class BotBlocker extends JavaPlugin implements Listener { | ||
|
||
private boolean pluginEnabled = true; | ||
private int timeLimit; // In seconds | ||
private HashMap<UUID, Long> joinTimes = new HashMap<>(); | ||
private FileConfiguration playersCfg; | ||
|
||
@Override | ||
public void onEnable() { | ||
saveDefaultConfig(); | ||
timeLimit = getConfig().getInt("time-limit", 60); // Default to 60 seconds | ||
Bukkit.getPluginManager().registerEvents(this, this); | ||
|
||
File playersFile = new File(getDataFolder(), "players.yml"); | ||
if (!playersFile.exists()) { | ||
saveResource("players.yml", false); | ||
} | ||
playersCfg = YamlConfiguration.loadConfiguration(playersFile); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
saveConfig(); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (command.getName().equalsIgnoreCase("botblocker")) { | ||
if (args.length > 0) { | ||
if (args[0].equalsIgnoreCase("enable")) { | ||
pluginEnabled = true; | ||
sender.sendMessage("BotBlocker enabled."); | ||
} else if (args[0].equalsIgnoreCase("disable")) { | ||
pluginEnabled = false; | ||
sender.sendMessage("BotBlocker disabled."); | ||
} else if (args[0].equalsIgnoreCase("setTimeLimit") && args.length > 1) { | ||
try { | ||
timeLimit = Integer.parseInt(args[1]); | ||
getConfig().set("time-limit", timeLimit); | ||
saveConfig(); | ||
sender.sendMessage("Time limit set to " + timeLimit + " seconds."); | ||
} catch (NumberFormatException e) { | ||
sender.sendMessage("Invalid number format. Please enter a valid integer."); | ||
} | ||
} else { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerJoin(PlayerJoinEvent event) { | ||
if (!pluginEnabled) return; | ||
|
||
UUID playerId = event.getPlayer().getUniqueId(); | ||
if (!playersCfg.contains(playerId.toString())) { | ||
joinTimes.put(playerId, System.currentTimeMillis()); | ||
playersCfg.set(playerId.toString(), true); | ||
saveConfig(); | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerQuit(PlayerQuitEvent event) { | ||
if (!pluginEnabled) return; | ||
|
||
UUID playerId = event.getPlayer().getUniqueId(); | ||
if (joinTimes.containsKey(playerId)) { | ||
long joinTime = joinTimes.get(playerId); | ||
long timeConnected = (System.currentTimeMillis() - joinTime) / 1000; | ||
if (timeConnected < timeLimit) { | ||
String playerName = event.getPlayer().getName(); | ||
Bukkit.getBanList(Type.NAME).addBan(playerName, "Bot detected. If you are a legitimate user, please contact the admin.", null, "Sistema anti-bot"); | ||
getLogger().info("Player '" + playerName + "' was banned for disconnecting within " + timeLimit + " seconds of joining for the first time - suspected bot."); | ||
} | ||
joinTimes.remove(playerId); | ||
} | ||
} | ||
} |
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,2 @@ | ||
# Time limit in seconds | ||
time-limit: 60 |
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,11 @@ | ||
name: BotBlocker | ||
main: eus.aichan.BotBlocker | ||
version: 1.0 | ||
description: A plugin to ban users who connect for the first time and disconnect within a certain time limit. | ||
commands: | ||
botblocker: | ||
description: Manages the BotBlocker plugin | ||
usage: | | ||
/<command> enable - Enables the BotBlocker plugin | ||
/<command> disable - Disables the BotBlocker plugin | ||
/<command> setTimeLimit [seconds] - Sets the time limit |
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,2 @@ | ||
# Time limit in seconds | ||
time-limit: 60 |
Binary file not shown.
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,11 @@ | ||
name: BotBlocker | ||
main: eus.aichan.BotBlocker | ||
version: 1.0 | ||
description: A plugin to ban users who connect for the first time and disconnect within a certain time limit. | ||
commands: | ||
botblocker: | ||
description: Manages the BotBlocker plugin | ||
usage: | | ||
/<command> enable - Enables the BotBlocker plugin | ||
/<command> disable - Disables the BotBlocker plugin | ||
/<command> setTimeLimit [seconds] - Sets the time limit |