Cleanup, fix a bug

This commit is contained in:
libraryaddict 2016-05-13 08:27:53 +12:00
parent 986dfe6246
commit eff6dc3025
6 changed files with 569 additions and 551 deletions

View File

@ -446,13 +446,24 @@ public class DisguiseUtilities
{ {
continue; continue;
} }
try
{
int chunkX = (int) Math.floor(loc.getX() / 16D) - 17, chunkZ = (int) Math.floor(loc.getZ() / 16D) - 17; int chunkX = (int) Math.floor(loc.getX() / 16D) - 17, chunkZ = (int) Math.floor(loc.getZ() / 16D) - 17;
chunkX -= chunkX % 8; chunkX -= chunkX % 8;
chunkZ -= chunkZ % 8; chunkZ -= chunkZ % 8;
// Make unload packets
packets[i] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.UNLOAD_CHUNK, chunkX, chunkZ)
.createPacket(bedChunk, 0);
i++;
// Make load packets
if (oldLoc == null || i > 1)
{
try
{
xChunk.set(bedChunk, chunkX); xChunk.set(bedChunk, chunkX);
zChunk.set(bedChunk, chunkZ); zChunk.set(bedChunk, chunkZ);
} }
@ -461,6 +472,10 @@ public class DisguiseUtilities
ex.printStackTrace(System.out); ex.printStackTrace(System.out);
} }
// MAP_CHUNK_BULK was replaced in 1.9 with several seperated chunk packets
// packets[i] = ProtocolLibrary.getProtocolManager()
// .createPacketConstructor(Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk))
// .createPacket(Arrays.asList(bedChunk));
// Make unload packets // Make unload packets
try try
{ {
@ -468,30 +483,12 @@ public class DisguiseUtilities
.createPacket(bedChunk, 0); .createPacket(bedChunk, 0);
} }
catch (IllegalArgumentException ex) catch (IllegalArgumentException ex)
{
try
{
packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(Server.MAP_CHUNK, bedChunk, true, 0, 40).createPacket(bedChunk, true, 0, 48);
}
catch (IllegalArgumentException ex1)
{ {
packets[i] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.MAP_CHUNK, bedChunk, true, 0) packets[i] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.MAP_CHUNK, bedChunk, true, 0)
.createPacket(bedChunk, true, 0); .createPacket(bedChunk, true, 0);
} }
}
i++; i++;
// Make load packets
if (oldLoc == null || i > 1)
{
// MAP_CHUNK_BULK was replaced in 1.9 with several seperated chunk packets
// packets[i] = ProtocolLibrary.getProtocolManager()
// .createPacketConstructor(Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk))
// .createPacket(Arrays.asList(bedChunk));
packets[i] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.MAP_CHUNK, bedChunk, true, 0)
.createPacket(bedChunk, true, 0);
i++;
} }
} }

View File

@ -53,14 +53,19 @@ public class PacketListenerClientInteract extends PacketAdapter
event.setCancelled(true); event.setCancelled(true);
} }
ItemStack item = observer.getItemInHand(); for (ItemStack item : new ItemStack[]
if (item != null && item.getType() == Material.INK_SACK)
{ {
observer.getInventory().getItemInMainHand(), observer.getInventory().getItemInOffHand()
})
{
if (item == null || item.getType() != Material.INK_SACK)
continue;
Disguise disguise = DisguiseAPI.getDisguise(observer, entity); Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise != null && (disguise.getType() == DisguiseType.SHEEP || disguise.getType() == DisguiseType.WOLF)) if (disguise == null || (disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF))
{ continue;
AnimalColor color = AnimalColor.getColor(item.getDurability()); AnimalColor color = AnimalColor.getColor(item.getDurability());
if (disguise.getType() == DisguiseType.SHEEP) if (disguise.getType() == DisguiseType.SHEEP)
@ -77,7 +82,6 @@ public class PacketListenerClientInteract extends PacketAdapter
} }
} }
} }
}
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();

View File

@ -41,8 +41,11 @@ public class PacketListenerInventory extends PacketAdapter
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary if (event.getPlayer().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 (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null)
{ {
return;
}
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer()); Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
// If player is disguised, views self disguises and has a inventory modifier // If player is disguised, views self disguises and has a inventory modifier
@ -265,23 +268,29 @@ public class PacketListenerInventory extends PacketAdapter
} }
} }
} }
}
} }
@Override @Override
public void onPacketSending(PacketEvent event) public void onPacketSending(PacketEvent event)
{ {
// 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 (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()); Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
// If the player is disguised, views self disguises and is hiding a item. if (disguise == null || !disguise.isSelfDisguiseVisible()
if (disguise != null && disguise.isSelfDisguiseVisible() || (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf()))
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf()))
{ {
return;
}
// If the player is disguised, views self disguises and is hiding a item.
// If the server is setting the slot // If the server is setting the slot
// Need to set it to air if its in a place it shouldn't be. // Need to set it to air if its in a place it shouldn't be.
// Things such as picking up a item, spawned in item. Plugin sets the item. etc. Will fire this // Things such as picking up a item, spawned in item. Plugin sets the item. etc. Will fire this
@ -351,8 +360,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() org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
.getArmorContents()[armorSlot];
if (item != null && item.getType() != Material.AIR) if (item != null && item.getType() != Material.AIR)
{ {
@ -384,7 +392,5 @@ public class PacketListenerInventory extends PacketAdapter
mods.write(0, items); mods.write(0, items);
} }
} }
}
}
} }

View File

@ -53,8 +53,11 @@ public class PacketListenerMain extends PacketAdapter
PacketContainer[][] packets = PacketsManager.transformPacket(event.getPacket(), event.getPlayer(), entity); PacketContainer[][] packets = PacketsManager.transformPacket(event.getPacket(), event.getPlayer(), entity);
if (packets != null) if (packets == null)
{ {
return;
}
event.setCancelled(true); event.setCancelled(true);
try try
@ -66,8 +69,11 @@ public class PacketListenerMain extends PacketAdapter
final PacketContainer[] delayed = packets[1]; final PacketContainer[] delayed = packets[1];
if (delayed.length > 0) if (delayed.length == 0)
{ {
return;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable()
{ {
public void run() public void run()
@ -86,12 +92,11 @@ public class PacketListenerMain extends PacketAdapter
} }
}, 2); }, 2);
} }
}
catch (InvocationTargetException ex) catch (InvocationTargetException ex)
{ {
ex.printStackTrace(); ex.printStackTrace();
} }
}
} }
} }

View File

@ -286,8 +286,11 @@ public class PacketListenerSounds extends PacketAdapter
} }
else if (event.getPacketType() == Server.ENTITY_STATUS) else if (event.getPacketType() == Server.ENTITY_STATUS)
{ {
if ((byte) mods.read(1) == 2) if ((byte) mods.read(1) != 2)
{ {
return;
}
// It made a damage animation // It made a damage animation
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0); Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
@ -403,4 +406,3 @@ public class PacketListenerSounds extends PacketAdapter
} }
} }
} }
}

View File

@ -47,10 +47,16 @@ public class PacketListenerViewDisguises extends PacketAdapter
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
return; return;
if (event.getPacket().getIntegers().read(0) == observer.getEntityId()) if (event.getPacket().getIntegers().read(0) != observer.getEntityId())
{ {
if (DisguiseAPI.isSelfDisguised(observer)) return;
}
if (!DisguiseAPI.isSelfDisguised(observer))
{ {
return;
}
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them. // Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
PacketContainer[][] transformed = PacketsManager.transformPacket(event.getPacket(), observer, observer); PacketContainer[][] transformed = PacketsManager.transformPacket(event.getPacket(), observer, observer);
@ -184,5 +190,3 @@ public class PacketListenerViewDisguises extends PacketAdapter
} }
} }
} }
}
}