forked from ChomeNS/chomens-bot-java
i am not sure if this works
This commit is contained in:
parent
b8b6f99d7e
commit
44410bfcbf
3 changed files with 55 additions and 56 deletions
|
@ -19,7 +19,6 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
// TODO: players can make the bossbar with the same exact component and fard the bossbar manager so mabe fix it
|
||||
// yes this has been rewritten to be not spammy
|
||||
public class BossbarManagerPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
|||
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.BlockChangeEntry;
|
||||
import com.github.steveice10.mc.protocol.data.game.level.block.CommandBlockMode;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCommandsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundBlockUpdatePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLevelChunkWithLightPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundSectionBlocksUpdatePacket;
|
||||
|
@ -55,6 +56,8 @@ public class CorePlugin extends PositionPlugin.Listener {
|
|||
|
||||
private final boolean kaboom;
|
||||
|
||||
@Getter private final List<String> queue = new ArrayList<>();
|
||||
|
||||
public CorePlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
this.kaboom = bot.options().kaboom();
|
||||
|
@ -74,6 +77,15 @@ public class CorePlugin extends PositionPlugin.Listener {
|
|||
|
||||
bot.position().addListener(this);
|
||||
|
||||
bot.tick().addListener(new TickPlugin.Listener() {
|
||||
@Override
|
||||
public void onTick() {
|
||||
CorePlugin.this.onTick();
|
||||
}
|
||||
});
|
||||
|
||||
bot.executor().scheduleAtFixedRate(() -> commandsPerSecond = 0, 0, 1, TimeUnit.SECONDS);
|
||||
|
||||
bot.addListener(new Bot.Listener() {
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
|
@ -94,10 +106,17 @@ public class CorePlugin extends PositionPlugin.Listener {
|
|||
});
|
||||
}
|
||||
|
||||
public void run (String command) {
|
||||
if (!ready) return;
|
||||
private int commandsPerSecond = 0;
|
||||
|
||||
if (bot.options().useCore()) {
|
||||
private void onTick () {
|
||||
if (queue.isEmpty()) return;
|
||||
|
||||
forceRun(queue.get(0));
|
||||
|
||||
queue.remove(0);
|
||||
}
|
||||
|
||||
private void forceRun (String command) {
|
||||
bot.session().send(new ServerboundSetCommandBlockPacket(
|
||||
absoluteCorePosition(),
|
||||
command,
|
||||
|
@ -108,6 +127,14 @@ public class CorePlugin extends PositionPlugin.Listener {
|
|||
));
|
||||
|
||||
incrementBlock();
|
||||
}
|
||||
|
||||
public void run (String command) {
|
||||
if (!ready) return;
|
||||
|
||||
if (bot.options().useCore()) {
|
||||
if (commandsPerSecond >= 100) queue.add(command);
|
||||
else forceRun(command);
|
||||
} else if (command.length() < 256) {
|
||||
bot.chat().send("/" + command);
|
||||
}
|
||||
|
|
|
@ -3,8 +3,11 @@ package land.chipmunk.chayapak.chomens_bot.util;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import land.chipmunk.chayapak.chomens_bot.Main;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PersistentDataUtilities {
|
||||
public static File file = new File("persistent.json");
|
||||
|
@ -13,6 +16,8 @@ public class PersistentDataUtilities {
|
|||
|
||||
public static JsonObject jsonObject = new JsonObject();
|
||||
|
||||
private static final ScheduledExecutorService executor = Main.executor;
|
||||
|
||||
static {
|
||||
init();
|
||||
}
|
||||
|
@ -35,75 +40,43 @@ public class PersistentDataUtilities {
|
|||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
executor.scheduleAtFixedRate(PersistentDataUtilities::write, 0, 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private static void write () {
|
||||
try {
|
||||
writer = new FileWriter(file, false);
|
||||
|
||||
writer.write(jsonObject.toString());
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void put (String property, JsonElement value) {
|
||||
if (jsonObject.has(property)) jsonObject.remove(property);
|
||||
jsonObject.add(property, value);
|
||||
|
||||
try {
|
||||
writer = new FileWriter(file, false);
|
||||
|
||||
writer.write(jsonObject.toString());
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void put (String property, String value) {
|
||||
if (jsonObject.has(property)) jsonObject.remove(property);
|
||||
jsonObject.addProperty(property, value);
|
||||
|
||||
try {
|
||||
writer = new FileWriter(file, false);
|
||||
|
||||
writer.write(jsonObject.toString());
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void put (String property, boolean value) {
|
||||
if (jsonObject.has(property)) jsonObject.remove(property);
|
||||
jsonObject.addProperty(property, value);
|
||||
|
||||
try {
|
||||
writer = new FileWriter(file, false);
|
||||
|
||||
writer.write(jsonObject.toString());
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void put (String property, int value) {
|
||||
if (jsonObject.has(property)) jsonObject.remove(property);
|
||||
jsonObject.addProperty(property, value);
|
||||
|
||||
try {
|
||||
writer = new FileWriter(file, false);
|
||||
|
||||
writer.write(jsonObject.toString());
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void put (String property, char value) {
|
||||
if (jsonObject.has(property)) jsonObject.remove(property);
|
||||
jsonObject.addProperty(property, value);
|
||||
|
||||
try {
|
||||
writer = new FileWriter(file, false);
|
||||
|
||||
writer.write(jsonObject.toString());
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue