diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 3ba13e0ce..a2af05902 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -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. \ No newline at end of file diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java index 8678e47ec..5f6798c87 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitViaAPI.java @@ -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 { @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 { - return ProtocolSupportUtil.getProtocolVersion(player); + 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 diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java index 7770fba8c..0be8c11d7 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaAPI.java @@ -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 { @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 diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaAPI.java b/common/src/main/java/us/myles/ViaVersion/api/ViaAPI.java index b5a469953..87f2e50f7 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaAPI.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaAPI.java @@ -17,19 +17,19 @@ import java.util.UUID; public interface ViaAPI { /** - * 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); diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java b/common/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java index 8a615f1ad..506880ea4 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java @@ -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); diff --git a/common/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ListSubCmd.java b/common/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ListSubCmd.java index 62ae1e31a..40f34dd89 100644 --- a/common/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ListSubCmd.java +++ b/common/src/main/java/us/myles/ViaVersion/commands/defaultsubs/ListSubCmd.java @@ -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> playerVersions = new TreeMap<>(new Comparator() { - @Override - public int compare(ProtocolVersion o1, ProtocolVersion o2) { - return ProtocolVersion.getIndex(o2) - ProtocolVersion.getIndex(o1); - } - }); + Map> 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()); - playerVersions.get(key).add(p.getName()); + playerVersions.computeIfAbsent(key, s -> new HashSet<>()).add(p.getName()); } - for (Map.Entry> entry : playerVersions.entrySet()) + for (Map.Entry> 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; diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java index 08aa32b2f..066b10aa9 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaAPI.java @@ -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 { @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 diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java index b58b2cc7b..dff032f6b 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/platform/VelocityViaAPI.java @@ -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 { + @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