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

Merge pull request #31 from LoJoSho/lojo_dev

Experimental ProtocolLib Switch
This commit is contained in:
lucian929
2022-08-15 16:25:20 -04:00
committed by GitHub
25 changed files with 1621 additions and 399 deletions

View File

@@ -39,13 +39,13 @@ dependencies {
compileOnly("com.mojang:authlib:1.5.25")
compileOnly("org.spigotmc:spigot:1.16.5-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:22.0.0")
// compileOnly("com.comphenix.protocol:ProtocolLib:4.7.0")
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.11.1")
compileOnly("com.github.oraxen:oraxen:-SNAPSHOT")
compileOnly("com.github.LoneDev6:API-ItemsAdder:2.5.4")
compileOnly("net.citizensnpcs:citizens-main:2.0.29-SNAPSHOT")
compileOnly("com.ticxo.modelengine:api:R2.5.0")
compileOnly("com.github.retrooper.packetevents:spigot:2.0-SNAPSHOT")
//compileOnly("com.github.retrooper.packetevents:spigot:2.0-SNAPSHOT")
implementation("net.kyori:adventure-api:4.10.0")
implementation ("net.kyori:adventure-text-minimessage:4.10.0-SNAPSHOT")
implementation("net.kyori:adventure-platform-bukkit:4.0.1")
@@ -111,7 +111,7 @@ bukkit {
name = "HMCCosmetics"
authors = listOf("MasterOfTheFish")
softDepend = listOf("Multiverse", "PlaceholderAPI", "Oraxen", "ItemsAdder", "Citizens", "ModelEngine")
depend = listOf("packetevents")
depend = listOf("ProtocolLib")
permissions {
register("hmccosmetics.cmd.default") {
default = BukkitPluginDescription.Permission.Default.OP

View File

@@ -1,6 +1,7 @@
package io.github.fisher2911.hmccosmetics;
import com.github.retrooper.packetevents.PacketEvents;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import io.github.fisher2911.hmccosmetics.command.CosmeticsCommand;
import io.github.fisher2911.hmccosmetics.concurrent.Threads;
import io.github.fisher2911.hmccosmetics.config.Settings;
@@ -57,6 +58,7 @@ public class HMCCosmetics extends JavaPlugin {
private Database database;
private BukkitTask saveTask;
private ProtocolManager manager;
/* // commented because PacketEvents is no longer shaded
@Override
@@ -77,6 +79,7 @@ public class HMCCosmetics extends JavaPlugin {
this.cosmeticManager = new CosmeticManager(new HashMap<>(), new HashMap<>(), new HashMap<>());
this.cosmeticsMenu = new CosmeticsMenu(this);
this.tokenLoader = new TokenLoader(this);
this.manager = ProtocolLibrary.getProtocolManager();
this.userManager.startTeleportTask();
@@ -107,7 +110,7 @@ public class HMCCosmetics extends JavaPlugin {
@Override
public void onDisable() {
PacketEvents.getAPI().terminate();
//PacketEvents.getAPI().terminate();
this.saveTask.cancel();
this.database.saveAll();
this.messageHandler.close();
@@ -241,6 +244,9 @@ public class HMCCosmetics extends JavaPlugin {
public Database getDatabase() {
return database;
}
public ProtocolManager getProtocolManager() {
return manager;
}
}

View File

@@ -1,17 +1,17 @@
package io.github.fisher2911.hmccosmetics.config;
import com.github.retrooper.packetevents.protocol.sound.SoundCategory;
import com.comphenix.protocol.wrappers.EnumWrappers;
import net.minecraft.server.v1_16_R3.MinecraftKey;
import org.bukkit.entity.Player;
public class SoundData {
private final String name;
private final SoundCategory soundCategory;
private final EnumWrappers.SoundCategory soundCategory;
private final float volume;
private final float pitch;
public SoundData(final String name, final SoundCategory soundCategory, final float volume, final float pitch) {
public SoundData(final String name, final EnumWrappers.SoundCategory soundCategory, final float volume, final float pitch) {
this.name = name;
this.soundCategory = soundCategory;
this.volume = volume;
@@ -30,7 +30,7 @@ public class SoundData {
return pitch;
}
public SoundCategory getSoundCategory() {
public EnumWrappers.SoundCategory getSoundCategory() {
return soundCategory;
}

View File

@@ -1,6 +1,6 @@
package io.github.fisher2911.hmccosmetics.config;
import com.github.retrooper.packetevents.protocol.sound.SoundCategory;
import com.comphenix.protocol.wrappers.EnumWrappers;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
@@ -37,7 +37,7 @@ public class SoundSerializer implements TypeSerializer<SoundData> {
} else {
soundData = new SoundData(
soundName,
SoundCategory.valueOf(category),
EnumWrappers.SoundCategory.valueOf(category),
volume,
pitch
);

View File

@@ -16,13 +16,13 @@ import io.github.fisher2911.hmccosmetics.user.EntityIds;
import io.github.fisher2911.hmccosmetics.user.NPCUser;
import io.github.fisher2911.hmccosmetics.user.User;
import io.github.fisher2911.hmccosmetics.user.Wardrobe;
import io.github.retrooper.packetevents.util.SpigotReflectionUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
public class Database {
@@ -234,6 +234,6 @@ public class Database {
}
public static int getNextEntityId() {
return SpigotReflectionUtil.generateEntityId();
return new AtomicInteger().incrementAndGet();
}
}

View File

@@ -348,18 +348,6 @@ public class ArmorItem extends WrappedGuiItem {
};
}
@Nullable
public static Type fromPacketSlot(final com.github.retrooper.packetevents.protocol.player.EquipmentSlot slot) {
return switch (slot) {
case HELMET -> Type.HAT;
case CHEST_PLATE -> Type.CHEST_PLATE;
case LEGGINGS -> Type.PANTS;
case BOOTS -> Type.BOOTS;
case OFF_HAND -> Type.OFF_HAND;
default -> null;
};
}
@Nullable
public static Type fromEquipmentSlot(final EquipmentSlot slot) {
for (final Type type : values()) {

View File

@@ -1,14 +1,18 @@
package io.github.fisher2911.hmccosmetics.listener;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.user.Equipment;
import io.github.fisher2911.hmccosmetics.user.User;
import io.github.fisher2911.hmccosmetics.user.UserManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.EquipmentSlot;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
public class ClickListener implements Listener {
@@ -56,15 +60,18 @@ public class ClickListener implements Listener {
this.plugin = plugin;
this.userManager = this.plugin.getUserManager();
}
/*
// @EventHandler
// public void onArmorSlotClick(final InventoryClickEvent event) {
// final int slot = event.getSlot();
// if (!(event.getWhoClicked() instanceof final Player player)) return;
// if (slot >= 36 && slot <= 40) {
// this.fixInventory(player);
// }
// }
@EventHandler
public void onArmorSlotClick(final InventoryClickEvent event) {
final int slot = event.getSlot();
if (!(event.getWhoClicked() instanceof Player)) return;
if (slot >= 36 && slot <= 40) {
this.fixInventory(((Player) event.getWhoClicked()).getPlayer());
}
}
*/
//
// @EventHandler
// public void onBlockClick(final PlayerInteractEvent event) {
@@ -102,22 +109,25 @@ public class ClickListener implements Listener {
// this.userManager.get(player.getUniqueId()).ifPresent(this::doRunnable);
// }
//
// private void fixInventory(final Player player) {
// final Optional<User> optionalUser = this.userManager.get(player.getUniqueId());
//
// if (optionalUser.isEmpty()) {
// return;
// }
//
// this.doRunnable(optionalUser.get());
// }
//
// private void doRunnable(final User user) {
// Bukkit.getScheduler().runTaskLaterAsynchronously(
// this.plugin, () -> this.userManager.updateCosmetics(user),
// 1);
// }
//
/*
private void fixInventory(final Player player) {
final Optional<User> optionalUser = this.userManager.get(player.getUniqueId());
if (optionalUser.isEmpty()) {
return;
}
this.doRunnable(optionalUser.get());
}
private void doRunnable(final User user) {
Equipment equip = this.userManager.getItemList(user, user.getEquipment(), Collections.emptySet());
Bukkit.getScheduler().runTaskLaterAsynchronously(
this.plugin, () -> this.userManager.sendUpdatePacket(user, equip),
1);
}
*/
// private void checkFix(final Player player, final int clickedSlot, final ItemStack itemStack) {
// final EquipmentSlot slot = this.getArmorSlot(itemStack.getType());
// if (slot == null) return;

View File

@@ -1,24 +1,23 @@
package io.github.fisher2911.hmccosmetics.listener;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientClickWindow;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerWindowItems;
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.config.CosmeticSettings;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayClientWindowClick;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerWindowItems;
import io.github.fisher2911.hmccosmetics.task.DelayedTask;
import io.github.fisher2911.hmccosmetics.task.TaskManager;
import io.github.fisher2911.hmccosmetics.user.Equipment;
import io.github.fisher2911.hmccosmetics.user.User;
import io.github.fisher2911.hmccosmetics.user.UserManager;
import io.github.fisher2911.hmccosmetics.util.Utils;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -36,13 +35,8 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.logging.Level;
public class CosmeticFixListener implements Listener {
@@ -140,117 +134,138 @@ public class CosmeticFixListener implements Listener {
}
private void registerInventoryClickListener() {
PacketEvents.getAPI().getEventManager().registerListener(
new PacketListenerAbstract() {
@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() != PacketType.Play.Client.CLICK_WINDOW) return;
final WrapperPlayClientClickWindow packet = new WrapperPlayClientClickWindow(event);
if (packet.getWindowId() != 0) return;
if (!(event.getPlayer() instanceof final Player player)) return;
int slotClicked = packet.getSlot();
taskManager.submit(() -> {
final Optional<User> optionalUser = userManager.get(player.getUniqueId());
if (optionalUser.isEmpty()) return;
final User user = optionalUser.get();
EquipmentSlot slot = getPacketArmorSlot(slotClicked);
if (slot == null) {
return;
}
final EntityEquipment entityEquipment = player.getEquipment();
if (entityEquipment == null) return;
final ItemStack current = Utils.replaceIfNull(entityEquipment.getItem(slot), new ItemStack(Material.AIR));
final ArmorItem.Type type = ArmorItem.Type.fromEquipmentSlot(slot);
if (type == null) return;
updateOnClick(
player,
slot,
user,
type,
current
);
});
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmetics.getPlugin(HMCCosmetics.class), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
@Override
public void onPacketReceiving(PacketEvent event) {
Player player = event.getPlayer();
if (event.getPacketType() != PacketType.Play.Client.WINDOW_CLICK) return;
if (event.getPacket().getIntegers().read(0) != 0) return;
if (!(event.getPlayer() instanceof Player)) return;
int slotClicked = event.getPacket().getIntegers().read(0);
taskManager.submit(() -> {
final Optional<User> optionalUser = userManager.get(player.getUniqueId());
if (optionalUser.isEmpty()) return;
final User user = optionalUser.get();
EquipmentSlot slot = getPacketArmorSlot(slotClicked);
if (slot == null) {
return;
}
}
);
final EntityEquipment entityEquipment = player.getEquipment();
if (entityEquipment == null) return;
final ItemStack current = Utils.replaceIfNull(entityEquipment.getItem(slot), new ItemStack(Material.AIR));
final ArmorItem.Type type = ArmorItem.Type.fromEquipmentSlot(slot);
if (type == null) return;
updateOnClick(
player,
slot,
user,
type,
current
);
});
}
});
}
private void updateOnClick(final Player player, final EquipmentSlot slot, final User user, final ArmorItem.Type type, final ItemStack current) {
//plugin.getLogger().log(Level.INFO, "updateOnClick (171)");
final Location location = player.getLocation();
final Equipment equipment = Equipment.fromEntityEquipment(player.getEquipment());
final Equipment equipment = userManager.getItemList(user);
final ItemStack cosmetic = userManager.getCosmeticItem(
user.getPlayerArmor().getItem(type),
current,
ArmorItem.Status.APPLIED,
slot
);
//plugin.getLogger().log(Level.INFO, "Set cosmetic in " + slot + " to " + cosmetic);
if (cosmetic != null && cosmetic.getType() != Material.AIR) equipment.setItem(slot, cosmetic);
//plugin.getLogger().log(Level.INFO, "Set cosmetic in " + slot + " to " + cosmetic + "(done)");
final List<com.github.retrooper.packetevents.protocol.player.Equipment> items =
final Equipment items =
userManager.getItemList(user, equipment, Collections.emptySet());
items.removeIf(e -> {
final com.github.retrooper.packetevents.protocol.player.EquipmentSlot s = e.getSlot();
final ArmorItem.Type t = ArmorItem.Type.fromPacketSlot(s);
if (t == null) return false;
for (EquipmentSlot e : items.keys()) {
//final EquipmentSlot s = e.getSlot();
final ArmorItem.Type t = ArmorItem.Type.fromWrapper(e);
ItemStack air = new ItemStack(Material.AIR);
if (t == null) {
//plugin.getLogger().log(Level.INFO, "T is null");
equipment.setItem(e, air);
return;
}
final ArmorItem armorItem = user.getPlayerArmor().getItem(t);
final ItemStack i = SpigotConversionUtil.toBukkitItemStack(e.getItem());
return armorItem.isEmpty() && i.equals(equipment.getItem(t.getSlot()));
});
final ItemStack i = equipment.getItem(e);
if (i == null) {
//plugin.getLogger().log(Level.INFO, "I is null");
equipment.setItem(e, air);
return;
}
Boolean remove = armorItem.isEmpty() && i.equals(equipment.getItem(t.getSlot()));
if (remove) {
//plugin.getLogger().log(Level.INFO, "Boolean is true");
equipment.setItem(e, air);
return;
}
return;
}
for (final Player other : Bukkit.getOnlinePlayers()) {
if (!settings.isInViewDistance(location, other.getLocation())) continue;
userManager.sendUpdatePacket(
user,
items
equipment
);
}
}
private void registerMenuChangeListener() {
PacketEvents.getAPI().getEventManager().registerListener(
new PacketListenerAbstract() {
@Override
public void onPacketSend(PacketSendEvent event) {
if (event.getPacketType() != PacketType.Play.Server.WINDOW_ITEMS) return;
final WrapperPlayServerWindowItems packet = new WrapperPlayServerWindowItems(event);
if (!(event.getPlayer() instanceof final Player player)) return;
final int windowId = packet.getWindowId();
final List<com.github.retrooper.packetevents.protocol.item.ItemStack> itemStacks = packet.getItems();
taskManager.submit(() -> {
final Optional<User> optionalUser = userManager.get(player.getUniqueId());
if (optionalUser.isEmpty()) return;
final User user = optionalUser.get();
if (windowId != 0) return;
final int size = itemStacks.size();
final PlayerArmor playerArmor = user.getPlayerArmor();
final List<com.github.retrooper.packetevents.protocol.player.Equipment> equipmentList = new ArrayList<>();
for (final ArmorItem armorItem : playerArmor.getArmorItems()) {
final ArmorItem.Type type = armorItem.getType();
final EquipmentSlot slot = type.getSlot();
if (slot == null) continue;
final int packetSlot = getPacketArmorSlot(slot);
if (packetSlot == -1) continue;
if (packetSlot >= size) continue;
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmetics.getPlugin(HMCCosmetics.class), ListenerPriority.NORMAL, PacketType.Play.Server.WINDOW_ITEMS) {
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
if (!event.getPacketType().equals(PacketType.Play.Server.WINDOW_ITEMS)) return;
if (event.getPlayer() == null) return;
WrapperPlayServerWindowItems wrapper = new WrapperPlayServerWindowItems(event.getPacket());
if (!(event.getPlayer() instanceof Player)) return;
final int windowId = wrapper.getWindowId();
final ItemStack current = SpigotConversionUtil.toBukkitItemStack(itemStacks.get(packetSlot));
final com.github.retrooper.packetevents.protocol.item.ItemStack setTo =
SpigotConversionUtil.fromBukkitItemStack(userManager.getCosmeticItem(
armorItem,
current,
ArmorItem.Status.APPLIED,
slot
));
if (SpigotConversionUtil.fromBukkitItemStack(current).equals(setTo)) continue;
equipmentList.add(PacketManager.getEquipment(setTo, slot));
}
userManager.sendUpdatePacket(
user,
equipmentList
);
});
// packet.setItems(itemStacks);
List<ItemStack> items = wrapper.getSlotData();
taskManager.submit(() -> {
final Optional<User> optionalUser = userManager.get(player.getUniqueId());
if (optionalUser.isEmpty()) return;
final User user = optionalUser.get();
if (windowId != 0) return;
final int size = items.size();
final PlayerArmor playerArmor = user.getPlayerArmor();
//final List<Equipment> equipmentList = new ArrayList<>();
final Equipment equip = userManager.getItemList(user);
for (final ArmorItem armorItem : playerArmor.getArmorItems()) {
final ArmorItem.Type type = armorItem.getType();
final EquipmentSlot slot = type.getSlot();
if (slot == null) continue;
final int packetSlot = getPacketArmorSlot(slot);
if (packetSlot == -1) continue;
if (packetSlot >= size) continue;
final ItemStack current = (items.get(packetSlot));
final ItemStack setTo =
(userManager.getCosmeticItem(
armorItem,
current,
ArmorItem.Status.APPLIED,
slot
));
if ((current).equals(setTo)) continue;
equip.setItem(slot, setTo);
//plugin.getLogger().log(Level.INFO, "Setto " + setTo);
//equipmentList.add(PacketManager.getEquipment(setTo, slot));
}
}
);
userManager.sendUpdatePacket(
user,
equip
);
});
}
});
}
private int getPacketArmorSlot(final EquipmentSlot slot) {
@@ -349,10 +364,11 @@ public class CosmeticFixListener implements Listener {
}
return null;
}
/*
private void fixCosmetics(final Player player) {
Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin,
() -> this.userManager.updateCosmetics(player.getUniqueId()), 2);
}
*/
}

View File

@@ -1,9 +1,5 @@
package io.github.fisher2911.hmccosmetics.listener;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.user.UserManager;
import org.bukkit.Bukkit;
@@ -20,6 +16,8 @@ public class WardrobeListener implements Listener {
public WardrobeListener(final HMCCosmetics plugin) {
this.plugin = plugin;
this.userManager = this.plugin.getUserManager();
// TODO: REDO this
/*
PacketEvents.getAPI().getEventManager().registerListener(
new PacketListenerAbstract() {
@Override
@@ -35,6 +33,8 @@ public class WardrobeListener implements Listener {
);
}
});
*/
}
@EventHandler

View File

@@ -1,26 +1,22 @@
package io.github.fisher2911.hmccosmetics.packet;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.entity.pose.EntityPose;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.player.*;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.github.retrooper.packetevents.wrapper.play.server.*;
import com.comphenix.protocol.PacketType;
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.retrooper.packetevents.util.SpigotConversionUtil;
import net.kyori.adventure.text.Component;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerRelEntityMove;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerRelEntityMoveLook;
import io.github.fisher2911.hmccosmetics.user.Equipment;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntArrayList;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
public class PacketManager {
//
@@ -45,65 +41,63 @@ public class PacketManager {
public static void sendArmorStandMetaContainer(final int armorStandId, final Player... sendTo) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityMetadata(
armorStandId,
List.of(
new EntityData(0, EntityDataTypes.BYTE, (byte) 0x20),
new EntityData(15, EntityDataTypes.BYTE, (byte) 0x10)
)
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, armorStandId);
WrappedDataWatcher metadata = new WrappedDataWatcher();
//final WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class);
if (metadata == null) return;
// 0x10 & 0x20
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
packet.getWatchableCollectionModifier().write(0, metadata.getWatchableObjects());
sendPacketAsync(p, packet);
}
}
public static void sendCloudMetaData(int entityId, Player... sendTo) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityMetadata(
entityId,
List.of(
new EntityData(0, EntityDataTypes.BYTE, (byte) 0),
new EntityData(2, EntityDataTypes.OPTIONAL_COMPONENT, Optional.empty()),
new EntityData(6, EntityDataTypes.ENTITY_POSE, EntityPose.STANDING),
new EntityData(4, EntityDataTypes.BOOLEAN, false),
new EntityData(8, EntityDataTypes.FLOAT, 0.0f),
new EntityData(9, EntityDataTypes.INT, 0),
new EntityData(11, EntityDataTypes.PARTICLE, 21),
new EntityData(10, EntityDataTypes.BOOLEAN, false),
new EntityData(1, EntityDataTypes.INT, 300),
new EntityData(3, EntityDataTypes.BOOLEAN, false),
new EntityData(7, EntityDataTypes.INT, 0),
new EntityData(5, EntityDataTypes.BOOLEAN, false)
)
));
}
}
public static void sendVelocityPacket(final int entityId, Player... sendTo) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityVelocity(
entityId,
new Vector3d(0.5, 0.5, 0.5)
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, entityId);
WrappedDataWatcher wrapper = new WrappedDataWatcher();
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.get(Optional.class)), Optional.empty());
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(6, WrappedDataWatcher.Registry.get(EnumWrappers.EntityPose.class)), EnumWrappers.EntityPose.STANDING);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(4, WrappedDataWatcher.Registry.get(Boolean.class)), false);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(8, WrappedDataWatcher.Registry.get(Float.class)), 0.0f);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(9, WrappedDataWatcher.Registry.get(int.class)), 0);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(11, WrappedDataWatcher.Registry.get(EnumWrappers.Particle.class)), 21);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(10, WrappedDataWatcher.Registry.get(Boolean.class)), false);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, WrappedDataWatcher.Registry.get(Boolean.class)), false);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(4, WrappedDataWatcher.Registry.get(Boolean.class)), false);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)), false);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(1, WrappedDataWatcher.Registry.get(int.class)), 300);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(7, WrappedDataWatcher.Registry.get(int.class)), 0);
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
sendPacketAsync(p, packet);
}
}
public static void sendRelativeMovePacket(final int entityId, Player... sendTo) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityRelativeMove(
entityId,
0.0,
0.0,
0.0,
false
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
wrapper.setDx(0.0);
wrapper.setDy(0.0);
wrapper.setDz(0.0);
wrapper.setOnGround(false);
sendPacketAsync(p, wrapper.getHandle());
}
}
public static void sendHeadLookPacket(int entityId, float yaw, Player... sendTo) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityHeadLook(
entityId,
yaw
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE_LOOK);
WrapperPlayServerRelEntityMoveLook wrapper = new WrapperPlayServerRelEntityMoveLook(packet);
wrapper.setYaw(yaw);
wrapper.setEntityID(entityId);
sendPacketAsync(p, wrapper.getHandle());
}
}
@@ -139,17 +133,26 @@ public class PacketManager {
final UUID uuid,
final Player... sendTo) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerSpawnEntity(
entityId,
Optional.of(uuid),
entityType,
new Vector3d(location.getX(), location.getY(), location.getZ()),
location.getYaw(),
location.getPitch(),
0f,
0,
Optional.of(Vector3d.zero())
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
packet.getUUIDs().write(0, uuid);
packet.getIntegers().write(0, entityId);
packet.getEntityTypeModifier().write(0, entityType);
packet.getDoubles().
write(0, location.getX()).
write(1, location.getY()).
write(2, location.getZ());
packet.getIntegers().write(1, 1);
//p.sendMessage("Packet sent");
//packet.getIntegers().write(2, 0);
//packet.getIntegers().write(3, 0);
//packet.getIntegers().write(4, 0);
//packet.getIntegers().write(5, 0);
//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);
}
}
@@ -161,17 +164,20 @@ public class PacketManager {
int data,
final Player... sendTo) {
for (final Player p : sendTo) {
/*
sendPacketAsync(p, new WrapperPlayServerSpawnEntity(
entityId,
Optional.of(uuid),
entityType,
new Vector3d(location.getX(), location.getY(), location.getZ()),
0,
0,
0f,
0, // pitch
0, // yaw
0f, // headyaw
data,
Optional.of(Vector3d.zero())
));
*/
}
}
@@ -181,10 +187,20 @@ public class PacketManager {
public static void sendInvisibilityPacket(final int entityId, final Player... sendTo) {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, entityId);
WrappedDataWatcher wrapper = new WrappedDataWatcher();
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
//packet.setMeta(String.valueOf(entityId), List.of(new EntityData(0, EntityDataTypes.BYTE, (byte) 0x20)));
/*
sendPacketAsync(p, new WrapperPlayServerEntityMetadata(
entityId,
List.of(new EntityData(0, EntityDataTypes.BYTE, (byte) 0x20))
));
*/
sendPacketAsync(p, packet);
}
}
@@ -204,6 +220,16 @@ public class PacketManager {
final Player... sendTo
) {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
packet.getIntegers().write(0, entityId);
packet.getDoubles().write(0, location.getX());
packet.getDoubles().write(1, location.getY());
packet.getDoubles().write(2, location.getZ());
packet.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
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()),
@@ -211,6 +237,8 @@ public class PacketManager {
location.getPitch(),
onGround
));
*/
}
}
@@ -232,13 +260,14 @@ public class PacketManager {
final Player... sendTo
) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityRelativeMove(
entityId,
to.getX() - from.getX(),
to.getY() - from.getY(),
to.getZ() - from.getZ(),
onGround
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
wrapper.setEntityID(entityId);
wrapper.setDx(to.getX() - from.getX());
wrapper.setDy(to.getY() - from.getY());
wrapper.setDz(to.getZ() - from.getZ());
wrapper.setOnGround(onGround);
sendPacketAsync(p, wrapper.getHandle());
}
}
@@ -256,32 +285,39 @@ public class PacketManager {
final Player... sendTo
) {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY);
packet.getIntegers().write(0, balloonId);
packet.getIntegers().write(1, entityId);
// Leash?
packet.getBooleans().write(0, true);
/*
sendPacketAsync(p, new WrapperPlayServerAttachEntity(
balloonId,
entityId,
true
));
*/
sendPacketAsync(p, packet);
}
}
public static void sendEquipmentPacket(
final List<Equipment> equipmentList,
final int entityId,
final Collection<? extends Player> sendTo
) {
sendEquipmentPacket(equipmentList, entityId, sendTo.toArray(new Player[0]));
}
public static void sendEquipmentPacket(
final List<Equipment> equipmentList,
final int entityId,
final Player... sendTo
) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityEquipment(
entityId,
equipmentList
));
final io.github.fisher2911.hmccosmetics.user.Equipment equipment,
final int entityID,
final Player... sendTo) {
// DONE: Fix Packet causing player disconnect! https://i.imgur.com/l4D6lmM.png
//List<PacketContainer> packets = new ArrayList<>();
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
packet.getIntegers().write(0, entityID);
List<Pair<EnumWrappers.ItemSlot, ItemStack>> list = new ArrayList<>();
for (EquipmentSlot slot : equipment.keys()) {
if (itemBukkitSlot(slot) != null) list.add(new Pair<>(itemBukkitSlot(slot), equipment.getItem(slot)));
}
if (list == null) return;
packet.getSlotStackPairLists().write(0, list);
for (Player p : sendTo) {
//p.sendMessage("Offhand Cosmetic: " + equipment.getItem(EquipmentSlot.OFF_HAND));
sendPacketAsync(p, packet);
}
}
@@ -301,12 +337,12 @@ public class PacketManager {
final Player... sendTo
) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityRotation(
entityId,
location.getYaw(),
location.getPitch(),
onGround
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
packet.getIntegers().write(0, entityId);
packet.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
packet.getBytes().write(1, (byte) (location.getPitch() * 256.0F / 360.0F));
packet.getBooleans().write(0, onGround);
sendPacketAsync(p, packet);
}
}
@@ -324,10 +360,10 @@ public class PacketManager {
final Player... sendTo
) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityHeadLook(
entityId,
location.getYaw()
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
packet.getIntegers().write(0, entityId);
packet.getBytes().write(0, (byte) location.getYaw());
sendPacketAsync(p, packet);
}
}
@@ -345,10 +381,11 @@ public class PacketManager {
final Player... sendTo
) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerSetPassengers(
mountId,
new int[]{passengerId}
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
packet.getIntegers().write(0, mountId);
packet.getIntegerArrays().write(0, new int[]{passengerId});
sendPacketAsync(p, packet);
}
}
@@ -358,13 +395,17 @@ public class PacketManager {
public static void sendEntityDestroyPacket(final int entityId, final Player... sendTo) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerDestroyEntities(entityId));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
sendPacketAsync(p, packet);
}
}
public static void sendCameraPacket(final int entityId, final Player... sendTo) {
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerCamera(entityId));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CAMERA);
packet.getIntegers().write(0, entityId);
sendPacketAsync(p, packet);
}
}
@@ -426,6 +467,17 @@ public class PacketManager {
final Player... sendTo
) {
for (final Player p : sendTo) {
// Needs testing!!!
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
packet.getIntegers().write(0, entityId);
packet.getUUIDs().write(0, uuid);
packet.getDoubles().write(0, location.getX())
.write(1, location.getY())
.write(2, location.getZ());
packet.getFloat().write(0, location.getYaw()).write(1, location.getPitch());
sendPacketAsync(p, packet);
/*
sendPacketAsync(p, new WrapperPlayServerSpawnPlayer(
entityId,
uuid,
@@ -437,6 +489,7 @@ public class PacketManager {
location.getPitch()
)
));
*/
}
}
@@ -453,6 +506,13 @@ 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);
packet.getPlayerInfoDataLists().write(0, List.of(
new PlayerInfoData(WrappedGameProfile.fromPlayer(skinnedPlayer), 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(skinnedPlayer.getName()))
));
/*
final List<TextureProperty> textures = PacketEvents.getAPI().getPlayerManager().getUser(skinnedPlayer).getProfile().getTextureProperties();
final WrapperPlayServerPlayerInfo.PlayerData data = new WrapperPlayServerPlayerInfo.PlayerData(
Component.text(""),
@@ -464,11 +524,15 @@ public class PacketManager {
GameMode.CREATIVE,
0
);
*/
for (final Player p : sendTo) {
sendPacketAsync(p, packet);
/*
sendPacketAsync(p, new WrapperPlayServerPlayerInfo(
WrapperPlayServerPlayerInfo.Action.ADD_PLAYER,
data
));
*/
}
}
@@ -485,13 +549,14 @@ public class PacketManager {
) {
final byte mask = 0x01 | 0x02 | 0x04 | 0x08 | 0x010 | 0x020 | 0x40;
for (final Player p : sendTo) {
sendPacketAsync(p, new WrapperPlayServerEntityMetadata(
playerId,
List.of(
new EntityData(17, EntityDataTypes.BYTE, mask),
new EntityData(15, EntityDataTypes.BYTE, (byte) 0x10)
)
));
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, playerId);
WrappedDataWatcher wrapper = new WrappedDataWatcher();
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(17, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
sendPacketAsync(p, packet);
}
}
@@ -509,6 +574,14 @@ public class PacketManager {
final Player... sendTo
) {
for (final Player p : sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
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()))
));
sendPacketAsync(p, packet);
/*
sendPacketAsync(p, new WrapperPlayServerPlayerInfo(
WrapperPlayServerPlayerInfo.Action.REMOVE_PLAYER,
new WrapperPlayServerPlayerInfo.PlayerData(
@@ -521,39 +594,25 @@ public class PacketManager {
0
)
));
*/
}
}
public static void sendPacketAsync(final Player player, final PacketWrapper<?> packet) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmetics.getPlugin(HMCCosmetics.class), () ->
PacketEvents.getAPI().getPlayerManager().sendPacket(player, packet)
);
public static void sendPacketAsync(final Player player, final PacketContainer packet) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmetics.getPlugin(HMCCosmetics.class), () -> {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
});
}
public static void sendPacketAsyncSilently(final Player player, final PacketWrapper<?> packet) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmetics.getPlugin(HMCCosmetics.class), () ->
PacketEvents.getAPI().getPlayerManager().sendPacketSilently(player, packet)
);
}
public static com.github.retrooper.packetevents.protocol.player.Equipment getEquipment(
public static io.github.fisher2911.hmccosmetics.user.Equipment getEquipment(
final ItemStack itemStack,
final org.bukkit.inventory.EquipmentSlot slot
) {
return getEquipment(SpigotConversionUtil.fromBukkitItemStack(itemStack), slot);
Equipment equip = new Equipment();
equip.setItem(slot, itemStack);
return equip;
}
public static com.github.retrooper.packetevents.protocol.player.Equipment getEquipment(
final com.github.retrooper.packetevents.protocol.item.ItemStack itemStack,
final org.bukkit.inventory.EquipmentSlot slot
) {
return new com.github.retrooper.packetevents.protocol.player.Equipment(
PacketManager.fromBukkitSlot(slot),
itemStack
);
}
/*
public static EquipmentSlot fromBukkitSlot(final org.bukkit.inventory.EquipmentSlot slot) {
return switch (slot) {
case HEAD -> EquipmentSlot.HELMET;
@@ -564,5 +623,18 @@ public class PacketManager {
case OFF_HAND -> EquipmentSlot.OFF_HAND;
};
}
*/
public static EnumWrappers.ItemSlot itemBukkitSlot(final org.bukkit.inventory.EquipmentSlot slot) {
return switch (slot) {
case HEAD -> EnumWrappers.ItemSlot.HEAD;
case CHEST -> EnumWrappers.ItemSlot.CHEST;
case LEGS -> EnumWrappers.ItemSlot.LEGS;
case FEET -> EnumWrappers.ItemSlot.FEET;
case HAND -> EnumWrappers.ItemSlot.MAINHAND;
case OFF_HAND -> EnumWrappers.ItemSlot.OFFHAND;
default -> null;
};
}
}

