mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-06 15:51:33 +00:00
Update fakeplayer api
This commit is contained in:
@@ -62,10 +62,10 @@ index 1fc734c2898fc3d3b89b58284d56a0cff68794c4..50c9e22183c796838dd66cfabbc4befe
|
||||
}
|
||||
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..8816683c795f9be6a4f112203cfac3f59d8faba5
|
||||
index 0000000000000000000000000000000000000000..02815077dcd6d5c1b155ef3ca5cd6e3a9c45c0b5
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/entity/Bot.java
|
||||
@@ -0,0 +1,46 @@
|
||||
@@ -0,0 +1,51 @@
|
||||
+package top.leavesmc.leaves.entity;
|
||||
+
|
||||
+import org.bukkit.entity.Player;
|
||||
@@ -73,6 +73,8 @@ index 0000000000000000000000000000000000000000..8816683c795f9be6a4f112203cfac3f5
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import top.leavesmc.leaves.entity.botaction.LeavesBotAction;
|
||||
+
|
||||
+import java.util.UUID;
|
||||
+
|
||||
+/**
|
||||
+ * Represents a fakeplayer
|
||||
+ */
|
||||
@@ -94,12 +96,15 @@ index 0000000000000000000000000000000000000000..8816683c795f9be6a4f112203cfac3f5
|
||||
+ @NotNull
|
||||
+ public String getRealName();
|
||||
+
|
||||
+ @Nullable
|
||||
+ public UUID getCreatePlayerUUID();
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the fakeplayer action with args.
|
||||
+ *
|
||||
+ * @param action action name
|
||||
+ * @param player player who create this action
|
||||
+ * @param args passed action arguments
|
||||
+ * @param args passed action arguments
|
||||
+ */
|
||||
+ public boolean setBotAction(@NotNull String action, @NotNull Player player, @NotNull String[] args);
|
||||
+
|
||||
@@ -108,7 +113,7 @@ index 0000000000000000000000000000000000000000..8816683c795f9be6a4f112203cfac3f5
|
||||
+ *
|
||||
+ * @param action leaves bot action
|
||||
+ * @param player player who create this action
|
||||
+ * @param args passed action arguments
|
||||
+ * @param args passed action arguments
|
||||
+ */
|
||||
+ public boolean setBotAction(@NotNull LeavesBotAction action, @NotNull Player player, @NotNull String[] args);
|
||||
+}
|
||||
@@ -470,6 +475,58 @@ index 0000000000000000000000000000000000000000..4a4fe07ce965d4a97e0d8105a91310da
|
||||
+ return bot;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/event/bot/BotInventoryOpenEvent.java b/src/main/java/top/leavesmc/leaves/event/bot/BotInventoryOpenEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..e889f7e98ec9cb6a3b95d8ea865e25fffea662a1
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/event/bot/BotInventoryOpenEvent.java
|
||||
@@ -0,0 +1,46 @@
|
||||
+package top.leavesmc.leaves.event.bot;
|
||||
+
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import top.leavesmc.leaves.entity.Bot;
|
||||
+
|
||||
+public class BotInventoryOpenEvent extends BotEvent implements Cancellable {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+
|
||||
+ private final Player player;
|
||||
+ private boolean cancel = false;
|
||||
+
|
||||
+ public BotInventoryOpenEvent(@NotNull Bot who, @Nullable Player player) {
|
||||
+ super(who);
|
||||
+ this.player = player;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCancelled() {
|
||||
+ return cancel;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCancelled(boolean cancel) {
|
||||
+ this.cancel = cancel;
|
||||
+ }
|
||||
+
|
||||
+ @Nullable
|
||||
+ public Player getOpenPlayer() {
|
||||
+ return player;
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/event/bot/BotJoinEvent.java b/src/main/java/top/leavesmc/leaves/event/bot/BotJoinEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..10afa5c7fd4ee8a4e72d64f8ca9bf8731ec2ad61
|
||||
|
||||
@@ -463,7 +463,7 @@ index e2b4cdf549f66ccc243442a239b3a94ed1429cd0..b3675ab0b40862993efb71ff9bda6ec8
|
||||
public static void load(final YamlConfiguration config) {
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/bot/BotCommand.java b/src/main/java/top/leavesmc/leaves/bot/BotCommand.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..ad49275aca2649ae0e7a6f90cfda9f439d72b067
|
||||
index 0000000000000000000000000000000000000000..6abc37cff54d876b598051bb23aa3a2c2e1a7baa
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/bot/BotCommand.java
|
||||
@@ -0,0 +1,275 @@
|
||||
@@ -581,7 +581,7 @@ index 0000000000000000000000000000000000000000..ad49275aca2649ae0e7a6f90cfda9f43
|
||||
+
|
||||
+ if (canCreate(sender, args[1])) {
|
||||
+ if (sender instanceof Player player) {
|
||||
+ new ServerBot.BotCreateState(player.getLocation(), args[1], args.length < 3 ? args[1] : args[2]).createAsync(null);
|
||||
+ new ServerBot.BotCreateState(player.getLocation(), args[1], args.length < 3 ? args[1] : args[2]).createAsync(bot -> bot.createPlayer = player.getUniqueId());
|
||||
+ } else if (sender instanceof ConsoleCommandSender) {
|
||||
+ if (args.length < 6) {
|
||||
+ sender.sendMessage(ChatColor.RED + "Use /bot create <name> <skin_name> <bukkit_world_name> <x> <y> <z> to create a fakeplayer");
|
||||
@@ -1209,10 +1209,10 @@ index 0000000000000000000000000000000000000000..daaece30b2a3983f1cc9ee9a851e8f37
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/bot/ServerBot.java b/src/main/java/top/leavesmc/leaves/bot/ServerBot.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..8c41c8034135d575d9f62847ba5894e84b5b0d21
|
||||
index 0000000000000000000000000000000000000000..1d86e1e1ff959403cdb651e2feea3f596be3efcb
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/bot/ServerBot.java
|
||||
@@ -0,0 +1,710 @@
|
||||
@@ -0,0 +1,712 @@
|
||||
+package top.leavesmc.leaves.bot;
|
||||
+
|
||||
+import com.google.common.collect.Lists;
|
||||
@@ -1263,13 +1263,9 @@ index 0000000000000000000000000000000000000000..8c41c8034135d575d9f62847ba5894e8
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.Material;
|
||||
+import org.bukkit.craftbukkit.CraftWorld;
|
||||
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
+import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
||||
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
|
||||
+import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
+import org.bukkit.plugin.Plugin;
|
||||
+import org.bukkit.util.Vector;
|
||||
+import org.jetbrains.annotations.Contract;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import top.leavesmc.leaves.LeavesConfig;
|
||||
+import top.leavesmc.leaves.bot.agent.BotAction;
|
||||
@@ -1277,6 +1273,7 @@ index 0000000000000000000000000000000000000000..8c41c8034135d575d9f62847ba5894e8
|
||||
+import top.leavesmc.leaves.entity.Bot;
|
||||
+import top.leavesmc.leaves.entity.CraftBot;
|
||||
+import top.leavesmc.leaves.event.bot.BotCreateEvent;
|
||||
+import top.leavesmc.leaves.event.bot.BotInventoryOpenEvent;
|
||||
+import top.leavesmc.leaves.event.bot.BotJoinEvent;
|
||||
+import top.leavesmc.leaves.util.MathUtils;
|
||||
+
|
||||
@@ -1311,6 +1308,7 @@ index 0000000000000000000000000000000000000000..8c41c8034135d575d9f62847ba5894e8
|
||||
+ public boolean waterSwim;
|
||||
+ private Vec3 knockback;
|
||||
+ public BotCreateState createState;
|
||||
+ public UUID createPlayer;
|
||||
+
|
||||
+ private final ServerStatsCounter stats;
|
||||
+ private final BotInventoryContainer container;
|
||||
@@ -1423,7 +1421,7 @@ index 0000000000000000000000000000000000000000..8c41c8034135d575d9f62847ba5894e8
|
||||
+ }
|
||||
+
|
||||
+ public void sendFakeData(ServerPlayerConnection playerConnection, boolean login) {
|
||||
+ playerConnection.send(new ClientboundAddEntityPacket(this));
|
||||
+ playerConnection.send(new ClientboundAddEntityPacket(this));
|
||||
+ if (login) {
|
||||
+ Bukkit.getScheduler().runTaskLater(CraftScheduler.MINECRAFT, () -> {
|
||||
+ connection.send(new ClientboundRotateHeadPacket(this, (byte) ((getYRot() * 256f) / 360f)));
|
||||
@@ -1753,9 +1751,13 @@ index 0000000000000000000000000000000000000000..8c41c8034135d575d9f62847ba5894e8
|
||||
+ @Override
|
||||
+ public @NotNull InteractionResult interact(@NotNull Player player, @NotNull InteractionHand hand) {
|
||||
+ if (LeavesConfig.openFakeplayerInventory) {
|
||||
+ if (player.getMainHandItem().isEmpty()) {
|
||||
+ player.openMenu(new SimpleMenuProvider((i, inventory, p) -> ChestMenu.sixRows(i, inventory, container), getDisplayName()));
|
||||
+ return InteractionResult.SUCCESS;
|
||||
+ if (player instanceof ServerPlayer player1 && player.getMainHandItem().isEmpty()) {
|
||||
+ BotInventoryOpenEvent event = new BotInventoryOpenEvent(this.getBukkitEntity(), player1.getBukkitEntity());
|
||||
+ server.server.getPluginManager().callEvent(event);
|
||||
+ if (!event.isCancelled()) {
|
||||
+ player.openMenu(new SimpleMenuProvider((i, inventory, p) -> ChestMenu.sixRows(i, inventory, container), getDisplayName()));
|
||||
+ return InteractionResult.SUCCESS;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ return super.interact(player, hand);
|
||||
@@ -3007,10 +3009,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..e30ce391f638778fc805ca75287917af99b37443
|
||||
index 0000000000000000000000000000000000000000..713240da3ba37915b455d952a45ae7f68b8294ee
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/entity/CraftBot.java
|
||||
@@ -0,0 +1,60 @@
|
||||
@@ -0,0 +1,67 @@
|
||||
+package top.leavesmc.leaves.entity;
|
||||
+
|
||||
+import org.bukkit.craftbukkit.CraftServer;
|
||||
@@ -3023,6 +3025,8 @@ index 0000000000000000000000000000000000000000..e30ce391f638778fc805ca75287917af
|
||||
+import top.leavesmc.leaves.bot.agent.BotAction;
|
||||
+import top.leavesmc.leaves.entity.botaction.LeavesBotAction;
|
||||
+
|
||||
+import java.util.UUID;
|
||||
+
|
||||
+public class CraftBot extends CraftPlayer implements Bot {
|
||||
+
|
||||
+ public CraftBot(CraftServer server, ServerBot entity) {
|
||||
@@ -3040,6 +3044,11 @@ index 0000000000000000000000000000000000000000..e30ce391f638778fc805ca75287917af
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @Nullable UUID getCreatePlayerUUID() {
|
||||
+ return getHandle().createPlayer;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean setBotAction(@NotNull String action, @NotNull Player player, @NotNull String[] args) {
|
||||
+ BotAction botAction = Actions.getForName(action);
|
||||
+ if (botAction != null) {
|
||||
|
||||
Reference in New Issue
Block a user