Fixed bug where players switching worlds would become invisible.

Fixed bug where arrows wouldn't blow disguises.
Added default permission for /libsdisguises reload (only ops can use by default)
This commit is contained in:
NavidK0 2015-08-02 18:39:44 -04:00
parent 3e19045a2c
commit 41cfa8eeaa
51 changed files with 2032 additions and 2009 deletions

@ -13,7 +13,7 @@ println 'Compiling LibsDisguises via Gradle ver. ' + gradle.gradleVersion
sourceCompatibility = '1.7' sourceCompatibility = '1.7'
ext.spigotVersion = '1.8.8-R0.1-SNAPSHOT' ext.spigotVersion = '1.8.8-R0.1-SNAPSHOT'
ext.disguisesVersion = '8.6.3' ext.disguisesVersion = '8.6.4'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

@ -143,8 +143,9 @@ public class DisguiseAPI {
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) {
@ -192,12 +193,14 @@ public class DisguiseAPI {
/** /**
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn. * Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
*
* @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();
} }
@ -215,6 +218,7 @@ public class DisguiseAPI {
/** /**
* Disguise this entity with this disguise * Disguise this entity with this disguise
*
* @param entity * @param entity
* @param disguise * @param disguise
*/ */
@ -224,8 +228,9 @@ public class DisguiseAPI {
} }
// 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);
} }
@ -268,40 +273,47 @@ public class DisguiseAPI {
/** /**
* Get the disguise of a entity * Get the disguise of a entity
*
* @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;
}
return DisguiseUtilities.getMainDisguise(disguised.getUniqueId()); return DisguiseUtilities.getMainDisguise(disguised.getUniqueId());
} }
/** /**
* Get the disguise of a entity * Get the disguise of a entity
*
* @param observer * @param observer
* @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;
}
return DisguiseUtilities.getDisguise(observer, disguised); return DisguiseUtilities.getDisguise(observer, disguised);
} }
/** /**
* Get the disguises of a entity * Get the disguises of a entity
*
* @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());
} }
/** /**
* Get the ID of a fake disguise for a entityplayer * Get the ID of a fake disguise for a entityplayer
*
* @param entityId * @param entityId
* @return * @return
*/ */
@ -316,6 +328,7 @@ public class DisguiseAPI {
/** /**
* Is this entity disguised * Is this entity disguised
*
* @param disguised * @param disguised
* @return * @return
*/ */
@ -325,6 +338,7 @@ public class DisguiseAPI {
/** /**
* Is this entity disguised * Is this entity disguised
*
* @param observer * @param observer
* @param disguised * @param disguised
* @return * @return
@ -342,8 +356,8 @@ public class DisguiseAPI {
} }
/** /**
* Returns true if the entitiy has /disguiseviewself toggled * Returns true if the entitiy has /disguiseviewself toggled on.
* on. *
* @param entity * @param entity
* @return * @return
*/ */
@ -352,8 +366,8 @@ public class DisguiseAPI {
} }
/** /**
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka removed from * Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka removed from the world.
* the world. *
* @param entity * @param entity
*/ */
public static void undisguiseToAll(Entity entity) { public static void undisguiseToAll(Entity entity) {
@ -364,8 +378,8 @@ public class DisguiseAPI {
} }
/** /**
* Set whether this player can see his * Set whether this player can see his own disguise or not.
* own disguise or not. *
* @param entity * @param entity
* @param toggled * @param toggled
*/ */
@ -375,8 +389,9 @@ public class DisguiseAPI {
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());
} }

@ -6,6 +6,7 @@ import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class DisguiseConfig { public class DisguiseConfig {
private static boolean animationEnabled; private static boolean animationEnabled;
private static boolean bedEnabled; private static boolean bedEnabled;
private static boolean blowDisguisesOnAttack; private static boolean blowDisguisesOnAttack;
@ -218,6 +219,7 @@ public class DisguiseConfig {
/** /**
* Is the velocity packets sent * Is the velocity packets sent
*
* @return * @return
*/ */
public static boolean isVelocitySent() { public static boolean isVelocitySent() {
@ -226,6 +228,7 @@ public class DisguiseConfig {
/** /**
* The default value if a player views his own disguise * The default value if a player views his own disguise
*
* @return * @return
*/ */
public static boolean isViewDisguises() { public static boolean isViewDisguises() {
@ -408,6 +411,7 @@ public class DisguiseConfig {
/** /**
* Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get? * Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get?
*
* @param sendVelocityPackets * @param sendVelocityPackets
*/ */
public static void setVelocitySent(boolean sendVelocityPackets) { public static void setVelocitySent(boolean sendVelocityPackets) {

@ -38,6 +38,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import org.bukkit.entity.Arrow;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
public class DisguiseListener implements Listener { public class DisguiseListener implements Listener {
@ -66,11 +67,13 @@ public class DisguiseListener implements Listener {
Bukkit.getScheduler().runTask(plugin, new Runnable() { Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
for (Player p : Bukkit.getOnlinePlayers()) for (Player p : Bukkit.getOnlinePlayers()) {
if (p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) if (p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) {
p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion,
latestVersion)); latestVersion));
} }
}
}
}); });
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -159,6 +162,8 @@ public class DisguiseListener implements Listener {
/** /**
* Most likely faster if we don't bother doing checks if he sees a player disguise * Most likely faster if we don't bother doing checks if he sees a player disguise
*
* @param event
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMove(PlayerMoveEvent event) { public void onMove(PlayerMoveEvent event) {
@ -266,12 +271,13 @@ public class DisguiseListener implements Listener {
if (DisguiseAPI.isDisguised(entity)) { if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(entity); DisguiseAPI.undisguiseToAll(entity);
p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName); p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName);
} else } else {
p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!"); p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!");
} }
} }
} }
} }
}
@EventHandler @EventHandler
public void onTarget(EntityTargetEvent event) { public void onTarget(EntityTargetEvent event) {
@ -292,6 +298,9 @@ public class DisguiseListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent event) { public void onTeleport(final PlayerTeleportEvent event) {
if (!DisguiseAPI.isDisguised(event.getPlayer())) {
return;
}
Location to = event.getTo(); Location to = event.getTo();
Location from = event.getFrom(); Location from = event.getFrom();
if (DisguiseConfig.isBedPacketsEnabled()) { if (DisguiseConfig.isBedPacketsEnabled()) {
@ -301,7 +310,7 @@ public class DisguiseListener implements Listener {
int z2 = (int) Math.floor(from.getZ() / 16D) - 17; int z2 = (int) Math.floor(from.getZ() / 16D) - 17;
if (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8)) { if (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8)) {
chunkMove(event.getPlayer(), null, from); chunkMove(event.getPlayer(), null, from);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
if (!event.isCancelled()) { if (!event.isCancelled()) {
@ -318,6 +327,17 @@ public class DisguiseListener implements Listener {
for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) { for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) {
disguise.removeDisguise(); disguise.removeDisguise();
} }
} else {
//Stupid hack to fix worldswitch invisibility bug
final boolean viewSelfToggled = DisguiseAPI.isViewSelfToggled(event.getPlayer());
final Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
disguise.setViewSelfDisguise(!viewSelfToggled);
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
disguise.setViewSelfDisguise(viewSelfToggled);
}
}, 20L); //I wish I could use lambdas here, so badly
} }
} }
@ -347,6 +367,9 @@ public class DisguiseListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldSwitch(final PlayerChangedWorldEvent event) { public void onWorldSwitch(final PlayerChangedWorldEvent event) {
if (!DisguiseAPI.isDisguised(event.getPlayer())) {
return;
}
if (DisguiseConfig.isBedPacketsEnabled()) { if (DisguiseConfig.isBedPacketsEnabled()) {
chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null); chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null);
} }

@ -69,7 +69,8 @@ public class LibsDisguises extends JavaPlugin {
try { try {
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
metrics.start(); metrics.start();
} catch (IOException e) {} } catch (IOException e) {
}
} }
/** /**
@ -82,8 +83,7 @@ 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()) {

@ -62,10 +62,12 @@ public class DisguiseCommand extends BaseDisguiseCommand {
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"); sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player")) if (allowedDisguises.contains("player")) {
sender.sendMessage(ChatColor.DARK_GREEN + "/disguise player <Name>"); sender.sendMessage(ChatColor.DARK_GREEN + "/disguise player <Name>");
}
sender.sendMessage(ChatColor.DARK_GREEN + "/disguise <DisguiseType> <Baby>"); sender.sendMessage(ChatColor.DARK_GREEN + "/disguise <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <Dropped_Item/Falling_Block> <Id> <Durability>"); sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <Dropped_Item/Falling_Block> <Id> <Durability>");
} }
} }
}

@ -42,6 +42,7 @@ public class DisguiseEntityCommand extends BaseDisguiseCommand {
/** /**
* Send the player the information * Send the player the information
*
* @param sender * @param sender
* @param map * @param map
*/ */
@ -51,11 +52,13 @@ public class DisguiseEntityCommand extends BaseDisguiseCommand {
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then right click a entity to disguise it!"); sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then right click a entity to disguise it!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player")) if (allowedDisguises.contains("player")) {
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity player <Name>"); sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity player <Name>");
}
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <DisguiseType> <Baby>"); sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> <Durability>"); sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> <Durability>");
} }
}
} }

@ -22,7 +22,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
public class DisguiseHelpCommand extends BaseDisguiseCommand { public class DisguiseHelpCommand 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;
@ -99,10 +101,11 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
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 + ")");
} }
}
enumHelp.add(new EnumHelp("PotionEffect", "PotionEffect", ChatColor.RED + "/disguisehelp PotionEffect " enumHelp.add(new EnumHelp("PotionEffect", "PotionEffect", ChatColor.RED + "/disguisehelp PotionEffect "
+ ChatColor.GREEN + "- View all the potion effects you can set", enumReturns.toArray(new String[enumReturns + ChatColor.GREEN + "- View all the potion effects you can set", enumReturns.toArray(new String[enumReturns
.size()]))); .size()])));
@ -273,8 +276,9 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
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, "_");
} }
} }

@ -85,11 +85,13 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand {
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!"); sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
if (allowedDisguises.contains("player")) if (allowedDisguises.contains("player")) {
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>"); sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>");
}
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>"); sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>");
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(ChatColor.DARK_GREEN sender.sendMessage(ChatColor.DARK_GREEN
+ "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>"); + "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>");
} }
} }
}

