summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityTrackerEntry.patch
blob: 552eb3917deeef99714d4614a29573c0e0fc2d53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
--- /home/matt/mc-dev-private//net/minecraft/server/EntityTrackerEntry.java	2015-02-26 22:40:22.711608138 +0000
+++ src/main/java/net/minecraft/server/EntityTrackerEntry.java	2015-02-26 22:40:22.715608138 +0000
@@ -8,6 +8,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
+
 public class EntityTrackerEntry {
 
     private static final Logger p = LogManager.getLogger();
@@ -74,13 +79,13 @@
             this.broadcast(new PacketPlayOutAttachEntity(0, this.tracker, this.tracker.vehicle));
         }
 
-        if (this.tracker instanceof EntityItemFrame && this.m % 10 == 0) {
+        if (this.tracker instanceof EntityItemFrame /*&& this.m % 10 == 0*/) { // CraftBukkit - Moved below, should always enter this block
             EntityItemFrame entityitemframe = (EntityItemFrame) this.tracker;
             ItemStack itemstack = entityitemframe.getItem();
 
-            if (itemstack != null && itemstack.getItem() instanceof ItemWorldMap) {
+            if (this.m % 10 == 0 && itemstack != null && itemstack.getItem() instanceof ItemWorldMap) { // CraftBukkit - Moved this.m % 10 logic here so item frames do not enter the other blocks
                 WorldMap worldmap = Items.FILLED_MAP.getSavedMap(itemstack, this.tracker.world);
-                Iterator iterator = list.iterator();
+                Iterator iterator = this.trackedPlayers.iterator(); // CraftBukkit
 
                 while (iterator.hasNext()) {
                     EntityHuman entityhuman = (EntityHuman) iterator.next();
@@ -116,6 +121,19 @@
                 boolean flag = Math.abs(j1) >= 4 || Math.abs(k1) >= 4 || Math.abs(l1) >= 4 || this.m % 60 == 0;
                 boolean flag1 = Math.abs(l - this.yRot) >= 4 || Math.abs(i1 - this.xRot) >= 4;
 
+                // CraftBukkit start - Code moved from below
+                if (flag) {
+                    this.xLoc = i;
+                    this.yLoc = j;
+                    this.zLoc = k;
+                }
+
+                if (flag1) {
+                    this.yRot = l;
+                    this.xRot = i1;
+                }
+                // CraftBukkit end
+
                 if (this.m > 0 || this.tracker instanceof EntityArrow) {
                     if (j1 >= -128 && j1 < 128 && k1 >= -128 && k1 < 128 && l1 >= -128 && l1 < 128 && this.v <= 400 && !this.x && this.y == this.tracker.onGround) {
                         if ((!flag || !flag1) && !(this.tracker instanceof EntityArrow)) {
@@ -130,6 +148,11 @@
                     } else {
                         this.y = this.tracker.onGround;
                         this.v = 0;
+                        // CraftBukkit start - Refresh list of who can see a player before sending teleport packet
+                        if (this.tracker instanceof EntityPlayer) {
+                            this.scanPlayers(new java.util.ArrayList(this.trackedPlayers));
+                        }
+                        // CraftBukkit end
                         object = new PacketPlayOutEntityTeleport(this.tracker.getId(), i, j, k, (byte) l, (byte) i1, this.tracker.onGround);
                     }
                 }
@@ -154,6 +177,7 @@
                 }
 
                 this.b();
+                /* CraftBukkit start - Code moved up
                 if (flag) {
                     this.xLoc = i;
                     this.yLoc = j;
@@ -164,6 +188,7 @@
                     this.yRot = l;
                     this.xRot = i1;
                 }
+                // CraftBukkit end */
 
                 this.x = false;
             } else {
@@ -195,7 +220,27 @@
 
         ++this.m;
         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);
+                this.tracker.world.getServer().getPluginManager().callEvent(event);
+
+                if (event.isCancelled()) {
+                    cancelled = true;
+                } else if (!velocity.equals(event.getVelocity())) {
+                    player.setVelocity(velocity);
+                }
+            }
+
+            if (!cancelled) {
+                this.broadcastIncludingSelf(new PacketPlayOutEntityVelocity(this.tracker));
+            }
+            // CraftBukkit end
             this.tracker.velocityChanged = false;
         }
 
@@ -213,6 +258,11 @@
             Set 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));
             }
 
@@ -263,6 +313,16 @@
         if (entityplayer != this.tracker) {
             if (this.c(entityplayer)) {
                 if (!this.trackedPlayers.contains(entityplayer) && (this.e(entityplayer) || this.tracker.attachedToPlayer)) {
+                    // CraftBukkit start - respect vanish API
+                    if (this.tracker instanceof EntityPlayer) {
+                        Player player = ((EntityPlayer) this.tracker).getBukkitEntity();
+                        if (!entityplayer.getBukkitEntity().canSee(player)) {
+                            return;
+                        }
+                    }
+
+                    entityplayer.removeQueue.remove(Integer.valueOf(this.tracker.getId()));
+                    // CraftBukkit end
                     this.trackedPlayers.add(entityplayer);
                     Packet packet = this.c();
 
@@ -281,6 +341,12 @@
                         AttributeMapServer attributemapserver = (AttributeMapServer) ((EntityLiving) this.tracker).getAttributeMap();
                         Collection 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()) {
                             entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateAttributes(this.tracker.getId(), collection));
                         }
@@ -319,6 +385,11 @@
                         }
                     }
 
+                    // CraftBukkit start - Fix for nonsensical head yaw
+                    this.i = MathHelper.d(this.tracker.getHeadRotation() * 256.0F / 360.0F);
+                    this.broadcast(new PacketPlayOutEntityHeadRotation(this.tracker, (byte) i));
+                    // CraftBukkit end
+
                     if (this.tracker instanceof EntityLiving) {
                         EntityLiving entityliving = (EntityLiving) this.tracker;
                         Iterator iterator = entityliving.getEffects().iterator();
@@ -339,8 +410,10 @@
     }
 
     public boolean c(EntityPlayer entityplayer) {
-        double d0 = entityplayer.locX - (double) (this.xLoc / 32);
-        double d1 = entityplayer.locZ - (double) (this.zLoc / 32);
+        // CraftBukkit start - this.*Loc / 30 -> this.tracker.loc*
+        double d0 = entityplayer.locX - this.tracker.locX;
+        double d1 = entityplayer.locZ - this.tracker.locZ;
+        // CraftBukkit end
 
         return d0 >= (double) (-this.b) && d0 <= (double) this.b && d1 >= (double) (-this.b) && d1 <= (double) this.b && this.tracker.a(entityplayer);
     }
@@ -358,7 +431,10 @@
 
     private Packet c() {
         if (this.tracker.dead) {
-            EntityTrackerEntry.p.warn("Fetching addPacket for removed entity");
+            // CraftBukkit start - Remove useless error spam, just return
+            // EntityTrackerEntry.p.warn("Fetching addPacket for removed entity");
+            return null;
+            // CraftBukkit end
         }
 
         if (this.tracker instanceof EntityItem) {