Delay tab removal to hopefully prevent skins not loading on login

This commit is contained in:
libraryaddict 2020-05-21 22:30:36 +12:00
parent 8d5efcbe56
commit 4eb367b61b
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
4 changed files with 82 additions and 3 deletions

View File

@ -318,20 +318,22 @@ public class DisguiseListener implements Listener {
@EventHandler @EventHandler
public void onLogin(PlayerRegisterChannelEvent event) { public void onLogin(PlayerRegisterChannelEvent event) {
Player player = event.getPlayer();
// If it's not a forge handshake, or we didn't register it // If it's not a forge handshake, or we didn't register it
if (!event.getChannel().equals("fml:handshake") || if (!event.getChannel().equals("fml:handshake") ||
!Bukkit.getMessenger().isOutgoingChannelRegistered(LibsDisguises.getInstance(), "fml:handshake")) { !Bukkit.getMessenger().isOutgoingChannelRegistered(LibsDisguises.getInstance(), "fml:handshake")) {
return; return;
} }
event.getPlayer() player.sendPluginMessage(LibsDisguises.getInstance(), "fml:handshake", ModdedManager.getFmlHandshake());
.sendPluginMessage(LibsDisguises.getInstance(), "fml:handshake", ModdedManager.getFmlHandshake());
} }
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) { public void onJoin(PlayerJoinEvent event) {
Player p = event.getPlayer(); Player p = event.getPlayer();
p.removeMetadata("ld_loggedin", LibsDisguises.getInstance());
plugin.getUpdateChecker().notifyUpdate(p); plugin.getUpdateChecker().notifyUpdate(p);
if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() && if (DisguiseConfig.isSaveGameProfiles() && DisguiseConfig.isUpdateGameProfiles() &&

View File

@ -37,6 +37,7 @@ public class PacketsManager {
ProtocolLibrary.getProtocolManager().addPacketListener(clientInteractEntityListener); ProtocolLibrary.getProtocolManager().addPacketListener(clientInteractEntityListener);
ProtocolLibrary.getProtocolManager().addPacketListener(tabListListener); ProtocolLibrary.getProtocolManager().addPacketListener(tabListListener);
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketListenerChannelRegister());
// Now I call this and the main listener is registered! // Now I call this and the main listener is registered!
setupMainPacketsListener(); setupMainPacketsListener();

View File

@ -8,6 +8,7 @@ import com.comphenix.protocol.wrappers.WrappedAttribute;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.*; import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
@ -28,6 +29,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; import java.util.ArrayList;
@ -178,7 +180,22 @@ public class PacketHandlerSpawn implements IPacketHandler {
if (LibsPremium.getPaidInformation() == null || if (LibsPremium.getPaidInformation() == null ||
LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) { LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) {
packets.addDelayedPacket(deleteTab, DisguiseConfig.getTablistRemoveDelay()); if (!observer.hasMetadata("ld_loggedin")) {
ArrayList<PacketContainer> toSend;
if (observer.hasMetadata("ld_tabsend") && !observer.getMetadata("ld_tabsend").isEmpty()) {
toSend = (ArrayList<PacketContainer>) observer.getMetadata("ld_tabsend").get(0).value();
} else {
toSend = new ArrayList<>();
observer.setMetadata("ld_tabsend",
new FixedMetadataValue(LibsDisguises.getInstance(), toSend));
}
toSend.add(deleteTab);
} else {
packets.addDelayedPacket(deleteTab, DisguiseConfig.getTablistRemoveDelay());
}
} }
} }

View File

@ -0,0 +1,59 @@
package me.libraryaddict.disguise.utilities.packets.packetlisteners;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import me.libraryaddict.disguise.LibsDisguises;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
/**
* Created by libraryaddict on 21/05/2020.
*/
public class PacketListenerChannelRegister extends PacketAdapter {
public PacketListenerChannelRegister() {
super(LibsDisguises.getInstance(), PacketType.Play.Client.CUSTOM_PAYLOAD);
}
@Override
public void onPacketReceiving(PacketEvent event) {
if (!event.getPacket().getMinecraftKeys().read(0).getFullKey().equals("minecraft:brand")) {
return;
}
new BukkitRunnable() {
@Override
public void run() {
Player player = event.getPlayer();
if (player.hasMetadata("ld_loggedin")) {
return;
}
if (player.hasMetadata("ld_tabsend") && !player.getMetadata("ld_tabsend").isEmpty()) {
ArrayList<PacketContainer> packets = (ArrayList<PacketContainer>) player.getMetadata("ld_tabsend")
.get(0).value();
player.removeMetadata("ld_tabsend", LibsDisguises.getInstance());
try {
for (PacketContainer packet : packets) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
player.setMetadata("ld_loggedin", new FixedMetadataValue(LibsDisguises.getInstance(), true));
}
}.runTaskLater(LibsDisguises.getInstance(), 5);
}
}