mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-23 00:49:23 +00:00
Fix custom bot action API
This commit is contained in:
@@ -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
|
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
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..4795a9fec1aba613ad86d76d4f23d920fa2ba082
|
index 0000000000000000000000000000000000000000..7abf4eef22e40468929e724ebc07a97b0b2a05f3
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/top/leavesmc/leaves/entity/botaction/CustomBotAction.java
|
+++ 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;
|
+package top.leavesmc.leaves.entity.botaction;
|
||||||
+
|
+
|
||||||
+import org.bukkit.entity.Player;
|
+import org.bukkit.entity.Player;
|
||||||
+import org.jetbrains.annotations.NotNull;
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+import org.jetbrains.annotations.Nullable;
|
||||||
+import top.leavesmc.leaves.entity.Bot;
|
+import top.leavesmc.leaves.entity.Bot;
|
||||||
+
|
+
|
||||||
+import java.util.List;
|
+import java.util.List;
|
||||||
@@ -249,7 +250,7 @@ index 0000000000000000000000000000000000000000..4795a9fec1aba613ad86d76d4f23d920
|
|||||||
+ * @param args passed action arguments
|
+ * @param args passed action arguments
|
||||||
+ * @return a new action instance with given args
|
+ * @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.
|
+ * Requests a list of possible completions for a action argument.
|
||||||
|
|||||||
@@ -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
|
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
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..71c810146fe059d8ce51ef323390f170faeb89ec
|
index 0000000000000000000000000000000000000000..b3593998718cd69738cba04234cc0bf7754ae524
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/top/leavesmc/leaves/bot/BotUtil.java
|
+++ b/src/main/java/top/leavesmc/leaves/bot/BotUtil.java
|
||||||
@@ -0,0 +1,177 @@
|
@@ -0,0 +1,179 @@
|
||||||
+package top.leavesmc.leaves.bot;
|
+package top.leavesmc.leaves.bot;
|
||||||
+
|
+
|
||||||
+import com.google.gson.JsonElement;
|
+import com.google.gson.JsonElement;
|
||||||
@@ -1012,10 +1012,12 @@ index 0000000000000000000000000000000000000000..71c810146fe059d8ce51ef323390f170
|
|||||||
+
|
+
|
||||||
+ if (finalActionObj != null) {
|
+ if (finalActionObj != null) {
|
||||||
+ BotAction action = Actions.getForName(finalActionObj.get("name").getAsString());
|
+ BotAction action = Actions.getForName(finalActionObj.get("name").getAsString());
|
||||||
+ BotAction newAction = action.getNew(serverBot,
|
+ if (action != null) {
|
||||||
+ action.getArgument().parse(0, new String[]{finalActionObj.get("delay").getAsString(), finalActionObj.get("number").getAsString()})
|
+ BotAction newAction = action.getNew(serverBot,
|
||||||
+ );
|
+ action.getArgument().parse(0, new String[]{finalActionObj.get("delay").getAsString(), finalActionObj.get("number").getAsString()})
|
||||||
+ serverBot.setBotAction(newAction);
|
+ );
|
||||||
|
+ serverBot.setBotAction(newAction);
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ }));
|
+ }));
|
||||||
+ }
|
+ }
|
||||||
@@ -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
|
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
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..3352c826174e2d33060514fe975d6eab92070fce
|
index 0000000000000000000000000000000000000000..89a361249179d7a0a84768e715ced05aafc13272
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/top/leavesmc/leaves/bot/agent/actions/CraftCustomBotAction.java
|
+++ 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;
|
+package top.leavesmc.leaves.bot.agent.actions;
|
||||||
+
|
+
|
||||||
+import net.minecraft.server.level.ServerPlayer;
|
+import net.minecraft.server.level.ServerPlayer;
|
||||||
@@ -2094,7 +2096,11 @@ index 0000000000000000000000000000000000000000..3352c826174e2d33060514fe975d6eab
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public BotAction getNew(@NotNull Player player, String[] args) {
|
+ 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
|
+ @Override
|
||||||
|
|||||||
Reference in New Issue
Block a user