Added rudimentary support for disguising Custom Entities and Modded Entities
Added the DisguiseType 'Unknown', obviously can't be used by players Cleaned up code
This commit is contained in:
parent
d30ffa1994
commit
27cc9cd70f
@ -13,7 +13,7 @@ println 'Compiling LibsDisguises via Gradle ver. ' + gradle.gradleVersion
|
|||||||
sourceCompatibility = '1.7'
|
sourceCompatibility = '1.7'
|
||||||
ext.spigotVersion = '1.8.7-R0.1-SNAPSHOT'
|
ext.spigotVersion = '1.8.7-R0.1-SNAPSHOT'
|
||||||
|
|
||||||
ext.disguisesVersion = '8.5.1'
|
ext.disguisesVersion = '8.5.2'
|
||||||
|
|
||||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||||
|
|
||||||
|
@ -189,6 +189,8 @@ public class DisguiseAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
|
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
|
||||||
|
* @param disguise
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int disguiseNextEntity(Disguise disguise) {
|
public static int disguiseNextEntity(Disguise disguise) {
|
||||||
if (disguise == null)
|
if (disguise == null)
|
||||||
@ -202,7 +204,7 @@ public class DisguiseAPI {
|
|||||||
int id = field.getInt(null);
|
int id = field.getInt(null);
|
||||||
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
||||||
return id;
|
return id;
|
||||||
} catch (Exception ex) {
|
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
|
||||||
ex.printStackTrace(System.out);
|
ex.printStackTrace(System.out);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@ -210,6 +212,8 @@ public class DisguiseAPI {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Disguise this entity with this disguise
|
* Disguise this entity with this disguise
|
||||||
|
* @param entity
|
||||||
|
* @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) {
|
||||||
|
@ -197,7 +197,7 @@ public class DisguiseListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
disguiseRunnable.remove(p.getName()).cancel();
|
disguiseRunnable.remove(p.getName()).cancel();
|
||||||
Entity entity = event.getRightClicked();
|
Entity entity = event.getRightClicked();
|
||||||
String entityName = "";
|
String entityName;
|
||||||
if (entity instanceof Player && !disguiseClone.containsKey(p.getName())) {
|
if (entity instanceof Player && !disguiseClone.containsKey(p.getName())) {
|
||||||
entityName = ((Player) entity).getName();
|
entityName = ((Player) entity).getName();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.libraryaddict.disguise;
|
package me.libraryaddict.disguise;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
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.utilities.FakeBoundingBox;
|
||||||
import me.libraryaddict.disguise.utilities.Metrics;
|
import me.libraryaddict.disguise.utilities.Metrics;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@ -87,7 +89,7 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
if (disguiseType.getEntityType() == null) {
|
if (disguiseType.getEntityType() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Class watcherClass = null;
|
Class watcherClass;
|
||||||
try {
|
try {
|
||||||
switch (disguiseType) {
|
switch (disguiseType) {
|
||||||
case MINECART_CHEST:
|
case MINECART_CHEST:
|
||||||
@ -125,14 +127,18 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
} 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 (Tameable.class.isAssignableFrom(entityClass)) {
|
if (entityClass != null) {
|
||||||
watcherClass = TameableWatcher.class;
|
if (Tameable.class.isAssignableFrom(entityClass)) {
|
||||||
} else if (Ageable.class.isAssignableFrom(entityClass)) {
|
watcherClass = TameableWatcher.class;
|
||||||
watcherClass = AgeableWatcher.class;
|
} else if (Ageable.class.isAssignableFrom(entityClass)) {
|
||||||
} else if (LivingEntity.class.isAssignableFrom(entityClass)) {
|
watcherClass = AgeableWatcher.class;
|
||||||
watcherClass = LivingWatcher.class;
|
} else if (LivingEntity.class.isAssignableFrom(entityClass)) {
|
||||||
|
watcherClass = LivingWatcher.class;
|
||||||
|
} else {
|
||||||
|
watcherClass = FlagWatcher.class;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
watcherClass = FlagWatcher.class;
|
watcherClass = FlagWatcher.class; //Disguise is unknown type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
disguiseType.setWatcherClass(watcherClass);
|
disguiseType.setWatcherClass(watcherClass);
|
||||||
@ -182,6 +188,15 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
try {
|
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) {
|
||||||
|
sound.setDamageAndIdleSoundVolume(1f);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
|
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
|
||||||
if (nmsEntity == null) {
|
if (nmsEntity == null) {
|
||||||
continue;
|
continue;
|
||||||
@ -201,14 +216,14 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
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..
|
||||||
|
|
||||||
// System.out.print("Disguise: " + disguiseType + ", ID: " + watch.getIndex() + ", Class: "
|
// System.out.print("Disguise: " + disguiseType + ", ID: " + watch.getIndex() + ", Class: "
|
||||||
// + (watch.getValue() == null ? "null" : watch.getValue().getClass()) + ", Value: " + watch.getValue());
|
// + (watch.getValue() == null ? "null" : watch.getValue().getClass()) + ", Value: " + watch.getValue());
|
||||||
}
|
}
|
||||||
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((Float) soundStrength);
|
sound.setDamageAndIdleSoundVolume(soundStrength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +237,7 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||||
}
|
}
|
||||||
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
|
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
|
||||||
} catch (Exception ex) {
|
} 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] 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, "
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.libraryaddict.disguise.commands;
|
package me.libraryaddict.disguise.commands;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ public class DisguiseEntityCommand extends BaseDisguiseCommand {
|
|||||||
sender.sendMessage(ex.getMessage());
|
sender.sendMessage(ex.getMessage());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception ex) {
|
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||||
ex.printStackTrace(System.out);
|
ex.printStackTrace(System.out);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,9 @@ public enum DisguiseType {
|
|||||||
|
|
||||||
ZOMBIE,
|
ZOMBIE,
|
||||||
|
|
||||||
ZOMBIE_VILLAGER;
|
ZOMBIE_VILLAGER,
|
||||||
|
|
||||||
|
UNKNOWN;
|
||||||
|
|
||||||
private static Method isVillager, getVariant, getSkeletonType, isElder;
|
private static Method isVillager, getVariant, getSkeletonType, isElder;
|
||||||
|
|
||||||
@ -253,7 +255,7 @@ public enum DisguiseType {
|
|||||||
try {
|
try {
|
||||||
return valueOf(entityType.name().toUpperCase());
|
return valueOf(entityType.name().toUpperCase());
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
return null;
|
return DisguiseType.UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,6 +318,10 @@ public enum DisguiseType {
|
|||||||
return this == DisguiseType.PLAYER;
|
return this == DisguiseType.PLAYER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isUnknown() {
|
||||||
|
return this == DisguiseType.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
private void setEntityType(EntityType entityType) {
|
private void setEntityType(EntityType entityType) {
|
||||||
this.entityType = entityType;
|
this.entityType = entityType;
|
||||||
}
|
}
|
||||||
|
@ -345,6 +345,9 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
|||||||
throw new DisguiseParseException(ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0]
|
throw new DisguiseParseException(ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0]
|
||||||
+ ChatColor.RED + " doesn't exist!");
|
+ ChatColor.RED + " doesn't exist!");
|
||||||
}
|
}
|
||||||
|
if (disguiseType.isUnknown()) {
|
||||||
|
throw new DisguiseParseException(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!");
|
||||||
|
}
|
||||||
if (disguiseType.getEntityType() == null) {
|
if (disguiseType.getEntityType() == null) {
|
||||||
throw new DisguiseParseException(ChatColor.RED + "Error! This version of minecraft does not have that disguise!");
|
throw new DisguiseParseException(ChatColor.RED + "Error! This version of minecraft does not have that disguise!");
|
||||||
}
|
}
|
||||||
|
@ -970,6 +970,7 @@ public class DisguiseUtilities {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup it so he can see himself when disguised
|
* Setup it so he can see himself when disguised
|
||||||
|
* @param disguise
|
||||||
*/
|
*/
|
||||||
public static void setupFakeDisguise(final Disguise disguise) {
|
public static void setupFakeDisguise(final Disguise disguise) {
|
||||||
Entity e = disguise.getEntity();
|
Entity e = disguise.getEntity();
|
||||||
|
@ -52,6 +52,7 @@ public class DisguiseValues {
|
|||||||
private HashMap<Integer, Object> metaValues = new HashMap<>();
|
private HashMap<Integer, Object> metaValues = new HashMap<>();
|
||||||
private Class nmsEntityClass;
|
private Class nmsEntityClass;
|
||||||
|
|
||||||
|
@SuppressWarnings("LeakingThisInConstructor")
|
||||||
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) {
|
public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) {
|
||||||
values.put(type, this);
|
values.put(type, this);
|
||||||
enumEntitySize = entitySize;
|
enumEntitySize = entitySize;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: LibsDisguises
|
name: LibsDisguises
|
||||||
main: me.libraryaddict.disguise.LibsDisguises
|
main: me.libraryaddict.disguise.LibsDisguises
|
||||||
version: 8.5.1
|
version: 8.5.2
|
||||||
author: libraryaddict
|
author: libraryaddict
|
||||||
authors: [Byteflux, Navid K.]
|
authors: [Byteflux, Navid K.]
|
||||||
depend: [ProtocolLib]
|
depend: [ProtocolLib]
|
||||||
|
Loading…
Reference in New Issue
Block a user