View File

@@ -1,37 +0,0 @@
package io.github.fisher2911.hmccosmetics.packet;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
public class WrapperPlayServerCamera extends PacketWrapper<WrapperPlayServerCamera> {
private int entityID;
public WrapperPlayServerCamera(final int entityID) {
super(PacketType.Play.Server.CAMERA);
this.entityID = entityID;
}
@Override
public void read() {
this.entityID = this.readVarInt();
}
@Override
public void copy(WrapperPlayServerCamera wrapper) {
this.entityID = wrapper.entityID;
}
public void write() {
this.writeVarInt(this.entityID);
}
public int getEntityId() {
return this.entityID;
}
public void setEntityIds(int entityID) {
this.entityID = entityID;
}
}

View File

@@ -0,0 +1,94 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.google.common.base.Objects;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
// Courtesy of Packet Wrapper
public class AbstractPacket {
// The packet we will be modifying
protected PacketContainer handle;
/**
* Constructs a new strongly typed wrapper for the given packet.
*
* @param handle - handle to the raw packet data.
* @param type - the packet type.
*/
protected AbstractPacket(PacketContainer handle, PacketType type) {
// Make sure we're given a valid packet
if (handle == null)
throw new IllegalArgumentException("Packet handle cannot be NULL.");
if (!Objects.equal(handle.getType(), type))
throw new IllegalArgumentException(handle.getHandle()
+ " is not a packet of type " + type);
this.handle = handle;
}
/**
* Retrieve a handle to the raw packet data.
*
* @return Raw packet data.
*/
public PacketContainer getHandle() {
return handle;
}
/**
* Send the current packet to the given receiver.
*
* @param receiver - the receiver.
* @throws RuntimeException If the packet cannot be sent.
*/
public void sendPacket(Player receiver) {
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
getHandle());
}
/**
* Send the current packet to all online players.
*/
public void broadcastPacket() {
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
}
/**
* Simulate receiving the current packet from the given sender.
*
* @param sender - the sender.
* @throws RuntimeException If the packet cannot be received.
* @deprecated Misspelled. recieve to receive
* @see #receivePacket(Player)
*/
@Deprecated
public void recievePacket(Player sender) {
try {
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
getHandle());
} catch (Exception e) {
throw new RuntimeException("Cannot recieve packet.", e);
}
}
/**
* Simulate receiving the current packet from the given sender.
*
* @param sender - the sender.
* @throws RuntimeException if the packet cannot be received.
*/
public void receivePacket(Player sender) {
try {
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
getHandle());
} catch (Exception e) {
throw new RuntimeException("Cannot receive packet.", e);
}
}
}

