Exemplo n.º 1
0
 public MOCKioskKiosk getKiosk(int kioskId) {
   for (MOCKioskKiosk kiosk : this.kiosks) {
     if (kiosk.getId() == kioskId) {
       return kiosk;
     }
   }
   return null;
 }
Exemplo n.º 2
0
  // ########################################################################################################################################
  public void deleteKiosk(MOCKioskKiosk kiosk) {
    // Remove block
    this.plugin
        .getServer()
        .getWorld(kiosk.getLocation().getWorld().getName())
        .getBlockAt(kiosk.getLocation())
        .setType(Material.AIR);

    // Remove in memory records
    MOCKioskKioskDeck deck = getDeck(kiosk.getPopup_deck_id());
    MOCKioskKioskSlide slide = getSlide(kiosk.getPopup_deck_id());
    this.kiosks.remove(kiosk);
    this.slides.remove(slide);
    this.decks.remove(deck);

    // Remove database records
    this.databaseConnection.deleteSafeQuery("DELETE FROM `kiosks` WHERE `id`=" + kiosk.getId());
    this.databaseConnection.deleteSafeQuery(
        "DELETE FROM `kiosk_decks` WHERE `id`=" + kiosk.getPopup_deck_id());
    this.databaseConnection.deleteSafeQuery(
        "DELETE FROM `kiosk_slides` WHERE `indeck_id`=" + kiosk.getPopup_deck_id());
  }
Exemplo n.º 3
0
  // ########################################################################################################################################
  public int saveKiosk(
      String kioskName,
      String nearText,
      String nearURL,
      String clickText,
      String clickURL,
      boolean usePopup,
      String popupTitle,
      String popupText,
      String popupURL,
      String popupImageURL,
      int popupImageSize,
      String playerName,
      Block block,
      MOCKioskKiosk editKiosk,
      MOCKioskKioskSlide editSlide) {
    int id = -1;

    if (editKiosk == null) {
      // New kiosk - Save
      PreparedStatement statement =
          this.databaseConnection.prepareStatementAndKeys(
              "INSERT INTO `kiosks` (`name`, `owner_id`, `neartext`, `nearurl`, `clicktext`, `clickurl`, `popup_deck_id`, `isactive`, `location_id`)"
                  + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");

      try {
        int playerId = this.getPlayerId(playerName);
        int popupDeckId = -1;
        int locationId = this.getLocationId(block.getLocation());

        statement.setString(1, kioskName); // name
        statement.setInt(2, playerId); // owner_id
        statement.setString(3, nearText); // neartext
        statement.setString(4, nearURL); // nearurl
        statement.setString(5, clickText); // clicktext
        statement.setString(6, clickURL); // clickurl
        if (usePopup) {
          popupDeckId =
              this.getPopupDeckId(
                  kioskName, popupTitle, popupText, popupURL, popupImageURL, popupImageSize);
          statement.setInt(7, popupDeckId); // popup_deck_id
        } else {
          statement.setInt(7, popupDeckId); // popup_deck_id
        }
        statement.setInt(8, 1); // isactive
        statement.setInt(9, locationId); // location_id

        this.databaseConnection.insertQuery(statement);

        ResultSet rs = statement.getGeneratedKeys();
        rs.next();

        id = rs.getInt(1);

        this.kiosks.add(
            new MOCKioskKiosk(
                id,
                kioskName,
                playerId,
                playerName,
                nearText,
                nearURL,
                clickText,
                clickURL,
                popupDeckId,
                1,
                locationId,
                block.getLocation()));

      } catch (SQLException e) {
        e.printStackTrace();
      }

    } else {
      // Update existing Kiosk
      PreparedStatement statement =
          this.databaseConnection.prepareStatementAndKeys(
              "UPDATE `kiosks` SET "
                  + "`name`=?, `neartext`=?, `nearurl`=?, `clicktext`=?, `clickurl`=?, `popup_deck_id`=? WHERE `id`=?");

      try {
        statement.setString(1, kioskName); // name
        statement.setString(2, nearText); // neartext
        statement.setString(3, nearURL); // nearurl
        statement.setString(4, clickText); // clicktext
        statement.setString(5, clickURL); // clickurl

        editKiosk.setName(kioskName);
        editKiosk.setNeartext(nearText);
        editKiosk.setNearurl(nearURL);
        editKiosk.setClicktext(clickText);
        editKiosk.setClickurl(clickURL);

        int popupDeckId = editKiosk.getPopup_deck_id();

        if (usePopup) {
          if (editSlide == null) {
            // Adding popup
            popupDeckId =
                this.getPopupDeckId(
                    kioskName, popupTitle, popupText, popupURL, popupImageURL, popupImageSize);
            statement.setInt(6, popupDeckId); // popup_deck_id
            editKiosk.setPopup_deck_id(popupDeckId);

          } else {
            // Updating popup
            statement.setInt(6, popupDeckId); // popup_deck_id
            this.updatePopupSlide(
                editSlide,
                kioskName,
                popupTitle,
                popupText,
                popupURL,
                popupImageURL,
                popupImageSize);
          }

        } else {
          // No popup - removing or overwriting -1
          editKiosk.setPopup_deck_id(-1);
          statement.setInt(6, -1); // popup_deck_id
        }

        statement.setInt(7, editKiosk.getId()); // id

        // Update kiosk
        this.databaseConnection.updateQuery(statement);

        id = editKiosk.getId();

      } catch (SQLException e) {
        e.printStackTrace();
      }
    }

    return id;
  }