@Override public void call(Event event) { if (event instanceof PlayerInteractEvent) { final PlayerInteractEvent pie = (PlayerInteractEvent) event; // Types of interacting where the arm must swing. if (pie.getAction() == Action.LEFT_CLICK_AIR || pie.getAction() == Action.LEFT_CLICK_BLOCK) { lastInteract = System.currentTimeMillis(); } } else if (event instanceof PlayerAnimationEvent) { final PlayerAnimationEvent pae = (PlayerAnimationEvent) event; if (pae.getAnimationType() == PlayerAnimationType.ARM_SWING) { final long difference = System.currentTimeMillis() - lastInteract; Bukkit.broadcastMessage("swing difference: " + difference); } } }
void onEvent(PlayerAnimationEvent event) { if(event.getAnimationType() != PlayerAnimationType.ARM_SWING) return; if(event.getPlayer().isDigging()) return; if(!isHoldingWeapon()) return; swinging = true; lastSwingTick = player.getMatch().getClock().now().tick; }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void detectBlockPunch(PlayerAnimationEvent event) { if(event.getAnimationType() != PlayerAnimationType.ARM_SWING) return; if(event.getPlayer().getGameMode() != GameMode.ADVENTURE) return; // Client will not punch blocks in adventure mode, so we detect it ourselves and fire a BlockPunchEvent. // We do this in the kit module only because its the one that is responsible for putting players in adventure mode. // A few other modules rely on this, including StaminaModule and BlockDropsModule. RayBlockIntersection hit = event.getPlayer().getTargetedBlock(true, false); if(hit == null) return; eventBus.callEvent(new BlockPunchEvent(event.getPlayer(), hit)); }
@EventHandler public void thirstSwing(PlayerAnimationEvent e) { if (e.getAnimationType() != PlayerAnimationType.ARM_SWING) return; Player p = e.getPlayer(); if (!RUtils.isInInfectedWorld(p)) return; final ItemStack hand = p.getItemInHand(); if (hand == null || hand.getType() == Material.AIR) changeThirst(p, -Config.thirstSwing); else changeThirst(p, -Config.thirstSwingItem); }
@EventHandler public void onAnim(PlayerAnimationEvent event) { if (event.getAnimationType() == PlayerAnimationType.ARM_SWING) { check(event.getPlayer().getInventory().getItemInMainHand(), event.getPlayer()); } }
@TargetedEventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSwing(PlayerAnimationEvent event) { if(event.getAnimationType() != PlayerAnimationType.ARM_SWING) return; if(event.getPlayer().isDigging()) return; updateSpeedometer(); }
@Override public PlayerAnimationType getAnimationType() { throw new NotImplementedException("TODO"); // TODO }
public PlayerAnimationType getAnimationType() { return null; }