forked from PaperMC/Velocity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement tab list entry uuid rewrite
unlink bungee, rewrite the current player only
- Loading branch information
1 parent
54634a7
commit 3ab03b3
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
proxy/src/main/java/com/velocitypowered/proxy/tablist/TabListUuidRewriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2018-2023 Velocity Contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.velocitypowered.proxy.tablist; | ||
|
||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; | ||
import com.velocitypowered.proxy.protocol.packet.LegacyPlayerListItem; | ||
import com.velocitypowered.proxy.protocol.packet.RemovePlayerInfo; | ||
import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfo; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* [fallen's fork] tab list entry uuid rewrite: rewrite logic. | ||
*/ | ||
public class TabListUuidRewriter { | ||
/** | ||
* Rewrite uuid for a LegacyPlayerListItem packet. | ||
*/ | ||
public static void rewrite(ConnectedPlayer player, LegacyPlayerListItem packet) { | ||
packet.getItems().replaceAll(item -> { | ||
if (player.getOfflineUuid().equals(item.getUuid())) { | ||
var newItem = new LegacyPlayerListItem.Item(player.getUniqueId()); | ||
|
||
newItem.setName(item.getName()); | ||
newItem.setProperties(item.getProperties()); | ||
newItem.setGameMode(item.getGameMode()); | ||
newItem.setLatency(item.getLatency()); | ||
newItem.setDisplayName(item.getDisplayName()); | ||
newItem.setPlayerKey(item.getPlayerKey()); | ||
|
||
item = newItem; | ||
} | ||
|
||
return item; | ||
}); | ||
} | ||
|
||
/** | ||
* Rewrite uuid for a UpsertPlayerInfo packet. | ||
*/ | ||
public static void rewrite(ConnectedPlayer player, UpsertPlayerInfo packet) { | ||
packet.getEntries().replaceAll(entry -> { | ||
if (player.getOfflineUuid().equals(entry.getProfileId())) { | ||
var newEntry = new UpsertPlayerInfo.Entry(player.getUniqueId()); | ||
|
||
newEntry.setProfile(player.getGameProfile()); | ||
newEntry.setListed(entry.isListed()); | ||
newEntry.setLatency(entry.getLatency()); | ||
newEntry.setGameMode(entry.getGameMode()); | ||
newEntry.setDisplayName(entry.getDisplayName()); | ||
newEntry.setChatSession(entry.getChatSession()); | ||
|
||
entry = newEntry; | ||
} | ||
|
||
return entry; | ||
}); | ||
} | ||
|
||
/** | ||
* Rewrite uuid for a RemovePlayerInfo packet. | ||
*/ | ||
public static void rewrite(ConnectedPlayer player, RemovePlayerInfo packet) { | ||
var newProfiles = packet.getProfilesToRemove().stream() | ||
.map(uuid -> { | ||
if (player.getOfflineUuid().equals(uuid)) { | ||
uuid = player.getUniqueId(); | ||
} | ||
return uuid; | ||
}) | ||
.collect(Collectors.toList()); | ||
packet.setProfilesToRemove(newProfiles); | ||
} | ||
} |