Convert back to maven

This commit is contained in:
BuildTools 2016-05-10 03:28:38 +12:00
parent 6776a9b427
commit d390adde38
301 changed files with 6503 additions and 2970 deletions

20
.classpath Normal file
View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LibsDisguises</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
encoding/src=UTF-8

View File

@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -1,95 +0,0 @@
plugins {
id 'java'
id 'maven-publish'
}
println 'Compiling LibsDisguises via Gradle ver. ' + gradle.gradleVersion
sourceCompatibility = '1.7'
ext.spigotVersion = '1.9-R0.1-SNAPSHOT'
ext.disguisesVersion = '9.0.3'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
mavenCentral()
maven {
name 'Spigot'
url 'https://hub.spigotmc.org/nexus/content/groups/public/'
}
maven {
url 'https://oss.sonatype.org/content/groups/public/'
}
maven {
name 'dmulloy2-repo'
url 'http://repo.dmulloy2.net/content/groups/public/'
}
flatDir {
dir 'libs'
}
}
task sourceJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
jar {
baseName "LibsDisguises"
}
processResources {
expand projectVersion: disguisesVersion
}
artifacts {
archives sourceJar
archives javadocJar
archives jar
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId 'LibsDisguises'
artifactId 'LibsDisguises'
version disguisesVersion + '-SNAPSHOT'
from components.java
artifact sourceJar {
classifier = 'sources'
}
artifact javadocJar {
classifier = 'javadoc'
}
}
}
repositories {
maven {
url "http://repo.md-5.net/content/repositories/releases/"
}
maven {
url "http://repo.md-5.net/content/repositories/snapshots/"
}
}
}
file('libs').mkdirs()
ant.get src: 'http://server.o2gaming.com/downloads/spigot-1.9.jar', dest: file('libs'), verbose: false, skipexisting: true
dependencies {
compile "org.spigotmc:spigot-api:$project.ext.spigotVersion"
compile 'com.comphenix.protocol:ProtocolLib:3.7.0-SNAPSHOT'
compile group: "spigot", name: 'spigot-1.9', version: "1.9"
testCompile group: 'junit', name: 'junit', version: '4.10'
}

130
config.yml Normal file
View File

@ -0,0 +1,130 @@
# 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

103
plugin.yml Normal file
View File

@ -0,0 +1,103 @@
name: LibsDisguises
main: me.libraryaddict.disguise.LibsDisguises
description: A disguise plugin with various disguises.
version: ${project.version}
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

74
pom.xml Normal file
View File

@ -0,0 +1,74 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>LibsDisguises</groupId>
<artifactId>LibsDisguises</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<defaultGoal>clean install</defaultGoal>
<directory>target</directory>
<finalName>LibsDisguises</finalName>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${project.basedir}</directory>
<includes>
<include>plugin.yml</include>
<include>config.yml</include>
<include>README.md</include>
</includes>
</resource>
</resources>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/content/groups/public/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.9.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.9.2-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>md_5-releases</id>
<url>http://repo.md-5.net/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>md_5-snapshots</id>
<url>http://repo.md-5.net/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>

View File

@ -1 +0,0 @@
rootProject.name = 'LibsDisguises'

View File

@ -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, " ");
}
}

View File

