Skip to content

Commit

Permalink
Fix fakeplayer resident? (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed May 22, 2023
1 parent 828bfd9 commit 8178d44
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions patches/server/0009-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,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..f3138e662d7cb58b083e202cd3c623d6ff3bc33d
index 0000000000000000000000000000000000000000..a609b0ff323ea4bc8a23a2b8be0d01c9e9d54d92
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/bot/BotUtil.java
@@ -0,0 +1,141 @@
@@ -0,0 +1,147 @@
+package top.leavesmc.leaves.bot;
+
+import com.google.gson.JsonElement;
Expand Down Expand Up @@ -885,10 +885,14 @@ index 0000000000000000000000000000000000000000..f3138e662d7cb58b083e202cd3c623d6
+ invnbt.put("Inventory", bot.getInventory().save(new ListTag()));
+
+ File file = MinecraftServer.getServer().getWorldPath(LevelResource.ROOT).resolve("fakeplayer/" + uuid + ".dat").toFile();
+ if (file.isFile()) {
+ file.delete();
+ }
+ File parent = file.getParentFile();
+ try {
+ if (!parent.exists() || !parent.isDirectory()) {
+ parent.mkdirs();
+ }
+ if (file.exists() && file.isFile()) {
+ file.delete();
+ }
+ file.createNewFile();
+ NbtIo.writeCompressed(invnbt, file);
+ } catch (IOException e) {
Expand All @@ -914,13 +918,15 @@ index 0000000000000000000000000000000000000000..f3138e662d7cb58b083e202cd3c623d6
+ if (fakePlayer.has("invuuid")) {
+ String uuid = fakePlayer.get("invuuid").getAsString();
+ File file = MinecraftServer.getServer().getWorldPath(LevelResource.ROOT).resolve("fakeplayer/" + uuid + ".dat").toFile();
+ try {
+ CompoundTag nbt = NbtIo.readCompressed(file);
+ inv = nbt.getList("Inventory", 10);
+ } catch (IOException e) {
+ e.printStackTrace();
+ if (file.exists()) {
+ try {
+ CompoundTag nbt = NbtIo.readCompressed(file);
+ inv = nbt.getList("Inventory", 10);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ file.delete();
+ }
+ file.delete();
+ }
+
+ ServerBot.createBot(new Location(Bukkit.getWorld(dimension), pos_x, pos_y, pos_z, yaw, pitch),
Expand Down

0 comments on commit 8178d44

Please sign in to comment.