more stuff + now ik why hashing break
well thats because yaml moment. i chaanged the key and it workdde fine so yeah yaml moment it sucks
This commit is contained in:
parent
7e1931f9b5
commit
3f28d95135
6 changed files with 127 additions and 133 deletions
|
@ -13,9 +13,8 @@ import org.apache.commons.lang3.RandomStringUtils;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class Bot {
|
||||
private final ArrayList<SessionListener> listeners = new ArrayList<>();
|
||||
|
@ -30,8 +29,6 @@ public class Bot {
|
|||
|
||||
@Getter private Session session;
|
||||
|
||||
@Getter private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(69);
|
||||
|
||||
@Getter @Setter private ConsolePlugin console;
|
||||
@Getter @Setter private LoggerPlugin logger; // in ConsolePlugin
|
||||
@Getter private final ChatPlugin chat;
|
||||
|
@ -50,14 +47,14 @@ public class Bot {
|
|||
this.allBots = allBots;
|
||||
this.config = config;
|
||||
|
||||
chat = new ChatPlugin(this);
|
||||
selfCare = new SelfCarePlugin(this);
|
||||
position = new PositionPlugin(this);
|
||||
core = new CorePlugin(this);
|
||||
commandHandler = new CommandHandlerPlugin();
|
||||
chatCommandHandler = new ChatCommandHandlerPlugin(this);
|
||||
hashing = new HashingPlugin(this);
|
||||
music = new MusicPlayerPlugin(this);
|
||||
this.chat = new ChatPlugin(this);
|
||||
this.selfCare = new SelfCarePlugin(this);
|
||||
this.position = new PositionPlugin(this);
|
||||
this.core = new CorePlugin(this);
|
||||
this.commandHandler = new CommandHandlerPlugin();
|
||||
this.chatCommandHandler = new ChatCommandHandlerPlugin(this);
|
||||
this.hashing = new HashingPlugin(this);
|
||||
this.music = new MusicPlayerPlugin(this);
|
||||
|
||||
reconnect();
|
||||
}
|
||||
|
@ -121,9 +118,13 @@ public class Bot {
|
|||
|
||||
if (reconnectDelay < 0) return; // to disable reconnecting
|
||||
|
||||
Runnable task = () -> reconnect();
|
||||
|
||||
executor.schedule(task, reconnectDelay, TimeUnit.MILLISECONDS);
|
||||
final Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
reconnect();
|
||||
}
|
||||
}, reconnectDelay, 1);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -18,11 +18,7 @@ import com.nukkitx.math.vector.Vector3i;
|
|||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.*;
|
||||
|
||||
public class CorePlugin extends PositionPlugin.PositionListener {
|
||||
private final Bot bot;
|
||||
|
@ -107,7 +103,14 @@ public class CorePlugin extends PositionPlugin.PositionListener {
|
|||
|
||||
if (!ready) {
|
||||
ready = true;
|
||||
bot.executor().schedule(this::refill, bot.config().core().refillInterval(), TimeUnit.MILLISECONDS);
|
||||
|
||||
final Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
refill();
|
||||
}
|
||||
}, 1, bot.config().core().refillInterval());
|
||||
for (Listener listener : listeners) listener.ready();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package me.chayapak1.chomensbot_mabe.plugins;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import lombok.Getter;
|
||||
import me.chayapak1.chomensbot_mabe.Bot;
|
||||
import me.chayapak1.chomensbot_mabe.util.Hexadecimal;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class HashingPlugin {
|
||||
private final Bot bot;
|
||||
|
@ -18,28 +17,27 @@ public class HashingPlugin {
|
|||
public HashingPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.executor().scheduleAtFixedRate(this::update, 1000 * 2, 500, TimeUnit.MILLISECONDS);
|
||||
final Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
update();
|
||||
}
|
||||
}, 1, 1000);
|
||||
}
|
||||
|
||||
public void update () {
|
||||
final String normalHashKey = bot.config().keys().get("normalKey");
|
||||
final String ownerHashKey = bot.config().keys().get("ownerKey");
|
||||
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
String time = String.valueOf(System.currentTimeMillis() / 10000);
|
||||
final String hashValue = (System.currentTimeMillis() / 10_000) + normalHashKey;
|
||||
hash = Hashing.sha256()
|
||||
.hashString(hashValue, StandardCharsets.UTF_8)
|
||||
.toString().substring(0, 16);
|
||||
|
||||
// messy
|
||||
String normalHashInput = time + normalHashKey;
|
||||
byte[] normalHashByteHash = md.digest(normalHashInput.getBytes(StandardCharsets.UTF_8));
|
||||
hash = Hexadecimal.encode(normalHashByteHash).substring(0, 16);
|
||||
|
||||
String ownerHashInput = time + ownerHashKey;
|
||||
byte[] ownerHashByteHash = md.digest(ownerHashInput.getBytes(StandardCharsets.UTF_8));
|
||||
ownerHash = Hexadecimal.encode(ownerHashByteHash).substring(0, 16);
|
||||
|
||||
bot.logger().log("normal hash input " + normalHashInput + " owner " + ownerHashInput);
|
||||
bot.logger().log(hash + " " + ownerHash);
|
||||
} catch (NoSuchAlgorithmException ignored) {}
|
||||
final String ownerHashValue = (System.currentTimeMillis() / 10_000) + ownerHashKey;
|
||||
ownerHash = Hashing.sha256()
|
||||
.hashString(ownerHashValue, StandardCharsets.UTF_8)
|
||||
.toString().substring(0, 16);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ import java.net.URL;
|
|||
import java.nio.file.Path;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class MusicPlayerPlugin extends SessionAdapter {
|
||||
private final Bot bot;
|
||||
|
||||
private ScheduledFuture<?> futurePlayTask;
|
||||
private TimerTask playTask;
|
||||
|
||||
public static final String SELECTOR = "@a[tag=!nomusic,tag=!chomens_bot_nomusic]";
|
||||
public static File SONG_DIR = new File("songs");
|
||||
|
@ -85,7 +85,9 @@ public class MusicPlayerPlugin extends SessionAdapter {
|
|||
}
|
||||
|
||||
public void coreReady () {
|
||||
final Runnable playTask = () -> {
|
||||
playTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (loaderThread != null && !loaderThread.isAlive()) {
|
||||
if (loaderThread.exception != null) {
|
||||
bot.chat().tellraw(Component.translatable("Failed to load song: %s", loaderThread.exception.message()).color(NamedTextColor.RED));
|
||||
|
@ -145,9 +147,11 @@ public class MusicPlayerPlugin extends SessionAdapter {
|
|||
currentSong.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
futurePlayTask = bot.executor().scheduleAtFixedRate(playTask, 50, 50, TimeUnit.MILLISECONDS);
|
||||
final Timer timer = new Timer();
|
||||
timer.schedule(playTask, 1, 50);
|
||||
|
||||
if (currentSong != null) currentSong.play();
|
||||
}
|
||||
|
@ -220,7 +224,7 @@ public class MusicPlayerPlugin extends SessionAdapter {
|
|||
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
futurePlayTask.cancel(false);
|
||||
playTask.cancel();
|
||||
|
||||
if (currentSong != null) currentSong.pause(); // nice.
|
||||
}
|
||||
|
|
|
@ -22,13 +22,13 @@ import me.chayapak1.chomensbot_mabe.Bot;
|
|||
import me.chayapak1.chomensbot_mabe.Configuration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class SelfCarePlugin extends SessionAdapter {
|
||||
private final Bot bot;
|
||||
|
||||
private ScheduledFuture<?> futureTask;
|
||||
private TimerTask checkTask;
|
||||
|
||||
@Getter @Setter boolean visibility = false;
|
||||
|
||||
|
@ -108,7 +108,9 @@ public class SelfCarePlugin extends SessionAdapter {
|
|||
muted = false;
|
||||
prefix = false;
|
||||
|
||||
final Runnable task = () -> {
|
||||
checkTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Session session = bot.session();
|
||||
final PacketProtocol protocol = session.getPacketProtocol();
|
||||
if (
|
||||
|
@ -120,9 +122,11 @@ public class SelfCarePlugin extends SessionAdapter {
|
|||
) return;
|
||||
|
||||
check();
|
||||
}
|
||||
};
|
||||
|
||||
futureTask = bot.executor().scheduleAtFixedRate(task, bot.config().selfCare().checkInterval(), 500, TimeUnit.MILLISECONDS);
|
||||
final Timer timer = new Timer();
|
||||
timer.schedule(checkTask, 1, bot.config().selfCare().checkInterval());
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundGameEventPacket packet) {
|
||||
|
@ -152,6 +156,6 @@ public class SelfCarePlugin extends SessionAdapter {
|
|||
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
futureTask.cancel(true);
|
||||
checkTask.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package me.chayapak1.chomensbot_mabe.util;
|
||||
|
||||
public interface Hexadecimal {
|
||||
static String encode (byte b) {
|
||||
return "" + Character.forDigit((b >> 4) & 0xF, 16) + Character.forDigit((b & 0xF), 16);
|
||||
}
|
||||
|
||||
static String encode (byte[] array) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < array.length; i++) sb.append(encode(array[i]));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// TODO: Decode
|
||||
}
|
||||
|
Loading…
Reference in a new issue