View File

@@ -0,0 +1,130 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
public class WrapperPlayClientWindowClick extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Client.WINDOW_CLICK;
public WrapperPlayClientWindowClick() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayClientWindowClick(PacketContainer packet) {
super(packet, TYPE);
}
/**
* Retrieve Window ID.
* <p>
* Notes: the id of the window which was clicked. 0 for player inventory.
*
* @return The current Window ID
*/
public int getWindowId() {
return handle.getIntegers().read(0);
}
/**
* Set Window ID.
*
* @param value - new value.
*/
public void setWindowId(int value) {
handle.getIntegers().write(0, value);
}
/**
* Retrieve Slot.
* <p>
* Notes: the clicked slot. See below.
*
* @return The current Slot
*/
public int getSlot() {
return handle.getIntegers().read(1);
}
/**
* Set Slot.
*
* @param value - new value.
*/
public void setSlot(int value) {
handle.getIntegers().write(1, value);
}
/**
* Retrieve Button.
* <p>
* Notes: the button used in the click. See below.
*
* @return The current Button
*/
public int getButton() {
return handle.getIntegers().read(2);
}
/**
* Set Button.
*
* @param value - new value.
*/
public void setButton(int value) {
handle.getIntegers().write(2, value);
}
/**
* Retrieve Action number.
* <p>
* Notes: a unique number for the action, used for transaction handling (See
* the Transaction packet).
*
* @return The current Action number
*/
public short getActionNumber() {
return handle.getShorts().read(0);
}
/**
* Set Action number.
*
* @param value - new value.
*/
public void setActionNumber(short value) {
handle.getShorts().write(0, value);
}
/**
* Retrieve Clicked item.
*
* @return The current Clicked item
*/
public ItemStack getClickedItem() {
return handle.getItemModifier().read(0);
}
/**
* Set Clicked item.
*
* @param value - new value.
*/
public void setClickedItem(ItemStack value) {
handle.getItemModifier().write(0, value);
}
public InventoryClickType getShift() {
return handle.getEnumModifier(InventoryClickType.class, 5).read(0);
}
public void setShift(InventoryClickType value) {
handle.getEnumModifier(InventoryClickType.class, 5).write(0, value);
}
public enum InventoryClickType {
PICKUP, QUICK_MOVE, SWAP, CLONE, THROW, QUICK_CRAFT, PICKUP_ALL;
}
}

