Skip to content

Commit

Permalink
Keep compatibility with plugins that use Velocity Tablist API internals
Browse files Browse the repository at this point in the history
  • Loading branch information
UserNugget committed Jun 23, 2024
1 parent 2278580 commit 5e2f384
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,28 @@

import com.velocitypowered.api.proxy.ProxyServer;
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.KeyedVelocityTabList;
import com.velocitypowered.proxy.tablist.KeyedVelocityTabListEntry;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

public class RewritingKeyedVelocityTabList extends KeyedVelocityTabList implements RewritingTabList {

// To keep compatibility with other plugins that use internal fields
protected final ConnectedPlayer player;
protected final MinecraftConnection connection;
protected final ProxyServer proxyServer;
protected final Map<UUID, KeyedVelocityTabListEntry> entries;

public RewritingKeyedVelocityTabList(ConnectedPlayer player, ProxyServer proxyServer) {
super(player, proxyServer);
this.player = super.player;
this.connection = super.connection;
this.proxyServer = super.proxyServer;
this.entries = super.entries;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,43 @@
package net.elytrium.limboapi.injection.tablist;

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 java.util.Map;
import java.util.Optional;
import java.util.UUID;

public class RewritingVelocityTabList extends VelocityTabList implements RewritingTabList {

private static final MethodHandle MH_entries;

static {
try {
MH_entries = MethodHandles.privateLookupIn(VelocityTabList.class, MethodHandles.lookup())
.findGetter(VelocityTabList.class, "entries", Map.class);
} catch (Throwable throwable) {
throw new ExceptionInInitializerError(throwable);
}
}

// To keep compatibility with other plugins that use internal fields
private final ConnectedPlayer player;
private final MinecraftConnection connection;
private final Map<UUID, KeyedVelocityTabListEntry> 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);
} catch (Throwable e) {
throw new IllegalStateException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,28 @@

import com.velocitypowered.api.proxy.ProxyServer;
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.VelocityTabListLegacy;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

public class RewritingVelocityTabListLegacy extends VelocityTabListLegacy implements RewritingTabList {

// To keep compatibility with other plugins that use internal fields
protected final ConnectedPlayer player;
protected final MinecraftConnection connection;
protected final ProxyServer proxyServer;
protected final Map<UUID, KeyedVelocityTabListEntry> entries;

public RewritingVelocityTabListLegacy(ConnectedPlayer player, ProxyServer proxyServer) {
super(player, proxyServer);
this.player = super.player;
this.connection = super.connection;
this.proxyServer = super.proxyServer;
this.entries = super.entries;
}

@Override
Expand Down

0 comments on commit 5e2f384

Please sign in to comment.