61 lines
1.9 KiB
Java
61 lines
1.9 KiB
Java
package de.wcloudservice.api.bedrock;
|
|
|
|
import com.velocitypowered.api.plugin.PluginContainer;
|
|
import com.velocitypowered.api.proxy.Player;
|
|
import com.velocitypowered.api.proxy.ProxyServer;
|
|
import org.geysermc.floodgate.api.FloodgateApi;
|
|
|
|
import java.util.Optional;
|
|
import java.util.UUID;
|
|
|
|
public class PlayerResolverVelocity {
|
|
|
|
private final ProxyServer proxy;
|
|
private boolean floodgateAvailable = false;
|
|
private FloodgateApi floodgateApi = null;
|
|
|
|
public PlayerResolverVelocity(ProxyServer proxy) {
|
|
this.proxy = proxy;
|
|
|
|
Optional<PluginContainer> floodgatePlugin = proxy.getPluginManager().getPlugin("floodgate");
|
|
if (floodgatePlugin.isPresent()) {
|
|
try {
|
|
this.floodgateApi = FloodgateApi.getInstance();
|
|
this.floodgateAvailable = (this.floodgateApi != null);
|
|
} catch (NoClassDefFoundError | Exception e) {
|
|
this.floodgateAvailable = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gibt die Floodgate-kompatible UUID eines Spielers zurück.
|
|
* Falls Java-Spieler → normale UUID.
|
|
*/
|
|
public UUID getEffectiveUuid(Player player) {
|
|
if (this.floodgateAvailable && this.floodgateApi.isFloodgatePlayer(player.getUniqueId())) {
|
|
return this.floodgateApi.getPlayer(player.getUniqueId()).getCorrectUniqueId();
|
|
}
|
|
return player.getUniqueId();
|
|
}
|
|
|
|
/**
|
|
* Holt einen Online-Spieler anhand seiner UUID (egal ob Java oder Bedrock).
|
|
*/
|
|
public Optional<Player> resolve(UUID uuid) {
|
|
return proxy.getPlayer(uuid);
|
|
}
|
|
|
|
/**
|
|
* Holt einen Online-Spieler anhand UUID oder Name (Fallback).
|
|
*/
|
|
public Optional<Player> resolve(UUID uuid, String name) {
|
|
Optional<Player> player = proxy.getPlayer(uuid);
|
|
if (player.isEmpty()) {
|
|
return proxy.getPlayer(name);
|
|
}
|
|
return player;
|
|
}
|
|
|
|
}
|