Released 9.3
This commit is contained in:
parent
9c779686a5
commit
28ca29d4b5
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>LibsDisguises</groupId>
|
<groupId>LibsDisguises</groupId>
|
||||||
<artifactId>LibsDisguises</artifactId>
|
<artifactId>LibsDisguises</artifactId>
|
||||||
<version>9.2.4-SNAPSHOT</version>
|
<version>9.3</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
@ -37,14 +38,16 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (player.getName().contains("UNKNOWN[")) // If the player is temporary
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null) {
|
if (player instanceof com.comphenix.net.sf.cglib.proxy.Factory || player.getVehicle() != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
|
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()
|
||||||
@ -57,7 +60,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
if (disguise.isHidingArmorFromSelf()) {
|
if (disguise.isHidingArmorFromSelf()) {
|
||||||
int armorSlot = Math.abs((slot - 5) - 3);
|
int armorSlot = Math.abs((slot - 5) - 3);
|
||||||
|
|
||||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
org.bukkit.inventory.ItemStack item = player.getInventory().getArmorContents()[armorSlot];
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||||
@ -69,7 +72,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
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 {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -79,10 +82,10 @@ 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 = event.getPlayer().getInventory().getHeldItemSlot();
|
int currentSlot = player.getInventory().getHeldItemSlot();
|
||||||
|
|
||||||
if (slot + 36 == currentSlot || slot == 45) {
|
if (slot + 36 == currentSlot || slot == 45) {
|
||||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
|
org.bukkit.inventory.ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||||
@ -93,7 +96,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
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 {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -110,7 +113,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
// 0 1 2 3 - 8
|
// 0 1 2 3 - 8
|
||||||
// If the packet is coming, then I need to replace the item they are switching to
|
// If the packet is coming, then I need to replace the item they are switching to
|
||||||
// As for the old item, I need to restore it.
|
// As for the old item, I need to restore it.
|
||||||
org.bukkit.inventory.ItemStack currentlyHeld = event.getPlayer().getItemInHand();
|
org.bukkit.inventory.ItemStack currentlyHeld = player.getItemInHand();
|
||||||
// If his old weapon isn't air
|
// If his old weapon isn't air
|
||||||
if (currentlyHeld != null && currentlyHeld.getType() != Material.AIR) {
|
if (currentlyHeld != null && currentlyHeld.getType() != Material.AIR) {
|
||||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||||
@ -118,18 +121,18 @@ 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, event.getPlayer().getInventory().getHeldItemSlot() + 36);
|
mods.write(1, player.getInventory().getHeldItemSlot() + 36);
|
||||||
mods.write(2, ReflectionManager.getNmsItem(currentlyHeld));
|
mods.write(2, ReflectionManager.getNmsItem(currentlyHeld));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
org.bukkit.inventory.ItemStack newHeld = event.getPlayer().getInventory()
|
org.bukkit.inventory.ItemStack newHeld = player.getInventory()
|
||||||
.getItem(event.getPacket().getIntegers().read(0));
|
.getItem(event.getPacket().getIntegers().read(0));
|
||||||
|
|
||||||
// If his new weapon isn't air either!
|
// If his new weapon isn't air either!
|
||||||
@ -143,7 +146,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
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 {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -165,7 +168,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
// Lets just update the entire inventory..
|
// Lets just update the entire inventory..
|
||||||
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
|
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
event.getPlayer().updateInventory();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -179,7 +182,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clickedItem = event.getPlayer().getItemOnCursor();
|
clickedItem = player.getItemOnCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clickedItem != null && clickedItem.getType() != Material.AIR) {
|
if (clickedItem != null && clickedItem.getType() != Material.AIR) {
|
||||||
@ -195,7 +198,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
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 {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -205,7 +208,7 @@ 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 = event.getPlayer().getInventory().getHeldItemSlot();
|
int currentSlot = player.getInventory().getHeldItemSlot();
|
||||||
|
|
||||||
// Check if the player is on the same slot as the slot that its setting
|
// Check if the player is on the same slot as the slot that its setting
|
||||||
if (slot == currentSlot + 36 || slot == 45) {
|
if (slot == currentSlot + 36 || slot == 45) {
|
||||||
@ -217,7 +220,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
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 {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -233,13 +236,15 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event) {
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
// If the inventory is the players inventory
|
// If the inventory is the players inventory
|
||||||
if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().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(event.getPlayer(), event.getPlayer());
|
Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
||||||
|
|
||||||
if (disguise == null || !disguise.isSelfDisguiseVisible()
|
if (disguise == null || !disguise.isSelfDisguiseVisible()
|
||||||
|| (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) {
|
|| (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) {
|
||||||
@ -265,7 +270,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
// Get the bukkit armor slot!
|
// Get the bukkit armor slot!
|
||||||
int armorSlot = Math.abs((slot - 5) - 3);
|
int armorSlot = Math.abs((slot - 5) - 3);
|
||||||
|
|
||||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
org.bukkit.inventory.ItemStack item = player.getInventory().getArmorContents()[armorSlot];
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
event.setPacket(event.getPacket().shallowClone());
|
event.setPacket(event.getPacket().shallowClone());
|
||||||
@ -278,11 +283,11 @@ 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 = event.getPlayer().getInventory().getHeldItemSlot();
|
int currentSlot = player.getInventory().getHeldItemSlot();
|
||||||
|
|
||||||
// Check if the player is on the same slot as the slot that its setting
|
// Check if the player is on the same slot as the slot that its setting
|
||||||
if (slot == currentSlot + 36 || slot == 45) {
|
if (slot == currentSlot + 36 || slot == 45) {
|
||||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
|
org.bukkit.inventory.ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
event.setPacket(event.getPacket().shallowClone());
|
event.setPacket(event.getPacket().shallowClone());
|
||||||
@ -297,7 +302,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
event.setPacket(event.getPacket().shallowClone());
|
event.setPacket(event.getPacket().shallowClone());
|
||||||
|
|
||||||
StructureModifier<List<ItemStack>> mods = event.getPacket().getItemListModifier();
|
StructureModifier<List<ItemStack>> mods = event.getPacket().getItemListModifier();
|
||||||
List<ItemStack> items = new ArrayList<ItemStack>(mods.read(0));
|
List<ItemStack> items = new ArrayList<>(mods.read(0));
|
||||||
|
|
||||||
for (int slot = 0; slot < items.size(); slot++) {
|
for (int slot = 0; slot < items.size(); slot++) {
|
||||||
if (slot >= 5 && slot <= 8) {
|
if (slot >= 5 && slot <= 8) {
|
||||||
@ -305,7 +310,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
|||||||
// Get the bukkit armor slot!
|
// Get the bukkit armor slot!
|
||||||
int armorSlot = Math.abs((slot - 5) - 3);
|
int armorSlot = Math.abs((slot - 5) - 3);
|
||||||
|
|
||||||
ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
ItemStack item = player.getInventory().getArmorContents()[armorSlot];
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
items.set(slot, new ItemStack(Material.AIR));
|
items.set(slot, new ItemStack(Material.AIR));
|
||||||
@ -315,11 +320,11 @@ 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 = event.getPlayer().getInventory().getHeldItemSlot();
|
int currentSlot = player.getInventory().getHeldItemSlot();
|
||||||
|
|
||||||
// Check if the player is on the same slot as the slot that its setting
|
// Check if the player is on the same slot as the slot that its setting
|
||||||
if (slot == currentSlot + 36 || slot == 45) {
|
if (slot == currentSlot + 36 || slot == 45) {
|
||||||
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
|
ItemStack item = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
items.set(slot, new ItemStack(Material.AIR));
|
items.set(slot, new ItemStack(Material.AIR));
|
||||||
|
Loading…
Reference in New Issue
Block a user