@EventHandler(priority = EventPriority.LOW)
 public void onPlayerAnimation(PlayerAnimationEvent e) {
   Player p = e.getPlayer();
   List<String> allowedMoves =
       Probending.plugin.getConfig().getStringList("TeamSettings.AllowedMoves");
   String playerTeam = PBMethods.getPlayerTeam(p.getUniqueId());
   if (playerTeam != null) {
     if (playerTeam.equalsIgnoreCase(PBMethods.TeamOne)
         || playerTeam.equalsIgnoreCase(PBMethods.TeamTwo)) {
       if (PBMethods.matchStarted) {
         if (!allowedMoves.contains(GeneralMethods.getBoundAbility(p).toString())
             && GeneralMethods.getBoundAbility(p) != null) {
           e.setCancelled(true);
         }
       }
     }
   }
   if (PBMethods.allowedZone.containsKey(p.getName())) {
     if (PBMethods.matchStarted
         && PBMethods.getWorldGuard() != null
         && PBMethods.AutomateMatches) {
       Location loc = p.getLocation();
       Set<String> regions = PBMethods.RegionsAtLocation(loc);
       String allowedZone = PBMethods.allowedZone.get(p.getName());
       if (regions != null && !regions.isEmpty()) {
         if (!regions.contains(allowedZone)) {
           e.setCancelled(true);
         }
       }
     }
   }
 }
  private void usePowertools(final PlayerAnimationEvent event) {
    if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) {
      return;
    }
    final User user = ess.getUser(event.getPlayer());
    final ItemStack is = user.getItemInHand();
    if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled()) {
      return;
    }
    final List<String> commandList = user.getPowertool(is);
    if (commandList == null || commandList.isEmpty()) {
      return;
    }

    // We need to loop through each command and execute
    for (String command : commandList) {
      if (command.matches(".*\\{player\\}.*")) {
        // user.sendMessage("Click a player to use this command");
        continue;
      } else if (command.startsWith("c:")) {
        for (Player p : server.getOnlinePlayers()) {
          p.sendMessage(user.getDisplayName() + ":" + command.substring(2));
        }
      } else {
        user.getServer().dispatchCommand(event.getPlayer(), command);
      }
    }
  }
Esempio n. 3
0
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onPlayerMovesArm(PlayerAnimationEvent event) {
   if (event.getAnimationType() == PlayerAnimationType.ARM_SWING) {
     plugin
         .getServer()
         .getScheduler()
         .runTask(plugin, new ResetIgnoreSleepTask(plugin, event.getPlayer().getName()));
   }
 }
Esempio n. 4
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerAnimation(PlayerAnimationEvent event) {
    VPlayer vplayer = VPlayers.i.get(event.getPlayer());
    if (!vplayer.isVampire()) return;

    if (event.getAnimationType() == PlayerAnimationType.ARM_SWING
        && Conf.jumpMaterials.contains(event.getPlayer().getItemInHand().getType())) {
      vplayer.jump(Conf.jumpDeltaSpeed, true);
    }
  }
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerSwing(PlayerAnimationEvent event) {
    Player player = event.getPlayer();
    if (this.interact.contains(player.getUniqueId())) {
      this.interact.remove(player.getUniqueId());
      return;
    }
    if (Bloodbending.isBloodbended(player) || Concussion.getTarget(player) != null) {
      event.setCancelled(true);
      return;
    }

    String ability = EntityTools.getBendingAbility(player);
    RegisteredAbility registered = AbilityManager.getManager().getRegisteredAbility(ability);
    if (registered == null) {
      return;
    }

    if (EntityTools.canBend(player, registered)
        && (registered.canBeUsedWithTools()
            || !EntityTools.isTool(player.getInventory().getItemInMainHand().getType()))) {
      Map<Object, BendingAbility> abilities = AbilityManager.getManager().getInstances(ability);
      boolean shouldCreateNew = true;
      for (BendingAbility a : abilities.values()) {
        if (player.equals(a.getPlayer()) && !((BendingActiveAbility) a).swing()) {
          shouldCreateNew = false;
        }
      }
      if (shouldCreateNew) {
        BendingActiveAbility ab = AbilityManager.getManager().buildAbility(ability, player);
        if (ab == null) {
          Bending.getInstance()
              .getLogger()
              .log(
                  Level.SEVERE,
                  "Ability "
                      + ability
                      + " failed to construct with buildAbility for player "
                      + player.getName());
          return;
        }
        if (ab.canBeInitialized()) {
          ab.swing();
          if (ab.getState() != BendingAbilityState.START
              && ab.getState() != BendingAbilityState.ENDED) {
            AbilityManager.getManager().addInstance(ab);
          }
        }
      }
    }
  }
Esempio n. 6
0
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onPlayerChangesHeldItem(PlayerAnimationEvent event) {
   plugin
       .getServer()
       .getScheduler()
       .runTask(plugin, new ResetIgnoreSleepTask(plugin, event.getPlayer().getName()));
 }
 /**
  * We listen to PlayerAnimation events because it is (currently) equivalent to "player swings arm"
  * and we want to check if he did that between block breaks.
  *
  * @param event the event
  */
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPlayerAnimation(final PlayerAnimationEvent event) {
   /*
    *  ____  _                            _          _                 _   _
    * |  _ \| | __ _ _   _  ___ _ __     / \   _ __ (_)_ __ ___   __ _| |_(_) ___  _ __
    * | |_) | |/ _` | | | |/ _ \ '__|   / _ \ | '_ \| | '_ ` _ \ / _` | __| |/ _ \| '_ \
    * |  __/| | (_| | |_| |  __/ |     / ___ \| | | | | | | | | | (_| | |_| | (_) | | | |
    * |_|   |_|\__,_|\__, |\___|_|    /_/   \_\_| |_|_|_| |_| |_|\__,_|\__|_|\___/|_| |_|
    *                |___/
    */
   // Just set a flag to true when the arm was swung.
   BlockPlaceData.getData(event.getPlayer()).noSwingArmSwung = true;
 }
Esempio n. 8
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerAnimation(PlayerAnimationEvent event) {
    final Player player = event.getPlayer();
    final Stick stick = plugin.getStick(player);
    if (plugin.canUse(player, stick)) {
      // try to catch the missing PLAYER_INTERACT
      Thread t =
          new Thread(
              new Runnable() {
                public void run() {
                  try {
                    Thread.sleep(10);
                  } catch (InterruptedException e) {
                    return;
                  }

                  long now = new Date().getTime();

                  if (now - stick.getLastActionTakenAt() > 40) {
                    Block target = player.getTargetBlock(null, 500);
                    PlayerInteractEvent pie =
                        new PlayerInteractEvent(
                            player,
                            target.getType() == Material.AIR
                                ? Action.LEFT_CLICK_AIR
                                : Action.LEFT_CLICK_BLOCK,
                            player.getItemInHand(),
                            target,
                            target.getFace(player.getEyeLocation().getBlock()));
                    // plugin.log("Calling onPlayerInteract");
                    onPlayerInteract(pie);
                  }
                }
              });
      t.setDaemon(true);
      t.start();
    }
  }