Sorted all members

This commit is contained in:
Andrew 2013-05-29 10:52:54 +12:00
parent b29a3fae5e
commit ecb4f1e8ec
9 changed files with 78 additions and 73 deletions

@ -50,6 +50,7 @@ public class DisguiseCommand implements CommandExecutor {
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player p = (Player) sender;
if (args.length == 0) {

@ -51,6 +51,7 @@ public class DisguisePlayerCommand implements CommandExecutor {
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("libsdisguises.disguiseothers")
|| (args.length > 0 && args[0].toLowerCase().startsWith("un") && sender

@ -10,6 +10,7 @@ import org.bukkit.entity.Player;
public class UndisguiseCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player p = (Player) sender;
if (sender.hasPermission("libsdisguises.undisguise")) {

@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
public class UndisguisePlayerCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("libsdisguises.undisguiseothers")) {
if (args.length > 0) {

@ -33,8 +33,44 @@ public class DisguiseAPI {
private static ConcurrentHashMap<Object, Disguise> disguises = new ConcurrentHashMap<Object, Disguise>();
private static PacketListener packetListener;
private static boolean soundsEnabled;
private static JavaPlugin plugin;
private static boolean soundsEnabled;
/**
* @param Player
* - The player to disguise
* @param Disguise
* - The disguise to wear
*/
public static void disguiseToAll(Entity entity, Disguise disguise) {
disguises.put(entity instanceof Player ? ((Player) entity).getName() : entity.getUniqueId(), disguise);
refresh(entity);
}
public static void enableSounds(boolean isSoundsEnabled) {
if (soundsEnabled != isSoundsEnabled) {
soundsEnabled = isSoundsEnabled;
if (soundsEnabled) {
ProtocolLibrary.getProtocolManager().addPacketListener(packetListener);
} else {
ProtocolLibrary.getProtocolManager().removePacketListener(packetListener);
}
}
}
/**
* @param Disguiser
* @return Disguise
*/
public static Disguise getDisguise(Object disguiser) {
if (disguiser instanceof Entity) {
if (disguiser instanceof Player)
return disguises.get(((Player) disguiser).getName());
else
return disguises.get(((Entity) disguiser).getUniqueId());
}
return disguises.get(disguiser);
}
protected static void init(JavaPlugin mainPlugin) {
plugin = mainPlugin;
@ -97,14 +133,17 @@ public class DisguiseAPI {
}
/**
* @param Player
* - The player to disguise
* @param Disguise
* - The disguise to wear
* @param Disguiser
* @return boolean - If the disguiser is disguised
*/
public static void disguiseToAll(Entity entity, Disguise disguise) {
disguises.put(entity instanceof Player ? ((Player) entity).getName() : entity.getUniqueId(), disguise);
refresh(entity);
public static boolean isDisguised(Object disguiser) {
if (disguiser instanceof Entity) {
if (disguiser instanceof Player)
return disguises.containsKey(((Player) disguiser).getName());
else
return disguises.containsKey(((Entity) disguiser).getUniqueId());
}
return disguises.containsKey(disguiser);
}
private static void refresh(Entity entity) {
@ -128,34 +167,6 @@ public class DisguiseAPI {
}*/
}
/**
* @param Disguiser
* @return Disguise
*/
public static Disguise getDisguise(Object disguiser) {
if (disguiser instanceof Entity) {
if (disguiser instanceof Player)
return disguises.get(((Player) disguiser).getName());
else
return disguises.get(((Entity) disguiser).getUniqueId());
}
return disguises.get(disguiser);
}
/**
* @param Disguiser
* @return boolean - If the disguiser is disguised
*/
public static boolean isDisguised(Object disguiser) {
if (disguiser instanceof Entity) {
if (disguiser instanceof Player)
return disguises.containsKey(((Player) disguiser).getName());
else
return disguises.containsKey(((Entity) disguiser).getUniqueId());
}
return disguises.containsKey(disguiser);
}
/**
* @param Disguiser
* - Undisguises him
@ -164,15 +175,4 @@ public class DisguiseAPI {
disguises.remove(entity instanceof Player ? ((Player) entity).getName() : entity.getUniqueId());
refresh(entity);
}
public static void enableSounds(boolean isSoundsEnabled) {
if (soundsEnabled != isSoundsEnabled) {
soundsEnabled = isSoundsEnabled;
if (soundsEnabled) {
ProtocolLibrary.getProtocolManager().addPacketListener(packetListener);
} else {
ProtocolLibrary.getProtocolManager().removePacketListener(packetListener);
}
}
}
}

@ -37,6 +37,13 @@ public class Disguise {
disguiseType = newType;
}
public PacketContainer constructDestroyPacket(int entityId) {
PacketContainer destroyPacket = ProtocolLibrary.getProtocolManager().createPacket(Packets.Server.DESTROY_ENTITY);
StructureModifier<Object> mods = destroyPacket.getModifier();
mods.write(0, new int[] { entityId });
return destroyPacket;
}
public PacketContainer constructPacket(org.bukkit.entity.Entity e) {
PacketContainer spawnPacket = null;
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
@ -175,13 +182,6 @@ public class Disguise {
return spawnPacket;
}
public PacketContainer constructDestroyPacket(int entityId) {
PacketContainer destroyPacket = ProtocolLibrary.getProtocolManager().createPacket(Packets.Server.DESTROY_ENTITY);
StructureModifier<Object> mods = destroyPacket.getModifier();
mods.write(0, new int[] { entityId });
return destroyPacket;
}
public Entity getEntity(World world, Location loc, int entityId) {
if (entity != null) {
entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());

@ -72,10 +72,24 @@ public enum DisguiseSound {
ZOMBIE(Sound.ZOMBIE_HURT, Sound.STEP_GRASS, Sound.ZOMBIE_DEATH, Sound.ZOMBIE_IDLE, Sound.ZOMBIE_INFECT, Sound.ZOMBIE_METAL,
Sound.ZOMBIE_WOODBREAK, Sound.ZOMBIE_WOOD);
public enum SoundType {
HURT, STEP, IDLE, DEATH, CANCEL;
CANCEL, DEATH, HURT, IDLE, STEP;
}
public static String getSoundName(Sound sound) {
return CraftSound.getSound(sound);
}
public static DisguiseSound getType(String name) {
try {
if (name.equals("GIANT"))
return DisguiseSound.GIANT_ZOMBIE;
return valueOf(name);
} catch (Exception ex) {
return null;
}
}
private HashSet<Sound> cancelSounds = new HashSet<Sound>();
private HashMap<SoundType, Sound> disguiseSounds = new HashMap<SoundType, Sound>();
DisguiseSound(Sound... sounds) {
@ -94,10 +108,6 @@ public enum DisguiseSound {
}
}
public boolean isCancelled(String soundName) {
return cancelSounds.contains(soundName);
}
public Sound getSound(SoundType type) {
if (type == null)
return null;
@ -108,8 +118,8 @@ public enum DisguiseSound {
return cancelSounds;
}
public static String getSoundName(Sound sound) {
return CraftSound.getSound(sound);
public boolean isCancelled(String soundName) {
return cancelSounds.contains(soundName);
}
public boolean isCancelSound(String sound) {
@ -136,14 +146,4 @@ public enum DisguiseSound {
}
return null;
}
public static DisguiseSound getType(String name) {
try {
if (name.equals("GIANT"))
return DisguiseSound.GIANT_ZOMBIE;
return valueOf(name);
} catch (Exception ex) {
return null;
}
}
}

@ -9,13 +9,13 @@ public enum DisguiseType {
EntityType.MOB), ITEM(EntityType.MISC, 2, 1), ITEM_FRAME(EntityType.MISC, 71), LARGE_FIREBALL(EntityType.MISC, 63, 0), MAGMA_CUBE(
EntityType.MOB), MINECART_CHEST(EntityType.MISC, 10, 1), MINECART_FURNACE(EntityType.MISC, 10, 2), MINECART_HOPPER(
EntityType.MISC, 10), MINECART_MOB_SPAWNER(EntityType.MISC, 10, 4), MINECART_RIDEABLE(EntityType.MISC, 10, 0), MINECART_TNT(
EntityType.MISC, 10, 3), MUSHROOM_COW(EntityType.MOB), OCELOT(EntityType.MOB), PIG(EntityType.MOB), PIG_ZOMBIE(
EntityType.MISC, 10, 3), MUSHROOM_COW(EntityType.MOB), OCELOT(EntityType.MOB), PAINTING(EntityType.MISC), PIG(EntityType.MOB), PIG_ZOMBIE(
EntityType.MOB), PLAYER(EntityType.PLAYER), POTION(EntityType.MISC, 73), PRIMED_TNT(EntityType.MISC, 50), SHEEP(
EntityType.MOB), SILVERFISH(EntityType.MOB), SKELETON(EntityType.MOB), SLIME(EntityType.MOB), SMALL_FIREBALL(
EntityType.MISC, 64, 0), SNOWBALL(EntityType.MISC, 61), SNOWMAN(EntityType.MOB), SPIDER(EntityType.MOB), SQUID(
EntityType.MOB), THROWN_EXP_BOTTLE(EntityType.MISC, 75), VILLAGER(EntityType.MOB), WITCH(EntityType.MOB), WITHER(
EntityType.MOB), WITHER_SKELETON(EntityType.MOB), WITHER_SKULL(EntityType.MISC, 66), WOLF(EntityType.MOB), ZOMBIE(
EntityType.MOB), PAINTING(EntityType.MISC);
EntityType.MOB);
public static enum EntityType {
MISC, MOB, PLAYER;

@ -28,6 +28,7 @@ import com.comphenix.protocol.reflect.StructureModifier;
public class LibsDisguises extends JavaPlugin {
@Override
public void onEnable() {
DisguiseAPI.init(this);
DisguiseAPI.enableSounds(true);