9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-22 16:39:30 +00:00

Fix bot list name

This commit is contained in:
violetc
2023-01-02 14:55:29 +08:00
parent e503c2d84c
commit 506e3963e3

View File

@@ -249,10 +249,10 @@ index 1fb25e8a21b568864974cc81b452ba062890d593..c32825a237a539035828a9c85673ea0e
public final String worldName;
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..5a9f2a01449cb8c11c6c05490ad48682acb0f389
index 0000000000000000000000000000000000000000..6d08dd6dfdbf97e9de7457602f58458fa4239bf3
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/bot/BotCommand.java
@@ -0,0 +1,271 @@
@@ -0,0 +1,272 @@
+package top.leavesmc.leaves.bot;
+
+import net.minecraft.world.damagesource.DamageSource;
@@ -308,6 +308,7 @@ index 0000000000000000000000000000000000000000..5a9f2a01449cb8c11c6c05490ad48682
+ if (args.length == 3) {
+ switch (args[0]) {
+ case "action" -> list.addAll(Actions.getAll().stream().map(BotAction::getName).toList());
+ case "create" -> list.add("<BotSkinName>");
+ }
+ }
+
@@ -398,7 +399,7 @@ index 0000000000000000000000000000000000000000..5a9f2a01449cb8c11c6c05490ad48682
+ sender.sendMessage(ChatColor.RED + "Fakeplayer limit is full");
+ }
+
+ ServerBot.createBot(((Player) sender).getLocation(), args[1]);
+ ServerBot.createBot(((Player) sender).getLocation(), args[1], args[2]);
+ }
+
+ private void onRemove(CommandSender sender, String @NotNull [] args) {
@@ -526,7 +527,7 @@ index 0000000000000000000000000000000000000000..5a9f2a01449cb8c11c6c05490ad48682
+}
diff --git a/src/main/java/top/leavesmc/leaves/bot/MojangAPI.java b/src/main/java/top/leavesmc/leaves/bot/MojangAPI.java
new file mode 100644
index 0000000000000000000000000000000000000000..daaece30b2a3983f1cc9ee9a851e8f373974d5ec
index 0000000000000000000000000000000000000000..d6466ee4db637106e1394bb462d875e541e9731d
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/bot/MojangAPI.java
@@ -0,0 +1,41 @@
@@ -543,7 +544,7 @@ index 0000000000000000000000000000000000000000..daaece30b2a3983f1cc9ee9a851e8f37
+
+public class MojangAPI {
+
+ private static final boolean CACHE_ENABLED = false;
+ private static final boolean CACHE_ENABLED = true;
+
+ private static final Map<String, String[]> CACHE = new HashMap<>();
+
@@ -573,10 +574,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..a79122d986fc6bad91d1f90c8dd9ce5207b8ba7e
index 0000000000000000000000000000000000000000..1d3b2363e8d37de5ab417487f63a8f4320eb3d78
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/bot/ServerBot.java
@@ -0,0 +1,729 @@
@@ -0,0 +1,732 @@
+package top.leavesmc.leaves.bot;
+
+import com.google.common.collect.Lists;
@@ -669,7 +670,7 @@ index 0000000000000000000000000000000000000000..a79122d986fc6bad91d1f90c8dd9ce52
+
+ private ServerBot(MinecraftServer server, ServerLevel world, GameProfile profile) {
+ super(server, world, profile);
+ // this.entityData.set(new EntityDataAccessor<>(16, EntityDataSerializers.INT), 0xFF);
+ this.entityData.set(new EntityDataAccessor<>(16, EntityDataSerializers.INT), 0xFF);
+
+ this.velocity = new Vector(0, 0, 0);
+ this.oldVelocity = velocity.clone();
@@ -681,15 +682,18 @@ index 0000000000000000000000000000000000000000..a79122d986fc6bad91d1f90c8dd9ce52
+ this.removeOnDeath = true;
+ }
+
+ public static void createBot(Location loc, String name) {
+ public static void createBot(Location loc, String name, String skinName) {
+ if (!checkCreateLegal(name)) {
+ return;
+ }
+
+ Bukkit.getScheduler().runTaskAsynchronously(MINECRAFT_PLUGIN, () -> {
+ String[] skin = MojangAPI.getSkin(name);
+ Bukkit.getScheduler().runTask(MINECRAFT_PLUGIN, () -> createBot(loc, name, skin));
+ });
+ if (skinName != null) {
+ Bukkit.getScheduler().runTaskAsynchronously(MINECRAFT_PLUGIN, () -> {
+ String[] skin = MojangAPI.getSkin(skinName);
+ Bukkit.getScheduler().runTask(MINECRAFT_PLUGIN, () -> createBot(loc, name, skin));
+ });
+ } else {
+ createBot(loc, name, (String[]) null);
+ }
+ }
+
+ @Nullable
@@ -780,7 +784,7 @@ index 0000000000000000000000000000000000000000..a79122d986fc6bad91d1f90c8dd9ce52
+
+ private Packet<?>[] getRenderPackets() {
+ return new Packet[]{
+ new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED), List.of(this)),
+ new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME), List.of(this)),
+ new ClientboundAddPlayerPacket(this),
+ // new ClientboundSetEntityDataPacket(this.getId(), ),
+ new ClientboundRotateHeadPacket(this, (byte) ((getYRot() * 256f) / 360f))