9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-30 04:19:28 +00:00

Bundle of changes

This commit is contained in:
LoJoSho
2022-08-18 15:02:21 -05:00
parent 2dc068a938
commit e95b30131c
5 changed files with 271 additions and 47 deletions

View File

@@ -5,9 +5,10 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.*;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerNamedEntitySpawn;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerPlayerInfo;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerRelEntityMove;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerRelEntityMoveLook;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerSpawnEntity;
import io.github.fisher2911.hmccosmetics.user.Equipment;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -40,9 +41,15 @@ public class PacketManager {
sendArmorStandMetaContainer(armorStandId, sendTo.toArray(new Player[0]));
}
/**
* Sends meta data for armor stands.
* @param armorStandId
* @param sendTo
*/
public static void sendArmorStandMetaContainer(final int armorStandId, final Player... sendTo) {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, armorStandId);
WrappedDataWatcher metadata = new WrappedDataWatcher();
//final WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class);
@@ -56,9 +63,15 @@ public class PacketManager {
}
}
/**
* Sends cloud meta data about an entity to a player (No idea what this means?)
* @param entityId
* @param sendTo
*/
public static void sendCloudMetaData(int entityId, Player... sendTo) {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, entityId);
WrappedDataWatcher wrapper = new WrappedDataWatcher();
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
@@ -79,6 +92,12 @@ public class PacketManager {
}
}
/**
* Sends a movement packet relative to a position.
* @param entityId
* @param sendTo
*/
public static void sendRelativeMovePacket(final int entityId, Player... sendTo) {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
@@ -135,6 +154,7 @@ public class PacketManager {
final Player... sendTo) {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
packet.getModifier().writeDefaults();
packet.getUUIDs().write(0, uuid);
packet.getIntegers().write(0, entityId);
packet.getEntityTypeModifier().write(0, entityType);
@@ -142,7 +162,7 @@ public class PacketManager {
write(0, location.getX()).
write(1, location.getY()).
write(2, location.getZ());
packet.getIntegers().write(1, 1);
//packet.getIntegers().write(1, 1);
//p.sendMessage("Packet sent");
//packet.getIntegers().write(2, 0);
//packet.getIntegers().write(3, 0);
@@ -151,9 +171,6 @@ public class PacketManager {
//packet.getIntegers().write(4, (int)(((location.getYaw() * 256.0F) / 360.0F)));
//packet.getIntegers().write(5, (int)(((location.getPitch() * 256.0F) / 360.0F)));
sendPacketAsync(p, packet);
}
}
@@ -190,6 +207,7 @@ public class PacketManager {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, entityId);
WrappedDataWatcher wrapper = new WrappedDataWatcher();
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
@@ -230,16 +248,6 @@ public class PacketManager {
packet.getBytes().write(1, (byte) (location.getPitch() * 256.0F / 360.0F));
packet.getBooleans().write(0, onGround);
sendPacketAsync(p, packet);
/*
sendPacketAsync(p, new WrapperPlayServerEntityTeleport(
entityId,
new Vector3d(location.getX(), location.getY(), location.getZ()),
location.getYaw(),
location.getPitch(),
onGround
));
*/
}
}
@@ -368,23 +376,16 @@ public class PacketManager {
}
}
public static void sendRidingPacket(
final int mountId,
final int passengerId,
final Collection<? extends Player> sendTo
) {
sendRidingPacket(mountId, passengerId, sendTo.toArray(new Player[0]));
}
public static void sendRidingPacket(
final int mountId,
final int passengerId,
final Player... sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
packet.getIntegerArrays().write(0, new int[]{passengerId});
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
packet.getIntegerArrays().write(0, new int[]{passengerId});
p.sendMessage("MountID: " + mountId + " Passenger ID: " + new int[]{passengerId} + " / Raw Passenger: " + passengerId);
sendPacketAsync(p, packet);
}
}
@@ -468,13 +469,31 @@ public class PacketManager {
) {
for (final Player p : sendTo) {
// Needs testing!!!
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
//PacketContainer packet = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
wrapper.setEntityID(entityId);
wrapper.setPlayerUUID(uuid);
wrapper.setPosition(location.toVector());
wrapper.setPitch(location.getPitch());
wrapper.setYaw(location.getYaw());
/*
packet.getModifier().writeDefaults();
//packet.getEntityTypeModifier().write(0, EntityType.PLAYER);
packet.getIntegers().write(0, entityId);
packet.getUUIDs().write(0, uuid);
packet.getDoubles().write(0, location.getX())
.write(1, location.getY())
.write(2, location.getZ());
/*
WrapperPlayServerSpawnEntity wrapper = new WrapperPlayServerSpawnEntity();
wrapper.setUniqueId(uuid);
wrapper.setEntityID(entityId);
wrapper.setType(EntityType.PLAYER);
wrapper.setY(location.getY());
wrapper.setX(location.getX());
wrapper.setZ(location.getZ());
*/
//wrapper.setPitch((location.getPitch() * 360.F) / 256.0F);
//wrapper.setYaw((location.getYaw() * 360.F) / 256.0F);
/*
@@ -516,14 +535,20 @@ public class PacketManager {
final UUID uuid,
final Player... sendTo
) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
//packet.getUUIDs().write(0, uuid);
//PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
info.setAction(EnumWrappers.PlayerInfoAction.ADD_PLAYER);
PlayerInfoData data = new PlayerInfoData(WrappedGameProfile.fromPlayer(skinnedPlayer), 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(""));
info.setData(List.of(new PlayerInfoData(new WrappedGameProfile(uuid, skinnedPlayer.getName()), 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(skinnedPlayer.getName() + "-NPC"))));
/*
packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
PlayerInfoData data = new PlayerInfoData(WrappedGameProfile.fromPlayer(skinnedPlayer), -1, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(""));
packet.getPlayerInfoDataLists().write(0, List.of(
data
));
*/
/*
final List<TextureProperty> textures = PacketEvents.getAPI().getPlayerManager().getUser(skinnedPlayer).getProfile().getTextureProperties();
final WrapperPlayServerPlayerInfo.PlayerData data = new WrapperPlayServerPlayerInfo.PlayerData(
@@ -538,13 +563,7 @@ public class PacketManager {
);
*/
for (final Player p : sendTo) {
sendPacketAsync(p, packet);
/*
sendPacketAsync(p, new WrapperPlayServerPlayerInfo(
WrapperPlayServerPlayerInfo.Action.ADD_PLAYER,
data
));
*/
sendPacketAsync(p, info.getHandle());
}
}
@@ -563,6 +582,7 @@ public class PacketManager {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, playerId);
WrappedDataWatcher wrapper = new WrappedDataWatcher();
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(17, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
@@ -590,7 +610,7 @@ public class PacketManager {
packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
//packet.getUUIDs().write(0, uuid);
packet.getPlayerInfoDataLists().write(0, List.of(
new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(player.getName()))
new PlayerInfoData(new WrappedGameProfile(uuid, uuid.toString()), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(player.getName()))
));
sendPacketAsync(p, packet);
/*

View File

@@ -0,0 +1,165 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import java.util.UUID;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
public static final PacketType TYPE =
PacketType.Play.Server.NAMED_ENTITY_SPAWN;
public WrapperPlayServerNamedEntitySpawn() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) {
super(packet, TYPE);
}
/**
* Retrieve Entity ID.
* <p>
* Notes: entity's ID
*
* @return The current Entity ID
*/
public int getEntityID() {
return handle.getIntegers().read(0);
}
/**
* Set Entity ID.
*
* @param value - new value.
*/
public void setEntityID(int value) {
handle.getIntegers().write(0, value);
}
/**
* Retrieve the entity of the painting that will be spawned.
*
* @param world - the current world of the entity.
* @return The spawned entity.
*/
public Entity getEntity(World world) {
return handle.getEntityModifier(world).read(0);
}
/**
* Retrieve the entity of the painting that will be spawned.
*
* @param event - the packet event.
* @return The spawned entity.
*/
public Entity getEntity(PacketEvent event) {
return getEntity(event.getPlayer().getWorld());
}
/**
* Retrieve Player UUID.
* <p>
* Notes: player's UUID
*
* @return The current Player UUID
*/
public UUID getPlayerUUID() {
return handle.getUUIDs().read(0);
}
/**
* Set Player UUID.
*
* @param value - new value.
*/
public void setPlayerUUID(UUID value) {
handle.getUUIDs().write(0, value);
}
/**
* Retrieve the position of the spawned entity as a vector.
*
* @return The position as a vector.
*/
public Vector getPosition() {
return new Vector(getX(), getY(), getZ());
}
/**
* Set the position of the spawned entity using a vector.
*
* @param position - the new position.
*/
public void setPosition(Vector position) {
setX(position.getX());
setY(position.getY());
setZ(position.getZ());
}
public double getX() {
return handle.getDoubles().read(0);
}
public void setX(double value) {
handle.getDoubles().write(0, value);
}
public double getY() {
return handle.getDoubles().read(1);
}
public void setY(double value) {
handle.getDoubles().write(1, value);
}
public double getZ() {
return handle.getDoubles().read(2);
}
public void setZ(double value) {
handle.getDoubles().write(2, value);
}
/**
* Retrieve the yaw of the spawned entity.
*
* @return The current Yaw
*/
public float getYaw() {
return (handle.getBytes().read(0) * 360.F) / 256.0F;
}
/**
* Set the yaw of the spawned entity.
*
* @param value - new yaw.
*/
public void setYaw(float value) {
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
}
/**
* Retrieve the pitch of the spawned entity.
*
* @return The current pitch
*/
public float getPitch() {
return (handle.getBytes().read(1) * 360.F) / 256.0F;
}
/**
* Set the pitch of the spawned entity.
*
* @param value - new pitch.
*/
public void setPitch(float value) {
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
}
}

View File

@@ -0,0 +1,37 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import java.util.List;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
public class WrapperPlayServerPlayerInfo extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
public WrapperPlayServerPlayerInfo() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerPlayerInfo(PacketContainer packet) {
super(packet, TYPE);
}
public PlayerInfoAction getAction() {
return handle.getPlayerInfoAction().read(0);
}
public void setAction(PlayerInfoAction value) {
handle.getPlayerInfoAction().write(0, value);
}
public List<PlayerInfoData> getData() {
return handle.getPlayerInfoDataLists().read(0);
}
public void setData(List<PlayerInfoData> value) {
handle.getPlayerInfoDataLists().write(0, value);
}
}

