diff --git a/build.gradle b/build.gradle index 47d20b0..6b4b567 100644 --- a/build.gradle +++ b/build.gradle @@ -33,4 +33,5 @@ dependencies { testAnnotationProcessor 'org.projectlombok:lombok:1.18.22' implementation files("${projectDir}/lib/BungeeCord.jar") + implementation files("${projectDir}/lib/BungeeTabListPlus.jar") } diff --git a/src/bungee.yml b/src/bungee.yml index f170630..51ed446 100644 --- a/src/bungee.yml +++ b/src/bungee.yml @@ -1,3 +1,6 @@ name: SteamWarBungeeTeamserver version: '${version}' main: de.steamwar.SteamWarBungeeTeamserver + +softDepends: + - BungeeTabListPlus \ No newline at end of file diff --git a/src/de/steamwar/listener/SteamwarConnectionListener.java b/src/de/steamwar/listener/SteamwarConnectionListener.java index ef91b81..e96d874 100644 --- a/src/de/steamwar/listener/SteamwarConnectionListener.java +++ b/src/de/steamwar/listener/SteamwarConnectionListener.java @@ -1,11 +1,15 @@ package de.steamwar.listener; import de.steamwar.ConfigSystem; +import de.steamwar.utils.BungeeTabListPlusFixer; import io.netty.buffer.ByteBuf; +import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.event.PreLoginEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.connection.InitialHandler; +import net.md_5.bungee.connection.LoginResult; import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.protocol.Protocol; @@ -25,6 +29,8 @@ public class SteamwarConnectionListener implements Listener { private Field chField; + private Field loginProfile; + private static class SteamwarHandshake extends Handshake { public void read(ByteBuf buf) { setProtocolVersion(readVarInt(buf)); @@ -64,6 +70,9 @@ public class SteamwarConnectionListener implements Listener { chField = InitialHandler.class.getDeclaredField("ch"); chField.setAccessible(true); + + loginProfile = InitialHandler.class.getDeclaredField("loginProfile"); + loginProfile.setAccessible(true); } catch (Exception e) { e.printStackTrace(); } @@ -106,9 +115,32 @@ public class SteamwarConnectionListener implements Listener { preLoginEvent.getConnection().setOnlineMode(false); initialHandler.setUniqueId(UUID.fromString(uuidStringBuilder.toString())); + + if (split.length > 3) { + LoginResult loginResult = BungeeCord.getInstance().gson.fromJson("{\"properties\":" + split[3] + ", \"id\":\"\", \"name\":\"\"}", LoginResult.class); + try { + loginProfile.set(initialHandler, loginResult); + } catch (IllegalArgumentException | IllegalAccessException e) { + // Ignore + } + } } else if (ConfigSystem.isOnlySteamWarJoin()) { preLoginEvent.setCancelled(true); preLoginEvent.setCancelReason(ConfigSystem.getNotFromSteamWarMessage()); } } + + @EventHandler + public void postLoginEvent(PostLoginEvent postLoginEvent) { + if (!ConfigSystem.isEnabled()) return; + + String address = postLoginEvent.getPlayer().getPendingConnection().getSocketAddress().toString(); + if (!address.startsWith("/127.127.127.127:")) { + return; + } + + if (BungeeCord.getInstance().getPluginManager().getPlugin("BungeeTabListPlus") != null) { + BungeeTabListPlusFixer.remove(postLoginEvent.getPlayer()); + } + } } diff --git a/src/de/steamwar/utils/BungeeTabListPlusFixer.java b/src/de/steamwar/utils/BungeeTabListPlusFixer.java new file mode 100644 index 0000000..bf433e1 --- /dev/null +++ b/src/de/steamwar/utils/BungeeTabListPlusFixer.java @@ -0,0 +1,17 @@ +package de.steamwar.utils; + +import codecrafter47.bungeetablistplus.BungeeTabListPlus; +import de.codecrafter47.taboverlay.TabView; +import lombok.experimental.UtilityClass; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +@UtilityClass +public class BungeeTabListPlusFixer { + + public static void remove(ProxiedPlayer player) { + TabView tabView = BungeeTabListPlus.getInstance().getTabViewManager().getTabView(player); + if (tabView != null) { + tabView.deactivate(); + } + } +}