3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-22 06:20:06 +01:00
Paper/nms-patches/EntityTrackerEntry.patch

172 Zeilen
7.1 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityTrackerEntry.java
+++ b/net/minecraft/server/EntityTrackerEntry.java
@@ -9,6 +9,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerVelocityEvent;
+// CraftBukkit end
+
2019-04-23 04:00:00 +02:00
public class EntityTrackerEntry {
2019-04-25 04:00:00 +02:00
private static final Logger LOGGER = LogManager.getLogger();
2019-04-23 04:00:00 +02:00
@@ -29,8 +34,12 @@
private List<Entity> p;
private boolean q;
private boolean r;
+ // CraftBukkit start
+ private final Set<EntityPlayer> trackedPlayers;
- public EntityTrackerEntry(WorldServer worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer) {
+ public EntityTrackerEntry(WorldServer worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer, Set<EntityPlayer> trackedPlayers) {
+ this.trackedPlayers = trackedPlayers;
+ // CraftBukkit end
this.m = Vec3D.a;
this.p = Collections.emptyList();
this.b = worldserver;
@@ -50,16 +59,17 @@
if (!list.equals(this.p)) {
this.p = list;
- this.f.accept(new PacketPlayOutMount(this.tracker));
+ this.broadcastIncludingSelf(new PacketPlayOutMount(this.tracker)); // CraftBukkit
}
2019-04-23 04:00:00 +02:00
- if (this.tracker instanceof EntityItemFrame && this.n % 10 == 0) {
2016-02-29 22:32:46 +01:00
+ // PAIL : rename
2019-04-23 04:00:00 +02:00
+ if (this.tracker instanceof EntityItemFrame /*&& this.n % 10 == 0*/) { // CraftBukkit - Moved below, should always enter this block
EntityItemFrame entityitemframe = (EntityItemFrame) this.tracker;
ItemStack itemstack = entityitemframe.getItem();
2016-11-17 02:41:03 +01:00
- if (itemstack.getItem() instanceof ItemWorldMap) {
2019-04-23 04:00:00 +02:00
+ if (this.n % 10 == 0 && itemstack.getItem() instanceof ItemWorldMap) { // CraftBukkit - Moved this.n % 10 logic here so item frames do not enter the other blocks
WorldMap worldmap = ItemWorldMap.getSavedMap(itemstack, this.b);
- Iterator iterator = this.b.getPlayers().iterator();
+ Iterator iterator = this.trackedPlayers.iterator(); // CraftBukkit
while (iterator.hasNext()) {
2019-04-23 04:00:00 +02:00
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
@@ -104,6 +114,17 @@
boolean flag2 = flag1 || this.n % 60 == 0;
boolean flag3 = Math.abs(i - this.yRot) >= 1 || Math.abs(j - this.xRot) >= 1;
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - Code moved from below
2019-04-23 04:00:00 +02:00
+ if (flag2) {
+ this.d();
+ }
+
2019-04-23 04:00:00 +02:00
+ if (flag3) {
+ this.yRot = i;
+ this.xRot = j;
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2019-04-23 04:00:00 +02:00
if (this.n > 0 || this.tracker instanceof EntityArrow) {
long k = PacketPlayOutEntity.a(vec3d.x);
long l = PacketPlayOutEntity.a(vec3d.y);
@@ -142,6 +163,7 @@
}
2019-04-23 04:00:00 +02:00
this.c();
+ /* CraftBukkit start - Code moved up
2019-04-23 04:00:00 +02:00
if (flag2) {
this.d();
}
@@ -150,6 +172,7 @@
this.yRot = i;
this.xRot = j;
}
+ // CraftBukkit end */
2019-04-23 04:00:00 +02:00
this.q = false;
2016-06-09 03:43:49 +02:00
}
2019-04-23 04:00:00 +02:00
@@ -165,7 +188,27 @@
2019-04-23 04:00:00 +02:00
++this.n;
if (this.tracker.velocityChanged) {
- this.broadcastIncludingSelf(new PacketPlayOutEntityVelocity(this.tracker));
+ // CraftBukkit start - Create PlayerVelocity event
+ boolean cancelled = false;
+
+ if (this.tracker instanceof EntityPlayer) {
+ Player player = (Player) this.tracker.getBukkitEntity();
+ org.bukkit.util.Vector velocity = player.getVelocity();
+
+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
+ this.tracker.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
+ } else if (!velocity.equals(event.getVelocity())) {
+ player.setVelocity(event.getVelocity());
+ }
+ }
+
+ if (!cancelled) {
+ this.broadcastIncludingSelf(new PacketPlayOutEntityVelocity(this.tracker));
+ }
+ // CraftBukkit end
this.tracker.velocityChanged = false;
}
2019-04-23 04:00:00 +02:00
@@ -180,14 +223,17 @@
PlayerConnection playerconnection = entityplayer.playerConnection;
entityplayer.playerConnection.getClass();
- this.a(playerconnection::sendPacket);
+ this.a(playerconnection::sendPacket, entityplayer); // CraftBukkit - add player
this.tracker.b(entityplayer);
entityplayer.d(this.tracker);
}
- public void a(Consumer<Packet<?>> consumer) {
+ public void a(Consumer<Packet<?>> consumer, EntityPlayer entityplayer) { // CraftBukkit - add player
if (this.tracker.dead) {
2019-06-21 12:00:00 +02:00
- EntityTrackerEntry.LOGGER.warn("Fetching packet for removed entity " + this.tracker);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start - Remove useless error spam, just return
2019-06-21 12:00:00 +02:00
+ // EntityTrackerEntry.LOGGER.warn("Fetching packet for removed entity " + this.tracker);
2019-04-23 04:00:00 +02:00
+ return;
+ // CraftBukkit end
}
Packet<?> packet = this.tracker.N();
@@ -204,6 +250,12 @@
AttributeMapServer attributemapserver = (AttributeMapServer) ((EntityLiving) this.tracker).getAttributeMap();
Collection<AttributeInstance> collection = attributemapserver.c();
+ // CraftBukkit start - If sending own attributes send scaled health instead of current maximum health
+ if (this.tracker.getId() == entityplayer.getId()) {
+ ((EntityPlayer) this.tracker).getBukkitEntity().injectScaledMaxHealth(collection, false);
+ }
+ // CraftBukkit end
+
if (!collection.isEmpty()) {
consumer.accept(new PacketPlayOutUpdateAttributes(this.tracker.getId(), collection));
}
@@ -232,6 +284,11 @@
}
}
+ // CraftBukkit start - Fix for nonsensical head yaw
+ this.headYaw = MathHelper.d(this.tracker.getHeadRotation() * 256.0F / 360.0F);
+ consumer.accept(new PacketPlayOutEntityHeadRotation(this.tracker, (byte) headYaw));
+ // CraftBukkit end
+
if (this.tracker instanceof EntityLiving) {
EntityLiving entityliving = (EntityLiving) this.tracker;
Iterator iterator = entityliving.getEffects().iterator();
@@ -265,6 +322,11 @@
2018-12-25 22:00:00 +01:00
Set<AttributeInstance> set = attributemapserver.getAttributes();
if (!set.isEmpty()) {
+ // CraftBukkit start - Send scaled max health
+ if (this.tracker instanceof EntityPlayer) {
+ ((EntityPlayer) this.tracker).getBukkitEntity().injectScaledMaxHealth(set, false);
+ }
+ // CraftBukkit end
this.broadcastIncludingSelf(new PacketPlayOutUpdateAttributes(this.tracker.getId(), set));
}