Try make scoreboard names a bit more unique

This commit is contained in:
libraryaddict 2022-01-17 10:01:14 +13:00
parent 0ec2dab889
commit b5fb5054a2

View File

@ -1394,7 +1394,9 @@ public class DisguiseUtilities {
// Gotta register all the flag watcher stuff before I make this one // Gotta register all the flag watcher stuff before I make this one
gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerFlagWatcher(gsonBuilder.create())); gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerFlagWatcher(gsonBuilder.create()));
gsonBuilder.registerTypeAdapter(Disguise.class, new SerializerDisguise()); gsonBuilder.registerTypeAdapter(Disguise.class, new SerializerDisguise());
gsonBuilder.registerTypeAdapter(Optional.class, (JsonSerializer<Optional>) (optional, type, jsonSerializationContext) -> jsonSerializationContext.serialize("<optional>(" + jsonSerializationContext.serialize(optional.orElse(null)) + ")")); gsonBuilder.registerTypeAdapter(Optional.class,
(JsonSerializer<Optional>) (optional, type, jsonSerializationContext) -> jsonSerializationContext.serialize(
"<optional>(" + jsonSerializationContext.serialize(optional.orElse(null)) + ")"));
gson = gsonBuilder.create(); gson = gsonBuilder.create();
@ -1902,14 +1904,12 @@ public class DisguiseUtilities {
Scoreboard mainBoard = Bukkit.getScoreboardManager().getMainScoreboard(); Scoreboard mainBoard = Bukkit.getScoreboardManager().getMainScoreboard();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
String teamName = encode(System.nanoTime() / 100 % 100000) + ""; String teamName = prefix + encode(getRandom().nextLong());
if (teamName.length() > 13) { if (teamName.length() > 16) {
teamName = teamName.substring(teamName.length() - 13); teamName = teamName.substring(0, 16);
} }
teamName = prefix + teamName;
if (mainBoard.getTeam(teamName) != null) { if (mainBoard.getTeam(teamName) != null) {
continue; continue;
} }
@ -2091,10 +2091,9 @@ public class DisguiseUtilities {
if (playerName == null || !playerName.startsWith(namePrefix)) { if (playerName == null || !playerName.startsWith(namePrefix)) {
String nameSuffix = "" + ChatColor.RESET; String nameSuffix = "" + ChatColor.RESET;
long time = System.nanoTime() / 100 % 10000;
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
String testName = namePrefix + colorize(encode(time + i)) + nameSuffix; String testName = namePrefix + colorize(encode(getRandom().nextInt(Integer.MAX_VALUE))) + nameSuffix;
if (testName.length() > 16) { if (testName.length() > 16) {
break; break;
@ -2585,8 +2584,9 @@ public class DisguiseUtilities {
} }
public static void sendProtocolLibUpdateMessage(CommandSender p, String version, String requiredProtocolLib) { public static void sendProtocolLibUpdateMessage(CommandSender p, String version, String requiredProtocolLib) {
p.sendMessage(ChatColor.RED + "Please ask the server owner to update ProtocolLib! You are running " + version + p.sendMessage(
" but the minimum version you should be on is " + requiredProtocolLib + "!"); ChatColor.RED + "Please ask the server owner to update ProtocolLib! You are running " + version + " but the minimum version you should be on is " +
requiredProtocolLib + "!");
p.sendMessage(ChatColor.RED + "https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" + "/ProtocolLib" + ".jar"); p.sendMessage(ChatColor.RED + "https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" + "/ProtocolLib" + ".jar");
p.sendMessage(ChatColor.RED + "Or! Use " + ChatColor.DARK_RED + "/ld updatepl" + ChatColor.RED + " - To update to the latest development build"); p.sendMessage(ChatColor.RED + "Or! Use " + ChatColor.DARK_RED + "/ld updatepl" + ChatColor.RED + " - To update to the latest development build");
p.sendMessage(ChatColor.DARK_GREEN + "This message is `kindly` provided by Lib's Disguises on repeat to all players due to the sheer " + p.sendMessage(ChatColor.DARK_GREEN + "This message is `kindly` provided by Lib's Disguises on repeat to all players due to the sheer " +
@ -2745,8 +2745,8 @@ public class DisguiseUtilities {
throw new IllegalArgumentException("Unable to find Serializer for " + value + throw new IllegalArgumentException("Unable to find Serializer for " + value +
(value instanceof Optional && ((Optional) value).isPresent() ? " (" + ((Optional) value).get().getClass().getName() + ")" : (value instanceof Optional && ((Optional) value).isPresent() ? " (" + ((Optional) value).get().getClass().getName() + ")" :
value instanceof Optional || value == null ? "" : " " + value.getClass().getName()) + "! Are you running " + "the latest " + value instanceof Optional || value == null ? "" : " " + value.getClass().getName()) + "! Are you running " + "the latest " + "version of " +
"version of " + "ProtocolLib?"); "ProtocolLib?");
} }
public static String serialize(NbtBase base) { public static String serialize(NbtBase base) {
@ -2966,8 +2966,9 @@ public class DisguiseUtilities {
name = ChatColor.translateAlternateColorCodes('&', newNames[i]); name = ChatColor.translateAlternateColorCodes('&', newNames[i]);
} }
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject( WrappedDataWatcher.WrappedDataWatcherObject obj =
NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME : MetaIndex.ENTITY_CUSTOM_NAME_OLD, name); ReflectionManager.createDataWatcherObject(NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME : MetaIndex.ENTITY_CUSTOM_NAME_OLD,
name);
watcher.setObject(obj, ReflectionManager.convertInvalidMeta(name)); watcher.setObject(obj, ReflectionManager.convertInvalidMeta(name));