Example #1
0
  @Override
  public boolean onRightClick(ItemStack itemInHand) {

    // right click toggling is enabled, handle it and check permission
    if (TGlobalSettings.mmRightToggle() && perms.has(player, "dtl.trader.manage")) {
      // if air then chane to stick item
      ItemStack itemToToggle = TGlobalSettings.mmItemToggle();
      if (itemToToggle.getType().equals(Material.AIR)) itemToToggle.setType(Material.STICK);

      // if id's in hand and for toggling are the same manage the mode change
      if (itemInHand != null && itemToToggle.getTypeId() == itemInHand.getTypeId()) {
        // send a event when manager mode toggling
        TraderClickEvent e =
            (TraderClickEvent) new TraderClickEvent(this, player, true, false).callEvent();

        // we can still stop mmToggling
        if (e.isManagerToggling()) {
          toggleManageMode("right");

          // stop event execution
          return false;
        }
      } else {
        // maybe we can do this bit more nicer?

        // send a event withoug toggling
        new TraderClickEvent(this, player, false, false).callEvent();
      }
    } else {
      // send a event withoug toggling
      new TraderClickEvent(this, player, false, false).callEvent();
    }

    // debug info
    dB.info(this.getClass().getSimpleName(), " Trader right click event, by: ", player.getName());

    if (status.inManagementMode()) inventory = stock.getManagementInventory(baseStatus, status);
    else inventory = stock.getInventory(status);
    parseStatus(status);

    updatePlayerInventory();

    // register the inventory as a traderInventory
    tNpcManager.instance().registerOpenedInventory(player, inventory);

    // open the traders inventory
    player.openInventory(inventory);

    return true;
  }
Example #2
0
  @Override
  public void onLeftClick(ItemStack itemInHand) {
    // send a event
    TraderClickEvent e =
        (TraderClickEvent)
            new TraderClickEvent(this, player, !TGlobalSettings.mmRightToggle(), true).callEvent();

    // check settings
    if (e.isManagerToggling()) return;

    // check permission
    if (!perms.has(player, "dtl.trader.manage")) return;

    // if air every item in hand is valid
    ItemStack itemToToggle = TGlobalSettings.mmItemToggle();
    if (itemInHand != null && !itemToToggle.getType().equals(Material.AIR)) {
      // if id are different then cancel the event
      if (itemToToggle.getTypeId() != itemInHand.getTypeId()) return;
    }

    toggleManageMode("left");
  }