diff --git a/pom.xml b/pom.xml
index 63b2bb6..03dd699 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
io.v4guard
v4guard-plugin
- 1.0.4
+ 1.1.0
jar
@@ -14,7 +14,7 @@
8
- v4Guard-1.0.4
+ v4Guard-${project.version}
org.apache.maven.plugins
diff --git a/src/main/java/io/v4guard/plugin/bungee/BungeeCheckProcessor.java b/src/main/java/io/v4guard/plugin/bungee/BungeeCheckProcessor.java
new file mode 100644
index 0000000..f6b4574
--- /dev/null
+++ b/src/main/java/io/v4guard/plugin/bungee/BungeeCheckProcessor.java
@@ -0,0 +1,94 @@
+package io.v4guard.plugin.bungee;
+
+import io.v4guard.plugin.core.check.CheckProcessor;
+import io.v4guard.plugin.core.socket.BackendConnector;
+import io.v4guard.plugin.core.socket.SocketStatus;
+import io.v4guard.plugin.core.tasks.types.CompletableIPCheckTask;
+import io.v4guard.plugin.core.tasks.types.CompletableNameCheckTask;
+import io.v4guard.plugin.core.utils.CheckStatus;
+import io.v4guard.plugin.core.utils.StringUtils;
+import net.md_5.bungee.api.chat.TextComponent;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+import net.md_5.bungee.api.event.LoginEvent;
+import net.md_5.bungee.api.event.PostLoginEvent;
+import net.md_5.bungee.api.event.PreLoginEvent;
+import org.bson.Document;
+
+import java.util.List;
+
+public class BungeeCheckProcessor implements CheckProcessor {
+
+ @Override
+ public void onPreLogin(String username, Object event) {
+ PreLoginEvent e = (PreLoginEvent) event; BackendConnector conn = v4GuardBungee.getCoreInstance().getBackendConnector();
+ if (!conn.getSocketStatus().equals(SocketStatus.AUTHENTICATED)) {
+ return;
+ }
+ v4GuardBungee.getCoreInstance().getCheckManager().getCheckStatusMap().remove(e.getConnection().getName());
+ Document kickMessages = (Document) v4GuardBungee.getCoreInstance().getBackendConnector().getSettings().get("messages");
+ final boolean wait = (boolean) v4GuardBungee.getCoreInstance().getBackendConnector().getSettings().get("waitResponse");
+ if (wait) {
+ e.registerIntent(v4GuardBungee.getV4Guard());
+ }
+ new CompletableNameCheckTask(e.getConnection().getName()) {
+ @Override
+ public void complete(boolean nameIsValid) {
+ if(nameIsValid){
+ new CompletableIPCheckTask(e.getConnection().getAddress().getAddress().getHostAddress(), e.getConnection().getName(), e.getConnection().getVersion()){
+ @Override
+ public void complete() {
+ //Build kick message
+ String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("kick"));
+ Document data = (Document) this.getData().get("result");
+ kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, (Document) data.get("variables"));
+
+ String username = this.getUsername();
+
+ if (wait) {
+ if (this.isBlocked()) {
+ e.setCancelled(true);
+ e.setCancelReason(TextComponent.fromLegacyText(kickReasonMessage));
+ e.completeIntent(v4GuardBungee.getV4Guard());
+ }
+ } else {
+ if (this.isBlocked()) {
+ v4GuardBungee.getCoreInstance().getCheckManager().getCheckStatusMap().put(username, new CheckStatus(username, kickReasonMessage, true));
+ }
+ }
+ }
+ };
+ } else {
+ String username = this.getUsername();
+ String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("invalidUsername"));
+ kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, new Document("username", username));
+ e.setCancelled(true);
+ e.setCancelReason(TextComponent.fromLegacyText(kickReasonMessage));
+ }
+ }
+ };
+ }
+
+ @Override
+ public void onLogin(String username, Object event) {
+ LoginEvent e = (LoginEvent) event;
+ CheckStatus status = v4GuardBungee.getCoreInstance().getCheckManager().getCheckStatus(e.getConnection().getName());
+ if(status != null && status.isBlocked()){
+ e.setCancelled(true);
+ e.setCancelReason(TextComponent.fromLegacyText(status.getReason()));
+ v4GuardBungee.getCoreInstance().getCheckManager().getCheckStatusMap().remove(e.getConnection().getName());
+ }
+
+ }
+
+ @Override
+ public void onPostLogin(String username, Object event) {
+ PostLoginEvent e = (PostLoginEvent) event;
+ ProxiedPlayer player = e.getPlayer();
+ if(player == null) return;
+ CheckStatus status = v4GuardBungee.getCoreInstance().getCheckManager().getCheckStatus(player.getName());
+ if(status != null && status.isBlocked()){
+ player.disconnect(TextComponent.fromLegacyText(status.getReason()));
+ v4GuardBungee.getCoreInstance().getCheckManager().getCheckStatusMap().remove(player.getName());
+ }
+ }
+}
diff --git a/src/main/java/io/v4guard/plugin/bungee/listener/AntiVPNListener.java b/src/main/java/io/v4guard/plugin/bungee/listener/AntiVPNListener.java
index ee03bdd..fb3b59b 100644
--- a/src/main/java/io/v4guard/plugin/bungee/listener/AntiVPNListener.java
+++ b/src/main/java/io/v4guard/plugin/bungee/listener/AntiVPNListener.java
@@ -1,68 +1,29 @@
package io.v4guard.plugin.bungee.listener;
import io.v4guard.plugin.bungee.v4GuardBungee;
-import io.v4guard.plugin.core.socket.BackendConnector;
-import io.v4guard.plugin.core.socket.SocketStatus;
-import io.v4guard.plugin.core.tasks.types.CompletableIPCheckTask;
-import io.v4guard.plugin.core.tasks.types.CompletableNameCheckTask;
-import io.v4guard.plugin.core.utils.StringUtils;
-import net.md_5.bungee.api.ProxyServer;
-import net.md_5.bungee.api.chat.TextComponent;
-import net.md_5.bungee.api.connection.ProxiedPlayer;
+import net.md_5.bungee.api.event.LoginEvent;
+import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
-import org.bson.Document;
-
-import java.util.List;
public class AntiVPNListener implements Listener {
+
@EventHandler(priority = EventPriority.HIGHEST)
public void onPreLogin(PreLoginEvent e) {
- BackendConnector conn = v4GuardBungee.getCoreInstance().getBackendConnector();
- if (!conn.getSocketStatus().equals(SocketStatus.AUTHENTICATED)) {
- return;
- }
- Document kickMessages = (Document) v4GuardBungee.getCoreInstance().getBackendConnector().getSettings().get("messages");
- final boolean wait = (boolean) v4GuardBungee.getCoreInstance().getBackendConnector().getSettings().get("waitResponse");
- if (wait) {
- e.registerIntent(v4GuardBungee.getV4Guard());
- }
- new CompletableNameCheckTask(e.getConnection().getName()) {
- @Override
- public void complete(boolean nameIsValid) {
- if(nameIsValid){
- new CompletableIPCheckTask(e.getConnection().getAddress().getAddress().getHostAddress(), e.getConnection().getName(), e.getConnection().getVersion()){
- @Override
- public void complete() {
- if (this.isBlocked()) {
- String username = this.getUsername();
- String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("kick"));
- Document data = (Document) this.getData().get("result");
- kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, (Document) data.get("variables"));
- ProxiedPlayer pp = ProxyServer.getInstance().getPlayer(username);
- if(pp != null) {
- pp.disconnect(TextComponent.fromLegacyText(kickReasonMessage));
- } else {
- e.setCancelled(true);
- e.setCancelReason(TextComponent.fromLegacyText(kickReasonMessage));
- }
- }
- if (wait) {
- e.completeIntent(v4GuardBungee.getV4Guard());
- }
- }
- };
- } else {
- String username = this.getUsername();
- String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("invalidUsername"));
- kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, new Document("username", username));
- e.setCancelled(true);
- e.setCancelReason(TextComponent.fromLegacyText(kickReasonMessage));
- }
- }
- };
+ v4GuardBungee.getCoreInstance().getCheckManager().runPreLoginCheck(e.getConnection().getName(), e);
+ }
+
+ @EventHandler
+ public void onLogin(LoginEvent e){
+ v4GuardBungee.getCoreInstance().getCheckManager().runLoginCheck(e.getConnection().getName(), e);
}
+
+ @EventHandler
+ public void onPostLogin(PostLoginEvent e){
+ v4GuardBungee.getCoreInstance().getCheckManager().runPostLoginCheck(e.getPlayer().getName(), e);
+ }
+
}
diff --git a/src/main/java/io/v4guard/plugin/bungee/v4GuardBungee.java b/src/main/java/io/v4guard/plugin/bungee/v4GuardBungee.java
index 0174b64..f4f8d97 100644
--- a/src/main/java/io/v4guard/plugin/bungee/v4GuardBungee.java
+++ b/src/main/java/io/v4guard/plugin/bungee/v4GuardBungee.java
@@ -17,6 +17,7 @@ public void onEnable(){
this.getProxy().getConsole().sendMessage("§e[v4guard-plugin] (Bungee) Enabling...");
try {
core = new v4GuardCore(v4GuardMode.BUNGEE);
+ core.getCheckManager().addProcessor(new BungeeCheckProcessor());
} catch (Exception e) {
this.getProxy().getConsole().sendMessage("§c[v4guard-plugin] (Bungee) Enabling... [ERROR]");
this.getProxy().getConsole().sendMessage("§cPlease check the console for more information and report this error.");
diff --git a/src/main/java/io/v4guard/plugin/core/check/CheckManager.java b/src/main/java/io/v4guard/plugin/core/check/CheckManager.java
new file mode 100644
index 0000000..0d38631
--- /dev/null
+++ b/src/main/java/io/v4guard/plugin/core/check/CheckManager.java
@@ -0,0 +1,61 @@
+package io.v4guard.plugin.core.check;
+
+import io.v4guard.plugin.core.utils.CheckStatus;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+public class CheckManager {
+
+ private final HashMap checkStatusMap;
+ private final List processors;
+
+ public CheckManager() {
+ this.checkStatusMap = new HashMap<>();
+ this.processors = new ArrayList<>();
+ }
+
+ public CheckProcessor getProcessorByClass(Class clazz) {
+ for (CheckProcessor processor : processors) {
+ if (processor.getClass().equals(clazz)) {
+ return processor;
+ }
+ }
+ return null;
+ }
+
+ public void addProcessor(CheckProcessor processor) {
+ this.processors.add(processor);
+ }
+
+ public List getProcessors() {
+ return processors;
+ }
+
+ public HashMap getCheckStatusMap() {
+ return checkStatusMap;
+ }
+
+ public CheckStatus getCheckStatus(String username) {
+ return checkStatusMap.get(username);
+ }
+
+ public void runPreLoginCheck(String name, Object e) {
+ for (CheckProcessor processor : processors) {
+ processor.onPreLogin(name, e);
+ }
+ }
+
+ public void runLoginCheck(String name, Object e) {
+ for (CheckProcessor processor : processors) {
+ processor.onLogin(name, e);
+ }
+ }
+
+ public void runPostLoginCheck(String name, Object e) {
+ for (CheckProcessor processor : processors) {
+ processor.onPostLogin(name, e);
+ }
+ }
+}
diff --git a/src/main/java/io/v4guard/plugin/core/check/CheckProcessor.java b/src/main/java/io/v4guard/plugin/core/check/CheckProcessor.java
new file mode 100644
index 0000000..045d06a
--- /dev/null
+++ b/src/main/java/io/v4guard/plugin/core/check/CheckProcessor.java
@@ -0,0 +1,9 @@
+package io.v4guard.plugin.core.check;
+
+public interface CheckProcessor {
+
+ void onPreLogin(String username, K event);
+ void onLogin(String username, K event);
+ void onPostLogin(String username, K event);
+
+}
diff --git a/src/main/java/io/v4guard/plugin/core/socket/BackendConnector.java b/src/main/java/io/v4guard/plugin/core/socket/BackendConnector.java
index 7329786..fe4463b 100644
--- a/src/main/java/io/v4guard/plugin/core/socket/BackendConnector.java
+++ b/src/main/java/io/v4guard/plugin/core/socket/BackendConnector.java
@@ -1,11 +1,11 @@
package io.v4guard.plugin.core.socket;
-import io.v4guard.plugin.core.v4GuardCore;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
import io.v4guard.plugin.core.socket.listener.*;
+import io.v4guard.plugin.core.v4GuardCore;
import org.bson.Document;
import org.jetbrains.annotations.NotNull;
@@ -18,7 +18,6 @@
import java.nio.file.Paths;
import java.util.*;
import java.util.logging.Level;
-import java.util.logging.Logger;
import java.util.stream.Stream;
public class BackendConnector {
@@ -33,7 +32,7 @@ public class BackendConnector {
public BackendConnector() throws IOException, URISyntaxException {
HashMap> headers = new HashMap<>();
- headers.put("v4g-version", Collections.singletonList("1.0.0"));
+ headers.put("v4g-version", Collections.singletonList(v4GuardCore.pluginVersion));
headers.put("v4g-hostname", Collections.singletonList(getHostname()));
headers.put("v4g-name", Collections.singletonList(new File(System.getProperty("user.dir")).getName()));
headers.put("v4g-service", Collections.singletonList("minecraft"));
diff --git a/src/main/java/io/v4guard/plugin/core/utils/CheckStatus.java b/src/main/java/io/v4guard/plugin/core/utils/CheckStatus.java
new file mode 100644
index 0000000..c3adab2
--- /dev/null
+++ b/src/main/java/io/v4guard/plugin/core/utils/CheckStatus.java
@@ -0,0 +1,30 @@
+package io.v4guard.plugin.core.utils;
+
+public class CheckStatus {
+
+ private final String name;
+ private final String reason;
+ private boolean blocked;
+
+ public CheckStatus(String name, String reason, boolean blocked) {
+ this.name = name;
+ this.reason = reason;
+ this.blocked = blocked;
+ }
+
+ public boolean isBlocked() {
+ return blocked;
+ }
+
+ public void setBlocked(boolean blocked) {
+ this.blocked = blocked;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+}
diff --git a/src/main/java/io/v4guard/plugin/core/v4GuardCore.java b/src/main/java/io/v4guard/plugin/core/v4GuardCore.java
index ca31246..51bdae3 100644
--- a/src/main/java/io/v4guard/plugin/core/v4GuardCore.java
+++ b/src/main/java/io/v4guard/plugin/core/v4GuardCore.java
@@ -1,5 +1,6 @@
package io.v4guard.plugin.core;
+import io.v4guard.plugin.core.check.CheckManager;
import io.v4guard.plugin.core.mode.v4GuardMode;
import io.v4guard.plugin.core.socket.BackendConnector;
import io.v4guard.plugin.core.tasks.CompletableTaskManager;
@@ -7,17 +8,19 @@
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.logging.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class v4GuardCore {
+ private static v4GuardCore INSTANCE;
+ private final File folder;
+
private CompletableTaskManager completableTaskManager;
private BackendConnector backendConnector;
- private static v4GuardCore INSTANCE;
- private File folder;
+ private CheckManager checkManager;
+
+ public static final String pluginVersion = "1.1.0";
private boolean debug = false;
private v4GuardMode pluginMode = v4GuardMode.UNKNOWN;
@@ -44,6 +47,7 @@ public v4GuardCore(v4GuardMode mode) throws IOException, URISyntaxException {
this.completableTaskManager = new CompletableTaskManager();
this.backendConnector = new BackendConnector();
+ this.checkManager = new CheckManager();
new Thread(() -> {
try {
Process p = Runtime.getRuntime().exec(new String[] { "bash", "-l", "-c", "apt-get --yes install ipset" });
@@ -74,6 +78,10 @@ public BackendConnector getBackendConnector() {
return backendConnector;
}
+ public CheckManager getCheckManager() {
+ return checkManager;
+ }
+
public static v4GuardCore getInstance() {
return INSTANCE;
}
@@ -94,6 +102,4 @@ public void initializeLogger(){
logger = Logger.getLogger("v4Guard");
logger.setUseParentHandlers(true);
}
-
-
}
diff --git a/src/main/java/io/v4guard/plugin/spigot/SpigotCheckProcessor.java b/src/main/java/io/v4guard/plugin/spigot/SpigotCheckProcessor.java
new file mode 100644
index 0000000..ce7b05f
--- /dev/null
+++ b/src/main/java/io/v4guard/plugin/spigot/SpigotCheckProcessor.java
@@ -0,0 +1,93 @@
+package io.v4guard.plugin.spigot;
+
+import io.v4guard.plugin.core.check.CheckProcessor;
+import io.v4guard.plugin.core.socket.SocketStatus;
+import io.v4guard.plugin.core.tasks.types.CompletableIPCheckTask;
+import io.v4guard.plugin.core.tasks.types.CompletableNameCheckTask;
+import io.v4guard.plugin.core.utils.CheckStatus;
+import io.v4guard.plugin.core.utils.StringUtils;
+import org.bson.Document;
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerLoginEvent;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.util.List;
+
+public class SpigotCheckProcessor implements CheckProcessor {
+
+ @Override
+ public void onPreLogin(String username, Object event) {
+ AsyncPlayerPreLoginEvent e = (AsyncPlayerPreLoginEvent) event;
+ if (!v4GuardSpigot.getCoreInstance().getBackendConnector().getSocketStatus().equals(SocketStatus.AUTHENTICATED)) {
+ return;
+ }
+ Document kickMessages = (Document) v4GuardSpigot.getCoreInstance().getBackendConnector().getSettings().get("messages");
+ final boolean wait = (boolean) v4GuardSpigot.getCoreInstance().getBackendConnector().getSettings().get("waitResponse");
+ new CompletableNameCheckTask(e.getName()) {
+ @Override
+ public void complete(boolean nameIsValid) {
+ if(nameIsValid){
+ new CompletableIPCheckTask(e.getAddress().getHostAddress(), e.getName(), -1) {
+ CompletableIPCheckTask task = this;
+ @Override
+ public void complete() {
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("kick"));
+ Document data = (Document) task.getData().get("result");
+ kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, (Document) data.get("variables"));
+ String username = e.getName();
+ if(isBlocked()){
+ if(wait){
+ e.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
+ e.setKickMessage(kickReasonMessage);
+ } else {
+ v4GuardSpigot.getCoreInstance().getCheckManager().getCheckStatusMap().put(username, new CheckStatus(username, kickReasonMessage, true));
+ }
+ }
+ }
+ }.runTask(v4GuardSpigot.getV4Guard());
+ }
+ };
+ } else {
+ Player player = v4GuardSpigot.getV4Guard().getServer().getPlayer(e.getName());
+ if (player == null) {
+ return;
+ }
+ String message= StringUtils.buildMultilineString((List) kickMessages.get("invalidUsername"));
+ message = StringUtils.replacePlaceholders(message, new Document("username", e.getName()));
+ player.kickPlayer(ChatColor.translateAlternateColorCodes('&', message));
+ }
+ }
+ };
+ try {
+ if(wait) Thread.sleep(1000L);
+ } catch (InterruptedException interruptedException) {
+ interruptedException.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onLogin(String username, Object event) {
+ PlayerLoginEvent e = (PlayerLoginEvent) event;
+ CheckStatus status = v4GuardSpigot.getCoreInstance().getCheckManager().getCheckStatus(e.getPlayer().getName());
+ if(status != null && status.isBlocked()){
+ e.disallow(PlayerLoginEvent.Result.KICK_OTHER, status.getReason());
+ v4GuardSpigot.getCoreInstance().getCheckManager().getCheckStatusMap().remove(e.getPlayer().getName());
+ }
+ }
+
+ @Override
+ public void onPostLogin(String username, Object event) {
+ PlayerJoinEvent e = (PlayerJoinEvent) event;
+ CheckStatus status = v4GuardSpigot.getCoreInstance().getCheckManager().getCheckStatus(e.getPlayer().getName());
+ if(status != null && status.isBlocked()){
+ e.getPlayer().kickPlayer(status.getReason());
+ v4GuardSpigot.getCoreInstance().getCheckManager().getCheckStatusMap().remove(e.getPlayer().getName());
+ }
+ }
+}
diff --git a/src/main/java/io/v4guard/plugin/spigot/listener/AntiVPNListener.java b/src/main/java/io/v4guard/plugin/spigot/listener/AntiVPNListener.java
index cac5630..74fdfb1 100644
--- a/src/main/java/io/v4guard/plugin/spigot/listener/AntiVPNListener.java
+++ b/src/main/java/io/v4guard/plugin/spigot/listener/AntiVPNListener.java
@@ -1,74 +1,27 @@
package io.v4guard.plugin.spigot.listener;
-import io.v4guard.plugin.core.socket.SocketStatus;
-import io.v4guard.plugin.core.tasks.types.CompletableIPCheckTask;
-import io.v4guard.plugin.core.tasks.types.CompletableNameCheckTask;
-import io.v4guard.plugin.core.utils.StringUtils;
import io.v4guard.plugin.spigot.v4GuardSpigot;
-import org.bson.Document;
-import org.bukkit.ChatColor;
-import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
-import org.bukkit.scheduler.BukkitRunnable;
-
-import java.util.List;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerLoginEvent;
public class AntiVPNListener implements Listener {
@EventHandler
public void onPreLogin(final AsyncPlayerPreLoginEvent e) {
- if (!v4GuardSpigot.getCoreInstance().getBackendConnector().getSocketStatus().equals(SocketStatus.AUTHENTICATED)) {
- return;
- }
- Document kickMessages = (Document) v4GuardSpigot.getCoreInstance().getBackendConnector().getSettings().get("messages");
- final boolean wait = (boolean) v4GuardSpigot.getCoreInstance().getBackendConnector().getSettings().get("waitResponse");
- new CompletableNameCheckTask(e.getName()) {
- @Override
- public void complete(boolean nameIsValid) {
- if(nameIsValid){
- new CompletableIPCheckTask(e.getAddress().getHostAddress(), e.getName(), -1) {
- CompletableIPCheckTask task = this;
- @Override
- public void complete() {
- new BukkitRunnable() {
- @Override
- public void run() {
- String username = e.getName();
- String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("kick"));
- Document data = (Document) task.getData().get("result");
- kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, (Document) data.get("variables"));
- if(isBlocked()){
- if(wait){
- e.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
- e.setKickMessage(kickReasonMessage);
- } else {
- Player player = v4GuardSpigot.getV4Guard().getServer().getPlayer(e.getName());
- player.kickPlayer(kickReasonMessage);
- }
- }
- }
- }.runTask(v4GuardSpigot.getV4Guard());
- }
- };
- } else {
- Player player = v4GuardSpigot.getV4Guard().getServer().getPlayer(e.getName());
- if (player == null) {
- return;
- }
- String message= StringUtils.buildMultilineString((List) kickMessages.get("invalidUsername"));
- message = StringUtils.replacePlaceholders(message, new Document("username", e.getName()));
- player.kickPlayer(ChatColor.translateAlternateColorCodes('&', message));
- }
- }
- };
+ v4GuardSpigot.getCoreInstance().getCheckManager().runPreLoginCheck(e.getName(), e);
+ }
+
+ @EventHandler
+ public void onLogin(final PlayerLoginEvent e) {
+ v4GuardSpigot.getCoreInstance().getCheckManager().runLoginCheck(e.getPlayer().getName(), e);
+ }
- try {
- if(wait) Thread.sleep(1000L);
- } catch (InterruptedException interruptedException) {
- interruptedException.printStackTrace();
- }
+ @EventHandler
+ public void onPostLogin(final PlayerJoinEvent e) {
+ v4GuardSpigot.getCoreInstance().getCheckManager().runPostLoginCheck(e.getPlayer().getName(), e);
}
}
diff --git a/src/main/java/io/v4guard/plugin/spigot/v4GuardSpigot.java b/src/main/java/io/v4guard/plugin/spigot/v4GuardSpigot.java
index 7755eee..9ad9337 100644
--- a/src/main/java/io/v4guard/plugin/spigot/v4GuardSpigot.java
+++ b/src/main/java/io/v4guard/plugin/spigot/v4GuardSpigot.java
@@ -18,6 +18,7 @@ public void onEnable(){
this.getServer().getConsoleSender().sendMessage("§e[v4guard-plugin] (Spigot) Enabling...");
try {
core = new v4GuardCore(v4GuardMode.SPIGOT);
+ core.getCheckManager().addProcessor(new SpigotCheckProcessor());
} catch (Exception e) {
this.getServer().getConsoleSender().sendMessage("§c[v4guard-plugin] (Spigot) Enabling... [ERROR]");
this.getServer().getConsoleSender().sendMessage("§cPlease check the console for more information and report this error.");
diff --git a/src/main/java/io/v4guard/plugin/velocity/VelocityCheckProcessor.java b/src/main/java/io/v4guard/plugin/velocity/VelocityCheckProcessor.java
new file mode 100644
index 0000000..fdc07e7
--- /dev/null
+++ b/src/main/java/io/v4guard/plugin/velocity/VelocityCheckProcessor.java
@@ -0,0 +1,97 @@
+package io.v4guard.plugin.velocity;
+
+import com.velocitypowered.api.event.Continuation;
+import com.velocitypowered.api.event.ResultedEvent;
+import com.velocitypowered.api.event.connection.LoginEvent;
+import com.velocitypowered.api.event.connection.PostLoginEvent;
+import com.velocitypowered.api.event.connection.PreLoginEvent;
+import com.velocitypowered.api.proxy.Player;
+import io.v4guard.plugin.core.check.CheckProcessor;
+import io.v4guard.plugin.core.socket.SocketStatus;
+import io.v4guard.plugin.core.tasks.types.CompletableIPCheckTask;
+import io.v4guard.plugin.core.tasks.types.CompletableNameCheckTask;
+import io.v4guard.plugin.core.utils.CheckStatus;
+import io.v4guard.plugin.core.utils.StringUtils;
+import net.kyori.adventure.text.Component;
+import org.bson.Document;
+
+import java.util.List;
+import java.util.Optional;
+
+public class VelocityCheckProcessor implements CheckProcessor {
+
+ public void onPreLoginWithContinuation(Object event, Continuation continuation) {
+ PreLoginEvent e = (PreLoginEvent) event;
+ final boolean wait = (boolean) v4GuardVelocity.getCoreInstance().getBackendConnector().getSettings().get("waitResponse");
+ if (!wait || !v4GuardVelocity.getCoreInstance().getBackendConnector().getSocketStatus().equals(SocketStatus.AUTHENTICATED)) {
+ if(continuation != null) continuation.resume();
+ return;
+ }
+ Document kickMessages = (Document) v4GuardVelocity.getCoreInstance().getBackendConnector().getSettings().get("messages");
+ doChecks(e, kickMessages, continuation);
+ }
+
+ @Override
+ public void onPreLogin(String username, Object event) {
+ PreLoginEvent e = (PreLoginEvent) event;
+ final boolean wait = (boolean) v4GuardVelocity.getCoreInstance().getBackendConnector().getSettings().get("waitResponse");
+ if(wait || !v4GuardVelocity.getCoreInstance().getBackendConnector().getSocketStatus().equals(SocketStatus.AUTHENTICATED)) return;
+ Document kickMessages = (Document) v4GuardVelocity.getCoreInstance().getBackendConnector().getSettings().get("messages");
+ doChecks(e, kickMessages, null);
+ }
+
+ @Override
+ public void onLogin(String username, Object event) {
+ LoginEvent e = (LoginEvent) event;
+ CheckStatus status = v4GuardVelocity.getCoreInstance().getCheckManager().getCheckStatus(e.getPlayer().getUsername());
+ if(status != null && status.isBlocked()){
+ e.setResult(ResultedEvent.ComponentResult.denied(Component.text(status.getReason())));
+ v4GuardVelocity.getCoreInstance().getCheckManager().getCheckStatusMap().remove(e.getPlayer().getUsername());
+ }
+ }
+
+ @Override
+ public void onPostLogin(String username, Object event) {
+ PostLoginEvent e = (PostLoginEvent) event;
+ CheckStatus status = v4GuardVelocity.getCoreInstance().getCheckManager().getCheckStatus(e.getPlayer().getUsername());
+ if(status != null && status.isBlocked()){
+ e.getPlayer().disconnect(Component.text(status.getReason()));
+ v4GuardVelocity.getCoreInstance().getCheckManager().getCheckStatusMap().remove(e.getPlayer().getUsername());
+ }
+ }
+
+
+ private void doChecks(PreLoginEvent e, Document kickMessages, Continuation continuation) {
+ new CompletableNameCheckTask(e.getUsername()) {
+ @Override
+ public void complete(boolean nameIsValid) {
+ if(nameIsValid){
+ new CompletableIPCheckTask(e.getConnection().getRemoteAddress().getAddress().getHostAddress(), e.getUsername(), e.getConnection().getProtocolVersion().getProtocol()){
+ @Override
+ public void complete() {
+ if (this.isBlocked()) {
+ String username = this.getUsername();
+ String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("kick"));
+ Document data = (Document) this.getData().get("result");
+ kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, (Document) data.get("variables"));
+ Optional pp = v4GuardVelocity.getV4Guard().getServer().getPlayer(username);
+ if(pp.isPresent()) {
+ pp.get().disconnect(Component.text(kickReasonMessage));
+ } else {
+ e.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(kickReasonMessage)));
+ }
+ }
+ if(continuation != null) continuation.resume();
+ }
+ };
+ } else {
+ String username = this.getUsername();
+ String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("invalidUsername"));
+ kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, new Document("username", username));
+ e.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(kickReasonMessage)));
+ if(continuation != null) continuation.resume();
+ }
+ }
+ };
+ }
+}
diff --git a/src/main/java/io/v4guard/plugin/velocity/listener/AntiVPNListener.java b/src/main/java/io/v4guard/plugin/velocity/listener/AntiVPNListener.java
index f60d128..6e4aaad 100644
--- a/src/main/java/io/v4guard/plugin/velocity/listener/AntiVPNListener.java
+++ b/src/main/java/io/v4guard/plugin/velocity/listener/AntiVPNListener.java
@@ -3,74 +3,34 @@
import com.velocitypowered.api.event.Continuation;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
+import com.velocitypowered.api.event.connection.LoginEvent;
+import com.velocitypowered.api.event.connection.PostLoginEvent;
import com.velocitypowered.api.event.connection.PreLoginEvent;
-import com.velocitypowered.api.proxy.Player;
-import io.v4guard.plugin.core.socket.BackendConnector;
-import io.v4guard.plugin.core.socket.SocketStatus;
-import io.v4guard.plugin.core.tasks.types.CompletableIPCheckTask;
-import io.v4guard.plugin.core.tasks.types.CompletableNameCheckTask;
-import io.v4guard.plugin.core.utils.StringUtils;
+import io.v4guard.plugin.velocity.VelocityCheckProcessor;
import io.v4guard.plugin.velocity.v4GuardVelocity;
-import net.kyori.adventure.text.Component;
-import org.bson.Document;
-
-import java.util.List;
-import java.util.Optional;
public class AntiVPNListener {
- private BackendConnector conn = v4GuardVelocity.getCoreInstance().getBackendConnector();
-
@Subscribe(order = PostOrder.FIRST)
public void onAsyncPreLogin(PreLoginEvent e, Continuation continuation) {
- final boolean wait = (boolean) v4GuardVelocity.getCoreInstance().getBackendConnector().getSettings().get("waitResponse");
- if (!wait || !conn.getSocketStatus().equals(SocketStatus.AUTHENTICATED)) {
- if(continuation != null) continuation.resume();
- return;
- }
- Document kickMessages = (Document) v4GuardVelocity.getCoreInstance().getBackendConnector().getSettings().get("messages");
- doChecks(e, kickMessages, continuation);
+ VelocityCheckProcessor pr = (VelocityCheckProcessor) v4GuardVelocity.getCoreInstance().getCheckManager().getProcessorByClass(VelocityCheckProcessor.class);
+ pr.onPreLoginWithContinuation(e, continuation);
}
@Subscribe(order = PostOrder.FIRST)
public void onPreLogin(PreLoginEvent e) {
- final boolean wait = (boolean) v4GuardVelocity.getCoreInstance().getBackendConnector().getSettings().get("waitResponse");
- if(wait || !conn.getSocketStatus().equals(SocketStatus.AUTHENTICATED)) return;
- Document kickMessages = (Document) v4GuardVelocity.getCoreInstance().getBackendConnector().getSettings().get("messages");
- doChecks(e, kickMessages, null);
+ v4GuardVelocity.getCoreInstance().getCheckManager().runPreLoginCheck(e.getUsername(), e);
+ }
+
+ @Subscribe(order = PostOrder.FIRST)
+ public void onLogin(LoginEvent e) {
+ v4GuardVelocity.getCoreInstance().getCheckManager().runLoginCheck(e.getPlayer().getUsername(), e);
}
- private void doChecks(PreLoginEvent e, Document kickMessages, Continuation continuation) {
- new CompletableNameCheckTask(e.getUsername()) {
- @Override
- public void complete(boolean nameIsValid) {
- if(nameIsValid){
- new CompletableIPCheckTask(e.getConnection().getRemoteAddress().getAddress().getHostAddress(), e.getUsername(), e.getConnection().getProtocolVersion().getProtocol()){
- @Override
- public void complete() {
- if (this.isBlocked()) {
- String username = this.getUsername();
- String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("kick"));
- Document data = (Document) this.getData().get("result");
- kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, (Document) data.get("variables"));
- Optional pp = v4GuardVelocity.getV4Guard().getServer().getPlayer(username);
- if(pp.isPresent()) {
- pp.get().disconnect(Component.text(kickReasonMessage));
- } else {
- e.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(kickReasonMessage)));
- }
- }
- if(continuation != null) continuation.resume();
- }
- };
- } else {
- String username = this.getUsername();
- String kickReasonMessage = StringUtils.buildMultilineString((List) kickMessages.get("invalidUsername"));
- kickReasonMessage = StringUtils.replacePlaceholders(kickReasonMessage, new Document("username", username));
- e.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(kickReasonMessage)));
- if(continuation != null) continuation.resume();
- }
- }
- };
+ @Subscribe(order = PostOrder.FIRST)
+ public void onPostLogin(PostLoginEvent e) {
+ v4GuardVelocity.getCoreInstance().getCheckManager().runPostLoginCheck(e.getPlayer().getUsername(), e);
}
+
+
}
diff --git a/src/main/java/io/v4guard/plugin/velocity/v4GuardVelocity.java b/src/main/java/io/v4guard/plugin/velocity/v4GuardVelocity.java
index 9fb883e..7ab1e6c 100644
--- a/src/main/java/io/v4guard/plugin/velocity/v4GuardVelocity.java
+++ b/src/main/java/io/v4guard/plugin/velocity/v4GuardVelocity.java
@@ -13,10 +13,12 @@
import java.util.logging.Logger;
-@Plugin(id = "v4guard-plugin", name = "v4Guard Plugin", version = "1.0.4",
+@Plugin(id = "v4guard-plugin", name = "v4Guard Plugin", version = v4GuardCore.pluginVersion,
url = "https://v4guard.io", description = "v4Guard Plugin for Minecraft Servers", authors = {"DigitalSynware"})
public class v4GuardVelocity {
+
+
private static v4GuardCore core;
private static v4GuardVelocity v4GuardVelocity;
@@ -34,6 +36,7 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
server.getConsoleCommandSource().sendMessage(Component.text("§e[v4guard-plugin] (Velocity) Enabling..."));
try {
core = new v4GuardCore(v4GuardMode.VELOCITY);
+ core.getCheckManager().addProcessor(new VelocityCheckProcessor());
} catch (Exception e) {
server.getConsoleCommandSource().sendMessage(Component.text("§c[v4guard-plugin] (Velocity) Enabling... [ERROR]"));
server.getConsoleCommandSource().sendMessage(Component.text("§cPlease check the console for more information and report this error."));
diff --git a/src/main/resources/bungee.yml b/src/main/resources/bungee.yml
index 027f08a..4757921 100644
--- a/src/main/resources/bungee.yml
+++ b/src/main/resources/bungee.yml
@@ -1,4 +1,4 @@
name: v4guard-plugin
-version: 1.0.4
+version: ${project.version}
main: io.v4guard.plugin.bungee.v4GuardBungee
author: DigitalSynware
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 0927574..9de5814 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,4 +1,4 @@
name: v4guard-plugin
-version: 1.0.4
+version: ${project.version}
main: io.v4guard.plugin.spigot.v4GuardSpigot
author: DigitalSynware