mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 04:19:28 +00:00
slowly moving to a more packet-based approach
This commit is contained in:
@@ -5,7 +5,6 @@ import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
@@ -89,23 +88,23 @@ public class PAPIHook extends PlaceholderExpansion {
|
||||
|
||||
public String getMaterial(Cosmetic cosmetic) {
|
||||
if (cosmetic instanceof CosmeticArmorType) {
|
||||
return ((CosmeticArmorType) cosmetic).getCosmeticItem().getType().toString();
|
||||
return ((CosmeticArmorType) cosmetic).getItem().getType().toString();
|
||||
}
|
||||
if (cosmetic instanceof CosmeticMainhandType) {
|
||||
return ((CosmeticMainhandType) cosmetic).getItemStack().getType().toString();
|
||||
return ((CosmeticMainhandType) cosmetic).getItem().getType().toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getModelData(Cosmetic cosmetic) {
|
||||
if (cosmetic instanceof CosmeticArmorType) {
|
||||
ItemStack item = ((CosmeticArmorType) cosmetic).getCosmeticItem();
|
||||
ItemStack item = ((CosmeticArmorType) cosmetic).getItem();
|
||||
if (item.hasItemMeta()) {
|
||||
return String.valueOf(item.getItemMeta().getCustomModelData());
|
||||
}
|
||||
}
|
||||
if (cosmetic instanceof CosmeticMainhandType) {
|
||||
ItemStack item = ((CosmeticMainhandType) cosmetic).getItemStack();
|
||||
ItemStack item = ((CosmeticMainhandType) cosmetic).getItem();
|
||||
if (item.hasItemMeta()) {
|
||||
return String.valueOf(item.getItemMeta().getCustomModelData());
|
||||
}
|
||||
@@ -115,13 +114,13 @@ public class PAPIHook extends PlaceholderExpansion {
|
||||
|
||||
public String getItemName(Cosmetic cosmetic) {
|
||||
if (cosmetic instanceof CosmeticArmorType) {
|
||||
ItemStack item = ((CosmeticArmorType) cosmetic).getCosmeticItem();
|
||||
ItemStack item = ((CosmeticArmorType) cosmetic).getItem();
|
||||
if (item.hasItemMeta()) {
|
||||
return item.getItemMeta().getDisplayName();
|
||||
}
|
||||
}
|
||||
if (cosmetic instanceof CosmeticMainhandType) {
|
||||
ItemStack item = ((CosmeticMainhandType) cosmetic).getItemStack();
|
||||
ItemStack item = ((CosmeticMainhandType) cosmetic).getItem();
|
||||
if (item.hasItemMeta()) {
|
||||
return item.getItemMeta().getDisplayName();
|
||||
}
|
||||
@@ -131,13 +130,13 @@ public class PAPIHook extends PlaceholderExpansion {
|
||||
|
||||
public String getItemLore(Cosmetic cosmetic) {
|
||||
if (cosmetic instanceof CosmeticArmorType) {
|
||||
ItemStack item = ((CosmeticArmorType) cosmetic).getCosmeticItem();
|
||||
ItemStack item = ((CosmeticArmorType) cosmetic).getItem();
|
||||
if (item.hasItemMeta()) {
|
||||
return String.valueOf(item.getItemMeta().getLore());
|
||||
}
|
||||
}
|
||||
if (cosmetic instanceof CosmeticMainhandType) {
|
||||
ItemStack item = ((CosmeticMainhandType) cosmetic).getItemStack();
|
||||
ItemStack item = ((CosmeticMainhandType) cosmetic).getItem();
|
||||
if (item.hasItemMeta()) {
|
||||
return String.valueOf(item.getItemMeta().getLore());
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ public class PlayerGameListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLook(PlayerMoveEvent event) {
|
||||
// TODO: Move to packets
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
if (user == null) return;
|
||||
// Really need to look into optimization of this
|
||||
@@ -247,7 +248,7 @@ public class PlayerGameListener implements Listener {
|
||||
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(InventoryUtils.BukkitCosmeticSlot(equipmentSlot));
|
||||
if (cosmeticArmor == null) continue;
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> pair = new Pair<>(InventoryUtils.itemBukkitSlot(cosmeticArmor.getEquipSlot()), cosmeticArmor.getCosmeticItem());
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> pair = new Pair<>(InventoryUtils.itemBukkitSlot(cosmeticArmor.getEquipSlot()), cosmeticArmor.getItem());
|
||||
armor.add(pair);
|
||||
}
|
||||
|
||||
@@ -273,6 +274,24 @@ public class PlayerGameListener implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
private void registerLookMovement() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.LOOK) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
//
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerTeleportMovement() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.TELEPORT_ACCEPT) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
//
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.hibiscusmc.hmccosmetics.util.packets;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.*;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
@@ -14,6 +13,7 @@ import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedE
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -132,6 +132,14 @@ public class PacketManager extends BasePacket {
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendRotationPacket(
|
||||
int entityId,
|
||||
Location location,
|
||||
boolean onGround
|
||||
) {
|
||||
sendRotationPacket(entityId, location, onGround, getWorldPlayers(location.getWorld()));
|
||||
}
|
||||
|
||||
public static void sendRotationPacket(
|
||||
int entityId,
|
||||
Location location,
|
||||
@@ -363,4 +371,8 @@ public class PacketManager extends BasePacket {
|
||||
sendPacket(p, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Player> getWorldPlayers(World world) {
|
||||
return world.getPlayers();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user