Corrected maven structure

This commit is contained in:
libraryaddict
2018-09-01 13:10:38 +12:00
parent 590061852c
commit 49c8f68911
135 changed files with 6 additions and 6 deletions

View File

@@ -0,0 +1,95 @@
package me.libraryaddict.disguise.utilities;
import java.net.URL;
import java.net.URLDecoder;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.bukkit.entity.Entity;
/**
* User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester
*/
// Code for this taken and slightly modified from
// https://github.com/ddopson/java-class-enumerator
public class ClassGetter
{
public static ArrayList<Class<?>> getClassesForPackage(String pkgname)
{
ArrayList<Class<?>> classes = new ArrayList<>();
// String relPath = pkgname.replace('.', '/');
// Get a File object for the package
CodeSource src = Entity.class.getProtectionDomain().getCodeSource();
if (src != null)
{
URL resource = src.getLocation();
resource.getPath();
processJarfile(resource, pkgname, classes);
}
return classes;
}
private static Class<?> loadClass(String className)
{
try
{
return Class.forName(className);
}
catch (ClassNotFoundException e)
{
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
}
catch (NoClassDefFoundError e)
{
return null;
}
}
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes)
{
try
{
String relPath = pkgname.replace('.', '/');
String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
JarFile jarFile = new JarFile(jarPath);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements())
{
JarEntry entry = entries.nextElement();
String entryName = entry.getName();
String className = null;
if (entryName.endsWith(".class") && entryName.startsWith(relPath)
&& entryName.length() > (relPath.length() + "/".length()))
{
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
}
if (className != null)
{
Class<?> c = loadClass(className);
if (c != null)
{
classes.add(c);
}
}
}
jarFile.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,337 @@
package me.libraryaddict.disguise.utilities;
import org.bukkit.Sound;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
/**
* Only living disguises go in here!
*/
public enum DisguiseSound {
ARMOR_STAND(Sound.ENTITY_ARMOR_STAND_HIT, null, Sound.ENTITY_ARMOR_STAND_BREAK, Sound.ENTITY_ARMOR_STAND_FALL,
Sound.ENTITY_ARMOR_STAND_PLACE),
ARROW(null, null, null, null, Sound.ENTITY_ARROW_HIT, Sound.ENTITY_ARROW_SHOOT),
BAT(Sound.ENTITY_BAT_HURT, null, Sound.ENTITY_BAT_DEATH, Sound.ENTITY_BAT_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
Sound.ENTITY_BAT_LOOP, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BAT_TAKEOFF),
BLAZE(Sound.ENTITY_BLAZE_HURT, null, Sound.ENTITY_BLAZE_DEATH, Sound.ENTITY_BLAZE_AMBIENT,
Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BLAZE_BURN,
Sound.ENTITY_BLAZE_SHOOT),
BOAT(null, Sound.ENTITY_BOAT_PADDLE_WATER, null, null, Sound.ENTITY_BOAT_PADDLE_LAND),
CAVE_SPIDER(Sound.ENTITY_SPIDER_HURT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH,
Sound.ENTITY_SPIDER_AMBIENT),
CHICKEN(Sound.ENTITY_CHICKEN_HURT, Sound.ENTITY_CHICKEN_STEP, Sound.ENTITY_CHICKEN_DEATH,
Sound.ENTITY_CHICKEN_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_CHICKEN_EGG,
Sound.ENTITY_PLAYER_BIG_FALL),
COD(Sound.ENTITY_COD_HURT, null, Sound.ENTITY_COD_DEATH, Sound.ENTITY_COD_AMBIENT, Sound.ENTITY_COD_FLOP,
Sound.ENTITY_FISH_SWIM),
COW(Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_STEP, Sound.ENTITY_COW_DEATH, Sound.ENTITY_COW_AMBIENT),
CREEPER(Sound.ENTITY_CREEPER_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_CREEPER_DEATH, null,
Sound.ENTITY_CREEPER_PRIMED),
DOLPHIN(Sound.ENTITY_DOLPHIN_HURT, Sound.ENTITY_DOLPHIN_SWIM, Sound.ENTITY_DOLPHIN_DEATH,
new Sound[]{Sound.ENTITY_DOLPHIN_AMBIENT, Sound.ENTITY_DOLPHIN_AMBIENT_WATER}, Sound.ENTITY_DOLPHIN_ATTACK,
Sound.ENTITY_DOLPHIN_EAT, Sound.ENTITY_DOLPHIN_SPLASH, Sound.ENTITY_DOLPHIN_PLAY, Sound.ENTITY_DOLPHIN_JUMP,
Sound.ENTITY_FISH_SWIM),
DONKEY(Sound.ENTITY_DONKEY_HURT, new Sound[]{Sound.BLOCK_GRASS_STEP, Sound.ENTITY_HORSE_STEP_WOOD,},
Sound.ENTITY_DONKEY_DEATH, Sound.ENTITY_DONKEY_AMBIENT, Sound.ENTITY_HORSE_GALLOP,
Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND,
Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY, Sound.ENTITY_DONKEY_CHEST),
DROWNED(new Sound[]{Sound.ENTITY_DROWNED_HURT, Sound.ENTITY_DROWNED_HURT_WATER},
new Sound[]{Sound.ENTITY_DROWNED_STEP, Sound.ENTITY_DROWNED_SWIM},
new Sound[]{Sound.ENTITY_DROWNED_DEATH, Sound.ENTITY_DROWNED_DEATH_WATER},
new Sound[]{Sound.ENTITY_DROWNED_AMBIENT, Sound.ENTITY_DROWNED_AMBIENT_WATER}, Sound.ENTITY_DROWNED_SHOOT),
ELDER_GUARDIAN(new Sound[]{Sound.ENTITY_ELDER_GUARDIAN_HURT, Sound.ENTITY_ELDER_GUARDIAN_HURT_LAND}, null,
new Sound[]{Sound.ENTITY_ELDER_GUARDIAN_DEATH, Sound.ENTITY_ELDER_GUARDIAN_DEATH_LAND},
new Sound[]{Sound.ENTITY_ELDER_GUARDIAN_AMBIENT, Sound.ENTITY_ELDER_GUARDIAN_AMBIENT_LAND},
Sound.ENTITY_ELDER_GUARDIAN_FLOP),
ENDER_DRAGON(Sound.ENTITY_ENDER_DRAGON_HURT, null, Sound.ENTITY_ENDER_DRAGON_DEATH,
Sound.ENTITY_ENDER_DRAGON_AMBIENT, Sound.ENTITY_GENERIC_SMALL_FALL, Sound.ENTITY_GENERIC_BIG_FALL,
Sound.ENTITY_ENDER_DRAGON_FLAP, Sound.ENTITY_ENDER_DRAGON_GROWL),
ENDERMAN(Sound.ENTITY_ENDERMAN_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_ENDERMAN_DEATH,
Sound.ENTITY_ENDERMAN_AMBIENT, Sound.ENTITY_ENDERMAN_SCREAM, Sound.ENTITY_ENDERMAN_TELEPORT,
Sound.ENTITY_ENDERMAN_STARE),
ENDERMITE(Sound.ENTITY_ENDERMITE_HURT, Sound.ENTITY_ENDERMITE_STEP, Sound.ENTITY_ENDERMITE_DEATH,
Sound.ENTITY_ENDERMITE_AMBIENT),
EVOKER(Sound.ENTITY_EVOKER_HURT, null, Sound.ENTITY_EVOKER_DEATH, Sound.ENTITY_EVOKER_AMBIENT,
Sound.ENTITY_EVOKER_CAST_SPELL, Sound.ENTITY_EVOKER_PREPARE_ATTACK, Sound.ENTITY_EVOKER_PREPARE_SUMMON,
Sound.ENTITY_EVOKER_PREPARE_WOLOLO),
EVOKER_FANGS(null, null, null, null, Sound.ENTITY_EVOKER_FANGS_ATTACK),
GHAST(Sound.ENTITY_GHAST_HURT, null, Sound.ENTITY_GHAST_DEATH, Sound.ENTITY_GHAST_AMBIENT,
Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_GHAST_SHOOT, Sound.ENTITY_PLAYER_BIG_FALL,
Sound.ENTITY_GHAST_SCREAM, Sound.ENTITY_GHAST_WARN),
GIANT(Sound.ENTITY_PLAYER_HURT, Sound.BLOCK_GRASS_STEP, null, null),
GUARDIAN(new Sound[]{Sound.ENTITY_GUARDIAN_HURT, Sound.ENTITY_GUARDIAN_HURT_LAND}, null,
new Sound[]{Sound.ENTITY_GUARDIAN_DEATH, Sound.ENTITY_GUARDIAN_DEATH_LAND},
new Sound[]{Sound.ENTITY_GUARDIAN_AMBIENT, Sound.ENTITY_GUARDIAN_AMBIENT_LAND}, Sound.ENTITY_GUARDIAN_FLOP),
HORSE(Sound.ENTITY_HORSE_HURT, new Sound[]{Sound.ENTITY_HORSE_STEP, Sound.ENTITY_HORSE_STEP_WOOD},
Sound.ENTITY_HORSE_DEATH, Sound.ENTITY_HORSE_AMBIENT, Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE,
Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP,
Sound.ENTITY_HORSE_ANGRY, Sound.ENTITY_HORSE_EAT, Sound.ENTITY_HORSE_BREATHE),
HUSK(Sound.ENTITY_HUSK_HURT, Sound.ENTITY_HUSK_STEP, Sound.ENTITY_HUSK_DEATH, Sound.ENTITY_HUSK_AMBIENT,
Sound.ENTITY_HUSK_CONVERTED_TO_ZOMBIE),
ILLUSIONER(Sound.ENTITY_ILLUSIONER_HURT, null, Sound.ENTITY_ILLUSIONER_DEATH, Sound.ENTITY_ILLUSIONER_AMBIENT,
Sound.ENTITY_ILLUSIONER_CAST_SPELL, Sound.ENTITY_ILLUSIONER_PREPARE_BLINDNESS,
Sound.ENTITY_ILLUSIONER_PREPARE_MIRROR, Sound.ENTITY_ILLUSIONER_MIRROR_MOVE),
IRON_GOLEM(Sound.ENTITY_IRON_GOLEM_HURT, Sound.ENTITY_IRON_GOLEM_STEP, Sound.ENTITY_IRON_GOLEM_DEATH,
Sound.ENTITY_IRON_GOLEM_ATTACK),
LLAMA(Sound.ENTITY_LLAMA_HURT, Sound.ENTITY_LLAMA_STEP, Sound.ENTITY_LLAMA_DEATH, Sound.ENTITY_LLAMA_AMBIENT,
Sound.ENTITY_LLAMA_ANGRY, Sound.ENTITY_LLAMA_CHEST, Sound.ENTITY_LLAMA_EAT, Sound.ENTITY_LLAMA_SWAG),
MAGMA_CUBE(Sound.ENTITY_MAGMA_CUBE_HURT, Sound.ENTITY_MAGMA_CUBE_JUMP,
new Sound[]{Sound.ENTITY_MAGMA_CUBE_DEATH, Sound.ENTITY_MAGMA_CUBE_DEATH_SMALL}, null,
Sound.ENTITY_MAGMA_CUBE_SQUISH, Sound.ENTITY_MAGMA_CUBE_SQUISH_SMALL),
MULE(Sound.ENTITY_MULE_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_MULE_DEATH, Sound.ENTITY_MULE_AMBIENT,
Sound.ENTITY_MULE_CHEST),
MUSHROOM_COW(Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_STEP, Sound.ENTITY_COW_DEATH, Sound.ENTITY_COW_AMBIENT),
OCELOT(Sound.ENTITY_CAT_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_CAT_DEATH,
new Sound[]{Sound.ENTITY_CAT_AMBIENT, Sound.ENTITY_CAT_PURR, Sound.ENTITY_CAT_PURREOW},
Sound.ENTITY_CAT_HISS),
PARROT(Sound.ENTITY_PARROT_HURT, Sound.ENTITY_PARROT_STEP, Sound.ENTITY_PARROT_DEATH, Sound.ENTITY_PARROT_AMBIENT,
Arrays.stream(Sound.values())
.filter(sound -> sound.name().contains("PARROT_IMITATE") || sound == Sound.ENTITY_PARROT_EAT ||
sound == Sound.ENTITY_PARROT_FLY).toArray(Sound[]::new)),
PIG(Sound.ENTITY_PIG_HURT, Sound.ENTITY_PIG_STEP, Sound.ENTITY_PIG_DEATH, Sound.ENTITY_PIG_AMBIENT),
PIG_ZOMBIE(Sound.ENTITY_ZOMBIE_PIGMAN_HURT, null, Sound.ENTITY_ZOMBIE_PIGMAN_DEATH,
Sound.ENTITY_ZOMBIE_PIGMAN_AMBIENT, Sound.ENTITY_ZOMBIE_PIGMAN_ANGRY),
PLAYER(Sound.ENTITY_PLAYER_HURT, Arrays.stream(Sound.values())
.filter(sound -> sound.name().startsWith("BLOCK_") && sound.name().endsWith("_STEP")).toArray(Sound[]::new),
Sound.ENTITY_PLAYER_DEATH, null),
PHANTOM(Sound.ENTITY_PHANTOM_HURT, new Sound[]{Sound.ENTITY_PHANTOM_FLAP, Sound.ENTITY_PHANTOM_SWOOP},
Sound.ENTITY_PHANTOM_DEATH, Sound.ENTITY_PHANTOM_AMBIENT, Sound.ENTITY_PHANTOM_BITE),
POLAR_BEAR(Sound.ENTITY_POLAR_BEAR_HURT, Sound.ENTITY_POLAR_BEAR_STEP, Sound.ENTITY_POLAR_BEAR_DEATH,
new Sound[]{Sound.ENTITY_POLAR_BEAR_AMBIENT, Sound.ENTITY_POLAR_BEAR_AMBIENT_BABY},
Sound.ENTITY_POLAR_BEAR_WARNING),
PUFFERFISH(Sound.ENTITY_PUFFER_FISH_HURT, null, Sound.ENTITY_PUFFER_FISH_DEATH, Sound.ENTITY_PUFFER_FISH_AMBIENT,
Sound.ENTITY_PUFFER_FISH_BLOW_OUT, Sound.ENTITY_PUFFER_FISH_BLOW_UP, Sound.ENTITY_PUFFER_FISH_FLOP,
Sound.ENTITY_PUFFER_FISH_STING, Sound.ENTITY_FISH_SWIM),
RABBIT(Sound.ENTITY_RABBIT_HURT, Sound.ENTITY_RABBIT_JUMP, Sound.ENTITY_RABBIT_DEATH, Sound.ENTITY_RABBIT_AMBIENT,
Sound.ENTITY_RABBIT_ATTACK),
SALMON(Sound.ENTITY_SALMON_HURT, null, Sound.ENTITY_SALMON_DEATH, Sound.ENTITY_SALMON_AMBIENT,
Sound.ENTITY_SALMON_FLOP, Sound.ENTITY_FISH_SWIM),
SHEEP(Sound.ENTITY_SHEEP_HURT, Sound.ENTITY_SHEEP_STEP, Sound.ENTITY_SHEEP_DEATH, Sound.ENTITY_SHEEP_AMBIENT,
Sound.ENTITY_SHEEP_SHEAR),
SHULKER(new Sound[]{Sound.ENTITY_SHULKER_HURT, Sound.ENTITY_SHULKER_HURT_CLOSED}, null, Sound.ENTITY_SHULKER_DEATH,
Sound.ENTITY_SHULKER_AMBIENT, Sound.ENTITY_SHULKER_OPEN, Sound.ENTITY_SHULKER_CLOSE,
Sound.ENTITY_SHULKER_TELEPORT),
SILVERFISH(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_SILVERFISH_STEP, Sound.ENTITY_SILVERFISH_DEATH,
Sound.ENTITY_SILVERFISH_AMBIENT),
SKELETON(Sound.ENTITY_SKELETON_HURT, Sound.ENTITY_SKELETON_STEP, Sound.ENTITY_SKELETON_DEATH,
Sound.ENTITY_SKELETON_AMBIENT),
SKELETON_HORSE(Sound.ENTITY_SKELETON_HORSE_HURT, new Sound[]{Sound.BLOCK_GRASS_STEP, Sound.ENTITY_HORSE_STEP_WOOD},
Sound.ENTITY_SKELETON_HORSE_DEATH,
new Sound[]{Sound.ENTITY_SKELETON_HORSE_AMBIENT, Sound.ENTITY_SKELETON_HORSE_AMBIENT_WATER},
Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND,
Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_SKELETON_HORSE_GALLOP_WATER, Sound.ENTITY_SKELETON_HORSE_JUMP_WATER,
Sound.ENTITY_SKELETON_HORSE_SWIM, Sound.ENTITY_SKELETON_HORSE_STEP_WATER),
SLIME(new Sound[]{Sound.ENTITY_SLIME_HURT, Sound.ENTITY_SLIME_HURT_SMALL},
new Sound[]{Sound.ENTITY_SLIME_JUMP, Sound.ENTITY_SLIME_JUMP_SMALL},
new Sound[]{Sound.ENTITY_SLIME_DEATH, Sound.ENTITY_SLIME_DEATH_SMALL}, null, Sound.ENTITY_SLIME_ATTACK,
Sound.ENTITY_SLIME_SQUISH, Sound.ENTITY_SLIME_SQUISH_SMALL),
SNOWMAN(Sound.ENTITY_SNOW_GOLEM_HURT, null, Sound.ENTITY_SNOW_GOLEM_DEATH, Sound.ENTITY_SNOW_GOLEM_AMBIENT,
Sound.ENTITY_SNOW_GOLEM_SHOOT),
SPIDER(Sound.ENTITY_SPIDER_HURT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH, Sound.ENTITY_SPIDER_AMBIENT),
STRAY(Sound.ENTITY_STRAY_HURT, Sound.ENTITY_STRAY_STEP, Sound.ENTITY_STRAY_DEATH, Sound.ENTITY_STRAY_AMBIENT),
SQUID(Sound.ENTITY_SQUID_HURT, null, Sound.ENTITY_SQUID_DEATH, Sound.ENTITY_SQUID_AMBIENT,
Sound.ENTITY_SQUID_SQUIRT, Sound.ENTITY_FISH_SWIM),
TROPICAL_FISH(Sound.ENTITY_TROPICAL_FISH_HURT, null, Sound.ENTITY_TROPICAL_FISH_DEATH,
Sound.ENTITY_TROPICAL_FISH_AMBIENT, Sound.ENTITY_TROPICAL_FISH_FLOP, Sound.ENTITY_FISH_SWIM),
TURTLE(new Sound[]{Sound.ENTITY_TURTLE_HURT, Sound.ENTITY_TURTLE_HURT_BABY},
new Sound[]{Sound.ENTITY_TURTLE_SHAMBLE, Sound.ENTITY_TURTLE_SHAMBLE_BABY},
new Sound[]{Sound.ENTITY_TURTLE_DEATH, Sound.ENTITY_TURTLE_DEATH_BABY}, Sound.ENTITY_TURTLE_AMBIENT_LAND,
Sound.ENTITY_TURTLE_LAY_EGG),
VEX(Sound.ENTITY_VEX_HURT, null, Sound.ENTITY_VEX_DEATH, Sound.ENTITY_VEX_AMBIENT, Sound.ENTITY_VEX_CHARGE),
VILLAGER(Sound.ENTITY_VILLAGER_HURT, null, Sound.ENTITY_VILLAGER_DEATH, Sound.ENTITY_VILLAGER_AMBIENT,
Sound.ENTITY_VILLAGER_TRADE, Sound.ENTITY_VILLAGER_NO, Sound.ENTITY_VILLAGER_YES),
VINDICATOR(Sound.ENTITY_VINDICATOR_HURT, null, Sound.ENTITY_VINDICATOR_DEATH, Sound.ENTITY_VINDICATOR_AMBIENT),
WITCH(Sound.ENTITY_WITCH_HURT, null, Sound.ENTITY_WITCH_DEATH, Sound.ENTITY_WITCH_AMBIENT),
WITHER(Sound.ENTITY_WITHER_HURT, null, Sound.ENTITY_WITHER_DEATH, Sound.ENTITY_WITHER_AMBIENT,
Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_WITHER_SPAWN, Sound.ENTITY_PLAYER_BIG_FALL,
Sound.ENTITY_WITHER_SHOOT),
WITHER_SKELETON(Sound.ENTITY_WITHER_SKELETON_HURT, Sound.ENTITY_WITHER_SKELETON_STEP,
Sound.ENTITY_WITHER_SKELETON_DEATH, Sound.ENTITY_WITHER_SKELETON_AMBIENT),
WOLF(Sound.ENTITY_WOLF_HURT, Sound.ENTITY_WOLF_STEP, Sound.ENTITY_WOLF_DEATH, Sound.ENTITY_WOLF_AMBIENT,
Sound.ENTITY_WOLF_GROWL, Sound.ENTITY_WOLF_PANT, Sound.ENTITY_WOLF_HOWL, Sound.ENTITY_WOLF_SHAKE,
Sound.ENTITY_WOLF_WHINE),
ZOMBIE(Sound.ENTITY_ZOMBIE_HURT, Sound.ENTITY_ZOMBIE_STEP, Sound.ENTITY_ZOMBIE_DEATH, Sound.ENTITY_ZOMBIE_AMBIENT,
Sound.ENTITY_ZOMBIE_INFECT, Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR,
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR),
ZOMBIE_HORSE(Sound.ENTITY_ZOMBIE_HORSE_HURT, new Sound[]{Sound.BLOCK_GRASS_STEP, Sound.ENTITY_HORSE_STEP_WOOD},
Sound.ENTITY_ZOMBIE_HORSE_DEATH, Sound.ENTITY_ZOMBIE_HORSE_AMBIENT, Sound.ENTITY_HORSE_GALLOP,
Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP,
Sound.ENTITY_HORSE_ANGRY),
ZOMBIE_VILLAGER(Sound.ENTITY_ZOMBIE_VILLAGER_HURT, Sound.ENTITY_ZOMBIE_VILLAGER_STEP,
Sound.ENTITY_ZOMBIE_VILLAGER_DEATH, Sound.ENTITY_ZOMBIE_VILLAGER_AMBIENT, Sound.ENTITY_ZOMBIE_INFECT,
Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR,
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
public enum SoundType {
CANCEL,
DEATH,
HURT,
IDLE,
STEP
}
public static DisguiseSound getType(String name) {
try {
return valueOf(name);
}
catch (Exception ex) {
return null;
}
}
private float damageSoundVolume = 1F;
private LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
DisguiseSound(Object hurt, Object step, Object death, Object idle, Sound... sounds) {
addSound(hurt, SoundType.HURT);
addSound(step, SoundType.STEP);
addSound(death, SoundType.DEATH);
addSound(idle, SoundType.IDLE);
for (Sound obj : sounds) {
addSound(obj, SoundType.CANCEL);
}
}
private void addSound(Object sound, SoundType type) {
if (sound == null) {
return;
}
if (sound instanceof Sound) {
addSound((Sound) sound, type);
} else if (sound instanceof Sound[]) {
for (Sound s : (Sound[]) sound) {
addSound(s, type);
}
} else {
throw new IllegalArgumentException("Was given an unknown object " + sound);
}
}
private void addSound(Sound sound, SoundType type) {
Object soundEffect = ReflectionManager.getCraftSound(sound);
if (disguiseSounds.containsKey(soundEffect)) {
DisguiseUtilities.getLogger().severe("Already doing " + sound);
}
disguiseSounds.put(soundEffect, type);
}
public float getDamageAndIdleSoundVolume() {
return damageSoundVolume;
}
public Object getSound(SoundType type) {
if (type == null) {
return null;
}
for (Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
if (entry.getValue() != type) {
continue;
}
return entry.getKey();
}
return null;
}
public SoundType getSound(Object sound) {
if (sound == null) {
return null;
}
return disguiseSounds.get(sound);
}
/**
* Used to check if this sound name is owned by this disguise sound.
*/
public SoundType getType(Object sound, boolean ignoreDamage) {
if (sound == null) {
return SoundType.CANCEL;
}
SoundType soundType = getSound(sound);
if (soundType == SoundType.DEATH || (ignoreDamage && soundType == SoundType.HURT)) {
return null;
}
return soundType;
}
public boolean isCancelSound(String sound) {
return getSound(sound) == SoundType.CANCEL;
}
public void setDamageAndIdleSoundVolume(float strength) {
this.damageSoundVolume = strength;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,62 @@
package me.libraryaddict.disguise.utilities;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import java.util.HashMap;
public class DisguiseValues {
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
public static DisguiseValues getDisguiseValues(DisguiseType type) {
return values.get(type);
}
public static Class getNmsEntityClass(DisguiseType type) {
return getDisguiseValues(type).getNmsEntityClass();
}
private FakeBoundingBox adultBox;
private FakeBoundingBox babyBox;
private float[] entitySize;
private double maxHealth;
private Class nmsEntityClass;
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) {
values.put(type, this);
nmsEntityClass = classType;
this.maxHealth = maxHealth;
}
public FakeBoundingBox getAdultBox() {
return adultBox;
}
public FakeBoundingBox getBabyBox() {
return babyBox;
}
public float[] getEntitySize() {
return entitySize;
}
public double getMaxHealth() {
return maxHealth;
}
public Class getNmsEntityClass() {
return nmsEntityClass;
}
public void setAdultBox(FakeBoundingBox newBox) {
adultBox = newBox;
}
public void setBabyBox(FakeBoundingBox newBox) {
babyBox = newBox;
}
public void setEntitySize(float[] size) {
this.entitySize = size;
}
}

View File

@@ -0,0 +1,27 @@
package me.libraryaddict.disguise.utilities;
public class FakeBoundingBox {
private double xMod;
private double yMod;
private double zMod;
public FakeBoundingBox(double xMod, double yMod, double zMod) {
this.xMod = xMod;
this.yMod = yMod;
this.zMod = zMod;
}
public double getX() {
return xMod / 2;
}
public double getY() {
return yMod;
}
public double getZ() {
return zMod / 2;
}
}

View File

@@ -0,0 +1,192 @@
package me.libraryaddict.disguise.utilities;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
/**
* Created by libraryaddict on 15/06/2017.
*/
public enum LibsMsg {
BLOWN_DISGUISE(ChatColor.RED + "Your disguise was blown!"),
CAN_USE_DISGS(ChatColor.DARK_GREEN + "You can use the disguises: %s"),
CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player/uuid '%s'"),
CLICK_TIMER(ChatColor.RED + "Right click a entity in the next %s seconds to grab the disguise reference!"),
CLONE_HELP1(ChatColor.DARK_GREEN +
"Right click a entity to get a disguise reference you can pass to other disguise commands!"),
CLONE_HELP2(ChatColor.DARK_GREEN +
"Security note: Any references you create will be available to all players able to use disguise " +
"references."),
CLONE_HELP3(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN +
"Optional" + ChatColor.DARK_GREEN + ")"),
D_HELP1(ChatColor.DARK_GREEN + "Disguise another player!"),
D_HELP3(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>"),
D_HELP4(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>"),
D_HELP5(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>"),
D_PARSE_NOPERM(ChatColor.RED + "You do not have permission to use the option %s"),
DHELP_CANTFIND(ChatColor.RED + "Cannot find the disguise %s"),
DHELP_HELP1(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN +
"- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission" +
" to use"),
DHELP_HELP2(ChatColor.RED + "/disguisehelp <DisguiseOption> " + ChatColor.GREEN + "- View information about the " +
"disguise options such as 'RabbitType'"),
DHELP_HELP3(ChatColor.RED + "/disguisehelp %s" + ChatColor.GREEN + " - %s"),
DHELP_HELP4(ChatColor.RED + "%s: " + ChatColor.GREEN + "%s"),
DHELP_HELP4_SEPERATOR(ChatColor.RED + ", " + ChatColor.GREEN),
DHELP_HELP5(ChatColor.RED + "%s: " + ChatColor.GREEN + "%s"),
DHELP_OPTIONS("%s options: %s"),
DISABLED_LIVING_TO_MISC(
ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"),
DISG_ENT_CLICK(ChatColor.RED + "Right click an entity in the next %s seconds to disguise it as a %s!"),
DISG_ENT_HELP1(ChatColor.DARK_GREEN + "Choose a disguise then right click an entity to disguise it!"),
DISG_ENT_HELP3(ChatColor.DARK_GREEN + "/disguiseentity player <Name>"),
DISG_ENT_HELP4(ChatColor.DARK_GREEN + "/disguiseentity <DisguiseType> <Baby>"),
DISG_ENT_HELP5(ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> <Durability>"),
DISG_HELP1(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"),
DISG_HELP2(ChatColor.DARK_GREEN + "/disguise player <Name>"),
DISG_HELP3(ChatColor.DARK_GREEN + "/disguise <DisguiseType> <Baby>"),
DISG_HELP4(ChatColor.DARK_GREEN + "/disguise <Dropped_Item/Falling_Block> <Id> <Durability>"),
DISG_PLAYER_AS_DISG(ChatColor.RED + "Successfully disguised %s as a %s!"),
DISG_PLAYER_AS_DISG_FAIL(ChatColor.RED + "Failed to disguise %s as a %s!"),
DISGUISED(ChatColor.RED + "Now disguised as a %s"),
DISRADIUS(ChatColor.RED + "Successfully disguised %s entities!"),
DISRADIUS_FAIL(ChatColor.RED + "Couldn't find any entities to disguise!"),
DMODENT_HELP1(ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!"),
DMODIFY_HELP1(ChatColor.DARK_GREEN + "Modify your own disguise as you wear it!"),
DMODIFY_HELP2(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true"),
DMODIFY_HELP3(ChatColor.DARK_GREEN + "You can modify the disguises: %s"),
DMODIFY_MODIFIED(ChatColor.RED + "Your disguise has been modified!"),
DMODIFY_NO_PERM(ChatColor.RED + "No permission to modify your disguise!"),
DMODIFYENT_CLICK(ChatColor.RED + "Right click a disguised entity in the next %s seconds to modify their disguise!"),
DMODPLAYER_HELP1(ChatColor.DARK_GREEN + "Modify the disguise of another player!"),
DMODPLAYER_MODIFIED(ChatColor.RED + "Modified the disguise of %s!"),
DMODPLAYER_NODISGUISE(ChatColor.RED + "The player '%s' is not disguised"),
DMODPLAYER_NOPERM(ChatColor.RED + "You do not have permission to modify this disguise"),
DMODRADIUS(ChatColor.RED + "Successfully modified the disguises of %s entities!"),
DMODRADIUS_HELP1(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"),
DHELP_SHOW("Show"),
DHELP_NO_OPTIONS(ChatColor.RED + "No options with permission to use"),
DCLONE_EQUIP("ignoreEquip"),
DCLONE_SNEAKSPRINT("doSneakSprint"),
DCLONE_SNEAK("doSneak"),
DCLONE_SPRINT("doSprint"),
DMODRADIUS_HELP2((ChatColor.DARK_GREEN + "/disguisemodifyradius <DisguiseType" + ChatColor.DARK_GREEN + "(" +
ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Disguise Options>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
DMODRADIUS_HELP3(ChatColor.DARK_GREEN + "See the DisguiseType's usable by " + ChatColor.GREEN +
"/disguisemodifyradius DisguiseType"),
DMODRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply the disguise options as well as the radius"),
DMODRADIUS_NEEDOPTIONS_ENTITY(
ChatColor.RED + "You need to supply the disguise options as well as the radius and EntityType"),
DMODRADIUS_NOENTS(ChatColor.RED + "Couldn't find any disguised entities!"),
DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"),
DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised DisguiseType %s"),
DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "DisguiseTypes usable are: %s" + ChatColor.DARK_GREEN + "."),
DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as the player/uuid"),
DRADIUS_ENTITIES(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"),
DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"),
DRADIUS_HELP3((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN +
"Optional" + ChatColor.DARK_GREEN + ")> <Radius> player <Name>").replace("<", "<" + ChatColor.GREEN)
.replace(">", ChatColor.DARK_GREEN + ">")),
DRADIUS_HELP4((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN +
"Optional" + ChatColor.DARK_GREEN + ")> <Radius> <DisguiseType> <Baby" + ChatColor.DARK_GREEN + "(" +
ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")>").replace("<", "<" + ChatColor.GREEN)
.replace(">", ChatColor.DARK_GREEN + ">")),
DRADIUS_HELP5((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN +
"Optional" + ChatColor.DARK_GREEN + ")> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" +
ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),
DRADIUS_HELP6(
ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"),
DRADIUS_MISCDISG(ChatColor.RED +
"Failed to disguise %s entities because the option to disguise a living entity as a non-living has been " +
"disabled in the config"),
DRADIUS_NEEDOPTIONS(ChatColor.RED + "You need to supply a disguise as well as the radius"),
DRADIUS_NEEDOPTIONS_ENTITY(ChatColor.RED + "You need to supply a disguise as well as the radius and EntityType"),
FAILED_DISGIUSE(ChatColor.RED + "Failed to disguise as a %s"),
INVALID_CLONE(ChatColor.DARK_RED + "Unknown option '%s' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' " +
"'DoSneak' 'DoSprint'"),
LIBS_RELOAD_WRONG(ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?"),
LIMITED_RADIUS(ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"),
LISTEN_ENTITY_ENTITY_DISG_ENTITY(ChatColor.RED + "Disguised %s as a %s!"),
LISTEN_ENTITY_ENTITY_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise %s as a %s!"),
LISTEN_ENTITY_ENTITY_DISG_PLAYER(ChatColor.RED + "Disguised %s as the player %s!"),
LISTEN_ENTITY_ENTITY_DISG_PLAYER_FAIL(ChatColor.RED + "Failed to disguise %s as the player %s!"),
LISTEN_ENTITY_PLAYER_DISG_ENTITY(ChatColor.RED + "Disguised the player %s as a %s!"),
LISTEN_ENTITY_PLAYER_DISG_ENTITY_FAIL(ChatColor.RED + "Failed to disguise the player %s as a %s!"),
LISTEN_ENTITY_PLAYER_DISG_PLAYER(ChatColor.RED + "Disguised the player %s as the player %s!"),
LISTEN_ENTITY_PLAYER_DISG_PLAYER_FAIL(ChatColor.RED + "Failed to disguise the player %s as the player %s!"),
LISTEN_UNDISG_ENT(ChatColor.RED + "Undisguised the %s"),
LISTEN_UNDISG_ENT_FAIL(ChatColor.RED + "%s isn't disguised!"),
LISTEN_UNDISG_PLAYER(ChatColor.RED + "Undisguised %s"),
LISTEN_UNDISG_PLAYER_FAIL(ChatColor.RED + "The %s isn't disguised!"),
LISTENER_MODIFIED_DISG(ChatColor.RED + "Modified the disguise!"),
MADE_REF(ChatColor.RED + "Constructed a %s disguise! Your reference is %s"),
MADE_REF_EXAMPLE(ChatColor.RED + "Example usage: /disguise %s"),
NO_CONSOLE(ChatColor.RED + "You may not use this command from the console!"),
NO_PERM(ChatColor.RED + "You are forbidden to use this command."),
NO_PERM_DISGUISE(ChatColor.RED + "You do not have permission for that disguise!"),
NO_PERMS_USE_OPTIONS(ChatColor.RED +
"Ignored %s options you do not have permission to use. Add 'show' to view unusable options."),
NOT_DISGUISED(ChatColor.RED + "You are not disguised!"),
NOT_NUMBER(ChatColor.RED + "Error! %s is not a number"),
PARSE_CANT_DISG_UNKNOWN(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"),
PARSE_CANT_LOAD(ChatColor.RED + "Error! This disguise couldn't be loaded!"),
PARSE_DISG_NO_EXIST(
ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " doesn't exist!"),
PARSE_EXPECTED_RECEIVED(
ChatColor.RED + "Expected " + ChatColor.GREEN + "%s" + ChatColor.RED + ", received " + ChatColor.GREEN +
"%s" + ChatColor.RED + " instead for " + ChatColor.GREEN + "%s"),
PARSE_NO_ARGS("No arguments defined"),
PARSE_NO_OPTION_VALUE(ChatColor.RED + "No value was given for the option %s"),
PARSE_NO_PERM_NAME(ChatColor.RED + "Error! You don't have permission to use that name!"),
PARSE_NO_PERM_PARAM(
ChatColor.RED + "Error! You do not have permission to use the parameter %s on the %s disguise!"),
PARSE_NO_PERM_REF(ChatColor.RED + "You do not have permission to use disguise references!"),
PARSE_NO_REF(ChatColor.RED + "Cannot find a disguise under the reference %s"),
PARSE_OPTION_NA(ChatColor.RED + "Cannot find the option %s"),
PARSE_SUPPLY_PLAYER(ChatColor.RED + "Error! You need to give a player name!"),
PARSE_TOO_MANY_ARGS(ChatColor.RED + "Error! %s doesn't know what to do with %s!"),
PARSE_USE_SECOND_NUM(ChatColor.RED + "Error! Only the disguises %s and %s uses a second number!"),
REF_TOO_MANY(ChatColor.RED +
"Failed to store the reference, too many cloned disguises. Please raise the maximum cloned disguises, or " +
"lower the time they last"),
RELOADED_CONFIG(ChatColor.GREEN + "[LibsDisguises] Reloaded config."),
UND_ENTITY(ChatColor.RED + "Right click a disguised entity to undisguise them!"),
UNDISG(ChatColor.RED + "You are no longer disguised"),
UNDISG_PLAYER(ChatColor.RED + "%s is no longer disguised"),
UNDISG_PLAYER_FAIL(ChatColor.RED + "%s not disguised!"),
UNDISG_PLAYER_HELP(ChatColor.RED + "/undisguiseplayer <Name>"),
UNDISRADIUS(ChatColor.RED + "Successfully undisguised %s entities!"),
UPDATE_READY(ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED +
"There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED +
", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"),
VIEW_SELF_ON(ChatColor.GREEN + "Toggled viewing own disguise on!"),
VIEW_SELF_OFF(ChatColor.GREEN + "Toggled viewing own disguise off!");
private String string;
LibsMsg(String string) {
this.string = string;
}
public String getRaw() {
return string;
}
public String get(Object... strings) {
if (StringUtils.countMatches(getRaw(), "%s") != strings.length) {
DisguiseUtilities.getLogger().severe("Mismatch in messages, incorrect parameters supplied for " + name() +
". Please inform plugin author.");
}
if (strings.length == 0) {
return TranslateType.MESSAGES.get(getRaw());
}
return String.format(TranslateType.MESSAGES.get(getRaw()), (Object[]) strings);
}
public String toString() {
throw new RuntimeException("Dont call this");
}
}

View File

@@ -0,0 +1,75 @@
package me.libraryaddict.disguise.utilities;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
/**
* Created by libraryaddict on 2/06/2017.
*/
public class LibsPremium {
// I believe I was tired and frustrated when I wrote this, but leaving it in because it's an entertaining read.
/**
* If you're seriously going to modify this to get the premium stuff for free, can you at least not
* distribute it? You didn't pay for it despite how cheap it is. You spend $8 on a trip to McDonalds
* but you balk at the idea of actually supporting someone when you can just steal it for free.
* Is the only reason you don't rob McDonalds because they can catch you? Is the only reason you don't rob your
* Grandma being that she knows who was in her house? If you see someone's credit card drop out their pocket,
* you planning on taking it and going shopping?
* Do you really have the right to give someones work away for free?
* You know enough to start coding, but you resist the idea of contributing to this plugin. Its even
* open-source, no one is stopping you. You're the guy who files a bug report because the hacked version has
* malware installed.
* I'd hate to work with you.
*/
private static Boolean thisPluginIsPaidFor;
/**
* Don't even think about disabling this unless you purchased the premium plugin. It will uh, corrupt your server
* and stuff. Also my dog will cry because I can't afford to feed him. And my sister will be beaten by my dad
* again because I'm not bringing enough money in.
*/
public static Boolean isPremium() {
return thisPluginIsPaidFor == null ? !"%%__USER__%%".contains("__USER__") : thisPluginIsPaidFor;
}
public static void check(String version) {
thisPluginIsPaidFor = isPremium();
if (!isPremium()) {
File[] files = new File("plugins/LibsDisguises/").listFiles();
if (files == null)
return;
for (File file : files) {
if (!file.isFile())
continue;
if (!file.getName().endsWith(".jar"))
continue;
try (URLClassLoader cl = new URLClassLoader(new URL[]{file.toURI().toURL()})) {
Class c = cl.loadClass(LibsPremium.class.getName());
Method m = c.getMethod("isPremium");
thisPluginIsPaidFor = (Boolean) m.invoke(null);
if (isPremium()) {
DisguiseUtilities.getLogger().info("Found a premium Lib's Disguises jar, premium enabled!");
break;
} else {
DisguiseUtilities.getLogger()
.warning("You have a non-premium Lib's Disguises jar (" + file.getName() + ") in the folder!");
}
}
catch (Exception ex) {
// Don't print off errors
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,24 @@
package me.libraryaddict.disguise.utilities;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.ProfileLookupCallback;
public class LibsProfileLookupCaller implements ProfileLookupCallback {
private WrappedGameProfile gameProfile;
public WrappedGameProfile getGameProfile() {
return gameProfile;
}
@Override
public void onProfileLookupFailed(GameProfile gameProfile, Exception arg1) {
}
@Override
public void onProfileLookupSucceeded(GameProfile profile) {
gameProfile = WrappedGameProfile.fromHandle(profile);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,289 @@
package me.libraryaddict.disguise.utilities;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MainHand;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.EulerAngle;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
public class ReflectionFlagWatchers {
public static class ParamInfo {
private Class paramClass;
private String name;
private String[] enums;
private String description;
public ParamInfo(Class paramClass, String name, String description) {
this(name, description);
this.paramClass = paramClass;
Enum[] enums = (Enum[]) paramClass.getEnumConstants();
if (enums != null) {
this.enums = new String[enums.length];
for (int i = 0; i < enums.length; i++) {
this.enums[i] = enums[i].name();
}
}
paramList.add(this);
}
private ParamInfo(String name, String description) {
this.name = name;
this.description = description;
}
public ParamInfo(Class paramClass, Enum[] enums, String name, String description) {
this(name, description);
this.enums = new String[enums.length];
this.paramClass = paramClass;
for (int i = 0; i < enums.length; i++) {
this.enums[i] = enums[i].name();
}
paramList.add(this);
}
public ParamInfo(Class paramClass, String name, String description, String[] enums) {
this(name, description);
this.enums = enums;
this.paramClass = paramClass;
paramList.add(this);
}
public boolean isEnums() {
return enums != null;
}
public Class getParamClass() {
return paramClass;
}
public String getName() {
return TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(getRawName());
}
public String getRawName() {
return name;
}
public String getDescription() {
return TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(getRawDescription());
}
public String getRawDescription() {
return description;
}
public String[] getEnums(String tabComplete) {
return enums;
}
}
private static ArrayList<ParamInfo> paramList = new ArrayList<>();
public static ArrayList<ParamInfo> getParamInfos() {
return paramList;
}
public static ParamInfo getParamInfo(Class c) {
for (ParamInfo info : getParamInfos()) {
if (info.getParamClass() != c)
continue;
return info;
}
return null;
}
public static ParamInfo getParamInfo(DisguisePerm disguiseType, String methodName) {
return getParamInfo(disguiseType.getType(), methodName);
}
public static ParamInfo getParamInfo(DisguiseType disguiseType, String methodName) {
for (Method method : getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
if (!method.getName().toLowerCase().equals(methodName.toLowerCase()))
continue;
if (method.getParameterTypes().length != 1)
continue;
if (method.getAnnotation(Deprecated.class) != null)
continue;
return getParamInfo(method.getParameterTypes()[0]);
}
return null;
}
static {
new ParamInfo(AnimalColor.class, "Animal Color", "View all the colors you can use for an animal color");
new ParamInfo(Art.class, "Art", "View all the paintings you can use for a painting disguise");
new ParamInfo(Horse.Color.class, "Horse Color", "View all the colors you can use for a horses color");
new ParamInfo(Ocelot.Type.class, "Ocelot Type", "View all the ocelot types you can use for ocelots");
new ParamInfo(Villager.Profession.class, "Villager Profession",
"View all the professions you can set on a Zombie and Normal Villager");
new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 6),
"Direction (North, East, South, West, Up, Down)",
"View the directions usable on player setSleeping and shulker direction");
new ParamInfo(RabbitType.class, "Rabbit Type", "View the kinds of rabbits you can turn into");
new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species");
new ParamInfo(EulerAngle.class, "Euler Angle (X,Y,Z)", "Set the X,Y,Z directions on an armorstand");
new ParamInfo(MainHand.class, "Main Hand", "Set the main hand for an entity");
new ParamInfo(Llama.Color.class, "Llama Color", "View all the colors you can use for a llama color");
new ParamInfo(Parrot.Variant.class, "Parrot Variant", "View the different colors a parrot can be");
new ParamInfo(Particle.class, "Particle", "The different particles of Minecraft");
new ParamInfo(TropicalFish.Pattern.class, "Pattern", "Patterns of a tropical fish");
new ParamInfo(DyeColor.class, "DyeColor", "Dye colors of many different colors");
try {
ArrayList<String> colors = new ArrayList<>();
Class cl = Class.forName("org.bukkit.Color");
for (Field field : cl.getFields()) {
if (field.getType() != cl) {
continue;
}
colors.add(field.getName());
}
new ParamInfo(Color.class, "Color", "Colors that can also be defined through RGB",
colors.toArray(new String[0]));
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
ArrayList<String> potionEnums = new ArrayList<>();
for (PotionEffectType effectType : PotionEffectType.values()) {
if (effectType == null)
continue;
potionEnums.add(toReadable(effectType.getName()));
}
String[] materials = new String[Material.values().length];
for (int i = 0; i < Material.values().length; i++) {
materials[i] = Material.values()[i].name();
}
new ParamInfo(ItemStack.class, "Item (Material:Damage:Amount:Glow), only Material required",
"An ItemStack compromised of Material:Durability", materials);
new ParamInfo(ItemStack[].class,
"Four ItemStacks (Material:Damage:Amount:Glow,Material:Damage:Amount:Glow..), only Material required",
"Four ItemStacks separated by an ,", materials) {
@Override
public String[] getEnums(String tabComplete) {
String beginning = tabComplete
.substring(0, tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0);
String end = tabComplete.substring(tabComplete.contains(",") ? tabComplete.lastIndexOf(",") + 1 : 0);
ArrayList<String> toReturn = new ArrayList<>();
for (String material : super.getEnums("")) {
if (!material.toLowerCase().startsWith(end.toLowerCase()))
continue;
toReturn.add(beginning + material);
}
return toReturn.toArray(new String[0]);
}
};
new ParamInfo(PotionEffectType.class, "Potion Effect", "View all the potion effects you can add",
potionEnums.toArray(new String[0]));
new ParamInfo(String.class, "Text", "A line of text");
new ParamInfo(boolean.class, "True/False", "True or False", new String[]{"true", "false"});
new ParamInfo(int.class, "Number", "A whole number, no decimals");
new ParamInfo(double.class, "Number.0", "A number which can have decimals");
new ParamInfo(float.class, "Number.0", "A number which can have decimals");
new ParamInfo(Horse.Style.class, "Horse Style", "Horse style which is the patterns on the horse");
new ParamInfo(int[].class, "number,number,number..", "Numbers separated by an ,");
new ParamInfo(BlockPosition.class, "Block Position (num,num,num)", "Three numbers separated by a ,");
new ParamInfo(WrappedGameProfile.class, "GameProfile", "Get the gameprofile here https://sessionserver.mojang" +
".com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false");
Collections.sort(paramList, new Comparator<ParamInfo>() {
@Override
public int compare(ParamInfo o1, ParamInfo o2) {
return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
}
});
}
public static Method[] getDisguiseWatcherMethods(@Nullable Class<? extends FlagWatcher> watcherClass) {
if (watcherClass == null) {
return new Method[0];
}
ArrayList<Method> methods = new ArrayList<>(Arrays.asList(watcherClass.getMethods()));
Iterator<Method> itel = methods.iterator();
while (itel.hasNext()) {
Method method = itel.next();
if (method.getParameterTypes().length != 1) {
itel.remove();
} else if (method.getName().startsWith("get")) {
itel.remove();
} else if (method.getAnnotation(Deprecated.class) != null) {
itel.remove();
} else if (getParamInfo(method.getParameterTypes()[0]) == null) {
itel.remove();
} else if (!method.getReturnType().equals(Void.TYPE)) {
itel.remove();
} else if (method.getName().equals("removePotionEffect")) {
itel.remove();
}
}
for (String methodName : new String[]{"setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf",
"setHearSelfDisguise", "setHidePlayer"}) {
try {
methods.add(Disguise.class.getMethod(methodName, boolean.class));
}
catch (Exception ex) {
ex.printStackTrace();
}
}
return methods.toArray(new Method[0]);
}
private static String toReadable(String string) {
String[] split = string.split("_");
for (int i = 0; i < split.length; i++) {
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
}
return StringUtils.join(split, "_");
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,82 @@
package me.libraryaddict.disguise.utilities;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method;
/**
* Created by libraryaddict on 10/06/2017.
*/
public class TranslateFiller {
public static void fillConfigs() {
// Fill the configs
for (ReflectionFlagWatchers.ParamInfo info : ReflectionFlagWatchers.getParamInfos()) {
TranslateType.DISGUISE_OPTIONS_PARAMETERS.save(info.getRawName(), "Used as a disguise option");
TranslateType.DISGUISE_OPTIONS_PARAMETERS
.save(info.getRawDescription(), "Description for the disguise option " + info.getRawName());
if (!info.isEnums() || info.getParamClass() == ItemStack.class || info.getParamClass() == ItemStack[].class)
continue;
for (String e : info.getEnums("")) {
TranslateType.DISGUISE_OPTIONS_PARAMETERS.save(e, "Used for the disguise option " + info.getRawName());
}
}
for (DisguiseType type : DisguiseType.values()) {
String[] split = type.name().split("_");
for (int i = 0; i < split.length; i++) {
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
}
TranslateType.DISGUISES.save(StringUtils.join(split, " "), "Name for the " + type.name() + " disguise");
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) {
Class para = method.getParameterTypes()[0];
String className = method.getDeclaringClass().getSimpleName().replace("Watcher", "");
if (className.equals("Flag") || className.equals("Disguise"))
className = "Entity";
else if (className.equals("Living"))
className = "Living Entity";
else if (className.equals("AbstractHorse"))
className = "Horse";
else if (className.equals("DroppedItem"))
className = "Item";
else if (className.equals("IllagerWizard"))
className = "Illager";
TranslateType.DISGUISE_OPTIONS.save(method.getName(),
"Found in the disguise options for " + className + " and uses " +
(para.isArray() ? "multiple" + " " : "a ") + para.getSimpleName().replace("[]", "s"));
}
}
TranslateType.DISGUISE_OPTIONS.save("baby", "Used as a shortcut for setBaby when disguising an entity");
TranslateType.DISGUISE_OPTIONS.save("adult", "Used as a shortcut for setBaby(false) when disguising an entity");
for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) {
if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null) {
TranslateType.DISGUISES.save(c.getSimpleName(),
"Name for the " + c.getSimpleName() + " EntityType, " + "this is used in radius commands");
}
}
TranslateType.DISGUISES.save("EntityType", "Used for the disgiuse radius command to list all entitytypes");
TranslateType.DISGUISES
.save("DisgiseType", "Used for the disgiuse modify radius command to list all " + "disguisetypes");
for (LibsMsg msg : LibsMsg.values()) {
TranslateType.MESSAGES.save(msg.getRaw(), "Reference: " + msg.name());
}
for (TranslateType type : TranslateType.values()) {
type.saveTranslations();
}
}
}

View File

@@ -0,0 +1,204 @@
package me.libraryaddict.disguise.utilities;
import me.libraryaddict.disguise.DisguiseConfig;
import org.apache.commons.lang.StringEscapeUtils;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
/**
* Created by libraryaddict on 10/06/2017.
*/
public enum TranslateType {
DISGUISES("disguises"),
MESSAGES("messages"),
DISGUISE_OPTIONS("disguise_options"),
DISGUISE_OPTIONS_PARAMETERS("disguise_option_parameters");
private File file;
private LinkedHashMap<String, String> translated = new LinkedHashMap<>();
private FileWriter writer;
TranslateType(String fileName) {
file = new File("plugins/LibsDisguises/Translations", fileName + ".yml");
}
public static void refreshTranslations() {
for (TranslateType type : values()) {
type.loadTranslations();
}
if (!LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
DisguiseUtilities.getLogger().severe("You must purchase the plugin to use translations!");
}
TranslateFiller.fillConfigs();
}
protected void saveTranslations() {
// First remove translations which are not different from each other. We don't need to store messages that
// were not translated.
Iterator<Map.Entry<String, String>> itel = translated.entrySet().iterator();
while (itel.hasNext()) {
Map.Entry<String, String> entry = itel.next();
if (!entry.getKey().equals(entry.getValue()))
continue;
itel.remove();
}
// Close the writer
try {
if (writer != null) {
writer.close();
writer = null;
}
}
catch (IOException e) {
e.printStackTrace();
}
}
private void loadTranslations() {
translated.clear();
if (LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
DisguiseUtilities.getLogger().info("Loading translations: " + name());
}
if (!getFile().exists()) {
DisguiseUtilities.getLogger().info("Translations for " + name() + " missing! Skipping...");
return;
}
YamlConfiguration config = new YamlConfiguration();
config.options().pathSeparator(Character.toChars(0)[0]);
try {
config.load(getFile());
int dupes = 0;
for (String key : config.getKeys(false)) {
String value = config.getString(key);
if (value == null) {
DisguiseUtilities.getLogger()
.severe("Translation for " + name() + " has a null value for the key '" + key + "'");
} else {
String newKey = ChatColor.translateAlternateColorCodes('&', key);
if (translated.containsKey(newKey)) {
if (dupes++ < 5) {
DisguiseUtilities.getLogger()
.severe("Alert! Duplicate translation entry for " + key + " in " + name() +
" translations!");
continue;
} else {
DisguiseUtilities.getLogger()
.severe("Too many duplicated keys! It's likely that this file was mildly " +
"corrupted by a previous bug!");
DisguiseUtilities.getLogger()
.severe("Delete the file, or you can remove every line after the first " +
"duplicate message!");
break;
}
}
translated.put(newKey, ChatColor.translateAlternateColorCodes('&', value));
}
}
}
catch (Exception e) {
e.printStackTrace();
}
if (LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
DisguiseUtilities.getLogger().info("Loaded " + translated.size() + " translations for " + name());
}
}
private File getFile() {
return file;
}
public void save(String msg) {
if (this != TranslateType.MESSAGES)
throw new IllegalArgumentException("Can't set no comment for '" + msg + "'");
save(msg, null);
}
public void save(String message, String comment) {
if (translated.containsKey(message)) {
return;
}
translated.put(message, message);
message = StringEscapeUtils.escapeJava(message.replace(ChatColor.COLOR_CHAR + "", "&"));
try {
boolean exists = getFile().exists();
if (!exists) {
getFile().getParentFile().mkdirs();
getFile().createNewFile();
}
if (writer == null) {
writer = new FileWriter(getFile(), true);
if (!exists) {
writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n");
if (this == TranslateType.MESSAGES) {
writer.write(
"# %s is where text is inserted, look up printf format codes if you're interested\n");
}
}
}
writer.write("\n" + (comment != null ? "# " + comment + "\n" : "") + "\"" + message + "\": \"" + message +
"\"\n");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public String reverseGet(String translated) {
if (translated == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations())
return translated;
String lowerCase = translated.toLowerCase();
for (Map.Entry<String, String> entry : this.translated.entrySet()) {
if (!Objects.equals(entry.getValue().toLowerCase(), lowerCase))
continue;
return entry.getKey();
}
return translated;
}
public String get(String msg) {
if (msg == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations())
return msg;
String toReturn = translated.get(msg);
return toReturn == null ? msg : toReturn;
}
}

View File

@@ -0,0 +1,67 @@
package me.libraryaddict.disguise.utilities;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Pattern;
public class UpdateChecker {
private String latestVersion;
private boolean checkHigher(String currentVersion, String newVersion) {
String current = toReadable(currentVersion);
String newVers = toReadable(newVersion);
return current.compareTo(newVers) < 0;
}
public void checkUpdate(String currentVersion) {
String version = getSpigotVersion();
if (version == null)
return;
if (!checkHigher(currentVersion, version))
return;
latestVersion = version;
}
public String getLatestVersion() {
return latestVersion;
}
/**
* Asks spigot for the version
*/
private String getSpigotVersion() {
try {
HttpURLConnection con = (HttpURLConnection) new URL("https://www.spigotmc.org/api/general.php")
.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.getOutputStream()
.write(("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=32453")
.getBytes("UTF-8"));
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
if (version.length() <= 10) {
return version;
}
}
catch (Exception ex) {
DisguiseUtilities.getLogger().warning("Failed to check for a update on spigot.");
}
return null;
}
private String toReadable(String version) {
String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", ""));
version = "";
for (String s : split) {
version += String.format("%4s", s);
}
return version;
}
}

View File

@@ -0,0 +1,66 @@
package me.libraryaddict.disguise.utilities.json;
import com.google.gson.*;
import me.libraryaddict.disguise.disguisetypes.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
/**
* Created by libraryaddict on 1/06/2017.
*/
public class SerializerDisguise implements JsonDeserializer<Disguise>, JsonSerializer<Disguise>, InstanceCreator<Disguise> {
@Override
public Disguise deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = (JsonObject) json;
DisguiseType type = DisguiseType.valueOf(obj.get("disguiseType").getAsString());
TargetedDisguise disg;
if (type.isPlayer()) {
disg = context.deserialize(json, PlayerDisguise.class);
} else if (type.isMob()) {
disg = context.deserialize(json, MobDisguise.class);
} else if (type.isMisc()) {
disg = context.deserialize(json, MiscDisguise.class);
} else
return null;
try {
Method method = FlagWatcher.class.getDeclaredMethod("setDisguise", TargetedDisguise.class);
method.setAccessible(true);
method.invoke(disg.getWatcher(), disg);
}
catch (Exception e) {
e.printStackTrace();
}
return disg;
}
@Override
public Disguise createInstance(Type type) {
if (type == PlayerDisguise.class)
return new PlayerDisguise("SaveDisgError");
else if (type == MobDisguise.class)
return new MobDisguise(DisguiseType.SHEEP);
else if (type == MiscDisguise.class)
return new MiscDisguise(DisguiseType.BOAT);
return null;
}
@Override
public JsonElement serialize(Disguise src, Type typeOfSrc, JsonSerializationContext context) {
if (src.isPlayerDisguise())
return context.serialize(src, PlayerDisguise.class);
else if (src.isMobDisguise())
return context.serialize(src, MobDisguise.class);
else if (src.isMiscDisguise())
return context.serialize(src, MiscDisguise.class);
return null;
}
}

View File

@@ -0,0 +1,97 @@
package me.libraryaddict.disguise.utilities.json;
import com.google.gson.*;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
/**
* Created by libraryaddict on 1/06/2017.
*/
public class SerializerFlagWatcher implements JsonDeserializer<FlagWatcher>, JsonSerializer<FlagWatcher>, InstanceCreator<FlagWatcher> {
@Override
public FlagWatcher deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
try {
FlagWatcher watcher = context.deserialize(json,
Class.forName(((JsonObject) json).get("flagType").getAsString()));
DisguiseType entity = DisguiseType.valueOf(((JsonObject) json).get("entityType").getAsString());
correct(watcher, watcher.getClass(), "entityValues");
correct(watcher, entity.getWatcherClass(), "backupEntityValues");
return watcher;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
private void correct(FlagWatcher watcher, Class<? extends FlagWatcher> flagWatcher,
String name) throws NoSuchFieldException, IllegalAccessException {
Field field = FlagWatcher.class.getDeclaredField(name);
field.setAccessible(true);
HashMap<Integer, Object> map = (HashMap<Integer, Object>) field.get(watcher);
for (Map.Entry<Integer, Object> entry : map.entrySet()) {
if (!(entry.getValue() instanceof Double))
continue;
MetaIndex index = MetaIndex.getFlag(flagWatcher, entry.getKey());
Object def = index.getDefault();
if (def instanceof Long)
entry.setValue(((Double) entry.getValue()).longValue());
else if (def instanceof Float)
entry.setValue(((Double) entry.getValue()).floatValue());
else if (def instanceof Integer)
entry.setValue(((Double) entry.getValue()).intValue());
else if (def instanceof Short)
entry.setValue(((Double) entry.getValue()).shortValue());
else if (def instanceof Byte)
entry.setValue(((Double) entry.getValue()).byteValue());
}
}
@Override
public FlagWatcher createInstance(Type type) {
try {
return (FlagWatcher) type.getClass().getConstructor(Disguise.class).newInstance(null);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public JsonElement serialize(FlagWatcher src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject obj = (JsonObject) context.serialize(src);
obj.addProperty("flagType", src.getClass().getName());
try {
Method method = FlagWatcher.class.getDeclaredMethod("getDisguise");
method.setAccessible(true);
Disguise disguise = (Disguise) method.invoke(src);
obj.addProperty("entityType", disguise.getType().name());
}
catch (Exception ex) {
ex.printStackTrace();
}
return obj;
}
}

View File

@@ -0,0 +1,34 @@
package me.libraryaddict.disguise.utilities.json;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.*;
import com.mojang.authlib.GameProfile;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.regex.Pattern;
/**
* Created by libraryaddict on 1/06/2017.
*/
public class SerializerGameProfile implements JsonSerializer<WrappedGameProfile>, JsonDeserializer<WrappedGameProfile> {
@Override
public JsonElement serialize(WrappedGameProfile src, Type typeOfSrc, JsonSerializationContext context) {
return context.serialize(src.getHandle(), GameProfile.class);
}
@Override
public WrappedGameProfile deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = json.getAsJsonObject();
if (obj.has("id") && !obj.get("id").getAsString().contains("-")) {
obj.addProperty("id",
Pattern.compile("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)")
.matcher(obj.get("id").getAsString()).replaceFirst("$1-$2-$3-$4-$5"));
}
return WrappedGameProfile.fromHandle(context.deserialize(json, GameProfile.class));
}
}

View File

@@ -0,0 +1,28 @@
package me.libraryaddict.disguise.utilities.json;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.*;
import com.mojang.authlib.GameProfile;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
/**
* Created by libraryaddict on 1/06/2017.
*/
public class SerializerItemStack implements JsonSerializer<ItemStack>, JsonDeserializer<ItemStack> {
@Override
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) {
return context.serialize(src.serialize());
}
@Override
public ItemStack deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
return ItemStack.deserialize((Map<String, Object>) context.deserialize(json, HashMap.class));
}
}

View File

@@ -0,0 +1,42 @@
package me.libraryaddict.disguise.utilities.json;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.*;
import com.mojang.authlib.GameProfile;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import java.lang.reflect.Type;
/**
* Created by libraryaddict on 1/06/2017.
*/
public class SerializerMetaIndex implements JsonSerializer<MetaIndex>, JsonDeserializer<MetaIndex> {
@Override
public JsonElement serialize(MetaIndex src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject obj = new JsonObject();
obj.addProperty("index", src.getIndex());
obj.addProperty("flagwatcher", src.getFlagWatcher().getSimpleName());
return obj;
}
@Override
public MetaIndex deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = json.getAsJsonObject();
String name = obj.get("flagwatcher").getAsString();
int index = obj.get("index").getAsInt();
for (MetaIndex i : MetaIndex.values()) {
if (i.getIndex() != index)
continue;
if (!i.getFlagWatcher().getSimpleName().equals(name))
continue;
return i;
}
return null;
}
}

View File

@@ -0,0 +1,31 @@
package me.libraryaddict.disguise.utilities.json;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.*;
import com.mojang.authlib.GameProfile;
import org.bukkit.Material;
import java.lang.reflect.Type;
/**
* Created by libraryaddict on 1/06/2017.
*/
public class SerializerWrappedBlockData implements JsonSerializer<WrappedBlockData>, JsonDeserializer<WrappedBlockData> {
@Override
public JsonElement serialize(WrappedBlockData src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject obj = new JsonObject();
obj.addProperty("type", src.getType().name());
obj.addProperty("data", src.getData());
return obj;
}
@Override
public WrappedBlockData deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = json.getAsJsonObject();
return WrappedBlockData.createData(Material.valueOf(obj.get("type").getAsString()), obj.get("data").getAsInt());
}
}

View File

@@ -0,0 +1,74 @@
package me.libraryaddict.disguise.utilities.packetlisteners;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
public class PacketListenerClientInteract extends PacketAdapter {
public PacketListenerClientInteract(LibsDisguises plugin) {
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY);
}
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.isCancelled())
return;
try {
Player observer = event.getPlayer();
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
return;
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
Entity entity = entityModifer.read(0);
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow ||
entity == observer) {
event.setCancelled(true);
}
for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(),
observer.getInventory().getItemInOffHand()}) {
if (item == null || item.getType() != Material.INK_SAC)
continue;
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise == null ||
(disguise.getType() != DisguiseType.SHEEP && disguise.getType() != DisguiseType.WOLF))
continue;
AnimalColor color = AnimalColor.getColor(item.getDurability());
if (disguise.getType() == DisguiseType.SHEEP) {
SheepWatcher watcher = (SheepWatcher) disguise.getWatcher();
watcher.setColor(DisguiseConfig.isSheepDyeable() ? color : watcher.getColor());
} else {
WolfWatcher watcher = (WolfWatcher) disguise.getWatcher();
watcher.setCollarColor(DisguiseConfig.isWolfDyeable() ? color : watcher.getCollarColor());
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,341 @@
package me.libraryaddict.disguise.utilities.packetlisteners;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.ReflectionManager;
public class PacketListenerInventory extends PacketAdapter {
private LibsDisguises libsDisguises;
public PacketListenerInventory(LibsDisguises plugin) {
super(plugin, ListenerPriority.HIGH, Server.SET_SLOT, Server.WINDOW_ITEMS, PacketType.Play.Client.HELD_ITEM_SLOT,
PacketType.Play.Client.SET_CREATIVE_SLOT, PacketType.Play.Client.WINDOW_CLICK);
libsDisguises = plugin;
}
@Override
public void onPacketReceiving(final PacketEvent event) {
if (event.isCancelled())
return;
final Player player = event.getPlayer();
if (player.getName().contains("UNKNOWN[")) // If the player is temporary
return;
if (player instanceof com.comphenix.net.sf.cglib.proxy.Factory || player.getVehicle() != null) {
return;
}
Disguise disguise = DisguiseAPI.getDisguise(player, player);
// If player is disguised, views self disguises and has a inventory modifier
if (disguise != null && disguise.isSelfDisguiseVisible()
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
// If they are in creative and clicked on a slot
if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT) {
int slot = event.getPacket().getIntegers().read(0);
if (slot >= 5 && slot <= 8) {
if (disguise.isHidingArmorFromSelf()) {
int armorSlot = Math.abs((slot - 5) - 3);
org.bukkit.inventory.ItemStack item = player.getInventory().getArmorContents()[armorSlot];
if (item != null && item.getType() != Material.AIR) {
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, 0);
mods.write(1, slot);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
else if (slot >= 36 && slot <= 45) {
if (disguise.isHidingHeldItemFromSelf()) {
int currentSlot = player.getInventory().getHeldItemSlot();
if (slot + 36 == currentSlot || slot == 45) {
org.bukkit.inventory.ItemStack item = player.getInventory().getItemInMainHand();
if (item != null && item.getType() != Material.AIR) {
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, 0);
mods.write(1, slot);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
}
}
// If the player switched item, aka he moved from slot 1 to slot 2
else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_SLOT) {
if (disguise.isHidingHeldItemFromSelf()) {
// From logging, it seems that both bukkit and nms uses the same thing for the slot switching.
// 0 1 2 3 - 8
// If the packet is coming, then I need to replace the item they are switching to
// As for the old item, I need to restore it.
org.bukkit.inventory.ItemStack currentlyHeld = player.getItemInHand();
// If his old weapon isn't air
if (currentlyHeld != null && currentlyHeld.getType() != Material.AIR) {
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, 0);
mods.write(1, player.getInventory().getHeldItemSlot() + 36);
mods.write(2, ReflectionManager.getNmsItem(currentlyHeld));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
org.bukkit.inventory.ItemStack newHeld = player.getInventory()
.getItem(event.getPacket().getIntegers().read(0));
// If his new weapon isn't air either!
if (newHeld != null && newHeld.getType() != Material.AIR) {
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, 0);
mods.write(1, event.getPacket().getIntegers().read(0) + 36);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) {
int slot = event.getPacket().getIntegers().read(1);
org.bukkit.inventory.ItemStack clickedItem;
if (event.getPacket().getShorts().read(0) == 1) {
// Its a shift click
clickedItem = event.getPacket().getItemModifier().read(0);
if (clickedItem != null && clickedItem.getType() != Material.AIR) {
// Rather than predict the clients actions
// Lets just update the entire inventory..
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
public void run() {
player.updateInventory();
}
});
}
return;
}
else {
// If its not a player inventory click
// Shift clicking is exempted for the item in hand..
if (event.getPacket().getIntegers().read(0) != 0) {
return;
}
clickedItem = player.getItemOnCursor();
}
if (clickedItem != null && clickedItem.getType() != Material.AIR) {
// If the slot is a armor slot
if (slot >= 5 && slot <= 8) {
if (disguise.isHidingArmorFromSelf()) {
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, 0);
mods.write(1, slot);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
// Else if its a hotbar slot
}
else if (slot >= 36 && slot <= 45) {
if (disguise.isHidingHeldItemFromSelf()) {
int currentSlot = player.getInventory().getHeldItemSlot();
// Check if the player is on the same slot as the slot that its setting
if (slot == currentSlot + 36 || slot == 45) {
PacketContainer packet = new PacketContainer(Server.SET_SLOT);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, 0);
mods.write(1, slot);
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
}
}
}
}
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
// If the inventory is the players inventory
if (player instanceof com.comphenix.net.sf.cglib.proxy.Factory || player.getVehicle() != null
|| event.getPacket().getIntegers().read(0) != 0) {
return;
}
Disguise disguise = DisguiseAPI.getDisguise(player, player);
if (disguise == null || !disguise.isSelfDisguiseVisible()
|| (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) {
return;
}
// If the player is disguised, views self disguises and is hiding a item.
// If the server is setting the slot
// Need to set it to air if its in a place it shouldn't be.
// Things such as picking up a item, spawned in item. Plugin sets the item. etc. Will fire this
/**
* Done
*/
if (event.getPacketType() == Server.SET_SLOT) {
// The raw slot
// nms code has the start of the hotbar being 36.
int slot = event.getPacket().getIntegers().read(1);
// If the slot is a armor slot
if (slot >= 5 && slot <= 8) {
if (disguise.isHidingArmorFromSelf()) {
// Get the bukkit armor slot!
int armorSlot = Math.abs((slot - 5) - 3);
org.bukkit.inventory.ItemStack item = player.getInventory().getArmorContents()[armorSlot];
if (item != null && item.getType() != Material.AIR) {
event.setPacket(event.getPacket().shallowClone());
event.getPacket().getModifier().write(2,
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
}
}
// Else if its a hotbar slot
}
else if (slot >= 36 && slot <= 45) {
if (disguise.isHidingHeldItemFromSelf()) {
int currentSlot = player.getInventory().getHeldItemSlot();
// Check if the player is on the same slot as the slot that its setting
if (slot == currentSlot + 36 || slot == 45) {
org.bukkit.inventory.ItemStack item = player.getInventory().getItemInMainHand();
if (item != null && item.getType() != Material.AIR) {
event.setPacket(event.getPacket().shallowClone());
event.getPacket().getModifier().write(2,
ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(Material.AIR)));
}
}
}
}
}
else if (event.getPacketType() == Server.WINDOW_ITEMS) {
event.setPacket(event.getPacket().shallowClone());
StructureModifier<List<ItemStack>> mods = event.getPacket().getItemListModifier();
List<ItemStack> items = new ArrayList<>(mods.read(0));
for (int slot = 0; slot < items.size(); slot++) {
if (slot >= 5 && slot <= 8) {
if (disguise.isHidingArmorFromSelf()) {
// Get the bukkit armor slot!
int armorSlot = Math.abs((slot - 5) - 3);
ItemStack item = player.getInventory().getArmorContents()[armorSlot];
if (item != null && item.getType() != Material.AIR) {
items.set(slot, new ItemStack(Material.AIR));
}
}
// Else if its a hotbar slot
}
else if (slot >= 36 && slot <= 45) {
if (disguise.isHidingHeldItemFromSelf()) {
int currentSlot = player.getInventory().getHeldItemSlot();
// Check if the player is on the same slot as the slot that its setting
if (slot == currentSlot + 36 || slot == 45) {
ItemStack item = player.getInventory().getItemInMainHand();
if (item != null && item.getType() != Material.AIR) {
items.set(slot, new ItemStack(Material.AIR));
}
}
}
}
}
mods.write(0, items);
}
}
}

View File

@@ -0,0 +1,86 @@
package me.libraryaddict.disguise.utilities.packetlisteners;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
public class PacketListenerMain extends PacketAdapter {
public PacketListenerMain(LibsDisguises plugin, ArrayList<PacketType> packetsToListen) {
super(plugin, ListenerPriority.HIGH, packetsToListen);
}
@Override
public void onPacketSending(final PacketEvent event) {
if (event.isCancelled())
return;
final Player observer = event.getPlayer();
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
return;
// First get the entity, the one sending this packet
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
org.bukkit.entity.Entity entity = entityModifer.read((Server.COLLECT == event.getPacketType() ? 1 : 0));
// If the entity is the same as the sender. Don't disguise!
// Prevents problems and there is no advantage to be gained.
if (entity == observer)
return;
final Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise == null)
return;
LibsPackets packets;
try {
packets = PacketsManager.transformPacket(event.getPacket(), disguise, observer, entity);
}
catch (Exception ex) {
ex.printStackTrace();
event.setCancelled(true);
return;
}
if (packets.isUnhandled()) {
return;
}
packets.setPacketType(event.getPacketType());
event.setCancelled(true);
try {
for (PacketContainer packet : packets.getPackets()) {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
packets.sendDelayed(observer);
}
catch (InvocationTargetException ex) {
ex.printStackTrace();
}
}
}

View File

@@ -0,0 +1,347 @@
package me.libraryaddict.disguise.utilities.packetlisteners;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import java.lang.reflect.InvocationTargetException;
public class PacketListenerSounds extends PacketAdapter {
/**
* 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 Object stepSoundEffect;
public PacketListenerSounds(LibsDisguises plugin) {
super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS);
stepSoundEffect = ReflectionManager.getCraftSound(Sound.BLOCK_GRASS_STEP);
}
@Override
public void onPacketSending(PacketEvent event) {
if (event.isCancelled()) {
return;
}
if (event.isAsync()) {
return;
}
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
return;
event.setPacket(event.getPacket().deepClone());
StructureModifier<Object> mods = event.getPacket().getModifier();
Player observer = event.getPlayer();
if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) {
SoundType soundType = null;
int[] soundCords = new int[]{(Integer) mods.read(2), (Integer) mods.read(3), (Integer) mods.read(4)};
int chunkX = (int) Math.floor((soundCords[0] / 8D) / 16D);
int chunkZ = (int) Math.floor((soundCords[2] / 8D) / 16D);
if (!observer.getWorld().isChunkLoaded(chunkX, chunkZ)) {
return;
}
Entity disguisedEntity = null;
DisguiseSound entitySound = null;
Disguise disguise = null;
Object soundEffectObj = mods.read(0);
Entity[] entities = observer.getWorld().getChunkAt(chunkX, chunkZ).getEntities();
for (Entity entity : entities) {
Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity);
if (entityDisguise != null) {
Location loc = entity.getLocation();
int[] entCords = new int[]{(int) (loc.getX() * 8), (int) (loc.getY() * 8), (int) (loc.getZ() * 8)};
if (soundCords[0] != entCords[0] || soundCords[1] != entCords[1] || soundCords[2] != entCords[2]) {
continue;
}
entitySound = DisguiseSound.getType(entity.getType().name());
if (entitySound == null) {
continue;
}
Object obj = null;
if (entity instanceof LivingEntity) {
try {
// Use reflection so that this works for either int or double methods
obj = LivingEntity.class.getMethod("getHealth").invoke(entity);
if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) {
soundType = SoundType.DEATH;
} else {
obj = null;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
if (obj == null) {
boolean hasInvun = false;
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
try {
if (entity instanceof LivingEntity) {
hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks").getInt(nmsEntity) ==
ReflectionManager.getNmsField("EntityLiving", "maxNoDamageTicks")
.getInt(nmsEntity);
} else {
Class clazz = ReflectionManager.getNmsClass("DamageSource");
hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", clazz)
.invoke(nmsEntity, ReflectionManager.getNmsField(clazz, "GENERIC").get(null));
}
}
catch (Exception ex) {
ex.printStackTrace();
}
soundType = entitySound.getType(soundEffectObj, !hasInvun);
}
if (soundType != null) {
disguise = entityDisguise;
disguisedEntity = entity;
break;
}
}
}
if (disguise != null && disguise.isSoundsReplaced() &&
(disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer)) {
Object sound = null;
DisguiseSound disguiseSound = DisguiseSound.getType(disguise.getType().name());
if (disguiseSound != null) {
sound = disguiseSound.getSound(soundType);
}
if (sound == null) {
event.setCancelled(true);
} else {
if (sound.equals("step.grass")) {
try {
Block block = observer.getWorld().getBlockAt((int) Math.floor(soundCords[0] / 8D),
(int) Math.floor(soundCords[1] / 8D), (int) Math.floor(soundCords[2] / 8D));
if (block != null) {
Object nmsBlock = ReflectionManager.getCraftMethod("block.CraftBlock", "getNMSBlock")
.invoke(block);
Object step = ReflectionManager.getNmsMethod("Block", "getStepSound").invoke(nmsBlock);
mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "d").invoke(step));
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
}
}
catch (Exception ex) {
ex.printStackTrace();
}
// There is no else statement. Because seriously. This should never be null. Unless
// someone is
// sending fake sounds. In which case. Why cancel it.
} else {
mods.write(0, sound);
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
// Time to change the pitch and volume
if (soundType == SoundType.HURT || soundType == SoundType.DEATH ||
soundType == SoundType.IDLE) {
// If the volume is the default
if (mods.read(5).equals(entitySound.getDamageAndIdleSoundVolume())) {
mods.write(5, disguiseSound.getDamageAndIdleSoundVolume());
}
// Here I assume its the default pitch as I can't calculate if its real.
if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity &&
((MobDisguise) disguise).doesDisguiseAge()) {
boolean baby = false;
if (disguisedEntity instanceof Zombie) {
baby = ((Zombie) disguisedEntity).isBaby();
} else if (disguisedEntity instanceof Ageable) {
baby = !((Ageable) disguisedEntity).isAdult();
}
if (((MobDisguise) disguise).isAdult() == baby) {
float pitch = (Float) mods.read(6);
if (baby) {
// If the pitch is not the expected
if (pitch < 1.5 || pitch > 1.7)
return;
pitch = (DisguiseUtilities.random.nextFloat() -
DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F;
// Min = 1.5
// Cap = 97.5
// Max = 1.7
// Cap = 110.5
} else {
// If the pitch is not the expected
if (pitch < 1 || pitch > 1.2)
return;
pitch = (DisguiseUtilities.random.nextFloat() -
DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
// Min = 1
// Cap = 63
// Max = 1.2
// Cap = 75.6
}
/*pitch *= 63;
if (pitch < 0)
pitch = 0;
if (pitch > 255)
pitch = 255;*/
mods.write(6, pitch);
}
}
}
}
}
}
} else if (event.getPacketType() == Server.ENTITY_STATUS) {
if ((byte) mods.read(1) != 2) {
return;
}
// It made a damage animation
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
if (disguise != null && !disguise.getType().isPlayer() &&
(disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) {
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
if (disSound == null)
return;
SoundType soundType = null;
Object obj = null;
if (entity instanceof LivingEntity) {
try {
obj = LivingEntity.class.getMethod("getHealth").invoke(entity);
if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) {
soundType = SoundType.DEATH;
} else {
obj = null;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
if (obj == null) {
soundType = SoundType.HURT;
}
if (disSound.getSound(soundType) == null ||
(disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) {
if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) {
cancelSound = !cancelSound;
if (cancelSound)
return;
}
disSound = DisguiseSound.getType(disguise.getType().name());
if (disSound != null) {
Object sound = disSound.getSound(soundType);
if (sound != null) {
Location loc = entity.getLocation();
PacketContainer packet = new PacketContainer(Server.NAMED_SOUND_EFFECT);
mods = packet.getModifier();
mods.write(0, sound);
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); // Meh
mods.write(2, (int) (loc.getX() * 8D));
mods.write(3, (int) (loc.getY() * 8D));
mods.write(4, (int) (loc.getZ() * 8D));
mods.write(5, disSound.getDamageAndIdleSoundVolume());
float pitch;
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) *
0.2F + 1.5F;
} else
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) *
0.2F + 1.0F;
if (disguise.getType() == DisguiseType.BAT)
pitch *= 0.95F;
/* pitch *= 63;
if (pitch < 0)
pitch = 0;
if (pitch > 255)
pitch = 255;*/
mods.write(6, pitch);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
}
}
}
}

View File

@@ -0,0 +1,65 @@
package me.libraryaddict.disguise.utilities.packetlisteners;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class PacketListenerTabList extends PacketAdapter {
public PacketListenerTabList(LibsDisguises plugin) {
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO);
}
@Override
public void onPacketSending(final PacketEvent event) {
if (event.isCancelled())
return;
Player observer = event.getPlayer();
if (event.getPacket().getPlayerInfoAction().read(0) != PlayerInfoAction.ADD_PLAYER)
return;
List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists().read(0);
Iterator<PlayerInfoData> itel = list.iterator();
while (itel.hasNext()) {
PlayerInfoData data = itel.next();
Player player = Bukkit.getPlayer(data.getProfile().getUUID());
if (player == null)
continue;
Disguise disguise = DisguiseAPI.getDisguise(observer, player);
if (disguise == null)
continue;
if (!disguise.isHidePlayer())
continue;
itel.remove();
}
if (list.isEmpty()) {
event.setCancelled(true);
}
else {
event.getPacket().getPlayerInfoDataLists().write(0, list);
}
}
}

View File

@@ -0,0 +1,172 @@
package me.libraryaddict.disguise.utilities.packetlisteners;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Play.Server;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
import me.libraryaddict.disguise.utilities.ReflectionManager;
public class PacketListenerViewDisguises extends PacketAdapter {
public PacketListenerViewDisguises(LibsDisguises plugin) {
super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE,
Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION,
Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT,
Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS);
}
@Override
public void onPacketSending(final PacketEvent event) {
if (event.isCancelled())
return;
try {
final Player observer = event.getPlayer();
if (observer.getName().contains("UNKNOWN[")) // If the player is temporary
return;
if (event.getPacket().getIntegers().read(0) != observer.getEntityId()) {
return;
}
if (!DisguiseAPI.isSelfDisguised(observer)) {
if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) {
Disguise disguise = DisguiseAPI.getDisguise(observer, observer);
if (disguise != null && disguise.isSelfDisguiseVisible()) {
event.setCancelled(true);
}
}
return;
}
final Disguise disguise = DisguiseAPI.getDisguise(observer, observer);
if (disguise == null)
return;
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
LibsPackets transformed = PacketsManager.transformPacket(event.getPacket(), disguise, observer, observer);
if (transformed.isUnhandled()) {
transformed.getPackets().add(event.getPacket());
}
transformed.setPacketType(event.getPacketType());
for (PacketContainer packet : transformed.getPackets()) {
if (packet.getType() != Server.PLAYER_INFO) {
if (packet.equals(event.getPacket())) {
packet = packet.shallowClone();
}
packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
}
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}
for (ArrayList<PacketContainer> packets : transformed.getDelayedPackets()) {
for (PacketContainer packet : packets) {
if (packet.getType() != Server.PLAYER_INFO) {
if (packet.equals(event.getPacket())) {
packet = packet.shallowClone();
}
packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
}
}
}
transformed.sendDelayed(observer);
if (event.getPacketType() == Server.ENTITY_METADATA) {
event.setPacket(event.getPacket().deepClone());
for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) {
if (watch.getIndex() == 0) {
byte b = (byte) watch.getValue();
byte a = (byte) (b | 1 << 5);
if ((b & 1 << 3) != 0)
a = (byte) (a | 1 << 3);
watch.setValue(a);
}
}
} else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) {
event.setCancelled(true);
PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, observer.getEntityId());
List<WrappedWatchableObject> watchableList = new ArrayList<>();
Byte b = 1 << 5;
if (observer.isSprinting())
b = (byte) (b | 1 << 3);
WrappedWatchableObject watch = ReflectionManager.createWatchable(0, b);
if (watch != null)
watchableList.add(watch);
packet.getWatchableCollectionModifier().write(0, watchableList);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
} else if (event.getPacketType() == Server.ANIMATION) {
if (event.getPacket().getIntegers().read(1) != 2) {
event.setCancelled(true);
}
} else if (event.getPacketType() == Server.ATTACH_ENTITY || event
.getPacketType() == Server.REL_ENTITY_MOVE || event
.getPacketType() == Server.REL_ENTITY_MOVE_LOOK || event
.getPacketType() == Server.ENTITY_LOOK || event.getPacketType() == Server.ENTITY_TELEPORT || event
.getPacketType() == Server.ENTITY_HEAD_ROTATION || event
.getPacketType() == Server.ENTITY_EQUIPMENT) {
event.setCancelled(true);
} else if (event.getPacketType() == Server.ENTITY_STATUS) {
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer() && event.getPacket()
.getBytes().read(0) == 2) {
event.setCancelled(true);
}
}
}
catch (Exception ex) {
event.setCancelled(true);
ex.printStackTrace();
}
}
}