Read desc
Added method getBukkitEntity to reflectionmanager Added a way for itemframe values to exist.
This commit is contained in:
parent
ca913347ce
commit
473769eb26
@ -24,6 +24,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -96,6 +97,15 @@ public class LibsDisguises extends JavaPlugin {
|
||||
* for mob noises. As well as setting their watcher class and entity size.
|
||||
*/
|
||||
private void registerValues() {
|
||||
try {
|
||||
DisguiseValues disguiseValues = new DisguiseValues((Enum) Class.forName("org.bukkit.entity.EntityType")
|
||||
.getField("ITEM_FRAME").get(null), null, 0);
|
||||
for (WrappedWatchableObject watch : WrappedDataWatcher.getEntityWatcher(
|
||||
ReflectionManager.getBukkitEntity(ReflectionManager.createEntityInstance("ItemFrame"))).getWatchableObjects())
|
||||
disguiseValues.setMetaValue(watch.getIndex(), watch.getValue());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||
if (disguiseType.getEntityType() == null) {
|
||||
continue;
|
||||
@ -179,10 +189,12 @@ public class LibsDisguises extends JavaPlugin {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (DisguiseValues.getDisguiseValues(disguiseType) != null) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
|
||||
Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity")
|
||||
.invoke(nmsEntity);
|
||||
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
|
||||
int entitySize = 0;
|
||||
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
||||
if (field.getType().getName().equals("EnumEntitySize")) {
|
||||
|
@ -139,7 +139,7 @@ public abstract class Disguise {
|
||||
case ENDER_CRYSTAL:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
// case ITEM_FRAME:
|
||||
// case ITEM_FRAME:
|
||||
case MINECART:
|
||||
case MINECART_CHEST:
|
||||
case MINECART_FURNACE:
|
||||
@ -213,7 +213,7 @@ public abstract class Disguise {
|
||||
Location loc = getEntity().getLocation();
|
||||
mods.write(
|
||||
4,
|
||||
PacketsManager.getYaw(getType(), DisguiseType.getType(getEntity().getType()),
|
||||
PacketsManager.getYaw(getType(), getEntity().getType(),
|
||||
(byte) Math.floor(loc.getYaw() * 256.0F / 360.0F)));
|
||||
mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F));
|
||||
if (isSelfDisguiseVisible() && getEntity() instanceof Player) {
|
||||
@ -295,11 +295,10 @@ public abstract class Disguise {
|
||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||
.invoke(trackedEntities, getEntity().getEntityId());
|
||||
if (entityTrackerEntry != null) {
|
||||
Method method = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity");
|
||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
for (Object p : trackedPlayers) {
|
||||
players.add((Player) method.invoke(p));
|
||||
players.add((Player) ReflectionManager.getBukkitEntity(p));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@ -445,7 +444,15 @@ public abstract class Disguise {
|
||||
*/
|
||||
private void setupWatcher() {
|
||||
HashMap<Integer, Object> disguiseValues = DisguiseValues.getMetaValues(getType());
|
||||
HashMap<Integer, Object> entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType()));
|
||||
HashMap<Integer, Object> entityValues = null;
|
||||
if (DisguiseType.getType(getEntity().getType()) != null)
|
||||
entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType()));
|
||||
else {
|
||||
DisguiseValues.getEntityValues(getEntity().getType()).getMetaValues();
|
||||
}
|
||||
if (entityValues == null) {
|
||||
entityValues = new HashMap();
|
||||
}
|
||||
// Start from 2 as they ALL share 0 and 1
|
||||
for (int dataNo = 2; dataNo <= 31; dataNo++) {
|
||||
// STEP 1. Find out if the watcher has set data on it.
|
||||
|
@ -167,7 +167,11 @@ public enum DisguiseType {
|
||||
}
|
||||
|
||||
public static DisguiseType getType(org.bukkit.entity.EntityType entityType) {
|
||||
return DisguiseType.valueOf(entityType.name());
|
||||
try {
|
||||
return DisguiseType.valueOf(entityType.name());
|
||||
} catch (Throwable ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private int defaultData;
|
||||
|
@ -58,13 +58,12 @@ public class DisguiseUtilities {
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
Method getBukkitEntity = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity");
|
||||
Method clear = entityTrackerEntry.getClass().getMethod("clear", ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer",
|
||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||
HashSet cloned = (HashSet) trackedPlayers.clone();
|
||||
for (Object player : cloned) {
|
||||
if (entity instanceof Player && !((Player) getBukkitEntity.invoke(player)).canSee((Player) entity))
|
||||
if (entity instanceof Player && !((Player) ReflectionManager.getBukkitEntity(player)).canSee((Player) entity))
|
||||
continue;
|
||||
clear.invoke(entityTrackerEntry, player);
|
||||
updatePlayer.invoke(entityTrackerEntry, player);
|
||||
|
@ -2,11 +2,13 @@ package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
|
||||
public class DisguiseValues {
|
||||
|
||||
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<DisguiseType, DisguiseValues>();
|
||||
private static HashMap<Enum, DisguiseValues> values = new HashMap<Enum, DisguiseValues>();
|
||||
|
||||
public static DisguiseValues getDisguiseValues(DisguiseType type) {
|
||||
switch (type) {
|
||||
@ -35,6 +37,10 @@ public class DisguiseValues {
|
||||
return values.get(type);
|
||||
}
|
||||
|
||||
public static DisguiseValues getEntityValues(EntityType type) {
|
||||
return values.get(type);
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Object> getMetaValues(DisguiseType type) {
|
||||
return getDisguiseValues(type).getMetaValues();
|
||||
}
|
||||
@ -47,7 +53,7 @@ public class DisguiseValues {
|
||||
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
|
||||
private Class nmsEntityClass;
|
||||
|
||||
public DisguiseValues(DisguiseType type, Class classType, int entitySize) {
|
||||
public DisguiseValues(Enum type, Class classType, int entitySize) {
|
||||
values.put(type, this);
|
||||
enumEntitySize = entitySize;
|
||||
nmsEntityClass = classType;
|
||||
|
@ -114,7 +114,17 @@ public class ReflectionManager {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + bukkitVersion + "." + className);
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Entity getBukkitEntity(Object nmsEntity) {
|
||||
try {
|
||||
Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity").invoke(nmsEntity);
|
||||
return bukkitEntity;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user