Skip to content

Commit

Permalink
Fix custom bot action API
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jul 23, 2023
1 parent ced4188 commit f8c0e47
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 4 additions & 3 deletions patches/api/0003-Add-fakeplayer-api.patch
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,15 @@ index 0000000000000000000000000000000000000000..f2258027b2ed4bfcf7feda2e9075b1a1
+}
diff --git a/src/main/java/top/leavesmc/leaves/entity/botaction/CustomBotAction.java b/src/main/java/top/leavesmc/leaves/entity/botaction/CustomBotAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..4795a9fec1aba613ad86d76d4f23d920fa2ba082
index 0000000000000000000000000000000000000000..7abf4eef22e40468929e724ebc07a97b0b2a05f3
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/entity/botaction/CustomBotAction.java
@@ -0,0 +1,51 @@
@@ -0,0 +1,52 @@
+package top.leavesmc.leaves.entity.botaction;
+
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import top.leavesmc.leaves.entity.Bot;
+
+import java.util.List;
Expand All @@ -249,7 +250,7 @@ index 0000000000000000000000000000000000000000..4795a9fec1aba613ad86d76d4f23d920
+ * @param args passed action arguments
+ * @return a new action instance with given args
+ */
+ public CustomBotAction getNew(Player player, String[] args);
+ public @Nullable CustomBotAction getNew(Player player, String[] args);
+
+ /**
+ * Requests a list of possible completions for a action argument.
Expand Down
24 changes: 15 additions & 9 deletions patches/server/0008-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,10 @@ index 0000000000000000000000000000000000000000..07b688d376a4af88305e57519a5ae983
+}
diff --git a/src/main/java/top/leavesmc/leaves/bot/BotUtil.java b/src/main/java/top/leavesmc/leaves/bot/BotUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..71c810146fe059d8ce51ef323390f170faeb89ec
index 0000000000000000000000000000000000000000..b3593998718cd69738cba04234cc0bf7754ae524
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/bot/BotUtil.java
@@ -0,0 +1,177 @@
@@ -0,0 +1,179 @@
+package top.leavesmc.leaves.bot;
+
+import com.google.gson.JsonElement;
Expand Down Expand Up @@ -1012,10 +1012,12 @@ index 0000000000000000000000000000000000000000..71c810146fe059d8ce51ef323390f170
+
+ if (finalActionObj != null) {
+ BotAction action = Actions.getForName(finalActionObj.get("name").getAsString());
+ BotAction newAction = action.getNew(serverBot,
+ action.getArgument().parse(0, new String[]{finalActionObj.get("delay").getAsString(), finalActionObj.get("number").getAsString()})
+ );
+ serverBot.setBotAction(newAction);
+ if (action != null) {
+ BotAction newAction = action.getNew(serverBot,
+ action.getArgument().parse(0, new String[]{finalActionObj.get("delay").getAsString(), finalActionObj.get("number").getAsString()})
+ );
+ serverBot.setBotAction(newAction);
+ }
+ }
+ }));
+ }
Expand Down Expand Up @@ -2064,10 +2066,10 @@ index 0000000000000000000000000000000000000000..2a3ca671b43fec658bf5cd8a6eb08b47
+}
diff --git a/src/main/java/top/leavesmc/leaves/bot/agent/actions/CraftCustomBotAction.java b/src/main/java/top/leavesmc/leaves/bot/agent/actions/CraftCustomBotAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..3352c826174e2d33060514fe975d6eab92070fce
index 0000000000000000000000000000000000000000..89a361249179d7a0a84768e715ced05aafc13272
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/bot/agent/actions/CraftCustomBotAction.java
@@ -0,0 +1,44 @@
@@ -0,0 +1,48 @@
+package top.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.server.level.ServerPlayer;
Expand All @@ -2094,7 +2096,11 @@ index 0000000000000000000000000000000000000000..3352c826174e2d33060514fe975d6eab
+ }
+
+ public BotAction getNew(@NotNull Player player, String[] args) {
+ return new CraftCustomBotAction(getName(), realAction.getNew(player, args));
+ CustomBotAction newRealAction = realAction.getNew(player, args);
+ if (newRealAction != null) {
+ return new CraftCustomBotAction(getName(), newRealAction);
+ }
+ return null;
+ }
+
+ @Override
Expand Down

0 comments on commit f8c0e47

Please sign in to comment.