Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Fix some PAPI placeholder stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Mar 23, 2023
1 parent 07cef34 commit 40f362f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public PAPIPlaceholders(PluginCore<?> plugin){
public String onPlaceholderRequest(Player pl, @NotNull String identifier){
InetSocketAddress address = pl.getAddress();

String host = address == null ? null : ProtocolLibEvents.getHostAddresses().get(address.getHostString());
String host = resolveVirtualHost(pl, address);
CachedPlayer cached = plugin.getCore().getPlayerHandler().getCachedPlayer(pl.getUniqueId());

int protocol = resolveProtocol(pl);
Expand Down Expand Up @@ -129,4 +129,17 @@ private int resolveProtocol(Player player){
// getProtocolVersion is only in Paper, so this is only called when
return Bukkit.getUnsafe().getProtocolVersion();
}

private String resolveVirtualHost(Player player, InetSocketAddress address){
try {
// Server is a Paper Server with Player#getVirtualHost()
Class.forName("com.destroystokyo.paper.network.NetworkClient");
return player.getVirtualHost() == null ? null : player.getVirtualHost().getHostString();
}catch(ClassNotFoundException ignored){}

if(address == null)
return null;

return ProtocolLibEvents.getHostAddresses().get(address.getHostString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import ch.andre601.advancedserverlist.core.interfaces.core.PluginCore;
import ch.andre601.advancedserverlist.core.profiles.favicon.FaviconHandler;
import ch.andre601.advancedserverlist.paper.events.PaperPingEvent;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.CachedServerIcon;

Expand Down Expand Up @@ -77,7 +79,9 @@ public void loadEvents(){

@Override
public void loadMetrics(){

new Metrics(this, 15584).addCustomChart(new SimplePie("profiles",
() -> String.valueOf(core.getFileHandler().getProfiles().size())
));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@
import ch.andre601.advancedserverlist.core.profiles.favicon.FaviconHandler;
import ch.andre601.advancedserverlist.spigot.events.LoadEvent;
import com.comphenix.protocol.wrappers.WrappedServerPing;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

import java.nio.file.Path;
Expand Down

0 comments on commit 40f362f

Please sign in to comment.