13
0
geforkt von Mirrors/Paper
Paper/nms-patches/EntityTrackerEntry.patch

172 Zeilen
7.2 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityTrackerEntry.java
+++ b/net/minecraft/server/EntityTrackerEntry.java
2020-06-25 02:00:00 +02:00
@@ -11,6 +11,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();
2020-06-25 02:00:00 +02:00
@@ -31,8 +36,12 @@
2019-04-23 04:00:00 +02:00
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;
2020-06-25 02:00:00 +02:00
@@ -52,16 +61,17 @@
2019-04-23 04:00:00 +02:00
if (!list.equals(this.p)) {
this.p = list;
- this.f.accept(new PacketPlayOutMount(this.tracker));
+ this.broadcastIncludingSelf(new PacketPlayOutMount(this.tracker)); // CraftBukkit
}
2019-12-10 23:00:00 +01:00
- if (this.tracker instanceof EntityItemFrame && this.tickCounter % 10 == 0) {
2016-02-29 22:32:46 +01:00
+ // PAIL : rename
2019-12-10 23:00:00 +01:00
+ 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();
2016-11-17 02:41:03 +01:00
- if (itemstack.getItem() instanceof ItemWorldMap) {
2019-12-10 23:00:00 +01:00
+ 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
2019-04-23 04:00:00 +02:00
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();
2020-06-25 02:00:00 +02:00
@@ -106,6 +116,17 @@
2019-12-10 23:00:00 +01:00
boolean flag2 = flag1 || this.tickCounter % 60 == 0;
2019-04-23 04:00:00 +02:00
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-12-10 23:00:00 +01:00
if (this.tickCounter > 0 || this.tracker instanceof EntityArrow) {
2019-04-23 04:00:00 +02:00
long k = PacketPlayOutEntity.a(vec3d.x);
long l = PacketPlayOutEntity.a(vec3d.y);
2020-06-25 02:00:00 +02:00
@@ -144,6 +165,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();
}
2020-06-25 02:00:00 +02:00
@@ -152,6 +174,7 @@
2019-04-23 04:00:00 +02:00
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
}
2020-06-25 02:00:00 +02:00
@@ -167,7 +190,27 @@
2019-12-10 23:00:00 +01:00
++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;
}
2020-06-25 02:00:00 +02:00
@@ -182,14 +225,17 @@
2019-04-23 04:00:00 +02:00
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
}
2020-06-25 02:00:00 +02:00
Packet<?> packet = this.tracker.O();
@@ -205,6 +251,12 @@
if (this.tracker instanceof EntityLiving) {
Collection<AttributeModifiable> collection = ((EntityLiving) this.tracker).getAttributeMap().b();
2019-04-23 04:00:00 +02:00
+ // 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));
}
2020-06-25 02:00:00 +02:00
@@ -238,6 +290,11 @@
2019-04-23 04:00:00 +02:00
}
}
+ // 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();
2020-06-25 02:00:00 +02:00
@@ -278,6 +335,11 @@
Set<AttributeModifiable> set = ((EntityLiving) this.tracker).getAttributeMap().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));
}