From d0e573613be9ab91b0a1306d51b44673a3ba9223 Mon Sep 17 00:00:00 2001 From: Mats Date: Wed, 16 Mar 2016 21:01:04 +0100 Subject: [PATCH] Add api method to get player's protocol id, --- .../java/us/myles/ViaVersion/ViaVersionPlugin.java | 8 ++++++++ .../java/us/myles/ViaVersion/api/ViaVersionAPI.java | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index ccd244d33..8e27b6895 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -5,6 +5,7 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.SocketChannel; +import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -195,6 +196,13 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { return isPorted(player.getUniqueId()); } + @Override + public int getPlayerVersion(@NonNull Player player) { + if (!isPorted(player)) + return 47; + return portedPlayers.get(player.getUniqueId()).getProtocol(); + } + @Override public boolean isPorted(UUID playerUUID) { return portedPlayers.containsKey(playerUUID); diff --git a/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java b/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java index bd0cbb24d..e05389461 100644 --- a/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java +++ b/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java @@ -10,13 +10,20 @@ import java.util.UUID; public interface ViaVersionAPI { /** - * Is player using 1.9? + * Is the player connection modified by ViaVersion? * - * @param player - * @return True if the client is on 1.9 + * @param player Bukkit player object + * @return True if the client is modified (At the moment it also means version 1.9 and higher) */ boolean isPorted(Player player); + /** + * Get protocol number from a player + * @param player Bukkit player object + * @return Protocol ID, For example (47=1.8-1.8.8, 107=1.9, 108=1.9.1) + */ + int getPlayerVersion(Player player); + /** * Is player using 1.9? *