Handle client interact packets differently
This commit is contained in:
parent
948e516505
commit
cd4ecb2974
@ -6,6 +6,7 @@ import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
@ -37,22 +38,44 @@ public class PacketListenerClientInteract extends PacketAdapter {
|
||||
if (observer == null || observer.getName().contains("UNKNOWN[")) // If the player is temporary
|
||||
return;
|
||||
|
||||
if (!observer.isOp() && ("%%__USER__%%".equals(123 + "45") || LibsDisguises.getInstance().getUpdateChecker().isGoSilent())) {
|
||||
if (!observer.isOp() &&
|
||||
("%%__USER__%%".equals(123 + "45") || LibsDisguises.getInstance().getUpdateChecker().isGoSilent())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
PacketContainer packet = event.getPacket();
|
||||
|
||||
final Disguise disguise = DisguiseUtilities.getDisguise(event.getPlayer(), packet.getIntegers().read(0));
|
||||
if (packet.getIntegers().read(0) == DisguiseAPI.getSelfDisguiseId()) {
|
||||
// Self disguise
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
Entity entity = DisguiseUtilities.getEntity(observer.getWorld(), packet.getIntegers().read(0));
|
||||
|
||||
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (event.isAsync()) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handleSync(observer, packet);
|
||||
}
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
} else {
|
||||
handleSync(observer, packet);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSync(Player observer, PacketContainer packet) {
|
||||
final Disguise disguise = DisguiseUtilities.getDisguise(observer, packet.getIntegers().read(0));
|
||||
|
||||
if (disguise == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (disguise.getEntity() == observer) {
|
||||
// If it's a self-interact
|
||||
event.setCancelled(true);
|
||||
|
||||
// The type of interact, we don't care the difference with "Interact_At" however as it's not
|
||||
// useful
|
||||
// for self disguises
|
||||
@ -78,12 +101,6 @@ public class PacketListenerClientInteract extends PacketAdapter {
|
||||
Bukkit.getPluginManager().callEvent(selfEvent);
|
||||
}
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
} else {
|
||||
Entity entity = disguise.getEntity();
|
||||
|
||||
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
switch (disguise.getType()) {
|
||||
|
@ -16,7 +16,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
@ -26,9 +25,8 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
private LibsDisguises libsDisguises;
|
||||
|
||||
public PacketListenerInventory(LibsDisguises plugin) {
|
||||
super(plugin, ListenerPriority.HIGH, Server.SET_SLOT, Server.WINDOW_ITEMS,
|
||||
PacketType.Play.Client.HELD_ITEM_SLOT, PacketType.Play.Client.SET_CREATIVE_SLOT,
|
||||
PacketType.Play.Client.WINDOW_CLICK);
|
||||
super(plugin, ListenerPriority.HIGH, Server.SET_SLOT, Server.WINDOW_ITEMS, PacketType.Play.Client.HELD_ITEM_SLOT,
|
||||
PacketType.Play.Client.SET_CREATIVE_SLOT, PacketType.Play.Client.WINDOW_CLICK);
|
||||
|
||||
libsDisguises = plugin;
|
||||
}
|
||||
@ -47,21 +45,11 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.isAsync()) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onPacketReceiving(event);
|
||||
}
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
return;
|
||||
}
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
||||
|
||||
// If player is disguised, views self disguises and has a inventory modifier
|
||||
if (disguise != null && disguise.isSelfDisguiseVisible() &&
|
||||
(disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
if (disguise != null && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
// If they are in creative and clicked on a slot
|
||||
if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT) {
|
||||
int slot = event.getPacket().getIntegers().read(0);
|
||||
@ -79,8 +67,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
|
||||
mods.write(0, 0);
|
||||
mods.write(1, slot);
|
||||
mods.write(2,
|
||||
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
@ -90,7 +77,8 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (slot >= 36 && slot <= 45) {
|
||||
}
|
||||
else if (slot >= 36 && slot <= 45) {
|
||||
if (disguise.isHidingHeldItemFromSelf()) {
|
||||
int currentSlot = player.getInventory().getHeldItemSlot();
|
||||
|
||||
@ -103,8 +91,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
mods.write(1, slot);
|
||||
mods.write(2,
|
||||
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
@ -164,7 +151,8 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) {
|
||||
}
|
||||
else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) {
|
||||
int slot = event.getPacket().getIntegers().read(1);
|
||||
|
||||
org.bukkit.inventory.ItemStack clickedItem;
|
||||
@ -184,7 +172,8 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// If its not a player inventory click
|
||||
// Shift clicking is exempted for the item in hand..
|
||||
if (event.getPacket().getIntegers().read(0) != 0) {
|
||||
@ -194,8 +183,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
clickedItem = player.getItemOnCursor();
|
||||
}
|
||||
|
||||
if (clickedItem != null && clickedItem.getType() != Material.AIR &&
|
||||
clickedItem.getType() != Material.ELYTRA) {
|
||||
if (clickedItem != null && clickedItem.getType() != Material.AIR && clickedItem.getType() != Material.ELYTRA) {
|
||||
// If the slot is a armor slot
|
||||
if (slot >= 5 && slot <= 8) {
|
||||
if (disguise.isHidingArmorFromSelf()) {
|
||||
@ -205,8 +193,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
|
||||
mods.write(0, 0);
|
||||
mods.write(1, slot);
|
||||
mods.write(2,
|
||||
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
@ -216,7 +203,8 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
}
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
} else if (slot >= 36 && slot <= 45) {
|
||||
}
|
||||
else if (slot >= 36 && slot <= 45) {
|
||||
if (disguise.isHidingHeldItemFromSelf()) {
|
||||
int currentSlot = player.getInventory().getHeldItemSlot();
|
||||
|
||||
@ -227,8 +215,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
mods.write(1, slot);
|
||||
mods.write(2,
|
||||
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
@ -242,6 +229,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -249,15 +237,15 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
// If the inventory is the players inventory
|
||||
if (player instanceof com.comphenix.net.sf.cglib.proxy.Factory || player.getVehicle() != null ||
|
||||
event.getPacket().getIntegers().read(0) != 0) {
|
||||
if (player instanceof com.comphenix.net.sf.cglib.proxy.Factory || player.getVehicle() != null
|
||||
|| event.getPacket().getIntegers().read(0) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
||||
|
||||
if (disguise == null || !disguise.isSelfDisguiseVisible() ||
|
||||
(!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) {
|
||||
if (disguise == null || !disguise.isSelfDisguiseVisible()
|
||||
|| (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -290,7 +278,8 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
}
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
} else if (slot >= 36 && slot <= 45) {
|
||||
}
|
||||
else if (slot >= 36 && slot <= 45) {
|
||||
if (disguise.isHidingHeldItemFromSelf()) {
|
||||
int currentSlot = player.getInventory().getHeldItemSlot();
|
||||
|
||||
@ -306,7 +295,8 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (event.getPacketType() == Server.WINDOW_ITEMS) {
|
||||
}
|
||||
else if (event.getPacketType() == Server.WINDOW_ITEMS) {
|
||||
event.setPacket(event.getPacket().shallowClone());
|
||||
|
||||
StructureModifier<List<ItemStack>> mods = event.getPacket().getItemListModifier();
|
||||
@ -325,7 +315,8 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
}
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
} else if (slot >= 36 && slot <= 45) {
|
||||
}
|
||||
else if (slot >= 36 && slot <= 45) {
|
||||
if (disguise.isHidingHeldItemFromSelf()) {
|
||||
int currentSlot = player.getInventory().getHeldItemSlot();
|
||||
|
||||
@ -344,4 +335,5 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
mods.write(0, items);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user