mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-11-04 08:59:47 +01:00
Fix scoreboards
This commit is contained in:
parent
3f43bf6924
commit
d9238a01c6
@ -15,7 +15,7 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException
|
|||||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||||
|
|
||||||
public class DisguiseConfig {
|
public class DisguiseConfig {
|
||||||
public static enum DisguisePushing {
|
public static enum DisguisePushing { // This enum has a really bad name..
|
||||||
MODIFY_SCOREBOARD, IGNORE_SCOREBOARD, CREATE_SCOREBOARD;
|
MODIFY_SCOREBOARD, IGNORE_SCOREBOARD, CREATE_SCOREBOARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ public class DisguiseUtilities {
|
|||||||
private static HashSet<UUID> selfDisguised = new HashSet<>();
|
private static HashSet<UUID> selfDisguised = new HashSet<>();
|
||||||
private static Thread mainThread;
|
private static Thread mainThread;
|
||||||
private static PacketContainer spawnChunk;
|
private static PacketContainer spawnChunk;
|
||||||
private static HashMap<UUID, String> previousTeam = new HashMap<UUID, String>();
|
private static HashMap<UUID, String> preDisguiseTeam = new HashMap<UUID, String>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@ -1031,17 +1031,19 @@ public class DisguiseUtilities {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
String prevTeam = previousTeam.remove(player.getUniqueId());
|
String originalTeam = preDisguiseTeam.remove(player.getUniqueId());
|
||||||
|
|
||||||
if (DisguiseConfig.getPushingOption() != DisguisePushing.IGNORE_SCOREBOARD) {
|
if (DisguiseConfig.getPushingOption() != DisguisePushing.IGNORE_SCOREBOARD) {
|
||||||
// Code to stop player pushing in 1.9
|
// Code to stop player pushing
|
||||||
Scoreboard scoreboard = player.getScoreboard();
|
Scoreboard scoreboard = player.getScoreboard();
|
||||||
Team team = prevTeam == null ? null : scoreboard.getTeam(prevTeam);
|
Team team = originalTeam == null ? null : scoreboard.getTeam(originalTeam);
|
||||||
Team ldTeam = scoreboard.getEntryTeam(player.getName());
|
Team ldTeam = scoreboard.getEntryTeam(player.getName());
|
||||||
|
|
||||||
if (ldTeam != null) {
|
if (ldTeam != null) {
|
||||||
if (!ldTeam.getName().equals("LDPushing") && !ldTeam.getName().endsWith("_LDP"))
|
if (!ldTeam.getName().equals("LDPushing") && !ldTeam.getName().endsWith("_LDP")) {
|
||||||
|
// Its not a team assigned by me
|
||||||
ldTeam = null;
|
ldTeam = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (team != null) {
|
if (team != null) {
|
||||||
@ -1137,47 +1139,59 @@ public class DisguiseUtilities {
|
|||||||
// Code to stop player pushing
|
// Code to stop player pushing
|
||||||
Scoreboard scoreboard = player.getScoreboard();
|
Scoreboard scoreboard = player.getScoreboard();
|
||||||
Team prevTeam = scoreboard.getEntryTeam(player.getName());
|
Team prevTeam = scoreboard.getEntryTeam(player.getName());
|
||||||
|
Team ldTeam = null;
|
||||||
|
|
||||||
if (prevTeam != null && pOption == DisguisePushing.CREATE_SCOREBOARD) {
|
// If the player is in a team already
|
||||||
previousTeam.put(player.getUniqueId(), prevTeam.getName());
|
if (prevTeam != null) {
|
||||||
|
// If we're creating a scoreboard
|
||||||
|
if (pOption == DisguisePushing.CREATE_SCOREBOARD) {
|
||||||
|
// Remember his old team so we can give him it back later
|
||||||
|
preDisguiseTeam.put(player.getUniqueId(), prevTeam.getName());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// We're modifying the scoreboard
|
||||||
|
ldTeam = prevTeam;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Team t;
|
String ldTeamName = null;
|
||||||
String createName = null;
|
|
||||||
|
|
||||||
|
// If we are creating a new scoreboard because the current one must not be modified
|
||||||
if (pOption == DisguisePushing.CREATE_SCOREBOARD) {
|
if (pOption == DisguisePushing.CREATE_SCOREBOARD) {
|
||||||
createName = (prevTeam == null ? "No Team" : prevTeam.getName());
|
// If they have a team, we'll reuse that name. Otherwise go for another name
|
||||||
|
ldTeamName = (prevTeam == null ? "No Team" : prevTeam.getName());
|
||||||
|
|
||||||
createName = createName.substring(0, Math.min(12, createName.length()));
|
// Give the teamname a custom name
|
||||||
|
ldTeamName = ldTeamName.substring(0, Math.min(12, ldTeamName.length())) + "_LDP";
|
||||||
}
|
}
|
||||||
else {
|
else if (ldTeam == null) {
|
||||||
createName = "LDPushing";
|
ldTeamName = "LDPushing";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((t = scoreboard.getTeam(createName)) == null) {
|
if (ldTeamName != null && (ldTeam = scoreboard.getTeam(ldTeamName)) == null) {
|
||||||
t = scoreboard.registerNewTeam(createName);
|
ldTeam = scoreboard.registerNewTeam(ldTeamName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER) {
|
if (ldTeam.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER) {
|
||||||
t.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
|
ldTeam.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.canSeeFriendlyInvisibles()) {
|
if (ldTeam.canSeeFriendlyInvisibles()) {
|
||||||
t.setCanSeeFriendlyInvisibles(false);
|
ldTeam.setCanSeeFriendlyInvisibles(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!t.hasEntry(player.getName()))
|
if (!ldTeam.hasEntry(player.getName()))
|
||||||
t.addEntry(player.getName());
|
ldTeam.addEntry(player.getName());
|
||||||
|
|
||||||
if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) {
|
if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) {
|
||||||
t.setAllowFriendlyFire(prevTeam.allowFriendlyFire());
|
ldTeam.setAllowFriendlyFire(prevTeam.allowFriendlyFire());
|
||||||
t.setCanSeeFriendlyInvisibles(prevTeam.canSeeFriendlyInvisibles());
|
ldTeam.setCanSeeFriendlyInvisibles(prevTeam.canSeeFriendlyInvisibles());
|
||||||
t.setDisplayName(prevTeam.getDisplayName());
|
ldTeam.setDisplayName(prevTeam.getDisplayName());
|
||||||
t.setPrefix(prevTeam.getPrefix());
|
ldTeam.setPrefix(prevTeam.getPrefix());
|
||||||
t.setSuffix(prevTeam.getSuffix());
|
ldTeam.setSuffix(prevTeam.getSuffix());
|
||||||
|
|
||||||
for (Option option : Team.Option.values()) {
|
for (Option option : Team.Option.values()) {
|
||||||
t.setOption(option, prevTeam.getOption(option));
|
ldTeam.setOption(option, prevTeam.getOption(option));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user