Skip to content

Commit

Permalink
Optimize fakeplayer and fix a memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Dec 1, 2023
1 parent 717898a commit e8203ab
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1221,10 +1221,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..e362d4e67258901a8e9b1dacdbb4f95835141fc0
index 0000000000000000000000000000000000000000..02ef39695d921f804c2a89ae5cf7959c0c0e2903
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/bot/ServerBot.java
@@ -0,0 +1,714 @@
@@ -0,0 +1,722 @@
+package top.leavesmc.leaves.bot;
+
+import com.google.common.collect.Lists;
Expand Down Expand Up @@ -1366,10 +1366,18 @@ index 0000000000000000000000000000000000000000..e362d4e67258901a8e9b1dacdbb4f958
+
+ ServerBot bot = new ServerBot(server, world, profile);
+
+ bot.connection = new ServerGamePacketListenerImpl(server, new Connection(PacketFlow.SERVERBOUND) {
+ bot.connection = new ServerGamePacketListenerImpl(server, new Connection(PacketFlow.SERVERBOUND) { // ?
+ @Override
+ public void send(@NotNull Packet<?> packet) {
+ }
+
+ @Override
+ public void send(@NotNull Packet<?> packet, @Nullable PacketSendListener packetsendlistener) {
+ }
+
+ @Override
+ public void send(@NotNull Packet<?> packet, @Nullable PacketSendListener callbacks, boolean flush) {
+ }
+ }, bot, CommonListenerCookie.createInitial(profile));
+ bot.isRealPlayer = true;
+ bot.createState = state;
Expand Down Expand Up @@ -1534,20 +1542,20 @@ index 0000000000000000000000000000000000000000..e362d4e67258901a8e9b1dacdbb4f958
+ this.updateLocation();
+ this.updatePlayerPose();
+
+ /* Disable now
+ float health = getHealth();
+ float maxHealth = getMaxHealth();
+ float regenAmount = LeavesConfig.fakeplayerRegenAmount;
+ float amount;
+ if (server.getTickCount() % 20 == 0) {
+ float health = getHealth();
+ float maxHealth = getMaxHealth();
+ float regenAmount = LeavesConfig.fakeplayerRegenAmount * 20;
+ float amount;
+
+ if (health < maxHealth - regenAmount) {
+ amount = health + regenAmount;
+ } else {
+ amount = maxHealth;
+ }
+ if (health < maxHealth - regenAmount) {
+ amount = health + regenAmount;
+ } else {
+ amount = maxHealth;
+ }
+
+ this.setHealth(amount);
+ */
+ this.setHealth(amount);
+ }
+
+ BlockPos blockposition = this.getOnPosLegacy();
+ BlockState iblockdata = this.level().getBlockState(blockposition);
Expand Down

0 comments on commit e8203ab

Please sign in to comment.