Added new disguises, added new disguisetypes, fixed the

horse/lama/whatever changes, fixed a boat 'facing' bug, renamed a few
internal methods, still dont know why some disguises are invisible.
This commit is contained in:
libraryaddict 2016-11-26 01:07:02 +13:00
parent 58b7086cd2
commit bb303ac96b
63 changed files with 1785 additions and 2485 deletions

View File

@ -37,17 +37,17 @@
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<version>4.1.0-SNAPSHOT</version> <version>4.2.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.10-R0.1-SNAPSHOT</version> <version>1.11-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.10-R0.1-SNAPSHOT</version> <version>1.11-R0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -27,158 +27,126 @@ import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseAbstractWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class DisguiseAPI public class DisguiseAPI {
{ public static Disguise constructDisguise(Entity entity) {
public static Disguise constructDisguise(Entity entity)
{
return constructDisguise(entity, true, true, true); return constructDisguise(entity, true, true, true);
} }
public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint) public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint) {
{
DisguiseType disguiseType = DisguiseType.getType(entity); DisguiseType disguiseType = DisguiseType.getType(entity);
Disguise disguise; Disguise disguise;
if (disguiseType.isMisc()) if (disguiseType.isMisc()) {
{
disguise = new MiscDisguise(disguiseType); disguise = new MiscDisguise(disguiseType);
} }
else if (disguiseType.isMob()) else if (disguiseType.isMob()) {
{
disguise = new MobDisguise(disguiseType); disguise = new MobDisguise(disguiseType);
} }
else else {
{
disguise = new PlayerDisguise(entity.getName()); disguise = new PlayerDisguise(entity.getName());
} }
FlagWatcher watcher = disguise.getWatcher(); FlagWatcher watcher = disguise.getWatcher();
if (entity instanceof LivingEntity) if (entity instanceof LivingEntity) {
{ for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects()) {
for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects())
{
((LivingWatcher) watcher).addPotionEffect(effect.getType()); ((LivingWatcher) watcher).addPotionEffect(effect.getType());
if (effect.getType() == PotionEffectType.INVISIBILITY) if (effect.getType() == PotionEffectType.INVISIBILITY) {
{
watcher.setInvisible(true); watcher.setInvisible(true);
} }
else if (effect.getType() == PotionEffectType.GLOWING) else if (effect.getType() == PotionEffectType.GLOWING) {
{
watcher.setGlowing(true); watcher.setGlowing(true);
} }
} }
} }
if (entity.getFireTicks() > 0) if (entity.getFireTicks() > 0) {
{
watcher.setBurning(true); watcher.setBurning(true);
} }
if (doEquipment && entity instanceof LivingEntity) if (doEquipment && entity instanceof LivingEntity) {
{
EntityEquipment equip = ((LivingEntity) entity).getEquipment(); EntityEquipment equip = ((LivingEntity) entity).getEquipment();
watcher.setArmor(equip.getArmorContents()); watcher.setArmor(equip.getArmorContents());
watcher.setItemInMainHand(equip.getItemInMainHand()); watcher.setItemInMainHand(equip.getItemInMainHand());
if (disguiseType.getEntityType() == EntityType.HORSE) if (disguiseType.getEntityType() == EntityType.HORSE) {
{
Horse horse = (Horse) entity; Horse horse = (Horse) entity;
HorseInventory horseInventory = horse.getInventory(); HorseInventory horseInventory = horse.getInventory();
ItemStack saddle = horseInventory.getSaddle(); ItemStack saddle = horseInventory.getSaddle();
if (saddle != null && saddle.getType() == Material.SADDLE) if (saddle != null && saddle.getType() == Material.SADDLE) {
{ ((HorseAbstractWatcher) watcher).setSaddled(true);
((HorseWatcher) watcher).setSaddled(true);
} }
if (watcher instanceof HorseWatcher)
((HorseWatcher) watcher).setHorseArmor(horseInventory.getArmor()); ((HorseWatcher) watcher).setHorseArmor(horseInventory.getArmor());
} }
} }
for (Method method : entity.getClass().getMethods()) for (Method method : entity.getClass().getMethods()) {
{
if ((doSneak || !method.getName().equals("setSneaking")) && (doSprint || !method.getName().equals("setSprinting")) if ((doSneak || !method.getName().equals("setSneaking")) && (doSprint || !method.getName().equals("setSprinting"))
&& method.getParameterTypes().length == 0 && method.getReturnType() != void.class) && method.getParameterTypes().length == 0 && method.getReturnType() != void.class) {
{
Class methodReturn = method.getReturnType(); Class methodReturn = method.getReturnType();
if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class) if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class) {
{
methodReturn = double.class; methodReturn = double.class;
} }
int firstCapitalMethod = firstCapital(method.getName()); int firstCapitalMethod = firstCapital(method.getName());
if (firstCapitalMethod > 0) if (firstCapitalMethod > 0) {
{ for (Method watcherMethod : watcher.getClass().getMethods()) {
for (Method watcherMethod : watcher.getClass().getMethods())
{
if (!watcherMethod.getName().startsWith("get") && watcherMethod.getReturnType() == void.class if (!watcherMethod.getName().startsWith("get") && watcherMethod.getReturnType() == void.class
&& watcherMethod.getParameterTypes().length == 1) && watcherMethod.getParameterTypes().length == 1) {
{
int firstCapitalWatcher = firstCapital(watcherMethod.getName()); int firstCapitalWatcher = firstCapital(watcherMethod.getName());
if (firstCapitalWatcher > 0 && method.getName().substring(firstCapitalMethod) if (firstCapitalWatcher > 0 && method.getName().substring(firstCapitalMethod)
.equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher))) .equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher))) {
{
Class methodParam = watcherMethod.getParameterTypes()[0]; Class methodParam = watcherMethod.getParameterTypes()[0];
if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class) if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class) {
{
methodParam = double.class; methodParam = double.class;
} }
else if (methodParam == AnimalColor.class) else if (methodParam == AnimalColor.class) {
{
methodParam = DyeColor.class; methodParam = DyeColor.class;
} }
if (methodReturn == methodParam) if (methodReturn == methodParam) {
{ try {
try
{
Object value = method.invoke(entity); Object value = method.invoke(entity);
if (value != null) if (value != null) {
{
Class toCast = watcherMethod.getParameterTypes()[0]; Class toCast = watcherMethod.getParameterTypes()[0];
if (!(toCast.isInstance(value))) if (!(toCast.isInstance(value))) {
{ if (toCast == float.class) {
if (toCast == float.class) if (!(value instanceof Float)) {
{
if (!(value instanceof Float))
{
double d = (Double) value; double d = (Double) value;
value = (float) d; value = (float) d;
} }
} }
else if (toCast == double.class) else if (toCast == double.class) {
{ if (!(value instanceof Double)) {
if (!(value instanceof Double))
{
float d = (Float) value; float d = (Float) value;
value = (double) d; value = (double) d;
} }
} }
else if (toCast == AnimalColor.class) else if (toCast == AnimalColor.class) {
{
value = AnimalColor.valueOf(((DyeColor) value).name()); value = AnimalColor.valueOf(((DyeColor) value).name());
} }
} }
if (value instanceof Boolean && !(Boolean) value if (value instanceof Boolean && !(Boolean) value
&& watcherMethod.getDeclaringClass() == FlagWatcher.class) && watcherMethod.getDeclaringClass() == FlagWatcher.class) {
{
continue; continue;
} }
} }
watcherMethod.invoke(watcher, value); watcherMethod.invoke(watcher, value);
} }
catch (Exception ex) catch (Exception ex) {
{
ex.printStackTrace(); ex.printStackTrace();
} }
} }
@ -191,21 +159,17 @@ public class DisguiseAPI
return disguise; return disguise;
} }
public static void disguiseEntity(Entity entity, Disguise disguise) public static void disguiseEntity(Entity entity, Disguise disguise) {
{
// If they are trying to disguise a null entity or use a null disguise // If they are trying to disguise a null entity or use a null disguise
// Just return. // Just return.
if (entity == null || disguise == null) if (entity == null || disguise == null) {
{
return; return;
} }
// The event wasn't cancelled. // The event wasn't cancelled.
// If the disguise entity isn't the same as the one we are disguising // If the disguise entity isn't the same as the one we are disguising
if (disguise.getEntity() != entity) if (disguise.getEntity() != entity) {
{
// If the disguise entity actually exists // If the disguise entity actually exists
if (disguise.getEntity() != null) if (disguise.getEntity() != null) {
{
// Clone the disguise // Clone the disguise
disguise = disguise.clone(); disguise = disguise.clone();
} }
@ -213,31 +177,25 @@ public class DisguiseAPI
disguise.setEntity(entity); disguise.setEntity(entity);
} }
if (Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId())) if (Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId())) {
{
disguise.setViewSelfDisguise(true); disguise.setViewSelfDisguise(true);
} }
disguise.startDisguise(); disguise.startDisguise();
} }
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) {
{ if (disguise.getEntity() != null) {
if (disguise.getEntity() != null)
{
disguise = disguise.clone(); disguise = disguise.clone();
} }
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS); ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
for (Object obj : playersToNotSeeDisguise) for (Object obj : playersToNotSeeDisguise) {
{ if (obj instanceof String) {
if (obj instanceof String)
{
((TargetedDisguise) disguise).addPlayer((String) obj); ((TargetedDisguise) disguise).addPlayer((String) obj);
} }
else if (obj instanceof Player) else if (obj instanceof Player) {
{
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName()); ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
} }
} }
@ -246,18 +204,15 @@ public class DisguiseAPI
} }
@Deprecated @Deprecated
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> playersToNotSeeDisguise) public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> playersToNotSeeDisguise) {
{
disguiseIgnorePlayers(entity, disguise, (Collection) playersToNotSeeDisguise); disguiseIgnorePlayers(entity, disguise, (Collection) playersToNotSeeDisguise);
} }
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Player... playersToNotSeeDisguise) public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Player... playersToNotSeeDisguise) {
{
disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise)); disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise));
} }
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise) public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise) {
{
disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise)); disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise));
} }
@ -267,27 +222,22 @@ public class DisguiseAPI
* @param disguise * @param disguise
* @return * @return
*/ */
public static int disguiseNextEntity(Disguise disguise) public static int disguiseNextEntity(Disguise disguise) {
{ if (disguise == null) {
if (disguise == null)
{
return -1; return -1;
} }
if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) {
{
disguise = disguise.clone(); disguise = disguise.clone();
} }
try try {
{
int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null); int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null);
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise); DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
return id; return id;
} }
catch (IllegalAccessException e) catch (IllegalAccessException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
@ -300,40 +250,32 @@ public class DisguiseAPI
* @param entity * @param entity
* @param disguise * @param disguise
*/ */
public static void disguiseToAll(Entity entity, Disguise disguise) public static void disguiseToAll(Entity entity, Disguise disguise) {
{ if (disguise.getEntity() != null) {
if (disguise.getEntity() != null)
{
disguise = disguise.clone(); disguise = disguise.clone();
} }
// You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!! // You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS); ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
for (String observer : ((TargetedDisguise) disguise).getObservers()) for (String observer : ((TargetedDisguise) disguise).getObservers()) {
{
((TargetedDisguise) disguise).removePlayer(observer); ((TargetedDisguise) disguise).removePlayer(observer);
} }
disguiseEntity(entity, disguise); disguiseEntity(entity, disguise);
} }
public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise) public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise) {
{ if (disguise.getEntity() != null) {
if (disguise.getEntity() != null)
{
disguise = disguise.clone(); disguise = disguise.clone();
} }
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS); ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
for (Object obj : playersToViewDisguise) for (Object obj : playersToViewDisguise) {
{ if (obj instanceof String) {
if (obj instanceof String)
{
((TargetedDisguise) disguise).addPlayer((String) obj); ((TargetedDisguise) disguise).addPlayer((String) obj);
} }
else if (obj instanceof Player) else if (obj instanceof Player) {
{
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName()); ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
} }
} }
@ -342,27 +284,21 @@ public class DisguiseAPI
} }
@Deprecated @Deprecated
public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> playersToViewDisguise) public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> playersToViewDisguise) {
{
disguiseToPlayers(entity, disguise, (Collection) playersToViewDisguise); disguiseToPlayers(entity, disguise, (Collection) playersToViewDisguise);
} }
public static void disguiseToPlayers(Entity entity, Disguise disguise, Player... playersToViewDisguise) public static void disguiseToPlayers(Entity entity, Disguise disguise, Player... playersToViewDisguise) {
{
disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise)); disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise));
} }
public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise) public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise) {
{
disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise)); disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise));
} }
private static int firstCapital(String str) private static int firstCapital(String str) {
{ for (int i = 0; i < str.length(); i++) {
for (int i = 0; i < str.length(); i++) if (Character.isUpperCase(str.charAt(i))) {
{
if (Character.isUpperCase(str.charAt(i)))
{
return i; return i;
} }
} }
@ -376,10 +312,8 @@ public class DisguiseAPI
* @param disguised * @param disguised
* @return * @return
*/ */
public static Disguise getDisguise(Entity disguised) public static Disguise getDisguise(Entity disguised) {
{ if (disguised == null) {
if (disguised == null)
{
return null; return null;
} }
@ -393,10 +327,8 @@ public class DisguiseAPI
* @param disguised * @param disguised
* @return * @return
*/ */
public static Disguise getDisguise(Player observer, Entity disguised) public static Disguise getDisguise(Player observer, Entity disguised) {
{ if (disguised == null || observer == null) {
if (disguised == null || observer == null)
{
return null; return null;
} }
@ -409,18 +341,15 @@ public class DisguiseAPI
* @param disguised * @param disguised
* @return * @return
*/ */
public static Disguise[] getDisguises(Entity disguised) public static Disguise[] getDisguises(Entity disguised) {
{ if (disguised == null) {
if (disguised == null)
{
return null; return null;
} }
return DisguiseUtilities.getDisguises(disguised.getUniqueId()); return DisguiseUtilities.getDisguises(disguised.getUniqueId());
} }
public static int getSelfDisguiseId() public static int getSelfDisguiseId() {
{
return -10; return -10;
} }
@ -430,8 +359,7 @@ public class DisguiseAPI
* @param disguised * @param disguised
* @return * @return
*/ */
public static boolean isDisguised(Entity disguised) public static boolean isDisguised(Entity disguised) {
{
return getDisguise(disguised) != null; return getDisguise(disguised) != null;
} }
@ -442,18 +370,15 @@ public class DisguiseAPI
* @param disguised * @param disguised
* @return * @return
*/ */
public static boolean isDisguised(Player observer, Entity disguised) public static boolean isDisguised(Player observer, Entity disguised) {
{
return getDisguise(observer, disguised) != null; return getDisguise(observer, disguised) != null;
} }
public static boolean isDisguiseInUse(Disguise disguise) public static boolean isDisguiseInUse(Disguise disguise) {
{
return disguise.isDisguiseInUse(); return disguise.isDisguiseInUse();
} }
public static boolean isSelfDisguised(Player player) public static boolean isSelfDisguised(Player player) {
{
return DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId()); return DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId());
} }
@ -463,8 +388,7 @@ public class DisguiseAPI
* @param entity * @param entity
* @return * @return
*/ */
public static boolean isViewSelfToggled(Entity entity) public static boolean isViewSelfToggled(Entity entity) {
{
return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible() return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible()
: Disguise.getViewSelf().contains(entity.getUniqueId()); : Disguise.getViewSelf().contains(entity.getUniqueId());
} }
@ -475,12 +399,10 @@ public class DisguiseAPI
* *
* @param entity * @param entity
*/ */
public static void undisguiseToAll(Entity entity) public static void undisguiseToAll(Entity entity) {
{
Disguise[] disguises = getDisguises(entity); Disguise[] disguises = getDisguises(entity);
for (Disguise disguise : disguises) for (Disguise disguise : disguises) {
{
disguise.removeDisguise(); disguise.removeDisguise();
} }
} }
@ -491,28 +413,22 @@ public class DisguiseAPI
* @param entity * @param entity
* @param toggled * @param toggled
*/ */
public static void setViewDisguiseToggled(Entity entity, boolean toggled) public static void setViewDisguiseToggled(Entity entity, boolean toggled) {
{ if (isDisguised(entity)) {
if (isDisguised(entity))
{
Disguise disguise = getDisguise(entity); Disguise disguise = getDisguise(entity);
disguise.setViewSelfDisguise(toggled); disguise.setViewSelfDisguise(toggled);
} }
if (toggled) if (toggled) {
{ if (!Disguise.getViewSelf().contains(entity.getUniqueId())) {
if (!Disguise.getViewSelf().contains(entity.getUniqueId()))
{
Disguise.getViewSelf().add(entity.getUniqueId()); Disguise.getViewSelf().add(entity.getUniqueId());
} }
} }
else else {
{
Disguise.getViewSelf().remove(entity.getUniqueId()); Disguise.getViewSelf().remove(entity.getUniqueId());
} }
} }
private DisguiseAPI() private DisguiseAPI() {
{
} }
} }

View File

@ -36,7 +36,6 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
@ -54,32 +53,26 @@ import me.libraryaddict.disguise.utilities.Metrics;
import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class LibsDisguises extends JavaPlugin public class LibsDisguises extends JavaPlugin {
{
private static LibsDisguises instance; private static LibsDisguises instance;
private DisguiseListener listener; private DisguiseListener listener;
@Override @Override
public void onEnable() public void onEnable() {
{ try {
try
{
Class.forName("com.comphenix.protocol.wrappers.Vector3F").getName(); Class.forName("com.comphenix.protocol.wrappers.Vector3F").getName();
} }
catch (Exception ex) catch (Exception ex) {
{
System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated ProtocolLib!"); System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated ProtocolLib!");
System.err.println( System.err.println(
"[LibsDisguises] You need to update ProtocolLib, please try this build http://ci.dmulloy2.net/job/ProtocolLib/lastStableBuild/artifact/modules/ProtocolLib/target/ProtocolLib.jar"); "[LibsDisguises] You need to update ProtocolLib, please try this build http://ci.dmulloy2.net/job/ProtocolLib/lastStableBuild/artifact/modules/ProtocolLib/target/ProtocolLib.jar");
return; return;
} }
try try {
{
ReflectionManager.getNmsClass("EntityShulker").getName(); ReflectionManager.getNmsClass("EntityShulker").getName();
} }
catch (Exception ex) catch (Exception ex) {
{
System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated server!"); System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated server!");
System.err.println("[LibsDisguises] This plugin does not offer backwards support!"); System.err.println("[LibsDisguises] This plugin does not offer backwards support!");
return; return;
@ -117,21 +110,18 @@ public class LibsDisguises extends JavaPlugin
instance = this; instance = this;
try try {
{
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
metrics.start(); metrics.start();
} }
catch (IOException e) catch (IOException e) {
{
} }
} }
/** /**
* Reloads the config with new config options. * Reloads the config with new config options.
*/ */
public void reload() public void reload() {
{
HandlerList.unregisterAll(listener); HandlerList.unregisterAll(listener);
reloadConfig(); reloadConfig();
@ -142,21 +132,16 @@ public class LibsDisguises extends JavaPlugin
* Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume * Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume
* for mob noises. As well as setting their watcher class and entity size. * for mob noises. As well as setting their watcher class and entity size.
*/ */
private void registerValues() private void registerValues() {
{ for (DisguiseType disguiseType : DisguiseType.values()) {
for (DisguiseType disguiseType : DisguiseType.values()) if (disguiseType.getEntityType() == null) {
{
if (disguiseType.getEntityType() == null)
{
continue; continue;
} }
Class watcherClass = null; Class watcherClass = null;
try try {
{ switch (disguiseType) {
switch (disguiseType)
{
case SPECTRAL_ARROW: case SPECTRAL_ARROW:
watcherClass = ArrowWatcher.class; watcherClass = ArrowWatcher.class;
break; break;
@ -175,12 +160,6 @@ public class LibsDisguises extends JavaPlugin
case CAVE_SPIDER: case CAVE_SPIDER:
watcherClass = SpiderWatcher.class; watcherClass = SpiderWatcher.class;
break; break;
case DONKEY:
case MULE:
case UNDEAD_HORSE:
case SKELETON_HORSE:
watcherClass = HorseWatcher.class;
break;
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
case PIG_ZOMBIE: case PIG_ZOMBIE:
case HUSK: case HUSK:
@ -202,57 +181,46 @@ public class LibsDisguises extends JavaPlugin
break; break;
} }
} }
catch (ClassNotFoundException ex) catch (ClassNotFoundException ex) {
{
// There is no explicit watcher for this entity. // There is no explicit watcher for this entity.
Class entityClass = disguiseType.getEntityType().getEntityClass(); Class entityClass = disguiseType.getEntityType().getEntityClass();
if (entityClass != null) if (entityClass != null) {
{ if (Tameable.class.isAssignableFrom(entityClass)) {
if (Tameable.class.isAssignableFrom(entityClass))
{
watcherClass = TameableWatcher.class; watcherClass = TameableWatcher.class;
} }
else if (Ageable.class.isAssignableFrom(entityClass)) else if (Ageable.class.isAssignableFrom(entityClass)) {
{
watcherClass = AgeableWatcher.class; watcherClass = AgeableWatcher.class;
} }
else if (Creature.class.isAssignableFrom(entityClass)) else if (Creature.class.isAssignableFrom(entityClass)) {
{
watcherClass = InsentientWatcher.class; watcherClass = InsentientWatcher.class;
} }
else if (LivingEntity.class.isAssignableFrom(entityClass)) else if (LivingEntity.class.isAssignableFrom(entityClass)) {
{
watcherClass = LivingWatcher.class; watcherClass = LivingWatcher.class;
} }
else else {
{
watcherClass = FlagWatcher.class; watcherClass = FlagWatcher.class;
} }
} }
else else {
{
watcherClass = FlagWatcher.class; // Disguise is unknown type watcherClass = FlagWatcher.class; // Disguise is unknown type
} }
} }
if (watcherClass == null) if (watcherClass == null) {
{
System.err.println("Error loading " + disguiseType.name() + ", FlagWatcher not assigned"); System.err.println("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
continue; continue;
} }
disguiseType.setWatcherClass(watcherClass); disguiseType.setWatcherClass(watcherClass);
if (DisguiseValues.getDisguiseValues(disguiseType) != null) if (DisguiseValues.getDisguiseValues(disguiseType) != null) {
{
continue; continue;
} }
String nmsEntityName = toReadable(disguiseType.name()); String nmsEntityName = toReadable(disguiseType.name());
switch (disguiseType) switch (disguiseType) {
{
case WITHER_SKELETON: case WITHER_SKELETON:
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
case DONKEY: case DONKEY:
@ -299,18 +267,15 @@ public class LibsDisguises extends JavaPlugin
break; break;
} }
try try {
{ if (nmsEntityName.equalsIgnoreCase("Unknown")) {
if (nmsEntityName.equalsIgnoreCase("Unknown"))
{
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0); DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0)); disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
if (sound != null) if (sound != null) {
{
sound.setDamageAndIdleSoundVolume(1f); sound.setDamageAndIdleSoundVolume(1f);
} }
@ -319,8 +284,7 @@ public class LibsDisguises extends JavaPlugin
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName); Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
if (nmsEntity == null) if (nmsEntity == null) {
{
getLogger().warning("Entity not found! (" + nmsEntityName + ")"); getLogger().warning("Entity not found! (" + nmsEntityName + ")");
continue; continue;
@ -329,10 +293,8 @@ public class LibsDisguises extends JavaPlugin
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
int entitySize = 0; int entitySize = 0;
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
{ if (field.getType().getName().equals("EnumEntitySize")) {
if (field.getType().getName().equals("EnumEntitySize"))
{
Enum enumEntitySize = (Enum) field.get(nmsEntity); Enum enumEntitySize = (Enum) field.get(nmsEntity);
entitySize = enumEntitySize.ordinal(); entitySize = enumEntitySize.ordinal();
@ -346,12 +308,10 @@ public class LibsDisguises extends JavaPlugin
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
{
FlagType flagType = FlagType.getFlag(watcherClass, watch.getIndex()); FlagType flagType = FlagType.getFlag(watcherClass, watch.getIndex());
if (flagType == null) if (flagType == null) {
{
System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " + watch.getIndex() System.err.println("Error finding the FlagType for " + disguiseType.name() + "! Index " + watch.getIndex()
+ " can't be found!"); + " can't be found!");
System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") ("
@ -363,12 +323,10 @@ public class LibsDisguises extends JavaPlugin
DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
if (sound != null) if (sound != null) {
{
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity); Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
if (soundStrength != null) if (soundStrength != null) {
{
sound.setDamageAndIdleSoundVolume(soundStrength); sound.setDamageAndIdleSoundVolume(soundStrength);
} }
} }
@ -376,14 +334,12 @@ public class LibsDisguises extends JavaPlugin
// Get the bounding box // Get the bounding box
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity)); disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
if (bukkitEntity instanceof Ageable) if (bukkitEntity instanceof Ageable) {
{
((Ageable) bukkitEntity).setBaby(); ((Ageable) bukkitEntity).setBaby();
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} }
else if (bukkitEntity instanceof Zombie) else if (bukkitEntity instanceof Zombie) {
{
((Zombie) bukkitEntity).setBaby(true); ((Zombie) bukkitEntity).setBaby(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
@ -391,8 +347,7 @@ public class LibsDisguises extends JavaPlugin
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity)); disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
} }
catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) {
{
System.out.print( System.out.print(
"[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!"); "[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
System.out.print("[LibsDisguises] Before reporting this error, " System.out.print("[LibsDisguises] Before reporting this error, "
@ -405,20 +360,17 @@ public class LibsDisguises extends JavaPlugin
} }
} }
private String toReadable(String string) private String toReadable(String string) {
{
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (String s : string.split("_")) for (String s : string.split("_")) {
{
builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase()); builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase());
} }
return builder.toString(); return builder.toString();
} }
public DisguiseListener getListener() public DisguiseListener getListener() {
{
return listener; return listener;
} }
@ -427,8 +379,7 @@ public class LibsDisguises extends JavaPlugin
* *
* @return The instance of this plugin * @return The instance of this plugin
*/ */
public static LibsDisguises getInstance() public static LibsDisguises getInstance() {
{
return instance; return instance;
} }
} }

View File

@ -23,22 +23,18 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.RabbitType; import me.libraryaddict.disguise.disguisetypes.RabbitType;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
public class HelpDisguiseCommand extends BaseDisguiseCommand public class HelpDisguiseCommand extends BaseDisguiseCommand {
{
private class EnumHelp private class EnumHelp {
{
private String enumDescription; private String enumDescription;
private String enumName; private String enumName;
private String[] enums; private String[] enums;
private String readableEnum; private String readableEnum;
public EnumHelp(String enumName, String enumReadable, String enumDescription, Enum[] enums) public EnumHelp(String enumName, String enumReadable, String enumDescription, Enum[] enums) {
{
String[] strings = new String[enums.length]; String[] strings = new String[enums.length];
for (int i = 0; i < strings.length; i++) for (int i = 0; i < strings.length; i++) {
{
strings[i] = toReadable(enums[i].name()); strings[i] = toReadable(enums[i].name());
} }
this.enumName = enumName; this.enumName = enumName;
@ -47,95 +43,84 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand
this.readableEnum = enumReadable; this.readableEnum = enumReadable;
} }
public EnumHelp(String enumName, String enumReadable, String enumDescription, String[] enums) public EnumHelp(String enumName, String enumReadable, String enumDescription, String[] enums) {
{
this.enumName = enumName; this.enumName = enumName;
this.enumDescription = enumDescription; this.enumDescription = enumDescription;
this.enums = enums; this.enums = enums;
this.readableEnum = enumReadable; this.readableEnum = enumReadable;
} }
public String getEnumDescription() public String getEnumDescription() {
{
return enumDescription; return enumDescription;
} }
public String getEnumName() public String getEnumName() {
{
return enumName; return enumName;
} }
public String[] getEnums() public String[] getEnums() {
{
return enums; return enums;
} }
public String getReadableEnum() public String getReadableEnum() {
{
return readableEnum; return readableEnum;
} }
} }
private ArrayList<EnumHelp> enumHelp = new ArrayList<>(); private ArrayList<EnumHelp> enumHelp = new ArrayList<>();
public HelpDisguiseCommand() public HelpDisguiseCommand() {
{ try {
try
{
enumHelp.add(new EnumHelp("AnimalColor", "Animal colors", ChatColor.RED + "/disguisehelp AnimalColors " enumHelp.add(new EnumHelp("AnimalColor", "Animal colors", ChatColor.RED + "/disguisehelp AnimalColors "
+ ChatColor.GREEN + "- View all the colors you can use for a animal color", AnimalColor.values())); + ChatColor.GREEN + "- View all the colors you can use for a animal color", AnimalColor.values()));
} }
catch (Exception ex) catch (Exception ex) {
{
ex.printStackTrace(); ex.printStackTrace();
} }
try try {
{
enumHelp.add(new EnumHelp("Art", "Arts", enumHelp.add(new EnumHelp("Art", "Arts",
ChatColor.RED + "/disguisehelp Art " + ChatColor.GREEN ChatColor.RED + "/disguisehelp Art " + ChatColor.GREEN
+ "- View all the painting arts you can use on a painting disguise", + "- View all the painting arts you can use on a painting disguise",
(Enum[]) Class.forName("org.bukkit.Art").getEnumConstants())); (Enum[]) Class.forName("org.bukkit.Art").getEnumConstants()));
} }
catch (Exception ex) catch (Exception ex) {
{
} }
try try {
{ enumHelp.add(new EnumHelp("LlamaColors", "Llama Colors",
enumHelp.add(new EnumHelp("HorseColor", "Horse colors", ChatColor.RED + "/disguisehelp LlamaColors " + ChatColor.GREEN
+ "- View all the colors you can use for a llama color",
(Enum[]) Class.forName("org.bukkit.entity.Llama$Color").getEnumConstants()));
}
catch (Exception ex) {
}
try {
enumHelp.add(new EnumHelp("HorseColors", "Horse colors",
ChatColor.RED + "/disguisehelp HorseColors " + ChatColor.GREEN ChatColor.RED + "/disguisehelp HorseColors " + ChatColor.GREEN
+ "- View all the colors you can use for a horses color", + "- View all the colors you can use for a horses color",
(Enum[]) Class.forName("org.bukkit.entity.Horse$Color").getEnumConstants())); (Enum[]) Class.forName("org.bukkit.entity.Horse$Color").getEnumConstants()));
} }
catch (Exception ex) catch (Exception ex) {
{
} }
try try {
{ enumHelp.add(new EnumHelp("HorseStyles", "Horse styles",
enumHelp.add(new EnumHelp("HorseStyle", "Horse styles",
ChatColor.RED + "/disguisehelp HorseStyles " + ChatColor.GREEN ChatColor.RED + "/disguisehelp HorseStyles " + ChatColor.GREEN
+ "- View all the styles you can use for a horses style", + "- View all the styles you can use for a horses style",
(Enum[]) Class.forName("org.bukkit.entity.Horse$Style").getEnumConstants())); (Enum[]) Class.forName("org.bukkit.entity.Horse$Style").getEnumConstants()));
} }
catch (Exception ex) catch (Exception ex) {
{
} }
try try {
{ enumHelp.add(new EnumHelp("OcelotTypes", "Ocelot types",
enumHelp.add(new EnumHelp("OcelotType", "Ocelot types",
ChatColor.RED + "/disguisehelp OcelotTypes " + ChatColor.GREEN ChatColor.RED + "/disguisehelp OcelotTypes " + ChatColor.GREEN
+ "- View all the ocelot types you can use for ocelots", + "- View all the ocelot types you can use for ocelots",
(Enum[]) Class.forName("org.bukkit.entity.Ocelot$Type").getEnumConstants())); (Enum[]) Class.forName("org.bukkit.entity.Ocelot$Type").getEnumConstants()));
} }
catch (Exception ex) catch (Exception ex) {
{
} }
try try {
{
ArrayList<String> enumReturns = new ArrayList<>(); ArrayList<String> enumReturns = new ArrayList<>();
for (PotionEffectType potionType : PotionEffectType.values()) for (PotionEffectType potionType : PotionEffectType.values()) {
{ if (potionType != null) {
if (potionType != null)
{
enumReturns.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN + potionType.getId() enumReturns.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN + potionType.getId()
+ ChatColor.RED + ")"); + ChatColor.RED + ")");
} }
@ -144,19 +129,16 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand
ChatColor.RED + "/disguisehelp PotionEffect " + ChatColor.GREEN + "- View all the potion effects you can set", ChatColor.RED + "/disguisehelp PotionEffect " + ChatColor.GREEN + "- View all the potion effects you can set",
enumReturns.toArray(new String[enumReturns.size()]))); enumReturns.toArray(new String[enumReturns.size()])));
} }
catch (Exception ex) catch (Exception ex) {
{
ex.printStackTrace(); ex.printStackTrace();
} }
try try {
{
enumHelp.add(new EnumHelp("Profession", "Villager professions", enumHelp.add(new EnumHelp("Profession", "Villager professions",
ChatColor.RED + "/disguisehelp Professions " + ChatColor.GREEN ChatColor.RED + "/disguisehelp Professions " + ChatColor.GREEN
+ "- View all the professions you can set on a villager", + "- View all the professions you can set on a villager",
(Enum[]) Class.forName("org.bukkit.entity.Villager$Profession").getEnumConstants())); (Enum[]) Class.forName("org.bukkit.entity.Villager$Profession").getEnumConstants()));
} }
catch (Exception ex) catch (Exception ex) {
{
} }
enumHelp.add(new EnumHelp("Direction", "Directions", enumHelp.add(new EnumHelp("Direction", "Directions",
ChatColor.RED + "/disguisehelp Directions " + ChatColor.GREEN ChatColor.RED + "/disguisehelp Directions " + ChatColor.GREEN
@ -168,56 +150,43 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
{ for (String node : new String[] {
for (String node : new String[]
{
"disguise", "disguiseradius", "disguiseentity", "disguiseplayer" "disguise", "disguiseradius", "disguiseentity", "disguiseplayer"
}) }) {
{
HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> permMap = getPermissions(sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> permMap = getPermissions(sender,
"libsdisguises." + node + "."); "libsdisguises." + node + ".");
if (!permMap.isEmpty()) if (!permMap.isEmpty()) {
{ if (args.length == 0) {
if (args.length == 0)
{
sendCommandUsage(sender, null); sendCommandUsage(sender, null);
return true; return true;
} }
else else {
{
EnumHelp help = null; EnumHelp help = null;
for (EnumHelp s : enumHelp) for (EnumHelp s : enumHelp) {
{ if (args[0].equalsIgnoreCase(s.getEnumName()) || args[0].equalsIgnoreCase(s.getEnumName() + "s")) {
if (args[0].equalsIgnoreCase(s.getEnumName()) || args[0].equalsIgnoreCase(s.getEnumName() + "s"))
{
help = s; help = s;
break; break;
} }
} }
if (help != null) if (help != null) {
{
sender.sendMessage(ChatColor.RED + help.getReadableEnum() + ": " + ChatColor.GREEN sender.sendMessage(ChatColor.RED + help.getReadableEnum() + ": " + ChatColor.GREEN
+ StringUtils.join(help.getEnums(), ChatColor.RED + ", " + ChatColor.GREEN)); + StringUtils.join(help.getEnums(), ChatColor.RED + ", " + ChatColor.GREEN));
return true; return true;
} }
DisguiseType type = null; DisguiseType type = null;
for (DisguiseType disguiseType : DisguiseType.values()) for (DisguiseType disguiseType : DisguiseType.values()) {
{
if (args[0].equalsIgnoreCase(disguiseType.name()) if (args[0].equalsIgnoreCase(disguiseType.name())
|| disguiseType.name().replace("_", "").equalsIgnoreCase(args[0])) || disguiseType.name().replace("_", "").equalsIgnoreCase(args[0])) {
{
type = disguiseType; type = disguiseType;
break; break;
} }
} }
if (type == null) if (type == null) {
{
sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]); sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]);
return true; return true;
} }
if (!permMap.containsKey(type)) if (!permMap.containsKey(type)) {
{
sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!"); sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!");
return true; return true;
} }
@ -225,119 +194,90 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand
HashMap<String, ChatColor> map = new HashMap<>(); HashMap<String, ChatColor> map = new HashMap<>();
Class watcher = type.getWatcherClass(); Class watcher = type.getWatcherClass();
int ignored = 0; int ignored = 0;
try try {
{ for (Method method : this.getDisguiseWatcherMethods(watcher)) {
for (Method method : this.getDisguiseWatcherMethods(watcher))
{
if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1 if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1
&& method.getAnnotation(Deprecated.class) == null) && method.getAnnotation(Deprecated.class) == null) {
{ if (args.length < 2 || !args[1].equalsIgnoreCase("show")) {
if (args.length < 2 || !args[1].equalsIgnoreCase("show"))
{
boolean allowed = false; boolean allowed = false;
for (ArrayList<String> key : permMap.get(type).keySet()) for (ArrayList<String> key : permMap.get(type).keySet()) {
{ if (permMap.get(type).get(key)) {
if (permMap.get(type).get(key)) if (key.contains("*") || key.contains(method.getName().toLowerCase())) {
{
if (key.contains("*") || key.contains(method.getName().toLowerCase()))
{
allowed = true; allowed = true;
break; break;
} }
} }
else if (!key.contains(method.getName().toLowerCase())) else if (!key.contains(method.getName().toLowerCase())) {
{
allowed = true; allowed = true;
break; break;
} }
} }
if (!allowed) if (!allowed) {
{
ignored++; ignored++;
continue; continue;
} }
} }
Class c = method.getParameterTypes()[0]; Class c = method.getParameterTypes()[0];
String valueType = null; String valueType = null;
if (c == String.class) if (c == String.class) {
{
valueType = "String"; valueType = "String";
} }
else if (boolean.class == c) else if (boolean.class == c) {
{
valueType = "True/False"; valueType = "True/False";
} }
else if (int.class == c) else if (int.class == c) {
{
valueType = "Number"; valueType = "Number";
} }
else if (float.class == c || double.class == c) else if (float.class == c || double.class == c) {
{
valueType = "Decimal"; valueType = "Decimal";
} }
else if (AnimalColor.class == c) else if (AnimalColor.class == c) {
{
valueType = "Color"; valueType = "Color";
} }
else if (ItemStack.class == c) else if (ItemStack.class == c) {
{
valueType = "Item (id:damage)"; valueType = "Item (id:damage)";
} }
else if (ItemStack[].class == c) else if (ItemStack[].class == c) {
{
valueType = "4 items (id:damage,id,...)"; valueType = "4 items (id:damage,id,...)";
} }
else if (c.getSimpleName().equals("Style")) else if (c.getSimpleName().equals("Style")) {
{
valueType = "Horse Style"; valueType = "Horse Style";
} }
else if (c.getSimpleName().equals("Color")) else if (c.getSimpleName().equals("Color")) {
{
valueType = "Horse Color"; valueType = "Horse Color";
} }
else if (c.getSimpleName().equals("Type")) else if (c.getSimpleName().equals("Type")) {
{
valueType = "Ocelot type"; valueType = "Ocelot type";
} }
else if (c.getSimpleName().equals("Profession")) else if (c.getSimpleName().equals("Profession")) {
{
valueType = "Villager Profession"; valueType = "Villager Profession";
} }
else if (PotionEffectType.class == c) else if (PotionEffectType.class == c) {
{
valueType = "Potion effect"; valueType = "Potion effect";
} }
else if (c == int[].class) else if (c == int[].class) {
{
valueType = "number,number,number..."; valueType = "number,number,number...";
} }
else if (c == BlockFace.class) else if (c == BlockFace.class) {
{
valueType = "direction"; valueType = "direction";
} }
else if (c == RabbitType.class) else if (c == RabbitType.class) {
{
valueType = "rabbit type"; valueType = "rabbit type";
} }
else if (c == BlockPosition.class) else if (c == BlockPosition.class) {
{
valueType = "three numbers"; valueType = "three numbers";
} }
else if (c == WrappedGameProfile.class) else if (c == WrappedGameProfile.class) {
{
valueType = "gameprofile"; valueType = "gameprofile";
} }
if (valueType != null) if (valueType != null) {
{
ChatColor methodColor = ChatColor.YELLOW; ChatColor methodColor = ChatColor.YELLOW;
Class<?> declaring = method.getDeclaringClass(); Class<?> declaring = method.getDeclaringClass();
if (declaring == LivingWatcher.class) if (declaring == LivingWatcher.class) {
{
methodColor = ChatColor.AQUA; methodColor = ChatColor.AQUA;
} }
else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) {
{
methodColor = ChatColor.GRAY; methodColor = ChatColor.GRAY;
} }
String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + valueType String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + valueType
@ -348,23 +288,19 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand
} }
} }
} }
catch (Exception ex) catch (Exception ex) {
{
ex.printStackTrace(); ex.printStackTrace();
} }
Collections.sort(methods, String.CASE_INSENSITIVE_ORDER); Collections.sort(methods, String.CASE_INSENSITIVE_ORDER);
for (int i = 0; i < methods.size(); i++) for (int i = 0; i < methods.size(); i++) {
{
methods.set(i, map.get(methods.get(i)) + methods.get(i)); methods.set(i, map.get(methods.get(i)) + methods.get(i));
} }
if (methods.isEmpty()) if (methods.isEmpty()) {
{
methods.add(ChatColor.RED + "No options with permission to use"); methods.add(ChatColor.RED + "No options with permission to use");
} }
sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: " sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: "
+ StringUtils.join(methods, ChatColor.DARK_RED + ", ")); + StringUtils.join(methods, ChatColor.DARK_RED + ", "));
if (ignored > 0) if (ignored > 0) {
{
sender.sendMessage(ChatColor.RED + "Ignored " + ignored sender.sendMessage(ChatColor.RED + "Ignored " + ignored
+ " options you do not have permission to view. Add 'show' to view unusable options."); + " options you do not have permission to view. Add 'show' to view unusable options.");
} }
@ -380,21 +316,17 @@ public class HelpDisguiseCommand extends BaseDisguiseCommand
* Send the player the information * Send the player the information
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
{
sender.sendMessage(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN sender.sendMessage(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN
+ "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use"); + "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use");
for (EnumHelp s : enumHelp) for (EnumHelp s : enumHelp) {
{
sender.sendMessage(s.getEnumDescription()); sender.sendMessage(s.getEnumDescription());
} }
} }
public String toReadable(String string) public String toReadable(String string) {
{
String[] split = string.split("_"); String[] split = string.split("_");
for (int i = 0; i < split.length; i++) for (int i = 0; i < split.length; i++) {
{
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
} }
return StringUtils.join(split, "_"); return StringUtils.join(split, "_");

View File

@ -11,7 +11,6 @@ import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse.Variant;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
@ -31,7 +30,6 @@ import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.events.DisguiseEvent; import me.libraryaddict.disguise.events.DisguiseEvent;
@ -40,8 +38,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public abstract class Disguise public abstract class Disguise {
{
private boolean disguiseInUse; private boolean disguiseInUse;
private DisguiseType disguiseType; private DisguiseType disguiseType;
private Entity entity; private Entity entity;
@ -71,15 +68,12 @@ public abstract class Disguise
* @param newType * @param newType
* The disguise * The disguise
*/ */
protected void createDisguise(DisguiseType newType) protected void createDisguise(DisguiseType newType) {
{ if (getWatcher() != null) {
if (getWatcher() != null)
{
return; return;
} }
if (newType.getEntityType() == null) if (newType.getEntityType() == null) {
{
throw new RuntimeException("DisguiseType " + newType throw new RuntimeException("DisguiseType " + newType
+ " was used in a futile attempt to construct a disguise, but this Minecraft version does not have that entity"); + " was used in a futile attempt to construct a disguise, but this Minecraft version does not have that entity");
} }
@ -90,45 +84,36 @@ public abstract class Disguise
boolean isAdult = true; boolean isAdult = true;
if (isMobDisguise()) if (isMobDisguise()) {
{
isAdult = ((MobDisguise) this).isAdult(); isAdult = ((MobDisguise) this).isAdult();
} }
try try {
{
// Construct the FlagWatcher from the stored class // Construct the FlagWatcher from the stored class
setWatcher((FlagWatcher) getType().getWatcherClass().getConstructor(Disguise.class).newInstance(this)); setWatcher((FlagWatcher) getType().getWatcherClass().getConstructor(Disguise.class).newInstance(this));
} }
catch (Exception e) catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
} }
// Set the disguise if its a baby or not // Set the disguise if its a baby or not
if (!isAdult) if (!isAdult) {
{ if (getWatcher() instanceof AgeableWatcher) {
if (getWatcher() instanceof AgeableWatcher)
{
((AgeableWatcher) getWatcher()).setBaby(true); ((AgeableWatcher) getWatcher()).setBaby(true);
} }
else if (getWatcher() instanceof ZombieWatcher) else if (getWatcher() instanceof ZombieWatcher) {
{
((ZombieWatcher) getWatcher()).setBaby(true); ((ZombieWatcher) getWatcher()).setBaby(true);
} }
} }
// If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton // If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton
if (getType() == DisguiseType.WITHER_SKELETON) if (getType() == DisguiseType.WITHER_SKELETON) {
{
((SkeletonWatcher) getWatcher()).setType(SkeletonType.WITHER); ((SkeletonWatcher) getWatcher()).setType(SkeletonType.WITHER);
} }
else if (getType() == DisguiseType.STRAY) else if (getType() == DisguiseType.STRAY) {
{
((SkeletonWatcher) getWatcher()).setType(SkeletonType.STRAY); ((SkeletonWatcher) getWatcher()).setType(SkeletonType.STRAY);
} // Else if its a zombie, but the disguise type is a zombie villager. Set the value. } // Else if its a zombie, but the disguise type is a zombie villager. Set the value.
else if (getType() == DisguiseType.ZOMBIE_VILLAGER) else if (getType() == DisguiseType.ZOMBIE_VILLAGER) {
{
Profession profession = null; Profession profession = null;
while (profession == null || profession == Profession.NORMAL || profession == Profession.HUSK) while (profession == null || profession == Profession.NORMAL || profession == Profession.HUSK)
@ -136,31 +121,16 @@ public abstract class Disguise
((ZombieWatcher) getWatcher()).setProfession(profession); ((ZombieWatcher) getWatcher()).setProfession(profession);
} }
else if (getType() == DisguiseType.HUSK) else if (getType() == DisguiseType.HUSK) {
{
((ZombieWatcher) getWatcher()).setProfession(Profession.HUSK); ((ZombieWatcher) getWatcher()).setProfession(Profession.HUSK);
} }
else if (getType() == DisguiseType.ELDER_GUARDIAN) else if (getType() == DisguiseType.ELDER_GUARDIAN) {
{
((GuardianWatcher) getWatcher()).setElder(true); ((GuardianWatcher) getWatcher()).setElder(true);
} // Else if its a horse. Set the horse watcher type
else if (getWatcher() instanceof HorseWatcher)
{
try
{
Variant horseType = Variant.valueOf(getType().name());
((HorseWatcher) getWatcher()).setVariant(horseType);
}
catch (Exception ex)
{
// Ok.. So it aint a horse
}
} }
final boolean alwaysSendVelocity; final boolean alwaysSendVelocity;
switch (getType()) switch (getType()) {
{
case EGG: case EGG:
case ENDER_PEARL: case ENDER_PEARL:
case BAT: case BAT:
@ -181,8 +151,7 @@ public abstract class Disguise
double velocitySpeed = 0.0005; double velocitySpeed = 0.0005;
switch (getType()) switch (getType()) {
{
case FIREWORK: case FIREWORK:
velocitySpeed = -0.040; velocitySpeed = -0.040;
break; break;
@ -232,32 +201,26 @@ public abstract class Disguise
final TargetedDisguise disguise = (TargetedDisguise) this; final TargetedDisguise disguise = (TargetedDisguise) this;
// A scheduler to clean up any unused disguises. // A scheduler to clean up any unused disguises.
velocityRunnable = new Runnable() velocityRunnable = new Runnable() {
{
private int blockX, blockY, blockZ, facing; private int blockX, blockY, blockZ, facing;
private int deadTicks = 0; private int deadTicks = 0;
private int refreshDisguise = 0; private int refreshDisguise = 0;
@Override @Override
public void run() public void run() {
{
// If entity is no longer valid. Remove it. // If entity is no longer valid. Remove it.
if (!getEntity().isValid()) if (!getEntity().isValid()) {
{
// If it has been dead for 30+ ticks // If it has been dead for 30+ ticks
// This is to ensure that this disguise isn't removed while clients think its the real entity // This is to ensure that this disguise isn't removed while clients think its the real entity
// The delay is because if it sends the destroy entity packets straight away, then it means no death animation // The delay is because if it sends the destroy entity packets straight away, then it means no death animation
// This is probably still a problem for wither and enderdragon deaths. // This is probably still a problem for wither and enderdragon deaths.
if (deadTicks++ > (getType() == DisguiseType.ENDER_DRAGON ? 200 : 20)) if (deadTicks++ > (getType() == DisguiseType.ENDER_DRAGON ? 200 : 20)) {
{
deadTicks = 0; deadTicks = 0;
if (isRemoveDisguiseOnDeath()) if (isRemoveDisguiseOnDeath()) {
{
removeDisguise(); removeDisguise();
} }
else else {
{
entity = null; entity = null;
watcher = getWatcher().clone(disguise); watcher = getWatcher().clone(disguise);
task.cancel(); task.cancel();
@ -265,32 +228,27 @@ public abstract class Disguise
} }
} }
} }
else else {
{
deadTicks = 0; deadTicks = 0;
// If the disguise type is tnt, we need to resend the entity packet else it will turn invisible // If the disguise type is tnt, we need to resend the entity packet else it will turn invisible
if (getType() == DisguiseType.FIREWORK) if (getType() == DisguiseType.FIREWORK) {
{
refreshDisguise++; refreshDisguise++;
if (refreshDisguise % 40 == 0) if (refreshDisguise % 40 == 0) {
{
refreshDisguise = 0; refreshDisguise = 0;
DisguiseUtilities.refreshTrackers(disguise); DisguiseUtilities.refreshTrackers(disguise);
} }
} }
if (getType() == DisguiseType.ITEM_FRAME) if (getType() == DisguiseType.ITEM_FRAME) {
{
Location loc = getEntity().getLocation(); Location loc = getEntity().getLocation();
int newFacing = (((int) loc.getYaw() + 720 + 45) / 90) % 4; int newFacing = (((int) loc.getYaw() + 720 + 45) / 90) % 4;
if (loc.getBlockX() != blockX || loc.getBlockY() != blockY || loc.getBlockZ() != blockZ if (loc.getBlockX() != blockX || loc.getBlockY() != blockY || loc.getBlockZ() != blockZ
|| newFacing != facing) || newFacing != facing) {
{
blockX = loc.getBlockX(); blockX = loc.getBlockX();
blockY = loc.getBlockY(); blockY = loc.getBlockY();
blockZ = loc.getBlockZ(); blockZ = loc.getBlockZ();
@ -300,37 +258,31 @@ public abstract class Disguise
} }
} }
if (isModifyBoundingBox()) if (isModifyBoundingBox()) {
{
DisguiseUtilities.doBoundingBox(disguise); DisguiseUtilities.doBoundingBox(disguise);
} }
if (getType() == DisguiseType.BAT && !((BatWatcher) getWatcher()).isHanging()) if (getType() == DisguiseType.BAT && !((BatWatcher) getWatcher()).isHanging()) {
{
return; return;
} }
// If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors. // If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors.
// If this disguise has velocity sending enabled and the entity is flying. // If this disguise has velocity sending enabled and the entity is flying.
if (isVelocitySent() && vectorY != 0 && (alwaysSendVelocity || !getEntity().isOnGround())) if (isVelocitySent() && vectorY != 0 && (alwaysSendVelocity || !getEntity().isOnGround())) {
{
Vector vector = getEntity().getVelocity(); Vector vector = getEntity().getVelocity();
// If the entity doesn't have velocity changes already - You know. I really can't wrap my head about the // If the entity doesn't have velocity changes already - You know. I really can't wrap my head about the
// if statement. // if statement.
// But it doesn't seem to do anything wrong.. // But it doesn't seem to do anything wrong..
if (vector.getY() != 0 && !(vector.getY() < 0 && alwaysSendVelocity && getEntity().isOnGround())) if (vector.getY() != 0 && !(vector.getY() < 0 && alwaysSendVelocity && getEntity().isOnGround())) {
{
return; return;
} }
// If disguise isn't a experience orb, or the entity isn't standing on the ground // If disguise isn't a experience orb, or the entity isn't standing on the ground
if (getType() != DisguiseType.EXPERIENCE_ORB || !getEntity().isOnGround()) if (getType() != DisguiseType.EXPERIENCE_ORB || !getEntity().isOnGround()) {
{
PacketContainer lookPacket = null; PacketContainer lookPacket = null;
if (getType() == DisguiseType.WITHER_SKULL && DisguiseConfig.isWitherSkullPacketsEnabled()) if (getType() == DisguiseType.WITHER_SKULL && DisguiseConfig.isWitherSkullPacketsEnabled()) {
{
lookPacket = new PacketContainer(Server.ENTITY_LOOK); lookPacket = new PacketContainer(Server.ENTITY_LOOK);
StructureModifier<Object> mods = lookPacket.getModifier(); StructureModifier<Object> mods = lookPacket.getModifier();
@ -342,26 +294,22 @@ public abstract class Disguise
mods.write(5, PacketsManager.getPitch(getType(), DisguiseType.getType(getEntity().getType()), mods.write(5, PacketsManager.getPitch(getType(), DisguiseType.getType(getEntity().getType()),
(byte) Math.floor(loc.getPitch() * 256.0F / 360.0F))); (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F)));
if (isSelfDisguiseVisible() && getEntity() instanceof Player) if (isSelfDisguiseVisible() && getEntity() instanceof Player) {
{
PacketContainer selfLookPacket = lookPacket.shallowClone(); PacketContainer selfLookPacket = lookPacket.shallowClone();
selfLookPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); selfLookPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(), ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(),
selfLookPacket, false); selfLookPacket, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
try try {
{
PacketContainer velocityPacket = new PacketContainer(Server.ENTITY_VELOCITY); PacketContainer velocityPacket = new PacketContainer(Server.ENTITY_VELOCITY);
StructureModifier<Integer> mods = velocityPacket.getIntegers(); StructureModifier<Integer> mods = velocityPacket.getIntegers();
@ -369,26 +317,21 @@ public abstract class Disguise
mods.write(1, (int) (vector.getX() * 8000)); mods.write(1, (int) (vector.getX() * 8000));
mods.write(3, (int) (vector.getZ() * 8000)); mods.write(3, (int) (vector.getZ() * 8000));
for (Player player : DisguiseUtilities.getPerverts(disguise)) for (Player player : DisguiseUtilities.getPerverts(disguise)) {
{ if (getEntity() == player) {
if (getEntity() == player) if (!isSelfDisguiseVisible()) {
{
if (!isSelfDisguiseVisible())
{
continue; continue;
} }
mods.write(0, DisguiseAPI.getSelfDisguiseId()); mods.write(0, DisguiseAPI.getSelfDisguiseId());
} }
else else {
{
mods.write(0, getEntity().getEntityId()); mods.write(0, getEntity().getEntityId());
} }
mods.write(2, (int) (8000D * (vectorY * ReflectionManager.getPing(player)) * 0.069D)); mods.write(2, (int) (8000D * (vectorY * ReflectionManager.getPing(player)) * 0.069D));
if (lookPacket != null && player != getEntity()) if (lookPacket != null && player != getEntity()) {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(player, lookPacket, false); ProtocolLibrary.getProtocolManager().sendServerPacket(player, lookPacket, false);
} }
@ -396,47 +339,38 @@ public abstract class Disguise
false); false);
} }
} }
catch (Exception e) catch (Exception e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
// If we need to send a packet to update the exp position as it likes to gravitate client sided to // If we need to send a packet to update the exp position as it likes to gravitate client sided to
// players. // players.
} }
if (getType() == DisguiseType.EXPERIENCE_ORB) if (getType() == DisguiseType.EXPERIENCE_ORB) {
{
PacketContainer packet = new PacketContainer(Server.REL_ENTITY_MOVE); PacketContainer packet = new PacketContainer(Server.REL_ENTITY_MOVE);
packet.getIntegers().write(0, getEntity().getEntityId()); packet.getIntegers().write(0, getEntity().getEntityId());
try try {
{ for (Player player : DisguiseUtilities.getPerverts(disguise)) {
for (Player player : DisguiseUtilities.getPerverts(disguise)) if (getEntity() != player) {
{
if (getEntity() != player)
{
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
} }
else if (isSelfDisguiseVisible()) else if (isSelfDisguiseVisible()) {
{
PacketContainer selfPacket = packet.shallowClone(); PacketContainer selfPacket = packet.shallowClone();
selfPacket.getModifier().write(0, DisguiseAPI.getSelfDisguiseId()); selfPacket.getModifier().write(0, DisguiseAPI.getSelfDisguiseId());
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(), selfPacket, ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(), selfPacket,
false); false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -450,8 +384,7 @@ public abstract class Disguise
* *
* @return entity * @return entity
*/ */
public Entity getEntity() public Entity getEntity() {
{
return entity; return entity;
} }
@ -460,8 +393,7 @@ public abstract class Disguise
* *
* @return disguiseType * @return disguiseType
*/ */
public DisguiseType getType() public DisguiseType getType() {
{
return disguiseType; return disguiseType;
} }
@ -470,8 +402,7 @@ public abstract class Disguise
* *
* @return flagWatcher * @return flagWatcher
*/ */
public FlagWatcher getWatcher() public FlagWatcher getWatcher() {
{
return watcher; return watcher;
} }
@ -481,68 +412,56 @@ public abstract class Disguise
* *
* @return isDisguiseInUse * @return isDisguiseInUse
*/ */
public boolean isDisguiseInUse() public boolean isDisguiseInUse() {
{
return disguiseInUse; return disguiseInUse;
} }
public boolean isHidingArmorFromSelf() public boolean isHidingArmorFromSelf() {
{
return hideArmorFromSelf; return hideArmorFromSelf;
} }
public boolean isHidingHeldItemFromSelf() public boolean isHidingHeldItemFromSelf() {
{
return hideHeldItemFromSelf; return hideHeldItemFromSelf;
} }
public boolean isKeepDisguiseOnEntityDespawn() public boolean isKeepDisguiseOnEntityDespawn() {
{
return this.keepDisguiseEntityDespawn; return this.keepDisguiseEntityDespawn;
} }
public boolean isKeepDisguiseOnPlayerDeath() public boolean isKeepDisguiseOnPlayerDeath() {
{
return this.keepDisguisePlayerDeath; return this.keepDisguisePlayerDeath;
} }
public boolean isKeepDisguiseOnPlayerLogout() public boolean isKeepDisguiseOnPlayerLogout() {
{
return this.keepDisguisePlayerLogout; return this.keepDisguisePlayerLogout;
} }
public boolean isMiscDisguise() public boolean isMiscDisguise() {
{
return false; return false;
} }
public boolean isMobDisguise() public boolean isMobDisguise() {
{
return false; return false;
} }
public boolean isModifyBoundingBox() public boolean isModifyBoundingBox() {
{
return modifyBoundingBox; return modifyBoundingBox;
} }
public boolean isPlayerDisguise() public boolean isPlayerDisguise() {
{
return false; return false;
} }
/** /**
* Internal use * Internal use
*/ */
public boolean isRemoveDisguiseOnDeath() public boolean isRemoveDisguiseOnDeath() {
{
return getEntity() == null || (getEntity() instanceof Player return getEntity() == null || (getEntity() instanceof Player
? (!((Player) getEntity()).isOnline() ? !isKeepDisguiseOnPlayerLogout() : !isKeepDisguiseOnPlayerDeath()) ? (!((Player) getEntity()).isOnline() ? !isKeepDisguiseOnPlayerLogout() : !isKeepDisguiseOnPlayerDeath())
: (!isKeepDisguiseOnEntityDespawn() || getEntity().isDead())); : (!isKeepDisguiseOnEntityDespawn() || getEntity().isDead()));
} }
public boolean isSelfDisguiseSoundsReplaced() public boolean isSelfDisguiseSoundsReplaced() {
{
return hearSelfDisguise; return hearSelfDisguise;
} }
@ -551,18 +470,15 @@ public abstract class Disguise
* *
* @return viewSelfDisguise * @return viewSelfDisguise
*/ */
public boolean isSelfDisguiseVisible() public boolean isSelfDisguiseVisible() {
{
return viewSelfDisguise; return viewSelfDisguise;
} }
public boolean isSoundsReplaced() public boolean isSoundsReplaced() {
{
return replaceSounds; return replaceSounds;
} }
public boolean isVelocitySent() public boolean isVelocitySent() {
{
return velocitySent; return velocitySent;
} }
@ -571,8 +487,7 @@ public abstract class Disguise
* *
* @return * @return
*/ */
public boolean isShowName() public boolean isShowName() {
{
return showName; return showName;
} }
@ -581,20 +496,16 @@ public abstract class Disguise
* *
* @return removeDiguise * @return removeDiguise
*/ */
public boolean removeDisguise() public boolean removeDisguise() {
{ if (disguiseInUse) {
if (disguiseInUse)
{
UndisguiseEvent event = new UndisguiseEvent(entity, this); UndisguiseEvent event = new UndisguiseEvent(entity, this);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) if (!event.isCancelled()) {
{
disguiseInUse = false; disguiseInUse = false;
if (task != null) if (task != null) {
{
task.cancel(); task.cancel();
task = null; task = null;
} }
@ -602,58 +513,45 @@ public abstract class Disguise
HashMap<UUID, HashSet<TargetedDisguise>> disguises = DisguiseUtilities.getDisguises(); HashMap<UUID, HashSet<TargetedDisguise>> disguises = DisguiseUtilities.getDisguises();
// If this disguise has a entity set // If this disguise has a entity set
if (getEntity() != null) if (getEntity() != null) {
{
// If this disguise is active // If this disguise is active
// Remove the disguise from the current disguises. // Remove the disguise from the current disguises.
if (DisguiseUtilities.removeDisguise((TargetedDisguise) this)) if (DisguiseUtilities.removeDisguise((TargetedDisguise) this)) {
{ if (getEntity() instanceof Player) {
if (getEntity() instanceof Player)
{
DisguiseUtilities.removeSelfDisguise((Player) getEntity()); DisguiseUtilities.removeSelfDisguise((Player) getEntity());
} }
// Better refresh the entity to undisguise it // Better refresh the entity to undisguise it
if (getEntity().isValid()) if (getEntity().isValid()) {
{
DisguiseUtilities.refreshTrackers((TargetedDisguise) this); DisguiseUtilities.refreshTrackers((TargetedDisguise) this);
} }
else else {
{
DisguiseUtilities.destroyEntity((TargetedDisguise) this); DisguiseUtilities.destroyEntity((TargetedDisguise) this);
} }
} }
} }
else else {
{
// Loop through the disguises because it could be used with a unknown entity id. // Loop through the disguises because it could be used with a unknown entity id.
HashMap<Integer, HashSet<TargetedDisguise>> future = DisguiseUtilities.getFutureDisguises(); HashMap<Integer, HashSet<TargetedDisguise>> future = DisguiseUtilities.getFutureDisguises();
Iterator<Integer> itel = DisguiseUtilities.getFutureDisguises().keySet().iterator(); Iterator<Integer> itel = DisguiseUtilities.getFutureDisguises().keySet().iterator();
while (itel.hasNext()) while (itel.hasNext()) {
{
int id = itel.next(); int id = itel.next();
if (future.get(id).remove(this) && future.get(id).isEmpty()) if (future.get(id).remove(this) && future.get(id).isEmpty()) {
{
itel.remove(); itel.remove();
} }
} }
} }
if (isPlayerDisguise()) if (isPlayerDisguise()) {
{
String name = ((PlayerDisguise) this).getName(); String name = ((PlayerDisguise) this).getName();
if (!DisguiseUtilities.getAddedByPlugins().contains(name.toLowerCase())) if (!DisguiseUtilities.getAddedByPlugins().contains(name.toLowerCase())) {
{ for (HashSet<TargetedDisguise> disguise : disguises.values()) {
for (HashSet<TargetedDisguise> disguise : disguises.values()) for (Disguise d : disguise) {
{ if (d.isPlayerDisguise() && ((PlayerDisguise) d).getName().equals(name)) {
for (Disguise d : disguise)
{
if (d.isPlayerDisguise() && ((PlayerDisguise) d).getName().equals(name))
{
return true; return true;
} }
} }
@ -675,20 +573,16 @@ public abstract class Disguise
* @param entity * @param entity
* @return disguise * @return disguise
*/ */
public Disguise setEntity(Entity entity) public Disguise setEntity(Entity entity) {
{ if (this.getEntity() != null) {
if (this.getEntity() != null) if (getEntity() == entity) {
{
if (getEntity() == entity)
{
return this; return this;
} }
throw new RuntimeException("This disguise is already in use! Try .clone()"); throw new RuntimeException("This disguise is already in use! Try .clone()");
} }
if (isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) if (isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) {
{
throw new RuntimeException( throw new RuntimeException(
"Cannot disguise a living entity with a misc disguise. Reenable MiscDisguisesForLiving in the config to do this"); "Cannot disguise a living entity with a misc disguise. Reenable MiscDisguisesForLiving in the config to do this");
} }
@ -700,79 +594,66 @@ public abstract class Disguise
return this; return this;
} }
public Disguise setShowName(boolean showName) public Disguise setShowName(boolean showName) {
{
this.showName = showName; this.showName = showName;
return this; return this;
} }
public Disguise setHearSelfDisguise(boolean hearSelfDisguise) public Disguise setHearSelfDisguise(boolean hearSelfDisguise) {
{
this.hearSelfDisguise = hearSelfDisguise; this.hearSelfDisguise = hearSelfDisguise;
return this; return this;
} }
public Disguise setHideArmorFromSelf(boolean hideArmor) public Disguise setHideArmorFromSelf(boolean hideArmor) {
{
this.hideArmorFromSelf = hideArmor; this.hideArmorFromSelf = hideArmor;
if (getEntity() instanceof Player) if (getEntity() instanceof Player) {
{
((Player) getEntity()).updateInventory(); ((Player) getEntity()).updateInventory();
} }
return this; return this;
} }
public Disguise setHideHeldItemFromSelf(boolean hideHeldItem) public Disguise setHideHeldItemFromSelf(boolean hideHeldItem) {
{
this.hideHeldItemFromSelf = hideHeldItem; this.hideHeldItemFromSelf = hideHeldItem;
if (getEntity() instanceof Player) if (getEntity() instanceof Player) {
{
((Player) getEntity()).updateInventory(); ((Player) getEntity()).updateInventory();
} }
return this; return this;
} }
public Disguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) public Disguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
{
this.keepDisguiseEntityDespawn = keepDisguise; this.keepDisguiseEntityDespawn = keepDisguise;
return this; return this;
} }
public Disguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) public Disguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
{
this.keepDisguisePlayerDeath = keepDisguise; this.keepDisguisePlayerDeath = keepDisguise;
return this; return this;
} }
public Disguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) public Disguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
{
this.keepDisguisePlayerLogout = keepDisguise; this.keepDisguisePlayerLogout = keepDisguise;
return this; return this;
} }
public Disguise setModifyBoundingBox(boolean modifyBox) public Disguise setModifyBoundingBox(boolean modifyBox) {
{ if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS)
{
throw new RuntimeException( throw new RuntimeException(
"Cannot modify the bounding box of a disguise which is not TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS"); "Cannot modify the bounding box of a disguise which is not TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS");
} }
if (isModifyBoundingBox() != modifyBox) if (isModifyBoundingBox() != modifyBox) {
{
this.modifyBoundingBox = modifyBox; this.modifyBoundingBox = modifyBox;
if (DisguiseUtilities.isDisguiseInUse(this)) if (DisguiseUtilities.isDisguiseInUse(this)) {
{
DisguiseUtilities.doBoundingBox((TargetedDisguise) this); DisguiseUtilities.doBoundingBox((TargetedDisguise) this);
} }
} }
@ -780,8 +661,7 @@ public abstract class Disguise
return this; return this;
} }
public Disguise setReplaceSounds(boolean areSoundsReplaced) public Disguise setReplaceSounds(boolean areSoundsReplaced) {
{
replaceSounds = areSoundsReplaced; replaceSounds = areSoundsReplaced;
return this; return this;
@ -791,20 +671,17 @@ public abstract class Disguise
* Sets up the FlagWatcher with the entityclass, it creates all the data it needs to prevent conflicts when sending the * Sets up the FlagWatcher with the entityclass, it creates all the data it needs to prevent conflicts when sending the
* datawatcher. * datawatcher.
*/ */
private void setupWatcher() private void setupWatcher() {
{
ArrayList<FlagType> disguiseFlags = FlagType.getFlags(getType().getWatcherClass()); ArrayList<FlagType> disguiseFlags = FlagType.getFlags(getType().getWatcherClass());
ArrayList<FlagType> entityFlags = FlagType.getFlags(DisguiseType.getType(getEntity().getType()).getWatcherClass()); ArrayList<FlagType> entityFlags = FlagType.getFlags(DisguiseType.getType(getEntity().getType()).getWatcherClass());
for (FlagType flag : entityFlags) for (FlagType flag : entityFlags) {
{
if (disguiseFlags.contains(flag)) if (disguiseFlags.contains(flag))
continue; continue;
FlagType backup = null; FlagType backup = null;
for (FlagType flagType : disguiseFlags) for (FlagType flagType : disguiseFlags) {
{
if (flagType.getIndex() == flag.getIndex()) if (flagType.getIndex() == flag.getIndex())
backup = flagType; backup = flagType;
} }
@ -815,8 +692,7 @@ public abstract class Disguise
getWatcher().setNoGravity(true); getWatcher().setNoGravity(true);
} }
public Disguise setVelocitySent(boolean sendVelocity) public Disguise setVelocitySent(boolean sendVelocity) {
{
this.velocitySent = sendVelocity; this.velocitySent = sendVelocity;
return this; return this;
@ -828,22 +704,16 @@ public abstract class Disguise
* @param viewSelfDisguise * @param viewSelfDisguise
* @return * @return
*/ */
public Disguise setViewSelfDisguise(boolean viewSelfDisguise) public Disguise setViewSelfDisguise(boolean viewSelfDisguise) {
{ if (isSelfDisguiseVisible() != viewSelfDisguise) {
if (isSelfDisguiseVisible() != viewSelfDisguise)
{
this.viewSelfDisguise = viewSelfDisguise; this.viewSelfDisguise = viewSelfDisguise;
if (getEntity() != null && getEntity() instanceof Player) if (getEntity() != null && getEntity() instanceof Player) {
{ if (DisguiseAPI.getDisguise((Player) getEntity(), getEntity()) == this) {
if (DisguiseAPI.getDisguise((Player) getEntity(), getEntity()) == this) if (isSelfDisguiseVisible()) {
{
if (isSelfDisguiseVisible())
{
DisguiseUtilities.setupFakeDisguise(this); DisguiseUtilities.setupFakeDisguise(this);
} }
else else {
{
DisguiseUtilities.removeSelfDisguise((Player) getEntity()); DisguiseUtilities.removeSelfDisguise((Player) getEntity());
} }
} }
@ -853,30 +723,24 @@ public abstract class Disguise
return this; return this;
} }
public Disguise setWatcher(FlagWatcher newWatcher) public Disguise setWatcher(FlagWatcher newWatcher) {
{ if (!getType().getWatcherClass().isInstance(newWatcher)) {
if (!getType().getWatcherClass().isInstance(newWatcher))
{
throw new IllegalArgumentException(newWatcher.getClass().getSimpleName() + " is not a instance of " throw new IllegalArgumentException(newWatcher.getClass().getSimpleName() + " is not a instance of "
+ getType().getWatcherClass().getSimpleName() + " for DisguiseType " + getType().name()); + getType().getWatcherClass().getSimpleName() + " for DisguiseType " + getType().name());
} }
watcher = newWatcher; watcher = newWatcher;
if (getEntity() != null) if (getEntity() != null) {
{
setupWatcher(); setupWatcher();
} }
return this; return this;
} }
public boolean startDisguise() public boolean startDisguise() {
{ if (!isDisguiseInUse()) {
if (!isDisguiseInUse()) if (getEntity() == null) {
{
if (getEntity() == null)
{
throw new RuntimeException("No entity is assigned to this disguise!"); throw new RuntimeException("No entity is assigned to this disguise!");
} }
@ -887,8 +751,7 @@ public abstract class Disguise
// If they cancelled this disguise event. No idea why. // If they cancelled this disguise event. No idea why.
// Just return. // Just return.
if (!event.isCancelled()) if (!event.isCancelled()) {
{
disguiseInUse = true; disguiseInUse = true;
task = Bukkit.getScheduler().runTaskTimer(LibsDisguises.getInstance(), velocityRunnable, 1, 1); task = Bukkit.getScheduler().runTaskTimer(LibsDisguises.getInstance(), velocityRunnable, 1, 1);
@ -896,8 +759,7 @@ public abstract class Disguise
// Stick the disguise in the disguises bin // Stick the disguise in the disguises bin
DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) this); DisguiseUtilities.addDisguise(entity.getUniqueId(), (TargetedDisguise) this);
if (isSelfDisguiseVisible() && getEntity() instanceof Player) if (isSelfDisguiseVisible() && getEntity() instanceof Player) {
{
DisguiseUtilities.removeSelfDisguise((Player) getEntity()); DisguiseUtilities.removeSelfDisguise((Player) getEntity());
} }
@ -905,11 +767,9 @@ public abstract class Disguise
DisguiseUtilities.refreshTrackers((TargetedDisguise) this); DisguiseUtilities.refreshTrackers((TargetedDisguise) this);
// If he is a player, then self disguise himself // If he is a player, then self disguise himself
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), new Runnable() Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), new Runnable() {
{
@Override @Override
public void run() public void run() {
{
DisguiseUtilities.setupFakeDisguise(Disguise.this); DisguiseUtilities.setupFakeDisguise(Disguise.this);
} }
}, 2); }, 2);
@ -919,8 +779,7 @@ public abstract class Disguise
return false; return false;
} }
public boolean stopDisguise() public boolean stopDisguise() {
{
return removeDisguise(); return removeDisguise();
} }
@ -929,8 +788,7 @@ public abstract class Disguise
* *
* @return * @return
*/ */
public static List<UUID> getViewSelf() public static List<UUID> getViewSelf() {
{
return viewSelf; return viewSelf;
} }
} }

View File

@ -9,8 +9,7 @@ import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
public enum DisguiseType public enum DisguiseType {
{
AREA_EFFECT_CLOUD(3, 0), AREA_EFFECT_CLOUD(3, 0),
ARMOR_STAND(78), ARMOR_STAND(78),
@ -53,6 +52,10 @@ public enum DisguiseType
ENDERMITE, ENDERMITE,
EVOKER,
EVOKER_FANGS(79),
EXPERIENCE_ORB, EXPERIENCE_ORB,
FALLING_BLOCK(70, 1), FALLING_BLOCK(70, 1),
@ -77,6 +80,10 @@ public enum DisguiseType
ITEM_FRAME(71), ITEM_FRAME(71),
LLAMA,
LLAMA_SPIT(68),
LEASH_HITCH(77), LEASH_HITCH(77),
MAGMA_CUBE, MAGMA_CUBE,
@ -153,8 +160,12 @@ public enum DisguiseType
UNKNOWN, UNKNOWN,
VEX,
VILLAGER, VILLAGER,
VINDICATOR,
WITCH, WITCH,
WITHER, WITHER,
@ -169,31 +180,21 @@ public enum DisguiseType
ZOMBIE_VILLAGER; ZOMBIE_VILLAGER;
static static {
{
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC. // We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC.
// Without erroring up everything. // Without erroring up everything.
for (DisguiseType type : values()) for (DisguiseType type : values()) {
{
try try {
{
DisguiseType toUse = type; DisguiseType toUse = type;
String name; String name;
switch (type) switch (type) {
{
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being.. // Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
// Usable. // Usable.
case ITEM_FRAME: case ITEM_FRAME:
break; break;
case DONKEY:
case MULE:
case UNDEAD_HORSE:
case SKELETON_HORSE:
toUse = DisguiseType.HORSE;
break;
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
case HUSK: case HUSK:
toUse = DisguiseType.ZOMBIE; toUse = DisguiseType.ZOMBIE;
@ -213,23 +214,19 @@ public enum DisguiseType
type.setEntityType(EntityType.valueOf(name)); type.setEntityType(EntityType.valueOf(name));
} }
catch (Throwable ex) catch (Throwable ex) {
{
// This version of Spigot doesn't have the disguise. // This version of Spigot doesn't have the disguise.
} }
} }
} }
public static DisguiseType getType(Entity entity) public static DisguiseType getType(Entity entity) {
{
DisguiseType disguiseType = getType(entity.getType()); DisguiseType disguiseType = getType(entity.getType());
switch (disguiseType) switch (disguiseType) {
{
case ZOMBIE: case ZOMBIE:
if (((Zombie) entity).isVillager()) if (((Zombie) entity).isVillager()) {
{
disguiseType = DisguiseType.ZOMBIE_VILLAGER; disguiseType = DisguiseType.ZOMBIE_VILLAGER;
} }
@ -243,16 +240,14 @@ public enum DisguiseType
case SKELETON: case SKELETON:
if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER) if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER) {
{
disguiseType = DisguiseType.WITHER_SKELETON; disguiseType = DisguiseType.WITHER_SKELETON;
} }
break; break;
case GUARDIAN: case GUARDIAN:
if (((Guardian) entity).isElder()) if (((Guardian) entity).isElder()) {
{
disguiseType = DisguiseType.ELDER_GUARDIAN; disguiseType = DisguiseType.ELDER_GUARDIAN;
} }
@ -265,14 +260,11 @@ public enum DisguiseType
} }
public static DisguiseType getType(EntityType entityType) public static DisguiseType getType(EntityType entityType) {
{ try {
try
{
return valueOf(entityType.name().toUpperCase()); return valueOf(entityType.name().toUpperCase());
} }
catch (Throwable ex) catch (Throwable ex) {
{
return DisguiseType.UNKNOWN; return DisguiseType.UNKNOWN;
} }
} }
@ -283,14 +275,11 @@ public enum DisguiseType
private Class<? extends FlagWatcher> watcherClass; private Class<? extends FlagWatcher> watcherClass;
DisguiseType(int... ints) DisguiseType(int... ints) {
{ for (int i = 0; i < ints.length; i++) {
for (int i = 0; i < ints.length; i++)
{
int value = ints[i]; int value = ints[i];
switch (i) switch (i) {
{
case 0: case 0:
objectId = value; objectId = value;
@ -305,23 +294,19 @@ public enum DisguiseType
} }
} }
public int getDefaultData() public int getDefaultData() {
{
return defaultData; return defaultData;
} }
public Class<? extends Entity> getEntityClass() public Class<? extends Entity> getEntityClass() {
{ if (entityType != null) {
if (entityType != null)
{
return getEntityType().getEntityClass(); return getEntityType().getEntityClass();
} }
return Entity.class; return Entity.class;
} }
public EntityType getEntityType() public EntityType getEntityType() {
{
return entityType; return entityType;
} }
@ -330,8 +315,7 @@ public enum DisguiseType
* *
* @return * @return
*/ */
public int getObjectId() public int getObjectId() {
{
return objectId; return objectId;
} }
@ -340,52 +324,42 @@ public enum DisguiseType
* *
* @return * @return
*/ */
public int getTypeId() public int getTypeId() {
{
return (int) getEntityType().getTypeId(); return (int) getEntityType().getTypeId();
} }
public Class<? extends FlagWatcher> getWatcherClass() public Class<? extends FlagWatcher> getWatcherClass() {
{
return watcherClass; return watcherClass;
} }
public boolean isMisc() public boolean isMisc() {
{
return getEntityType() != null && !getEntityType().isAlive(); return getEntityType() != null && !getEntityType().isAlive();
} }
public boolean isMob() public boolean isMob() {
{
return getEntityType() != null && getEntityType().isAlive() && !isPlayer(); return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
} }
public boolean isPlayer() public boolean isPlayer() {
{
return this == DisguiseType.PLAYER; return this == DisguiseType.PLAYER;
} }
public boolean isUnknown() public boolean isUnknown() {
{
return this == DisguiseType.UNKNOWN; return this == DisguiseType.UNKNOWN;
} }
private void setEntityType(EntityType entityType) private void setEntityType(EntityType entityType) {
{
this.entityType = entityType; this.entityType = entityType;
} }
public void setWatcherClass(Class<? extends FlagWatcher> c) public void setWatcherClass(Class<? extends FlagWatcher> c) {
{
watcherClass = c; watcherClass = c;
} }
public String toReadable() public String toReadable() {
{
String[] split = name().split("_"); String[] split = name().split("_");
for (int i = 0; i < split.length; i++) for (int i = 0; i < split.length; i++) {
{
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
} }

View File

@ -28,16 +28,20 @@ import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EnderCrystalWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.EnderCrystalWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EnderDragonWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.EnderDragonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EndermanWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.EndermanWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EvokerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FireworkWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FireworkWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.FishingHookWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FishingHookWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GhastWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GhastWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseAbstractWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseChestedWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.InsentientWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.IronGolemWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.IronGolemWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ItemFrameWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ItemFrameWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LlamaWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.OcelotWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.OcelotWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PigWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PigWatcher;
@ -53,15 +57,16 @@ import me.libraryaddict.disguise.disguisetypes.watchers.SpiderWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TNTWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.TNTWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.VexWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.VillagerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.VillagerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.VindicatorWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WitchWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitchWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WitherSkullWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitherSkullWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WitherWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitherWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
public class FlagType<Y> public class FlagType<Y> {
{
private static FlagType[] _values = new FlagType[0]; private static FlagType[] _values = new FlagType[0];
public static FlagType<Boolean> AGEABLE_BABY = new FlagType<Boolean>(AgeableWatcher.class, 0, false); public static FlagType<Boolean> AGEABLE_BABY = new FlagType<Boolean>(AgeableWatcher.class, 0, false);
@ -79,11 +84,9 @@ public class FlagType<Y>
public static FlagType<Float> AREA_EFFECT_RADIUS = new FlagType<Float>(AreaEffectCloudWatcher.class, 0, 0F); public static FlagType<Float> AREA_EFFECT_RADIUS = new FlagType<Float>(AreaEffectCloudWatcher.class, 0, 0F);
public static FlagType<Vector3F> ARMORSTAND_BODY = new FlagType<Vector3F>(ArmorStandWatcher.class, 2, public static FlagType<Vector3F> ARMORSTAND_BODY = new FlagType<Vector3F>(ArmorStandWatcher.class, 2, new Vector3F(0, 0, 0));
new Vector3F(0, 0, 0));
public static FlagType<Vector3F> ARMORSTAND_HEAD = new FlagType<Vector3F>(ArmorStandWatcher.class, 1, public static FlagType<Vector3F> ARMORSTAND_HEAD = new FlagType<Vector3F>(ArmorStandWatcher.class, 1, new Vector3F(0, 0, 0));
new Vector3F(0, 0, 0));
public static FlagType<Vector3F> ARMORSTAND_LEFT_ARM = new FlagType<Vector3F>(ArmorStandWatcher.class, 3, public static FlagType<Vector3F> ARMORSTAND_LEFT_ARM = new FlagType<Vector3F>(ArmorStandWatcher.class, 3,
new Vector3F(0, 0, 0)); new Vector3F(0, 0, 0));
@ -93,9 +96,11 @@ public class FlagType<Y>
public static FlagType<Byte> ARMORSTAND_META = new FlagType<Byte>(ArmorStandWatcher.class, 0, (byte) 0); public static FlagType<Byte> ARMORSTAND_META = new FlagType<Byte>(ArmorStandWatcher.class, 0, (byte) 0);
public static FlagType<Vector3F> ARMORSTAND_RIGHT_ARM = new FlagType<Vector3F>(ArmorStandWatcher.class, 4, new Vector3F(0,0,0)); public static FlagType<Vector3F> ARMORSTAND_RIGHT_ARM = new FlagType<Vector3F>(ArmorStandWatcher.class, 4,
new Vector3F(0, 0, 0));
public static FlagType<Vector3F> ARMORSTAND_RIGHT_LEG = new FlagType<Vector3F>(ArmorStandWatcher.class, 6, new Vector3F(0,0,0)); public static FlagType<Vector3F> ARMORSTAND_RIGHT_LEG = new FlagType<Vector3F>(ArmorStandWatcher.class, 6,
new Vector3F(0, 0, 0));
public static FlagType<Byte> ARROW_CRITICAL = new FlagType<Byte>(ArrowWatcher.class, 0, (byte) 0); public static FlagType<Byte> ARROW_CRITICAL = new FlagType<Byte>(ArrowWatcher.class, 0, (byte) 0);
@ -148,6 +153,8 @@ public class FlagType<Y>
public static FlagType<Boolean> ENTITY_SILENT = new FlagType<Boolean>(FlagWatcher.class, 4, false); public static FlagType<Boolean> ENTITY_SILENT = new FlagType<Boolean>(FlagWatcher.class, 4, false);
public static FlagType<Byte> EVOKER_SPELL_TICKS = new FlagType<Byte>(EvokerWatcher.class, 0, (byte) 0);
public static FlagType<BlockPosition> FALLING_BLOCK_POSITION = new FlagType<BlockPosition>(FallingBlockWatcher.class, 0, public static FlagType<BlockPosition> FALLING_BLOCK_POSITION = new FlagType<BlockPosition>(FallingBlockWatcher.class, 0,
BlockPosition.ORIGIN); BlockPosition.ORIGIN);
@ -162,16 +169,18 @@ public class FlagType<Y>
public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 1, 0); public static FlagType<Integer> GUARDIAN_TARGET = new FlagType<Integer>(GuardianWatcher.class, 1, 0);
public static FlagType<Integer> HORSE_ARMOR = new FlagType<Integer>(HorseWatcher.class, 4, 0); public static FlagType<Integer> HORSE_ARMOR = new FlagType<Integer>(HorseWatcher.class, 1, 0);
public static FlagType<Integer> HORSE_COLOR = new FlagType<Integer>(HorseWatcher.class, 2, 0); public static FlagType<Integer> HORSE_COLOR = new FlagType<Integer>(HorseWatcher.class, 0, 0);
public static FlagType<Byte> HORSE_META = new FlagType<Byte>(HorseWatcher.class, 0, (byte) 0); public static FlagType<Byte> HORSE_META = new FlagType<Byte>(HorseAbstractWatcher.class, 0, (byte) 0);
public static FlagType<Optional<UUID>> HORSE_OWNER = new FlagType<Optional<UUID>>(HorseWatcher.class, 3, public static FlagType<Boolean> HORSE_CARRYING_CHEST = new FlagType<Boolean>(HorseChestedWatcher.class, 0, false);
public static FlagType<Optional<UUID>> HORSE_OWNER = new FlagType<Optional<UUID>>(HorseAbstractWatcher.class, 1,
Optional.<UUID> absent()); Optional.<UUID> absent());
public static FlagType<Integer> HORSE_VARIANT = new FlagType<Integer>(HorseWatcher.class, 1, 0); // public static FlagType<Integer> HORSE_VARIANT = new FlagType<Integer>(HorseWatcher.class, 0, 0);
public static FlagType<Byte> INSENTIENT_META = new FlagType<Byte>(InsentientWatcher.class, 0, (byte) 0); public static FlagType<Byte> INSENTIENT_META = new FlagType<Byte>(InsentientWatcher.class, 0, (byte) 0);
@ -182,6 +191,12 @@ public class FlagType<Y>
public static FlagType<Integer> ITEMFRAME_ROTATION = new FlagType<Integer>(ItemFrameWatcher.class, 1, 0); public static FlagType<Integer> ITEMFRAME_ROTATION = new FlagType<Integer>(ItemFrameWatcher.class, 1, 0);
public static FlagType<Integer> LLAMA_STRENGTH = new FlagType<Integer>(LlamaWatcher.class, 0, 0);
public static FlagType<Integer> LLAMA_COLOR = new FlagType<Integer>(LlamaWatcher.class, 1, -1);
public static FlagType<Integer> LLAMA_CARPET = new FlagType<Integer>(LlamaWatcher.class, 2, 0);
public static FlagType<Integer> LIVING_ARROWS = new FlagType<Integer>(LivingWatcher.class, 4, 0); public static FlagType<Integer> LIVING_ARROWS = new FlagType<Integer>(LivingWatcher.class, 4, 0);
public static FlagType<Byte> LIVING_HAND = new FlagType<Byte>(LivingWatcher.class, 0, (byte) 0); public static FlagType<Byte> LIVING_HAND = new FlagType<Byte>(LivingWatcher.class, 0, (byte) 0);
@ -229,6 +244,8 @@ public class FlagType<Y>
public static FlagType<Byte> SHULKER_PEEKING = new FlagType<Byte>(ShulkerWatcher.class, 2, (byte) 0); public static FlagType<Byte> SHULKER_PEEKING = new FlagType<Byte>(ShulkerWatcher.class, 2, (byte) 0);
public static FlagType<Byte> SHULKER_COLOR = new FlagType<Byte>(ShulkerWatcher.class, 3, (byte) 10);
public static FlagType<Boolean> SKELETON_SWING_ARMS = new FlagType<Boolean>(SkeletonWatcher.class, 1, false); public static FlagType<Boolean> SKELETON_SWING_ARMS = new FlagType<Boolean>(SkeletonWatcher.class, 1, false);
public static FlagType<Integer> SKELETON_TYPE = new FlagType<Integer>(SkeletonWatcher.class, 0, 0); public static FlagType<Integer> SKELETON_TYPE = new FlagType<Integer>(SkeletonWatcher.class, 0, 0);
@ -257,8 +274,12 @@ public class FlagType<Y>
public static FlagType<Integer> TNT_FUSE_TICKS = new FlagType<Integer>(TNTWatcher.class, 0, Integer.MAX_VALUE); public static FlagType<Integer> TNT_FUSE_TICKS = new FlagType<Integer>(TNTWatcher.class, 0, Integer.MAX_VALUE);
public static FlagType<Boolean> VEX_ANGRY = new FlagType<Boolean>(VexWatcher.class, 0, false);
public static FlagType<Integer> VILLAGER_PROFESSION = new FlagType<Integer>(VillagerWatcher.class, 0, 0); public static FlagType<Integer> VILLAGER_PROFESSION = new FlagType<Integer>(VillagerWatcher.class, 0, 0);
public static FlagType<Byte> VINDICATOR_JOHNNY = new FlagType<Byte>(VindicatorWatcher.class, 0, (byte) 0);
public static FlagType<Boolean> WITCH_AGGRESSIVE = new FlagType<Boolean>(WitchWatcher.class, 0, false); public static FlagType<Boolean> WITCH_AGGRESSIVE = new FlagType<Boolean>(WitchWatcher.class, 0, false);
public static FlagType<Integer> WITHER_INVUL = new FlagType<Integer>(WitherWatcher.class, 3, 0); public static FlagType<Integer> WITHER_INVUL = new FlagType<Integer>(WitherWatcher.class, 3, 0);
@ -285,10 +306,8 @@ public class FlagType<Y>
public static FlagType<Boolean> ZOMBIE_SHAKING = new FlagType<Boolean>(ZombieWatcher.class, 2, false); public static FlagType<Boolean> ZOMBIE_SHAKING = new FlagType<Boolean>(ZombieWatcher.class, 2, false);
static static {
{ for (FlagType flagType : values()) {
for (FlagType flagType : values())
{
if (flagType.getFlagWatcher() == FlagWatcher.class) if (flagType.getFlagWatcher() == FlagWatcher.class)
continue; continue;
@ -302,32 +321,27 @@ public class FlagType<Y>
HashMap<Class, Integer> maxValues = new HashMap<Class, Integer>(); HashMap<Class, Integer> maxValues = new HashMap<Class, Integer>();
for (FlagType type : values()) for (FlagType type : values()) {
{
if (maxValues.containsKey(type.getFlagWatcher()) && maxValues.get(type.getFlagWatcher()) > type.getIndex()) if (maxValues.containsKey(type.getFlagWatcher()) && maxValues.get(type.getFlagWatcher()) > type.getIndex())
continue; continue;
maxValues.put(type.getFlagWatcher(), type.getIndex()); maxValues.put(type.getFlagWatcher(), type.getIndex());
} }
for (Entry<Class, Integer> entry : maxValues.entrySet()) for (Entry<Class, Integer> entry : maxValues.entrySet()) {
{
loop: loop:
for (int i = 0; i < entry.getValue(); i++) for (int i = 0; i < entry.getValue(); i++) {
{
FlagType found = null; FlagType found = null;
for (FlagType type : values()) for (FlagType type : values()) {
{
if (type.getIndex() != i) if (type.getIndex() != i)
continue; continue;
if (!type.getFlagWatcher().isAssignableFrom(entry.getKey())) if (!type.getFlagWatcher().isAssignableFrom(entry.getKey()))
continue; continue;
if (found != null) if (found != null) {
{
System.err.println(entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index " System.err.println(entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index "
+ i + " (" + type.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher().getSimpleName() + i + " (" + type.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher().getSimpleName()
+ ")"); + ")");
@ -345,10 +359,8 @@ public class FlagType<Y>
} }
} }
public static FlagType getFlag(Class<? extends FlagWatcher> watcherClass, int flagNo) public static FlagType getFlag(Class<? extends FlagWatcher> watcherClass, int flagNo) {
{ for (FlagType type : values()) {
for (FlagType type : values())
{
if (type.getIndex() != flagNo) if (type.getIndex() != flagNo)
continue; continue;
@ -361,12 +373,10 @@ public class FlagType<Y>
return null; return null;
} }
public static ArrayList<FlagType> getFlags(Class<? extends FlagWatcher> watcherClass) public static ArrayList<FlagType> getFlags(Class<? extends FlagWatcher> watcherClass) {
{
ArrayList<FlagType> list = new ArrayList<FlagType>(); ArrayList<FlagType> list = new ArrayList<FlagType>();
for (FlagType type : values()) for (FlagType type : values()) {
{
if (!type.getFlagWatcher().isAssignableFrom(watcherClass)) if (!type.getFlagWatcher().isAssignableFrom(watcherClass))
continue; continue;
@ -376,28 +386,24 @@ public class FlagType<Y>
return list; return list;
} }
private static int getNoIndexes(Class c) private static int getNoIndexes(Class c) {
{
int found = 0; int found = 0;
for (FlagType type : values()) for (FlagType type : values()) {
{
if (type.getFlagWatcher() != c) if (type.getFlagWatcher() != c)
continue; continue;
found++; found++;
} }
if (c != FlagWatcher.class) if (c != FlagWatcher.class) {
{
found += getNoIndexes(c.getSuperclass()); found += getNoIndexes(c.getSuperclass());
} }
return found; return found;
} }
public static FlagType[] values() public static FlagType[] values() {
{
return _values; return _values;
} }
@ -405,8 +411,7 @@ public class FlagType<Y>
private int _index; private int _index;
private Class<? extends FlagWatcher> _watcher; private Class<? extends FlagWatcher> _watcher;
private FlagType(Class<? extends FlagWatcher> watcher, int index, Y defaultValue) private FlagType(Class<? extends FlagWatcher> watcher, int index, Y defaultValue) {
{
_index = index; _index = index;
_watcher = watcher; _watcher = watcher;
_defaultValue = defaultValue; _defaultValue = defaultValue;
@ -415,18 +420,15 @@ public class FlagType<Y>
_values[_values.length - 1] = this; _values[_values.length - 1] = this;
} }
public Y getDefault() public Y getDefault() {
{
return _defaultValue; return _defaultValue;
} }
public Class<? extends FlagWatcher> getFlagWatcher() public Class<? extends FlagWatcher> getFlagWatcher() {
{
return _watcher; return _watcher;
} }
public int getIndex() public int getIndex() {
{
return _index; return _index;
} }
} }

View File

@ -243,7 +243,7 @@ public class FlagWatcher
public String getCustomName() public String getCustomName()
{ {
return (String) getValue(FlagType.ENTITY_CUSTOM_NAME); return (String) getData(FlagType.ENTITY_CUSTOM_NAME);
} }
protected TargetedDisguise getDisguise() protected TargetedDisguise getDisguise()
@ -253,7 +253,7 @@ public class FlagWatcher
private boolean getEntityFlag(int byteValue) private boolean getEntityFlag(int byteValue)
{ {
return (getValue(FlagType.ENTITY_META) & 1 << byteValue) != 0; return (getData(FlagType.ENTITY_META) & 1 << byteValue) != 0;
} }
public EntityEquipment getEquipment() public EntityEquipment getEquipment()
@ -301,7 +301,7 @@ public class FlagWatcher
return null; return null;
} }
protected <Y> Y getValue(FlagType<Y> flagType) protected <Y> Y getData(FlagType<Y> flagType)
{ {
if (_entityValues.containsKey(flagType.getIndex())) if (_entityValues.containsKey(flagType.getIndex()))
{ {
@ -338,7 +338,7 @@ public class FlagWatcher
public boolean isCustomNameVisible() public boolean isCustomNameVisible()
{ {
return getValue(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); return getData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE);
} }
public boolean isEntityAnimationsAdded() public boolean isEntityAnimationsAdded()
@ -363,7 +363,7 @@ public class FlagWatcher
public boolean isNoGravity() public boolean isNoGravity()
{ {
return getValue(FlagType.ENTITY_NO_GRAVITY); return getData(FlagType.ENTITY_NO_GRAVITY);
} }
public boolean isRightClicking() public boolean isRightClicking()
@ -509,13 +509,13 @@ public class FlagWatcher
name = name.substring(0, 64); name = name.substring(0, 64);
} }
setValue(FlagType.ENTITY_CUSTOM_NAME, name); setData(FlagType.ENTITY_CUSTOM_NAME, name);
sendData(FlagType.ENTITY_CUSTOM_NAME); sendData(FlagType.ENTITY_CUSTOM_NAME);
} }
public void setCustomNameVisible(boolean display) public void setCustomNameVisible(boolean display)
{ {
setValue(FlagType.ENTITY_CUSTOM_NAME_VISIBLE, display); setData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE, display);
sendData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); sendData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE);
} }
@ -523,15 +523,15 @@ public class FlagWatcher
{ {
_modifiedEntityAnimations.add(byteValue); _modifiedEntityAnimations.add(byteValue);
byte b0 = (byte) getValue(FlagType.ENTITY_META); byte b0 = (byte) getData(FlagType.ENTITY_META);
if (flag) if (flag)
{ {
setValue(FlagType.ENTITY_META, (byte) (b0 | 1 << byteValue)); setData(FlagType.ENTITY_META, (byte) (b0 | 1 << byteValue));
} }
else else
{ {
setValue(FlagType.ENTITY_META, (byte) (b0 & ~(1 << byteValue))); setData(FlagType.ENTITY_META, (byte) (b0 & ~(1 << byteValue)));
} }
} }
@ -653,7 +653,7 @@ public class FlagWatcher
public void setNoGravity(boolean noGravity) public void setNoGravity(boolean noGravity)
{ {
setValue(FlagType.ENTITY_NO_GRAVITY, noGravity); setData(FlagType.ENTITY_NO_GRAVITY, noGravity);
sendData(FlagType.ENTITY_NO_GRAVITY); sendData(FlagType.ENTITY_NO_GRAVITY);
} }
@ -675,7 +675,7 @@ public class FlagWatcher
sendData(FlagType.ENTITY_META); sendData(FlagType.ENTITY_META);
} }
protected <Y> void setValue(FlagType<Y> id, Y value) protected <Y> void setData(FlagType<Y> id, Y value)
{ {
_entityValues.put(id.getIndex(), value); _entityValues.put(id.getIndex(), value);

View File

@ -17,7 +17,7 @@ public class AgeableWatcher extends InsentientWatcher
public boolean isBaby() public boolean isBaby()
{ {
return getValue(FlagType.AGEABLE_BABY); return getData(FlagType.AGEABLE_BABY);
} }
public void setAdult() public void setAdult()
@ -32,7 +32,7 @@ public class AgeableWatcher extends InsentientWatcher
public void setBaby(boolean isBaby) public void setBaby(boolean isBaby)
{ {
setValue(FlagType.AGEABLE_BABY, isBaby); setData(FlagType.AGEABLE_BABY, isBaby);
sendData(FlagType.AGEABLE_BABY); sendData(FlagType.AGEABLE_BABY);
} }
} }

View File

@ -17,42 +17,42 @@ public class AreaEffectCloudWatcher extends FlagWatcher
public float getRadius() public float getRadius()
{ {
return getValue(FlagType.AREA_EFFECT_RADIUS); return getData(FlagType.AREA_EFFECT_RADIUS);
} }
public int getColor() public int getColor()
{ {
return getValue(FlagType.AREA_EFFECT_COLOR); return getData(FlagType.AREA_EFFECT_COLOR);
} }
public boolean isIgnoreRadius() public boolean isIgnoreRadius()
{ {
return getValue(FlagType.AREA_EFFECT_IGNORE_RADIUS); return getData(FlagType.AREA_EFFECT_IGNORE_RADIUS);
} }
public int getParticleId() public int getParticleId()
{ {
return getValue(FlagType.AREA_EFFECT_PARTICLE); return getData(FlagType.AREA_EFFECT_PARTICLE);
} }
public void setRadius(float radius) public void setRadius(float radius)
{ {
setValue(FlagType.AREA_EFFECT_RADIUS, radius); setData(FlagType.AREA_EFFECT_RADIUS, radius);
} }
public void setColor(int color) public void setColor(int color)
{ {
setValue(FlagType.AREA_EFFECT_COLOR, color); setData(FlagType.AREA_EFFECT_COLOR, color);
} }
public void setIgnoreRadius(boolean ignore) public void setIgnoreRadius(boolean ignore)
{ {
setValue(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore); setData(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore);
} }
public void setParticleId(int particleId) public void setParticleId(int particleId)
{ {
setValue(FlagType.AREA_EFFECT_PARTICLE, particleId); setData(FlagType.AREA_EFFECT_PARTICLE, particleId);
} }
} }

View File

@ -16,7 +16,7 @@ public class ArmorStandWatcher extends LivingWatcher
private boolean getArmorStandFlag(int value) private boolean getArmorStandFlag(int value)
{ {
return (getValue(FlagType.ARMORSTAND_META) & value) != 0; return (getData(FlagType.ARMORSTAND_META) & value) != 0;
} }
public EulerAngle getBody() public EulerAngle getBody()
@ -44,7 +44,7 @@ public class ArmorStandWatcher extends LivingWatcher
if (!hasValue(type)) if (!hasValue(type))
return new EulerAngle(0, 0, 0); return new EulerAngle(0, 0, 0);
Vector3F vec = getValue(type); Vector3F vec = getData(type);
return new EulerAngle(vec.getX(), vec.getY(), vec.getZ()); return new EulerAngle(vec.getX(), vec.getY(), vec.getZ());
} }
@ -86,7 +86,7 @@ public class ArmorStandWatcher extends LivingWatcher
private void setArmorStandFlag(int value, boolean isTrue) private void setArmorStandFlag(int value, boolean isTrue)
{ {
byte b1 = (byte) getValue(FlagType.ARMORSTAND_META); byte b1 = (byte) getData(FlagType.ARMORSTAND_META);
if (isTrue) if (isTrue)
{ {
@ -97,7 +97,7 @@ public class ArmorStandWatcher extends LivingWatcher
b1 = (byte) (b1 & value); b1 = (byte) (b1 & value);
} }
setValue(FlagType.ARMORSTAND_META, b1); setData(FlagType.ARMORSTAND_META, b1);
sendData(FlagType.ARMORSTAND_META); sendData(FlagType.ARMORSTAND_META);
} }
@ -141,7 +141,7 @@ public class ArmorStandWatcher extends LivingWatcher
private void setPose(FlagType<Vector3F> type, EulerAngle vector) private void setPose(FlagType<Vector3F> type, EulerAngle vector)
{ {
setValue(type, new Vector3F((float) vector.getX(), (float) vector.getY(), (float) vector.getZ())); setData(type, new Vector3F((float) vector.getX(), (float) vector.getY(), (float) vector.getZ()));
sendData(type); sendData(type);
} }

View File

@ -13,12 +13,12 @@ public class ArrowWatcher extends FlagWatcher
public boolean isCritical() public boolean isCritical()
{ {
return (byte) getValue(FlagType.ARROW_CRITICAL) == 1; return (byte) getData(FlagType.ARROW_CRITICAL) == 1;
} }
public void setCritical(boolean critical) public void setCritical(boolean critical)
{ {
setValue(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0)); setData(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0));
sendData(FlagType.ARROW_CRITICAL); sendData(FlagType.ARROW_CRITICAL);
} }
} }

View File

@ -15,12 +15,12 @@ public class BatWatcher extends InsentientWatcher
public boolean isHanging() public boolean isHanging()
{ {
return ((byte) getValue(FlagType.BAT_HANGING)) == 1; return ((byte) getData(FlagType.BAT_HANGING)) == 1;
} }
public void setHanging(boolean hanging) public void setHanging(boolean hanging)
{ {
setValue(FlagType.BAT_HANGING, hanging ? (byte) 1 : (byte) 0); setData(FlagType.BAT_HANGING, hanging ? (byte) 1 : (byte) 0);
sendData(FlagType.BAT_HANGING); sendData(FlagType.BAT_HANGING);
} }
} }

View File

@ -12,12 +12,12 @@ public class BlazeWatcher extends InsentientWatcher
public boolean isBlazing() public boolean isBlazing()
{ {
return getValue(FlagType.BLAZE_BLAZING) == 1; return getData(FlagType.BLAZE_BLAZING) == 1;
} }
public void setBlazing(boolean isBlazing) public void setBlazing(boolean isBlazing)
{ {
setValue(FlagType.BLAZE_BLAZING, (byte) (isBlazing ? 1 : 0)); setData(FlagType.BLAZE_BLAZING, (byte) (isBlazing ? 1 : 0));
sendData(FlagType.BLAZE_BLAZING); sendData(FlagType.BLAZE_BLAZING);
} }

View File

@ -19,46 +19,46 @@ public class BoatWatcher extends FlagWatcher
public float getDamage() public float getDamage()
{ {
return getValue(FlagType.BOAT_DAMAGE); return getData(FlagType.BOAT_DAMAGE);
} }
public void setDamage(float dmg) public void setDamage(float dmg)
{ {
setValue(FlagType.BOAT_DAMAGE, dmg); setData(FlagType.BOAT_DAMAGE, dmg);
sendData(FlagType.BOAT_DAMAGE); sendData(FlagType.BOAT_DAMAGE);
} }
public void setRightPaddling(boolean rightPaddling) public void setRightPaddling(boolean rightPaddling)
{ {
setValue(FlagType.BOAT_RIGHT_PADDLING, rightPaddling); setData(FlagType.BOAT_RIGHT_PADDLING, rightPaddling);
sendData(FlagType.BOAT_RIGHT_PADDLING); sendData(FlagType.BOAT_RIGHT_PADDLING);
} }
public void setLeftPaddling(boolean leftPaddling) public void setLeftPaddling(boolean leftPaddling)
{ {
setValue(FlagType.BOAT_LEFT_PADDLING, leftPaddling); setData(FlagType.BOAT_LEFT_PADDLING, leftPaddling);
sendData(FlagType.BOAT_LEFT_PADDLING); sendData(FlagType.BOAT_LEFT_PADDLING);
} }
public boolean isRightPaddling() public boolean isRightPaddling()
{ {
return getValue(FlagType.BOAT_RIGHT_PADDLING); return getData(FlagType.BOAT_RIGHT_PADDLING);
} }
public boolean isLeftPaddling() public boolean isLeftPaddling()
{ {
return getValue(FlagType.BOAT_LEFT_PADDLING); return getData(FlagType.BOAT_LEFT_PADDLING);
} }
public void setBoatType(TreeSpecies boatType) public void setBoatType(TreeSpecies boatType)
{ {
setValue(FlagType.BOAT_TYPE, (int) boatType.getData()); setData(FlagType.BOAT_TYPE, (int) boatType.getData());
sendData(FlagType.BOAT_TYPE); sendData(FlagType.BOAT_TYPE);
} }
public TreeSpecies getBoatType() public TreeSpecies getBoatType()
{ {
return TreeSpecies.getByData(getValue(FlagType.BOAT_TYPE).byteValue()); return TreeSpecies.getByData(getData(FlagType.BOAT_TYPE).byteValue());
} }
} }

View File

@ -13,23 +13,23 @@ public class CreeperWatcher extends InsentientWatcher
public boolean isIgnited() public boolean isIgnited()
{ {
return (boolean) getValue(FlagType.CREEPER_IGNITED); return (boolean) getData(FlagType.CREEPER_IGNITED);
} }
public boolean isPowered() public boolean isPowered()
{ {
return (boolean) getValue(FlagType.CREEPER_POWERED); return (boolean) getData(FlagType.CREEPER_POWERED);
} }
public void setIgnited(boolean ignited) public void setIgnited(boolean ignited)
{ {
setValue(FlagType.CREEPER_IGNITED, ignited); setData(FlagType.CREEPER_IGNITED, ignited);
sendData(FlagType.CREEPER_IGNITED); sendData(FlagType.CREEPER_IGNITED);
} }
public void setPowered(boolean powered) public void setPowered(boolean powered)
{ {
setValue(FlagType.CREEPER_POWERED, powered); setData(FlagType.CREEPER_POWERED, powered);
sendData(FlagType.CREEPER_POWERED); sendData(FlagType.CREEPER_POWERED);
} }

View File

@ -0,0 +1,11 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class DonkeyWatcher extends HorseChestedWatcher {
public DonkeyWatcher(Disguise disguise) {
super(disguise);
}
}

View File

@ -17,12 +17,12 @@ public class DroppedItemWatcher extends FlagWatcher
public ItemStack getItemStack() public ItemStack getItemStack()
{ {
return getValue(FlagType.DROPPED_ITEM).get(); return getData(FlagType.DROPPED_ITEM).get();
} }
public void setItemStack(ItemStack item) public void setItemStack(ItemStack item)
{ {
setValue(FlagType.DROPPED_ITEM, Optional.<ItemStack> of(item)); setData(FlagType.DROPPED_ITEM, Optional.<ItemStack> of(item));
sendData(FlagType.DROPPED_ITEM); sendData(FlagType.DROPPED_ITEM);
} }
} }

View File

@ -19,24 +19,24 @@ public class EnderCrystalWatcher extends FlagWatcher
public void setBeamTarget(BlockPosition position) public void setBeamTarget(BlockPosition position)
{ {
setValue(FlagType.ENDER_CRYSTAL_BEAM, Optional.of(position)); setData(FlagType.ENDER_CRYSTAL_BEAM, Optional.of(position));
sendData(FlagType.ENDER_CRYSTAL_BEAM); sendData(FlagType.ENDER_CRYSTAL_BEAM);
} }
public Optional<BlockPosition> getBeamTarget() public Optional<BlockPosition> getBeamTarget()
{ {
return getValue(FlagType.ENDER_CRYSTAL_BEAM); return getData(FlagType.ENDER_CRYSTAL_BEAM);
} }
public void setShowBottom(boolean bool) public void setShowBottom(boolean bool)
{ {
setValue(FlagType.ENDER_CRYSTAL_PLATE, bool); setData(FlagType.ENDER_CRYSTAL_PLATE, bool);
sendData(FlagType.ENDER_CRYSTAL_PLATE); sendData(FlagType.ENDER_CRYSTAL_PLATE);
} }
public boolean isShowBottom() public boolean isShowBottom()
{ {
return getValue(FlagType.ENDER_CRYSTAL_PLATE); return getData(FlagType.ENDER_CRYSTAL_PLATE);
} }
} }

View File

@ -16,12 +16,12 @@ public class EnderDragonWatcher extends InsentientWatcher
public int getPhase() public int getPhase()
{ {
return getValue(FlagType.ENDERDRAGON_PHASE); return getData(FlagType.ENDERDRAGON_PHASE);
} }
public void setPhase(int phase) public void setPhase(int phase)
{ {
setValue(FlagType.ENDERDRAGON_PHASE, phase); setData(FlagType.ENDERDRAGON_PHASE, phase);
sendData(FlagType.ENDERDRAGON_PHASE); sendData(FlagType.ENDERDRAGON_PHASE);
} }
} }

View File

@ -20,7 +20,7 @@ public class EndermanWatcher extends InsentientWatcher
@Override @Override
public ItemStack getItemInMainHand() public ItemStack getItemInMainHand()
{ {
Optional<WrappedBlockData> value = getValue(FlagType.ENDERMAN_ITEM); Optional<WrappedBlockData> value = getData(FlagType.ENDERMAN_ITEM);
if (value.isPresent()) if (value.isPresent())
{ {
@ -62,7 +62,7 @@ public class EndermanWatcher extends InsentientWatcher
else else
optional = Optional.<WrappedBlockData> of(WrappedBlockData.createData(type, data)); optional = Optional.<WrappedBlockData> of(WrappedBlockData.createData(type, data));
setValue(FlagType.ENDERMAN_ITEM, optional); setData(FlagType.ENDERMAN_ITEM, optional);
} }
@Deprecated @Deprecated
@ -73,12 +73,12 @@ public class EndermanWatcher extends InsentientWatcher
public boolean isAggressive() public boolean isAggressive()
{ {
return getValue(FlagType.ENDERMAN_AGRESSIVE); return getData(FlagType.ENDERMAN_AGRESSIVE);
} }
public void setAggressive(boolean isAggressive) public void setAggressive(boolean isAggressive)
{ {
setValue(FlagType.ENDERMAN_AGRESSIVE, isAggressive); setData(FlagType.ENDERMAN_AGRESSIVE, isAggressive);
sendData(FlagType.ENDERMAN_AGRESSIVE); sendData(FlagType.ENDERMAN_AGRESSIVE);
} }

View File

@ -0,0 +1,20 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class EvokerWatcher extends InsentientWatcher {
public EvokerWatcher(Disguise disguise) {
super(disguise);
}
public void setSpellTicks(int spellTicks) {
setData(FlagType.EVOKER_SPELL_TICKS, (byte) spellTicks);
sendData(FlagType.EVOKER_SPELL_TICKS);
}
public int getSpellTicks() {
return getData(FlagType.EVOKER_SPELL_TICKS);
}
}

View File

@ -18,12 +18,12 @@ public class FireworkWatcher extends FlagWatcher
public ItemStack getFirework() public ItemStack getFirework()
{ {
if (getValue(FlagType.FIREWORK_ITEM) == null) if (getData(FlagType.FIREWORK_ITEM) == null)
{ {
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);
} }
return (ItemStack) getValue(FlagType.FIREWORK_ITEM).get(); return (ItemStack) getData(FlagType.FIREWORK_ITEM).get();
} }
public void setFirework(ItemStack newItem) public void setFirework(ItemStack newItem)
@ -36,7 +36,7 @@ public class FireworkWatcher extends FlagWatcher
newItem = newItem.clone(); newItem = newItem.clone();
newItem.setAmount(1); newItem.setAmount(1);
setValue(FlagType.FIREWORK_ITEM, Optional.<ItemStack> of(newItem)); setData(FlagType.FIREWORK_ITEM, Optional.<ItemStack> of(newItem));
sendData(FlagType.FIREWORK_ITEM); sendData(FlagType.FIREWORK_ITEM);
} }

View File

@ -13,13 +13,13 @@ public class FishingHookWatcher extends FlagWatcher
public void setHooked(int hookedId) public void setHooked(int hookedId)
{ {
setValue(FlagType.FISHING_HOOK, hookedId + 1); setData(FlagType.FISHING_HOOK, hookedId + 1);
sendData(FlagType.FISHING_HOOK); sendData(FlagType.FISHING_HOOK);
} }
public int getHooked() public int getHooked()
{ {
int hooked = getValue(FlagType.FISHING_HOOK); int hooked = getData(FlagType.FISHING_HOOK);
if (hooked > 0) if (hooked > 0)
hooked--; hooked--;

View File

@ -13,12 +13,12 @@ public class GhastWatcher extends InsentientWatcher
public boolean isAggressive() public boolean isAggressive()
{ {
return getValue(FlagType.GHAST_AGRESSIVE); return getData(FlagType.GHAST_AGRESSIVE);
} }
public void setAggressive(boolean isAggressive) public void setAggressive(boolean isAggressive)
{ {
setValue(FlagType.GHAST_AGRESSIVE, isAggressive); setData(FlagType.GHAST_AGRESSIVE, isAggressive);
sendData(FlagType.GHAST_AGRESSIVE); sendData(FlagType.GHAST_AGRESSIVE);
} }

View File

@ -22,7 +22,7 @@ public class GuardianWatcher extends InsentientWatcher
*/ */
public boolean isTarget() public boolean isTarget()
{ {
return ((int) getValue(FlagType.GUARDIAN_TARGET)) != 0; return ((int) getData(FlagType.GUARDIAN_TARGET)) != 0;
} }
/** /**
@ -32,7 +32,7 @@ public class GuardianWatcher extends InsentientWatcher
*/ */
public void setTarget(int entityId) public void setTarget(int entityId)
{ {
setValue(FlagType.GUARDIAN_TARGET, entityId); setData(FlagType.GUARDIAN_TARGET, entityId);
sendData(FlagType.GUARDIAN_TARGET); sendData(FlagType.GUARDIAN_TARGET);
} }
@ -53,7 +53,7 @@ public class GuardianWatcher extends InsentientWatcher
if (player == null) if (player == null)
return; return;
setValue(FlagType.GUARDIAN_TARGET, player.getEntityId()); setData(FlagType.GUARDIAN_TARGET, player.getEntityId());
sendData(FlagType.GUARDIAN_TARGET); sendData(FlagType.GUARDIAN_TARGET);
} }
@ -79,20 +79,20 @@ public class GuardianWatcher extends InsentientWatcher
protected boolean isGuardianFlag(int no) protected boolean isGuardianFlag(int no)
{ {
return (getValue(FlagType.GUARDIAN_FLAG) & no) != 0; return (getData(FlagType.GUARDIAN_FLAG) & no) != 0;
} }
protected void setGuardianFlag(int no, boolean flag) protected void setGuardianFlag(int no, boolean flag)
{ {
byte b0 = getValue(FlagType.GUARDIAN_FLAG); byte b0 = getData(FlagType.GUARDIAN_FLAG);
if (flag) if (flag)
{ {
setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 | no)); setData(FlagType.GUARDIAN_FLAG, (byte) (b0 | no));
} }
else else
{ {
setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 & -(no + 1))); setData(FlagType.GUARDIAN_FLAG, (byte) (b0 & -(no + 1)));
} }
sendData(FlagType.GUARDIAN_FLAG); sendData(FlagType.GUARDIAN_FLAG);

View File

@ -0,0 +1,101 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.util.UUID;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class HorseAbstractWatcher extends AgeableWatcher {
public HorseAbstractWatcher(Disguise disguise) {
super(disguise);
}
public Optional<UUID> getOwner() {
return getData(FlagType.HORSE_OWNER);
}
public boolean hasChest() {
return isHorseFlag(8);
}
public boolean isBreedable() {
return isHorseFlag(16);
}
public boolean isGrazing() {
return isHorseFlag(32);
}
public boolean isMouthOpen() {
return isHorseFlag(128);
}
public boolean isRearing() {
return isHorseFlag(64);
}
public boolean isSaddled() {
return isHorseFlag(4);
}
public boolean isTamed() {
return isHorseFlag(2);
}
private boolean isHorseFlag(int i) {
return (getHorseFlag() & i) != 0;
}
private byte getHorseFlag() {
return getData(FlagType.HORSE_META);
}
public void setCanBreed(boolean breed) {
setHorseFlag(16, breed);
}
public void setCarryingChest(boolean chest) {
setHorseFlag(8, chest);
}
private void setHorseFlag(int i, boolean flag) {
byte j = getData(FlagType.HORSE_META);
if (flag) {
setData(FlagType.HORSE_META, (byte) (j | i));
}
else {
setData(FlagType.HORSE_META, (byte) (j & ~i));
}
sendData(FlagType.HORSE_META);
}
public void setGrazing(boolean grazing) {
setHorseFlag(32, grazing);
}
public void setMouthOpen(boolean mouthOpen) {
setHorseFlag(128, mouthOpen);
}
public void setOwner(UUID uuid) {
setData(FlagType.HORSE_OWNER, Optional.of(uuid));
sendData(FlagType.HORSE_OWNER);
}
public void setRearing(boolean rear) {
setHorseFlag(64, rear);
}
public void setSaddled(boolean saddled) {
setHorseFlag(4, saddled);
}
public void setTamed(boolean tamed) {
setHorseFlag(2, tamed);
}
}

View File

@ -0,0 +1,20 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class HorseChestedWatcher extends HorseAbstractWatcher {
public HorseChestedWatcher(Disguise disguise) {
super(disguise);
}
public void setCarryingChest(boolean carryingChest) {
setData(FlagType.HORSE_CARRYING_CHEST, carryingChest);
sendData(FlagType.HORSE_CARRYING_CHEST);
}
public boolean isCarryingChest() {
return getData(FlagType.HORSE_CARRYING_CHEST);
}
}

View File

@ -1,61 +1,30 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import java.util.UUID;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Horse.Color; import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style; import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.Horse.Variant;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class HorseWatcher extends AgeableWatcher public class HorseWatcher extends HorseAbstractWatcher {
{ public HorseWatcher(Disguise disguise) {
public HorseWatcher(Disguise disguise)
{
super(disguise); super(disguise);
setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]); setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]);
setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]); setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]);
} }
public Variant getVariant() public Color getColor() {
{ return Color.values()[((Integer) getData(FlagType.HORSE_COLOR) & 0xFF)];
return Variant.values()[getValue(FlagType.HORSE_VARIANT)];
} }
public void setVariant(Variant variant) public ItemStack getHorseArmor() {
{
setVariant(variant.ordinal());
}
public void setVariant(int variant)
{
if (variant < 0 || variant > 4)
{
variant = 0; // Crashing people is mean
}
setValue(FlagType.HORSE_VARIANT, variant);
sendData(FlagType.HORSE_VARIANT);
}
public Color getColor()
{
return Color.values()[((Integer) getValue(FlagType.HORSE_COLOR) & 0xFF)];
}
public ItemStack getHorseArmor()
{
int horseValue = getHorseArmorAsInt(); int horseValue = getHorseArmorAsInt();
switch (horseValue) switch (horseValue) {
{
case 1: case 1:
return new ItemStack(Material.IRON_BARDING); return new ItemStack(Material.IRON_BARDING);
case 2: case 2:
@ -69,127 +38,42 @@ public class HorseWatcher extends AgeableWatcher
return null; return null;
} }
protected int getHorseArmorAsInt() public Style getStyle() {
{ return Style.values()[(getData(FlagType.HORSE_COLOR) >>> 8)];
return getValue(FlagType.HORSE_ARMOR);
} }
public Optional<UUID> getOwner() public void setColor(Color color) {
{ setData(FlagType.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
return getValue(FlagType.HORSE_OWNER);
}
public Style getStyle()
{
return Style.values()[(getValue(FlagType.HORSE_COLOR) >>> 8)];
}
public boolean hasChest()
{
return isHorseFlag(8);
}
public boolean isBreedable()
{
return isHorseFlag(16);
}
public boolean isGrazing()
{
return isHorseFlag(32);
}
public boolean isMouthOpen()
{
return isHorseFlag(128);
}
public boolean isRearing()
{
return isHorseFlag(64);
}
public boolean isSaddled()
{
return isHorseFlag(4);
}
public boolean isTamed()
{
return isHorseFlag(2);
}
private boolean isHorseFlag(int i)
{
return (getHorseFlag() & i) != 0;
}
private byte getHorseFlag()
{
return getValue(FlagType.HORSE_META);
}
public void setCanBreed(boolean breed)
{
setHorseFlag(16, breed);
}
public void setCarryingChest(boolean chest)
{
setHorseFlag(8, chest);
}
public void setColor(Color color)
{
setValue(FlagType.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
sendData(FlagType.HORSE_COLOR); sendData(FlagType.HORSE_COLOR);
} }
private void setHorseFlag(int i, boolean flag) protected int getHorseArmorAsInt() {
{ return getData(FlagType.HORSE_ARMOR);
byte j = getValue(FlagType.HORSE_META);
if (flag)
{
setValue(FlagType.HORSE_META, (byte) (j | i));
}
else
{
setValue(FlagType.HORSE_META, (byte) (j & ~i));
} }
sendData(FlagType.HORSE_META); protected void setHorseArmor(int armor) {
} setData(FlagType.HORSE_ARMOR, armor);
public void setGrazing(boolean grazing)
{
setHorseFlag(32, grazing);
}
protected void setHorseArmor(int armor)
{
setValue(FlagType.HORSE_ARMOR, armor);
sendData(FlagType.HORSE_ARMOR); sendData(FlagType.HORSE_ARMOR);
} }
public void setHorseArmor(ItemStack item) public void setStyle(Style style) {
{ setData(FlagType.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8);
sendData(FlagType.HORSE_COLOR);
}
public void setHorseArmor(ItemStack item) {
int value = 0; int value = 0;
if (item != null) if (item != null) {
{
Material mat = item.getType(); Material mat = item.getType();
if (mat == Material.IRON_BARDING) if (mat == Material.IRON_BARDING) {
{
value = 1; value = 1;
} }
else if (mat == Material.GOLD_BARDING) else if (mat == Material.GOLD_BARDING) {
{
value = 2; value = 2;
} }
else if (mat == Material.DIAMOND_BARDING) else if (mat == Material.DIAMOND_BARDING) {
{
value = 3; value = 3;
} }
} }
@ -197,36 +81,4 @@ public class HorseWatcher extends AgeableWatcher
setHorseArmor(value); setHorseArmor(value);
} }
public void setMouthOpen(boolean mouthOpen)
{
setHorseFlag(128, mouthOpen);
}
public void setOwner(UUID uuid)
{
setValue(FlagType.HORSE_OWNER, Optional.of(uuid));
sendData(FlagType.HORSE_OWNER);
}
public void setRearing(boolean rear)
{
setHorseFlag(64, rear);
}
public void setSaddled(boolean saddled)
{
setHorseFlag(4, saddled);
}
public void setStyle(Style style)
{
setValue(FlagType.HORSE_COLOR, getColor().ordinal() & 0xFF | style.ordinal() << 8);
sendData(FlagType.HORSE_COLOR);
}
public void setTamed(boolean tamed)
{
setHorseFlag(2, tamed);
}
} }

View File

@ -36,20 +36,20 @@ public class InsentientWatcher extends LivingWatcher
private void setInsentientFlag(int i, boolean flag) private void setInsentientFlag(int i, boolean flag)
{ {
byte b0 = (byte) getValue(FlagType.INSENTIENT_META); byte b0 = (byte) getData(FlagType.INSENTIENT_META);
if (flag) if (flag)
{ {
setValue(FlagType.INSENTIENT_META, (byte) (b0 | 1 << i)); setData(FlagType.INSENTIENT_META, (byte) (b0 | 1 << i));
} }
else else
{ {
setValue(FlagType.INSENTIENT_META, (byte) (b0 & (~1 << i))); setData(FlagType.INSENTIENT_META, (byte) (b0 & (~1 << i)));
} }
} }
private boolean getInsentientFlag(int i) private boolean getInsentientFlag(int i)
{ {
return ((byte) getValue(FlagType.INSENTIENT_META) & 1 << i) != 0; return ((byte) getData(FlagType.INSENTIENT_META) & 1 << i) != 0;
} }
} }

View File

@ -18,17 +18,17 @@ public class ItemFrameWatcher extends FlagWatcher
public ItemStack getItem() public ItemStack getItem()
{ {
if (getValue(FlagType.ITEMFRAME_ITEM) == null) if (getData(FlagType.ITEMFRAME_ITEM) == null)
{ {
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);
} }
return (ItemStack) getValue(FlagType.ITEMFRAME_ITEM).get(); return (ItemStack) getData(FlagType.ITEMFRAME_ITEM).get();
} }
public int getRotation() public int getRotation()
{ {
return getValue(FlagType.ITEMFRAME_ROTATION); return getData(FlagType.ITEMFRAME_ROTATION);
} }
public void setItem(ItemStack newItem) public void setItem(ItemStack newItem)
@ -41,13 +41,13 @@ public class ItemFrameWatcher extends FlagWatcher
newItem = newItem.clone(); newItem = newItem.clone();
newItem.setAmount(1); newItem.setAmount(1);
setValue(FlagType.ITEMFRAME_ITEM, Optional.<ItemStack> of(newItem)); setData(FlagType.ITEMFRAME_ITEM, Optional.<ItemStack> of(newItem));
sendData(FlagType.ITEMFRAME_ITEM); sendData(FlagType.ITEMFRAME_ITEM);
} }
public void setRotation(int rotation) public void setRotation(int rotation)
{ {
setValue(FlagType.ITEMFRAME_ROTATION, rotation % 4); setData(FlagType.ITEMFRAME_ROTATION, rotation % 4);
sendData(FlagType.ITEMFRAME_ROTATION); sendData(FlagType.ITEMFRAME_ROTATION);
} }

View File

@ -82,7 +82,7 @@ public class LivingWatcher extends FlagWatcher
public float getHealth() public float getHealth()
{ {
return (float) getValue(FlagType.LIVING_HEALTH); return (float) getData(FlagType.LIVING_HEALTH);
} }
public double getMaxHealth() public double getMaxHealth()
@ -92,7 +92,7 @@ public class LivingWatcher extends FlagWatcher
public boolean isPotionParticlesAmbient() public boolean isPotionParticlesAmbient()
{ {
return (boolean) getValue(FlagType.LIVING_POTION_AMBIENT); return (boolean) getData(FlagType.LIVING_POTION_AMBIENT);
} }
private int getPotions() private int getPotions()
@ -152,30 +152,30 @@ public class LivingWatcher extends FlagWatcher
public void setPotionParticlesAmbient(boolean particles) public void setPotionParticlesAmbient(boolean particles)
{ {
setValue(FlagType.LIVING_POTION_AMBIENT, particles); setData(FlagType.LIVING_POTION_AMBIENT, particles);
sendData(FlagType.LIVING_POTION_AMBIENT); sendData(FlagType.LIVING_POTION_AMBIENT);
} }
private void sendPotionEffects() private void sendPotionEffects()
{ {
setValue(FlagType.LIVING_POTIONS, getPotions()); setData(FlagType.LIVING_POTIONS, getPotions());
sendData(FlagType.LIVING_POTIONS); sendData(FlagType.LIVING_POTIONS);
} }
public void setHealth(float health) public void setHealth(float health)
{ {
setValue(FlagType.LIVING_HEALTH, health); setData(FlagType.LIVING_HEALTH, health);
sendData(FlagType.LIVING_HEALTH); sendData(FlagType.LIVING_HEALTH);
} }
public int getArrowsSticking() public int getArrowsSticking()
{ {
return (int) getValue(FlagType.LIVING_ARROWS); return (int) getData(FlagType.LIVING_ARROWS);
} }
public void setArrowsSticking(int arrowsNo) public void setArrowsSticking(int arrowsNo)
{ {
setValue(FlagType.LIVING_ARROWS, arrowsNo); setData(FlagType.LIVING_ARROWS, arrowsNo);
sendData(FlagType.LIVING_ARROWS); sendData(FlagType.LIVING_ARROWS);
} }

View File

@ -0,0 +1,42 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.entity.Llama;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class LlamaWatcher extends HorseChestedWatcher {
public LlamaWatcher(Disguise disguise) {
super(disguise);
}
public void setColor(Llama.Color color) {
setData(FlagType.LLAMA_COLOR, color.ordinal());
sendData(FlagType.LLAMA_COLOR);
}
public Llama.Color getColor() {
return Llama.Color.values()[getData(FlagType.LLAMA_COLOR)];
}
public void setCarpet(AnimalColor color) {
setData(FlagType.LLAMA_CARPET, color.ordinal());
sendData(FlagType.LLAMA_CARPET);
}
public AnimalColor getCarpet() {
return AnimalColor.getColor(getData(FlagType.LLAMA_CARPET));
}
public void setStrength(int strength) {
setData(FlagType.LLAMA_STRENGTH, strength);
sendData(FlagType.LLAMA_STRENGTH);
}
public int getStrength() {
return getData(FlagType.LLAMA_STRENGTH);
}
}

View File

@ -16,20 +16,20 @@ public class MinecartWatcher extends FlagWatcher
public ItemStack getBlockInCart() public ItemStack getBlockInCart()
{ {
int id = (int) getValue(FlagType.MINECART_BLOCK) & 0xffff; int id = (int) getData(FlagType.MINECART_BLOCK) & 0xffff;
int data = (int) getValue(FlagType.MINECART_BLOCK) >> 16; int data = (int) getData(FlagType.MINECART_BLOCK) >> 16;
return new ItemStack(id, 1, (short) data); return new ItemStack(id, 1, (short) data);
} }
public int getBlockYOffset() public int getBlockYOffset()
{ {
return (int) getValue(FlagType.MINECART_BLOCK_Y); return (int) getData(FlagType.MINECART_BLOCK_Y);
} }
public boolean isViewBlockInCart() public boolean isViewBlockInCart()
{ {
return (boolean) getValue(FlagType.MINECART_BLOCK_VISIBLE); return (boolean) getData(FlagType.MINECART_BLOCK_VISIBLE);
} }
public void setBlockInCart(ItemStack item) public void setBlockInCart(ItemStack item)
@ -37,21 +37,21 @@ public class MinecartWatcher extends FlagWatcher
int id = item.getTypeId(); int id = item.getTypeId();
int data = item.getDurability(); int data = item.getDurability();
setValue(FlagType.MINECART_BLOCK, id & 0xffff | data << 16); setData(FlagType.MINECART_BLOCK, id & 0xffff | data << 16);
setValue(FlagType.MINECART_BLOCK_VISIBLE, true); // Show block setData(FlagType.MINECART_BLOCK_VISIBLE, true); // Show block
sendData(FlagType.MINECART_BLOCK); sendData(FlagType.MINECART_BLOCK);
} }
public void setBlockOffset(int i) public void setBlockOffset(int i)
{ {
setValue(FlagType.MINECART_BLOCK_Y, i); setData(FlagType.MINECART_BLOCK_Y, i);
sendData(FlagType.MINECART_BLOCK_Y); sendData(FlagType.MINECART_BLOCK_Y);
} }
public void setViewBlockInCart(boolean viewBlock) public void setViewBlockInCart(boolean viewBlock)
{ {
setValue(FlagType.MINECART_BLOCK_VISIBLE, viewBlock); setData(FlagType.MINECART_BLOCK_VISIBLE, viewBlock);
sendData(FlagType.MINECART_BLOCK_VISIBLE); sendData(FlagType.MINECART_BLOCK_VISIBLE);
} }
} }

View File

@ -0,0 +1,11 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class MuleWatcher extends HorseChestedWatcher {
public MuleWatcher(Disguise disguise) {
super(disguise);
}
}

View File

@ -16,12 +16,12 @@ public class OcelotWatcher extends TameableWatcher
public Type getType() public Type getType()
{ {
return Ocelot.Type.getType(getValue(FlagType.OCELOT_TYPE)); return Ocelot.Type.getType(getData(FlagType.OCELOT_TYPE));
} }
public void setType(Type newType) public void setType(Type newType)
{ {
setValue(FlagType.OCELOT_TYPE, newType.getId()); setData(FlagType.OCELOT_TYPE, newType.getId());
sendData(FlagType.OCELOT_TYPE); sendData(FlagType.OCELOT_TYPE);
} }
} }

View File

@ -13,12 +13,12 @@ public class PigWatcher extends AgeableWatcher
public boolean isSaddled() public boolean isSaddled()
{ {
return (boolean) getValue(FlagType.PIG_SADDLED); return (boolean) getData(FlagType.PIG_SADDLED);
} }
public void setSaddled(boolean isSaddled) public void setSaddled(boolean isSaddled)
{ {
setValue(FlagType.PIG_SADDLED, isSaddled); setData(FlagType.PIG_SADDLED, isSaddled);
sendData(FlagType.PIG_SADDLED); sendData(FlagType.PIG_SADDLED);
} }
} }

View File

@ -26,7 +26,7 @@ public class PlayerWatcher extends LivingWatcher
{ {
super(disguise); super(disguise);
setValue(FlagType.PLAYER_SKIN, FlagType.PLAYER_SKIN.getDefault()); setData(FlagType.PLAYER_SKIN, FlagType.PLAYER_SKIN.getDefault());
} }
@Override @Override
@ -39,13 +39,13 @@ public class PlayerWatcher extends LivingWatcher
public void setMainHand(MainHand mainHand) public void setMainHand(MainHand mainHand)
{ {
setValue(FlagType.PLAYER_HAND, (byte) mainHand.ordinal()); setData(FlagType.PLAYER_HAND, (byte) mainHand.ordinal());
sendData(FlagType.PLAYER_HAND); sendData(FlagType.PLAYER_HAND);
} }
public MainHand getMainHand() public MainHand getMainHand()
{ {
return MainHand.values()[getValue(FlagType.PLAYER_HAND)]; return MainHand.values()[getData(FlagType.PLAYER_HAND)];
} }
public BlockFace getSleepingDirection() public BlockFace getSleepingDirection()
@ -75,7 +75,7 @@ public class PlayerWatcher extends LivingWatcher
private boolean isSkinFlag(int i) private boolean isSkinFlag(int i)
{ {
return ((byte) getValue(FlagType.PLAYER_SKIN) & 1 << i) != 0; return ((byte) getData(FlagType.PLAYER_SKIN) & 1 << i) != 0;
} }
public boolean isCapeEnabled() public boolean isCapeEnabled()
@ -257,15 +257,15 @@ public class PlayerWatcher extends LivingWatcher
private void setSkinFlags(int i, boolean flag) private void setSkinFlags(int i, boolean flag)
{ {
byte b0 = (byte) getValue(FlagType.PLAYER_SKIN); byte b0 = (byte) getData(FlagType.PLAYER_SKIN);
if (flag) if (flag)
{ {
setValue(FlagType.PLAYER_SKIN, (byte) (b0 | 1 << i)); setData(FlagType.PLAYER_SKIN, (byte) (b0 | 1 << i));
} }
else else
{ {
setValue(FlagType.PLAYER_SKIN, (byte) (b0 & (~1 << i))); setData(FlagType.PLAYER_SKIN, (byte) (b0 & (~1 << i)));
} }
} }

View File

@ -12,12 +12,12 @@ public class PolarBearWatcher extends AgeableWatcher
public void setStanding(boolean standing) public void setStanding(boolean standing)
{ {
setValue(FlagType.POLAR_BEAR_STANDING, standing); setData(FlagType.POLAR_BEAR_STANDING, standing);
sendData(FlagType.POLAR_BEAR_STANDING); sendData(FlagType.POLAR_BEAR_STANDING);
} }
public boolean isStanding() public boolean isStanding()
{ {
return getValue(FlagType.POLAR_BEAR_STANDING); return getData(FlagType.POLAR_BEAR_STANDING);
} }
} }

View File

@ -16,12 +16,12 @@ public class RabbitWatcher extends AgeableWatcher
public RabbitType getType() public RabbitType getType()
{ {
return RabbitType.getType((int) getValue(FlagType.RABBIT_TYPE)); return RabbitType.getType((int) getData(FlagType.RABBIT_TYPE));
} }
public void setType(RabbitType type) public void setType(RabbitType type)
{ {
setValue(FlagType.RABBIT_TYPE, type.getTypeId()); setData(FlagType.RABBIT_TYPE, type.getTypeId());
sendData(FlagType.RABBIT_TYPE); sendData(FlagType.RABBIT_TYPE);
} }

View File

@ -13,17 +13,17 @@ public class SheepWatcher extends AgeableWatcher
{ {
super(disguise); super(disguise);
setValue(FlagType.SHEEP_WOOL, (byte) 0); setData(FlagType.SHEEP_WOOL, (byte) 0);
} }
public AnimalColor getColor() public AnimalColor getColor()
{ {
return AnimalColor.getColor(((int) getValue(FlagType.SHEEP_WOOL) & 15)); return AnimalColor.getColor(((int) getData(FlagType.SHEEP_WOOL) & 15));
} }
public boolean isSheared() public boolean isSheared()
{ {
return ((byte) getValue(FlagType.SHEEP_WOOL) & 16) != 0; return ((byte) getData(FlagType.SHEEP_WOOL) & 16) != 0;
} }
public void setColor(AnimalColor color) public void setColor(AnimalColor color)
@ -33,23 +33,23 @@ public class SheepWatcher extends AgeableWatcher
public void setColor(DyeColor color) public void setColor(DyeColor color)
{ {
byte b0 = (byte) getValue(FlagType.SHEEP_WOOL); byte b0 = (byte) getData(FlagType.SHEEP_WOOL);
setValue(FlagType.SHEEP_WOOL, (byte) (b0 & 240 | color.getWoolData() & 15)); setData(FlagType.SHEEP_WOOL, (byte) (b0 & 240 | color.getWoolData() & 15));
sendData(FlagType.SHEEP_WOOL); sendData(FlagType.SHEEP_WOOL);
} }
public void setSheared(boolean flag) public void setSheared(boolean flag)
{ {
byte b0 = (byte) getValue(FlagType.SHEEP_WOOL); byte b0 = (byte) getData(FlagType.SHEEP_WOOL);
if (flag) if (flag)
{ {
setValue(FlagType.SHEEP_WOOL, (byte) (b0 | 16)); setData(FlagType.SHEEP_WOOL, (byte) (b0 | 16));
} }
else else
{ {
setValue(FlagType.SHEEP_WOOL, (byte) (b0 & -17)); setData(FlagType.SHEEP_WOOL, (byte) (b0 & -17));
} }
sendData(FlagType.SHEEP_WOOL); sendData(FlagType.SHEEP_WOOL);

View File

@ -6,57 +6,54 @@ import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction; import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagType;
/** /**
* @author Navid * @author Navid
*/ */
public class ShulkerWatcher extends InsentientWatcher public class ShulkerWatcher extends InsentientWatcher {
{
public ShulkerWatcher(Disguise disguise) public ShulkerWatcher(Disguise disguise) {
{
super(disguise); super(disguise);
} }
public BlockFace getFacingDirection() public BlockFace getFacingDirection() {
{ return BlockFace.valueOf(getData(FlagType.SHULKER_FACING).name());
return BlockFace.valueOf(getValue(FlagType.SHULKER_FACING).name());
} }
public void setFacingDirection(BlockFace face) public void setFacingDirection(BlockFace face) {
{ setData(FlagType.SHULKER_FACING, Direction.valueOf(face.name()));
setValue(FlagType.SHULKER_FACING, Direction.valueOf(face.name()));
sendData(FlagType.SHULKER_FACING); sendData(FlagType.SHULKER_FACING);
} }
public BlockPosition getAttachmentPosition() public BlockPosition getAttachmentPosition() {
{ return getData(FlagType.SHULKER_ATTACHED).get();
return getValue(FlagType.SHULKER_ATTACHED).get();
} }
public void setAttachmentPosition(BlockPosition pos) public void setAttachmentPosition(BlockPosition pos) {
{ setData(FlagType.SHULKER_ATTACHED, Optional.of(pos));
setValue(FlagType.SHULKER_ATTACHED, Optional.of(pos));
sendData(FlagType.SHULKER_ATTACHED); sendData(FlagType.SHULKER_ATTACHED);
} }
public int getShieldHeight() public int getShieldHeight() {
{ return getData(FlagType.SHULKER_PEEKING);
return getValue(FlagType.SHULKER_PEEKING);
} }
public void setShieldHeight(int newHeight) public void setShieldHeight(int newHeight) {
{
if (newHeight < 0) if (newHeight < 0)
newHeight = 0; newHeight = 0;
if (newHeight > 127) if (newHeight > 127)
newHeight = 127; newHeight = 127;
setValue(FlagType.SHULKER_PEEKING, (byte) newHeight); setData(FlagType.SHULKER_PEEKING, (byte) newHeight);
sendData(FlagType.SHULKER_PEEKING); sendData(FlagType.SHULKER_PEEKING);
} }
public void setColor(AnimalColor color) {
setData(FlagType.SHULKER_COLOR, (byte) color.getId());
sendData(FlagType.SHULKER_COLOR);
}
} }

View File

@ -0,0 +1,11 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class SkeletonHorseWatcher extends HorseAbstractWatcher {
public SkeletonHorseWatcher(Disguise disguise) {
super(disguise);
}
}

View File

@ -17,23 +17,23 @@ public class SkeletonWatcher extends InsentientWatcher
public void setSwingArms(boolean swingingArms) public void setSwingArms(boolean swingingArms)
{ {
setValue(FlagType.SKELETON_SWING_ARMS, swingingArms); setData(FlagType.SKELETON_SWING_ARMS, swingingArms);
sendData(FlagType.SKELETON_SWING_ARMS); sendData(FlagType.SKELETON_SWING_ARMS);
} }
public boolean isSwingArms() public boolean isSwingArms()
{ {
return getValue(FlagType.SKELETON_SWING_ARMS); return getData(FlagType.SKELETON_SWING_ARMS);
} }
public void setType(SkeletonType type) public void setType(SkeletonType type)
{ {
setValue(FlagType.SKELETON_TYPE, type.ordinal()); setData(FlagType.SKELETON_TYPE, type.ordinal());
sendData(FlagType.SKELETON_TYPE); sendData(FlagType.SKELETON_TYPE);
} }
public SkeletonType getType() public SkeletonType getType()
{ {
return SkeletonType.values()[getValue(FlagType.SKELETON_TYPE)]; return SkeletonType.values()[getData(FlagType.SKELETON_TYPE)];
} }
} }

View File

@ -15,7 +15,7 @@ public class SlimeWatcher extends InsentientWatcher
public int getSize() public int getSize()
{ {
return (int) getValue(FlagType.SLIME_SIZE); return (int) getData(FlagType.SLIME_SIZE);
} }
public void setSize(int size) public void setSize(int size)
@ -25,7 +25,7 @@ public class SlimeWatcher extends InsentientWatcher
size = 1; size = 1;
} }
setValue(FlagType.SLIME_SIZE, size); setData(FlagType.SLIME_SIZE, size);
sendData(FlagType.SLIME_SIZE); sendData(FlagType.SLIME_SIZE);
} }

View File

@ -12,12 +12,12 @@ public class SnowmanWatcher extends InsentientWatcher
public void setHat(boolean hat) public void setHat(boolean hat)
{ {
setValue(FlagType.SNOWMAN_HAT, (byte) (hat ? 0 : 16)); setData(FlagType.SNOWMAN_HAT, (byte) (hat ? 0 : 16));
sendData(FlagType.SNOWMAN_HAT); sendData(FlagType.SNOWMAN_HAT);
} }
public boolean isHat() public boolean isHat()
{ {
return getValue(FlagType.SNOWMAN_HAT) == 0; return getData(FlagType.SNOWMAN_HAT) == 0;
} }
} }

View File

@ -12,12 +12,12 @@ public class SpiderWatcher extends InsentientWatcher
public void setClimbing(boolean climbing) public void setClimbing(boolean climbing)
{ {
setValue(FlagType.SPIDER_CLIMB, (byte) (climbing ? 1 : 0)); setData(FlagType.SPIDER_CLIMB, (byte) (climbing ? 1 : 0));
sendData(FlagType.SPIDER_CLIMB); sendData(FlagType.SPIDER_CLIMB);
} }
public boolean isClimbing() public boolean isClimbing()
{ {
return getValue(FlagType.SPIDER_CLIMB) == (byte) 1; return getData(FlagType.SPIDER_CLIMB) == (byte) 1;
} }
} }

View File

@ -34,13 +34,13 @@ public class SplashPotionWatcher extends FlagWatcher
public void setSplashPotion(ItemStack item) public void setSplashPotion(ItemStack item)
{ {
setValue(FlagType.SPLASH_POTION_ITEM, Optional.of(item)); setData(FlagType.SPLASH_POTION_ITEM, Optional.of(item));
sendData(FlagType.SPLASH_POTION_ITEM); sendData(FlagType.SPLASH_POTION_ITEM);
} }
public ItemStack getSplashPotion() public ItemStack getSplashPotion()
{ {
return getValue(FlagType.SPLASH_POTION_ITEM).get(); return getData(FlagType.SPLASH_POTION_ITEM).get();
} }
public void setPotionId(int newPotionId) public void setPotionId(int newPotionId)

View File

@ -16,7 +16,7 @@ public class TameableWatcher extends AgeableWatcher
public Optional<UUID> getOwner() public Optional<UUID> getOwner()
{ {
return getValue(FlagType.TAMEABLE_OWNER); return getData(FlagType.TAMEABLE_OWNER);
} }
public boolean isSitting() public boolean isSitting()
@ -31,20 +31,20 @@ public class TameableWatcher extends AgeableWatcher
protected boolean isTameableFlag(int no) protected boolean isTameableFlag(int no)
{ {
return ((byte) getValue(FlagType.TAMEABLE_META) & no) != 0; return ((byte) getData(FlagType.TAMEABLE_META) & no) != 0;
} }
protected void setTameableFlag(int no, boolean flag) protected void setTameableFlag(int no, boolean flag)
{ {
byte value = (byte) getValue(FlagType.TAMEABLE_META); byte value = (byte) getData(FlagType.TAMEABLE_META);
if (flag) if (flag)
{ {
setValue(FlagType.TAMEABLE_META, (byte) (value | no)); setData(FlagType.TAMEABLE_META, (byte) (value | no));
} }
else else
{ {
setValue(FlagType.TAMEABLE_META, (byte) (value & -(no + 1))); setData(FlagType.TAMEABLE_META, (byte) (value & -(no + 1)));
} }
sendData(FlagType.TAMEABLE_META); sendData(FlagType.TAMEABLE_META);
@ -52,7 +52,7 @@ public class TameableWatcher extends AgeableWatcher
public void setOwner(UUID owner) public void setOwner(UUID owner)
{ {
setValue(FlagType.TAMEABLE_OWNER, Optional.of(owner)); setData(FlagType.TAMEABLE_OWNER, Optional.of(owner));
sendData(FlagType.TAMEABLE_OWNER); sendData(FlagType.TAMEABLE_OWNER);
} }

View File

@ -25,13 +25,13 @@ public class TippedArrowWatcher extends ArrowWatcher
public Color getColor() public Color getColor()
{ {
int color = (int) getValue(FlagType.TIPPED_ARROW_COLOR); int color = (int) getData(FlagType.TIPPED_ARROW_COLOR);
return Color.fromRGB(color); return Color.fromRGB(color);
} }
public void setColor(Color color) public void setColor(Color color)
{ {
setValue(FlagType.TIPPED_ARROW_COLOR, color.asRGB()); setData(FlagType.TIPPED_ARROW_COLOR, color.asRGB());
sendData(FlagType.TIPPED_ARROW_COLOR); sendData(FlagType.TIPPED_ARROW_COLOR);
} }
} }

View File

@ -0,0 +1,21 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class VexWatcher extends InsentientWatcher {
public VexWatcher(Disguise disguise) {
super(disguise);
}
public void setAngry(boolean angry) {
setData(FlagType.VEX_ANGRY, angry);
sendData(FlagType.VEX_ANGRY);
}
public boolean isAngry() {
return getData(FlagType.VEX_ANGRY);
}
}

View File

@ -17,12 +17,12 @@ public class VillagerWatcher extends AgeableWatcher
public Profession getProfession() public Profession getProfession()
{ {
return Profession.values()[getValue(FlagType.VILLAGER_PROFESSION)]; return Profession.values()[getData(FlagType.VILLAGER_PROFESSION)];
} }
public void setProfession(int professionId) public void setProfession(int professionId)
{ {
setValue(FlagType.VILLAGER_PROFESSION, professionId); setData(FlagType.VILLAGER_PROFESSION, professionId);
sendData(FlagType.VILLAGER_PROFESSION); sendData(FlagType.VILLAGER_PROFESSION);
} }

View File

@ -0,0 +1,17 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagType;
public class VindicatorWatcher extends InsentientWatcher {
public VindicatorWatcher(Disguise disguise) {
super(disguise);
}
public void setJohnny(boolean isJohnny) {
setData(FlagType.VINDICATOR_JOHNNY, (byte) (isJohnny ? 1 : 0));
sendData(FlagType.VINDICATOR_JOHNNY);
}
}

View File

@ -16,12 +16,12 @@ public class WitchWatcher extends InsentientWatcher
public boolean isAggressive() public boolean isAggressive()
{ {
return (boolean) getValue(FlagType.WITCH_AGGRESSIVE); return (boolean) getData(FlagType.WITCH_AGGRESSIVE);
} }
public void setAggressive(boolean aggressive) public void setAggressive(boolean aggressive)
{ {
setValue(FlagType.WITCH_AGGRESSIVE, aggressive); setData(FlagType.WITCH_AGGRESSIVE, aggressive);
sendData(FlagType.WITCH_AGGRESSIVE); sendData(FlagType.WITCH_AGGRESSIVE);
} }

View File

@ -14,12 +14,12 @@ public class WitherSkullWatcher extends FlagWatcher
public boolean isBlue() public boolean isBlue()
{ {
return (boolean) getValue(FlagType.WITHERSKULL_BLUE); return (boolean) getData(FlagType.WITHERSKULL_BLUE);
} }
public void setBlue(boolean blue) public void setBlue(boolean blue)
{ {
setValue(FlagType.WITHERSKULL_BLUE, blue); setData(FlagType.WITHERSKULL_BLUE, blue);
sendData(FlagType.WITHERSKULL_BLUE); sendData(FlagType.WITHERSKULL_BLUE);
} }

View File

@ -22,14 +22,14 @@ public class WitherWatcher extends InsentientWatcher
*/ */
public int getInvulnerability() public int getInvulnerability()
{ {
return (int) getValue(FlagType.WITHER_INVUL); return (int) getData(FlagType.WITHER_INVUL);
} }
public int[] getTargets() public int[] getTargets()
{ {
return new int[] return new int[]
{ {
getValue(FlagType.WITHER_TARGET_1), getValue(FlagType.WITHER_TARGET_2), getValue(FlagType.WITHER_TARGET_3) getData(FlagType.WITHER_TARGET_1), getData(FlagType.WITHER_TARGET_2), getData(FlagType.WITHER_TARGET_3)
}; };
} }
@ -38,7 +38,7 @@ public class WitherWatcher extends InsentientWatcher
*/ */
public void setInvulnerability(int invulnerability) public void setInvulnerability(int invulnerability)
{ {
setValue(FlagType.WITHER_INVUL, invulnerability); setData(FlagType.WITHER_INVUL, invulnerability);
sendData(FlagType.WITHER_INVUL); sendData(FlagType.WITHER_INVUL);
} }
@ -49,9 +49,9 @@ public class WitherWatcher extends InsentientWatcher
throw new InvalidParameterException( throw new InvalidParameterException(
ChatColor.RED + "Expected 3 numbers for wither setTargets. Received " + targets.length); ChatColor.RED + "Expected 3 numbers for wither setTargets. Received " + targets.length);
} }
setValue(FlagType.WITHER_TARGET_1, targets[0]); setData(FlagType.WITHER_TARGET_1, targets[0]);
setValue(FlagType.WITHER_TARGET_2, targets[1]); setData(FlagType.WITHER_TARGET_2, targets[1]);
setValue(FlagType.WITHER_TARGET_3, targets[2]); setData(FlagType.WITHER_TARGET_3, targets[2]);
sendData(FlagType.WITHER_TARGET_1, FlagType.WITHER_TARGET_2, FlagType.WITHER_TARGET_3); sendData(FlagType.WITHER_TARGET_1, FlagType.WITHER_TARGET_2, FlagType.WITHER_TARGET_3);
} }

View File

@ -16,7 +16,7 @@ public class WolfWatcher extends TameableWatcher
public AnimalColor getCollarColor() public AnimalColor getCollarColor()
{ {
return AnimalColor.getColor(getValue(FlagType.WOLF_COLLAR)); return AnimalColor.getColor(getData(FlagType.WOLF_COLLAR));
} }
/** /**
@ -26,7 +26,7 @@ public class WolfWatcher extends TameableWatcher
*/ */
public float getDamageTaken() public float getDamageTaken()
{ {
return (float) getValue(FlagType.WOLF_DAMAGE); return (float) getData(FlagType.WOLF_DAMAGE);
} }
/** /**
@ -36,18 +36,18 @@ public class WolfWatcher extends TameableWatcher
*/ */
public void setDamageTaken(float damage) public void setDamageTaken(float damage)
{ {
setValue(FlagType.WOLF_DAMAGE, damage); setData(FlagType.WOLF_DAMAGE, damage);
sendData(FlagType.WOLF_DAMAGE); sendData(FlagType.WOLF_DAMAGE);
} }
public boolean isBegging() public boolean isBegging()
{ {
return (boolean) getValue(FlagType.WOLF_BEGGING); return (boolean) getData(FlagType.WOLF_BEGGING);
} }
public void setBegging(boolean begging) public void setBegging(boolean begging)
{ {
setValue(FlagType.WOLF_BEGGING, begging); setData(FlagType.WOLF_BEGGING, begging);
sendData(FlagType.WOLF_BEGGING); sendData(FlagType.WOLF_BEGGING);
} }
@ -78,7 +78,7 @@ public class WolfWatcher extends TameableWatcher
return; return;
} }
setValue(FlagType.WOLF_COLLAR, (int) newColor.getDyeData()); setData(FlagType.WOLF_COLLAR, (int) newColor.getDyeData());
sendData(FlagType.WOLF_COLLAR); sendData(FlagType.WOLF_COLLAR);
} }

