Minor cleanup of code, fixed setSkin not working as intended
This commit is contained in:
parent
477464851e
commit
2522b0eefd
@ -1,10 +1,17 @@
|
|||||||
package me.libraryaddict.disguise.commands;
|
package me.libraryaddict.disguise.commands;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||||
import java.util.ArrayList;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import java.util.HashMap;
|
import me.libraryaddict.disguise.DisguiseConfig;
|
||||||
import java.util.List;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||||
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseParser;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
|
||||||
|
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
|
||||||
|
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -14,16 +21,10 @@ import org.bukkit.command.TabCompleter;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import java.lang.reflect.Method;
|
||||||
import me.libraryaddict.disguise.DisguiseConfig;
|
import java.util.ArrayList;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import java.util.HashMap;
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import java.util.List;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseParser;
|
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException;
|
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
|
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
|
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
|
|
||||||
|
|
||||||
public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter {
|
public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter {
|
||||||
@Override
|
@Override
|
||||||
@ -69,8 +70,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
|
|
||||||
if (disguise.isDisguiseInUse()) {
|
if (disguise.isDisguiseInUse()) {
|
||||||
sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable());
|
sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
sender.sendMessage(ChatColor.RED + "Failed to disguise as a " + disguise.getType().toReadable());
|
sender.sendMessage(ChatColor.RED + "Failed to disguise as a " + disguise.getType().toReadable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,8 +88,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
for (String type : getAllowedDisguises(perms)) {
|
for (String type : getAllowedDisguises(perms)) {
|
||||||
tabs.add(type);
|
tabs.add(type);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[0]);
|
DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[0]);
|
||||||
|
|
||||||
if (disguiseType == null)
|
if (disguiseType == null)
|
||||||
@ -100,8 +99,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
tabs.add(player.getName());
|
tabs.add(player.getName());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ArrayList<String> usedOptions = new ArrayList<String>();
|
ArrayList<String> usedOptions = new ArrayList<String>();
|
||||||
|
|
||||||
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
|
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
|
||||||
@ -131,8 +129,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
|
for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
|
||||||
tabs.add(e);
|
tabs.add(e);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (info.getParamClass() == String.class) {
|
if (info.getParamClass() == String.class) {
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
tabs.add(player.getName());
|
tabs.add(player.getName());
|
||||||
@ -144,7 +141,8 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
|
|
||||||
if (addMethods) {
|
if (addMethods) {
|
||||||
// If this is a method, add. Else if it can be a param of the previous argument, add.
|
// If this is a method, add. Else if it can be a param of the previous argument, add.
|
||||||
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
|
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(
|
||||||
|
disguiseType.getWatcherClass())) {
|
||||||
tabs.add(method.getName());
|
tabs.add(method.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,11 +157,12 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
* Send the player the information
|
* Send the player the information
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
|
protected void sendCommandUsage(CommandSender sender,
|
||||||
|
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
|
||||||
ArrayList<String> allowedDisguises = getAllowedDisguises(map);
|
ArrayList<String> allowedDisguises = getAllowedDisguises(map);
|
||||||
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(
|
||||||
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
|
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>");
|
||||||
|
@ -240,6 +240,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
|||||||
if (isDisguiseInUse() || skinToUse == null)
|
if (isDisguiseInUse() || skinToUse == null)
|
||||||
return super.startDisguise();
|
return super.startDisguise();
|
||||||
|
|
||||||
|
if (getGameProfile() == null) {
|
||||||
currentLookup = new LibsProfileLookup() {
|
currentLookup = new LibsProfileLookup() {
|
||||||
@Override
|
@Override
|
||||||
public void onLookup(WrappedGameProfile gameProfile) {
|
public void onLookup(WrappedGameProfile gameProfile) {
|
||||||
@ -258,6 +259,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
|||||||
if (gameProfile != null) {
|
if (gameProfile != null) {
|
||||||
setSkin(gameProfile);
|
setSkin(gameProfile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return super.startDisguise();
|
return super.startDisguise();
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,8 @@ public class PacketsManager {
|
|||||||
/**
|
/**
|
||||||
* Construct the packets I need to spawn in the disguise
|
* Construct the packets I need to spawn in the disguise
|
||||||
*/
|
*/
|
||||||
private static LibsPackets constructSpawnPackets(final Player observer, LibsPackets packets, Entity disguisedEntity) {
|
private static LibsPackets constructSpawnPackets(final Player observer, LibsPackets packets,
|
||||||
|
Entity disguisedEntity) {
|
||||||
Disguise disguise = packets.getDisguise();
|
Disguise disguise = packets.getDisguise();
|
||||||
|
|
||||||
if (disguise.getEntity() == null) {
|
if (disguise.getEntity() == null) {
|
||||||
@ -224,11 +225,9 @@ public class PacketsManager {
|
|||||||
|
|
||||||
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
|
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
|
||||||
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
|
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
|
||||||
}
|
} else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && disguisedEntity instanceof Damageable) {
|
||||||
else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity() && disguisedEntity instanceof Damageable) {
|
|
||||||
builder.baseValue(((Damageable) disguisedEntity).getMaxHealth());
|
builder.baseValue(((Damageable) disguisedEntity).getMaxHealth());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
|
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,8 +265,7 @@ public class PacketsManager {
|
|||||||
mods.write(2, loc.getY() + 0.06);
|
mods.write(2, loc.getY() + 0.06);
|
||||||
mods.write(3, loc.getZ());
|
mods.write(3, loc.getZ());
|
||||||
mods.write(4, 1);
|
mods.write(4, 1);
|
||||||
}
|
} else if (disguise.getType() == DisguiseType.PAINTING) {
|
||||||
else if (disguise.getType() == DisguiseType.PAINTING) {
|
|
||||||
PacketContainer spawnPainting = new PacketContainer(Server.SPAWN_ENTITY_PAINTING);
|
PacketContainer spawnPainting = new PacketContainer(Server.SPAWN_ENTITY_PAINTING);
|
||||||
packets.addPacket(spawnPainting);
|
packets.addPacket(spawnPainting);
|
||||||
|
|
||||||
@ -294,8 +292,7 @@ public class PacketsManager {
|
|||||||
mods.write(3, loc.getZ());
|
mods.write(3, loc.getZ());
|
||||||
mods.write(4, yaw);
|
mods.write(4, yaw);
|
||||||
mods.write(5, pitch);
|
mods.write(5, pitch);
|
||||||
}
|
} else if (disguise.getType().isPlayer()) {
|
||||||
else if (disguise.getType().isPlayer()) {
|
|
||||||
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
|
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
|
||||||
|
|
||||||
String name = playerDisguise.getName();
|
String name = playerDisguise.getName();
|
||||||
@ -306,8 +303,6 @@ public class PacketsManager {
|
|||||||
removeName = !DisguiseUtilities.getAddedByPlugins().contains(name);
|
removeName = !DisguiseUtilities.getAddedByPlugins().contains(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
WrappedGameProfile gameProfile = playerDisguise.getGameProfile();
|
|
||||||
|
|
||||||
if (removeName) {
|
if (removeName) {
|
||||||
DisguiseUtilities.getAddedByPlugins().remove(name);
|
DisguiseUtilities.getAddedByPlugins().remove(name);
|
||||||
}
|
}
|
||||||
@ -321,9 +316,10 @@ public class PacketsManager {
|
|||||||
// Add player to the list, necessary to spawn them
|
// Add player to the list, necessary to spawn them
|
||||||
sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
|
sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
|
||||||
|
|
||||||
|
WrappedGameProfile gameProfile = playerDisguise.getGameProfile();
|
||||||
List playerList = new ArrayList();
|
List playerList = new ArrayList();
|
||||||
|
|
||||||
playerList.add(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), playerDisguise.getGameProfile()));
|
playerList.add(ReflectionManager.getPlayerInfoData(sendTab.getHandle(), gameProfile));
|
||||||
sendTab.getModifier().write(1, playerList);
|
sendTab.getModifier().write(1, playerList);
|
||||||
|
|
||||||
// Spawn the player
|
// Spawn the player
|
||||||
@ -339,9 +335,9 @@ public class PacketsManager {
|
|||||||
WrappedDataWatcher newWatcher;
|
WrappedDataWatcher newWatcher;
|
||||||
|
|
||||||
if (selfDisguise) {
|
if (selfDisguise) {
|
||||||
newWatcher = createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
newWatcher = createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
|
||||||
}
|
disguise.getWatcher());
|
||||||
else {
|
} else {
|
||||||
newWatcher = new WrappedDataWatcher();
|
newWatcher = new WrappedDataWatcher();
|
||||||
|
|
||||||
spawnAt = observer.getLocation();
|
spawnAt = observer.getLocation();
|
||||||
@ -361,7 +357,8 @@ public class PacketsManager {
|
|||||||
spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
|
spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
|
||||||
|
|
||||||
// Make him invisible
|
// Make him invisible
|
||||||
newWatcher.setObject(new WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(), Registry.get(Byte.class)),
|
newWatcher.setObject(
|
||||||
|
new WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(), Registry.get(Byte.class)),
|
||||||
(byte) 32);
|
(byte) 32);
|
||||||
|
|
||||||
packets.addPacket(spawnPlayer);
|
packets.addPacket(spawnPlayer);
|
||||||
@ -374,8 +371,7 @@ public class PacketsManager {
|
|||||||
for (PacketContainer packet : bedPackets) {
|
for (PacketContainer packet : bedPackets) {
|
||||||
packets.addPacket(packet);
|
packets.addPacket(packet);
|
||||||
}
|
}
|
||||||
}
|
} else if (!selfDisguise) {
|
||||||
else if (!selfDisguise) {
|
|
||||||
// Teleport the player back to where he's supposed to be
|
// Teleport the player back to where he's supposed to be
|
||||||
PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||||
|
|
||||||
@ -397,7 +393,8 @@ public class PacketsManager {
|
|||||||
// Send a metadata packet
|
// Send a metadata packet
|
||||||
PacketContainer metaPacket = new PacketContainer(Play.Server.ENTITY_METADATA);
|
PacketContainer metaPacket = new PacketContainer(Play.Server.ENTITY_METADATA);
|
||||||
|
|
||||||
newWatcher = createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
newWatcher = createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
|
||||||
|
disguise.getWatcher());
|
||||||
|
|
||||||
metaPacket.getIntegers().write(0, entityId); // Id
|
metaPacket.getIntegers().write(0, entityId); // Id
|
||||||
metaPacket.getWatchableCollectionModifier().write(0, newWatcher.getWatchableObjects());
|
metaPacket.getWatchableCollectionModifier().write(0, newWatcher.getWatchableObjects());
|
||||||
@ -417,8 +414,7 @@ public class PacketsManager {
|
|||||||
if (!((PlayerDisguise) disguise).isDisplayedInTab()) {
|
if (!((PlayerDisguise) disguise).isDisplayedInTab()) {
|
||||||
packets.addDelayedPacket(deleteTab, 40);
|
packets.addDelayedPacket(deleteTab, 40);
|
||||||
}
|
}
|
||||||
}
|
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
|
||||||
else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
|
|
||||||
Vector vec = disguisedEntity.getVelocity();
|
Vector vec = disguisedEntity.getVelocity();
|
||||||
|
|
||||||
PacketContainer spawnEntity = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
|
PacketContainer spawnEntity = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
|
||||||
@ -460,27 +456,24 @@ public class PacketsManager {
|
|||||||
|
|
||||||
spawnEntity.getDataWatcherModifier().write(0,
|
spawnEntity.getDataWatcherModifier().write(0,
|
||||||
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||||
}
|
} else if (disguise.getType().isMisc()) {
|
||||||
else if (disguise.getType().isMisc()) {
|
|
||||||
int objectId = disguise.getType().getObjectId();
|
int objectId = disguise.getType().getObjectId();
|
||||||
int data = ((MiscDisguise) disguise).getData();
|
int data = ((MiscDisguise) disguise).getData();
|
||||||
|
|
||||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
||||||
data = ReflectionManager.getCombinedId(((MiscDisguise) disguise).getId(), data);
|
data = ReflectionManager.getCombinedId(((MiscDisguise) disguise).getId(), data);
|
||||||
}
|
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) {
|
||||||
else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) {
|
|
||||||
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id
|
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id
|
||||||
data = observer.getEntityId();
|
data = observer.getEntityId();
|
||||||
}
|
} else if (disguise.getType() == DisguiseType.ITEM_FRAME) {
|
||||||
else if (disguise.getType() == DisguiseType.ITEM_FRAME) {
|
|
||||||
data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4;
|
data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
|
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
|
||||||
|
|
||||||
PacketContainer spawnEntity = ProtocolLibrary.getProtocolManager()
|
PacketContainer spawnEntity = ProtocolLibrary.getProtocolManager().createPacketConstructor(
|
||||||
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
|
PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data).createPacket(nmsEntity, objectId,
|
||||||
.createPacket(nmsEntity, objectId, data);
|
data);
|
||||||
packets.addPacket(spawnEntity);
|
packets.addPacket(spawnEntity);
|
||||||
|
|
||||||
spawnEntity.getModifier().write(8, pitch);
|
spawnEntity.getModifier().write(8, pitch);
|
||||||
@ -489,8 +482,7 @@ public class PacketsManager {
|
|||||||
if (disguise.getType() == DisguiseType.ITEM_FRAME) {
|
if (disguise.getType() == DisguiseType.ITEM_FRAME) {
|
||||||
if (data % 2 == 0) {
|
if (data % 2 == 0) {
|
||||||
spawnEntity.getModifier().write(4, loc.getZ() + (data == 0 ? -1 : 1));
|
spawnEntity.getModifier().write(4, loc.getZ() + (data == 0 ? -1 : 1));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
spawnEntity.getModifier().write(2, loc.getX() + (data == 3 ? -1 : 1));
|
spawnEntity.getModifier().write(2, loc.getX() + (data == 3 ? -1 : 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -526,8 +518,8 @@ public class PacketsManager {
|
|||||||
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled()
|
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert(
|
||||||
? flagWatcher.convert(watcher.getWatchableObjects()) : flagWatcher.getWatchableObjects();
|
watcher.getWatchableObjects()) : flagWatcher.getWatchableObjects();
|
||||||
|
|
||||||
for (WrappedWatchableObject watchableObject : list) {
|
for (WrappedWatchableObject watchableObject : list) {
|
||||||
if (watchableObject == null)
|
if (watchableObject == null)
|
||||||
@ -654,8 +646,7 @@ public class PacketsManager {
|
|||||||
public static double getYModifier(Entity entity, Disguise disguise) {
|
public static double getYModifier(Entity entity, Disguise disguise) {
|
||||||
double yMod = 0;
|
double yMod = 0;
|
||||||
|
|
||||||
if ((disguise.getType() != DisguiseType.PLAYER || !((PlayerWatcher) disguise.getWatcher()).isSleeping())
|
if ((disguise.getType() != DisguiseType.PLAYER || !((PlayerWatcher) disguise.getWatcher()).isSleeping()) && entity.getType() == EntityType.DROPPED_ITEM) {
|
||||||
&& entity.getType() == EntityType.DROPPED_ITEM) {
|
|
||||||
yMod -= 0.13;
|
yMod -= 0.13;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,8 +731,7 @@ public class PacketsManager {
|
|||||||
|
|
||||||
if (soundsListenerEnabled) {
|
if (soundsListenerEnabled) {
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(soundsListener);
|
ProtocolLibrary.getProtocolManager().addPacketListener(soundsListener);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ProtocolLibrary.getProtocolManager().removePacketListener(soundsListener);
|
ProtocolLibrary.getProtocolManager().removePacketListener(soundsListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -753,8 +743,7 @@ public class PacketsManager {
|
|||||||
|
|
||||||
if (inventoryModifierEnabled) {
|
if (inventoryModifierEnabled) {
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(inventoryListener);
|
ProtocolLibrary.getProtocolManager().addPacketListener(inventoryListener);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ProtocolLibrary.getProtocolManager().removePacketListener(inventoryListener);
|
ProtocolLibrary.getProtocolManager().removePacketListener(inventoryListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -762,8 +751,7 @@ public class PacketsManager {
|
|||||||
Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
||||||
|
|
||||||
if (disguise != null) {
|
if (disguise != null) {
|
||||||
if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible()
|
if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible() && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -841,8 +829,7 @@ public class PacketsManager {
|
|||||||
|
|
||||||
if (viewDisguisesListenerEnabled) {
|
if (viewDisguisesListenerEnabled) {
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener);
|
ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener);
|
ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -853,13 +840,11 @@ public class PacketsManager {
|
|||||||
if (disguise.isSelfDisguiseVisible()) {
|
if (disguise.isSelfDisguiseVisible()) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
DisguiseUtilities.setupFakeDisguise(disguise);
|
DisguiseUtilities.setupFakeDisguise(disguise);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
DisguiseUtilities.removeSelfDisguise(player);
|
DisguiseUtilities.removeSelfDisguise(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inventoryModifierEnabled
|
if (inventoryModifierEnabled && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -872,7 +857,8 @@ 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
|
||||||
*/
|
*/
|
||||||
public static LibsPackets transformPacket(PacketContainer sentPacket, Disguise disguise, Player observer, Entity entity) {
|
public static LibsPackets transformPacket(PacketContainer sentPacket, Disguise disguise, Player observer,
|
||||||
|
Entity entity) {
|
||||||
LibsPackets packets = new LibsPackets(disguise);
|
LibsPackets packets = new LibsPackets(disguise);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -882,8 +868,7 @@ public class PacketsManager {
|
|||||||
if (sentPacket.getType() == Server.UPDATE_ATTRIBUTES) {
|
if (sentPacket.getType() == Server.UPDATE_ATTRIBUTES) {
|
||||||
if (disguise.isMiscDisguise()) {
|
if (disguise.isMiscDisguise()) {
|
||||||
packets.clear();
|
packets.clear();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
List<WrappedAttribute> attributes = new ArrayList<>();
|
List<WrappedAttribute> attributes = new ArrayList<>();
|
||||||
|
|
||||||
for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) {
|
for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) {
|
||||||
@ -899,11 +884,9 @@ public class PacketsManager {
|
|||||||
builder = WrappedAttribute.newBuilder();
|
builder = WrappedAttribute.newBuilder();
|
||||||
builder.attributeKey("generic.maxHealth");
|
builder.attributeKey("generic.maxHealth");
|
||||||
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
|
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
|
||||||
}
|
} else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity()) {
|
||||||
else if (DisguiseConfig.isMaxHealthDeterminedByDisguisedEntity()) {
|
|
||||||
builder = WrappedAttribute.newBuilder(attribute);
|
builder = WrappedAttribute.newBuilder(attribute);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
builder = WrappedAttribute.newBuilder();
|
builder = WrappedAttribute.newBuilder();
|
||||||
builder.attributeKey("generic.maxHealth");
|
builder.attributeKey("generic.maxHealth");
|
||||||
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
|
builder.baseValue(DisguiseValues.getDisguiseValues(disguise.getType()).getMaxHealth());
|
||||||
@ -919,8 +902,7 @@ public class PacketsManager {
|
|||||||
if (!attributes.isEmpty()) {
|
if (!attributes.isEmpty()) {
|
||||||
packets.getPackets().get(0).getIntegers().write(0, entity.getEntityId());
|
packets.getPackets().get(0).getIntegers().write(0, entity.getEntityId());
|
||||||
packets.getPackets().get(0).getAttributeCollectionModifier().write(0, attributes);
|
packets.getPackets().get(0).getAttributeCollectionModifier().write(0, attributes);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
packets.clear();
|
packets.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -930,10 +912,10 @@ public class PacketsManager {
|
|||||||
else if (sentPacket.getType() == Server.ENTITY_METADATA) {
|
else if (sentPacket.getType() == Server.ENTITY_METADATA) {
|
||||||
packets.clear();
|
packets.clear();
|
||||||
|
|
||||||
if (DisguiseConfig.isMetadataPacketsEnabled()
|
if (DisguiseConfig.isMetadataPacketsEnabled() && (!cancelMeta.containsKey(disguise) || !cancelMeta.get(
|
||||||
&& (!cancelMeta.containsKey(disguise) || !cancelMeta.get(disguise).contains(observer.getUniqueId()))) {
|
disguise).contains(observer.getUniqueId()))) {
|
||||||
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher()
|
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||||
.convert(sentPacket.getWatchableCollectionModifier().read(0));
|
sentPacket.getWatchableCollectionModifier().read(0));
|
||||||
|
|
||||||
PacketContainer metaPacket = new PacketContainer(Server.ENTITY_METADATA);
|
PacketContainer metaPacket = new PacketContainer(Server.ENTITY_METADATA);
|
||||||
|
|
||||||
@ -948,9 +930,7 @@ public class PacketsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Else if the packet is spawning..
|
// Else if the packet is spawning..
|
||||||
else if (sentPacket.getType() == Server.NAMED_ENTITY_SPAWN || sentPacket.getType() == Server.SPAWN_ENTITY_LIVING
|
else if (sentPacket.getType() == Server.NAMED_ENTITY_SPAWN || sentPacket.getType() == Server.SPAWN_ENTITY_LIVING || sentPacket.getType() == Server.SPAWN_ENTITY_EXPERIENCE_ORB || sentPacket.getType() == Server.SPAWN_ENTITY || sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING) {
|
||||||
|| sentPacket.getType() == Server.SPAWN_ENTITY_EXPERIENCE_ORB || sentPacket.getType() == Server.SPAWN_ENTITY
|
|
||||||
|| sentPacket.getType() == Server.SPAWN_ENTITY_PAINTING) {
|
|
||||||
packets.clear();
|
packets.clear();
|
||||||
|
|
||||||
constructSpawnPackets(observer, packets, entity);
|
constructSpawnPackets(observer, packets, entity);
|
||||||
@ -958,8 +938,8 @@ public class PacketsManager {
|
|||||||
|
|
||||||
// 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() == Server.ANIMATION) {
|
else if (sentPacket.getType() == Server.ANIMATION) {
|
||||||
if (disguise.getType().isMisc() || (sentPacket.getIntegers().read(1) == 2 && (!disguise.getType().isPlayer()
|
if (disguise.getType().isMisc() || (sentPacket.getIntegers().read(
|
||||||
|| (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping())))) {
|
1) == 2 && (!disguise.getType().isPlayer() || (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping())))) {
|
||||||
packets.clear();
|
packets.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -968,10 +948,7 @@ public class PacketsManager {
|
|||||||
else if (sentPacket.getType() == Server.COLLECT) {
|
else if (sentPacket.getType() == Server.COLLECT) {
|
||||||
if (disguise.getType().isMisc()) {
|
if (disguise.getType().isMisc()) {
|
||||||
packets.clear();
|
packets.clear();
|
||||||
}
|
} else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
|
||||||
|
|
||||||
else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer()
|
|
||||||
&& ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
|
|
||||||
PacketContainer newPacket = new PacketContainer(Server.ANIMATION);
|
PacketContainer newPacket = new PacketContainer(Server.ANIMATION);
|
||||||
|
|
||||||
StructureModifier<Integer> mods = newPacket.getIntegers();
|
StructureModifier<Integer> mods = newPacket.getIntegers();
|
||||||
@ -986,16 +963,16 @@ public class PacketsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Else if the disguise is moving.
|
// Else if the disguise is moving.
|
||||||
else if (sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK || sentPacket.getType() == Server.ENTITY_LOOK
|
else if (sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK || sentPacket.getType() == Server.ENTITY_LOOK || sentPacket.getType() == Server.ENTITY_TELEPORT || sentPacket.getType() == Server.REL_ENTITY_MOVE) {
|
||||||
|| sentPacket.getType() == Server.ENTITY_TELEPORT || sentPacket.getType() == Server.REL_ENTITY_MOVE) {
|
if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE || sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) {
|
||||||
if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE
|
|
||||||
|| sentPacket.getType() == Server.REL_ENTITY_MOVE_LOOK)) {
|
|
||||||
// Rabbit robbing...
|
// Rabbit robbing...
|
||||||
if (entity.getMetadata("LibsRabbitHop").isEmpty()
|
if (entity.getMetadata(
|
||||||
|| System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() < 100
|
"LibsRabbitHop").isEmpty() || System.currentTimeMillis() - entity.getMetadata(
|
||||||
|| System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) {
|
"LibsRabbitHop").get(0).asLong() < 100 || System.currentTimeMillis() - entity.getMetadata(
|
||||||
if (entity.getMetadata("LibsRabbitHop").isEmpty()
|
"LibsRabbitHop").get(0).asLong() > 500) {
|
||||||
|| System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) {
|
if (entity.getMetadata(
|
||||||
|
"LibsRabbitHop").isEmpty() || System.currentTimeMillis() - entity.getMetadata(
|
||||||
|
"LibsRabbitHop").get(0).asLong() > 500) {
|
||||||
entity.removeMetadata("LibsRabbitHop", libsDisguises);
|
entity.removeMetadata("LibsRabbitHop", libsDisguises);
|
||||||
entity.setMetadata("LibsRabbitHop",
|
entity.setMetadata("LibsRabbitHop",
|
||||||
new FixedMetadataValue(libsDisguises, System.currentTimeMillis()));
|
new FixedMetadataValue(libsDisguises, System.currentTimeMillis()));
|
||||||
@ -1012,8 +989,7 @@ public class PacketsManager {
|
|||||||
// Stop wither skulls from looking
|
// Stop wither skulls from looking
|
||||||
if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) {
|
if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) {
|
||||||
packets.clear();
|
packets.clear();
|
||||||
}
|
} else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) {
|
||||||
else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) {
|
|
||||||
packets.clear();
|
packets.clear();
|
||||||
|
|
||||||
PacketContainer movePacket = sentPacket.shallowClone();
|
PacketContainer movePacket = sentPacket.shallowClone();
|
||||||
@ -1038,8 +1014,7 @@ public class PacketsManager {
|
|||||||
if (data % 2 == 0) {
|
if (data % 2 == 0) {
|
||||||
if (data % 2 == 0) {
|
if (data % 2 == 0) {
|
||||||
doubles.write(3, loc.getZ());
|
doubles.write(3, loc.getZ());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
doubles.write(1, loc.getZ());
|
doubles.write(1, loc.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1055,7 +1030,8 @@ public class PacketsManager {
|
|||||||
|
|
||||||
// Else if the disguise is updating equipment
|
// Else if the disguise is updating equipment
|
||||||
else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT) {
|
else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT) {
|
||||||
EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1));
|
EquipmentSlot slot = ReflectionManager.createEquipmentSlot(
|
||||||
|
packets.getPackets().get(0).getModifier().read(1));
|
||||||
|
|
||||||
org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot);
|
org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot);
|
||||||
|
|
||||||
@ -1084,8 +1060,7 @@ public class PacketsManager {
|
|||||||
list.add(watch);
|
list.add(watch);
|
||||||
|
|
||||||
list = disguise.getWatcher().convert(list);
|
list = disguise.getWatcher().convert(list);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
|
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
|
||||||
if (obj.getIndex() == 0) {
|
if (obj.getIndex() == 0) {
|
||||||
list.add(obj);
|
list.add(obj);
|
||||||
@ -1163,8 +1138,7 @@ public class PacketsManager {
|
|||||||
packets.addPacket(look);
|
packets.addPacket(look);
|
||||||
packets.addPacket(rotation);
|
packets.addPacket(rotation);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
packets.setUnhandled();
|
packets.setUnhandled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,18 +113,9 @@ public class ReflectionManager {
|
|||||||
ArrayList<Map<String, String>> properties = (ArrayList) response.get("properties");
|
ArrayList<Map<String, String>> properties = (ArrayList) response.get("properties");
|
||||||
|
|
||||||
for (Map<String, String> s : properties) {
|
for (Map<String, String> s : properties) {
|
||||||
String gName = null;
|
String gName = s.containsKey("name") ? s.get("name") : null;
|
||||||
String gValue = null;
|
String gValue = s.containsKey("value") ? s.get("value") : null;
|
||||||
String gSigned = null;
|
String gSigned = s.containsKey("signature") ? s.get("signature") : null;
|
||||||
|
|
||||||
if (s.containsKey("name"))
|
|
||||||
gName = s.get("name");
|
|
||||||
|
|
||||||
if (s.containsKey("value"))
|
|
||||||
gValue = s.get("value");
|
|
||||||
|
|
||||||
if (s.containsKey("signature"))
|
|
||||||
gSigned = s.get("signature");
|
|
||||||
|
|
||||||
gameProfile.getProperties().put(gName, new WrappedSignedProperty(gName, gValue, gSigned));
|
gameProfile.getProperties().put(gName, new WrappedSignedProperty(gName, gValue, gSigned));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user