2019-01-03 03:13:03 +01:00
|
|
|
package me.libraryaddict.disguise.utilities.packets;
|
|
|
|
|
|
|
|
import com.comphenix.protocol.PacketType;
|
|
|
|
import com.comphenix.protocol.events.PacketContainer;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
2019-12-05 23:37:33 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.packets.packethandlers.*;
|
2020-02-19 04:32:32 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
2019-01-03 03:13:03 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by libraryaddict on 3/01/2019.
|
|
|
|
*/
|
|
|
|
public class PacketsHandler {
|
|
|
|
private HashMap<Disguise, ArrayList<UUID>> cancelMeta = new HashMap<>();
|
|
|
|
private Collection<IPacketHandler> packetHandlers;
|
|
|
|
|
|
|
|
public PacketsHandler() {
|
|
|
|
registerPacketHandlers();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void registerPacketHandlers() {
|
|
|
|
packetHandlers = new ArrayList<>();
|
|
|
|
|
|
|
|
packetHandlers.add(new PacketHandlerAnimation());
|
|
|
|
packetHandlers.add(new PacketHandlerAttributes());
|
|
|
|
packetHandlers.add(new PacketHandlerCollect());
|
|
|
|
packetHandlers.add(new PacketHandlerEntityStatus());
|
2019-10-13 07:22:39 +02:00
|
|
|
packetHandlers.add(new PacketHandlerEquipment(this));
|
2020-02-19 04:32:32 +01:00
|
|
|
|
|
|
|
if (!NmsVersion.v1_14.isSupported()) {
|
|
|
|
packetHandlers.add(new PacketHandlerHeadRotation());
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
packetHandlers.add(new PacketHandlerMetadata(this));
|
|
|
|
packetHandlers.add(new PacketHandlerMovement());
|
|
|
|
packetHandlers.add(new PacketHandlerSpawn(this));
|
|
|
|
packetHandlers.add(new PacketHandlerVelocity());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCancelMeta(Disguise disguise, Player observer) {
|
|
|
|
return cancelMeta.containsKey(disguise) && cancelMeta.get(disguise).contains(observer.getUniqueId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addCancel(Disguise disguise, Player observer) {
|
|
|
|
if (!cancelMeta.containsKey(disguise)) {
|
|
|
|
cancelMeta.put(disguise, new ArrayList<UUID>());
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelMeta.get(disguise).add(observer.getUniqueId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeCancel(Disguise disguise, Player observer) {
|
|
|
|
ArrayList<UUID> cancel;
|
|
|
|
|
|
|
|
if ((cancel = cancelMeta.get(disguise)) == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cancel.remove(observer.getUniqueId());
|
|
|
|
|
|
|
|
if (!cancel.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
cancelMeta.remove(disguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if
|
|
|
|
* its not
|
|
|
|
* transformed
|
|
|
|
*/
|
|
|
|
public LibsPackets transformPacket(PacketContainer sentPacket, Disguise disguise, Player observer, Entity entity) {
|
|
|
|
LibsPackets packets = new LibsPackets(disguise);
|
|
|
|
|
2019-12-05 23:37:33 +01:00
|
|
|
if (disguise.getType() == DisguiseType.UNKNOWN) {
|
|
|
|
return packets;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
try {
|
|
|
|
packets.addPacket(sentPacket);
|
|
|
|
|
|
|
|
for (IPacketHandler packetHandler : packetHandlers) {
|
|
|
|
for (PacketType packetType : packetHandler.getHandledPackets()) {
|
|
|
|
if (packetType != sentPacket.getType()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
packetHandler.handle(disguise, sentPacket, packets, observer, entity);
|
|
|
|
return packets;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
packets.setUnhandled();
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return packets;
|
|
|
|
}
|
|
|
|
}
|