Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

. #282

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
19 changes: 19 additions & 0 deletions patches/server/0107-Remove-random-damage-for-protection.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kirill <sprytex@users.noreply.github.com>
Date: Fri, 3 Jan 2025 21:55:01 +0500
Subject: [PATCH] Remove random damage for protection.


diff --git a/src/main/java/net/minecraft/server/EnchantmentManager.java b/src/main/java/net/minecraft/server/EnchantmentManager.java
index 98656815ff5b4a176e145162d0077c30cb1ea1a6..09c69dd4f984201a7bf1168623e8574918e41d36 100644
--- a/src/main/java/net/minecraft/server/EnchantmentManager.java
+++ b/src/main/java/net/minecraft/server/EnchantmentManager.java
@@ -148,7 +148,7 @@ public class EnchantmentManager {
EnchantmentManager.b.a = 0;
}

- return (EnchantmentManager.b.a + 1 >> 1) + EnchantmentManager.a.nextInt((EnchantmentManager.b.a >> 1) + 1);
+ return (EnchantmentManager.b.a + 1 >> 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add PandaSpigot comment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And since this changes the vanilla default, add an option in the config

}

public static float a(ItemStack itemstack, EnumMonsterType enummonstertype) {
54 changes: 54 additions & 0 deletions patches/server/0108-Prevent-chest-visual-open-bug.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Rejomy <sprytex@users.noreply.github.com>
Date: Fri, 10 Jan 2025 21:02:29 +0500
Subject: [PATCH] Prevent chest visual open bug.


diff --git a/src/main/java/com/hpfxd/pandaspigot/config/PandaSpigotConfig.java b/src/main/java/com/hpfxd/pandaspigot/config/PandaSpigotConfig.java
index 1d8e4d1050ebafef8784920481621965fd5c212f..66bb8b59e406a54e10a2291e0615c3e2b6b24285 100644
--- a/src/main/java/com/hpfxd/pandaspigot/config/PandaSpigotConfig.java
+++ b/src/main/java/com/hpfxd/pandaspigot/config/PandaSpigotConfig.java
@@ -94,6 +94,9 @@ public class PandaSpigotConfig {
public static PandaSpigotConfig get() {
return config;
}
+
+ @Comment("Prevent chest and sound bugs.")
+ public boolean dropUsePacketsInInventory = true;

//------------------------------------------------------------------------
@Comment("On servers with plugins that constantly churn through scoreboards, there is a risk of\n" +
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 40dc1eb6a86dede8377775ad2776fd9193d24cbc..0b1d3f5c79bf3ca9a9b2a3b51f39db225493d8c5 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.google.common.primitives.Doubles;
import com.google.common.primitives.Floats;
import com.google.common.util.concurrent.Futures;
+import com.hpfxd.pandaspigot.config.PandaSpigotConfig;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to say this in a simple way, but instead of importing it is preferable to use com.hpfxd.pandaspigot.config.PandaSpigotConfig.get() directly below, to avoid unnecessary diff

import io.netty.buffer.Unpooled;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
@@ -24,6 +25,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.HashSet;

+import org.bukkit.Bukkit;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary import

import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftInventoryView;
@@ -658,6 +660,13 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
// CraftBukkit start
if (this.player.dead) return;

+ // Rejomy patch Use packets while inventory is open.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change comments to "// PandaSpigot start", "// PandaSpigot end"

+ // Even if inventory is not open active container will equals player inventory same with defaultContainer.
+ if (PandaSpigotConfig.get().dropUsePacketsInInventory && player.activeContainer != player.defaultContainer) {
+ return;
+ }
+ // Rejomy patch End
+
// CraftBukkit - if rightclick decremented the item, always send the update packet. */
// this is not here for CraftBukkit's own functionality; rather it is to fix
// a notch bug where the item doesn't update correctly.
39 changes: 39 additions & 0 deletions patches/server/0109-Reset-NaN-Entity-Values.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 750a22a1f122a92275eebd14b555ea0482010b54 Mon Sep 17 00:00:00 2001
From: LinsaFTW <25271111+linsaftw@users.noreply.github.com>
Date: Fri, 13 Jan 2023 17:02:17 -0300
Subject: [PATCH] Reset NaN Entity Values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can these values ​​be null? Exploits?



diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 5971e4375..2d48d02ab 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1204,6 +1204,12 @@ public abstract class Entity implements ICommandListener {

public void e(NBTTagCompound nbttagcompound) {
try {
+ // FlamePaper start - Reset NaN Entity Values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change comments to "// PandaSpigot start", "// PandaSpigot end"

+ if (Double.isNaN(locX)) this.locX = 0;
+ if (Double.isNaN(locY)) this.locY = 0;
+ if (Double.isNaN(locZ)) this.locZ = 0;
+ // FlamePaper start - Reset NaN Entity Values
+
nbttagcompound.set("Pos", this.a(new double[] { this.locX, this.locY, this.locZ}));
nbttagcompound.set("Motion", this.a(new double[] { this.motX, this.motY, this.motZ}));

diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index d44fc62b9..a0269fbe0 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1374,7 +1374,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

@Override
public double getHealth() {
- return health;
+ return Double.isNaN(health) ? 0.0D : health; // FlamePaper - Reset NaN Entity Values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change comment to "// PandaSpigot -",

}

public void setRealHealth(double health) {
--
2.37.3.windows.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: necrozma <necrozma999@gmail.com>
Date: Fri, 14 Jul 2023 22:16:17 -0600
Subject: [PATCH] Ensure correct attack damage on slot change
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly @ThatApplePieGuy closed the original pullrequest because the patch didn't fix the problem 100%



diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index 86ab9994079c6e18e3aed885db4171d0d87b4c1a..10284da163e2f1d1b5f12ca738a8fc5580d1373b 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -692,6 +692,7 @@ public abstract class EntityHuman extends EntityLiving {
NBTTagList nbttaglist = nbttagcompound.getList("Inventory", 10);

this.inventory.b(nbttaglist);
+ this.inventory.prevItemInHandIndex = this.inventory.itemInHandIndex; // PandaSpigot
this.inventory.itemInHandIndex = nbttagcompound.getInt("SelectedItemSlot");
this.sleeping = nbttagcompound.getBoolean("Sleeping");
this.sleepTicks = nbttagcompound.getShort("SleepTimer");
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 94d8f2ffe938bd2d57d0297f9efc43ee55da3ba9..95c92fe5a1f1866da16fb991d29c6de1671684d6 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -34,7 +34,7 @@ public abstract class EntityLiving extends Entity {

private static final UUID a = UUID.fromString("662A6B8D-DA3E-4C1C-8813-96EA6097278D");
private static final AttributeModifier b = (new AttributeModifier(EntityLiving.a, "Sprinting speed boost", 0.30000001192092896D, 2)).a(false);
- private AttributeMapBase c;
+ public AttributeMapBase c; // PandaSpigot
public CombatTracker combatTracker = new CombatTracker(this);
public final Map<Integer, MobEffect> effects = Maps.newHashMap();
private final ItemStack[] h = new ItemStack[5];
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 23bd5d11f8b909817855f593adc51d3ca5d9f976..eb56c4ee33c756bc7adfed0e76ef516b5c0566da 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -963,8 +963,20 @@ public class PlayerConnection implements PacketListenerPlayIn, IUpdatePlayerList
return;
}
// CraftBukkit end
+ this.player.inventory.prevItemInHandIndex = this.player.inventory.itemInHandIndex; // PandaSpigot
this.player.inventory.itemInHandIndex = packetplayinhelditemslot.a();
this.player.resetIdleTimer();
+ // PandaSpigot start - ensure correct attack damage on slot change
+ ItemStack prevItemStack = this.player.inventory.items[this.player.inventory.prevItemInHandIndex];
+ if (prevItemStack != null) {
+ for (AttributeModifier attributemodifier : prevItemStack.B().get("generic.attackDamage")) {
+ this.player.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).c(attributemodifier); // remove attack damage from previous held item
+ }
+ }
+ if (this.player.inventory.getItemInHand() != null) {
+ ((EntityLiving) this.player).c.b(this.player.inventory.getItemInHand().B()); // apply attack damage from current held item
+ }
+ // PandaSpigot end
} else {
PlayerConnection.c.warn(this.player.getName() + " tried to set an invalid carried item");
this.disconnect("Invalid hotbar selection (Hacking?)"); // CraftBukkit //Spigot "Nope" -> Descriptive reason
diff --git a/src/main/java/net/minecraft/server/PlayerInventory.java b/src/main/java/net/minecraft/server/PlayerInventory.java
index 76fa51d97e9a938d4198bbe657d77900f6327744..3a8c600b7d80a46be0c33f0f6b50b751b764eb49 100644
--- a/src/main/java/net/minecraft/server/PlayerInventory.java
+++ b/src/main/java/net/minecraft/server/PlayerInventory.java
@@ -14,6 +14,7 @@ public class PlayerInventory implements IInventory {
public ItemStack[] items = new ItemStack[36];
public ItemStack[] armor = new ItemStack[4];
public int itemInHandIndex;
+ public int prevItemInHandIndex; // PandaSpigot
public EntityHuman player;
private ItemStack f;
public boolean e;
@@ -571,6 +572,7 @@ public class PlayerInventory implements IInventory {
this.armor[i] = ItemStack.b(playerinventory.armor[i]);
}

+ this.prevItemInHandIndex = playerinventory.prevItemInHandIndex; // PandaSpigot
this.itemInHandIndex = playerinventory.itemInHandIndex;
}

diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
index dba8d5ba1df8c04d8988af9b1e3329269e9a1942..202975055eda4e66e922b7d67d84ad30973591b0 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java
@@ -81,6 +81,7 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i

public void setHeldItemSlot(int slot) {
Validate.isTrue(slot >= 0 && slot < PlayerInventory.getHotbarSize(), "Slot is not between 0 and 8 inclusive");
+ this.getInventory().prevItemInHandIndex = this.getInventory().itemInHandIndex; // PandaSpigot
this.getInventory().itemInHandIndex = slot;
((CraftPlayer) this.getHolder()).getHandle().playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(slot));
}