View File

@ -0,0 +1,11 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class ZombieHorseWatcher extends HorseAbstractWatcher {
public ZombieHorseWatcher(Disguise disguise) {
super(disguise);
}
}

View File

@ -20,12 +20,12 @@ public class ZombieWatcher extends InsentientWatcher
public boolean isBaby() public boolean isBaby()
{ {
return getValue(FlagType.ZOMBIE_BABY); return getData(FlagType.ZOMBIE_BABY);
} }
public boolean isShaking() public boolean isShaking()
{ {
return getValue(FlagType.ZOMBIE_SHAKING); return getData(FlagType.ZOMBIE_SHAKING);
} }
/** /**
@ -35,12 +35,12 @@ public class ZombieWatcher extends InsentientWatcher
*/ */
public boolean isVillager() public boolean isVillager()
{ {
return ((int) getValue(FlagType.ZOMBIE_PROFESSION)) != 0; return ((int) getData(FlagType.ZOMBIE_PROFESSION)) != 0;
} }
public boolean isAggressive() public boolean isAggressive()
{ {
return (boolean) getValue(FlagType.ZOMBIE_AGGRESSIVE); return (boolean) getData(FlagType.ZOMBIE_AGGRESSIVE);
} }
/** /**
@ -50,7 +50,7 @@ public class ZombieWatcher extends InsentientWatcher
*/ */
public Profession getProfession() public Profession getProfession()
{ {
return Profession.values()[getValue(FlagType.ZOMBIE_PROFESSION)]; return Profession.values()[getData(FlagType.ZOMBIE_PROFESSION)];
} }
public void setAdult() public void setAdult()
@ -65,13 +65,13 @@ public class ZombieWatcher extends InsentientWatcher
public void setBaby(boolean baby) public void setBaby(boolean baby)
{ {
setValue(FlagType.ZOMBIE_BABY, baby); setData(FlagType.ZOMBIE_BABY, baby);
sendData(FlagType.ZOMBIE_BABY); sendData(FlagType.ZOMBIE_BABY);
} }
public void setShaking(boolean shaking) public void setShaking(boolean shaking)
{ {
setValue(FlagType.ZOMBIE_SHAKING, shaking); setData(FlagType.ZOMBIE_SHAKING, shaking);
sendData(FlagType.ZOMBIE_SHAKING); sendData(FlagType.ZOMBIE_SHAKING);
} }
@ -82,7 +82,7 @@ public class ZombieWatcher extends InsentientWatcher
*/ */
public void setProfession(int id) public void setProfession(int id)
{ {
setValue(FlagType.ZOMBIE_PROFESSION, id); setData(FlagType.ZOMBIE_PROFESSION, id);
sendData(FlagType.ZOMBIE_PROFESSION); sendData(FlagType.ZOMBIE_PROFESSION);
} }
@ -93,13 +93,13 @@ public class ZombieWatcher extends InsentientWatcher
*/ */
public void setProfession(Profession profession) public void setProfession(Profession profession)
{ {
setValue(FlagType.ZOMBIE_PROFESSION, profession.ordinal()); setData(FlagType.ZOMBIE_PROFESSION, profession.ordinal());
sendData(FlagType.ZOMBIE_PROFESSION); sendData(FlagType.ZOMBIE_PROFESSION);
} }
public void setAggressive(boolean handsup) public void setAggressive(boolean handsup)
{ {
setValue(FlagType.ZOMBIE_AGGRESSIVE, handsup); setData(FlagType.ZOMBIE_AGGRESSIVE, handsup);
sendData(FlagType.ZOMBIE_AGGRESSIVE); sendData(FlagType.ZOMBIE_AGGRESSIVE);
} }

