mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-31 04:46:42 +00:00
Compiling without PacketEvents
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package io.github.fisher2911.hmccosmetics;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import io.github.fisher2911.hmccosmetics.command.CosmeticsCommand;
|
||||
import io.github.fisher2911.hmccosmetics.concurrent.Threads;
|
||||
import io.github.fisher2911.hmccosmetics.config.Settings;
|
||||
@@ -107,7 +106,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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -1,26 +1,13 @@
|
||||
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 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.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;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -36,10 +23,7 @@ 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;
|
||||
@@ -140,6 +124,7 @@ public class CosmeticFixListener implements Listener {
|
||||
}
|
||||
|
||||
private void registerInventoryClickListener() {
|
||||
/*
|
||||
PacketEvents.getAPI().getEventManager().registerListener(
|
||||
new PacketListenerAbstract() {
|
||||
@Override
|
||||
@@ -173,9 +158,11 @@ public class CosmeticFixListener implements Listener {
|
||||
}
|
||||
}
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
private void updateOnClick(final Player player, final EquipmentSlot slot, final User user, final ArmorItem.Type type, final ItemStack current) {
|
||||
/*
|
||||
final Location location = player.getLocation();
|
||||
final Equipment equipment = Equipment.fromEntityEquipment(player.getEquipment());
|
||||
final ItemStack cosmetic = userManager.getCosmeticItem(
|
||||
@@ -186,14 +173,14 @@ public class CosmeticFixListener implements Listener {
|
||||
);
|
||||
if (cosmetic != null && cosmetic.getType() != Material.AIR) equipment.setItem(slot, cosmetic);
|
||||
|
||||
final List<com.github.retrooper.packetevents.protocol.player.Equipment> items =
|
||||
final List<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);
|
||||
//final EquipmentSlot s = e.getSlot();
|
||||
final ArmorItem.Type t = ArmorItem.Type.fromPacketSlot(slot);
|
||||
if (t == null) return false;
|
||||
final ArmorItem armorItem = user.getPlayerArmor().getItem(t);
|
||||
final ItemStack i = SpigotConversionUtil.toBukkitItemStack(e.getItem());
|
||||
final ItemStack i = e.getItem(slot);
|
||||
return armorItem.isEmpty() && i.equals(equipment.getItem(t.getSlot()));
|
||||
});
|
||||
for (final Player other : Bukkit.getOnlinePlayers()) {
|
||||
@@ -203,9 +190,35 @@ public class CosmeticFixListener implements Listener {
|
||||
items
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void registerMenuChangeListener() {
|
||||
/*
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmetics.getPlugin(HMCCosmetics.class), ListenerPriority.NORMAL) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (!event.getPacketType().equals(PacketType.Play.Server.WINDOW_ITEMS)) return;
|
||||
if (event.getPlayer() == null) return;
|
||||
WrapperPlayServerWindowItems wrapper = new WrapperPlayServerWindowItems(event.getPacket());
|
||||
final int windowId = wrapper.getWindowId();
|
||||
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
int count = items.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
items.add(wrapper.getSlotData().get(count));
|
||||
}
|
||||
|
||||
|
||||
//final WrapperPlayServerWindowItems packet = new WrapperPlayServerWindowItems(event);
|
||||
|
||||
|
||||
|
||||
//final int windowId = packet.getWindowId();
|
||||
}
|
||||
});
|
||||
*/
|
||||
/*
|
||||
PacketEvents.getAPI().getEventManager().registerListener(
|
||||
new PacketListenerAbstract() {
|
||||
@Override
|
||||
@@ -214,7 +227,7 @@ public class CosmeticFixListener implements Listener {
|
||||
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();
|
||||
final List<ItemStack> itemStacks = packet.getItems();
|
||||
taskManager.submit(() -> {
|
||||
final Optional<User> optionalUser = userManager.get(player.getUniqueId());
|
||||
if (optionalUser.isEmpty()) return;
|
||||
@@ -222,7 +235,7 @@ public class CosmeticFixListener implements Listener {
|
||||
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<>();
|
||||
final List<Equipment> equipmentList = new ArrayList<>();
|
||||
for (final ArmorItem armorItem : playerArmor.getArmorItems()) {
|
||||
final ArmorItem.Type type = armorItem.getType();
|
||||
final EquipmentSlot slot = type.getSlot();
|
||||
@@ -231,15 +244,15 @@ public class CosmeticFixListener implements Listener {
|
||||
if (packetSlot == -1) continue;
|
||||
if (packetSlot >= size) continue;
|
||||
|
||||
final ItemStack current = SpigotConversionUtil.toBukkitItemStack(itemStacks.get(packetSlot));
|
||||
final com.github.retrooper.packetevents.protocol.item.ItemStack setTo =
|
||||
SpigotConversionUtil.fromBukkitItemStack(userManager.getCosmeticItem(
|
||||
final ItemStack current = (itemStacks.get(packetSlot));
|
||||
final ItemStack setTo =
|
||||
(userManager.getCosmeticItem(
|
||||
armorItem,
|
||||
current,
|
||||
ArmorItem.Status.APPLIED,
|
||||
slot
|
||||
));
|
||||
if (SpigotConversionUtil.fromBukkitItemStack(current).equals(setTo)) continue;
|
||||
if ((current).equals(setTo)) continue;
|
||||
equipmentList.add(PacketManager.getEquipment(setTo, slot));
|
||||
}
|
||||
userManager.sendUpdatePacket(
|
||||
@@ -247,10 +260,11 @@ public class CosmeticFixListener implements Listener {
|
||||
equipmentList
|
||||
);
|
||||
});
|
||||
// packet.setItems(itemStacks);
|
||||
packet.setItems(itemStacks);
|
||||
}
|
||||
}
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
private int getPacketArmorSlot(final EquipmentSlot slot) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,28 +3,18 @@ package io.github.fisher2911.hmccosmetics.packet;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
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.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.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class PacketManager {
|
||||
//
|
||||
@@ -50,64 +40,81 @@ public class PacketManager {
|
||||
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.setMeta(String.valueOf(armorStandId), List.of(
|
||||
new EntityData(0, EntityDataTypes.BYTE, (byte) 0x20),
|
||||
new EntityData(15, EntityDataTypes.BYTE, (byte) 0x10)
|
||||
)
|
||||
);
|
||||
packet.getIntegers().write(0, armorStandId);
|
||||
WrappedDataWatcher metadata = new WrappedDataWatcher();
|
||||
if (metadata == null) return;
|
||||
// 0x10 & 0x20
|
||||
WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class);
|
||||
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer), (byte) 0x20);
|
||||
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer), (byte) 0x10);
|
||||
//metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
|
||||
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,
|
||||
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(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());
|
||||
/*
|
||||
packet.setMeta(String.valueOf(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)
|
||||
)
|
||||
));
|
||||
new EntityData(7, EntityDataTypes.INT, 0)
|
||||
));
|
||||
*/
|
||||
sendPacketAsync(p, packet);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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_VELOCITY);
|
||||
packet.setMeta(String.valueOf(entityId), new Vector3d(0.5, 0.5, 0.5));
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +150,25 @@ public class PacketManager {
|
||||
final UUID uuid,
|
||||
final Player... sendTo) {
|
||||
for (final Player p : sendTo) {
|
||||
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
// Why java... why...
|
||||
io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerSpawnEntity wrapper = new io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerSpawnEntity(packet);
|
||||
wrapper.setEntityID(entityId);
|
||||
wrapper.setUniqueId(uuid);
|
||||
wrapper.setType(entityType);
|
||||
wrapper.setYaw(location.getYaw());
|
||||
wrapper.setPitch(location.getPitch());
|
||||
wrapper.setX(location.getX());
|
||||
wrapper.setY(location.getY());
|
||||
wrapper.setZ(location.getZ());
|
||||
wrapper.setObjectData(0);
|
||||
wrapper.setOptionalSpeedX(0);
|
||||
wrapper.setOptionalSpeedY(0);
|
||||
wrapper.setOptionalSpeedZ(0);
|
||||
|
||||
sendPacketAsync(p, wrapper.getHandle());
|
||||
/*
|
||||
sendPacketAsync(p, new WrapperPlayServerSpawnEntity(
|
||||
entityId,
|
||||
Optional.of(uuid),
|
||||
@@ -154,6 +180,7 @@ public class PacketManager {
|
||||
0,
|
||||
Optional.of(Vector3d.zero())
|
||||
));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,17 +192,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())
|
||||
));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,10 +215,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,6 +248,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()),
|
||||
@@ -215,6 +265,8 @@ public class PacketManager {
|
||||
location.getPitch(),
|
||||
onGround
|
||||
));
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,13 +288,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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,32 +313,41 @@ 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]));
|
||||
}
|
||||
final io.github.fisher2911.hmccosmetics.user.Equipment equipment,
|
||||
final int entityID,
|
||||
final Player... sendTo) {
|
||||
List<PacketContainer> packets = new ArrayList<>();
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||
|
||||
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
|
||||
));
|
||||
for (org.bukkit.inventory.EquipmentSlot slot : equipment.values()) {
|
||||
io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerEntityEquipment wrapper = new io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerEntityEquipment(packet);
|
||||
EnumWrappers.ItemSlot is = itemBukkitSlot(slot);
|
||||
wrapper.setSlot(is);
|
||||
wrapper.setItem(equipment.getItem(slot));
|
||||
packets.add(wrapper.getHandle());
|
||||
}
|
||||
for (Player p : sendTo) {
|
||||
for (PacketContainer pack : packets) {
|
||||
// Why???
|
||||
sendPacketAsync(p, pack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,12 +367,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,10 +390,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,10 +411,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,13 +425,21 @@ 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);
|
||||
if (packet.getIntegers().getValues().size() > 0) {
|
||||
packet.getIntegers().write(0, entityId);
|
||||
sendPacketAsync(p, packet);
|
||||
}
|
||||
//sendPacketAsync(p, new WrapperPlayServerDestroyEntities(entityId));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
//sendPacketAsync(p, new WrapperPlayServerCamera(entityId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,6 +501,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,
|
||||
@@ -441,6 +523,7 @@ public class PacketManager {
|
||||
location.getPitch()
|
||||
)
|
||||
));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,6 +540,12 @@ 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.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(""),
|
||||
@@ -468,11 +557,15 @@ public class PacketManager {
|
||||
GameMode.CREATIVE,
|
||||
0
|
||||
);
|
||||
*/
|
||||
for (final Player p : sendTo) {
|
||||
sendPacketAsync(p, packet);
|
||||
/*
|
||||
sendPacketAsync(p, new WrapperPlayServerPlayerInfo(
|
||||
WrapperPlayServerPlayerInfo.Action.ADD_PLAYER,
|
||||
data
|
||||
));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,6 +582,23 @@ public class PacketManager {
|
||||
) {
|
||||
final byte mask = 0x01 | 0x02 | 0x04 | 0x08 | 0x010 | 0x020 | 0x40;
|
||||
for (final Player p : sendTo) {
|
||||
|
||||
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) mask);
|
||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
|
||||
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
|
||||
/*
|
||||
packet.setMeta(String.valueOf(playerId), List.of(
|
||||
new EntityData(17, EntityDataTypes.BYTE, mask),
|
||||
new EntityData(15, EntityDataTypes.BYTE, (byte) 0x10)
|
||||
)
|
||||
);
|
||||
|
||||
*/
|
||||
sendPacketAsync(p, packet);
|
||||
/*
|
||||
sendPacketAsync(p, new WrapperPlayServerEntityMetadata(
|
||||
playerId,
|
||||
List.of(
|
||||
@@ -496,6 +606,7 @@ public class PacketManager {
|
||||
new EntityData(15, EntityDataTypes.BYTE, (byte) 0x10)
|
||||
)
|
||||
));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,6 +624,13 @@ 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.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(
|
||||
@@ -525,50 +643,25 @@ public class PacketManager {
|
||||
0
|
||||
)
|
||||
));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
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), () -> {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
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;
|
||||
@@ -579,5 +672,51 @@ 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;
|
||||
};
|
||||
}
|
||||
|
||||
public enum EntityData {
|
||||
|
||||
ON_FIRE((byte) 0x01),
|
||||
CROUCHING((byte) 0x02),
|
||||
SPRINTING((byte) 0x08),
|
||||
SWIMMING((byte) 0x10),
|
||||
INVISIBLE((byte) 0x20),
|
||||
GLOWING((byte) 0x40),
|
||||
ELYTRA_FLY((byte) 0x80);
|
||||
|
||||
final byte bitMask;
|
||||
|
||||
EntityData(byte bitMask) {
|
||||
this.bitMask = bitMask;
|
||||
}
|
||||
|
||||
public byte getBitMask() {
|
||||
return bitMask;
|
||||
}
|
||||
|
||||
public boolean isPresent(byte bits) {
|
||||
return (this.bitMask & bits) == this.bitMask;
|
||||
}
|
||||
|
||||
public byte setBit(byte bits) {
|
||||
return (byte) (bits | this.bitMask);
|
||||
}
|
||||
|
||||
public byte unsetBit(byte bits) {
|
||||
return (byte) (bits & ~this.bitMask);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package io.github.fisher2911.hmccosmetics.packet.wrappers;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
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;
|
||||
|
||||
public class WrapperPlayServerEntityEquipment extends AbstractPacket {
|
||||
public static final PacketType TYPE =
|
||||
PacketType.Play.Server.ENTITY_EQUIPMENT;
|
||||
|
||||
public WrapperPlayServerEntityEquipment() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerEntityEquipment(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());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
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.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Backpack {
|
||||
|
||||
@@ -46,7 +45,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 +53,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 +63,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,7 +92,7 @@ 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<>();
|
||||
final int lookDownPitch = settings.getCosmeticSettings().getLookDownPitch();
|
||||
final boolean hidden = !owner.shouldShow(other);
|
||||
final boolean isLookingDown =
|
||||
@@ -101,23 +100,20 @@ public class Backpack {
|
||||
isSelf &&
|
||||
lookDownPitch != -1 &&
|
||||
owner.isFacingDown(location, lookDownPitch);
|
||||
Equipment equipment = Equipment.fromEntityEquipment(other.getEquipment());
|
||||
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);
|
||||
return;
|
||||
}
|
||||
final com.github.retrooper.packetevents.protocol.item.ItemStack itemStack =
|
||||
SpigotConversionUtil.fromBukkitItemStack(owner.getPlayerArmor().getItem(type).getItemStack(ArmorItem.Status.APPLIED));
|
||||
final ItemStack itemStack =
|
||||
owner.getPlayerArmor().getItem(type).getItemStack(ArmorItem.Status.APPLIED);
|
||||
/*
|
||||
equipment.add(new com.github.retrooper.packetevents.protocol.player.Equipment(
|
||||
EquipmentSlot.HELMET,
|
||||
itemStack
|
||||
));
|
||||
|
||||
*/
|
||||
equipment.setItem(EquipmentSlot.HEAD, itemStack);
|
||||
PacketManager.sendEquipmentPacket(equipment, this.armorStandID, other);
|
||||
PacketManager.sendArmorStandMetaContainer(this.armorStandID, other);
|
||||
PacketManager.sendRotationPacket(this.armorStandID, location, false, other);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package io.github.fisher2911.hmccosmetics.user;
|
||||
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
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;
|
||||
@@ -25,6 +29,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 +56,8 @@ public class Equipment {
|
||||
this.equipment.put(slot, itemStack);
|
||||
}
|
||||
|
||||
public EquipmentSlot[] values() {
|
||||
return VALUES;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -148,13 +148,13 @@ public class UserManager {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public List<com.github.retrooper.packetevents.protocol.player.Equipment> getItemList(
|
||||
public List<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<>();
|
||||
for (final ArmorItem.Type type : ArmorItem.Type.values()) {
|
||||
final EquipmentSlot slot = type.getSlot();
|
||||
if (slot == null) continue;
|
||||
@@ -174,8 +174,8 @@ public class UserManager {
|
||||
return items;
|
||||
}
|
||||
|
||||
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,14 +286,14 @@ 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<>();
|
||||
final List<Equipment> itemList = new ArrayList<>();
|
||||
itemList.add(PacketManager.getEquipment(itemStack, slot));
|
||||
this.sendUpdatePacket(user, itemList);
|
||||
}
|
||||
|
||||
public void sendUpdatePacket(
|
||||
final BaseUser<?> user,
|
||||
List<com.github.retrooper.packetevents.protocol.player.Equipment> items
|
||||
List<Equipment> items
|
||||
) {
|
||||
// final Player player = user.getPlayer();
|
||||
// if (player == null) return;
|
||||
@@ -307,18 +307,21 @@ public class UserManager {
|
||||
if (!user.shouldShow(other)) continue;
|
||||
if (!this.settings.getCosmeticSettings().isInViewDistance(location, other.getLocation())) continue;
|
||||
user.updateBackpack(other, this.settings);
|
||||
PacketManager.sendEquipmentPacket(Equipment.fromEntityEquipment(other.getEquipment()), entityId, other);
|
||||
/*
|
||||
PacketManager.sendEquipmentPacket(
|
||||
items,
|
||||
entityId,
|
||||
other
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
public void sendUpdatePacket(
|
||||
final BaseUser<?> user,
|
||||
final Player other,
|
||||
List<com.github.retrooper.packetevents.protocol.player.Equipment> items
|
||||
List<Equipment> items
|
||||
) {
|
||||
// final Player player = user.getPlayer();
|
||||
// if (player == null) return;
|
||||
@@ -328,10 +331,13 @@ public class UserManager {
|
||||
if (other == null) return;
|
||||
if (!user.shouldShow(other)) return;
|
||||
if (!this.settings.getCosmeticSettings().isInViewDistance(location, other.getLocation())) return;
|
||||
PacketManager.sendEquipmentPacket(Equipment.fromEntityEquipment(other.getEquipment()), entityId, other);
|
||||
/*
|
||||
PacketManager.sendEquipmentPacket(
|
||||
items,
|
||||
entityId,
|
||||
other
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -61,7 +61,7 @@ public class Wardrobe extends User {
|
||||
PacketManager.sendEntitySpawnPacket(
|
||||
settings.getViewerLocation(),
|
||||
this.entityIds.wardrobeViewer(),
|
||||
EntityTypes.ARMOR_STAND,
|
||||
EntityType.ARMOR_STAND,
|
||||
viewer
|
||||
);
|
||||
PacketManager.sendCameraPacket(
|
||||
|
||||
Reference in New Issue
Block a user