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