Example #1
0
  /**
   * Checks a player.
   *
   * @param player the player
   * @return true, if successful
   */
  public boolean check(final Player player) {
    final InventoryConfig cc = InventoryConfig.getConfig(player);
    final InventoryData data = InventoryData.getData(player);

    boolean cancel = false;

    // Has the configured time passed? If so, reset the counter.
    if (data.dropLastTime + cc.dropTimeFrame <= System.currentTimeMillis()) {
      data.dropLastTime = System.currentTimeMillis();
      data.dropCount = 0;
      data.dropVL = 0D;
    }

    // Security check, if the system time changes.
    else if (data.dropLastTime > System.currentTimeMillis()) data.dropLastTime = Integer.MIN_VALUE;

    data.dropCount++;

    // The player dropped more than he should.
    if (data.dropCount > cc.dropLimit) {
      // Set his violation level.
      data.dropVL = data.dropCount - cc.dropLimit;

      // Dispatch a drop event (API).
      final DropEvent e = new DropEvent(player);
      Bukkit.getPluginManager().callEvent(e);

      // Execute whatever actions are associated with this check and the violation level and find
      // out if we should
      // cancel the event.
      cancel = !e.isCancelled() && executeActions(player, cc.dropActions, data.dropVL);
    }

    return cancel;
  }
Example #2
0
 @Override
 public HandlerRegistration addDropHandler(DropHandler handler) {
   return handlers.addHandler(DropEvent.getType(), handler);
 }