Patch consistent application of scoreboard teams (#2302)

* Patch consistent application of scoreboard teams

This corrects issues with scoreboard team logic by ensuring NPCs use a consistent internal name, rather than randomizing

* apply team name tag visible=false earlier
This commit is contained in:
Alex "mcmonkey" Goodwin 2020-08-28 07:43:14 -07:00 committed by GitHub
parent 31409f46e2
commit a79e8a571a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 41 deletions

View File

@ -33,10 +33,6 @@ public class HumanController extends AbstractEntityController {
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
String coloredName = npc.getFullName();
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
if (npc.requiresNameHologram()) {
name = npc.getId() + UUID.randomUUID().toString().replace("-", "");
name = name.substring(0, 16);
}
UUID uuid = npc.getUniqueId();
if (uuid.version() == 4) { // clear version
@ -46,6 +42,11 @@ public class HumanController extends AbstractEntityController {
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
String teamName = Util.getTeamName(uuid);
if (npc.requiresNameHologram()) {
name = teamName;
}
final GameProfile profile = new GameProfile(uuid, name);
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
@ -67,12 +68,14 @@ public class HumanController extends AbstractEntityController {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Util.getDummyScoreboard();
String teamName = Util.getTeamName(profile.getId());
Team team = scoreboard.getTeam(teamName);
int mode = 2;
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (npc.requiresNameHologram()) {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
mode = 0;
}
team.addPlayer(handle.getBukkitEntity());

View File

@ -33,10 +33,6 @@ public class HumanController extends AbstractEntityController {
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
String coloredName = npc.getFullName();
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
if (npc.requiresNameHologram()) {
name = npc.getId() + UUID.randomUUID().toString().replace("-", "");
name = name.substring(0, 16);
}
UUID uuid = npc.getUniqueId();
if (uuid.version() == 4) { // clear version
@ -46,6 +42,11 @@ public class HumanController extends AbstractEntityController {
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
String teamName = Util.getTeamName(uuid);
if (npc.requiresNameHologram()) {
name = teamName;
}
final GameProfile profile = new GameProfile(uuid, name);
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
@ -67,12 +68,14 @@ public class HumanController extends AbstractEntityController {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Util.getDummyScoreboard();
String teamName = Util.getTeamName(profile.getId());
Team team = scoreboard.getTeam(teamName);
int mode = 2;
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (npc.requiresNameHologram()) {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
mode = 0;
}
team.addPlayer(handle.getBukkitEntity());

View File

@ -33,10 +33,6 @@ public class HumanController extends AbstractEntityController {
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
String coloredName = npc.getFullName();
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
if (npc.requiresNameHologram()) {
name = npc.getId() + UUID.randomUUID().toString().replace("-", "");
name = name.substring(0, 16);
}
UUID uuid = npc.getUniqueId();
if (uuid.version() == 4) { // clear version
@ -46,6 +42,11 @@ public class HumanController extends AbstractEntityController {
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
String teamName = Util.getTeamName(uuid);
if (npc.requiresNameHologram()) {
name = teamName;
}
final GameProfile profile = new GameProfile(uuid, name);
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
@ -67,12 +68,14 @@ public class HumanController extends AbstractEntityController {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Util.getDummyScoreboard();
String teamName = Util.getTeamName(profile.getId());
Team team = scoreboard.getTeam(teamName);
int mode = 2;
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (npc.requiresNameHologram()) {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
mode = 0;
}
team.addPlayer(handle.getBukkitEntity());

View File

@ -33,10 +33,6 @@ public class HumanController extends AbstractEntityController {
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
String coloredName = npc.getFullName();
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
if (npc.requiresNameHologram()) {
name = npc.getId() + UUID.randomUUID().toString().replace("-", "");
name = name.substring(0, 16);
}
UUID uuid = npc.getUniqueId();
if (uuid.version() == 4) { // clear version
@ -46,6 +42,11 @@ public class HumanController extends AbstractEntityController {
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
String teamName = Util.getTeamName(uuid);
if (npc.requiresNameHologram()) {
name = teamName;
}
final GameProfile profile = new GameProfile(uuid, name);
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
@ -67,12 +68,14 @@ public class HumanController extends AbstractEntityController {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Util.getDummyScoreboard();
String teamName = Util.getTeamName(profile.getId());
Team team = scoreboard.getTeam(teamName);
int mode = 2;
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (npc.requiresNameHologram()) {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
mode = 0;
}
team.addPlayer(handle.getBukkitEntity());

View File

@ -33,10 +33,6 @@ public class HumanController extends AbstractEntityController {
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
String coloredName = npc.getFullName();
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
if (npc.requiresNameHologram()) {
name = npc.getId() + UUID.randomUUID().toString().replace("-", "");
name = name.substring(0, 16);
}
UUID uuid = npc.getUniqueId();
if (uuid.version() == 4) { // clear version
@ -46,6 +42,11 @@ public class HumanController extends AbstractEntityController {
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
String teamName = Util.getTeamName(uuid);
if (npc.requiresNameHologram()) {
name = teamName;
}
final GameProfile profile = new GameProfile(uuid, name);
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
@ -67,12 +68,14 @@ public class HumanController extends AbstractEntityController {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Util.getDummyScoreboard();
String teamName = Util.getTeamName(profile.getId());
Team team = scoreboard.getTeam(teamName);
int mode = 2;
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (npc.requiresNameHologram()) {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
mode = 0;
}
team.addPlayer(handle.getBukkitEntity());

View File

@ -33,10 +33,6 @@ public class HumanController extends AbstractEntityController {
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
String coloredName = npc.getFullName();
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
if (npc.requiresNameHologram()) {
name = npc.getId() + UUID.randomUUID().toString().replace("-", "");
name = name.substring(0, 16);
}
UUID uuid = npc.getUniqueId();
if (uuid.version() == 4) { // clear version
@ -46,6 +42,11 @@ public class HumanController extends AbstractEntityController {
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
String teamName = Util.getTeamName(uuid);
if (npc.requiresNameHologram()) {
name = teamName;
}
final GameProfile profile = new GameProfile(uuid, name);
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
@ -67,12 +68,14 @@ public class HumanController extends AbstractEntityController {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Util.getDummyScoreboard();
String teamName = Util.getTeamName(profile.getId());
Team team = scoreboard.getTeam(teamName);
int mode = 2;
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (npc.requiresNameHologram()) {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
mode = 0;
}
team.addPlayer(handle.getBukkitEntity());

View File

@ -33,10 +33,6 @@ public class HumanController extends AbstractEntityController {
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
String coloredName = npc.getFullName();
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
if (npc.requiresNameHologram()) {
name = npc.getId() + UUID.randomUUID().toString().replace("-", "");
name = name.substring(0, 16);
}
UUID uuid = npc.getUniqueId();
if (uuid.version() == 4) { // clear version
@ -45,6 +41,12 @@ public class HumanController extends AbstractEntityController {
msb |= 0x0000000000002000L;
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
String teamName = Util.getTeamName(uuid);
if (npc.requiresNameHologram()) {
name = teamName;
}
final GameProfile profile = new GameProfile(uuid, name);
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
@ -67,12 +69,14 @@ public class HumanController extends AbstractEntityController {
if (!Setting.USE_SCOREBOARD_TEAMS.asBoolean())
return;
Scoreboard scoreboard = Util.getDummyScoreboard();
String teamName = Util.getTeamName(profile.getId());
Team team = scoreboard.getTeam(teamName);
int mode = 2;
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (npc.requiresNameHologram()) {
team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
mode = 0;
}
team.addPlayer(handle.getBukkitEntity());

View File

@ -7,6 +7,7 @@ import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.NameTagVisibility;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
@ -33,10 +34,6 @@ public class HumanController extends AbstractEntityController {
final WorldServer nmsWorld = ((CraftWorld) at.getWorld()).getHandle();
String coloredName = npc.getFullName();
String name = coloredName.length() > 16 ? coloredName.substring(0, 16) : coloredName;
if (npc.requiresNameHologram()) {
name = npc.getId() + UUID.randomUUID().toString().replace("-", "");
name = name.substring(0, 16);
}
UUID uuid = npc.getUniqueId();
if (uuid.version() == 4) { // clear version
@ -46,6 +43,11 @@ public class HumanController extends AbstractEntityController {
uuid = new UUID(msb, uuid.getLeastSignificantBits());
}
final String teamName = Util.getTeamName(uuid);
if (npc.requiresNameHologram()) {
name = teamName;
}
final GameProfile profile = new GameProfile(uuid, name);
final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile,
@ -67,12 +69,14 @@ public class HumanController extends AbstractEntityController {
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
Scoreboard scoreboard = Util.getDummyScoreboard();
String teamName = Util.getTeamName(profile.getId());
Team team = scoreboard.getTeam(teamName);
int mode = 2;
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (npc.requiresNameHologram()) {
team.setNameTagVisibility(NameTagVisibility.NEVER);
}
mode = 0;
}
team.addPlayer(handle.getBukkitEntity());