Skip to content

Commit

Permalink
Do not use MethodHandle for VelocityTabList.entries
Browse files Browse the repository at this point in the history
  • Loading branch information
UserNugget committed Jul 19, 2024
1 parent c0b748a commit 0afdb5d
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.tablist.KeyedVelocityTabListEntry;
import com.velocitypowered.proxy.tablist.VelocityTabList;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import com.velocitypowered.proxy.tablist.VelocityTabListEntry;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

public class RewritingVelocityTabList extends VelocityTabList implements RewritingTabList {

private static final MethodHandle MH_entries;
private static final Field ENTRIES;

static {
try {
MH_entries = MethodHandles.privateLookupIn(VelocityTabList.class, MethodHandles.lookup())
.findGetter(VelocityTabList.class, "entries", Map.class);
ENTRIES = VelocityTabList.class.getDeclaredField("entries");
ENTRIES.setAccessible(true);
} catch (Throwable throwable) {
throw new ExceptionInInitializerError(throwable);
}
Expand All @@ -44,14 +43,14 @@ public class RewritingVelocityTabList extends VelocityTabList implements Rewriti
// To keep compatibility with other plugins that use internal fields
private final ConnectedPlayer player;
private final MinecraftConnection connection;
private final Map<UUID, KeyedVelocityTabListEntry> entries;
private final Map<UUID, VelocityTabListEntry> entries;

public RewritingVelocityTabList(ConnectedPlayer player) {
super(player);
try {
this.player = player;
this.connection = player.getConnection();
this.entries = (Map<UUID, KeyedVelocityTabListEntry>) MH_entries.invokeExact((VelocityTabList) this);
this.entries = (Map<UUID, VelocityTabListEntry>) ENTRIES.get(this);
} catch (Throwable e) {
throw new IllegalStateException(e);
}
Expand Down

1 comment on commit 0afdb5d

@mdxd44
Copy link
Member

@mdxd44 mdxd44 commented on 0afdb5d Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purpose: There is a fork of Velocity that uses ConcurrentMap instead of Map.
(@UserNugget, please add purpose information yourself in all future commits.)

Please sign in to comment.