Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for VanishBridge. Raised the target Java version from 11 to 17. #27

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ repositories {
name = 'papermc-repo'
url = 'https://repo.papermc.io/repository/maven-public/'
}
maven {
url = 'https://repo.loapu.dev/releases'
}
}

def velocityApiVersion = '3.2.0-SNAPSHOT'

dependencies {
compileOnly "dev.loapu.vanishbridge:vanishbridge-api:1.0"
compileOnly "com.velocitypowered:velocity-api:$velocityApiVersion"
annotationProcessor "com.velocitypowered:velocity-api:$velocityApiVersion"
}

def targetJavaVersion = 11
def targetJavaVersion = 17
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.event.proxy.ProxyReloadEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.proxy.server.ServerPing;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.experimental.FieldDefaults;
import org.slf4j.Logger;
import voruti.velocityplayerlistquery.hook.VanishBridgeHook;
import voruti.velocityplayerlistquery.model.exception.InvalidServerPingException;
import voruti.velocityplayerlistquery.service.ConfigService;
import voruti.velocityplayerlistquery.service.serverpingprocessor.ServerPingProcessor;
Expand All @@ -25,7 +27,10 @@
version = BuildConstants.VERSION,
description = "A Velocity plugin that shows current players in the server list.",
url = "https://github.com/voruti/VelocityPlayerListQuery",
authors = {"voruti"}
authors = {"voruti"},
dependencies = {
@Dependency(id = "vanishbridge", optional = true)
}
)
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VelocityPlayerListQuery {
Expand All @@ -38,12 +43,17 @@ public class VelocityPlayerListQuery {

@Inject
ServerPingProcessorRegistry serverPingProcessorRegistry;

@Inject
VanishBridgeHook vanishBridgeHook;


@Subscribe
public void onProxyInitialization(ProxyInitializeEvent ignored) {
this.configService.reloadConfig();


if (this.vanishBridgeHook.hooked()) this.logger.info("VanishBridge found, enabling vanish support");

this.logger.info("Enabled");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package voruti.velocityplayerlistquery.hook;

import com.google.inject.Inject;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import dev.loapu.vanishbridge.api.model.VanishBridgePlayer;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import dev.loapu.vanishbridge.api.VanishBridgeProvider;

import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Collection;

@Singleton
@FieldDefaults(level = AccessLevel.PRIVATE)
public class VanishBridgeHook {
@Inject
ProxyServer server;

public boolean hooked() {
return server.getPluginManager().isLoaded("vanishbridge");
}

public Collection<Player> unvanishedPlayers() {
var allPlayers = server.getAllPlayers();
Collection<Player> unvanishedPlayers = new ArrayList<>();
var vanishedPlayers = VanishBridgeProvider.get().vanishedPlayers();
allPlayers.forEach(player -> {
if (vanishedPlayers.stream().noneMatch(vanishedPlayer -> vanishedPlayer.uuid().equals(player.getUniqueId()))) {
unvanishedPlayers.add(player);
}
});

return unvanishedPlayers;
}

public int unvanishedPlayerCount() {
return unvanishedPlayers().size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.velocitypowered.api.proxy.server.ServerPing;
import lombok.NonNull;
import lombok.experimental.FieldDefaults;
import voruti.velocityplayerlistquery.hook.VanishBridgeHook;
import voruti.velocityplayerlistquery.service.ConfigService;

import javax.inject.Inject;
Expand All @@ -18,6 +19,9 @@ public class OnlinePlayerCountServerPingProcessor extends ServerPingProcessor {

@Inject
ProxyServer proxyServer;

@Inject
VanishBridgeHook vanishBridgeHook;


@Override
Expand All @@ -29,6 +33,6 @@ public boolean isEnabled() {
public void applyToServerPing(@NonNull final ServerPing.Builder serverPing) {
super.applyToServerPing(serverPing);

serverPing.onlinePlayers(this.proxyServer.getPlayerCount());
serverPing.onlinePlayers(this.vanishBridgeHook.hooked() ? this.vanishBridgeHook.unvanishedPlayerCount() : this.proxyServer.getPlayerCount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.velocitypowered.api.proxy.server.ServerPing;
import lombok.NonNull;
import lombok.experimental.FieldDefaults;
import voruti.velocityplayerlistquery.hook.VanishBridgeHook;
import voruti.velocityplayerlistquery.model.Config;
import voruti.velocityplayerlistquery.model.Config.PlayerListMode;
import voruti.velocityplayerlistquery.service.ConfigService;
Expand Down Expand Up @@ -33,6 +34,9 @@ public class PlayerListServerPingProcessor extends ServerPingProcessor {

@Inject
ServerListEntryBuilderService serverListEntryBuilderService;

@Inject
VanishBridgeHook vanishBridgeHook;


@Override
Expand All @@ -51,7 +55,7 @@ public void applyToServerPing(@NonNull final ServerPing.Builder serverPing) {
super.applyToServerPing(serverPing);

// collect players:
final Collection<Player> players = this.proxyServer.getAllPlayers();
final Collection<Player> players = this.vanishBridgeHook.hooked() ? this.vanishBridgeHook.unvanishedPlayers() : this.proxyServer.getAllPlayers();
final Stream<ServerPing.SamplePlayer> playerStream = players.stream()
// format players:
.map(player -> new ServerPing.SamplePlayer(
Expand Down