9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-29 20:09:13 +00:00

Work towards wardrobe fixes for 1.19.3

This commit is contained in:
LoJoSho
2023-01-13 17:18:20 -06:00
parent 6bf7b9fc74
commit 80f0450fa8
5 changed files with 45 additions and 13 deletions

View File

@@ -26,7 +26,7 @@ allprojects {
maven("https://jitpack.io")
// ProtocolLib repo
//maven("https://repo.dmulloy2.net/repository/public/") ProtocolLib Repo, constantly down
maven("https://repo.dmulloy2.net/repository/public/") //ProtocolLib Repo, constantly down
maven("https://repo.mineinabyss.com/releases/")
// PlaceholderAPI

View File

@@ -11,6 +11,7 @@ public class NMSHandlers {
private static final String[] SUPPORTED_VERSION = new String[]{"v1_19_R1", "v1_19_R2"};
private static NMSHandler handler;
private static String version;
public static NMSHandler getHandler() {
if (handler != null) {
@@ -21,16 +22,21 @@ public class NMSHandlers {
return handler;
}
public static String getVersion() {
return version;
}
public static void setup() {
if (handler != null) return;
final String packageName = HMCCosmeticsPlugin.getInstance().getServer().getClass().getPackage().getName();
String packageVersion = packageName.substring(packageName.lastIndexOf('.') + 1);
for (String version : SUPPORTED_VERSION) {
if (!version.contains(packageVersion)) {
for (String selectedVersion : SUPPORTED_VERSION) {
if (!selectedVersion.contains(packageVersion)) {
continue;
}
MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.SEVERE);
version = packageVersion;
try {
//Class.forName("org.bukkit.craftbukkit." + version + ".block.CraftBlock").getName();
handler = (NMSHandler) Class.forName("com.hibiscusmc.hmccosmetics.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();

View File

@@ -20,8 +20,10 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class PacketManager extends BasePacket {
@@ -281,8 +283,18 @@ public class PacketManager extends BasePacket {
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
WrappedSignedProperty skinData = PlayerUtils.getSkin(skinnedPlayer);
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
info.setData(List.of(new PlayerInfoData(wrappedGameProfile, 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(name))));
if (!NMSHandlers.getVersion().contains("v1_19_R2")) {
info.setData(List.of(new PlayerInfoData(wrappedGameProfile, 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(name))));
} else {
info.getHandle().getPlayerInfoDataLists().write(1, Collections.singletonList(new PlayerInfoData(
wrappedGameProfile,
0,
EnumWrappers.NativeGameMode.CREATIVE,
WrappedChatComponent.fromText(name)
)));
}
for (final Player p : sendTo) sendPacket(p, info.getHandle());
return;
}
@@ -330,16 +342,22 @@ public class PacketManager extends BasePacket {
final UUID uuid,
final List<Player> sendTo
) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
info.setAction(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
if (!NMSHandlers.getVersion().contains("v1_19_R2")) {
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
info.setAction(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
String name = "Mannequin-" + player.getEntityId();
while (name.length() > 16) {
name = name.substring(16);
String name = "Mannequin-" + player.getEntityId();
while (name.length() > 16) {
name = name.substring(16);
}
info.setData(List.of(new PlayerInfoData(new WrappedGameProfile(uuid, player.getName()), 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(name))));
for (final Player p : sendTo) sendPacket(p, info.getHandle());
return;
}
info.setData(List.of(new PlayerInfoData(new WrappedGameProfile(uuid, player.getName()), 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(name))));
for (final Player p : sendTo) sendPacket(p, info.getHandle());
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO_REMOVE);
packet.getUUIDLists().write(0, List.of(uuid));
for (final Player p : sendTo) sendPacket(p, packet);
}
public static void sendLeashPacket(

View File

@@ -4,8 +4,10 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import java.util.List;
import java.util.Set;
public class WrapperPlayServerPlayerInfo extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
@@ -24,7 +26,11 @@ public class WrapperPlayServerPlayerInfo extends AbstractPacket {
}
public void setAction(PlayerInfoAction value) {
handle.getPlayerInfoAction().write(0, value);
if (!NMSHandlers.getVersion().contains("v1_19_R2")) {
handle.getPlayerInfoAction().write(0, value);
} else {
handle.getPlayerInfoActions().write(0, Set.of(value));
}
}
public List<PlayerInfoData> getData() {

View File

@@ -12,6 +12,7 @@ import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
import com.mojang.datafixers.util.Pair;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
@@ -42,6 +43,7 @@ import org.bukkit.scoreboard.Scoreboard;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override