2013-05-17 23:05:19 +02:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
import me.libraryaddict.disguise.DisguiseTypes.Disguise;
|
|
|
|
import net.minecraft.server.v1_5_R3.*;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
public class DisguiseAPI {
|
|
|
|
|
|
|
|
private static ConcurrentHashMap<String, Disguise> disguises = new ConcurrentHashMap<String, Disguise>();
|
2013-05-21 02:59:57 +02:00
|
|
|
private static boolean playSounds = true;
|
2013-05-17 23:05:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Player
|
|
|
|
* - The player to disguise
|
|
|
|
* @param Disguise
|
|
|
|
* - The disguise to wear
|
|
|
|
*/
|
|
|
|
public static void disguiseToAll(Player p, Disguise disguise) {
|
|
|
|
disguises.put(p.getName(), disguise);
|
2013-05-20 09:57:41 +02:00
|
|
|
disguise.constructPacket(p);
|
2013-05-17 23:05:19 +02:00
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
2013-05-21 03:35:39 +02:00
|
|
|
if (p.getWorld() != player.getWorld() || !player.canSee(p))
|
2013-05-17 23:05:19 +02:00
|
|
|
continue;
|
|
|
|
player.hidePlayer(p);
|
|
|
|
player.showPlayer(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Player
|
|
|
|
* - The player who is being disguised
|
|
|
|
* @param Player
|
|
|
|
* - The player who is watching the disguised
|
|
|
|
* @param Disguise
|
|
|
|
* - The disguise he is wearing
|
|
|
|
*/
|
|
|
|
public static void disguiseToPlayer(Player disguiser, Player observer, Disguise disguise) {
|
|
|
|
disguises.put(disguiser.getName(), disguise);
|
|
|
|
Packet29DestroyEntity destroyPacket = new Packet29DestroyEntity(new int[] { disguiser.getEntityId() });
|
2013-05-19 05:44:13 +02:00
|
|
|
Packet spawnPacket = disguise.constructPacket(disguiser);
|
2013-05-17 23:05:19 +02:00
|
|
|
((CraftPlayer) observer).getHandle().playerConnection.sendPacket(destroyPacket);
|
|
|
|
((CraftPlayer) observer).getHandle().playerConnection.sendPacket(spawnPacket);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Disguiser
|
|
|
|
* @return Disguise
|
|
|
|
*/
|
|
|
|
public static Disguise getDisguise(Player p) {
|
|
|
|
return getDisguise(p.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Disguiser
|
|
|
|
* @return Disguise
|
|
|
|
*/
|
|
|
|
public static Disguise getDisguise(String name) {
|
|
|
|
return disguises.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Disguiser
|
|
|
|
* @return Boolean - If the disguiser is disguised
|
|
|
|
*/
|
|
|
|
public static boolean isDisguised(Player p) {
|
|
|
|
return isDisguised(p.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Disguiser
|
|
|
|
* @return boolean - If the disguiser is disguised
|
|
|
|
*/
|
|
|
|
public static boolean isDisguised(String name) {
|
|
|
|
return disguises.containsKey(name);
|
|
|
|
}
|
|
|
|
|
2013-05-21 02:59:57 +02:00
|
|
|
/**
|
|
|
|
* Does sounds play when the disguiser is hurt
|
|
|
|
*/
|
|
|
|
public static boolean playSounds() {
|
|
|
|
return playSounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-21 03:35:39 +02:00
|
|
|
* @param Boolean
|
|
|
|
* - Set if sounds play when the disguiser is hurt
|
2013-05-21 02:59:57 +02:00
|
|
|
*/
|
|
|
|
public static void setPlaySounds(boolean sounds) {
|
|
|
|
playSounds = sounds;
|
|
|
|
}
|
|
|
|
|
2013-05-17 23:05:19 +02:00
|
|
|
/**
|
|
|
|
* @param Disguiser
|
|
|
|
* - Undisguises him
|
|
|
|
*/
|
|
|
|
public static void undisguiseToAll(Player p) {
|
|
|
|
disguises.remove(p.getName());
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
if (p.getWorld() != player.getWorld())
|
|
|
|
continue;
|
|
|
|
player.hidePlayer(p);
|
|
|
|
player.showPlayer(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|