feat: username self-care that isn't chat-based (idea from denis, thanks !)
This commit is contained in:
@@ -1 +1 @@
|
||||
3574
|
||||
3583
|
||||
@@ -17,10 +17,9 @@ public abstract class SelfCare {
|
||||
public abstract boolean shouldRun ();
|
||||
|
||||
public void onPacketReceived (final Packet packet) { }
|
||||
|
||||
public void onMessageReceived (final Component component, final String string) { }
|
||||
|
||||
public void onCommandSpyMessageReceived (final PlayerEntry sender, final String command) { }
|
||||
public void onPlayerChangedUsername (final PlayerEntry target, final String from, final String to) { }
|
||||
|
||||
public void run () { }
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@ public class PlayersPlugin implements Listener {
|
||||
case UPDATE_GAME_MODE -> updateGameMode(entry);
|
||||
case UPDATE_LATENCY -> updateLatency(entry);
|
||||
case UPDATE_DISPLAY_NAME -> updateDisplayName(entry);
|
||||
default -> { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,11 @@ public class SelfCarePlugin implements Listener {
|
||||
for (final SelfCare selfCare : selfCares) selfCare.onCommandSpyMessageReceived(sender, command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChangedUsername (final PlayerEntry target, final String from, final String to) {
|
||||
for (final SelfCare selfCare : selfCares) selfCare.onPlayerChangedUsername(target, from, to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (final Session session, final Packet packet) {
|
||||
if (packet instanceof final ClientboundLoginPacket t_packet) packetReceived(t_packet);
|
||||
|
||||
@@ -1,30 +1,25 @@
|
||||
package me.chayapak1.chomens_bot.selfCares.kaboom.extras;
|
||||
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.data.player.PlayerEntry;
|
||||
import me.chayapak1.chomens_bot.data.selfCare.SelfCare;
|
||||
import me.chayapak1.chomens_bot.util.IllegalCharactersUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class UsernameSelfCare extends SelfCare {
|
||||
private long usernameStartTime = System.currentTimeMillis();
|
||||
private long usernameStartTime;
|
||||
private long successTime;
|
||||
|
||||
public UsernameSelfCare (final Bot bot) {
|
||||
super(bot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived (final Component component, final String string) {
|
||||
if (
|
||||
string.equals("Successfully set your username to \"" + bot.username + "\"")
|
||||
|| string.startsWith("You already have the username \"" + bot.username + "\"")
|
||||
) {
|
||||
this.needsRunning = false;
|
||||
} else if (
|
||||
string.startsWith("Successfully set your username to \"")
|
||||
|| string.startsWith("You already have the username \"")
|
||||
) {
|
||||
this.needsRunning = true;
|
||||
this.usernameStartTime = System.currentTimeMillis();
|
||||
public void onPlayerChangedUsername (final PlayerEntry target, final String from, final String to) {
|
||||
if (target.profile.getId().equals(bot.profile.getId())) {
|
||||
this.needsRunning = !to.equals(bot.username);
|
||||
|
||||
if (this.needsRunning) this.usernameStartTime = System.currentTimeMillis();
|
||||
else this.successTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +29,7 @@ public class UsernameSelfCare extends SelfCare {
|
||||
|
||||
return // running less than 2 seconds is useless since the bot will just get a cooldown message
|
||||
(System.currentTimeMillis() - usernameStartTime) >= 2 * 1000
|
||||
&& (System.currentTimeMillis() - successTime) >= 4 * 1000 // prevents the bot from spamming
|
||||
&& IllegalCharactersUtilities.isValidChatString(username);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user