View File

@@ -0,0 +1,111 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import io.github.fisher2911.hmccosmetics.user.Equipment;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot;
import java.util.List;
public class WrapperPlayServerEntityEquipment extends AbstractPacket {
public static final PacketType TYPE =
PacketType.Play.Server.ENTITY_EQUIPMENT;
private List<Equipment> equipment;
public WrapperPlayServerEntityEquipment() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerEntityEquipment(PacketContainer packet) {
super(packet, TYPE);
}
public void read() {
}
public WrapperPlayServerEntityEquipment(PacketContainer packet, int entityId, List<Equipment> equipment) {
super(packet, TYPE);
setEntityID(entityId);
this.equipment = equipment;
}
/**
* 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());
}
public ItemSlot getSlot() {
return handle.getItemSlots().read(0);
}
public void setSlot(ItemSlot value) {
if (handle.getItemSlots().getValues().size() > 0) {
handle.getItemSlots().write(0, value);
}
}
/**
* Retrieve Item.
* <p>
* Notes: item in slot format
*
* @return The current Item
*/
public ItemStack getItem() {
return handle.getItemModifier().read(0);
}
/**
* Set Item.
*
* @param value - new value.
*/
public void setItem(ItemStack value) {
if (handle.getItemModifier().getValues().size() > 0) {
handle.getItemModifier().write(0, value);
}
}
}

