Skip to content

Commit

Permalink
Updated papiproxybridge version
Browse files Browse the repository at this point in the history
Added a check to correctly remove old entries after a player left a server
Fixed problem where PlayerChannelHandler couldn't be able to handle tablist entries before the creation of TabPlayer object.
  • Loading branch information
alexdev03 committed Oct 2, 2024
1 parent 4f2fe1e commit cc548b1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
compileOnly 'org.projectlombok:lombok:1.18.34'
compileOnly 'net.luckperms:api:5.4'
compileOnly 'io.github.miniplaceholders:miniplaceholders-api:2.2.3'
compileOnly 'net.william278:PAPIProxyBridge:1.5'
compileOnly 'net.william278:PAPIProxyBridge:1.6.2'
compileOnly 'it.unimi.dsi:fastutil:8.5.14'
compileOnly 'net.kyori:adventure-nbt:4.17.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ private static Pair<Boolean, String> processRelationalPlaceholders(@NotNull Stri

final Matcher testMatcher = TEST.matcher(format);
while (testMatcher.find()) {
if(testMatcher.group().startsWith("<velocitab_rel")) {
if (testMatcher.group().startsWith("<velocitab_rel")) {
final Matcher second = TEST.matcher(testMatcher.group().substring(1));
while (second.find()) {
String s = second.group();
for (Map.Entry<String, String> entry : SYMBOL_SUBSTITUTES.entrySet()) {
s = s.replace(entry.getKey(), entry.getValue());
}
format = format.replace(second.group(), s);
format = format.replace(second.group(), s);
}
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
package net.william278.velocitab.packet;

import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.ServerInfo;
import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfoPacket;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import lombok.RequiredArgsConstructor;
import net.william278.velocitab.Velocitab;
import net.william278.velocitab.config.Group;
import net.william278.velocitab.player.TabPlayer;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -83,7 +86,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)

try {
final Optional<TabPlayer> tabPlayer = plugin.getTabList().getTabPlayer(player);
if (tabPlayer.isEmpty()) {
if (tabPlayer.isEmpty() && !isFutureTabPlayer()) {
super.write(ctx, msg, promise);
return;
}
Expand Down Expand Up @@ -121,4 +124,14 @@ private void forceGameMode(@NotNull List<UpsertPlayerInfoPacket.Entry> entries)
.filter(entry -> entry.getProfileId() != null && entry.getGameMode() == 3 && !entry.getProfileId().equals(player.getUniqueId()))
.forEach(entry -> entry.setGameMode(0));
}

private boolean isFutureTabPlayer() {
final String serverName = player.getCurrentServer()
.map(ServerConnection::getServerInfo)
.map(ServerInfo::getName)
.orElse("");

final Optional<Group> groupOptional = plugin.getTabList().getGroup(serverName);
return groupOptional.isPresent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public class Protocol404Adapter extends TeamsPacketAdapter {
private final GsonComponentSerializer serializer;

public Protocol404Adapter(@NotNull Velocitab plugin) {
super(plugin, Set.of(ProtocolVersion.MINECRAFT_1_13_2,
super(plugin, Set.of(
ProtocolVersion.MINECRAFT_1_13,
ProtocolVersion.MINECRAFT_1_13_1,
ProtocolVersion.MINECRAFT_1_13_2,
ProtocolVersion.MINECRAFT_1_14,
ProtocolVersion.MINECRAFT_1_14_1,
ProtocolVersion.MINECRAFT_1_14_2,
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/william278/velocitab/tab/PlayerTabList.java
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ public Optional<Group> getGroup(@NotNull String serverName) {
return plugin.getTabGroups().getGroupFromServer(serverName, plugin);
}

public void removeOldEntry(@NotNull Group group, @NotNull UUID uuid) {
final Set<TabPlayer> players = group.getTabPlayers(plugin);
players.forEach(player -> player.getPlayer().getTabList().removeEntry(uuid));
}

/**
* Remove an offline player from the list of tracked TAB players
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,22 @@ public void onPlayerJoin(@NotNull ServerPostConnectEvent event) {
.map(ServerInfo::getName)
.orElse("");

final Optional<Group> previousGroup = tabList.getTabPlayer(joined)
.map(TabPlayer::getGroup);

// Get the group the player should now be in
final @NotNull Optional<Group> groupOptional = tabList.getGroup(serverName);
final boolean isDefault = groupOptional.map(g -> g.isDefault(plugin)).orElse(true);

// Removes cached relational data of the joined player from all other players
plugin.getTabList().clearCachedData(joined);

if (!plugin.getSettings().isShowAllPlayersFromAllGroups() && previousGroup.isPresent()
&& (groupOptional.isPresent() && !previousGroup.get().equals(groupOptional.get())
|| groupOptional.isEmpty())) {
tabList.removeOldEntry(previousGroup.get(), joined.getUniqueId());
}

// If the server is not in a group, use fallback.
// If fallback is disabled, permit the player to switch excluded servers without a header or footer override
if (isDefault && !plugin.getSettings().isFallbackEnabled() && !groupOptional.map(g -> g.containsServer(plugin, serverName)).orElse(false)) {
Expand Down

0 comments on commit cc548b1

Please sign in to comment.