mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-21 23:51:46 +01:00
Refactor scoreboard handling to use instant scoreboard application at spawn (#2544)
Full description in PR https://github.com/CitizensDev/Citizens2/pull/2544
This commit is contained in:
parent
a4dde9f017
commit
4dc123bb4b
@ -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)
|
||||
|
@ -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().<Object> 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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user