Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
AitorAstorga committed Jul 19, 2023
1 parent 25cfe34 commit 4e61027
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
36 changes: 25 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
<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">
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>
<version>1.2-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>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
</properties>

<repositories>
<!-- This adds the Spigot Maven repository to the build -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<dependencies>
<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<!-- Uses the properties in this file for plugin.yml and config.yml -->
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>players.yml</include>
<include>plugin.yml</include>
<include>config.yml</include>
</includes>
</resource>
</resources>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
Expand All @@ -54,4 +68,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
17 changes: 16 additions & 1 deletion src/main/java/eus/aichan/Blocker/BotBlocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.UUID;

Expand All @@ -22,14 +23,15 @@ public class BotBlocker extends JavaPlugin implements Listener {
private int timeLimit; // In seconds
private HashMap<UUID, Long> joinTimes = new HashMap<>();
private FileConfiguration playersCfg;
private File playersFile;

@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");
playersFile = new File(getDataFolder(), "players.yml");
if (!playersFile.exists()) {
saveResource("players.yml", false);
}
Expand Down Expand Up @@ -93,8 +95,21 @@ public void onPlayerQuit(PlayerQuitEvent event) {
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.");
} else {
// Add the player to players.yml if it is not banned
playersCfg.set(playerId.toString(), true);
savePlayers();
}
joinTimes.remove(playerId);
}
}

private void savePlayers() {
try {
playersCfg.save(playersFile);
} catch (IOException e) {
e.printStackTrace();
}
}

}
Empty file added src/main/resources/players.yml
Empty file.
6 changes: 4 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: BotBlocker
main: eus.aichan.BotBlocker
version: 1.0
main: eus.aichan.Blocker.BotBlocker
version: 1.2
api-version: '1.20'
author: aichan
description: A plugin to ban users who connect for the first time and disconnect within a certain time limit.
commands:
botblocker:
Expand Down
Binary file added target/BotBlocker-1.2-SNAPSHOT.jar
Binary file not shown.
Empty file modified target/classes/config.yml
100755 → 100644
Empty file.
Binary file modified target/classes/eus/aichan/Blocker/BotBlocker.class
Binary file not shown.
Empty file added target/classes/players.yml
Empty file.
6 changes: 4 additions & 2 deletions target/classes/plugin.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: BotBlocker
main: eus.aichan.BotBlocker
version: 1.0
main: eus.aichan.Blocker.BotBlocker
version: 1.2
api-version: '1.20'
author: aichan
description: A plugin to ban users who connect for the first time and disconnect within a certain time limit.
commands:
botblocker:
Expand Down
3 changes: 3 additions & 0 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=BotBlocker
groupId=eus.aichan
version=1.2-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eus/aichan/Blocker/BotBlocker.class
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/aichan/Documentos/GitHub/BotBlocker/src/main/java/eus/aichan/Blocker/BotBlocker.java

0 comments on commit 4e61027

Please sign in to comment.