mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Reduce potential for errors with packet teams (#2138)
* Reduce potential for errors with packet teams Move scoreboard removal out of NMS to event method, and make more unique names * remove unneeded isCancelled check
This commit is contained in:
parent
92d3605e30
commit
30f2dee4d7
@ -50,6 +50,7 @@ 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;
|
||||
@ -416,6 +417,22 @@ public class EventListen implements Listener {
|
||||
+ event.getReason().name());
|
||||
}
|
||||
skinUpdateTracker.onNPCDespawn(event.getNPC());
|
||||
if (event.getNPC().getEntity() instanceof Player && Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
String teamName = event.getNPC().data().get(NPC.SCOREBOARD_FAKE_TEAM_NAME_METADATA, "");
|
||||
if (teamName.length() > 0) {
|
||||
Player player = (Player) event.getNPC().getEntity();
|
||||
Team team = Util.getDummyScoreboard().getTeam(teamName);
|
||||
if (team != null && team.hasPlayer(player)) {
|
||||
if (team.getSize() == 1) {
|
||||
Util.sendTeamPacketToOnlinePlayers(team, 1);
|
||||
team.unregister();
|
||||
}
|
||||
else {
|
||||
team.removePlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
|
@ -4,6 +4,7 @@ import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -104,6 +105,10 @@ public class Util {
|
||||
return MINECRAFT_REVISION.substring(MINECRAFT_REVISION.lastIndexOf('.') + 2);
|
||||
}
|
||||
|
||||
public static String getTeamName(UUID id) {
|
||||
return "CIT-" + id.toString().replace("-", "").substring(0, 12);
|
||||
}
|
||||
|
||||
public static boolean isAlwaysFlyable(EntityType type) {
|
||||
if (type.name().toLowerCase().equals("vex") || type.name().toLowerCase().equals("parrot")
|
||||
|| type.name().toLowerCase().equals("bee") || type.name().toLowerCase().equals("phantom"))
|
||||
|
@ -68,7 +68,7 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
String teamName = profile.getId().toString().substring(0, 16);
|
||||
String teamName = Util.getTeamName(profile.getId());
|
||||
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
int mode = 2;
|
||||
@ -105,20 +105,6 @@ public class HumanController extends AbstractEntityController {
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
String teamName = entity.getUniqueId().toString().substring(0, 16);
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
if (team != null && team.hasPlayer(entity)) {
|
||||
if (team.getSize() == 1) {
|
||||
Util.sendTeamPacketToOnlinePlayers(team, 1);
|
||||
team.unregister();
|
||||
}
|
||||
else {
|
||||
team.removePlayer(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
|
@ -68,7 +68,7 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
String teamName = profile.getId().toString().substring(0, 16);
|
||||
String teamName = Util.getTeamName(profile.getId());
|
||||
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
int mode = 2;
|
||||
@ -105,20 +105,6 @@ public class HumanController extends AbstractEntityController {
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
String teamName = entity.getUniqueId().toString().substring(0, 16);
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
if (team != null && team.hasPlayer(entity)) {
|
||||
if (team.getSize() == 1) {
|
||||
Util.sendTeamPacketToOnlinePlayers(team, 1);
|
||||
team.unregister();
|
||||
}
|
||||
else {
|
||||
team.removePlayer(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
|
@ -68,7 +68,7 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
String teamName = profile.getId().toString().substring(0, 16);
|
||||
String teamName = Util.getTeamName(profile.getId());
|
||||
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
int mode = 2;
|
||||
@ -105,20 +105,6 @@ public class HumanController extends AbstractEntityController {
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
String teamName = entity.getUniqueId().toString().substring(0, 16);
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
if (team != null && team.hasPlayer(entity)) {
|
||||
if (team.getSize() == 1) {
|
||||
Util.sendTeamPacketToOnlinePlayers(team, 1);
|
||||
team.unregister();
|
||||
}
|
||||
else {
|
||||
team.removePlayer(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
|
@ -68,7 +68,7 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
String teamName = profile.getId().toString().substring(0, 16);
|
||||
String teamName = Util.getTeamName(profile.getId());
|
||||
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
int mode = 2;
|
||||
@ -105,20 +105,6 @@ public class HumanController extends AbstractEntityController {
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
String teamName = entity.getUniqueId().toString().substring(0, 16);
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
if (team != null && team.hasPlayer(entity)) {
|
||||
if (team.getSize() == 1) {
|
||||
Util.sendTeamPacketToOnlinePlayers(team, 1);
|
||||
team.unregister();
|
||||
}
|
||||
else {
|
||||
team.removePlayer(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
|
@ -68,7 +68,7 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
String teamName = profile.getId().toString().substring(0, 16);
|
||||
String teamName = Util.getTeamName(profile.getId());
|
||||
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
int mode = 2;
|
||||
@ -105,20 +105,6 @@ public class HumanController extends AbstractEntityController {
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
String teamName = entity.getUniqueId().toString().substring(0, 16);
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
if (team != null && team.hasPlayer(entity)) {
|
||||
if (team.getSize() == 1) {
|
||||
Util.sendTeamPacketToOnlinePlayers(team, 1);
|
||||
team.unregister();
|
||||
}
|
||||
else {
|
||||
team.removePlayer(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
|
@ -68,7 +68,7 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
String teamName = profile.getId().toString().substring(0, 16);
|
||||
String teamName = Util.getTeamName(profile.getId());
|
||||
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
int mode = 2;
|
||||
@ -105,20 +105,6 @@ public class HumanController extends AbstractEntityController {
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
String teamName = entity.getUniqueId().toString().substring(0, 16);
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
if (team != null && team.hasPlayer(entity)) {
|
||||
if (team.getSize() == 1) {
|
||||
Util.sendTeamPacketToOnlinePlayers(team, 1);
|
||||
team.unregister();
|
||||
}
|
||||
else {
|
||||
team.removePlayer(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
|
@ -68,7 +68,7 @@ public class HumanController extends AbstractEntityController {
|
||||
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
String teamName = profile.getId().toString().substring(0, 16);
|
||||
String teamName = Util.getTeamName(profile.getId());
|
||||
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
int mode = 2;
|
||||
@ -105,20 +105,6 @@ public class HumanController extends AbstractEntityController {
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
if (Setting.USE_SCOREBOARD_TEAMS.asBoolean()) {
|
||||
String teamName = entity.getUniqueId().toString().substring(0, 16);
|
||||
Scoreboard scoreboard = Util.getDummyScoreboard();
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
if (team != null && team.hasPlayer(entity)) {
|
||||
if (team.getSize() == 1) {
|
||||
Util.sendTeamPacketToOnlinePlayers(team, 1);
|
||||
team.unregister();
|
||||
}
|
||||
else {
|
||||
team.removePlayer(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
|
Loading…
Reference in New Issue
Block a user