Skip to content

Commit

Permalink
Update bot API (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lumine1909 authored Aug 24, 2024
1 parent 595afb8 commit 39440b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
10 changes: 7 additions & 3 deletions patches/api/0003-Add-fakeplayer-api.patch
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,18 @@ index 0000000000000000000000000000000000000000..0b1648013d5f03d064c0719c23198108
+}
diff --git a/src/main/java/org/leavesmc/leaves/entity/botaction/LeavesBotAction.java b/src/main/java/org/leavesmc/leaves/entity/botaction/LeavesBotAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..b239acd298b299e338ae56aa6507570942ce44e2
index 0000000000000000000000000000000000000000..a6fdf8c77318172621494af94a0efb2bd34ca651
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/entity/botaction/LeavesBotAction.java
@@ -0,0 +1,32 @@
@@ -0,0 +1,36 @@
+package org.leavesmc.leaves.entity.botaction;
+
+/**
+ * A Leaves bot action enum
+ */
+public enum LeavesBotAction {
+ ATTACK("attack"),
+ @Deprecated(since = "1.21.1", forRemoval = true)
+ ATTACK_SELF("attack_self"),
+ BREAK("break"),
+ DROP("drop"),
Expand All @@ -332,7 +333,10 @@ index 0000000000000000000000000000000000000000..b239acd298b299e338ae56aa65075709
+ SWIM("swim"),
+ USE("use"),
+ USE_ON("use_on"),
+ USE_TO("use_to");
+ USE_TO("use_to"),
+ USE_OFFHAND("use_offhand"),
+ USE_ON_OFFHAND("use_on_offhand"),
+ USE_TO_OFFHAND("use_to_offhand");
+
+ private final String name;
+
Expand Down
26 changes: 18 additions & 8 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ index 22f1ed383313829b8af4badda9ef8dc85cae8fd1..1c47e320e464af9651953ff308a2583f
// Paper end
diff --git a/src/main/java/org/leavesmc/leaves/bot/BotCommand.java b/src/main/java/org/leavesmc/leaves/bot/BotCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..b64361c4151659d5e3f8884562cb811d60776c38
index 0000000000000000000000000000000000000000..918cdffedddba7cebb8013600bf3a2f5ce1e32c0
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/BotCommand.java
@@ -0,0 +1,472 @@
Expand Down Expand Up @@ -710,7 +710,7 @@ index 0000000000000000000000000000000000000000..b64361c4151659d5e3f8884562cb811d
+
+ if (canCreate(sender, args[1])) {
+ if (sender instanceof Player player) {
+ new ServerBot.BotCreateState(player.getLocation(), args[1], args.length < 3 ? args[1] : args[2], BotCreateEvent.CreateReason.COMMAND, player).create(bot -> bot.createPlayer = player.getUniqueId());
+ new ServerBot.BotCreateState(player.getLocation(), args[1], args.length < 3 ? args[1] : args[2], BotCreateEvent.CreateReason.COMMAND, player).create(null);
+ } else if (sender instanceof ConsoleCommandSender csender) {
+ if (args.length < 6) {
+ sender.sendMessage(ChatColor.RED + "Use /bot create <name> <skin_name> <bukkit_world_name> <x> <y> <z> to create a fakeplayer");
Expand Down Expand Up @@ -1555,10 +1555,10 @@ index 0000000000000000000000000000000000000000..0db337866c71283464d026a4f230016b
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/ServerBot.java b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
new file mode 100644
index 0000000000000000000000000000000000000000..31de3025586331839870796ad9191738b96b4ef8
index 0000000000000000000000000000000000000000..64d8fbe3b1a7c5337436ffa3ea754cec0207f996
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
@@ -0,0 +1,772 @@
@@ -0,0 +1,781 @@
+package org.leavesmc.leaves.bot;
+
+import com.google.common.collect.Lists;
Expand All @@ -1569,6 +1569,8 @@ index 0000000000000000000000000000000000000000..31de3025586331839870796ad9191738
+import com.mojang.authlib.properties.Property;
+import io.papermc.paper.adventure.PaperAdventure;
+import io.papermc.paper.event.entity.EntityKnockbackEvent;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.format.Style;
+import net.minecraft.Util;
+import net.minecraft.core.BlockPos;
+import net.minecraft.network.Connection;
Expand Down Expand Up @@ -1734,6 +1736,9 @@ index 0000000000000000000000000000000000000000..31de3025586331839870796ad9191738
+ }, bot, CommonListenerCookie.createInitial(profile, false));
+ bot.isRealPlayer = true;
+ bot.createState = state;
+ if (event.getCreator().isPresent() && event.getCreator().get() instanceof org.bukkit.entity.Player player) {
+ bot.createPlayer = player.getUniqueId();
+ }
+
+ bot.teleportTo(location.getX(), location.getY(), location.getZ());
+ bot.setRot(location.getYaw(), location.getPitch());
Expand All @@ -1743,7 +1748,7 @@ index 0000000000000000000000000000000000000000..31de3025586331839870796ad9191738
+ server.getPlayerList().addNewBot(bot);
+ bots.add(bot);
+
+ BotJoinEvent event1 = new BotJoinEvent(bot.getBukkitPlayer(), PaperAdventure.asAdventure(Component.translatable("multiplayer.player.joined", bot.getDisplayName())));
+ BotJoinEvent event1 = new BotJoinEvent(bot.getBukkitPlayer(), PaperAdventure.asAdventure(Component.translatable("multiplayer.player.joined", bot.getDisplayName())).style(Style.style(NamedTextColor.YELLOW)));
+ server.server.getPluginManager().callEvent(event1);
+
+ net.kyori.adventure.text.Component joinMessage = event1.joinMessage();
Expand Down Expand Up @@ -1830,7 +1835,7 @@ index 0000000000000000000000000000000000000000..31de3025586331839870796ad9191738
+ }
+
+ public void onRemove(BotRemoveEvent.RemoveReason reason, @Nullable CommandSender remover) {
+ BotRemoveEvent event = new BotRemoveEvent(this.getBukkitPlayer(), reason, remover, PaperAdventure.asAdventure(Component.translatable("multiplayer.player.left", this.getDisplayName())));
+ BotRemoveEvent event = new BotRemoveEvent(this.getBukkitPlayer(), reason, remover, PaperAdventure.asAdventure(Component.translatable("multiplayer.player.left", this.getDisplayName())).style(Style.style(NamedTextColor.YELLOW)));
+ this.server.server.getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
Expand Down Expand Up @@ -2018,6 +2023,10 @@ index 0000000000000000000000000000000000000000..31de3025586331839870796ad9191738
+ detectEquipmentUpdatesPublic();
+ }
+
+ public long getEatStartTime() {
+ return eatStartTime;
+ }
+
+ @Override
+ public void checkFallDamage(double heightDifference, boolean onGround, @NotNull BlockState state, @NotNull BlockPos landedPosition) {
+ if (onGround) {
Expand Down Expand Up @@ -3246,12 +3255,13 @@ index 0000000000000000000000000000000000000000..c91ca987eb5922b8dbcd271deb33f80b
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..acc28becb88b691ecfb8cd15d86031086cba3ba3
index 0000000000000000000000000000000000000000..cf56fbdd461ae7f3a00043dbe979421a1dd3b5a4
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemAction.java
@@ -0,0 +1,33 @@
@@ -0,0 +1,34 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.core.component.DataComponents;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.InteractionHand;
+import org.jetbrains.annotations.NotNull;
Expand Down

0 comments on commit 39440b4

Please sign in to comment.