diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index e95404e67..06f1ce883 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -52,7 +52,6 @@ import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.scheduler.BukkitRunnable; -import org.bukkit.scoreboard.Team; import com.google.common.base.Predicates; import com.google.common.collect.ArrayListMultimap; @@ -433,24 +432,6 @@ public class EventListen implements Listener { + event.getReason().name()); } skinUpdateTracker.onNPCDespawn(event.getNPC()); - if (!Setting.USE_SCOREBOARD_TEAMS.asBoolean()) - return; - String teamName = event.getNPC().data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, ""); - if (teamName.isEmpty()) - return; - Team team = Util.getDummyScoreboard().getTeam(teamName); - event.getNPC().data().remove(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA); - if (team == null || !(event.getNPC().getEntity() instanceof Player)) - return; - Player player = (Player) event.getNPC().getEntity(); - if (team.hasPlayer(player)) { - if (team.getSize() == 1) { - Util.sendTeamPacketToOnlinePlayers(team, 1); - team.unregister(); - } else { - team.removePlayer(player); - } - } } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) diff --git a/main/src/main/java/net/citizensnpcs/util/Util.java b/main/src/main/java/net/citizensnpcs/util/Util.java index 11da9133c..e5f04261b 100644 --- a/main/src/main/java/net/citizensnpcs/util/Util.java +++ b/main/src/main/java/net/citizensnpcs/util/Util.java @@ -99,6 +99,22 @@ public class Util { NMS.look(entity, to, headOnly, immediate); } + public static void generateTeamFor(NPC npc, String name, String teamName) { + Scoreboard scoreboard = getDummyScoreboard(); + Team team = scoreboard.getTeam(teamName); + int mode = 2; + if (team == null) { + team = scoreboard.registerNewTeam(teamName); + if (npc.requiresNameHologram() || npc.data(). get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString().equals("false")) { + NMS.setTeamNameTagVisible(team, false); + } + mode = 0; + } + team.addEntry(name); + npc.data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); + sendTeamPacketToOnlinePlayers(team, mode); + } + public static Scoreboard getDummyScoreboard() { return DUMMY_SCOREBOARD; } @@ -266,6 +282,24 @@ public class Util { to.getBlockZ(), (int) to.getYaw(), (int) to.getPitch()); } + public static void removeTeamFor(NPC npc, String name) { + String teamName = npc.data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, ""); + if (teamName.isEmpty()) + return; + Team team = getDummyScoreboard().getTeam(teamName); + npc.data().remove(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA); + if (team == null) + return; + if (team.hasEntry(name)) { + if (team.getSize() == 1) { + sendTeamPacketToOnlinePlayers(team, 1); + team.unregister(); + } else { + team.removeEntry(name); + } + } + } + /** * @param mode * 0 for create, 1 for remove, 2 for update diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/HumanController.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/HumanController.java index 853c4ba96..658944532 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/HumanController.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/entity/HumanController.java @@ -7,8 +7,6 @@ import org.bukkit.Location; import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; import com.mojang.authlib.GameProfile; @@ -47,6 +45,10 @@ public class HumanController extends AbstractEntityController { name = teamName; } + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.generateTeamFor(npc, name, teamName); + } + final GameProfile profile = new GameProfile(uuid, name); final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, @@ -66,25 +68,6 @@ public class HumanController extends AbstractEntityController { boolean removeFromPlayerList = npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList); - - if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { - Scoreboard scoreboard = Util.getDummyScoreboard(); - - 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()); - - handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); - - Util.sendTeamPacketToOnlinePlayers(team, mode); - } } }, 20); @@ -102,6 +85,9 @@ public class HumanController extends AbstractEntityController { public void remove() { Player entity = getBukkitEntity(); if (entity != null) { + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.removeTeamFor(NMS.getNPC(entity), entity.getName()); + } NMS.removeFromWorld(entity); SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null; npc.getSkinTracker().onRemoveNPC(); diff --git a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java index d4f5509d2..96f10b618 100644 --- a/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java +++ b/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/NMSImpl.java @@ -1037,16 +1037,7 @@ public class NMSImpl implements NMSBridge { @Override public void setTeamNameTagVisible(Team team, boolean visible) { - if (TEAM_FIELD == null) { - TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); - } - ScoreboardTeam nmsTeam; - try { - nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); - nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); - } catch (Throwable e) { - e.printStackTrace(); - } + team.setOption(Team.Option.NAME_TAG_VISIBILITY, visible ? Team.OptionStatus.ALWAYS : Team.OptionStatus.NEVER); } @Override diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HumanController.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HumanController.java index ad6092ef9..d1b9f771d 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HumanController.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/entity/HumanController.java @@ -7,8 +7,6 @@ import org.bukkit.Location; import org.bukkit.craftbukkit.v1_11_R1.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; import com.mojang.authlib.GameProfile; @@ -47,6 +45,10 @@ public class HumanController extends AbstractEntityController { name = teamName; } + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.generateTeamFor(npc, name, teamName); + } + final GameProfile profile = new GameProfile(uuid, name); final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, @@ -66,25 +68,6 @@ public class HumanController extends AbstractEntityController { boolean removeFromPlayerList = npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList); - - if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { - Scoreboard scoreboard = Util.getDummyScoreboard(); - - 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()); - - handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); - - Util.sendTeamPacketToOnlinePlayers(team, mode); - } } }, 20); @@ -102,6 +85,9 @@ public class HumanController extends AbstractEntityController { public void remove() { Player entity = getBukkitEntity(); if (entity != null) { + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.removeTeamFor(NMS.getNPC(entity), entity.getName()); + } NMS.removeFromWorld(entity); SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null; npc.getSkinTracker().onRemoveNPC(); diff --git a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java index 2e26d5d0a..8bff6e99e 100644 --- a/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java +++ b/v1_11_R1/src/main/java/net/citizensnpcs/nms/v1_11_R1/util/NMSImpl.java @@ -219,7 +219,6 @@ import net.minecraft.server.v1_11_R1.PathfinderGoalSelector; import net.minecraft.server.v1_11_R1.RegistryMaterials; import net.minecraft.server.v1_11_R1.ReportedException; import net.minecraft.server.v1_11_R1.ScoreboardTeam; -import net.minecraft.server.v1_11_R1.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_11_R1.SoundEffect; import net.minecraft.server.v1_11_R1.Vec3D; import net.minecraft.server.v1_11_R1.WorldServer; @@ -1094,16 +1093,7 @@ public class NMSImpl implements NMSBridge { @Override public void setTeamNameTagVisible(Team team, boolean visible) { - if (TEAM_FIELD == null) { - TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); - } - ScoreboardTeam nmsTeam; - try { - nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); - nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); - } catch (Throwable e) { - e.printStackTrace(); - } + team.setOption(Team.Option.NAME_TAG_VISIBILITY, visible ? Team.OptionStatus.ALWAYS : Team.OptionStatus.NEVER); } @Override diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/HumanController.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/HumanController.java index b5a3d0812..b8b88b6de 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/HumanController.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/entity/HumanController.java @@ -7,8 +7,6 @@ import org.bukkit.Location; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; import com.mojang.authlib.GameProfile; @@ -47,6 +45,10 @@ public class HumanController extends AbstractEntityController { name = teamName; } + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.generateTeamFor(npc, name, teamName); + } + final GameProfile profile = new GameProfile(uuid, name); final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, @@ -66,25 +68,6 @@ public class HumanController extends AbstractEntityController { boolean removeFromPlayerList = npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList); - - if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { - Scoreboard scoreboard = Util.getDummyScoreboard(); - - 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()); - - handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); - - Util.sendTeamPacketToOnlinePlayers(team, mode); - } } }, 20); @@ -102,6 +85,9 @@ public class HumanController extends AbstractEntityController { public void remove() { Player entity = getBukkitEntity(); if (entity != null) { + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.removeTeamFor(NMS.getNPC(entity), entity.getName()); + } NMS.removeFromWorld(entity); SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null; npc.getSkinTracker().onRemoveNPC(); diff --git a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java index d3cc9d634..586aab26c 100644 --- a/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java +++ b/v1_12_R1/src/main/java/net/citizensnpcs/nms/v1_12_R1/util/NMSImpl.java @@ -25,7 +25,6 @@ import org.bukkit.boss.BossBar; import org.bukkit.craftbukkit.v1_12_R1.CraftServer; import org.bukkit.craftbukkit.v1_12_R1.CraftSound; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock; import org.bukkit.craftbukkit.v1_12_R1.boss.CraftBossBar; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; @@ -224,7 +223,6 @@ import net.minecraft.server.v1_12_R1.PathfinderGoalSelector; import net.minecraft.server.v1_12_R1.RegistryMaterials; import net.minecraft.server.v1_12_R1.ReportedException; import net.minecraft.server.v1_12_R1.ScoreboardTeam; -import net.minecraft.server.v1_12_R1.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_12_R1.SoundEffect; import net.minecraft.server.v1_12_R1.SoundEffects; import net.minecraft.server.v1_12_R1.Vec3D; @@ -1103,16 +1101,7 @@ public class NMSImpl implements NMSBridge { @Override public void setTeamNameTagVisible(Team team, boolean visible) { - if (TEAM_FIELD == null) { - TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); - } - ScoreboardTeam nmsTeam; - try { - nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); - nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); - } catch (Throwable e) { - e.printStackTrace(); - } + team.setOption(Team.Option.NAME_TAG_VISIBILITY, visible ? Team.OptionStatus.ALWAYS : Team.OptionStatus.NEVER); } @Override diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/HumanController.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/HumanController.java index ee82c4cad..8de295143 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/HumanController.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/entity/HumanController.java @@ -7,8 +7,6 @@ import org.bukkit.Location; import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; import com.mojang.authlib.GameProfile; @@ -47,6 +45,10 @@ public class HumanController extends AbstractEntityController { name = teamName; } + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.generateTeamFor(npc, name, teamName); + } + final GameProfile profile = new GameProfile(uuid, name); final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, @@ -66,25 +68,6 @@ public class HumanController extends AbstractEntityController { boolean removeFromPlayerList = npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList); - - if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { - Scoreboard scoreboard = Util.getDummyScoreboard(); - - 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()); - - handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); - - Util.sendTeamPacketToOnlinePlayers(team, mode); - } } }, 20); @@ -102,6 +85,9 @@ public class HumanController extends AbstractEntityController { public void remove() { Player entity = getBukkitEntity(); if (entity != null) { + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.removeTeamFor(NMS.getNPC(entity), entity.getName()); + } NMS.removeFromWorld(entity); SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null; npc.getSkinTracker().onRemoveNPC(); diff --git a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java index fa7513c9e..a8279fcb5 100644 --- a/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java +++ b/v1_13_R2/src/main/java/net/citizensnpcs/nms/v1_13_R2/util/NMSImpl.java @@ -240,7 +240,6 @@ import net.minecraft.server.v1_13_R2.PathfinderGoalSelector; import net.minecraft.server.v1_13_R2.RegistryMaterials; import net.minecraft.server.v1_13_R2.ReportedException; import net.minecraft.server.v1_13_R2.ScoreboardTeam; -import net.minecraft.server.v1_13_R2.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_13_R2.SoundEffect; import net.minecraft.server.v1_13_R2.SoundEffects; import net.minecraft.server.v1_13_R2.Vec3D; @@ -1140,16 +1139,7 @@ public class NMSImpl implements NMSBridge { @Override public void setTeamNameTagVisible(Team team, boolean visible) { - if (TEAM_FIELD == null) { - TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); - } - ScoreboardTeam nmsTeam; - try { - nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); - nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); - } catch (Throwable e) { - e.printStackTrace(); - } + team.setOption(Team.Option.NAME_TAG_VISIBILITY, visible ? Team.OptionStatus.ALWAYS : Team.OptionStatus.NEVER); } @Override diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/HumanController.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/HumanController.java index 66d5056f6..fd7dd42cc 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/HumanController.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/entity/HumanController.java @@ -7,8 +7,6 @@ import org.bukkit.Location; import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; import com.mojang.authlib.GameProfile; @@ -47,6 +45,10 @@ public class HumanController extends AbstractEntityController { name = teamName; } + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.generateTeamFor(npc, name, teamName); + } + final GameProfile profile = new GameProfile(uuid, name); final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, @@ -66,25 +68,6 @@ public class HumanController extends AbstractEntityController { boolean removeFromPlayerList = npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList); - - if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { - Scoreboard scoreboard = Util.getDummyScoreboard(); - - 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()); - - handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); - - Util.sendTeamPacketToOnlinePlayers(team, mode); - } } }, 20); @@ -102,6 +85,9 @@ public class HumanController extends AbstractEntityController { public void remove() { Player entity = getBukkitEntity(); if (entity != null) { + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.removeTeamFor(NMS.getNPC(entity), entity.getName()); + } NMS.removeFromWorld(entity); SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null; npc.getSkinTracker().onRemoveNPC(); diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index 759a85a29..e0b21d74e 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -261,7 +261,6 @@ import net.minecraft.server.v1_14_R1.PlayerChunkMap.EntityTracker; import net.minecraft.server.v1_14_R1.RegistryBlocks; import net.minecraft.server.v1_14_R1.ReportedException; import net.minecraft.server.v1_14_R1.ScoreboardTeam; -import net.minecraft.server.v1_14_R1.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_14_R1.SoundEffect; import net.minecraft.server.v1_14_R1.Vec3D; import net.minecraft.server.v1_14_R1.VoxelShape; @@ -1191,16 +1190,7 @@ public class NMSImpl implements NMSBridge { @Override public void setTeamNameTagVisible(Team team, boolean visible) { - if (TEAM_FIELD == null) { - TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); - } - ScoreboardTeam nmsTeam; - try { - nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); - nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); - } catch (Throwable e) { - e.printStackTrace(); - } + team.setOption(Team.Option.NAME_TAG_VISIBILITY, visible ? Team.OptionStatus.ALWAYS : Team.OptionStatus.NEVER); } @Override diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/HumanController.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/HumanController.java index 705477343..5ce5f72dc 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/HumanController.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/entity/HumanController.java @@ -7,8 +7,6 @@ import org.bukkit.Location; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; import com.mojang.authlib.GameProfile; @@ -47,6 +45,10 @@ public class HumanController extends AbstractEntityController { name = teamName; } + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.generateTeamFor(npc, name, teamName); + } + final GameProfile profile = new GameProfile(uuid, name); final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, @@ -66,25 +68,6 @@ public class HumanController extends AbstractEntityController { boolean removeFromPlayerList = npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList); - - if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { - Scoreboard scoreboard = Util.getDummyScoreboard(); - - 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()); - - handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); - - Util.sendTeamPacketToOnlinePlayers(team, mode); - } } }, 20); @@ -102,6 +85,9 @@ public class HumanController extends AbstractEntityController { public void remove() { Player entity = getBukkitEntity(); if (entity != null) { + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.removeTeamFor(NMS.getNPC(entity), entity.getName()); + } NMS.removeFromWorld(entity); SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null; npc.getSkinTracker().onRemoveNPC(); diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index 10c4d3bb9..915b504ef 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -264,7 +264,6 @@ import net.minecraft.server.v1_15_R1.PlayerChunkMap.EntityTracker; import net.minecraft.server.v1_15_R1.RegistryBlocks; import net.minecraft.server.v1_15_R1.ReportedException; import net.minecraft.server.v1_15_R1.ScoreboardTeam; -import net.minecraft.server.v1_15_R1.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_15_R1.SoundEffect; import net.minecraft.server.v1_15_R1.Vec3D; import net.minecraft.server.v1_15_R1.VoxelShape; @@ -1209,16 +1208,7 @@ public class NMSImpl implements NMSBridge { @Override public void setTeamNameTagVisible(Team team, boolean visible) { - if (TEAM_FIELD == null) { - TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); - } - ScoreboardTeam nmsTeam; - try { - nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); - nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); - } catch (Throwable e) { - e.printStackTrace(); - } + team.setOption(Team.Option.NAME_TAG_VISIBILITY, visible ? Team.OptionStatus.ALWAYS : Team.OptionStatus.NEVER); } @Override diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/HumanController.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/HumanController.java index 1e66b94d3..061bd3565 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/HumanController.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/entity/HumanController.java @@ -7,8 +7,6 @@ import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; import com.mojang.authlib.GameProfile; @@ -47,6 +45,10 @@ public class HumanController extends AbstractEntityController { name = teamName; } + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.generateTeamFor(npc, name, teamName); + } + final GameProfile profile = new GameProfile(uuid, name); final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, @@ -66,25 +68,6 @@ public class HumanController extends AbstractEntityController { boolean removeFromPlayerList = npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList); - - if (!Setting.USE_SCOREBOARD_TEAMS.asBoolean()) - return; - Scoreboard scoreboard = Util.getDummyScoreboard(); - - 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()); - - handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); - - Util.sendTeamPacketToOnlinePlayers(team, mode); } }, 20); @@ -102,6 +85,9 @@ public class HumanController extends AbstractEntityController { public void remove() { Player entity = getBukkitEntity(); if (entity != null) { + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.removeTeamFor(NMS.getNPC(entity), entity.getName()); + } NMS.removeFromWorld(entity); SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null; npc.getSkinTracker().onRemoveNPC(); diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java index 3467a604f..a308cd649 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java @@ -270,7 +270,6 @@ import net.minecraft.server.v1_16_R3.PlayerChunkMap.EntityTracker; import net.minecraft.server.v1_16_R3.RegistryBlocks; import net.minecraft.server.v1_16_R3.ReportedException; import net.minecraft.server.v1_16_R3.ScoreboardTeam; -import net.minecraft.server.v1_16_R3.ScoreboardTeamBase.EnumNameTagVisibility; import net.minecraft.server.v1_16_R3.SoundEffect; import net.minecraft.server.v1_16_R3.TagsFluid; import net.minecraft.server.v1_16_R3.Vec3D; @@ -1237,16 +1236,7 @@ public class NMSImpl implements NMSBridge { @Override public void setTeamNameTagVisible(Team team, boolean visible) { - if (TEAM_FIELD == null) { - TEAM_FIELD = NMS.getGetter(team.getClass(), "team"); - } - ScoreboardTeam nmsTeam; - try { - nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team); - nmsTeam.setNameTagVisibility(visible ? EnumNameTagVisibility.ALWAYS : EnumNameTagVisibility.NEVER); - } catch (Throwable e) { - e.printStackTrace(); - } + team.setOption(Team.Option.NAME_TAG_VISIBILITY, visible ? Team.OptionStatus.ALWAYS : Team.OptionStatus.NEVER); } @Override diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HumanController.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HumanController.java index 35c854295..e46335531 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HumanController.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/entity/HumanController.java @@ -7,9 +7,6 @@ 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; import com.mojang.authlib.GameProfile; @@ -48,6 +45,10 @@ public class HumanController extends AbstractEntityController { name = teamName; } + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.generateTeamFor(npc, name, teamName); + } + final GameProfile profile = new GameProfile(uuid, name); final EntityHumanNPC handle = new EntityHumanNPC(nmsWorld.getServer().getServer(), nmsWorld, profile, @@ -67,25 +68,6 @@ public class HumanController extends AbstractEntityController { boolean removeFromPlayerList = npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); NMS.addOrRemoveFromPlayerList(getBukkitEntity(), removeFromPlayerList); - - if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { - Scoreboard scoreboard = Util.getDummyScoreboard(); - - 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()); - - handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName); - - Util.sendTeamPacketToOnlinePlayers(team, mode); - } } }, 20); @@ -103,6 +85,9 @@ public class HumanController extends AbstractEntityController { public void remove() { Player entity = getBukkitEntity(); if (entity != null) { + if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) { + Util.removeTeamFor(NMS.getNPC(entity), entity.getName()); + } NMS.removeFromWorld(entity); SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null; npc.getSkinTracker().onRemoveNPC();