diff --git a/pom.xml b/pom.xml
index 07aab91..959294f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.lielamar
2fa
- 1.6.0
+ 1.6.1
UTF-8
@@ -132,7 +132,7 @@
com.lielamar
LielsUtils
- 1.6.27
+ 1.6.28
compile
diff --git a/src/main/java/com/lielamar/auth/bukkit/TwoFactorAuthentication.java b/src/main/java/com/lielamar/auth/bukkit/TwoFactorAuthentication.java
index 6ce8acc..75fe0a8 100644
--- a/src/main/java/com/lielamar/auth/bukkit/TwoFactorAuthentication.java
+++ b/src/main/java/com/lielamar/auth/bukkit/TwoFactorAuthentication.java
@@ -94,6 +94,7 @@ public void setupAuth() {
this.storageHandler = StorageHandler.loadStorageHandler(this.configHandler, getDataFolder().getAbsolutePath());
AuthCommunicationHandler authCommunicationHandler;
+
{
if(this.configHandler.getCommunicationMethod() == CommunicationMethod.PROXY) {
authCommunicationHandler = new ProxyAuthCommunication(this);
@@ -106,7 +107,7 @@ public void setupAuth() {
}
}
- this.authHandler = new AuthHandler(this, storageHandler, authCommunicationHandler);
+ this.authHandler = new AuthHandler(this, storageHandler, authCommunicationHandler, new BasicAuthCommunication(this));
this.authTracker = new AuthTracker();
}
diff --git a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/CancelCommand.java b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/CancelCommand.java
index edb63db..101cb46 100644
--- a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/CancelCommand.java
+++ b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/CancelCommand.java
@@ -46,7 +46,7 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}
@Override
- public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] strings) {
+ public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] args) {
return new ArrayList<>();
}
diff --git a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/DisableCommand.java b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/DisableCommand.java
index dcc00da..0a56e72 100644
--- a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/DisableCommand.java
+++ b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/DisableCommand.java
@@ -54,8 +54,8 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}
@Override
- public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] strings) {
- return new TabOptionsBuilder().player().build(new String[0]);
+ public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] args) {
+ return new TabOptionsBuilder().player().build(args);
}
@Override
diff --git a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/DisableForOthersCommand.java b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/DisableForOthersCommand.java
index eb4b054..8ea8be6 100644
--- a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/DisableForOthersCommand.java
+++ b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/DisableForOthersCommand.java
@@ -54,8 +54,8 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}
@Override
- public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] strings) {
- return new TabOptionsBuilder().player().build(new String[0]);
+ public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] args) {
+ return new TabOptionsBuilder().player().build(args);
}
@Override
diff --git a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/EnableCommand.java b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/EnableCommand.java
index 2c577f7..a3452a4 100644
--- a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/EnableCommand.java
+++ b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/EnableCommand.java
@@ -47,8 +47,8 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}
@Override
- public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] strings) {
- return new TabOptionsBuilder().player().build(new String[0]);
+ public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] args) {
+ return new TabOptionsBuilder().player().build(args);
}
@Override
diff --git a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/HelpCommand.java b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/HelpCommand.java
index 201dc57..3a96ecd 100644
--- a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/HelpCommand.java
+++ b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/HelpCommand.java
@@ -45,7 +45,7 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}
@Override
- public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] strings) {
+ public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] args) {
return new ArrayList<>();
}
diff --git a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/LoginCommand.java b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/LoginCommand.java
index 223f8c2..c0065eb 100644
--- a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/LoginCommand.java
+++ b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/LoginCommand.java
@@ -60,7 +60,7 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}
@Override
- public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] strings) {
+ public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] args) {
return new ArrayList<>();
}
diff --git a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/ReloadCommand.java b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/ReloadCommand.java
index 48531f5..8916bf8 100644
--- a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/ReloadCommand.java
+++ b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/ReloadCommand.java
@@ -48,7 +48,7 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}
@Override
- public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] strings) {
+ public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] args) {
return new ArrayList<>();
}
diff --git a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/ReportCommand.java b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/ReportCommand.java
index 9ea7484..0389acb 100644
--- a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/ReportCommand.java
+++ b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/ReportCommand.java
@@ -90,7 +90,7 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}
@Override
- public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] strings) {
+ public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] args) {
return new ArrayList<>();
}
diff --git a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/SetupCommand.java b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/SetupCommand.java
index 97e300e..314e59c 100644
--- a/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/SetupCommand.java
+++ b/src/main/java/com/lielamar/auth/bukkit/commands/subcommands/SetupCommand.java
@@ -62,7 +62,7 @@ public boolean runCommand(@NotNull CommandSender commandSender, @NotNull String[
}
@Override
- public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] strings) {
+ public List tabOptions(@NotNull CommandSender commandSender, @NotNull String[] args) {
return new ArrayList<>();
}
diff --git a/src/main/java/com/lielamar/auth/bukkit/communication/BasicAuthCommunication.java b/src/main/java/com/lielamar/auth/bukkit/communication/BasicAuthCommunication.java
index 350e5c6..5dbf9a8 100644
--- a/src/main/java/com/lielamar/auth/bukkit/communication/BasicAuthCommunication.java
+++ b/src/main/java/com/lielamar/auth/bukkit/communication/BasicAuthCommunication.java
@@ -19,8 +19,9 @@ public BasicAuthCommunication(TwoFactorAuthentication plugin) {
long timeout = this.plugin.getConfigHandler().getCommunicationTimeout();
// Timeouts all callbacks that were set more than ${timeout} seconds ago using #onTimeout
- Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
+ Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
long currentTimestamp = System.currentTimeMillis();
+
super.callbacks.entrySet().removeIf(entry -> {
if(((currentTimestamp - entry.getValue().getExecutionStamp()) / 1000) > (timeout / 20)) {
entry.getValue().onTimeout();
diff --git a/src/main/java/com/lielamar/auth/bukkit/handlers/AuthHandler.java b/src/main/java/com/lielamar/auth/bukkit/handlers/AuthHandler.java
index 40d4aa9..40bb7f7 100644
--- a/src/main/java/com/lielamar/auth/bukkit/handlers/AuthHandler.java
+++ b/src/main/java/com/lielamar/auth/bukkit/handlers/AuthHandler.java
@@ -36,8 +36,8 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-import java.util.Objects;
import java.util.UUID;
+import java.util.stream.Collectors;
public class AuthHandler extends com.lielamar.auth.shared.handlers.AuthHandler {
@@ -48,9 +48,11 @@ public class AuthHandler extends com.lielamar.auth.shared.handlers.AuthHandler {
protected Hash hash;
+ private int callbackTimeouts;
+
public AuthHandler(@NotNull TwoFactorAuthentication plugin, @Nullable StorageHandler storageHandler,
- @Nullable AuthCommunicationHandler authCommunicationHandler) {
- super(storageHandler, authCommunicationHandler);
+ @Nullable AuthCommunicationHandler authCommunicationHandler, @Nullable AuthCommunicationHandler fallbackCommunicationHandler) {
+ super(storageHandler, authCommunicationHandler, fallbackCommunicationHandler);
this.plugin = plugin;
@@ -63,6 +65,8 @@ public AuthHandler(@NotNull TwoFactorAuthentication plugin, @Nullable StorageHan
if(hashType.equalsIgnoreCase("SHA256")) this.hash = new SHA256();
else if(hashType.equalsIgnoreCase("SHA512")) this.hash = new SHA512();
else this.hash = new NoHash();
+
+ this.callbackTimeouts = 0;
}
public void reloadOnlinePlayers() {
@@ -139,8 +143,22 @@ public void playerJoin(@NotNull UUID uuid) {
if(super.authCommunicationHandler == null)
super.authCommunicationHandler = new BasicAuthCommunication(this.plugin);
+ // Checking whether we need to retrieve data on the user
+ Player player = Bukkit.getPlayer(uuid);
+
+ if(player == null || !player.isOnline())
+ return;
+
+ if(this.getStorageHandler() == null)
+ return;
+
+ if(!player.hasPermission("2fa.use") || this.getStorageHandler().getKey(uuid) == null) {
+ this.changeState(uuid, AuthState.DISABLED);
+ return;
+ }
+
// Setting the initial state so players can't abuse the brief moment without 2fa protection
- changeState(uuid, AuthState.PENDING_LOGIN);
+ this.changeState(uuid, AuthState.PENDING_LOGIN);
// Asking communication handler to load the player state and execute LoadAuthCallback when a result is given
super.authCommunicationHandler.loadPlayerState(uuid, new LoadAuthCallback(uuid));
@@ -335,16 +353,11 @@ public void execute(AuthState authState) {
if(player == null || !player.isOnline())
return;
- if(!player.hasPermission("2fa.use")) {
- changeState(playerUUID, AuthState.DISABLED);
- return;
- }
-
if(getStorageHandler() == null)
return;
// If AuthCommunication's result returned that the player is already authenticated, we don't need to continue
- if(authState == AuthState.AUTHENTICATED) {
+ if(authState == AuthState.AUTHENTICATED || authState == AuthState.NONE) {
changeState(this.playerUUID, authState);
return;
}
@@ -370,7 +383,16 @@ public void execute(AuthState authState) {
@Override
public void onTimeout() {
- execute(AuthState.NONE);
+ callbackTimeouts++;
+ if(callbackTimeouts > 10) {
+ callbackTimeouts = 0;
+
+ Bukkit.getOnlinePlayers().stream().filter(pl -> pl.hasPermission("2fa.alerts")).forEach(pl -> {
+ plugin.getMessageHandler().sendMessage(pl, MessageHandler.TwoFAMessages.COMMUNICATION_METHOD_NOT_CORRECT);
+ });
+ }
+
+ fallbackCommunicationHandler.loadPlayerState(playerUUID, this);
}
@Override
diff --git a/src/main/java/com/lielamar/auth/bukkit/handlers/ConfigHandler.java b/src/main/java/com/lielamar/auth/bukkit/handlers/ConfigHandler.java
index 589548b..4df367e 100644
--- a/src/main/java/com/lielamar/auth/bukkit/handlers/ConfigHandler.java
+++ b/src/main/java/com/lielamar/auth/bukkit/handlers/ConfigHandler.java
@@ -12,6 +12,7 @@
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.*;
@@ -51,7 +52,7 @@ public ConfigHandler(FileManager fileManager) {
protected Location tpAfterAuthLocation = null;
protected CommunicationMethod communicationMethod = CommunicationMethod.PROXY;
- protected int communicationTimeout = 100;
+ protected int communicationTimeout = 30;
public boolean shouldCheckForUpdates() { return this.checkForUpdates; }
@@ -409,7 +410,8 @@ protected enum ShorterEvents {
CHANGE_SLOT(PlayerItemHeldEvent.class),
COMMANDS(PlayerCommandPreprocessEvent.class),
MOVE_ITEM(InventoryMoveItemEvent.class),
- INTERACT_WITH_FRAMES(PlayerInteractEntityEvent.class);
+ INTERACT_WITH_FRAMES(PlayerInteractEntityEvent.class),
+ DEATH(PlayerDeathEvent.class);
private final Class extends Event> matchingEvent;
diff --git a/src/main/java/com/lielamar/auth/bukkit/listeners/DisabledEvents.java b/src/main/java/com/lielamar/auth/bukkit/listeners/DisabledEvents.java
index e7aa034..453b985 100644
--- a/src/main/java/com/lielamar/auth/bukkit/listeners/DisabledEvents.java
+++ b/src/main/java/com/lielamar/auth/bukkit/listeners/DisabledEvents.java
@@ -12,6 +12,7 @@
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
@@ -91,6 +92,19 @@ public void onItemPickup(PlayerPickupItemEvent event) {
}
}
+ @EventHandler (priority = EventPriority.HIGHEST)
+ public void onItemPickup(EntityPickupItemEvent event) {
+ if(!(event.getEntity() instanceof Player)) return;
+
+ if(!this.plugin.getConfigHandler().getDisabledEvents().getOrDefault(event.getClass(), true)) return;
+
+ if(this.plugin.getAuthHandler().needsToAuthenticate(event.getEntity().getUniqueId())) {
+ event.setCancelled(true);
+ } else if(this.plugin.getAuthHandler().isQRCodeItem(event.getItem().getItemStack())) {
+ event.getItem().remove();
+ }
+ }
+
@EventHandler (priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event) {
if(!this.plugin.getConfigHandler().getDisabledEvents().getOrDefault(event.getClass(), true)) return;
diff --git a/src/main/java/com/lielamar/auth/shared/handlers/AuthHandler.java b/src/main/java/com/lielamar/auth/shared/handlers/AuthHandler.java
index 13ec90a..0000dc0 100644
--- a/src/main/java/com/lielamar/auth/shared/handlers/AuthHandler.java
+++ b/src/main/java/com/lielamar/auth/shared/handlers/AuthHandler.java
@@ -17,7 +17,7 @@ public abstract class AuthHandler {
private final Map failedAttempts;
protected StorageHandler storageHandler;
- protected AuthCommunicationHandler authCommunicationHandler;
+ protected AuthCommunicationHandler authCommunicationHandler, fallbackCommunicationHandler;
protected HashMap authStates;
@@ -26,11 +26,17 @@ public AuthHandler() {
}
public AuthHandler(@Nullable StorageHandler storageHandler, @Nullable AuthCommunicationHandler authCommunicationHandler) {
+ this(storageHandler, authCommunicationHandler, null);
+ }
+
+ public AuthHandler(@Nullable StorageHandler storageHandler, @Nullable AuthCommunicationHandler authCommunicationHandler,
+ @Nullable AuthCommunicationHandler fallbackCommunicationHandler) {
this.pendingKeys = new HashMap<>();
this.failedAttempts = new HashMap<>();
this.storageHandler = storageHandler;
this.authCommunicationHandler = authCommunicationHandler;
+ this.fallbackCommunicationHandler = fallbackCommunicationHandler;
this.authStates = new HashMap<>();
}
diff --git a/src/main/java/com/lielamar/auth/shared/handlers/MessageHandler.java b/src/main/java/com/lielamar/auth/shared/handlers/MessageHandler.java
index 848bc19..fb0987f 100644
--- a/src/main/java/com/lielamar/auth/shared/handlers/MessageHandler.java
+++ b/src/main/java/com/lielamar/auth/shared/handlers/MessageHandler.java
@@ -75,6 +75,8 @@ public enum TwoFAMessages {
RELOADED_CONFIG("&aConfig was reloaded"),
FAILED_AUTHENTICATION_ALERT("&c%name% failed to authenticate %times% times"),
SOMETHING_WENT_WRONG("&cSomething went wrong. Please contact a Staff Member!"),
+ COMMUNICATION_METHOD_NOT_CORRECT("&cWe have noticed that a lot of the requests 2FA make between servers are being timed out." +
+ "\nPlease make sure Communication-Method is set to the best option for your server in the configuration!"),
KEYWORD_ENABLED("Enabled"),
KEYWORD_DISABLED("Disabled"),
KEYWORD_REQUIRED("Required"),
diff --git a/src/main/java/com/lielamar/auth/velocity/TwoFactorAuthentication.java b/src/main/java/com/lielamar/auth/velocity/TwoFactorAuthentication.java
index 4d6228e..8dde938 100644
--- a/src/main/java/com/lielamar/auth/velocity/TwoFactorAuthentication.java
+++ b/src/main/java/com/lielamar/auth/velocity/TwoFactorAuthentication.java
@@ -20,7 +20,7 @@
import java.nio.file.Path;
-@Plugin(id = "twofa", name = "2FA", version = "1.6.0", description = "Add another layer of protection to your server", authors = { "Liel Amar", "SadGhost"})
+@Plugin(id = "twofa", name = "2FA", version = "1.6.1", description = "Add another layer of protection to your server", authors = { "Liel Amar", "SadGhost"})
public class TwoFactorAuthentication implements TwoFactorAuthenticationPlugin {
private final ProxyServer proxy;
diff --git a/src/main/resources/bungee.yml b/src/main/resources/bungee.yml
index bc34d69..a563ca5 100644
--- a/src/main/resources/bungee.yml
+++ b/src/main/resources/bungee.yml
@@ -1,5 +1,5 @@
name: 2FA
-version: "1.6.0"
+version: "1.6.1"
author: "LielAmar"
main: com.lielamar.auth.bungee.TwoFactorAuthentication
description: Add another layer of protection to your server
\ No newline at end of file
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 4bf9400..9fbfcda 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -103,6 +103,7 @@ tp-after-auth:
# Possible methods for the plugin to communicate between servers
#
+# - NONE (Only use NONE if you have a single server)
# - PROXY
# - REDIS (NOT SUPPORTED YET)
# - RABBITMQ (NOT SUPPORTED YET)
@@ -111,7 +112,7 @@ communication-method: PROXY
communication-data:
# How long (in ticks) should the plugin wait before timing out communication messages
# 1 second = 20 ticks
- timeout: 100
+ timeout: 30
# Possible methods for the plugin to store data
#
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 6b1d0d6..e014548 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,5 +1,5 @@
name: 2FA
-version: "1.6.0"
+version: "1.6.1"
api-version: 1.13
authors: [LielAmar, SadGhost]
main: com.lielamar.auth.bukkit.TwoFactorAuthentication
@@ -32,6 +32,7 @@ permissions:
2fa.remove: true
2fa.remove.others: true
2fa.reload: true
+ 2fa.alerts: true
2fa.use:
description: Permissions to use the /2FA command
default: op
@@ -49,4 +50,6 @@ permissions:
default: op
2fa.demand:
description: A player with this permission must have 2FA linked to thier account
- default: false
\ No newline at end of file
+ default: false
+ 2fa.alerts:
+ description: Admin permissions to get alerts on critical issues with 2FA configuration
\ No newline at end of file