LibsDisguises/src/me/libraryaddict/disguise/DisguiseAPI.java

112 lines
3.1 KiB
Java
Raw Normal View History

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>();
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);
disguise.constructPacket(p);
2013-05-17 23:05:19 +02:00
for (Player player : Bukkit.getOnlinePlayers()) {
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() });
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);
}
/**
* Does sounds play when the disguiser is hurt
*/
public static boolean playSounds() {
return playSounds;
}
/**
* @param Boolean
* - Set if sounds play when the disguiser is hurt
*/
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);
}
}
}