Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
Return -1 in getPlayerVersion if the player is not connected
Dieser Commit ist enthalten in:
Ursprung
2beed20f1b
Commit
4cc8a3f092
4
.github/ISSUE_TEMPLATE/config.yml
vendored
4
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: ViaVersion Discord Server
|
||||
url: https://discord.gg/casfFyh
|
||||
about: You can also join the Via Discord server for help with smaller issues during setup.
|
@ -13,7 +13,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.boss.ViaBossBar;
|
||||
import us.myles.ViaVersion.bukkit.util.ProtocolSupportUtil;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
@ -33,17 +32,15 @@ public class BukkitViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
if (!isInjected(uuid))
|
||||
return getExternalVersion(Bukkit.getPlayer(uuid));
|
||||
return Via.getManager().getConnection(uuid).getProtocolInfo().getProtocolVersion();
|
||||
}
|
||||
|
||||
private int getExternalVersion(Player player) {
|
||||
if (!isProtocolSupport()) {
|
||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
||||
} else {
|
||||
UserConnection connection = Via.getManager().getConnection(uuid);
|
||||
if (connection == null) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null && isProtocolSupport()) {
|
||||
return ProtocolSupportUtil.getProtocolVersion(player);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return connection.getProtocolInfo().getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.bungee.platform;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
@ -12,7 +11,6 @@ import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
@ -22,16 +20,13 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(ProxiedPlayer player) {
|
||||
UserConnection conn = Via.getManager().getConnection(player.getUniqueId());
|
||||
if (conn == null) {
|
||||
return player.getPendingConnection().getVersion();
|
||||
}
|
||||
return conn.getProtocolInfo().getProtocolVersion();
|
||||
return getPlayerVersion(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
return getPlayerVersion(ProxyServer.getInstance().getPlayer(uuid));
|
||||
UserConnection connection = Via.getManager().getConnection(uuid);
|
||||
return connection != null ? connection.getProtocolInfo().getProtocolVersion() : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,19 +17,19 @@ import java.util.UUID;
|
||||
public interface ViaAPI<T> {
|
||||
|
||||
/**
|
||||
* Get protocol number from a player
|
||||
* Get protocol version number from a player.
|
||||
* Will also retrieve version from ProtocolSupport if it's being used.
|
||||
*
|
||||
* @param player Platform player object, eg. Bukkit this is Player
|
||||
* @return Protocol ID, For example (47=1.8-1.8.8, 107=1.9, 108=1.9.1)
|
||||
* @return Protocol ID, For example (47=1.8-1.8.8, 107=1.9, 108=1.9.1), or -1 if no longer connected
|
||||
*/
|
||||
int getPlayerVersion(T player);
|
||||
|
||||
/**
|
||||
* Get protocol number from a player
|
||||
* Get protocol number from a player.
|
||||
*
|
||||
* @param uuid UUID of a player
|
||||
* @return Protocol ID, For example (47=1.8-1.8.8, 107=1.9, 108=1.9.1)
|
||||
* @return Protocol ID, For example (47=1.8-1.8.8, 107=1.9, 108=1.9.1), or -1 if not connected
|
||||
*/
|
||||
int getPlayerVersion(UUID uuid);
|
||||
|
||||
|
@ -13,8 +13,9 @@ public interface EntityType {
|
||||
|
||||
default boolean is(EntityType... types) {
|
||||
for (EntityType type : types)
|
||||
if (is(type))
|
||||
if (this == type) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -26,8 +27,9 @@ public interface EntityType {
|
||||
EntityType parent = this;
|
||||
|
||||
do {
|
||||
if (parent.equals(type))
|
||||
if (parent == type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
parent = parent.getParent();
|
||||
} while (parent != null);
|
||||
|
@ -5,7 +5,10 @@ import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.command.ViaSubCommand;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ListSubCmd extends ViaSubCommand {
|
||||
@Override
|
||||
@ -25,23 +28,17 @@ public class ListSubCmd extends ViaSubCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(ViaCommandSender sender, String[] args) {
|
||||
Map<ProtocolVersion, Set<String>> playerVersions = new TreeMap<>(new Comparator<ProtocolVersion>() {
|
||||
@Override
|
||||
public int compare(ProtocolVersion o1, ProtocolVersion o2) {
|
||||
return ProtocolVersion.getIndex(o2) - ProtocolVersion.getIndex(o1);
|
||||
}
|
||||
});
|
||||
Map<ProtocolVersion, Set<String>> playerVersions = new TreeMap<>((o1, o2) -> ProtocolVersion.getIndex(o2) - ProtocolVersion.getIndex(o1));
|
||||
|
||||
for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) {
|
||||
int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
|
||||
ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion);
|
||||
if (!playerVersions.containsKey(key))
|
||||
playerVersions.put(key, new HashSet<String>());
|
||||
playerVersions.get(key).add(p.getName());
|
||||
playerVersions.computeIfAbsent(key, s -> new HashSet<>()).add(p.getName());
|
||||
}
|
||||
|
||||
for (Map.Entry<ProtocolVersion, Set<String>> entry : playerVersions.entrySet())
|
||||
for (Map.Entry<ProtocolVersion, Set<String>> entry : playerVersions.entrySet()) {
|
||||
sendMessage(sender, "&8[&6%s&8] (&7%d&8): &b%s", entry.getKey().getName(), entry.getValue().size(), entry.getValue());
|
||||
}
|
||||
|
||||
playerVersions.clear();
|
||||
return true;
|
||||
|
@ -9,7 +9,6 @@ import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
@ -24,9 +23,8 @@ public class SpongeViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
if (!isInjected(uuid))
|
||||
return ProtocolRegistry.SERVER_PROTOCOL;
|
||||
return Via.getManager().getConnection(uuid).getProtocolInfo().getProtocolVersion();
|
||||
UserConnection connection = Via.getManager().getConnection(uuid);
|
||||
return connection != null ? connection.getProtocolInfo().getProtocolVersion() : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,6 @@ package us.myles.ViaVersion.velocity.platform;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import us.myles.ViaVersion.VelocityPlugin;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
import us.myles.ViaVersion.api.boss.BossBar;
|
||||
@ -10,25 +9,22 @@ import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class VelocityViaAPI implements ViaAPI<Player> {
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(Player player) {
|
||||
if (!isInjected(player.getUniqueId()))
|
||||
return player.getProtocolVersion().getProtocol();
|
||||
return Via.getManager().getConnection(player.getUniqueId()).getProtocolInfo().getProtocolVersion();
|
||||
return getPlayerVersion(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
return getPlayerVersion(VelocityPlugin.PROXY.getPlayer(uuid).orElseThrow(NoSuchElementException::new));
|
||||
|
||||
UserConnection connection = Via.getManager().getConnection(uuid);
|
||||
return connection != null ? connection.getProtocolInfo().getProtocolVersion() : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren