Added new disguises, added new disguisetypes, fixed the
horse/lama/whatever changes, fixed a boat 'facing' bug, renamed a few internal methods, still dont know why some disguises are invisible.
This commit is contained in:
@@ -8,8 +8,7 @@ import org.bukkit.Sound;
|
||||
/**
|
||||
* Only living disguises go in here!
|
||||
*/
|
||||
public enum DisguiseSound
|
||||
{
|
||||
public enum DisguiseSound {
|
||||
|
||||
ARROW(null, null, null, null, Sound.ENTITY_ARROW_HIT, Sound.ENTITY_ARROW_SHOOT),
|
||||
|
||||
@@ -44,6 +43,13 @@ public enum DisguiseSound
|
||||
ENDERMITE(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_ENDERMITE_STEP, Sound.ENTITY_ENDERMITE_DEATH,
|
||||
Sound.ENTITY_ENDERMITE_AMBIENT),
|
||||
|
||||
EVOKER(Sound.ENTITY_EVOCATION_ILLAGER_HURT, null, Sound.ENTITY_EVOCATION_ILLAGER_DEATH,
|
||||
Sound.ENTITY_EVOCATION_ILLAGER_AMBIENT, Sound.ENTITY_EVOCATION_ILLAGER_CAST_SPELL,
|
||||
Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_ATTACK, Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_SUMMON,
|
||||
Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_WOLOLO),
|
||||
|
||||
EVOKER_FANGS(null, null, null, null, Sound.ENTITY_EVOCATION_FANGS_ATTACK),
|
||||
|
||||
GHAST(Sound.ENTITY_GHAST_HURT, null, Sound.ENTITY_GHAST_DEATH, Sound.ENTITY_GHAST_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
|
||||
Sound.ENTITY_GHAST_SHOOT, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_GHAST_SCREAM, Sound.ENTITY_GHAST_WARN),
|
||||
|
||||
@@ -58,6 +64,9 @@ public enum DisguiseSound
|
||||
IRON_GOLEM(Sound.ENTITY_IRONGOLEM_HURT, Sound.ENTITY_IRONGOLEM_STEP, Sound.ENTITY_IRONGOLEM_DEATH,
|
||||
Sound.ENTITY_IRONGOLEM_ATTACK),
|
||||
|
||||
LLAMA(Sound.ENTITY_LLAMA_HURT, Sound.ENTITY_LLAMA_STEP, Sound.ENTITY_LLAMA_DEATH, Sound.ENTITY_LLAMA_AMBIENT,
|
||||
Sound.ENTITY_LLAMA_ANGRY, Sound.ENTITY_LLAMA_CHEST, Sound.ENTITY_LLAMA_EAT, Sound.ENTITY_LLAMA_SWAG),
|
||||
|
||||
MAGMA_CUBE(Sound.ENTITY_MAGMACUBE_HURT, Sound.ENTITY_MAGMACUBE_JUMP, null, null),
|
||||
|
||||
MULE(Sound.ENTITY_MULE_HURT, "step.grass", Sound.ENTITY_MULE_DEATH, Sound.ENTITY_MULE_AMBIENT),
|
||||
@@ -104,9 +113,14 @@ public enum DisguiseSound
|
||||
Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD,
|
||||
Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
|
||||
|
||||
VEX(Sound.ENTITY_VEX_HURT, null, Sound.ENTITY_VEX_DEATH, Sound.ENTITY_VEX_AMBIENT, Sound.ENTITY_VEX_CHARGE),
|
||||
|
||||
VILLAGER(Sound.ENTITY_VILLAGER_HURT, null, Sound.ENTITY_VILLAGER_DEATH, Sound.ENTITY_VILLAGER_AMBIENT,
|
||||
Sound.ENTITY_VILLAGER_TRADING, Sound.ENTITY_VILLAGER_NO, Sound.ENTITY_VILLAGER_YES),
|
||||
|
||||
VINDICATOR(Sound.ENTITY_VINDICATION_ILLAGER_HURT, null, Sound.ENTITY_VINDICATION_ILLAGER_DEATH,
|
||||
Sound.ENTITY_VINDICATION_ILLAGER_AMBIENT),
|
||||
|
||||
WITCH(Sound.ENTITY_WITCH_HURT, null, Sound.ENTITY_WITCH_DEATH, Sound.ENTITY_WITCH_AMBIENT),
|
||||
|
||||
WITHER(Sound.ENTITY_WITHER_HURT, null, Sound.ENTITY_WITHER_DEATH, Sound.ENTITY_WITHER_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
|
||||
@@ -126,19 +140,15 @@ public enum DisguiseSound
|
||||
Sound.ENTITY_ZOMBIE_INFECT, Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD,
|
||||
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
|
||||
|
||||
public enum SoundType
|
||||
{
|
||||
public enum SoundType {
|
||||
CANCEL, DEATH, HURT, IDLE, STEP
|
||||
}
|
||||
|
||||
public static DisguiseSound getType(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static DisguiseSound getType(String name) {
|
||||
try {
|
||||
return valueOf(name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -147,43 +157,35 @@ public enum DisguiseSound
|
||||
private float damageSoundVolume = 1F;
|
||||
private HashMap<SoundType, String> disguiseSounds = new HashMap<>();
|
||||
|
||||
DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds)
|
||||
{
|
||||
DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds) {
|
||||
addSound(hurt, SoundType.HURT);
|
||||
addSound(step, SoundType.STEP);
|
||||
addSound(death, SoundType.DEATH);
|
||||
addSound(idle, SoundType.IDLE);
|
||||
|
||||
for (Object obj : sounds)
|
||||
{
|
||||
for (Object obj : sounds) {
|
||||
addSound(obj, SoundType.CANCEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addSound(Object sound, SoundType type)
|
||||
{
|
||||
private void addSound(Object sound, SoundType type) {
|
||||
String s;
|
||||
|
||||
if (sound == null)
|
||||
{
|
||||
if (sound == null) {
|
||||
return;
|
||||
}
|
||||
else if (sound instanceof String)
|
||||
{
|
||||
else if (sound instanceof String) {
|
||||
s = (String) sound;
|
||||
}
|
||||
else if (sound instanceof Sound)
|
||||
{
|
||||
else if (sound instanceof Sound) {
|
||||
s = ReflectionManager.getCraftSound((Sound) sound);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
throw new RuntimeException("Was given a unknown object " + sound);
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
switch (type) {
|
||||
case HURT:
|
||||
disguiseSounds.put(SoundType.HURT, s);
|
||||
break;
|
||||
@@ -201,58 +203,47 @@ public enum DisguiseSound
|
||||
}
|
||||
}
|
||||
|
||||
public float getDamageAndIdleSoundVolume()
|
||||
{
|
||||
public float getDamageAndIdleSoundVolume() {
|
||||
return damageSoundVolume;
|
||||
}
|
||||
|
||||
public String getSound(SoundType type)
|
||||
{
|
||||
if (type == null || !disguiseSounds.containsKey(type))
|
||||
{
|
||||
public String getSound(SoundType type) {
|
||||
if (type == null || !disguiseSounds.containsKey(type)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return disguiseSounds.get(type);
|
||||
}
|
||||
|
||||
public HashSet<String> getSoundsToCancel()
|
||||
{
|
||||
public HashSet<String> getSoundsToCancel() {
|
||||
return cancelSounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check if this sound name is owned by this disguise sound.
|
||||
*/
|
||||
public SoundType getType(String sound, boolean ignoreDamage)
|
||||
{
|
||||
public SoundType getType(String sound, boolean ignoreDamage) {
|
||||
if (sound == null)
|
||||
return SoundType.CANCEL;
|
||||
|
||||
if (isCancelSound(sound))
|
||||
{
|
||||
if (isCancelSound(sound)) {
|
||||
return SoundType.CANCEL;
|
||||
}
|
||||
|
||||
if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.")
|
||||
&& sound.startsWith("step."))
|
||||
{
|
||||
&& sound.startsWith("step.")) {
|
||||
return SoundType.STEP;
|
||||
}
|
||||
|
||||
for (SoundType type : SoundType.values())
|
||||
{
|
||||
if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT))
|
||||
{
|
||||
for (SoundType type : SoundType.values()) {
|
||||
if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String s = disguiseSounds.get(type);
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
if (s.equals(sound))
|
||||
{
|
||||
if (s != null) {
|
||||
if (s.equals(sound)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -261,46 +252,36 @@ public enum DisguiseSound
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isCancelSound(String sound)
|
||||
{
|
||||
public boolean isCancelSound(String sound) {
|
||||
return getSoundsToCancel().contains(sound);
|
||||
}
|
||||
|
||||
public void removeSound(SoundType type, Sound sound)
|
||||
{
|
||||
public void removeSound(SoundType type, Sound sound) {
|
||||
removeSound(type, ReflectionManager.getCraftSound(sound));
|
||||
}
|
||||
|
||||
public void removeSound(SoundType type, String sound)
|
||||
{
|
||||
if (type == SoundType.CANCEL)
|
||||
{
|
||||
public void removeSound(SoundType type, String sound) {
|
||||
if (type == SoundType.CANCEL) {
|
||||
cancelSounds.remove(sound);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
disguiseSounds.remove(type);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDamageAndIdleSoundVolume(float strength)
|
||||
{
|
||||
public void setDamageAndIdleSoundVolume(float strength) {
|
||||
this.damageSoundVolume = strength;
|
||||
}
|
||||
|
||||
public void setSound(SoundType type, Sound sound)
|
||||
{
|
||||
public void setSound(SoundType type, Sound sound) {
|
||||
setSound(type, ReflectionManager.getCraftSound(sound));
|
||||
}
|
||||
|
||||
public void setSound(SoundType type, String sound)
|
||||
{
|
||||
if (type == SoundType.CANCEL)
|
||||
{
|
||||
public void setSound(SoundType type, String sound) {
|
||||
if (type == SoundType.CANCEL) {
|
||||
cancelSounds.add(sound);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
disguiseSounds.put(type, sound);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,7 @@
|
||||
package me.libraryaddict.disguise.utilities.packetlisteners;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -20,12 +21,10 @@ import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class PacketListenerInventory extends PacketAdapter
|
||||
{
|
||||
public class PacketListenerInventory extends PacketAdapter {
|
||||
private LibsDisguises libsDisguises;
|
||||
|
||||
public PacketListenerInventory(LibsDisguises plugin)
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -33,16 +32,14 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(final PacketEvent event)
|
||||
{
|
||||
public void onPacketReceiving(final PacketEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
|
||||
return;
|
||||
|
||||
if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null)
|
||||
{
|
||||
if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,23 +47,18 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
|
||||
// If player is disguised, views self disguises and has a inventory modifier
|
||||
if (disguise != null && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()))
|
||||
{
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
// 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);
|
||||
|
||||
if (slot >= 5 && slot <= 8)
|
||||
{
|
||||
if (disguise.isHidingArmorFromSelf())
|
||||
{
|
||||
if (slot >= 5 && slot <= 8) {
|
||||
if (disguise.isHidingArmorFromSelf()) {
|
||||
int armorSlot = Math.abs((slot - 5) - 3);
|
||||
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
@@ -75,29 +67,23 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
mods.write(1, slot);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (slot >= 36 && slot <= 44)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
else if (slot >= 36 && slot <= 44) {
|
||||
if (disguise.isHidingHeldItemFromSelf()) {
|
||||
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
|
||||
|
||||
if (slot + 36 == currentSlot)
|
||||
{
|
||||
if (slot + 36 == currentSlot) {
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
@@ -105,12 +91,10 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
mods.write(1, slot);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -119,18 +103,15 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
}
|
||||
}
|
||||
// If the player switched item, aka he moved from slot 1 to slot 2
|
||||
else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_SLOT)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_SLOT) {
|
||||
if (disguise.isHidingHeldItemFromSelf()) {
|
||||
// From logging, it seems that both bukkit and nms uses the same thing for the slot switching.
|
||||
// 0 1 2 3 - 8
|
||||
// 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.
|
||||
org.bukkit.inventory.ItemStack currentlyHeld = event.getPlayer().getItemInHand();
|
||||
// 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);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
@@ -139,12 +120,10 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36);
|
||||
mods.write(2, ReflectionManager.getNmsItem(currentlyHeld));
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -153,8 +132,7 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
.getItem(event.getPacket().getIntegers().read(0));
|
||||
|
||||
// If his new weapon isn't air either!
|
||||
if (newHeld != null && newHeld.getType() != Material.AIR)
|
||||
{
|
||||
if (newHeld != null && newHeld.getType() != Material.AIR) {
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
@@ -163,36 +141,29 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
mods.write(1, event.getPacket().getIntegers().read(0) + 36);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
if (event.getPacket().getShorts().read(0) == 1)
|
||||
{
|
||||
if (event.getPacket().getShorts().read(0) == 1) {
|
||||
// Its a shift click
|
||||
clickedItem = event.getPacket().getItemModifier().read(0);
|
||||
|
||||
if (clickedItem != null && clickedItem.getType() != Material.AIR)
|
||||
{
|
||||
if (clickedItem != null && clickedItem.getType() != Material.AIR) {
|
||||
// Rather than predict the clients actions
|
||||
// Lets just update the entire inventory..
|
||||
Bukkit.getScheduler().runTask(libsDisguises, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
|
||||
public void run() {
|
||||
event.getPlayer().updateInventory();
|
||||
}
|
||||
});
|
||||
@@ -200,25 +171,20 @@ 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)
|
||||
{
|
||||
if (event.getPacket().getIntegers().read(0) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
clickedItem = event.getPlayer().getItemOnCursor();
|
||||
}
|
||||
|
||||
if (clickedItem != null && clickedItem.getType() != Material.AIR)
|
||||
{
|
||||
if (clickedItem != null && clickedItem.getType() != Material.AIR) {
|
||||
// If the slot is a armor slot
|
||||
if (slot >= 5 && slot <= 8)
|
||||
{
|
||||
if (disguise.isHidingArmorFromSelf())
|
||||
{
|
||||
if (slot >= 5 && slot <= 8) {
|
||||
if (disguise.isHidingArmorFromSelf()) {
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
@@ -227,26 +193,21 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
mods.write(1, slot);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
}
|
||||
else if (slot >= 36 && slot <= 44)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
else if (slot >= 36 && slot <= 44) {
|
||||
if (disguise.isHidingHeldItemFromSelf()) {
|
||||
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
|
||||
|
||||
// Check if the player is on the same slot as the slot that its setting
|
||||
if (slot == currentSlot + 36)
|
||||
{
|
||||
if (slot == currentSlot + 36) {
|
||||
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
@@ -254,12 +215,10 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
mods.write(1, slot);
|
||||
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -272,20 +231,17 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event)
|
||||
{
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
// If the inventory is the players inventory
|
||||
if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null
|
||||
|| event.getPacket().getIntegers().read(0) != 0)
|
||||
{
|
||||
|| event.getPacket().getIntegers().read(0) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
|
||||
|
||||
if (disguise == null || !disguise.isSelfDisguiseVisible()
|
||||
|| (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf()))
|
||||
{
|
||||
|| (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -297,24 +253,20 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
/**
|
||||
* Done
|
||||
*/
|
||||
if (event.getPacketType() == Server.SET_SLOT)
|
||||
{
|
||||
if (event.getPacketType() == Server.SET_SLOT) {
|
||||
// The raw slot
|
||||
// nms code has the start of the hotbar being 36.
|
||||
int slot = event.getPacket().getIntegers().read(1);
|
||||
|
||||
// If the slot is a armor slot
|
||||
if (slot >= 5 && slot <= 8)
|
||||
{
|
||||
if (disguise.isHidingArmorFromSelf())
|
||||
{
|
||||
if (slot >= 5 && slot <= 8) {
|
||||
if (disguise.isHidingArmorFromSelf()) {
|
||||
// Get the bukkit armor slot!
|
||||
int armorSlot = Math.abs((slot - 5) - 3);
|
||||
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
event.setPacket(event.getPacket().shallowClone());
|
||||
|
||||
event.getPacket().getModifier().write(2,
|
||||
@@ -323,19 +275,15 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
}
|
||||
else if (slot >= 36 && slot <= 44)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
else if (slot >= 36 && slot <= 44) {
|
||||
if (disguise.isHidingHeldItemFromSelf()) {
|
||||
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
|
||||
|
||||
// Check if the player is on the same slot as the slot that its setting
|
||||
if (slot == currentSlot + 36)
|
||||
{
|
||||
if (slot == currentSlot + 36) {
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
event.setPacket(event.getPacket().shallowClone());
|
||||
event.getPacket().getModifier().write(2,
|
||||
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
@@ -344,45 +292,36 @@ public class PacketListenerInventory extends PacketAdapter
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event.getPacketType() == Server.WINDOW_ITEMS)
|
||||
{
|
||||
else if (event.getPacketType() == Server.WINDOW_ITEMS) {
|
||||
event.setPacket(event.getPacket().deepClone());
|
||||
|
||||
StructureModifier<ItemStack[]> mods = event.getPacket().getItemArrayModifier();
|
||||
ItemStack[] items = mods.read(0);
|
||||
StructureModifier<List<ItemStack>> mods = event.getPacket().getItemListModifier();
|
||||
List<ItemStack> items = mods.read(0);
|
||||
|
||||
for (int slot = 0; slot < items.length; slot++)
|
||||
{
|
||||
if (slot >= 5 && slot <= 8)
|
||||
{
|
||||
if (disguise.isHidingArmorFromSelf())
|
||||
{
|
||||
for (int slot = 0; slot < items.size(); slot++) {
|
||||
if (slot >= 5 && slot <= 8) {
|
||||
if (disguise.isHidingArmorFromSelf()) {
|
||||
// Get the bukkit armor slot!
|
||||
int armorSlot = Math.abs((slot - 5) - 3);
|
||||
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
||||
ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
items[slot] = new org.bukkit.inventory.ItemStack(0);
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
items.set(slot, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
}
|
||||
else if (slot >= 36 && slot <= 44)
|
||||
{
|
||||
if (disguise.isHidingHeldItemFromSelf())
|
||||
{
|
||||
else if (slot >= 36 && slot <= 44) {
|
||||
if (disguise.isHidingHeldItemFromSelf()) {
|
||||
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
|
||||
|
||||
// Check if the player is on the same slot as the slot that its setting
|
||||
if (slot == currentSlot + 36)
|
||||
{
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||
if (slot == currentSlot + 36) {
|
||||
ItemStack item = event.getPlayer().getItemInHand();
|
||||
|
||||
if (item != null && item.getType() != Material.AIR)
|
||||
{
|
||||
items[slot] = new org.bukkit.inventory.ItemStack(0);
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
items.set(slot, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user