Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Remove metrics, drop legacy support (require slf4j), improve version …
Browse files Browse the repository at this point in the history
…parser, rewrite database, upload codestyle, use var
  • Loading branch information
xxneox committed Nov 18, 2021
1 parent 783d5df commit 5e9621b
Show file tree
Hide file tree
Showing 61 changed files with 1,009 additions and 463 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
A simple AntiBot plugin for newest Minecraft versions.

## ✅ Supported platforms
* [Paper 1.16.5+](https://papermc.io/) *(all paper forks are supported)*
* [Velocity 3.0.0+](https://velocitypowered.com/)
* BungeeCord *([Waterfall](https://papermc.io/downloads#Waterfall) required)*
* Java **16**+ is required.
* [Paper 1.16+](https://papermc.io/) *(all paper forks are supported)*
* [Velocity 3.0+](https://velocitypowered.com/)
* BungeeCord *([Waterfall](https://papermc.io/downloads#Waterfall) required fork)*
* Java **16**

## ✨ Features
* A total of **8** configurable antibot checks:
Expand Down Expand Up @@ -89,6 +89,7 @@ dependencies {
<groupId>com.github.xxneox</groupId>
<artifactId>EpicGuard</artifactId>
<version>[VERSION OR COMMIT ID HERE]</version>
<scope>provided</scope>
</dependency>
</dependencies>
```
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ subprojects {
relocate("com.google.common", "me.xneox.epicguard.libs.googlecommons")
relocate("com.typesafe.config", "me.xneox.epicguard.libs.config")
relocate("com.zaxxer.hikari", "me.xneox.epicguard.libs.hikari")
relocate("co.aikar.idb", "me.xneox.epicguard.libs.idb")
relocate("io.leangen.geantyref", "me.xneox.epicguard.libs.geantyref")

// Minimize, but exclude drivers shaded in the velocity platform.
Expand Down
599 changes: 599 additions & 0 deletions codestyle.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies {
implementation("org.spongepowered:configurate-hocon:4.1.2")
implementation("org.jetbrains:annotations:22.0.0")
implementation("com.zaxxer:HikariCP:5.0.0")
implementation("co.aikar:idb-core:1.0.0-SNAPSHOT")

compileOnly("net.kyori:adventure-api:4.9.3")
compileOnly("net.kyori:adventure-text-serializer-legacy:4.9.3")
Expand Down
35 changes: 27 additions & 8 deletions core/src/main/java/me/xneox/epicguard/core/EpicGuard.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.concurrent.TimeUnit;
import me.xneox.epicguard.core.config.MessagesConfiguration;
import me.xneox.epicguard.core.config.PluginConfiguration;
import me.xneox.epicguard.core.proxy.ProxyService;
import me.xneox.epicguard.core.proxy.ProxyServiceSerializer;
import me.xneox.epicguard.core.util.LogUtils;
import me.xneox.epicguard.core.util.VersionUtils;
import me.xneox.epicguard.core.util.logging.LogFilter;
Expand All @@ -34,8 +36,10 @@
import me.xneox.epicguard.core.task.UpdateCheckerTask;
import me.xneox.epicguard.core.util.ConfigurationLoader;
import me.xneox.epicguard.core.util.FileUtils;
import me.xneox.epicguard.core.util.logging.LogWrapper;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;

/**
* The main class of the EpicGuard's core.
Expand Down Expand Up @@ -81,61 +85,76 @@ private void startup() {
this.platform.scheduleRepeatingTask(new AttackResetTask(this), this.config.misc().attackResetInterval());
this.platform.scheduleRepeatingTask(new DataSaveTask(this), TimeUnit.MINUTES.toSeconds(this.config.misc().autoSaveInterval()));

logger().info("Startup completed successfully. Welcome to EpicGuard v" + VersionUtils.VERSION);
logger().info("Startup completed successfully. Welcome to EpicGuard v" + VersionUtils.CURRENT_VERSION);
}

public void loadConfigurations() {
File configurationFile = new File(FileUtils.EPICGUARD_DIR, "settings.conf");
File messagesFile = new File(FileUtils.EPICGUARD_DIR, "messages.conf");
var configLoader = HoconConfigurationLoader.builder()
.defaultOptions(opt -> opt.serializers(builder -> builder.register(ProxyService.class, ProxyServiceSerializer.INSTANCE)))
.file(new File(FileUtils.EPICGUARD_DIR, "settings.conf"))
.build();

var messagesLoader = HoconConfigurationLoader.builder()
.file(new File(FileUtils.EPICGUARD_DIR, "messages.conf"))
.build();

try {
this.config = new ConfigurationLoader<>(configurationFile, PluginConfiguration.class).load();
this.messages = new ConfigurationLoader<>(messagesFile, MessagesConfiguration.class).load();
this.config = new ConfigurationLoader<>(PluginConfiguration.class, configLoader).load();
this.messages = new ConfigurationLoader<>(MessagesConfiguration.class, messagesLoader).load();
} catch (ConfigurateException exception) {
LogUtils.catchException("Couldn't load the configuration file", exception);
}
}

public void shutdown() {
try {
this.storageManager.database().saveData();
this.storageManager.database().save();
} catch (SQLException exception) {
LogUtils.catchException("Could not save data to the SQL database (during shutdown)", exception);
}
}

public LogWrapper logger() {
@NotNull
public Logger logger() {
return this.platform.logger();
}

@NotNull
public Platform platform() {
return this.platform;
}

@NotNull
public PluginConfiguration config() {
return this.config;
}

@NotNull
public MessagesConfiguration messages() {
return this.messages;
}

@NotNull
public UserManager userManager() {
return this.userManager;
}

@NotNull
public GeoManager geoManager() {
return this.geoManager;
}

@NotNull
public StorageManager storageManager() {
return this.storageManager;
}

@NotNull
public AttackManager attackManager() {
return this.attackManager;
}

@NotNull
public ProxyManager proxyManager() {
return this.proxyManager;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/me/xneox/epicguard/core/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package me.xneox.epicguard.core;

import java.util.UUID;
import me.xneox.epicguard.core.util.logging.LogWrapper;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

public interface Platform {
/**
Expand All @@ -33,7 +33,7 @@ public interface Platform {
* @return A wrapper of the platform plugin's logger.
*/
@NotNull
LogWrapper logger();
Logger logger();

/**
* @param uuid UUID of the online user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

package me.xneox.epicguard.core.check;

import java.util.List;
import me.xneox.epicguard.core.EpicGuard;
import me.xneox.epicguard.core.check.AbstractCheck;
import me.xneox.epicguard.core.user.ConnectingUser;
import org.jetbrains.annotations.NotNull;

Expand All @@ -31,8 +29,7 @@ public AccountLimitCheck(EpicGuard epicGuard) {

@Override
public boolean isDetected(@NotNull ConnectingUser user) {
List<String> accounts = this.epicGuard.storageManager().addressMeta(user.address()).nicknames();

var accounts = this.epicGuard.storageManager().addressMeta(user.address()).nicknames();
return this.evaluate(this.epicGuard.config().accountLimitCheck().checkMode(),
!accounts.contains(user.nickname()) && accounts.size() >= this.epicGuard.config().accountLimitCheck().accountLimit());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package me.xneox.epicguard.core.check;

import me.xneox.epicguard.core.EpicGuard;
import me.xneox.epicguard.core.check.AbstractCheck;
import me.xneox.epicguard.core.user.ConnectingUser;
import org.jetbrains.annotations.NotNull;

Expand All @@ -30,7 +29,6 @@ public LockdownCheck(EpicGuard epicGuard) {

@Override
public boolean isDetected(@NotNull ConnectingUser user) {
return this.epicGuard.attackManager().isUnderAttack()
&& this.epicGuard.config().misc().lockdownOnAttack();
return this.epicGuard.attackManager().isUnderAttack() && this.epicGuard.config().misc().lockdownOnAttack();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ public CommandHandler(EpicGuard epicGuard) {
public void handleCommand(@NotNull String[] args, @NotNull Audience audience) {
// No arguments provided - send the version message.
if (args.length < 1) {
audience.sendMessage(TextUtils.component("&#99ff00 You are running EpicGuard v" + VersionUtils.VERSION +
audience.sendMessage(TextUtils.component("&#99ff00 You are running EpicGuard v" + VersionUtils.CURRENT_VERSION
+
" on " + this.epicGuard.platform().platformVersion()));
audience.sendMessage(TextUtils.component("&#99ff00 Run &l/guard help &#99ff00to see available commands and statistics"));
return;
}

SubCommand command = this.commandMap.get(args[0]);
if (command == null) {
var subCommand = this.commandMap.get(args[0]);
if (subCommand == null) {
audience.sendMessage(TextUtils.component(this.epicGuard.messages().command().prefix() + this.epicGuard.messages().command().unknownCommand()));
return;
}

command.execute(audience, args, this.epicGuard);
subCommand.execute(audience, args, this.epicGuard);
}

@NotNull
Expand All @@ -77,9 +78,9 @@ public Collection<String> handleSuggestions(@NotNull String[] args) {
return this.commandMap.keySet();
}

SubCommand command = this.commandMap.get(args[0]);
if (command != null) {
return command.suggest(args, this.epicGuard);
var subCommand = this.commandMap.get(args[0]);
if (subCommand != null) {
return subCommand.suggest(args, this.epicGuard);
}
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
public class AnalyzeCommand implements SubCommand {
@Override
public void execute(@NotNull Audience audience, @NotNull String[] args, @NotNull EpicGuard epicGuard) {
MessagesConfiguration.Command config = epicGuard.messages().command();
var config = epicGuard.messages().command();

if (args.length != 2) {
audience.sendMessage(TextUtils.component(config.prefix() +
config.usage().replace("{USAGE}", "/guard analyze <nickname/address>")));
return;
}

AddressMeta meta = epicGuard.storageManager().resolveAddressMeta(args[1]);
var meta = epicGuard.storageManager().resolveAddressMeta(args[1]);
if (meta == null) {
audience.sendMessage(TextUtils.component(config.prefix() + config.invalidArgument()));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,36 @@
public class BlacklistCommand implements SubCommand {
@Override
public void execute(@NotNull Audience audience, @NotNull String[] args, @NotNull EpicGuard epicGuard) {
MessagesConfiguration.Command config = epicGuard.messages().command();
var config = epicGuard.messages().command();

if (args.length != 3) {
audience.sendMessage(TextUtils.component(config.prefix() + config.usage()
.replace("{USAGE}", "/guard blacklist <add/remove> <nickname/address>")));
return;
}

AddressMeta meta = epicGuard.storageManager().resolveAddressMeta(args[2]);
var meta = epicGuard.storageManager().resolveAddressMeta(args[2]);
if (meta == null) {
audience.sendMessage(TextUtils.component(config.prefix() + config.invalidArgument()));
return;
}

if (args[1].equalsIgnoreCase("add")) {
if (meta.blacklisted()) {
audience.sendMessage(
TextUtils.component(config.prefix() + config.alreadyBlacklisted().replace("{USER}", args[2])));
audience.sendMessage(TextUtils.component(config.prefix() + config.alreadyBlacklisted().replace("{USER}", args[2])));
return;
}

meta.blacklisted(true);
audience.sendMessage(
TextUtils.component(config.prefix() + config.blacklistAdd().replace("{USER}", args[2])));
audience.sendMessage(TextUtils.component(config.prefix() + config.blacklistAdd().replace("{USER}", args[2])));
} else if (args[1].equalsIgnoreCase("remove")) {
if (!meta.blacklisted()) {
audience.sendMessage(
TextUtils.component(config.prefix() + config.notBlacklisted().replace("{USER}", args[2])));
audience.sendMessage(TextUtils.component(config.prefix() + config.notBlacklisted().replace("{USER}", args[2])));
return;
}

meta.blacklisted(false);
audience.sendMessage(
TextUtils.component(config.prefix() + config.blacklistRemove().replace("{USER}", args[2])));
audience.sendMessage(TextUtils.component(config.prefix() + config.blacklistRemove().replace("{USER}", args[2])));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class HelpCommand implements SubCommand {
public void execute(@NotNull Audience audience, @NotNull String[] args, @NotNull EpicGuard epicGuard) {
for (String line : epicGuard.messages().command().mainCommand()) {
audience.sendMessage(TextUtils.component(line
.replace("{VERSION}", VersionUtils.VERSION)
.replace("{VERSION}", VersionUtils.CURRENT_VERSION)
.replace("{BLACKLISTED-IPS}", String.valueOf(epicGuard.storageManager().viewAddresses(AddressMeta::blacklisted).size()))
.replace("{WHITELISTED-IPS}", String.valueOf(epicGuard.storageManager().viewAddresses(AddressMeta::whitelisted).size()))
.replace("{CPS}", String.valueOf(epicGuard.attackManager().connectionCounter()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class ReloadCommand implements SubCommand {
@Override
public void execute(@NotNull Audience audience, @NotNull String[] args, @NotNull EpicGuard epicGuard) {
MessagesConfiguration.Command config = epicGuard.messages().command();
var config = epicGuard.messages().command();

epicGuard.loadConfigurations();
audience.sendMessage(TextUtils.component(config.prefix() + config.reloaded()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SaveCommand implements SubCommand {
@Override
public void execute(@NotNull Audience audience, @NotNull String[] args, @NotNull EpicGuard epicGuard) {
try {
epicGuard.storageManager().database().saveData();
epicGuard.storageManager().database().save();
audience.sendMessage(TextUtils.component(epicGuard.messages().command().prefix() + "&aData has been saved succesfully."));
} catch (SQLException ex) {
audience.sendMessage(TextUtils.component(epicGuard.messages().command().prefix() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.UUID;
import me.xneox.epicguard.core.EpicGuard;
import me.xneox.epicguard.core.command.SubCommand;
import me.xneox.epicguard.core.config.MessagesConfiguration;
import me.xneox.epicguard.core.user.OnlineUser;
import me.xneox.epicguard.core.util.TextUtils;
import net.kyori.adventure.audience.Audience;
Expand All @@ -31,10 +30,9 @@
public class StatusCommand implements SubCommand {
@Override
public void execute(@NotNull Audience audience, @NotNull String[] args, @NotNull EpicGuard epicGuard) {
MessagesConfiguration.Command config = epicGuard.messages().command();
var config = epicGuard.messages().command();

//TODO: Paper implemented Pointers in build #277 and this code works fine on that build, but
// even though Pointers are also implemented on Velocity, the don't work there...
// for some reason not working in Velocity
if (!audience.pointers().supports(Identity.UUID)) {
audience.sendMessage(Component
.text("This command is unavailable in the current environment.")
Expand Down
Loading

0 comments on commit 5e9621b

Please sign in to comment.