use of com.comphenix.protocol.wrappers.WrappedBlockData 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.WrappedBlockData 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.WrappedBlockData in project CombatLogX by SirBlobman.
the class ForceFieldAdapter method onPacketSending.
@Override
public void onPacketSending(PacketEvent e) {
if (e.isCancelled()) {
return;
}
Player player = e.getPlayer();
ICombatManager combatManager = this.plugin.getCombatManager();
if (!combatManager.isInCombat(player)) {
return;
}
World world = player.getWorld();
PacketContainer packetContainer = e.getPacket();
Location location = getLocation0(world, packetContainer);
if (isForceFieldBlock(player, location)) {
WrappedBlockData wrappedBlockData = getWrappedBlockData();
if (wrappedBlockData != null) {
packetContainer.getBlockData().writeSafely(0, wrappedBlockData);
}
}
}
Aggregations