9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-29 20:09:23 +00:00

Some format

This commit is contained in:
violetc
2025-09-23 16:21:47 +08:00
parent b155a0568d
commit dd3af55495
27 changed files with 37 additions and 88 deletions

View File

@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Sat, 1 Feb 2025 14:21:06 +0800
Subject: [PATCH] Leaves Server Config And Command
Subject: [PATCH] Leaves Server Config
diff --git a/src/main/java/io/papermc/paper/SparksFly.java b/src/main/java/io/papermc/paper/SparksFly.java
@@ -18,7 +18,7 @@ index 62e2d5704c348955bc8284dc2d54c933b7bcdd06..7ef20f0138fad39a1d23edd7b26ddc88
public void executeAsync(final Runnable runnable) {
MCUtil.scheduleAsyncTask(this.catching(runnable, "asynchronous"));
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 32fe51b19323e3c4c56e7f9e621e6e808ee5fe38..2eba1d900b20a781c4bb08caa2b30bfeb2d02b9d 100644
index 1d12a870a2f239bf95df639ef350b38911558199..1e9a43814613b57483845cc4f66b9be4717b746f 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1076,6 +1076,7 @@ public final class CraftServer implements Server {

View File

@@ -16,7 +16,7 @@ public class Actions {
private static final Map<String, AbstractBotAction<?>> actionsByName = new HashMap<>();
private static final Map<Class<?>, AbstractBotAction<?>> actionsByClass = new HashMap<>();
static {
static {
register(new ServerAttackAction(), AttackAction.class);
register(new ServerBreakBlockAction(), BreakBlockAction.class);
register(new ServerDropAction(), DropAction.class);

View File

@@ -6,7 +6,6 @@ import net.minecraft.core.UUIDUtil;
import net.minecraft.nbt.CompoundTag;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.LeavesLogger;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.command.CommandContext;

View File

@@ -3,7 +3,6 @@ package org.leavesmc.leaves.bot.agent.actions;
import java.util.function.Supplier;
public abstract class AbstractStateBotAction<E extends AbstractStateBotAction<E>> extends AbstractBotAction<E> {
public AbstractStateBotAction(String name, Supplier<E> creator) {
super(name, creator);
this.setDoNumber(-1);

View File

@@ -13,12 +13,8 @@ public abstract class AbstractTimerBotAction<E extends AbstractTimerBotAction<E>
public AbstractTimerBotAction(String name, Supplier<E> creator) {
super(name, creator);
this.addArgument("delay", integer(0))
.suggests(strings("0", "5", "10", "20"))
.setOptional(true);
this.addArgument("interval", integer(0))
.suggests(strings("20", "0", "5", "10"))
.setOptional(true);
this.addArgument("delay", integer(0)).suggests(strings("0", "5", "10", "20")).setOptional(true);
this.addArgument("interval", integer(0)).suggests(strings("20", "0", "5", "10")).setOptional(true);
this.addArgument("do_number", integer(-1))
.suggests(((context, builder) -> builder.suggest("-1", Component.literal("do infinite times"))))
.setOptional(true);

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.event.bot.BotActionStopEvent;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.event.bot.BotActionStopEvent;
import java.util.function.Supplier;

View File

@@ -13,8 +13,8 @@ import net.minecraft.world.phys.Vec3;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.entity.bot.actions.CraftLookAction;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.entity.bot.actions.CraftLookAction;
public class ServerLookAction extends AbstractBotAction<ServerLookAction> {
@@ -25,17 +25,7 @@ public class ServerLookAction extends AbstractBotAction<ServerLookAction> {
public ServerLookAction() {
super("look", ServerLookAction::new);
declarePlayerBranch();
declareLocationBranch();
}
private void declarePlayerBranch() {
this.fork(0);
this.addArgument("player", EntityArgument.player())
.setOptional(true);
}
private void declareLocationBranch() {
this.addArgument("player", EntityArgument.player()).setOptional(true);
this.fork(1);
this.addArgument("location", Vec3Argument.vec3(false));
}

View File

@@ -3,12 +3,11 @@ package org.leavesmc.leaves.bot.agent.actions;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.entity.bot.action.MoveAction.MoveDirection;
import org.leavesmc.leaves.entity.bot.actions.CraftMoveAction;
import org.leavesmc.leaves.event.bot.BotActionStopEvent;
import org.leavesmc.leaves.command.CommandContext;
import java.util.Arrays;
import java.util.Map;
@@ -26,11 +25,7 @@ public class ServerMoveAction extends AbstractStateBotAction<ServerMoveAction> {
public ServerMoveAction() {
super("move", ServerMoveAction::new);
this.addArgument("direction", StringArgumentType.word())
.suggests(strings(
Arrays.stream(MoveDirection.values())
.map((it) -> it.name)
.toList()
));
.suggests(strings(Arrays.stream(MoveDirection.values()).map((it) -> it.name).toList()));
}
@Override

View File

@@ -6,8 +6,8 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.entity.bot.actions.CraftRotationAction;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.entity.bot.actions.CraftRotationAction;
import java.text.DecimalFormat;

View File

@@ -40,10 +40,7 @@ public class CommandUtils {
}
@DefaultQualifier(NonNull.class)
public static @NotNull List<String> getListClosestMatchingLast(
final String last,
final Collection<?> collection
) {
public static @NotNull List<String> getListClosestMatchingLast(final String last, final Collection<?> collection) {
if (collection.isEmpty()) {
return Collections.emptyList();
}
@@ -132,7 +129,6 @@ public class CommandUtils {
return H[s1Len + 1][s2Len + 1];
}
// Copy from org/bukkit/command/defaults/HelpCommand.java
private record Candidate(String item, int score) {
@Contract("_, _ -> new")
private static @NotNull Candidate of(String item, int score) {

View File

@@ -8,7 +8,6 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.util.concurrent.CompletableFuture;
public interface CustomArgumentType<T, B> {
ArgumentType<B> getBaseArgumentType();
T transform(B value) throws CommandSyntaxException;

View File

@@ -5,7 +5,6 @@ import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.command.LiteralNode;
public abstract class BotSubcommand extends LiteralNode {
protected BotSubcommand(String name) {
super(name);
}

View File

@@ -42,9 +42,7 @@ public class ConfigCommand extends BotSubcommand {
private BotArgument() {
super("bot", new org.leavesmc.leaves.command.bot.BotArgument());
Configs.getConfigs().stream()
.map(this::configNodeCreator)
.forEach(this::children);
Configs.getConfigs().stream().map(this::configNodeCreator).forEach(this::children);
}
@Contract(pure = true)
@@ -93,8 +91,7 @@ public class ConfigCommand extends BotSubcommand {
CommandContext ctx = new CommandContext(mojangCtx);
return executeSet(ctx) ? 1 : 0;
});
return super.compileBase()
.then(argument);
return super.compileBase().then(argument);
}
@Override

View File

@@ -19,10 +19,10 @@ import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.bot.BotCreateState;
import org.leavesmc.leaves.bot.BotList;
import org.leavesmc.leaves.event.bot.BotCreateEvent;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.bot.BotSubcommand;
import org.leavesmc.leaves.event.bot.BotCreateEvent;
import static net.kyori.adventure.text.Component.text;
import static net.minecraft.commands.arguments.DimensionArgument.getDimension;
@@ -99,7 +99,6 @@ public class CreateCommand extends BotSubcommand {
}
private static class NameArgument extends ArgumentNode<String> {
private NameArgument() {
super("name", StringArgumentType.word());
children(SkinNameArgument::new);
@@ -112,7 +111,6 @@ public class CreateCommand extends BotSubcommand {
}
private static class SkinNameArgument extends ArgumentNode<String> {
private SkinNameArgument() {
super("skin_name", StringArgumentType.word());
children(WorldArgument::new);
@@ -125,7 +123,6 @@ public class CreateCommand extends BotSubcommand {
}
private static class WorldArgument extends ArgumentNode<ResourceLocation> {
private WorldArgument() {
super("world", DimensionArgument.dimension());
children(LocationArgument::new);
@@ -138,7 +135,6 @@ public class CreateCommand extends BotSubcommand {
}
private static class LocationArgument extends ArgumentNode<Coordinates> {
private LocationArgument() {
super("location", Vec3Argument.vec3(true));
}

View File

@@ -55,11 +55,7 @@ public class LoadCommand extends BotSubcommand {
sender.sendMessage(text("Failed to load bot, please check log", NamedTextColor.RED));
return false;
}
sender.sendMessage(join(
spaces(),
text("Successfully loaded bot", NamedTextColor.GRAY),
asAdventure(bot.getDisplayName())
));
sender.sendMessage(join(spaces(), text("Successfully loaded bot", NamedTextColor.GRAY), asAdventure(bot.getDisplayName())));
return true;
}

View File

@@ -9,11 +9,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.bot.BotList;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.event.bot.BotRemoveEvent;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.CustomArgumentNode;
import org.leavesmc.leaves.command.bot.BotSubcommand;
import org.leavesmc.leaves.event.bot.BotRemoveEvent;
import org.leavesmc.leaves.plugin.MinecraftInternalPlugin;
import java.util.regex.Matcher;
@@ -42,7 +42,6 @@ public class RemoveCommand extends BotSubcommand {
}
private static class BotArgument extends CustomArgumentNode<ServerBot, String> {
private BotArgument() {
super("bot", new org.leavesmc.leaves.command.bot.BotArgument());
children(RemoveTimeArgument::new);
@@ -116,9 +115,15 @@ public class RemoveCommand extends BotSubcommand {
foundMatch = true;
int value = Integer.parseInt(matcher.group(1));
switch (matcher.group(2).toLowerCase()) {
case "h": seconds += value * 3600; break;
case "m": seconds += value * 60; break;
case "s": seconds += value; break;
case "h":
seconds += value * 3600;
break;
case "m":
seconds += value * 60;
break;
case "s":
seconds += value;
break;
}
}

View File

@@ -8,10 +8,10 @@ import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.bot.BotList;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.event.bot.BotRemoveEvent;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.CustomArgumentNode;
import org.leavesmc.leaves.command.bot.BotSubcommand;
import org.leavesmc.leaves.event.bot.BotRemoveEvent;
import static io.papermc.paper.adventure.PaperAdventure.asAdventure;
import static net.kyori.adventure.text.Component.join;

View File

@@ -36,10 +36,7 @@ public class ListCommand extends LiteralNode {
return true;
}
sender.sendMessage(
asAdventure(bot.getDisplayName())
.append(text("'s action list:", GRAY))
);
sender.sendMessage(asAdventure(bot.getDisplayName()).append(text("'s action list:", GRAY)));
for (int i = 0; i < actions.size(); i++) {
AbstractBotAction<?> action = actions.get(i);
sender.sendMessage(join(spaces(),

View File

@@ -32,10 +32,7 @@ public class StartCommand extends LiteralNode {
public StartCommand() {
super("start");
Actions.getAll()
.stream()
.map(this::actionNodeCreator)
.forEach(this::children);
Actions.getAll().stream().map(this::actionNodeCreator).forEach(this::children);
}
private boolean handleStartCommand(CommandContext context, @NotNull AbstractBotAction<?> action) throws CommandSyntaxException {

View File

@@ -9,11 +9,11 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.bot.ServerBot;
import org.leavesmc.leaves.bot.agent.actions.AbstractBotAction;
import org.leavesmc.leaves.event.bot.BotActionStopEvent;
import org.leavesmc.leaves.command.ArgumentNode;
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;
import java.util.HashSet;
import java.util.List;

View File

@@ -11,6 +11,7 @@ import org.leavesmc.leaves.command.leaves.subcommands.ReportCommand;
import org.leavesmc.leaves.command.leaves.subcommands.UpdateCommand;
public class LeavesCommand extends RootNode {
public static final LeavesCommand INSTANCE = new LeavesCommand();
private static final String PERM_BASE = "bukkit.command.leaves";

View File

@@ -46,7 +46,6 @@ public class BlockUpdateCommand extends LeavesSubcommand {
}
private class EnableNode extends LiteralNode {
private EnableNode() {
super("enable");
}
@@ -73,7 +72,6 @@ public class BlockUpdateCommand extends LeavesSubcommand {
}
private class DisableNode extends LiteralNode {
private DisableNode() {
super("disable");
}

View File

@@ -6,11 +6,12 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.leavesmc.leaves.config.GlobalConfigManager;
import org.leavesmc.leaves.config.VerifiedConfig;
import org.leavesmc.leaves.command.ArgumentNode;
import org.leavesmc.leaves.command.CommandContext;
import org.leavesmc.leaves.command.CommandUtils;
import org.leavesmc.leaves.command.leaves.LeavesSubcommand;
import org.leavesmc.leaves.config.GlobalConfigManager;
import org.leavesmc.leaves.config.VerifiedConfig;
import java.util.concurrent.CompletableFuture;
@@ -18,7 +19,6 @@ import static net.kyori.adventure.text.Component.join;
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.JoinConfiguration.spaces;
import static net.kyori.adventure.text.format.NamedTextColor.*;
import static org.leavesmc.leaves.command.CommandUtils.getListClosestMatchingLast;
public class ConfigCommand extends LeavesSubcommand {
@@ -39,10 +39,8 @@ public class ConfigCommand extends LeavesSubcommand {
String path = context.getArgumentOrDefault(PathArgument.class, "");
int dotIndex = path.lastIndexOf(".");
builder = builder.createOffset(builder.getInput().lastIndexOf(' ') + dotIndex + 2);
getListClosestMatchingLast(
path.substring(dotIndex + 1),
GlobalConfigManager.getVerifiedConfigSubPaths(path)
).forEach(builder::suggest);
CommandUtils.getListClosestMatchingLast(path.substring(dotIndex + 1), GlobalConfigManager.getVerifiedConfigSubPaths(path))
.forEach(builder::suggest);
return builder.buildFuture();
}
@@ -75,7 +73,6 @@ public class ConfigCommand extends LeavesSubcommand {
}
return verifiedConfig;
}
}
private static class ValueArgument extends ArgumentNode<String> {

View File

@@ -48,7 +48,6 @@ public class CounterCommand extends LeavesSubcommand {
}
private static class EnableNode extends LiteralNode {
private EnableNode() {
super("enable");
}
@@ -73,7 +72,6 @@ public class CounterCommand extends LeavesSubcommand {
}
private static class DisableNode extends LiteralNode {
private DisableNode() {
super("disable");
}
@@ -98,7 +96,6 @@ public class CounterCommand extends LeavesSubcommand {
}
private static class ResetAllNode extends LiteralNode {
private ResetAllNode() {
super("reset");
}
@@ -138,7 +135,6 @@ public class CounterCommand extends LeavesSubcommand {
}
private class ResetNode extends LiteralNode {
private ResetNode() {
super("reset");
}
@@ -155,7 +151,6 @@ public class CounterCommand extends LeavesSubcommand {
}
private class RealtimeNode extends LiteralNode {
private RealtimeNode() {
super("realtime");
}

View File

@@ -12,7 +12,6 @@ import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.format.NamedTextColor.GREEN;
public class ReloadCommand extends LeavesSubcommand {
public ReloadCommand() {
super("reload");
}

View File

@@ -104,7 +104,7 @@ public class ServuxLitematicsProtocol implements LeavesProtocol {
case PACKET_C2S_BLOCK_ENTITY_REQUEST -> onBlockEntityRequest(player, payload.getPos());
case PACKET_C2S_ENTITY_REQUEST -> onEntityRequest(player, payload.getEntityId());
case PACKET_C2S_BULK_ENTITY_NBT_REQUEST -> onBulkEntityRequest(player, payload.getChunkPos(), payload.getCompound());
case PACKET_C2S_NBT_RESPONSE_DATA -> {

View File

@@ -7,8 +7,6 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;