@ -1,5 +1,24 @@
package me.libraryaddict.disguise; 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.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
@ -13,120 +32,158 @@ import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.bukkit.DyeColor;
import org.bukkit.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; public class DisguiseAPI
import java.util.Arrays; {
import java.util.Collection; public static Disguise constructDisguise(Entity entity)
import java.util.List; {
import java.util.UUID;
public class DisguiseAPI {
public static Disguise constructDisguise(Entity entity) {
return constructDisguise(entity, true, true, true); 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); DisguiseType disguiseType = DisguiseType.getType(entity);
Disguise disguise; Disguise disguise;
if (disguiseType.isMisc()) {
if (disguiseType.isMisc())
{
disguise = new MiscDisguise(disguiseType); disguise = new MiscDisguise(disguiseType);
} else if (disguiseType.isMob()) { }
else if (disguiseType.isMob())
{
disguise = new MobDisguise(disguiseType); disguise = new MobDisguise(disguiseType);
} else { }
else
{
disguise = new PlayerDisguise(entity.getName()); disguise = new PlayerDisguise(entity.getName());
} }
FlagWatcher watcher = disguise.getWatcher(); 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()); ((LivingWatcher) watcher).addPotionEffect(effect.getType());
if (effect.getType() == PotionEffectType.INVISIBILITY) {
if (effect.getType() == PotionEffectType.INVISIBILITY)
{
watcher.setInvisible(true); watcher.setInvisible(true);
} else if (effect.getType() == PotionEffectType.GLOWING) { }
else if (effect.getType() == PotionEffectType.GLOWING)
{
watcher.setGlowing(true); watcher.setGlowing(true);
} }
} }
} }
if (entity.getFireTicks() > 0) {
if (entity.getFireTicks() > 0)
{
watcher.setBurning(true); watcher.setBurning(true);
} }
if (doEquipment && entity instanceof LivingEntity) {
if (doEquipment && entity instanceof LivingEntity)
{
EntityEquipment equip = ((LivingEntity) entity).getEquipment(); EntityEquipment equip = ((LivingEntity) entity).getEquipment();
watcher.setArmor(equip.getArmorContents()); watcher.setArmor(equip.getArmorContents());
watcher.setItemInMainHand(equip.getItemInMainHand()); watcher.setItemInMainHand(equip.getItemInMainHand());
if (disguiseType.getEntityType() == EntityType.HORSE) {
if (disguiseType.getEntityType() == EntityType.HORSE)
{
Horse horse = (Horse) entity; Horse horse = (Horse) entity;
HorseInventory horseInventory = horse.getInventory(); HorseInventory horseInventory = horse.getInventory();
ItemStack saddle = horseInventory.getSaddle(); ItemStack saddle = horseInventory.getSaddle();
if (saddle != null && saddle.getType() == Material.SADDLE) {
if (saddle != null && saddle.getType() == Material.SADDLE)
{
((HorseWatcher) watcher).setSaddled(true); ((HorseWatcher) watcher).setSaddled(true);
} }
((HorseWatcher) watcher).setHorseArmor(horseInventory.getArmor()); ((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")) 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(); 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; methodReturn = double.class;
} }
int firstCapitalMethod = firstCapital(method.getName()); 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 if (!watcherMethod.getName().startsWith("get") && watcherMethod.getReturnType() == void.class
&& watcherMethod.getParameterTypes().length == 1) { && watcherMethod.getParameterTypes().length == 1)
{
int firstCapitalWatcher = firstCapital(watcherMethod.getName()); int firstCapitalWatcher = firstCapital(watcherMethod.getName());
if (firstCapitalWatcher > 0
&& method.getName().substring(firstCapitalMethod) if (firstCapitalWatcher > 0 && method.getName().substring(firstCapitalMethod)
.equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher))) { .equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher)))
{
Class methodParam = watcherMethod.getParameterTypes()[0]; 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; methodParam = double.class;
} else if (methodParam == AnimalColor.class) { }
else if (methodParam == AnimalColor.class)
{
methodParam = DyeColor.class; methodParam = DyeColor.class;
} }
if (methodReturn == methodParam) { if (methodReturn == methodParam)
try { {
try
{
Object value = method.invoke(entity); Object value = method.invoke(entity);
if (value != null) { if (value != null)
{
Class toCast = watcherMethod.getParameterTypes()[0]; Class toCast = watcherMethod.getParameterTypes()[0];
if (!(toCast.isInstance(value))) { if (!(toCast.isInstance(value)))
if (toCast == float.class) { {
if (value instanceof Float) { if (toCast == float.class)
{
if (value instanceof Float)
{
value = value; value = value;
} else { }
else
{
double d = (Double) value; double d = (Double) value;
value = (float) d; 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; float d = (Float) value;
value = (double) d; value = (double) d;
} }
} else if (toCast == AnimalColor.class) { }
else if (toCast == AnimalColor.class)
{
value = AnimalColor.valueOf(((DyeColor) value).name()); value = AnimalColor.valueOf(((DyeColor) value).name());
} }
} }
if (value instanceof Boolean && !(Boolean) value if (value instanceof Boolean && !(Boolean) value
&& watcherMethod.getDeclaringClass() == FlagWatcher.class) { && watcherMethod.getDeclaringClass() == FlagWatcher.class)
{
continue; continue;
} }
} }
watcherMethod.invoke(watcher, value); watcherMethod.invoke(watcher, value);
} catch (Exception ex) { }
catch (Exception ex)
{
ex.printStackTrace(System.out); ex.printStackTrace(System.out);
} }
} }
@ -139,54 +196,73 @@ public class DisguiseAPI {
return disguise; 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 // If they are trying to disguise a null entity or use a null disguise
// Just return. // Just return.
if (entity == null || disguise == null) { if (entity == null || disguise == null)
{
return; return;
} }
// The event wasn't cancelled. // The event wasn't cancelled.
// If the disguise entity isn't the same as the one we are disguising // If the disguise entity isn't the same as the one we are disguising
if (disguise.getEntity() != entity) { if (disguise.getEntity() != entity)
{
// If the disguise entity actually exists // If the disguise entity actually exists
if (disguise.getEntity() != null) { if (disguise.getEntity() != null)
{
// Clone the disguise // Clone the disguise
disguise = disguise.clone(); disguise = disguise.clone();
} }
// Set the disguise's entity // Set the disguise's entity
disguise.setEntity(entity); disguise.setEntity(entity);
} }
if (Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId())) {
if (Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId()))
{
disguise.setViewSelfDisguise(true); disguise.setViewSelfDisguise(true);
} }
disguise.startDisguise(); disguise.startDisguise();
} }
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) { public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise)
if (disguise.getEntity() != null) { {
if (disguise.getEntity() != null)
{
disguise = disguise.clone(); disguise = disguise.clone();
} }
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS); ((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); ((TargetedDisguise) disguise).addPlayer((String) obj);
} else if (obj instanceof Player) { }
else if (obj instanceof Player)
{
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName()); ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
} }
} }
disguiseEntity(entity, disguise); disguiseEntity(entity, disguise);
} }
@Deprecated @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); 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)); 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)); disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise));
} }
@ -196,20 +272,29 @@ public class DisguiseAPI {
* @param disguise * @param disguise
* @return * @return
*/ */
public static int disguiseNextEntity(Disguise disguise) { public static int disguiseNextEntity(Disguise disguise)
if (disguise == null) { {
if (disguise == null)
{
return -1; return -1;
} }
if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) {
if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise))
{
disguise = disguise.clone(); disguise = disguise.clone();
} }
try {
try
{
int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null); int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null);
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise); DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
return id; return id;
} catch (IllegalAccessException e) { }
catch (IllegalAccessException e)
{
e.printStackTrace(); e.printStackTrace();
} }
return -1; return -1;
} }
@ -219,52 +304,73 @@ public class DisguiseAPI {
* @param entity * @param entity
* @param disguise * @param disguise
*/ */
public static void disguiseToAll(Entity entity, Disguise disguise) { public static void disguiseToAll(Entity entity, Disguise disguise)
if (disguise.getEntity() != null) { {
if (disguise.getEntity() != null)
{
disguise = disguise.clone(); disguise = disguise.clone();
} }
// You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!! // You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS); ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
for (String observer : ((TargetedDisguise) disguise).getObservers()) {
for (String observer : ((TargetedDisguise) disguise).getObservers())
{
((TargetedDisguise) disguise).removePlayer(observer); ((TargetedDisguise) disguise).removePlayer(observer);
} }
disguiseEntity(entity, disguise); disguiseEntity(entity, disguise);
} }
public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise) { public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise)
if (disguise.getEntity() != null) { {
if (disguise.getEntity() != null)
{
disguise = disguise.clone(); disguise = disguise.clone();
} }
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS); ((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); ((TargetedDisguise) disguise).addPlayer((String) obj);
} else if (obj instanceof Player) { }
else if (obj instanceof Player)
{
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName()); ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
} }
} }
disguiseEntity(entity, disguise); disguiseEntity(entity, disguise);
} }
@Deprecated @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); 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)); 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)); disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise));
} }
private static int firstCapital(String str) { private static int firstCapital(String str)
for (int i = 0; i < str.length(); i++) { {
if (Character.isUpperCase(str.charAt(i))) { for (int i = 0; i < str.length(); i++)
{
if (Character.isUpperCase(str.charAt(i)))
{
return i; return i;
} }
} }
return -1; return -1;
} }
@ -274,10 +380,13 @@ public class DisguiseAPI {
* @param disguised * @param disguised
* @return * @return
*/ */
public static Disguise getDisguise(Entity disguised) { public static Disguise getDisguise(Entity disguised)
if (disguised == null) { {
if (disguised == null)
{
return null; return null;
} }
return DisguiseUtilities.getMainDisguise(disguised.getUniqueId()); return DisguiseUtilities.getMainDisguise(disguised.getUniqueId());
} }
@ -288,10 +397,13 @@ public class DisguiseAPI {
* @param disguised * @param disguised
* @return * @return
*/ */
public static Disguise getDisguise(Player observer, Entity disguised) { public static Disguise getDisguise(Player observer, Entity disguised)
if (disguised == null || observer == null) { {
if (disguised == null || observer == null)
{
return null; return null;
} }
return DisguiseUtilities.getDisguise(observer, disguised); return DisguiseUtilities.getDisguise(observer, disguised);
} }
@ -301,10 +413,13 @@ public class DisguiseAPI {
* @param disguised * @param disguised
* @return * @return
*/ */
public static Disguise[] getDisguises(Entity disguised) { public static Disguise[] getDisguises(Entity disguised)
if (disguised == null) { {
if (disguised == null)
{
return null; return null;
} }
return DisguiseUtilities.getDisguises(disguised.getUniqueId()); return DisguiseUtilities.getDisguises(disguised.getUniqueId());
} }
@ -315,11 +430,13 @@ public class DisguiseAPI {
* @return * @return
*/ */
@Deprecated @Deprecated
public static int getFakeDisguise(UUID entityId) { public static int getFakeDisguise(UUID entityId)
{
return -10; return -10;
} }
public static int getSelfDisguiseId() { public static int getSelfDisguiseId()
{
return -10; return -10;
} }
@ -329,7 +446,8 @@ public class DisguiseAPI {
* @param disguised * @param disguised
* @return * @return
*/ */
public static boolean isDisguised(Entity disguised) { public static boolean isDisguised(Entity disguised)
{
return getDisguise(disguised) != null; return getDisguise(disguised) != null;
} }
@ -340,15 +458,18 @@ public class DisguiseAPI {
* @param disguised * @param disguised
* @return * @return
*/ */
public static boolean isDisguised(Player observer, Entity disguised) { public static boolean isDisguised(Player observer, Entity disguised)
{
return getDisguise(observer, disguised) != null; return getDisguise(observer, disguised) != null;
} }
public static boolean isDisguiseInUse(Disguise disguise) { public static boolean isDisguiseInUse(Disguise disguise)
{
return disguise.isDisguiseInUse(); return disguise.isDisguiseInUse();
} }
public static boolean isSelfDisguised(Player player) { public static boolean isSelfDisguised(Player player)
{
return DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId()); return DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId());
} }
@ -358,18 +479,24 @@ public class DisguiseAPI {
* @param entity * @param entity
* @return * @return
*/ */
public static boolean isViewSelfToggled(Entity entity) { public static boolean isViewSelfToggled(Entity entity)
return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible() : Disguise.getViewSelf().contains(entity.getUniqueId()); {
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 * @param entity
*/ */
public static void undisguiseToAll(Entity entity) { public static void undisguiseToAll(Entity entity)
{
Disguise[] disguises = getDisguises(entity); Disguise[] disguises = getDisguises(entity);
for (Disguise disguise : disguises) {
for (Disguise disguise : disguises)
{
disguise.removeDisguise(); disguise.removeDisguise();
} }
} }
@ -380,20 +507,28 @@ public class DisguiseAPI {
* @param entity * @param entity
* @param toggled * @param toggled
*/ */
public static void setViewDisguiseToggled(Entity entity, boolean toggled) { public static void setViewDisguiseToggled(Entity entity, boolean toggled)
if (isDisguised(entity)) { {
if (isDisguised(entity))
{
Disguise disguise = getDisguise(entity); Disguise disguise = getDisguise(entity);
disguise.setViewSelfDisguise(toggled); disguise.setViewSelfDisguise(toggled);
} }
if (toggled) {
if (!Disguise.getViewSelf().contains(entity.getUniqueId())) { if (toggled)
{
if (!Disguise.getViewSelf().contains(entity.getUniqueId()))
{
Disguise.getViewSelf().add(entity.getUniqueId()); Disguise.getViewSelf().add(entity.getUniqueId());
} }
} else { }
else
{
Disguise.getViewSelf().remove(entity.getUniqueId()); Disguise.getViewSelf().remove(entity.getUniqueId());
} }
} }
private DisguiseAPI() { private DisguiseAPI()
{
} }
} }

View File

@ -1,10 +1,12 @@
package me.libraryaddict.disguise; package me.libraryaddict.disguise;
import me.libraryaddict.disguise.utilities.PacketsManager;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class DisguiseConfig { import me.libraryaddict.disguise.utilities.PacketsManager;
public class DisguiseConfig
{
private static boolean animationEnabled; private static boolean animationEnabled;
private static boolean bedEnabled; private static boolean bedEnabled;
@ -43,34 +45,43 @@ public class DisguiseConfig {
private static String updateNotificationPermission; private static String updateNotificationPermission;
private static boolean witherSkullEnabled; private static boolean witherSkullEnabled;
public static String getDisguiseBlownMessage() { public static String getDisguiseBlownMessage()
{
return disguiseBlownMessage; return disguiseBlownMessage;
} }
public static int getDisguiseCloneExpire() { public static int getDisguiseCloneExpire()
{
return disguiseCloneExpire; return disguiseCloneExpire;
} }
public static int getDisguiseEntityExpire() { public static int getDisguiseEntityExpire()
{
return disguiseEntityExpire; return disguiseEntityExpire;
} }
public static int getMaxClonedDisguises() { public static int getMaxClonedDisguises()
{
return maxClonedDisguises; return maxClonedDisguises;
} }
public static String getUpdateMessage() { public static String getUpdateMessage()
{
return updateMessage; return updateMessage;
} }
public static String getUpdateNotificationPermission() { public static String getUpdateNotificationPermission()
{
return updateNotificationPermission; return updateNotificationPermission;
} }
public static void initConfig(ConfigurationSection config) { public static void initConfig(ConfigurationSection config)
{
setSoundsEnabled(config.getBoolean("DisguiseSounds")); setSoundsEnabled(config.getBoolean("DisguiseSounds"));
setVelocitySent(config.getBoolean("SendVelocity")); 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); PacketsManager.setViewDisguisesListener(true);
setHearSelfDisguise(config.getBoolean("HearSelfDisguise")); setHearSelfDisguise(config.getBoolean("HearSelfDisguise"));
setHideArmorFromSelf(config.getBoolean("RemoveArmor")); setHideArmorFromSelf(config.getBoolean("RemoveArmor"));
@ -105,19 +116,23 @@ public class DisguiseConfig {
setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true)); setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true));
} }
public static boolean isAnimationPacketsEnabled() { public static boolean isAnimationPacketsEnabled()
{
return animationEnabled; return animationEnabled;
} }
public static boolean isBedPacketsEnabled() { public static boolean isBedPacketsEnabled()
{
return bedEnabled; return bedEnabled;
} }
public static boolean isCollectPacketsEnabled() { public static boolean isCollectPacketsEnabled()
{
return collectEnabled; return collectEnabled;
} }
public static boolean isDisguiseBlownOnAttack() { public static boolean isDisguiseBlownOnAttack()
{
return blowDisguisesOnAttack; return blowDisguisesOnAttack;
} }
@ -125,96 +140,117 @@ public class DisguiseConfig {
* @deprecated Spelling mistake. * @deprecated Spelling mistake.
*/ */
@Deprecated @Deprecated
public static boolean isEnquipmentPacketsEnabled() { public static boolean isEnquipmentPacketsEnabled()
{
return equipmentEnabled; return equipmentEnabled;
} }
public static boolean isEntityAnimationsAdded() { public static boolean isEntityAnimationsAdded()
{
return entityAnimationsAdded; return entityAnimationsAdded;
} }
public static boolean isEntityStatusPacketsEnabled() { public static boolean isEntityStatusPacketsEnabled()
{
return entityStatusEnabled; return entityStatusEnabled;
} }
public static boolean isEquipmentPacketsEnabled() { public static boolean isEquipmentPacketsEnabled()
{
return equipmentEnabled; return equipmentEnabled;
} }
/** /**
* Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around * 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; return hidingArmor;
} }
/** /**
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise * 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; return hidingHeldItem;
} }
public static boolean isKeepDisguiseOnEntityDespawn() { public static boolean isKeepDisguiseOnEntityDespawn()
{
return keepDisguiseEntityDespawn; return keepDisguiseEntityDespawn;
} }
public static boolean isKeepDisguiseOnPlayerDeath() { public static boolean isKeepDisguiseOnPlayerDeath()
{
return keepDisguisePlayerDeath; return keepDisguisePlayerDeath;
} }
public static boolean isKeepDisguiseOnPlayerLogout() { public static boolean isKeepDisguiseOnPlayerLogout()
{
return keepDisguisePlayerLogout; return keepDisguisePlayerLogout;
} }
public static boolean isMaxHealthDeterminedByDisguisedEntity() { public static boolean isMaxHealthDeterminedByDisguisedEntity()
{
return maxHealthIsDisguisedEntity; return maxHealthIsDisguisedEntity;
} }
public static boolean isMetadataPacketsEnabled() { public static boolean isMetadataPacketsEnabled()
{
return sendsEntityMetadata; return sendsEntityMetadata;
} }
public static boolean isMiscDisguisesForLivingEnabled() { public static boolean isMiscDisguisesForLivingEnabled()
{
return miscDisguisesForLivingEnabled; return miscDisguisesForLivingEnabled;
} }
public static boolean isModifyBoundingBox() { public static boolean isModifyBoundingBox()
{
return modifyBoundingBox; return modifyBoundingBox;
} }
public static boolean isMonstersIgnoreDisguises() { public static boolean isMonstersIgnoreDisguises()
{
return targetDisguises; return targetDisguises;
} }
public static boolean isMovementPacketsEnabled() { public static boolean isMovementPacketsEnabled()
{
return movementEnabled; return movementEnabled;
} }
public static boolean isNameAboveHeadAlwaysVisible() { public static boolean isNameAboveHeadAlwaysVisible()
{
return showNameAboveHeadAlwaysVisible; return showNameAboveHeadAlwaysVisible;
} }
public static boolean isNameOfPlayerShownAboveDisguise() { public static boolean isNameOfPlayerShownAboveDisguise()
{
return showNameAboveHead; return showNameAboveHead;
} }
public static boolean isSelfDisguisesSoundsReplaced() { public static boolean isSelfDisguisesSoundsReplaced()
{
return hearSelfDisguise; return hearSelfDisguise;
} }
public static boolean isSheepDyeable() { public static boolean isSheepDyeable()
{
return colorizeSheep; return colorizeSheep;
} }
/** /**
* Is the sound packets caught and modified * Is the sound packets caught and modified
*/ */
public static boolean isSoundEnabled() { public static boolean isSoundEnabled()
{
return PacketsManager.isHearDisguisesEnabled(); return PacketsManager.isHearDisguisesEnabled();
} }
public static boolean isUndisguiseOnWorldChange() { public static boolean isUndisguiseOnWorldChange()
{
return undisguiseSwitchWorlds; return undisguiseSwitchWorlds;
} }
@ -223,7 +259,8 @@ public class DisguiseConfig {
* *
* @return * @return
*/ */
public static boolean isVelocitySent() { public static boolean isVelocitySent()
{
return sendVelocity; return sendVelocity;
} }
@ -232,74 +269,98 @@ public class DisguiseConfig {
* *
* @return * @return
*/ */
public static boolean isViewDisguises() { public static boolean isViewDisguises()
{
return viewSelfDisguise; return viewSelfDisguise;
} }
public static boolean isWitherSkullPacketsEnabled() { public static boolean isWitherSkullPacketsEnabled()
{
return witherSkullEnabled; return witherSkullEnabled;
} }
public static boolean isWolfDyeable() { public static boolean isWolfDyeable()
{
return colorizeWolf; return colorizeWolf;
} }
public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) { public static void setAddEntityAnimations(boolean isEntityAnimationsAdded)
{
entityAnimationsAdded = isEntityAnimationsAdded; entityAnimationsAdded = isEntityAnimationsAdded;
} }
public static void setAnimationPacketsEnabled(boolean enabled) { public static void setAnimationPacketsEnabled(boolean enabled)
if (enabled != isAnimationPacketsEnabled()) { {
if (enabled != isAnimationPacketsEnabled())
{
animationEnabled = enabled; animationEnabled = enabled;
PacketsManager.setupMainPacketsListener(); PacketsManager.setupMainPacketsListener();
} }
} }
public static void setBedPacketsEnabled(boolean enabled) { public static void setBedPacketsEnabled(boolean enabled)
if (enabled != isBedPacketsEnabled()) { {
if (enabled != isBedPacketsEnabled())
{
bedEnabled = enabled; bedEnabled = enabled;
PacketsManager.setupMainPacketsListener(); PacketsManager.setupMainPacketsListener();
} }
} }
public static void setCollectPacketsEnabled(boolean enabled) { public static void setCollectPacketsEnabled(boolean enabled)
if (enabled != isCollectPacketsEnabled()) { {
if (enabled != isCollectPacketsEnabled())
{
collectEnabled = enabled; collectEnabled = enabled;
PacketsManager.setupMainPacketsListener(); PacketsManager.setupMainPacketsListener();
} }
} }
public static void setDisguiseBlownMessage(String newMessage) { public static void setDisguiseBlownMessage(String newMessage)
{
disguiseBlownMessage = newMessage; disguiseBlownMessage = newMessage;
} }
public static void setDisguiseBlownOnAttack(boolean blowDisguise) { public static void setDisguiseBlownOnAttack(boolean blowDisguise)
{
blowDisguisesOnAttack = blowDisguise; blowDisguisesOnAttack = blowDisguise;
} }
public static void setDisguiseCloneExpire(int newExpires) { public static void setDisguiseCloneExpire(int newExpires)
{
disguiseCloneExpire = newExpires; disguiseCloneExpire = newExpires;
} }
public static void setDisguiseEntityExpire(int newExpires) { public static void setDisguiseEntityExpire(int newExpires)
{
disguiseEntityExpire = newExpires; disguiseEntityExpire = newExpires;
} }
@Deprecated @Deprecated
public static void setEnquipmentPacketsEnabled(boolean enabled) { public static void setEnquipmentPacketsEnabled(boolean enabled)
{
setEquipmentPacketsEnabled(enabled); setEquipmentPacketsEnabled(enabled);
} }
public static void setEntityStatusPacketsEnabled(boolean enabled) { public static void setEntityStatusPacketsEnabled(boolean enabled)
if (enabled != isEntityStatusPacketsEnabled()) { {
if (enabled != isEntityStatusPacketsEnabled())
{
entityStatusEnabled = enabled; entityStatusEnabled = enabled;
PacketsManager.setupMainPacketsListener(); PacketsManager.setupMainPacketsListener();
} }
} }
public static void setEquipmentPacketsEnabled(boolean enabled) { public static void setEquipmentPacketsEnabled(boolean enabled)
if (enabled != isEquipmentPacketsEnabled()) { {
if (enabled != isEquipmentPacketsEnabled())
{
equipmentEnabled = enabled; equipmentEnabled = enabled;
PacketsManager.setupMainPacketsListener(); PacketsManager.setupMainPacketsListener();
} }
} }
@ -307,8 +368,10 @@ public class DisguiseConfig {
/** /**
* Can players hear their own disguises * Can players hear their own disguises
*/ */
public static void setHearSelfDisguise(boolean replaceSound) { public static void setHearSelfDisguise(boolean replaceSound)
if (hearSelfDisguise != replaceSound) { {
if (hearSelfDisguise != replaceSound)
{
hearSelfDisguise = replaceSound; hearSelfDisguise = replaceSound;
} }
} }
@ -316,9 +379,12 @@ public class DisguiseConfig {
/** /**
* Set the plugin to hide self disguises armor from theirselves * Set the plugin to hide self disguises armor from theirselves
*/ */
public static void setHideArmorFromSelf(boolean hideArmor) { public static void setHideArmorFromSelf(boolean hideArmor)
if (hidingArmor != hideArmor) { {
if (hidingArmor != hideArmor)
{
hidingArmor = hideArmor; hidingArmor = hideArmor;
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf()); 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 * 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) { public static void setHideHeldItemFromSelf(boolean hideHelditem)
if (hidingHeldItem != hideHelditem) { {
if (hidingHeldItem != hideHelditem)
{
hidingHeldItem = hideHelditem; hidingHeldItem = hideHelditem;
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf()); PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
} }
} }
public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) { public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise)
{
keepDisguiseEntityDespawn = keepDisguise; keepDisguiseEntityDespawn = keepDisguise;
} }
public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) { public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise)
{
keepDisguisePlayerDeath = keepDisguise; keepDisguisePlayerDeath = keepDisguise;
} }
public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) { public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise)
{
keepDisguisePlayerLogout = keepDisguise; keepDisguisePlayerLogout = keepDisguise;
} }
public static void setMaxClonedDisguises(int newMax) { public static void setMaxClonedDisguises(int newMax)
{
maxClonedDisguises = newMax; maxClonedDisguises = newMax;
} }
public static void setMaxHealthDeterminedByDisguisedEntity(boolean isDetermined) { public static void setMaxHealthDeterminedByDisguisedEntity(boolean isDetermined)
{
maxHealthIsDisguisedEntity = isDetermined; maxHealthIsDisguisedEntity = isDetermined;
} }
public static void setMetadataPacketsEnabled(boolean enabled) { public static void setMetadataPacketsEnabled(boolean enabled)
{
sendsEntityMetadata = enabled; sendsEntityMetadata = enabled;
} }
public static void setMiscDisguisesForLivingEnabled(boolean enabled) { public static void setMiscDisguisesForLivingEnabled(boolean enabled)
if (enabled != isMiscDisguisesForLivingEnabled()) { {
if (enabled != isMiscDisguisesForLivingEnabled())
{
miscDisguisesForLivingEnabled = enabled; miscDisguisesForLivingEnabled = enabled;
PacketsManager.setupMainPacketsListener(); PacketsManager.setupMainPacketsListener();
} }
} }
public static void setModifyBoundingBox(boolean modifyBounding) { public static void setModifyBoundingBox(boolean modifyBounding)
{
modifyBoundingBox = modifyBounding; modifyBoundingBox = modifyBounding;
} }
public static void setMonstersIgnoreDisguises(boolean ignore) { public static void setMonstersIgnoreDisguises(boolean ignore)
{
targetDisguises = ignore; targetDisguises = ignore;
} }
public static void setMovementPacketsEnabled(boolean enabled) { public static void setMovementPacketsEnabled(boolean enabled)
if (enabled != isMovementPacketsEnabled()) { {
if (enabled != isMovementPacketsEnabled())
{
movementEnabled = enabled; movementEnabled = enabled;
PacketsManager.setupMainPacketsListener(); PacketsManager.setupMainPacketsListener();
} }
} }
public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) { public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible)
{
showNameAboveHeadAlwaysVisible = alwaysVisible; showNameAboveHeadAlwaysVisible = alwaysVisible;
} }
public static void setNameOfPlayerShownAboveDisguise(boolean showNames) { public static void setNameOfPlayerShownAboveDisguise(boolean showNames)
{
showNameAboveHead = showNames; showNameAboveHead = showNames;
} }
public static void setSheepDyeable(boolean color) { public static void setSheepDyeable(boolean color)
{
colorizeSheep = color; colorizeSheep = color;
} }
/** /**
* Set if the disguises play sounds when hurt * Set if the disguises play sounds when hurt
*/ */
public static void setSoundsEnabled(boolean isSoundsEnabled) { public static void setSoundsEnabled(boolean isSoundsEnabled)
{
PacketsManager.setHearDisguisesListener(isSoundsEnabled); PacketsManager.setHearDisguisesListener(isSoundsEnabled);
} }
public static void setUndisguiseOnWorldChange(boolean isUndisguise) { public static void setUndisguiseOnWorldChange(boolean isUndisguise)
{
undisguiseSwitchWorlds = isUndisguise; undisguiseSwitchWorlds = isUndisguise;
} }
public static void setUpdateMessage(String newMessage) { public static void setUpdateMessage(String newMessage)
{
updateMessage = newMessage; updateMessage = newMessage;
} }
public static void setUpdateNotificationPermission(String newPermission) { public static void setUpdateNotificationPermission(String newPermission)
{
updateNotificationPermission = newPermission; updateNotificationPermission = newPermission;
} }
public static void setStopShulkerDisguisesFromMoving(boolean stopShulkerDisguisesFromMoving) { public static void setStopShulkerDisguisesFromMoving(boolean stopShulkerDisguisesFromMoving)
{
DisguiseConfig.stopShulkerDisguisesFromMoving = stopShulkerDisguisesFromMoving; DisguiseConfig.stopShulkerDisguisesFromMoving = stopShulkerDisguisesFromMoving;
} }
public static boolean isStopShulkerDisguisesFromMoving() { public static boolean isStopShulkerDisguisesFromMoving()
{
return stopShulkerDisguisesFromMoving; return stopShulkerDisguisesFromMoving;
} }
@ -423,22 +515,27 @@ public class DisguiseConfig {
* *
* @param sendVelocityPackets * @param sendVelocityPackets
*/ */
public static void setVelocitySent(boolean sendVelocityPackets) { public static void setVelocitySent(boolean sendVelocityPackets)
{
sendVelocity = sendVelocityPackets; sendVelocity = sendVelocityPackets;
} }
public static void setViewDisguises(boolean seeOwnDisguise) { public static void setViewDisguises(boolean seeOwnDisguise)
{
viewSelfDisguise = seeOwnDisguise; viewSelfDisguise = seeOwnDisguise;
} }
public static void setWitherSkullPacketsEnabled(boolean enabled) { public static void setWitherSkullPacketsEnabled(boolean enabled)
{
witherSkullEnabled = enabled; witherSkullEnabled = enabled;
} }
public static void setWolfDyeable(boolean color) { public static void setWolfDyeable(boolean color)
{
colorizeWolf = color; colorizeWolf = color;
} }
private DisguiseConfig() { private DisguiseConfig()
{
} }
} }

View File

@ -1,15 +1,9 @@
package me.libraryaddict.disguise; package me.libraryaddict.disguise;
import com.comphenix.protocol.ProtocolLibrary; import java.lang.reflect.InvocationTargetException;
import com.comphenix.protocol.events.PacketContainer; import java.util.HashMap;
import me.libraryaddict.disguise.disguisetypes.Disguise; import java.util.HashSet;
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 org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -33,9 +27,17 @@ import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.lang.reflect.InvocationTargetException; import com.comphenix.protocol.ProtocolLibrary;
import java.util.HashMap; import com.comphenix.protocol.events.PacketContainer;
import java.util.HashSet;
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 { public class DisguiseListener implements Listener {

View File

@ -1,8 +1,22 @@
package me.libraryaddict.disguise; 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.reflect.FieldAccessException;
import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedWatchableObject; import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import me.libraryaddict.disguise.commands.CloneDisguiseCommand; import me.libraryaddict.disguise.commands.CloneDisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseCommand; import me.libraryaddict.disguise.commands.DisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseViewSelf; 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.Metrics;
import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager; 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 static LibsDisguises instance;
private DisguiseListener listener; private DisguiseListener listener;
@Override @Override
public void onEnable() { public void onEnable()
{
getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion()); getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion());
saveDefaultConfig(); saveDefaultConfig();
PacketsManager.init(this); PacketsManager.init(this);
DisguiseUtilities.init(this); DisguiseUtilities.init(this);
DisguiseConfig.initConfig(getConfig()); DisguiseConfig.initConfig(getConfig());
PacketsManager.addPacketListeners(); PacketsManager.addPacketListeners();
listener = new DisguiseListener(this); listener = new DisguiseListener(this);
Bukkit.getPluginManager().registerEvents(listener, this); Bukkit.getPluginManager().registerEvents(listener, this);
getCommand("disguise").setExecutor(new DisguiseCommand()); getCommand("disguise").setExecutor(new DisguiseCommand());
getCommand("undisguise").setExecutor(new UndisguiseCommand()); getCommand("undisguise").setExecutor(new UndisguiseCommand());
getCommand("disguiseplayer").setExecutor(new PlayerDisguiseCommand()); getCommand("disguiseplayer").setExecutor(new PlayerDisguiseCommand());
@ -76,35 +83,51 @@ public class LibsDisguises extends JavaPlugin {
getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand()); getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand());
getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand()); getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand());
getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf()); getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf());
registerValues(); registerValues();
instance = this; instance = this;
try {
try
{
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
metrics.start(); metrics.start();
} catch (IOException e) { }
catch (IOException e)
{
} }
} }
/** /**
* Reloads the config with new config options. * Reloads the config with new config options.
*/ */
public void reload() { public void reload()
{
HandlerList.unregisterAll(listener); HandlerList.unregisterAll(listener);
reloadConfig(); reloadConfig();
DisguiseConfig.initConfig(getConfig()); 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() { private void registerValues()
for (DisguiseType disguiseType : DisguiseType.values()) { {
if (disguiseType.getEntityType() == null) { for (DisguiseType disguiseType : DisguiseType.values())
{
if (disguiseType.getEntityType() == null)
{
continue; continue;
} }
Class watcherClass = null; Class watcherClass = null;
try {
switch (disguiseType) { try
{
switch (disguiseType)
{
case ITEM_FRAME: // Not really supported... case ITEM_FRAME: // Not really supported...
break; break;
case MINECART_CHEST: case MINECART_CHEST:
@ -138,33 +161,52 @@ public class LibsDisguises extends JavaPlugin {
watcherClass = SkeletonWatcher.class; watcherClass = SkeletonWatcher.class;
break; break;
default: default:
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." watcherClass = Class.forName(
+ toReadable(disguiseType.name()) + "Watcher"); "me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher");
break; break;
} }
} catch (ClassNotFoundException ex) { }
catch (ClassNotFoundException ex)
{
// There is no explicit watcher for this entity. // There is no explicit watcher for this entity.
Class entityClass = disguiseType.getEntityType().getEntityClass(); Class entityClass = disguiseType.getEntityType().getEntityClass();
if (entityClass != null) {
if (Tameable.class.isAssignableFrom(entityClass)) { if (entityClass != null)
{
if (Tameable.class.isAssignableFrom(entityClass))
{
watcherClass = TameableWatcher.class; watcherClass = TameableWatcher.class;
} else if (Ageable.class.isAssignableFrom(entityClass)) { }
else if (Ageable.class.isAssignableFrom(entityClass))
{
watcherClass = AgeableWatcher.class; watcherClass = AgeableWatcher.class;
} else if (LivingEntity.class.isAssignableFrom(entityClass)) { }
else if (LivingEntity.class.isAssignableFrom(entityClass))
{
watcherClass = LivingWatcher.class; watcherClass = LivingWatcher.class;
} else { }
else
{
watcherClass = FlagWatcher.class; watcherClass = FlagWatcher.class;
} }
} else { }
else
{
watcherClass = FlagWatcher.class; // Disguise is unknown type watcherClass = FlagWatcher.class; // Disguise is unknown type
} }
} }
disguiseType.setWatcherClass(watcherClass); disguiseType.setWatcherClass(watcherClass);
if (DisguiseValues.getDisguiseValues(disguiseType) != null) {
if (DisguiseValues.getDisguiseValues(disguiseType) != null)
{
continue; continue;
} }
String nmsEntityName = toReadable(disguiseType.name()); String nmsEntityName = toReadable(disguiseType.name());
switch (disguiseType) {
switch (disguiseType)
{
case WITHER_SKELETON: case WITHER_SKELETON:
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
case DONKEY: case DONKEY:
@ -207,34 +249,56 @@ public class LibsDisguises extends JavaPlugin {
default: default:
break; break;
} }
try {
if (nmsEntityName.equalsIgnoreCase("Unknown")) { try
{
if (nmsEntityName.equalsIgnoreCase("Unknown"))
{
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0); DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0)); disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
if (sound != null) {
if (sound != null)
{
sound.setDamageAndIdleSoundVolume(1f); sound.setDamageAndIdleSoundVolume(1f);
} }
continue; continue;
} }
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName); Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
if (nmsEntity == null) {
if (nmsEntity == null)
{
getLogger().warning("Entity not found! (" + nmsEntityName + ")"); getLogger().warning("Entity not found! (" + nmsEntityName + ")");
continue; continue;
} }
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
int entitySize = 0; 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); Enum enumEntitySize = (Enum) field.get(nmsEntity);
entitySize = enumEntitySize.ordinal(); entitySize = enumEntitySize.ordinal();
break; break;
} }
} }
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize, DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize,
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0); bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
for (WrappedWatchableObject watch : watcher.getWatchableObjects())
{
disguiseValues.setMetaValue(watch.getIndex(), watch.getValue()); disguiseValues.setMetaValue(watch.getIndex(), watch.getValue());
// Uncomment when I need to find the new datawatcher values for a class.. // Uncomment when I need to find the new datawatcher values for a class..
// int id = watch.getIndex(); // int id = watch.getIndex();
@ -245,33 +309,47 @@ public class LibsDisguises extends JavaPlugin {
// } catch (Exception e) { // } catch (Exception e) {
// val = val != null ? val.getClass() : "null"; // val = val != null ? val.getClass() : "null";
// } // }
// System.out.println("Disguise: " + disguiseType + ", ID: " + id + ", Class: " + (val == null ? "null" : valClazz) + ", Value: " + val); // System.out.println("Disguise: " + disguiseType + ", ID: " + id + ", Class: " + (val == null ? "null" :
// valClazz) + ", Value: " + val);
} }
DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
if (sound != null) {
if (sound != null)
{
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity); Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
if (soundStrength != null) {
if (soundStrength != null)
{
sound.setDamageAndIdleSoundVolume(soundStrength); sound.setDamageAndIdleSoundVolume(soundStrength);
} }
} }
// Get the bounding box // Get the bounding box
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity)); disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
if (bukkitEntity instanceof Ageable) {
if (bukkitEntity instanceof Ageable)
{
((Ageable) bukkitEntity).setBaby(); ((Ageable) bukkitEntity).setBaby();
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} else if (bukkitEntity instanceof Zombie) {
((Zombie) bukkitEntity).setBaby(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} }
else if (bukkitEntity instanceof Zombie)
{
((Zombie) bukkitEntity).setBaby(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
disguiseValues.setEntitySize(ReflectionManager.getSize(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, " System.out.print("[LibsDisguises] Before reporting this error, "
+ "please make sure you are using the latest version of LibsDisguises and ProtocolLib."); + "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
System.out System.out.print("[LibsDisguises] Development builds are available at (ProtocolLib) "
.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+/"); + "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/");
ex.printStackTrace(System.out); ex.printStackTrace(System.out);
@ -279,25 +357,30 @@ public class LibsDisguises extends JavaPlugin {
} }
} }
private String toReadable(String string) { private String toReadable(String string)
{
StringBuilder builder = new StringBuilder(); 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()); builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase());
} }
return builder.toString(); return builder.toString();
} }
public DisguiseListener getListener() { public DisguiseListener getListener()
{
return listener; return listener;
} }
/** /**
* External APIs shouldn't actually need this instance. * External APIs shouldn't actually need this instance. DisguiseAPI should be enough to handle most cases.
* DisguiseAPI should be enough to handle most cases.
* *
* @return The instance of this plugin * @return The instance of this plugin
*/ */
public static LibsDisguises getInstance() { public static LibsDisguises getInstance()
{
return instance; return instance;
} }
} }

View File

@ -1,14 +1,13 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.disguisetypes.AnimalColor; import java.lang.reflect.InvocationTargetException;
import me.libraryaddict.disguise.disguisetypes.Disguise; import java.lang.reflect.Method;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import java.util.ArrayList;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import java.util.Arrays;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise; import java.util.Collections;
import me.libraryaddict.disguise.disguisetypes.MobDisguise; import java.util.HashMap;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import java.util.Map.Entry;
import me.libraryaddict.disguise.disguisetypes.RabbitType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -21,13 +20,15 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import java.lang.reflect.InvocationTargetException; import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import java.lang.reflect.Method; import me.libraryaddict.disguise.disguisetypes.Disguise;
import java.util.ArrayList; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import java.util.Arrays; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import java.util.Collections; import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
import java.util.HashMap; import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import java.util.Map.Entry; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.RabbitType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
/** /**

Some files were not shown because too many files have changed in this diff Show More