@EventHandler(priority = EventPriority.HIGHEST)
 public void handleClick(ButtonClickEvent event) {
   Button b = event.getButton();
   SpoutPlayer player = event.getPlayer();
   if (event.isCancelled() || event == null || event.getPlayer() == null) return;
   if (b.equals(loginBtn)) {
     plugin.management.performLogin(player, passBox.getText(), false);
   } else if (b.equals(exitBtn)) {
     event.getPlayer().kickPlayer(exitMsg);
   }
 }
  @Override
  public void onButtonClick(Button button) {

    if (button.equals(button1)) {
      spoutp.getMainScreen().getActivePopup().close();
      spoutp.getMainScreen().attachPopupScreen(new PrimClassesGUI(plugin, spoutp));
    } else if (button.equals(button2)) {
      spoutp.getMainScreen().getActivePopup().close();
      spoutp.getMainScreen().attachPopupScreen(new ProfClassesGUI(plugin, spoutp));
    }
  }
  public HeroesSelectGUI(HeroesHUD plugin, SpoutPlayer spoutp) {
    this.plugin = plugin;
    this.spoutp = spoutp;

    GenericTexture backgroundMain = new GenericTexture();

    int screenWidth = spoutp.getMainScreen().getWidth();
    int screenHeight = spoutp.getMainScreen().getHeight();
    int x = (screenWidth / 2) - 170;
    int y = (screenHeight / 2) - 100;

    // BackgroundMain!

    backgroundMain.setX(x).setY(y);
    backgroundMain.setWidth(340).setHeight(200);
    backgroundMain.setUrl(plugin.HeroesSelectGuiBackgroundMain);
    backgroundMain.setFixed(false);
    backgroundMain.setPriority(RenderPriority.Highest);

    // Button1 Main
    button1 = new GenericButton();
    button1.setText("Primary");
    button1
        .setWidth(GenericLabel.getStringWidth(button1.getText()) + 5 + 30)
        .setHeight(GenericLabel.getStringHeight(button1.getText()) + 5);
    button1.setX(backgroundMain.getX() + 20);
    button1.setY(backgroundMain.getY() + 65);
    button1.setDirty(true);
    button1.setAutoDirty(true);

    // Button2 Main
    button2 = new GenericButton();
    button2.setText("Profession");
    button2
        .setWidth(GenericLabel.getStringWidth(button2.getText()) + 5 + 30)
        .setHeight(GenericLabel.getStringHeight(button2.getText()) + 5);
    button2.setX(backgroundMain.getX() + 235);
    button2.setY(backgroundMain.getY() + 65);
    button2.setDirty(true);
    button2.setAutoDirty(true);

    super.attachWidgets(plugin, backgroundMain, button1, button2);
    super.setAnchor(WidgetAnchor.TOP_LEFT);
  }
  public void onCustomEvent(Event event) {
    if (event instanceof ButtonClickEvent) {
      Button button = ((ButtonClickEvent) event).getButton();
      UUID uuid = button.getId();
      SpoutPlayer sPlayer = ((ButtonClickEvent) event).getPlayer();
      ItemStack itemInHand = sPlayer.getInventory().getItemInHand();
      int id = sPlayer.getEntityId();
      if (BITBook.BITButtons.get(uuid) == "saveBookButton") {
        BITBook.popupScreen.get(id).close();
        BITBook.cleanupPopupScreen(sPlayer);
        BITBook.BITButtons.remove(uuid);
        int i = BITBook.currentPageNo.get(id);
        BITBook.bodytextGUI2.get(id)[i] = BITBook.bodytextGUI.get(id).getText();

        BITBook.saveBook(sPlayer, BITBook.currentBookId.get(id));
        itemInHand.setDurability(BITBook.currentBookId.get(id));
        sPlayer.closeActiveWindow();
        BITBook.hasOpenedBook.put(id, false);

      } else if (BITBook.BITButtons.get(uuid) == "cancelBookButton"
          || BITBook.BITButtons.get(uuid) == "returnBookButton") {
        BITBook.popupScreen.get(id).close();
        BITBook.cleanupPopupScreen(sPlayer);
        BITBook.BITButtons.remove(uuid);
        BITBook.bitBooks.remove(BITBook.currentBookId.get(id));
        BITBook.currentBookId.put(id, (short) 1000);
        sPlayer.closeActiveWindow();
        BITBook.hasOpenedBook.put(id, false);

      } else if ((BITBook.BITButtons.get(uuid) == "nextPageButton")) {
        if (validateFields(sPlayer)) {
          BITBook.showNextPage(sPlayer);
        }
      } else if ((BITBook.BITButtons.get(uuid) == "previousPageButton")) {
        if (validateFields(sPlayer)) {
          BITBook.showPreviousPage(sPlayer);
        }
      } else if ((BITBook.BITButtons.get(uuid) == "masterCopyButton")) {
        if (validateFields(sPlayer)) {
          if (BITBook.masterCopyGUI.get(id)) {
            BITBook.masterCopyGUI.put(id, false);
          } else {
            BITBook.masterCopyGUI.put(id, true);
          }
          BITBook.masterCopyButtonGUI.get(id).setText("Master:" + BITBook.masterCopyGUI.get(id));
          BITBook.masterCopyButtonGUI.get(id).setDirty(true);
        }
      } else if ((BITBook.BITButtons.get(uuid) == "forceBookToPlayerInventoryButton")) {
        if (validateFields(sPlayer)) {
          if (BITBook.forceBookToPlayerInventoryGUI.get(id)) {
            BITBook.forceBookToPlayerInventoryGUI.put(id, false);
          } else {
            BITBook.forceBookToPlayerInventoryGUI.put(id, true);
          }
          BITBook.forceBookToPlayerInventoryButtonGUI
              .get(id)
              .setText("Force:" + BITBook.forceBookToPlayerInventoryGUI.get(id));
          BITBook.forceBookToPlayerInventoryButtonGUI.get(id).setDirty(true);
        }
      } else if ((BITBook.BITButtons.get(uuid) == "canBeMovedFromInventoryButton")) {
        if (validateFields(sPlayer)) {
          if (BITBook.canBeMovedFromInventoryGUI.get(id)) {
            BITBook.canBeMovedFromInventoryGUI.put(id, false);
          } else {
            BITBook.canBeMovedFromInventoryGUI.put(id, true);
          }
          BITBook.canBeMovedFromInventoryButtonGUI
              .get(id)
              .setText("Moved:" + BITBook.canBeMovedFromInventoryGUI.get(id));
          BITBook.canBeMovedFromInventoryButtonGUI.get(id).setDirty(true);
        }
      } else if ((BITBook.BITButtons.get(uuid) == "copyTheBookWhenMovedButton")) {
        if (validateFields(sPlayer)) {
          if (BITBook.copyTheBookWhenMovedGUI.get(id)) {
            BITBook.copyTheBookWhenMovedGUI.put(id, false);
          } else {
            BITBook.copyTheBookWhenMovedGUI.put(id, true);
          }
          BITBook.copyTheBookWhenMovedButtonGUI
              .get(id)
              .setText("Copy:" + BITBook.copyTheBookWhenMovedGUI.get(id));
          BITBook.copyTheBookWhenMovedButtonGUI.get(id).setDirty(true);
        }
      }

      // ************************************
      // This only happens if I have forgot to handle a button
      // ************************************
      else {
        if (BITConfig.DEBUG_GUI)
          sPlayer.sendMessage(
              "BITBookSpoutListener: Unknow button:" + BITBook.BITButtons.get(uuid));
      }
    }
  }