9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-28 19:39:22 +00:00

feat: try to impl custom

This commit is contained in:
MC_XiaoHei
2025-09-24 23:33:31 +08:00
parent d89a099a0d
commit b658777341
35 changed files with 284 additions and 52 deletions

View File

@@ -0,0 +1,57 @@
package org.leavesmc.leaves.command;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.RedirectModifier;
import com.mojang.brigadier.context.ParsedCommandNode;
import com.mojang.brigadier.context.StringRange;
import com.mojang.brigadier.tree.CommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface LeavesCommandContext {
com.mojang.brigadier.context.CommandContext<CommandSourceStack> getChild();
com.mojang.brigadier.context.CommandContext<CommandSourceStack> getLastChild();
Command<CommandSourceStack> getCommand();
CommandSourceStack getSource();
CommandSender getSender();
<V> @NotNull V getArgument(final String name, final Class<V> clazz);
int getInteger(final String name);
boolean getBoolean(final String name);
String getString(final String name);
<V> V getArgumentOrDefault(final String name, final Class<V> clazz, final V defaultValue);
String getStringOrDefault(final String name, final String defaultValue);
int getIntegerOrDefault(final String name, final int defaultValue);
float getFloatOrDefault(final String name, final float defaultValue);
RedirectModifier<CommandSourceStack> getRedirectModifier();
StringRange getRange();
String getInput();
CommandNode<CommandSourceStack> getRootNode();
List<ParsedCommandNode<CommandSourceStack>> getNodes();
boolean hasNodes();
boolean isForked();
com.mojang.brigadier.context.CommandContext<CommandSourceStack> rawContext();
}

View File

@@ -0,0 +1,35 @@
package org.leavesmc.leaves.command;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.util.concurrent.CompletableFuture;
@SuppressWarnings("unused")
public interface LeavesWrappedArgument<T> {
LeavesWrappedArgument<T> suggestsAsync(AsyncSuggestionProvider provider);
LeavesWrappedArgument<T> suggests(SuggestionApplier provider);
LeavesWrappedArgument<T> setOptional(boolean optional);
boolean isOptional();
@FunctionalInterface
interface SuggestionApplier {
void applySuggestions(final LeavesCommandContext context, final SuggestionsBuilder builder) throws CommandSyntaxException;
}
@FunctionalInterface
interface AsyncSuggestionProvider {
CompletableFuture<Suggestions> getSuggestions(final LeavesCommandContext context, final SuggestionsBuilder builder) throws CommandSyntaxException;
}
interface ArgumentHandler {
<T> LeavesWrappedArgument<T> create(String name, com.mojang.brigadier.arguments.ArgumentType<T> type);
void fork(int forkId);
}
}

View File

@@ -4,6 +4,7 @@ import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.entity.bot.action.BotAction;
import org.leavesmc.leaves.entity.bot.action.CustomBotAction;
import java.util.Collection;
import java.util.UUID;
@@ -45,4 +46,8 @@ public interface BotManager {
<T extends BotAction<T>> T newAction(@NotNull Class<T> type);
BotCreator botCreator(@NotNull String realName, @NotNull Location location);
boolean registerCustomAction(@NotNull CustomBotAction customBotAction, boolean resendCommandTree);
boolean registerCustomAction(@NotNull CustomBotAction customBotAction);
}

View File

@@ -0,0 +1,51 @@
package org.leavesmc.leaves.entity.bot.action;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.command.LeavesWrappedArgument;
import org.leavesmc.leaves.entity.bot.Bot;
import org.leavesmc.leaves.util.ExtraData;
@SuppressWarnings("unused")
public abstract class CustomBotAction {
private LeavesWrappedArgument.ArgumentHandler factory;
public abstract boolean doTick(@NotNull Bot bot);
public abstract String getName();
public void init() {
}
public void loadCommand(CommandContext<CommandSourceStack> context) {
}
public void provideActionData(@NotNull ExtraData data) {
}
public void provideArgumentFactory(LeavesWrappedArgument.ArgumentHandler factory) {
this.factory = factory;
}
protected <T> LeavesWrappedArgument<T> addArgument(String name, ArgumentType<T> type) {
if (factory == null) {
throw new IllegalStateException("Argument factory not provided! Are you calling addArgument() outside of init() method?");
}
return factory.create(name, type);
}
protected void fork(int forkId) {
if (factory == null) {
throw new IllegalStateException("Argument factory not provided! Are you calling fork() outside of init() method?");
}
factory.fork(forkId);
}
@ApiStatus.Internal
public interface InternalCustomBotAction extends BotAction<InternalCustomBotAction> {
}
}