@ -21,6 +21,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class DisguiseRadiusCommand extends BaseDisguiseCommand { public class DisguiseRadiusCommand extends BaseDisguiseCommand {
private int maxRadius = 30; private int maxRadius = 30;
private ArrayList<Class> validClasses = new ArrayList<>(); private ArrayList<Class> validClasses = new ArrayList<>();
@ -111,8 +112,9 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
int disguisedEntitys = 0; int disguisedEntitys = 0;
int miscDisguises = 0; int miscDisguises = 0;
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
if (entity == sender) if (entity == sender) {
continue; continue;
}
if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) { if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) {
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
&& entity instanceof LivingEntity) { && entity instanceof LivingEntity) {

@ -19,7 +19,7 @@ public class LibsDisguisesCommand implements CommandExecutor {
+ " by libraryaddict, maintained by NavidK0.\n" + " by libraryaddict, maintained by NavidK0.\n"
+ "Use /libsdisguises reload to reload the config. All disguises will be blown by doing this."); + "Use /libsdisguises reload to reload the config. All disguises will be blown by doing this.");
} else if (args.length > 0) { } else if (args.length > 0) {
if (!sender.hasPermission("libsdisguises.reload")) { if (sender.hasPermission("libsdisguises.reload")) {
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
LibsDisguises.instance.reload(); LibsDisguises.instance.reload();
sender.sendMessage(ChatColor.GREEN + "[LibsDisguises] Reloaded config."); sender.sendMessage(ChatColor.GREEN + "[LibsDisguises] Reloaded config.");

@ -21,10 +21,12 @@ public class UndisguiseCommand implements CommandExecutor {
if (DisguiseAPI.isDisguised((Entity) sender)) { if (DisguiseAPI.isDisguised((Entity) sender)) {
DisguiseAPI.undisguiseToAll((Player) sender); DisguiseAPI.undisguiseToAll((Player) sender);
sender.sendMessage(ChatColor.RED + "You are no longer disguised"); sender.sendMessage(ChatColor.RED + "You are no longer disguised");
} else } else {
sender.sendMessage(ChatColor.RED + "You are not disguised!"); sender.sendMessage(ChatColor.RED + "You are not disguised!");
} else }
} else {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true; return true;
} }
} }

@ -19,8 +19,9 @@ public class UndisguiseEntityCommand implements CommandExecutor {
if (sender.hasPermission("libsdisguises.undisguiseentity")) { if (sender.hasPermission("libsdisguises.undisguiseentity")) {
LibsDisguises.instance.getListener().setDisguiseEntity(sender.getName(), null); LibsDisguises.instance.getListener().setDisguiseEntity(sender.getName(), null);
sender.sendMessage(ChatColor.RED + "Right click a disguised entity to undisguise them!"); sender.sendMessage(ChatColor.RED + "Right click a disguised entity to undisguise them!");
} else } else {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true; return true;
} }
} }

@ -20,14 +20,18 @@ public class UndisguisePlayerCommand implements CommandExecutor {
if (DisguiseAPI.isDisguised(p)) { if (DisguiseAPI.isDisguised(p)) {
DisguiseAPI.undisguiseToAll(p); DisguiseAPI.undisguiseToAll(p);
sender.sendMessage(ChatColor.RED + "The player is no longer disguised"); sender.sendMessage(ChatColor.RED + "The player is no longer disguised");
} else } else {
sender.sendMessage(ChatColor.RED + "The player is not disguised!"); sender.sendMessage(ChatColor.RED + "The player is not disguised!");
} else }
} else {
sender.sendMessage(ChatColor.RED + "Player not found"); sender.sendMessage(ChatColor.RED + "Player not found");
} else }
} else {
sender.sendMessage(ChatColor.RED + "/undisguiseplayer <Name>"); sender.sendMessage(ChatColor.RED + "/undisguiseplayer <Name>");
} else }
} else {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true; return true;
} }
} }

