Convert back to maven
This commit is contained in:
@@ -1,290 +0,0 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Guardian;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Skeleton;
|
||||
import org.bukkit.entity.Zombie;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public enum DisguiseType {
|
||||
|
||||
AREA_EFFECT_CLOUD(3, 0),
|
||||
ARMOR_STAND(78),
|
||||
ARROW(60, 0),
|
||||
BAT,
|
||||
BLAZE,
|
||||
BOAT(1),
|
||||
CAVE_SPIDER,
|
||||
CHICKEN,
|
||||
COW,
|
||||
CREEPER,
|
||||
DONKEY,
|
||||
DRAGON_FIREBALL(93),
|
||||
DROPPED_ITEM(2, 1),
|
||||
EGG(62),
|
||||
ELDER_GUARDIAN,
|
||||
ENDER_CRYSTAL(51),
|
||||
ENDER_DRAGON,
|
||||
ENDER_PEARL(65),
|
||||
ENDER_SIGNAL(72),
|
||||
ENDERMAN,
|
||||
ENDERMITE,
|
||||
EXPERIENCE_ORB,
|
||||
FALLING_BLOCK(70, 1),
|
||||
FIREBALL(63),
|
||||
FIREWORK(76),
|
||||
FISHING_HOOK(90),
|
||||
GHAST,
|
||||
GIANT,
|
||||
GUARDIAN,
|
||||
HORSE,
|
||||
IRON_GOLEM,
|
||||
ITEM_FRAME(71),
|
||||
LEASH_HITCH(77),
|
||||
MAGMA_CUBE,
|
||||
MINECART(10),
|
||||
MINECART_CHEST(10, 1),
|
||||
MINECART_COMMAND(10, 6),
|
||||
MINECART_FURNACE(10, 2),
|
||||
MINECART_HOPPER(10, 5),
|
||||
MINECART_MOB_SPAWNER(10, 4),
|
||||
MINECART_TNT(10, 3),
|
||||
MULE,
|
||||
MUSHROOM_COW,
|
||||
OCELOT,
|
||||
PAINTING,
|
||||
PIG,
|
||||
PIG_ZOMBIE,
|
||||
PLAYER,
|
||||
PRIMED_TNT(50),
|
||||
RABBIT,
|
||||
SHEEP,
|
||||
SHULKER,
|
||||
SHULKER_BULLET(67),
|
||||
SILVERFISH,
|
||||
SKELETON,
|
||||
SKELETON_HORSE,
|
||||
SLIME,
|
||||
SMALL_FIREBALL(63),
|
||||
SNOWBALL(61),
|
||||
SNOWMAN,
|
||||
SPECTRAL_ARROW(91),
|
||||
SPIDER,
|
||||
SPLASH_POTION(73, 0),
|
||||
SQUID,
|
||||
TIPPED_ARROW(92),
|
||||
THROWN_EXP_BOTTLE(75),
|
||||
UNDEAD_HORSE,
|
||||
VILLAGER,
|
||||
WITCH,
|
||||
WITHER,
|
||||
WITHER_SKELETON,
|
||||
WITHER_SKULL(66),
|
||||
WOLF,
|
||||
ZOMBIE,
|
||||
ZOMBIE_VILLAGER,
|
||||
UNKNOWN;
|
||||
|
||||
private static Method isVillager, getVariant, getSkeletonType, isElder;
|
||||
|
||||
static {
|
||||
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC.
|
||||
// Without erroring up everything.
|
||||
for (DisguiseType type : values()) {
|
||||
try {
|
||||
DisguiseType toUse = type;
|
||||
String name;
|
||||
switch (type) {
|
||||
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
|
||||
// Usable.
|
||||
case ITEM_FRAME:
|
||||
break;
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
toUse = DisguiseType.HORSE;
|
||||
break;
|
||||
case ZOMBIE_VILLAGER:
|
||||
toUse = DisguiseType.ZOMBIE;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
toUse = DisguiseType.SKELETON;
|
||||
break;
|
||||
case ELDER_GUARDIAN:
|
||||
toUse = DisguiseType.GUARDIAN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
name = toUse.name();
|
||||
type.setEntityType(EntityType.valueOf(name));
|
||||
} catch (Throwable ex) {
|
||||
// This version of Spigot doesn't have the disguise.
|
||||
}
|
||||
}
|
||||
try {
|
||||
isVillager = Zombie.class.getMethod("isVillager");
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
try {
|
||||
getVariant = Horse.class.getMethod("getVariant");
|
||||
} catch (Throwable ignored) {
|
||||
// Pre-1.6, but that isn't even supported
|
||||
}
|
||||
try {
|
||||
getSkeletonType = Skeleton.class.getMethod("getSkeletonType");
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
try {
|
||||
isElder = Guardian.class.getMethod("isElder");
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static DisguiseType getType(Entity entity) {
|
||||
DisguiseType disguiseType = getType(entity.getType());
|
||||
switch (disguiseType) {
|
||||
case ZOMBIE:
|
||||
try {
|
||||
if ((Boolean) isVillager.invoke(entity)) {
|
||||
disguiseType = DisguiseType.ZOMBIE_VILLAGER;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
break;
|
||||
case HORSE:
|
||||
try {
|
||||
Object variant = getVariant.invoke(entity);
|
||||
disguiseType = DisguiseType.valueOf(((Enum) variant).name());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
break;
|
||||
case SKELETON:
|
||||
try {
|
||||
Object type = getSkeletonType.invoke(entity);
|
||||
if (type == Skeleton.SkeletonType.WITHER) {
|
||||
disguiseType = DisguiseType.WITHER_SKELETON;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
break;
|
||||
case GUARDIAN:
|
||||
try {
|
||||
if ((Boolean) isElder.invoke(entity)) {
|
||||
disguiseType = DisguiseType.ELDER_GUARDIAN;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return disguiseType;
|
||||
}
|
||||
|
||||
public static DisguiseType getType(EntityType entityType) {
|
||||
try {
|
||||
return valueOf(entityType.name().toUpperCase());
|
||||
} catch (Throwable ex) {
|
||||
return DisguiseType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
private int objectId = -1, defaultData = 0;
|
||||
private EntityType entityType;
|
||||
private Class<? extends FlagWatcher> watcherClass;
|
||||
|
||||
DisguiseType(int... ints) {
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
int value = ints[i];
|
||||
switch (i) {
|
||||
case 0:
|
||||
objectId = value;
|
||||
break;
|
||||
case 1:
|
||||
defaultData = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getDefaultData() {
|
||||
return defaultData;
|
||||
}
|
||||
|
||||
public Class<? extends Entity> getEntityClass() {
|
||||
if (entityType != null) {
|
||||
return getEntityType().getEntityClass();
|
||||
}
|
||||
return Entity.class;
|
||||
}
|
||||
|
||||
public EntityType getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The TYPE id of this entity. Different from the Object Id
|
||||
* send in spawn packets when spawning miscs.
|
||||
* @return
|
||||
*/
|
||||
public int getTypeId() {
|
||||
return (int) getEntityType().getTypeId();
|
||||
}
|
||||
|
||||
/**
|
||||
* The object type send in packets when spawning a misc entity.
|
||||
* Otherwise, -1.
|
||||
* @return
|
||||
*/
|
||||
public int getObjectId() {
|
||||
return objectId;
|
||||
}
|
||||
|
||||
public Class getWatcherClass() {
|
||||
return watcherClass;
|
||||
}
|
||||
|
||||
public boolean isMisc() {
|
||||
return getEntityType() != null && !getEntityType().isAlive();
|
||||
}
|
||||
|
||||
public boolean isMob() {
|
||||
return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
return this == DisguiseType.PLAYER;
|
||||
}
|
||||
|
||||
public boolean isUnknown() {
|
||||
return this == DisguiseType.UNKNOWN;
|
||||
}
|
||||
|
||||
private void setEntityType(EntityType entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
public void setWatcherClass(Class<? extends FlagWatcher> c) {
|
||||
watcherClass = c;
|
||||
}
|
||||
|
||||
public String toReadable() {
|
||||
String[] split = name().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, " ");
|
||||
}
|
||||
}
|
@@ -1,130 +0,0 @@
|
||||
# Shall I notify people of a LibsDisguises update?
|
||||
NotifyUpdate: true
|
||||
# Whats the permission to get the notification?
|
||||
Permission: 'libsdisguises.update'
|
||||
# Whats the max size allowed for command disguiseradius
|
||||
DisguiseRadiusMax: 50
|
||||
# Whats the max size allowed for command undisguiseradius
|
||||
UndisguiseRadiusMax: 50
|
||||
# Shall the players view their disguises?
|
||||
# Best used when viewing yourself in 3rd person
|
||||
ViewSelfDisguises: true
|
||||
# Shall I disguise the sounds?
|
||||
# This turns your damage sound into a MOOOO
|
||||
DisguiseSounds: true
|
||||
# Shall the disguised hear their disguise sounds or their damage sounds.
|
||||
# I disable this as it can be a little confusing when not used with self disguises
|
||||
HearSelfDisguise: true
|
||||
# Shall I send the velocity packets? I REALLY recommend you don't disable.
|
||||
# This is the only thing allowing the mobs to fly without glitching out.
|
||||
SendVelocity: true
|
||||
# For self disguises, they need to have the armor and the held item removed
|
||||
# Else they see floating armor, floating held items.
|
||||
# This turns the items invisible in the disguised players inventory. It does not actually remove them!
|
||||
RemoveArmor: true
|
||||
RemoveHeldItem: false
|
||||
# If you set a disguise to burning, it will no longer be able to be shown as sneaking or invisible.
|
||||
# Set this to true if you want the disguise to get the animations of the disguised entity. Such as invisible, on fire, sprinting, sneaking, blocking
|
||||
# This is only valid if you set a animation on the disguise itself. Because the entitys animations are applied otherwise.
|
||||
AddEntityAnimations: true
|
||||
# When a sheep or wolf is right clicked with dye. The client automatically assumes it was successful and displays the sheeps wool or the wolfs collar as dyed.
|
||||
# This is a option that either prevents that happening, or it changes their color officially in the plugin so that everyone sees it changed.
|
||||
# Its currently set to false which means that the color is not changed and will refresh itself to the player.
|
||||
# Please note that this will not remove the dye from their hands. This also does not check if the disguised entity is actually a sheep/wolf and wants a say in its color.
|
||||
DyeableSheep: false
|
||||
DyeableWolf: false
|
||||
# This is only called into action when the disguise is constructed using the commands.
|
||||
# And when the disguise supports that. This will not be used at all for plugins constructing the disguises for instance.
|
||||
# Such as prophunt. Its also false because its kind of a retarded feature.
|
||||
# This is pretty simple. It shows the players displayname (Name as it appears in chat) above their head.
|
||||
# This also overrides any custom name they have set in their disguise options.
|
||||
ShowNamesAboveDisguises: false
|
||||
# This supports the above option.
|
||||
# If this is true, then the name shown above the head appears regardless of if you are looking at the disguise directly or not.
|
||||
NameAboveHeadAlwaysVisible: true
|
||||
# This modifys the bounding box, This is stuff like can a arrow hit them.
|
||||
# If you turn this to true, arrows will act like they hit the disguise in the right place!
|
||||
# So someone disguised as a enderdragon will easily get shot down by arrows!
|
||||
# This WILL conflict with NoCheatPlus. Other plugins may also get problems.
|
||||
# This shouldn't really be enabled for players as it also interferes with their movement because the server thinks the player is larger than he really is.
|
||||
# That makes the player unable to approach this building because the server thinks he is trying to glitch inside blocks.
|
||||
ModifyBoundingBox: false
|
||||
# This prevents disguised players from being targeted by monsters.
|
||||
# This doesn't prevent their targeting you if already targeting when disguised
|
||||
# They will just ignore you unless provoked.
|
||||
MonstersIgnoreDisguises: false
|
||||
# Sigh. People are going to want this.
|
||||
# So lets make your disguise blown if you are attacked..
|
||||
# Works only for disguised players when attacked by a entity (arrow, monster. etc)
|
||||
# This will blow all disguises he has on him
|
||||
BlowDisguises: false
|
||||
BlownDisguiseMessage: '&cYour disguise was blown!'
|
||||
|
||||
#Stop shulker disguises from moving, they're weird. This option only effects PLAYERS that are disguised, other entities disguised as shulkers will NOT be effected!
|
||||
StopShulkerDisguisesFromMoving: true
|
||||
|
||||
# A option to choose how many seconds a DisguiseEntity command is valid for people to right click a entity to disguise it before expiring
|
||||
DisguiseEntityExpire: 10
|
||||
|
||||
# Another option to choose the same thing for DisguiseClone command
|
||||
DisguiseCloneExpire: 10
|
||||
# Max disguises to store at a time with the DisguiseClone command
|
||||
DisguiseCloneSize: 3
|
||||
|
||||
# This I don't really recommend turning on as it can make a memory leak..
|
||||
# These disguises, as normal will not persist after a server restart.
|
||||
# There is also no EntityDeath option as entities do not revive after death.
|
||||
KeepDisguises:
|
||||
EntityDespawn: false
|
||||
PlayerDeath: false
|
||||
PlayerLogout: false
|
||||
|
||||
# This controls if a entitys max health is determined by the entity, or by the disguise.
|
||||
# Wither is 200, a player is 20. With this enabled, a player disguised as a wither will have the boss bar health accurate to the players health.
|
||||
# Else it will be 1/20 of the boss bar when he is full health.
|
||||
# Setting this in LivingWatcher overrides both values.
|
||||
MaxHealthDeterminedByEntity: true
|
||||
|
||||
# This here is a option to turn off misc disguises.
|
||||
# This means you can not have a living entity disguise as a non-living entity.
|
||||
# This disables the Attributes packet, Non-living entities can still disguise as other non-living
|
||||
# This means that the above option will not work as it uses the attribute packet.
|
||||
MiscDisguisesForLiving: true
|
||||
|
||||
# Turn this to true to have players undisguised when switching worlds
|
||||
UndisguiseOnWorldChange: false
|
||||
|
||||
# Contact Mojang's servers? Disabling this option will disable player skin disguises!
|
||||
ContactMojangServers: true
|
||||
|
||||
# This will help performance, especially with CPU
|
||||
# Due to safety reasons, self disguises can never have their packets disabled.
|
||||
PacketsEnabled:
|
||||
# This disables the animation packet. If a disguised entity sends a animation packet and they are using a non-living disguise. People will crash.
|
||||
# Disabling this also means that if a player disguised as a non-player leaves a bug. People will crash
|
||||
Animation: true
|
||||
# Disabling this means that you can't use the setSleeping option on a player disguise. Also you will crash anyone watching when you try to sleep in a bed if disguised as a non-player
|
||||
# This also sends a chunk packet at key positions else it doesn't work for 1.8. Lazyness means it does it for older versions too currently.
|
||||
Bed: true
|
||||
# This disguises the collect packet. If a living entity disguised as a non-living entity picks up a item. People will crash. This fixes it
|
||||
# This also fixes people crashing if a item disguised as a sleeping player is picked up - Only true if Bed is enabled as well
|
||||
Collect: true
|
||||
# This disables a fix for when a disguised entity wearing armor dies, if the disguise can wear armor. It drops unpickupable items to anyone watching.
|
||||
EntityStatus: true
|
||||
# Entity equipment is the packets that are sent to ensure that a disguise has or doesn't have armor, and their held item.
|
||||
# Disabling this means that any disguises which can wear armor or hold items will show the armor/held item that the disguised is wearing.
|
||||
Equipment: true
|
||||
# This doesn't actually disable the packet. It would introduce problems. Instead it does the next best thing and caches the data.
|
||||
# This means that entity metadata will not change, and will only be sent in the spawn packet.
|
||||
# This is good if performance is extremely in need.
|
||||
# This is bad to disable unless you are ONLY going to use the disguises for decorations.
|
||||
# To be honest. This is basically "Disable entity animations". That option is called 'AddEntityAnimations' in the config but unlike that, this is always in effect.
|
||||
# Animations set by use of the api or through the disguise command are still in effect.
|
||||
Metadata: true
|
||||
# Movement packets are the biggest cpu hit. These are majorly used to ensure that the disguises facing direction isn't bugged up.
|
||||
# If you are using the Item_Frame disguise, when a packet is sent (Roughly every 2min) the disguise will bug up until they move.
|
||||
Movement: true
|
||||
# Disable this if you don't mind crashing everytime you see someone riding something disguised as a non-living entity
|
||||
Riding: true
|
||||
# When disguised as a wither skull, it sends a look packet every tick so that the wither skull is facing the right way.
|
||||
WitherSkull: true
|
@@ -1,103 +0,0 @@
|
||||
name: LibsDisguises
|
||||
main: me.libraryaddict.disguise.LibsDisguises
|
||||
description: A disguise plugin with various disguises.
|
||||
version: ${projectVersion}
|
||||
author: libraryaddict
|
||||
authors: [Byteflux, Navid K.]
|
||||
softdepend: [ProtocolLib]
|
||||
commands:
|
||||
libsdisguises:
|
||||
permission: libsdisguises.seecmd.libsdisguises
|
||||
description: Main command for libsdisguises.
|
||||
disguise:
|
||||
aliases: [d, dis]
|
||||
permission: libsdisguises.seecmd.disguise
|
||||
description: Disguise yourself as an entity.
|
||||
disguiseentity:
|
||||
aliases: [dentity, disentity]
|
||||
permission: libsdisguises.seecmd.disguiseentity
|
||||
description: Disguise an entity as another entity.
|
||||
disguisehelp:
|
||||
aliases: [dhelp, dishelp]
|
||||
permission: libsdisguises.seecmd.disguisehelp
|
||||
description: Help command for LibsDisguises.
|
||||
disguiseplayer:
|
||||
aliases: [dplayer, displayer]
|
||||
permission: libsdisguises.seecmd.disguiseplayer
|
||||
description: Disguise another player as an entity.
|
||||
disguiseradius:
|
||||
aliases: [disradius, dradius]
|
||||
permission: libsdisguises.seecmd.disguiseradius
|
||||
description: Disguise all entities within a radius as an entity.
|
||||
undisguise:
|
||||
aliases: [u, und, undis]
|
||||
permission: libsdisguises.seecmd.undisguise
|
||||
description: Undisguise yourself.
|
||||
undisguiseentity:
|
||||
aliases: [undisentity, undentity]
|
||||
permission: libsdisguises.seecmd.undisguiseentity
|
||||
description: Undisguise an entity.
|
||||
undisguiseplayer:
|
||||
aliases: [undisplayer, undplayer]
|
||||
permission: libsdisguises.seecmd.undisguiseplayer
|
||||
description: Undisguise a player.
|
||||
undisguiseradius:
|
||||
aliases: [undisradius, undradius]
|
||||
permission: libsdisguises.seecmd.undisguiseradius
|
||||
description: Undisguise all entities within a radius.
|
||||
disguiseclone:
|
||||
aliases: [disguisec, disc, disclone, dclone, clonedisguise, clonedis, cdisguise, cdis]
|
||||
permission: libsdisguises.seecmd.disguiseclone
|
||||
description: Copy a disguise (or entity) and use it later.
|
||||
disguiseviewself:
|
||||
aliases: [dviewself, dvs, disguisevs, disvs, vsd, viewselfdisguise, viewselfd]
|
||||
permission: libsdisguises.seecmd.viewself
|
||||
description: Toggle seeing your own disguise on or off.
|
||||
|
||||
permissions:
|
||||
libsdisguises.reload:
|
||||
description: Allows the user to reload LibsDisguises.
|
||||
default: op
|
||||
libsdisguises.seethrough:
|
||||
description: Allows player to see through disguises.
|
||||
default: false
|
||||
libsdisguises.seecmd:
|
||||
description: See all commands in tab-completion
|
||||
default: true
|
||||
children:
|
||||
libsdisguises.seecmd.libsdisguises: true
|
||||
libsdisguises.seecmd.disguise: true
|
||||
libsdisguises.seecmd.disguiseentity: true
|
||||
libsdisguises.seecmd.disguisehelp: true
|
||||
libsdisguises.seecmd.disguiseplayer: true
|
||||
libsdisguises.seecmd.disguiseradius: true
|
||||
libsdisguises.seecmd.undisguise: true
|
||||
libsdisguises.seecmd.undisguiseentity: true
|
||||
libsdisguises.seecmd.undisguiseplayer: true
|
||||
libsdisguises.seecmd.undisguiseradius: true
|
||||
libsdisguises.seecmd.disguiseclone: true
|
||||
libsdisguises.seecmd.disguiseviewself: true
|
||||
libsdisguises.seecmd.libsdisguises:
|
||||
description: See the /libsdisguises command in tab-completion
|
||||
libsdisguises.seecmd.disguiseviewself:
|
||||
description: See the /disguiseviewself command in tab-completion
|
||||
libsdisguises.seecmd.disguise:
|
||||
description: See the /disguise command in tab-completion
|
||||
libsdisguises.seecmd.disguiseentity:
|
||||
description: See the /disguiseentity command in tab-completion
|
||||
libsdisguises.seecmd.disguisehelp:
|
||||
description: See the /disguisehelp command in tab-completion
|
||||
libsdisguises.seecmd.disguiseplayer:
|
||||
description: See the /disguiseplayer command in tab-completion
|
||||
libsdisguises.seecmd.disguiseradius:
|
||||
description: See the /disguiseradius command in tab-completion
|
||||
libsdisguises.seecmd.undisguise:
|
||||
description: See the /undisguise command in tab-completion
|
||||
libsdisguises.seecmd.undisguiseentity:
|
||||
description: See the /undisguiseentity command in tab-completion
|
||||
libsdisguises.seecmd.undisguiseplayer:
|
||||
description: See the /undisguiseplayer command in tab-completion
|
||||
libsdisguises.seecmd.undisguiseradius:
|
||||
description: See the /undisguiseradius command in tab-completion
|
||||
libsdisguises.seecmd.disguiseclone:
|
||||
description: See the /disguiseclone command in tab-completion
|
@@ -1,5 +1,24 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.HorseInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
@@ -13,120 +32,158 @@ import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.HorseInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DisguiseAPI {
|
||||
|
||||
public static Disguise constructDisguise(Entity entity) {
|
||||
public class DisguiseAPI
|
||||
{
|
||||
public static Disguise constructDisguise(Entity entity)
|
||||
{
|
||||
return constructDisguise(entity, true, true, true);
|
||||
}
|
||||
|
||||
public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint) {
|
||||
public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint)
|
||||
{
|
||||
DisguiseType disguiseType = DisguiseType.getType(entity);
|
||||
Disguise disguise;
|
||||
if (disguiseType.isMisc()) {
|
||||
|
||||
if (disguiseType.isMisc())
|
||||
{
|
||||
disguise = new MiscDisguise(disguiseType);
|
||||
} else if (disguiseType.isMob()) {
|
||||
}
|
||||
else if (disguiseType.isMob())
|
||||
{
|
||||
disguise = new MobDisguise(disguiseType);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
disguise = new PlayerDisguise(entity.getName());
|
||||
}
|
||||
|
||||
FlagWatcher watcher = disguise.getWatcher();
|
||||
if (entity instanceof LivingEntity) {
|
||||
for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects()) {
|
||||
|
||||
if (entity instanceof LivingEntity)
|
||||
{
|
||||
for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects())
|
||||
{
|
||||
((LivingWatcher) watcher).addPotionEffect(effect.getType());
|
||||
if (effect.getType() == PotionEffectType.INVISIBILITY) {
|
||||
|
||||
if (effect.getType() == PotionEffectType.INVISIBILITY)
|
||||
{
|
||||
watcher.setInvisible(true);
|
||||
} else if (effect.getType() == PotionEffectType.GLOWING) {
|
||||
}
|
||||
else if (effect.getType() == PotionEffectType.GLOWING)
|
||||
{
|
||||
watcher.setGlowing(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entity.getFireTicks() > 0) {
|
||||
|
||||
if (entity.getFireTicks() > 0)
|
||||
{
|
||||
watcher.setBurning(true);
|
||||
}
|
||||
if (doEquipment && entity instanceof LivingEntity) {
|
||||
|
||||
if (doEquipment && entity instanceof LivingEntity)
|
||||
{
|
||||
EntityEquipment equip = ((LivingEntity) entity).getEquipment();
|
||||
|
||||
watcher.setArmor(equip.getArmorContents());
|
||||
watcher.setItemInMainHand(equip.getItemInMainHand());
|
||||
if (disguiseType.getEntityType() == EntityType.HORSE) {
|
||||
|
||||
if (disguiseType.getEntityType() == EntityType.HORSE)
|
||||
{
|
||||
Horse horse = (Horse) entity;
|
||||
HorseInventory horseInventory = horse.getInventory();
|
||||
ItemStack saddle = horseInventory.getSaddle();
|
||||
if (saddle != null && saddle.getType() == Material.SADDLE) {
|
||||
|
||||
if (saddle != null && saddle.getType() == Material.SADDLE)
|
||||
{
|
||||
((HorseWatcher) watcher).setSaddled(true);
|
||||
}
|
||||
|
||||
((HorseWatcher) watcher).setHorseArmor(horseInventory.getArmor());
|
||||
}
|
||||
}
|
||||
for (Method method : entity.getClass().getMethods()) {
|
||||
for (Method method : entity.getClass().getMethods())
|
||||
{
|
||||
if ((doSneak || !method.getName().equals("setSneaking")) && (doSprint || !method.getName().equals("setSprinting"))
|
||||
&& method.getParameterTypes().length == 0 && method.getReturnType() != void.class) {
|
||||
&& method.getParameterTypes().length == 0 && method.getReturnType() != void.class)
|
||||
{
|
||||
Class methodReturn = method.getReturnType();
|
||||
if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class) {
|
||||
|
||||
if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class)
|
||||
{
|
||||
methodReturn = double.class;
|
||||
}
|
||||
|
||||
int firstCapitalMethod = firstCapital(method.getName());
|
||||
if (firstCapitalMethod > 0) {
|
||||
for (Method watcherMethod : watcher.getClass().getMethods()) {
|
||||
|
||||
if (firstCapitalMethod > 0)
|
||||
{
|
||||
for (Method watcherMethod : watcher.getClass().getMethods())
|
||||
{
|
||||
if (!watcherMethod.getName().startsWith("get") && watcherMethod.getReturnType() == void.class
|
||||
&& watcherMethod.getParameterTypes().length == 1) {
|
||||
&& watcherMethod.getParameterTypes().length == 1)
|
||||
{
|
||||
int firstCapitalWatcher = firstCapital(watcherMethod.getName());
|
||||
if (firstCapitalWatcher > 0
|
||||
&& method.getName().substring(firstCapitalMethod)
|
||||
.equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher))) {
|
||||
|
||||
if (firstCapitalWatcher > 0 && method.getName().substring(firstCapitalMethod)
|
||||
.equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher)))
|
||||
{
|
||||
Class methodParam = watcherMethod.getParameterTypes()[0];
|
||||
if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class) {
|
||||
|
||||
if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class)
|
||||
{
|
||||
methodParam = double.class;
|
||||
} else if (methodParam == AnimalColor.class) {
|
||||
}
|
||||
else if (methodParam == AnimalColor.class)
|
||||
{
|
||||
methodParam = DyeColor.class;
|
||||
}
|
||||
if (methodReturn == methodParam) {
|
||||
try {
|
||||
if (methodReturn == methodParam)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object value = method.invoke(entity);
|
||||
if (value != null) {
|
||||
if (value != null)
|
||||
{
|
||||
Class toCast = watcherMethod.getParameterTypes()[0];
|
||||
if (!(toCast.isInstance(value))) {
|
||||
if (toCast == float.class) {
|
||||
if (value instanceof Float) {
|
||||
if (!(toCast.isInstance(value)))
|
||||
{
|
||||
if (toCast == float.class)
|
||||
{
|
||||
if (value instanceof Float)
|
||||
{
|
||||
value = value;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
double d = (Double) value;
|
||||
value = (float) d;
|
||||
}
|
||||
} else if (toCast == double.class) {
|
||||
if (!(value instanceof Double)) {
|
||||
}
|
||||
else if (toCast == double.class)
|
||||
{
|
||||
if (!(value instanceof Double))
|
||||
{
|
||||
float d = (Float) value;
|
||||
value = (double) d;
|
||||
}
|
||||
} else if (toCast == AnimalColor.class) {
|
||||
}
|
||||
else if (toCast == AnimalColor.class)
|
||||
{
|
||||
value = AnimalColor.valueOf(((DyeColor) value).name());
|
||||
}
|
||||
}
|
||||
if (value instanceof Boolean && !(Boolean) value
|
||||
&& watcherMethod.getDeclaringClass() == FlagWatcher.class) {
|
||||
&& watcherMethod.getDeclaringClass() == FlagWatcher.class)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
watcherMethod.invoke(watcher, value);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
@@ -139,54 +196,73 @@ public class DisguiseAPI {
|
||||
return disguise;
|
||||
}
|
||||
|
||||
public static void disguiseEntity(Entity entity, Disguise disguise) {
|
||||
public static void disguiseEntity(Entity entity, Disguise disguise)
|
||||
{
|
||||
// If they are trying to disguise a null entity or use a null disguise
|
||||
// Just return.
|
||||
if (entity == null || disguise == null) {
|
||||
if (entity == null || disguise == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// The event wasn't cancelled.
|
||||
// If the disguise entity isn't the same as the one we are disguising
|
||||
if (disguise.getEntity() != entity) {
|
||||
if (disguise.getEntity() != entity)
|
||||
{
|
||||
// If the disguise entity actually exists
|
||||
if (disguise.getEntity() != null) {
|
||||
if (disguise.getEntity() != null)
|
||||
{
|
||||
// Clone the disguise
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
// Set the disguise's entity
|
||||
disguise.setEntity(entity);
|
||||
}
|
||||
if (Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId())) {
|
||||
|
||||
if (Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId()))
|
||||
{
|
||||
disguise.setViewSelfDisguise(true);
|
||||
}
|
||||
|
||||
disguise.startDisguise();
|
||||
}
|
||||
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) {
|
||||
if (disguise.getEntity() != null) {
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise)
|
||||
{
|
||||
if (disguise.getEntity() != null)
|
||||
{
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
|
||||
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
|
||||
for (Object obj : playersToNotSeeDisguise) {
|
||||
if (obj instanceof String) {
|
||||
|
||||
for (Object obj : playersToNotSeeDisguise)
|
||||
{
|
||||
if (obj instanceof String)
|
||||
{
|
||||
((TargetedDisguise) disguise).addPlayer((String) obj);
|
||||
} else if (obj instanceof Player) {
|
||||
}
|
||||
else if (obj instanceof Player)
|
||||
{
|
||||
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
|
||||
}
|
||||
}
|
||||
|
||||
disguiseEntity(entity, disguise);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> playersToNotSeeDisguise) {
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> playersToNotSeeDisguise)
|
||||
{
|
||||
disguiseIgnorePlayers(entity, disguise, (Collection) playersToNotSeeDisguise);
|
||||
}
|
||||
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Player... playersToNotSeeDisguise) {
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Player... playersToNotSeeDisguise)
|
||||
{
|
||||
disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise));
|
||||
}
|
||||
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise) {
|
||||
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise)
|
||||
{
|
||||
disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise));
|
||||
}
|
||||
|
||||
@@ -196,20 +272,29 @@ public class DisguiseAPI {
|
||||
* @param disguise
|
||||
* @return
|
||||
*/
|
||||
public static int disguiseNextEntity(Disguise disguise) {
|
||||
if (disguise == null) {
|
||||
public static int disguiseNextEntity(Disguise disguise)
|
||||
{
|
||||
if (disguise == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) {
|
||||
|
||||
if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise))
|
||||
{
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null);
|
||||
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
||||
return id;
|
||||
} catch (IllegalAccessException e) {
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -219,52 +304,73 @@ public class DisguiseAPI {
|
||||
* @param entity
|
||||
* @param disguise
|
||||
*/
|
||||
public static void disguiseToAll(Entity entity, Disguise disguise) {
|
||||
if (disguise.getEntity() != null) {
|
||||
public static void disguiseToAll(Entity entity, Disguise disguise)
|
||||
{
|
||||
if (disguise.getEntity() != null)
|
||||
{
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
|
||||
// You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
|
||||
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
|
||||
for (String observer : ((TargetedDisguise) disguise).getObservers()) {
|
||||
|
||||
for (String observer : ((TargetedDisguise) disguise).getObservers())
|
||||
{
|
||||
((TargetedDisguise) disguise).removePlayer(observer);
|
||||
}
|
||||
disguiseEntity(entity, disguise);
|
||||
}
|
||||
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise) {
|
||||
if (disguise.getEntity() != null) {
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise)
|
||||
{
|
||||
if (disguise.getEntity() != null)
|
||||
{
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
|
||||
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
|
||||
for (Object obj : playersToViewDisguise) {
|
||||
if (obj instanceof String) {
|
||||
|
||||
for (Object obj : playersToViewDisguise)
|
||||
{
|
||||
if (obj instanceof String)
|
||||
{
|
||||
((TargetedDisguise) disguise).addPlayer((String) obj);
|
||||
} else if (obj instanceof Player) {
|
||||
}
|
||||
else if (obj instanceof Player)
|
||||
{
|
||||
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
|
||||
}
|
||||
}
|
||||
|
||||
disguiseEntity(entity, disguise);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> playersToViewDisguise) {
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> playersToViewDisguise)
|
||||
{
|
||||
disguiseToPlayers(entity, disguise, (Collection) playersToViewDisguise);
|
||||
}
|
||||
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, Player... playersToViewDisguise) {
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, Player... playersToViewDisguise)
|
||||
{
|
||||
disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise));
|
||||
}
|
||||
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise) {
|
||||
public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise)
|
||||
{
|
||||
disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise));
|
||||
}
|
||||
|
||||
private static int firstCapital(String str) {
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
if (Character.isUpperCase(str.charAt(i))) {
|
||||
private static int firstCapital(String str)
|
||||
{
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
{
|
||||
if (Character.isUpperCase(str.charAt(i)))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -274,10 +380,13 @@ public class DisguiseAPI {
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static Disguise getDisguise(Entity disguised) {
|
||||
if (disguised == null) {
|
||||
public static Disguise getDisguise(Entity disguised)
|
||||
{
|
||||
if (disguised == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return DisguiseUtilities.getMainDisguise(disguised.getUniqueId());
|
||||
}
|
||||
|
||||
@@ -288,10 +397,13 @@ public class DisguiseAPI {
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static Disguise getDisguise(Player observer, Entity disguised) {
|
||||
if (disguised == null || observer == null) {
|
||||
public static Disguise getDisguise(Player observer, Entity disguised)
|
||||
{
|
||||
if (disguised == null || observer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return DisguiseUtilities.getDisguise(observer, disguised);
|
||||
}
|
||||
|
||||
@@ -301,10 +413,13 @@ public class DisguiseAPI {
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static Disguise[] getDisguises(Entity disguised) {
|
||||
if (disguised == null) {
|
||||
public static Disguise[] getDisguises(Entity disguised)
|
||||
{
|
||||
if (disguised == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return DisguiseUtilities.getDisguises(disguised.getUniqueId());
|
||||
}
|
||||
|
||||
@@ -315,11 +430,13 @@ public class DisguiseAPI {
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getFakeDisguise(UUID entityId) {
|
||||
public static int getFakeDisguise(UUID entityId)
|
||||
{
|
||||
return -10;
|
||||
}
|
||||
|
||||
public static int getSelfDisguiseId() {
|
||||
public static int getSelfDisguiseId()
|
||||
{
|
||||
return -10;
|
||||
}
|
||||
|
||||
@@ -329,7 +446,8 @@ public class DisguiseAPI {
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static boolean isDisguised(Entity disguised) {
|
||||
public static boolean isDisguised(Entity disguised)
|
||||
{
|
||||
return getDisguise(disguised) != null;
|
||||
}
|
||||
|
||||
@@ -340,15 +458,18 @@ public class DisguiseAPI {
|
||||
* @param disguised
|
||||
* @return
|
||||
*/
|
||||
public static boolean isDisguised(Player observer, Entity disguised) {
|
||||
public static boolean isDisguised(Player observer, Entity disguised)
|
||||
{
|
||||
return getDisguise(observer, disguised) != null;
|
||||
}
|
||||
|
||||
public static boolean isDisguiseInUse(Disguise disguise) {
|
||||
public static boolean isDisguiseInUse(Disguise disguise)
|
||||
{
|
||||
return disguise.isDisguiseInUse();
|
||||
}
|
||||
|
||||
public static boolean isSelfDisguised(Player player) {
|
||||
public static boolean isSelfDisguised(Player player)
|
||||
{
|
||||
return DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
@@ -358,18 +479,24 @@ public class DisguiseAPI {
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static boolean isViewSelfToggled(Entity entity) {
|
||||
return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible() : Disguise.getViewSelf().contains(entity.getUniqueId());
|
||||
public static boolean isViewSelfToggled(Entity entity)
|
||||
{
|
||||
return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible()
|
||||
: Disguise.getViewSelf().contains(entity.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka removed from the world.
|
||||
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka removed from
|
||||
* the world.
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
public static void undisguiseToAll(Entity entity) {
|
||||
public static void undisguiseToAll(Entity entity)
|
||||
{
|
||||
Disguise[] disguises = getDisguises(entity);
|
||||
for (Disguise disguise : disguises) {
|
||||
|
||||
for (Disguise disguise : disguises)
|
||||
{
|
||||
disguise.removeDisguise();
|
||||
}
|
||||
}
|
||||
@@ -380,20 +507,28 @@ public class DisguiseAPI {
|
||||
* @param entity
|
||||
* @param toggled
|
||||
*/
|
||||
public static void setViewDisguiseToggled(Entity entity, boolean toggled) {
|
||||
if (isDisguised(entity)) {
|
||||
public static void setViewDisguiseToggled(Entity entity, boolean toggled)
|
||||
{
|
||||
if (isDisguised(entity))
|
||||
{
|
||||
Disguise disguise = getDisguise(entity);
|
||||
disguise.setViewSelfDisguise(toggled);
|
||||
}
|
||||
if (toggled) {
|
||||
if (!Disguise.getViewSelf().contains(entity.getUniqueId())) {
|
||||
|
||||
if (toggled)
|
||||
{
|
||||
if (!Disguise.getViewSelf().contains(entity.getUniqueId()))
|
||||
{
|
||||
Disguise.getViewSelf().add(entity.getUniqueId());
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Disguise.getViewSelf().remove(entity.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
private DisguiseAPI() {
|
||||
private DisguiseAPI()
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,10 +1,12 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class DisguiseConfig {
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
|
||||
public class DisguiseConfig
|
||||
{
|
||||
|
||||
private static boolean animationEnabled;
|
||||
private static boolean bedEnabled;
|
||||
@@ -43,34 +45,43 @@ public class DisguiseConfig {
|
||||
private static String updateNotificationPermission;
|
||||
private static boolean witherSkullEnabled;
|
||||
|
||||
public static String getDisguiseBlownMessage() {
|
||||
public static String getDisguiseBlownMessage()
|
||||
{
|
||||
return disguiseBlownMessage;
|
||||
}
|
||||
|
||||
public static int getDisguiseCloneExpire() {
|
||||
public static int getDisguiseCloneExpire()
|
||||
{
|
||||
return disguiseCloneExpire;
|
||||
}
|
||||
|
||||
public static int getDisguiseEntityExpire() {
|
||||
public static int getDisguiseEntityExpire()
|
||||
{
|
||||
return disguiseEntityExpire;
|
||||
}
|
||||
|
||||
public static int getMaxClonedDisguises() {
|
||||
public static int getMaxClonedDisguises()
|
||||
{
|
||||
return maxClonedDisguises;
|
||||
}
|
||||
|
||||
public static String getUpdateMessage() {
|
||||
public static String getUpdateMessage()
|
||||
{
|
||||
return updateMessage;
|
||||
}
|
||||
|
||||
public static String getUpdateNotificationPermission() {
|
||||
public static String getUpdateNotificationPermission()
|
||||
{
|
||||
return updateNotificationPermission;
|
||||
}
|
||||
|
||||
public static void initConfig(ConfigurationSection config) {
|
||||
public static void initConfig(ConfigurationSection config)
|
||||
{
|
||||
|
||||
setSoundsEnabled(config.getBoolean("DisguiseSounds"));
|
||||
setVelocitySent(config.getBoolean("SendVelocity"));
|
||||
setViewDisguises(config.getBoolean("ViewSelfDisguises")); //Since we can now toggle, the view disguises listener must always be on
|
||||
setViewDisguises(config.getBoolean("ViewSelfDisguises")); // Since we can now toggle, the view disguises listener must
|
||||
// always be on
|
||||
PacketsManager.setViewDisguisesListener(true);
|
||||
setHearSelfDisguise(config.getBoolean("HearSelfDisguise"));
|
||||
setHideArmorFromSelf(config.getBoolean("RemoveArmor"));
|
||||
@@ -105,19 +116,23 @@ public class DisguiseConfig {
|
||||
setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true));
|
||||
}
|
||||
|
||||
public static boolean isAnimationPacketsEnabled() {
|
||||
public static boolean isAnimationPacketsEnabled()
|
||||
{
|
||||
return animationEnabled;
|
||||
}
|
||||
|
||||
public static boolean isBedPacketsEnabled() {
|
||||
public static boolean isBedPacketsEnabled()
|
||||
{
|
||||
return bedEnabled;
|
||||
}
|
||||
|
||||
public static boolean isCollectPacketsEnabled() {
|
||||
public static boolean isCollectPacketsEnabled()
|
||||
{
|
||||
return collectEnabled;
|
||||
}
|
||||
|
||||
public static boolean isDisguiseBlownOnAttack() {
|
||||
public static boolean isDisguiseBlownOnAttack()
|
||||
{
|
||||
return blowDisguisesOnAttack;
|
||||
}
|
||||
|
||||
@@ -125,96 +140,117 @@ public class DisguiseConfig {
|
||||
* @deprecated Spelling mistake.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isEnquipmentPacketsEnabled() {
|
||||
public static boolean isEnquipmentPacketsEnabled()
|
||||
{
|
||||
return equipmentEnabled;
|
||||
}
|
||||
|
||||
public static boolean isEntityAnimationsAdded() {
|
||||
public static boolean isEntityAnimationsAdded()
|
||||
{
|
||||
return entityAnimationsAdded;
|
||||
}
|
||||
|
||||
public static boolean isEntityStatusPacketsEnabled() {
|
||||
public static boolean isEntityStatusPacketsEnabled()
|
||||
{
|
||||
return entityStatusEnabled;
|
||||
}
|
||||
|
||||
public static boolean isEquipmentPacketsEnabled() {
|
||||
public static boolean isEquipmentPacketsEnabled()
|
||||
{
|
||||
return equipmentEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around
|
||||
*/
|
||||
public static boolean isHidingArmorFromSelf() {
|
||||
public static boolean isHidingArmorFromSelf()
|
||||
{
|
||||
return hidingArmor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
|
||||
*/
|
||||
public static boolean isHidingHeldItemFromSelf() {
|
||||
public static boolean isHidingHeldItemFromSelf()
|
||||
{
|
||||
return hidingHeldItem;
|
||||
}
|
||||
|
||||
public static boolean isKeepDisguiseOnEntityDespawn() {
|
||||
public static boolean isKeepDisguiseOnEntityDespawn()
|
||||
{
|
||||
return keepDisguiseEntityDespawn;
|
||||
}
|
||||
|
||||
public static boolean isKeepDisguiseOnPlayerDeath() {
|
||||
public static boolean isKeepDisguiseOnPlayerDeath()
|
||||
{
|
||||
return keepDisguisePlayerDeath;
|
||||
}
|
||||
|
||||
public static boolean isKeepDisguiseOnPlayerLogout() {
|
||||
public static boolean isKeepDisguiseOnPlayerLogout()
|
||||
{
|
||||
return keepDisguisePlayerLogout;
|
||||
}
|
||||
|
||||
public static boolean isMaxHealthDeterminedByDisguisedEntity() {
|
||||
public static boolean isMaxHealthDeterminedByDisguisedEntity()
|
||||
{
|
||||
return maxHealthIsDisguisedEntity;
|
||||
}
|
||||
|
||||
public static boolean isMetadataPacketsEnabled() {
|
||||
public static boolean isMetadataPacketsEnabled()
|
||||
{
|
||||
return sendsEntityMetadata;
|
||||
}
|
||||
|
||||
public static boolean isMiscDisguisesForLivingEnabled() {
|
||||
public static boolean isMiscDisguisesForLivingEnabled()
|
||||
{
|
||||
return miscDisguisesForLivingEnabled;
|
||||
}
|
||||
|
||||
public static boolean isModifyBoundingBox() {
|
||||
public static boolean isModifyBoundingBox()
|
||||
{
|
||||
return modifyBoundingBox;
|
||||
}
|
||||
|
||||
public static boolean isMonstersIgnoreDisguises() {
|
||||
public static boolean isMonstersIgnoreDisguises()
|
||||
{
|
||||
return targetDisguises;
|
||||
}
|
||||
|
||||
public static boolean isMovementPacketsEnabled() {
|
||||
public static boolean isMovementPacketsEnabled()
|
||||
{
|
||||
return movementEnabled;
|
||||
}
|
||||
|
||||
public static boolean isNameAboveHeadAlwaysVisible() {
|
||||
public static boolean isNameAboveHeadAlwaysVisible()
|
||||
{
|
||||
return showNameAboveHeadAlwaysVisible;
|
||||
}
|
||||
|
||||
public static boolean isNameOfPlayerShownAboveDisguise() {
|
||||
public static boolean isNameOfPlayerShownAboveDisguise()
|
||||
{
|
||||
return showNameAboveHead;
|
||||
}
|
||||
|
||||
public static boolean isSelfDisguisesSoundsReplaced() {
|
||||
public static boolean isSelfDisguisesSoundsReplaced()
|
||||
{
|
||||
return hearSelfDisguise;
|
||||
}
|
||||
|
||||
public static boolean isSheepDyeable() {
|
||||
public static boolean isSheepDyeable()
|
||||
{
|
||||
return colorizeSheep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the sound packets caught and modified
|
||||
*/
|
||||
public static boolean isSoundEnabled() {
|
||||
public static boolean isSoundEnabled()
|
||||
{
|
||||
return PacketsManager.isHearDisguisesEnabled();
|
||||
}
|
||||
|
||||
public static boolean isUndisguiseOnWorldChange() {
|
||||
public static boolean isUndisguiseOnWorldChange()
|
||||
{
|
||||
return undisguiseSwitchWorlds;
|
||||
}
|
||||
|
||||
@@ -223,7 +259,8 @@ public class DisguiseConfig {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isVelocitySent() {
|
||||
public static boolean isVelocitySent()
|
||||
{
|
||||
return sendVelocity;
|
||||
}
|
||||
|
||||
@@ -232,74 +269,98 @@ public class DisguiseConfig {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean isViewDisguises() {
|
||||
public static boolean isViewDisguises()
|
||||
{
|
||||
return viewSelfDisguise;
|
||||
}
|
||||
|
||||
public static boolean isWitherSkullPacketsEnabled() {
|
||||
public static boolean isWitherSkullPacketsEnabled()
|
||||
{
|
||||
return witherSkullEnabled;
|
||||
}
|
||||
|
||||
public static boolean isWolfDyeable() {
|
||||
public static boolean isWolfDyeable()
|
||||
{
|
||||
return colorizeWolf;
|
||||
}
|
||||
|
||||
public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
|
||||
public static void setAddEntityAnimations(boolean isEntityAnimationsAdded)
|
||||
{
|
||||
entityAnimationsAdded = isEntityAnimationsAdded;
|
||||
}
|
||||
|
||||
public static void setAnimationPacketsEnabled(boolean enabled) {
|
||||
if (enabled != isAnimationPacketsEnabled()) {
|
||||
public static void setAnimationPacketsEnabled(boolean enabled)
|
||||
{
|
||||
if (enabled != isAnimationPacketsEnabled())
|
||||
{
|
||||
animationEnabled = enabled;
|
||||
|
||||
PacketsManager.setupMainPacketsListener();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBedPacketsEnabled(boolean enabled) {
|
||||
if (enabled != isBedPacketsEnabled()) {
|
||||
public static void setBedPacketsEnabled(boolean enabled)
|
||||
{
|
||||
if (enabled != isBedPacketsEnabled())
|
||||
{
|
||||
bedEnabled = enabled;
|
||||
|
||||
PacketsManager.setupMainPacketsListener();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCollectPacketsEnabled(boolean enabled) {
|
||||
if (enabled != isCollectPacketsEnabled()) {
|
||||
public static void setCollectPacketsEnabled(boolean enabled)
|
||||
{
|
||||
if (enabled != isCollectPacketsEnabled())
|
||||
{
|
||||
collectEnabled = enabled;
|
||||
|
||||
PacketsManager.setupMainPacketsListener();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setDisguiseBlownMessage(String newMessage) {
|
||||
public static void setDisguiseBlownMessage(String newMessage)
|
||||
{
|
||||
disguiseBlownMessage = newMessage;
|
||||
}
|
||||
|
||||
public static void setDisguiseBlownOnAttack(boolean blowDisguise) {
|
||||
public static void setDisguiseBlownOnAttack(boolean blowDisguise)
|
||||
{
|
||||
blowDisguisesOnAttack = blowDisguise;
|
||||
}
|
||||
|
||||
public static void setDisguiseCloneExpire(int newExpires) {
|
||||
public static void setDisguiseCloneExpire(int newExpires)
|
||||
{
|
||||
disguiseCloneExpire = newExpires;
|
||||
}
|
||||
|
||||
public static void setDisguiseEntityExpire(int newExpires) {
|
||||
public static void setDisguiseEntityExpire(int newExpires)
|
||||
{
|
||||
disguiseEntityExpire = newExpires;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void setEnquipmentPacketsEnabled(boolean enabled) {
|
||||
public static void setEnquipmentPacketsEnabled(boolean enabled)
|
||||
{
|
||||
setEquipmentPacketsEnabled(enabled);
|
||||
}
|
||||
|
||||
public static void setEntityStatusPacketsEnabled(boolean enabled) {
|
||||
if (enabled != isEntityStatusPacketsEnabled()) {
|
||||
public static void setEntityStatusPacketsEnabled(boolean enabled)
|
||||
{
|
||||
if (enabled != isEntityStatusPacketsEnabled())
|
||||
{
|
||||
entityStatusEnabled = enabled;
|
||||
|
||||
PacketsManager.setupMainPacketsListener();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setEquipmentPacketsEnabled(boolean enabled) {
|
||||
if (enabled != isEquipmentPacketsEnabled()) {
|
||||
public static void setEquipmentPacketsEnabled(boolean enabled)
|
||||
{
|
||||
if (enabled != isEquipmentPacketsEnabled())
|
||||
{
|
||||
equipmentEnabled = enabled;
|
||||
|
||||
PacketsManager.setupMainPacketsListener();
|
||||
}
|
||||
}
|
||||
@@ -307,8 +368,10 @@ public class DisguiseConfig {
|
||||
/**
|
||||
* Can players hear their own disguises
|
||||
*/
|
||||
public static void setHearSelfDisguise(boolean replaceSound) {
|
||||
if (hearSelfDisguise != replaceSound) {
|
||||
public static void setHearSelfDisguise(boolean replaceSound)
|
||||
{
|
||||
if (hearSelfDisguise != replaceSound)
|
||||
{
|
||||
hearSelfDisguise = replaceSound;
|
||||
}
|
||||
}
|
||||
@@ -316,9 +379,12 @@ public class DisguiseConfig {
|
||||
/**
|
||||
* Set the plugin to hide self disguises armor from theirselves
|
||||
*/
|
||||
public static void setHideArmorFromSelf(boolean hideArmor) {
|
||||
if (hidingArmor != hideArmor) {
|
||||
public static void setHideArmorFromSelf(boolean hideArmor)
|
||||
{
|
||||
if (hidingArmor != hideArmor)
|
||||
{
|
||||
hidingArmor = hideArmor;
|
||||
|
||||
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
|
||||
}
|
||||
}
|
||||
@@ -326,95 +392,121 @@ public class DisguiseConfig {
|
||||
/**
|
||||
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
|
||||
*/
|
||||
public static void setHideHeldItemFromSelf(boolean hideHelditem) {
|
||||
if (hidingHeldItem != hideHelditem) {
|
||||
public static void setHideHeldItemFromSelf(boolean hideHelditem)
|
||||
{
|
||||
if (hidingHeldItem != hideHelditem)
|
||||
{
|
||||
hidingHeldItem = hideHelditem;
|
||||
|
||||
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
|
||||
public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise)
|
||||
{
|
||||
keepDisguiseEntityDespawn = keepDisguise;
|
||||
}
|
||||
|
||||
public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
|
||||
public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise)
|
||||
{
|
||||
keepDisguisePlayerDeath = keepDisguise;
|
||||
}
|
||||
|
||||
public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
|
||||
public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise)
|
||||
{
|
||||
keepDisguisePlayerLogout = keepDisguise;
|
||||
}
|
||||
|
||||
public static void setMaxClonedDisguises(int newMax) {
|
||||
public static void setMaxClonedDisguises(int newMax)
|
||||
{
|
||||
maxClonedDisguises = newMax;
|
||||
}
|
||||
|
||||
public static void setMaxHealthDeterminedByDisguisedEntity(boolean isDetermined) {
|
||||
public static void setMaxHealthDeterminedByDisguisedEntity(boolean isDetermined)
|
||||
{
|
||||
maxHealthIsDisguisedEntity = isDetermined;
|
||||
}
|
||||
|
||||
public static void setMetadataPacketsEnabled(boolean enabled) {
|
||||
public static void setMetadataPacketsEnabled(boolean enabled)
|
||||
{
|
||||
sendsEntityMetadata = enabled;
|
||||
}
|
||||
|
||||
public static void setMiscDisguisesForLivingEnabled(boolean enabled) {
|
||||
if (enabled != isMiscDisguisesForLivingEnabled()) {
|
||||
public static void setMiscDisguisesForLivingEnabled(boolean enabled)
|
||||
{
|
||||
if (enabled != isMiscDisguisesForLivingEnabled())
|
||||
{
|
||||
miscDisguisesForLivingEnabled = enabled;
|
||||
|
||||
PacketsManager.setupMainPacketsListener();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setModifyBoundingBox(boolean modifyBounding) {
|
||||
public static void setModifyBoundingBox(boolean modifyBounding)
|
||||
{
|
||||
modifyBoundingBox = modifyBounding;
|
||||
}
|
||||
|
||||
public static void setMonstersIgnoreDisguises(boolean ignore) {
|
||||
public static void setMonstersIgnoreDisguises(boolean ignore)
|
||||
{
|
||||
targetDisguises = ignore;
|
||||
}
|
||||
|
||||
public static void setMovementPacketsEnabled(boolean enabled) {
|
||||
if (enabled != isMovementPacketsEnabled()) {
|
||||
public static void setMovementPacketsEnabled(boolean enabled)
|
||||
{
|
||||
if (enabled != isMovementPacketsEnabled())
|
||||
{
|
||||
movementEnabled = enabled;
|
||||
|
||||
PacketsManager.setupMainPacketsListener();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) {
|
||||
public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible)
|
||||
{
|
||||
showNameAboveHeadAlwaysVisible = alwaysVisible;
|
||||
}
|
||||
|
||||
public static void setNameOfPlayerShownAboveDisguise(boolean showNames) {
|
||||
public static void setNameOfPlayerShownAboveDisguise(boolean showNames)
|
||||
{
|
||||
showNameAboveHead = showNames;
|
||||
}
|
||||
|
||||
public static void setSheepDyeable(boolean color) {
|
||||
public static void setSheepDyeable(boolean color)
|
||||
{
|
||||
colorizeSheep = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the disguises play sounds when hurt
|
||||
*/
|
||||
public static void setSoundsEnabled(boolean isSoundsEnabled) {
|
||||
public static void setSoundsEnabled(boolean isSoundsEnabled)
|
||||
{
|
||||
PacketsManager.setHearDisguisesListener(isSoundsEnabled);
|
||||
}
|
||||
|
||||
public static void setUndisguiseOnWorldChange(boolean isUndisguise) {
|
||||
public static void setUndisguiseOnWorldChange(boolean isUndisguise)
|
||||
{
|
||||
undisguiseSwitchWorlds = isUndisguise;
|
||||
}
|
||||
|
||||
public static void setUpdateMessage(String newMessage) {
|
||||
public static void setUpdateMessage(String newMessage)
|
||||
{
|
||||
updateMessage = newMessage;
|
||||
}
|
||||
|
||||
public static void setUpdateNotificationPermission(String newPermission) {
|
||||
public static void setUpdateNotificationPermission(String newPermission)
|
||||
{
|
||||
updateNotificationPermission = newPermission;
|
||||
}
|
||||
|
||||
public static void setStopShulkerDisguisesFromMoving(boolean stopShulkerDisguisesFromMoving) {
|
||||
public static void setStopShulkerDisguisesFromMoving(boolean stopShulkerDisguisesFromMoving)
|
||||
{
|
||||
DisguiseConfig.stopShulkerDisguisesFromMoving = stopShulkerDisguisesFromMoving;
|
||||
}
|
||||
|
||||
public static boolean isStopShulkerDisguisesFromMoving() {
|
||||
public static boolean isStopShulkerDisguisesFromMoving()
|
||||
{
|
||||
return stopShulkerDisguisesFromMoving;
|
||||
}
|
||||
|
||||
@@ -423,22 +515,27 @@ public class DisguiseConfig {
|
||||
*
|
||||
* @param sendVelocityPackets
|
||||
*/
|
||||
public static void setVelocitySent(boolean sendVelocityPackets) {
|
||||
public static void setVelocitySent(boolean sendVelocityPackets)
|
||||
{
|
||||
sendVelocity = sendVelocityPackets;
|
||||
}
|
||||
|
||||
public static void setViewDisguises(boolean seeOwnDisguise) {
|
||||
public static void setViewDisguises(boolean seeOwnDisguise)
|
||||
{
|
||||
viewSelfDisguise = seeOwnDisguise;
|
||||
}
|
||||
|
||||
public static void setWitherSkullPacketsEnabled(boolean enabled) {
|
||||
public static void setWitherSkullPacketsEnabled(boolean enabled)
|
||||
{
|
||||
witherSkullEnabled = enabled;
|
||||
}
|
||||
|
||||
public static void setWolfDyeable(boolean color) {
|
||||
public static void setWolfDyeable(boolean color)
|
||||
{
|
||||
colorizeWolf = color;
|
||||
}
|
||||
|
||||
private DisguiseConfig() {
|
||||
private DisguiseConfig()
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,15 +1,9 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.UpdateChecker;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@@ -33,9 +27,17 @@ import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.UpdateChecker;
|
||||
|
||||
public class DisguiseListener implements Listener {
|
||||
|
@@ -1,8 +1,22 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
|
||||
import me.libraryaddict.disguise.commands.CloneDisguiseCommand;
|
||||
import me.libraryaddict.disguise.commands.DisguiseCommand;
|
||||
import me.libraryaddict.disguise.commands.DisguiseViewSelf;
|
||||
@@ -33,37 +47,30 @@ import me.libraryaddict.disguise.utilities.FakeBoundingBox;
|
||||
import me.libraryaddict.disguise.utilities.Metrics;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
|
||||
public class LibsDisguises extends JavaPlugin {
|
||||
|
||||
public class LibsDisguises extends JavaPlugin
|
||||
{
|
||||
private static LibsDisguises instance;
|
||||
private DisguiseListener listener;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
public void onEnable()
|
||||
{
|
||||
getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion());
|
||||
|
||||
saveDefaultConfig();
|
||||
|
||||
PacketsManager.init(this);
|
||||
DisguiseUtilities.init(this);
|
||||
|
||||
DisguiseConfig.initConfig(getConfig());
|
||||
|
||||
PacketsManager.addPacketListeners();
|
||||
|
||||
listener = new DisguiseListener(this);
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(listener, this);
|
||||
|
||||
getCommand("disguise").setExecutor(new DisguiseCommand());
|
||||
getCommand("undisguise").setExecutor(new UndisguiseCommand());
|
||||
getCommand("disguiseplayer").setExecutor(new PlayerDisguiseCommand());
|
||||
@@ -76,228 +83,304 @@ public class LibsDisguises extends JavaPlugin {
|
||||
getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand());
|
||||
getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand());
|
||||
getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf());
|
||||
|
||||
registerValues();
|
||||
|
||||
instance = this;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the config with new config options.
|
||||
*/
|
||||
public void reload() {
|
||||
public void reload()
|
||||
{
|
||||
HandlerList.unregisterAll(listener);
|
||||
|
||||
reloadConfig();
|
||||
DisguiseConfig.initConfig(getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume for mob noises. As well as setting their watcher class and entity size.
|
||||
* Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume
|
||||
* for mob noises. As well as setting their watcher class and entity size.
|
||||
*/
|
||||
private void registerValues() {
|
||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||
if (disguiseType.getEntityType() == null) {
|
||||
private void registerValues()
|
||||
{
|
||||
for (DisguiseType disguiseType : DisguiseType.values())
|
||||
{
|
||||
if (disguiseType.getEntityType() == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Class watcherClass = null;
|
||||
try {
|
||||
switch (disguiseType) {
|
||||
case ITEM_FRAME: //Not really supported...
|
||||
break;
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case MINECART_TNT:
|
||||
watcherClass = MinecartWatcher.class;
|
||||
break;
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
watcherClass = HorseWatcher.class;
|
||||
break;
|
||||
case ZOMBIE_VILLAGER:
|
||||
case PIG_ZOMBIE:
|
||||
watcherClass = ZombieWatcher.class;
|
||||
break;
|
||||
case MAGMA_CUBE:
|
||||
watcherClass = SlimeWatcher.class;
|
||||
break;
|
||||
case ELDER_GUARDIAN:
|
||||
watcherClass = GuardianWatcher.class;
|
||||
break;
|
||||
case ENDERMITE:
|
||||
watcherClass = LivingWatcher.class;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
watcherClass = SkeletonWatcher.class;
|
||||
break;
|
||||
default:
|
||||
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers."
|
||||
+ toReadable(disguiseType.name()) + "Watcher");
|
||||
break;
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
// There is no explicit watcher for this entity.
|
||||
Class entityClass = disguiseType.getEntityType().getEntityClass();
|
||||
if (entityClass != null) {
|
||||
if (Tameable.class.isAssignableFrom(entityClass)) {
|
||||
watcherClass = TameableWatcher.class;
|
||||
} else if (Ageable.class.isAssignableFrom(entityClass)) {
|
||||
watcherClass = AgeableWatcher.class;
|
||||
} else if (LivingEntity.class.isAssignableFrom(entityClass)) {
|
||||
watcherClass = LivingWatcher.class;
|
||||
} else {
|
||||
watcherClass = FlagWatcher.class;
|
||||
}
|
||||
} else {
|
||||
watcherClass = FlagWatcher.class; //Disguise is unknown type
|
||||
}
|
||||
}
|
||||
disguiseType.setWatcherClass(watcherClass);
|
||||
if (DisguiseValues.getDisguiseValues(disguiseType) != null) {
|
||||
continue;
|
||||
}
|
||||
String nmsEntityName = toReadable(disguiseType.name());
|
||||
switch (disguiseType) {
|
||||
case WITHER_SKELETON:
|
||||
case ZOMBIE_VILLAGER:
|
||||
|
||||
try
|
||||
{
|
||||
switch (disguiseType)
|
||||
{
|
||||
case ITEM_FRAME: // Not really supported...
|
||||
break;
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case MINECART_TNT:
|
||||
watcherClass = MinecartWatcher.class;
|
||||
break;
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
continue;
|
||||
case PRIMED_TNT:
|
||||
nmsEntityName = "TNTPrimed";
|
||||
watcherClass = HorseWatcher.class;
|
||||
break;
|
||||
case MINECART_TNT:
|
||||
nmsEntityName = "MinecartTNT";
|
||||
case ZOMBIE_VILLAGER:
|
||||
case PIG_ZOMBIE:
|
||||
watcherClass = ZombieWatcher.class;
|
||||
break;
|
||||
case MINECART:
|
||||
nmsEntityName = "MinecartRideable";
|
||||
break;
|
||||
case FIREWORK:
|
||||
nmsEntityName = "Fireworks";
|
||||
break;
|
||||
case SPLASH_POTION:
|
||||
nmsEntityName = "Potion";
|
||||
break;
|
||||
case GIANT:
|
||||
nmsEntityName = "GiantZombie";
|
||||
break;
|
||||
case DROPPED_ITEM:
|
||||
nmsEntityName = "Item";
|
||||
break;
|
||||
case FIREBALL:
|
||||
nmsEntityName = "LargeFireball";
|
||||
break;
|
||||
case LEASH_HITCH:
|
||||
nmsEntityName = "Leash";
|
||||
case MAGMA_CUBE:
|
||||
watcherClass = SlimeWatcher.class;
|
||||
break;
|
||||
case ELDER_GUARDIAN:
|
||||
nmsEntityName = "Guardian";
|
||||
watcherClass = GuardianWatcher.class;
|
||||
break;
|
||||
case ENDERMITE:
|
||||
watcherClass = LivingWatcher.class;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
watcherClass = SkeletonWatcher.class;
|
||||
break;
|
||||
case ARROW:
|
||||
nmsEntityName = "TippedArrow";
|
||||
default:
|
||||
watcherClass = Class.forName(
|
||||
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher");
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (nmsEntityName.equalsIgnoreCase("Unknown")) {
|
||||
catch (ClassNotFoundException ex)
|
||||
{
|
||||
// There is no explicit watcher for this entity.
|
||||
Class entityClass = disguiseType.getEntityType().getEntityClass();
|
||||
|
||||
if (entityClass != null)
|
||||
{
|
||||
if (Tameable.class.isAssignableFrom(entityClass))
|
||||
{
|
||||
watcherClass = TameableWatcher.class;
|
||||
}
|
||||
else if (Ageable.class.isAssignableFrom(entityClass))
|
||||
{
|
||||
watcherClass = AgeableWatcher.class;
|
||||
}
|
||||
else if (LivingEntity.class.isAssignableFrom(entityClass))
|
||||
{
|
||||
watcherClass = LivingWatcher.class;
|
||||
}
|
||||
else
|
||||
{
|
||||
watcherClass = FlagWatcher.class;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
watcherClass = FlagWatcher.class; // Disguise is unknown type
|
||||
}
|
||||
}
|
||||
|
||||
disguiseType.setWatcherClass(watcherClass);
|
||||
|
||||
if (DisguiseValues.getDisguiseValues(disguiseType) != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
String nmsEntityName = toReadable(disguiseType.name());
|
||||
|
||||
switch (disguiseType)
|
||||
{
|
||||
case WITHER_SKELETON:
|
||||
case ZOMBIE_VILLAGER:
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
continue;
|
||||
case PRIMED_TNT:
|
||||
nmsEntityName = "TNTPrimed";
|
||||
break;
|
||||
case MINECART_TNT:
|
||||
nmsEntityName = "MinecartTNT";
|
||||
break;
|
||||
case MINECART:
|
||||
nmsEntityName = "MinecartRideable";
|
||||
break;
|
||||
case FIREWORK:
|
||||
nmsEntityName = "Fireworks";
|
||||
break;
|
||||
case SPLASH_POTION:
|
||||
nmsEntityName = "Potion";
|
||||
break;
|
||||
case GIANT:
|
||||
nmsEntityName = "GiantZombie";
|
||||
break;
|
||||
case DROPPED_ITEM:
|
||||
nmsEntityName = "Item";
|
||||
break;
|
||||
case FIREBALL:
|
||||
nmsEntityName = "LargeFireball";
|
||||
break;
|
||||
case LEASH_HITCH:
|
||||
nmsEntityName = "Leash";
|
||||
break;
|
||||
case ELDER_GUARDIAN:
|
||||
nmsEntityName = "Guardian";
|
||||
break;
|
||||
case ARROW:
|
||||
nmsEntityName = "TippedArrow";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (nmsEntityName.equalsIgnoreCase("Unknown"))
|
||||
{
|
||||
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
|
||||
|
||||
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
|
||||
|
||||
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
||||
if (sound != null) {
|
||||
|
||||
if (sound != null)
|
||||
{
|
||||
sound.setDamageAndIdleSoundVolume(1f);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
|
||||
if (nmsEntity == null) {
|
||||
|
||||
if (nmsEntity == null)
|
||||
{
|
||||
getLogger().warning("Entity not found! (" + nmsEntityName + ")");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
|
||||
int entitySize = 0;
|
||||
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
||||
if (field.getType().getName().equals("EnumEntitySize")) {
|
||||
|
||||
for (Field field : ReflectionManager.getNmsClass("Entity").getFields())
|
||||
{
|
||||
if (field.getType().getName().equals("EnumEntitySize"))
|
||||
{
|
||||
Enum enumEntitySize = (Enum) field.get(nmsEntity);
|
||||
|
||||
entitySize = enumEntitySize.ordinal();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize,
|
||||
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
|
||||
|
||||
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
|
||||
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
|
||||
|
||||
for (WrappedWatchableObject watch : watcher.getWatchableObjects())
|
||||
{
|
||||
disguiseValues.setMetaValue(watch.getIndex(), watch.getValue());
|
||||
// Uncomment when I need to find the new datawatcher values for a class..
|
||||
// int id = watch.getIndex();
|
||||
// Object val = watch.getValue();
|
||||
// Class<?> valClazz = val != null ? watch.getValue().getClass() : null;
|
||||
// try {
|
||||
// val = val.toString();
|
||||
// } catch (Exception e) {
|
||||
// val = val != null ? val.getClass() : "null";
|
||||
// }
|
||||
// System.out.println("Disguise: " + disguiseType + ", ID: " + id + ", Class: " + (val == null ? "null" : valClazz) + ", Value: " + val);
|
||||
// int id = watch.getIndex();
|
||||
// Object val = watch.getValue();
|
||||
// Class<?> valClazz = val != null ? watch.getValue().getClass() : null;
|
||||
// try {
|
||||
// val = val.toString();
|
||||
// } catch (Exception e) {
|
||||
// val = val != null ? val.getClass() : "null";
|
||||
// }
|
||||
// System.out.println("Disguise: " + disguiseType + ", ID: " + id + ", Class: " + (val == null ? "null" :
|
||||
// valClazz) + ", Value: " + val);
|
||||
}
|
||||
|
||||
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
||||
if (sound != null) {
|
||||
|
||||
if (sound != null)
|
||||
{
|
||||
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
|
||||
if (soundStrength != null) {
|
||||
|
||||
if (soundStrength != null)
|
||||
{
|
||||
sound.setDamageAndIdleSoundVolume(soundStrength);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the bounding box
|
||||
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||
if (bukkitEntity instanceof Ageable) {
|
||||
|
||||
if (bukkitEntity instanceof Ageable)
|
||||
{
|
||||
((Ageable) bukkitEntity).setBaby();
|
||||
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||
} else if (bukkitEntity instanceof Zombie) {
|
||||
((Zombie) bukkitEntity).setBaby(true);
|
||||
|
||||
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||
}
|
||||
else if (bukkitEntity instanceof Zombie)
|
||||
{
|
||||
((Zombie) bukkitEntity).setBaby(true);
|
||||
|
||||
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||
}
|
||||
|
||||
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
|
||||
} catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) {
|
||||
System.out.print("[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name()
|
||||
+ "!");
|
||||
}
|
||||
catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex)
|
||||
{
|
||||
System.out.print(
|
||||
"[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
|
||||
System.out.print("[LibsDisguises] Before reporting this error, "
|
||||
+ "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
|
||||
System.out
|
||||
.print("[LibsDisguises] Development builds are available at (ProtocolLib) "
|
||||
+ "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/");
|
||||
System.out.print("[LibsDisguises] Development builds are available at (ProtocolLib) "
|
||||
+ "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/");
|
||||
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String toReadable(String string) {
|
||||
private String toReadable(String string)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String s : string.split("_")) {
|
||||
|
||||
for (String s : string.split("_"))
|
||||
{
|
||||
builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase());
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public DisguiseListener getListener() {
|
||||
public DisguiseListener getListener()
|
||||
{
|
||||
return listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* External APIs shouldn't actually need this instance.
|
||||
* DisguiseAPI should be enough to handle most cases.
|
||||
* External APIs shouldn't actually need this instance. DisguiseAPI should be enough to handle most cases.
|
||||
*
|
||||
* @return The instance of this plugin
|
||||
*/
|
||||
public static LibsDisguises getInstance() {
|
||||
public static LibsDisguises getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
@@ -1,14 +1,13 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@@ -21,13 +20,15 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
|
||||
|
||||
/**
|
@@ -1,15 +1,16 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
||||
public class CloneDisguiseCommand extends BaseDisguiseCommand {
|
||||
|
@@ -1,18 +1,19 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
|
||||
public class DisguiseCommand extends BaseDisguiseCommand {
|
||||
|
@@ -1,12 +1,13 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Navid
|
@@ -1,17 +1,18 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
||||
public class EntityDisguiseCommand extends BaseDisguiseCommand {
|
||||
|
@@ -1,10 +1,11 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@@ -13,11 +14,11 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
|
||||
public class HelpDisguiseCommand extends BaseDisguiseCommand {
|
||||
|
@@ -1,12 +1,13 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
|
||||
public class LibsDisguisesCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
@@ -1,10 +1,8 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -12,8 +10,11 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
|
||||
public class PlayerDisguiseCommand extends BaseDisguiseCommand {
|
||||
|
@@ -1,11 +1,9 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.ClassGetter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -15,135 +13,207 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.ClassGetter;
|
||||
|
||||
public class RadiusDisguiseCommand extends BaseDisguiseCommand {
|
||||
public class RadiusDisguiseCommand extends BaseDisguiseCommand
|
||||
{
|
||||
|
||||
private int maxRadius = 30;
|
||||
private ArrayList<Class> validClasses = new ArrayList<>();
|
||||
|
||||
public RadiusDisguiseCommand(int maxRadius) {
|
||||
public RadiusDisguiseCommand(int maxRadius)
|
||||
{
|
||||
this.maxRadius = maxRadius;
|
||||
for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) {
|
||||
if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null) {
|
||||
|
||||
for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity"))
|
||||
{
|
||||
if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null)
|
||||
{
|
||||
validClasses.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (sender.getName().equals("CONSOLE")) {
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
||||
{
|
||||
if (sender.getName().equals("CONSOLE"))
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
|
||||
return true;
|
||||
}
|
||||
|
||||
HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
|
||||
if (map.isEmpty()) {
|
||||
|
||||
if (map.isEmpty())
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
sendCommandUsage(sender, map);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("entitytype") || args[0].equalsIgnoreCase("entitytypes")) {
|
||||
|
||||
if (args[0].equalsIgnoreCase("entitytype") || args[0].equalsIgnoreCase("entitytypes"))
|
||||
{
|
||||
ArrayList<String> classes = new ArrayList<>();
|
||||
for (Class c : validClasses) {
|
||||
|
||||
for (Class c : validClasses)
|
||||
{
|
||||
classes.add(c.getSimpleName());
|
||||
}
|
||||
|
||||
Collections.sort(classes);
|
||||
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN
|
||||
+ StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + ".");
|
||||
return true;
|
||||
}
|
||||
|
||||
Class entityClass = Entity.class;
|
||||
EntityType type = null;
|
||||
int starting = 0;
|
||||
if (!isNumeric(args[0])) {
|
||||
for (Class c : validClasses) {
|
||||
if (c.getSimpleName().equalsIgnoreCase(args[0])) {
|
||||
|
||||
if (!isNumeric(args[0]))
|
||||
{
|
||||
for (Class c : validClasses)
|
||||
{
|
||||
if (c.getSimpleName().equalsIgnoreCase(args[0]))
|
||||
{
|
||||
entityClass = c;
|
||||
starting = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (starting == 0) {
|
||||
try {
|
||||
|
||||
if (starting == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
type = EntityType.valueOf(args[0].toUpperCase());
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
if (type == null) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args.length == starting + 1) {
|
||||
|
||||
if (args.length == starting + 1)
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius"
|
||||
+ (starting != 0 ? " and EntityType" : ""));
|
||||
return true;
|
||||
}
|
||||
if (!isNumeric(args[starting])) {
|
||||
|
||||
if (!isNumeric(args[starting]))
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + args[starting] + " is not a number");
|
||||
return true;
|
||||
}
|
||||
|
||||
int radius = Integer.parseInt(args[starting]);
|
||||
if (radius > maxRadius) {
|
||||
|
||||
if (radius > maxRadius)
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?");
|
||||
radius = maxRadius;
|
||||
}
|
||||
|
||||
String[] newArgs = new String[args.length - (starting + 1)];
|
||||
System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
|
||||
Disguise disguise;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
disguise = parseDisguise(sender, newArgs, map);
|
||||
} catch (DisguiseParseException ex) {
|
||||
if (ex.getMessage() != null) {
|
||||
}
|
||||
catch (DisguiseParseException ex)
|
||||
{
|
||||
if (ex.getMessage() != null)
|
||||
{
|
||||
sender.sendMessage(ex.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace(System.out);
|
||||
return true;
|
||||
} // Time to use it!
|
||||
}
|
||||
|
||||
// Time to use it!
|
||||
int disguisedEntitys = 0;
|
||||
int miscDisguises = 0;
|
||||
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
|
||||
if (entity == sender) {
|
||||
|
||||
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius))
|
||||
{
|
||||
if (entity == sender)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) {
|
||||
|
||||
if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass()))
|
||||
{
|
||||
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
|
||||
&& entity instanceof LivingEntity) {
|
||||
&& entity instanceof LivingEntity)
|
||||
{
|
||||
miscDisguises++;
|
||||
continue;
|
||||
}
|
||||
|
||||
disguise = disguise.clone();
|
||||
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
|
||||
if (disguise.getWatcher() instanceof LivingWatcher) {
|
||||
|
||||
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise())
|
||||
{
|
||||
if (disguise.getWatcher() instanceof LivingWatcher)
|
||||
{
|
||||
disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
|
||||
if (DisguiseConfig.isNameAboveHeadAlwaysVisible())
|
||||
{
|
||||
disguise.getWatcher().setCustomNameVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DisguiseAPI.disguiseToAll(entity, disguise);
|
||||
if (disguise.isDisguiseInUse()) {
|
||||
|
||||
if (disguise.isDisguiseInUse())
|
||||
{
|
||||
disguisedEntitys++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (disguisedEntitys > 0) {
|
||||
|
||||
if (disguisedEntitys > 0)
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Couldn't find any entities to disguise!");
|
||||
}
|
||||
if (miscDisguises > 0) {
|
||||
|
||||
if (miscDisguises > 0)
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Failed to disguise " + miscDisguises
|
||||
+ " entities because the option to disguise a living entity as a non-living has been disabled in the config");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -151,25 +221,34 @@ public class RadiusDisguiseCommand extends BaseDisguiseCommand {
|
||||
* Send the player the information
|
||||
*/
|
||||
@Override
|
||||
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
|
||||
protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map)
|
||||
{
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(map);
|
||||
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at 30 blocks!");
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
|
||||
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||
|
||||
String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")";
|
||||
if (allowedDisguises.contains("player")) {
|
||||
|
||||
if (allowedDisguises.contains("player"))
|
||||
{
|
||||
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>")
|
||||
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
|
||||
}
|
||||
|
||||
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby"
|
||||
+ optional + ">").replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
|
||||
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
|
||||
|
||||
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
|
||||
{
|
||||
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional
|
||||
+ "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">").replace("<",
|
||||
"<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
|
||||
+ "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">")
|
||||
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
|
||||
}
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN
|
||||
+ "/disguiseradius EntityTypes");
|
||||
|
||||
sender.sendMessage(
|
||||
ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes");
|
||||
}
|
||||
|
||||
}
|
@@ -1,7 +1,5 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -9,6 +7,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
|
||||
public class UndisguiseCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
@@ -1,11 +1,12 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
|
||||
public class UndisguiseEntityCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
@@ -1,7 +1,5 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -9,6 +7,8 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
|
||||
public class UndisguisePlayerCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
@@ -1,7 +1,5 @@
|
||||
package me.libraryaddict.disguise.commands;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -9,6 +7,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
|
||||
public class UndisguiseRadiusCommand implements CommandExecutor {
|
||||
|
||||
private int maxRadius = 30;
|
@@ -1,29 +1,35 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
public enum AnimalColor {
|
||||
|
||||
public enum AnimalColor
|
||||
{
|
||||
BLACK(15), BLUE(11), BROWN(12), CYAN(9), GRAY(7), GREEN(13), LIGHT_BLUE(3), LIME(5), MAGENTA(2), ORANGE(1), PINK(6), PURPLE(
|
||||
10), RED(14), SILVER(8), WHITE(0), YELLOW(4);
|
||||
|
||||
public static AnimalColor getColor(int nmsId) {
|
||||
for (AnimalColor color : values()) {
|
||||
if (color.getId() == nmsId) {
|
||||
public static AnimalColor getColor(int nmsId)
|
||||
{
|
||||
for (AnimalColor color : values())
|
||||
{
|
||||
if (color.getId() == nmsId)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
AnimalColor(int newValue) {
|
||||
AnimalColor(int newValue)
|
||||
{
|
||||
value = newValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* The color ID as defined by nms internals.
|
||||
*/
|
||||
public int getId() {
|
||||
public int getId()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
389
src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java
Normal file
389
src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java
Normal file
@@ -0,0 +1,389 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Guardian;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Skeleton;
|
||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||
import org.bukkit.entity.Zombie;
|
||||
|
||||
public enum DisguiseType
|
||||
{
|
||||
|
||||
AREA_EFFECT_CLOUD(3, 0),
|
||||
|
||||
ARMOR_STAND(78),
|
||||
|
||||
ARROW(60, 0),
|
||||
|
||||
BAT,
|
||||
|
||||
BLAZE,
|
||||
|
||||
BOAT(1),
|
||||
|
||||
CAVE_SPIDER,
|
||||
|
||||
CHICKEN,
|
||||
|
||||
COW,
|
||||
|
||||
CREEPER,
|
||||
|
||||
DONKEY,
|
||||
|
||||
DRAGON_FIREBALL(93),
|
||||
|
||||
DROPPED_ITEM(2, 1),
|
||||
|
||||
EGG(62),
|
||||
|
||||
ELDER_GUARDIAN,
|
||||
|
||||
ENDER_CRYSTAL(51),
|
||||
|
||||
ENDER_DRAGON,
|
||||
|
||||
ENDER_PEARL(65),
|
||||
|
||||
ENDER_SIGNAL(72),
|
||||
|
||||
ENDERMAN,
|
||||
|
||||
ENDERMITE,
|
||||
|
||||
EXPERIENCE_ORB,
|
||||
|
||||
FALLING_BLOCK(70, 1),
|
||||
|
||||
FIREBALL(63),
|
||||
|
||||
FIREWORK(76),
|
||||
|
||||
FISHING_HOOK(90),
|
||||
|
||||
GHAST,
|
||||
|
||||
GIANT,
|
||||
|
||||
GUARDIAN,
|
||||
|
||||
HORSE,
|
||||
|
||||
IRON_GOLEM,
|
||||
|
||||
ITEM_FRAME(71),
|
||||
|
||||
LEASH_HITCH(77),
|
||||
|
||||
MAGMA_CUBE,
|
||||
|
||||
MINECART(10),
|
||||
|
||||
MINECART_CHEST(10, 1),
|
||||
|
||||
MINECART_COMMAND(10, 6),
|
||||
|
||||
MINECART_FURNACE(10, 2),
|
||||
|
||||
MINECART_HOPPER(10, 5),
|
||||
|
||||
MINECART_MOB_SPAWNER(10, 4),
|
||||
|
||||
MINECART_TNT(10, 3),
|
||||
|
||||
MULE,
|
||||
|
||||
MUSHROOM_COW,
|
||||
|
||||
OCELOT,
|
||||
|
||||
PAINTING,
|
||||
|
||||
PIG,
|
||||
|
||||
PIG_ZOMBIE,
|
||||
|
||||
PLAYER,
|
||||
|
||||
PRIMED_TNT(50),
|
||||
|
||||
RABBIT,
|
||||
|
||||
SHEEP,
|
||||
|
||||
SHULKER,
|
||||
|
||||
SHULKER_BULLET(67),
|
||||
|
||||
SILVERFISH,
|
||||
|
||||
SKELETON,
|
||||
|
||||
SKELETON_HORSE,
|
||||
|
||||
SLIME,
|
||||
|
||||
SMALL_FIREBALL(63),
|
||||
|
||||
SNOWBALL(61),
|
||||
|
||||
SNOWMAN,
|
||||
|
||||
SPECTRAL_ARROW(91),
|
||||
|
||||
SPIDER,
|
||||
|
||||
SPLASH_POTION(73, 0),
|
||||
|
||||
SQUID,
|
||||
|
||||
TIPPED_ARROW(92),
|
||||
|
||||
THROWN_EXP_BOTTLE(75),
|
||||
|
||||
UNDEAD_HORSE,
|
||||
|
||||
VILLAGER,
|
||||
|
||||
WITCH,
|
||||
|
||||
WITHER,
|
||||
|
||||
WITHER_SKELETON,
|
||||
|
||||
WITHER_SKULL(66),
|
||||
|
||||
WOLF,
|
||||
|
||||
ZOMBIE,
|
||||
|
||||
ZOMBIE_VILLAGER,
|
||||
|
||||
UNKNOWN;
|
||||
|
||||
static
|
||||
{
|
||||
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC.
|
||||
// Without erroring up everything.
|
||||
|
||||
for (DisguiseType type : values())
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
DisguiseType toUse = type;
|
||||
String name;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
|
||||
// Usable.
|
||||
case ITEM_FRAME:
|
||||
break;
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case UNDEAD_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
toUse = DisguiseType.HORSE;
|
||||
break;
|
||||
case ZOMBIE_VILLAGER:
|
||||
toUse = DisguiseType.ZOMBIE;
|
||||
break;
|
||||
case WITHER_SKELETON:
|
||||
toUse = DisguiseType.SKELETON;
|
||||
break;
|
||||
case ELDER_GUARDIAN:
|
||||
toUse = DisguiseType.GUARDIAN;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
name = toUse.name();
|
||||
|
||||
type.setEntityType(EntityType.valueOf(name));
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
// This version of Spigot doesn't have the disguise.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DisguiseType getType(Entity entity)
|
||||
{
|
||||
DisguiseType disguiseType = getType(entity.getType());
|
||||
|
||||
switch (disguiseType)
|
||||
{
|
||||
case ZOMBIE:
|
||||
|
||||
if (((Zombie) entity).isVillager())
|
||||
{
|
||||
disguiseType = DisguiseType.ZOMBIE_VILLAGER;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HORSE:
|
||||
|
||||
disguiseType = DisguiseType.valueOf(((Horse) entity).getVariant().name());
|
||||
|
||||
break;
|
||||
|
||||
case SKELETON:
|
||||
|
||||
if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER)
|
||||
{
|
||||
disguiseType = DisguiseType.WITHER_SKELETON;
|
||||
}
|
||||
|
||||
break;
|
||||
case GUARDIAN:
|
||||
|
||||
if (((Guardian) entity).isElder())
|
||||
{
|
||||
disguiseType = DisguiseType.ELDER_GUARDIAN;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return disguiseType;
|
||||
|
||||
}
|
||||
|
||||
public static DisguiseType getType(EntityType entityType)
|
||||
{
|
||||
try
|
||||
{
|
||||
return valueOf(entityType.name().toUpperCase());
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
return DisguiseType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
private int objectId = -1, defaultData = 0;
|
||||
|
||||
private EntityType entityType;
|
||||
|
||||
private Class<? extends FlagWatcher> watcherClass;
|
||||
|
||||
DisguiseType(int... ints)
|
||||
{
|
||||
for (int i = 0; i < ints.length; i++)
|
||||
{
|
||||
int value = ints[i];
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
objectId = value;
|
||||
|
||||
break;
|
||||
case 1:
|
||||
defaultData = value;
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getDefaultData()
|
||||
{
|
||||
return defaultData;
|
||||
}
|
||||
|
||||
public Class<? extends Entity> getEntityClass()
|
||||
{
|
||||
if (entityType != null)
|
||||
{
|
||||
return getEntityType().getEntityClass();
|
||||
}
|
||||
|
||||
return Entity.class;
|
||||
}
|
||||
|
||||
public EntityType getEntityType()
|
||||
{
|
||||
return entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* The TYPE id of this entity. Different from the Object Id send in spawn packets when spawning miscs.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getTypeId()
|
||||
{
|
||||
return (int) getEntityType().getTypeId();
|
||||
}
|
||||
|
||||
/**
|
||||
* The object type send in packets when spawning a misc entity. Otherwise, -1.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getObjectId()
|
||||
{
|
||||
return objectId;
|
||||
}
|
||||
|
||||
public Class getWatcherClass()
|
||||
{
|
||||
return watcherClass;
|
||||
}
|
||||
|
||||
public boolean isMisc()
|
||||
{
|
||||
return getEntityType() != null && !getEntityType().isAlive();
|
||||
}
|
||||
|
||||
public boolean isMob()
|
||||
{
|
||||
return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
|
||||
}
|
||||
|
||||
public boolean isPlayer()
|
||||
{
|
||||
return this == DisguiseType.PLAYER;
|
||||
}
|
||||
|
||||
public boolean isUnknown()
|
||||
{
|
||||
return this == DisguiseType.UNKNOWN;
|
||||
}
|
||||
|
||||
private void setEntityType(EntityType entityType)
|
||||
{
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
public void setWatcherClass(Class<? extends FlagWatcher> c)
|
||||
{
|
||||
watcherClass = c;
|
||||
}
|
||||
|
||||
public String toReadable()
|
||||
{
|
||||
String[] split = name().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, " ");
|
||||
}
|
||||
}
|
@@ -1,29 +1,32 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class FlagWatcher {
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class FlagWatcher
|
||||
{
|
||||
|
||||
private boolean addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded();
|
||||
/**
|
||||
@@ -37,305 +40,445 @@ public class FlagWatcher {
|
||||
private HashSet<Integer> modifiedEntityAnimations = new HashSet<>();
|
||||
private List<WrappedWatchableObject> watchableObjects;
|
||||
|
||||
public FlagWatcher(Disguise disguise) {
|
||||
public FlagWatcher(Disguise disguise)
|
||||
{
|
||||
this.disguise = (TargetedDisguise) disguise;
|
||||
equipment = ReflectionManager.createEntityEquipment(disguise.getEntity());
|
||||
}
|
||||
|
||||
private byte addEntityAnimations(byte originalValue, byte entityValue) {
|
||||
private byte addEntityAnimations(byte originalValue, byte entityValue)
|
||||
{
|
||||
byte valueByte = originalValue;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations.contains(i)) {
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations.contains(i))
|
||||
{
|
||||
valueByte = (byte) (valueByte | 1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
originalValue = valueByte;
|
||||
|
||||
return originalValue;
|
||||
}
|
||||
|
||||
public FlagWatcher clone(Disguise owningDisguise) {
|
||||
public FlagWatcher clone(Disguise owningDisguise)
|
||||
{
|
||||
FlagWatcher cloned;
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
cloned = getClass().getConstructor(Disguise.class).newInstance(getDisguise());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.out);
|
||||
cloned = new FlagWatcher(getDisguise());
|
||||
}
|
||||
|
||||
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
|
||||
cloned.equipment = ReflectionManager.createEntityEquipment(cloned.getDisguise().getEntity());
|
||||
cloned.modifiedEntityAnimations = (HashSet<Integer>) modifiedEntityAnimations.clone();
|
||||
cloned.addEntityAnimations = addEntityAnimations;
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) {
|
||||
public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list)
|
||||
{
|
||||
List<WrappedWatchableObject> newList = new ArrayList<>();
|
||||
HashSet<Integer> sentValues = new HashSet<>();
|
||||
boolean sendAllCustom = false;
|
||||
for (WrappedWatchableObject watch : list) {
|
||||
|
||||
for (WrappedWatchableObject watch : list)
|
||||
{
|
||||
int id = watch.getIndex();
|
||||
sentValues.add(id);
|
||||
|
||||
// Its sending the air metadata. This is the least commonly sent metadata which all entitys still share.
|
||||
// I send my custom values if I see this!
|
||||
if (id == 1) {
|
||||
if (id == 1)
|
||||
{
|
||||
sendAllCustom = true;
|
||||
}
|
||||
|
||||
Object value = null;
|
||||
if (entityValues.containsKey(id)) {
|
||||
if (entityValues.get(id) == null) {
|
||||
|
||||
if (entityValues.containsKey(id))
|
||||
{
|
||||
if (entityValues.get(id) == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
value = entityValues.get(id);
|
||||
} else if (backupEntityValues.containsKey(id)) {
|
||||
if (backupEntityValues.get(id) == null) {
|
||||
}
|
||||
else if (backupEntityValues.containsKey(id))
|
||||
{
|
||||
if (backupEntityValues.get(id) == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
value = backupEntityValues.get(id);
|
||||
}
|
||||
if (value != null) {
|
||||
if (isEntityAnimationsAdded() && id == 0) {
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
if (isEntityAnimationsAdded() && id == 0)
|
||||
{
|
||||
value = this.addEntityAnimations((byte) value, (byte) watch.getValue());
|
||||
}
|
||||
|
||||
boolean isDirty = watch.getDirtyState();
|
||||
|
||||
watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
|
||||
if (!isDirty) {
|
||||
watch.setDirtyState(false);
|
||||
}
|
||||
} else {
|
||||
boolean isDirty = watch.getDirtyState();
|
||||
watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, watch.getValue()));
|
||||
if (!isDirty) {
|
||||
|
||||
if (!isDirty)
|
||||
{
|
||||
watch.setDirtyState(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean isDirty = watch.getDirtyState();
|
||||
|
||||
watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, watch.getValue()));
|
||||
|
||||
if (!isDirty)
|
||||
{
|
||||
watch.setDirtyState(false);
|
||||
}
|
||||
}
|
||||
|
||||
newList.add(watch);
|
||||
}
|
||||
if (sendAllCustom) {
|
||||
|
||||
if (sendAllCustom)
|
||||
{
|
||||
// Its sending the entire meta data. Better add the custom meta
|
||||
for (int id : entityValues.keySet()) {
|
||||
if (sentValues.contains(id)) {
|
||||
for (int id : entityValues.keySet())
|
||||
{
|
||||
if (sentValues.contains(id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Object value = entityValues.get(id);
|
||||
if (value == null) {
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
|
||||
|
||||
newList.add(watch);
|
||||
}
|
||||
}
|
||||
// Here we check for if there is a health packet that says they died.
|
||||
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) {
|
||||
for (WrappedWatchableObject watch : newList) {
|
||||
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null
|
||||
&& getDisguise().getEntity() instanceof Player)
|
||||
{
|
||||
for (WrappedWatchableObject watch : newList)
|
||||
{
|
||||
// Its a health packet
|
||||
if (watch.getIndex() == 6) {
|
||||
if (watch.getIndex() == 6)
|
||||
{
|
||||
Object value = watch.getValue();
|
||||
if (value != null && value instanceof Float) {
|
||||
|
||||
if (value != null && value instanceof Float)
|
||||
{
|
||||
float newHealth = (Float) value;
|
||||
if (newHealth > 0 && hasDied) {
|
||||
|
||||
if (newHealth > 0 && hasDied)
|
||||
{
|
||||
hasDied = false;
|
||||
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), disguise);
|
||||
} else if (newHealth <= 0 && !hasDied) {
|
||||
}
|
||||
else if (newHealth <= 0 && !hasDied)
|
||||
{
|
||||
hasDied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
public ItemStack[] getArmor() {
|
||||
public ItemStack[] getArmor()
|
||||
{
|
||||
ItemStack[] armor = new ItemStack[4];
|
||||
System.arraycopy(armor, 0, armor, 0, 4);
|
||||
|
||||
return armor;
|
||||
}
|
||||
|
||||
public String getCustomName() {
|
||||
public String getCustomName()
|
||||
{
|
||||
return (String) getValue(2, null);
|
||||
}
|
||||
|
||||
protected TargetedDisguise getDisguise() {
|
||||
protected TargetedDisguise getDisguise()
|
||||
{
|
||||
return disguise;
|
||||
}
|
||||
|
||||
private boolean getEntityFlag(int byteValue) {
|
||||
private boolean getEntityFlag(int byteValue)
|
||||
{
|
||||
return ((byte) getValue(0, (byte) 0) & 1 << byteValue) != 0;
|
||||
}
|
||||
|
||||
public ItemStack getItemInMainHand() {
|
||||
if (equipment == null) return null;
|
||||
public ItemStack getItemInMainHand()
|
||||
{
|
||||
if (equipment == null)
|
||||
return null;
|
||||
|
||||
return equipment.getItemInMainHand();
|
||||
}
|
||||
|
||||
public ItemStack getItemInOffHand() {
|
||||
if (equipment == null) return null;
|
||||
public ItemStack getItemInOffHand()
|
||||
{
|
||||
if (equipment == null)
|
||||
return null;
|
||||
|
||||
return equipment.getItemInOffHand();
|
||||
}
|
||||
|
||||
public EntityEquipment getEquipment() {
|
||||
public EntityEquipment getEquipment()
|
||||
{
|
||||
return equipment;
|
||||
}
|
||||
|
||||
protected Object getValue(int no, Object backup) {
|
||||
if (entityValues.containsKey(no)) {
|
||||
return entityValues.get(no);
|
||||
protected <Y> Y getValue(int no, Y backup)
|
||||
{
|
||||
if (entityValues.containsKey(no))
|
||||
{
|
||||
return (Y) entityValues.get(no);
|
||||
}
|
||||
|
||||
return backup;
|
||||
}
|
||||
|
||||
public List<WrappedWatchableObject> getWatchableObjects() {
|
||||
if (watchableObjects == null) {
|
||||
public List<WrappedWatchableObject> getWatchableObjects()
|
||||
{
|
||||
if (watchableObjects == null)
|
||||
{
|
||||
rebuildWatchableObjects();
|
||||
}
|
||||
|
||||
return watchableObjects;
|
||||
}
|
||||
|
||||
public boolean hasCustomName() {
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return getCustomName() != null;
|
||||
}
|
||||
|
||||
protected boolean hasValue(int no) {
|
||||
protected boolean hasValue(int no)
|
||||
{
|
||||
return entityValues.containsKey(no);
|
||||
}
|
||||
|
||||
public boolean isCustomNameVisible() {
|
||||
public boolean isCustomNameVisible()
|
||||
{
|
||||
return (boolean) getValue(3, false);
|
||||
}
|
||||
|
||||
public boolean isEntityAnimationsAdded() {
|
||||
public boolean isEntityAnimationsAdded()
|
||||
{
|
||||
return addEntityAnimations;
|
||||
}
|
||||
|
||||
public boolean isBurning() {
|
||||
public boolean isBurning()
|
||||
{
|
||||
return getEntityFlag(0);
|
||||
}
|
||||
|
||||
public boolean isSneaking() {
|
||||
public boolean isSneaking()
|
||||
{
|
||||
return getEntityFlag(1);
|
||||
}
|
||||
|
||||
public boolean isSprinting() {
|
||||
public boolean isSprinting()
|
||||
{
|
||||
return getEntityFlag(3);
|
||||
}
|
||||
|
||||
public boolean isRightClicking() {
|
||||
public boolean isRightClicking()
|
||||
{
|
||||
return getEntityFlag(4);
|
||||
}
|
||||
|
||||
public boolean isInvisible() {
|
||||
public boolean isInvisible()
|
||||
{
|
||||
return getEntityFlag(5);
|
||||
}
|
||||
|
||||
public boolean isGlowing() {
|
||||
public boolean isGlowing()
|
||||
{
|
||||
return getEntityFlag(6);
|
||||
}
|
||||
|
||||
public boolean isFlyingWithElytra() {
|
||||
public boolean isFlyingWithElytra()
|
||||
{
|
||||
return getEntityFlag(7);
|
||||
}
|
||||
|
||||
public void rebuildWatchableObjects() {
|
||||
public void rebuildWatchableObjects()
|
||||
{
|
||||
watchableObjects = new ArrayList<>();
|
||||
for (int i = 0; i <= 31; i++) {
|
||||
|
||||
for (int i = 0; i <= 31; i++)
|
||||
{
|
||||
WrappedWatchableObject watchable = null;
|
||||
if (this.entityValues.containsKey(i) && this.entityValues.get(i) != null) {
|
||||
watchable = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(i, entityValues.get(i)));
|
||||
} else if (this.backupEntityValues.containsKey(i) && this.backupEntityValues.get(i) != null) {
|
||||
|
||||
if (this.entityValues.containsKey(i) && this.entityValues.get(i) != null)
|
||||
{
|
||||
watchable = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(i, entityValues.get(i)));
|
||||
}
|
||||
if (watchable != null) {
|
||||
else if (this.backupEntityValues.containsKey(i) && this.backupEntityValues.get(i) != null)
|
||||
{
|
||||
watchable = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(i, entityValues.get(i)));
|
||||
}
|
||||
|
||||
if (watchable != null)
|
||||
{
|
||||
watchableObjects.add(watchable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendData(int... dataValues) {
|
||||
if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) {
|
||||
protected void sendData(int... dataValues)
|
||||
{
|
||||
if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||
for (int data : dataValues) {
|
||||
if (!entityValues.containsKey(data) || entityValues.get(data) == null) {
|
||||
|
||||
for (int data : dataValues)
|
||||
{
|
||||
if (!entityValues.containsKey(data) || entityValues.get(data) == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Object value = entityValues.get(data);
|
||||
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) {
|
||||
|
||||
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0)
|
||||
{
|
||||
if (!PacketsManager.isStaticMetadataDisguiseType(disguise))
|
||||
value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
|
||||
{
|
||||
value = addEntityAnimations((byte) value,
|
||||
WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
|
||||
}
|
||||
}
|
||||
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(data, value));
|
||||
|
||||
list.add(watch);
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, getDisguise().getEntity().getEntityId());
|
||||
|
||||
packet.getWatchableCollectionModifier().write(0, list);
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
try {
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
|
||||
{
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
|
||||
public void setAddEntityAnimations(boolean isEntityAnimationsAdded)
|
||||
{
|
||||
this.addEntityAnimations = isEntityAnimationsAdded;
|
||||
}
|
||||
|
||||
public void setArmor(ItemStack[] itemstack) {
|
||||
public void setArmor(ItemStack[] itemstack)
|
||||
{
|
||||
setItemStack(EquipmentSlot.HEAD, itemstack[0]);
|
||||
setItemStack(EquipmentSlot.CHEST, itemstack[1]);
|
||||
setItemStack(EquipmentSlot.LEGS, itemstack[2]);
|
||||
setItemStack(EquipmentSlot.FEET, itemstack[3]);
|
||||
}
|
||||
|
||||
protected void setBackupValue(int no, Object value) {
|
||||
protected void setBackupValue(int no, Object value)
|
||||
{
|
||||
backupEntityValues.put(no, value);
|
||||
}
|
||||
|
||||
public void setBurning(boolean setBurning) {
|
||||
public void setBurning(boolean setBurning)
|
||||
{
|
||||
setEntityFlag(0, setBurning);
|
||||
|
||||
sendData(0);
|
||||
}
|
||||
|
||||
public void setCustomName(String name) {
|
||||
if (name != null && name.length() > 64) {
|
||||
public void setCustomName(String name)
|
||||
{
|
||||
if (name != null && name.length() > 64)
|
||||
{
|
||||
name = name.substring(0, 64);
|
||||
}
|
||||
|
||||
setValue(2, name);
|
||||
sendData(2);
|
||||
}
|
||||
|
||||
public void setCustomNameVisible(boolean display) {
|
||||
public void setCustomNameVisible(boolean display)
|
||||
{
|
||||
setValue(3, display);
|
||||
sendData(3);
|
||||
}
|
||||
|
||||
private void setEntityFlag(int byteValue, boolean flag) {
|
||||
private void setEntityFlag(int byteValue, boolean flag)
|
||||
{
|
||||
modifiedEntityAnimations.add(byteValue);
|
||||
|
||||
byte b0 = (byte) getValue(0, (byte) 0);
|
||||
if (flag) {
|
||||
|
||||
if (flag)
|
||||
{
|
||||
setValue(0, (byte) (b0 | 1 << byteValue));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue(0, (byte) (b0 & ~(1 << byteValue)));
|
||||
}
|
||||
}
|
||||
|
||||
public void setInvisible(boolean setInvis) {
|
||||
public void setInvisible(boolean setInvis)
|
||||
{
|
||||
setEntityFlag(5, setInvis);
|
||||
sendData(0);
|
||||
}
|
||||
|
||||
public void setGlowing(boolean glowing) {
|
||||
public void setGlowing(boolean glowing)
|
||||
{
|
||||
setEntityFlag(6, glowing);
|
||||
sendData(0);
|
||||
}
|
||||
|
||||
public void setFlyingWithElytra(boolean flying) {
|
||||
public void setFlyingWithElytra(boolean flying)
|
||||
{
|
||||
setEntityFlag(7, flying);
|
||||
sendData(0);
|
||||
}
|
||||
@@ -346,110 +489,146 @@ public class FlagWatcher {
|
||||
* @param itemstack
|
||||
*/
|
||||
@Deprecated
|
||||
public void setItemInHand(ItemStack itemstack) {
|
||||
public void setItemInHand(ItemStack itemstack)
|
||||
{
|
||||
setItemInMainHand(itemstack);
|
||||
}
|
||||
|
||||
public void setItemInMainHand(ItemStack itemstack) {
|
||||
public void setItemInMainHand(ItemStack itemstack)
|
||||
{
|
||||
setItemStack(EquipmentSlot.HAND, itemstack);
|
||||
}
|
||||
|
||||
public void setItemInOffHand(ItemStack itemstack) {
|
||||
public void setItemInOffHand(ItemStack itemstack)
|
||||
{
|
||||
setItemStack(EquipmentSlot.OFF_HAND, itemstack);
|
||||
}
|
||||
|
||||
public void setItemStack(EquipmentSlot slot, ItemStack itemStack) {
|
||||
if (equipment == null) return;
|
||||
public void setItemStack(EquipmentSlot slot, ItemStack itemStack)
|
||||
{
|
||||
if (equipment == null)
|
||||
return;
|
||||
|
||||
// Itemstack which is null means that its not replacing the disguises itemstack.
|
||||
if (itemStack == null) {
|
||||
if (itemStack == null)
|
||||
{
|
||||
// Find the item to replace it with
|
||||
if (getDisguise().getEntity() instanceof LivingEntity) {
|
||||
if (getDisguise().getEntity() instanceof LivingEntity)
|
||||
{
|
||||
EntityEquipment equipment = ((LivingEntity) getDisguise().getEntity()).getEquipment();
|
||||
setItemStack(equipment, slot, itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
Object itemToSend = null;
|
||||
if (itemStack != null && itemStack.getTypeId() != 0) {
|
||||
|
||||
if (itemStack != null && itemStack.getTypeId() != 0)
|
||||
{
|
||||
itemToSend = ReflectionManager.getNmsItem(itemStack);
|
||||
}
|
||||
|
||||
setItemStack(equipment, slot, itemStack);
|
||||
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
|
||||
|
||||
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this)
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.ENTITY_EQUIPMENT);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
|
||||
mods.write(0, getDisguise().getEntity().getEntityId());
|
||||
mods.write(1, ReflectionManager.createEnumItemSlot(slot));
|
||||
mods.write(2, itemToSend);
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
try {
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
|
||||
{
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setItemStack(EntityEquipment equipment, EquipmentSlot slot, ItemStack itemStack) {
|
||||
if (equipment == null) return;
|
||||
switch (slot) {
|
||||
case CHEST:
|
||||
equipment.setChestplate(itemStack);
|
||||
break;
|
||||
case FEET:
|
||||
equipment.setBoots(itemStack);
|
||||
break;
|
||||
case HAND:
|
||||
equipment.setItemInMainHand(itemStack);
|
||||
break;
|
||||
case HEAD:
|
||||
equipment.setHelmet(itemStack);
|
||||
break;
|
||||
case LEGS:
|
||||
equipment.setLeggings(itemStack);
|
||||
break;
|
||||
case OFF_HAND:
|
||||
equipment.setItemInOffHand(itemStack);
|
||||
break;
|
||||
private void setItemStack(EntityEquipment equipment, EquipmentSlot slot, ItemStack itemStack)
|
||||
{
|
||||
if (equipment == null)
|
||||
return;
|
||||
|
||||
switch (slot)
|
||||
{
|
||||
case CHEST:
|
||||
equipment.setChestplate(itemStack);
|
||||
break;
|
||||
case FEET:
|
||||
equipment.setBoots(itemStack);
|
||||
break;
|
||||
case HAND:
|
||||
equipment.setItemInMainHand(itemStack);
|
||||
break;
|
||||
case HEAD:
|
||||
equipment.setHelmet(itemStack);
|
||||
break;
|
||||
case LEGS:
|
||||
equipment.setLeggings(itemStack);
|
||||
break;
|
||||
case OFF_HAND:
|
||||
equipment.setItemInOffHand(itemStack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(EquipmentSlot slot) {
|
||||
if (equipment == null) return null;
|
||||
switch (slot) {
|
||||
case CHEST:
|
||||
return equipment.getChestplate();
|
||||
case FEET:
|
||||
return equipment.getBoots();
|
||||
case HAND:
|
||||
return equipment.getItemInMainHand();
|
||||
case HEAD:
|
||||
return equipment.getHelmet();
|
||||
case LEGS:
|
||||
return equipment.getLeggings();
|
||||
case OFF_HAND:
|
||||
return equipment.getItemInOffHand();
|
||||
public ItemStack getItemStack(EquipmentSlot slot)
|
||||
{
|
||||
if (equipment == null)
|
||||
return null;
|
||||
|
||||
switch (slot)
|
||||
{
|
||||
case CHEST:
|
||||
return equipment.getChestplate();
|
||||
case FEET:
|
||||
return equipment.getBoots();
|
||||
case HAND:
|
||||
return equipment.getItemInMainHand();
|
||||
case HEAD:
|
||||
return equipment.getHelmet();
|
||||
case LEGS:
|
||||
return equipment.getLeggings();
|
||||
case OFF_HAND:
|
||||
return equipment.getItemInOffHand();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setRightClicking(boolean setRightClicking) {
|
||||
public void setRightClicking(boolean setRightClicking)
|
||||
{
|
||||
setEntityFlag(4, setRightClicking);
|
||||
sendData(0);
|
||||
}
|
||||
|
||||
public void setSneaking(boolean setSneaking) {
|
||||
public void setSneaking(boolean setSneaking)
|
||||
{
|
||||
setEntityFlag(1, setSneaking);
|
||||
sendData(0);
|
||||
}
|
||||
|
||||
public void setSprinting(boolean setSprinting) {
|
||||
public void setSprinting(boolean setSprinting)
|
||||
{
|
||||
setEntityFlag(3, setSprinting);
|
||||
sendData(0);
|
||||
}
|
||||
|
||||
protected void setValue(int id, Object value) {
|
||||
protected void setValue(int id, Object value)
|
||||
{
|
||||
entityValues.put(id, value);
|
||||
if (!DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
|
||||
if (!DisguiseConfig.isMetadataPacketsEnabled())
|
||||
{
|
||||
this.rebuildWatchableObjects();
|
||||
}
|
||||
}
|
@@ -1,15 +1,16 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
|
||||
|
||||
public class MiscDisguise extends TargetedDisguise {
|
||||
|
@@ -2,14 +2,14 @@ package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
|
||||
public class MobDisguise extends TargetedDisguise {
|
||||
|
||||
private boolean isAdult;
|
@@ -1,14 +1,16 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsProfileLookup;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerDisguise extends TargetedDisguise {
|
||||
|
@@ -1,25 +1,32 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
public enum RabbitType {
|
||||
public enum RabbitType
|
||||
{
|
||||
|
||||
BLACK(2), BROWN(0), GOLD(4), KILLER_BUNNY(99), PATCHES(3), PEPPER(5), WHITE(1);
|
||||
|
||||
public static RabbitType getType(int id) {
|
||||
for (RabbitType type : values()) {
|
||||
if (type.getTypeId() == id) {
|
||||
public static RabbitType getType(int id)
|
||||
{
|
||||
for (RabbitType type : values())
|
||||
{
|
||||
if (type.getTypeId() == id)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int type;
|
||||
|
||||
RabbitType(int type) {
|
||||
RabbitType(int type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
public int getTypeId()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
@@ -1,93 +1,127 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TargetedDisguise extends Disguise {
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public enum TargetType {
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
|
||||
public abstract class TargetedDisguise extends Disguise
|
||||
{
|
||||
|
||||
public enum TargetType
|
||||
{
|
||||
HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS, SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
|
||||
}
|
||||
|
||||
private List<String> disguiseViewers = new ArrayList<>();
|
||||
private TargetType targetType = TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS;
|
||||
|
||||
public TargetedDisguise addPlayer(Player player) {
|
||||
public TargetedDisguise addPlayer(Player player)
|
||||
{
|
||||
addPlayer(player.getName());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetedDisguise addPlayer(String playername) {
|
||||
if (!disguiseViewers.contains(playername)) {
|
||||
public TargetedDisguise addPlayer(String playername)
|
||||
{
|
||||
if (!disguiseViewers.contains(playername))
|
||||
{
|
||||
disguiseViewers.add(playername);
|
||||
if (DisguiseAPI.isDisguiseInUse(this)) {
|
||||
|
||||
if (DisguiseAPI.isDisguiseInUse(this))
|
||||
{
|
||||
DisguiseUtilities.checkConflicts(this, playername);
|
||||
DisguiseUtilities.refreshTracker(this, playername);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean canSee(Player player) {
|
||||
public boolean canSee(Player player)
|
||||
{
|
||||
return canSee(player.getName());
|
||||
}
|
||||
|
||||
public boolean canSee(String playername) {
|
||||
public boolean canSee(String playername)
|
||||
{
|
||||
boolean hasPlayer = disguiseViewers.contains(playername);
|
||||
if (targetType == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
||||
|
||||
if (targetType == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS)
|
||||
{
|
||||
return !hasPlayer;
|
||||
}
|
||||
|
||||
return hasPlayer;
|
||||
}
|
||||
|
||||
public TargetType getDisguiseTarget() {
|
||||
public TargetType getDisguiseTarget()
|
||||
{
|
||||
return targetType;
|
||||
}
|
||||
|
||||
public List<String> getObservers() {
|
||||
public List<String> getObservers()
|
||||
{
|
||||
return Collections.unmodifiableList(disguiseViewers);
|
||||
}
|
||||
|
||||
public TargetedDisguise removePlayer(Player player) {
|
||||
public TargetedDisguise removePlayer(Player player)
|
||||
{
|
||||
removePlayer(player.getName());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetedDisguise removePlayer(String playername) {
|
||||
if (disguiseViewers.contains(playername)) {
|
||||
public TargetedDisguise removePlayer(String playername)
|
||||
{
|
||||
if (disguiseViewers.contains(playername))
|
||||
{
|
||||
disguiseViewers.remove(playername);
|
||||
if (DisguiseAPI.isDisguiseInUse(this)) {
|
||||
|
||||
if (DisguiseAPI.isDisguiseInUse(this))
|
||||
{
|
||||
DisguiseUtilities.checkConflicts(this, playername);
|
||||
DisguiseUtilities.refreshTracker(this, playername);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetedDisguise setDisguiseTarget(TargetType newTargetType) {
|
||||
if (DisguiseUtilities.isDisguiseInUse(this)) {
|
||||
public TargetedDisguise setDisguiseTarget(TargetType newTargetType)
|
||||
{
|
||||
if (DisguiseUtilities.isDisguiseInUse(this))
|
||||
{
|
||||
throw new RuntimeException("Cannot set the disguise target after the entity has been disguised");
|
||||
}
|
||||
|
||||
targetType = newTargetType;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetedDisguise silentlyAddPlayer(String playername) {
|
||||
if (!disguiseViewers.contains(playername)) {
|
||||
public TargetedDisguise silentlyAddPlayer(String playername)
|
||||
{
|
||||
if (!disguiseViewers.contains(playername))
|
||||
{
|
||||
disguiseViewers.add(playername);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetedDisguise silentlyRemovePlayer(String playername) {
|
||||
if (disguiseViewers.contains(playername)) {
|
||||
public TargetedDisguise silentlyRemovePlayer(String playername)
|
||||
{
|
||||
if (disguiseViewers.contains(playername))
|
||||
{
|
||||
disguiseViewers.remove(playername);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class AgeableWatcher extends LivingWatcher {
|
||||
|
||||
public AgeableWatcher(Disguise disguise) {
|
@@ -1,10 +1,10 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
@@ -2,68 +2,85 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class ArmorStandWatcher extends LivingWatcher {
|
||||
public class ArmorStandWatcher extends LivingWatcher
|
||||
{
|
||||
|
||||
public ArmorStandWatcher(Disguise disguise) {
|
||||
public ArmorStandWatcher(Disguise disguise)
|
||||
{
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
private boolean getArmorStandFlag(int value) {
|
||||
return ((byte) getValue(10, 0) & value) != 0;
|
||||
private boolean getArmorStandFlag(int value)
|
||||
{
|
||||
return (getValue(10, 0) & value) != 0;
|
||||
}
|
||||
|
||||
public boolean isNoBasePlate() {
|
||||
public boolean isNoBasePlate()
|
||||
{
|
||||
return getArmorStandFlag(8);
|
||||
}
|
||||
|
||||
public boolean isNoGravity() {
|
||||
public boolean isNoGravity()
|
||||
{
|
||||
return getArmorStandFlag(2);
|
||||
}
|
||||
|
||||
public boolean isShowArms() {
|
||||
public boolean isShowArms()
|
||||
{
|
||||
return getArmorStandFlag(4);
|
||||
}
|
||||
|
||||
public boolean isSmall() {
|
||||
public boolean isSmall()
|
||||
{
|
||||
return getArmorStandFlag(1);
|
||||
}
|
||||
|
||||
public boolean isMarker() {
|
||||
public boolean isMarker()
|
||||
{
|
||||
return getArmorStandFlag(10);
|
||||
}
|
||||
|
||||
private void setArmorStandFlag(int value, boolean isTrue) {
|
||||
private void setArmorStandFlag(int value, boolean isTrue)
|
||||
{
|
||||
byte b1 = (byte) getValue(10, (byte) 0);
|
||||
if (isTrue) {
|
||||
if (isTrue)
|
||||
{
|
||||
b1 = (byte) (b1 | value);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
b1 = (byte) (b1 & value);
|
||||
}
|
||||
setValue(10, b1);
|
||||
sendData(10);
|
||||
}
|
||||
|
||||
public void setNoBasePlate(boolean noBasePlate) {
|
||||
public void setNoBasePlate(boolean noBasePlate)
|
||||
{
|
||||
setArmorStandFlag(8, noBasePlate);
|
||||
sendData(10);
|
||||
}
|
||||
|
||||
public void setNoGravity(boolean noGravity) {
|
||||
public void setNoGravity(boolean noGravity)
|
||||
{
|
||||
setArmorStandFlag(2, noGravity);
|
||||
sendData(10);
|
||||
}
|
||||
|
||||
public void setShowArms(boolean showArms) {
|
||||
public void setShowArms(boolean showArms)
|
||||
{
|
||||
setArmorStandFlag(4, showArms);
|
||||
sendData(10);
|
||||
}
|
||||
|
||||
public void setSmall(boolean isSmall) {
|
||||
public void setSmall(boolean isSmall)
|
||||
{
|
||||
setArmorStandFlag(1, isSmall);
|
||||
sendData(10);
|
||||
}
|
||||
|
||||
public void setMarker(boolean isMarker) {
|
||||
public void setMarker(boolean isMarker)
|
||||
{
|
||||
setArmorStandFlag(10, isMarker);
|
||||
sendData(10);
|
||||
}
|
@@ -2,17 +2,20 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class BlazeWatcher extends LivingWatcher {
|
||||
|
||||
public BlazeWatcher(Disguise disguise) {
|
||||
public class BlazeWatcher extends LivingWatcher
|
||||
{
|
||||
public BlazeWatcher(Disguise disguise)
|
||||
{
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public boolean isBlazing() {
|
||||
public boolean isBlazing()
|
||||
{
|
||||
return (boolean) getValue(11, false);
|
||||
}
|
||||
|
||||
public void setBlazing(boolean isBlazing) {
|
||||
public void setBlazing(boolean isBlazing)
|
||||
{
|
||||
setValue(11, isBlazing);
|
||||
sendData(11);
|
||||
}
|
@@ -3,22 +3,25 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
|
||||
public class BoatWatcher extends FlagWatcher {
|
||||
public class BoatWatcher extends FlagWatcher
|
||||
{
|
||||
|
||||
//TODO: Add stuff for new boat values
|
||||
// TODO: Add stuff for new boat values
|
||||
|
||||
public BoatWatcher(Disguise disguise) {
|
||||
public BoatWatcher(Disguise disguise)
|
||||
{
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return (int) getValue(7, 40F);
|
||||
public float getDamage()
|
||||
{
|
||||
return getValue(7, 40F);
|
||||
}
|
||||
|
||||
public void setDamage(float dmg) {
|
||||
public void setDamage(float dmg)
|
||||
{
|
||||
setValue(7, dmg);
|
||||
sendData(7);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
//TODO: Add support for custom items instead of just stone
|
||||
public class DroppedItemWatcher extends FlagWatcher {
|
@@ -2,35 +2,40 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
||||
public class EnderCrystalWatcher extends FlagWatcher {
|
||||
|
||||
public EnderCrystalWatcher(Disguise disguise) {
|
||||
public class EnderCrystalWatcher extends FlagWatcher
|
||||
{
|
||||
public EnderCrystalWatcher(Disguise disguise)
|
||||
{
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public void setBeamTarget(BlockPosition position) {
|
||||
public void setBeamTarget(BlockPosition position)
|
||||
{
|
||||
setValue(5, Optional.of(position));
|
||||
sendData(5);
|
||||
}
|
||||
|
||||
public Optional<BlockPosition> getBeamTarget() {
|
||||
public Optional<BlockPosition> getBeamTarget()
|
||||
{
|
||||
return (Optional) getValue(5, Optional.absent());
|
||||
}
|
||||
|
||||
public void setShowBottom(boolean bool) {
|
||||
public void setShowBottom(boolean bool)
|
||||
{
|
||||
setValue(6, bool);
|
||||
sendData(6);
|
||||
}
|
||||
|
||||
public boolean isShowBottom() {
|
||||
public boolean isShowBottom()
|
||||
{
|
||||
return (boolean) getValue(6, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,11 +1,13 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class EndermanWatcher extends LivingWatcher {
|
||||
|
||||
public EndermanWatcher(Disguise disguise) {
|
@@ -1,11 +1,12 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class FallingBlockWatcher extends FlagWatcher {
|
||||
|
@@ -1,9 +1,10 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class GuardianWatcher extends LivingWatcher {
|
||||
|
||||
public GuardianWatcher(Disguise disguise) {
|
@@ -1,177 +1,222 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Horse.Color;
|
||||
import org.bukkit.entity.Horse.Style;
|
||||
import org.bukkit.entity.Horse.Variant;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
public class HorseWatcher extends AgeableWatcher {
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
|
||||
public HorseWatcher(Disguise disguise) {
|
||||
public class HorseWatcher extends AgeableWatcher
|
||||
{
|
||||
|
||||
public HorseWatcher(Disguise disguise)
|
||||
{
|
||||
super(disguise);
|
||||
setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]);
|
||||
setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]);
|
||||
}
|
||||
|
||||
public Variant getVariant() {
|
||||
public Variant getVariant()
|
||||
{
|
||||
return Variant.values()[(int) getValue(13, 0)];
|
||||
}
|
||||
|
||||
public void setVariant(Variant variant) {
|
||||
public void setVariant(Variant variant)
|
||||
{
|
||||
setVariant(variant.ordinal());
|
||||
}
|
||||
|
||||
public void setVariant(int variant) {
|
||||
if (variant < 0 || variant > 4) {
|
||||
variant = 0; //Crashing people is mean
|
||||
public void setVariant(int variant)
|
||||
{
|
||||
if (variant < 0 || variant > 4)
|
||||
{
|
||||
variant = 0; // Crashing people is mean
|
||||
}
|
||||
setValue(13, variant);
|
||||
sendData(13);
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
public Color getColor()
|
||||
{
|
||||
return Color.values()[((Integer) getValue(14, 0) & 0xFF)];
|
||||
}
|
||||
|
||||
public ItemStack getHorseArmor() {
|
||||
public ItemStack getHorseArmor()
|
||||
{
|
||||
int horseValue = getHorseArmorAsInt();
|
||||
switch (horseValue) {
|
||||
case 1:
|
||||
return new ItemStack(Material.getMaterial("IRON_BARDING"));
|
||||
case 2:
|
||||
return new ItemStack(Material.getMaterial("GOLD_BARDING"));
|
||||
case 3:
|
||||
return new ItemStack(Material.getMaterial("DIAMOND_BARDING"));
|
||||
default:
|
||||
break;
|
||||
switch (horseValue)
|
||||
{
|
||||
case 1:
|
||||
return new ItemStack(Material.getMaterial("IRON_BARDING"));
|
||||
case 2:
|
||||
return new ItemStack(Material.getMaterial("GOLD_BARDING"));
|
||||
case 3:
|
||||
return new ItemStack(Material.getMaterial("DIAMOND_BARDING"));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int getHorseArmorAsInt() {
|
||||
protected int getHorseArmorAsInt()
|
||||
{
|
||||
return (int) getValue(16, 0);
|
||||
}
|
||||
|
||||
public Optional<UUID> getOwner() {
|
||||
return (Optional<UUID>) getValue(15, Optional.absent());
|
||||
public Optional<UUID> getOwner()
|
||||
{
|
||||
return getValue(15, Optional.<UUID> absent());
|
||||
}
|
||||
|
||||
public Style getStyle() {
|
||||
public Style getStyle()
|
||||
{
|
||||
return Style.values()[((int) getValue(14, 0) >>> 8)];
|
||||
}
|
||||
|
||||
public boolean hasChest() {
|
||||
public boolean hasChest()
|
||||
{
|
||||
return isHorseFlag(8);
|
||||
}
|
||||
|
||||
public boolean isBreedable() {
|
||||
public boolean isBreedable()
|
||||
{
|
||||
return isHorseFlag(16);
|
||||
}
|
||||
|
||||
public boolean isGrazing() {
|
||||
public boolean isGrazing()
|
||||
{
|
||||
return isHorseFlag(32);
|
||||
}
|
||||
|
||||
public boolean isMouthOpen() {
|
||||
public boolean isMouthOpen()
|
||||
{
|
||||
return isHorseFlag(128);
|
||||
}
|
||||
|
||||
public boolean isRearing() {
|
||||
public boolean isRearing()
|
||||
{
|
||||
return isHorseFlag(64);
|
||||
}
|
||||
|
||||
public boolean isSaddled() {
|
||||
public boolean isSaddled()
|
||||
{
|
||||
return isHorseFlag(4);
|
||||
}
|
||||
|
||||
public boolean isTamed() {
|
||||
public boolean isTamed()
|
||||
{
|
||||
return isHorseFlag(2);
|
||||
}
|
||||
|
||||
private boolean isHorseFlag(int i) {
|
||||
private boolean isHorseFlag(int i)
|
||||
{
|
||||
return (getHorseFlag() & i) != 0;
|
||||
}
|
||||
|
||||
private byte getHorseFlag() {
|
||||
private byte getHorseFlag()
|
||||
{
|
||||
return (byte) getValue(12, (byte) 0);
|
||||
}
|
||||
|
||||
public void setCanBreed(boolean breed) {
|
||||
public void setCanBreed(boolean breed)
|
||||
{
|
||||
setHorseFlag(16, breed);
|
||||
}
|
||||
|
||||
public void setCarryingChest(boolean chest) {
|
||||
public void setCarryingChest(boolean chest)
|
||||
{
|
||||
setHorseFlag(8, chest);
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
public void setColor(Color color)
|
||||
{
|
||||
setValue(14, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
|
||||
sendData(14);
|
||||
}
|
||||
|
||||
private void setHorseFlag(int i, boolean flag) {
|
||||
private void setHorseFlag(int i, boolean flag)
|
||||
{
|
||||
byte j = (byte) getValue(12, (byte) 0);
|
||||
if (flag) {
|
||||
if (flag)
|
||||
{
|
||||
setValue(12, (byte) (j | i));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue(12, (byte) (j & ~i));
|
||||
}
|
||||
sendData(12);
|
||||
}
|
||||
|
||||
public void setGrazing(boolean grazing) {
|
||||
public void setGrazing(boolean grazing)
|
||||
{
|
||||
setHorseFlag(32, grazing);
|
||||
}
|
||||
|
||||
protected void setHorseArmor(int armor) {
|
||||
protected void setHorseArmor(int armor)
|
||||
{
|
||||
setValue(16, armor);
|
||||
sendData(16);
|
||||
}
|
||||
|
||||
public void setHorseArmor(ItemStack item) {
|
||||
public void setHorseArmor(ItemStack item)
|
||||
{
|
||||
int value = 0;
|
||||
if (item != null) {
|
||||
if (item != null)
|
||||
{
|
||||
Material mat = item.getType();
|
||||
if (mat == Material.IRON_BARDING) {
|
||||
if (mat == Material.IRON_BARDING)
|
||||
{
|
||||
value = 1;
|
||||
} else if (mat == Material.GOLD_BARDING) {
|
||||
}
|
||||
else if (mat == Material.GOLD_BARDING)
|
||||
{
|
||||
value = 2;
|
||||
} else if (mat == Material.DIAMOND_BARDING) {
|
||||
}
|
||||
else if (mat == Material.DIAMOND_BARDING)
|
||||
{
|
||||
value = 3;
|
||||
}
|
||||
}
|
||||
setHorseArmor(value);
|
||||
}
|
||||
|
||||
public void setMouthOpen(boolean mouthOpen) {
|
||||
public void setMouthOpen(boolean mouthOpen)
|
||||
{
|
||||
setHorseFlag(128, mouthOpen);
|
||||
}
|
||||
|
||||
public void setOwner(UUID uuid) {
|
||||
public void setOwner(UUID uuid)
|
||||
{
|
||||
setValue(15, Optional.of(uuid));
|
||||
sendData(15);
|
||||
}
|
||||
|
||||
public void setRearing(boolean rear) {
|
||||
public void setRearing(boolean rear)
|
||||
{
|
||||
setHorseFlag(64, rear);
|
||||
}
|
||||
|
||||
public void setSaddled(boolean saddled) {
|
||||
public void setSaddled(boolean saddled)
|
||||
{
|
||||
setHorseFlag(4, saddled);
|
||||
}
|
||||
|
||||
public void setStyle(Style style) {
|
||||
public void setStyle(Style style)
|
||||
{
|
||||
setValue(14, getColor().ordinal() & 0xFF | style.ordinal() << 8);
|
||||
sendData(14);
|
||||
}
|
||||
|
||||
public void setTamed(boolean tamed) {
|
||||
public void setTamed(boolean tamed)
|
||||
{
|
||||
setHorseFlag(2, tamed);
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemFrameWatcher extends FlagWatcher {
|
||||
|
@@ -1,19 +1,5 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedAttribute;
|
||||
import com.comphenix.protocol.wrappers.WrappedAttribute.Builder;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@@ -22,64 +8,98 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LivingWatcher extends FlagWatcher {
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedAttribute;
|
||||
import com.comphenix.protocol.wrappers.WrappedAttribute.Builder;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
public class LivingWatcher extends FlagWatcher
|
||||
{
|
||||
|
||||
static Map<Integer, Object> list = new HashMap<>();
|
||||
static Method getId;
|
||||
|
||||
static {
|
||||
try {
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
getId = ReflectionManager.getNmsMethod("MobEffectList", "getId", ReflectionManager.getNmsClass("MobEffectList"));
|
||||
Object REGISTRY = ReflectionManager.getNmsField("MobEffectList", "REGISTRY").get(null);
|
||||
for (Object next: ((Iterable)REGISTRY)) {
|
||||
for (Object next : ((Iterable) REGISTRY))
|
||||
{
|
||||
int id = (int) getId.invoke(null, next);
|
||||
list.put(id, next);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
}
|
||||
|
||||
private double maxHealth;
|
||||
private boolean maxHealthSet;
|
||||
private HashSet<Integer> potionEffects = new HashSet<>();
|
||||
|
||||
public LivingWatcher(Disguise disguise) {
|
||||
public LivingWatcher(Disguise disguise)
|
||||
{
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public void addPotionEffect(PotionEffectType potionEffect) {
|
||||
if (!hasPotionEffect(potionEffect)) {
|
||||
public void addPotionEffect(PotionEffectType potionEffect)
|
||||
{
|
||||
if (!hasPotionEffect(potionEffect))
|
||||
{
|
||||
removePotionEffect(potionEffect);
|
||||
potionEffects.add(potionEffect.getId());
|
||||
|
||||
sendPotionEffects();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingWatcher clone(Disguise disguise) {
|
||||
public LivingWatcher clone(Disguise disguise)
|
||||
{
|
||||
LivingWatcher clone = (LivingWatcher) super.clone(disguise);
|
||||
clone.potionEffects = (HashSet<Integer>) potionEffects.clone();
|
||||
clone.maxHealth = maxHealth;
|
||||
clone.maxHealthSet = maxHealthSet;
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
public float getHealth() {
|
||||
public float getHealth()
|
||||
{
|
||||
return (float) getValue(6, 0F);
|
||||
}
|
||||
|
||||
public double getMaxHealth() {
|
||||
public double getMaxHealth()
|
||||
{
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public boolean isPotionParticlesAmbient() {
|
||||
public boolean isPotionParticlesAmbient()
|
||||
{
|
||||
return (boolean) getValue(8, false);
|
||||
}
|
||||
|
||||
private int getPotions() {
|
||||
private int getPotions()
|
||||
{
|
||||
int m = 3694022;
|
||||
|
||||
if (potionEffects.isEmpty()) {
|
||||
if (potionEffects.isEmpty())
|
||||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -87,15 +107,19 @@ public class LivingWatcher extends FlagWatcher {
|
||||
float f2 = 0.0F;
|
||||
float f3 = 0.0F;
|
||||
float f4 = 0.0F;
|
||||
try {
|
||||
for (int localMobEffect : potionEffects) {
|
||||
try
|
||||
{
|
||||
for (int localMobEffect : potionEffects)
|
||||
{
|
||||
int n = (Integer) getId.invoke(list.get(localMobEffect));
|
||||
f1 += (n >> 16 & 0xFF) / 255.0F;
|
||||
f2 += (n >> 8 & 0xFF) / 255.0F;
|
||||
f3 += (n & 0xFF) / 255.0F;
|
||||
f4 += 1.0F;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
|
||||
@@ -106,64 +130,86 @@ public class LivingWatcher extends FlagWatcher {
|
||||
return (int) f1 << 16 | (int) f2 << 8 | (int) f3;
|
||||
}
|
||||
|
||||
public boolean hasPotionEffect(PotionEffectType type) {
|
||||
public boolean hasPotionEffect(PotionEffectType type)
|
||||
{
|
||||
return potionEffects.contains(type.getId());
|
||||
}
|
||||
|
||||
public boolean isMaxHealthSet() {
|
||||
public boolean isMaxHealthSet()
|
||||
{
|
||||
return maxHealthSet;
|
||||
}
|
||||
|
||||
public void removePotionEffect(PotionEffectType type) {
|
||||
if (potionEffects.contains(type.getId())) {
|
||||
public void removePotionEffect(PotionEffectType type)
|
||||
{
|
||||
if (potionEffects.contains(type.getId()))
|
||||
{
|
||||
potionEffects.remove(type.getId());
|
||||
sendPotionEffects();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPotionParticlesAmbient(boolean particles) {
|
||||
public void setPotionParticlesAmbient(boolean particles)
|
||||
{
|
||||
setValue(8, particles);
|
||||
sendData(8);
|
||||
}
|
||||
|
||||
private void sendPotionEffects() {
|
||||
private void sendPotionEffects()
|
||||
{
|
||||
setValue(7, getPotions());
|
||||
sendData(7);
|
||||
}
|
||||
|
||||
public void setHealth(float health) {
|
||||
public void setHealth(float health)
|
||||
{
|
||||
setValue(6, health);
|
||||
sendData(6);
|
||||
}
|
||||
|
||||
public int getArrowsSticking() {
|
||||
public int getArrowsSticking()
|
||||
{
|
||||
return (int) getValue(9, 0);
|
||||
}
|
||||
|
||||
public void setArrowsSticking(int arrowsNo) {
|
||||
public void setArrowsSticking(int arrowsNo)
|
||||
{
|
||||
setValue(9, arrowsNo);
|
||||
sendData(9);
|
||||
}
|
||||
|
||||
public void setMaxHealth(double newHealth) {
|
||||
public void setMaxHealth(double newHealth)
|
||||
{
|
||||
this.maxHealth = newHealth;
|
||||
this.maxHealthSet = true;
|
||||
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
|
||||
|
||||
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this)
|
||||
{
|
||||
PacketContainer packet = new PacketContainer(Server.UPDATE_ATTRIBUTES);
|
||||
|
||||
List<WrappedAttribute> attributes = new ArrayList<>();
|
||||
|
||||
Builder builder;
|
||||
builder = WrappedAttribute.newBuilder();
|
||||
builder.attributeKey("generic.maxHealth");
|
||||
builder.baseValue(getMaxHealth());
|
||||
builder.packet(packet);
|
||||
|
||||
attributes.add(builder.build());
|
||||
|
||||
Entity entity = getDisguise().getEntity();
|
||||
|
||||
packet.getIntegers().write(0, entity.getEntityId());
|
||||
packet.getAttributeCollectionModifier().write(0, attributes);
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
try {
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
|
||||
{
|
||||
try
|
||||
{
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace(System.out);
|
||||
}
|
||||
}
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class MinecartWatcher extends FlagWatcher {
|
||||
|
@@ -1,9 +1,10 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.entity.Ocelot;
|
||||
import org.bukkit.entity.Ocelot.Type;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class OcelotWatcher extends TameableWatcher {
|
||||
|
||||
public OcelotWatcher(Disguise disguise) {
|
@@ -1,9 +1,10 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.Art;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.Art;
|
||||
|
||||
public class PaintingWatcher extends FlagWatcher {
|
||||
|
@@ -1,17 +1,19 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerWatcher extends LivingWatcher {
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
public class SheepWatcher extends AgeableWatcher {
|
||||
|
@@ -1,9 +1,11 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
/**
|
||||
* @author Navid
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
/**
|
||||
* @author Navid
|
||||
*/
|
@@ -1,52 +1,66 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TameableWatcher extends AgeableWatcher {
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
public TameableWatcher(Disguise disguise) {
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class TameableWatcher extends AgeableWatcher
|
||||
{
|
||||
|
||||
public TameableWatcher(Disguise disguise)
|
||||
{
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public Optional<UUID> getOwner() {
|
||||
return (Optional<UUID>) getValue(13, Optional.absent());
|
||||
public Optional<UUID> getOwner()
|
||||
{
|
||||
return getValue(13, Optional.<UUID> absent());
|
||||
}
|
||||
|
||||
public boolean isSitting() {
|
||||
public boolean isSitting()
|
||||
{
|
||||
return isTameableFlag(1);
|
||||
}
|
||||
|
||||
public boolean isTamed() {
|
||||
public boolean isTamed()
|
||||
{
|
||||
return isTameableFlag(4);
|
||||
}
|
||||
|
||||
protected boolean isTameableFlag(int no) {
|
||||
protected boolean isTameableFlag(int no)
|
||||
{
|
||||
return ((byte) getValue(12, (byte) 0) & no) != 0;
|
||||
}
|
||||
|
||||
protected void setTameableFlag(int no, boolean flag) {
|
||||
protected void setTameableFlag(int no, boolean flag)
|
||||
{
|
||||
byte value = (byte) getValue(12, (byte) 0);
|
||||
if (flag) {
|
||||
if (flag)
|
||||
{
|
||||
setValue(12, (byte) (value | no));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue(12, (byte) (value & -(no + 1)));
|
||||
}
|
||||
sendData(12);
|
||||
}
|
||||
|
||||
public void setOwner(UUID owner) {
|
||||
public void setOwner(UUID owner)
|
||||
{
|
||||
setValue(13, Optional.of(owner));
|
||||
sendData(13);
|
||||
}
|
||||
|
||||
public void setSitting(boolean sitting) {
|
||||
public void setSitting(boolean sitting)
|
||||
{
|
||||
setTameableFlag(1, sitting);
|
||||
}
|
||||
|
||||
public void setTamed(boolean tamed) {
|
||||
public void setTamed(boolean tamed)
|
||||
{
|
||||
setTameableFlag(4, tamed);
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.Color;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.Color;
|
||||
|
||||
/**
|
||||
* @author Navid
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
|
||||
public class VillagerWatcher extends AgeableWatcher {
|
||||
|
@@ -1,9 +1,10 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class WitherWatcher extends LivingWatcher {
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
public class WolfWatcher extends TameableWatcher {
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class ZombieWatcher extends LivingWatcher {
|
||||
|
||||
public ZombieWatcher(Disguise disguise) {
|
@@ -1,12 +1,12 @@
|
||||
package me.libraryaddict.disguise.events;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class DisguiseEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
@@ -1,12 +1,12 @@
|
||||
package me.libraryaddict.disguise.events;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
|
||||
public class UndisguiseEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
@@ -1,7 +1,5 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.security.CodeSource;
|
||||
@@ -10,60 +8,81 @@ 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 class ClassGetter
|
||||
{
|
||||
|
||||
public static ArrayList<Class<?>> getClassesForPackage(String pkgname) {
|
||||
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) {
|
||||
|
||||
if (src != null)
|
||||
{
|
||||
URL resource = src.getLocation();
|
||||
resource.getPath();
|
||||
processJarfile(resource, pkgname, classes);
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static Class<?> loadClass(String className) {
|
||||
try {
|
||||
private static Class<?> loadClass(String className)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Class.forName(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
|
||||
} catch (NoClassDefFoundError e) {
|
||||
}
|
||||
catch (NoClassDefFoundError e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes) {
|
||||
try {
|
||||
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()) {
|
||||
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())) {
|
||||
&& entryName.length() > (relPath.length() + "/".length()))
|
||||
{
|
||||
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
|
||||
}
|
||||
if (className != null) {
|
||||
if (className != null)
|
||||
{
|
||||
Class<?> c = loadClass(className);
|
||||
if (c != null) {
|
||||
if (c != null)
|
||||
{
|
||||
classes.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace(System.out);
|
||||
}
|
||||
}
|
@@ -1,87 +1,145 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
|
||||
/**
|
||||
* Only living disguises go in here!
|
||||
*/
|
||||
public enum DisguiseSound {
|
||||
public enum DisguiseSound
|
||||
{
|
||||
|
||||
ARROW(null, null, null, null, Sound.ENTITY_ARROW_HIT, Sound.ENTITY_ARROW_SHOOT),
|
||||
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),
|
||||
|
||||
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),
|
||||
|
||||
CAVE_SPIDER(Sound.ENTITY_SPIDER_AMBIENT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH, Sound.ENTITY_SPIDER_AMBIENT),
|
||||
CHICKEN(Sound.ENTITY_CHICKEN_HURT, Sound.ENTITY_CHICKEN_STEP, Sound.ENTITY_CHICKEN_HURT, Sound.ENTITY_CHICKEN_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
|
||||
Sound.ENTITY_CHICKEN_EGG, Sound.ENTITY_PLAYER_BIG_FALL),
|
||||
|
||||
CHICKEN(Sound.ENTITY_CHICKEN_HURT, Sound.ENTITY_CHICKEN_STEP, Sound.ENTITY_CHICKEN_HURT, Sound.ENTITY_CHICKEN_AMBIENT,
|
||||
Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_CHICKEN_EGG, Sound.ENTITY_PLAYER_BIG_FALL),
|
||||
|
||||
COW(Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_STEP, Sound.ENTITY_COW_DEATH, Sound.ENTITY_COW_AMBIENT),
|
||||
|
||||
CREEPER(Sound.ENTITY_CREEPER_HURT, "step.grass", Sound.ENTITY_CREEPER_DEATH, null),
|
||||
DONKEY(Sound.ENTITY_DONKEY_HURT, "step.grass", Sound.ENTITY_DONKEY_DEATH, Sound.ENTITY_DONKEY_AMBIENT, Sound.ENTITY_HORSE_GALLOP,
|
||||
Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR,
|
||||
Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
|
||||
ELDER_GUARDIAN(Sound.ENTITY_ELDER_GUARDIAN_HURT, null, Sound.ENTITY_ELDER_GUARDIAN_DEATH, Sound.ENTITY_ELDER_GUARDIAN_AMBIENT),
|
||||
ENDER_DRAGON(Sound.ENTITY_ENDERDRAGON_HURT, null, Sound.ENTITY_ENDERDRAGON_DEATH, Sound.ENTITY_ENDERDRAGON_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
|
||||
Sound.ENTITY_ENDERDRAGON_FLAP, Sound.ENTITY_PLAYER_BIG_FALL),
|
||||
ENDERMAN(Sound.ENTITY_ENDERMEN_HURT, "step.grass", Sound.ENTITY_ENDERMEN_DEATH, Sound.ENTITY_ENDERMEN_AMBIENT, Sound.ENTITY_ENDERMEN_SCREAM,
|
||||
Sound.ENTITY_ENDERMEN_TELEPORT, Sound.ENTITY_ENDERMEN_STARE),
|
||||
ENDERMITE(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_ENDERMITE_STEP, Sound.ENTITY_ENDERMITE_DEATH, Sound.ENTITY_ENDERMITE_AMBIENT),
|
||||
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),
|
||||
|
||||
DONKEY(Sound.ENTITY_DONKEY_HURT, "step.grass", Sound.ENTITY_DONKEY_DEATH, Sound.ENTITY_DONKEY_AMBIENT,
|
||||
Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD,
|
||||
Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
|
||||
|
||||
ELDER_GUARDIAN(Sound.ENTITY_ELDER_GUARDIAN_HURT, null, Sound.ENTITY_ELDER_GUARDIAN_DEATH,
|
||||
Sound.ENTITY_ELDER_GUARDIAN_AMBIENT),
|
||||
|
||||
ENDER_DRAGON(Sound.ENTITY_ENDERDRAGON_HURT, null, Sound.ENTITY_ENDERDRAGON_DEATH, Sound.ENTITY_ENDERDRAGON_AMBIENT,
|
||||
Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_ENDERDRAGON_FLAP, Sound.ENTITY_PLAYER_BIG_FALL),
|
||||
|
||||
ENDERMAN(Sound.ENTITY_ENDERMEN_HURT, "step.grass", Sound.ENTITY_ENDERMEN_DEATH, Sound.ENTITY_ENDERMEN_AMBIENT,
|
||||
Sound.ENTITY_ENDERMEN_SCREAM, Sound.ENTITY_ENDERMEN_TELEPORT, Sound.ENTITY_ENDERMEN_STARE),
|
||||
|
||||
ENDERMITE(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_ENDERMITE_STEP, Sound.ENTITY_ENDERMITE_DEATH,
|
||||
Sound.ENTITY_ENDERMITE_AMBIENT),
|
||||
|
||||
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, "step.grass", null, null),
|
||||
|
||||
GUARDIAN(Sound.ENTITY_GUARDIAN_HURT, null, Sound.ENTITY_GUARDIAN_DEATH, Sound.ENTITY_ELDER_GUARDIAN_AMBIENT),
|
||||
|
||||
HORSE(Sound.ENTITY_HORSE_HURT, "step.grass", Sound.ENTITY_HORSE_DEATH, Sound.ENTITY_HORSE_AMBIENT, Sound.ENTITY_HORSE_GALLOP,
|
||||
Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR,
|
||||
Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
|
||||
IRON_GOLEM(Sound.ENTITY_IRONGOLEM_HURT, Sound.ENTITY_IRONGOLEM_STEP, Sound.ENTITY_IRONGOLEM_DEATH, Sound.ENTITY_IRONGOLEM_ATTACK),
|
||||
|
||||
IRON_GOLEM(Sound.ENTITY_IRONGOLEM_HURT, Sound.ENTITY_IRONGOLEM_STEP, Sound.ENTITY_IRONGOLEM_DEATH,
|
||||
Sound.ENTITY_IRONGOLEM_ATTACK),
|
||||
|
||||
MAGMA_CUBE(Sound.ENTITY_MAGMACUBE_HURT, Sound.ENTITY_MAGMACUBE_JUMP, null, null),
|
||||
|
||||
MULE(Sound.ENTITY_MULE_HURT, "step.grass", Sound.ENTITY_MULE_DEATH, Sound.ENTITY_MULE_AMBIENT),
|
||||
|
||||
MUSHROOM_COW(Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_STEP, Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_AMBIENT),
|
||||
OCELOT(Sound.ENTITY_CAT_HURT, "step.grass", Sound.ENTITY_CAT_HURT, Sound.ENTITY_CAT_AMBIENT, Sound.ENTITY_CAT_PURR, Sound.ENTITY_CAT_PURREOW),
|
||||
|
||||
OCELOT(Sound.ENTITY_CAT_HURT, "step.grass", Sound.ENTITY_CAT_HURT, Sound.ENTITY_CAT_AMBIENT, Sound.ENTITY_CAT_PURR,
|
||||
Sound.ENTITY_CAT_PURREOW),
|
||||
|
||||
PIG(Sound.ENTITY_PIG_HURT, Sound.ENTITY_PIG_STEP, Sound.ENTITY_PIG_DEATH, Sound.ENTITY_PIG_AMBIENT),
|
||||
PIG_ZOMBIE(Sound.ENTITY_ZOMBIE_PIG_HURT, null, Sound.ENTITY_ZOMBIE_PIG_DEATH, Sound.ENTITY_ZOMBIE_PIG_AMBIENT, Sound.ENTITY_ZOMBIE_PIG_ANGRY),
|
||||
|
||||
PIG_ZOMBIE(Sound.ENTITY_ZOMBIE_PIG_HURT, null, Sound.ENTITY_ZOMBIE_PIG_DEATH, Sound.ENTITY_ZOMBIE_PIG_AMBIENT,
|
||||
Sound.ENTITY_ZOMBIE_PIG_ANGRY),
|
||||
|
||||
PLAYER(Sound.ENTITY_PLAYER_HURT, "step.grass", Sound.ENTITY_PLAYER_DEATH, null),
|
||||
|
||||
RABBIT(Sound.ENTITY_RABBIT_HURT, Sound.ENTITY_RABBIT_JUMP, Sound.ENTITY_RABBIT_DEATH, Sound.ENTITY_RABBIT_AMBIENT),
|
||||
|
||||
SHEEP(Sound.ENTITY_SHEEP_HURT, Sound.ENTITY_SHEEP_STEP, null, Sound.ENTITY_SHEEP_AMBIENT, Sound.ENTITY_SHEEP_SHEAR),
|
||||
|
||||
SHULKER(Sound.ENTITY_SHULKER_HURT, null, Sound.ENTITY_SHULKER_DEATH, Sound.ENTITY_SHULKER_AMBIENT, Sound.ENTITY_SHULKER_OPEN,
|
||||
Sound.ENTITY_SHULKER_CLOSE, Sound.ENTITY_SHULKER_HURT_CLOSED, 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, "step.grass", Sound.ENTITY_SKELETON_HORSE_DEATH, Sound.ENTITY_SKELETON_HORSE_AMBIENT,
|
||||
Sound.ENTITY_HORSE_GALLOP,
|
||||
Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR,
|
||||
Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
|
||||
SLIME(Sound.ENTITY_SLIME_HURT, Sound.ENTITY_SLIME_JUMP, Sound.ENTITY_SLIME_DEATH, null),
|
||||
SNOWMAN(Sound.ENTITY_SNOWMAN_HURT, null, Sound.ENTITY_SNOWMAN_DEATH, Sound.ENTITY_SNOWMAN_AMBIENT, Sound.ENTITY_SNOWMAN_SHOOT),
|
||||
SPIDER(Sound.ENTITY_SPIDER_AMBIENT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH, Sound.ENTITY_SPIDER_AMBIENT),
|
||||
SQUID(Sound.ENTITY_SQUID_HURT, null, Sound.ENTITY_SQUID_DEATH, Sound.ENTITY_SQUID_AMBIENT),
|
||||
UNDEAD_HORSE(Sound.ENTITY_ZOMBIE_HORSE_HURT, "step.grass", Sound.ENTITY_ZOMBIE_HORSE_DEATH, Sound.ENTITY_ZOMBIE_HORSE_AMBIENT, Sound.ENTITY_HORSE_GALLOP,
|
||||
Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR,
|
||||
Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
|
||||
VILLAGER(Sound.ENTITY_VILLAGER_HURT, null, Sound.ENTITY_VILLAGER_DEATH, Sound.ENTITY_VILLAGER_AMBIENT, Sound.ENTITY_VILLAGER_TRADING, Sound.ENTITY_VILLAGER_NO,
|
||||
Sound.ENTITY_VILLAGER_YES),
|
||||
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_SKELETON_HURT, Sound.ENTITY_SKELETON_STEP, Sound.ENTITY_SKELETON_DEATH, Sound.ENTITY_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_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR),
|
||||
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_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
|
||||
|
||||
public enum SoundType {
|
||||
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, "step.grass", Sound.ENTITY_SKELETON_HORSE_DEATH,
|
||||
Sound.ENTITY_SKELETON_HORSE_AMBIENT, Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY,
|
||||
Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP,
|
||||
Sound.ENTITY_HORSE_ANGRY),
|
||||
|
||||
SLIME(Sound.ENTITY_SLIME_HURT, Sound.ENTITY_SLIME_JUMP, Sound.ENTITY_SLIME_DEATH, null),
|
||||
|
||||
SNOWMAN(Sound.ENTITY_SNOWMAN_HURT, null, Sound.ENTITY_SNOWMAN_DEATH, Sound.ENTITY_SNOWMAN_AMBIENT,
|
||||
Sound.ENTITY_SNOWMAN_SHOOT),
|
||||
|
||||
SPIDER(Sound.ENTITY_SPIDER_AMBIENT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH, Sound.ENTITY_SPIDER_AMBIENT),
|
||||
|
||||
SQUID(Sound.ENTITY_SQUID_HURT, null, Sound.ENTITY_SQUID_DEATH, Sound.ENTITY_SQUID_AMBIENT),
|
||||
|
||||
UNDEAD_HORSE(Sound.ENTITY_ZOMBIE_HORSE_HURT, "step.grass", Sound.ENTITY_ZOMBIE_HORSE_DEATH, Sound.ENTITY_ZOMBIE_HORSE_AMBIENT,
|
||||
Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD,
|
||||
Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
|
||||
|
||||
VILLAGER(Sound.ENTITY_VILLAGER_HURT, null, Sound.ENTITY_VILLAGER_DEATH, Sound.ENTITY_VILLAGER_AMBIENT,
|
||||
Sound.ENTITY_VILLAGER_TRADING, Sound.ENTITY_VILLAGER_NO, Sound.ENTITY_VILLAGER_YES),
|
||||
|
||||
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_SKELETON_HURT, Sound.ENTITY_SKELETON_STEP, Sound.ENTITY_SKELETON_DEATH,
|
||||
Sound.ENTITY_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_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD,
|
||||
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR), 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_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD,
|
||||
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
|
||||
|
||||
public enum SoundType
|
||||
{
|
||||
CANCEL, DEATH, HURT, IDLE, STEP
|
||||
}
|
||||
|
||||
public static DisguiseSound getType(String name) {
|
||||
//TODO: FIX the disguise sounds
|
||||
try {
|
||||
public static DisguiseSound getType(String name)
|
||||
{
|
||||
// TODO: FIX the disguise sounds
|
||||
try
|
||||
{
|
||||
return valueOf(name);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -90,115 +148,160 @@ public enum DisguiseSound {
|
||||
private float damageSoundVolume = 1F;
|
||||
private HashMap<SoundType, String> disguiseSounds = new HashMap<>();
|
||||
|
||||
DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds) {
|
||||
DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds)
|
||||
{
|
||||
addSound(hurt, SoundType.HURT);
|
||||
addSound(step, SoundType.STEP);
|
||||
addSound(death, SoundType.DEATH);
|
||||
addSound(idle, SoundType.IDLE);
|
||||
for (Object obj : sounds) {
|
||||
|
||||
for (Object obj : sounds)
|
||||
{
|
||||
addSound(obj, SoundType.CANCEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addSound(Object sound, SoundType type) {
|
||||
private void addSound(Object sound, SoundType type)
|
||||
{
|
||||
String s;
|
||||
if (sound == null) {
|
||||
|
||||
if (sound == null)
|
||||
{
|
||||
return;
|
||||
} else if (sound instanceof String) {
|
||||
}
|
||||
else if (sound instanceof String)
|
||||
{
|
||||
s = (String) sound;
|
||||
} else if (sound instanceof Sound) {
|
||||
}
|
||||
else if (sound instanceof Sound)
|
||||
{
|
||||
s = ReflectionManager.getCraftSound((Sound) sound);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException("Was given a unknown object " + sound);
|
||||
}
|
||||
switch (type) {
|
||||
case HURT:
|
||||
disguiseSounds.put(SoundType.HURT, s);
|
||||
break;
|
||||
case STEP:
|
||||
disguiseSounds.put(SoundType.STEP, s);
|
||||
break;
|
||||
case DEATH:
|
||||
disguiseSounds.put(SoundType.DEATH, s);
|
||||
break;
|
||||
case IDLE:
|
||||
disguiseSounds.put(SoundType.IDLE, s);
|
||||
break;
|
||||
case CANCEL:
|
||||
cancelSounds.add(s);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case HURT:
|
||||
disguiseSounds.put(SoundType.HURT, s);
|
||||
break;
|
||||
case STEP:
|
||||
disguiseSounds.put(SoundType.STEP, s);
|
||||
break;
|
||||
case DEATH:
|
||||
disguiseSounds.put(SoundType.DEATH, s);
|
||||
break;
|
||||
case IDLE:
|
||||
disguiseSounds.put(SoundType.IDLE, s);
|
||||
break;
|
||||
case CANCEL:
|
||||
cancelSounds.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
public float getDamageAndIdleSoundVolume() {
|
||||
public float getDamageAndIdleSoundVolume()
|
||||
{
|
||||
return damageSoundVolume;
|
||||
}
|
||||
|
||||
public String getSound(SoundType type) {
|
||||
if (type == null || !disguiseSounds.containsKey(type)) {
|
||||
public String getSound(SoundType type)
|
||||
{
|
||||
if (type == null || !disguiseSounds.containsKey(type))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return disguiseSounds.get(type);
|
||||
}
|
||||
|
||||
public HashSet<String> getSoundsToCancel() {
|
||||
public HashSet<String> getSoundsToCancel()
|
||||
{
|
||||
return cancelSounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check if this sound name is owned by this disguise sound.
|
||||
*/
|
||||
public SoundType getType(String sound, boolean ignoreDamage) {
|
||||
if (sound == null) return SoundType.CANCEL;
|
||||
if (isCancelSound(sound)) {
|
||||
public SoundType getType(String sound, boolean ignoreDamage)
|
||||
{
|
||||
if (sound == null)
|
||||
return SoundType.CANCEL;
|
||||
|
||||
if (isCancelSound(sound))
|
||||
{
|
||||
return SoundType.CANCEL;
|
||||
}
|
||||
|
||||
if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.")
|
||||
&& sound.startsWith("step.")) {
|
||||
&& sound.startsWith("step."))
|
||||
{
|
||||
return SoundType.STEP;
|
||||
}
|
||||
for (SoundType type : SoundType.values()) {
|
||||
if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT)) {
|
||||
|
||||
for (SoundType type : SoundType.values())
|
||||
{
|
||||
if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
String s = disguiseSounds.get(type);
|
||||
if (s != null) {
|
||||
if (s.equals(sound)) {
|
||||
|
||||
if (s != null)
|
||||
{
|
||||
if (s.equals(sound))
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isCancelSound(String sound) {
|
||||
public boolean isCancelSound(String sound)
|
||||
{
|
||||
return getSoundsToCancel().contains(sound);
|
||||
}
|
||||
|
||||
public void removeSound(SoundType type, Sound sound) {
|
||||
public void removeSound(SoundType type, Sound sound)
|
||||
{
|
||||
removeSound(type, ReflectionManager.getCraftSound(sound));
|
||||
}
|
||||
|
||||
public void removeSound(SoundType type, String sound) {
|
||||
if (type == SoundType.CANCEL) {
|
||||
public void removeSound(SoundType type, String sound)
|
||||
{
|
||||
if (type == SoundType.CANCEL)
|
||||
{
|
||||
cancelSounds.remove(sound);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
disguiseSounds.remove(type);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDamageAndIdleSoundVolume(float strength) {
|
||||
public void setDamageAndIdleSoundVolume(float strength)
|
||||
{
|
||||
this.damageSoundVolume = strength;
|
||||
}
|
||||
|
||||
public void setSound(SoundType type, Sound sound) {
|
||||
public void setSound(SoundType type, Sound sound)
|
||||
{
|
||||
setSound(type, ReflectionManager.getCraftSound(sound));
|
||||
}
|
||||
|
||||
public void setSound(SoundType type, String sound) {
|
||||
if (type == SoundType.CANCEL) {
|
||||
public void setSound(SoundType type, String sound)
|
||||
{
|
||||
if (type == SoundType.CANCEL)
|
||||
{
|
||||
cancelSounds.add(sound);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
disguiseSounds.put(type, sound);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
||||
public class DisguiseValues {
|
||||
|
||||
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
|
@@ -1,7 +1,6 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.ProfileLookupCallback;
|
||||
|
@@ -27,13 +27,6 @@
|
||||
*/
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -53,7 +46,15 @@ import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class Metrics {
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class Metrics
|
||||
{
|
||||
|
||||
/**
|
||||
* The current revision number
|
||||
@@ -104,8 +105,10 @@ public class Metrics {
|
||||
*/
|
||||
private volatile BukkitTask task = null;
|
||||
|
||||
public Metrics(final Plugin plugin) throws IOException {
|
||||
if (plugin == null) {
|
||||
public Metrics(final Plugin plugin) throws IOException
|
||||
{
|
||||
if (plugin == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Plugin cannot be null");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
@@ -117,7 +120,8 @@ public class Metrics {
|
||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||
configuration.addDefault("debug", false);
|
||||
// Do we need to create the file?
|
||||
if (configuration.get("guid", null) == null) {
|
||||
if (configuration.get("guid", null) == null)
|
||||
{
|
||||
configuration.options().header("http://mcstats.org").copyDefaults(true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
@@ -127,13 +131,17 @@ public class Metrics {
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics website. Plotters can be added to the graph object returned.
|
||||
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics website.
|
||||
* Plotters can be added to the graph object returned.
|
||||
*
|
||||
* @param name The name of the graph
|
||||
* @param name
|
||||
* The name of the graph
|
||||
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
|
||||
*/
|
||||
public Graph createGraph(final String name) {
|
||||
if (name == null) {
|
||||
public Graph createGraph(final String name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Graph name cannot be null");
|
||||
}
|
||||
// Construct the graph object
|
||||
@@ -147,45 +155,59 @@ public class Metrics {
|
||||
/**
|
||||
* Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend
|
||||
*
|
||||
* @param graph The name of the graph
|
||||
* @param graph
|
||||
* The name of the graph
|
||||
*/
|
||||
public void addGraph(final Graph graph) {
|
||||
if (graph == null) {
|
||||
public void addGraph(final Graph graph)
|
||||
{
|
||||
if (graph == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Graph cannot be null");
|
||||
}
|
||||
graphs.add(graph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200 ticks.
|
||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the initial data to
|
||||
* the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200 ticks.
|
||||
*
|
||||
* @return True if statistics measuring is running, otherwise false.
|
||||
*/
|
||||
public boolean start() {
|
||||
synchronized (optOutLock) {
|
||||
public boolean start()
|
||||
{
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
// Did we opt out?
|
||||
if (isOptOut()) {
|
||||
if (isOptOut())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Is metrics already running?
|
||||
if (task != null) {
|
||||
if (task != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// Begin hitting the server with glorious data
|
||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable()
|
||||
{
|
||||
private boolean firstPost = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
// This has to be synchronized or it can collide with the disable method.
|
||||
synchronized (optOutLock) {
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && task != null) {
|
||||
if (isOptOut() && task != null)
|
||||
{
|
||||
task.cancel();
|
||||
task = null;
|
||||
// Tell all plotters to stop gathering information.
|
||||
for (Graph graph : graphs) {
|
||||
for (Graph graph : graphs)
|
||||
{
|
||||
graph.onOptOut();
|
||||
}
|
||||
}
|
||||
@@ -197,8 +219,11 @@ public class Metrics {
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (IOException e) {
|
||||
if (debug) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -213,13 +238,19 @@ public class Metrics {
|
||||
*
|
||||
* @return true if metrics should be opted out of it
|
||||
*/
|
||||
public boolean isOptOut() {
|
||||
synchronized (optOutLock) {
|
||||
try {
|
||||
public boolean isOptOut()
|
||||
{
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Reload the metrics file
|
||||
configuration.load(getConfigFile());
|
||||
} catch (IOException | InvalidConfigurationException ex) {
|
||||
if (debug) {
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException ex)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
@@ -233,16 +264,20 @@ public class Metrics {
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void enable() throws IOException {
|
||||
public void enable() throws IOException
|
||||
{
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
if (isOptOut())
|
||||
{
|
||||
configuration.set("opt-out", false);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
// Enable Task, if it is not running
|
||||
if (task == null) {
|
||||
if (task == null)
|
||||
{
|
||||
start();
|
||||
}
|
||||
}
|
||||
@@ -253,16 +288,20 @@ public class Metrics {
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void disable() throws IOException {
|
||||
public void disable() throws IOException
|
||||
{
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
synchronized (optOutLock)
|
||||
{
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut()) {
|
||||
if (!isOptOut())
|
||||
{
|
||||
configuration.set("opt-out", true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
// Disable Task, if it is running
|
||||
if (task != null) {
|
||||
if (task != null)
|
||||
{
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
@@ -274,7 +313,8 @@ public class Metrics {
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile() {
|
||||
public File getConfigFile()
|
||||
{
|
||||
// I believe the easiest way to get the base folder (e.g Spigot set via -P) for plugins to use
|
||||
// is to abuse the plugin object we already have
|
||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
||||
@@ -288,7 +328,8 @@ public class Metrics {
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*/
|
||||
private void postPlugin(final boolean isPing) throws IOException {
|
||||
private void postPlugin(final boolean isPing) throws IOException
|
||||
{
|
||||
// Server software specific section
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
String pluginName = description.getName();
|
||||
@@ -312,7 +353,8 @@ public class Metrics {
|
||||
String java_version = System.getProperty("java.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
// normalize os arch .. amd64 -> x86_64
|
||||
if (osarch.equals("amd64")) {
|
||||
if (osarch.equals("amd64"))
|
||||
{
|
||||
osarch = "x86_64";
|
||||
}
|
||||
appendJSONPair(json, "osname", osname);
|
||||
@@ -322,11 +364,14 @@ public class Metrics {
|
||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
|
||||
appendJSONPair(json, "java_version", java_version);
|
||||
// If we're pinging, append it
|
||||
if (isPing) {
|
||||
if (isPing)
|
||||
{
|
||||
appendJSONPair(json, "ping", "1");
|
||||
}
|
||||
if (graphs.size() > 0) {
|
||||
synchronized (graphs) {
|
||||
if (graphs.size() > 0)
|
||||
{
|
||||
synchronized (graphs)
|
||||
{
|
||||
json.append(',');
|
||||
json.append('"');
|
||||
json.append("graphs");
|
||||
@@ -334,14 +379,17 @@ public class Metrics {
|
||||
json.append(':');
|
||||
json.append('{');
|
||||
boolean firstGraph = true;
|
||||
for (Graph graph : graphs) {
|
||||
for (Graph graph : graphs)
|
||||
{
|
||||
StringBuilder graphJson = new StringBuilder();
|
||||
graphJson.append('{');
|
||||
for (Plotter plotter : graph.getPlotters()) {
|
||||
for (Plotter plotter : graph.getPlotters())
|
||||
{
|
||||
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
|
||||
}
|
||||
graphJson.append('}');
|
||||
if (!firstGraph) {
|
||||
if (!firstGraph)
|
||||
{
|
||||
json.append(',');
|
||||
}
|
||||
json.append(escapeJSON(graph.getName()));
|
||||
@@ -360,9 +408,12 @@ public class Metrics {
|
||||
URLConnection connection;
|
||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
||||
// It does not reroute POST requests so we need to go around it
|
||||
if (isMineshafterPresent()) {
|
||||
if (isMineshafterPresent())
|
||||
{
|
||||
connection = url.openConnection(Proxy.NO_PROXY);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
connection = url.openConnection();
|
||||
}
|
||||
byte[] uncompressed = json.toString().getBytes();
|
||||
@@ -375,8 +426,10 @@ public class Metrics {
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.setDoOutput(true);
|
||||
if (debug) {
|
||||
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||
if (debug)
|
||||
{
|
||||
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length
|
||||
+ " compressed=" + compressed.length);
|
||||
}
|
||||
// Write the data
|
||||
OutputStream os = connection.getOutputStream();
|
||||
@@ -384,24 +437,35 @@ public class Metrics {
|
||||
os.flush();
|
||||
String response;
|
||||
try ( // Now read the response
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())))
|
||||
{
|
||||
response = reader.readLine();
|
||||
// close resources
|
||||
os.close();
|
||||
}
|
||||
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
||||
if (response == null) {
|
||||
if (response == null || response.startsWith("ERR") || response.startsWith("7"))
|
||||
{
|
||||
if (response == null)
|
||||
{
|
||||
response = "null";
|
||||
} else if (response.startsWith("7")) {
|
||||
}
|
||||
else if (response.startsWith("7"))
|
||||
{
|
||||
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
||||
}
|
||||
throw new IOException(response);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Is this the first update this hour?
|
||||
if (response.equals("1") || response.contains("This is your first update this hour")) {
|
||||
synchronized (graphs) {
|
||||
for (Graph graph : graphs) {
|
||||
for (Plotter plotter : graph.getPlotters()) {
|
||||
if (response.equals("1") || response.contains("This is your first update this hour"))
|
||||
{
|
||||
synchronized (graphs)
|
||||
{
|
||||
for (Graph graph : graphs)
|
||||
{
|
||||
for (Plotter plotter : graph.getPlotters())
|
||||
{
|
||||
plotter.reset();
|
||||
}
|
||||
}
|
||||
@@ -416,19 +480,29 @@ public class Metrics {
|
||||
* @param input
|
||||
* @return byte[]
|
||||
*/
|
||||
public static byte[] gzip(String input) {
|
||||
public static byte[] gzip(String input)
|
||||
{
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
try {
|
||||
try
|
||||
{
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace(System.out);
|
||||
} finally {
|
||||
if (gzos != null) {
|
||||
try {
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (gzos != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
gzos.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -440,11 +514,15 @@ public class Metrics {
|
||||
*
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
private boolean isMineshafterPresent()
|
||||
{
|
||||
try
|
||||
{
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -457,24 +535,33 @@ public class Metrics {
|
||||
* @param value
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
|
||||
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException
|
||||
{
|
||||
boolean isValueNumeric = false;
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
try
|
||||
{
|
||||
if (value.equals("0") || !value.endsWith("0"))
|
||||
{
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
isValueNumeric = false;
|
||||
}
|
||||
if (json.charAt(json.length() - 1) != '{') {
|
||||
if (json.charAt(json.length() - 1) != '{')
|
||||
{
|
||||
json.append(',');
|
||||
}
|
||||
json.append(escapeJSON(key));
|
||||
json.append(':');
|
||||
if (isValueNumeric) {
|
||||
if (isValueNumeric)
|
||||
{
|
||||
json.append(value);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
json.append(escapeJSON(value));
|
||||
}
|
||||
}
|
||||
@@ -485,37 +572,43 @@ public class Metrics {
|
||||
* @param text
|
||||
* @return String
|
||||
*/
|
||||
private static String escapeJSON(String text) {
|
||||
private static String escapeJSON(String text)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
for (int index = 0; index < text.length(); index++)
|
||||
{
|
||||
char chr = text.charAt(index);
|
||||
switch (chr) {
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
switch (chr)
|
||||
{
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
builder.append(chr);
|
||||
break;
|
||||
case '\b':
|
||||
builder.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
builder.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
builder.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ')
|
||||
{
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u").append(t.substring(t.length() - 4));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.append(chr);
|
||||
break;
|
||||
case '\b':
|
||||
builder.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
builder.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
builder.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ') {
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u").append(t.substring(t.length() - 4));
|
||||
} else {
|
||||
builder.append(chr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.append('"');
|
||||
@@ -525,17 +618,20 @@ public class Metrics {
|
||||
/**
|
||||
* Encode text as UTF-8
|
||||
*
|
||||
* @param text the text to encode
|
||||
* @param text
|
||||
* the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException
|
||||
{
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom graph on the website
|
||||
*/
|
||||
public static class Graph {
|
||||
public static class Graph
|
||||
{
|
||||
|
||||
/**
|
||||
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is rejected
|
||||
@@ -546,7 +642,8 @@ public class Metrics {
|
||||
*/
|
||||
private final Set<Plotter> plotters = new LinkedHashSet<>();
|
||||
|
||||
private Graph(final String name) {
|
||||
private Graph(final String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -555,25 +652,30 @@ public class Metrics {
|
||||
*
|
||||
* @return the Graph's name
|
||||
*/
|
||||
public String getName() {
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a plotter to the graph, which will be used to plot entries
|
||||
*
|
||||
* @param plotter the plotter to add to the graph
|
||||
* @param plotter
|
||||
* the plotter to add to the graph
|
||||
*/
|
||||
public void addPlotter(final Plotter plotter) {
|
||||
public void addPlotter(final Plotter plotter)
|
||||
{
|
||||
plotters.add(plotter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a plotter from the graph
|
||||
*
|
||||
* @param plotter the plotter to remove from the graph
|
||||
* @param plotter
|
||||
* the plotter to remove from the graph
|
||||
*/
|
||||
public void removePlotter(final Plotter plotter) {
|
||||
public void removePlotter(final Plotter plotter)
|
||||
{
|
||||
plotters.remove(plotter);
|
||||
}
|
||||
|
||||
@@ -582,18 +684,22 @@ public class Metrics {
|
||||
*
|
||||
* @return an unmodifiable {@link java.util.Set} of the plotter objects
|
||||
*/
|
||||
public Set<Plotter> getPlotters() {
|
||||
public Set<Plotter> getPlotters()
|
||||
{
|
||||
return Collections.unmodifiableSet(plotters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
public int hashCode()
|
||||
{
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
if (!(object instanceof Graph)) {
|
||||
public boolean equals(final Object object)
|
||||
{
|
||||
if (!(object instanceof Graph))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final Graph graph = (Graph) object;
|
||||
@@ -603,14 +709,16 @@ public class Metrics {
|
||||
/**
|
||||
* Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
|
||||
*/
|
||||
protected void onOptOut() {
|
||||
protected void onOptOut()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface used to collect custom data for a plugin
|
||||
*/
|
||||
public static abstract class Plotter {
|
||||
public static abstract class Plotter
|
||||
{
|
||||
|
||||
/**
|
||||
* The plot's name
|
||||
@@ -620,21 +728,26 @@ public class Metrics {
|
||||
/**
|
||||
* Construct a plotter with the default plot name
|
||||
*/
|
||||
public Plotter() {
|
||||
public Plotter()
|
||||
{
|
||||
this("Default");
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a plotter with a specific plot name
|
||||
*
|
||||
* @param name the name of the plotter to use, which will show up on the website
|
||||
* @param name
|
||||
* the name of the plotter to use, which will show up on the website
|
||||
*/
|
||||
public Plotter(final String name) {
|
||||
public Plotter(final String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value for the plotted point. Since this function defers to an external function it may or may not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called from any thread so care should be taken when accessing resources that need to be synchronized.
|
||||
* Get the current value for the plotted point. Since this function defers to an external function it may or may not
|
||||
* return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called from any thread
|
||||
* so care should be taken when accessing resources that need to be synchronized.
|
||||
*
|
||||
* @return the current value for the point to be plotted.
|
||||
*/
|
||||
@@ -645,24 +758,29 @@ public class Metrics {
|
||||
*
|
||||
* @return the plotted point's column name
|
||||
*/
|
||||
public String getColumnName() {
|
||||
public String getColumnName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after the website graphs have been updated
|
||||
*/
|
||||
public void reset() {
|
||||
public void reset()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
public int hashCode()
|
||||
{
|
||||
return getColumnName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
if (!(object instanceof Plotter)) {
|
||||
public boolean equals(final Object object)
|
||||
{
|
||||
if (!(object instanceof Plotter))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final Plotter plotter = (Plotter) object;
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user