Experimental support for disabling the core
This commit is contained in:
parent
7d3cafa578
commit
35f247ef29
5 changed files with 71 additions and 17 deletions
|
@ -14,19 +14,29 @@ import land.chipmunk.chipmunkbot.plugins.*;
|
|||
import java.util.List;
|
||||
|
||||
public class ChipmunkBot extends Client {
|
||||
@Getter public final ChatPlugin chat = new ChatPlugin(this);
|
||||
@Getter public final TabCompletePlugin tabComplete = new TabCompletePlugin(this);
|
||||
@Getter public final QueryPlugin query = new QueryPlugin(this);
|
||||
@Getter public final PlayerListPlugin playerList = new PlayerListPlugin(this);
|
||||
@Getter public final CommandManager commandManager = new CommandManager(this);
|
||||
@Getter public final ChatPlugin chat;
|
||||
@Getter public final TabCompletePlugin tabComplete;
|
||||
@Getter public final QueryPlugin query;
|
||||
@Getter public final PlayerListPlugin playerList;
|
||||
@Getter public final CommandManager commandManager;
|
||||
@Getter public final ChatCommandHandler chatCommandHandler;
|
||||
@Getter public final PositionManager position = new PositionManager(this);
|
||||
@Getter public final CommandCore core = new CommandCore(this);
|
||||
@Getter public final SelfCarePlugin selfCare = new SelfCarePlugin(this);
|
||||
@Getter public final SongPlayer songPlayer = new SongPlayer(this);
|
||||
@Getter public final PositionManager position;
|
||||
@Getter public final CommandCore core;
|
||||
@Getter public final SelfCarePlugin selfCare;
|
||||
@Getter public final SongPlayer songPlayer;
|
||||
|
||||
public ChipmunkBot (Options options, List<Client> allClients) {
|
||||
super(options.host, options.port, new MinecraftProtocol(options.username), null, options.reconnectDelay, allClients);
|
||||
chatCommandHandler = new ChatCommandHandler(this, options.commands);
|
||||
|
||||
this.chat = new ChatPlugin(this);
|
||||
this.tabComplete = new TabCompletePlugin(this);
|
||||
this.query = new QueryPlugin(this);
|
||||
this.playerList = new PlayerListPlugin(this);
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.chatCommandHandler = new ChatCommandHandler(this, options);
|
||||
this.position = new PositionManager(this);
|
||||
this.core = new CommandCore(this, options);
|
||||
this.selfCare = new SelfCarePlugin(this);
|
||||
this.songPlayer = new SongPlayer(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,13 @@ public class Options {
|
|||
|
||||
public Commands commands = new Commands();
|
||||
|
||||
public Core core = new Core();
|
||||
|
||||
public class Commands {
|
||||
public String prefix = "default.";
|
||||
}
|
||||
|
||||
public class Core {
|
||||
public boolean enabled = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@ public class ChatCommandHandler extends ChatPlugin.Listener {
|
|||
private ChipmunkBot client;
|
||||
@Getter @Setter private String prefix;
|
||||
|
||||
public ChatCommandHandler (ChipmunkBot client, Options.Commands options) {
|
||||
public ChatCommandHandler (ChipmunkBot client, Options options) {
|
||||
this.client = client;
|
||||
this.prefix = options.prefix;
|
||||
this.prefix = options.commands.prefix;
|
||||
client.chat().addListener((ChatPlugin.Listener) this);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package land.chipmunk.chipmunkbot.plugins;
|
||||
|
||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||
import land.chipmunk.chipmunkbot.Options;
|
||||
import land.chipmunk.chipmunkbot.plugins.PositionManager;
|
||||
import land.chipmunk.chipmunkbot.data.BlockArea;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
|
@ -34,6 +35,7 @@ import java.util.concurrent.CompletableFuture;
|
|||
|
||||
public class CommandCore extends SessionAdapter {
|
||||
private ChipmunkBot client;
|
||||
@Getter @Setter private boolean enabled = false;
|
||||
@Getter @Setter private boolean ready = false;
|
||||
@Getter @Setter private Vector3i origin;
|
||||
// TODO: Make it configurable
|
||||
|
@ -43,8 +45,9 @@ public class CommandCore extends SessionAdapter {
|
|||
|
||||
@Getter private List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
public CommandCore (ChipmunkBot client) {
|
||||
public CommandCore (ChipmunkBot client, Options options) {
|
||||
this.client = client;
|
||||
this.enabled = options.core.enabled;
|
||||
client.addListener((SessionListener) this);
|
||||
}
|
||||
|
||||
|
@ -56,9 +59,18 @@ public class CommandCore extends SessionAdapter {
|
|||
public void packetReceived (Session session, ClientboundPlayerPositionPacket packet) {
|
||||
if (!ready) {
|
||||
ready = true;
|
||||
|
||||
if (enabled) {
|
||||
final TimerTask refillTask = new TimerTask () { @Override public void run () { refill(); } };
|
||||
refillTimer = new Timer();
|
||||
refillTimer.schedule(refillTask, 60L * 1000L, 60L * 1000L);
|
||||
}
|
||||
|
||||
for (Listener listener : listeners) listener.ready();
|
||||
}
|
||||
|
||||
if (!enabled) return;
|
||||
|
||||
final Vector3i oldOrigin = origin;
|
||||
origin = Vector3i.from(
|
||||
((int) packet.getX() / 16) * 16,
|
||||
|
@ -68,10 +80,6 @@ public class CommandCore extends SessionAdapter {
|
|||
|
||||
if (currentBlockRelative == null) currentBlockRelative = Vector3i.from(relativeArea.start());
|
||||
if (!origin.equals(oldOrigin)) refill();
|
||||
|
||||
final TimerTask refillTask = new TimerTask () { @Override public void run () { refill(); } };
|
||||
refillTimer = new Timer();
|
||||
refillTimer.schedule(refillTask, 60L * 1000L, 60L * 1000L);
|
||||
}
|
||||
|
||||
public void refill () {
|
||||
|
@ -108,6 +116,11 @@ public class CommandCore extends SessionAdapter {
|
|||
session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.NORTH, Hand.OFF_HAND, 0.5f, 0.5f, 0.5f, false, 0));
|
||||
}
|
||||
|
||||
public int maxCommandLength () {
|
||||
if (!enabled) return 256;
|
||||
return 32767;
|
||||
}
|
||||
|
||||
public void incrementCurrentBlock () {
|
||||
final Vector3i start = relativeArea.start();
|
||||
final Vector3i end = relativeArea.end();
|
||||
|
@ -142,6 +155,13 @@ public class CommandCore extends SessionAdapter {
|
|||
}
|
||||
|
||||
public void run (String command) {
|
||||
if (command.length() > maxCommandLength()) return;
|
||||
|
||||
if (!enabled) {
|
||||
client.chat().command(command); // fall back to chat
|
||||
return;
|
||||
}
|
||||
|
||||
final Session session = client.session();
|
||||
final Vector3i currentBlock = currentBlockAbsolute();
|
||||
|
||||
|
@ -153,6 +173,14 @@ public class CommandCore extends SessionAdapter {
|
|||
}
|
||||
|
||||
public CompletableFuture<CompoundTag> runTracked (String command) {
|
||||
if (command.length() > maxCommandLength()) return emptyCompoundTagFuture();
|
||||
|
||||
if (!enabled) {
|
||||
client.chat().command(command); // fall back to chat
|
||||
|
||||
return emptyCompoundTagFuture();
|
||||
}
|
||||
|
||||
final Session session = client.session();
|
||||
final Vector3i currentBlock = currentBlockAbsolute();
|
||||
|
||||
|
@ -179,6 +207,12 @@ public class CommandCore extends SessionAdapter {
|
|||
return future;
|
||||
}
|
||||
|
||||
private CompletableFuture<CompoundTag> emptyCompoundTagFuture () {
|
||||
CompletableFuture<CompoundTag> future = new CompletableFuture<CompoundTag>();
|
||||
future.complete(new CompoundTag(""));
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
origin = null;
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
|
||||
"commands": {
|
||||
"prefix": "default."
|
||||
},
|
||||
|
||||
"core": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue