Self disguises now behave when riding something

This commit is contained in:
Andrew 2013-11-06 06:09:44 +13:00
parent acd2da49f8
commit ef7d1e936f
3 changed files with 140 additions and 114 deletions

View File

@ -264,7 +264,7 @@ public class DisguiseAPI {
// Remove the old disguise, else we have weird disguises around the place
removeSelfDisguise(player);
// If the disguised player can't see himself. Return
if (!disguise.viewSelfDisguise() || !PacketsManager.isViewDisguisesListenerEnabled())
if (!disguise.viewSelfDisguise() || !PacketsManager.isViewDisguisesListenerEnabled() || player.getVehicle() != null)
return;
try {
// Grab the entity ID the fake disguise will use

View File

@ -2,19 +2,20 @@ package me.libraryaddict.disguise;
import java.util.HashMap;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.scheduler.BukkitRunnable;
public class DisguiseListener implements Listener {
private String currentVersion;
@ -26,6 +27,7 @@ public class DisguiseListener implements Listener {
private String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED
+ "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED
+ ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!";
private DisguiseAPI disguiseAPI = new DisguiseAPI();
public DisguiseListener(LibsDisguises libsDisguises) {
plugin = libsDisguises;
@ -56,6 +58,26 @@ public class DisguiseListener implements Listener {
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onVechileLeave(VehicleExitEvent event) {
final Disguise disguise = DisguiseAPI.getDisguise(event.getExited());
if (disguise != null) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
disguiseAPI.setupFakeDisguise(disguise);
}
});
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onVechileEnter(VehicleEnterEvent event) {
Disguise disguise = DisguiseAPI.getDisguise(event.getEntered());
if (disguise != null && event.getEntered() instanceof Player) {
disguiseAPI.removeVisibleDisguise((Player) event.getEntered());
}
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();

View File

@ -697,7 +697,7 @@ public class PacketsManager {
@Override
public void onPacketSending(PacketEvent event) {
// If the inventory is the players inventory
if (event.getPacket().getIntegers().read(0) == 0) {
if (event.getPlayer().getVehicle() == null && event.getPacket().getIntegers().read(0) == 0) {
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
// If the player is disguised, views self disguises and is hiding a item.
if (disguise != null && disguise.viewSelfDisguise()
@ -786,6 +786,7 @@ public class PacketsManager {
Packets.Client.BLOCK_ITEM_SWITCH, Packets.Client.SET_CREATIVE_SLOT, Packets.Client.WINDOW_CLICK) {
@Override
public void onPacketReceiving(final PacketEvent event) {
if (event.getPlayer().getVehicle() == null) {
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
// If player is disguised, views self disguises and has a inventory modifier
if (disguise != null && disguise.viewSelfDisguise()
@ -805,7 +806,8 @@ public class PacketsManager {
mods.write(1, slot);
mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
false);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
@ -908,7 +910,8 @@ public class PacketsManager {
mods.write(1, slot);
mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
false);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
@ -942,6 +945,7 @@ public class PacketsManager {
}
}
}
}
};
}