View File

@@ -0,0 +1,83 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import java.util.List;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
public class WrapperPlayServerEntityMetadata extends AbstractPacket {
public static final PacketType TYPE =
PacketType.Play.Server.ENTITY_METADATA;
public WrapperPlayServerEntityMetadata() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerEntityMetadata(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 Metadata.
*
* @return The current Metadata
*/
public List<WrappedWatchableObject> getMetadata() {
return handle.getWatchableCollectionModifier().read(0);
}
/**
* Set Metadata.
*
* @param value - new value.
*/
public void setMetadata(List<WrappedWatchableObject> value) {
handle.getWatchableCollectionModifier().write(0, value);
}
}

View File

@@ -0,0 +1,170 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
public class WrapperPlayServerRelEntityMove extends AbstractPacket {
public static final PacketType TYPE =
PacketType.Play.Server.REL_ENTITY_MOVE;
public WrapperPlayServerRelEntityMove() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerRelEntityMove(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 DX.
*
* @return The current DX
*/
public double getDx() {
return handle.getShorts().read(0) / 4096D;
}
/**
* Set DX.
*
* @param value - new value.
*/
public void setDx(double value) {
handle.getShorts().write(0, (short) (value * 4096));
}
/**
* Retrieve DY.
*
* @return The current DY
*/
public double getDy() {
return handle.getShorts().read(1) / 4096D;
}
/**
* Set DY.
*
* @param value - new value.
*/
public void setDy(double value) {
handle.getShorts().write(1, (short) (value * 4096));
}
/**
* Retrieve DZ.
*
* @return The current DZ
*/
public double getDz() {
return handle.getShorts().read(2) / 4096D;
}
/**
* Set DZ.
*
* @param value - new value.
*/
public void setDz(double value) {
handle.getShorts().write(2, (short) (value * 4096));
}
/**
* Retrieve the yaw of the current entity.
*
* @return The current Yaw
*/
public float getYaw() {
return (handle.getBytes().read(0) * 360.F) / 256.0F;
}
/**
* Set the yaw of the current 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 current entity.
*
* @return The current pitch
*/
public float getPitch() {
return (handle.getBytes().read(1) * 360.F) / 256.0F;
}
/**
* Set the pitch of the current entity.
*
* @param value - new pitch.
*/
public void setPitch(float value) {
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
}
/**
* Retrieve On Ground.
*
* @return The current On Ground
*/
public boolean getOnGround() {
return handle.getBooleans().read(0);
}
/**
* Set On Ground.
*
* @param value - new value.
*/
public void setOnGround(boolean value) {
handle.getBooleans().write(0, value);
}
}

View File

@@ -0,0 +1,170 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
public class WrapperPlayServerRelEntityMoveLook extends AbstractPacket {
public static final PacketType TYPE =
PacketType.Play.Server.REL_ENTITY_MOVE_LOOK;
public WrapperPlayServerRelEntityMoveLook() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerRelEntityMoveLook(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 DX.
*
* @return The current DX
*/
public double getDx() {
return handle.getShorts().read(0) / 4096D;
}
/**
* Set DX.
*
* @param value - new value.
*/
public void setDx(double value) {
handle.getShorts().write(0, (short) (value * 4096));
}
/**
* Retrieve DY.
*
* @return The current DY
*/
public double getDy() {
return handle.getShorts().read(1) / 4096D;
}
/**
* Set DY.
*
* @param value - new value.
*/
public void setDy(double value) {
handle.getShorts().write(1, (short) (value * 4096));
}
/**
* Retrieve DZ.
*
* @return The current DZ
*/
public double getDz() {
return handle.getShorts().read(2) / 4096D;
}
/**
* Set DZ.
*
* @param value - new value.
*/
public void setDz(double value) {
handle.getShorts().write(2, (short) (value * 4096));
}
/**
* Retrieve the yaw of the current entity.
*
* @return The current Yaw
*/
public float getYaw() {
return (handle.getBytes().read(0) * 360.F) / 256.0F;
}
/**
* Set the yaw of the current 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 current entity.
*
* @return The current pitch
*/
public float getPitch() {
return (handle.getBytes().read(1) * 360.F) / 256.0F;
}
/**
* Set the pitch of the current entity.
*
* @param value - new pitch.
*/
public void setPitch(float value) {
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
}
/**
* Retrieve On Ground.
*
* @return The current On Ground
*/
public boolean getOnGround() {
return handle.getBooleans().read(0);
}
/**
* Set On Ground.
*
* @param value - new value.
*/
public void setOnGround(boolean value) {
handle.getBooleans().write(0, value);
}
}

View File

@@ -0,0 +1,314 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import java.util.UUID;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PacketConstructor;
public class WrapperPlayServerSpawnEntity extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY;
private static PacketConstructor entityConstructor;
public WrapperPlayServerSpawnEntity() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerSpawnEntity(PacketContainer packet) {
super(packet, TYPE);
}
public WrapperPlayServerSpawnEntity(Entity entity, int type, int objectData) {
super(fromEntity(entity, type, objectData), TYPE);
}
// Useful constructor
private static PacketContainer fromEntity(Entity entity, int type,
int objectData) {
if (entityConstructor == null)
entityConstructor =
ProtocolLibrary.getProtocolManager()
.createPacketConstructor(TYPE, entity, type,
objectData);
return entityConstructor.createPacket(entity, type, objectData);
}
/**
* Retrieve entity ID of the Object.
*
* @return The current EID
*/
public int getEntityID() {
return handle.getIntegers().read(0);
}
/**
* Retrieve the entity 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 that will be spawned.
*
* @param event - the packet event.
* @return The spawned entity.
*/
public Entity getEntity(PacketEvent event) {
return getEntity(event.getPlayer().getWorld());
}
/**
* Set entity ID of the Object.
*
* @param value - new value.
*/
public void setEntityID(int value) {
handle.getIntegers().write(0, value);
}
public UUID getUniqueId() {
return handle.getUUIDs().read(0);
}
public void setUniqueId(UUID value) {
handle.getUUIDs().write(0, value);
}
/**
* Retrieve the x position of the object.
* <p>
* Note that the coordinate is rounded off to the nearest 1/32 of a meter.
*
* @return The current X
*/
public double getX() {
return handle.getDoubles().read(0);
}
/**
* Set the x position of the object.
*
* @param value - new value.
*/
public void setX(double value) {
handle.getDoubles().write(0, value);
}
/**
* Retrieve the y position of the object.
* <p>
* Note that the coordinate is rounded off to the nearest 1/32 of a meter.
*
* @return The current y
*/
public double getY() {
return handle.getDoubles().read(1);
}
/**
* Set the y position of the object.
*
* @param value - new value.
*/
public void setY(double value) {
handle.getDoubles().write(1, value);
}
/**
* Retrieve the z position of the object.
* <p>
* Note that the coordinate is rounded off to the nearest 1/32 of a meter.
*
* @return The current z
*/
public double getZ() {
return handle.getDoubles().read(2);
}
/**
* Set the z position of the object.
*
* @param value - new value.
*/
public void setZ(double value) {
handle.getDoubles().write(2, value);
}
/**
* Retrieve the optional speed x.
* <p>
* This is ignored if {@link #getObjectData()} is zero.
*
* @return The optional speed x.
*/
public double getOptionalSpeedX() {
return handle.getIntegers().read(1) / 8000.0D;
}
/**
* Set the optional speed x.
*
* @param value - new value.
*/
public void setOptionalSpeedX(double value) {
handle.getIntegers().write(1, (int) (value * 8000.0D));
}
/**
* Retrieve the optional speed y.
* <p>
* This is ignored if {@link #getObjectData()} is zero.
*
* @return The optional speed y.
*/
public double getOptionalSpeedY() {
return handle.getIntegers().read(2) / 8000.0D;
}
/**
* Set the optional speed y.
*
* @param value - new value.
*/
public void setOptionalSpeedY(double value) {
handle.getIntegers().write(2, (int) (value * 8000.0D));
}
/**
* Retrieve the optional speed z.
* <p>
* This is ignored if {@link #getObjectData()} is zero.
*
* @return The optional speed z.
*/
public double getOptionalSpeedZ() {
return handle.getIntegers().read(3) / 8000.0D;
}
/**
* Set the optional speed z.
*
* @param value - new value.
*/
public void setOptionalSpeedZ(double value) {
handle.getIntegers().write(3, (int) (value * 8000.0D));
}
/**
* Retrieve the pitch.
*
* @return The current pitch.
*/
public float getPitch() {
return (handle.getIntegers().read(4) * 360.F) / 256.0F;
}
/**
* Set the pitch.
*
* @param value - new pitch.
*/
public void setPitch(float value) {
handle.getIntegers().write(4, (int) (value * 256.0F / 360.0F));
}
/**
* Retrieve the yaw.
*
* @return The current Yaw
*/
public float getYaw() {
return (handle.getIntegers().read(5) * 360.F) / 256.0F;
}
/**
* Set the yaw of the object spawned.
*
* @param value - new yaw.
*/
public void setYaw(float value) {
handle.getIntegers().write(5, (int) (value * 256.0F / 360.0F));
}
/**
* Retrieve the type of object.
*
* @return The current Type
*/
public EntityType getType() {
return handle.getEntityTypeModifier().read(0);
}
/**
* Set the type of object.
*
* @param value - new value.
*/
public void setType(EntityType value) {
handle.getEntityTypeModifier().write(0, value);
}
/**
* Retrieve object data.
* <p>
* The content depends on the object type:
* <table border="1" cellpadding="4">
* <tr>
* <th>Object Type:</th>
* <th>Name:</th>
* <th>Description</th>
* </tr>
* <tr>
* <td>ITEM_FRAME</td>
* <td>Orientation</td>
* <td>0-3: South, West, North, East</td>
* </tr>
* <tr>
* <td>FALLING_BLOCK</td>
* <td>Block Type</td>
* <td>BlockID | (Metadata << 0xC)</td>
* </tr>
* <tr>
* <td>Projectiles</td>
* <td>Entity ID</td>
* <td>The entity ID of the thrower</td>
* </tr>
* <tr>
* <td>Splash Potions</td>
* <td>Data Value</td>
* <td>Potion data value.</td>
* </tr>
* </table>
*
* @return The current object Data
*/
public int getObjectData() {
return handle.getIntegers().read(6);
}
/**
* Set object Data.
* <p>
* The content depends on the object type. See {@link #getObjectData()} for
* more information.
*
* @param value - new object data.
*/
public void setObjectData(int value) {
handle.getIntegers().write(6, value);
}
}

View File

@@ -0,0 +1,61 @@
package io.github.fisher2911.hmccosmetics.packet.wrappers;
import java.util.List;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
public class WrapperPlayServerWindowItems extends AbstractPacket {
public static final PacketType TYPE = PacketType.Play.Server.WINDOW_ITEMS;
public WrapperPlayServerWindowItems() {
super(new PacketContainer(TYPE), TYPE);
handle.getModifier().writeDefaults();
}
public WrapperPlayServerWindowItems(PacketContainer packet) {
super(packet, TYPE);
}
/**
* Retrieve Window ID.
* <p>
* Notes: the id of window which items are being sent for. 0 for player
* inventory.
*
* @return The current Window ID
*/
public int getWindowId() {
return handle.getIntegers().read(0);
}
/**
* Set Window ID.
*
* @param value - new value.
*/
public void setWindowId(int value) {
handle.getIntegers().write(0, value);
}
/**
* Retrieve Slot data.
*
* @return The current Slot data
*/
public List<ItemStack> getSlotData() {
return handle.getItemListModifier().read(0);
}
/**
* Set Slot data.
*
* @param value - new value.
*/
public void setSlotData(List<ItemStack> value) {
handle.getItemListModifier().write(0, value);
}
}

View File

@@ -1,21 +1,22 @@
package io.github.fisher2911.hmccosmetics.user;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.protocol.player.EquipmentSlot;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.config.Settings;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import io.github.retrooper.packetevents.util.SpigotReflectionUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
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;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
public class Backpack {
@@ -46,7 +47,7 @@ public class Backpack {
if (currentSize == particleCount) return;
if (currentSize < particleCount) {
for (int i = currentSize; i < particleCount; i++) {
this.particleIDS.add(SpigotReflectionUtil.generateEntityId());
this.particleIDS.add(new AtomicInteger().incrementAndGet());
}
return;
}
@@ -54,7 +55,7 @@ public class Backpack {
}
private void spawnForOther(BaseUser<?> owner, Player other, Location location) {
PacketManager.sendEntitySpawnPacket(location, this.armorStandID, EntityTypes.ARMOR_STAND, other);
PacketManager.sendEntitySpawnPacket(location, this.armorStandID, EntityType.ARMOR_STAND, other);
PacketManager.sendArmorStandMetaContainer(this.armorStandID, other);
PacketManager.sendRidingPacket(owner.getEntityId(), this.armorStandID, other);
}
@@ -64,13 +65,13 @@ public class Backpack {
PacketManager.sendEntityNotLivingSpawnPacket(
location,
id,
EntityTypes.AREA_EFFECT_CLOUD,
EntityType.AREA_EFFECT_CLOUD,
UUID.randomUUID(),
0,
other
);
}
PacketManager.sendEntitySpawnPacket(location, this.armorStandID, EntityTypes.ARMOR_STAND, other);
PacketManager.sendEntitySpawnPacket(location, this.armorStandID, EntityType.ARMOR_STAND, other);
}
public void despawn(Player player) {
@@ -93,32 +94,24 @@ public class Backpack {
final boolean isSelf = owner.getId().equals(other.getUniqueId());
final boolean firstPersonMode = settings.getCosmeticSettings().isFirstPersonBackpackMode();
final ArmorItem.Type type = isSelf && firstPersonMode ? ArmorItem.Type.SELF_BACKPACK : ArmorItem.Type.BACKPACK;
final List<com.github.retrooper.packetevents.protocol.player.Equipment> equipment = new ArrayList<>();
//final List<com.github.retrooper.packetevents.protocol.player.Equipment> equipment = new ArrayList<>();
//Equipment equipment = owner.getEquipment();
final int lookDownPitch = settings.getCosmeticSettings().getLookDownPitch();
final boolean hidden = !owner.shouldShow(other);
ItemStack itemStack = owner.getPlayerArmor().getItem(type).getItemStack(ArmorItem.Status.APPLIED);
Equipment equip = new Equipment();
final boolean isLookingDown =
!firstPersonMode &&
isSelf &&
lookDownPitch != -1 &&
owner.isFacingDown(location, lookDownPitch);
if (hidden || isLookingDown) {
equipment.add(new com.github.retrooper.packetevents.protocol.player.Equipment(
EquipmentSlot.HELMET,
new com.github.retrooper.packetevents.protocol.item.ItemStack.Builder().
type(ItemTypes.AIR).
build()
));
PacketManager.sendEquipmentPacket(equipment, this.armorStandID, other);
equip.setItem(EquipmentSlot.HEAD, new ItemStack(Material.AIR));
PacketManager.sendEquipmentPacket(equip, this.armorStandID, other);
return;
}
final com.github.retrooper.packetevents.protocol.item.ItemStack itemStack =
SpigotConversionUtil.fromBukkitItemStack(owner.getPlayerArmor().getItem(type).getItemStack(ArmorItem.Status.APPLIED));
equipment.add(new com.github.retrooper.packetevents.protocol.player.Equipment(
EquipmentSlot.HELMET,
itemStack
));
PacketManager.sendEquipmentPacket(equipment, this.armorStandID, other);
equip.setItem(EquipmentSlot.HEAD, itemStack);
PacketManager.sendEquipmentPacket(equip, this.armorStandID, other);
PacketManager.sendArmorStandMetaContainer(this.armorStandID, other);
PacketManager.sendRotationPacket(this.armorStandID, location, false, other);
PacketManager.sendLookPacket(this.armorStandID, location, other);

View File

@@ -1,7 +1,6 @@
package io.github.fisher2911.hmccosmetics.user;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import io.github.fisher2911.hmccosmetics.config.CosmeticSettings;
import io.github.fisher2911.hmccosmetics.config.Settings;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
@@ -139,7 +138,7 @@ public abstract class BaseUser<T> {
this.balloon.addPlayerToModel(other, id);
}
final int balloonId = this.getBalloonId();
PacketManager.sendEntitySpawnPacket(actual, balloonId, EntityTypes.PUFFERFISH, other);
PacketManager.sendEntitySpawnPacket(actual, balloonId, EntityType.PUFFERFISH, other);
PacketManager.sendInvisibilityPacket(balloonId, other);
PacketManager.sendLeashPacket(balloonId, this.getEntityId(), other);
this.updateBalloon(other, location, settings);

View File

@@ -1,17 +1,25 @@
package io.github.fisher2911.hmccosmetics.user;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableList;
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Equipment {
private static final EquipmentSlot[] VALUES = EquipmentSlot.values();
private final Map<EquipmentSlot, ItemStack> equipment = new EnumMap<>(EquipmentSlot.class);
private final HashMap<EquipmentSlot, ItemStack> equipment = new HashMap<>();
public Equipment() {
}
@@ -25,6 +33,24 @@ public class Equipment {
return equipment;
}
public static Equipment fromEntityEquipment(@Nullable final Player player) {
if (player == null) return new Equipment();
final Equipment equipment = new Equipment();
for (final EquipmentSlot slot : VALUES) {
equipment.setItem(slot, player.getInventory().getItem(slot));
}
return equipment;
}
public static Equipment fromEntityEquipment(@Nullable final User user) {
if (user == null) return new Equipment();
final Equipment equipment = new Equipment();
for (final EquipmentSlot slot : VALUES) {
equipment.setItem(slot, user.getPlayer().getInventory().getItem(slot));
}
return equipment;
}
@Nullable
public ItemStack getItem(final EquipmentSlot slot) {
return this.equipment.get(slot);
@@ -34,4 +60,19 @@ public class Equipment {
this.equipment.put(slot, itemStack);
}
public EquipmentSlot[] values() {
return VALUES;
}
public Set<EquipmentSlot> keys() {
return equipment.keySet();
}
public void removeSlot(EquipmentSlot slot) {
equipment.remove(slot);
}
public void clear() {
equipment.clear();
}
}

View File

@@ -1,5 +1,6 @@
package io.github.fisher2911.hmccosmetics.user;
import com.comphenix.protocol.wrappers.EnumWrappers;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.api.CosmeticItem;
import io.github.fisher2911.hmccosmetics.api.event.CosmeticChangeEvent;
@@ -105,18 +106,14 @@ public class UserManager {
this.sendUpdatePacket(
user,
other,
this.getItemList(
user,
user.getEquipment(),
Collections.emptySet()
)
getItemList(user)
);
}
public void updateCosmetics(final BaseUser<?> user) {
this.sendUpdatePacket(
user,
this.getItemList(user, user.getEquipment(), Collections.emptySet())
getItemList(user)
);
}
@@ -148,18 +145,27 @@ public class UserManager {
return itemStack;
}
public List<com.github.retrooper.packetevents.protocol.player.Equipment> getItemList(
public Equipment getItemList(
final BaseUser<?> user
) {
return getItemList(user, new Equipment(), Collections.emptySet());
}
public Equipment getItemList(
final BaseUser<?> user,
final Equipment equipment,
final Set<ArmorItem.Type> ignored
) {
final PlayerArmor armor = user.getPlayerArmor();
final List<com.github.retrooper.packetevents.protocol.player.Equipment> items = new ArrayList<>();
//final List<Equipment> items = new ArrayList<>();
//Equipment equip = new Equipment();
for (final ArmorItem.Type type : ArmorItem.Type.values()) {
final EquipmentSlot slot = type.getSlot();
if (slot == null) continue;
if (ignored.contains(type)) {
items.add(PacketManager.getEquipment(equipment.getItem(slot), slot));
Equipment item = PacketManager.getEquipment(equipment.getItem(slot), slot);
equipment.setItem(slot, item.getItem(slot));
//items.add(PacketManager.getEquipment(equipment.getItem(slot), slot));
continue;
}
final ItemStack wearing = Utils.replaceIfNull(equipment.getItem(slot), new ItemStack(Material.AIR));
@@ -169,13 +175,13 @@ public class UserManager {
ArmorItem.Status.APPLIED,
slot
);
items.add(PacketManager.getEquipment(itemStack, slot));
equipment.setItem(slot, itemStack);
}
return items;
return equipment;
}
public List<com.github.retrooper.packetevents.protocol.player.Equipment> getEmptyItemList() {
final List<com.github.retrooper.packetevents.protocol.player.Equipment> items = new ArrayList<>();
public List<Equipment> getEmptyItemList() {
final List<Equipment> items = new ArrayList<>();
for (final EquipmentSlot slot : EquipmentSlot.values()) {
items.add(PacketManager.getEquipment(new ItemStack(Material.AIR), slot));
}
@@ -286,39 +292,38 @@ public class UserManager {
final ArmorItem.Type type) {
final EquipmentSlot slot = type.getSlot();
final ItemStack itemStack = this.getCosmeticItem(armorItem, wearing, ArmorItem.Status.APPLIED, slot);
final List<com.github.retrooper.packetevents.protocol.player.Equipment> itemList = new ArrayList<>();
itemList.add(PacketManager.getEquipment(itemStack, slot));
this.sendUpdatePacket(user, itemList);
//final List<Equipment> itemList = new ArrayList<>();
//itemList.add(PacketManager.getEquipment(itemStack, slot));
Equipment equip = user.getEquipment();
equip.setItem(slot, itemStack);
this.sendUpdatePacket(user, equip);
}
public void sendUpdatePacket(
final BaseUser<?> user,
List<com.github.retrooper.packetevents.protocol.player.Equipment> items
Equipment equipment
) {
// final Player player = user.getPlayer();
// if (player == null) return;
final Location location = user.getLocation();
if (location == null) return;
final int entityId = user.getEntityId();
if (items.isEmpty()) return;
if (equipment == null) return;
for (final User otherUser : this.userMap.values()) {
final Player other = otherUser.getPlayer();
//other.sendMessage("Offhand Cosmetic (sendUpdatePacket) " + equipment.getItem(EquipmentSlot.OFF_HAND));
if (other == null) continue;
if (!user.shouldShow(other)) continue;
if (!this.settings.getCosmeticSettings().isInViewDistance(location, other.getLocation())) continue;
user.updateBackpack(other, this.settings);
PacketManager.sendEquipmentPacket(
items,
entityId,
other
);
PacketManager.sendEquipmentPacket(equipment, entityId, other);
}
}
public void sendUpdatePacket(
final BaseUser<?> user,
final Player other,
List<com.github.retrooper.packetevents.protocol.player.Equipment> items
Equipment equipment
) {
// final Player player = user.getPlayer();
// if (player == null) return;
@@ -328,10 +333,6 @@ public class UserManager {
if (other == null) return;
if (!user.shouldShow(other)) return;
if (!this.settings.getCosmeticSettings().isInViewDistance(location, other.getLocation())) return;
PacketManager.sendEquipmentPacket(
items,
entityId,
other
);
PacketManager.sendEquipmentPacket(equipment, entityId, other);
}
}

View File

@@ -1,6 +1,5 @@
package io.github.fisher2911.hmccosmetics.user;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.config.WardrobeSettings;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
@@ -11,6 +10,7 @@ import io.github.fisher2911.hmccosmetics.task.Task;
import io.github.fisher2911.hmccosmetics.task.TaskChain;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;
@@ -54,14 +54,14 @@ public class Wardrobe extends User {
if (settings.inDistanceOfStatic(viewer.getLocation())) {
this.currentLocation = settings.getWardrobeLocation();
userManager.get(viewer.getUniqueId()).ifPresent(user -> {
userManager.sendUpdatePacket(user, userManager.getEmptyItemList());
userManager.sendUpdatePacket(user, user.getEquipment());
user.despawnAttached();
user.despawnBalloon();
});
PacketManager.sendEntitySpawnPacket(
settings.getViewerLocation(),
this.entityIds.wardrobeViewer(),
EntityTypes.ARMOR_STAND,
EntityType.ARMOR_STAND,
viewer
);
PacketManager.sendCameraPacket(

View File

@@ -1,2 +1,2 @@
copyJar=true
copyJar=false
hibiscusmc_plugin_path=""