mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Implement packet-based scoreboard team enforcement (#2127)
* Implement packet-based scoreboard team enforcement This should fix incompatibility with scoreboard plugins that break the main scoreboard * impl to 1.8-1.12, move event logic, fix Setting usage * pull setting if to outside of foreach loop * fix return vs continue, minor opti as requested
This commit is contained in:
parent
8109a90440
commit
0e31ffb9f8
@ -481,6 +481,20 @@ public class EventListen implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
skinUpdateTracker.updatePlayer(event.getPlayer(), 6 * 20, true);
|
||||
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
for (NPC npc : getAllNPCs()) {
|
||||
if (!(npc.getEntity() instanceof Player)) {
|
||||
continue;
|
||||
}
|
||||
String teamName = npc.data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, "");
|
||||
Team team = null;
|
||||
if (teamName.length() == 0 || (team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam(teamName)) == null)
|
||||
continue;
|
||||
|
||||
NMS.sendTeamPacket(event.getPlayer(), team);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
|
@ -4,7 +4,9 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import org.bukkit.scoreboard.Team.Option;
|
||||
import org.bukkit.scoreboard.Team.OptionStatus;
|
||||
@ -90,6 +92,9 @@ public class ScoreboardTrait extends Trait {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
NMS.sendTeamPacket(player, team);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTag(String tag) {
|
||||
@ -103,4 +108,4 @@ public class ScoreboardTrait extends Trait {
|
||||
private static boolean SUPPORT_GLOWING_COLOR = true;
|
||||
private static boolean SUPPORT_TAGS = true;
|
||||
private static boolean SUPPORT_TEAM_SETOPTION = true;
|
||||
}
|
||||
}
|
||||
|
@ -366,6 +366,10 @@ public class NMS {
|
||||
BRIDGE.sendTabListRemove(recipient, listPlayer);
|
||||
}
|
||||
|
||||
public static void sendTeamPacket(Player recipient, Team team) {
|
||||
BRIDGE.sendTeamPacket(recipient, team);
|
||||
}
|
||||
|
||||
public static void setBodyYaw(Entity entity, float yaw) {
|
||||
BRIDGE.setBodyYaw(entity, yaw);
|
||||
}
|
||||
|
@ -119,6 +119,8 @@ public interface NMSBridge {
|
||||
|
||||
public void sendTabListRemove(Player recipient, Player listPlayer);
|
||||
|
||||
public void sendTeamPacket(Player recipient, Team team);
|
||||
|
||||
public void setBodyYaw(Entity entity, float yaw);
|
||||
|
||||
public void setDestination(Entity entity, double x, double y, double z, float speed);
|
||||
|
@ -83,6 +83,10 @@ public class HumanController extends AbstractEntityController {
|
||||
team.addPlayer(handle.getBukkitEntity());
|
||||
|
||||
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
NMS.sendTeamPacket(player, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
|
@ -191,6 +191,7 @@ import net.minecraft.server.v1_10_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_10_R1.Packet;
|
||||
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityTeleport;
|
||||
import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.v1_10_R1.PacketPlayOutScoreboardTeam;
|
||||
import net.minecraft.server.v1_10_R1.PathEntity;
|
||||
import net.minecraft.server.v1_10_R1.PathPoint;
|
||||
import net.minecraft.server.v1_10_R1.PathType;
|
||||
@ -859,6 +860,23 @@ public class NMSImpl implements NMSBridge {
|
||||
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entities));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeamPacket(Player recipient, Team team) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
Preconditions.checkNotNull(team);
|
||||
|
||||
if (TEAM_FIELD == null) {
|
||||
TEAM_FIELD = NMS.getGetter(team.getClass(), "team");
|
||||
}
|
||||
|
||||
try {
|
||||
ScoreboardTeam nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team);
|
||||
sendPacket(recipient, new PacketPlayOutScoreboardTeam(nmsTeam, 0));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTabListRemove(Player recipient, Player listPlayer) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
|
@ -83,6 +83,10 @@ public class HumanController extends AbstractEntityController {
|
||||
team.addPlayer(handle.getBukkitEntity());
|
||||
|
||||
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
NMS.sendTeamPacket(player, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
|
@ -209,6 +209,7 @@ import net.minecraft.server.v1_11_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_11_R1.Packet;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutEntityTeleport;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.v1_11_R1.PacketPlayOutScoreboardTeam;
|
||||
import net.minecraft.server.v1_11_R1.PathEntity;
|
||||
import net.minecraft.server.v1_11_R1.PathPoint;
|
||||
import net.minecraft.server.v1_11_R1.PathType;
|
||||
@ -926,6 +927,23 @@ public class NMSImpl implements NMSBridge {
|
||||
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeamPacket(Player recipient, Team team) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
Preconditions.checkNotNull(team);
|
||||
|
||||
if (TEAM_FIELD == null) {
|
||||
TEAM_FIELD = NMS.getGetter(team.getClass(), "team");
|
||||
}
|
||||
|
||||
try {
|
||||
ScoreboardTeam nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team);
|
||||
sendPacket(recipient, new PacketPlayOutScoreboardTeam(nmsTeam, 0));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
|
||||
getHandle(entity).yaw = yaw;
|
||||
|
@ -83,6 +83,10 @@ public class HumanController extends AbstractEntityController {
|
||||
team.addPlayer(handle.getBukkitEntity());
|
||||
|
||||
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
NMS.sendTeamPacket(player, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
|
@ -213,6 +213,7 @@ import net.minecraft.server.v1_12_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_12_R1.Packet;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityTeleport;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardTeam;
|
||||
import net.minecraft.server.v1_12_R1.PathEntity;
|
||||
import net.minecraft.server.v1_12_R1.PathPoint;
|
||||
import net.minecraft.server.v1_12_R1.PathType;
|
||||
@ -923,6 +924,23 @@ public class NMSImpl implements NMSBridge {
|
||||
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entities));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeamPacket(Player recipient, Team team) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
Preconditions.checkNotNull(team);
|
||||
|
||||
if (TEAM_FIELD == null) {
|
||||
TEAM_FIELD = NMS.getGetter(team.getClass(), "team");
|
||||
}
|
||||
|
||||
try {
|
||||
ScoreboardTeam nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team);
|
||||
sendPacket(recipient, new PacketPlayOutScoreboardTeam(nmsTeam, 0));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTabListRemove(Player recipient, Player listPlayer) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
|
@ -83,6 +83,10 @@ public class HumanController extends AbstractEntityController {
|
||||
team.addPlayer(handle.getBukkitEntity());
|
||||
|
||||
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
NMS.sendTeamPacket(player, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
|
@ -228,6 +228,7 @@ import net.minecraft.server.v1_13_R2.NetworkManager;
|
||||
import net.minecraft.server.v1_13_R2.Packet;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutEntityTeleport;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.v1_13_R2.PacketPlayOutScoreboardTeam;
|
||||
import net.minecraft.server.v1_13_R2.PathEntity;
|
||||
import net.minecraft.server.v1_13_R2.PathPoint;
|
||||
import net.minecraft.server.v1_13_R2.PathType;
|
||||
@ -958,6 +959,23 @@ public class NMSImpl implements NMSBridge {
|
||||
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entities));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeamPacket(Player recipient, Team team) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
Preconditions.checkNotNull(team);
|
||||
|
||||
if (TEAM_FIELD == null) {
|
||||
TEAM_FIELD = NMS.getGetter(team.getClass(), "team");
|
||||
}
|
||||
|
||||
try {
|
||||
ScoreboardTeam nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team);
|
||||
sendPacket(recipient, new PacketPlayOutScoreboardTeam(nmsTeam, 0));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTabListRemove(Player recipient, Player listPlayer) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
|
@ -83,6 +83,10 @@ public class HumanController extends AbstractEntityController {
|
||||
team.addPlayer(handle.getBukkitEntity());
|
||||
|
||||
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
NMS.sendTeamPacket(player, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
|
@ -247,6 +247,7 @@ import net.minecraft.server.v1_14_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_14_R1.Packet;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityTeleport;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.v1_14_R1.PacketPlayOutScoreboardTeam;
|
||||
import net.minecraft.server.v1_14_R1.PathEntity;
|
||||
import net.minecraft.server.v1_14_R1.PathPoint;
|
||||
import net.minecraft.server.v1_14_R1.PathType;
|
||||
@ -1021,6 +1022,23 @@ public class NMSImpl implements NMSBridge {
|
||||
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeamPacket(Player recipient, Team team) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
Preconditions.checkNotNull(team);
|
||||
|
||||
if (TEAM_FIELD == null) {
|
||||
TEAM_FIELD = NMS.getGetter(team.getClass(), "team");
|
||||
}
|
||||
|
||||
try {
|
||||
ScoreboardTeam nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team);
|
||||
sendPacket(recipient, new PacketPlayOutScoreboardTeam(nmsTeam, 0));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
|
||||
getHandle(entity).yaw = yaw;
|
||||
|
@ -83,6 +83,10 @@ public class HumanController extends AbstractEntityController {
|
||||
team.addPlayer(handle.getBukkitEntity());
|
||||
|
||||
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
NMS.sendTeamPacket(player, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
|
@ -248,6 +248,7 @@ import net.minecraft.server.v1_15_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_15_R1.Packet;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutScoreboardTeam;
|
||||
import net.minecraft.server.v1_15_R1.PathEntity;
|
||||
import net.minecraft.server.v1_15_R1.PathPoint;
|
||||
import net.minecraft.server.v1_15_R1.PathType;
|
||||
@ -1024,6 +1025,23 @@ public class NMSImpl implements NMSBridge {
|
||||
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeamPacket(Player recipient, Team team) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
Preconditions.checkNotNull(team);
|
||||
|
||||
if (TEAM_FIELD == null) {
|
||||
TEAM_FIELD = NMS.getGetter(team.getClass(), "team");
|
||||
}
|
||||
|
||||
try {
|
||||
ScoreboardTeam nmsTeam = (ScoreboardTeam) TEAM_FIELD.invoke(team);
|
||||
sendPacket(recipient, new PacketPlayOutScoreboardTeam(nmsTeam, 0));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
|
||||
getHandle(entity).yaw = yaw;
|
||||
|
@ -83,6 +83,10 @@ public class HumanController extends AbstractEntityController {
|
||||
team.addPlayer(handle.getBukkitEntity());
|
||||
|
||||
handle.getNPC().data().set(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, teamName);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
NMS.sendTeamPacket(player, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
|
@ -165,6 +165,7 @@ import net.minecraft.server.v1_8_R3.NetworkManager;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutScoreboardTeam;
|
||||
import net.minecraft.server.v1_8_R3.PathEntity;
|
||||
import net.minecraft.server.v1_8_R3.PathPoint;
|
||||
import net.minecraft.server.v1_8_R3.PathfinderGoalSelector;
|
||||
@ -786,6 +787,23 @@ public class NMSImpl implements NMSBridge {
|
||||
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entities));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTeamPacket(Player recipient, Team team) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
Preconditions.checkNotNull(team);
|
||||
|
||||
if (TEAM_FIELD == null) {
|
||||
TEAM_FIELD = NMS.getField(team.getClass(), "team");
|
||||
}
|
||||
|
||||
try {
|
||||
ScoreboardTeam nmsTeam = (ScoreboardTeam) TEAM_FIELD.get(team);
|
||||
sendPacket(recipient, new PacketPlayOutScoreboardTeam(nmsTeam, 0));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTabListRemove(Player recipient, Player listPlayer) {
|
||||
Preconditions.checkNotNull(recipient);
|
||||
|
Loading…
Reference in New Issue
Block a user