mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-18 08:36:13 +01:00
172 lines
7.2 KiB
Diff
172 lines
7.2 KiB
Diff
--- 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
|
|
+
|
|
public class EntityTrackerEntry {
|
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
@@ -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
|
|
}
|
|
|
|
- if (this.tracker instanceof EntityItemFrame && this.tickCounter % 10 == 0) {
|
|
+ // PAIL : rename
|
|
+ if (this.tracker instanceof EntityItemFrame /*&& this.tickCounter % 10 == 0*/) { // CraftBukkit - Moved below, should always enter this block
|
|
EntityItemFrame entityitemframe = (EntityItemFrame) this.tracker;
|
|
ItemStack itemstack = entityitemframe.getItem();
|
|
|
|
- if (itemstack.getItem() instanceof ItemWorldMap) {
|
|
+ if (this.tickCounter % 10 == 0 && itemstack.getItem() instanceof ItemWorldMap) { // CraftBukkit - Moved this.tickCounter % 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()) {
|
|
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
|
|
@@ -104,6 +114,17 @@
|
|
boolean flag2 = flag1 || this.tickCounter % 60 == 0;
|
|
boolean flag3 = Math.abs(i - this.yRot) >= 1 || Math.abs(j - this.xRot) >= 1;
|
|
|
|
+ // CraftBukkit start - Code moved from below
|
|
+ if (flag2) {
|
|
+ this.d();
|
|
+ }
|
|
+
|
|
+ if (flag3) {
|
|
+ this.yRot = i;
|
|
+ this.xRot = j;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
if (this.tickCounter > 0 || this.tracker instanceof EntityArrow) {
|
|
long k = PacketPlayOutEntity.a(vec3d.x);
|
|
long l = PacketPlayOutEntity.a(vec3d.y);
|
|
@@ -142,6 +163,7 @@
|
|
}
|
|
|
|
this.c();
|
|
+ /* CraftBukkit start - Code moved up
|
|
if (flag2) {
|
|
this.d();
|
|
}
|
|
@@ -150,6 +172,7 @@
|
|
this.yRot = i;
|
|
this.xRot = j;
|
|
}
|
|
+ // CraftBukkit end */
|
|
|
|
this.q = false;
|
|
}
|
|
@@ -165,7 +188,27 @@
|
|
|
|
++this.tickCounter;
|
|
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;
|
|
}
|
|
|
|
@@ -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) {
|
|
- EntityTrackerEntry.LOGGER.warn("Fetching packet for removed entity " + this.tracker);
|
|
+ // CraftBukkit start - Remove useless error spam, just return
|
|
+ // EntityTrackerEntry.LOGGER.warn("Fetching packet for removed entity " + this.tracker);
|
|
+ return;
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
Packet<?> packet = this.tracker.L();
|
|
@@ -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();
|
|
@@ -273,6 +330,11 @@
|
|
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));
|
|
}
|
|
|