View File

@@ -11,7 +11,6 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
@@ -58,6 +57,7 @@ public class Backpack {
PacketManager.sendEntitySpawnPacket(location, this.armorStandID, EntityType.ARMOR_STAND, other);
PacketManager.sendArmorStandMetaContainer(this.armorStandID, other);
PacketManager.sendRidingPacket(owner.getEntityId(), this.armorStandID, other);
//PacketManager.sendRidingPacket(owner.getEntityId(), new int[]{this.armorStandID}, other);
}
private void spawnForSelf(Player other, Location location) {
@@ -115,8 +115,9 @@ public class Backpack {
PacketManager.sendArmorStandMetaContainer(this.armorStandID, other);
PacketManager.sendRotationPacket(this.armorStandID, location, false, other);
PacketManager.sendLookPacket(this.armorStandID, location, other);
if (!isSelf || !firstPersonMode || this.particleIDS.size() == 0) {;
if (!isSelf || !firstPersonMode || this.particleIDS.size() == 0) {
PacketManager.sendRidingPacket(owner.getEntityId(), this.armorStandID, other);
//PacketManager.sendRidingPacket(owner.getEntityId(), new int[]{this.armorStandID}, other);
return;
}
for (int i = 0; i < this.particleIDS.size(); i++) {
@@ -130,5 +131,4 @@ public class Backpack {
}
PacketManager.sendRidingPacket(particleIDS.get(particleIDS.size() - 1), this.armorStandID, other);
}
}

View File

@@ -54,7 +54,7 @@ public class Wardrobe extends User {
if (settings.inDistanceOfStatic(viewer.getLocation())) {
this.currentLocation = settings.getWardrobeLocation();
userManager.get(viewer.getUniqueId()).ifPresent(user -> {
userManager.sendUpdatePacket(user, user.getEquipment());
userManager.sendUpdatePacket(user, userManager.getItemList(user));
user.despawnAttached();
user.despawnBalloon();
});
@@ -126,8 +126,9 @@ public class Wardrobe extends User {
() -> {
this.spawned = false;
final int entityId = this.getEntityId();
PacketManager.sendEntityDestroyPacket(entityId, viewer);
PacketManager.sendRemovePlayerPacket(viewer, this.id, viewer);
//PacketManager.sendEntityDestroyPacket(entityId, viewer);
//PacketManager.sendRemovePlayerPacket(viewer, this.id, viewer);
/*
PacketManager.sendEntityDestroyPacket(
this.entityIds.wardrobeViewer(),
viewer
@@ -136,6 +137,7 @@ public class Wardrobe extends User {
viewer.getEntityId(),
viewer
);
*/
this.showPlayer(this.plugin.getUserManager());
final Collection<ArmorItem> armorItems = new ArrayList<>(this.getPlayerArmor().getArmorItems());
if (settings.isApplyCosmeticsOnClose()) {
@@ -188,10 +190,10 @@ public class Wardrobe extends User {
final Location location = this.currentLocation.clone();
final int yaw = data.get();
location.setYaw(yaw);
PacketManager.sendLookPacket(entityId, location, player);
//PacketManager.sendLookPacket(entityId, location, player);
this.updateOutsideCosmetics(player, location, this.plugin.getSettings());
location.setYaw(this.getNextYaw(yaw - 30, rotationSpeed));
PacketManager.sendRotationPacket(entityId, location, true, player);
//PacketManager.sendRotationPacket(entityId, location, true, player);
data.set(this.getNextYaw(yaw, rotationSpeed));
},
() -> !this.spawned || this.currentLocation == null