mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-11-04 08:59:47 +01:00
- Cleaned up code
- Future proofed code via reflection again (DamageSource in PacketsManager)
This commit is contained in:
parent
8955290dc7
commit
758df7990e
@ -9,7 +9,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.7'
|
ext.disguisesVersion = '8.6.8'
|
||||||
|
|
||||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||||
|
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
package me.libraryaddict.disguise;
|
package me.libraryaddict.disguise;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
@ -20,7 +13,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||||
|
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -33,6 +25,13 @@ import org.bukkit.inventory.HorseInventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DisguiseAPI {
|
public class DisguiseAPI {
|
||||||
|
|
||||||
public static Disguise constructDisguise(Entity entity) {
|
public static Disguise constructDisguise(Entity entity) {
|
||||||
@ -47,7 +46,7 @@ public class DisguiseAPI {
|
|||||||
} else if (disguiseType.isMob()) {
|
} else if (disguiseType.isMob()) {
|
||||||
disguise = new MobDisguise(disguiseType);
|
disguise = new MobDisguise(disguiseType);
|
||||||
} else {
|
} else {
|
||||||
disguise = new PlayerDisguise(((Player) entity).getName());
|
disguise = new PlayerDisguise(entity.getName());
|
||||||
}
|
}
|
||||||
FlagWatcher watcher = disguise.getWatcher();
|
FlagWatcher watcher = disguise.getWatcher();
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
@ -105,14 +104,14 @@ public class DisguiseAPI {
|
|||||||
if (!(toCast.isInstance(value))) {
|
if (!(toCast.isInstance(value))) {
|
||||||
if (toCast == float.class) {
|
if (toCast == float.class) {
|
||||||
if (value instanceof Float) {
|
if (value instanceof Float) {
|
||||||
value = ((Float) value);
|
value = value;
|
||||||
} else {
|
} else {
|
||||||
double d = (Double) value;
|
double d = (Double) value;
|
||||||
value = (float) d;
|
value = (float) d;
|
||||||
}
|
}
|
||||||
} else if (toCast == double.class) {
|
} else if (toCast == double.class) {
|
||||||
if (value instanceof Double) {
|
if (value instanceof Double) {
|
||||||
value = ((Double) value);
|
value = value;
|
||||||
} else {
|
} else {
|
||||||
float d = (Float) value;
|
float d = (Float) value;
|
||||||
value = (double) d;
|
value = (double) d;
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
package me.libraryaddict.disguise.commands;
|
package me.libraryaddict.disguise.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.DisguiseConfig;
|
import me.libraryaddict.disguise.DisguiseConfig;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||||
import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
|
import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class DisguiseCommand extends BaseDisguiseCommand {
|
public class DisguiseCommand extends BaseDisguiseCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -38,9 +37,9 @@ public class DisguiseCommand extends BaseDisguiseCommand {
|
|||||||
}
|
}
|
||||||
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||||
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) sender).getDisplayName());
|
disguise.getWatcher().setCustomName(((Player) sender).getDisplayName());
|
||||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||||
((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true);
|
disguise.getWatcher().setCustomNameVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package me.libraryaddict.disguise.commands;
|
package me.libraryaddict.disguise.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.DisguiseConfig;
|
import me.libraryaddict.disguise.DisguiseConfig;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
@ -16,6 +13,9 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class DisguisePlayerCommand extends BaseDisguiseCommand {
|
public class DisguisePlayerCommand extends BaseDisguiseCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,9 +59,9 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand {
|
|||||||
}
|
}
|
||||||
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||||
((LivingWatcher) disguise.getWatcher()).setCustomName(player.getDisplayName());
|
disguise.getWatcher().setCustomName(player.getDisplayName());
|
||||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||||
((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true);
|
disguise.getWatcher().setCustomNameVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package me.libraryaddict.disguise.commands;
|
package me.libraryaddict.disguise.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.DisguiseConfig;
|
import me.libraryaddict.disguise.DisguiseConfig;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
@ -20,6 +16,10 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
||||||
|
|
||||||
private int maxRadius = 30;
|
private int maxRadius = 30;
|
||||||
@ -124,9 +124,9 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
|||||||
disguise = disguise.clone();
|
disguise = disguise.clone();
|
||||||
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||||
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName());
|
disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
|
||||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||||
((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true);
|
disguise.getWatcher().setCustomNameVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public enum AnimalColor {
|
|||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
private AnimalColor(int newValue) {
|
AnimalColor(int newValue) {
|
||||||
value = newValue;
|
value = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes;
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -10,6 +8,8 @@ import org.bukkit.entity.Horse;
|
|||||||
import org.bukkit.entity.Skeleton;
|
import org.bukkit.entity.Skeleton;
|
||||||
import org.bukkit.entity.Zombie;
|
import org.bukkit.entity.Zombie;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public enum DisguiseType {
|
public enum DisguiseType {
|
||||||
|
|
||||||
ARMOR_STAND(78),
|
ARMOR_STAND(78),
|
||||||
@ -195,7 +195,7 @@ public enum DisguiseType {
|
|||||||
private EntityType entityType;
|
private EntityType entityType;
|
||||||
private Class<? extends FlagWatcher> watcherClass;
|
private Class<? extends FlagWatcher> watcherClass;
|
||||||
|
|
||||||
private DisguiseType(int... ints) {
|
DisguiseType(int... ints) {
|
||||||
for (int i = 0; i < ints.length; i++) {
|
for (int i = 0; i < ints.length; i++) {
|
||||||
int value = ints[i];
|
int value = ints[i];
|
||||||
switch (i) {
|
switch (i) {
|
||||||
|
@ -1,27 +1,25 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes;
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.DisguiseConfig;
|
import me.libraryaddict.disguise.DisguiseConfig;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class FlagWatcher {
|
public class FlagWatcher {
|
||||||
|
|
||||||
@ -31,7 +29,7 @@ public class FlagWatcher {
|
|||||||
// The ints is for bukkit. Not nms slots.
|
// The ints is for bukkit. Not nms slots.
|
||||||
private int slotNo = 0;
|
private int slotNo = 0;
|
||||||
|
|
||||||
private SlotType(int no) {
|
SlotType(int no) {
|
||||||
slotNo = no;
|
slotNo = no;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +215,7 @@ public class FlagWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCustomNameVisible() {
|
public boolean isCustomNameVisible() {
|
||||||
return (Byte) getValue(3, (byte) 0) == 1;
|
return (byte) getValue(3, (byte) 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEntityAnimationsAdded() {
|
public boolean isEntityAnimationsAdded() {
|
||||||
|
@ -15,7 +15,7 @@ public enum RabbitType {
|
|||||||
|
|
||||||
private int type;
|
private int type;
|
||||||
|
|
||||||
private RabbitType(int type) {
|
RabbitType(int type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes;
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> disguiseViewers = new ArrayList<>();
|
private List<String> disguiseViewers = new ArrayList<>();
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class MinecartWatcher extends FlagWatcher {
|
public class MinecartWatcher extends FlagWatcher {
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ public class MinecartWatcher extends FlagWatcher {
|
|||||||
public void setBlockInCart(ItemStack item) {
|
public void setBlockInCart(ItemStack item) {
|
||||||
int id = item.getTypeId();
|
int id = item.getTypeId();
|
||||||
int data = item.getDurability();
|
int data = item.getDurability();
|
||||||
setValue(20, (int) (id & 0xffff | data << 16));
|
setValue(20, id & 0xffff | data << 16);
|
||||||
setValue(22, (byte) 1);
|
setValue(22, (byte) 1);
|
||||||
sendData(20, 22);
|
sendData(20, 22);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class RabbitWatcher extends AgeableWatcher {
|
public class RabbitWatcher extends AgeableWatcher {
|
||||||
|
|
||||||
public RabbitWatcher(Disguise disguise) {
|
public RabbitWatcher(Disguise disguise) {
|
||||||
@ -13,7 +13,7 @@ public class RabbitWatcher extends AgeableWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public RabbitType getType() {
|
public RabbitType getType() {
|
||||||
return RabbitType.getType((Integer) getValue(18, (int) 0));
|
return RabbitType.getType((Integer) getValue(18, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(RabbitType type) {
|
public void setType(RabbitType type) {
|
||||||
|
@ -1,16 +1,5 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
package me.libraryaddict.disguise.utilities;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.UUID;
|
|
||||||
import me.libraryaddict.disguise.DisguiseConfig;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||||
@ -19,7 +8,6 @@ import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -32,6 +20,14 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public abstract class BaseDisguiseCommand implements CommandExecutor {
|
public abstract class BaseDisguiseCommand implements CommandExecutor {
|
||||||
|
|
||||||
public class DisguiseParseException extends Exception {
|
public class DisguiseParseException extends Exception {
|
||||||
@ -506,7 +502,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
|||||||
if (int.class == param) {
|
if (int.class == param) {
|
||||||
// Parse to integer
|
// Parse to integer
|
||||||
if (isNumeric(valueString)) {
|
if (isNumeric(valueString)) {
|
||||||
value = (int) Integer.parseInt(valueString);
|
value = Integer.parseInt(valueString);
|
||||||
} else {
|
} else {
|
||||||
throw parseToException("number", valueString, methodName);
|
throw parseToException("number", valueString, methodName);
|
||||||
}
|
}
|
||||||
@ -515,7 +511,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
|||||||
if (isDouble(valueString)) {
|
if (isDouble(valueString)) {
|
||||||
float obj = Float.parseFloat(valueString);
|
float obj = Float.parseFloat(valueString);
|
||||||
if (param == float.class) {
|
if (param == float.class) {
|
||||||
value = (float) obj;
|
value = obj;
|
||||||
} else if (param == double.class) {
|
} else if (param == double.class) {
|
||||||
value = (double) obj;
|
value = (double) obj;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
package me.libraryaddict.disguise.utilities;
|
||||||
|
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
|
|
||||||
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only living disguises go in here!
|
* Only living disguises go in here!
|
||||||
*/
|
*/
|
||||||
@ -74,7 +72,7 @@ public enum DisguiseSound {
|
|||||||
|
|
||||||
public enum SoundType {
|
public enum SoundType {
|
||||||
|
|
||||||
CANCEL, DEATH, HURT, IDLE, STEP;
|
CANCEL, DEATH, HURT, IDLE, STEP
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DisguiseSound getType(String name) {
|
public static DisguiseSound getType(String name) {
|
||||||
@ -89,7 +87,7 @@ public enum DisguiseSound {
|
|||||||
private float damageSoundVolume = 1F;
|
private float damageSoundVolume = 1F;
|
||||||
private HashMap<SoundType, String> disguiseSounds = new HashMap<>();
|
private HashMap<SoundType, String> disguiseSounds = new HashMap<>();
|
||||||
|
|
||||||
private DisguiseSound(Object... sounds) {
|
DisguiseSound(Object... sounds) {
|
||||||
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;
|
||||||
|
@ -4,6 +4,6 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
|||||||
|
|
||||||
public interface LibsProfileLookup {
|
public interface LibsProfileLookup {
|
||||||
|
|
||||||
public void onLookup(WrappedGameProfile gameProfile);
|
void onLookup(WrappedGameProfile gameProfile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
|
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
|
||||||
import net.minecraft.server.v1_8_R3.DamageSource;
|
|
||||||
import org.bukkit.Art;
|
import org.bukkit.Art;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -55,9 +54,9 @@ import java.util.Random;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PacketsManager {
|
public class PacketsManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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"
|
* 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"
|
||||||
*/
|
*/
|
||||||
private static boolean cancelSound;
|
private static boolean cancelSound;
|
||||||
private static PacketListener clientInteractEntityListener;
|
private static PacketListener clientInteractEntityListener;
|
||||||
@ -78,9 +77,8 @@ 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());
|
||||||
@ -105,7 +103,7 @@ public class PacketsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -116,26 +114,19 @@ 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 disguise
|
|
||||||
* @param disguisedEntity
|
|
||||||
* @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<PacketContainer>();
|
||||||
// This sends the armor packets so that the player isn't naked.
|
// This sends the armor packets so that the player isn't naked.
|
||||||
// Please note it only sends the packets that wouldn't be sent normally
|
// Please note it only sends the packets that wouldn't be sent normally
|
||||||
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;
|
||||||
@ -160,7 +151,7 @@ public class PacketsManager {
|
|||||||
if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
|
if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
|
||||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
|
||||||
List<WrappedAttribute> attributes = new ArrayList<>();
|
List<WrappedAttribute> attributes = new ArrayList<WrappedAttribute>();
|
||||||
Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth");
|
Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth");
|
||||||
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
|
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
|
||||||
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
|
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
|
||||||
@ -219,6 +210,7 @@ public class PacketsManager {
|
|||||||
mods.write(5, pitch);
|
mods.write(5, pitch);
|
||||||
|
|
||||||
} else if (disguise.getType().isPlayer()) {
|
} else if (disguise.getType().isPlayer()) {
|
||||||
|
|
||||||
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
||||||
StructureModifier<String> stringMods = spawnPackets[0].getStrings();
|
StructureModifier<String> stringMods = spawnPackets[0].getStrings();
|
||||||
WrappedGameProfile gameProfile;
|
WrappedGameProfile gameProfile;
|
||||||
@ -270,12 +262,11 @@ public class PacketsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<PacketContainer> newPackets = new ArrayList<>();
|
ArrayList<PacketContainer> newPackets = new ArrayList<PacketContainer>();
|
||||||
newPackets.add(null);
|
newPackets.add(null);
|
||||||
for (PacketContainer spawnPacket : spawnPackets) {
|
for (int i = 0; i < spawnPackets.length; i++) {
|
||||||
if (spawnPacket != null) {
|
if (spawnPackets[i] != null) { // Get rid of empty packet '1' if it exists.
|
||||||
// Get rid of empty packet '1' if it exists.
|
newPackets.add(spawnPackets[i]);
|
||||||
newPackets.add(spawnPacket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spawnPackets = newPackets.toArray(new PacketContainer[newPackets.size()]);
|
spawnPackets = newPackets.toArray(new PacketContainer[newPackets.size()]);
|
||||||
@ -290,6 +281,7 @@ public class PacketsManager {
|
|||||||
delayedPackets = new PacketContainer[] { delayedPacket };
|
delayedPackets = new PacketContainer[] { delayedPacket };
|
||||||
|
|
||||||
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
|
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
|
||||||
|
|
||||||
DisguiseValues values = DisguiseValues.getDisguiseValues(disguise.getType());
|
DisguiseValues values = DisguiseValues.getDisguiseValues(disguise.getType());
|
||||||
Vector vec = disguisedEntity.getVelocity();
|
Vector vec = disguisedEntity.getVelocity();
|
||||||
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
|
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
|
||||||
@ -300,24 +292,18 @@ 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()));
|
||||||
@ -328,12 +314,13 @@ public class PacketsManager {
|
|||||||
mods.write(9, pitch);
|
mods.write(9, pitch);
|
||||||
spawnPackets[0].getDataWatcherModifier().write(0,
|
spawnPackets[0].getDataWatcherModifier().write(0,
|
||||||
createDataWatcher(player, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
createDataWatcher(player, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||||
|
|
||||||
} else if (disguise.getType().isMisc()) {
|
} else if (disguise.getType().isMisc()) {
|
||||||
MiscDisguise msc = (MiscDisguise) disguise;
|
|
||||||
int id = disguise.getType().getEntityId();
|
int id = disguise.getType().getEntityId();
|
||||||
int data = msc.getData();
|
int data = ((MiscDisguise) disguise).getData();
|
||||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
||||||
data = msc.getId() + (msc.getData() << 12);
|
data = (((MiscDisguise) disguise).getId() | data << 16);
|
||||||
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) {
|
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) {
|
||||||
// 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 = disguisedEntity.getEntityId();
|
data = disguisedEntity.getEntityId();
|
||||||
@ -382,7 +369,7 @@ public class PacketsManager {
|
|||||||
newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue());
|
newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace(System.out);
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return newWatcher;
|
return newWatcher;
|
||||||
}
|
}
|
||||||
@ -487,9 +474,8 @@ 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:
|
||||||
@ -536,8 +522,6 @@ public class PacketsManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the packet listeners
|
* Creates the packet listeners
|
||||||
*
|
|
||||||
* @param plugin
|
|
||||||
*/
|
*/
|
||||||
public static void init(LibsDisguises plugin) {
|
public static void init(LibsDisguises plugin) {
|
||||||
libsDisguises = plugin;
|
libsDisguises = plugin;
|
||||||
@ -563,7 +547,8 @@ public class PacketsManager {
|
|||||||
DisguiseSound entitySound = null;
|
DisguiseSound entitySound = null;
|
||||||
Disguise disguise = null;
|
Disguise disguise = null;
|
||||||
Entity[] entities = soundLoc.getChunk().getEntities();
|
Entity[] entities = soundLoc.getChunk().getEntities();
|
||||||
for (Entity entity : entities) {
|
for (int i = 0; i < entities.length; i++) {
|
||||||
|
Entity entity = entities[i];
|
||||||
Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity);
|
Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity);
|
||||||
if (entityDisguise != null) {
|
if (entityDisguise != null) {
|
||||||
Location loc = entity.getLocation();
|
Location loc = entity.getLocation();
|
||||||
@ -583,7 +568,7 @@ public class PacketsManager {
|
|||||||
obj = null;
|
obj = null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
@ -595,11 +580,12 @@ public class PacketsManager {
|
|||||||
nmsEntity) == ReflectionManager.getNmsField("EntityLiving",
|
nmsEntity) == ReflectionManager.getNmsField("EntityLiving",
|
||||||
"maxNoDamageTicks").getInt(nmsEntity);
|
"maxNoDamageTicks").getInt(nmsEntity);
|
||||||
} else {
|
} else {
|
||||||
hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", DamageSource.class)
|
Class clazz = ReflectionManager.getNmsClass("DamageSource");
|
||||||
.invoke(nmsEntity, DamageSource.GENERIC);
|
hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", clazz)
|
||||||
|
.invoke(nmsEntity, ReflectionManager.getNmsField(clazz, "GENERIC"));
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace(System.out);
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
soundType = entitySound.getType(soundName, !hasInvun);
|
soundType = entitySound.getType(soundName, !hasInvun);
|
||||||
}
|
}
|
||||||
@ -617,9 +603,8 @@ 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);
|
||||||
@ -637,7 +622,7 @@ public class PacketsManager {
|
|||||||
.invoke(step));
|
.invoke(step));
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace(System.out);
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
// There is no else statement. Because seriously. This should never be null. Unless
|
// There is no else statement. Because seriously. This should never be null. Unless
|
||||||
// someone is
|
// someone is
|
||||||
@ -665,9 +650,8 @@ 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
|
||||||
@ -675,9 +659,8 @@ 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
|
||||||
@ -685,12 +668,10 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -708,9 +689,8 @@ 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) {
|
||||||
@ -722,7 +702,7 @@ public class PacketsManager {
|
|||||||
obj = null;
|
obj = null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
@ -732,10 +712,9 @@ 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);
|
||||||
@ -751,24 +730,20 @@ 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);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -788,9 +763,8 @@ 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)) {
|
||||||
@ -811,19 +785,18 @@ public class PacketsManager {
|
|||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (delayedPackets != null && delayedPackets.length > 0) {
|
if (delayedPackets != null && delayedPackets.length > 0) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
||||||
@Override
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
for (PacketContainer packet : delayedPackets) {
|
for (PacketContainer packet : delayedPackets) {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||||
}
|
}
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 2);
|
}, 2);
|
||||||
@ -834,9 +807,8 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -845,17 +817,16 @@ public class PacketsManager {
|
|||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, observer.getEntityId());
|
mods.write(0, observer.getEntityId());
|
||||||
List<WrappedWatchableObject> watchableList = new ArrayList<>();
|
List<WrappedWatchableObject> watchableList = new ArrayList<WrappedWatchableObject>();
|
||||||
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 {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else if (event.getPacketType() == PacketType.Play.Server.ANIMATION) {
|
} else if (event.getPacketType() == PacketType.Play.Server.ANIMATION) {
|
||||||
if (event.getPacket().getIntegers().read(1) != 2) {
|
if (event.getPacket().getIntegers().read(1) != 2) {
|
||||||
@ -888,9 +859,8 @@ 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());
|
||||||
@ -914,7 +884,7 @@ public class PacketsManager {
|
|||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||||
false);
|
false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -933,13 +903,14 @@ public class PacketsManager {
|
|||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||||
false);
|
false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // 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.
|
||||||
@ -957,7 +928,7 @@ public class PacketsManager {
|
|||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
org.bukkit.inventory.ItemStack newHeld = event.getPlayer().getInventory()
|
org.bukkit.inventory.ItemStack newHeld = event.getPlayer().getInventory()
|
||||||
@ -972,7 +943,7 @@ public class PacketsManager {
|
|||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -986,7 +957,6 @@ public class PacketsManager {
|
|||||||
// Rather than predict the clients actions
|
// Rather than predict the clients actions
|
||||||
// Lets just update the entire inventory..
|
// Lets just update the entire inventory..
|
||||||
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
|
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
|
||||||
@Override
|
|
||||||
public void run() {
|
public void run() {
|
||||||
event.getPlayer().updateInventory();
|
event.getPlayer().updateInventory();
|
||||||
}
|
}
|
||||||
@ -1014,7 +984,7 @@ public class PacketsManager {
|
|||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||||
false);
|
false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Else if its a hotbar slot
|
// Else if its a hotbar slot
|
||||||
@ -1032,7 +1002,7 @@ public class PacketsManager {
|
|||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||||
false);
|
false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1174,7 +1144,7 @@ public class PacketsManager {
|
|||||||
if (mainListener != null) {
|
if (mainListener != null) {
|
||||||
ProtocolLibrary.getProtocolManager().removePacketListener(mainListener);
|
ProtocolLibrary.getProtocolManager().removePacketListener(mainListener);
|
||||||
}
|
}
|
||||||
List<PacketType> packetsToListen = new ArrayList<>();
|
List<PacketType> packetsToListen = new ArrayList<PacketType>();
|
||||||
// Add spawn packets
|
// Add spawn packets
|
||||||
{
|
{
|
||||||
packetsToListen.add(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
packetsToListen.add(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
||||||
@ -1220,9 +1190,8 @@ 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());
|
||||||
@ -1230,9 +1199,8 @@ 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);
|
||||||
@ -1243,20 +1211,19 @@ public class PacketsManager {
|
|||||||
final PacketContainer[] delayed = packets[1];
|
final PacketContainer[] delayed = packets[1];
|
||||||
if (delayed.length > 0) {
|
if (delayed.length > 0) {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
||||||
@Override
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
for (PacketContainer packet : delayed) {
|
for (PacketContainer packet : delayed) {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||||
}
|
}
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 2);
|
}, 2);
|
||||||
}
|
}
|
||||||
} catch (InvocationTargetException ex) {
|
} catch (InvocationTargetException ex) {
|
||||||
ex.printStackTrace(System.out);
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1292,12 +1259,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 transformed
|
* Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not
|
||||||
*
|
* 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;
|
||||||
@ -1313,7 +1276,7 @@ public class PacketsManager {
|
|||||||
if (disguise.isMiscDisguise()) {
|
if (disguise.isMiscDisguise()) {
|
||||||
packets = new PacketContainer[0];
|
packets = new PacketContainer[0];
|
||||||
} else {
|
} else {
|
||||||
List<WrappedAttribute> attributes = new ArrayList<>();
|
List<WrappedAttribute> attributes = new ArrayList<WrappedAttribute>();
|
||||||
for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) {
|
for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) {
|
||||||
if (attribute.getAttributeKey().equals("generic.maxHealth")) {
|
if (attribute.getAttributeKey().equals("generic.maxHealth")) {
|
||||||
packets[0] = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
|
packets[0] = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
|
||||||
@ -1341,7 +1304,9 @@ 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(
|
||||||
@ -1354,7 +1319,9 @@ 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
|
||||||
@ -1363,7 +1330,9 @@ 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()
|
||||||
@ -1371,7 +1340,9 @@ 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()
|
||||||
@ -1382,7 +1353,9 @@ 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
|
||||||
@ -1435,11 +1408,12 @@ public class PacketsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
|
|
||||||
int slot = (Integer) packets[0].getModifier().read(1) - 1;
|
|
||||||
if (slot < 0) {
|
|
||||||
slot = 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
|
||||||
|
int slot = (Integer) packets[0].getModifier().read(1) - 1;
|
||||||
|
if (slot < 0)
|
||||||
|
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();
|
||||||
@ -1450,7 +1424,7 @@ public class PacketsManager {
|
|||||||
ItemStack heldItem = packets[0].getItemModifier().read(0);
|
ItemStack heldItem = packets[0].getItemModifier().read(0);
|
||||||
if (heldItem != null && heldItem.getType() != Material.AIR) {
|
if (heldItem != null && heldItem.getType() != Material.AIR) {
|
||||||
// Convert the datawatcher
|
// Convert the datawatcher
|
||||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>();
|
||||||
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||||
list.add(new WrappedWatchableObject(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0)));
|
list.add(new WrappedWatchableObject(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0)));
|
||||||
list = disguise.getWatcher().convert(list);
|
list = disguise.getWatcher().convert(list);
|
||||||
@ -1479,15 +1453,21 @@ 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()),
|
||||||
@ -1503,13 +1483,15 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return packets == null ? null : new PacketContainer[][] { packets, delayedPackets };
|
return packets == null ? null : new PacketContainer[][] { packets, delayedPackets };
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
package me.libraryaddict.disguise.utilities;
|
package me.libraryaddict.disguise.utilities;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.bukkit.Art;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -14,20 +26,6 @@ import java.util.UUID;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
|
|
||||||
import org.bukkit.Art;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
|
|
||||||
public class ReflectionManager {
|
public class ReflectionManager {
|
||||||
|
|
||||||
public enum LibVersion {
|
public enum LibVersion {
|
||||||
@ -202,7 +200,8 @@ public class ReflectionManager {
|
|||||||
Class<?> entityClass = getNmsClass("Entity" + entityName);
|
Class<?> entityClass = getNmsClass("Entity" + entityName);
|
||||||
Object entityObject;
|
Object entityObject;
|
||||||
Object world = getWorld(Bukkit.getWorlds().get(0));
|
Object world = getWorld(Bukkit.getWorlds().get(0));
|
||||||
if (entityName.equals("Player")) {
|
switch (entityName) {
|
||||||
|
case "Player":
|
||||||
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
|
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
|
||||||
Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World"))
|
Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World"))
|
||||||
.newInstance(world);
|
.newInstance(world);
|
||||||
@ -210,11 +209,14 @@ public class ReflectionManager {
|
|||||||
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
||||||
gameProfile.getHandleType(), playerinteractmanager.getClass()).newInstance(minecraftServer, world,
|
gameProfile.getHandleType(), playerinteractmanager.getClass()).newInstance(minecraftServer, world,
|
||||||
gameProfile.getHandle(), playerinteractmanager);
|
gameProfile.getHandle(), playerinteractmanager);
|
||||||
} else if (entityName.equals("EnderPearl")) {
|
break;
|
||||||
|
case "EnderPearl":
|
||||||
entityObject = entityClass.getConstructor(getNmsClass("World"), getNmsClass("EntityLiving"))
|
entityObject = entityClass.getConstructor(getNmsClass("World"), getNmsClass("EntityLiving"))
|
||||||
.newInstance(world, createEntityInstance("Cow"));
|
.newInstance(world, createEntityInstance("Cow"));
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world);
|
entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return entityObject;
|
return entityObject;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -397,6 +399,7 @@ public class ReflectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) {
|
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName);
|
WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName);
|
||||||
gameProfile.getProperties().putAll(profileWithSkin.getProperties());
|
gameProfile.getProperties().putAll(profileWithSkin.getProperties());
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: LibsDisguises
|
name: LibsDisguises
|
||||||
main: me.libraryaddict.disguise.LibsDisguises
|
main: me.libraryaddict.disguise.LibsDisguises
|
||||||
version: 8.6.7
|
version: 8.6.8
|
||||||
author: libraryaddict
|
author: libraryaddict
|
||||||
authors: [Byteflux, Navid K.]
|
authors: [Byteflux, Navid K.]
|
||||||
depend: [ProtocolLib]
|
depend: [ProtocolLib]
|
||||||
|
Loading…
Reference in New Issue
Block a user