2013-05-17 23:05:19 +02:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
2013-07-30 02:44:00 +02:00
|
|
|
import java.lang.reflect.Field;
|
2013-09-25 16:49:24 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
2013-12-01 13:32:38 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.TargettedDisguise;
|
2013-09-25 16:49:24 +02:00
|
|
|
import me.libraryaddict.disguise.events.DisguiseEvent;
|
|
|
|
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
2013-11-22 21:10:20 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
|
|
import me.libraryaddict.disguise.utilities.PacketsManager;
|
|
|
|
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
2013-05-29 00:29:36 +02:00
|
|
|
|
2013-07-24 02:16:54 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2013-05-29 00:29:36 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
2013-12-01 14:36:42 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2013-05-17 23:05:19 +02:00
|
|
|
|
|
|
|
public class DisguiseAPI {
|
2013-08-01 09:56:27 +02:00
|
|
|
private static boolean hearSelfDisguise;
|
2013-09-29 02:32:26 +02:00
|
|
|
private static boolean hidingArmor;
|
|
|
|
private static boolean hidingHeldItem;
|
2013-11-23 22:05:08 +01:00
|
|
|
private static boolean isEntityAnimationsAdded;
|
2013-07-21 05:17:21 +02:00
|
|
|
private static boolean sendVelocity;
|
2013-11-23 22:05:08 +01:00
|
|
|
|
2013-11-22 20:52:15 +01:00
|
|
|
@Deprecated
|
2013-08-01 09:56:27 +02:00
|
|
|
public static boolean canHearSelfDisguise() {
|
|
|
|
return hearSelfDisguise;
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
|
|
|
|
*/
|
2013-08-08 23:14:44 +02:00
|
|
|
public static void disguiseNextEntity(Disguise disguise) {
|
|
|
|
if (disguise == null)
|
|
|
|
return;
|
2013-11-22 20:52:15 +01:00
|
|
|
if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) {
|
2013-08-13 11:44:54 +02:00
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
2013-08-08 23:14:44 +02:00
|
|
|
try {
|
2013-11-18 12:49:04 +01:00
|
|
|
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
|
2013-08-08 23:14:44 +02:00
|
|
|
field.setAccessible(true);
|
|
|
|
int id = field.getInt(null);
|
2013-12-01 13:32:38 +01:00
|
|
|
DisguiseUtilities.addDisguise(id, (TargettedDisguise) disguise);
|
2013-08-08 23:14:44 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-29 00:52:54 +02:00
|
|
|
/**
|
2013-08-13 11:44:54 +02:00
|
|
|
* Disguise this entity with this disguise
|
2013-05-29 00:52:54 +02:00
|
|
|
*/
|
|
|
|
public static void disguiseToAll(Entity entity, Disguise disguise) {
|
2013-12-01 14:36:42 +01:00
|
|
|
// TODO Make everyone see this disguise. Remove any old disguises.
|
2013-08-13 05:19:50 +02:00
|
|
|
// If they are trying to disguise a null entity or use a null disguise
|
|
|
|
// Just return.
|
2013-08-08 19:56:13 +02:00
|
|
|
if (entity == null || disguise == null)
|
2013-06-01 08:35:31 +02:00
|
|
|
return;
|
2013-08-13 05:19:50 +02:00
|
|
|
// Fire a disguise event
|
2013-08-11 20:32:51 +02:00
|
|
|
DisguiseEvent event = new DisguiseEvent(entity, disguise);
|
2013-07-31 09:39:16 +02:00
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
2013-08-13 05:19:50 +02:00
|
|
|
// If they cancelled this disguise event. No idea why.
|
|
|
|
// Just return.
|
|
|
|
if (event.isCancelled())
|
2013-07-31 09:39:16 +02:00
|
|
|
return;
|
2013-08-13 11:44:54 +02:00
|
|
|
// The event wasn't cancelled.
|
2013-08-13 05:19:50 +02:00
|
|
|
// If the disguise entity isn't the same as the one we are disguising
|
2013-07-28 00:58:21 +02:00
|
|
|
if (disguise.getEntity() != entity) {
|
2013-08-13 05:19:50 +02:00
|
|
|
// If the disguise entity actually exists
|
2013-08-07 12:51:42 +02:00
|
|
|
if (disguise.getEntity() != null) {
|
2013-08-13 05:19:50 +02:00
|
|
|
// Clone the disguise
|
2013-07-28 00:58:21 +02:00
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
2013-08-13 05:19:50 +02:00
|
|
|
// Set the disguise's entity
|
2013-08-07 12:51:42 +02:00
|
|
|
disguise.setEntity(entity);
|
2013-08-13 11:44:54 +02:00
|
|
|
} // If there was a old disguise
|
|
|
|
Disguise oldDisguise = getDisguise(entity);
|
2013-08-13 05:19:50 +02:00
|
|
|
// Stick the disguise in the disguises bin
|
2013-12-01 13:32:38 +01:00
|
|
|
DisguiseUtilities.addDisguise(entity.getEntityId(), (TargettedDisguise) disguise);
|
2013-08-13 05:19:50 +02:00
|
|
|
// Resend the disguised entity's packet
|
2013-11-22 20:52:15 +01:00
|
|
|
DisguiseUtilities.refreshTrackers(entity);
|
2013-08-13 05:19:50 +02:00
|
|
|
// If he is a player, then self disguise himself
|
2013-11-22 20:52:15 +01:00
|
|
|
DisguiseUtilities.setupFakeDisguise(disguise);
|
2013-08-13 11:44:54 +02:00
|
|
|
// Discard the disguise
|
|
|
|
if (oldDisguise != null)
|
2013-08-13 11:57:21 +02:00
|
|
|
oldDisguise.removeDisguise();
|
2013-05-29 00:52:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-13 05:19:50 +02:00
|
|
|
* Get the disguise of a entity
|
2013-05-29 00:52:54 +02:00
|
|
|
*/
|
2013-12-01 14:36:42 +01:00
|
|
|
@Deprecated
|
2013-11-22 20:52:15 +01:00
|
|
|
public static Disguise getDisguise(Entity disguised) {
|
|
|
|
if (disguised == null)
|
2013-08-08 19:56:13 +02:00
|
|
|
return null;
|
2013-12-01 13:32:38 +01:00
|
|
|
return DisguiseUtilities.getDisguise(disguised.getEntityId());
|
2013-05-29 00:52:54 +02:00
|
|
|
}
|
2013-05-29 00:29:36 +02:00
|
|
|
|
2013-12-01 14:36:42 +01:00
|
|
|
/**
|
|
|
|
* Get the disguise of a entity
|
|
|
|
*/
|
|
|
|
public static Disguise getDisguise(Player observer, Entity disguised) {
|
|
|
|
if (disguised == null)
|
|
|
|
return null;
|
|
|
|
return DisguiseUtilities.getDisguise(observer, disguised.getEntityId());
|
|
|
|
}
|
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
/**
|
|
|
|
* Get the ID of a fake disguise for a entityplayer
|
|
|
|
*/
|
2013-11-22 20:52:15 +01:00
|
|
|
public static int getFakeDisguise(int entityId) {
|
|
|
|
if (DisguiseUtilities.getSelfDisguisesIds().containsKey(entityId))
|
|
|
|
return DisguiseUtilities.getSelfDisguisesIds().get(entityId);
|
2013-07-30 02:44:00 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-17 23:05:19 +02:00
|
|
|
/**
|
2013-08-13 11:44:54 +02:00
|
|
|
* Is this entity disguised
|
2013-05-17 23:05:19 +02:00
|
|
|
*/
|
2013-12-01 14:36:42 +01:00
|
|
|
@Deprecated
|
2013-11-22 20:52:15 +01:00
|
|
|
public static boolean isDisguised(Entity disguised) {
|
|
|
|
return getDisguise(disguised) != null;
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|
|
|
|
|
2013-12-01 14:36:42 +01:00
|
|
|
public static boolean isDisguiseInUse(Disguise disguise) {
|
|
|
|
return DisguiseUtilities.isDisguiseInUse(disguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this entity disguised
|
|
|
|
*/
|
|
|
|
public static boolean isDisguised(Player observer, Entity disguised) {
|
|
|
|
return getDisguise(observer, disguised) != null;
|
|
|
|
}
|
|
|
|
|
2013-11-23 22:05:08 +01:00
|
|
|
public static boolean isEntityAnimationsAdded() {
|
|
|
|
return isEntityAnimationsAdded;
|
|
|
|
}
|
|
|
|
|
2013-09-29 02:32:26 +02:00
|
|
|
/**
|
|
|
|
* Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around
|
|
|
|
*/
|
|
|
|
public static boolean isHidingArmorFromSelf() {
|
|
|
|
return hidingArmor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
|
|
|
|
*/
|
|
|
|
public static boolean isHidingHeldItemFromSelf() {
|
|
|
|
return hidingHeldItem;
|
|
|
|
}
|
|
|
|
|
2013-10-18 03:11:35 +02:00
|
|
|
public static boolean isInventoryListenerEnabled() {
|
|
|
|
return PacketsManager.isInventoryListenerEnabled();
|
|
|
|
}
|
|
|
|
|
2013-11-22 20:52:15 +01:00
|
|
|
public static boolean isSelfDisguisesSoundsReplaced() {
|
|
|
|
return hearSelfDisguise;
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Is the sound packets caught and modified
|
|
|
|
*/
|
2013-08-11 21:24:52 +02:00
|
|
|
public static boolean isSoundEnabled() {
|
2013-08-13 05:19:50 +02:00
|
|
|
return PacketsManager.isHearDisguisesEnabled();
|
2013-08-11 21:24:52 +02:00
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Is the velocity packets sent
|
|
|
|
*/
|
2013-07-21 05:17:21 +02:00
|
|
|
public static boolean isVelocitySent() {
|
|
|
|
return sendVelocity;
|
|
|
|
}
|
|
|
|
|
2013-08-13 05:19:50 +02:00
|
|
|
/**
|
|
|
|
* The default value if a player views his own disguise
|
|
|
|
*/
|
|
|
|
public static boolean isViewDisguises() {
|
|
|
|
return PacketsManager.isViewDisguisesListenerEnabled();
|
|
|
|
}
|
|
|
|
|
2013-11-23 22:05:08 +01:00
|
|
|
public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
|
|
|
|
DisguiseAPI.isEntityAnimationsAdded = isEntityAnimationsAdded;
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Can players hear their own disguises
|
|
|
|
*/
|
2013-08-01 09:56:27 +02:00
|
|
|
public static void setHearSelfDisguise(boolean replaceSound) {
|
|
|
|
if (hearSelfDisguise != replaceSound) {
|
|
|
|
hearSelfDisguise = replaceSound;
|
2013-07-31 07:12:39 +02:00
|
|
|
}
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2013-09-29 02:32:26 +02:00
|
|
|
/**
|
|
|
|
* Set the plugin to hide self disguises armor from theirselves
|
|
|
|
*/
|
|
|
|
public static void setHideArmorFromSelf(boolean hideArmor) {
|
|
|
|
if (hidingArmor != hideArmor) {
|
|
|
|
hidingArmor = hideArmor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
|
|
|
|
*/
|
|
|
|
public static void setHideHeldItemFromSelf(boolean hideHelditem) {
|
|
|
|
if (hidingHeldItem != hideHelditem) {
|
|
|
|
hidingHeldItem = hideHelditem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 03:11:35 +02:00
|
|
|
public static void setInventoryListenerEnabled(boolean inventoryListenerEnabled) {
|
|
|
|
if (PacketsManager.isInventoryListenerEnabled() != inventoryListenerEnabled) {
|
|
|
|
PacketsManager.setInventoryListenerEnabled(inventoryListenerEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 11:44:54 +02:00
|
|
|
/**
|
|
|
|
* Set if the disguises play sounds when hurt
|
|
|
|
*/
|
2013-08-13 05:19:50 +02:00
|
|
|
public static void setSoundsEnabled(boolean isSoundsEnabled) {
|
|
|
|
PacketsManager.setHearDisguisesListener(isSoundsEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get?
|
|
|
|
*/
|
2013-07-21 05:17:21 +02:00
|
|
|
public static void setVelocitySent(boolean sendVelocityPackets) {
|
|
|
|
sendVelocity = sendVelocityPackets;
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:44:00 +02:00
|
|
|
public static void setViewDisguises(boolean seeOwnDisguise) {
|
2013-08-13 05:19:50 +02:00
|
|
|
PacketsManager.setViewDisguisesListener(seeOwnDisguise);
|
2013-07-30 02:44:00 +02:00
|
|
|
}
|
|
|
|
|
2013-05-17 23:05:19 +02:00
|
|
|
/**
|
2013-08-13 11:44:54 +02:00
|
|
|
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka removed from
|
|
|
|
* the world.
|
2013-05-17 23:05:19 +02:00
|
|
|
*/
|
2013-05-29 00:29:36 +02:00
|
|
|
public static void undisguiseToAll(Entity entity) {
|
2013-12-01 14:36:42 +01:00
|
|
|
// TODO Make all of these disguises be removed
|
2013-07-21 05:17:21 +02:00
|
|
|
Disguise disguise = getDisguise(entity);
|
|
|
|
if (disguise == null)
|
|
|
|
return;
|
2013-08-11 21:25:48 +02:00
|
|
|
UndisguiseEvent event = new UndisguiseEvent(entity, disguise);
|
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
2013-08-13 11:44:54 +02:00
|
|
|
if (event.isCancelled())
|
2013-08-11 21:25:48 +02:00
|
|
|
return;
|
2013-08-13 11:57:21 +02:00
|
|
|
disguise.removeDisguise();
|
2013-08-13 11:44:54 +02:00
|
|
|
}
|
|
|
|
|
2013-11-22 20:52:15 +01:00
|
|
|
private DisguiseAPI() {
|
2013-08-14 22:57:30 +02:00
|
|
|
}
|
2013-05-17 23:05:19 +02:00
|
|
|
}
|