mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-22 23:31:31 +01:00
Fix for client NPE issue - don't missend player spawn packets (#1525)
* Fix #1360 - don't missend player spawn packets Player spawn packets were improperly sent by the Minecraft internals in early NPC spawn sequence, when they are not valid to be sent yet. This patch blocks their sending until the tracker system is pushed onto the NPC. Tested and functional. * improve long name cutting order, fixes #1422 ensures that root name will always be 16 characters if the given name was too long - previously, the root name could be as small as a single character (for input name of 17 characters).
This commit is contained in:
parent
42fda25ceb
commit
221eb4b8d5
@ -74,6 +74,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
private int updateCounter = 0;
|
||||
private boolean isTracked = false;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
PlayerInteractManager playerInteractManager, NPC npc) {
|
||||
@ -89,6 +90,18 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
|
||||
public void setTracked() {
|
||||
isTracked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityPlayer entityplayer) {
|
||||
if (npc != null && !isTracked) {
|
||||
return false;
|
||||
}
|
||||
return super.a(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
|
@ -37,8 +37,8 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
String name = coloredName, prefix = null, suffix = null;
|
||||
if (coloredName.length() > 16) {
|
||||
prefix = coloredName.substring(0, 16);
|
||||
if (coloredName.length() >= 30) {
|
||||
prefix = coloredName.substring(0, 16);
|
||||
int len = 30;
|
||||
name = coloredName.substring(16, 30);
|
||||
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
|
||||
@ -54,7 +54,8 @@ public class HumanController extends AbstractEntityController {
|
||||
}
|
||||
suffix = coloredName.substring(len);
|
||||
} else {
|
||||
name = coloredName.substring(16);
|
||||
prefix = coloredName.substring(0, coloredName.length() - 16);
|
||||
name = coloredName.substring(prefix.length());
|
||||
if (!NON_ALPHABET_MATCHER.matcher(name).matches()) {
|
||||
name = ChatColor.RESET + name;
|
||||
}
|
||||
|
@ -756,6 +756,9 @@ public class NMSImpl implements NMSBridge {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
||||
((EntityHumanNPC) getHandle(player)).setTracked();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,6 +76,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
private int updateCounter = 0;
|
||||
private boolean isTracked = false;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
PlayerInteractManager playerInteractManager, NPC npc) {
|
||||
@ -91,6 +92,18 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
|
||||
public void setTracked() {
|
||||
isTracked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityPlayer entityplayer) {
|
||||
if (npc != null && !isTracked) {
|
||||
return false;
|
||||
}
|
||||
return super.a(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
|
@ -37,8 +37,8 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
String name = coloredName, prefix = null, suffix = null;
|
||||
if (coloredName.length() > 16) {
|
||||
prefix = coloredName.substring(0, 16);
|
||||
if (coloredName.length() >= 30) {
|
||||
prefix = coloredName.substring(0, 16);
|
||||
int len = 30;
|
||||
name = coloredName.substring(16, 30);
|
||||
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
|
||||
@ -54,7 +54,8 @@ public class HumanController extends AbstractEntityController {
|
||||
}
|
||||
suffix = coloredName.substring(len);
|
||||
} else {
|
||||
name = coloredName.substring(16);
|
||||
prefix = coloredName.substring(0, coloredName.length() - 16);
|
||||
name = coloredName.substring(prefix.length());
|
||||
if (!NON_ALPHABET_MATCHER.matcher(name).matches()) {
|
||||
name = ChatColor.RESET + name;
|
||||
}
|
||||
|
@ -814,6 +814,9 @@ public class NMSImpl implements NMSBridge {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
||||
((EntityHumanNPC) getHandle(player)).setTracked();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,6 +79,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
private int updateCounter = 0;
|
||||
private boolean isTracked = false;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
PlayerInteractManager playerInteractManager, NPC npc) {
|
||||
@ -94,6 +95,18 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
|
||||
public void setTracked() {
|
||||
isTracked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityPlayer entityplayer) {
|
||||
if (npc != null && !isTracked) {
|
||||
return false;
|
||||
}
|
||||
return super.a(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockposition) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
|
@ -37,8 +37,8 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
String name = coloredName, prefix = null, suffix = null;
|
||||
if (coloredName.length() > 16) {
|
||||
prefix = coloredName.substring(0, 16);
|
||||
if (coloredName.length() >= 30) {
|
||||
prefix = coloredName.substring(0, 16);
|
||||
int len = 30;
|
||||
name = coloredName.substring(16, 30);
|
||||
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
|
||||
@ -54,7 +54,8 @@ public class HumanController extends AbstractEntityController {
|
||||
}
|
||||
suffix = coloredName.substring(len);
|
||||
} else {
|
||||
name = coloredName.substring(16);
|
||||
prefix = coloredName.substring(0, coloredName.length() - 16);
|
||||
name = coloredName.substring(prefix.length());
|
||||
if (!NON_ALPHABET_MATCHER.matcher(name).matches()) {
|
||||
name = ChatColor.RESET + name;
|
||||
}
|
||||
|
@ -821,6 +821,9 @@ public class NMSImpl implements NMSBridge {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
||||
((EntityHumanNPC) getHandle(player)).setTracked();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,6 +68,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
private int updateCounter = 0;
|
||||
private boolean isTracked = false;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
PlayerInteractManager playerInteractManager, NPC npc) {
|
||||
@ -83,6 +84,18 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
|
||||
public void setTracked() {
|
||||
isTracked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityPlayer entityplayer) {
|
||||
if (npc != null && !isTracked) {
|
||||
return false;
|
||||
}
|
||||
return super.a(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void a(double d0, boolean flag, Block block, BlockPosition blockposition) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
|
@ -37,8 +37,8 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
String name = coloredName, prefix = null, suffix = null;
|
||||
if (coloredName.length() > 16) {
|
||||
prefix = coloredName.substring(0, 16);
|
||||
if (coloredName.length() >= 30) {
|
||||
prefix = coloredName.substring(0, 16);
|
||||
int len = 30;
|
||||
name = coloredName.substring(16, 30);
|
||||
if (NON_ALPHABET_MATCHER.matcher(name).matches()) {
|
||||
@ -54,7 +54,8 @@ public class HumanController extends AbstractEntityController {
|
||||
}
|
||||
suffix = coloredName.substring(len);
|
||||
} else {
|
||||
name = coloredName.substring(16);
|
||||
prefix = coloredName.substring(0, coloredName.length() - 16);
|
||||
name = coloredName.substring(prefix.length());
|
||||
if (!NON_ALPHABET_MATCHER.matcher(name).matches()) {
|
||||
name = ChatColor.RESET + name;
|
||||
}
|
||||
|
@ -711,6 +711,9 @@ public class NMSImpl implements NMSBridge {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (getHandle(player) instanceof EntityHumanNPC) {
|
||||
((EntityHumanNPC) getHandle(player)).setTracked();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user