Search in sources :

Example 11 with EntityWrapper

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));
}
Also used : EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper) ZoomData(me.deecaad.weaponmechanics.wrappers.ZoomData)

Example 12 with EntityWrapper

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);
}
Also used : EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper)

Example 13 with EntityWrapper

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;
}
Also used : EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper) Nullable(javax.annotation.Nullable)

Example 14 with EntityWrapper

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();
    }
}
Also used : EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper)

Example 15 with EntityWrapper

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();
}
Also used : EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EntityWrapper (me.deecaad.weaponmechanics.wrappers.EntityWrapper)17 CastData (me.deecaad.weaponmechanics.mechanics.CastData)4 Player (org.bukkit.entity.Player)4 EventHandler (org.bukkit.event.EventHandler)4 ItemStack (org.bukkit.inventory.ItemStack)4 PlayerWrapper (me.deecaad.weaponmechanics.wrappers.PlayerWrapper)3 LivingEntity (org.bukkit.entity.LivingEntity)3 Configuration (me.deecaad.core.file.Configuration)2 WeaponMechanics.getEntityWrapper (me.deecaad.weaponmechanics.WeaponMechanics.getEntityWrapper)2 EntityEquipment (org.bukkit.inventory.EntityEquipment)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 ArrayList (java.util.ArrayList)1 Nonnegative (javax.annotation.Nonnegative)1 Nullable (javax.annotation.Nullable)1 WorldGuardCompatibility (me.deecaad.core.compatibility.worldguard.WorldGuardCompatibility)1 WeaponMechanics (me.deecaad.weaponmechanics.WeaponMechanics)1 Mechanics (me.deecaad.weaponmechanics.mechanics.Mechanics)1 BlockRegenSorter (me.deecaad.weaponmechanics.weapon.explode.regeneration.BlockRegenSorter)1 LayerDistanceSorter (me.deecaad.weaponmechanics.weapon.explode.regeneration.LayerDistanceSorter)1 WeaponInfoDisplay (me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay)1