use of com.comphenix.protocol.wrappers.EnumWrappers.Direction in project LibsDisguises by libraryaddict.
the class ReflectionManager method convertInvalidMeta.
public static Object convertInvalidMeta(Object value) {
if (value instanceof Optional) {
Optional opt = (Optional) value;
if (!opt.isPresent()) {
return NmsVersion.v1_13.isSupported() ? value : com.google.common.base.Optional.absent();
}
if (nmsReflection != null) {
return nmsReflection.convertOptional(opt.get());
}
Object val = opt.get();
if (val instanceof BlockPosition) {
BlockPosition pos = (BlockPosition) val;
try {
Object obj = blockPositionConstructor.newInstance(pos.getX(), pos.getY(), pos.getZ());
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (val instanceof WrappedBlockData) {
try {
Object obj = ((WrappedBlockData) val).getHandle();
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (val instanceof ItemStack) {
val = getNmsItem((ItemStack) val);
if (val == null) {
return NmsVersion.v1_13.isSupported() ? Optional.empty() : com.google.common.base.Optional.absent();
} else {
return Optional.of(val);
}
} else if (val instanceof WrappedChatComponent) {
Object obj = ((WrappedChatComponent) val).getHandle();
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
} else if (!NmsVersion.v1_13.isSupported()) {
return com.google.common.base.Optional.of(val);
} else {
return Optional.of(val);
}
} else if (value instanceof Vector3F) {
Vector3F angle = (Vector3F) value;
if (nmsReflection != null) {
return nmsReflection.convertVec3(angle);
}
try {
return vector3FConstructor.newInstance(angle.getX(), angle.getY(), angle.getZ());
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (value instanceof EulerAngle) {
EulerAngle angle = (EulerAngle) value;
if (nmsReflection != null) {
return nmsReflection.convertVec3(angle);
}
try {
return vector3FConstructor.newInstance((float) angle.getX(), (float) angle.getY(), (float) angle.getZ());
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (value instanceof Direction) {
if (nmsReflection != null) {
return nmsReflection.convertDirection((Direction) value);
}
try {
return enumDirectionFrom.invoke(null, ((Direction) value).ordinal());
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (value instanceof BlockPosition) {
BlockPosition pos = (BlockPosition) value;
if (nmsReflection != null) {
return nmsReflection.getBlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
try {
return blockPositionConstructor.newInstance(pos.getX(), pos.getY(), pos.getZ());
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (value instanceof ItemStack) {
return getNmsItem((ItemStack) value);
} else if (value instanceof Double) {
return ((Double) value).floatValue();
} else if (value instanceof NbtWrapper) {
return ((NbtWrapper) value).getHandle();
} else if (value instanceof WrappedParticle) {
return ((WrappedParticle) value).getHandle();
} else if (value instanceof EntityPose) {
return getNmsEntityPose((EntityPose) value);
} else if (value instanceof VillagerData) {
return getNmsVillagerData((VillagerData) value);
} else if (value instanceof WrappedChatComponent) {
return ((WrappedChatComponent) value).getHandle();
}
return value;
}
Aggregations