MAJOR FIX ( VERy )

This commit is contained in:
Chayapak 2023-08-22 19:50:41 +07:00
parent 45704468e7
commit 413592c64f
3 changed files with 16 additions and 18 deletions

View file

@ -34,8 +34,8 @@ public class AuthPlugin extends PlayersPlugin.Listener {
bot.players.addListener(this); bot.players.addListener(this);
bot.chat.addListener(new ChatPlugin.Listener() { bot.chat.addListener(new ChatPlugin.Listener() {
@Override @Override
public void systemMessageReceived(Component component, String string, String ansi) { public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, String string, String ansi) {
AuthPlugin.this.systemMessageReceived(component); AuthPlugin.this.systemMessageReceived(component, isCommandSuggestions, isAuth);
} }
}); });
bot.executor.scheduleAtFixedRate(this::check, 0, 1, TimeUnit.SECONDS); bot.executor.scheduleAtFixedRate(this::check, 0, 1, TimeUnit.SECONDS);
@ -45,15 +45,15 @@ public class AuthPlugin extends PlayersPlugin.Listener {
public void playerJoined(PlayerEntry target) { public void playerJoined(PlayerEntry target) {
if (!target.profile.getName().equals(bot.config.ownerName) || !bot.options.useCore) return; if (!target.profile.getName().equals(bot.config.ownerName) || !bot.options.useCore) return;
bot.executor.schedule(() -> sendVerificationMessage(target), 2, TimeUnit.SECONDS); bot.executor.schedule(() -> sendVerificationMessage(target, true), 2, TimeUnit.SECONDS);
} }
public void sendVerificationMessage (PlayerEntry entry) { public void sendVerificationMessage (PlayerEntry entry, boolean setTimeJoined) {
started = true; started = true;
final long currentTime = System.currentTimeMillis(); final long currentTime = System.currentTimeMillis();
timeJoined = currentTime; if (setTimeJoined) timeJoined = currentTime;
final long time = currentTime / 10_000; final long time = currentTime / 10_000;
@ -79,13 +79,9 @@ public class AuthPlugin extends PlayersPlugin.Listener {
started = false; started = false;
} }
private void systemMessageReceived (Component component) { private void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth) {
try { try {
if (!(component instanceof TextComponent)) return; if (isCommandSuggestions || !isAuth) return;
final String content = ((TextComponent) component).content();
if (!content.equals(id)) return;
final List<Component> children = component.children(); final List<Component> children = component.children();
@ -116,7 +112,7 @@ public class AuthPlugin extends PlayersPlugin.Listener {
final long timeSinceJoined = System.currentTimeMillis() - timeJoined; final long timeSinceJoined = System.currentTimeMillis() - timeJoined;
if (!hasCorrectHash) sendVerificationMessage(entry); if (!hasCorrectHash) sendVerificationMessage(entry, false);
if (timeSinceJoined > bot.config.ownerAuthentication.timeout && !hasCorrectHash) { if (timeSinceJoined > bot.config.ownerAuthentication.timeout && !hasCorrectHash) {
bot.filter.mute(entry, "Not verified"); bot.filter.mute(entry, "Not verified");

View file

@ -91,19 +91,21 @@ public class ChatPlugin extends Bot.Listener {
if (playerMessage != null) break; if (playerMessage != null) break;
} }
boolean ignore = false; boolean isCommandSuggestions = false;
boolean isAuth = false;
if (component instanceof TextComponent t_component) { if (component instanceof TextComponent t_component) {
final String id = t_component.content(); final String id = t_component.content();
if (id.equals(bot.commandSuggestion.id) || id.equals(bot.auth.id)) ignore = true; if (id.equals(bot.commandSuggestion.id)) isCommandSuggestions = true;
else if (id.equals(bot.auth.id)) isAuth = true;
} }
final String string = ComponentUtilities.stringify(component); final String string = ComponentUtilities.stringify(component);
final String ansi = ComponentUtilities.stringifyAnsi(component); final String ansi = ComponentUtilities.stringifyAnsi(component);
for (Listener listener : listeners) { for (Listener listener : listeners) {
if (!ignore) listener.systemMessageReceived(component, string, ansi); if (!isCommandSuggestions && !isAuth) listener.systemMessageReceived(component, string, ansi);
listener.systemMessageReceived(component, ignore, string, ansi); listener.systemMessageReceived(component, isCommandSuggestions, isAuth, string, ansi);
if (playerMessage != null) listener.playerMessageReceived(playerMessage); if (playerMessage != null) listener.playerMessageReceived(playerMessage);
} }
@ -363,6 +365,6 @@ public class ChatPlugin extends Bot.Listener {
public static class Listener { public static class Listener {
public void playerMessageReceived (PlayerMessage message) {} public void playerMessageReceived (PlayerMessage message) {}
public void systemMessageReceived (Component component, String string, String ansi) {} public void systemMessageReceived (Component component, String string, String ansi) {}
public void systemMessageReceived (Component component, boolean isCommandSuggestions, String string, String ansi) {} public void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth, String string, String ansi) {}
} }
} }

View file

@ -20,7 +20,7 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener {
} }
@Override @Override
public void systemMessageReceived(Component component, boolean isCommandSuggestions, String string, String ansi) { public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, String string, String ansi) {
if (!isCommandSuggestions) return; if (!isCommandSuggestions) return;
try { try {