12
0
Fork 0

Add BungeeTabListPlusFixer

Fix SteamwarConnectionListener loginProfile
Fix tablist with BungeeTabListPlus
Dieser Commit ist enthalten in:
yoyosource 2022-06-04 19:02:31 +02:00
Ursprung 95209dfd82
Commit afeb4c3d45
4 geänderte Dateien mit 53 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -33,4 +33,5 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation files("${projectDir}/lib/BungeeCord.jar")
implementation files("${projectDir}/lib/BungeeTabListPlus.jar")
}

Datei anzeigen

@ -1,3 +1,6 @@
name: SteamWarBungeeTeamserver
version: '${version}'
main: de.steamwar.SteamWarBungeeTeamserver
softDepends:
- BungeeTabListPlus

Datei anzeigen

@ -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());
}
}
}

Datei anzeigen

@ -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();
}
}
}