Add protocol mappings for 1.19 versions, Add DEBUG_TEAM_NAME placeholder, weight sort logic tweaks

This commit is contained in:
William 2023-02-19 23:51:45 +00:00
parent 51c7853b7b
commit 54928f597a
No known key found for this signature in database
5 changed files with 23 additions and 16 deletions

View File

@ -93,6 +93,7 @@ public class Velocitab {
try {
luckPerms = new LuckPermsHook(this);
server.getEventManager().register(this, luckPerms);
logger.info("Successfully hooked into LuckPerms");
} catch (IllegalArgumentException e) {
logger.warn("LuckPerms was not loaded: " + e.getMessage(), e);
}
@ -120,8 +121,12 @@ public class Velocitab {
@NotNull
public TabPlayer getTabPlayer(@NotNull Player player) {
return new TabPlayer(player, getLuckPerms().map(hook -> hook.getPlayerRole(player)).orElse(Role.DEFAULT_ROLE),
getLuckPerms().map(LuckPermsHook::getHighestWeight).orElse(0));
return new TabPlayer(
player,
getLuckPerms().map(hook -> hook.getPlayerRole(player))
.orElse(Role.DEFAULT_ROLE),
getLuckPerms().map(LuckPermsHook::getHighestWeight)
.orElse(0));
}
}

View File

@ -26,7 +26,8 @@ public enum Placeholder {
PING((plugin, player) -> Long.toString(player.getPlayer().getPing())),
PREFIX((plugin, player) -> player.getRole().getPrefix().orElse("")),
SUFFIX((plugin, player) -> player.getRole().getSuffix().orElse("")),
ROLE((plugin, player) -> player.getRole().getName().orElse(""));
ROLE((plugin, player) -> player.getRole().getName().orElse("")),
DEBUG_TEAM_NAME((plugin, player) -> player.getTeamName());
private final BiFunction<Velocitab, TabPlayer, String> formatter;

View File

@ -30,16 +30,15 @@ public class LuckPermsHook {
@NotNull
public Role getPlayerRole(@NotNull Player player) {
final CachedMetaData metaData = getUser(player.getUniqueId()).getCachedData().getMetaData();
final OptionalInt roleWeight = getWeight(metaData.getPrimaryGroup());
if (roleWeight.isPresent()) {
return new Role(
roleWeight.getAsInt(),
metaData.getPrimaryGroup(),
metaData.getPrefix(),
metaData.getSuffix()
);
if (metaData.getPrimaryGroup() == null) {
return Role.DEFAULT_ROLE;
}
return Role.DEFAULT_ROLE;
return new Role(
getWeight(metaData.getPrimaryGroup()).orElse(0),
metaData.getPrimaryGroup(),
metaData.getPrefix(),
metaData.getSuffix()
);
}
@Subscribe

View File

@ -15,8 +15,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static dev.simplix.protocolize.api.util.ProtocolVersions.MINECRAFT_1_19;
import static dev.simplix.protocolize.api.util.ProtocolVersions.MINECRAFT_1_19_3;
import static dev.simplix.protocolize.api.util.ProtocolVersions.*;
@Getter
@Setter
@ -28,7 +27,9 @@ import static dev.simplix.protocolize.api.util.ProtocolVersions.MINECRAFT_1_19_3
public class UpdateTeamsPacket extends AbstractPacket {
protected static final List<ProtocolIdMapping> MAPPINGS = List.of(
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_19, MINECRAFT_1_19_3, 0x56)
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_19, MINECRAFT_1_19, 0x55),
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_19_1, MINECRAFT_1_19_2, 0x58),
AbstractProtocolMapping.rangedIdMapping(MINECRAFT_1_19_3, MINECRAFT_LATEST, 0x56)
);
private String teamName;

View File

@ -42,6 +42,7 @@ public class Role implements Comparable<Role> {
@NotNull
public String getStringComparableWeight(int highestWeight) {
return String.format("%0" + (highestWeight + "").length() + "d", highestWeight - weight);
return String.format("%0" + (highestWeight + "").length() + "d", weight);
//return String.format("%0" + (highestWeight + "").length() + "d", highestWeight - weight);
}
}