use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.
the class OutAbilitiesListener method onPacket.
@Override
public void onPacket(Packet packet) {
EntityWrapper entityWrapper = WeaponMechanics.getEntityWrapper(packet.getPlayer());
ZoomData main = entityWrapper.getMainHandData().getZoomData();
ZoomData off = entityWrapper.getOffHandData().getZoomData();
// Not zooming
if (!main.isZooming() && !off.isZooming())
return;
int zoomAmount = main.isZooming() ? main.getZoomAmount() : off.getZoomAmount();
// Set the f field to scope level amount.
// f field means walk speed field
packet.setFieldValue(walkSpeedField, ScopeLevel.getScope(zoomAmount));
}
use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.
the class OutEntityEffectListener method onPacket.
@Override
public void onPacket(Packet packet) {
int id = (int) packet.getFieldValue(idField);
if (id < 0) {
// Means that it was sent by ScopeCompatibility
// Simply convert id back to normal and let packet pass
// By pass I mean, not cancel it, that return statement is there for reason (to cancel night vision remove when it should be on)
packet.setFieldValue(idField, -id);
return;
}
// If packet entity id is not player's id
if (id != packet.getPlayer().getEntityId()) {
return;
}
EntityWrapper entityWrapper = WeaponMechanics.getEntityWrapper(packet.getPlayer());
if (!entityWrapper.getMainHandData().getZoomData().hasZoomNightVision() && !entityWrapper.getOffHandData().getZoomData().hasZoomNightVision())
return;
if ((byte) packet.getFieldValue(dataField) != (byte) (PotionEffectType.NIGHT_VISION.getId() & 255))
return;
packet.setCancelled(true);
}
use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.
the class WeaponMechanics method getEntityWrapper.
/**
* This method will return null if no auto add is set to true and EntityWrapper is not found.
* If no auto add is false then new EntityWrapper is automatically created if not found and returned by this method.
*
* @param entity the entity
* @param noAutoAdd true means that EntityWrapper wont be automatically added if not found
* @return the entity wrapper or null if no auto add is true and EntityWrapper was not found
*/
@Nullable
public static EntityWrapper getEntityWrapper(LivingEntity entity, boolean noAutoAdd) {
EntityWrapper wrapper = plugin.entityWrappers.get(entity);
if (wrapper == null) {
if (noAutoAdd) {
return null;
}
wrapper = new EntityWrapper(entity);
plugin.entityWrappers.put(entity, wrapper);
}
return wrapper;
}
use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.
the class WeaponMechanics method removeEntityWrapper.
/**
* Removes entity (and player) wrapper and all of its content.
* Move task is also cancelled.
*
* @param entity the entity (or player)
*/
public static void removeEntityWrapper(LivingEntity entity) {
EntityWrapper oldWrapper = plugin.entityWrappers.remove(entity);
if (oldWrapper != null) {
int oldMoveTask = oldWrapper.getMoveTaskId();
if (oldMoveTask != 0) {
Bukkit.getScheduler().cancelTask(oldMoveTask);
}
oldWrapper.getMainHandData().cancelTasks();
oldWrapper.getOffHandData().cancelTasks();
}
}
use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.
the class WeaponListeners method swapHandItems.
@EventHandler(ignoreCancelled = true)
public void swapHandItems(PlayerSwapHandItemsEvent e) {
EntityWrapper entityWrapper = WeaponMechanics.getEntityWrapper(e.getPlayer());
entityWrapper.getMainHandData().cancelTasks();
entityWrapper.getOffHandData().cancelTasks();
}
Aggregations