9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-26 02:19:25 +00:00

Gui Opening + Skins in Wardrobe

This commit is contained in:
LoJoSho
2022-08-29 19:24:18 -05:00
parent 1b9e2ac531
commit f5d1a09d28
3 changed files with 35 additions and 4 deletions

View File

@@ -1,5 +1,10 @@
package io.github.fisher2911.hmccosmetics.listener;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.user.UserManager;
import org.bukkit.Bukkit;
@@ -16,6 +21,22 @@ public class WardrobeListener implements Listener {
public WardrobeListener(final HMCCosmetics plugin) {
this.plugin = plugin;
this.userManager = this.plugin.getUserManager();
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmetics.getPlugin(HMCCosmetics.class), ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (!(event.getPlayer() instanceof Player)) return;
Player player = event.getPlayer();
WardrobeListener.this.userManager.get(player.getUniqueId()).ifPresent(user -> {
if (!user.getWardrobe().isActive()) return;
Bukkit.getScheduler().runTask(plugin, () -> {
WardrobeListener.this.plugin.getCosmeticsMenu().openDefault(player);
});
}
);
}
});
// TODO: REDO this
/*
PacketEvents.getAPI().getEventManager().registerListener(

View File

@@ -611,8 +611,9 @@ public class PacketManager {
) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
info.setAction(EnumWrappers.PlayerInfoAction.ADD_PLAYER);
//WrappedProfilePublicKey key = WrappedProfilePublicKey.ofPlayer(skinnedPlayer);
info.setData(List.of(new PlayerInfoData(new WrappedGameProfile(uuid, skinnedPlayer.getName()), 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(skinnedPlayer.getName() + "-NPC"))));
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, skinnedPlayer.getName() + "-NPC");
wrappedGameProfile.getProperties().put("textures", getSkin(skinnedPlayer));
info.setData(List.of(new PlayerInfoData(wrappedGameProfile, 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(skinnedPlayer.getName() + "-NPC"))));
for (final Player p : sendTo) {
sendPacketAsync(p, info.getHandle());
}
@@ -681,7 +682,6 @@ public class PacketManager {
for (final Player p : sendTo) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
info.setAction(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
//WrappedProfilePublicKey key = WrappedProfilePublicKey.ofPlayer(player);
info.setData(List.of(new PlayerInfoData(new WrappedGameProfile(uuid, player.getName()), 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(player.getName() + "-NPC"))));
sendPacketAsync(p, info.getHandle());
}
@@ -782,4 +782,14 @@ public class PacketManager {
case SPECTATOR -> 3;
};
}
public static WrappedSignedProperty getSkin(Player player) {
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
.get("textures").stream().findAny().orElse(null);
if (skinData == null)
throw new RuntimeException("Missing skin data");
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
}
}

View File

@@ -120,7 +120,7 @@ public class Backpack {
if (!isSelf || !firstPersonMode || this.particleIDS.size() == 0) {
PacketManager.sendRidingPacket(owner.getEntityId(), this.armorStandID, other);
//plugin.getLogger().info("Sent updateBackpack. Mount: " + owner.getEntityId() + " | Armorstand: " + this.armorStandID);
//PacketManager.sendRidingPacket(owner.getEntityId(), new int[]{this.armorStandID}, other);
PacketManager.sendRidingPacket(owner.getEntityId(), this.armorStandID, other);
return;
}
for (int i = 0; i < this.particleIDS.size(); i++) {