tag self care?
This commit is contained in:
parent
b0bc44ce7f
commit
23966e0eb2
2 changed files with 52 additions and 7 deletions
|
@ -115,8 +115,8 @@ public class MailCommand extends Command {
|
||||||
final List<Component> children = output.children();
|
final List<Component> children = output.children();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
children.size() > 0 &&
|
!children.isEmpty() &&
|
||||||
children.get(0).children().size() > 0 &&
|
!children.get(0).children().isEmpty() &&
|
||||||
((TranslatableComponent) children.get(0).children().get(0))
|
((TranslatableComponent) children.get(0).children().get(0))
|
||||||
.key()
|
.key()
|
||||||
.equals("arguments.nbtpath.nothing_found")
|
.equals("arguments.nbtpath.nothing_found")
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||||
|
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||||
import land.chipmunk.chayapak.chomens_bot.util.UUIDUtilities;
|
import land.chipmunk.chayapak.chomens_bot.util.UUIDUtilities;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TranslatableComponent;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
// TODO: self care
|
// TODO: self care
|
||||||
public class TagPlugin extends CorePlugin.Listener {
|
public class TagPlugin extends CorePlugin.Listener {
|
||||||
|
@ -12,13 +22,48 @@ public class TagPlugin extends CorePlugin.Listener {
|
||||||
public TagPlugin (Bot bot) {
|
public TagPlugin (Bot bot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
|
|
||||||
bot.core.addListener(this);
|
// tracked core is meant to be a standby core so ill use 30 seconds for this
|
||||||
|
bot.executor.scheduleAtFixedRate(this::checkAndAdd, 5, 30, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void checkAndAdd () {
|
||||||
public void ready () { // might not be the best idea but whatever
|
final String botSelector = UUIDUtilities.selector(bot.profile.getId());
|
||||||
final String command = "minecraft:tag " + UUIDUtilities.selector(bot.profile.getId()) + " add " + tag;
|
|
||||||
|
|
||||||
bot.core.run(command);
|
final CompletableFuture<CompoundTag> future = bot.core.runTracked("minecraft:data get entity " + botSelector + " Tags");
|
||||||
|
|
||||||
|
if (future == null) return;
|
||||||
|
|
||||||
|
future.thenApply((tags) -> {
|
||||||
|
if (!tags.contains("LastOutput") || !(tags.get("LastOutput") instanceof StringTag)) return tags;
|
||||||
|
|
||||||
|
final StringTag lastOutput = tags.get("LastOutput");
|
||||||
|
|
||||||
|
final Component output = GsonComponentSerializer.gson().deserialize(lastOutput.getValue());
|
||||||
|
|
||||||
|
final List<Component> children = output.children();
|
||||||
|
|
||||||
|
if (
|
||||||
|
!children.isEmpty() &&
|
||||||
|
!children.get(0).children().isEmpty() &&
|
||||||
|
((TranslatableComponent) children.get(0).children().get(0))
|
||||||
|
.key()
|
||||||
|
.equals("arguments.nbtpath.nothing_found")
|
||||||
|
) {
|
||||||
|
runCommand();
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String value = ComponentUtilities.stringify(((TranslatableComponent) children.get(0)).args().get(1));
|
||||||
|
|
||||||
|
if (!value.contains("\"" + tag + "\"")) runCommand();
|
||||||
|
|
||||||
|
return tags;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runCommand () {
|
||||||
|
final String botSelector = UUIDUtilities.selector(bot.profile.getId());
|
||||||
|
|
||||||
|
bot.core.run("minecraft:tag " + botSelector + " add " + tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue