Skip to content

Commit

Permalink
Update fakeplayer api
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jul 30, 2023
1 parent cec1d29 commit 6ae833b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
52 changes: 50 additions & 2 deletions patches/api/0003-Add-fakeplayer-api.patch
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ index 3c4915b8dd1b6e802a5942658b15d3a9db472364..0bfe5628c8327e9cd5728cea7ae6c2ce
}
diff --git a/src/main/java/top/leavesmc/leaves/entity/Bot.java b/src/main/java/top/leavesmc/leaves/entity/Bot.java
new file mode 100644
index 0000000000000000000000000000000000000000..c5be2641cdacef540f13f958009c8a250cb23090
index 0000000000000000000000000000000000000000..8816683c795f9be6a4f112203cfac3f59d8faba5
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/entity/Bot.java
@@ -0,0 +1,36 @@
@@ -0,0 +1,46 @@
+package top.leavesmc.leaves.entity;
+
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import top.leavesmc.leaves.entity.botaction.LeavesBotAction;
+
+/**
+ * Represents a fakeplayer
Expand Down Expand Up @@ -101,6 +102,15 @@ index 0000000000000000000000000000000000000000..c5be2641cdacef540f13f958009c8a25
+ * @param args passed action arguments
+ */
+ public boolean setBotAction(@NotNull String action, @NotNull Player player, @NotNull String[] args);
+
+ /**
+ * Sets the fakeplayer action with args.
+ *
+ * @param action leaves bot action
+ * @param player player who create this action
+ * @param args passed action arguments
+ */
+ public boolean setBotAction(@NotNull LeavesBotAction action, @NotNull Player player, @NotNull String[] args);
+}
diff --git a/src/main/java/top/leavesmc/leaves/entity/BotManager.java b/src/main/java/top/leavesmc/leaves/entity/BotManager.java
new file mode 100644
Expand Down Expand Up @@ -273,6 +283,44 @@ index 0000000000000000000000000000000000000000..7abf4eef22e40468929e724ebc07a97b
+ */
+ public int getNumber();
+}
diff --git a/src/main/java/top/leavesmc/leaves/entity/botaction/LeavesBotAction.java b/src/main/java/top/leavesmc/leaves/entity/botaction/LeavesBotAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..e298722319ff0cfd52e531693ea3767e5f9a3d52
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/entity/botaction/LeavesBotAction.java
@@ -0,0 +1,32 @@
+package top.leavesmc.leaves.entity.botaction;
+
+/**
+ * A Leaves bot action enum
+ */
+public enum LeavesBotAction {
+ ATTACK("attack"),
+ ATTACK_SELF("attack_self"),
+ BREAK("break"),
+ DROP("drop"),
+ FISH("fish"),
+ JUMP("jump"),
+ LAY("lay"),
+ LOOK("look"),
+ ROTATE("rotate"),
+ SNEAK("sneak"),
+ STOP("stop"),
+ SWIM("swim"),
+ USE("use"),
+ USE_ON("use_on"),
+ USE_TO("use_to");
+
+ private final String name;
+
+ private LeavesBotAction(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/src/main/java/top/leavesmc/leaves/event/bot/BotCreateEvent.java b/src/main/java/top/leavesmc/leaves/event/bot/BotCreateEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..7cf1eb4eb3d2fe9310f9272ec53208632b87b49b
Expand Down
10 changes: 8 additions & 2 deletions patches/server/0008-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2668,10 +2668,10 @@ index 340eaca64c96180b895a075ce9e44402cd104eed..39e90dcff0de259373d7955021c29397
}
diff --git a/src/main/java/top/leavesmc/leaves/entity/CraftBot.java b/src/main/java/top/leavesmc/leaves/entity/CraftBot.java
new file mode 100644
index 0000000000000000000000000000000000000000..1346cfaafdb0c3a467b3619fd42286742e4e9f36
index 0000000000000000000000000000000000000000..a2ea0da6dc0314209c2c366b1e33b5a878312131
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/entity/CraftBot.java
@@ -0,0 +1,54 @@
@@ -0,0 +1,60 @@
+package top.leavesmc.leaves.entity;
+
+import org.bukkit.craftbukkit.CraftServer;
Expand All @@ -2682,6 +2682,7 @@ index 0000000000000000000000000000000000000000..1346cfaafdb0c3a467b3619fd4228674
+import top.leavesmc.leaves.bot.ServerBot;
+import top.leavesmc.leaves.bot.agent.Actions;
+import top.leavesmc.leaves.bot.agent.BotAction;
+import top.leavesmc.leaves.entity.botaction.LeavesBotAction;
+
+public class CraftBot extends CraftPlayer implements Bot {
+
Expand Down Expand Up @@ -2713,6 +2714,11 @@ index 0000000000000000000000000000000000000000..1346cfaafdb0c3a467b3619fd4228674
+ }
+
+ @Override
+ public boolean setBotAction(@NotNull LeavesBotAction action, @NotNull Player player, @NotNull String[] args) {
+ return setBotAction(action.getName(), player, args);
+ }
+
+ @Override
+ public ServerBot getHandle() {
+ return (ServerBot) entity;
+ }
Expand Down

0 comments on commit 6ae833b

Please sign in to comment.