View File

@@ -1,4 +1,4 @@
package org.leavesmc.leaves.bot.agent;
package org.leavesmc.leaves.util;
import org.apache.commons.lang3.tuple.Pair;

View File

@@ -38,6 +38,10 @@ public class Actions {
register(new ServerSwapAction(), SwapAction.class);
}
public static boolean register(@NotNull CustomBotAction customBotAction) {
return register(new ServerCustomBotAction(customBotAction), customBotAction.getClass());
}
public static boolean register(@NotNull AbstractBotAction<?> action, Class<?> type) {
if (!actionsByName.containsKey(action.getName())) {
actionsByName.put(action.getName(), action);

View File

@@ -8,8 +8,8 @@ import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesLogger;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.ExtraData;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.util.ExtraData;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.WrappedArgument;
import org.leavesmc.leaves.event.bot.BotActionExecuteEvent;
import org.leavesmc.leaves.event.bot.BotActionStopEvent;
@@ -181,7 +181,7 @@ public abstract class AbstractBotAction<E extends AbstractBotAction<E>> {
}
@SuppressWarnings("RedundantThrows")
public void loadCommand(@NotNull CommandContext context) throws CommandSyntaxException {
public void loadCommand(@NotNull LeavesCommandContext context) throws CommandSyntaxException {
}
@NotNull

View File

@@ -2,8 +2,8 @@ package org.leavesmc.leaves.bot.agent.actions;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.agent.ExtraData;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.util.ExtraData;
import org.leavesmc.leaves.command.LeavesCommandContext;
import java.util.function.Supplier;
@@ -22,7 +22,7 @@ public abstract class AbstractTimerBotAction<E extends AbstractTimerBotAction<E>
}
@Override
public void loadCommand(@NotNull CommandContext context) {
public void loadCommand(@NotNull LeavesCommandContext context) {
this.setStartDelayTick(context.getIntegerOrDefault("delay", 0));
this.setDoIntervalTick(context.getIntegerOrDefault("interval", 20));
this.setDoNumber(context.getIntegerOrDefault("do_number", 1));

View File

@@ -5,8 +5,8 @@ import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionResult;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.ExtraData;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.util.ExtraData;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.event.bot.BotActionStopEvent;
import java.util.function.Supplier;
@@ -30,7 +30,7 @@ public abstract class AbstractUseBotAction<T extends AbstractUseBotAction<T>> ex
}
@Override
public void loadCommand(@NotNull CommandContext context) {
public void loadCommand(@NotNull LeavesCommandContext context) {
super.loadCommand(context);
this.useTickTimeout = context.getIntegerOrDefault("use_timeout", -1);
}

View File

@@ -0,0 +1,54 @@
package org.leavesmc.leaves.bot.agent.actions;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.command.LeavesWrappedArgument;
import org.leavesmc.leaves.util.ExtraData;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.entity.bot.action.CustomBotAction;
import org.leavesmc.leaves.entity.bot.actions.CraftCustomBotAction;
public class ServerCustomBotAction extends AbstractBotAction<ServerCustomBotAction> {
private final CustomBotAction customBotAction;
public ServerCustomBotAction(@NotNull CustomBotAction customBotAction) {
super(customBotAction.getName(), () -> new ServerCustomBotAction(customBotAction));
this.customBotAction = customBotAction;
customBotAction.provideArgumentFactory(new LeavesWrappedArgument.ArgumentHandler() {
@Override
public <T> LeavesWrappedArgument<T> create(String name, ArgumentType<T> type) {
return addArgument(name, type);
}
@Override
public void fork(int forkId) {
ServerCustomBotAction.this.fork(forkId);
}
});
customBotAction.init();
}
@Override
public String getActionDataString(@NotNull ExtraData data) {
customBotAction.provideActionData(data);
return super.getActionDataString(data);
}
@Override
public void loadCommand(@NotNull LeavesCommandContext context) throws CommandSyntaxException {
super.loadCommand(context);
customBotAction.loadCommand(context.rawContext());
}
@Override
public boolean doTick(@NotNull ServerBot bot) {
return customBotAction.doTick(bot.getBukkitEntity());
}
@Override
public Object asCraft() {
return new CraftCustomBotAction(this);
}
}

View File

@@ -13,7 +13,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.entity.bot.actions.CraftLookAction;
public class ServerLookAction extends AbstractBotAction<ServerLookAction> {
@@ -31,7 +31,7 @@ public class ServerLookAction extends AbstractBotAction<ServerLookAction> {
}
@Override
public void loadCommand(@NotNull CommandContext context) throws CommandSyntaxException {
public void loadCommand(@NotNull LeavesCommandContext context) throws CommandSyntaxException {
PlayerSelectorArgumentResolver playerSelectorResolver = context.getArgumentOrDefault("player", PlayerSelectorArgumentResolver.class, null);
FinePositionResolver positionResolver = context.getArgumentOrDefault("location", FinePositionResolver.class, null);
CommandSourceStack source = context.getSource();

View File

@@ -2,8 +2,8 @@ package org.leavesmc.leaves.bot.agent.actions;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.ExtraData;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.util.ExtraData;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.arguments.EnumArgumentType;
import org.leavesmc.leaves.entity.bot.action.MoveAction.MoveDirection;
import org.leavesmc.leaves.entity.bot.actions.CraftMoveAction;
@@ -18,7 +18,7 @@ public class ServerMoveAction extends AbstractStateBotAction<ServerMoveAction> {
}
@Override
public void loadCommand(@NotNull CommandContext context) {
public void loadCommand(@NotNull LeavesCommandContext context) {
this.direction = context.getArgument("direction", MoveDirection.class);
}

View File

@@ -7,8 +7,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.ExtraData;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.util.ExtraData;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.entity.bot.actions.CraftRotationAction;
import java.text.DecimalFormat;
@@ -47,7 +47,7 @@ public class ServerRotationAction extends AbstractBotAction<ServerRotationAction
private float pitch = 0.0f;
@Override
public void loadCommand(@NotNull CommandContext context) {
public void loadCommand(@NotNull LeavesCommandContext context) {
CommandSender sender = context.getSender();
if (sender instanceof Entity entity) {
this.yaw = entity.getYaw();

View File

@@ -9,8 +9,8 @@ import net.kyori.adventure.text.format.NamedTextColor;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.ExtraData;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.util.ExtraData;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.WrappedArgument;
import java.lang.reflect.Method;
@@ -34,7 +34,7 @@ public abstract class AbstractBotConfig<T, E extends AbstractBotConfig<T, E>> {
}
@SuppressWarnings("RedundantThrows")
public void applySuggestions(final CommandContext context, final SuggestionsBuilder builder) throws CommandSyntaxException {
public void applySuggestions(final LeavesCommandContext context, final SuggestionsBuilder builder) throws CommandSyntaxException {
}
public AbstractBotConfig<T, E> setBot(ServerBot bot) {
@@ -50,7 +50,7 @@ public abstract class AbstractBotConfig<T, E extends AbstractBotConfig<T, E>> {
public abstract void setValue(T value) throws CommandSyntaxException;
public abstract T loadFromCommand(@NotNull CommandContext context) throws CommandSyntaxException;
public abstract T loadFromCommand(@NotNull LeavesCommandContext context) throws CommandSyntaxException;
public String getName() {
return name;

View File

@@ -4,7 +4,7 @@ import com.mojang.brigadier.arguments.BoolArgumentType;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
public class AlwaysSendDataConfig extends AbstractBotConfig<Boolean, AlwaysSendDataConfig> {
private boolean value;
@@ -25,7 +25,7 @@ public class AlwaysSendDataConfig extends AbstractBotConfig<Boolean, AlwaysSendD
}
@Override
public Boolean loadFromCommand(@NotNull CommandContext context) {
public Boolean loadFromCommand(@NotNull LeavesCommandContext context) {
return context.getBoolean(getName());
}

View File

@@ -5,7 +5,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.waypoints.ServerWaypointManager;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
public class LocatorBarConfig extends AbstractBotConfig<Boolean, LocatorBarConfig> {
private boolean value;
@@ -32,7 +32,7 @@ public class LocatorBarConfig extends AbstractBotConfig<Boolean, LocatorBarConfi
}
@Override
public Boolean loadFromCommand(@NotNull CommandContext context) {
public Boolean loadFromCommand(@NotNull LeavesCommandContext context) {
return context.getBoolean(getName());
}

View File

@@ -5,7 +5,7 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import static net.minecraft.network.chat.Component.literal;
@@ -16,7 +16,7 @@ public class SimulationDistanceConfig extends AbstractBotConfig<Integer, Simulat
}
@Override
public void applySuggestions(CommandContext context, @NotNull SuggestionsBuilder builder) {
public void applySuggestions(LeavesCommandContext context, @NotNull SuggestionsBuilder builder) {
builder.suggest("2", literal("Minimum simulation distance"));
builder.suggest("8");
builder.suggest("12");
@@ -35,7 +35,7 @@ public class SimulationDistanceConfig extends AbstractBotConfig<Integer, Simulat
}
@Override
public Integer loadFromCommand(@NotNull CommandContext context) {
public Integer loadFromCommand(@NotNull LeavesCommandContext context) {
return context.getInteger(getName());
}

View File

@@ -4,7 +4,7 @@ import com.mojang.brigadier.arguments.BoolArgumentType;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
public class SkipSleepConfig extends AbstractBotConfig<Boolean, SkipSleepConfig> {
@@ -23,7 +23,7 @@ public class SkipSleepConfig extends AbstractBotConfig<Boolean, SkipSleepConfig>
}
@Override
public Boolean loadFromCommand(@NotNull CommandContext context) {
public Boolean loadFromCommand(@NotNull LeavesCommandContext context) {
return context.getBoolean(getName());
}

View File

@@ -4,8 +4,8 @@ import com.mojang.brigadier.arguments.BoolArgumentType;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.bot.agent.ExtraData;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.util.ExtraData;
import org.leavesmc.leaves.command.LeavesCommandContext;
public class SpawnPhantomConfig extends AbstractBotConfig<Boolean, SpawnPhantomConfig> {
private boolean value;
@@ -32,7 +32,7 @@ public class SpawnPhantomConfig extends AbstractBotConfig<Boolean, SpawnPhantomC
}
@Override
public Boolean loadFromCommand(@NotNull CommandContext context) {
public Boolean loadFromCommand(@NotNull LeavesCommandContext context) {
return context.getBoolean(getName());
}

View File

@@ -4,7 +4,7 @@ import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.arguments.EnumArgumentType;
public class TickTypeConfig extends AbstractBotConfig<ServerBot.TickType, TickTypeConfig> {
@@ -16,7 +16,7 @@ public class TickTypeConfig extends AbstractBotConfig<ServerBot.TickType, TickTy
}
@Override
public ServerBot.TickType loadFromCommand(@NotNull CommandContext context) {
public ServerBot.TickType loadFromCommand(@NotNull LeavesCommandContext context) {
return context.getArgument("tick_type", ServerBot.TickType.class);
}

View File

@@ -14,7 +14,7 @@ import java.util.List;
import static org.leavesmc.leaves.command.CommandNode.getNameForNode;
@SuppressWarnings({"ClassCanBeRecord", "unused"})
public class CommandContext {
public class CommandContext implements LeavesCommandContext {
private final com.mojang.brigadier.context.CommandContext<CommandSourceStack> source;
public CommandContext(com.mojang.brigadier.context.CommandContext<CommandSourceStack> source) {
@@ -119,7 +119,7 @@ public class CommandContext {
return source.isForked();
}
public com.mojang.brigadier.context.CommandContext<CommandSourceStack> getMojangContext() {
public com.mojang.brigadier.context.CommandContext<CommandSourceStack> rawContext() {
return source;
}
}

View File

@@ -2,15 +2,12 @@ package org.leavesmc.leaves.command;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import java.util.concurrent.CompletableFuture;
public class WrappedArgument<T> {
public class WrappedArgument<T> implements LeavesWrappedArgument<T> {
private final String name;
private final ArgumentType<T> type;
private AsyncSuggestionProvider asyncSuggestionProvider = null;
@@ -55,14 +52,4 @@ public class WrappedArgument<T> {
}
return builder;
}
@FunctionalInterface
public interface SuggestionApplier {
void applySuggestions(final CommandContext context, final SuggestionsBuilder builder) throws CommandSyntaxException;
}
@FunctionalInterface
public interface AsyncSuggestionProvider {
CompletableFuture<Suggestions> getSuggestions(final CommandContext context, final SuggestionsBuilder builder) throws CommandSyntaxException;
}
}

View File

@@ -6,6 +6,7 @@ import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.arguments.BotArgumentType;
import org.leavesmc.leaves.command.bot.BotSubcommand;
import org.leavesmc.leaves.command.bot.subcommands.action.ListCommand;

View File

@@ -19,6 +19,7 @@ import org.leavesmc.leaves.bot.BotCreateState;
import org.leavesmc.leaves.bot.BotList;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.bot.BotSubcommand;
import org.leavesmc.leaves.event.bot.BotCreateEvent;

View File

@@ -16,6 +16,7 @@ import org.leavesmc.leaves.bot.BotList;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.bot.BotSubcommand;
import java.util.List;

View File

@@ -13,6 +13,7 @@ import org.leavesmc.leaves.bot.BotList;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.bot.BotSubcommand;
import java.util.Set;

View File

@@ -9,6 +9,7 @@ import org.leavesmc.leaves.bot.BotList;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.arguments.BotArgumentType;
import org.leavesmc.leaves.command.bot.BotSubcommand;
import org.leavesmc.leaves.event.bot.BotRemoveEvent;

View File

@@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.actions.AbstractBotAction;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.LiteralNode;
import org.leavesmc.leaves.command.bot.subcommands.ActionCommand;

View File

@@ -12,6 +12,7 @@ import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.Actions;
import org.leavesmc.leaves.bot.agent.actions.AbstractBotAction;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.LiteralNode;
import org.leavesmc.leaves.command.WrappedArgument;

View File

@@ -11,6 +11,7 @@ import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.actions.AbstractBotAction;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LiteralNode;
import org.leavesmc.leaves.command.bot.subcommands.ActionCommand;
import org.leavesmc.leaves.event.bot.BotActionStopEvent;

View File

@@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.LiteralNode;
import org.leavesmc.leaves.command.leaves.LeavesSubcommand;

View File

@@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.CommandUtils;
import org.leavesmc.leaves.command.leaves.LeavesSubcommand;
import org.leavesmc.leaves.config.GlobalConfigManager;

View File

@@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.LeavesCommandContext;
import org.leavesmc.leaves.command.leaves.LeavesSubcommand;
import static net.kyori.adventure.text.Component.text;

View File

@@ -2,7 +2,9 @@ package org.leavesmc.leaves.entity.bot;
import com.google.common.collect.Lists;
import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.bot.BotCreateState;
@@ -11,6 +13,7 @@ import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.Actions;
import org.leavesmc.leaves.bot.agent.actions.AbstractBotAction;
import org.leavesmc.leaves.entity.bot.action.BotAction;
import org.leavesmc.leaves.entity.bot.action.CustomBotAction;
import org.leavesmc.leaves.event.bot.BotCreateEvent;
import java.util.Collection;
@@ -71,4 +74,18 @@ public class CraftBotManager implements BotManager {
public BotCreator botCreator(@NotNull String realName, @NotNull Location location) {
return BotCreateState.builder(realName, location).createReason(BotCreateEvent.CreateReason.PLUGIN);
}
@Override
public boolean registerCustomAction(@NotNull CustomBotAction customBotAction, boolean resendCommandTree) {
boolean result = Actions.register(customBotAction);
if (result && resendCommandTree) {
Bukkit.getOnlinePlayers().forEach(Player::updateCommands);
}
return result;
}
@Override
public boolean registerCustomAction(@NotNull CustomBotAction customBotAction) {
return registerCustomAction(customBotAction, true);
}
}

View File

@@ -0,0 +1,11 @@
package org.leavesmc.leaves.entity.bot.actions;
import org.leavesmc.leaves.bot.agent.actions.ServerCustomBotAction;
import org.leavesmc.leaves.entity.bot.action.CustomBotAction;
public class CraftCustomBotAction extends CraftBotAction<CustomBotAction.InternalCustomBotAction, ServerCustomBotAction> implements CustomBotAction.InternalCustomBotAction {
public CraftCustomBotAction(ServerCustomBotAction serverAction) {
super(serverAction, CraftCustomBotAction::new);
}
}