View File

@ -8,8 +8,7 @@ import org.bukkit.Sound;
/** /**
* Only living disguises go in here! * Only living disguises go in here!
*/ */
public enum DisguiseSound public enum DisguiseSound {
{
ARROW(null, null, null, null, Sound.ENTITY_ARROW_HIT, Sound.ENTITY_ARROW_SHOOT), ARROW(null, null, null, null, Sound.ENTITY_ARROW_HIT, Sound.ENTITY_ARROW_SHOOT),
@ -44,6 +43,13 @@ public enum DisguiseSound
ENDERMITE(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_ENDERMITE_STEP, Sound.ENTITY_ENDERMITE_DEATH, ENDERMITE(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_ENDERMITE_STEP, Sound.ENTITY_ENDERMITE_DEATH,
Sound.ENTITY_ENDERMITE_AMBIENT), Sound.ENTITY_ENDERMITE_AMBIENT),
EVOKER(Sound.ENTITY_EVOCATION_ILLAGER_HURT, null, Sound.ENTITY_EVOCATION_ILLAGER_DEATH,
Sound.ENTITY_EVOCATION_ILLAGER_AMBIENT, Sound.ENTITY_EVOCATION_ILLAGER_CAST_SPELL,
Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_ATTACK, Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_SUMMON,
Sound.ENTITY_EVOCATION_ILLAGER_PREPARE_WOLOLO),
EVOKER_FANGS(null, null, null, null, Sound.ENTITY_EVOCATION_FANGS_ATTACK),
GHAST(Sound.ENTITY_GHAST_HURT, null, Sound.ENTITY_GHAST_DEATH, Sound.ENTITY_GHAST_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL, GHAST(Sound.ENTITY_GHAST_HURT, null, Sound.ENTITY_GHAST_DEATH, Sound.ENTITY_GHAST_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
Sound.ENTITY_GHAST_SHOOT, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_GHAST_SCREAM, Sound.ENTITY_GHAST_WARN), Sound.ENTITY_GHAST_SHOOT, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_GHAST_SCREAM, Sound.ENTITY_GHAST_WARN),
@ -58,6 +64,9 @@ public enum DisguiseSound
IRON_GOLEM(Sound.ENTITY_IRONGOLEM_HURT, Sound.ENTITY_IRONGOLEM_STEP, Sound.ENTITY_IRONGOLEM_DEATH, IRON_GOLEM(Sound.ENTITY_IRONGOLEM_HURT, Sound.ENTITY_IRONGOLEM_STEP, Sound.ENTITY_IRONGOLEM_DEATH,
Sound.ENTITY_IRONGOLEM_ATTACK), Sound.ENTITY_IRONGOLEM_ATTACK),
LLAMA(Sound.ENTITY_LLAMA_HURT, Sound.ENTITY_LLAMA_STEP, Sound.ENTITY_LLAMA_DEATH, Sound.ENTITY_LLAMA_AMBIENT,
Sound.ENTITY_LLAMA_ANGRY, Sound.ENTITY_LLAMA_CHEST, Sound.ENTITY_LLAMA_EAT, Sound.ENTITY_LLAMA_SWAG),
MAGMA_CUBE(Sound.ENTITY_MAGMACUBE_HURT, Sound.ENTITY_MAGMACUBE_JUMP, null, null), MAGMA_CUBE(Sound.ENTITY_MAGMACUBE_HURT, Sound.ENTITY_MAGMACUBE_JUMP, null, null),
MULE(Sound.ENTITY_MULE_HURT, "step.grass", Sound.ENTITY_MULE_DEATH, Sound.ENTITY_MULE_AMBIENT), MULE(Sound.ENTITY_MULE_HURT, "step.grass", Sound.ENTITY_MULE_DEATH, Sound.ENTITY_MULE_AMBIENT),
@ -104,9 +113,14 @@ public enum DisguiseSound
Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD,
Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY), Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
VEX(Sound.ENTITY_VEX_HURT, null, Sound.ENTITY_VEX_DEATH, Sound.ENTITY_VEX_AMBIENT, Sound.ENTITY_VEX_CHARGE),
VILLAGER(Sound.ENTITY_VILLAGER_HURT, null, Sound.ENTITY_VILLAGER_DEATH, Sound.ENTITY_VILLAGER_AMBIENT, VILLAGER(Sound.ENTITY_VILLAGER_HURT, null, Sound.ENTITY_VILLAGER_DEATH, Sound.ENTITY_VILLAGER_AMBIENT,
Sound.ENTITY_VILLAGER_TRADING, Sound.ENTITY_VILLAGER_NO, Sound.ENTITY_VILLAGER_YES), Sound.ENTITY_VILLAGER_TRADING, Sound.ENTITY_VILLAGER_NO, Sound.ENTITY_VILLAGER_YES),
VINDICATOR(Sound.ENTITY_VINDICATION_ILLAGER_HURT, null, Sound.ENTITY_VINDICATION_ILLAGER_DEATH,
Sound.ENTITY_VINDICATION_ILLAGER_AMBIENT),
WITCH(Sound.ENTITY_WITCH_HURT, null, Sound.ENTITY_WITCH_DEATH, Sound.ENTITY_WITCH_AMBIENT), WITCH(Sound.ENTITY_WITCH_HURT, null, Sound.ENTITY_WITCH_DEATH, Sound.ENTITY_WITCH_AMBIENT),
WITHER(Sound.ENTITY_WITHER_HURT, null, Sound.ENTITY_WITHER_DEATH, Sound.ENTITY_WITHER_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL, WITHER(Sound.ENTITY_WITHER_HURT, null, Sound.ENTITY_WITHER_DEATH, Sound.ENTITY_WITHER_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
@ -126,19 +140,15 @@ public enum DisguiseSound
Sound.ENTITY_ZOMBIE_INFECT, Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_INFECT, Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD,
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR); Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
public enum SoundType public enum SoundType {
{
CANCEL, DEATH, HURT, IDLE, STEP CANCEL, DEATH, HURT, IDLE, STEP
} }
public static DisguiseSound getType(String name) public static DisguiseSound getType(String name) {
{ try {
try
{
return valueOf(name); return valueOf(name);
} }
catch (Exception ex) catch (Exception ex) {
{
return null; return null;
} }
} }
@ -147,43 +157,35 @@ public enum DisguiseSound
private float damageSoundVolume = 1F; private float damageSoundVolume = 1F;
private HashMap<SoundType, String> disguiseSounds = new HashMap<>(); private HashMap<SoundType, String> disguiseSounds = new HashMap<>();
DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds) DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds) {
{
addSound(hurt, SoundType.HURT); addSound(hurt, SoundType.HURT);
addSound(step, SoundType.STEP); addSound(step, SoundType.STEP);
addSound(death, SoundType.DEATH); addSound(death, SoundType.DEATH);
addSound(idle, SoundType.IDLE); addSound(idle, SoundType.IDLE);
for (Object obj : sounds) for (Object obj : sounds) {
{
addSound(obj, SoundType.CANCEL); addSound(obj, SoundType.CANCEL);
} }
} }
private void addSound(Object sound, SoundType type) private void addSound(Object sound, SoundType type) {
{
String s; String s;
if (sound == null) if (sound == null) {
{
return; return;
} }
else if (sound instanceof String) else if (sound instanceof String) {
{
s = (String) sound; s = (String) sound;
} }
else if (sound instanceof Sound) else if (sound instanceof Sound) {
{
s = ReflectionManager.getCraftSound((Sound) sound); s = ReflectionManager.getCraftSound((Sound) sound);
} }
else else {
{
throw new RuntimeException("Was given a unknown object " + sound); throw new RuntimeException("Was given a unknown object " + sound);
} }
switch (type) switch (type) {
{
case HURT: case HURT:
disguiseSounds.put(SoundType.HURT, s); disguiseSounds.put(SoundType.HURT, s);
break; break;
@ -201,58 +203,47 @@ public enum DisguiseSound
} }
} }
public float getDamageAndIdleSoundVolume() public float getDamageAndIdleSoundVolume() {
{
return damageSoundVolume; return damageSoundVolume;
} }
public String getSound(SoundType type) public String getSound(SoundType type) {
{ if (type == null || !disguiseSounds.containsKey(type)) {
if (type == null || !disguiseSounds.containsKey(type))
{
return null; return null;
} }
return disguiseSounds.get(type); return disguiseSounds.get(type);
} }
public HashSet<String> getSoundsToCancel() public HashSet<String> getSoundsToCancel() {
{
return cancelSounds; return cancelSounds;
} }
/** /**
* Used to check if this sound name is owned by this disguise sound. * Used to check if this sound name is owned by this disguise sound.
*/ */
public SoundType getType(String sound, boolean ignoreDamage) public SoundType getType(String sound, boolean ignoreDamage) {
{
if (sound == null) if (sound == null)
return SoundType.CANCEL; return SoundType.CANCEL;
if (isCancelSound(sound)) if (isCancelSound(sound)) {
{
return SoundType.CANCEL; return SoundType.CANCEL;
} }
if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.") if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.")
&& sound.startsWith("step.")) && sound.startsWith("step.")) {
{
return SoundType.STEP; return SoundType.STEP;
} }
for (SoundType type : SoundType.values()) for (SoundType type : SoundType.values()) {
{ if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT)) {
if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT))
{
continue; continue;
} }
String s = disguiseSounds.get(type); String s = disguiseSounds.get(type);
if (s != null) if (s != null) {
{ if (s.equals(sound)) {
if (s.equals(sound))
{
return type; return type;
} }
} }
@ -261,46 +252,36 @@ public enum DisguiseSound
return null; return null;
} }
public boolean isCancelSound(String sound) public boolean isCancelSound(String sound) {
{
return getSoundsToCancel().contains(sound); return getSoundsToCancel().contains(sound);
} }
public void removeSound(SoundType type, Sound sound) public void removeSound(SoundType type, Sound sound) {
{
removeSound(type, ReflectionManager.getCraftSound(sound)); removeSound(type, ReflectionManager.getCraftSound(sound));
} }
public void removeSound(SoundType type, String sound) public void removeSound(SoundType type, String sound) {
{ if (type == SoundType.CANCEL) {
if (type == SoundType.CANCEL)
{
cancelSounds.remove(sound); cancelSounds.remove(sound);
} }
else else {
{
disguiseSounds.remove(type); disguiseSounds.remove(type);
} }
} }
public void setDamageAndIdleSoundVolume(float strength) public void setDamageAndIdleSoundVolume(float strength) {
{
this.damageSoundVolume = strength; this.damageSoundVolume = strength;
} }
public void setSound(SoundType type, Sound sound) public void setSound(SoundType type, Sound sound) {
{
setSound(type, ReflectionManager.getCraftSound(sound)); setSound(type, ReflectionManager.getCraftSound(sound));
} }
public void setSound(SoundType type, String sound) public void setSound(SoundType type, String sound) {
{ if (type == SoundType.CANCEL) {
if (type == SoundType.CANCEL)
{
cancelSounds.add(sound); cancelSounds.add(sound);
} }
else else {
{
disguiseSounds.put(type, sound); disguiseSounds.put(type, sound);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.utilities.packetlisteners; package me.libraryaddict.disguise.utilities.packetlisteners;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -20,12 +21,10 @@ import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class PacketListenerInventory extends PacketAdapter public class PacketListenerInventory extends PacketAdapter {
{
private LibsDisguises libsDisguises; private LibsDisguises libsDisguises;
public PacketListenerInventory(LibsDisguises plugin) public PacketListenerInventory(LibsDisguises plugin) {
{
super(plugin, ListenerPriority.HIGH, Server.SET_SLOT, Server.WINDOW_ITEMS, PacketType.Play.Client.HELD_ITEM_SLOT, super(plugin, ListenerPriority.HIGH, Server.SET_SLOT, Server.WINDOW_ITEMS, PacketType.Play.Client.HELD_ITEM_SLOT,
PacketType.Play.Client.SET_CREATIVE_SLOT, PacketType.Play.Client.WINDOW_CLICK); PacketType.Play.Client.SET_CREATIVE_SLOT, PacketType.Play.Client.WINDOW_CLICK);
@ -33,16 +32,14 @@ public class PacketListenerInventory extends PacketAdapter
} }
@Override @Override
public void onPacketReceiving(final PacketEvent event) public void onPacketReceiving(final PacketEvent event) {
{
if (event.isCancelled()) if (event.isCancelled())
return; return;
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
return; return;
if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null) if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null) {
{
return; return;
} }
@ -50,23 +47,18 @@ public class PacketListenerInventory extends PacketAdapter
// If player is disguised, views self disguises and has a inventory modifier // If player is disguised, views self disguises and has a inventory modifier
if (disguise != null && disguise.isSelfDisguiseVisible() if (disguise != null && disguise.isSelfDisguiseVisible()
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
{
// If they are in creative and clicked on a slot // If they are in creative and clicked on a slot
if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT) if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT) {
{
int slot = event.getPacket().getIntegers().read(0); int slot = event.getPacket().getIntegers().read(0);
if (slot >= 5 && slot <= 8) if (slot >= 5 && slot <= 8) {
{ if (disguise.isHidingArmorFromSelf()) {
if (disguise.isHidingArmorFromSelf())
{
int armorSlot = Math.abs((slot - 5) - 3); int armorSlot = Math.abs((slot - 5) - 3);
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
if (item != null && item.getType() != Material.AIR) if (item != null && item.getType() != Material.AIR) {
{
PacketContainer packet = new PacketContainer(Server.SET_SLOT); PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
@ -75,29 +67,23 @@ public class PacketListenerInventory extends PacketAdapter
mods.write(1, slot); mods.write(1, slot);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
else if (slot >= 36 && slot <= 44) else if (slot >= 36 && slot <= 44) {
{ if (disguise.isHidingHeldItemFromSelf()) {
if (disguise.isHidingHeldItemFromSelf())
{
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot(); int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
if (slot + 36 == currentSlot) if (slot + 36 == currentSlot) {
{
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
if (item != null && item.getType() != Material.AIR) if (item != null && item.getType() != Material.AIR) {
{
PacketContainer packet = new PacketContainer(Server.SET_SLOT); PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
@ -105,12 +91,10 @@ public class PacketListenerInventory extends PacketAdapter
mods.write(1, slot); mods.write(1, slot);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -119,18 +103,15 @@ public class PacketListenerInventory extends PacketAdapter
} }
} }
// If the player switched item, aka he moved from slot 1 to slot 2 // If the player switched item, aka he moved from slot 1 to slot 2
else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_SLOT) else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_SLOT) {
{ if (disguise.isHidingHeldItemFromSelf()) {
if (disguise.isHidingHeldItemFromSelf())
{
// From logging, it seems that both bukkit and nms uses the same thing for the slot switching. // From logging, it seems that both bukkit and nms uses the same thing for the slot switching.
// 0 1 2 3 - 8 // 0 1 2 3 - 8
// If the packet is coming, then I need to replace the item they are switching to // If the packet is coming, then I need to replace the item they are switching to
// As for the old item, I need to restore it. // As for the old item, I need to restore it.
org.bukkit.inventory.ItemStack currentlyHeld = event.getPlayer().getItemInHand(); org.bukkit.inventory.ItemStack currentlyHeld = event.getPlayer().getItemInHand();
// If his old weapon isn't air // If his old weapon isn't air
if (currentlyHeld != null && currentlyHeld.getType() != Material.AIR) if (currentlyHeld != null && currentlyHeld.getType() != Material.AIR) {
{
PacketContainer packet = new PacketContainer(Server.SET_SLOT); PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
@ -139,12 +120,10 @@ public class PacketListenerInventory extends PacketAdapter
mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36); mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36);
mods.write(2, ReflectionManager.getNmsItem(currentlyHeld)); mods.write(2, ReflectionManager.getNmsItem(currentlyHeld));
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -153,8 +132,7 @@ public class PacketListenerInventory extends PacketAdapter
.getItem(event.getPacket().getIntegers().read(0)); .getItem(event.getPacket().getIntegers().read(0));
// If his new weapon isn't air either! // If his new weapon isn't air either!
if (newHeld != null && newHeld.getType() != Material.AIR) if (newHeld != null && newHeld.getType() != Material.AIR) {
{
PacketContainer packet = new PacketContainer(Server.SET_SLOT); PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
@ -163,36 +141,29 @@ public class PacketListenerInventory extends PacketAdapter
mods.write(1, event.getPacket().getIntegers().read(0) + 36); mods.write(1, event.getPacket().getIntegers().read(0) + 36);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) {
{
int slot = event.getPacket().getIntegers().read(1); int slot = event.getPacket().getIntegers().read(1);
org.bukkit.inventory.ItemStack clickedItem; org.bukkit.inventory.ItemStack clickedItem;
if (event.getPacket().getShorts().read(0) == 1) if (event.getPacket().getShorts().read(0) == 1) {
{
// Its a shift click // Its a shift click
clickedItem = event.getPacket().getItemModifier().read(0); clickedItem = event.getPacket().getItemModifier().read(0);
if (clickedItem != null && clickedItem.getType() != Material.AIR) if (clickedItem != null && clickedItem.getType() != Material.AIR) {
{
// Rather than predict the clients actions // Rather than predict the clients actions
// Lets just update the entire inventory.. // Lets just update the entire inventory..
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
{ public void run() {
public void run()
{
event.getPlayer().updateInventory(); event.getPlayer().updateInventory();
} }
}); });
@ -200,25 +171,20 @@ public class PacketListenerInventory extends PacketAdapter
return; return;
} }
else else {
{
// If its not a player inventory click // If its not a player inventory click
// Shift clicking is exempted for the item in hand.. // Shift clicking is exempted for the item in hand..
if (event.getPacket().getIntegers().read(0) != 0) if (event.getPacket().getIntegers().read(0) != 0) {
{
return; return;
} }
clickedItem = event.getPlayer().getItemOnCursor(); clickedItem = event.getPlayer().getItemOnCursor();
} }
if (clickedItem != null && clickedItem.getType() != Material.AIR) if (clickedItem != null && clickedItem.getType() != Material.AIR) {
{
// If the slot is a armor slot // If the slot is a armor slot
if (slot >= 5 && slot <= 8) if (slot >= 5 && slot <= 8) {
{ if (disguise.isHidingArmorFromSelf()) {
if (disguise.isHidingArmorFromSelf())
{
PacketContainer packet = new PacketContainer(Server.SET_SLOT); PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
@ -227,26 +193,21 @@ public class PacketListenerInventory extends PacketAdapter
mods.write(1, slot); mods.write(1, slot);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
// Else if its a hotbar slot // Else if its a hotbar slot
} }
else if (slot >= 36 && slot <= 44) else if (slot >= 36 && slot <= 44) {
{ if (disguise.isHidingHeldItemFromSelf()) {
if (disguise.isHidingHeldItemFromSelf())
{
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot(); int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
// Check if the player is on the same slot as the slot that its setting // Check if the player is on the same slot as the slot that its setting
if (slot == currentSlot + 36) if (slot == currentSlot + 36) {
{
PacketContainer packet = new PacketContainer(Server.SET_SLOT); PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
@ -254,12 +215,10 @@ public class PacketListenerInventory extends PacketAdapter
mods.write(1, slot); mods.write(1, slot);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
try try {
{
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
} }
catch (InvocationTargetException e) catch (InvocationTargetException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -272,20 +231,17 @@ public class PacketListenerInventory extends PacketAdapter
} }
@Override @Override
public void onPacketSending(PacketEvent event) public void onPacketSending(PacketEvent event) {
{
// If the inventory is the players inventory // If the inventory is the players inventory
if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null if (event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory || event.getPlayer().getVehicle() != null
|| event.getPacket().getIntegers().read(0) != 0) || event.getPacket().getIntegers().read(0) != 0) {
{
return; return;
} }
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer()); Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
if (disguise == null || !disguise.isSelfDisguiseVisible() if (disguise == null || !disguise.isSelfDisguiseVisible()
|| (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) || (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) {
{
return; return;
} }
@ -297,24 +253,20 @@ public class PacketListenerInventory extends PacketAdapter
/** /**
* Done * Done
*/ */
if (event.getPacketType() == Server.SET_SLOT) if (event.getPacketType() == Server.SET_SLOT) {
{
// The raw slot // The raw slot
// nms code has the start of the hotbar being 36. // nms code has the start of the hotbar being 36.
int slot = event.getPacket().getIntegers().read(1); int slot = event.getPacket().getIntegers().read(1);
// If the slot is a armor slot // If the slot is a armor slot
if (slot >= 5 && slot <= 8) if (slot >= 5 && slot <= 8) {
{ if (disguise.isHidingArmorFromSelf()) {
if (disguise.isHidingArmorFromSelf())
{
// Get the bukkit armor slot! // Get the bukkit armor slot!
int armorSlot = Math.abs((slot - 5) - 3); int armorSlot = Math.abs((slot - 5) - 3);
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
if (item != null && item.getType() != Material.AIR) if (item != null && item.getType() != Material.AIR) {
{
event.setPacket(event.getPacket().shallowClone()); event.setPacket(event.getPacket().shallowClone());
event.getPacket().getModifier().write(2, event.getPacket().getModifier().write(2,
@ -323,19 +275,15 @@ public class PacketListenerInventory extends PacketAdapter
} }
// Else if its a hotbar slot // Else if its a hotbar slot
} }
else if (slot >= 36 && slot <= 44) else if (slot >= 36 && slot <= 44) {
{ if (disguise.isHidingHeldItemFromSelf()) {
if (disguise.isHidingHeldItemFromSelf())
{
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot(); int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
// Check if the player is on the same slot as the slot that its setting // Check if the player is on the same slot as the slot that its setting
if (slot == currentSlot + 36) if (slot == currentSlot + 36) {
{
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
if (item != null && item.getType() != Material.AIR) if (item != null && item.getType() != Material.AIR) {
{
event.setPacket(event.getPacket().shallowClone()); event.setPacket(event.getPacket().shallowClone());
event.getPacket().getModifier().write(2, event.getPacket().getModifier().write(2,
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
@ -344,45 +292,36 @@ public class PacketListenerInventory extends PacketAdapter
} }
} }
} }
else if (event.getPacketType() == Server.WINDOW_ITEMS) else if (event.getPacketType() == Server.WINDOW_ITEMS) {
{
event.setPacket(event.getPacket().deepClone()); event.setPacket(event.getPacket().deepClone());
StructureModifier<ItemStack[]> mods = event.getPacket().getItemArrayModifier(); StructureModifier<List<ItemStack>> mods = event.getPacket().getItemListModifier();
ItemStack[] items = mods.read(0); List<ItemStack> items = mods.read(0);
for (int slot = 0; slot < items.length; slot++) for (int slot = 0; slot < items.size(); slot++) {
{ if (slot >= 5 && slot <= 8) {
if (slot >= 5 && slot <= 8) if (disguise.isHidingArmorFromSelf()) {
{
if (disguise.isHidingArmorFromSelf())
{
// Get the bukkit armor slot! // Get the bukkit armor slot!
int armorSlot = Math.abs((slot - 5) - 3); int armorSlot = Math.abs((slot - 5) - 3);
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
if (item != null && item.getType() != Material.AIR) if (item != null && item.getType() != Material.AIR) {
{ items.set(slot, new ItemStack(Material.AIR));
items[slot] = new org.bukkit.inventory.ItemStack(0);
} }
} }
// Else if its a hotbar slot // Else if its a hotbar slot
} }
else if (slot >= 36 && slot <= 44) else if (slot >= 36 && slot <= 44) {
{ if (disguise.isHidingHeldItemFromSelf()) {
if (disguise.isHidingHeldItemFromSelf())
{
int currentSlot = event.getPlayer().getInventory().getHeldItemSlot(); int currentSlot = event.getPlayer().getInventory().getHeldItemSlot();
// Check if the player is on the same slot as the slot that its setting // Check if the player is on the same slot as the slot that its setting
if (slot == currentSlot + 36) if (slot == currentSlot + 36) {
{ ItemStack item = event.getPlayer().getItemInHand();
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
if (item != null && item.getType() != Material.AIR) if (item != null && item.getType() != Material.AIR) {
{ items.set(slot, new ItemStack(Material.AIR));
items[slot] = new org.bukkit.inventory.ItemStack(0);
} }
} }
} }