refactor: improve AuthPlugin by at least a bit

This commit is contained in:
Chayapak 2024-11-04 16:57:28 +07:00
parent cb86896223
commit 783a7a937e
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA

View file

@ -23,6 +23,8 @@ public class AuthPlugin extends PlayersPlugin.Listener {
private boolean hasCorrectHash; private boolean hasCorrectHash;
private PlayerEntry targetPlayer;
private boolean started = false; private boolean started = false;
public AuthPlugin (Bot bot) { public AuthPlugin (Bot bot) {
@ -39,7 +41,7 @@ public class AuthPlugin extends PlayersPlugin.Listener {
return AuthPlugin.this.systemMessageReceived(component); return AuthPlugin.this.systemMessageReceived(component);
} }
}); });
bot.executor.scheduleAtFixedRate(this::check, 0, 1, TimeUnit.SECONDS); bot.executor.scheduleAtFixedRate(this::check, 1, 3, TimeUnit.SECONDS);
} }
private String getSanitizedOwnerName() { private String getSanitizedOwnerName() {
@ -50,6 +52,8 @@ public class AuthPlugin extends PlayersPlugin.Listener {
public void playerJoined(PlayerEntry target) { public void playerJoined(PlayerEntry target) {
if (!target.profile.getName().equals(getSanitizedOwnerName()) || !bot.options.useCore) return; if (!target.profile.getName().equals(getSanitizedOwnerName()) || !bot.options.useCore) return;
targetPlayer = target;
bot.executor.schedule(() -> sendVerificationMessage(target, true), 2, TimeUnit.SECONDS); bot.executor.schedule(() -> sendVerificationMessage(target, true), 2, TimeUnit.SECONDS);
} }
@ -110,6 +114,8 @@ public class AuthPlugin extends PlayersPlugin.Listener {
hasCorrectHash = inputHash.equals(hash); hasCorrectHash = inputHash.equals(hash);
if (hasCorrectHash && targetPlayer != null) bot.chat.tellraw(Component.text("You have been verified").color(NamedTextColor.GREEN), targetPlayer.profile.getId());
return false; return false;
} catch (Exception ignored) {} } catch (Exception ignored) {}
@ -117,7 +123,7 @@ public class AuthPlugin extends PlayersPlugin.Listener {
} }
private void check() { private void check() {
if (!started) return; if (!started || !bot.config.ownerAuthentication.enabled) return;
final PlayerEntry entry = bot.players.getEntry(getSanitizedOwnerName()); final PlayerEntry entry = bot.players.getEntry(getSanitizedOwnerName());