@ -10,6 +10,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class UndisguiseRadiusCommand implements CommandExecutor { public class UndisguiseRadiusCommand implements CommandExecutor {
private int maxRadius = 30; private int maxRadius = 30;
public UndisguiseRadiusCommand(int maxRadius) { public UndisguiseRadiusCommand(int maxRadius) {
@ -48,16 +49,18 @@ public class UndisguiseRadiusCommand implements CommandExecutor {
} }
int disguisedEntitys = 0; int disguisedEntitys = 0;
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
if (entity == sender) if (entity == sender) {
continue; continue;
}
if (DisguiseAPI.isDisguised(entity)) { if (DisguiseAPI.isDisguised(entity)) {
DisguiseAPI.undisguiseToAll(entity); DisguiseAPI.undisguiseToAll(entity);
disguisedEntitys++; disguisedEntitys++;
} }
} }
sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!"); sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!");
} else } else {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
}
return true; return true;
} }
} }

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.disguisetypes; package me.libraryaddict.disguise.disguisetypes;
public enum AnimalColor { public enum AnimalColor {
BLACK(15), BLUE(11), BROWN(12), CYAN(9), GRAY(7), GREEN(13), LIGHT_BLUE(3), LIME(5), MAGENTA(2), ORANGE(1), PINK(6), PURPLE( BLACK(15), BLUE(11), BROWN(12), CYAN(9), GRAY(7), GREEN(13), LIGHT_BLUE(3), LIME(5), MAGENTA(2), ORANGE(1), PINK(6), PURPLE(
10), RED(14), SILVER(8), WHITE(0), YELLOW(4); 10), RED(14), SILVER(8), WHITE(0), YELLOW(4);

@ -39,6 +39,7 @@ import java.util.Map;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
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;
@ -64,11 +65,13 @@ public abstract class Disguise {
/** /**
* Seems I do this method so I can make cleaner constructors on disguises.. * Seems I do this method so I can make cleaner constructors on disguises..
*
* @param newType * @param newType
*/ */
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( throw new RuntimeException(
"DisguiseType " "DisguiseType "
@ -99,16 +102,12 @@ public abstract class Disguise {
// 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) {
getWatcher().setValue(13, (byte) 1); getWatcher().setValue(13, (byte) 1);
} } // 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) {
getWatcher().setValue(13, (byte) 1); getWatcher().setValue(13, (byte) 1);
} } else if (getType() == DisguiseType.ELDER_GUARDIAN) {
else if (getType() == DisguiseType.ELDER_GUARDIAN) {
getWatcher().setValue(16, 0 | 4); getWatcher().setValue(16, 0 | 4);
} } // Else if its a horse. Set the horse watcher type
// Else if its a horse. Set the horse watcher type
else if (getWatcher() instanceof HorseWatcher) { else if (getWatcher() instanceof HorseWatcher) {
try { try {
// Don't mess with this because Varient is something like ZombieHorse and so on. // Don't mess with this because Varient is something like ZombieHorse and so on.
@ -328,6 +327,7 @@ public abstract class Disguise {
/** /**
* Get the disguised entity * Get the disguised entity
*
* @return * @return
*/ */
public Entity getEntity() { public Entity getEntity() {
@ -336,6 +336,7 @@ public abstract class Disguise {
/** /**
* Get the disguise type * Get the disguise type
*
* @return * @return
*/ */
public DisguiseType getType() { public DisguiseType getType() {
@ -344,6 +345,7 @@ public abstract class Disguise {
/** /**
* Get the flag watcher * Get the flag watcher
*
* @return * @return
*/ */
public FlagWatcher getWatcher() { public FlagWatcher getWatcher() {
@ -351,8 +353,8 @@ public abstract class Disguise {
} }
/** /**
* In use doesn't mean that this disguise is active. It means that Lib's Disguises still stores a reference to the disguise. * In use doesn't mean that this disguise is active. It means that Lib's Disguises still stores a reference to the disguise. getEntity() can still return null if this disguise is active after despawn, logout, etc.
* getEntity() can still return null if this disguise is active after despawn, logout, etc. *
* @return * @return
*/ */
public boolean isDisguiseInUse() { public boolean isDisguiseInUse() {
@ -397,17 +399,16 @@ public abstract class Disguise {
/** /**
* Internal use * Internal use
*
* @return * @return
*/ */
public boolean isRemoveDisguiseOnDeath() { public boolean isRemoveDisguiseOnDeath() {
if (getEntity() == null) return true; if (getEntity() == null) {
return getEntity() instanceof Player ? return true;
}
(!((Player) getEntity()).isOnline() ? !isKeepDisguiseOnPlayerLogout() : !isKeepDisguiseOnPlayerDeath()) return getEntity() instanceof Player
? (!((Player) getEntity()).isOnline() ? !isKeepDisguiseOnPlayerLogout() : !isKeepDisguiseOnPlayerDeath())
: : (!isKeepDisguiseOnEntityDespawn() || getEntity().isDead());
(!isKeepDisguiseOnEntityDespawn() || getEntity().isDead());
} }
public boolean isSelfDisguiseSoundsReplaced() { public boolean isSelfDisguiseSoundsReplaced() {
@ -416,6 +417,7 @@ public abstract class Disguise {
/** /**
* Can the disguised view himself as the disguise * Can the disguised view himself as the disguise
*
* @return * @return
*/ */
public boolean isSelfDisguiseVisible() { public boolean isSelfDisguiseVisible() {
@ -432,6 +434,7 @@ public abstract class Disguise {
/** /**
* Returns true if the entity's name is showing through the disguise * Returns true if the entity's name is showing through the disguise
*
* @return * @return
*/ */
public boolean isShowName() { public boolean isShowName() {
@ -503,13 +506,15 @@ public abstract class Disguise {
/** /**
* Set the entity of the disguise. Only used for internal things. * Set the entity of the disguise. Only used for internal things.
*
* @param entity * @param entity
* @return * @return
*/ */
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) {
@ -582,8 +587,7 @@ 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() {
HashMap<Integer, Object> disguiseValues = DisguiseValues.getMetaValues(getType()); HashMap<Integer, Object> disguiseValues = DisguiseValues.getMetaValues(getType());
@ -611,8 +615,9 @@ public abstract class Disguise {
} }
// STEP 2. As the watcher has not set data on it, check if I need to set the default data. // STEP 2. As the watcher has not set data on it, check if I need to set the default data.
// If neither of them touch it // If neither of them touch it
if (!entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo)) if (!entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo)) {
continue; continue;
}
// If the disguise has this, but not the entity. Then better set it! // If the disguise has this, but not the entity. Then better set it!
if (!entityValues.containsKey(dataNo) && disguiseValues.containsKey(dataNo)) { if (!entityValues.containsKey(dataNo) && disguiseValues.containsKey(dataNo)) {
getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo)); getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo));
@ -626,9 +631,9 @@ public abstract class Disguise {
Object eObj = entityValues.get(dataNo); Object eObj = entityValues.get(dataNo);
Object dObj = disguiseValues.get(dataNo); Object dObj = disguiseValues.get(dataNo);
if (eObj == null || dObj == null) { if (eObj == null || dObj == null) {
if (eObj == null && dObj == null) if (eObj == null && dObj == null) {
continue; continue;
else { } else {
getWatcher().setBackupValue(dataNo, dObj); getWatcher().setBackupValue(dataNo, dObj);
continue; continue;
} }
@ -645,7 +650,6 @@ public abstract class Disguise {
// EntityInsentient is 10 & 11 // EntityInsentient is 10 & 11
// EntityZombie is 12 & 13 & 14 - But it overrides other values and another check already does this. // EntityZombie is 12 & 13 & 14 - But it overrides other values and another check already does this.
// EntityLiving is 6 & 7 & 8 & 9 // EntityLiving is 6 & 7 & 8 & 9
// Lets use switch // Lets use switch
Class baseClass = null; Class baseClass = null;
switch (dataNo) { switch (dataNo) {
@ -670,16 +674,18 @@ public abstract class Disguise {
if (nmsDisguiseClass != null) { if (nmsDisguiseClass != null) {
// If they both extend the same base class. They OBVIOUSLY share the same datavalue. Right..? // If they both extend the same base class. They OBVIOUSLY share the same datavalue. Right..?
if (baseClass != null && baseClass.isAssignableFrom(nmsDisguiseClass) if (baseClass != null && baseClass.isAssignableFrom(nmsDisguiseClass)
&& baseClass.isAssignableFrom(nmsEntityClass)) && baseClass.isAssignableFrom(nmsEntityClass)) {
continue; continue;
}
// So they don't extend a basic class. // So they don't extend a basic class.
// Maybe if I check that they extend each other.. // Maybe if I check that they extend each other..
// Seeing as I only store the finished forms of entitys. This should raise no problems and allow for more shared // Seeing as I only store the finished forms of entitys. This should raise no problems and allow for more shared
// datawatchers. // datawatchers.
if (nmsEntityClass.isAssignableFrom(nmsDisguiseClass) || nmsDisguiseClass.isAssignableFrom(nmsEntityClass)) if (nmsEntityClass.isAssignableFrom(nmsDisguiseClass) || nmsDisguiseClass.isAssignableFrom(nmsEntityClass)) {
continue; continue;
} }
}
// Well I can't find a reason I should leave it alone. They will probably conflict. // Well I can't find a reason I should leave it alone. They will probably conflict.
// Time to set the value to the disguises value so no conflicts! // Time to set the value to the disguises value so no conflicts!
getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo)); getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo));
@ -704,11 +710,12 @@ public abstract class Disguise {
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());
} }
} }
} }
}
return this; return this;
} }
@ -762,8 +769,8 @@ public abstract class Disguise {
} }
/** /**
* Returns the list of people who have /disguiseViewSelf * Returns the list of people who have /disguiseViewSelf toggled on
* toggled on *
* @return * @return
*/ */
public static List<UUID> getViewSelf() { public static List<UUID> getViewSelf() {

@ -11,144 +11,76 @@ import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
public enum DisguiseType { public enum DisguiseType {
ARMOR_STAND(78), ARMOR_STAND(78),
ARROW(60), ARROW(60),
BAT, BAT,
BLAZE, BLAZE,
BOAT(1), BOAT(1),
CAVE_SPIDER, CAVE_SPIDER,
CHICKEN, CHICKEN,
COW, COW,
CREEPER, CREEPER,
DONKEY, DONKEY,
DROPPED_ITEM(2, 1), DROPPED_ITEM(2, 1),
EGG(62), EGG(62),
ELDER_GUARDIAN, ELDER_GUARDIAN,
ENDER_CRYSTAL(51), ENDER_CRYSTAL(51),
ENDER_DRAGON, ENDER_DRAGON,
ENDER_PEARL(65), ENDER_PEARL(65),
ENDER_SIGNAL(72), ENDER_SIGNAL(72),
ENDERMAN, ENDERMAN,
ENDERMITE, ENDERMITE,
EXPERIENCE_ORB, EXPERIENCE_ORB,
FALLING_BLOCK(70, 1), FALLING_BLOCK(70, 1),
FIREBALL(63, 0), FIREBALL(63, 0),
FIREWORK(76), FIREWORK(76),
FISHING_HOOK(90), FISHING_HOOK(90),
GHAST, GHAST,
GIANT, GIANT,
GUARDIAN, GUARDIAN,
HORSE, HORSE,
IRON_GOLEM, IRON_GOLEM,
ITEM_FRAME(71), ITEM_FRAME(71),
LEASH_HITCH(77), LEASH_HITCH(77),
MAGMA_CUBE, MAGMA_CUBE,
MINECART(10, 0), MINECART(10, 0),
MINECART_CHEST(10, 1), MINECART_CHEST(10, 1),
MINECART_COMMAND(10, 6), MINECART_COMMAND(10, 6),
MINECART_FURNACE(10, 2), MINECART_FURNACE(10, 2),
MINECART_HOPPER(10, 5), MINECART_HOPPER(10, 5),
MINECART_MOB_SPAWNER(10, 4), MINECART_MOB_SPAWNER(10, 4),
MINECART_TNT(10, 3), MINECART_TNT(10, 3),
MULE, MULE,
MUSHROOM_COW, MUSHROOM_COW,
OCELOT, OCELOT,
PAINTING, PAINTING,
PIG, PIG,
PIG_ZOMBIE, PIG_ZOMBIE,
PLAYER, PLAYER,
PRIMED_TNT(50), PRIMED_TNT(50),
RABBIT, RABBIT,
SHEEP, SHEEP,
SILVERFISH, SILVERFISH,
SKELETON, SKELETON,
SKELETON_HORSE, SKELETON_HORSE,
SLIME, SLIME,
SMALL_FIREBALL(64, 0), SMALL_FIREBALL(64, 0),
SNOWBALL(61), SNOWBALL(61),
SNOWMAN, SNOWMAN,
SPIDER, SPIDER,
SPLASH_POTION(73), SPLASH_POTION(73),
SQUID, SQUID,
THROWN_EXP_BOTTLE(75), THROWN_EXP_BOTTLE(75),
UNDEAD_HORSE, UNDEAD_HORSE,
VILLAGER, VILLAGER,
WITCH, WITCH,
WITHER, WITHER,
WITHER_SKELETON, WITHER_SKELETON,
WITHER_SKULL(66), WITHER_SKULL(66),
WOLF, WOLF,
ZOMBIE, ZOMBIE,
ZOMBIE_VILLAGER, ZOMBIE_VILLAGER,
UNKNOWN; UNKNOWN;
private static Method isVillager, getVariant, getSkeletonType, isElder; private static Method isVillager, getVariant, getSkeletonType, isElder;
@ -332,8 +264,9 @@ public enum DisguiseType {
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();
}
return StringUtils.join(split, " "); return StringUtils.join(split, " ");
} }
} }

@ -24,7 +24,9 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class FlagWatcher { public class FlagWatcher {
public enum SlotType { public enum SlotType {
BOOTS(0), CHESTPLATE(2), HELD_ITEM(4), HELMET(3), LEGGINGS(1); BOOTS(0), CHESTPLATE(2), HELD_ITEM(4), HELMET(3), LEGGINGS(1);
// The ints is for bukkit. Not nms slots. // The ints is for bukkit. Not nms slots.
private int slotNo = 0; private int slotNo = 0;
@ -89,16 +91,19 @@ public class FlagWatcher {
sentValues.add(dataType); sentValues.add(dataType);
// Its sending the air metadata. This is the least commonly sent metadata which all entitys still share. // Its sending the air metadata. This is the least commonly sent metadata which all entitys still share.
// I send my custom values if I see this! // I send my custom values if I see this!
if (dataType == 1) if (dataType == 1) {
sendAllCustom = true; sendAllCustom = true;
}
Object value = null; Object value = null;
if (entityValues.containsKey(dataType)) { if (entityValues.containsKey(dataType)) {
if (entityValues.get(dataType) == null) if (entityValues.get(dataType) == null) {
continue; continue;
}
value = entityValues.get(dataType); value = entityValues.get(dataType);
} else if (backupEntityValues.containsKey(dataType)) { } else if (backupEntityValues.containsKey(dataType)) {
if (backupEntityValues.get(dataType) == null) if (backupEntityValues.get(dataType) == null) {
continue; continue;
}
value = backupEntityValues.get(dataType); value = backupEntityValues.get(dataType);
} }
if (value != null) { if (value != null) {
@ -107,24 +112,28 @@ public class FlagWatcher {
} }
boolean isDirty = watch.getDirtyState(); boolean isDirty = watch.getDirtyState();
watch = new WrappedWatchableObject(dataType, value); watch = new WrappedWatchableObject(dataType, value);
if (!isDirty) if (!isDirty) {
watch.setDirtyState(false); watch.setDirtyState(false);
}
} else { } else {
boolean isDirty = watch.getDirtyState(); boolean isDirty = watch.getDirtyState();
watch = new WrappedWatchableObject(dataType, watch.getValue()); watch = new WrappedWatchableObject(dataType, watch.getValue());
if (!isDirty) if (!isDirty) {
watch.setDirtyState(false); watch.setDirtyState(false);
} }
}
newList.add(watch); newList.add(watch);
} }
if (sendAllCustom) { if (sendAllCustom) {
// Its sending the entire meta data. Better add the custom meta // Its sending the entire meta data. Better add the custom meta
for (int value : entityValues.keySet()) { for (int value : entityValues.keySet()) {
if (sentValues.contains(value)) if (sentValues.contains(value)) {
continue; continue;
}
Object obj = entityValues.get(value); Object obj = entityValues.get(value);
if (obj == null) if (obj == null) {
continue; continue;
}
WrappedWatchableObject watch = new WrappedWatchableObject(value, obj); WrappedWatchableObject watch = new WrappedWatchableObject(value, obj);
newList.add(watch); newList.add(watch);
} }
@ -182,8 +191,9 @@ public class FlagWatcher {
} }
protected Object getValue(int no, Object backup) { protected Object getValue(int no, Object backup) {
if (entityValues.containsKey(no)) if (entityValues.containsKey(no)) {
return entityValues.get(no); return entityValues.get(no);
}
return backup; return backup;
} }
@ -246,12 +256,14 @@ public class FlagWatcher {
} }
protected void sendData(int... dataValues) { protected void sendData(int... dataValues) {
if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) {
return; return;
}
List<WrappedWatchableObject> list = new ArrayList<>(); List<WrappedWatchableObject> list = new ArrayList<>();
for (int data : dataValues) { for (int data : dataValues) {
if (!entityValues.containsKey(data) || entityValues.get(data) == null) if (!entityValues.containsKey(data) || entityValues.get(data) == null) {
continue; continue;
}
Object value = entityValues.get(data); Object value = entityValues.get(data);
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) { if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) {
value = addEntityAnimations((Byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); value = addEntityAnimations((Byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
@ -348,8 +360,9 @@ public class FlagWatcher {
items[slot] = itemStack; items[slot] = itemStack;
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) { if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
slot++; slot++;
if (slot > 4) if (slot > 4) {
slot = 0; slot = 0;
}
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT); PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
mods.write(0, getDisguise().getEntity().getEntityId()); mods.write(0, getDisguise().getEntity().getEntityId());

@ -14,6 +14,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class MiscDisguise extends TargetedDisguise { public class MiscDisguise extends TargetedDisguise {
private int id = -1, data = 0; private int id = -1, data = 0;
public MiscDisguise(DisguiseType disguiseType) { public MiscDisguise(DisguiseType disguiseType) {

@ -13,14 +13,16 @@ import me.libraryaddict.disguise.utilities.LibsProfileLookup;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
public class PlayerDisguise extends TargetedDisguise { public class PlayerDisguise extends TargetedDisguise {
private LibsProfileLookup currentLookup; private LibsProfileLookup currentLookup;
private WrappedGameProfile gameProfile; private WrappedGameProfile gameProfile;
private String playerName; private String playerName;
private String skinToUse; private String skinToUse;
public PlayerDisguise(String name) { public PlayerDisguise(String name) {
if (name.length() > 16) if (name.length() > 16) {
name = name.substring(0, 16); name = name.substring(0, 16);
}
playerName = name; playerName = name;
createDisguise(DisguiseType.PLAYER); createDisguise(DisguiseType.PLAYER);
} }
@ -199,8 +201,7 @@ public class PlayerDisguise extends TargetedDisguise {
/** /**
* Set the GameProfile, without tampering. * Set the GameProfile, without tampering.
* *
* @param gameProfile * @param gameProfile GameProfile
* GameProfile
* @return * @return
*/ */
public PlayerDisguise setSkin(WrappedGameProfile gameProfile) { public PlayerDisguise setSkin(WrappedGameProfile gameProfile) {

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.disguisetypes; package me.libraryaddict.disguise.disguisetypes;
public enum RabbitType { public enum RabbitType {
BLACK(2), BROWN(0), GOLD(4), KILLER_BUNNY(99), PATCHES(3), PEPPER(5), WHITE(1); BLACK(2), BROWN(0), GOLD(4), KILLER_BUNNY(99), PATCHES(3), PEPPER(5), WHITE(1);
public static RabbitType getType(int id) { public static RabbitType getType(int id) {

@ -10,7 +10,9 @@ import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public abstract class TargetedDisguise extends Disguise { public abstract class TargetedDisguise extends Disguise {
public enum TargetType { public enum TargetType {
HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS, SHOW_TO_EVERYONE_BUT_THESE_PLAYERS; HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS, SHOW_TO_EVERYONE_BUT_THESE_PLAYERS;
} }

@ -30,9 +30,9 @@ public class ArmorStandWatcher extends LivingWatcher {
private void set10(int value, boolean isTrue) { private void set10(int value, boolean isTrue) {
byte b1 = (Byte) getValue(10, (byte) 0); byte b1 = (Byte) getValue(10, (byte) 0);
if (isTrue) if (isTrue) {
b1 = (byte) (b1 | value); b1 = (byte) (b1 | value);
else { } else {
b1 = (byte) (b1 & value); b1 = (byte) (b1 & value);
} }
setValue(10, b1); setValue(10, b1);

@ -9,6 +9,7 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class FallingBlockWatcher extends FlagWatcher { public class FallingBlockWatcher extends FlagWatcher {
private ItemStack block; private ItemStack block;
public FallingBlockWatcher(Disguise disguise) { public FallingBlockWatcher(Disguise disguise) {

@ -11,8 +11,9 @@ public class ItemFrameWatcher extends FlagWatcher {
} }
public ItemStack getItem() { public ItemStack getItem() {
if (getValue(2, null) == null) if (getValue(2, null) == null) {
return new ItemStack(0); return new ItemStack(0);
}
return (ItemStack) getValue(8, null); return (ItemStack) getValue(8, null);
} }
@ -21,8 +22,9 @@ public class ItemFrameWatcher extends FlagWatcher {
} }
public void setItem(ItemStack newItem) { public void setItem(ItemStack newItem) {
if (newItem == null) if (newItem == null) {
newItem = new ItemStack(0); newItem = new ItemStack(0);
}
newItem = newItem.clone(); newItem = newItem.clone();
newItem.setAmount(1); newItem.setAmount(1);
setValue(8, newItem); setValue(8, newItem);

@ -23,8 +23,10 @@ import com.comphenix.protocol.wrappers.WrappedAttribute;
import com.comphenix.protocol.wrappers.WrappedAttribute.Builder; import com.comphenix.protocol.wrappers.WrappedAttribute.Builder;
public class LivingWatcher extends FlagWatcher { public class LivingWatcher extends FlagWatcher {
static Object[] list; static Object[] list;
static Method potionNo; static Method potionNo;
static { static {
try { try {
list = (Object[]) ReflectionManager.getNmsField("MobEffectList", "byId").get(null); list = (Object[]) ReflectionManager.getNmsField("MobEffectList", "byId").get(null);

@ -6,6 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class PaintingWatcher extends FlagWatcher { public class PaintingWatcher extends FlagWatcher {
private Art painting; private Art painting;
public PaintingWatcher(Disguise disguise) { public PaintingWatcher(Disguise disguise) {

@ -16,6 +16,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion; import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
public class PlayerWatcher extends LivingWatcher { public class PlayerWatcher extends LivingWatcher {
private boolean isInBed; private boolean isInBed;
private BlockFace sleepingDirection; private BlockFace sleepingDirection;
@ -82,6 +83,7 @@ public class PlayerWatcher extends LivingWatcher {
/** /**
* If no BlockFace is supplied. It grabs it from the entities facing direction if applicable. * If no BlockFace is supplied. It grabs it from the entities facing direction if applicable.
*
* @param sleeping * @param sleeping
* @param sleepingDirection * @param sleepingDirection
*/ */

@ -5,6 +5,7 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class SplashPotionWatcher extends FlagWatcher { public class SplashPotionWatcher extends FlagWatcher {
private int potionId; private int potionId;
public SplashPotionWatcher(Disguise disguise) { public SplashPotionWatcher(Disguise disguise) {

@ -8,6 +8,7 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class DisguiseEvent extends Event implements Cancellable { public class DisguiseEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {

@ -8,6 +8,7 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class UndisguiseEvent extends Event implements Cancellable { public class UndisguiseEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {

@ -35,6 +35,7 @@ import org.bukkit.potion.PotionEffectType;
public abstract class BaseDisguiseCommand implements CommandExecutor { public abstract class BaseDisguiseCommand implements CommandExecutor {
public class DisguiseParseException extends Exception { public class DisguiseParseException extends Exception {
private static final long serialVersionUID = 1276971370793124510L; private static final long serialVersionUID = 1276971370793124510L;
public DisguiseParseException() { public DisguiseParseException() {
@ -105,6 +106,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
/** /**
* Get perms for the node. Returns a hashmap of allowed disguisetypes and their options * Get perms for the node. Returns a hashmap of allowed disguisetypes and their options
*
* @param sender * @param sender
* @param permissionNode * @param permissionNode
* @return * @return
@ -265,8 +267,9 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
option = option.substring(1); option = option.substring(1);
isRemove = false; isRemove = false;
} }
if (option.equals("baby")) if (option.equals("baby")) {
option = "setbaby"; option = "setbaby";
}
list.add(option); list.add(option);
} }
HashMap<ArrayList<String>, Boolean> options = new HashMap<>(); HashMap<ArrayList<String>, Boolean> options = new HashMap<>();
@ -293,9 +296,8 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
} }
/** /**
* Returns the disguise if it all parsed correctly. Returns a exception with a complete message if it didn't. The * Returns the disguise if it all parsed correctly. Returns a exception with a complete message if it didn't. The commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this point, the disguise has been feed a proper disguisetype.
* commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this point, the *
* disguise has been feed a proper disguisetype.
* @param sender * @param sender
* @param args * @param args
* @param map * @param map
@ -577,8 +579,9 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
if (potionType == null && isNumeric(valueString)) { if (potionType == null && isNumeric(valueString)) {
potionType = PotionEffectType.getById(Integer.parseInt(valueString)); potionType = PotionEffectType.getById(Integer.parseInt(valueString));
} }
if (potionType == null) if (potionType == null) {
throw new DisguiseParseException(); throw new DisguiseParseException();
}
value = potionType; value = potionType;
} catch (Exception ex) { } catch (Exception ex) {
throw parseToException("a potioneffect type", valueString, methodName); throw parseToException("a potioneffect type", valueString, methodName);
@ -597,8 +600,9 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
} else if (param == BlockFace.class) { } else if (param == BlockFace.class) {
try { try {
BlockFace face = BlockFace.valueOf(valueString.toUpperCase()); BlockFace face = BlockFace.valueOf(valueString.toUpperCase());
if (face.ordinal() > 4) if (face.ordinal() > 4) {
throw new DisguiseParseException(); throw new DisguiseParseException();
}
value = face; value = face;
} catch (Exception ex) { } catch (Exception ex) {
throw parseToException("a direction (north, east, south, west, up)", valueString, methodName); throw parseToException("a direction (north, east, south, west, up)", valueString, methodName);
@ -661,11 +665,12 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
usedOptions.add(methodName.toLowerCase()); usedOptions.add(methodName.toLowerCase());
} }
doCheck(optionPermissions, usedOptions); doCheck(optionPermissions, usedOptions);
if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass())) if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass())) {
methodToUse.invoke(disguise.getWatcher(), value); methodToUse.invoke(disguise.getWatcher(), value);
else } else {
methodToUse.invoke(disguise, value); methodToUse.invoke(disguise, value);
} }
}
// Alright. We've constructed our disguise. // Alright. We've constructed our disguise.
return disguise; return disguise;
} }

@ -13,7 +13,6 @@ import java.util.jar.JarFile;
/** /**
* User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester * User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester
*/ */
// Code for this taken and slightly modified from // Code for this taken and slightly modified from
// https://github.com/ddopson/java-class-enumerator // https://github.com/ddopson/java-class-enumerator
public class ClassGetter { public class ClassGetter {
@ -59,10 +58,11 @@ public class ClassGetter {
} }
if (className != null) { if (className != null) {
Class<?> c = loadClass(className); Class<?> c = loadClass(className);
if (c != null) if (c != null) {
classes.add(c); classes.add(c);
} }
} }
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(System.out); ex.printStackTrace(System.out);
} }

@ -11,107 +11,69 @@ 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, "random.bowhit"),
ARROW(null, null, null, null, "random.bowhit"),
BAT("mob.bat.hurt", null, "mob.bat.death", "mob.bat.idle", "damage.fallsmall", "mob.bat.loop", "damage.fallbig", BAT("mob.bat.hurt", null, "mob.bat.death", "mob.bat.idle", "damage.fallsmall", "mob.bat.loop", "damage.fallbig",
"mob.bat.takeoff"), "mob.bat.takeoff"),
BLAZE("mob.blaze.hit", null, "mob.blaze.death", "mob.blaze.breathe", "damage.fallsmall", "damage.fallbig"), BLAZE("mob.blaze.hit", null, "mob.blaze.death", "mob.blaze.breathe", "damage.fallsmall", "damage.fallbig"),
CAVE_SPIDER("mob.spider.say", "mob.spider.step", "mob.spider.death", "mob.spider.say"), CAVE_SPIDER("mob.spider.say", "mob.spider.step", "mob.spider.death", "mob.spider.say"),
CHICKEN("mob.chicken.hurt", "mob.chicken.step", "mob.chicken.hurt", "mob.chicken.say", "damage.fallsmall", CHICKEN("mob.chicken.hurt", "mob.chicken.step", "mob.chicken.hurt", "mob.chicken.say", "damage.fallsmall",
"mob.chicken.plop", "damage.fallbig"), "mob.chicken.plop", "damage.fallbig"),
COW("mob.cow.hurt", "mob.cow.step", "mob.cow.hurt", "mob.cow.say"), COW("mob.cow.hurt", "mob.cow.step", "mob.cow.hurt", "mob.cow.say"),
CREEPER("mob.creeper.say", "step.grass", "mob.creeper.death", null), CREEPER("mob.creeper.say", "step.grass", "mob.creeper.death", null),
DONKEY("mob.horse.donkey.hit", "step.grass", "mob.horse.donkey.death", "mob.horse.donkey.idle", "mob.horse.gallop", DONKEY("mob.horse.donkey.hit", "step.grass", "mob.horse.donkey.death", "mob.horse.donkey.idle", "mob.horse.gallop",
"mob.horse.leather", "mob.horse.donkey.angry", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.leather", "mob.horse.donkey.angry", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft",
"mob.horse.land", "mob.horse.jump", "mob.horse.angry"), "mob.horse.land", "mob.horse.jump", "mob.horse.angry"),
ELDER_GUARDIAN("mob.guardian.elder.hit", null, "mob.guardian.elder.death", "mob.guardian.elder.death"), ELDER_GUARDIAN("mob.guardian.elder.hit", null, "mob.guardian.elder.death", "mob.guardian.elder.death"),
ENDER_DRAGON("mob.enderdragon.hit", null, "mob.enderdragon.end", "mob.enderdragon.growl", "damage.fallsmall", ENDER_DRAGON("mob.enderdragon.hit", null, "mob.enderdragon.end", "mob.enderdragon.growl", "damage.fallsmall",
"mob.enderdragon.wings", "damage.fallbig"), "mob.enderdragon.wings", "damage.fallbig"),
ENDERMAN("mob.endermen.hit", "step.grass", "mob.endermen.death", "mob.endermen.idle", "mob.endermen.scream", ENDERMAN("mob.endermen.hit", "step.grass", "mob.endermen.death", "mob.endermen.idle", "mob.endermen.scream",
"mob.endermen.portal", "mob.endermen.stare"), "mob.endermen.portal", "mob.endermen.stare"),
ENDERMITE("mob.silverfish.hit", "mob.silverfish.step", "mob.silverfish.kill", "mob.silverfish.say"), ENDERMITE("mob.silverfish.hit", "mob.silverfish.step", "mob.silverfish.kill", "mob.silverfish.say"),
GHAST("mob.ghast.scream", null, "mob.ghast.death", "mob.ghast.moan", "damage.fallsmall", "mob.ghast.fireball", GHAST("mob.ghast.scream", null, "mob.ghast.death", "mob.ghast.moan", "damage.fallsmall", "mob.ghast.fireball",
"damage.fallbig", "mob.ghast.affectionate_scream", "mob.ghast.charge"), "damage.fallbig", "mob.ghast.affectionate_scream", "mob.ghast.charge"),
GIANT("damage.hit", "step.grass", null, null), GIANT("damage.hit", "step.grass", null, null),
GUARDIAN("mob.guardian.hit", null, "mob.guardian.death", "mob.guardian.death"), GUARDIAN("mob.guardian.hit", null, "mob.guardian.death", "mob.guardian.death"),
HORSE("mob.horse.hit", "step.grass", "mob.horse.death", "mob.horse.idle", "mob.horse.gallop", "mob.horse.leather", HORSE("mob.horse.hit", "step.grass", "mob.horse.death", "mob.horse.idle", "mob.horse.gallop", "mob.horse.leather",
"mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.land", "mob.horse.jump", "mob.horse.angry", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.land", "mob.horse.jump", "mob.horse.angry",
"mob.horse.leather"), "mob.horse.leather"),
IRON_GOLEM("mob.irongolem.hit", "mob.irongolem.walk", "mob.irongolem.death", "mob.irongolem.throw"), IRON_GOLEM("mob.irongolem.hit", "mob.irongolem.walk", "mob.irongolem.death", "mob.irongolem.throw"),
MAGMA_CUBE("mob.slime.attack", "mob.slime.big", null, null, "mob.slime.small"), MAGMA_CUBE("mob.slime.attack", "mob.slime.big", null, null, "mob.slime.small"),
MULE("mob.horse.donkey.hit", "step.grass", "mob.horse.donkey.death", "mob.horse.donkey.idle"), MULE("mob.horse.donkey.hit", "step.grass", "mob.horse.donkey.death", "mob.horse.donkey.idle"),
MUSHROOM_COW("mob.cow.hurt", "mob.cow.step", "mob.cow.hurt", "mob.cow.say"), MUSHROOM_COW("mob.cow.hurt", "mob.cow.step", "mob.cow.hurt", "mob.cow.say"),
OCELOT("mob.cat.hitt", "step.grass", "mob.cat.hitt", "mob.cat.meow", "mob.cat.purreow", "mob.cat.purr"), OCELOT("mob.cat.hitt", "step.grass", "mob.cat.hitt", "mob.cat.meow", "mob.cat.purreow", "mob.cat.purr"),
PIG("mob.pig.say", "mob.pig.step", "mob.pig.death", "mob.pig.say"), PIG("mob.pig.say", "mob.pig.step", "mob.pig.death", "mob.pig.say"),
PIG_ZOMBIE("mob.zombiepig.zpighurt", null, "mob.zombiepig.zpigdeath", "mob.zombiepig.zpig", "mob.zombiepig.zpigangry"), PIG_ZOMBIE("mob.zombiepig.zpighurt", null, "mob.zombiepig.zpigdeath", "mob.zombiepig.zpig", "mob.zombiepig.zpigangry"),
PLAYER("game.player.hurt", "step.grass", "game.player.hurt", null), PLAYER("game.player.hurt", "step.grass", "game.player.hurt", null),
RABBIT("mob.rabbit.hurt", "mob.rabbit.hop", "mob.rabbit.death", "mob.rabbit.idle"), RABBIT("mob.rabbit.hurt", "mob.rabbit.hop", "mob.rabbit.death", "mob.rabbit.idle"),
SHEEP("mob.sheep.say", "mob.sheep.step", null, "mob.sheep.say", "mob.sheep.shear"), SHEEP("mob.sheep.say", "mob.sheep.step", null, "mob.sheep.say", "mob.sheep.shear"),
SILVERFISH("mob.silverfish.hit", "mob.silverfish.step", "mob.silverfish.kill", "mob.silverfish.say"), SILVERFISH("mob.silverfish.hit", "mob.silverfish.step", "mob.silverfish.kill", "mob.silverfish.say"),
SKELETON("mob.skeleton.hurt", "mob.skeleton.step", "mob.skeleton.death", "mob.skeleton.say"), SKELETON("mob.skeleton.hurt", "mob.skeleton.step", "mob.skeleton.death", "mob.skeleton.say"),
SKELETON_HORSE("mob.horse.skeleton.hit", "step.grass", "mob.horse.skeleton.death", "mob.horse.skeleton.idle", SKELETON_HORSE("mob.horse.skeleton.hit", "step.grass", "mob.horse.skeleton.death", "mob.horse.skeleton.idle",
"mob.horse.gallop", "mob.horse.leather", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.land", "mob.horse.gallop", "mob.horse.leather", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.land",
"mob.horse.jump", "mob.horse.angry"), "mob.horse.jump", "mob.horse.angry"),
SLIME("mob.slime.attack", "mob.slime.big", null, null, "mob.slime.small"), SLIME("mob.slime.attack", "mob.slime.big", null, null, "mob.slime.small"),
SNOWMAN(), SNOWMAN(),
SPIDER("mob.spider.say", "mob.spider.step", "mob.spider.death", "mob.spider.say"), SPIDER("mob.spider.say", "mob.spider.step", "mob.spider.death", "mob.spider.say"),
SQUID(), SQUID(),
UNDEAD_HORSE("mob.horse.zombie.hit", "step.grass", "mob.horse.zombie.death", "mob.horse.zombie.idle", "mob.horse.gallop", UNDEAD_HORSE("mob.horse.zombie.hit", "step.grass", "mob.horse.zombie.death", "mob.horse.zombie.idle", "mob.horse.gallop",
"mob.horse.leather", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.land", "mob.horse.jump", "mob.horse.leather", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.land", "mob.horse.jump",
"mob.horse.angry"), "mob.horse.angry"),
VILLAGER("mob.villager.hit", null, "mob.villager.death", "mob.villager.idle", "mob.villager.haggle", "mob.villager.no", VILLAGER("mob.villager.hit", null, "mob.villager.death", "mob.villager.idle", "mob.villager.haggle", "mob.villager.no",
"mob.villager.yes"), "mob.villager.yes"),
WITCH("mob.witch.hurt", null, "mob.witch.death", "mob.witch.idle"), WITCH("mob.witch.hurt", null, "mob.witch.death", "mob.witch.idle"),
WITHER("mob.wither.hurt", null, "mob.wither.death", "mob.wither.idle", "damage.fallsmall", "mob.wither.spawn", WITHER("mob.wither.hurt", null, "mob.wither.death", "mob.wither.idle", "damage.fallsmall", "mob.wither.spawn",
"damage.fallbig", "mob.wither.shoot"), "damage.fallbig", "mob.wither.shoot"),
WITHER_SKELETON("mob.skeleton.hurt", "mob.skeleton.step", "mob.skeleton.death", "mob.skeleton.say"), WITHER_SKELETON("mob.skeleton.hurt", "mob.skeleton.step", "mob.skeleton.death", "mob.skeleton.say"),
WOLF("mob.wolf.hurt", "mob.wolf.step", "mob.wolf.death", "mob.wolf.bark", "mob.wolf.panting", "mob.wolf.whine", WOLF("mob.wolf.hurt", "mob.wolf.step", "mob.wolf.death", "mob.wolf.bark", "mob.wolf.panting", "mob.wolf.whine",
"mob.wolf.howl", "mob.wolf.growl", "mob.wolf.shake"), "mob.wolf.howl", "mob.wolf.growl", "mob.wolf.shake"),
ZOMBIE("mob.zombie.hurt", "mob.zombie.step", "mob.zombie.death", "mob.zombie.say", "mob.zombie.infect", ZOMBIE("mob.zombie.hurt", "mob.zombie.step", "mob.zombie.death", "mob.zombie.say", "mob.zombie.infect",
"mob.zombie.woodbreak", "mob.zombie.metal", "mob.zombie.wood"), "mob.zombie.woodbreak", "mob.zombie.metal", "mob.zombie.wood"),
ZOMBIE_VILLAGER("mob.zombie.hurt", "mob.zombie.step", "mob.zombie.death", "mob.zombie.say", "mob.zombie.infect", ZOMBIE_VILLAGER("mob.zombie.hurt", "mob.zombie.step", "mob.zombie.death", "mob.zombie.say", "mob.zombie.infect",
"mob.zombie.woodbreak", "mob.zombie.metal", "mob.zombie.wood"); "mob.zombie.woodbreak", "mob.zombie.metal", "mob.zombie.wood");
public enum SoundType { public enum SoundType {
CANCEL, DEATH, HURT, IDLE, STEP; CANCEL, DEATH, HURT, IDLE, STEP;
} }
@ -131,9 +93,9 @@ public enum DisguiseSound {
for (int i = 0; i < sounds.length; i++) { for (int i = 0; i < sounds.length; i++) {
Object obj = sounds[i]; Object obj = sounds[i];
String s; String s;
if (obj == null) if (obj == null) {
continue; continue;
else if (obj instanceof String) { } else if (obj instanceof String) {
s = (String) obj; s = (String) obj;
} else if (obj instanceof Sound) { } else if (obj instanceof Sound) {
s = ReflectionManager.getCraftSound((Sound) obj); s = ReflectionManager.getCraftSound((Sound) obj);
@ -166,8 +128,9 @@ public enum DisguiseSound {
} }
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);
} }
@ -179,20 +142,24 @@ public enum DisguiseSound {
* 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 (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;
} }
} }
}
return null; return null;
} }
@ -205,9 +172,9 @@ public enum DisguiseSound {
} }
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);
} }
} }
@ -221,9 +188,9 @@ public enum DisguiseSound {
} }
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);
} }
} }

@ -51,20 +51,20 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedWatchableObject; import com.comphenix.protocol.wrappers.WrappedWatchableObject;
public class DisguiseUtilities { public class DisguiseUtilities {
/** /**
* This is a list of names which was called by other plugins. As such, don't remove from the gameProfiles as its the duty of * This is a list of names which was called by other plugins. As such, don't remove from the gameProfiles as its the duty of the plugin to do that.
* the plugin to do that.
*/ */
private static HashSet<String> addedByPlugins = new HashSet<>(); private static HashSet<String> addedByPlugins = new HashSet<>();
private static Object bedChunk; private static Object bedChunk;
private static LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>(); private static LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>();
/** /**
* A hashmap of the uuid's of entitys, alive and dead. And their disguises in use * A hashmap of the uuid's of entitys, alive and dead. And their disguises in use
**/ *
*/
private static HashMap<UUID, HashSet<TargetedDisguise>> disguisesInUse = new HashMap<>(); private static HashMap<UUID, HashSet<TargetedDisguise>> disguisesInUse = new HashMap<>();
/** /**
* Disguises which are stored ready for a entity to be seen by a player Preferably, disguises in this should only stay in for * Disguises which are stored ready for a entity to be seen by a player Preferably, disguises in this should only stay in for a max of a second.
* a max of a second.
*/ */
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<>(); private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<>();
/** /**
@ -179,8 +179,7 @@ public class DisguiseUtilities {
} }
/** /**
* If name isn't null. Make sure that the name doesn't see any other disguise. Else if name is null. Make sure that the * If name isn't null. Make sure that the name doesn't see any other disguise. Else if name is null. Make sure that the observers in the disguise don't see any other disguise.
* observers in the disguise don't see any other disguise.
*/ */
public static void checkConflicts(TargetedDisguise disguise, String name) { public static void checkConflicts(TargetedDisguise disguise, String name) {
// If the disguise is being used.. Else we may accidentally undisguise something else // If the disguise is being used.. Else we may accidentally undisguise something else
@ -237,7 +236,6 @@ public class DisguiseUtilities {
// System.out.print("Cannot set more than one " + TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS // System.out.print("Cannot set more than one " + TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
// + " on a entity. Removed the old disguise."); // + " on a entity. Removed the old disguise.");
disguiseItel.remove(); disguiseItel.remove();
d.removeDisguise(); d.removeDisguise();
} }
@ -433,6 +431,7 @@ public class DisguiseUtilities {
/** /**
* Get all EntityPlayers who have this entity in their Entity Tracker And they are in the targetted disguise. * Get all EntityPlayers who have this entity in their Entity Tracker And they are in the targetted disguise.
*
* @param disguise * @param disguise
* @return * @return
*/ */
@ -478,8 +477,7 @@ public class DisguiseUtilities {
} }
/** /**
* Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup * Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup using schedulers. The runnable is run once the GameProfile has been successfully dealt with
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
*/ */
public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn) { public static WrappedGameProfile getProfileFromMojang(String playerName, LibsProfileLookup runnableIfCantReturn) {
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn); return getProfileFromMojang(playerName, (Object) runnableIfCantReturn);
@ -550,8 +548,7 @@ public class DisguiseUtilities {
} }
/** /**
* Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup * Thread safe to use. This returns a GameProfile. And if its GameProfile doesn't have a skin blob. Then it does a lookup using schedulers. The runnable is run once the GameProfile has been successfully dealt with
* using schedulers. The runnable is run once the GameProfile has been successfully dealt with
*/ */
public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn) { public static WrappedGameProfile getProfileFromMojang(String playerName, Runnable runnableIfCantReturn) {
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn); return getProfileFromMojang(playerName, (Object) runnableIfCantReturn);
@ -582,14 +579,14 @@ public class DisguiseUtilities {
} }
/** /**
* Please note that in the future when 'DualInt' and the like are removed. This should break.. However, that should be negated * Please note that in the future when 'DualInt' and the like are removed. This should break.. However, that should be negated in the future as I'd be able to set the watcher index's as per the spigot version. Instead of checking on the player's version every single packet..
* in the future as I'd be able to set the watcher index's as per the spigot version. Instead of checking on the player's
* version every single packet..
*/ */
public static List<WrappedWatchableObject> rebuildForVersion(Player player, FlagWatcher watcher, public static List<WrappedWatchableObject> rebuildForVersion(Player player, FlagWatcher watcher,
List<WrappedWatchableObject> list) { List<WrappedWatchableObject> list) {
if (true) // Use for future protocol compatibility if (true) // Use for future protocol compatibility
{
return list; return list;
}
ArrayList<WrappedWatchableObject> rebuiltList = new ArrayList<>(); ArrayList<WrappedWatchableObject> rebuiltList = new ArrayList<>();
ArrayList<WrappedWatchableObject> backups = new ArrayList<>(); ArrayList<WrappedWatchableObject> backups = new ArrayList<>();
for (WrappedWatchableObject obj : list) { for (WrappedWatchableObject obj : list) {
@ -625,8 +622,9 @@ public class DisguiseUtilities {
if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player
&& ((Player) disguise.getEntity()).getName().equalsIgnoreCase(player)) { && ((Player) disguise.getEntity()).getName().equalsIgnoreCase(player)) {
removeSelfDisguise((Player) disguise.getEntity()); removeSelfDisguise((Player) disguise.getEntity());
if (disguise.isSelfDisguiseVisible()) if (disguise.isSelfDisguiseVisible()) {
selfDisguised.add(disguise.getEntity().getUniqueId()); selfDisguised.add(disguise.getEntity().getUniqueId());
}
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket); ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@Override @Override
@ -972,6 +970,7 @@ public class DisguiseUtilities {
/** /**
* Setup it so he can see himself when disguised * Setup it so he can see himself when disguised
*
* @param disguise * @param disguise
*/ */
public static void setupFakeDisguise(final Disguise disguise) { public static void setupFakeDisguise(final Disguise disguise) {

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.utilities; package me.libraryaddict.disguise.utilities;
public class FakeBoundingBox { public class FakeBoundingBox {
private double xMod; private double xMod;
private double yMod; private double yMod;
private double zMod; private double zMod;

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
public interface LibsProfileLookup { public interface LibsProfileLookup {
public void onLookup(WrappedGameProfile gameProfile); public void onLookup(WrappedGameProfile gameProfile);
} }

@ -6,6 +6,7 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.ProfileLookupCallback; import com.mojang.authlib.ProfileLookupCallback;
public class LibsProfileLookupCaller implements ProfileLookupCallback { public class LibsProfileLookupCaller implements ProfileLookupCallback {
private WrappedGameProfile gameProfile; private WrappedGameProfile gameProfile;
public WrappedGameProfile getGameProfile() { public WrappedGameProfile getGameProfile() {

@ -54,6 +54,7 @@ import java.util.logging.Level;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
public class Metrics { public class Metrics {
/** /**
* The current revision number * The current revision number
*/ */
@ -128,8 +129,7 @@ public class Metrics {
/** /**
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics website. Plotters can be added to the graph object returned. * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics website. Plotters can be added to the graph object returned.
* *
* @param name * @param name The name of the graph
* The name of the graph
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given * @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
*/ */
public Graph createGraph(final String name) { public Graph createGraph(final String name) {
@ -147,8 +147,7 @@ public class Metrics {
/** /**
* Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend * Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend
* *
* @param graph * @param graph The name of the graph
* The name of the graph
*/ */
public void addGraph(final Graph graph) { public void addGraph(final Graph graph) {
if (graph == null) { if (graph == null) {
@ -430,12 +429,13 @@ public class Metrics {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(System.out); e.printStackTrace(System.out);
} finally { } finally {
if (gzos != null) if (gzos != null) {
try { try {
gzos.close(); gzos.close();
} catch (IOException ignore) { } catch (IOException ignore) {
} }
} }
}
return baos.toByteArray(); return baos.toByteArray();
} }
@ -529,8 +529,7 @@ public class Metrics {
/** /**
* Encode text as UTF-8 * Encode text as UTF-8
* *
* @param text * @param text the text to encode
* the text to encode
* @return the encoded text, as UTF-8 * @return the encoded text, as UTF-8
*/ */
private static String urlEncode(final String text) throws UnsupportedEncodingException { private static String urlEncode(final String text) throws UnsupportedEncodingException {
@ -541,6 +540,7 @@ public class Metrics {
* Represents a custom graph on the website * Represents a custom graph on the website
*/ */
public static class Graph { public static class Graph {
/** /**
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is rejected * The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is rejected
*/ */
@ -566,8 +566,7 @@ public class Metrics {
/** /**
* Add a plotter to the graph, which will be used to plot entries * Add a plotter to the graph, which will be used to plot entries
* *
* @param plotter * @param plotter the plotter to add to the graph
* the plotter to add to the graph
*/ */
public void addPlotter(final Plotter plotter) { public void addPlotter(final Plotter plotter) {
plotters.add(plotter); plotters.add(plotter);
@ -576,8 +575,7 @@ public class Metrics {
/** /**
* Remove a plotter from the graph * Remove a plotter from the graph
* *
* @param plotter * @param plotter the plotter to remove from the graph
* the plotter to remove from the graph
*/ */
public void removePlotter(final Plotter plotter) { public void removePlotter(final Plotter plotter) {
plotters.remove(plotter); plotters.remove(plotter);
@ -617,6 +615,7 @@ public class Metrics {
* Interface used to collect custom data for a plugin * Interface used to collect custom data for a plugin
*/ */
public static abstract class Plotter { public static abstract class Plotter {
/** /**
* The plot's name * The plot's name
*/ */
@ -632,8 +631,7 @@ public class Metrics {
/** /**
* Construct a plotter with a specific plot name * Construct a plotter with a specific plot name
* *
* @param name * @param name the name of the plotter to use, which will show up on the website
* the name of the plotter to use, which will show up on the website
*/ */
public Plotter(final String name) { public Plotter(final String name) {
this.name = name; this.name = name;

@ -58,9 +58,9 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import net.minecraft.server.v1_8_R3.DamageSource; import net.minecraft.server.v1_8_R3.DamageSource;
public class PacketsManager { public class PacketsManager {
/** /**
* This is a fix for the stupidity that is * This is a fix for the stupidity that is "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard"
* "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard"
*/ */
private static boolean cancelSound; private static boolean cancelSound;
private static PacketListener clientInteractEntityListener; private static PacketListener clientInteractEntityListener;
@ -81,8 +81,9 @@ public class PacketsManager {
PacketType.Play.Client.USE_ENTITY) { PacketType.Play.Client.USE_ENTITY) {
@Override @Override
public void onPacketReceiving(PacketEvent event) { public void onPacketReceiving(PacketEvent event) {
if (event.isCancelled()) if (event.isCancelled()) {
return; return;
}
try { try {
Player observer = event.getPlayer(); Player observer = event.getPlayer();
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld()); StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
@ -118,14 +119,16 @@ public class PacketsManager {
/** /**
* Construct the packets I need to spawn in the disguise * Construct the packets I need to spawn in the disguise
*
* @param player * @param player
* @param disguise * @param disguise
* @param disguisedEntity * @param disguisedEntity
* @return * @return
*/ */
public static PacketContainer[][] constructSpawnPackets(final Player player, Disguise disguise, Entity disguisedEntity) { public static PacketContainer[][] constructSpawnPackets(final Player player, Disguise disguise, Entity disguisedEntity) {
if (disguise.getEntity() == null) if (disguise.getEntity() == null) {
disguise.setEntity(disguisedEntity); disguise.setEntity(disguisedEntity);
}
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
ArrayList<PacketContainer> packets = new ArrayList<>(); ArrayList<PacketContainer> packets = new ArrayList<>();
// This sends the armor packets so that the player isn't naked. // This sends the armor packets so that the player isn't naked.
@ -133,8 +136,9 @@ public class PacketsManager {
if (DisguiseConfig.isEquipmentPacketsEnabled()) { if (DisguiseConfig.isEquipmentPacketsEnabled()) {
for (int nmsSlot = 0; nmsSlot < 5; nmsSlot++) { for (int nmsSlot = 0; nmsSlot < 5; nmsSlot++) {
int armorSlot = nmsSlot - 1; int armorSlot = nmsSlot - 1;
if (armorSlot < 0) if (armorSlot < 0) {
armorSlot = 4; armorSlot = 4;
}
ItemStack itemstack = disguise.getWatcher().getItemStack(armorSlot); ItemStack itemstack = disguise.getWatcher().getItemStack(armorSlot);
if (itemstack != null && itemstack.getTypeId() != 0) { if (itemstack != null && itemstack.getTypeId() != 0) {
ItemStack item = null; ItemStack item = null;
@ -299,18 +303,24 @@ public class PacketsManager {
double d2 = vec.getX(); double d2 = vec.getX();
double d3 = vec.getY(); double d3 = vec.getY();
double d4 = vec.getZ(); double d4 = vec.getZ();
if (d2 < -d1) if (d2 < -d1) {
d2 = -d1; d2 = -d1;
if (d3 < -d1) }
if (d3 < -d1) {
d3 = -d1; d3 = -d1;
if (d4 < -d1) }
if (d4 < -d1) {
d4 = -d1; d4 = -d1;
if (d2 > d1) }
if (d2 > d1) {
d2 = d1; d2 = d1;
if (d3 > d1) }
if (d3 > d1) {
d3 = d1; d3 = d1;
if (d4 > d1) }
if (d4 > d1) {
d4 = d1; d4 = d1;
}
mods.write(2, values.getEntitySize(loc.getX())); mods.write(2, values.getEntitySize(loc.getX()));
mods.write(3, (int) Math.floor(loc.getY() * 32D)); mods.write(3, (int) Math.floor(loc.getY() * 32D));
mods.write(4, values.getEntitySize(loc.getZ())); mods.write(4, values.getEntitySize(loc.getZ()));
@ -480,8 +490,9 @@ public class PacketsManager {
} }
switch (disguise.getType()) { switch (disguise.getType()) {
case BAT: case BAT:
if (entity instanceof LivingEntity) if (entity instanceof LivingEntity) {
return yMod + ((LivingEntity) entity).getEyeHeight(); return yMod + ((LivingEntity) entity).getEyeHeight();
}
case MINECART: case MINECART:
case MINECART_COMMAND: case MINECART_COMMAND:
case MINECART_CHEST: case MINECART_CHEST:
@ -528,6 +539,7 @@ public class PacketsManager {
/** /**
* Creates the packet listeners * Creates the packet listeners
*
* @param plugin * @param plugin
*/ */
public static void init(LibsDisguises plugin) { public static void init(LibsDisguises plugin) {
@ -608,8 +620,9 @@ public class PacketsManager {
if (disguise.isSoundsReplaced()) { if (disguise.isSoundsReplaced()) {
String sound = null; String sound = null;
DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name()); DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name());
if (dSound != null) if (dSound != null) {
sound = dSound.getSound(soundType); sound = dSound.getSound(soundType);
}
if (sound == null) { if (sound == null) {
event.setCancelled(true); event.setCancelled(true);
@ -655,8 +668,9 @@ public class PacketsManager {
float pitch = (Integer) mods.read(5); float pitch = (Integer) mods.read(5);
if (baby) { if (baby) {
// If the pitch is not the expected // If the pitch is not the expected
if (pitch > 97 || pitch < 111) if (pitch > 97 || pitch < 111) {
return; return;
}
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;
// Min = 1.5 // Min = 1.5
// Cap = 97.5 // Cap = 97.5
@ -664,8 +678,9 @@ public class PacketsManager {
// Cap = 110.5 // Cap = 110.5
} else { } else {
// If the pitch is not the expected // If the pitch is not the expected
if (pitch >= 63 || pitch <= 76) if (pitch >= 63 || pitch <= 76) {
return; return;
}
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F;
// Min = 1 // Min = 1
// Cap = 63 // Cap = 63
@ -673,10 +688,12 @@ public class PacketsManager {
// Cap = 75.6 // Cap = 75.6
} }
pitch *= 63; pitch *= 63;
if (pitch < 0) if (pitch < 0) {
pitch = 0; pitch = 0;
if (pitch > 255) }
if (pitch > 255) {
pitch = 255; pitch = 255;
}
mods.write(5, (int) pitch); mods.write(5, (int) pitch);
} }
} }
@ -694,8 +711,9 @@ public class PacketsManager {
if (disguise != null && !disguise.getType().isPlayer() if (disguise != null && !disguise.getType().isPlayer()
&& (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) { && (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) {
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
if (disSound == null) if (disSound == null) {
return; return;
}
SoundType soundType = null; SoundType soundType = null;
Object obj = null; Object obj = null;
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
@ -717,9 +735,10 @@ public class PacketsManager {
|| (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) { || (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) {
if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) { if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) {
cancelSound = !cancelSound; cancelSound = !cancelSound;
if (cancelSound) if (cancelSound) {
return; return;
} }
}
disSound = DisguiseSound.getType(disguise.getType().name()); disSound = DisguiseSound.getType(disguise.getType().name());
if (disSound != null) { if (disSound != null) {
String sound = disSound.getSound(soundType); String sound = disSound.getSound(soundType);
@ -735,15 +754,19 @@ public class PacketsManager {
float pitch; float pitch;
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;
} else } else {
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F;
if (disguise.getType() == DisguiseType.BAT) }
if (disguise.getType() == DisguiseType.BAT) {
pitch *= 95F; pitch *= 95F;
}
pitch *= 63; pitch *= 63;
if (pitch < 0) if (pitch < 0) {
pitch = 0; pitch = 0;
if (pitch > 255) }
if (pitch > 255) {
pitch = 255; pitch = 255;
}
mods.write(5, (int) pitch); mods.write(5, (int) pitch);
try { try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
@ -768,8 +791,9 @@ public class PacketsManager {
PacketType.Play.Server.UPDATE_ATTRIBUTES, PacketType.Play.Server.ENTITY_STATUS) { PacketType.Play.Server.UPDATE_ATTRIBUTES, PacketType.Play.Server.ENTITY_STATUS) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
if (event.isCancelled()) if (event.isCancelled()) {
return; return;
}
final Player observer = event.getPlayer(); final Player observer = event.getPlayer();
if (event.getPacket().getIntegers().read(0) == observer.getEntityId()) { if (event.getPacket().getIntegers().read(0) == observer.getEntityId()) {
if (DisguiseAPI.isSelfDisguised(observer)) { if (DisguiseAPI.isSelfDisguised(observer)) {
@ -813,8 +837,9 @@ public class PacketsManager {
if (watch.getIndex() == 0) { if (watch.getIndex() == 0) {
byte b = (Byte) watch.getValue(); byte b = (Byte) watch.getValue();
byte a = (byte) (b | 1 << 5); byte a = (byte) (b | 1 << 5);
if ((b & 1 << 3) != 0) if ((b & 1 << 3) != 0) {
a = (byte) (a | 1 << 3); a = (byte) (a | 1 << 3);
}
watch.setValue(a); watch.setValue(a);
} }
} }
@ -825,8 +850,9 @@ public class PacketsManager {
mods.write(0, observer.getEntityId()); mods.write(0, observer.getEntityId());
List<WrappedWatchableObject> watchableList = new ArrayList<>(); List<WrappedWatchableObject> watchableList = new ArrayList<>();
byte b = (byte) 1 << 5; byte b = (byte) 1 << 5;
if (observer.isSprinting()) if (observer.isSprinting()) {
b = (byte) (b | 1 << 3); b = (byte) (b | 1 << 3);
}
watchableList.add(new WrappedWatchableObject(0, b)); watchableList.add(new WrappedWatchableObject(0, b));
packet.getWatchableCollectionModifier().write(0, watchableList); packet.getWatchableCollectionModifier().write(0, watchableList);
try { try {
@ -865,8 +891,9 @@ public class PacketsManager {
PacketType.Play.Client.SET_CREATIVE_SLOT, PacketType.Play.Client.WINDOW_CLICK) { PacketType.Play.Client.SET_CREATIVE_SLOT, PacketType.Play.Client.WINDOW_CLICK) {
@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() instanceof com.comphenix.net.sf.cglib.proxy.Factory) if (!(event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory)
&& event.getPlayer().getVehicle() == null) { && event.getPlayer().getVehicle() == null) {
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer()); Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
@ -915,8 +942,7 @@ public class PacketsManager {
} }
} }
} }
} } // 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.
@ -1197,8 +1223,9 @@ public class PacketsManager {
mainListener = new PacketAdapter(libsDisguises, ListenerPriority.HIGH, packetsToListen) { mainListener = new PacketAdapter(libsDisguises, ListenerPriority.HIGH, packetsToListen) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
if (event.isCancelled()) if (event.isCancelled()) {
return; return;
}
final Player observer = event.getPlayer(); final Player observer = event.getPlayer();
// First get the entity, the one sending this packet // First get the entity, the one sending this packet
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld()); StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
@ -1206,8 +1233,9 @@ public class PacketsManager {
.read((PacketType.Play.Server.COLLECT == event.getPacketType() ? 1 : 0)); .read((PacketType.Play.Server.COLLECT == event.getPacketType() ? 1 : 0));
// If the entity is the same as the sender. Don't disguise! // If the entity is the same as the sender. Don't disguise!
// Prevents problems and there is no advantage to be gained. // Prevents problems and there is no advantage to be gained.
if (entity == observer) if (entity == observer) {
return; return;
}
PacketContainer[][] packets = transformPacket(event.getPacket(), event.getPlayer(), entity); PacketContainer[][] packets = transformPacket(event.getPacket(), event.getPlayer(), entity);
if (packets != null) { if (packets != null) {
event.setCancelled(true); event.setCancelled(true);
@ -1267,8 +1295,12 @@ public class PacketsManager {
} }
/** /**
* Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not * Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not transformed
* transformed *
* @param sentPacket
* @param observer
* @param entity
* @return
*/ */
public static PacketContainer[][] transformPacket(PacketContainer sentPacket, Player observer, Entity entity) { public static PacketContainer[][] transformPacket(PacketContainer sentPacket, Player observer, Entity entity) {
PacketContainer[] packets = null; PacketContainer[] packets = null;
@ -1312,9 +1344,7 @@ public class PacketsManager {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} }
} }
} } // Else if the packet is sending entity metadata
// Else if the packet is sending entity metadata
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_METADATA) { else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_METADATA) {
if (DisguiseConfig.isMetadataPacketsEnabled()) { if (DisguiseConfig.isMetadataPacketsEnabled()) {
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert( List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(
@ -1327,9 +1357,7 @@ public class PacketsManager {
} else { } else {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} }
} } // Else if the packet is spawning..
// Else if the packet is spawning..
else if (sentPacket.getType() == PacketType.Play.Server.NAMED_ENTITY_SPAWN else if (sentPacket.getType() == PacketType.Play.Server.NAMED_ENTITY_SPAWN
|| sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_LIVING || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_LIVING
|| sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB
@ -1338,9 +1366,7 @@ public class PacketsManager {
PacketContainer[][] spawnPackets = constructSpawnPackets(observer, disguise, entity); PacketContainer[][] spawnPackets = constructSpawnPackets(observer, disguise, entity);
packets = spawnPackets[0]; packets = spawnPackets[0];
delayedPackets = spawnPackets[1]; delayedPackets = spawnPackets[1];
} } // Else if the disguise is attempting to send players a forbidden packet
// Else if the disguise is attempting to send players a forbidden packet
else if (sentPacket.getType() == PacketType.Play.Server.ANIMATION) { else if (sentPacket.getType() == PacketType.Play.Server.ANIMATION) {
if (disguise.getType().isMisc() if (disguise.getType().isMisc()
|| (packets[0].getIntegers().read(1) == 2 && (!disguise.getType() || (packets[0].getIntegers().read(1) == 2 && (!disguise.getType()
@ -1348,9 +1374,7 @@ public class PacketsManager {
.getWatcher()).isSleeping())))) { .getWatcher()).isSleeping())))) {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} }
} } else if (sentPacket.getType() == PacketType.Play.Server.COLLECT) {
else if (sentPacket.getType() == PacketType.Play.Server.COLLECT) {
if (disguise.getType().isMisc()) { if (disguise.getType().isMisc()) {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() } else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer()
@ -1361,9 +1385,7 @@ public class PacketsManager {
mods.write(1, 3); mods.write(1, 3);
packets = new PacketContainer[]{newPacket, sentPacket}; packets = new PacketContainer[]{newPacket, sentPacket};
} }
} } // Else if the disguise is moving.
// Else if the disguise is moving.
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_MOVE_LOOK else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_MOVE_LOOK
|| sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK || sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK
|| sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT || sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT
@ -1393,9 +1415,9 @@ public class PacketsManager {
packets[0] = sentPacket.shallowClone(); packets[0] = sentPacket.shallowClone();
StructureModifier<Byte> bytes = packets[0].getBytes(); StructureModifier<Byte> bytes = packets[0].getBytes();
boolean tele = sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT; boolean tele = sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT;
byte yawValue = (Byte) bytes.read(tele ? 0 : 3); byte yawValue = bytes.read(tele ? 0 : 3);
bytes.write(tele ? 0 : 3, getYaw(disguise.getType(), entity.getType(), yawValue)); bytes.write(tele ? 0 : 3, getYaw(disguise.getType(), entity.getType(), yawValue));
byte pitchValue = (Byte) bytes.read(tele ? 1 : 4); byte pitchValue = bytes.read(tele ? 1 : 4);
bytes.write(tele ? 1 : 4, bytes.write(tele ? 1 : 4,
getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue)); getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue));
if (tele && disguise.getType() == DisguiseType.ITEM_FRAME) { if (tele && disguise.getType() == DisguiseType.ITEM_FRAME) {
@ -1412,16 +1434,15 @@ public class PacketsManager {
double y = getYModifier(entity, disguise); double y = getYModifier(entity, disguise);
if (y != 0) { if (y != 0) {
y *= 32; y *= 32;
ints.write(2, (Integer) ints.read(2) + (int) Math.floor(y)); ints.write(2, ints.read(2) + (int) Math.floor(y));
} }
} }
} }
} } else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
int slot = (Integer) packets[0].getModifier().read(1) - 1; int slot = (Integer) packets[0].getModifier().read(1) - 1;
if (slot < 0) if (slot < 0) {
slot = 4; slot = 4;
}
org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot); org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot);
if (itemstack != null) { if (itemstack != null) {
packets[0] = packets[0].shallowClone(); packets[0] = packets[0].shallowClone();
@ -1461,21 +1482,15 @@ public class PacketsManager {
// it. // it.
} }
} }
} } else if (sentPacket.getType() == PacketType.Play.Server.BED) {
else if (sentPacket.getType() == PacketType.Play.Server.BED) {
if (!disguise.getType().isPlayer()) { if (!disguise.getType().isPlayer()) {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} }
} } else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_STATUS) {
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_STATUS) {
if (packets[0].getBytes().read(0) == (byte) 3) { if (packets[0].getBytes().read(0) == (byte) 3) {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} }
} } else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_HEAD_ROTATION) {
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_HEAD_ROTATION) {
if (disguise.getType().isPlayer() && entity.getType() != EntityType.PLAYER) { if (disguise.getType().isPlayer() && entity.getType() != EntityType.PLAYER) {
Location loc = entity.getLocation(); Location loc = entity.getLocation();
byte pitch = getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), byte pitch = getPitch(disguise.getType(), DisguiseType.getType(entity.getType()),
@ -1491,9 +1506,7 @@ public class PacketsManager {
look.getBytes().write(4, pitch); look.getBytes().write(4, pitch);
packets = new PacketContainer[]{look, rotation}; packets = new PacketContainer[]{look, rotation};
} }
} } else {
else {
packets = null; packets = null;
} }

@ -31,8 +31,10 @@ import org.bukkit.potion.PotionEffect;
public class ReflectionManager { public class ReflectionManager {
public enum LibVersion { public enum LibVersion {
V1_8; V1_8;
private static LibVersion currentVersion; private static LibVersion currentVersion;
static { static {
//String mcVersion = Bukkit.getVersion().split("MC: ")[1].replace(")", ""); //String mcVersion = Bukkit.getVersion().split("MC: ")[1].replace(")", "");
currentVersion = V1_8; currentVersion = V1_8;
@ -59,8 +61,7 @@ public class ReflectionManager {
private static Map<String, Map<String, String>> ForgeFieldMappings; private static Map<String, Map<String, String>> ForgeFieldMappings;
/** /**
* Map of Forge fully qualified class names to a map from mc-dev method names to a map from method signatures to Forge method * Map of Forge fully qualified class names to a map from mc-dev method names to a map from method signatures to Forge method names.
* names.
*/ */
private static Map<String, Map<String, Map<String, String>>> ForgeMethodMappings; private static Map<String, Map<String, Map<String, String>>> ForgeMethodMappings;
private static final Method ihmGet; private static final Method ihmGet;
@ -607,10 +608,8 @@ public class ReflectionManager {
public static void setAllowSleep(Player player) { public static void setAllowSleep(Player player) {
try { try {
/** /**
Object nmsEntity = getNmsEntity(player); * Object nmsEntity = getNmsEntity(player); Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity); Field check = getNmsField(connection.getClass(), "checkMovement"); check.setBoolean(connection, true); *
Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity); */
Field check = getNmsField(connection.getClass(), "checkMovement");
check.setBoolean(connection, true); **/
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(System.out); ex.printStackTrace(System.out);
} }

@ -7,6 +7,7 @@ import java.net.URL;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class UpdateChecker { public class UpdateChecker {
private String latestVersion; private String latestVersion;
private boolean checkHigher(String currentVersion, String newVersion) { private boolean checkHigher(String currentVersion, String newVersion) {
@ -51,8 +52,9 @@ public class UpdateChecker {
private String toReadable(String version) { private String toReadable(String version) {
String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", "")); String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", ""));
version = ""; version = "";
for (String s : split) for (String s : split) {
version += String.format("%4s", s); version += String.format("%4s", s);
}
return version; return version;
} }
} }

@ -1,6 +1,6 @@
name: LibsDisguises name: LibsDisguises
main: me.libraryaddict.disguise.LibsDisguises main: me.libraryaddict.disguise.LibsDisguises
version: 8.6.3 version: 8.6.4
author: libraryaddict author: libraryaddict
authors: [Byteflux, Navid K.] authors: [Byteflux, Navid K.]
depend: [ProtocolLib] depend: [ProtocolLib]
@ -54,6 +54,9 @@ commands:
description: Toggle seeing your own disguise on or off. description: Toggle seeing your own disguise on or off.
permissions: permissions:
libsdisguises.reload:
description: Allows the user to reload LibsDisguises.
default: op
libsdisguises.seethrough: libsdisguises.seethrough:
description: Allows player to see through disguises. description: Allows player to see through disguises.
default: false default: false
@ -97,4 +100,3 @@ permissions:
description: See the /undisguiseradius command in tab-completion description: See the /undisguiseradius command in tab-completion
libsdisguises.seecmd.disguiseclone: libsdisguises.seecmd.disguiseclone:
description: See the /disguiseclone command in tab-completion description: See the /disguiseclone command in tab-completion