use of com.comphenix.protocol.wrappers.WrappedParticle 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;
}
use of com.comphenix.protocol.wrappers.WrappedParticle in project LibsDisguises by libraryaddict.
the class ParamInfoParticle method toString.
@Override
public String toString(Object object) {
WrappedParticle particle = (WrappedParticle) object;
Object data = particle.getData();
String returns = particle.getParticle().name();
if (data != null) {
if (data instanceof ItemStack) {
returns += "," + ((ItemStack) data).getType().name();
} else if (data instanceof WrappedBlockData) {
returns += "," + ((WrappedBlockData) data).getType().name();
} else if (data instanceof Particle.DustOptions) {
returns += "," + ParamInfoManager.getParamInfo(Color.class).toString(((Particle.DustOptions) data).getColor());
if (((Particle.DustOptions) data).getSize() != 1f) {
returns += "," + ((Particle.DustOptions) data).getSize();
}
}
}
return returns;
}
use of com.comphenix.protocol.wrappers.WrappedParticle in project LibsDisguises by libraryaddict.
the class SerializerFlagWatcher method correct.
private void correct(FlagWatcher watcher, Class<? extends FlagWatcher> flagWatcher, String name) throws NoSuchFieldException, IllegalAccessException, DisguiseParseException {
Field field = FlagWatcher.class.getDeclaredField(name);
field.setAccessible(true);
HashMap<Integer, Object> map = (HashMap<Integer, Object>) field.get(watcher);
int count = 0;
for (Map.Entry<Integer, Object> entry : map.entrySet()) {
MetaIndex index = MetaIndex.getMetaIndex(flagWatcher, entry.getKey());
if (entry.getValue() instanceof Double) {
Object def = index.getDefault();
if (def instanceof Long) {
entry.setValue(((Double) entry.getValue()).longValue());
} else if (def instanceof Float) {
entry.setValue(((Double) entry.getValue()).floatValue());
} else if (def instanceof Integer) {
entry.setValue(((Double) entry.getValue()).intValue());
} else if (def instanceof Short) {
entry.setValue(((Double) entry.getValue()).shortValue());
} else if (def instanceof Byte) {
entry.setValue(((Double) entry.getValue()).byteValue());
}
} else if (entry.getValue() instanceof String) {
if (index.getDefault() instanceof WrappedParticle) {
entry.setValue(((ParamInfoParticle) ParamInfoManager.getParamInfo(WrappedParticle.class)).fromString((String) entry.getValue()));
} else if (index.getDefault() instanceof EntityPose) {
entry.setValue(((ParamInfoEnum) ParamInfoManager.getParamInfo(EntityPose.class)).fromString((String) entry.getValue()));
}
} else if (entry.getValue() instanceof LinkedTreeMap) {
// If the default value is not VillagerData
if (index.getDefault() instanceof VillagerData) {
entry.setValue(new Gson().fromJson(new Gson().toJson(entry.getValue()), VillagerData.class));
} else if (index.getDefault() instanceof Optional) {
for (Field f : MetaIndex.class.getFields()) {
try {
if (f.get(null) != index) {
continue;
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Type type = f.getGenericType();
Type opt = ((ParameterizedType) type).getActualTypeArguments()[0];
if (opt instanceof ParameterizedType) {
Type val = ((ParameterizedType) opt).getActualTypeArguments()[0];
Optional value;
if (((LinkedTreeMap) entry.getValue()).isEmpty()) {
value = Optional.empty();
} else {
value = Optional.of(gson.fromJson(gson.toJson(((LinkedTreeMap) entry.getValue()).get("value")), val));
}
entry.setValue(value);
}
}
} else if (index.getDefault() instanceof ItemStack) {
entry.setValue(gson.fromJson(gson.toJson(entry.getValue()), ItemStack.class));
}
}
// If the deserialized class is not the same class type as the default
if (!index.getDefault().getClass().isInstance(entry.getValue())) {
entry.setValue(index.getDefault());
count++;
}
}
if (count > 0) {
DisguiseUtilities.getLogger().info("Fixed " + count + " incorrect disguise flags on saved disguise");
}
}
use of com.comphenix.protocol.wrappers.WrappedParticle in project LibsDisguises by libraryaddict.
the class AreaEffectCloudWatcher method getParticle.
@NmsAddedIn(NmsVersion.v1_13)
public WrappedParticle getParticle() {
if (NmsVersion.v1_13.isSupported()) {
return getData(MetaIndex.AREA_EFFECT_PARTICLE);
} else {
// Item crack, block crack, block dust, falling dust
int particleId = getData(MetaIndex.AREA_EFFECT_PARTICLE_OLD);
Particle particle = Particle.values()[particleId];
return WrappedParticle.create(particle, null);
}
}
use of com.comphenix.protocol.wrappers.WrappedParticle in project GuardiansOfAdelia by Lix3nn53.
the class MyPacketListeners method addPacketListeners.
public static void addPacketListeners() {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
protocolManager.addPacketListener(new PacketAdapter(GuardiansOfAdelia.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.WORLD_PARTICLES) {
@Override
public void onPacketSending(PacketEvent event) {
WrappedParticle wrappedParticle = event.getPacket().getNewParticles().read(0);
Particle particle = wrappedParticle.getParticle();
if (particle.equals(Particle.DAMAGE_INDICATOR)) {
event.setCancelled(true);
}
}
});
}
Aggregations