Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try playerlist handling via EntityTrackerEntry instead of adhoc event…
… listening
- Loading branch information
Showing
7 changed files
with
96 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/net/citizensnpcs/util/nms/PlayerlistTrackerEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.citizensnpcs.util.nms; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import net.citizensnpcs.util.NMS; | ||
import net.minecraft.server.v1_8_R1.Entity; | ||
import net.minecraft.server.v1_8_R1.EntityPlayer; | ||
import net.minecraft.server.v1_8_R1.EntityTrackerEntry; | ||
import net.minecraft.server.v1_8_R1.EnumPlayerInfoAction; | ||
import net.minecraft.server.v1_8_R1.PacketPlayOutPlayerInfo; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
public class PlayerlistTrackerEntry extends EntityTrackerEntry { | ||
public PlayerlistTrackerEntry(Entity entity, int i, int j, boolean flag) { | ||
super(entity, i, j, flag); | ||
} | ||
|
||
public PlayerlistTrackerEntry(EntityTrackerEntry entry) { | ||
this(entry.tracker, entry.b, entry.c, getU(entry)); | ||
} | ||
|
||
@Override | ||
public void updatePlayer(EntityPlayer entityplayer) { | ||
if (entityplayer != this.tracker && c(entityplayer)) { | ||
if (!this.trackedPlayers.contains(entityplayer) | ||
&& ((entityplayer.u().getPlayerChunkMap().a(entityplayer, this.tracker.ae, this.tracker.ag)) || (this.tracker.attachedToPlayer))) { | ||
if ((this.tracker instanceof EntityPlayer)) { | ||
Player player = ((EntityPlayer) this.tracker).getBukkitEntity(); | ||
if (!entityplayer.getBukkitEntity().canSee(player)) { | ||
return; | ||
} | ||
entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo( | ||
EnumPlayerInfoAction.ADD_PLAYER, (EntityPlayer) this.tracker)); | ||
} | ||
} | ||
} | ||
super.updatePlayer(entityplayer); | ||
} | ||
|
||
private static boolean getU(EntityTrackerEntry entry) { | ||
try { | ||
return (Boolean) U.get(entry); | ||
} catch (IllegalArgumentException e) { | ||
e.printStackTrace(); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
private static Field U = NMS.getField(EntityTrackerEntry.class, "u"); | ||
} |