Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 00:00:28 +01:00
javadoc, remove ViaAPIs getPortedPlayers, fix ViaManager.getPortedPlayers name, rename to ViaAPI#isInjected
Dieser Commit ist enthalten in:
Ursprung
ee7eaecdb3
Commit
17881b342a
@ -16,7 +16,6 @@ import us.myles.ViaVersion.boss.ViaBossBar;
|
||||
import us.myles.ViaVersion.bukkit.util.ProtocolSupportUtil;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
@ -35,9 +34,9 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(@NonNull UUID uuid) {
|
||||
if (!isPorted(uuid))
|
||||
if (!isInjected(uuid))
|
||||
return getExternalVersion(Bukkit.getPlayer(uuid));
|
||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
|
||||
private int getExternalVersion(Player player) {
|
||||
@ -49,8 +48,8 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPorted(UUID playerUUID) {
|
||||
return getPortedPlayers().containsKey(playerUUID);
|
||||
public boolean isInjected(UUID playerUUID) {
|
||||
return Via.getManager().isClientConnected(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,8 +59,8 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = getPortedPlayers().get(uuid);
|
||||
if (!isInjected(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||
ci.sendRawPacket(packet);
|
||||
}
|
||||
|
||||
@ -107,7 +106,4 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
return plugin.isProtocolSupport();
|
||||
}
|
||||
|
||||
private Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getConnectedClients();
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
@ -23,24 +22,21 @@ import java.util.UUID;
|
||||
public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
||||
@Override
|
||||
public int getPlayerVersion(@NonNull ProxiedPlayer player) {
|
||||
if (!isPorted(player.getUniqueId()))
|
||||
UserConnection conn = Via.getManager().getConnection(player.getUniqueId());
|
||||
if (conn == null) {
|
||||
return player.getPendingConnection().getVersion();
|
||||
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
return conn.get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(@NonNull UUID uuid) {
|
||||
if (!isPorted(uuid)) {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
if (player != null) return player.getPendingConnection().getVersion();
|
||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
||||
}
|
||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return getPlayerVersion(ProxyServer.getInstance().getPlayer(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPorted(UUID playerUUID) {
|
||||
return getPortedPlayers().containsKey(playerUUID);
|
||||
public boolean isInjected(UUID playerUUID) {
|
||||
return Via.getManager().isClientConnected(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,8 +46,10 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = getPortedPlayers().get(uuid);
|
||||
if (!isInjected(uuid)) {
|
||||
throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
}
|
||||
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||
ci.sendRawPacket(packet);
|
||||
}
|
||||
|
||||
@ -78,10 +76,6 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
||||
return outputSet;
|
||||
}
|
||||
|
||||
private Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getConnectedClients();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces ViaVersion to probe a server
|
||||
*
|
||||
|
@ -21,11 +21,11 @@ import java.util.UUID;
|
||||
public class ViaManager {
|
||||
private final ViaPlatform<?> platform;
|
||||
private final ViaProviders providers = new ViaProviders();
|
||||
private boolean debug;
|
||||
// Internals
|
||||
private final ViaInjector injector;
|
||||
private final ViaCommandHandler commandHandler;
|
||||
private final ViaPlatformLoader loader;
|
||||
private boolean debug;
|
||||
|
||||
@Builder
|
||||
public ViaManager(ViaPlatform<?> platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) {
|
||||
@ -118,7 +118,7 @@ public class ViaManager {
|
||||
* @deprecated use getConnectedClients()
|
||||
*/
|
||||
@Deprecated
|
||||
public Map<UUID, UserConnection> getPortedClients() {
|
||||
public Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return getConnectedClients();
|
||||
}
|
||||
|
||||
@ -126,6 +126,10 @@ public class ViaManager {
|
||||
return platform.getConnectionManager().getConnectedClients();
|
||||
}
|
||||
|
||||
public boolean isClientConnected(UUID player) {
|
||||
return platform.getConnectionManager().isClientConnected(player);
|
||||
}
|
||||
|
||||
public void handleLoginSuccess(UserConnection info) {
|
||||
platform.getConnectionManager().onLoginSuccess(info);
|
||||
}
|
||||
|
@ -38,10 +38,21 @@ public interface ViaAPI<T> {
|
||||
*
|
||||
* @param playerUUID UUID of a player
|
||||
* @return true if Via has a cached userconnection for this player
|
||||
* @deprecated as of 0.9.9, because all players are ported use {@link #getPlayerVersion(UUID)}
|
||||
* @deprecated as of 0.9.9, because all players are ported use {@link #getPlayerVersion(UUID)},
|
||||
* or use {@link #isInjected(UUID)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isPorted(UUID playerUUID);
|
||||
default boolean isPorted(UUID playerUUID) {
|
||||
return isInjected(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if Via injected into this player connection
|
||||
*
|
||||
* @param playerUUID UUID of a player
|
||||
* @return true if Via has a cached UserConnection for this player
|
||||
*/
|
||||
boolean isInjected(UUID playerUUID);
|
||||
|
||||
/**
|
||||
* Get the version of the plugin
|
||||
|
@ -7,7 +7,7 @@ import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Handles UserConnections
|
||||
* Handles injected UserConnections
|
||||
*/
|
||||
public class ViaConnectionManager {
|
||||
protected final Map<UUID, UserConnection> clients = new ConcurrentHashMap<>();
|
||||
@ -30,6 +30,8 @@ public class ViaConnectionManager {
|
||||
/**
|
||||
* Returns a map containing the UUIDs and frontend UserConnections from players connected to this proxy server
|
||||
* Returns empty list when there isn't a server
|
||||
* When ViaVersion is reloaded, this method may not return some players.
|
||||
* May not contain ProtocolSupport players.
|
||||
*/
|
||||
public Map<UUID, UserConnection> getConnectedClients() {
|
||||
return Collections.unmodifiableMap(clients);
|
||||
@ -38,17 +40,25 @@ public class ViaConnectionManager {
|
||||
/**
|
||||
* Returns the frontend UserConnection from the player connected to this proxy server
|
||||
* Returns null when there isn't a server or connection was not found
|
||||
* When ViaVersion is reloaded, this method may not return some players.
|
||||
* May not return ProtocolSupport players.
|
||||
*/
|
||||
public UserConnection getConnectedClient(UUID clientIdentifier) {
|
||||
return clients.get(clientIdentifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all UserConnections which are active
|
||||
* Returns all UserConnections which are registered
|
||||
* May contain duplicated UUIDs on multiple ProtocolInfo.
|
||||
* May contain frontend, backend and/or client-sided connections.
|
||||
* When ViaVersion is reloaded, this method may not return some players.
|
||||
* May not contain ProtocolSupport players.
|
||||
*/
|
||||
public Set<UserConnection> getConnections() {
|
||||
return Collections.unmodifiableSet(connections);
|
||||
}
|
||||
|
||||
public boolean isClientConnected(UUID playerId) {
|
||||
return clients.containsKey(playerId);
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
||||
}
|
||||
|
||||
private void sendPacket(UUID uuid, PacketWrapper wrapper) {
|
||||
if (!Via.getAPI().isPorted(uuid) || !(Via.getAPI().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) {
|
||||
if (!Via.getAPI().isInjected(uuid) || !(Via.getAPI().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) {
|
||||
players.remove(uuid);
|
||||
return;
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
@ -21,21 +20,19 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(@NonNull Player player) {
|
||||
if (!isPorted(player.getUniqueId()))
|
||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
||||
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return getPlayerVersion(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(@NonNull UUID uuid) {
|
||||
if (!isPorted(uuid))
|
||||
if (!isInjected(uuid))
|
||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPorted(UUID playerUUID) {
|
||||
return getPortedPlayers().containsKey(playerUUID);
|
||||
public boolean isInjected(UUID playerUUID) {
|
||||
return Via.getManager().isClientConnected(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,8 +42,8 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = getPortedPlayers().get(uuid);
|
||||
if (!isInjected(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||
ci.sendRawPacket(packet);
|
||||
}
|
||||
|
||||
@ -72,8 +69,4 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
||||
|
||||
return outputSet;
|
||||
}
|
||||
|
||||
private Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getConnectedClients();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package us.myles.ViaVersion.velocity.platform;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.NonNull;
|
||||
@ -15,7 +13,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
@ -23,25 +21,19 @@ import java.util.UUID;
|
||||
public class VelocityViaAPI implements ViaAPI<Player> {
|
||||
@Override
|
||||
public int getPlayerVersion(@NonNull Player player) {
|
||||
if (!isPorted(player.getUniqueId()))
|
||||
if (!isInjected(player.getUniqueId()))
|
||||
return player.getProtocolVersion().getProtocol();
|
||||
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return Via.getManager().getConnection(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(@NonNull UUID uuid) {
|
||||
if (!isPorted(uuid)) {
|
||||
return VelocityPlugin.PROXY.getPlayer(uuid)
|
||||
.map(InboundConnection::getProtocolVersion)
|
||||
.map(ProtocolVersion::getProtocol)
|
||||
.orElse(ProtocolRegistry.SERVER_PROTOCOL);
|
||||
}
|
||||
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
return getPlayerVersion(VelocityPlugin.PROXY.getPlayer(uuid).orElseThrow(NoSuchElementException::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPorted(UUID playerUUID) {
|
||||
return getPortedPlayers().containsKey(playerUUID);
|
||||
public boolean isInjected(UUID playerUUID) {
|
||||
return Via.getManager().isClientConnected(playerUUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,8 +43,8 @@ public class VelocityViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException {
|
||||
if (!isPorted(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = getPortedPlayers().get(uuid);
|
||||
if (!isInjected(uuid)) throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
|
||||
UserConnection ci = Via.getManager().getConnection(uuid);
|
||||
ci.sendRawPacket(packet);
|
||||
}
|
||||
|
||||
@ -79,7 +71,4 @@ public class VelocityViaAPI implements ViaAPI<Player> {
|
||||
return outputSet;
|
||||
}
|
||||
|
||||
private Map<UUID, UserConnection> getPortedPlayers() {
|
||||
return Via.getManager().getConnectedClients();
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren